Skip to content

Commit 7c12f6b

Browse files
committed
feat: add object instance controls
(cherry picked from commit 1303a53)
1 parent ee03ea9 commit 7c12f6b

3 files changed

Lines changed: 49 additions & 13 deletions

File tree

src/slic3r/GUI/GUI_Factories.cpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,11 +1246,53 @@ void MenuFactory::create_default_menu()
12461246
[]() { return plater()->is_view3D_shown(); }, [this]() { return plater()->are_view3D_object_labels_shown(); }, m_parent);
12471247
}
12481248

1249+
void MenuFactory::append_menu_items_instance_manipulation(wxMenu* menu)
1250+
{
1251+
const MenuType type = menu == &m_object_menu ? mtObjectFFF : mtObjectSLA;
1252+
1253+
items_increase[type] = append_menu_item(
1254+
menu,
1255+
wxID_ANY,
1256+
_L("Add instance"),
1257+
_L("Add one more instance of the selected object"),
1258+
[](wxCommandEvent&) { plater()->increase_instances(); },
1259+
"",
1260+
nullptr,
1261+
[]() { return plater()->can_increase_instances(); },
1262+
m_parent);
1263+
1264+
items_decrease[type] = append_menu_item(
1265+
menu,
1266+
wxID_ANY,
1267+
_L("Remove instance"),
1268+
_L("Remove one instance of the selected object"),
1269+
[](wxCommandEvent&) { plater()->decrease_instances(); },
1270+
"",
1271+
nullptr,
1272+
[]() { return plater()->can_decrease_instances(); },
1273+
m_parent);
1274+
1275+
items_set_number_of_copies[type] = append_menu_item(
1276+
menu,
1277+
wxID_ANY,
1278+
_L("Set number of instances") + dots,
1279+
_L("Change the number of instances of the selected object"),
1280+
[](wxCommandEvent&) { plater()->set_number_of_copies(); },
1281+
"",
1282+
nullptr,
1283+
[]() {
1284+
return plater()->can_increase_instances() ||
1285+
plater()->can_decrease_instances();
1286+
},
1287+
m_parent);
1288+
1289+
menu->AppendSeparator();
1290+
}
1291+
12491292
void MenuFactory::create_common_object_menu(wxMenu* menu)
12501293
{
12511294
append_menu_item_rename(menu);
1252-
// BBS
1253-
//append_menu_items_instance_manipulation(menu);
1295+
append_menu_items_instance_manipulation(menu);
12541296
// Delete menu was moved to be after +/- instace to make it more difficult to be selected by mistake.
12551297
append_menu_item_delete(menu);
12561298
//append_menu_item_instance_to_object(menu);
@@ -1292,6 +1334,7 @@ void MenuFactory::create_object_menu()
12921334

12931335
void MenuFactory::create_bbl_object_menu()
12941336
{
1337+
append_menu_items_instance_manipulation(&m_object_menu);
12951338
append_menu_item_fill_bed(&m_object_menu);
12961339
// Object Clone
12971340
append_menu_item_clone(&m_object_menu);

src/slic3r/GUI/GUI_Factories.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class MenuFactory
166166
void append_menu_item_edit_text(wxMenu *menu);
167167
void append_menu_item_edit_svg(wxMenu *menu);
168168

169-
//void append_menu_items_instance_manipulation(wxMenu *menu);
169+
void append_menu_items_instance_manipulation(wxMenu *menu);
170170
//void update_menu_items_instance_manipulation(MenuType type);
171171
//BBS add bbl menu item
172172
void append_menu_item_clone(wxMenu* menu);

src/slic3r/GUI/Plater.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20265,8 +20265,6 @@ void Plater::remove_selected()
2026520265

2026620266
void Plater::increase_instances(size_t num)
2026720267
{
20268-
// BBS
20269-
#if 0
2027020268
if (! can_increase_instances()) { return; }
2027120269

2027220270
Plater::TakeSnapshot snapshot(this, "Increase Instances");
@@ -20299,13 +20297,10 @@ void Plater::increase_instances(size_t num)
2029920297

2030020298
p->selection_changed();
2030120299
this->p->schedule_background_process();
20302-
#endif
2030320300
}
2030420301

2030520302
void Plater::decrease_instances(size_t num)
2030620303
{
20307-
// BBS
20308-
#if 0
2030920304
if (! can_decrease_instances()) { return; }
2031020305

2031120306
Plater::TakeSnapshot snapshot(this, "Decrease Instances");
@@ -20322,14 +20317,14 @@ void Plater::decrease_instances(size_t num)
2032220317
}
2032320318
else {
2032420319
remove(obj_idx);
20320+
return;
2032520321
}
2032620322

2032720323
if (!model_object->instances.empty())
2032820324
p->get_selection().add_instance(obj_idx, (int)model_object->instances.size() - 1);
2032920325

2033020326
p->selection_changed();
2033120327
this->p->schedule_background_process();
20332-
#endif
2033320328
}
2033420329

2033520330
static long GetNumberFromUser( const wxString& msg,
@@ -20360,13 +20355,11 @@ void Plater::set_number_of_copies(/*size_t num*/)
2036020355

2036120356
ModelObject* model_object = p->model.objects[obj_idx];
2036220357

20363-
const int num = GetNumberFromUser( " ", _L("Number of copies:"),
20364-
_L("Copies of the selected object"), model_object->instances.size(), 0, 1000, this );
20358+
const int num = GetNumberFromUser( " ", _L("Number of instances:"),
20359+
_L("Instances of the selected object"), model_object->instances.size(), 1, 1000, this );
2036520360
if (num < 0)
2036620361
return;
2036720362

20368-
Plater::TakeSnapshot snapshot(this, (boost::format("Set numbers of copies to %1%")%num).str());
20369-
2037020363
int diff = num - (int)model_object->instances.size();
2037120364
if (diff > 0)
2037220365
increase_instances(diff);

0 commit comments

Comments
 (0)