From 475696167884ac80cf554b9dd6bad772facd3e8c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 4 Jun 2019 15:22:29 +0200 Subject: [PATCH] Added LayerRangeEditor class for universally editing of the layer_range's parameters + Implemented layer_height editing --- src/slic3r/GUI/GUI_ObjectLayers.cpp | 91 +++++++++++++++++++---------- src/slic3r/GUI/GUI_ObjectLayers.hpp | 16 +++++ src/slic3r/GUI/GUI_ObjectList.cpp | 8 ++- src/slic3r/GUI/GUI_ObjectList.hpp | 2 +- 4 files changed, 85 insertions(+), 32 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index 1bd57e0d8b..bba39f76a2 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.cpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp @@ -46,44 +46,21 @@ wxSizer* ObjectLayers::create_layer_without_buttons(const t_layer_config_ranges: auto size = wxSize(field_width * em_unit(m_parent), wxDefaultCoord); // Add control for the "Min Z" - wxString text_value = double_to_string(layer.first.first); - auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER); - temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - - temp->Bind(wxEVT_TEXT_ENTER, ([this, temp](wxEvent& e) - { - - }), temp->GetId()); - - temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e) - { - - }), temp->GetId()); - - - temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event) - { - // select all text using Ctrl+A - if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL)) - temp->SetSelection(-1, -1); //select all - event.Skip(); - })); - + auto temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.first), size); m_grid_sizer->Add(temp); // Add control for the "Max Z" - text_value = double_to_string(layer.first.second); - temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER); - temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - + temp = new LayerRangeEditor(m_parent, double_to_string(layer.first.second), size); m_grid_sizer->Add(temp); // Add control for the "Layer height" auto sizer = new wxBoxSizer(wxHORIZONTAL); - text_value = double_to_string(layer.second.option("layer_height")->getFloat()); - temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, wxTE_PROCESS_ENTER); - temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); + 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) { + wxGetApp().obj_list()->edit_layer_range(layer.first, layer_height); + } ); sizer->Add(temp); m_grid_sizer->Add(sizer); @@ -185,5 +162,59 @@ void ObjectLayers::msw_rescale() m_bmp_add.msw_rescale(); } +LayerRangeEditor::LayerRangeEditor( wxWindow* parent, + const wxString& value, + const wxSize& size, + std::function edit_fn + ) : + wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition, size, 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; + }), this->GetId()); + + this->Bind(wxEVT_KILL_FOCUS, ([this, edit_fn](wxEvent& e) + { + e.Skip(); + if (!m_enter_pressed) + edit_fn(get_value()); + m_enter_pressed = false; + }), this->GetId()); + + + this->Bind(wxEVT_CHAR, ([this](wxKeyEvent& event) + { + // select all text using Ctrl+A + if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL)) + this->SetSelection(-1, -1); //select all + event.Skip(); + })); +} + +coordf_t LayerRangeEditor::get_value() +{ + wxString str = GetValue(); + + coordf_t layer_height; + // Replace the first occurence of comma in decimal number. + str.Replace(",", ".", false); + if (str == ".") + layer_height = 0.0; + else + { + if (!str.ToCDouble(&layer_height) || layer_height < 0.0f) + { + show_error(m_parent, _(L("Invalid numeric input."))); + SetValue(double_to_string(layer_height)); + } + } + + return layer_height; +} + } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectLayers.hpp b/src/slic3r/GUI/GUI_ObjectLayers.hpp index 329452950c..3aa3cb967c 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.hpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.hpp @@ -12,6 +12,22 @@ class ModelObject; namespace GUI { class ConfigOptionsGroup; +class LayerRangeEditor : public wxTextCtrl +{ + bool m_enter_pressed { false }; +public: + LayerRangeEditor( wxWindow* parent, + const wxString& value = wxEmptyString, + const wxSize& size = wxDefaultSize, + std::function edit_fn = [](coordf_t) {; } + ); + ~LayerRangeEditor() {} + + +private: + coordf_t get_value(); +}; + class ObjectLayers : public OG_Settings { ScalableBitmap m_bmp_delete; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 9b826f5d8f..25df5c4fbd 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -2312,9 +2312,15 @@ void ObjectList::add_layer_item(const t_layer_height_range& range, m_objects_model->AddLayersChild(layers_item, label, layer_idx); } -void ObjectList::edit_layer_range(const std::pair& range) +void ObjectList::edit_layer_range(const t_layer_height_range& range, coordf_t layer_height) { + const int obj_idx = get_selected_obj_idx(); + if (obj_idx < 0) return; + t_layer_config_ranges& ranges = object(obj_idx)->layer_config_ranges; + + DynamicPrintConfig* config = &ranges[range]; + config->set_key_value("layer_height", new ConfigOptionFloat(layer_height)); } void ObjectList::init_objects() diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 5b4fd4c49b..5e24b96590 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -276,7 +276,7 @@ public: void add_layer_item (const std::pair& range, const wxDataViewItem layers_item, const int layer_idx = -1); - void edit_layer_range(const std::pair& range); + void edit_layer_range(const std::pair& range, coordf_t layer_height); void init_objects(); bool multiple_selection() const ;