From b852a7113f8926043cd7c49691b5b96768de1b32 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Thu, 17 Apr 2025 09:36:48 +0800 Subject: [PATCH] FIX:revert offset when exit ObjColorDialog jira: github 6344 Change-Id: Ia574876aa24fde7c7b958b02d928d1aef6f0633f --- src/slic3r/GUI/ObjColorDialog.cpp | 15 +++++++++++---- src/slic3r/GUI/ObjColorDialog.hpp | 4 +++- src/slic3r/GUI/Plater.cpp | 3 ++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/ObjColorDialog.cpp b/src/slic3r/GUI/ObjColorDialog.cpp index fcd284fc2..679693c0c 100644 --- a/src/slic3r/GUI/ObjColorDialog.cpp +++ b/src/slic3r/GUI/ObjColorDialog.cpp @@ -236,7 +236,7 @@ ObjColorDialog::ObjColorDialog(wxWindow *parent, Slic3r::ObjDialogInOut &in_out, EndModal(wxCANCEL); return; } - m_panel_ObjColor->clear_instance(); + m_panel_ObjColor->clear_instance_and_revert_offset(); m_panel_ObjColor->send_new_filament_to_ui(); EndModal(wxID_OK); }, wxID_OK); @@ -360,9 +360,11 @@ ObjColorPanel::ObjColorPanel(wxWindow *parent, Slic3r::ObjDialogInOut &in_out, c auto mo = m_obj_in_out.model->objects[0]; mo->add_instance(); auto mv = mo->volumes[0]; + m_thumbnail_offset = Slic3r::Vec3d::Zero(); auto box = mo->bounding_box(); if (box.min.x() < 0 || box.min.y() < 0 || box.min.z() < 0) { - mv->translate(box.min.x() < 0 ? -box.min.x() : 0, box.min.y() < 0 ? -box.min.y() : 0, box.min.z() < 0 ? -box.min.z() : 0); + m_thumbnail_offset = Slic3r::Vec3d(box.min.x() < 0 ? -box.min.x() : 0, box.min.y() < 0 ? -box.min.y() : 0, box.min.z() < 0 ? -box.min.z() : 0); + mv->translate(m_thumbnail_offset); } } @@ -521,7 +523,7 @@ void ObjColorPanel::cancel_paint_color() { m_filament_ids.clear(); auto mo = m_obj_in_out.model->objects[0]; mo->config.set("extruder", 1); - clear_instance(); + clear_instance_and_revert_offset(); auto mv = mo->volumes[0]; mv->mmu_segmentation_facets.reset(); mv->config.set("extruder", 1); @@ -934,10 +936,15 @@ void ObjColorPanel::set_view_angle_type(int value) } -void ObjColorPanel::clear_instance() +void ObjColorPanel::clear_instance_and_revert_offset() { auto mo = m_obj_in_out.model->objects[0]; mo->clear_instances(); + auto mv = mo->volumes[0]; + auto box = mo->bounding_box(); + if (!m_thumbnail_offset.isApprox(Slic3r::Vec3d::Zero())) { + mv->translate(-m_thumbnail_offset); + } } bool ObjColorPanel::do_show(bool show) { diff --git a/src/slic3r/GUI/ObjColorDialog.hpp b/src/slic3r/GUI/ObjColorDialog.hpp index c89894e56..bac3a8051 100644 --- a/src/slic3r/GUI/ObjColorDialog.hpp +++ b/src/slic3r/GUI/ObjColorDialog.hpp @@ -36,7 +36,7 @@ public: void set_layout_callback(LayoutChanggeCallback); void do_layout_callback(); bool do_show(bool show); - void clear_instance(); + void clear_instance_and_revert_offset(); private: wxBoxSizer *create_approximate_match_btn_sizer(wxWindow *parent); @@ -105,6 +105,8 @@ private: bool m_is_add_filament{false}; unsigned char& m_first_extruder_id; std::vector &m_filament_ids; + + Slic3r::Vec3d m_thumbnail_offset; }; class ObjColorDialog : public Slic3r::GUI::DPIDialog diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c7be48ed4..9c27ec59b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5876,7 +5876,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ int model_idx = 0; for (ModelObject *model_object : model.objects) { - if (!type_3mf && !type_any_amf) model_object->center_around_origin(false); + if (!type_3mf && !type_any_amf) + model_object->center_around_origin(false); // BBS BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ":" << __LINE__ << boost::format("import 3mf IMPORT_LOAD_MODEL_OBJECTS \n");