Several minor fixes to Model

This commit is contained in:
Alessandro Ranellucci 2014-05-08 13:33:43 +02:00
parent 6e207d3830
commit f76e2c2222
6 changed files with 76 additions and 10 deletions

View File

@ -250,6 +250,18 @@ ConfigBase::set_deserialize(const t_config_option_key opt_key, SV* str) {
}
#endif
DynamicConfig& DynamicConfig::operator= (DynamicConfig other)
{
this->swap(other);
return *this;
}
void
DynamicConfig::swap(DynamicConfig &other)
{
std::swap(this->options, other.options);
}
DynamicConfig::~DynamicConfig () {
for (t_options_map::iterator it = this->options.begin(); it != this->options.end(); ++it) {
ConfigOption* opt = it->second;

View File

@ -488,6 +488,8 @@ class DynamicConfig : public ConfigBase
public:
DynamicConfig() {};
DynamicConfig(const DynamicConfig& other);
DynamicConfig& operator= (DynamicConfig other);
void swap(DynamicConfig &other);
~DynamicConfig();
ConfigOption* option(const t_config_option_key opt_key, bool create = false);
const ConfigOption* option(const t_config_option_key opt_key) const;
@ -495,7 +497,6 @@ class DynamicConfig : public ConfigBase
void erase(const t_config_option_key opt_key);
private:
DynamicConfig& operator= (const DynamicConfig& other); // we disable this by making it private and unimplemented
typedef std::map<t_config_option_key,ConfigOption*> t_options_map;
t_options_map options;
};

View File

@ -30,6 +30,19 @@ Model::Model(const Model &other)
}
}
Model& Model::operator= (Model other)
{
this->swap(other);
return *this;
}
void
Model::swap(Model &other)
{
std::swap(this->materials, other.materials);
std::swap(this->objects, other.objects);
}
Model::~Model()
{
this->clear_objects();
@ -57,7 +70,8 @@ Model::delete_object(size_t idx)
void
Model::clear_objects()
{
for (size_t i = this->objects.size()-1; i >= 0; --i)
// int instead of size_t because it can be -1 when vector is empty
for (int i = this->objects.size()-1; i >= 0; --i)
this->delete_object(i);
}
@ -194,6 +208,25 @@ ModelObject::ModelObject(const ModelObject &other)
}
}
ModelObject& ModelObject::operator= (ModelObject other)
{
this->swap(other);
return *this;
}
void
ModelObject::swap(ModelObject &other)
{
std::swap(this->input_file, other.input_file);
std::swap(this->instances, other.instances);
std::swap(this->volumes, other.volumes);
std::swap(this->config, other.config);
std::swap(this->layer_height_ranges, other.layer_height_ranges);
std::swap(this->origin_translation, other.origin_translation);
std::swap(this->_bounding_box, other._bounding_box);
std::swap(this->_bounding_box_valid, other._bounding_box_valid);
}
ModelObject::~ModelObject()
{
this->clear_volumes();
@ -222,7 +255,8 @@ ModelObject::delete_volume(size_t idx)
void
ModelObject::clear_volumes()
{
for (size_t i = this->volumes.size()-1; i >= 0; --i)
// int instead of size_t because it can be -1 when vector is empty
for (int i = this->volumes.size()-1; i >= 0; --i)
this->delete_volume(i);
}
@ -307,10 +341,6 @@ ModelInstance::ModelInstance(ModelObject *object, double rotation,
{
}
ModelInstance::~ModelInstance()
{
}
#ifdef SLIC3RXS
REGISTER_CLASS(ModelInstance, "Model::Instance");

View File

@ -35,6 +35,8 @@ class Model
Model();
Model(const Model &other);
Model& operator= (Model other);
void swap(Model &other);
~Model();
ModelObject* add_object(const std::string &input_file, const DynamicPrintConfig &config,
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
@ -82,12 +84,12 @@ class ModelObject
DynamicPrintConfig config;
t_layer_height_ranges layer_height_ranges;
Pointf origin_translation;
BoundingBoxf3 _bounding_box;
bool _bounding_box_valid;
ModelObject(Model *model, const std::string &input_file, const DynamicPrintConfig &config,
const t_layer_height_ranges &layer_height_ranges, const Pointf &origin_translation);
ModelObject(const ModelObject &other);
ModelObject& operator= (ModelObject other);
void swap(ModelObject &other);
~ModelObject();
ModelVolume* add_volume(const t_model_material_id &material_id,
@ -118,6 +120,9 @@ class ModelObject
#endif
private:
BoundingBoxf3 _bounding_box;
bool _bounding_box_valid;
void update_bounding_box();
};
@ -147,7 +152,6 @@ class ModelInstance
ModelInstance(ModelObject *object, double rotation, double scaling_factor,
const Pointf &offset);
~ModelInstance();
void transform_mesh(TriangleMesh* mesh, bool dont_translate) const;
void transform_polygon(Polygon* polygon) const;

View File

@ -50,6 +50,23 @@ TriangleMesh::TriangleMesh(const TriangleMesh &other)
}
}
TriangleMesh& TriangleMesh::operator= (TriangleMesh other)
{
this->swap(other);
return *this;
}
void
TriangleMesh::swap(TriangleMesh &other)
{
std::swap(this->stl, other.stl);
std::swap(this->repaired, other.repaired);
std::swap(this->stl.facet_start, other.stl.facet_start);
std::swap(this->stl.neighbors_start, other.stl.neighbors_start);
std::swap(this->stl.v_indices, other.stl.v_indices);
std::swap(this->stl.v_shared, other.stl.v_shared);
}
TriangleMesh::~TriangleMesh() {
stl_close(&this->stl);
}

View File

@ -20,6 +20,8 @@ class TriangleMesh
public:
TriangleMesh();
TriangleMesh(const TriangleMesh &other);
TriangleMesh& operator= (TriangleMesh other);
void swap(TriangleMesh &other);
~TriangleMesh();
void ReadSTLFile(char* input_file);
void write_ascii(char* output_file);