diff options
author | YuSanka <yusanka@gmail.com> | 2019-06-04 16:22:29 +0300 |
---|---|---|
committer | YuSanka <yusanka@gmail.com> | 2019-06-04 16:22:29 +0300 |
commit | 475696167884ac80cf554b9dd6bad772facd3e8c (patch) | |
tree | 1ccbb66163c6cb5fcd2017e85e50780e9c833d04 /src/slic3r/GUI/GUI_ObjectLayers.cpp | |
parent | 79a89c4c8fd5b09374ba981fea7c3a3da6711236 (diff) |
Added LayerRangeEditor class for universally editing of the layer_range's parameters
+ Implemented layer_height editing
Diffstat (limited to 'src/slic3r/GUI/GUI_ObjectLayers.cpp')
-rw-r--r-- | src/slic3r/GUI/GUI_ObjectLayers.cpp | 91 |
1 files changed, 61 insertions, 30 deletions
diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index 1bd57e0d8..bba39f76a 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<void(coordf_t)> 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 |