This commit is contained in:
Enrico Turri 2019-08-01 11:01:26 +02:00
commit 5f89414501
2 changed files with 30 additions and 26 deletions

View file

@ -286,9 +286,11 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
auto sizer = new wxBoxSizer(wxHORIZONTAL); auto sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(btn, wxBU_EXACTFIT); sizer->Add(btn, wxBU_EXACTFIT);
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) { btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent &e) {
change_scale_value(0, 100.); wxGetApp().plater()->take_snapshot(_(L("Reset scale")));
change_scale_value(1, 100.); // the empty strings prevent taking another three snapshots
change_scale_value(2, 100.); change_scale_value(0, 100., std::string());
change_scale_value(1, 100., std::string());
change_scale_value(2, 100., std::string());
}); });
return sizer; return sizer;
}; };
@ -323,7 +325,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL); selection.synchronize_unselected_instances(Selection::SYNC_ROTATION_GENERAL);
selection.synchronize_unselected_volumes(); selection.synchronize_unselected_volumes();
// Copy rotation values from GLVolumes into Model (ModelInstance / ModelVolume), trigger background processing. // 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); UpdateAndShow(true);
}); });
@ -350,9 +352,11 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
const Geometry::Transformation& instance_trafo = volume->get_instance_transformation(); 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)); Vec3d diff = m_cache.position - instance_trafo.get_matrix(true).inverse() * Vec3d(0., 0., get_volume_min_z(volume));
change_position_value(0, diff.x()); // Take an undo/redo snapshot and prevent change_position_value from doing it three times.
change_position_value(1, diff.y()); wxGetApp().plater()->take_snapshot(_(L("Drop to bed")));
change_position_value(2, diff.z()); change_position_value(0, diff.x(), std::string());
change_position_value(1, diff.y(), std::string());
change_position_value(2, diff.z(), std::string());
} }
}); });
return sizer; return sizer;
@ -697,7 +701,7 @@ void ObjectManipulation::reset_settings_value()
// m_dirty = true; // m_dirty = true;
} }
void ObjectManipulation::change_position_value(int axis, double value) void ObjectManipulation::change_position_value(int axis, double value, const std::string& snapshot_name)
{ {
if (std::abs(m_cache.position_rounded(axis) - value) < EPSILON) if (std::abs(m_cache.position_rounded(axis) - value) < EPSILON)
return; return;
@ -709,14 +713,14 @@ void ObjectManipulation::change_position_value(int axis, double value)
Selection& selection = canvas->get_selection(); Selection& selection = canvas->get_selection();
selection.start_dragging(); selection.start_dragging();
selection.translate(position - m_cache.position, selection.requires_local_axes()); selection.translate(position - m_cache.position, selection.requires_local_axes());
canvas->do_move(L("Set Position")); canvas->do_move(snapshot_name);
m_cache.position = position; m_cache.position = position;
m_cache.position_rounded(axis) = DBL_MAX; m_cache.position_rounded(axis) = DBL_MAX;
this->UpdateAndShow(true); this->UpdateAndShow(true);
} }
void ObjectManipulation::change_rotation_value(int axis, double value) void ObjectManipulation::change_rotation_value(int axis, double value, const std::string& snapshot_name)
{ {
if (std::abs(m_cache.rotation_rounded(axis) - value) < EPSILON) if (std::abs(m_cache.rotation_rounded(axis) - value) < EPSILON)
return; return;
@ -740,14 +744,14 @@ void ObjectManipulation::change_rotation_value(int axis, double value)
selection.rotate( selection.rotate(
(M_PI / 180.0) * (transformation_type.absolute() ? rotation : rotation - m_cache.rotation), (M_PI / 180.0) * (transformation_type.absolute() ? rotation : rotation - m_cache.rotation),
transformation_type); transformation_type);
canvas->do_rotate(L("Set Orientation")); canvas->do_rotate(snapshot_name);
m_cache.rotation = rotation; m_cache.rotation = rotation;
m_cache.rotation_rounded(axis) = DBL_MAX; m_cache.rotation_rounded(axis) = DBL_MAX;
this->UpdateAndShow(true); this->UpdateAndShow(true);
} }
void ObjectManipulation::change_scale_value(int axis, double value) void ObjectManipulation::change_scale_value(int axis, double value, const std::string& snapshot_name)
{ {
if (std::abs(m_cache.scale_rounded(axis) - value) < EPSILON) if (std::abs(m_cache.scale_rounded(axis) - value) < EPSILON)
return; return;
@ -755,7 +759,7 @@ void ObjectManipulation::change_scale_value(int axis, double value)
Vec3d scale = m_cache.scale; Vec3d scale = m_cache.scale;
scale(axis) = value; scale(axis) = value;
this->do_scale(axis, scale); this->do_scale(axis, scale, snapshot_name);
m_cache.scale = scale; m_cache.scale = scale;
m_cache.scale_rounded(axis) = DBL_MAX; m_cache.scale_rounded(axis) = DBL_MAX;
@ -763,7 +767,7 @@ void ObjectManipulation::change_scale_value(int axis, double value)
} }
void ObjectManipulation::change_size_value(int axis, double value) void ObjectManipulation::change_size_value(int axis, double value, const std::string& snapshot_name)
{ {
if (std::abs(m_cache.size_rounded(axis) - value) < EPSILON) if (std::abs(m_cache.size_rounded(axis) - value) < EPSILON)
return; return;
@ -781,14 +785,14 @@ void ObjectManipulation::change_size_value(int axis, double value)
selection.get_unscaled_instance_bounding_box().size() : 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(); 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))); this->do_scale(axis, 100. * Vec3d(size(0) / ref_size(0), size(1) / ref_size(1), size(2) / ref_size(2)), snapshot_name);
m_cache.size = size; m_cache.size = size;
m_cache.size_rounded(axis) = DBL_MAX; m_cache.size_rounded(axis) = DBL_MAX;
this->UpdateAndShow(true); this->UpdateAndShow(true);
} }
void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const void ObjectManipulation::do_scale(int axis, const Vec3d &scale, const std::string& snapshot_name) const
{ {
Selection& selection = wxGetApp().plater()->canvas3D()->get_selection(); Selection& selection = wxGetApp().plater()->canvas3D()->get_selection();
Vec3d scaling_factor = scale; Vec3d scaling_factor = scale;
@ -805,7 +809,7 @@ void ObjectManipulation::do_scale(int axis, const Vec3d &scale) const
selection.start_dragging(); selection.start_dragging();
selection.scale(scaling_factor * 0.01, transformation_type); selection.scale(scaling_factor * 0.01, transformation_type);
wxGetApp().plater()->canvas3D()->do_scale(L("Set Scale")); wxGetApp().plater()->canvas3D()->do_scale(snapshot_name);
} }
void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value) void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any& value)
@ -833,13 +837,13 @@ void ObjectManipulation::on_change(t_config_option_key opt_key, const boost::any
double new_value = boost::any_cast<double>(m_og->get_value(opt_key)); double new_value = boost::any_cast<double>(m_og->get_value(opt_key));
if (boost::starts_with(opt_key, "position_")) if (boost::starts_with(opt_key, "position_"))
change_position_value(axis, new_value); change_position_value(axis, new_value, L("Set Position"));
else if (boost::starts_with(opt_key, "rotation_")) else if (boost::starts_with(opt_key, "rotation_"))
change_rotation_value(axis, new_value); change_rotation_value(axis, new_value, L("Set Orientation"));
else if (boost::starts_with(opt_key, "scale_")) else if (boost::starts_with(opt_key, "scale_"))
change_scale_value(axis, new_value); change_scale_value(axis, new_value, L("Set Scale"));
else if (boost::starts_with(opt_key, "size_")) else if (boost::starts_with(opt_key, "size_"))
change_size_value(axis, new_value); change_size_value(axis, new_value, L("Set Scale"));
} }
void ObjectManipulation::on_fill_empty_value(const std::string& opt_key) void ObjectManipulation::on_fill_empty_value(const std::string& opt_key)

View file

@ -135,11 +135,11 @@ private:
void update_mirror_buttons_visibility(); void update_mirror_buttons_visibility();
// change values // change values
void change_position_value(int axis, double value); void change_position_value(int axis, double value, const std::string& snapshot_name);
void change_rotation_value(int axis, double value); void change_rotation_value(int axis, double value, const std::string& snapshot_name);
void change_scale_value(int axis, double value); void change_scale_value(int axis, double value, const std::string& snapshot_name);
void change_size_value(int axis, double value); void change_size_value(int axis, double value, const std::string& snapshot_name);
void do_scale(int axis, const Vec3d &scale) const; void do_scale(int axis, const Vec3d &scale, const std::string& snapshot_name) const;
void on_change(t_config_option_key opt_key, const boost::any& value); void on_change(t_config_option_key opt_key, const boost::any& value);
void on_fill_empty_value(const std::string& opt_key); void on_fill_empty_value(const std::string& opt_key);