From 6881911411f40abee6770c21074f70579ab5992b Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 7 May 2019 15:43:53 +0200 Subject: [PATCH] World / local coordinates: Fixed wrong scaling of a group selection, changed the "anisotropic scaling" - "embed vertices" message, fixed scaling in the world coordinate system, so it does not count the modifiers into the bounding box size. --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 15 ++++++----- src/slic3r/GUI/OptionsGroup.hpp | 3 --- src/slic3r/GUI/Selection.cpp | 32 +++++++++++++++++++---- src/slic3r/GUI/Selection.hpp | 6 ++++- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 96a69e464..ecce5770e 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -37,8 +37,8 @@ static wxBitmapComboBox* create_word_local_combo(wxWindow *parent) temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); temp->SetBackgroundStyle(wxBG_STYLE_PAINT); - temp->Append(_(L("World"))); - temp->Append(_(L("Local"))); + temp->Append(_(L("World coordinates"))); + temp->Append(_(L("Local coordinates"))); temp->SetSelection(0); temp->SetValue(temp->GetString(0)); @@ -228,7 +228,7 @@ void ObjectManipulation::Show(const bool show) bool ObjectManipulation::IsShown() { - return m_og->get_grid_sizer()->IsShown(2); + return dynamic_cast(m_og->sizer)->GetStaticBox()->IsShown(); // m_og->get_grid_sizer()->IsShown(2); } void ObjectManipulation::UpdateAndShow(const bool show) @@ -265,7 +265,7 @@ void ObjectManipulation::update_settings_value(const Selection& selection) if (m_world_coordinates) { m_new_rotate_label_string = L("Rotate"); m_new_rotation = Vec3d::Zero(); - m_new_size = selection.get_bounding_box().size(); + m_new_size = selection.get_scaled_instance_bounding_box().size(); m_new_scale = m_new_size.cwiseProduct(selection.get_unscaled_instance_bounding_box().size().cwiseInverse()) * 100.; } else { m_new_rotation = volume->get_instance_rotation() * (180. / M_PI); @@ -399,7 +399,7 @@ void ObjectManipulation::reset_settings_value() { m_new_position = Vec3d::Zero(); m_new_rotation = Vec3d::Zero(); - m_new_scale = Vec3d::Ones(); + m_new_scale = Vec3d::Ones() * 100.; m_new_size = Vec3d::Zero(); m_new_enabled = false; // no need to set the dirty flag here as this method is called from update_settings_value(), @@ -590,10 +590,11 @@ void ObjectManipulation::set_uniform_scaling(const bool new_value) wxMessageDialog dlg(GUI::wxGetApp().mainframe, _(L("The currently manipulated object is tilted (rotation angles are not multiples of 90°).\n" "Non-uniform scaling of tilted objects is only possible in the World coordinate system,\n" - "once the rotation is embedded into the object coordinates.\n" + "once the rotation is embedded into the object coordinates.")) + "\n" + + _(L("This operation is irreversible.\n" "Do you want to proceed?")), SLIC3R_APP_NAME, - wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION); + wxYES_NO | wxCANCEL | wxCANCEL_DEFAULT | wxICON_QUESTION); if (dlg.ShowModal() != wxID_YES) { // Enforce uniform scaling. m_lock_bnt->SetLock(true); diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index fa8a19940..73b2c5110 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -1,17 +1,14 @@ #ifndef slic3r_OptionsGroup_hpp_ #define slic3r_OptionsGroup_hpp_ -//#include #include #include -//#include #include #include #include "libslic3r/Config.hpp" #include "libslic3r/PrintConfig.hpp" -// #include "libslic3r/libslic3r.h" #include "Field.hpp" #include "GUI_App.hpp" diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index 28cab3eba..eaa00bf6f 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -430,10 +430,16 @@ const BoundingBoxf3& Selection::get_unscaled_instance_bounding_box() const { if (m_unscaled_instance_bounding_box_dirty) calc_unscaled_instance_bounding_box(); - return m_unscaled_instance_bounding_box; } +const BoundingBoxf3& Selection::get_scaled_instance_bounding_box() const +{ + if (m_scaled_instance_bounding_box_dirty) + calc_scaled_instance_bounding_box(); + return m_scaled_instance_bounding_box; +} + void Selection::start_dragging() { if (!m_valid) @@ -1416,11 +1422,11 @@ void Selection::calc_bounding_box() const void Selection::calc_unscaled_instance_bounding_box() const { m_unscaled_instance_bounding_box = BoundingBoxf3(); - if (m_valid) - { - for (unsigned int i : m_list) - { + if (m_valid) { + for (unsigned int i : m_list) { const GLVolume &volume = *(*m_volumes)[i]; + if (volume.is_modifier) + continue; Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, true, false) * volume.get_volume_transformation().get_matrix(); trafo.translation()(2) += volume.get_sla_shift_z(); m_unscaled_instance_bounding_box.merge(volume.transformed_convex_hull_bounding_box(trafo)); @@ -1429,6 +1435,22 @@ void Selection::calc_unscaled_instance_bounding_box() const m_unscaled_instance_bounding_box_dirty = false; } +void Selection::calc_scaled_instance_bounding_box() const +{ + m_scaled_instance_bounding_box = BoundingBoxf3(); + if (m_valid) { + for (unsigned int i : m_list) { + const GLVolume &volume = *(*m_volumes)[i]; + if (volume.is_modifier) + continue; + Transform3d trafo = volume.get_instance_transformation().get_matrix(false, false, false, false) * volume.get_volume_transformation().get_matrix(); + trafo.translation()(2) += volume.get_sla_shift_z(); + m_scaled_instance_bounding_box.merge(volume.transformed_convex_hull_bounding_box(trafo)); + } + } + m_scaled_instance_bounding_box_dirty = false; +} + void Selection::render_selected_volumes() const { float color[3] = { 1.0f, 1.0f, 1.0f }; diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index d808bee07..4e5da3685 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -187,6 +187,8 @@ private: // is useful for absolute scaling of tilted objects in world coordinate space. mutable BoundingBoxf3 m_unscaled_instance_bounding_box; mutable bool m_unscaled_instance_bounding_box_dirty; + mutable BoundingBoxf3 m_scaled_instance_bounding_box; + mutable bool m_scaled_instance_bounding_box_dirty; #if ENABLE_RENDER_SELECTION_CENTER GLUquadricObj* m_quadric; @@ -272,6 +274,7 @@ public: // Bounding box of a selection, with no instance scaling applied. This bounding box // is useful for absolute scaling of tilted objects in world coordinate space. const BoundingBoxf3& get_unscaled_instance_bounding_box() const; + const BoundingBoxf3& get_scaled_instance_bounding_box() const; void start_dragging(); @@ -311,7 +314,8 @@ private: void do_remove_object(unsigned int object_idx); void calc_bounding_box() const; void calc_unscaled_instance_bounding_box() const; - void set_bounding_boxes_dirty() { m_bounding_box_dirty = true; m_unscaled_instance_bounding_box_dirty = true; } + void calc_scaled_instance_bounding_box() const; + void set_bounding_boxes_dirty() { m_bounding_box_dirty = true; m_unscaled_instance_bounding_box_dirty = true; m_scaled_instance_bounding_box_dirty = true; } void render_selected_volumes() const; void render_synchronized_volumes() const; void render_bounding_box(const BoundingBoxf3& box, float* color) const;