Removed StringMap

This commit is contained in:
Alessandro Ranellucci 2014-05-07 00:22:56 +02:00
parent 05b2993769
commit 54a199919b
11 changed files with 35 additions and 162 deletions

View File

@ -69,7 +69,11 @@ sub set_material {
my $self = shift; my $self = shift;
my ($material_id, $attributes) = @_; 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 { sub duplicate_objects_grid {
@ -218,7 +222,8 @@ sub center_instances_around_point {
foreach my $instance (@{$object->instances}) { foreach my $instance (@{$object->instances}) {
$instance->set_offset(Slic3r::Pointf->new( $instance->set_offset(Slic3r::Pointf->new(
$instance->offset->x + $shift[X], $instance->offset->x + $shift[X],
$instance->offset->y + $shift[Y])); $instance->offset->y + $shift[Y], #++
));
} }
$object->update_bounding_box; $object->update_bounding_box;
} }
@ -309,10 +314,6 @@ sub get_material_name {
package Slic3r::Model::Material; package Slic3r::Model::Material;
sub attributes {
$_[0]->_attributes->to_hash;
}
package Slic3r::Model::Object; package Slic3r::Model::Object;
use File::Basename qw(basename); use File::Basename qw(basename);

View File

@ -1706,8 +1706,6 @@ src/Print.cpp
src/Print.hpp src/Print.hpp
src/PrintConfig.cpp src/PrintConfig.cpp
src/PrintConfig.hpp src/PrintConfig.hpp
src/StringMap.cpp
src/StringMap.hpp
src/Surface.cpp src/Surface.cpp
src/Surface.hpp src/Surface.hpp
src/SurfaceCollection.cpp src/SurfaceCollection.cpp
@ -1753,7 +1751,6 @@ xsp/Polygon.xsp
xsp/Polyline.xsp xsp/Polyline.xsp
xsp/PolylineCollection.xsp xsp/PolylineCollection.xsp
xsp/Print.xsp xsp/Print.xsp
xsp/StringMap.xsp
xsp/Surface.xsp xsp/Surface.xsp
xsp/SurfaceCollection.xsp xsp/SurfaceCollection.xsp
xsp/TriangleMesh.xsp xsp/TriangleMesh.xsp

View File

@ -189,20 +189,6 @@ use overload
'@{}' => sub { $_[0]->arrayref }, '@{}' => sub { $_[0]->arrayref },
'fallback' => 1; '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; package main;
for my $class (qw( for my $class (qw(
Slic3r::Config Slic3r::Config
@ -223,7 +209,6 @@ for my $class (qw(
Slic3r::Pointf3 Slic3r::Pointf3
Slic3r::Polygon Slic3r::Polygon
Slic3r::Polyline Slic3r::Polyline
Slic3r::StringMap
Slic3r::Surface Slic3r::Surface
Slic3r::TriangleMesh Slic3r::TriangleMesh
)) ))

View File

@ -83,19 +83,17 @@ Model::delete_all_materials()
} }
ModelMaterial * ModelMaterial *
Model::set_material(t_model_material_id material_id, Model::set_material(t_model_material_id material_id)
const t_model_material_attributes &attributes)
{ {
ModelMaterialMap::iterator i = this->materials.find(material_id); ModelMaterialMap::iterator i = this->materials.find(material_id);
ModelMaterial *mat; ModelMaterial *mat;
if (i == this->materials.end()) { if (i == this->materials.end()) {
mat = this->materials[material_id] = new ModelMaterial(this); mat = this->materials[material_id] = new ModelMaterial(this);
} else { } else {
mat = i->second; mat = i->second;
} }
mat->apply(attributes);
return mat; return mat;
} }
@ -142,12 +140,7 @@ REGISTER_CLASS(Model, "Model");
#endif #endif
ModelMaterial::ModelMaterial(Model *model) ModelMaterial::ModelMaterial(Model *model) : model(model) {}
: model(model),
attributes(),
config()
{
}
void void
ModelMaterial::apply(const t_model_material_attributes &attributes) ModelMaterial::apply(const t_model_material_attributes &attributes)

View File

@ -41,8 +41,7 @@ class Model
void delete_object(size_t idx); void delete_object(size_t idx);
void delete_all_objects(); void delete_all_objects();
void delete_all_materials(); void delete_all_materials();
ModelMaterial *set_material(t_model_material_id material_id, ModelMaterial *set_material(t_model_material_id material_id);
const t_model_material_attributes &attributes);
// 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);
// void arrange_objects(coordf_t distance, const BoundingBox &bb); // void arrange_objects(coordf_t distance, const BoundingBox &bb);

View File

@ -1,13 +0,0 @@
#include "StringMap.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r {
#ifdef SLIC3RXS
__REGISTER_CLASS(StringMap, "StringMap");
#endif
}

View File

@ -1,16 +0,0 @@
#ifndef slic3r_StringMap_hpp_
#define slic3r_StringMap_hpp_
#include <myinit.h>
#include <map>
#include <string>
namespace Slic3r {
// this is just for XSPP, because it chokes on the template typename
typedef std::map<std::string, std::string> StringMap;
}
#endif

View File

@ -4,7 +4,6 @@
#include <myinit.h> #include <myinit.h>
#include "Model.hpp" #include "Model.hpp"
#include "PrintConfig.hpp" #include "PrintConfig.hpp"
#include "StringMap.hpp"
#include "perlglue.hpp" #include "perlglue.hpp"
%} %}
@ -28,9 +27,8 @@
void delete_all_objects(); void delete_all_objects();
void delete_all_materials(); void delete_all_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)
StringMap attributes) %code%{ RETVAL = THIS->set_material(material_id); %};
%code%{ RETVAL = THIS->set_material(material_id, attributes); %};
Ref<ModelMaterial> get_material(t_model_material_id material_id) Ref<ModelMaterial> get_material(t_model_material_id material_id)
%code%{ %code%{
@ -89,11 +87,29 @@
Ref<Model> model() Ref<Model> model()
%code%{ RETVAL = THIS->model; %}; %code%{ RETVAL = THIS->model; %};
Ref<StringMap> _attributes()
%code%{ RETVAL = &THIS->attributes; %};
Ref<DynamicPrintConfig> config() Ref<DynamicPrintConfig> config()
%code%{ RETVAL = &THIS->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
%}
}; };

