From e79bcee739d5d55f5bd9c678536fa3505a2bc867 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 26 Jul 2021 14:40:19 +0200 Subject: [PATCH] Fixed update of the default menu after changing of the mode. + Added check for the output directory for the G-code extport. --- src/libslic3r/AppConfig.cpp | 4 ++-- src/libslic3r/Utils.hpp | 1 + src/libslic3r/utils.cpp | 5 +++++ src/slic3r/GUI/GUI_App.cpp | 2 +- src/slic3r/GUI/GUI_Factories.cpp | 14 ++++++++++++++ src/slic3r/GUI/GUI_Factories.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 7 +++---- src/slic3r/GUI/Plater.hpp | 2 +- 8 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 9f97bebc0..dc720db48 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -542,7 +542,7 @@ void AppConfig::update_config_dir(const std::string &dir) void AppConfig::update_skein_dir(const std::string &dir) { - if (dir == sys_shapes_dir() || dir == custom_shapes_dir()) + if (is_shapes_dir(dir)) return; // do not save "shapes gallery" directory this->set("recent", "skein_directory", dir); } @@ -576,7 +576,7 @@ std::string AppConfig::get_last_output_dir(const std::string& alt, const bool re if (it2 != it->second.end() && it3 != it->second.end() && !it2->second.empty() && it3->second == "1") return it2->second; } - return alt; + return is_shapes_dir(alt) ? get_last_dir() : alt; } void AppConfig::update_last_output_dir(const std::string& dir, const bool removable) diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 211755bbb..81897553c 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -102,6 +102,7 @@ extern bool is_gcode_file(const std::string &path); extern bool is_img_file(const std::string& path); extern bool is_stl_file(const boost::filesystem::directory_entry& path); extern bool is_stl_file(const std::string& path); +extern bool is_shapes_dir(const std::string& dir); // File path / name / extension splitting utilities, working with UTF-8, // to be published to Perl. diff --git a/src/libslic3r/utils.cpp b/src/libslic3r/utils.cpp index 3e38a3e67..085db8705 100644 --- a/src/libslic3r/utils.cpp +++ b/src/libslic3r/utils.cpp @@ -776,6 +776,11 @@ bool is_stl_file(const std::string &path) return boost::iends_with(path, ".stl"); } +bool is_shapes_dir(const std::string& dir) +{ + return dir == sys_shapes_dir() || dir == custom_shapes_dir(); +} + } // namespace Slic3r #ifdef WIN32 diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1b71e0d8c..a73ca880a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1780,7 +1780,7 @@ void GUI_App::update_mode() for (auto tab : tabs_list) tab->update_mode(); - plater()->update_object_menu(); + plater()->update_menus(); plater()->canvas3D()->update_gizmos_on_off_state(); } diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index 6a945c061..86f3eae0a 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -953,6 +953,12 @@ void MenuFactory::init(wxWindow* parent) create_instance_menu(); } +void MenuFactory::update() +{ + update_default_menu(); + update_object_menu(); +} + wxMenu* MenuFactory::default_menu() { return &m_default_menu; @@ -1077,6 +1083,14 @@ void MenuFactory::update_object_menu() append_menu_items_add_volume(&m_object_menu); } +void MenuFactory::update_default_menu() +{ + const auto menu_item_id = m_default_menu.FindItem(_("Add Shape")); + if (menu_item_id != wxNOT_FOUND) + m_default_menu.Destroy(menu_item_id); + create_default_menu(); +} + void MenuFactory::msw_rescale() { for (MenuWithSeparators* menu : { &m_object_menu, &m_sla_object_menu, &m_part_menu, &m_default_menu }) diff --git a/src/slic3r/GUI/GUI_Factories.hpp b/src/slic3r/GUI/GUI_Factories.hpp index e8928d3ff..f47837d73 100644 --- a/src/slic3r/GUI/GUI_Factories.hpp +++ b/src/slic3r/GUI/GUI_Factories.hpp @@ -40,7 +40,9 @@ public: ~MenuFactory() = default; void init(wxWindow* parent); + void update(); void update_object_menu(); + void update_default_menu(); void msw_rescale(); void sys_color_changed(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b318c1cde..00cc49f75 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2653,11 +2653,10 @@ wxString Plater::priv::get_export_file(GUI::FileType file_type) default: break; } - std::string dir = (boost::filesystem::path(output_file).parent_path()).string(); - bool use_def_out_dir = dir == sys_shapes_dir() || dir == custom_shapes_dir(); + std::string out_dir = (boost::filesystem::path(output_file).parent_path()).string(); wxFileDialog dlg(q, dlg_title, - use_def_out_dir ? from_u8(wxGetApp().app_config->get_last_dir()) : from_path(output_file.parent_path()), from_path(output_file.filename()), + is_shapes_dir(out_dir) ? from_u8(wxGetApp().app_config->get_last_dir()) : from_path(output_file.parent_path()), from_path(output_file.filename()), wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if (dlg.ShowModal() != wxID_OK) @@ -6269,7 +6268,7 @@ void Plater::mirror(Axis axis) { p->mirror(axis); } void Plater::split_object() { p->split_object(); } void Plater::split_volume() { p->split_volume(); } void Plater::optimize_rotation() { p->m_ui_jobs.optimize_rotation();} -void Plater::update_object_menu() { p->menus.update_object_menu(); } +void Plater::update_menus() { p->menus.update(); } void Plater::show_action_buttons(const bool ready_to_slice) const { p->show_action_buttons(ready_to_slice); } void Plater::copy_selection_to_clipboard() diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 6fdd70032..69069de8c 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -268,7 +268,7 @@ public: std::vector get_extruder_colors_from_plater_config(const GCodeProcessor::Result* const result = nullptr) const; std::vector get_colors_for_color_print(const GCodeProcessor::Result* const result = nullptr) const; - void update_object_menu(); + void update_menus(); void show_action_buttons(const bool is_ready_to_slice) const; wxString get_project_filename(const wxString& extension = wxEmptyString) const;