From 54a199919bd69f085eee157d148d27ab793a61b2 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 7 May 2014 00:22:56 +0200 Subject: [PATCH] Removed StringMap --- lib/Slic3r/Model.pm | 13 +++++----- xs/MANIFEST | 3 --- xs/lib/Slic3r/XS.pm | 15 ----------- xs/src/Model.cpp | 15 +++-------- xs/src/Model.hpp | 3 +-- xs/src/StringMap.cpp | 13 ---------- xs/src/StringMap.hpp | 16 ------------ xs/xsp/Model.xsp | 30 ++++++++++++++++------ xs/xsp/StringMap.xsp | 59 -------------------------------------------- xs/xsp/my.map | 27 -------------------- xs/xsp/typemap.xspt | 3 --- 11 files changed, 35 insertions(+), 162 deletions(-) delete mode 100644 xs/src/StringMap.cpp delete mode 100644 xs/src/StringMap.hpp delete mode 100644 xs/xsp/StringMap.xsp diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 666a68b8d..9f17b292f 100644 --- a/lib/Slic3r/Model.pm +++ b/lib/Slic3r/Model.pm @@ -69,7 +69,11 @@ sub set_material { my $self = shift; my ($material_id, $attributes) = @_; - return $self->_set_material($material_id, $attributes || {}); + $attributes //= {}; + + my $material = $self->_set_material($material_id); + $material->set_attribute($_, $attributes->{$_}) for keys %$attributes; + return $material; } sub duplicate_objects_grid { @@ -218,7 +222,8 @@ sub center_instances_around_point { foreach my $instance (@{$object->instances}) { $instance->set_offset(Slic3r::Pointf->new( $instance->offset->x + $shift[X], - $instance->offset->y + $shift[Y])); + $instance->offset->y + $shift[Y], #++ + )); } $object->update_bounding_box; } @@ -309,10 +314,6 @@ sub get_material_name { package Slic3r::Model::Material; -sub attributes { - $_[0]->_attributes->to_hash; -} - package Slic3r::Model::Object; use File::Basename qw(basename); diff --git a/xs/MANIFEST b/xs/MANIFEST index e3b436a6c..0fdceff84 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -1706,8 +1706,6 @@ src/Print.cpp src/Print.hpp src/PrintConfig.cpp src/PrintConfig.hpp -src/StringMap.cpp -src/StringMap.hpp src/Surface.cpp src/Surface.hpp src/SurfaceCollection.cpp @@ -1753,7 +1751,6 @@ xsp/Polygon.xsp xsp/Polyline.xsp xsp/PolylineCollection.xsp xsp/Print.xsp -xsp/StringMap.xsp xsp/Surface.xsp xsp/SurfaceCollection.xsp xsp/TriangleMesh.xsp diff --git a/xs/lib/Slic3r/XS.pm b/xs/lib/Slic3r/XS.pm index 83d03cb32..b2e9b6cd4 100644 --- a/xs/lib/Slic3r/XS.pm +++ b/xs/lib/Slic3r/XS.pm @@ -189,20 +189,6 @@ use overload '@{}' => sub { $_[0]->arrayref }, 'fallback' => 1; -package Slic3r::StringMap; - -sub to_hash { - my $self = shift; - my %tiehash; - tie %tiehash, 'Slic3r::StringMap', $self; - return \%tiehash; -} - -sub TIEHASH { - my ($class, $self) = @_; - return $self; -} - package main; for my $class (qw( Slic3r::Config @@ -223,7 +209,6 @@ for my $class (qw( Slic3r::Pointf3 Slic3r::Polygon Slic3r::Polyline - Slic3r::StringMap Slic3r::Surface Slic3r::TriangleMesh )) diff --git a/xs/src/Model.cpp b/xs/src/Model.cpp index e14595582..1991c052a 100644 --- a/xs/src/Model.cpp +++ b/xs/src/Model.cpp @@ -83,19 +83,17 @@ Model::delete_all_materials() } ModelMaterial * -Model::set_material(t_model_material_id material_id, - const t_model_material_attributes &attributes) +Model::set_material(t_model_material_id material_id) { ModelMaterialMap::iterator i = this->materials.find(material_id); - + ModelMaterial *mat; if (i == this->materials.end()) { mat = this->materials[material_id] = new ModelMaterial(this); } else { mat = i->second; } - - mat->apply(attributes); + return mat; } @@ -142,12 +140,7 @@ REGISTER_CLASS(Model, "Model"); #endif -ModelMaterial::ModelMaterial(Model *model) -: model(model), - attributes(), - config() -{ -} +ModelMaterial::ModelMaterial(Model *model) : model(model) {} void ModelMaterial::apply(const t_model_material_attributes &attributes) diff --git a/xs/src/Model.hpp b/xs/src/Model.hpp index 8fbf4fcaf..52179c9f6 100644 --- a/xs/src/Model.hpp +++ b/xs/src/Model.hpp @@ -41,8 +41,7 @@ class Model void delete_object(size_t idx); void delete_all_objects(); void delete_all_materials(); - ModelMaterial *set_material(t_model_material_id material_id, - const t_model_material_attributes &attributes); + 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(size_t copies_num, coordf_t distance, const BoundingBox &bb); // void arrange_objects(coordf_t distance, const BoundingBox &bb); diff --git a/xs/src/StringMap.cpp b/xs/src/StringMap.cpp deleted file mode 100644 index 7a8f02f94..000000000 --- a/xs/src/StringMap.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "StringMap.hpp" -#ifdef SLIC3RXS -#include "perlglue.hpp" -#endif - - -namespace Slic3r { - -#ifdef SLIC3RXS -__REGISTER_CLASS(StringMap, "StringMap"); -#endif - -} diff --git a/xs/src/StringMap.hpp b/xs/src/StringMap.hpp deleted file mode 100644 index f39bd7ce6..000000000 --- a/xs/src/StringMap.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef slic3r_StringMap_hpp_ -#define slic3r_StringMap_hpp_ - -#include -#include -#include - -namespace Slic3r { - -// this is just for XSPP, because it chokes on the template typename -typedef std::map StringMap; - -} - - -#endif diff --git a/xs/xsp/Model.xsp b/xs/xsp/Model.xsp index f9067c70f..7f636d858 100644 --- a/xs/xsp/Model.xsp +++ b/xs/xsp/Model.xsp @@ -4,7 +4,6 @@ #include #include "Model.hpp" #include "PrintConfig.hpp" -#include "StringMap.hpp" #include "perlglue.hpp" %} @@ -28,9 +27,8 @@ void delete_all_objects(); void delete_all_materials(); - %name{_set_material} Ref set_material(t_model_material_id material_id, - StringMap attributes) - %code%{ RETVAL = THIS->set_material(material_id, attributes); %}; + %name{_set_material} Ref set_material(t_model_material_id material_id) + %code%{ RETVAL = THIS->set_material(material_id); %}; Ref get_material(t_model_material_id material_id) %code%{ @@ -89,11 +87,29 @@ Ref model() %code%{ RETVAL = THIS->model; %}; - Ref _attributes() - %code%{ RETVAL = &THIS->attributes; %}; - Ref config() %code%{ RETVAL = &THIS->config; %}; + + std::string get_attribute(std::string name) + %code%{ if (THIS->attributes.find(name) != THIS->attributes.end()) RETVAL = THIS->attributes[name]; %}; + + void set_attribute(std::string name, std::string value) + %code%{ THIS->attributes[name] = value; %}; + +%{ + +SV* +ModelMaterial::attributes() + CODE: + HV* hv = newHV(); + for (t_model_material_attributes::const_iterator attr = THIS->attributes.begin(); attr != THIS->attributes.end(); ++attr) { + (void)hv_store( hv, attr->first.c_str(), attr->first.length(), newSVpv(attr->second.c_str(), attr->second.length()), 0 ); + } + RETVAL = (SV*)newRV_noinc((SV*)hv); + OUTPUT: + RETVAL +%} + }; diff --git a/xs/xsp/StringMap.xsp b/xs/xsp/StringMap.xsp deleted file mode 100644 index 874e2a7d2..000000000 --- a/xs/xsp/StringMap.xsp +++ /dev/null @@ -1,59 +0,0 @@ -%module{Slic3r::XS}; - -%{ -#include -#include "StringMap.hpp" -#include "perlglue.hpp" -%} - -%name{Slic3r::StringMap} class StringMap { - std::string FETCH(std::string key) - %code%{ - StringMap::iterator i = THIS->find(key); - if (i == THIS->end()) { - XSRETURN_UNDEF; - } - - RETVAL = i->second; - %}; - - void STORE(std::string key, std::string val) - %code%{ (*THIS)[key] = val; %}; - - void DELETE(std::string key) - %code%{ THIS->erase(key); %}; - - void CLEAR() - %code%{ THIS->clear(); %}; - - bool EXISTS(std::string key) - %code%{ RETVAL = (THIS->find(key) != THIS->end()); %}; - - std::string FIRSTKEY() - %code%{ - StringMap::iterator i = THIS->begin(); - if (i == THIS->end()) { - XSRETURN_UNDEF; - } else { - RETVAL = i->first; - } - %}; - - std::string NEXTKEY(std::string lastkey) - %code%{ - StringMap::iterator i = THIS->find(lastkey); - if (i == THIS->end()) { - XSRETURN_UNDEF; - } - - ++i; - if (i == THIS->end()) { - XSRETURN_UNDEF; - } else { - RETVAL = i->first; - } - %}; - - bool SCALAR() - %code%{ RETVAL = !THIS->empty(); %}; -}; diff --git a/xs/xsp/my.map b/xs/xsp/my.map index 7075c6868..11c924ea3 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -8,11 +8,6 @@ t_model_material_id T_STD_STRING t_layer_height_ranges T_LAYER_HEIGHT_RANGES -StringMap T_STRING_MAP -StringMap* O_OBJECT_SLIC3R -Ref O_OBJECT_SLIC3R_T - - BoundingBox* O_OBJECT_SLIC3R Ref O_OBJECT_SLIC3R_T Clone O_OBJECT_SLIC3R_T @@ -177,28 +172,6 @@ T_ARRAYREF ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, \"$var\"); -# http://www.perlmonks.org/?node_id=853194 -T_STRING_MAP - { - HV *hv; - HE *he; - std::map t_sm; - if(SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVHV) { - hv = (HV *)SvRV($arg); - hv_iterinit(hv); - } else { - warn(\"${Package}::$func_name() -- $var is not a hash reference\"); - XSRETURN_UNDEF; - } - - while((he = hv_iternext(hv)) != NULL) { - SV *svkey = HeSVKEY_force(he); - SV *svval = HeVAL(he); - t_sm[SvPV_nolen(svkey)] = SvPV_nolen(svval); - } - $var = t_sm; - } - T_LAYER_HEIGHT_RANGES { if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) { diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 669987111..e33b30c2b 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -11,9 +11,6 @@ %typemap{std::vector*}; %typemap{std::vector}; %typemap{t_layer_height_ranges}; -%typemap{StringMap}; -%typemap{StringMap*}; -%typemap{Ref}{simple}; %typemap{SV*}; %typemap{AV*}; %typemap{Point*};