diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index eb79a705db..ff2d09cd73 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2069,6 +2069,11 @@ void GLCanvas3D::select_curr_plate_all() m_dirty = true; } +void GLCanvas3D::select_object_from_idx(std::vector& object_idxs) { + m_selection.add_object_from_idx(object_idxs); + m_dirty = true; +} + //BBS void GLCanvas3D::remove_curr_plate_all() { @@ -4738,6 +4743,13 @@ void GLCanvas3D::do_center() m_selection.center(); } +void GLCanvas3D::do_center_plate(const int plate_idx) { + if (m_model == nullptr) + return; + + m_selection.center_plate(plate_idx); +} + void GLCanvas3D::do_mirror(const std::string& snapshot_type) { if (m_model == nullptr) diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 8eb5158a09..a58d6f324c 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -876,6 +876,7 @@ public: //BBS void select_curr_plate_all(); + void select_object_from_idx(std::vector& object_idxs); void remove_curr_plate_all(); void update_plate_thumbnails(); @@ -941,6 +942,7 @@ public: void do_scale(const std::string& snapshot_type); void do_flatten(const Vec3d& normal, const std::string& snapshot_type); void do_center(); + void do_center_plate(const int plate_idx); void do_mirror(const std::string& snapshot_type); void update_gizmos_on_off_state(); diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index d92d99dd72..c1ce4ea351 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -124,6 +124,11 @@ void View3D::select_curr_plate_all() m_canvas->select_curr_plate_all(); } +void View3D::select_object_from_idx(std::vector& object_idxs) { + if (m_canvas != nullptr) + m_canvas->select_object_from_idx(object_idxs); +} + //BBS void View3D::remove_curr_plate_all() { @@ -155,6 +160,11 @@ void View3D::center_selected() m_canvas->do_center(); } +void View3D::center_selected_plate(const int plate_idx) { + if (m_canvas != nullptr) + m_canvas->do_center_plate(plate_idx); +} + void View3D::mirror_selection(Axis axis) { if (m_canvas != nullptr) diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index 88e1336640..2ce7e67ec1 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -58,12 +58,14 @@ public: //BBS void select_curr_plate_all(); + void select_object_from_idx(std::vector &object_idxs); void remove_curr_plate_all(); void select_all(); void deselect_all(); void delete_selected(); void center_selected(); + void center_selected_plate(const int plate_idx); void mirror_selection(Axis axis); bool is_layers_editing_enabled() const; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 92acce3e3e..538783035a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5780,13 +5780,31 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) auto idx = combo->get_filament_idx(); + // BBS:Save the plate parameters before switching + PartPlateList& old_plate_list = this->partplate_list; + PartPlate* old_plate = old_plate_list.get_selected_plate(); + Vec3d old_plate_pos = old_plate->get_center_origin(); + + // BBS: Save the model in the current platelist + std::vector > plate_object; + for (size_t i = 0; i < old_plate_list.get_plate_count(); ++i) { + PartPlate* plate = old_plate_list.get_plate(i); + std::vector obj_idxs; + for (int obj_idx = 0; obj_idx < model.objects.size(); obj_idx++) { + if (plate && plate->contain_instance(obj_idx, 0)) { + obj_idxs.emplace_back(obj_idx); + } + } + plate_object.emplace_back(obj_idxs); + } + //! Because of The MSW and GTK version of wxBitmapComboBox derived from wxComboBox, //! but the OSX version derived from wxOwnerDrawnCombo. //! So, to get selected string we do //! combo->GetString(combo->GetSelection()) //! instead of //! combo->GetStringSelection().ToUTF8().data()); - + std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, Preset::remove_suffix_modified(combo->GetString(selection).ToUTF8().data())); @@ -5826,6 +5844,21 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) * and for SLA presets they should be deleted */ wxGetApp().obj_list()->update_object_list_by_printer_technology(); + + // BBS:Model reset by plate center + PartPlateList& cur_plate_list = this->partplate_list; + PartPlate* cur_plate = cur_plate_list.get_curr_plate(); + Vec3d cur_plate_pos = cur_plate->get_center_origin(); + + if (old_plate_pos.x() != cur_plate_pos.x() || old_plate_pos.y() != cur_plate_pos.y()) { + for (int i = 0; i < plate_object.size(); ++i) { + view3D->select_object_from_idx(plate_object[i]); + this->sidebar->obj_list()->update_selections(); + view3D->center_selected_plate(i); + } + + view3D->deselect_all(); + } } #ifdef __WXMSW__ diff --git a/src/slic3r/GUI/Selection.cpp b/src/slic3r/GUI/Selection.cpp index c007703c7a..4cb8655abb 100644 --- a/src/slic3r/GUI/Selection.cpp +++ b/src/slic3r/GUI/Selection.cpp @@ -414,6 +414,22 @@ void Selection::add_curr_plate() this->set_bounding_boxes_dirty(); } +void Selection::add_object_from_idx(std::vector& object_idxs) { + if (!m_valid) + return; + + m_mode = Instance; + clear(); + + for (int obj_idx = 0; obj_idx < object_idxs.size(); obj_idx++) { + std::vector volume_idxs = get_volume_idxs_from_object(object_idxs[obj_idx]); + do_add_volumes(volume_idxs); + } + + update_type(); + this->set_bounding_boxes_dirty(); +} + void Selection::remove_curr_plate() { if (!m_valid) @@ -464,6 +480,20 @@ void Selection::center() return; } +void Selection::center_plate(const int plate_idx) { + + PartPlate* plate = wxGetApp().plater()->get_partplate_list().get_plate(plate_idx); + + + Vec3d src_pos = this->get_bounding_box().center(); + Vec3d tar_pos = plate->get_center_origin(); + Vec3d distance = Vec3d(tar_pos.x() - src_pos.x(), tar_pos.y() - src_pos.y(), 0); + + this->move_to_center(distance); + wxGetApp().plater()->get_view3D_canvas3D()->do_move(L("Move Object")); + return; +} + //BBS void Selection::set_printable(bool printable) { diff --git a/src/slic3r/GUI/Selection.hpp b/src/slic3r/GUI/Selection.hpp index bfee49bd2b..3c1a7b04de 100644 --- a/src/slic3r/GUI/Selection.hpp +++ b/src/slic3r/GUI/Selection.hpp @@ -260,9 +260,11 @@ public: //BBS void add_curr_plate(); + void add_object_from_idx(std::vector& object_idxs); void remove_curr_plate(); void clone(int numbers = 1); void center(); + void center_plate(const int plate_idx); void set_printable(bool printable); void add_all();