From 27c73f5983644f57a67297032484c124f6d3d05d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 10 May 2014 16:59:17 +0200 Subject: [PATCH] Some fixes after the recent Model refactoring --- lib/Slic3r/GUI/Plater.pm | 2 +- lib/Slic3r/Print.pm | 5 +++-- xs/src/Model.cpp | 27 +++++++++++++++++++++++++-- xs/src/Model.hpp | 5 ++++- xs/xsp/Model.xsp | 6 +++--- xs/xsp/Point.xsp | 1 + 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index aa6a521ed..6b818ed68 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -403,7 +403,7 @@ sub load_model_objects { ); push @obj_idx, $#{ $self->{objects} }; - if (!defined $model_object->instances) { + if ($model_object->instances_count == 0) { # if object has no defined position(s) we need to rearrange everything after loading $need_arrange = 1; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 050e4c39d..cdf26c9e0 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -104,8 +104,9 @@ sub apply_config { if ($rearrange_regions) { # the current subdivision of regions does not make sense anymore. # we need to remove all objects and re-add them + my @model_objects = map $_->model_object, @{$self->objects}; $self->clear_objects; - $self->add_model_object($_->model_object) for @{$self->objects}; + $self->add_model_object($_) for @model_objects; } } @@ -137,7 +138,7 @@ sub add_model_object { $config->apply_dynamic($object_config); if (defined $volume->material_id) { - my $material_config = $object->model->get_material($volume->material_id)->config->clone; + my $material_config = $volume->material->config->clone; $material_config->normalize; $config->apply_dynamic($material_config); } diff --git a/xs/src/Model.cpp b/xs/src/Model.cpp index 35cf33792..5d24b39b6 100644 --- a/xs/src/Model.cpp +++ b/xs/src/Model.cpp @@ -321,8 +321,31 @@ ModelVolume::ModelVolume(ModelObject* object, const TriangleMesh &mesh) {} ModelVolume::ModelVolume(ModelObject* object, const ModelVolume &other) -: object(object), material_id(other.material_id), mesh(other.mesh), modifier(other.modifier) -{} +: object(object), mesh(other.mesh), modifier(other.modifier) +{ + this->material_id(other.material_id()); +} + +t_model_material_id +ModelVolume::material_id() const +{ + return this->_material_id; +} + +void +ModelVolume::material_id(t_model_material_id material_id) +{ + this->_material_id = material_id; + + // ensure this->_material_id references an existing material + (void)this->object->get_model()->add_material(material_id); +} + +ModelMaterial* +ModelVolume::material() const +{ + return this->object->get_model()->get_material(this->_material_id); +} #ifdef SLIC3RXS REGISTER_CLASS(ModelVolume, "Model::Volume"); diff --git a/xs/src/Model.hpp b/xs/src/Model.hpp index 84c68ee61..9e2d1234c 100644 --- a/xs/src/Model.hpp +++ b/xs/src/Model.hpp @@ -138,14 +138,17 @@ class ModelVolume { friend class ModelObject; public: - t_model_material_id material_id; TriangleMesh mesh; bool modifier; ModelObject* get_object() const { return this->object; }; + t_model_material_id material_id() const; + void material_id(t_model_material_id material_id); + ModelMaterial* material() const; private: ModelObject* object; + t_model_material_id _material_id; ModelVolume(ModelObject *object, const TriangleMesh &mesh); ModelVolume(ModelObject *object, const ModelVolume &other); diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index 1dc8d010b..5903994ca 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -162,10 +162,10 @@ ModelMaterial::attributes() Ref object() %code%{ RETVAL = THIS->get_object(); %}; - t_model_material_id material_id() - %code%{ RETVAL = THIS->material_id; %}; + t_model_material_id material_id(); void set_material_id(t_model_material_id material_id) - %code%{ THIS->material_id = material_id; %}; + %code%{ THIS->material_id(material_id); %}; + Ref material(); Ref mesh() %code%{ RETVAL = &THIS->mesh; %}; diff --git a/xs/xsp/Point.xsp b/xs/xsp/Point.xsp index 6fd39eac0..4335c6eb8 100644 --- a/xs/xsp/Point.xsp +++ b/xs/xsp/Point.xsp @@ -64,6 +64,7 @@ Point::coincides_with(point_sv) %code{% RETVAL = THIS->x; %}; double y() %code{% RETVAL = THIS->y; %}; + void translate(double x, double y); }; %name{Slic3r::Pointf3} class Pointf3 {