ENH: add connected to printer preset list
and add group name jira:none Change-Id: Iecc4ec38ff071105f856c2034ceac0d5bde3b7b0
This commit is contained in:
parent
4030bde50d
commit
c44cc2db1a
|
@ -2246,6 +2246,8 @@ void Sidebar::load_ams_list(std::string const &device, MachineObject* obj)
|
|||
|
||||
for (auto c : p->combos_filament)
|
||||
c->update();
|
||||
|
||||
p->combo_printer->update();
|
||||
}
|
||||
|
||||
void Sidebar::sync_ams_list()
|
||||
|
@ -4864,33 +4866,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
|
|||
machine_type = "C12";
|
||||
|
||||
if (printer_preset.get_current_printer_type(preset_bundle) != machine_type || !is_approx((float) preset_nozzle_diameter, machine_nozzle_diameter)) {
|
||||
auto get_printer_preset = [](MachineObject *obj, float nozzle_value) -> Preset * {
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
|
||||
Preset *printer_preset = nullptr;
|
||||
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
|
||||
for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) {
|
||||
// only use system printer preset
|
||||
if (!printer_it->is_system) continue;
|
||||
|
||||
ConfigOption *printer_nozzle_opt = printer_it->config.option("nozzle_diameter");
|
||||
ConfigOptionFloatsNullable *printer_nozzle_vals = nullptr;
|
||||
if (printer_nozzle_opt) printer_nozzle_vals = dynamic_cast<ConfigOptionFloatsNullable *>(printer_nozzle_opt);
|
||||
std::string model_id = printer_it->get_current_printer_type(preset_bundle);
|
||||
|
||||
std::string printer_type = obj->printer_type;
|
||||
if (obj->is_support_upgrade_kit && obj->installed_upgrade_kit)
|
||||
printer_type = "C12";
|
||||
if (model_id.compare(printer_type) == 0 && printer_nozzle_vals && abs(printer_nozzle_vals->get_at(0) - nozzle_value) < 1e-3) {
|
||||
printer_preset = &(*printer_it);
|
||||
}
|
||||
};
|
||||
|
||||
return printer_preset;
|
||||
};
|
||||
|
||||
Preset *machine_preset = get_printer_preset(obj, machine_nozzle_diameter);
|
||||
Preset *machine_preset = get_printer_preset(obj);
|
||||
if (machine_preset != nullptr) {
|
||||
bool sync_printer_info = false;
|
||||
if (!wxGetApp().app_config->has("sync_after_load_file_show_flag")) {
|
||||
|
@ -7180,8 +7156,12 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
|
|||
//! instead of
|
||||
//! combo->GetStringSelection().ToUTF8().data());
|
||||
|
||||
wxString wx_name = combo->GetString(selection);
|
||||
if (preset_type == Preset::TYPE_PRINTER) {
|
||||
wx_name = combo->get_preset_item_name(selection); }
|
||||
|
||||
std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type,
|
||||
Preset::remove_suffix_modified(combo->GetString(selection).ToUTF8().data()));
|
||||
Preset::remove_suffix_modified(wx_name.ToUTF8().data()));
|
||||
|
||||
if (preset_type == Preset::TYPE_FILAMENT) {
|
||||
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
|
||||
|
@ -12384,6 +12364,33 @@ void Plater::export_core_3mf()
|
|||
export_3mf(path_u8, SaveStrategy::Silence);
|
||||
}
|
||||
|
||||
Preset *get_printer_preset(MachineObject *obj)
|
||||
{
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
|
||||
Preset *printer_preset = nullptr;
|
||||
float machine_nozzle_diameter = obj->m_extder_data.extders[0].current_nozzle_diameter;
|
||||
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
|
||||
for (auto printer_it = preset_bundle->printers.begin(); printer_it != preset_bundle->printers.end(); printer_it++) {
|
||||
// only use system printer preset
|
||||
if (!printer_it->is_system)
|
||||
continue;
|
||||
|
||||
ConfigOption *printer_nozzle_opt = printer_it->config.option("nozzle_diameter");
|
||||
ConfigOptionFloatsNullable *printer_nozzle_vals = nullptr;
|
||||
if (printer_nozzle_opt) printer_nozzle_vals = dynamic_cast<ConfigOptionFloatsNullable *>(printer_nozzle_opt);
|
||||
std::string model_id = printer_it->get_current_printer_type(preset_bundle);
|
||||
|
||||
std::string printer_type = obj->printer_type;
|
||||
if (obj->is_support_upgrade_kit && obj->installed_upgrade_kit) printer_type = "C12";
|
||||
if (model_id.compare(printer_type) == 0 && printer_nozzle_vals && abs(printer_nozzle_vals->get_at(0) - machine_nozzle_diameter) < 1e-3) {
|
||||
printer_preset = &(*printer_it);
|
||||
}
|
||||
}
|
||||
return printer_preset;
|
||||
}
|
||||
|
||||
// OK if fail_msg is empty
|
||||
std::string check_boolean_possible(const std::vector<const ModelVolume*>& volumes) {
|
||||
std::string fail_msg;
|
||||
|
|
|
@ -812,6 +812,8 @@ private:
|
|||
|
||||
std::vector<int> get_min_flush_volumes(const DynamicPrintConfig &full_config, size_t nozzle_id);
|
||||
std::string check_boolean_possible(const std::vector<const ModelVolume*>& volumes);
|
||||
|
||||
Preset *get_printer_preset(MachineObject *obj);
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
|
@ -282,6 +282,38 @@ wxString PresetComboBox::get_tooltip(const Preset &preset)
|
|||
return tooltip;
|
||||
}
|
||||
|
||||
wxString PresetComboBox::get_preset_item_name(unsigned int index)
|
||||
{
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
int idx = selected_connected_printer();
|
||||
if (idx < 0) {
|
||||
return GetString(index).ToUTF8().data();
|
||||
}
|
||||
else {
|
||||
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
|
||||
if (!dev) {
|
||||
assert(false);
|
||||
return GetString(index).ToUTF8().data();
|
||||
}
|
||||
|
||||
std::map<std::string, MachineObject *> machine_list = dev->get_my_machine_list();
|
||||
if (machine_list.empty()) {
|
||||
assert(false);
|
||||
return GetString(index).ToUTF8().data();
|
||||
}
|
||||
|
||||
auto iter = machine_list.begin();
|
||||
std::advance(iter, idx);
|
||||
Preset* machine_preset = get_printer_preset(iter->second);
|
||||
if (machine_preset) {
|
||||
return from_u8(machine_preset->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GetString(index).ToUTF8().data();
|
||||
}
|
||||
|
||||
wxString PresetComboBox::get_preset_name(const Preset & preset)
|
||||
{
|
||||
return from_u8(preset.name/* + suffix(preset)*/);
|
||||
|
@ -371,6 +403,32 @@ void PresetComboBox::update_from_bundle()
|
|||
this->update(m_collection->get_selected_preset().name);
|
||||
}
|
||||
|
||||
void PresetComboBox::add_connected_printers(std::string selected, bool alias_name)
|
||||
{
|
||||
DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager();
|
||||
if (!dev)
|
||||
return;
|
||||
|
||||
std::map<std::string, MachineObject *> machine_list = dev->get_my_machine_list();
|
||||
if (machine_list.empty())
|
||||
return;
|
||||
|
||||
set_label_marker(Append(separator(L("My Printer")), wxNullBitmap));
|
||||
m_first_printer_idx = GetCount();
|
||||
for (auto iter = machine_list.begin(); iter != machine_list.end(); ++iter) {
|
||||
int item_id = Append(from_u8(iter->second->dev_name), wxNullBitmap, &m_first_printer_idx + std::distance(machine_list.begin(), iter));
|
||||
}
|
||||
m_last_printer_idx = GetCount();
|
||||
}
|
||||
|
||||
int PresetComboBox::selected_connected_printer() const
|
||||
{
|
||||
if (m_first_printer_idx && m_last_selected >= m_first_printer_idx && m_last_selected < m_last_printer_idx) {
|
||||
return reinterpret_cast<int *>(GetClientData(m_last_selected)) - &m_first_printer_idx;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
|
||||
{
|
||||
bool is_bbl_vendor_preset = m_preset_bundle->printers.get_edited_preset().is_bbl_vendor_preset(m_preset_bundle);
|
||||
|
@ -913,6 +971,18 @@ void PlaterPresetComboBox::show_edit_menu()
|
|||
wxGetApp().plater()->PopupMenu(menu);
|
||||
}
|
||||
|
||||
wxString PlaterPresetComboBox::get_preset_group_name(const Preset &preset)
|
||||
{
|
||||
wxString group_name;
|
||||
if (preset.is_system) {
|
||||
wxString name = get_preset_name(preset);
|
||||
if (name.size() > 12) {
|
||||
group_name = name.SubString(0, name.size() - 11);
|
||||
}
|
||||
}
|
||||
return group_name;
|
||||
}
|
||||
|
||||
wxString PlaterPresetComboBox::get_preset_name(const Preset& preset)
|
||||
{
|
||||
return from_u8(preset.label(false));
|
||||
|
@ -959,10 +1029,19 @@ void PlaterPresetComboBox::update()
|
|||
// and draw a red flag in front of the selected preset.
|
||||
bool wide_icons = selected_preset && !selected_preset->is_compatible;
|
||||
|
||||
std::map<wxString, wxBitmap*> nonsys_presets;
|
||||
struct PresetItemInfo
|
||||
{
|
||||
wxString name;
|
||||
wxString group_name;
|
||||
wxBitmap *bitmap;
|
||||
|
||||
PresetItemInfo(wxString name_, wxString group_name_, wxBitmap * bitmap_): name(name_), group_name(group_name_), bitmap(bitmap_) {}
|
||||
};
|
||||
|
||||
std::vector<PresetItemInfo> nonsys_presets;
|
||||
//BBS: add project embedded presets logic
|
||||
std::map<wxString, wxBitmap*> project_embedded_presets;
|
||||
std::map<wxString, wxBitmap *> system_presets;
|
||||
std::vector<PresetItemInfo> project_embedded_presets;
|
||||
std::vector<PresetItemInfo> system_presets;
|
||||
std::map<wxString, wxString> preset_descriptions;
|
||||
std::map<wxString, std::string> preset_filament_vendors;
|
||||
std::map<wxString, std::string> preset_filament_types;
|
||||
|
@ -991,6 +1070,11 @@ void PlaterPresetComboBox::update()
|
|||
|
||||
bool single_bar = false;
|
||||
const wxString name = get_preset_name(preset);
|
||||
|
||||
wxString group_name;
|
||||
if (m_type == Preset::TYPE_PRINTER)
|
||||
group_name = get_preset_group_name(preset);
|
||||
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
{
|
||||
#if 0
|
||||
|
@ -1013,7 +1097,7 @@ void PlaterPresetComboBox::update()
|
|||
|
||||
if (preset.is_default || preset.is_system) {
|
||||
//BBS: move system to the end
|
||||
system_presets.emplace(name, bmp);
|
||||
system_presets.emplace_back(PresetItemInfo(name, group_name, bmp));
|
||||
if (is_selected) {
|
||||
tooltip = get_tooltip(preset);
|
||||
selected_system_preset = name;
|
||||
|
@ -1027,7 +1111,7 @@ void PlaterPresetComboBox::update()
|
|||
//BBS: add project embedded preset logic
|
||||
else if (preset.is_project_embedded)
|
||||
{
|
||||
project_embedded_presets.emplace(name, bmp);
|
||||
project_embedded_presets.emplace_back(PresetItemInfo(name, group_name, bmp));
|
||||
if (is_selected) {
|
||||
selected_user_preset = name;
|
||||
tooltip = wxString::FromUTF8(preset.name.c_str());
|
||||
|
@ -1035,7 +1119,7 @@ void PlaterPresetComboBox::update()
|
|||
}
|
||||
else
|
||||
{
|
||||
nonsys_presets.emplace(name, bmp);
|
||||
nonsys_presets.emplace_back(PresetItemInfo(name, group_name, bmp));
|
||||
if (is_selected) {
|
||||
selected_user_preset = name;
|
||||
//BBS set tooltip
|
||||
|
@ -1046,6 +1130,8 @@ void PlaterPresetComboBox::update()
|
|||
//if (i + 1 == m_collection->num_default_presets())
|
||||
// set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
||||
}
|
||||
if (m_type == Preset::TYPE_PRINTER)
|
||||
add_connected_printers("", true);
|
||||
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
add_ams_filaments(into_u8(selected_user_preset.empty() ? selected_system_preset : selected_user_preset), true);
|
||||
|
@ -1055,41 +1141,40 @@ void PlaterPresetComboBox::update()
|
|||
std::vector<std::string> first_vendors = {"Bambu Lab", "Generic"};
|
||||
std::vector<std::string> first_types = {"PLA", "PETG", "ABS", "TPU"};
|
||||
auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types]
|
||||
(std::map<wxString, wxBitmap *> const &presets, wxString const &selected, std::string const &group) {
|
||||
(std::vector<PresetItemInfo> presets, wxString const &selected, std::string const &group) {
|
||||
if (!presets.empty()) {
|
||||
set_label_marker(Append(separator(group), wxNullBitmap));
|
||||
if (m_type == Preset::TYPE_FILAMENT) {
|
||||
std::vector<std::map<wxString, wxBitmap *>::value_type const*> list(presets.size(), nullptr);
|
||||
std::transform(presets.begin(), presets.end(), list.begin(), [](auto & pair) { return &pair; });
|
||||
std::sort(list.begin(), list.end(), [&filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types](auto *l, auto *r) {
|
||||
std::sort(presets.begin(), presets.end(), [&filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types]
|
||||
(const PresetItemInfo& l, const PresetItemInfo& r) {
|
||||
{ // Compare order
|
||||
auto iter1 = std::find(filament_orders.begin(), filament_orders.end(), l->first);
|
||||
auto iter2 = std::find(filament_orders.begin(), filament_orders.end(), r->first);
|
||||
auto iter1 = std::find(filament_orders.begin(), filament_orders.end(), l.name);
|
||||
auto iter2 = std::find(filament_orders.begin(), filament_orders.end(), r.name);
|
||||
if (iter1 != iter2)
|
||||
return iter1 < iter2;
|
||||
}
|
||||
{ // Compare vendor
|
||||
auto iter1 = std::find(first_vendors.begin(), first_vendors.end(), preset_filament_vendors[l->first]);
|
||||
auto iter2 = std::find(first_vendors.begin(), first_vendors.end(), preset_filament_vendors[r->first]);
|
||||
auto iter1 = std::find(first_vendors.begin(), first_vendors.end(), preset_filament_vendors[l.name]);
|
||||
auto iter2 = std::find(first_vendors.begin(), first_vendors.end(), preset_filament_vendors[r.name]);
|
||||
if (iter1 != iter2)
|
||||
return iter1 < iter2;
|
||||
}
|
||||
{ // Compare type
|
||||
auto iter1 = std::find(first_types.begin(), first_types.end(), preset_filament_types[l->first]);
|
||||
auto iter2 = std::find(first_types.begin(), first_types.end(), preset_filament_types[r->first]);
|
||||
auto iter1 = std::find(first_types.begin(), first_types.end(), preset_filament_types[l.name]);
|
||||
auto iter2 = std::find(first_types.begin(), first_types.end(), preset_filament_types[r.name]);
|
||||
if (iter1 != iter2)
|
||||
return iter1 < iter2;
|
||||
}
|
||||
return l->first < r->first;
|
||||
return l.name < r.name;
|
||||
});
|
||||
for (auto it : list) {
|
||||
SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]);
|
||||
validate_selection(it->first == selected);
|
||||
for (auto it = presets.begin(); it != presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->name, *it->bitmap), preset_descriptions[it->name]);
|
||||
validate_selection(it->name == selected);
|
||||
}
|
||||
} else {
|
||||
for (std::map<wxString, wxBitmap *>::const_iterator it = presets.begin(); it != presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->first, *it->second, it->first.Left(13)), preset_descriptions[it->first]);
|
||||
validate_selection(it->first == selected);
|
||||
for (auto it = presets.begin(); it != presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->name, *it->bitmap, it->group_name), preset_descriptions[it->name]);
|
||||
validate_selection(it->name == selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
|
||||
bool is_selected_physical_printer();
|
||||
|
||||
// Return true, if physical printer was selected
|
||||
// Return true, if physical printer was selected
|
||||
// and next internal selection was accomplished
|
||||
bool selection_is_changed_according_to_physical_printers();
|
||||
|
||||
|
@ -66,19 +66,25 @@ public:
|
|||
// select preset which is selected in PreseBundle
|
||||
void update_from_bundle();
|
||||
|
||||
// BBS: printer
|
||||
void add_connected_printers(std::string selected, bool alias_name = false);
|
||||
int selected_connected_printer() const;
|
||||
|
||||
// BBS: ams
|
||||
void add_ams_filaments(std::string selected, bool alias_name = false);
|
||||
int selected_ams_filament() const;
|
||||
|
||||
|
||||
void set_filament_idx(const int extr_idx) { m_filament_idx = extr_idx; }
|
||||
int get_filament_idx() const { return m_filament_idx; }
|
||||
|
||||
// BBS
|
||||
wxString get_tooltip(const Preset& preset);
|
||||
|
||||
wxString get_preset_item_name(unsigned int index);
|
||||
|
||||
static wxColor different_color(wxColor const & color);
|
||||
|
||||
virtual wxString get_preset_name(const Preset& preset);
|
||||
virtual wxString get_preset_name(const Preset& preset);
|
||||
Preset::Type get_type() { return m_type; }
|
||||
void show_all(bool show_all);
|
||||
virtual void update();
|
||||
|
@ -122,6 +128,10 @@ protected:
|
|||
int thin_space_icon_width;
|
||||
int wide_space_icon_width;
|
||||
|
||||
// BBS: printer
|
||||
int m_first_printer_idx = 0;
|
||||
int m_last_printer_idx = 0;
|
||||
|
||||
PrinterTechnology printer_technology {ptAny};
|
||||
|
||||
void invalidate_selection();
|
||||
|
@ -134,13 +144,13 @@ protected:
|
|||
#ifdef __linux__
|
||||
static const char* separator_head() { return "------- "; }
|
||||
static const char* separator_tail() { return " -------"; }
|
||||
#else // __linux__
|
||||
#else // __linux__
|
||||
static const char* separator_head() { return "------ "; }
|
||||
static const char* separator_tail() { return " ------"; }
|
||||
#endif // __linux__
|
||||
static wxString separator(const std::string& label);
|
||||
|
||||
wxBitmap* get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name,
|
||||
wxBitmap* get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name,
|
||||
bool is_compatible = true, bool is_system = false, bool is_single_bar = false,
|
||||
const std::string& filament_rgb = "", const std::string& extruder_rgb = "", const std::string& material_rgb = "");
|
||||
|
||||
|
@ -177,6 +187,7 @@ public:
|
|||
void show_add_menu();
|
||||
void show_edit_menu();
|
||||
|
||||
wxString get_preset_group_name(const Preset &preset);
|
||||
wxString get_preset_name(const Preset& preset) override;
|
||||
void update() override;
|
||||
void msw_rescale() override;
|
||||
|
|
Loading…
Reference in New Issue