diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index ffaa2d20c..138946166 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3310,6 +3310,11 @@ void GLCanvas3D::handle_sidebar_focus_event(const std::string& opt_key, bool foc } } +void GLCanvas3D::handle_layers_data_focus_event(const t_layer_height_range range, const EditorType type) +{ + printf("min_z = %.2f, max_z = %.2f, type=%d\n", range.first, range.second, type); +} + void GLCanvas3D::update_ui_from_settings() { #if ENABLE_RETINA_GL diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index d39a910b3..95fd123eb 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -12,6 +12,7 @@ #include "Camera.hpp" #include "Selection.hpp" #include "Gizmos/GLGizmosManager.hpp" +#include "GUI_ObjectLayers.hpp" #include @@ -606,6 +607,7 @@ public: void reset_all_gizmos() { m_gizmos.reset_all_states(); } void handle_sidebar_focus_event(const std::string& opt_key, bool focus_on); + void handle_layers_data_focus_event(const t_layer_height_range range, const EditorType type); void update_ui_from_settings(); diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp index 1426ccf02..d854e54b3 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.cpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp @@ -4,6 +4,7 @@ #include "OptionsGroup.hpp" #include "PresetBundle.hpp" #include "libslic3r/Model.hpp" +#include "GLCanvas3D.hpp" #include @@ -62,13 +63,13 @@ wxSizer* ObjectLayers::create_layer(const t_layer_height_range& range) { const bool is_last_edited_range = range == m_selectable_range; - auto set_focus_fn = [range, this](const EditorType type) + auto set_focus_data = [range, this](const EditorType type) { m_selectable_range = range; m_selection_type = type; }; - auto set_focus = [range, this](const t_layer_height_range& new_range, EditorType type, bool enter_pressed) + auto update_focus_data = [range, this](const t_layer_height_range& new_range, EditorType type, bool enter_pressed) { // change selectable range for new one, if enter was pressed or if same range was selected if (enter_pressed || m_selectable_range == range) @@ -79,8 +80,8 @@ wxSizer* ObjectLayers::create_layer(const t_layer_height_range& range) // Add control for the "Min Z" - auto editor = new LayerRangeEditor(m_parent, double_to_string(range.first), etMinZ, - set_focus_fn, [range, set_focus, this](coordf_t min_z, bool enter_pressed) + auto editor = new LayerRangeEditor(this, double_to_string(range.first), etMinZ, + set_focus_data, [range, update_focus_data, this](coordf_t min_z, bool enter_pressed) { if (fabs(min_z - range.first) < EPSILON) { m_selection_type = etUndef; @@ -89,8 +90,8 @@ wxSizer* ObjectLayers::create_layer(const t_layer_height_range& range) // data for next focusing coordf_t max_z = min_z < range.second ? range.second : min_z + 0.5; - const t_layer_height_range& new_range = { min_z, max_z/*range.second*/ }; - set_focus(new_range, etMinZ, enter_pressed); + const t_layer_height_range& new_range = { min_z, max_z }; + update_focus_data(new_range, etMinZ, enter_pressed); return wxGetApp().obj_list()->edit_layer_range(range, new_range); }); @@ -100,8 +101,8 @@ wxSizer* ObjectLayers::create_layer(const t_layer_height_range& range) // Add control for the "Max Z" - editor = new LayerRangeEditor(m_parent, double_to_string(range.second), etMaxZ, - set_focus_fn, [range, set_focus, this](coordf_t max_z, bool enter_pressed) + editor = new LayerRangeEditor(this, double_to_string(range.second), etMaxZ, + set_focus_data, [range, update_focus_data, this](coordf_t max_z, bool enter_pressed) { if (fabs(max_z - range.second) < EPSILON || range.first > max_z) { m_selection_type = etUndef; @@ -110,7 +111,7 @@ wxSizer* ObjectLayers::create_layer(const t_layer_height_range& range) // data for next focusing const t_layer_height_range& new_range = { range.first, max_z }; - set_focus(new_range, etMaxZ, enter_pressed); + update_focus_data(new_range, etMaxZ, enter_pressed); return wxGetApp().obj_list()->edit_layer_range(range, new_range); }); @@ -120,9 +121,9 @@ wxSizer* ObjectLayers::create_layer(const t_layer_height_range& range) // Add control for the "Layer height" - editor = new LayerRangeEditor(m_parent, + editor = new LayerRangeEditor(this, double_to_string(m_object->layer_config_ranges[range].option("layer_height")->getFloat()), - etLayerHeight, set_focus_fn, [range, this](coordf_t layer_height, bool) + etLayerHeight, set_focus_data, [range, this](coordf_t layer_height, bool) { return wxGetApp().obj_list()->edit_layer_range(range, layer_height); }); @@ -203,6 +204,12 @@ void ObjectLayers::update_layers_list() m_parent->Layout(); } +void ObjectLayers::update_scene_from_editor_selection() const +{ + // needed to show the visual hints in 3D scene + wxGetApp().plater()->canvas3D()->handle_layers_data_focus_event(m_selectable_range, m_selection_type); +} + void ObjectLayers::UpdateAndShow(const bool show) { if (show) @@ -217,17 +224,17 @@ void ObjectLayers::msw_rescale() m_bmp_add.msw_rescale(); } -LayerRangeEditor::LayerRangeEditor( wxWindow* parent, +LayerRangeEditor::LayerRangeEditor( ObjectLayers* parent, const wxString& value, EditorType type, - std::function set_focus_fn, + std::function set_focus_data_fn, std::function edit_fn ) : m_valid_value(value), m_type(type), - m_set_focus(set_focus_fn), - wxTextCtrl(parent, wxID_ANY, value, wxDefaultPosition, - wxSize(8 * em_unit(parent), wxDefaultCoord), wxTE_PROCESS_ENTER) + m_set_focus_data(set_focus_data_fn), + wxTextCtrl(parent->m_parent, wxID_ANY, value, wxDefaultPosition, + wxSize(8 * em_unit(parent->m_parent), wxDefaultCoord), wxTE_PROCESS_ENTER) { this->SetFont(wxGetApp().normal_font()); @@ -258,7 +265,7 @@ LayerRangeEditor::LayerRangeEditor( wxWindow* parent, * */ LayerRangeEditor* new_editor = dynamic_cast(e.GetWindow()); if (new_editor) - new_editor->set_focus(); + new_editor->set_focus_data(); #endif // not __WXGTK__ // If LayersList wasn't updated/recreated, we should call e.Skip() if (m_type & etLayerHeight) { @@ -279,10 +286,17 @@ LayerRangeEditor::LayerRangeEditor( wxWindow* parent, } }, this->GetId()); + this->Bind(wxEVT_SET_FOCUS, [this, parent](wxFocusEvent& e) + { + set_focus_data(); + parent->update_scene_from_editor_selection(); + e.Skip(); + }, this->GetId()); + #ifdef __WXGTK__ // Workaround! To take information about selectable range this->Bind(wxEVT_LEFT_DOWN, [this](wxEvent& e) { - set_focus(); + set_focus_data(); e.Skip(); }, this->GetId()); #endif //__WXGTK__ diff --git a/src/slic3r/GUI/GUI_ObjectLayers.hpp b/src/slic3r/GUI/GUI_ObjectLayers.hpp index e3366e03e..f19217fbe 100644 --- a/src/slic3r/GUI/GUI_ObjectLayers.hpp +++ b/src/slic3r/GUI/GUI_ObjectLayers.hpp @@ -19,6 +19,8 @@ class ConfigOptionsGroup; typedef double coordf_t; typedef std::pair t_layer_height_range; +class ObjectLayers; + enum EditorType { etUndef = 0, @@ -34,19 +36,19 @@ class LayerRangeEditor : public wxTextCtrl wxString m_valid_value; EditorType m_type; - std::function m_set_focus; + std::function m_set_focus_data; public: - LayerRangeEditor( wxWindow* parent, + LayerRangeEditor( ObjectLayers* parent, const wxString& value = wxEmptyString, EditorType type = etUndef, - std::function set_focus_fn = [](EditorType) {;}, - std::function edit_fn = [](coordf_t, bool) {return false; } + std::function set_focus_data_fn = [](EditorType) {;}, + std::function edit_fn = [](coordf_t, bool) {return false; } ); ~LayerRangeEditor() {} EditorType type() const {return m_type;} - void set_focus() const { m_set_focus(m_type);} + void set_focus_data() const { m_set_focus_data(m_type);} private: coordf_t get_value(); @@ -71,8 +73,12 @@ public: void create_layers_list(); void update_layers_list(); + void update_scene_from_editor_selection() const; + void UpdateAndShow(const bool show) override; void msw_rescale(); + + friend class LayerRangeEditor; }; }}