mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-01-28 20:01:16 -07:00
ENH: add connected to printer preset list
and add group name jira:none Change-Id: Iecc4ec38ff071105f856c2034ceac0d5bde3b7b0 (cherry picked from commit c44cc2db1a4b27955e0099b06f2508faf824b538)
This commit is contained in:
parent
7b81f21093
commit
6afd3a961b
4 changed files with 155 additions and 48 deletions
|
|
@ -2228,6 +2228,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()
|
||||
|
|
@ -4929,33 +4931,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")) {
|
||||
|
|
@ -7201,8 +7177,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);
|
||||
|
|
@ -12486,6 +12466,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;
|
||||
}
|
||||
|
||||
// Following lambda generates a combined mesh for export with normals pointing outwards.
|
||||
TriangleMesh Plater::combine_mesh_fff(const ModelObject& mo, int instance_id, std::function<void(const std::string&)> notify_func)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -861,6 +861,8 @@ private:
|
|||
};
|
||||
|
||||
std::vector<int> get_min_flush_volumes(const DynamicPrintConfig &full_config, size_t nozzle_id);
|
||||
|
||||
Preset *get_printer_preset(MachineObject *obj);
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
|
|
|
|||
|
|
@ -305,6 +305,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)*/);
|
||||
|
|
@ -394,6 +426,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->is_bbl_vendor();
|
||||
|
|
@ -937,6 +995,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));
|
||||
|
|
@ -984,10 +1054,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;
|
||||
|
||||
//BBS: move system to the end
|
||||
|
|
@ -1013,6 +1092,11 @@ void PlaterPresetComboBox::update()
|
|||
continue;
|
||||
|
||||
bool single_bar = false;
|
||||
|
||||
wxString group_name;
|
||||
if (m_type == Preset::TYPE_PRINTER)
|
||||
group_name = get_preset_group_name(preset);
|
||||
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
{
|
||||
#if 0
|
||||
|
|
@ -1034,7 +1118,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;
|
||||
|
|
@ -1048,7 +1132,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());
|
||||
|
|
@ -1056,7 +1140,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
|
||||
|
|
@ -1067,6 +1151,9 @@ 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 && m_preset_bundle->is_bbl_vendor())
|
||||
add_ams_filaments(into_u8(selected_user_preset), true);
|
||||
|
||||
|
|
@ -1074,26 +1161,26 @@ void PlaterPresetComboBox::update()
|
|||
if (!project_embedded_presets.empty())
|
||||
{
|
||||
set_label_marker(Append(separator(L("Project-inside presets")), wxNullBitmap));
|
||||
for (std::map<wxString, wxBitmap*>::iterator it = project_embedded_presets.begin(); it != project_embedded_presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]);
|
||||
validate_selection(it->first == selected_user_preset);
|
||||
for (auto it = project_embedded_presets.begin(); it != project_embedded_presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->name, *it->bitmap), preset_descriptions[it->name]);
|
||||
validate_selection(it->name == selected_user_preset);
|
||||
}
|
||||
}
|
||||
if (!nonsys_presets.empty())
|
||||
{
|
||||
set_label_marker(Append(separator(L("User presets")), wxNullBitmap));
|
||||
for (std::map<wxString, wxBitmap*>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]);
|
||||
validate_selection(it->first == selected_user_preset);
|
||||
for (auto it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->name, *it->bitmap), preset_descriptions[it->name]);
|
||||
validate_selection(it->name == selected_user_preset);
|
||||
}
|
||||
}
|
||||
//BBS: move system to the end
|
||||
if (!system_presets.empty())
|
||||
{
|
||||
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
||||
for (std::map<wxString, wxBitmap*>::iterator it = system_presets.begin(); it != system_presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]);
|
||||
validate_selection(it->first == selected_system_preset);
|
||||
for (auto it = system_presets.begin(); it != system_presets.end(); ++it) {
|
||||
SetItemTooltip(Append(it->name, *it->bitmap), preset_descriptions[it->name]);
|
||||
validate_selection(it->name == selected_system_preset);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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…
Add table
Add a link
Reference in a new issue