From 213635f5596193008a96e1f910b8e2da507e9f9d Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 4 Jun 2019 17:30:44 +0200 Subject: [PATCH] Implemented range's min/max Z editing --- src/slic3r/GUI/GUI_ObjectLayers.cpp | 46 +++++++++++++++++------------ src/slic3r/GUI/GUI_ObjectLayers.hpp | 4 +-- src/slic3r/GUI/GUI_ObjectList.cpp | 28 ++++++++++++++++++ src/slic3r/GUI/GUI_ObjectList.hpp | 2 ++ 4 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index bba39f76a..de1c95fc9 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.cpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp @@ -43,26 +43,31 @@ ObjectLayers::ObjectLayers(wxWindow* parent) : wxSizer* ObjectLayers::create_layer_without_buttons(const t_layer_config_ranges::value_type& layer) { - auto size = wxSize(field_width * em_unit(m_parent), wxDefaultCoord); - // Add control for the "Min Z" - auto temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.first), size); + auto temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.first), + [layer](coordf_t min_z) { + wxGetApp().obj_list()->edit_layer_range(layer.first, { min_z, layer.first.second }); + }); + m_grid_sizer->Add(temp); // Add control for the "Max Z" - temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.second), size); + temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.second), + [layer](coordf_t max_z) { + wxGetApp().obj_list()->edit_layer_range(layer.first, { layer.first.first, max_z }); + }); + m_grid_sizer->Add(temp); // Add control for the "Layer height" - auto sizer = new wxBoxSizer(wxHORIZONTAL); - - const wxString text_value = double_to_string(layer.second.option("layer_height")->getFloat()); - - temp = new LayerRangeEditor(m_parent, text_value, size, [temp, layer](coordf_t layer_height) { + temp = new LayerRangeEditor(m_parent, + double_to_string(layer.second.option("layer_height")->getFloat()), + [layer](coordf_t layer_height) { wxGetApp().obj_list()->edit_layer_range(layer.first, layer_height); - } ); - sizer->Add(temp); + }, false ); + auto sizer = new wxBoxSizer(wxHORIZONTAL); + sizer->Add(temp); m_grid_sizer->Add(sizer); return sizer; @@ -164,25 +169,28 @@ void ObjectLayers::msw_rescale() LayerRangeEditor::LayerRangeEditor( wxWindow* parent, const wxString& value, - const wxSize& size, - std::function edit_fn + std::function edit_fn, + const bool deletable_after_change ) : - wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition, size, wxTE_PROCESS_ENTER) + wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition, + wxSize(field_width * em_unit(parent), wxDefaultCoord), wxTE_PROCESS_ENTER) { this->SetFont(wxGetApp().normal_font()); this->Bind(wxEVT_TEXT_ENTER, ([this, edit_fn](wxEvent& e) { - edit_fn(get_value()); m_enter_pressed = true; + edit_fn(get_value()); }), this->GetId()); - this->Bind(wxEVT_KILL_FOCUS, ([this, edit_fn](wxEvent& e) + this->Bind(wxEVT_KILL_FOCUS, ([this, edit_fn, deletable_after_change](wxEvent& e) { - e.Skip(); - if (!m_enter_pressed) + if (!deletable_after_change) + e.Skip(); + if (!m_enter_pressed) { + m_enter_pressed = false; edit_fn(get_value()); - m_enter_pressed = false; + } }), this->GetId()); diff --git a/src/slic3r/GUI/GUI_ObjectLayers.hpp b/src/slic3r/GUI/GUI_ObjectLayers.hpp index 3aa3cb967..f34dd1314 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.hpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.hpp @@ -18,8 +18,8 @@ class LayerRangeEditor : public wxTextCtrl public: LayerRangeEditor( wxWindow* parent, const wxString& value = wxEmptyString, - const wxSize& size = wxDefaultSize, - std::function edit_fn = [](coordf_t) {; } + std::function edit_fn = [](coordf_t) {}, + const bool deletable_after_change = true ); ~LayerRangeEditor() {} diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 25df5c4fb..96d071d54 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -2265,6 +2265,9 @@ void ObjectList::add_layer_range(const t_layer_height_range& range) ++it; } + if (selected_range->first.second > next_range->first.first) + return; // range devision has no mean + if (selected_range->first.second == next_range->first.first) { const coordf_t delta = (next_range->first.second - next_range->first.first); @@ -2323,6 +2326,31 @@ void ObjectList::edit_layer_range(const t_layer_height_range& range, coordf_t la config->set_key_value("layer_height", new ConfigOptionFloat(layer_height)); } +void ObjectList::edit_layer_range(const t_layer_height_range& range, const t_layer_height_range& new_range) +{ + const int obj_idx = get_selected_obj_idx(); + if (obj_idx < 0) return; + + t_layer_config_ranges& ranges = object(obj_idx)->layer_config_ranges; + + const DynamicPrintConfig config = ranges[range]; + + ranges.erase(range); + ranges[new_range] = config; + + wxDataViewItem root_item = m_objects_model->GetLayerRootItem(m_objects_model->GetItemById(obj_idx)); + m_objects_model->DeleteChildren(root_item); + + if (root_item.IsOk()) + // create Layer item(s) according to the layer_config_ranges + for (const auto r : ranges) + add_layer_item(r.first, root_item); + + // To update(recreate) layers sizer call select_item for LayerRoot item expand + select_item(root_item); + Expand(root_item); +} + 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 5e24b9659..c970a23a0 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -277,6 +277,8 @@ public: const wxDataViewItem layers_item, const int layer_idx = -1); void edit_layer_range(const std::pair& range, coordf_t layer_height); + void edit_layer_range(const std::pair& range, + const std::pair& new_range); void init_objects(); bool multiple_selection() const ;