Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate Current Plate With Objects (Second PR) #6710

Merged
merged 14 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ src/OrcaSlicer-doc/
/deps/DL_CACHE
**/.flatpak-builder/
resources/profiles/user/default
OrcaSlicer.code-workspace
*.code-workspace
16 changes: 16 additions & 0 deletions resources/images/plate_duplicate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions resources/images/plate_duplicate_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions resources/images/plate_duplicate_hover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions resources/images/plate_duplicate_hover_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions resources/images/toolbar_duplicate_plate.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions resources/images/toolbar_duplicate_plate_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/slic3r/GUI/GLCanvas3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ wxDEFINE_EVENT(EVT_GLCANVAS_PLATE_RIGHT_CLICK, RBtnPlateEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
//BBS: add arrange and orient event
// wxDEFINE_EVENT(EVT_GLCANVAS_DUPLICATE_PLATE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ARRANGE_PARTPLATE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ORIENT, SimpleEvent);
wxDEFINE_EVENT(EVT_GLCANVAS_ORIENT_PARTPLATE, SimpleEvent);
Expand Down Expand Up @@ -6241,6 +6242,9 @@ void GLCanvas3D::_switch_toolbars_icon_filename()
item = m_main_toolbar.get_item("addplate");
item->set_icon_filename(m_is_dark ? "toolbar_add_plate_dark.svg" : "toolbar_add_plate.svg");

item = m_main_toolbar.get_item("duplicateplate");
item->set_icon_filename(m_is_dark ? "toolbar_duplicate_plate_dark.svg" : "toolbar_duplicate_plate.svg");

item = m_main_toolbar.get_item("orient");
item->set_icon_filename(m_is_dark ? "toolbar_orient_dark.svg" : "toolbar_orient.svg");

Expand Down Expand Up @@ -6353,6 +6357,15 @@ bool GLCanvas3D::_init_main_toolbar()
if (!m_main_toolbar.add_item(item))
return false;

// item.name = "duplicateplate";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove these unused commented codes?
There are other commentted codes, let's remove them as well

// item.icon_filename = m_is_dark ? "toolbar_duplicate_plate_dark.svg" : "toolbar_duplicate_plate.svg";
// item.tooltip = _utf8(L("Duplicate current plate"));
// item.sprite_id++;
// item.left.action_callback = [this]() { if (m_canvas != nullptr) wxPostEvent(m_canvas, SimpleEvent(EVT_GLTOOLBAR_DUPLICATE_PLATE)); };
// item.enabling_callback = []()->bool {return wxGetApp().plater()->can_add_plate(); }; // we can use can_add_plate here...
// if (!m_main_toolbar.add_item(item))
// return false;

item.name = "orient";
item.icon_filename = m_is_dark ? "toolbar_orient_dark.svg" : "toolbar_orient.svg";
item.tooltip = _utf8(L("Auto orient"));
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GLCanvas3D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ wxDECLARE_EVENT(EVT_GLCANVAS_PLATE_RIGHT_CLICK, RBtnPlateEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
//BBS: add arrange and orient event
// wxDECLARE_EVENT(EVT_GLCANVAS_DUPLICATE_PLATE, SimpleEvent);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove these unused commented codes?

wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE_PARTPLATE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ORIENT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ORIENT_PARTPLATE, SimpleEvent);
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GLToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ wxDEFINE_EVENT(EVT_GLTOOLBAR_DELETE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_DELETE_ALL, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_ADD_PLATE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_DEL_PLATE, SimpleEvent);
// wxDEFINE_EVENT(EVT_GLTOOLBAR_DUPLICATE_PLATE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_ORIENT, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_ARRANGE, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent);
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/GLToolbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ wxDECLARE_EVENT(EVT_GLTOOLBAR_DELETE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_DELETE_ALL, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_ADD_PLATE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_DEL_PLATE, SimpleEvent);
// wxDECLARE_EVENT(EVT_GLTOOLBAR_DUPLICATE_PLATE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_ORIENT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_ARRANGE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent);
Expand Down
13 changes: 13 additions & 0 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2433,6 +2433,12 @@ void MainFrame::init_menubar_as_editor()
},
"menu_remove", nullptr, [this](){return can_clone(); }, this);
editMenu->AppendSeparator();
append_menu_item(editMenu, wxID_ANY, _L("Duplicate Current Plate"),
_L("Duplicate the current plate"),[this](wxCommandEvent&) {
m_plater->duplicate_plate();
},
"menu_remove", nullptr, [this](){return true;}, this);
editMenu->AppendSeparator();
#else
// BBS undo
append_menu_item(editMenu, wxID_ANY, _L("Undo") + "\t" + ctrl + "Z",
Expand Down Expand Up @@ -2530,6 +2536,13 @@ void MainFrame::init_menubar_as_editor()
},
"", nullptr, [this](){return can_clone(); }, this);
editMenu->AppendSeparator();
append_menu_item(editMenu, wxID_ANY, _L("Duplicate Current Plate"),
_L("Duplicate the current plate"),[this, handle_key_event](wxCommandEvent&) {
m_plater->duplicate_plate();
},
"", nullptr, [this](){return true;}, this);
editMenu->AppendSeparator();

#endif

