From 38641ef5784f8607f6be77e3242970684fed3810 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 31 May 2019 10:54:52 +0200 Subject: [PATCH] ObjectLayers::del_layer_range() -> delete a layers range using "Del" button from ObjectLayers sizer --- src/slic3r/GUI/GUI_ObjectLayers.cpp | 61 ++++++++++++----------------- src/slic3r/GUI/GUI_ObjectLayers.hpp | 2 - src/slic3r/GUI/GUI_ObjectList.cpp | 35 ++++++++++++++++- src/slic3r/GUI/GUI_ObjectList.hpp | 2 + src/slic3r/GUI/wxExtensions.cpp | 25 +++++++++--- src/slic3r/GUI/wxExtensions.hpp | 3 ++ 6 files changed, 84 insertions(+), 44 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index 191a65386..5ff650e86 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.cpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp @@ -16,8 +16,6 @@ namespace Slic3r namespace GUI { -typedef std::map t_layer_height_ranges; - #define field_width 8 ObjectLayers::ObjectLayers(wxWindow* parent) : @@ -76,42 +74,32 @@ static Line create_new_layer(const t_layer_height_ranges::value_type& layer) void ObjectLayers::create_layers_list() { - auto create_btns = [this](wxWindow* parent) { - auto sizer = new wxBoxSizer(wxHORIZONTAL); - - auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete); - del_btn->SetToolTip(_(L("Remove layer"))); - - sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent)); - - del_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) { - del_layer(); -// wxTheApp->CallAfter([this]() { -// wxWindowUpdateLocker noUpdates(m_parent); -// update_layers_list(); -// m_parent->Layout(); -// }); - }); - - auto add_btn = new ScalableButton(parent, wxID_ANY, m_bmp_add); - add_btn->SetToolTip(_(L("Add layer"))); - - sizer->Add(add_btn, 0, wxRIGHT, em_unit(parent)); - - add_btn->Bind(wxEVT_BUTTON, [this](wxEvent &event) { - add_layer(); -// wxTheApp->CallAfter([this]() { -// wxWindowUpdateLocker noUpdates(m_parent); -// update_layers_list(); -// m_parent->Layout(); -// }); - }); - - return sizer; - }; - for (const auto layer : m_object->layer_height_ranges) { + auto create_btns = [this, layer](wxWindow* parent) { + auto sizer = new wxBoxSizer(wxHORIZONTAL); + + auto del_btn = new ScalableButton(parent, wxID_ANY, m_bmp_delete); + del_btn->SetToolTip(_(L("Remove layer"))); + + sizer->Add(del_btn, 0, wxRIGHT, em_unit(parent)); + + del_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) { + wxGetApp().obj_list()->del_layer_range(layer.first); + }); + + auto add_btn = new ScalableButton(parent, wxID_ANY, m_bmp_add); + add_btn->SetToolTip(_(L("Add layer"))); + + sizer->Add(add_btn, 0, wxRIGHT, em_unit(parent)); + + add_btn->Bind(wxEVT_BUTTON, [this, layer](wxEvent &event) { + wxGetApp().obj_list()->add_layer_range(layer.first); + }); + + return sizer; + }; + Line line = create_new_layer(layer); line.append_widget(create_btns); m_og->append_line(line); @@ -122,6 +110,7 @@ void ObjectLayers::create_layer(int id) { t_layer_height_ranges::iterator layer_range = m_object->layer_height_ranges.begin(); + // May be not a best solution #ys_FIXME while (id > 0 && layer_range != m_object->layer_height_ranges.end()) { layer_range++; id--; diff --git a/src/slic3r/GUI/GUI_ObjectLayers.hpp b/src/slic3r/GUI/GUI_ObjectLayers.hpp index b9e9efb14..0b209d523 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.hpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.hpp @@ -27,8 +27,6 @@ public: void create_layers_list(); void create_layer(int id); void update_layers_list(); - void add_layer() {}; - void del_layer() {}; void UpdateAndShow(const bool show) override; void msw_rescale(); diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 8043ee565..cb815fc72 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1812,7 +1812,7 @@ void ObjectList::layers_editing() wxDataViewItem obj_item = m_objects_model->GetTopParent(item); - wxDataViewItem layers_item = m_objects_model->GetItemByType(obj_item, itLayerRoot); + wxDataViewItem layers_item = m_objects_model->GetLayerRootItem(obj_item); if (!layers_item.IsOk()) { // --->>>--- Just for testing @@ -2202,6 +2202,39 @@ void ObjectList::remove() } } +void ObjectList::del_layer_range(const std::pair& range) +{ + const int obj_idx = get_selected_obj_idx(); + if (obj_idx < 0) return; + + t_layer_height_ranges& ranges = object(obj_idx)->layer_height_ranges; + + wxDataViewItem selectable_item = GetSelection(); + int layer_idx = 0; + + if (ranges.size() == 1) + selectable_item = m_objects_model->GetParent(selectable_item); + else { + // May be not a best solution #ys_FIXME + t_layer_height_ranges::iterator layer_selected = ranges.find(range); + t_layer_height_ranges::iterator it = ranges.begin(); + while (it != layer_selected) { + it++; + layer_idx++; + } + } + + wxDataViewItem layer_item = m_objects_model->GetItemByLayerId(obj_idx, layer_idx); + del_subobject_item(layer_item); + + select_item(selectable_item); +} + +void ObjectList::add_layer_range(const std::pair& range) +{ + +} + void ObjectList::init_objects() { m_objects = wxGetApp().model_objects(); diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 6963805e9..388369137 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -270,6 +270,8 @@ public: // Remove objects/sub-object from the list void remove(); + void del_layer_range(const std::pair& range); + void add_layer_range(const std::pair& range); void init_objects(); bool multiple_selection() const ; diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 4511ab8ac..dbe19dff5 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1098,25 +1098,35 @@ wxDataViewItem ObjectDataViewModel::GetItemByVolumeId(int obj_idx, int volume_id return wxDataViewItem(0); } -wxDataViewItem ObjectDataViewModel::GetItemByInstanceId(int obj_idx, int inst_idx) +wxDataViewItem ObjectDataViewModel::GetItemById(const int obj_idx, const int sub_obj_idx, const ItemType parent_type) { if (obj_idx >= m_objects.size() || obj_idx < 0) { printf("Error! Out of objects range.\n"); return wxDataViewItem(0); } - auto instances_item = GetInstanceRootItem(wxDataViewItem(m_objects[obj_idx])); - if (!instances_item) + auto item = GetItemByType(wxDataViewItem(m_objects[obj_idx]), parent_type); + if (!item) return wxDataViewItem(0); - auto parent = (ObjectDataViewModelNode*)instances_item.GetID();; + auto parent = (ObjectDataViewModelNode*)item.GetID();; for (size_t i = 0; i < parent->GetChildCount(); i++) - if (parent->GetNthChild(i)->m_idx == inst_idx) + if (parent->GetNthChild(i)->m_idx == sub_obj_idx) return wxDataViewItem(parent->GetNthChild(i)); return wxDataViewItem(0); } +wxDataViewItem ObjectDataViewModel::GetItemByInstanceId(int obj_idx, int inst_idx) +{ + return GetItemById(obj_idx, inst_idx, itInstanceRoot); +} + +wxDataViewItem ObjectDataViewModel::GetItemByLayerId(int obj_idx, int layer_idx) +{ + return GetItemById(obj_idx, layer_idx, itLayerRoot); +} + int ObjectDataViewModel::GetIdByItem(const wxDataViewItem& item) const { wxASSERT(item.IsOk()); @@ -1447,6 +1457,11 @@ wxDataViewItem ObjectDataViewModel::GetInstanceRootItem(const wxDataViewItem &it return GetItemByType(item, itInstanceRoot); } +wxDataViewItem ObjectDataViewModel::GetLayerRootItem(const wxDataViewItem &item) const +{ + return GetItemByType(item, itLayerRoot); +} + bool ObjectDataViewModel::IsSettingsItem(const wxDataViewItem &item) const { if (!item.IsOk()) diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index b3d8ebc18..23150a915 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -404,8 +404,10 @@ public: void DeleteVolumeChildren(wxDataViewItem& parent); void DeleteSettings(const wxDataViewItem& parent); wxDataViewItem GetItemById(int obj_idx); + wxDataViewItem GetItemById(const int obj_idx, const int sub_obj_idx, const ItemType parent_type); wxDataViewItem GetItemByVolumeId(int obj_idx, int volume_idx); wxDataViewItem GetItemByInstanceId(int obj_idx, int inst_idx); + wxDataViewItem GetItemByLayerId(int obj_idx, int layer_idx); int GetIdByItem(const wxDataViewItem& item) const; int GetIdByItemAndType(const wxDataViewItem& item, const ItemType type) const; int GetObjectIdByItem(const wxDataViewItem& item) const; @@ -460,6 +462,7 @@ public: ItemType type) const; wxDataViewItem GetSettingsItem(const wxDataViewItem &item) const; wxDataViewItem GetInstanceRootItem(const wxDataViewItem &item) const; + wxDataViewItem GetLayerRootItem(const wxDataViewItem &item) const; bool IsSettingsItem(const wxDataViewItem &item) const; void UpdateSettingsDigest( const wxDataViewItem &item, const std::vector& categories);