From 1f02eb704ae2e7df51622c39fd0af60f0fd75114 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 22 Apr 2019 01:51:10 +0200 Subject: [PATCH] Code refactoring: Deleted unused variables and _cleaned_ overbusy functions --- src/slic3r/GUI/GUI_ObjectList.cpp | 41 ++++++-------------- src/slic3r/GUI/GUI_ObjectList.hpp | 9 ++--- src/slic3r/GUI/GUI_ObjectSettings.cpp | 4 +- src/slic3r/GUI/Plater.cpp | 55 ++++++++++----------------- src/slic3r/GUI/Tab.cpp | 2 + 5 files changed, 39 insertions(+), 72 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index f8ad8b7bb..fe8b13fb7 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -463,8 +463,7 @@ void ObjectList::paste_volumes_into_list(int obj_idx, const ModelVolumePtrs& vol items.Add(vol_item); } - m_parts_changed = true; - parts_changed(obj_idx); + changed_object(obj_idx); if (items.size() > 1) { @@ -490,9 +489,7 @@ void ObjectList::paste_objects_into_list(const std::vector& object_idxs) items.Add(m_objects_model->GetItemById(object)); } - m_parts_changed = true; wxGetApp().plater()->changed_objects(object_idxs); - m_parts_changed = false; select_items(items); #ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME @@ -703,8 +700,7 @@ void ObjectList::OnDrop(wxDataViewEvent &event) select_item(m_objects_model->ReorganizeChildren(from_volume_id, to_volume_id, m_objects_model->GetParent(item))); - m_parts_changed = true; - parts_changed(m_dragged_data.obj_idx()); + changed_object(m_dragged_data.obj_idx()); m_dragged_data.clear(); } @@ -1290,7 +1286,7 @@ void ObjectList::load_subobject(ModelVolumeType type) wxArrayString part_names; load_part((*m_objects)[obj_idx], part_names, type); - parts_changed(obj_idx); + changed_object(obj_idx); for (int i = 0; i < part_names.size(); ++i) { const wxDataViewItem sel_item = m_objects_model->AddVolumeChild(item, part_names.Item(i), type); @@ -1306,7 +1302,6 @@ void ObjectList::load_part( ModelObject* model_object, { wxWindow* parent = wxGetApp().tab_panel()->GetPage(0); - m_parts_changed = false; wxArrayString input_files; wxGetApp().import_model(parent, input_files); for (int i = 0; i < input_files.size(); ++i) { @@ -1342,8 +1337,6 @@ void ObjectList::load_part( ModelObject* model_object, // set a default extruder value, since user can't add it manually new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); - - m_parts_changed = true; } } } @@ -1493,8 +1486,7 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode // set a default extruder value, since user can't add it manually new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); - m_parts_changed = true; - parts_changed(obj_idx); + changed_object(obj_idx); const auto object_item = m_objects_model->GetTopParent(GetSelection()); select_item(m_objects_model->AddVolumeChild(object_item, name, type)); @@ -1558,8 +1550,7 @@ void ObjectList::del_instances_from_object(const int obj_idx) (*m_objects)[obj_idx]->invalidate_bounding_box(); // ? #ys_FIXME - m_parts_changed = true; - parts_changed(obj_idx); + changed_object(obj_idx); } bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, const int type) @@ -1604,8 +1595,7 @@ bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, con else return false; - m_parts_changed = true; - parts_changed(obj_idx); + changed_object(obj_idx); return true; } @@ -1655,8 +1645,7 @@ void ObjectList::split() if (parent == item) Expand(parent); - m_parts_changed = true; - parts_changed(obj_idx); + changed_object(obj_idx); } bool ObjectList::get_volume_by_item(const wxDataViewItem& item, ModelVolume*& volume) @@ -1713,17 +1702,10 @@ bool ObjectList::can_split_instances() return selection.is_multiple_full_instance() || selection.is_single_full_instance(); } -void ObjectList::part_settings_changed() +// NO_PARAMETERS function call means that changed object index will be determine from Selection() +void ObjectList::changed_object(const int obj_idx/* = -1*/) const { - m_part_settings_changed = true; - wxGetApp().plater()->changed_object(get_selected_obj_idx()); - m_part_settings_changed = false; -} - -void ObjectList::parts_changed(int obj_idx) -{ - wxGetApp().plater()->changed_object(obj_idx); - m_parts_changed = false; + wxGetApp().plater()->changed_object(obj_idx < 0 ? get_selected_obj_idx() : obj_idx); } void ObjectList::part_selection_changed() @@ -2446,8 +2428,7 @@ void ObjectList::change_part_type() volume->set_type(new_type); m_objects_model->SetVolumeType(item, new_type); - m_parts_changed = true; - parts_changed(get_selected_obj_idx()); + changed_object(get_selected_obj_idx()); // Update settings showing, if we have it //(we show additional settings for Part and Modifier and hide it for Support Blocker/Enforcer) diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index a0343100a..7b3b2c744 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -139,8 +139,8 @@ class ObjectList : public wxDataViewCtrl // update_settings_items - updating canvas selection is undesirable, // because it would turn off the gizmos (mainly a problem for the SLA gizmo) - bool m_parts_changed = false; - bool m_part_settings_changed = false; +// bool m_parts_changed = false; +// bool m_part_settings_changed = false; int m_selected_row = 0; wxDataViewItem m_last_selected_item {nullptr}; @@ -225,11 +225,8 @@ public: wxBoxSizer* get_sizer() {return m_sizer;} int get_selected_obj_idx() const; DynamicPrintConfig& get_item_config(const wxDataViewItem& item) const; - bool is_parts_changed() const { return m_parts_changed; } - bool is_part_settings_changed() const { return m_part_settings_changed; } - void part_settings_changed(); - void parts_changed(int obj_idx); + void changed_object(const int obj_idx = -1) const; void part_selection_changed(); // Add object to the list diff --git a/src/slic3r/GUI/GUI_ObjectSettings.cpp b/src/slic3r/GUI/GUI_ObjectSettings.cpp index 72eeb76de..1c5ca5a32 100644 --- a/src/slic3r/GUI/GUI_ObjectSettings.cpp +++ b/src/slic3r/GUI/GUI_ObjectSettings.cpp @@ -84,7 +84,7 @@ void ObjectSettings::update_settings_list() #endif // __WXMSW__ btn->Bind(wxEVT_BUTTON, [opt_key, config, this](wxEvent &event) { config->erase(opt_key); - wxGetApp().obj_list()->part_settings_changed(); + wxGetApp().obj_list()->changed_object(); wxTheApp->CallAfter([this]() { wxWindowUpdateLocker noUpdates(m_parent); update_settings_list(); @@ -127,7 +127,7 @@ void ObjectSettings::update_settings_list() optgroup->sidetext_width = 5.5 * wxGetApp().em_unit(); optgroup->m_on_change = [](const t_config_option_key& opt_id, const boost::any& value) { - wxGetApp().obj_list()->part_settings_changed(); }; + wxGetApp().obj_list()->changed_object(); }; for (auto& opt : cat.second) { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index f908dca92..5bba6ce72 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -3709,22 +3709,16 @@ void Plater::changed_object(int obj_idx) { if (obj_idx < 0) return; - auto list = wxGetApp().obj_list(); - wxASSERT(list != nullptr); - if (list == nullptr) - return; - - if (list->is_parts_changed()) { - // recenter and re - align to Z = 0 - auto model_object = p->model.objects[obj_idx]; - model_object->ensure_on_bed(); - if (this->p->printer_technology == ptSLA) { - // Update the SLAPrint from the current Model, so that the reload_scene() - // pulls the correct data, update the 3D scene. - this->p->update_restart_background_process(true, false); - } else - p->view3D->reload_scene(false); + // recenter and re - align to Z = 0 + auto model_object = p->model.objects[obj_idx]; + model_object->ensure_on_bed(); + if (this->p->printer_technology == ptSLA) { + // Update the SLAPrint from the current Model, so that the reload_scene() + // pulls the correct data, update the 3D scene. + this->p->update_restart_background_process(true, false); } + else + p->view3D->reload_scene(false); // update print this->p->schedule_background_process(); @@ -3735,26 +3729,19 @@ void Plater::changed_objects(const std::vector& object_idxs) if (object_idxs.empty()) return; - auto list = wxGetApp().obj_list(); - wxASSERT(list != nullptr); - if (list == nullptr) - return; - - if (list->is_parts_changed()) { - for (int obj_idx : object_idxs) - { - if (obj_idx < p->model.objects.size()) - // recenter and re - align to Z = 0 - p->model.objects[obj_idx]->ensure_on_bed(); - } - if (this->p->printer_technology == ptSLA) { - // Update the SLAPrint from the current Model, so that the reload_scene() - // pulls the correct data, update the 3D scene. - this->p->update_restart_background_process(true, false); - } - else - p->view3D->reload_scene(false); + for (int obj_idx : object_idxs) + { + if (obj_idx < p->model.objects.size()) + // recenter and re - align to Z = 0 + p->model.objects[obj_idx]->ensure_on_bed(); } + if (this->p->printer_technology == ptSLA) { + // Update the SLAPrint from the current Model, so that the reload_scene() + // pulls the correct data, update the 3D scene. + this->p->update_restart_background_process(true, false); + } + else + p->view3D->reload_scene(false); // update print this->p->schedule_background_process(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index a73105c1d..d1347d9e5 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1755,6 +1755,8 @@ void TabPrinter::build_fff() auto *nozzle_diameter = dynamic_cast(m_config->option("nozzle_diameter")); m_initial_extruders_count = m_extruders_count = nozzle_diameter->values.size(); + wxGetApp().sidebar().update_objects_list_extruder_column(m_initial_extruders_count); + const Preset* parent_preset = m_presets->get_selected_preset_parent(); m_sys_extruders_count = parent_preset == nullptr ? 0 : static_cast(parent_preset->config.option("nozzle_diameter"))->values.size();