From 81ab43ea9adfd3498e9a5619b9cef02e5b564d6e Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 1 Aug 2019 11:18:11 +0200 Subject: [PATCH 1/3] Revert "Changed snapshot names for reset rotation/reset scale/drop to bed functions" This reverts commit 1ca8ff1285a10d723469d6723708f32078e0693b. --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 46 +++++++++++------------ src/slic3r/GUI/GUI_ObjectManipulation.hpp | 10 ++--- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 7dd73ece9..a4aa3c6d8 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -286,11 +286,9 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn, wxBU_EXACTFIT); btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { - wxGetApp().plater()->take_snapshot(_(L("Reset scale"))); - // the empty strings prevent taking another three snapshots - change_scale_value(0, 100., std::string()); - change_scale_value(1, 100., std::string()); - change_scale_value(2, 100., std::string()); + change_scale_value(0, 100.); + change_scale_value(1, 100.); + change_scale_value(2, 100.); }); return sizer; }; @@ -325,7 +323,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); selection.synchronize_unselected_volumes(); // Copy rotation values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. - canvas->do_rotate(L("Reset Rotation")); + canvas->do_rotate(L("Set Rotation")); UpdateAndShow(true); }); @@ -352,11 +350,9 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : const Geometry::Transformation& instance_trafo = volume->get_instance_transformation(); Vec3d diff = m_cache.position - instance_trafo.get_matrix(true).inverse() * Vec3d(0., 0., get_volume_min_z(volume)); - // Take an undo/redo snapshot and prevent change_position_value from doing it three times. - wxGetApp().plater()->take_snapshot(_(L("Drop to bed"))); - change_position_value(0, diff.x(), std::string()); - change_position_value(1, diff.y(), std::string()); - change_position_value(2, diff.z(), std::string()); + change_position_value(0, diff.x()); + change_position_value(1, diff.y()); + change_position_value(2, diff.z()); } }); return sizer; @@ -701,7 +697,7 @@ void ObjectManipulation::reset_settings_value() // m_dirty = true; } -void ObjectManipulation::change_position_value(int axis, double value, const std::string& snapshot_name) +void ObjectManipulation::change_position_value(int axis, double value) { if (std::abs(m_cache.position_rounded(axis) - value) < EPSILON) return; @@ -713,14 +709,14 @@ void ObjectManipulation::change_position_value(int axis, double value, const std Selection& selection = canvas->get_selection(); selection.start_dragging(); selection.translate(position - m_cache.position, selection.requires_local_axes()); - canvas->do_move(snapshot_name); + canvas->do_move(L("Set Position")); m_cache.position = position; m_cache.position_rounded(axis) = DBL_MAX; this->UpdateAndShow(true); } -void ObjectManipulation::change_rotation_value(int axis, double value, const std::string& snapshot_name) +void ObjectManipulation::change_rotation_value(int axis, double value) { if (std::abs(m_cache.rotation_rounded(axis) - value) < EPSILON) return; @@ -744,14 +740,14 @@ void ObjectManipulation::change_rotation_value(int axis, double value, const std selection.rotate( (M_PI / 180.0) * (transformation_type.absolute() ? rotation : rotation - m_cache.rotation), transformation_type); - canvas->do_rotate(snapshot_name); + canvas->do_rotate(L("Set Orientation")); m_cache.rotation = rotation; m_cache.rotation_rounded(axis) = DBL_MAX; this->UpdateAndShow(true); } -void ObjectManipulation::change_scale_value(int axis, double value, const std::string& snapshot_name) +void ObjectManipulation::change_scale_value(int axis, double value) { if (std::abs(m_cache.scale_rounded(axis) - value) < EPSILON) return; @@ -759,7 +755,7 @@ void ObjectManipulation::change_scale_value(int axis, double value, const std::s Vec3d scale = m_cache.scale; scale(axis) = value; - this->do_scale(axis, scale, snapshot_name); + this->do_scale(axis, scale); m_cache.scale = scale; m_cache.scale_rounded(axis) = DBL_MAX; @@ -767,7 +763,7 @@ void ObjectManipulation::change_scale_value(int axis, double value, const std::s } -void ObjectManipulation::change_size_value(int axis, double value, const std::string& snapshot_name) +void ObjectManipulation::change_size_value(int axis, double value) { if (std::abs(m_cache.size_rounded(axis) - value) < EPSILON) return; @@ -785,14 +781,14 @@ void ObjectManipulation::change_size_value(int axis, double value, const std::st selection.get_unscaled_instance_bounding_box().size() : wxGetApp().model().objects[selection.get_volume(*selection.get_volume_idxs().begin())->object_idx()]->raw_mesh_bounding_box().size(); - this->do_scale(axis, 100. * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2)), snapshot_name); + this->do_scale(axis, 100. * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2))); m_cache.size = size; m_cache.size_rounded(axis) = DBL_MAX; this->UpdateAndShow(true); } -void ObjectManipulation::do_scale(int axis, const Vec3d &scale, const std::string& snapshot_name) const +void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const { Selection& selection = wxGetApp().plater()->canvas3D()->get_selection(); Vec3d scaling_factor = scale; @@ -809,7 +805,7 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale, const std::strin selection.start_dragging(); selection.scale(scaling_factor * 0.01, transformation_type); - wxGetApp().plater()->canvas3D()->do_scale(snapshot_name); + wxGetApp().plater()->canvas3D()->do_scale(L("Set Scale")); } void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value) @@ -837,13 +833,13 @@ void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any double new_value = boost::any_cast(m_og->get_value(opt_key)); if (boost::starts_with(opt_key, "position_")) - change_position_value(axis, new_value, L("Set Position")); + change_position_value(axis, new_value); else if (boost::starts_with(opt_key, "rotation_")) - change_rotation_value(axis, new_value, L("Set Orientation")); + change_rotation_value(axis, new_value); else if (boost::starts_with(opt_key, "scale_")) - change_scale_value(axis, new_value, L("Set Scale")); + change_scale_value(axis, new_value); else if (boost::starts_with(opt_key, "size_")) - change_size_value(axis, new_value, L("Set Scale")); + change_size_value(axis, new_value); } void ObjectManipulation::on_fill_empty_value(const std::string& opt_key) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index bda7aa55f..e4e190b5b 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -135,11 +135,11 @@ private: void update_mirror_buttons_visibility(); // change values - void change_position_value(int axis, double value, const std::string& snapshot_name); - void change_rotation_value(int axis, double value, const std::string& snapshot_name); - void change_scale_value(int axis, double value, const std::string& snapshot_name); - void change_size_value(int axis, double value, const std::string& snapshot_name); - void do_scale(int axis, const Vec3d &scale, const std::string& snapshot_name) const; + void change_position_value(int axis, double value); + void change_rotation_value(int axis, double value); + void change_scale_value(int axis, double value); + void change_size_value(int axis, double value); + void do_scale(int axis, const Vec3d &scale) const; void on_change(t_config_option_key opt_key, const boost::any& value); void on_fill_empty_value(const std::string& opt_key); From 98e08e356feee4c74de978cc9c30bd3806adfb49 Mon Sep 17 00:00:00 2001 From: Lukas Matena Date: Thu, 1 Aug 2019 12:27:32 +0200 Subject: [PATCH 2/3] Changed snapshot names for reset scale/reset rotation/drop to bed functions (it's done a bit simpler this time) --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index a4aa3c6d8..40f27d7c0 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -286,6 +286,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn, wxBU_EXACTFIT); btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { + Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Reset scale"))); change_scale_value(0, 100.); change_scale_value(1, 100.); change_scale_value(2, 100.); @@ -323,7 +324,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); selection.synchronize_unselected_volumes(); // Copy rotation values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. - canvas->do_rotate(L("Set Rotation")); + canvas->do_rotate(L("Reset Rotation")); UpdateAndShow(true); }); @@ -350,6 +351,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : const Geometry::Transformation& instance_trafo = volume->get_instance_transformation(); Vec3d diff = m_cache.position - instance_trafo.get_matrix(true).inverse() * Vec3d(0., 0., get_volume_min_z(volume)); + Plater::TakeSnapshot snapshot(wxGetApp().plater(), _(L("Drop to bed"))); change_position_value(0, diff.x()); change_position_value(1, diff.y()); change_position_value(2, diff.z()); From c2a43dc8644ad59ac5ee5647b18ee956de2d419d Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 1 Aug 2019 11:35:43 +0200 Subject: [PATCH 3/3] Mirroring buttons: Fixed scaling issues and ensured proper hiding on Win --- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 14 ++++++++----- src/slic3r/GUI/wxExtensions.cpp | 24 +++++++++++++++++++++-- src/slic3r/GUI/wxExtensions.hpp | 4 ++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 40f27d7c0..2bbf11170 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -210,6 +210,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : wxSize btn_size(em_unit(parent) * mirror_btn_width, em_unit(parent) * mirror_btn_width); auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_off", wxEmptyString, btn_size, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW); btn->SetToolTip(wxString::Format(_(L("Toggle %c axis mirroring")), (int)label)); + btn->SetBitmapDisabled_(m_mirror_bitmap_hidden); m_mirror_buttons[axis_idx].first = btn; m_mirror_buttons[axis_idx].second = mbShown; @@ -648,13 +649,13 @@ void ObjectManipulation::update_mirror_buttons_visibility() wxGetApp().CallAfter([this, new_states]{ for (int i=0; i<3; ++i) { if (new_states[i] != m_mirror_buttons[i].second) { - const wxBitmap* bmp; + const ScalableBitmap* bmp; switch (new_states[i]) { - case mbHidden : bmp = &m_mirror_bitmap_hidden.bmp(); m_mirror_buttons[i].first->Enable(false); break; - case mbShown : bmp = &m_mirror_bitmap_off.bmp(); m_mirror_buttons[i].first->Enable(true); break; - case mbActive : bmp = &m_mirror_bitmap_on.bmp(); m_mirror_buttons[i].first->Enable(true); break; + case mbHidden : bmp = &m_mirror_bitmap_hidden; m_mirror_buttons[i].first->Enable(false); break; + case mbShown : bmp = &m_mirror_bitmap_off; m_mirror_buttons[i].first->Enable(true); break; + case mbActive : bmp = &m_mirror_bitmap_on; m_mirror_buttons[i].first->Enable(true); break; } - m_mirror_buttons[i].first->SetBitmap(*bmp); + m_mirror_buttons[i].first->SetBitmap_(*bmp); m_mirror_buttons[i].second = new_states[i]; } } @@ -927,6 +928,9 @@ void ObjectManipulation::msw_rescale() m_reset_rotation_button->msw_rescale(); m_drop_to_bed_button->msw_rescale(); + for (int id = 0; id < 3; ++id) + m_mirror_buttons[id].first->msw_rescale(); + get_og()->msw_rescale(); } diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 0f8d3ce4e..a33b7248c 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -2966,6 +2966,13 @@ ScalableButton::ScalableButton( wxWindow * parent, #endif // __WXMSW__ SetBitmap(create_scaled_bitmap(parent, icon_name)); + + if (size != wxDefaultSize) + { + const int em = em_unit(parent); + m_width = size.x/em; + m_height= size.y/em; + } } @@ -2992,11 +2999,24 @@ void ScalableButton::SetBitmap_(const ScalableBitmap& bmp) m_current_icon_name = bmp.name(); } +void ScalableButton::SetBitmapDisabled_(const ScalableBitmap& bmp) +{ + SetBitmapDisabled(bmp.bmp()); + m_disabled_icon_name = bmp.name(); +} + void ScalableButton::msw_rescale() { - const wxBitmap bmp = create_scaled_bitmap(m_parent, m_current_icon_name); + SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name)); + if (!m_disabled_icon_name.empty()) + SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name)); - SetBitmap(bmp); + if (m_width > 0 || m_height>0) + { + const int em = em_unit(m_parent); + wxSize size(m_width * em, m_height * em); + SetMinSize(size); + } } diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 725f7c507..2a8d8fccf 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -904,12 +904,16 @@ public: ~ScalableButton() {} void SetBitmap_(const ScalableBitmap& bmp); + void SetBitmapDisabled_(const ScalableBitmap &bmp); void msw_rescale(); private: wxWindow* m_parent; std::string m_current_icon_name = ""; + std::string m_disabled_icon_name = ""; + int m_width {-1}; // should be multiplied to em_unit + int m_height{-1}; // should be multiplied to em_unit };