// BBS Select All
Expand Down
36 changes: 34 additions & 2 deletions src/slic3r/GUI/PartPlate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@ bool PartPlate::set_shape(const Pointfs& shape, const Pointfs& exclude_areas, Ve
calc_vertex_for_number(0, false, m_plate_idx_icon);
if (m_plater) {
// calc vertex for plate name
generate_plate_name_texture();
generate_plate_name_texture();
}
}

Expand Down Expand Up @@ -3654,6 +3654,38 @@ int PartPlateList::create_plate(bool adjust_position)
return new_index;
}


int PartPlateList::duplicate_plate(int index)
{
// create a new plate
int new_plate_index = create_plate(true);
PartPlate* old_plate = NULL;
PartPlate* new_plate = NULL;
old_plate = get_plate(index);
new_plate = get_plate(new_plate_index);

// get the offset between plate centers
Vec3d plate_to_plate_offset = new_plate->m_origin - old_plate->m_origin;

// iterate over all the objects in this plate
ModelObjectPtrs obj_ptrs = old_plate->get_objects_on_this_plate();
for (ModelObject* object : obj_ptrs){
// copy and move the object to the same relative position in the new plate
ModelObject* object_copy = m_model->add_object(*object);
int new_obj_id = new_plate->m_model->objects.size() - 1;
// go over the instances and pair with the object
for (size_t new_instance_id = 0; new_instance_id < object_copy->instances.size(); new_instance_id++){
new_plate->obj_to_instance_set.emplace(std::pair(new_obj_id, new_instance_id));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": duplicate object into plate: index_pair [%1%,%2%], obj_id %3%") % new_obj_id % new_instance_id % object_copy->id().id;
}
}
new_plate->translate_all_instance(plate_to_plate_offset);
// update the plates
wxGetApp().obj_list()->reload_all_plates();
return new_plate_index;
}


//destroy print's objects and results
int PartPlateList::destroy_print(int print_index)
{
Expand Down Expand Up @@ -4781,7 +4813,7 @@ void PartPlateList::render(const Transform3d& view_matrix, const Transform3d& pr
if (m_is_dark != last_dark_mode_status) {
last_dark_mode_status = m_is_dark;
generate_icon_textures();
}else if(m_del_texture.get_id() == 0)
} else if(m_del_texture.get_id() == 0)
generate_icon_textures();
for (it = m_plate_list.begin(); it != m_plate_list.end(); it++) {
int current_index = (*it)->get_index();
Expand Down
3 changes: 3 additions & 0 deletions src/slic3r/GUI/PartPlate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,9 @@ class PartPlateList : public ObjectBase
//create an empty plate and return its index
int create_plate(bool adjust_position = true);

// duplicate plate
int duplicate_plate(int index);

//destroy print which has the index of print_index
int destroy_print(int print_index);

Expand Down
21 changes: 17 additions & 4 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2951,19 +2951,19 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
view3D_canvas->Bind(EVT_GLCANVAS_PLATE_RIGHT_CLICK, &priv::on_plate_right_click, this);
view3D_canvas->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent& evt) {
//BBS arrage from EVT set default state.
//BBS arrange from EVT set default state.
this->q->set_prepare_state(Job::PREPARE_STATE_DEFAULT);
this->q->arrange(); });
view3D_canvas->Bind(EVT_GLCANVAS_ARRANGE_PARTPLATE, [this](SimpleEvent& evt) {
//BBS arrage from EVT set default state.
//BBS arrange from EVT set default state.
this->q->set_prepare_state(Job::PREPARE_STATE_MENU);
this->q->arrange(); });
view3D_canvas->Bind(EVT_GLCANVAS_ORIENT, [this](SimpleEvent& evt) {
//BBS oriant from EVT set default state.
//BBS orient from EVT set default state.
this->q->set_prepare_state(Job::PREPARE_STATE_DEFAULT);
this->q->orient(); });
view3D_canvas->Bind(EVT_GLCANVAS_ORIENT_PARTPLATE, [this](SimpleEvent& evt) {
//BBS oriant from EVT set default state.
//BBS orient from EVT set default state.
this->q->set_prepare_state(Job::PREPARE_STATE_MENU);
this->q->orient(); });
//BBS
Expand Down Expand Up @@ -13997,6 +13997,19 @@ int Plater::select_plate_by_hover_id(int hover_id, bool right_click, bool isModi
return ret;
}

int Plater::duplicate_plate(int plate_index)
{
int index = plate_index, ret;
if (plate_index == -1)
index = p->partplate_list.get_curr_plate_index();

ret = p->partplate_list.duplicate_plate(index);

//need to call update
update();
return ret;
}

//BBS: delete the plate, index= -1 means the current plate
int Plater::delete_plate(int plate_index)
{
Expand Down
1 change: 1 addition & 0 deletions src/slic3r/GUI/Plater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ class Plater: public wxPanel
int select_plate_by_hover_id(int hover_id, bool right_click = false, bool isModidyPlateName = false);
//BBS: delete the plate, index= -1 means the current plate
int delete_plate(int plate_index = -1);
int duplicate_plate(int plate_index = -1);
//BBS: select the sliced plate by index
int select_sliced_plate(int plate_index);
//BBS: set bed positions
Expand Down