diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 0024f60d7..fd4fa1953 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -933,13 +933,13 @@ private: void _update_gcode_volumes_visibility(const GCodePreviewData& preview_data); void _update_toolpath_volumes_outside_state(); void _show_warning_texture_if_needed(); - +public: void _on_move(); void _on_rotate(); void _on_scale(); void _on_flatten(); void _on_mirror(); - +private: // generates the legend texture in dependence of the current shown view type void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index d1c67f20d..73c004514 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -14,7 +14,7 @@ namespace Slic3r namespace GUI { -ObjectManipulation::ObjectManipulation(wxWindow* parent): +ObjectManipulation::ObjectManipulation(wxWindow* parent) : OG_Settings(parent, true) { m_og->set_name(_(L("Object Manipulation"))); @@ -35,6 +35,17 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): update_scale_values(); return; } + + std::string param; + std::copy(opt_key.begin(), opt_key.end() - 2, std::back_inserter(param)); + + if (param == "position") { + Vec3d displacement; + displacement(0) = boost::any_cast<double>(m_og->get_value("position_x")); + displacement(1) = boost::any_cast<double>(m_og->get_value("position_y")); + displacement(2) = boost::any_cast<double>(m_og->get_value("position_z")); + change_position_value(displacement); + } }; ConfigOptionDef def; @@ -248,6 +259,8 @@ void ObjectManipulation::reset_position_value() m_og->set_value("position_x", def_0); m_og->set_value("position_y", def_0); m_og->set_value("position_z", def_0); + + cache_position = { 0., 0., 0. }; } void ObjectManipulation::reset_rotation_value() @@ -324,6 +337,8 @@ void ObjectManipulation::update_position_value(const Vec3d& position) m_og->set_value("position_x", double_to_string(position(0), 2)); m_og->set_value("position_y", double_to_string(position(1), 2)); m_og->set_value("position_z", double_to_string(position(2), 2)); + + cache_position = position; } void ObjectManipulation::update_scale_value(const Vec3d& scaling_factor) @@ -371,5 +386,25 @@ void ObjectManipulation::update_rotation_value(const Vec3d& rotation) m_og->set_value("rotation_z", double_to_string(round_nearest(Geometry::rad2deg(rotation(2)), 0), 2)); } + +void ObjectManipulation::change_position_value(const Vec3d& position) +{ + Vec3d displacement(position - cache_position); + + auto canvas = _3DScene::get_canvas(wxGetApp().canvas3D()); + canvas->get_selection().start_dragging(); + canvas->get_selection().translate(displacement); + canvas->_on_move(); + + cache_position = position; +} + + + +void ObjectManipulation::print_cashe_value(const std::string& label, const Vec3d& value) +{ + std::cout << label << " => " << " X:" << value(0) << " Y:" << value(1) << " Z:" << value(2) << std::endl; +} + } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 29c5cfe53..2f016f46f 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -17,6 +17,10 @@ class ObjectManipulation : public OG_Settings // false -> uniform scale unit bool m_is_uniform_scale = false; // It indicates if scale is uniform + Vec3d cache_position { 0., 0., 0. }; + Vec3d cache_rotation { 0., 0., 0. }; + Vec3d cache_scale { 0., 0., 0. }; + public: ObjectManipulation(wxWindow* parent); ~ObjectManipulation() {} @@ -48,6 +52,13 @@ public: void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; } + + // change values + void change_position_value(const Vec3d& position); + + +private: + void print_cashe_value(const std::string& label, const Vec3d& value); }; }} diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b141b7a6b..fe00593e5 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -692,14 +692,15 @@ void Sidebar::update_objects_list_extruder_column(int extruders_count) void Sidebar::show_info_sizer() { if (!p->plater->is_single_full_object_selection() || - m_mode < ConfigMenuModeExpert ) { + m_mode < ConfigMenuModeExpert || + p->plater->model().objects.empty()) { p->object_info->Show(false); return; } int obj_idx = p->plater->get_selected_object_idx(); - const ModelObject* model_object = (*wxGetApp().model_objects())[obj_idx]; + const ModelObject* model_object = p->plater->model().objects[obj_idx]; // hack to avoid crash when deleting the last object on the bed if (model_object->volumes.empty()) {