Fixed DnD for "Model part" volumes inside the object

Fixed volumes order inside the object
This commit is contained in:
YuSanka 2021-06-02 12:52:47 +02:00
parent 2d9953069a
commit 7eebd56b5f
7 changed files with 101 additions and 96 deletions

View file

@ -652,23 +652,10 @@ ModelVolume* ModelObject::add_volume(const TriangleMesh &mesh)
return v;
}
static void add_v_to_volumes(ModelVolumePtrs* volumes, ModelVolume* v)
{
if (volumes->empty() || v->type() >= volumes->back()->type())
volumes->push_back(v);
else {
for (int pos = volumes->size() - 1; pos >= 0; pos--)
if (v->type() >= (*volumes)[pos]->type()) {
volumes->insert(volumes->begin() + pos + 1, v);
break;
}
}
}
ModelVolume* ModelObject::add_volume(TriangleMesh &&mesh, ModelVolumeType type /*= ModelVolumeType::MODEL_PART*/)
{
ModelVolume* v = new ModelVolume(this, std::move(mesh), type);
add_v_to_volumes(&(this->volumes), v);
this->volumes.push_back(v);
v->center_geometry_after_creation();
this->invalidate_bounding_box();
return v;
@ -679,7 +666,7 @@ ModelVolume* ModelObject::add_volume(const ModelVolume &other, ModelVolumeType t
ModelVolume* v = new ModelVolume(this, other);
if (type != ModelVolumeType::INVALID && v->type() != type)
v->set_type(type);
add_v_to_volumes(&(this->volumes), v);
this->volumes.push_back(v);
// The volume should already be centered at this point of time when copying shared pointers of the triangle mesh and convex hull.
// v->center_geometry_after_creation();
// this->invalidate_bounding_box();
@ -728,6 +715,20 @@ void ModelObject::clear_volumes()
this->invalidate_bounding_box();
}
void ModelObject::sort_volumes(bool full_sort)
{
// sort volumes inside the object to order "Model Part, Negative Volume, Modifier, Support Blocker and Support Enforcer. "
if (full_sort)
std::stable_sort(volumes.begin(), volumes.end(), [](ModelVolume* vl, ModelVolume* vr) {
return vl->type() < vr->type();
});
// sort have to controll "place" of the support blockers/enforcers. But one of the model parts have to be on the first place.
else
std::stable_sort(volumes.begin(), volumes.end(), [](ModelVolume* vl, ModelVolume* vr) {
return vl->type() > ModelVolumeType::PARAMETER_MODIFIER && vl->type() < vr->type();
});
}
ModelInstance* ModelObject::add_instance()
{
ModelInstance* i = new ModelInstance(this);