From a1e49e7f8c44f676d19d33b6dc06a101e15fe8b0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 9 Feb 2021 16:03:32 +0100 Subject: [PATCH 1/2] Implemented #4931 - Added colored background for the Manipulation panel, if option "Use colors for axes values in Manipulation panel" is enabled in Preferences -> GUI + Fix one more compilation warning in UnsavedChangesDialog.cpp --- src/libslic3r/AppConfig.cpp | 3 +++ src/slic3r/GUI/GUI_ObjectManipulation.cpp | 26 ++++++++++++++++++++--- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 4 +++- src/slic3r/GUI/Preferences.cpp | 8 +++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 79b9a025a..737c4fcda 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -123,6 +123,9 @@ void AppConfig::set_defaults() if (get("default_action_on_select_preset").empty()) set("default_action_on_select_preset", "none"); // , "transfer", "discard" or "save" + + if (get("color_mapinulation_panel").empty()) + set("color_mapinulation_panel", "0"); } #if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN else { diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index e9c873509..cba7cef36 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -109,10 +109,13 @@ static void set_font_and_background_style(wxWindow* win, const wxFont& font) win->SetBackgroundStyle(wxBG_STYLE_PAINT); } +static const wxString axes_color_text[] = { "#990000", "#009900", "#000099" }; +static const wxString axes_color_back[] = { "#f5dcdc", "#dcf5dc", "#dcdcf5" }; ObjectManipulation::ObjectManipulation(wxWindow* parent) : OG_Settings(parent, true) { m_imperial_units = wxGetApp().app_config->get("use_inches") == "1"; + m_use_colors = wxGetApp().app_config->get("color_mapinulation_panel") == "1"; m_manifold_warning_bmp = ScalableBitmap(parent, "exclamation"); @@ -236,13 +239,14 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : // Add Axes labels with icons static const char axes[] = { 'X', 'Y', 'Z' }; -// std::vector axes_color = {"#990000", "#009900","#000099"}; +// std::vector axes_color = {"#EE0000", "#00EE00", "#0000EE"}; for (size_t axis_idx = 0; axis_idx < sizeof(axes); axis_idx++) { const char label = axes[axis_idx]; wxStaticText* axis_name = new wxStaticText(m_parent, wxID_ANY, wxString(label)); set_font_and_background_style(axis_name, wxGetApp().bold_font()); -// axis_name->SetForegroundColour(wxColour(axes_color[axis_idx])); + //if (m_use_colors) + // axis_name->SetForegroundColour(wxColour(axes_color_text[axis_idx])); sizer = new wxBoxSizer(wxHORIZONTAL); // Under OSX we use font, smaller than default font, so @@ -481,8 +485,20 @@ void ObjectManipulation::update_ui_from_settings() update(3/*meSize*/, m_new_size); } } - m_check_inch->SetValue(m_imperial_units); + + if (m_use_colors != (wxGetApp().app_config->get("color_mapinulation_panel") == "1")) + { + m_use_colors = wxGetApp().app_config->get("color_mapinulation_panel") == "1"; + // update colors for edit-boxes + int axis_id = 0; + for (ManipulationEditor* editor : m_editors) { +// editor->SetForegroundColour(m_use_colors ? wxColour(axes_color_text[axis_id]) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); + editor->SetBackgroundColour(m_use_colors ? wxColour(axes_color_back[axis_id]) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + if (++axis_id == 3) + axis_id = 0; + } + } } void ObjectManipulation::update_settings_value(const Selection& selection) @@ -1000,6 +1016,10 @@ ManipulationEditor::ManipulationEditor(ObjectManipulation* parent, #ifdef __WXOSX__ this->OSXDisableAllSmartSubstitutions(); #endif // __WXOSX__ + if (parent->use_colors()) { +// this->SetForegroundColour(wxColour(axes_color_text[axis])); + this->SetBackgroundColour(wxColour(axes_color_back[axis])); + } // A name used to call handle_sidebar_focus_event() m_full_opt_name = m_opt_key+"_"+axes[axis]; diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 6b275799f..bcc0d4123 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -95,6 +95,7 @@ private: wxStaticText* m_rotate_Label = nullptr; bool m_imperial_units { false }; + bool m_use_colors { false }; wxStaticText* m_position_unit { nullptr }; wxStaticText* m_size_unit { nullptr }; @@ -162,7 +163,8 @@ public: void Show(const bool show) override; bool IsShown() override; void UpdateAndShow(const bool show) override; - void update_ui_from_settings(); + void update_ui_from_settings(); + bool use_colors() { return m_use_colors; } void set_dirty() { m_dirty = true; } // Called from the App to update the UI if dirty. diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 0a8a6c886..ab296d297 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -297,6 +297,14 @@ void PreferencesDialog::build() option = Option(def, "suppress_hyperlinks"); m_optgroup_gui->append_single_option_line(option); + def.label = L("Use colors for axes values in Manipulation panel"); + def.type = coBool; + def.tooltip = L("If enabled, the axes names and axes values will be colorized according to the axes colors. " + "If disabled, old UI will be used."); + def.set_default_value(new ConfigOptionBool{ app_config->get("color_mapinulation_panel") == "1" }); + option = Option(def, "color_mapinulation_panel"); + m_optgroup_gui->append_single_option_line(option); + 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."); From a86e7107a5d4549cf313c4097f87c309c3ff4d2c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 9 Feb 2021 17:04:32 +0100 Subject: [PATCH 2/2] Added check for loaded STL file if it was saved in meters. Related to #4521 (Some files are imported in the wrong size) --- src/libslic3r/Model.cpp | 23 +++++++++++++++++++++++ src/libslic3r/Model.hpp | 2 ++ src/slic3r/GUI/Plater.cpp | 13 ++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index c25026cc4..a07708669 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -472,6 +472,29 @@ void Model::convert_from_imperial_units(bool only_small_volumes) } } +bool Model::looks_like_saved_in_meters() const +{ + if (this->objects.size() == 0) + return false; + + for (ModelObject* obj : this->objects) + if (obj->get_object_stl_stats().volume < 0.001) // 0.001 = 0.1*0.1*0.1; + return true; + + return false; +} + +void Model::convert_from_meters(bool only_small_volumes) +{ + double m_to_mm = 1000; + for (ModelObject* obj : this->objects) + if (! only_small_volumes || obj->get_object_stl_stats().volume < 0.001) { // 0.001 = 0.1*0.1*0.1; + obj->scale_mesh_after_creation(Vec3d(m_to_mm, m_to_mm, m_to_mm)); + for (ModelVolume* v : obj->volumes) + v->source.is_converted_from_inches = true; + } +} + void Model::adjust_min_z() { if (objects.empty()) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 99db132f6..b06ecf527 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1019,6 +1019,8 @@ public: void convert_multipart_object(unsigned int max_extruders); bool looks_like_imperial_units() const; void convert_from_imperial_units(bool only_small_volumes); + bool looks_like_saved_in_meters() const; + void convert_from_meters(bool only_small_volumes); // Ensures that the min z of the model is not negative void adjust_min_z(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8ca335fa8..9912e7aa0 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2415,13 +2415,24 @@ std::vector Plater::priv::load_files(const std::vector& input_ auto convert_from_imperial_units = [](Model& model, bool only_small_volumes) { model.convert_from_imperial_units(only_small_volumes); // wxGetApp().app_config->set("use_inches", "1"); - wxGetApp().sidebar().update_ui_from_settings(); +// wxGetApp().sidebar().update_ui_from_settings(); }; if (!is_project_file) { if (imperial_units) // Convert even if the object is big. convert_from_imperial_units(model, false); + else if (model.looks_like_saved_in_meters()) { + wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL( + "The object in file %s looks like saved in meters.\n" + "Should I consider it as a saved in meters and convert it?", + "Some objects in file %s look like saved in meters.\n" + "Should I consider them as a saved in meters and convert them?", model.objects.size()), from_path(filename)) + "\n", + _L("The object appears to be saved in meters"), wxICON_WARNING | wxYES | wxNO); + if (msg_dlg.ShowModal() == wxID_YES) + //FIXME up-scale only the small parts? + model.convert_from_meters(true); + } else if (model.looks_like_imperial_units()) { wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL( "The object in file %s looks like saved in inches.\n"