diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 925346ee7..a410f3ad8 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -95,11 +95,6 @@ void AppConfig::set_defaults() set("use_free_camera", "0"); #endif // ENABLE_6DOF_CAMERA -#if ENABLE_SHOW_SCENE_LABELS - if (get("show_labels").empty()) - set("show_labels", "0"); -#endif // ENABLE_SHOW_SCENE_LABELS - // Remove legacy window positions/sizes erase("", "main_frame_maximized"); erase("", "main_frame_pos"); diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 26ab4f435..449b7fbb8 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1238,21 +1238,6 @@ void GLCanvas3D::LegendTexture::render(const GLCanvas3D& canvas) const } #if ENABLE_SHOW_SCENE_LABELS -void GLCanvas3D::Labels::show(bool show) -{ - bool shown = is_shown(); - if (shown != show) - { - wxGetApp().app_config->set("show_labels", show ? "1" : "0"); - wxGetApp().app_config->save(); - } -} - -bool GLCanvas3D::Labels::is_shown() const -{ - return wxGetApp().app_config->get("show_labels") == "1"; -} - void GLCanvas3D::Labels::render(const std::vector& sorted_instances) const { if (!m_enabled || !is_shown()) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 24675ee30..ae26d6f52 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -381,13 +381,14 @@ private: class Labels { bool m_enabled{ false }; + bool m_shown{ false }; GLCanvas3D& m_canvas; public: explicit Labels(GLCanvas3D& canvas) : m_canvas(canvas) {} void enable(bool enable) { m_enabled = enable; } - void show(bool show); - bool is_shown() const; + void show(bool show) { m_shown = m_enabled ? show : false; } + bool is_shown() const { return m_shown; } void render(const std::vector& sorted_instances) const; }; #endif // ENABLE_SHOW_SCENE_LABELS @@ -676,6 +677,11 @@ public: void mouse_up_cleanup(); +#if ENABLE_SHOW_SCENE_LABELS + bool are_labels_shown() const { return m_labels.is_shown(); } + void show_labels(bool show) { m_labels.show(show); } +#endif // ENABLE_SHOW_SCENE_LABELS + private: bool _is_shown_on_screen() const; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 105c6faa5..b05155ef2 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -550,10 +550,10 @@ void MainFrame::init_menubar() wxString hotkey_delete = "Del"; #endif append_menu_item(editMenu, wxID_ANY, _(L("&Select all")) + sep + GUI::shortkey_ctrl_prefix() + sep_space + "A", - _(L("Selects all objects")), [this](wxCommandEvent&) { if (m_plater != nullptr) m_plater->select_all(); }, + _(L("Selects all objects")), [this](wxCommandEvent&) { m_plater->select_all(); }, "", nullptr, [this](){return can_select(); }, this); append_menu_item(editMenu, wxID_ANY, _(L("D&eselect all")) + sep + "Esc", - _(L("Deselects all objects")), [this](wxCommandEvent&) { if (m_plater != nullptr) m_plater->deselect_all(); }, + _(L("Deselects all objects")), [this](wxCommandEvent&) { m_plater->deselect_all(); }, "", nullptr, [this](){return can_deselect(); }, this); editMenu->AppendSeparator(); append_menu_item(editMenu, wxID_ANY, _(L("&Delete selected")) + sep + hotkey_delete, @@ -659,6 +659,12 @@ void MainFrame::init_menubar() "", nullptr, [this](){return can_change_view(); }, this); append_menu_item(viewMenu, wxID_ANY, _(L("Right")) + sep + "&6", _(L("Right View")), [this](wxCommandEvent&) { select_view("right"); }, "", nullptr, [this](){return can_change_view(); }, this); +#if ENABLE_SHOW_SCENE_LABELS + viewMenu->AppendSeparator(); + append_menu_check_item(viewMenu, wxID_ANY, _(L("Show &labels")) + sep + "E", _(L("Show object/instance labels in 3D scene")), + [this](wxCommandEvent&) { m_plater->show_view3D_labels(!m_plater->are_view3D_labels_shown()); }, this, + [this]() { return m_plater->is_view3D_shown(); }, [this]() { return m_plater->are_view3D_labels_shown(); }, this); +#endif // ENABLE_SHOW_SCENE_LABELS } // Help menu diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index bbb7db74d..2ff099a98 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1784,6 +1784,11 @@ struct Plater::priv bool is_preview_loaded() const { return preview->is_loaded(); } bool is_view3D_shown() const { return current_panel == view3D; } +#if ENABLE_SHOW_SCENE_LABELS + bool are_view3D_labels_shown() const { return (current_panel == view3D) && view3D->get_canvas3d()->are_labels_shown(); } + void show_view3D_labels(bool show) { if (current_panel == view3D) view3D->get_canvas3d()->show_labels(show); } +#endif // ENABLE_SHOW_SCENE_LABELS + void set_current_canvas_as_dirty(); #if ENABLE_BACKWARD_COMPATIBLE_RELOAD_FROM_DISK GLCanvas3D* get_current_canvas3D(); @@ -4672,6 +4677,11 @@ bool Plater::is_preview_shown() const { return p->is_preview_shown(); } bool Plater::is_preview_loaded() const { return p->is_preview_loaded(); } bool Plater::is_view3D_shown() const { return p->is_view3D_shown(); } +#if ENABLE_SHOW_SCENE_LABELS +bool Plater::are_view3D_labels_shown() const { return p->are_view3D_labels_shown(); } +void Plater::show_view3D_labels(bool show) { p->show_view3D_labels(show); } +#endif // ENABLE_SHOW_SCENE_LABELS + void Plater::select_all() { p->select_all(); } void Plater::deselect_all() { p->deselect_all(); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 568727abf..bd562d17e 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -170,6 +170,11 @@ public: bool is_preview_loaded() const; bool is_view3D_shown() const; +#if ENABLE_SHOW_SCENE_LABELS + bool are_view3D_labels_shown() const; + void show_view3D_labels(bool show); +#endif // ENABLE_SHOW_SCENE_LABELS + // Called after the Preferences dialog is closed and the program settings are saved. // Update the UI based on the current preferences. void update_ui_from_settings(); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 57748d3a8..4fd63fe0e 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -144,15 +144,6 @@ void PreferencesDialog::build() } }; -#if ENABLE_SHOW_SCENE_LABELS - def.label = L("Show object/instance labels in 3D scene"); - def.type = coBool; - def.tooltip = L("If enabled, shows labels containing info about objects/instances."); - def.set_default_value(new ConfigOptionBool{ app_config->get("show_labels") == "1" }); - option = Option(def, "show_labels"); - m_optgroup_gui->append_single_option_line(option); -#endif // ENABLE_SHOW_SCENE_LABELS - def.label = L("Use custom size for toolbar icons"); def.type = coBool; def.tooltip = L("If enabled, you can change size of toolbar icons manually."); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 399fcdf03..f814c11df 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -146,7 +146,8 @@ wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, } wxMenuItem* append_menu_check_item(wxMenu* menu, int id, const wxString& string, const wxString& description, - std::function cb, wxEvtHandler* event_handler) + std::function cb, wxEvtHandler* event_handler, + std::function const enable_condition, std::function const check_condition, wxWindow* parent) { if (id == wxID_ANY) id = wxNewId(); @@ -160,6 +161,13 @@ wxMenuItem* append_menu_check_item(wxMenu* menu, int id, const wxString& string, #endif // __WXMSW__ menu->Bind(wxEVT_MENU, cb, id); + if (parent) + parent->Bind(wxEVT_UPDATE_UI, [enable_condition, check_condition](wxUpdateUIEvent& evt) + { + evt.Enable(enable_condition()); + evt.Check(check_condition()); + }, id); + return item; } diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 55dac5433..d4679f757 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -34,7 +34,9 @@ wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, std::function cb, wxEvtHandler* event_handler); wxMenuItem* append_menu_check_item(wxMenu* menu, int id, const wxString& string, const wxString& description, - std::function cb, wxEvtHandler* event_handler); + std::function cb, wxEvtHandler* event_handler, + std::function const enable_condition = []() { return true; }, + std::function const check_condition = []() { return true; }, wxWindow* parent = nullptr); void enable_menu_item(wxUpdateUIEvent& evt, std::function const cb_condition, wxMenuItem* item, wxWindow* win);