Skip to content

Commit

Permalink
Avoid code duplication when naming objects after split
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmatena committed Feb 8, 2021
1 parent b85480c commit eaa80df
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/PrusaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,7 @@ int CLI::run(int argc, char **argv)
size_t num_objects = model.objects.size();
for (size_t i = 0; i < num_objects; ++ i) {
ModelObjectPtrs new_objects;
ModelObject* front = model.objects.front();
front->split(&new_objects);
unsigned int counter = 1;
for (ModelObject* m : new_objects)
m->name = front->name + "_" + std::to_string(counter++);
model.objects.front()->split(&new_objects);
model.delete_object(size_t(0));
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,7 @@ void ModelObject::split(ModelObjectPtrs* new_objects)

ModelVolume* volume = this->volumes.front();
TriangleMeshPtrs meshptrs = volume->mesh().split();
size_t counter = 1;
for (TriangleMesh *mesh : meshptrs) {

// FIXME: crashes if not satisfied
Expand All @@ -1291,7 +1292,8 @@ void ModelObject::split(ModelObjectPtrs* new_objects)

// XXX: this seems to be the only real usage of m_model, maybe refactor this so that it's not needed?
ModelObject* new_object = m_model->add_object();
new_object->name = this->name;
new_object->name = this->name + (meshptrs.size() > 1 ? "_" + std::to_string(counter++) : "");

// Don't copy the config's ID.
new_object->config.assign_config(this->config);
assert(new_object->config.id().valid());
Expand Down
4 changes: 0 additions & 4 deletions src/slic3r/GUI/Plater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2881,10 +2881,6 @@ void Plater::priv::split_object()
{
Plater::TakeSnapshot snapshot(q, _L("Split to Objects"));

unsigned int counter = 1;
for (ModelObject* m : new_objects)
m->name = current_model_object->name + "_" + std::to_string(counter++);

remove(obj_idx);

// load all model objects at once, otherwise the plate would be rearranged after each one
Expand Down

0 comments on commit eaa80df

Please sign in to comment.