From 2add733caadff82c794c85954cc767eca1cf55e7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 29 Nov 2018 12:33:04 +0100 Subject: [PATCH] Suppress change preset to SLA if we have multi-part object --- src/slic3r/GUI/GUI_ObjectList.cpp | 13 ++++++ src/slic3r/GUI/GUI_ObjectList.hpp | 1 + src/slic3r/GUI/Tab.cpp | 78 +++++++++++++++++++------------ src/slic3r/GUI/Tab.hpp | 1 + 4 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 23da410e9..3b77e0873 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1536,5 +1536,18 @@ void ObjectList::last_volume_is_deleted(const int obj_idx) volume->config.set_key_value("extruder", new ConfigOptionInt(0)); } +bool ObjectList::has_multi_part_objects() +{ + if (!m_objects_model->IsEmpty()) { + wxDataViewItemArray items; + m_objects_model->GetChildren(wxDataViewItem(0), items); + + for (auto& item : items) + if (m_objects_model->GetItemByType(item, itVolume)) + return true; + } + return false; +} + } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 862e0237b..4a51a5f9f 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -166,6 +166,7 @@ public: void change_part_type(); void last_volume_is_deleted(const int obj_idx); + bool has_multi_part_objects(); }; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 71a6566ba..c71f4dbae 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -28,6 +28,7 @@ #include #include "GUI_App.hpp" +#include "GUI_ObjectList.hpp" namespace Slic3r { namespace GUI { @@ -2368,36 +2369,38 @@ void Tab::select_preset(std::string preset_name) const Preset &new_printer_preset = *m_presets->find_preset(preset_name, true); PrinterTechnology old_printer_technology = m_presets->get_edited_preset().printer_technology(); PrinterTechnology new_printer_technology = new_printer_preset.printer_technology(); - struct PresetUpdate { - Preset::Type tab_type; - PresetCollection *presets; - PrinterTechnology technology; - bool old_preset_dirty; - bool new_preset_compatible; - }; - std::vector updates = { - { Preset::Type::TYPE_PRINT, &m_preset_bundle->prints, ptFFF }, - { Preset::Type::TYPE_SLA_PRINT, &m_preset_bundle->sla_prints, ptSLA }, - { Preset::Type::TYPE_FILAMENT, &m_preset_bundle->filaments, ptFFF }, - { Preset::Type::TYPE_SLA_MATERIAL,&m_preset_bundle->sla_materials, ptSLA } - }; - for (PresetUpdate &pu : updates) { - pu.old_preset_dirty = (old_printer_technology == pu.technology) && pu.presets->current_is_dirty(); - pu.new_preset_compatible = (new_printer_technology == pu.technology) && pu.presets->get_edited_preset().is_compatible_with_printer(new_printer_preset); - if (! canceled) - canceled = pu.old_preset_dirty && ! pu.new_preset_compatible && ! may_discard_current_dirty_preset(pu.presets, preset_name); - } - if (! canceled) { - for (PresetUpdate &pu : updates) { - // The preset will be switched to a different, compatible preset, or the '-- default --'. - if (pu.technology == new_printer_technology) { -// m_reload_dependent_tabs.emplace_back(pu.name); - m_dependent_tabs.emplace_back(pu.tab_type); - } - if (pu.old_preset_dirty) - pu.presets->discard_current_changes(); - } - } + if (new_printer_technology == ptSLA && old_printer_technology == ptFFF && !may_switch_to_SLA_preset()) + canceled = true; + else { + struct PresetUpdate { + Preset::Type tab_type; + PresetCollection *presets; + PrinterTechnology technology; + bool old_preset_dirty; + bool new_preset_compatible; + }; + std::vector updates = { + { Preset::Type::TYPE_PRINT, &m_preset_bundle->prints, ptFFF }, + { Preset::Type::TYPE_SLA_PRINT, &m_preset_bundle->sla_prints, ptSLA }, + { Preset::Type::TYPE_FILAMENT, &m_preset_bundle->filaments, ptFFF }, + { Preset::Type::TYPE_SLA_MATERIAL, &m_preset_bundle->sla_materials,ptSLA } + }; + for (PresetUpdate &pu : updates) { + pu.old_preset_dirty = (old_printer_technology == pu.technology) && pu.presets->current_is_dirty(); + pu.new_preset_compatible = (new_printer_technology == pu.technology) && pu.presets->get_edited_preset().is_compatible_with_printer(new_printer_preset); + if (!canceled) + canceled = pu.old_preset_dirty && !pu.new_preset_compatible && !may_discard_current_dirty_preset(pu.presets, preset_name); + } + if (!canceled) { + for (PresetUpdate &pu : updates) { + // The preset will be switched to a different, compatible preset, or the '-- default --'. + if (pu.technology == new_printer_technology) + m_dependent_tabs.emplace_back(pu.tab_type); + if (pu.old_preset_dirty) + pu.presets->discard_current_changes(); + } + } + } } if (canceled) { update_tab_ui(); @@ -2457,6 +2460,21 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr return confirm->ShowModal() == wxID_YES; } +// If we are switching from the FFF-preset to the SLA, we should to control the printed objects if they have a part(s). +// Because of we can't to print the multi-part objects with SLA technology. +bool Tab::may_switch_to_SLA_preset() +{ + if (wxGetApp().obj_list()->has_multi_part_objects()) + { + show_info( parent(), + _(L("It's impossible to print multi-part object(s) with SLA technology.")) + + _(L("\n\nPlease check your object list before preset changing.")), + _(L("Attention!")) ); + return false; + } + return true; +} + void Tab::OnTreeSelChange(wxTreeEvent& event) { if (m_disable_tree_sel_changed_event) return; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 9b897b6f7..5ed6549bf 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -222,6 +222,7 @@ public: void update_page_tree_visibility(); void select_preset(std::string preset_name = ""); bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = ""); + bool may_switch_to_SLA_preset(); wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn); void load_key_value(const std::string& opt_key, const boost::any& value, bool saved_value = false);