View File

@ -1,59 +0,0 @@
%module{Slic3r::XS};
%{
#include <myinit.h>
#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(); %};
};

View File

@ -8,11 +8,6 @@ t_model_material_id T_STD_STRING
t_layer_height_ranges T_LAYER_HEIGHT_RANGES t_layer_height_ranges T_LAYER_HEIGHT_RANGES
StringMap T_STRING_MAP
StringMap* O_OBJECT_SLIC3R
Ref<StringMap> O_OBJECT_SLIC3R_T
BoundingBox* O_OBJECT_SLIC3R BoundingBox* O_OBJECT_SLIC3R
Ref<BoundingBox> O_OBJECT_SLIC3R_T Ref<BoundingBox> O_OBJECT_SLIC3R_T
Clone<BoundingBox> O_OBJECT_SLIC3R_T Clone<BoundingBox> O_OBJECT_SLIC3R_T
@ -177,28 +172,6 @@ T_ARRAYREF
${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]}, ${$ALIAS?\q[GvNAME(CvGV(cv))]:\qq[\"$pname\"]},
\"$var\"); \"$var\");
# http://www.perlmonks.org/?node_id=853194
T_STRING_MAP
{
HV *hv;
HE *he;
std::map<std::string, std::string> 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 T_LAYER_HEIGHT_RANGES
{ {
if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) { if (!SvROK($arg) || SvTYPE(SvRV($arg)) != SVt_PVAV) {

View File

@ -11,9 +11,6 @@
%typemap{std::vector<double>*}; %typemap{std::vector<double>*};
%typemap{std::vector<std::string>}; %typemap{std::vector<std::string>};
%typemap{t_layer_height_ranges}; %typemap{t_layer_height_ranges};
%typemap{StringMap};
%typemap{StringMap*};
%typemap{Ref<StringMap>}{simple};
%typemap{SV*}; %typemap{SV*};
%typemap{AV*}; %typemap{AV*};
%typemap{Point*}; %typemap{Point*};