From 62aa34b4440f3ecdf560adc46b9470cbfe3f152f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 14 Nov 2018 12:33:48 +0100 Subject: [PATCH] SpinCtrsl inside Manipulation pane is replaced to TextCtrls + Added "proces_enter" mode for TextCtrl (The control will generate the event wxEVT_TEXT_ENTER) --- src/slic3r/GUI/Field.cpp | 49 ++++++------ src/slic3r/GUI/Field.hpp | 8 +- src/slic3r/GUI/GLCanvas3D.cpp | 4 +- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 91 ++++++++++------------- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 2 - src/slic3r/GUI/OptionsGroup.cpp | 2 +- src/slic3r/GUI/OptionsGroup.hpp | 11 ++- 7 files changed, 87 insertions(+), 80 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 94b7f2b5d..68d3948bb 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -11,22 +11,21 @@ namespace Slic3r { namespace GUI { -wxString double_to_string(double const value) +wxString double_to_string(double const value, const int max_precision /*= 4*/) { if (value - int(value) == 0) return wxString::Format(_T("%i"), int(value)); - else { - int precision = 4; - for (size_t p = 1; p < 4; p++) - { - double cur_val = pow(10, p)*value; - if (cur_val - int(cur_val) == 0) { - precision = p; - break; - } + + int precision = max_precision; + for (size_t p = 1; p < max_precision; p++) + { + double cur_val = pow(10, p)*value; + if (cur_val - int(cur_val) == 0) { + precision = p; + break; } - return wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None); } + return wxNumberFormatter::ToString(value, precision, wxNumberFormatter::Style_None); } void Field::PostInitialize() @@ -209,7 +208,8 @@ void TextCtrl::BUILD() { break; } - auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, (m_opt.multiline ? wxTE_MULTILINE : 0)); + const long style = m_opt.multiline ? wxTE_MULTILINE : 0 | m_process_enter ? wxTE_PROCESS_ENTER : 0; + auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style); temp->SetToolTip(get_tooltip_text(text_value)); @@ -234,21 +234,26 @@ void TextCtrl::BUILD() { }), temp->GetId()); #endif // __WXGTK__ - temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) - { + if (m_process_enter) { + temp->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent& evt) { on_change_field(); }), temp->GetId()); + } + else { + temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt) + { #ifdef __WXGTK__ - if (bChangedValueEvent) + if (bChangedValueEvent) #endif //__WXGTK__ - on_change_field(); - }), temp->GetId()); + on_change_field(); + }), temp->GetId()); #ifdef __WXGTK__ - // to correct value updating on GTK we should: - // call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT - // and prevent value updating on wxEVT_KEY_DOWN - temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this); - temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); + // to correct value updating on GTK we should: + // call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT + // and prevent value updating on wxEVT_KEY_DOWN + temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this); + temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this); #endif //__WXGTK__ + } // select all text using Ctrl+A temp->Bind(wxEVT_CHAR, ([temp](wxKeyEvent& event) diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 58c6afebe..29ae6f9ce 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -34,7 +34,7 @@ using t_kill_focus = std::function; using t_change = std::function; using t_back_to_init = std::function; -wxString double_to_string(double const value); +wxString double_to_string(double const value, const int max_precision = 4); class MyButton : public wxButton { @@ -139,9 +139,10 @@ public: /// Factory method for generating new derived classes. template - static t_field Create(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) // interface for creating shared objects + static t_field Create(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id, const bool process_enter = false)// interface for creating shared objects { auto p = Slic3r::make_unique(parent, opt, id); + p->m_process_enter = process_enter; p->PostInitialize(); return std::move(p); //!p; } @@ -221,6 +222,9 @@ protected: // current value boost::any m_value; + + //this variable shows a mode of a call of the on_change function + bool m_process_enter { false }; friend class OptionsGroup; }; diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 24401f7ef..4220625c6 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1464,7 +1464,9 @@ void GLCanvas3D::Selection::translate(const Vec3d& displacement) } #if !DISABLE_INSTANCES_SYNCH - if (m_mode == Volume) + if (m_mode == Instance) + _synchronize_unselected_instances(); + else if (m_mode == Volume) _synchronize_unselected_volumes(); #endif // !DISABLE_INSTANCES_SYNCH diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 5993eb1e1..8484faae0 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -20,7 +20,8 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): m_og->set_name(_(L("Object Manipulation"))); m_og->label_width = 100; m_og->set_grid_vgap(5); - + m_og->set_process_enter(); // We need to update new values only after press ENTER + m_og->m_on_change = [this](t_config_option_key opt_key, boost::any value) { if (opt_key == "scale_unit") { const wxString& selection = boost::any_cast(value); @@ -32,6 +33,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): m_is_percent_scale = selection == _("%"); update_scale_values(); + return; } }; @@ -64,7 +66,6 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): auto add_og_to_object_settings = [](const std::string& option_name, const std::string& sidetext) { - int def_value = 0; Line line = { _(option_name), "" }; if (option_name == "Scale") { line.near_label_widget = [](wxWindow* parent) { @@ -80,14 +81,12 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): } ConfigOptionDef def; - def.type = coInt; - def.default_value = new ConfigOptionInt(def_value); + def.type = coFloat; + def.default_value = new ConfigOptionFloat(0.0); def.width = 55; if (option_name == "Rotation") def.min = -360; - else - def.min = -1000; const std::string lower_name = boost::algorithm::to_lower_copy(option_name); @@ -243,40 +242,40 @@ void ObjectManipulation::reset_settings_value() void ObjectManipulation::reset_position_value() { - m_og->set_value("position_x", 0); - m_og->set_value("position_y", 0); - m_og->set_value("position_z", 0); + m_og->set_value("position_x", "0"); + m_og->set_value("position_y", "0"); + m_og->set_value("position_z", "0"); } void ObjectManipulation::reset_rotation_value() { - m_og->set_value("rotation_x", 0); - m_og->set_value("rotation_y", 0); - m_og->set_value("rotation_z", 0); + m_og->set_value("rotation_x", "0"); + m_og->set_value("rotation_y", "0"); + m_og->set_value("rotation_z", "0"); } void ObjectManipulation::reset_scale_value() { m_is_percent_scale = true; m_og->set_value("scale_unit", _("%")); - m_og->set_value("scale_x", 100); - m_og->set_value("scale_y", 100); - m_og->set_value("scale_z", 100); + m_og->set_value("scale_x", "100"); + m_og->set_value("scale_y", "100"); + m_og->set_value("scale_z", "100"); } void ObjectManipulation::update_values() { int selection = ol_selection(); if (selection < 0 || wxGetApp().mainframe->m_plater->model().objects.size() <= selection) { - m_og->set_value("position_x", 0); - m_og->set_value("position_y", 0); - m_og->set_value("position_z", 0); - m_og->set_value("scale_x", 0); - m_og->set_value("scale_y", 0); - m_og->set_value("scale_z", 0); - m_og->set_value("rotation_x", 0); - m_og->set_value("rotation_y", 0); - m_og->set_value("rotation_z", 0); + m_og->set_value("position_x", "0"); + m_og->set_value("position_y", "0"); + m_og->set_value("position_z", "0"); + m_og->set_value("scale_x", "0"); + m_og->set_value("scale_y", "0"); + m_og->set_value("scale_z", "0"); + m_og->set_value("rotation_x", "0"); + m_og->set_value("rotation_y", "0"); + m_og->set_value("rotation_z", "0"); m_og->disable(); return; } @@ -297,14 +296,14 @@ void ObjectManipulation::update_scale_values() auto size = objects[selection]->instance_bounding_box(0).size(); if (m_is_percent_scale) { - m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * 100)); - m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * 100)); - m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * 100)); + m_og->set_value("scale_x", double_to_string(instance->get_scaling_factor(X) * 100, 2)); + m_og->set_value("scale_y", double_to_string(instance->get_scaling_factor(Y) * 100, 2)); + m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * 100, 2)); } else { - m_og->set_value("scale_x", int(instance->get_scaling_factor(X) * size(0) + 0.5)); - m_og->set_value("scale_y", int(instance->get_scaling_factor(Y) * size(1) + 0.5)); - m_og->set_value("scale_z", int(instance->get_scaling_factor(Z) * size(2) + 0.5)); + m_og->set_value("scale_x", double_to_string(instance->get_scaling_factor(X) * size(0) + 0.5, 2)); + m_og->set_value("scale_y", double_to_string(instance->get_scaling_factor(Y) * size(1) + 0.5, 2)); + m_og->set_value("scale_z", double_to_string(instance->get_scaling_factor(Z) * size(2) + 0.5, 2)); } } @@ -312,16 +311,16 @@ void ObjectManipulation::update_position_values() { auto instance = wxGetApp().mainframe->m_plater->model().objects[ol_selection()]->instances.front(); - m_og->set_value("position_x", int(instance->get_offset(X))); - m_og->set_value("position_y", int(instance->get_offset(Y))); - m_og->set_value("position_z", int(instance->get_offset(Z))); + m_og->set_value("position_x", double_to_string(instance->get_offset(X), 2)); + m_og->set_value("position_y", double_to_string(instance->get_offset(Y), 2)); + m_og->set_value("position_z", double_to_string(instance->get_offset(Z), 2)); } void ObjectManipulation::update_position_value(const Vec3d& position) { - m_og->set_value("position_x", int(position(0))); - m_og->set_value("position_y", int(position(1))); - m_og->set_value("position_z", int(position(2))); + m_og->set_value("position_x", double_to_string(position(0), 2)); + m_og->set_value("position_y", double_to_string(position(1), 2)); + m_og->set_value("position_z", double_to_string(position(2), 2)); } void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) @@ -334,9 +333,9 @@ void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) m_og->set_value("scale_unit", _("%")); auto scale = scaling_factor * 100.0; - m_og->set_value("scale_x", int(scale(0))); - m_og->set_value("scale_y", int(scale(1))); - m_og->set_value("scale_z", int(scale(2))); + m_og->set_value("scale_x", double_to_string(scale(0), 2)); + m_og->set_value("scale_y", double_to_string(scale(1), 2)); + m_og->set_value("scale_z", double_to_string(scale(2), 2)); } void ObjectManipulation::update_rotation_values() @@ -364,18 +363,10 @@ void ObjectManipulation::update_rotation_value(double angle, Axis axis) void ObjectManipulation::update_rotation_value(const Vec3d& rotation) { - m_og->set_value("rotation_x", int(round_nearest(Geometry::rad2deg(rotation(0)), 0))); - m_og->set_value("rotation_y", int(round_nearest(Geometry::rad2deg(rotation(1)), 0))); - m_og->set_value("rotation_z", int(round_nearest(Geometry::rad2deg(rotation(2)), 0))); + m_og->set_value("rotation_x", double_to_string(round_nearest(Geometry::rad2deg(rotation(0)), 0), 2)); + m_og->set_value("rotation_y", double_to_string(round_nearest(Geometry::rad2deg(rotation(1)), 0), 2)); + m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(rotation(2)), 0), 2)); } -void ObjectManipulation::show_object_name(bool show) -{ - wxGridSizer* grid_sizer = m_og->get_grid_sizer(); - grid_sizer->Show(static_cast(0), show); - grid_sizer->Show(static_cast(1), show); -} - - } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 974af0f38..29c5cfe53 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -48,8 +48,6 @@ public: void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; } - void show_object_name(bool show); - }; }} diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 445736d3e..4d70d529e 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -43,7 +43,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co case coPercents: case coString: case coStrings: - m_fields.emplace(id, std::move(TextCtrl::Create(parent(), opt, id))); + m_fields.emplace(id, std::move(TextCtrl::Create(parent(), opt, id, process_enter))); break; case coBool: case coBools: diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index b1c6d4b6e..c86ad0975 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -94,6 +94,8 @@ public: wxFont label_font {wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; int sidetext_width{ -1 }; + bool process_enter { false }; + /// Returns a copy of the pointer of the parent wxWindow. /// Accessor function is because users are not allowed to change the parent /// but defining it as const means a lot of const_casts to deal with wx functions. @@ -148,8 +150,13 @@ public: inline void disable() { for (auto& field : m_fields) field.second->disable(); } void set_grid_vgap(int gap) { m_grid_sizer->SetVGap(gap); } - void set_show_modified_btns_val(bool show) { - m_show_modified_btns = show; + void set_show_modified_btns_val(bool show) { + m_show_modified_btns = show; + } + + // The controls inside this option group will generate the event wxEVT_TEXT_ENTER + void set_process_enter() { + process_enter = true; } OptionsGroup( wxWindow* _parent, const wxString& title, bool is_tab_opt = false,