Fixed DnD function for volumes inside the object in respect to the volume type

This commit is contained in:
YuSanka 2021-05-26 15:36:02 +02:00
parent 980ca195f5
commit b7769856d1
7 changed files with 106 additions and 28 deletions

View file

@ -126,6 +126,9 @@ void AppConfig::set_defaults()
if (get("color_mapinulation_panel").empty())
set("color_mapinulation_panel", "0");
if (get("order_volumes").empty())
set("order_volumes", "1");
}
else {
#ifdef _WIN32

View file

@ -652,19 +652,34 @@ ModelVolume* ModelObject::add_volume(const TriangleMesh &mesh)
return v;
}
ModelVolume* ModelObject::add_volume(TriangleMesh &&mesh)
static void add_v_to_volumes(ModelVolumePtrs* volumes, ModelVolume* v)
{
ModelVolume* v = new ModelVolume(this, std::move(mesh));
this->volumes.push_back(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);
v->center_geometry_after_creation();
this->invalidate_bounding_box();
return v;
}
ModelVolume* ModelObject::add_volume(const ModelVolume &other)
ModelVolume* ModelObject::add_volume(const ModelVolume &other, ModelVolumeType type /*= ModelVolumeType::MODEL_PART*/)
{
ModelVolume* v = new ModelVolume(this, other);
this->volumes.push_back(v);
if (v->type() != type)
v->set_type(type);
add_v_to_volumes(&(this->volumes), 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();

View file

@ -216,6 +216,16 @@ private:
friend class ModelObject;
};
// Declared outside of ModelVolume, so it could be forward declared.
enum class ModelVolumeType : int {
INVALID = -1,
MODEL_PART = 0,
NEGATIVE_VOLUME,
PARAMETER_MODIFIER,
SUPPORT_BLOCKER,
SUPPORT_ENFORCER,
};
// A printable object, possibly having multiple print volumes (each with its own set of parameters and materials),
// and possibly having multiple modifier volumes, each modifier volume with its set of parameters and materials.
// Each ModelObject may be instantiated mutliple times, each instance having different placement on the print bed,
@ -262,8 +272,8 @@ public:
const Model* get_model() const { return m_model; }
ModelVolume* add_volume(const TriangleMesh &mesh);
ModelVolume* add_volume(TriangleMesh &&mesh);
ModelVolume* add_volume(const ModelVolume &volume);
ModelVolume* add_volume(TriangleMesh &&mesh, ModelVolumeType type = ModelVolumeType::MODEL_PART);
ModelVolume* add_volume(const ModelVolume &volume, ModelVolumeType type = ModelVolumeType::MODEL_PART);
ModelVolume* add_volume(const ModelVolume &volume, TriangleMesh &&mesh);
void delete_volume(size_t idx);
void clear_volumes();
@ -482,16 +492,6 @@ private:
}
};
// Declared outside of ModelVolume, so it could be forward declared.
enum class ModelVolumeType : int {
INVALID = -1,
MODEL_PART = 0,
NEGATIVE_VOLUME,
PARAMETER_MODIFIER,
SUPPORT_BLOCKER,
SUPPORT_ENFORCER,
};
enum class EnforcerBlockerType : int8_t {
// Maximum is 3. The value is serialized in TriangleSelector into 2 bits!
NONE = 0,
@ -717,7 +717,7 @@ private:
// 1 -> is splittable
mutable int m_is_splittable{ -1 };
ModelVolume(ModelObject *object, const TriangleMesh &mesh) : m_mesh(new TriangleMesh(mesh)), m_type(ModelVolumeType::MODEL_PART), object(object)
ModelVolume(ModelObject *object, const TriangleMesh &mesh, ModelVolumeType type = ModelVolumeType::MODEL_PART) : m_mesh(new TriangleMesh(mesh)), m_type(type), object(object)
{
assert(this->id().valid());
assert(this->config.id().valid());
@ -731,8 +731,8 @@ private:
if (mesh.stl.stats.number_of_facets > 1)
calculate_convex_hull();
}
ModelVolume(ModelObject *object, TriangleMesh &&mesh, TriangleMesh &&convex_hull) :
m_mesh(new TriangleMesh(std::move(mesh))), m_convex_hull(new TriangleMesh(std::move(convex_hull))), m_type(ModelVolumeType::MODEL_PART), object(object) {
ModelVolume(ModelObject *object, TriangleMesh &&mesh, TriangleMesh &&convex_hull, ModelVolumeType type = ModelVolumeType::MODEL_PART) :
m_mesh(new TriangleMesh(std::move(mesh))), m_convex_hull(new TriangleMesh(std::move(convex_hull))), m_type(type), object(object) {
assert(this->id().valid());
assert(this->config.id().valid());
assert(this->supported_facets.id().valid());