Use Pointf for origin_translation and pass const refs whenever possible

This commit is contained in:
Alessandro Ranellucci 2014-05-07 00:58:29 +02:00
parent 54a199919b
commit 13af16ea24
7 changed files with 80 additions and 89 deletions

View File

@ -471,8 +471,8 @@ sub reset {
my $self = shift; my $self = shift;
@{$self->{objects}} = (); @{$self->{objects}} = ();
$self->{model}->delete_all_objects; $self->{model}->clear_objects;
$self->{print}->delete_all_objects; $self->{print}->clear_objects;
$self->{list}->DeleteAllItems; $self->{list}->DeleteAllItems;
$self->object_list_changed; $self->object_list_changed;

View File

@ -58,7 +58,7 @@ sub add_object {
$args{input_file}, $args{input_file},
$args{config} // Slic3r::Config->new, $args{config} // Slic3r::Config->new,
$args{layer_height_ranges} // [], $args{layer_height_ranges} // [],
$args{origin_translation} // Slic3r::Point->new, $args{origin_translation} // Slic3r::Pointf->new,
); );
} }

View File

@ -105,7 +105,7 @@ sub apply_config {
# the current subdivision of regions does not make sense anymore. # the current subdivision of regions does not make sense anymore.
# we need to remove all objects and re-add them # we need to remove all objects and re-add them
my @models_objects = map [$_->model, $_->model_object], @{$self->objects}; my @models_objects = map [$_->model, $_->model_object], @{$self->objects};
$self->delete_all_objects; $self->clear_objects;
$self->add_model_object(@$_) for @models_objects; $self->add_model_object(@$_) for @models_objects;
} }
} }
@ -202,7 +202,7 @@ sub delete_object {
$self->_state->invalidate(STEP_BRIM); $self->_state->invalidate(STEP_BRIM);
} }
sub delete_all_objects { sub clear_objects {
my ($self) = @_; my ($self) = @_;
@{$self->objects} = (); @{$self->objects} = ();
@ -222,7 +222,7 @@ sub reload_object {
# This should also check whether object volumes (parts) have changed. # This should also check whether object volumes (parts) have changed.
my @models_objects = map [$_->model, $_->model_object], @{$self->objects}; my @models_objects = map [$_->model, $_->model_object], @{$self->objects};
$self->delete_all_objects; $self->clear_objects;
$self->add_model_object(@$_) for @models_objects; $self->add_model_object(@$_) for @models_objects;
} }

View File

@ -44,7 +44,7 @@ sub set_model {
my ($self, $model) = @_; my ($self, $model) = @_;
# make method idempotent so that the object is reusable # make method idempotent so that the object is reusable
$self->_print->delete_all_objects; $self->_print->clear_objects;
# make sure all objects have at least one defined instance # make sure all objects have at least one defined instance
my $need_arrange = $model->add_default_instances; my $need_arrange = $model->add_default_instances;

View File

@ -6,13 +6,9 @@
namespace Slic3r { namespace Slic3r {
Model::Model() Model::Model() {}
{
}
Model::Model(const Model &other) Model::Model(const Model &other)
: materials(),
objects()
{ {
objects.reserve(other.objects.size()); objects.reserve(other.objects.size());
@ -36,15 +32,15 @@ Model::Model(const Model &other)
Model::~Model() Model::~Model()
{ {
delete_all_objects(); this->clear_objects();
delete_all_materials(); this->clear_materials();
} }
ModelObject * ModelObject*
Model::add_object(std::string input_file, DynamicPrintConfig *config, Model::add_object(const std::string &input_file, const DynamicPrintConfig &config,
t_layer_height_ranges layer_height_ranges, Point origin_translation) const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation)
{ {
ModelObject *object = new ModelObject(this, input_file, config, ModelObject* object = new ModelObject(this, input_file, config,
layer_height_ranges, origin_translation); layer_height_ranges, origin_translation);
this->objects.push_back(object); this->objects.push_back(object);
return object; return object;
@ -59,27 +55,27 @@ Model::delete_object(size_t idx)
} }
void void
Model::delete_all_objects() Model::clear_objects()
{ {
for (ModelObjectPtrs::iterator i = this->objects.begin(); for (size_t i = 0; i < this->objects.size(); ++i)
i != this->objects.end(); ++i) this->delete_object(i);
{
delete *i;
}
objects.clear();
} }
void void
Model::delete_all_materials() Model::delete_material(t_model_material_id material_id)
{ {
for (ModelMaterialMap::iterator i = this->materials.begin(); ModelMaterialMap::iterator i = this->materials.find(material_id);
i != this->materials.end(); ++i) if (i != this->materials.end()) {
{
delete i->second; delete i->second;
this->materials.erase(i);
} }
}
this->materials.clear(); void
Model::clear_materials()
{
while (!this->materials.empty())
this->delete_material( this->materials.begin()->first );
} }
ModelMaterial * ModelMaterial *
@ -154,12 +150,12 @@ REGISTER_CLASS(ModelMaterial, "Model::Material");
#endif #endif
ModelObject::ModelObject(Model *model, std::string input_file, ModelObject::ModelObject(Model *model, const std::string &input_file,
DynamicPrintConfig *config, t_layer_height_ranges layer_height_ranges, const DynamicPrintConfig &config, const t_layer_height_ranges &layer_height_ranges,
Point origin_translation) const Pointf &origin_translation)
: model(model), : model(model),
input_file(input_file), input_file(input_file),
config(*config), config(config),
layer_height_ranges(layer_height_ranges), layer_height_ranges(layer_height_ranges),
origin_translation(origin_translation), origin_translation(origin_translation),
_bounding_box_valid(false) _bounding_box_valid(false)
@ -205,8 +201,8 @@ ModelObject::~ModelObject()
} }
ModelVolume * ModelVolume *
ModelObject::add_volume(t_model_material_id material_id, ModelObject::add_volume(const t_model_material_id &material_id,
TriangleMesh *mesh, bool modifier) const TriangleMesh &mesh, bool modifier)
{ {
ModelVolume *v = new ModelVolume(this, material_id, mesh, modifier); ModelVolume *v = new ModelVolume(this, material_id, mesh, modifier);
this->volumes.push_back(v); this->volumes.push_back(v);
@ -226,13 +222,8 @@ ModelObject::delete_volume(size_t idx)
void void
ModelObject::clear_volumes() ModelObject::clear_volumes()
{ {
for (ModelVolumePtrs::iterator i = this->volumes.begin(); for (size_t i = 0; i < this->volumes.size(); ++i)
i != this->volumes.end(); ++i) this->delete_volume(i);
{
delete *i;
}
this->volumes.clear();
} }
ModelInstance * ModelInstance *
@ -246,24 +237,26 @@ ModelObject::add_instance(double rotation, double scaling_factor,
return i; return i;
} }
void
ModelObject::delete_instance(size_t idx)
{
ModelInstancePtrs::iterator i = this->instances.begin() + idx;
delete *i;
this->instances.erase(i);
this->invalidate_bounding_box();
}
void void
ModelObject::delete_last_instance() ModelObject::delete_last_instance()
{ {
delete this->instances.back(); this->delete_instance(this->instances.size() - 1);
this->instances.pop_back();
this->invalidate_bounding_box();
} }
void void
ModelObject::clear_instances() ModelObject::clear_instances()
{ {
for (ModelInstancePtrs::iterator i = this->instances.begin(); for (size_t i = 0; i < this->instances.size(); ++i)
i != this->instances.end(); ++i) this->delete_instance(i);
{
delete *i;
}
this->instances.clear();
} }
void void
@ -284,19 +277,15 @@ ModelObject::to_SV_ref() {
#endif #endif
ModelVolume::ModelVolume(ModelObject *object, t_model_material_id material_id, ModelVolume::ModelVolume(ModelObject* object, const t_model_material_id &material_id,
TriangleMesh *mesh, bool modifier) const TriangleMesh &mesh, bool modifier)
: object(object), : object(object),
material_id(material_id), material_id(material_id),
mesh(*mesh), mesh(mesh),
modifier(modifier) modifier(modifier)
{ {
} }
ModelVolume::~ModelVolume()
{
}
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(ModelVolume, "Model::Volume"); REGISTER_CLASS(ModelVolume, "Model::Volume");
@ -310,7 +299,7 @@ ModelVolume::to_SV_ref() {
ModelInstance::ModelInstance(ModelObject *object, double rotation, ModelInstance::ModelInstance(ModelObject *object, double rotation,
double scaling_factor, Pointf offset) double scaling_factor, const Pointf &offset)
: object(object), : object(object),
rotation(rotation), rotation(rotation),
scaling_factor(scaling_factor), scaling_factor(scaling_factor),

View File

@ -36,11 +36,12 @@ class Model
Model(); Model();
Model(const Model &other); Model(const Model &other);
~Model(); ~Model();
ModelObject *add_object(std::string input_file, DynamicPrintConfig *config, ModelObject* add_object(const std::string &input_file, const DynamicPrintConfig &config,
t_layer_height_ranges layer_height_ranges, Point origin_translation); const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
void delete_object(size_t idx); void delete_object(size_t idx);
void delete_all_objects(); void clear_objects();
void delete_all_materials(); void delete_material(t_model_material_id material_id);
void clear_materials();
ModelMaterial *set_material(t_model_material_id material_id); ModelMaterial *set_material(t_model_material_id material_id);
// void duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance); // void duplicate_objects_grid(unsigned int x, unsigned int y, coordf_t distance);
// void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb); // void duplicate_objects(size_t copies_num, coordf_t distance, const BoundingBox &bb);
@ -80,22 +81,23 @@ class ModelObject
ModelVolumePtrs volumes; ModelVolumePtrs volumes;
DynamicPrintConfig config; DynamicPrintConfig config;
t_layer_height_ranges layer_height_ranges; t_layer_height_ranges layer_height_ranges;
Point origin_translation; Pointf origin_translation;
BoundingBoxf3 _bounding_box; BoundingBoxf3 _bounding_box;
bool _bounding_box_valid; bool _bounding_box_valid;
ModelObject(Model *model, std::string input_file, DynamicPrintConfig *config, ModelObject(Model *model, const std::string &input_file, const DynamicPrintConfig &config,
t_layer_height_ranges layer_height_ranges, Point origin_translation); const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
ModelObject(const ModelObject &other); ModelObject(const ModelObject &other);
~ModelObject(); ~ModelObject();
ModelVolume *add_volume(t_model_material_id material_id, ModelVolume* add_volume(const t_model_material_id &material_id,
TriangleMesh *mesh, bool modifier); const TriangleMesh &mesh, bool modifier);
void delete_volume(size_t idx); void delete_volume(size_t idx);
void clear_volumes(); void clear_volumes();
ModelInstance *add_instance(double rotation=0, double scaling_factor=1, ModelInstance *add_instance(double rotation=0, double scaling_factor = 1,
Pointf offset=Pointf(0, 0)); Pointf offset = Pointf(0, 0));
void delete_instance(size_t idx);
void delete_last_instance(); void delete_last_instance();
void clear_instances(); void clear_instances();
@ -127,9 +129,8 @@ class ModelVolume
TriangleMesh mesh; TriangleMesh mesh;
bool modifier; bool modifier;
ModelVolume(ModelObject *object, t_model_material_id material_id, ModelVolume(ModelObject *object, const t_model_material_id &material_id,
TriangleMesh *mesh, bool modifier); const TriangleMesh &mesh, bool modifier);
~ModelVolume();
#ifdef SLIC3RXS #ifdef SLIC3RXS
SV* to_SV_ref(); SV* to_SV_ref();
@ -145,7 +146,7 @@ class ModelInstance
Pointf offset; // in unscaled coordinates Pointf offset; // in unscaled coordinates
ModelInstance(ModelObject *object, double rotation, double scaling_factor, ModelInstance(ModelObject *object, double rotation, double scaling_factor,
Pointf offset); const Pointf &offset);
~ModelInstance(); ~ModelInstance();
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const; void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;

View File

@ -15,17 +15,18 @@
%code%{ RETVAL = THIS; %}; %code%{ RETVAL = THIS; %};
Ref<ModelObject> _add_object(std::string input_file, Ref<ModelObject> _add_object(std::string input_file,
DynamicPrintConfig *config, DynamicPrintConfig* config,
t_layer_height_ranges layer_height_ranges, t_layer_height_ranges layer_height_ranges,
Point *origin_translation) Pointf* origin_translation)
%code%{ %code%{
RETVAL = THIS->add_object(input_file, config, layer_height_ranges, RETVAL = THIS->add_object(input_file, *config, layer_height_ranges,
*origin_translation); *origin_translation);
%}; %};
void delete_object(size_t idx); void delete_object(size_t idx);
void delete_all_objects(); void clear_objects();
void delete_all_materials(); void delete_material(t_model_material_id material_id);
void clear_materials();
%name{_set_material} Ref<ModelMaterial> set_material(t_model_material_id material_id) %name{_set_material} Ref<ModelMaterial> set_material(t_model_material_id material_id)
%code%{ RETVAL = THIS->set_material(material_id); %}; %code%{ RETVAL = THIS->set_material(material_id); %};
@ -114,11 +115,11 @@ ModelMaterial::attributes()
%name{Slic3r::Model::Object} class ModelObject { %name{Slic3r::Model::Object} class ModelObject {
ModelObject(Model *model, std::string input_file, ModelObject(Model* model, std::string input_file,
DynamicPrintConfig *config, t_layer_height_ranges layer_height_ranges, DynamicPrintConfig* config, t_layer_height_ranges layer_height_ranges,
Point *origin_translation) Pointf* origin_translation)
%code%{ %code%{
RETVAL = new ModelObject(model, input_file, config, RETVAL = new ModelObject(model, input_file, *config,
layer_height_ranges, *origin_translation); layer_height_ranges, *origin_translation);
%}; %};
@ -160,8 +161,8 @@ ModelMaterial::attributes()
%}; %};
%name{_add_volume} Ref<ModelVolume> add_volume( %name{_add_volume} Ref<ModelVolume> add_volume(
t_model_material_id material_id, TriangleMesh *mesh, bool modifier) t_model_material_id material_id, TriangleMesh* mesh, bool modifier)
%code%{ RETVAL = THIS->add_volume(material_id, mesh, modifier); %}; %code%{ RETVAL = THIS->add_volume(material_id, *mesh, modifier); %};
void delete_volume(size_t idx); void delete_volume(size_t idx);
void clear_volumes(); void clear_volumes();
@ -188,7 +189,7 @@ ModelMaterial::attributes()
t_layer_height_ranges layer_height_ranges() t_layer_height_ranges layer_height_ranges()
%code%{ RETVAL = THIS->layer_height_ranges; %}; %code%{ RETVAL = THIS->layer_height_ranges; %};
Clone<Point> origin_translation() Clone<Pointf> origin_translation()
%code%{ RETVAL = THIS->origin_translation; %}; %code%{ RETVAL = THIS->origin_translation; %};
}; };