Merge branch 'master' into tm_arrange_selection

This commit is contained in:
tamasmeszaros 2019-07-17 17:25:31 +02:00
commit a695dec51a
185 changed files with 9235 additions and 5047 deletions
src/libslic3r

View file

@ -23,21 +23,6 @@ namespace Slic3r {
unsigned int Model::s_auto_extruder_id = 1;
size_t ModelBase::s_last_id = 0;
// Unique object / instance ID for the wipe tower.
ModelID wipe_tower_object_id()
{
static ModelBase mine;
return mine.id();
}
ModelID wipe_tower_instance_id()
{
static ModelBase mine;
return mine.id();
}
Model& Model::assign_copy(const Model &rhs)
{
this->copy_id(rhs);
@ -88,6 +73,19 @@ void Model::assign_new_unique_ids_recursive()
model_object->assign_new_unique_ids_recursive();
}
void Model::update_links_bottom_up_recursive()
{
for (std::pair<const t_model_material_id, ModelMaterial*> &kvp : this->materials)
kvp.second->set_model(this);
for (ModelObject *model_object : this->objects) {
model_object->set_model(this);
for (ModelInstance *model_instance : model_object->instances)
model_instance->set_model_object(model_object);
for (ModelVolume *model_volume : model_object->volumes)
model_volume->set_model_object(model_object);
}
}
Model Model::read_from_file(const std::string &input_file, DynamicPrintConfig *config, bool add_default_instances)
{
Model model;
@ -222,7 +220,7 @@ bool Model::delete_object(ModelObject* object)
return false;
}
bool Model::delete_object(ModelID id)
bool Model::delete_object(ObjectID id)
{
if (id.id != 0) {
size_t idx = 0;
@ -633,14 +631,18 @@ ModelObject::~ModelObject()
// maintains the m_model pointer
ModelObject& ModelObject::assign_copy(const ModelObject &rhs)
{
this->copy_id(rhs);
assert(this->id().invalid() || this->id() == rhs.id());
assert(this->config.id().invalid() || this->config.id() == rhs.config.id());
this->copy_id(rhs);
this->name = rhs.name;
this->input_file = rhs.input_file;
// Copies the config's ID
this->config = rhs.config;
assert(this->config.id() == rhs.config.id());
this->sla_support_points = rhs.sla_support_points;
this->sla_points_status = rhs.sla_points_status;
this->layer_height_ranges = rhs.layer_height_ranges;
this->layer_config_ranges = rhs.layer_config_ranges; // #ys_FIXME_experiment
this->layer_height_profile = rhs.layer_height_profile;
this->origin_translation = rhs.origin_translation;
m_bounding_box = rhs.m_bounding_box;
@ -669,14 +671,17 @@ ModelObject& ModelObject::assign_copy(const ModelObject &rhs)
// maintains the m_model pointer
ModelObject& ModelObject::assign_copy(ModelObject &&rhs)
{
assert(this->id().invalid());
this->copy_id(rhs);
this->name = std::move(rhs.name);
this->input_file = std::move(rhs.input_file);
// Moves the config's ID
this->config = std::move(rhs.config);
assert(this->config.id() == rhs.config.id());
this->sla_support_points = std::move(rhs.sla_support_points);
this->sla_points_status = std::move(rhs.sla_points_status);
this->layer_height_ranges = std::move(rhs.layer_height_ranges);
this->layer_config_ranges = std::move(rhs.layer_config_ranges); // #ys_FIXME_experiment
this->layer_height_profile = std::move(rhs.layer_height_profile);
this->origin_translation = std::move(rhs.origin_translation);
m_bounding_box = std::move(rhs.m_bounding_box);
@ -1081,11 +1086,11 @@ void ModelObject::mirror(Axis axis)
}
// This method could only be called before the meshes of this ModelVolumes are not shared!
void ModelObject::scale_mesh(const Vec3d &versor)
void ModelObject::scale_mesh_after_creation(const Vec3d &versor)
{
for (ModelVolume *v : this->volumes)
{
v->scale_geometry(versor);
v->scale_geometry_after_creation(versor);
v->set_offset(versor.cwiseProduct(v->get_offset()));
}
this->invalidate_bounding_box();
@ -1202,13 +1207,19 @@ ModelObjectPtrs ModelObject::cut(size_t instance, coordf_t z, bool keep_upper, b
if (keep_upper && upper_mesh.facets_count() > 0) {
ModelVolume* vol = upper->add_volume(upper_mesh);
vol->name = volume->name;
vol->config = volume->config;
// Don't copy the config's ID.
static_cast<DynamicPrintConfig&>(vol->config) = static_cast<const DynamicPrintConfig&>(volume->config);
assert(vol->config.id().valid());
assert(vol->config.id() != volume->config.id());
vol->set_material(volume->material_id(), *volume->material());
}
if (keep_lower && lower_mesh.facets_count() > 0) {
ModelVolume* vol = lower->add_volume(lower_mesh);
vol->name = volume->name;
vol->config = volume->config;
// Don't copy the config's ID.
static_cast<DynamicPrintConfig&>(vol->config) = static_cast<const DynamicPrintConfig&>(volume->config);
assert(vol->config.id().valid());
assert(vol->config.id() != volume->config.id());
vol->set_material(volume->material_id(), *volume->material());
// Compute the lower part instances' bounding boxes to figure out where to place
@ -1283,7 +1294,10 @@ 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->config = this->config;
// Don't copy the config's ID.
static_cast<DynamicPrintConfig&>(new_object->config) = static_cast<const DynamicPrintConfig&>(this->config);
assert(new_object->config.id().valid());
assert(new_object->config.id() != this->config.id());
new_object->instances.reserve(this->instances.size());
for (const ModelInstance *model_instance : this->instances)
new_object->add_instance(*model_instance);
@ -1576,9 +1590,9 @@ void ModelVolume::center_geometry_after_creation()
if (!shift.isApprox(Vec3d::Zero()))
{
if (m_mesh)
m_mesh->translate(-(float)shift(0), -(float)shift(1), -(float)shift(2));
const_cast<TriangleMesh*>(m_mesh.get())->translate(-(float)shift(0), -(float)shift(1), -(float)shift(2));
if (m_convex_hull)
m_convex_hull->translate(-(float)shift(0), -(float)shift(1), -(float)shift(2));
const_cast<TriangleMesh*>(m_convex_hull.get())->translate(-(float)shift(0), -(float)shift(1), -(float)shift(2));
translate(shift);
}
}
@ -1731,10 +1745,10 @@ void ModelVolume::mirror(Axis axis)
}
// This method could only be called before the meshes of this ModelVolumes are not shared!
void ModelVolume::scale_geometry(const Vec3d& versor)
void ModelVolume::scale_geometry_after_creation(const Vec3d& versor)
{
m_mesh->scale(versor);
m_convex_hull->scale(versor);
const_cast<TriangleMesh*>(m_mesh.get())->scale(versor);
const_cast<TriangleMesh*>(m_convex_hull.get())->scale(versor);
}
void ModelVolume::transform_this_mesh(const Transform3d &mesh_trafo, bool fix_left_handed)
@ -1891,7 +1905,7 @@ bool model_volume_list_changed(const ModelObject &model_object_old, const ModelO
if (!mv_old.get_matrix().isApprox(mv_new.get_matrix()))
return true;
++i_old;
++ i_old;
++ i_new;
}
for (; i_old < model_object_old.volumes.size(); ++ i_old) {
@ -1913,21 +1927,26 @@ bool model_volume_list_changed(const ModelObject &model_object_old, const ModelO
// Verify whether the IDs of Model / ModelObject / ModelVolume / ModelInstance / ModelMaterial are valid and unique.
void check_model_ids_validity(const Model &model)
{
std::set<ModelID> ids;
auto check = [&ids](ModelID id) {
assert(id.id > 0);
std::set<ObjectID> ids;
auto check = [&ids](ObjectID id) {
assert(id.valid());
assert(ids.find(id) == ids.end());
ids.insert(id);
};
for (const ModelObject *model_object : model.objects) {
check(model_object->id());
for (const ModelVolume *model_volume : model_object->volumes)
check(model_object->config.id());
for (const ModelVolume *model_volume : model_object->volumes) {
check(model_volume->id());
check(model_volume->config.id());
}
for (const ModelInstance *model_instance : model_object->instances)
check(model_instance->id());
}
for (const auto mm : model.materials)
for (const auto mm : model.materials) {
check(mm.second->id());
check(mm.second->config.id());
}
}
void check_model_ids_equal(const Model &model1, const Model &model2)
@ -1938,10 +1957,13 @@ void check_model_ids_equal(const Model &model1, const Model &model2)
const ModelObject &model_object1 = *model1.objects[idx_model];
const ModelObject &model_object2 = * model2.objects[idx_model];
assert(model_object1.id() == model_object2.id());
assert(model_object1.config.id() == model_object2.config.id());
assert(model_object1.volumes.size() == model_object2.volumes.size());
assert(model_object1.instances.size() == model_object2.instances.size());
for (size_t i = 0; i < model_object1.volumes.size(); ++ i)
for (size_t i = 0; i < model_object1.volumes.size(); ++ i) {
assert(model_object1.volumes[i]->id() == model_object2.volumes[i]->id());
assert(model_object1.volumes[i]->config.id() == model_object2.volumes[i]->config.id());
}
for (size_t i = 0; i < model_object1.instances.size(); ++ i)
assert(model_object1.instances[i]->id() == model_object2.instances[i]->id());
}
@ -1952,9 +1974,22 @@ void check_model_ids_equal(const Model &model1, const Model &model2)
for (; it1 != model1.materials.end(); ++ it1, ++ it2) {
assert(it1->first == it2->first); // compare keys
assert(it1->second->id() == it2->second->id());
assert(it1->second->config.id() == it2->second->config.id());
}
}
}
#endif /* NDEBUG */
}
#if 0
CEREAL_REGISTER_TYPE(Slic3r::ModelObject)
CEREAL_REGISTER_TYPE(Slic3r::ModelVolume)
CEREAL_REGISTER_TYPE(Slic3r::ModelInstance)
CEREAL_REGISTER_TYPE(Slic3r::Model)
CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ObjectBase, Slic3r::ModelObject)
CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ObjectBase, Slic3r::ModelVolume)
CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ObjectBase, Slic3r::ModelInstance)
CEREAL_REGISTER_POLYMORPHIC_RELATION(Slic3r::ObjectBase, Slic3r::Model)
#endif