diff options
Diffstat (limited to 'xs/src')
70 files changed, 719 insertions, 950 deletions
diff --git a/xs/src/libslic3r/BoundingBox.cpp b/xs/src/libslic3r/BoundingBox.cpp index 16c8acadb..1116d2dcb 100644 --- a/xs/src/libslic3r/BoundingBox.cpp +++ b/xs/src/libslic3r/BoundingBox.cpp @@ -219,10 +219,4 @@ BoundingBox3Base<PointClass>::center() const } template Pointf3 BoundingBox3Base<Pointf3>::center() const; -#ifdef SLIC3RXS -REGISTER_CLASS(BoundingBox, "Geometry::BoundingBox"); -REGISTER_CLASS(BoundingBoxf, "Geometry::BoundingBoxf"); -REGISTER_CLASS(BoundingBoxf3, "Geometry::BoundingBoxf3"); -#endif - } diff --git a/xs/src/libslic3r/BoundingBox.hpp b/xs/src/libslic3r/BoundingBox.hpp index fd106a7a5..533a19b56 100644 --- a/xs/src/libslic3r/BoundingBox.hpp +++ b/xs/src/libslic3r/BoundingBox.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_BoundingBox_hpp_ #define slic3r_BoundingBox_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Point.hpp" #include "Polygon.hpp" diff --git a/xs/src/libslic3r/BridgeDetector.cpp b/xs/src/libslic3r/BridgeDetector.cpp index 24140c7b2..956f51a29 100644 --- a/xs/src/libslic3r/BridgeDetector.cpp +++ b/xs/src/libslic3r/BridgeDetector.cpp @@ -327,8 +327,4 @@ BridgeDetector::unsupported_edges(double angle) const return pp; } -#ifdef SLIC3RXS -REGISTER_CLASS(BridgeDetector, "BridgeDetector"); -#endif - } diff --git a/xs/src/libslic3r/BridgeDetector.hpp b/xs/src/libslic3r/BridgeDetector.hpp index c3af09542..5b1566b27 100644 --- a/xs/src/libslic3r/BridgeDetector.hpp +++ b/xs/src/libslic3r/BridgeDetector.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_BridgeDetector_hpp_ #define slic3r_BridgeDetector_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "ExPolygon.hpp" #include "ExPolygonCollection.hpp" #include <string> diff --git a/xs/src/libslic3r/ClipperUtils.cpp b/xs/src/libslic3r/ClipperUtils.cpp index d9cfd5ff5..d085f6c43 100644 --- a/xs/src/libslic3r/ClipperUtils.cpp +++ b/xs/src/libslic3r/ClipperUtils.cpp @@ -689,35 +689,4 @@ void safety_offset(ClipperLib::Paths* paths) scaleClipperPolygons(*paths, 1.0/CLIPPER_OFFSET_SCALE); } -/////////////////////// - -#ifdef SLIC3RXS -SV* -polynode_children_2_perl(const ClipperLib::PolyNode& node) -{ - AV* av = newAV(); - const int len = node.ChildCount(); - if (len > 0) av_extend(av, len-1); - for (int i = 0; i < len; ++i) { - av_store(av, i, polynode2perl(*node.Childs[i])); - } - return (SV*)newRV_noinc((SV*)av); -} - -SV* -polynode2perl(const ClipperLib::PolyNode& node) -{ - HV* hv = newHV(); - Slic3r::Polygon p; - ClipperPath_to_Slic3rMultiPoint(node.Contour, &p); - if (node.IsHole()) { - (void)hv_stores( hv, "hole", Slic3r::perl_to_SV_clone_ref(p) ); - } else { - (void)hv_stores( hv, "outer", Slic3r::perl_to_SV_clone_ref(p) ); - } - (void)hv_stores( hv, "children", polynode_children_2_perl(node) ); - return (SV*)newRV_noinc((SV*)hv); -} -#endif - } diff --git a/xs/src/libslic3r/ClipperUtils.hpp b/xs/src/libslic3r/ClipperUtils.hpp index e5a3b7da5..7bc8deae9 100644 --- a/xs/src/libslic3r/ClipperUtils.hpp +++ b/xs/src/libslic3r/ClipperUtils.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_ClipperUtils_hpp_ #define slic3r_ClipperUtils_hpp_ -#include <myinit.h> +#include <libslic3r.h> #include "clipper.hpp" #include "ExPolygon.hpp" #include "Polygon.hpp" @@ -134,13 +134,6 @@ void simplify_polygons(const Slic3r::Polygons &subject, Slic3r::ExPolygons* retv void safety_offset(ClipperLib::Paths* paths); -///////////////// - -#ifdef SLIC3RXS -SV* polynode_children_2_perl(const ClipperLib::PolyNode& node); -SV* polynode2perl(const ClipperLib::PolyNode& node); -#endif - } #endif diff --git a/xs/src/libslic3r/Config.cpp b/xs/src/libslic3r/Config.cpp index 102a07a2f..71b38c994 100644 --- a/xs/src/libslic3r/Config.cpp +++ b/xs/src/libslic3r/Config.cpp @@ -149,219 +149,6 @@ ConfigBase::setenv_() #endif } -#ifdef SLIC3RXS -SV* -ConfigBase::as_hash() { - HV* hv = newHV(); - - t_config_option_keys opt_keys = this->keys(); - for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) - (void)hv_store( hv, it->c_str(), it->length(), this->get(*it), 0 ); - - return newRV_noinc((SV*)hv); -} - -SV* -ConfigBase::get(t_config_option_key opt_key) { - ConfigOption* opt = this->option(opt_key); - if (opt == NULL) return &PL_sv_undef; - - const ConfigOptionDef* def = this->def->get(opt_key); - if (def->type == coFloat) { - ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt); - return newSVnv(optv->value); - } else if (def->type == coFloats) { - ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt); - AV* av = newAV(); - av_fill(av, optv->values.size()-1); - for (std::vector<double>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) - av_store(av, it - optv->values.begin(), newSVnv(*it)); - return newRV_noinc((SV*)av); - } else if (def->type == coPercent) { - ConfigOptionPercent* optv = dynamic_cast<ConfigOptionPercent*>(opt); - return newSVnv(optv->value); - } else if (def->type == coInt) { - ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt); - return newSViv(optv->value); - } else if (def->type == coInts) { - ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt); - AV* av = newAV(); - av_fill(av, optv->values.size()-1); - for (std::vector<int>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) - av_store(av, it - optv->values.begin(), newSViv(*it)); - return newRV_noinc((SV*)av); - } else if (def->type == coString) { - ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt); - // we don't serialize() because that would escape newlines - return newSVpvn_utf8(optv->value.c_str(), optv->value.length(), true); - } else if (def->type == coStrings) { - ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt); - AV* av = newAV(); - av_fill(av, optv->values.size()-1); - for (std::vector<std::string>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) - av_store(av, it - optv->values.begin(), newSVpvn_utf8(it->c_str(), it->length(), true)); - return newRV_noinc((SV*)av); - } else if (def->type == coPoint) { - ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt); - return perl_to_SV_clone_ref(optv->value); - } else if (def->type == coPoints) { - ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt); - AV* av = newAV(); - av_fill(av, optv->values.size()-1); - for (Pointfs::iterator it = optv->values.begin(); it != optv->values.end(); ++it) - av_store(av, it - optv->values.begin(), perl_to_SV_clone_ref(*it)); - return newRV_noinc((SV*)av); - } else if (def->type == coBool) { - ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt); - return newSViv(optv->value ? 1 : 0); - } else if (def->type == coBools) { - ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt); - AV* av = newAV(); - av_fill(av, optv->values.size()-1); - for (std::vector<bool>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) - av_store(av, it - optv->values.begin(), newSViv(*it ? 1 : 0)); - return newRV_noinc((SV*)av); - } else { - std::string serialized = opt->serialize(); - return newSVpvn_utf8(serialized.c_str(), serialized.length(), true); - } -} - -SV* -ConfigBase::get_at(t_config_option_key opt_key, size_t i) { - ConfigOption* opt = this->option(opt_key); - if (opt == NULL) return &PL_sv_undef; - - const ConfigOptionDef* def = this->def->get(opt_key); - if (def->type == coFloats) { - ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt); - return newSVnv(optv->get_at(i)); - } else if (def->type == coInts) { - ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt); - return newSViv(optv->get_at(i)); - } else if (def->type == coStrings) { - ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt); - // we don't serialize() because that would escape newlines - std::string val = optv->get_at(i); - return newSVpvn_utf8(val.c_str(), val.length(), true); - } else if (def->type == coPoints) { - ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt); - return perl_to_SV_clone_ref(optv->get_at(i)); - } else if (def->type == coBools) { - ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt); - return newSViv(optv->get_at(i) ? 1 : 0); - } else { - return &PL_sv_undef; - } -} - -bool -ConfigBase::set(t_config_option_key opt_key, SV* value) { - ConfigOption* opt = this->option(opt_key, true); - if (opt == NULL) CONFESS("Trying to set non-existing option"); - - const ConfigOptionDef* def = this->def->get(opt_key); - if (def->type == coFloat) { - if (!looks_like_number(value)) return false; - ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt); - optv->value = SvNV(value); - } else if (def->type == coFloats) { - ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt); - std::vector<double> values; - AV* av = (AV*)SvRV(value); - const size_t len = av_len(av)+1; - for (size_t i = 0; i < len; i++) { - SV** elem = av_fetch(av, i, 0); - if (elem == NULL || !looks_like_number(*elem)) return false; - values.push_back(SvNV(*elem)); - } - optv->values = values; - } else if (def->type == coInt) { - if (!looks_like_number(value)) return false; - ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt); - optv->value = SvIV(value); - } else if (def->type == coInts) { - ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt); - std::vector<int> values; - AV* av = (AV*)SvRV(value); - const size_t len = av_len(av)+1; - for (size_t i = 0; i < len; i++) { - SV** elem = av_fetch(av, i, 0); - if (elem == NULL || !looks_like_number(*elem)) return false; - values.push_back(SvIV(*elem)); - } - optv->values = values; - } else if (def->type == coString) { - ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt); - optv->value = std::string(SvPV_nolen(value), SvCUR(value)); - } else if (def->type == coStrings) { - ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt); - optv->values.clear(); - AV* av = (AV*)SvRV(value); - const size_t len = av_len(av)+1; - for (size_t i = 0; i < len; i++) { - SV** elem = av_fetch(av, i, 0); - if (elem == NULL) return false; - optv->values.push_back(std::string(SvPV_nolen(*elem), SvCUR(*elem))); - } - } else if (def->type == coPoint) { - ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt); - return optv->value.from_SV_check(value); - } else if (def->type == coPoints) { - ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt); - std::vector<Pointf> values; - AV* av = (AV*)SvRV(value); - const size_t len = av_len(av)+1; - for (size_t i = 0; i < len; i++) { - SV** elem = av_fetch(av, i, 0); - Pointf point; - if (elem == NULL || !point.from_SV_check(*elem)) return false; - values.push_back(point); - } - optv->values = values; - } else if (def->type == coBool) { - ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt); - optv->value = SvTRUE(value); - } else if (def->type == coBools) { - ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt); - optv->values.clear(); - AV* av = (AV*)SvRV(value); - const size_t len = av_len(av)+1; - for (size_t i = 0; i < len; i++) { - SV** elem = av_fetch(av, i, 0); - if (elem == NULL) return false; - optv->values.push_back(SvTRUE(*elem)); - } - } else { - if (!opt->deserialize( std::string(SvPV_nolen(value)) )) return false; - } - return true; -} - -/* This method is implemented as a workaround for this typemap bug: - https://rt.cpan.org/Public/Bug/Display.html?id=94110 */ -bool -ConfigBase::set_deserialize(const t_config_option_key &opt_key, SV* str) { - size_t len; - const char * c = SvPV(str, len); - std::string value(c, len); - - return this->set_deserialize(opt_key, value); -} - -void -ConfigBase::set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize) -{ - if (!this->has(opt_key)) { - if (deserialize) { - this->set_deserialize(opt_key, value); - } else { - this->set(opt_key, value); - } - } -} -#endif - DynamicConfig& DynamicConfig::operator= (DynamicConfig other) { this->swap(other); @@ -491,19 +278,4 @@ StaticConfig::option(const t_config_option_key &opt_key) const return const_cast<StaticConfig*>(this)->option(opt_key, false); } -#ifdef SLIC3RXS -bool -StaticConfig::set(t_config_option_key opt_key, SV* value) { - const ConfigOptionDef* optdef = this->def->get(opt_key); - if (!optdef->shortcut.empty()) { - for (std::vector<t_config_option_key>::const_iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { - if (!this->set(*it, value)) return false; - } - return true; - } - - return static_cast<ConfigBase*>(this)->set(opt_key, value); -} -#endif - } diff --git a/xs/src/libslic3r/Config.hpp b/xs/src/libslic3r/Config.hpp index 126049579..d4700d3f4 100644 --- a/xs/src/libslic3r/Config.hpp +++ b/xs/src/libslic3r/Config.hpp @@ -9,7 +9,7 @@ #include <stdexcept> #include <string> #include <vector> -#include <myinit.h> +#include "libslic3r.h" #include "Point.hpp" namespace Slic3r { @@ -555,18 +555,9 @@ class ConfigBase t_config_option_keys diff(ConfigBase &other); std::string serialize(const t_config_option_key &opt_key) const; bool set_deserialize(const t_config_option_key &opt_key, std::string str); - void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false); double get_abs_value(const t_config_option_key &opt_key); double get_abs_value(const t_config_option_key &opt_key, double ratio_over); void setenv_(); - - #ifdef SLIC3RXS - SV* as_hash(); - SV* get(t_config_option_key opt_key); - SV* get_at(t_config_option_key opt_key, size_t i); - bool set(t_config_option_key opt_key, SV* value); - bool set_deserialize(const t_config_option_key &opt_key, SV* str); - #endif }; class DynamicConfig : public virtual ConfigBase @@ -596,10 +587,6 @@ class StaticConfig : public virtual ConfigBase virtual ConfigOption* option(const t_config_option_key &opt_key, bool create = false) = 0; const ConfigOption* option(const t_config_option_key &opt_key) const; void set_defaults(); - - #ifdef SLIC3RXS - bool set(t_config_option_key opt_key, SV* value); - #endif }; } diff --git a/xs/src/libslic3r/ExPolygon.cpp b/xs/src/libslic3r/ExPolygon.cpp index c423c6e0a..4e068f0d1 100644 --- a/xs/src/libslic3r/ExPolygon.cpp +++ b/xs/src/libslic3r/ExPolygon.cpp @@ -425,65 +425,4 @@ ExPolygon::lines() const return lines; } -#ifdef SLIC3RXS - -REGISTER_CLASS(ExPolygon, "ExPolygon"); - -SV* -ExPolygon::to_AV() { - const unsigned int num_holes = this->holes.size(); - AV* av = newAV(); - av_extend(av, num_holes); // -1 +1 - - av_store(av, 0, perl_to_SV_ref(this->contour)); - - for (unsigned int i = 0; i < num_holes; i++) { - av_store(av, i+1, perl_to_SV_ref(this->holes[i])); - } - return newRV_noinc((SV*)av); -} - -SV* -ExPolygon::to_SV_pureperl() const -{ - const unsigned int num_holes = this->holes.size(); - AV* av = newAV(); - av_extend(av, num_holes); // -1 +1 - av_store(av, 0, this->contour.to_SV_pureperl()); - for (unsigned int i = 0; i < num_holes; i++) { - av_store(av, i+1, this->holes[i].to_SV_pureperl()); - } - return newRV_noinc((SV*)av); -} - -void -ExPolygon::from_SV(SV* expoly_sv) -{ - AV* expoly_av = (AV*)SvRV(expoly_sv); - const unsigned int num_polygons = av_len(expoly_av)+1; - this->holes.resize(num_polygons-1); - - SV** polygon_sv = av_fetch(expoly_av, 0, 0); - this->contour.from_SV(*polygon_sv); - for (unsigned int i = 0; i < num_polygons-1; i++) { - polygon_sv = av_fetch(expoly_av, i+1, 0); - this->holes[i].from_SV(*polygon_sv); - } -} - -void -ExPolygon::from_SV_check(SV* expoly_sv) -{ - if (sv_isobject(expoly_sv) && (SvTYPE(SvRV(expoly_sv)) == SVt_PVMG)) { - if (!sv_isa(expoly_sv, perl_class_name(this)) && !sv_isa(expoly_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object", perl_class_name(this)); - // a XS ExPolygon was supplied - *this = *(ExPolygon *)SvIV((SV*)SvRV( expoly_sv )); - } else { - // a Perl arrayref was supplied - this->from_SV(expoly_sv); - } -} -#endif - } diff --git a/xs/src/libslic3r/ExPolygon.hpp b/xs/src/libslic3r/ExPolygon.hpp index 7b7b0b760..18d4d8095 100644 --- a/xs/src/libslic3r/ExPolygon.hpp +++ b/xs/src/libslic3r/ExPolygon.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_ExPolygon_hpp_ #define slic3r_ExPolygon_hpp_ +#include "libslic3r.h" #include "Polygon.hpp" #include "Polyline.hpp" #include <vector> @@ -40,13 +41,6 @@ class ExPolygon void triangulate_pp(Polygons* polygons) const; void triangulate_p2t(Polygons* polygons) const; Lines lines() const; - - #ifdef SLIC3RXS - void from_SV(SV* poly_sv); - void from_SV_check(SV* poly_sv); - SV* to_AV(); - SV* to_SV_pureperl() const; - #endif }; } diff --git a/xs/src/libslic3r/ExPolygonCollection.cpp b/xs/src/libslic3r/ExPolygonCollection.cpp index 45f0df477..bebc1260e 100644 --- a/xs/src/libslic3r/ExPolygonCollection.cpp +++ b/xs/src/libslic3r/ExPolygonCollection.cpp @@ -128,8 +128,4 @@ ExPolygonCollection::append(const ExPolygons &expp) this->expolygons.insert(this->expolygons.end(), expp.begin(), expp.end()); } -#ifdef SLIC3RXS -REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection"); -#endif - } diff --git a/xs/src/libslic3r/ExPolygonCollection.hpp b/xs/src/libslic3r/ExPolygonCollection.hpp index ffb306c92..ec3cb9522 100644 --- a/xs/src/libslic3r/ExPolygonCollection.hpp +++ b/xs/src/libslic3r/ExPolygonCollection.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_ExPolygonCollection_hpp_ #define slic3r_ExPolygonCollection_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "ExPolygon.hpp" #include "Line.hpp" #include "Polyline.hpp" diff --git a/xs/src/libslic3r/Extruder.cpp b/xs/src/libslic3r/Extruder.cpp index e254d6806..b9be14661 100644 --- a/xs/src/libslic3r/Extruder.cpp +++ b/xs/src/libslic3r/Extruder.cpp @@ -153,9 +153,4 @@ Extruder::retract_restart_extra_toolchange() const return this->config->retract_restart_extra_toolchange.get_at(this->id); } - -#ifdef SLIC3RXS -REGISTER_CLASS(Extruder, "Extruder"); -#endif - } diff --git a/xs/src/libslic3r/Extruder.hpp b/xs/src/libslic3r/Extruder.hpp index fa91bb42f..76b70df63 100644 --- a/xs/src/libslic3r/Extruder.hpp +++ b/xs/src/libslic3r/Extruder.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Extruder_hpp_ #define slic3r_Extruder_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Point.hpp" #include "PrintConfig.hpp" diff --git a/xs/src/libslic3r/ExtrusionEntity.cpp b/xs/src/libslic3r/ExtrusionEntity.cpp index be32519f6..54ca91e4a 100644 --- a/xs/src/libslic3r/ExtrusionEntity.cpp +++ b/xs/src/libslic3r/ExtrusionEntity.cpp @@ -110,10 +110,6 @@ ExtrusionPath::_inflate_collection(const Polylines &polylines, ExtrusionEntityCo } } -#ifdef SLIC3RXS -REGISTER_CLASS(ExtrusionPath, "ExtrusionPath"); -#endif - Polygons ExtrusionPath::grow() const { @@ -339,8 +335,4 @@ ExtrusionLoop::min_mm3_per_mm() const return min_mm3_per_mm; } -#ifdef SLIC3RXS -REGISTER_CLASS(ExtrusionLoop, "ExtrusionLoop"); -#endif - } diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index c1eef6af3..719c80c15 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_ExtrusionEntity_hpp_ #define slic3r_ExtrusionEntity_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Polygon.hpp" #include "Polyline.hpp" diff --git a/xs/src/libslic3r/ExtrusionEntityCollection.cpp b/xs/src/libslic3r/ExtrusionEntityCollection.cpp index b0f369ec8..dc9b722d3 100644 --- a/xs/src/libslic3r/ExtrusionEntityCollection.cpp +++ b/xs/src/libslic3r/ExtrusionEntityCollection.cpp @@ -227,9 +227,4 @@ ExtrusionEntityCollection::min_mm3_per_mm() const return min_mm3_per_mm; } -#ifdef SLIC3RXS -// there is no ExtrusionLoop::Collection or ExtrusionEntity::Collection -REGISTER_CLASS(ExtrusionEntityCollection, "ExtrusionPath::Collection"); -#endif - } diff --git a/xs/src/libslic3r/ExtrusionEntityCollection.hpp b/xs/src/libslic3r/ExtrusionEntityCollection.hpp index 62909c55c..8ee1b3864 100644 --- a/xs/src/libslic3r/ExtrusionEntityCollection.hpp +++ b/xs/src/libslic3r/ExtrusionEntityCollection.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_ExtrusionEntityCollection_hpp_ #define slic3r_ExtrusionEntityCollection_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "ExtrusionEntity.hpp" namespace Slic3r { diff --git a/xs/src/libslic3r/Flow.cpp b/xs/src/libslic3r/Flow.cpp index f91caed4b..276f60a6a 100644 --- a/xs/src/libslic3r/Flow.cpp +++ b/xs/src/libslic3r/Flow.cpp @@ -114,8 +114,4 @@ Flow::_width_from_spacing(float spacing, float nozzle_diameter, float height, bo return spacing + OVERLAP_FACTOR * height * (1 - PI/4.0); } -#ifdef SLIC3RXS -REGISTER_CLASS(Flow, "Flow"); -#endif - } diff --git a/xs/src/libslic3r/Flow.hpp b/xs/src/libslic3r/Flow.hpp index 88cae2477..cb7291266 100644 --- a/xs/src/libslic3r/Flow.hpp +++ b/xs/src/libslic3r/Flow.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Flow_hpp_ #define slic3r_Flow_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Config.hpp" #include "ExtrusionEntity.hpp" diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 8f4f98260..f94784450 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -65,10 +65,6 @@ AvoidCrossingPerimeters::travel_to(GCode &gcodegen, Point point) } } -#ifdef SLIC3RXS -REGISTER_CLASS(AvoidCrossingPerimeters, "GCode::AvoidCrossingPerimeters"); -#endif - OozePrevention::OozePrevention() : enable(false) { @@ -125,10 +121,6 @@ OozePrevention::_get_temp(GCode &gcodegen) : gcodegen.config.temperature.get_at(gcodegen.writer.extruder()->id); } -#ifdef SLIC3RXS -REGISTER_CLASS(OozePrevention, "GCode::OozePrevention"); -#endif - Wipe::Wipe() : enable(false) { @@ -202,10 +194,6 @@ Wipe::wipe(GCode &gcodegen, bool toolchange) return gcode; } -#ifdef SLIC3RXS -REGISTER_CLASS(Wipe, "GCode::Wipe"); -#endif - #define EXTRUDER_CONFIG(OPT) this->config.OPT.get_at(this->writer.extruder()->id) GCode::GCode() @@ -766,8 +754,4 @@ GCode::point_to_gcode(const Point &point) ); } -#ifdef SLIC3RXS -REGISTER_CLASS(GCode, "GCode"); -#endif - } diff --git a/xs/src/libslic3r/GCode.hpp b/xs/src/libslic3r/GCode.hpp index f477c779e..29aa7633a 100644 --- a/xs/src/libslic3r/GCode.hpp +++ b/xs/src/libslic3r/GCode.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_GCode_hpp_ #define slic3r_GCode_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "ExPolygon.hpp" #include "GCodeWriter.hpp" #include "Layer.hpp" diff --git a/xs/src/libslic3r/GCodeSender.cpp b/xs/src/libslic3r/GCodeSender.cpp index 5123ccbd2..9d3a45477 100644 --- a/xs/src/libslic3r/GCodeSender.cpp +++ b/xs/src/libslic3r/GCodeSender.cpp @@ -474,11 +474,4 @@ GCodeSender::reset() } -#ifdef SLIC3RXS -#include <myinit.h> -namespace Slic3r { -__REGISTER_CLASS(GCodeSender, "GCode::Sender"); -} -#endif - #endif diff --git a/xs/src/libslic3r/GCodeSender.hpp b/xs/src/libslic3r/GCodeSender.hpp index 6b5af95fe..384d417cc 100644 --- a/xs/src/libslic3r/GCodeSender.hpp +++ b/xs/src/libslic3r/GCodeSender.hpp @@ -2,7 +2,7 @@ #define slic3r_GCodeSender_hpp_ #ifdef BOOST_LIBS -#include <libslic3r/libslic3r.h> +#include "libslic3r.h" #include <queue> #include <string> #include <vector> diff --git a/xs/src/libslic3r/GCodeWriter.cpp b/xs/src/libslic3r/GCodeWriter.cpp index 4055a270a..e6bcb8df8 100644 --- a/xs/src/libslic3r/GCodeWriter.cpp +++ b/xs/src/libslic3r/GCodeWriter.cpp @@ -520,8 +520,4 @@ GCodeWriter::get_position() const return this->_pos; } -#ifdef SLIC3RXS -REGISTER_CLASS(GCodeWriter, "GCode::Writer"); -#endif - } diff --git a/xs/src/libslic3r/GCodeWriter.hpp b/xs/src/libslic3r/GCodeWriter.hpp index e7b93ac42..21ed8d241 100644 --- a/xs/src/libslic3r/GCodeWriter.hpp +++ b/xs/src/libslic3r/GCodeWriter.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_GCodeWriter_hpp_ #define slic3r_GCodeWriter_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <string> #include "Extruder.hpp" #include "Point.hpp" diff --git a/xs/src/libslic3r/Geometry.hpp b/xs/src/libslic3r/Geometry.hpp index b73480725..f64871d2d 100644 --- a/xs/src/libslic3r/Geometry.hpp +++ b/xs/src/libslic3r/Geometry.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_Geometry_hpp_ #define slic3r_Geometry_hpp_ +#include "libslic3r.h" #include "BoundingBox.hpp" #include "Polygon.hpp" #include "Polyline.hpp" diff --git a/xs/src/libslic3r/Layer.cpp b/xs/src/libslic3r/Layer.cpp index f3d5b1637..dc931923c 100644 --- a/xs/src/libslic3r/Layer.cpp +++ b/xs/src/libslic3r/Layer.cpp @@ -245,10 +245,6 @@ Layer::make_perimeters() } } -#ifdef SLIC3RXS -REGISTER_CLASS(Layer, "Layer"); -#endif - SupportLayer::SupportLayer(size_t id, PrintObject *object, coordf_t height, coordf_t print_z, coordf_t slice_z) @@ -260,9 +256,5 @@ SupportLayer::~SupportLayer() { } -#ifdef SLIC3RXS -REGISTER_CLASS(SupportLayer, "Layer::Support"); -#endif - } diff --git a/xs/src/libslic3r/Layer.hpp b/xs/src/libslic3r/Layer.hpp index a6f6f9a43..4badb8374 100644 --- a/xs/src/libslic3r/Layer.hpp +++ b/xs/src/libslic3r/Layer.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Layer_hpp_ #define slic3r_Layer_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Flow.hpp" #include "SurfaceCollection.hpp" #include "ExtrusionEntityCollection.hpp" diff --git a/xs/src/libslic3r/LayerRegion.cpp b/xs/src/libslic3r/LayerRegion.cpp index 4f874a2ea..a2683fa03 100644 --- a/xs/src/libslic3r/LayerRegion.cpp +++ b/xs/src/libslic3r/LayerRegion.cpp @@ -271,8 +271,4 @@ LayerRegion::infill_area_threshold() const return ss*ss; } -#ifdef SLIC3RXS -REGISTER_CLASS(LayerRegion, "Layer::Region"); -#endif - } diff --git a/xs/src/libslic3r/Line.cpp b/xs/src/libslic3r/Line.cpp index 84ba10a5b..f3b8ff43c 100644 --- a/xs/src/libslic3r/Line.cpp +++ b/xs/src/libslic3r/Line.cpp @@ -163,51 +163,6 @@ Line::normal() const return Vector((this->b.y - this->a.y), -(this->b.x - this->a.x)); } -#ifdef SLIC3RXS - -REGISTER_CLASS(Line, "Line"); - -void -Line::from_SV(SV* line_sv) -{ - AV* line_av = (AV*)SvRV(line_sv); - this->a.from_SV_check(*av_fetch(line_av, 0, 0)); - this->b.from_SV_check(*av_fetch(line_av, 1, 0)); -} - -void -Line::from_SV_check(SV* line_sv) -{ - if (sv_isobject(line_sv) && (SvTYPE(SvRV(line_sv)) == SVt_PVMG)) { - if (!sv_isa(line_sv, perl_class_name(this)) && !sv_isa(line_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object", perl_class_name(this)); - *this = *(Line*)SvIV((SV*)SvRV( line_sv )); - } else { - this->from_SV(line_sv); - } -} - -SV* -Line::to_AV() { - AV* av = newAV(); - av_extend(av, 1); - - av_store(av, 0, perl_to_SV_ref(this->a)); - av_store(av, 1, perl_to_SV_ref(this->b)); - - return newRV_noinc((SV*)av); -} - -SV* -Line::to_SV_pureperl() const { - AV* av = newAV(); - av_extend(av, 1); - av_store(av, 0, this->a.to_SV_pureperl()); - av_store(av, 1, this->b.to_SV_pureperl()); - return newRV_noinc((SV*)av); -} -#endif - Pointf3 Linef3::intersect_plane(double z) const { @@ -225,8 +180,4 @@ Linef3::scale(double factor) this->b.scale(factor); } -#ifdef SLIC3RXS -REGISTER_CLASS(Linef3, "Linef3"); -#endif - } diff --git a/xs/src/libslic3r/Line.hpp b/xs/src/libslic3r/Line.hpp index 327ff4d1e..c4438792a 100644 --- a/xs/src/libslic3r/Line.hpp +++ b/xs/src/libslic3r/Line.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Line_hpp_ #define slic3r_Line_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Point.hpp" namespace Slic3r { @@ -39,13 +39,6 @@ class Line double direction() const; Vector vector() const; Vector normal() const; - - #ifdef SLIC3RXS - void from_SV(SV* line_sv); - void from_SV_check(SV* line_sv); - SV* to_AV(); - SV* to_SV_pureperl() const; - #endif }; class Linef @@ -66,12 +59,6 @@ class Linef3 explicit Linef3(Pointf3 _a, Pointf3 _b): a(_a), b(_b) {}; Pointf3 intersect_plane(double z) const; void scale(double factor); - - #ifdef SLIC3RXS - void from_SV(SV* line_sv); - void from_SV_check(SV* line_sv); - SV* to_SV_pureperl() const; - #endif }; } diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp index 8bd381dd0..36001b9b2 100644 --- a/xs/src/libslic3r/Model.cpp +++ b/xs/src/libslic3r/Model.cpp @@ -311,11 +311,6 @@ Model::duplicate_objects_grid(size_t x, size_t y, coordf_t dist) } } -#ifdef SLIC3RXS -REGISTER_CLASS(Model, "Model"); -#endif - - ModelMaterial::ModelMaterial(Model *model) : model(model) {} ModelMaterial::ModelMaterial(Model *model, const ModelMaterial &other) : attributes(other.attributes), config(other.config), model(model) @@ -328,11 +323,6 @@ ModelMaterial::apply(const t_model_material_attributes &attributes) } -#ifdef SLIC3RXS -REGISTER_CLASS(ModelMaterial, "Model::Material"); -#endif - - ModelObject::ModelObject(Model *model) : model(model) {} @@ -711,10 +701,6 @@ ModelObject::split(ModelObjectPtrs* new_objects) return; } -#ifdef SLIC3RXS -REGISTER_CLASS(ModelObject, "Model::Object"); -#endif - ModelVolume::ModelVolume(ModelObject* object, const TriangleMesh &mesh) : mesh(mesh), modifier(false), object(object) @@ -765,10 +751,6 @@ ModelVolume::assign_unique_material() return model->add_material(this->_material_id); } -#ifdef SLIC3RXS -REGISTER_CLASS(ModelVolume, "Model::Volume"); -#endif - ModelInstance::ModelInstance(ModelObject *object) : rotation(0), scaling_factor(1), object(object) @@ -794,8 +776,4 @@ ModelInstance::transform_polygon(Polygon* polygon) const polygon->scale(this->scaling_factor); // scale around polygon origin } -#ifdef SLIC3RXS -REGISTER_CLASS(ModelInstance, "Model::Instance"); -#endif - } diff --git a/xs/src/libslic3r/Model.hpp b/xs/src/libslic3r/Model.hpp index a2553f6fa..f10707457 100644 --- a/xs/src/libslic3r/Model.hpp +++ b/xs/src/libslic3r/Model.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Model_hpp_ #define slic3r_Model_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "PrintConfig.hpp" #include "Layer.hpp" #include "Point.hpp" diff --git a/xs/src/libslic3r/MotionPlanner.cpp b/xs/src/libslic3r/MotionPlanner.cpp index d35a89ec5..836be3e20 100644 --- a/xs/src/libslic3r/MotionPlanner.cpp +++ b/xs/src/libslic3r/MotionPlanner.cpp @@ -391,8 +391,4 @@ MotionPlannerGraph::shortest_path(size_t from, size_t to) return polyline; } -#ifdef SLIC3RXS -REGISTER_CLASS(MotionPlanner, "MotionPlanner"); -#endif - } diff --git a/xs/src/libslic3r/MotionPlanner.hpp b/xs/src/libslic3r/MotionPlanner.hpp index d49cc8198..8344f74de 100644 --- a/xs/src/libslic3r/MotionPlanner.hpp +++ b/xs/src/libslic3r/MotionPlanner.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_MotionPlanner_hpp_ #define slic3r_MotionPlanner_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "ClipperUtils.hpp" #include "ExPolygonCollection.hpp" #include "Polyline.hpp" diff --git a/xs/src/libslic3r/MultiPoint.cpp b/xs/src/libslic3r/MultiPoint.cpp index 2e7131e6e..0e4ede761 100644 --- a/xs/src/libslic3r/MultiPoint.cpp +++ b/xs/src/libslic3r/MultiPoint.cpp @@ -154,51 +154,4 @@ MultiPoint::_douglas_peucker(const Points &points, const double tolerance) return results; } -#ifdef SLIC3RXS -void -MultiPoint::from_SV(SV* poly_sv) -{ - AV* poly_av = (AV*)SvRV(poly_sv); - const unsigned int num_points = av_len(poly_av)+1; - this->points.resize(num_points); - - for (unsigned int i = 0; i < num_points; i++) { - SV** point_sv = av_fetch(poly_av, i, 0); - this->points[i].from_SV_check(*point_sv); - } -} - -void -MultiPoint::from_SV_check(SV* poly_sv) -{ - if (sv_isobject(poly_sv) && (SvTYPE(SvRV(poly_sv)) == SVt_PVMG)) { - *this = *(MultiPoint*)SvIV((SV*)SvRV( poly_sv )); - } else { - this->from_SV(poly_sv); - } -} - -SV* -MultiPoint::to_AV() { - const unsigned int num_points = this->points.size(); - AV* av = newAV(); - if (num_points > 0) av_extend(av, num_points-1); - for (unsigned int i = 0; i < num_points; i++) { - av_store(av, i, perl_to_SV_ref(this->points[i])); - } - return newRV_noinc((SV*)av); -} - -SV* -MultiPoint::to_SV_pureperl() const { - const unsigned int num_points = this->points.size(); - AV* av = newAV(); - if (num_points > 0) av_extend(av, num_points-1); - for (unsigned int i = 0; i < num_points; i++) { - av_store(av, i, this->points[i].to_SV_pureperl()); - } - return newRV_noinc((SV*)av); -} -#endif - } diff --git a/xs/src/libslic3r/MultiPoint.hpp b/xs/src/libslic3r/MultiPoint.hpp index 63ee3bda7..053709bbd 100644 --- a/xs/src/libslic3r/MultiPoint.hpp +++ b/xs/src/libslic3r/MultiPoint.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_MultiPoint_hpp_ #define slic3r_MultiPoint_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <algorithm> #include <vector> #include "Line.hpp" @@ -38,13 +38,6 @@ class MultiPoint void append(const Points::const_iterator &begin, const Points::const_iterator &end); static Points _douglas_peucker(const Points &points, const double tolerance); - - #ifdef SLIC3RXS - void from_SV(SV* poly_sv); - void from_SV_check(SV* poly_sv); - SV* to_AV(); - SV* to_SV_pureperl() const; - #endif }; } diff --git a/xs/src/libslic3r/PerimeterGenerator.cpp b/xs/src/libslic3r/PerimeterGenerator.cpp index 969a85259..5a69f4f20 100644 --- a/xs/src/libslic3r/PerimeterGenerator.cpp +++ b/xs/src/libslic3r/PerimeterGenerator.cpp @@ -497,10 +497,6 @@ PerimeterGenerator::_fill_gaps(double min, double max, double w, return coll; } -#ifdef SLIC3RXS -REGISTER_CLASS(PerimeterGenerator, "Layer::PerimeterGenerator"); -#endif - bool PerimeterGeneratorLoop::is_external() const { diff --git a/xs/src/libslic3r/PerimeterGenerator.hpp b/xs/src/libslic3r/PerimeterGenerator.hpp index 680790ffd..b25a996a0 100644 --- a/xs/src/libslic3r/PerimeterGenerator.hpp +++ b/xs/src/libslic3r/PerimeterGenerator.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_PerimeterGenerator_hpp_ #define slic3r_PerimeterGenerator_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <vector> #include "ExPolygonCollection.hpp" #include "Flow.hpp" diff --git a/xs/src/libslic3r/PlaceholderParser.cpp b/xs/src/libslic3r/PlaceholderParser.cpp index 4a73cd12b..57220628f 100644 --- a/xs/src/libslic3r/PlaceholderParser.cpp +++ b/xs/src/libslic3r/PlaceholderParser.cpp @@ -151,8 +151,4 @@ PlaceholderParser::find_and_replace(std::string &source, std::string const &find return found; } -#ifdef SLIC3RXS -REGISTER_CLASS(PlaceholderParser, "GCode::PlaceholderParser"); -#endif - } diff --git a/xs/src/libslic3r/PlaceholderParser.hpp b/xs/src/libslic3r/PlaceholderParser.hpp index 20c1ace48..0cdf809d5 100644 --- a/xs/src/libslic3r/PlaceholderParser.hpp +++ b/xs/src/libslic3r/PlaceholderParser.hpp @@ -1,8 +1,7 @@ #ifndef slic3r_PlaceholderParser_hpp_ #define slic3r_PlaceholderParser_hpp_ - -#include <myinit.h> +#include "libslic3r.h" #include <map> #include <string> #include <vector> diff --git a/xs/src/libslic3r/Point.cpp b/xs/src/libslic3r/Point.cpp index 51ad8b4d1..35948b7d8 100644 --- a/xs/src/libslic3r/Point.cpp +++ b/xs/src/libslic3r/Point.cpp @@ -299,46 +299,6 @@ operator*(double scalar, const Point& point2) return Point(scalar * point2.x, scalar * point2.y); } -#ifdef SLIC3RXS - -REGISTER_CLASS(Point, "Point"); - -SV* -Point::to_SV_pureperl() const { - AV* av = newAV(); - av_fill(av, 1); - av_store(av, 0, newSViv(this->x)); - av_store(av, 1, newSViv(this->y)); - return newRV_noinc((SV*)av); -} - -void -Point::from_SV(SV* point_sv) -{ - AV* point_av = (AV*)SvRV(point_sv); - // get a double from Perl and round it, otherwise - // it would get truncated - this->x = lrint(SvNV(*av_fetch(point_av, 0, 0))); - this->y = lrint(SvNV(*av_fetch(point_av, 1, 0))); -} - -void -Point::from_SV_check(SV* point_sv) -{ - if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { - if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv)))); - *this = *(Point*)SvIV((SV*)SvRV( point_sv )); - } else { - this->from_SV(point_sv); - } -} - - -REGISTER_CLASS(Point3, "Point3"); - -#endif - std::ostream& operator<<(std::ostream &stm, const Pointf &pointf) { @@ -386,46 +346,6 @@ Pointf::vector_to(const Pointf &point) const return Vectorf(point.x - this->x, point.y - this->y); } -#ifdef SLIC3RXS - -REGISTER_CLASS(Pointf, "Pointf"); - -SV* -Pointf::to_SV_pureperl() const { - AV* av = newAV(); - av_fill(av, 1); - av_store(av, 0, newSVnv(this->x)); - av_store(av, 1, newSVnv(this->y)); - return newRV_noinc((SV*)av); -} - -bool -Pointf::from_SV(SV* point_sv) -{ - AV* point_av = (AV*)SvRV(point_sv); - SV* sv_x = *av_fetch(point_av, 0, 0); - SV* sv_y = *av_fetch(point_av, 1, 0); - if (!looks_like_number(sv_x) || !looks_like_number(sv_y)) return false; - - this->x = SvNV(sv_x); - this->y = SvNV(sv_y); - return true; -} - -bool -Pointf::from_SV_check(SV* point_sv) -{ - if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { - if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv)))); - *this = *(Pointf*)SvIV((SV*)SvRV( point_sv )); - return true; - } else { - return this->from_SV(point_sv); - } -} -#endif - void Pointf3::scale(double factor) { @@ -467,8 +387,4 @@ Pointf3::vector_to(const Pointf3 &point) const return Vectorf3(point.x - this->x, point.y - this->y, point.z - this->z); } -#ifdef SLIC3RXS -REGISTER_CLASS(Pointf3, "Pointf3"); -#endif - } diff --git a/xs/src/libslic3r/Point.hpp b/xs/src/libslic3r/Point.hpp index a0e382fb3..1a5bd641e 100644 --- a/xs/src/libslic3r/Point.hpp +++ b/xs/src/libslic3r/Point.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Point_hpp_ #define slic3r_Point_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <vector> #include <math.h> #include <string> @@ -60,12 +60,6 @@ class Point Point projection_onto(const Line &line) const; Point negative() const; Vector vector_to(const Point &point) const; - - #ifdef SLIC3RXS - void from_SV(SV* point_sv); - void from_SV_check(SV* point_sv); - SV* to_SV_pureperl() const; - #endif }; Point operator+(const Point& point1, const Point& point2); @@ -98,12 +92,6 @@ class Pointf void rotate(double angle, const Pointf ¢er); Pointf negative() const; Vectorf vector_to(const Pointf &point) const; - - #ifdef SLIC3RXS - bool from_SV(SV* point_sv); - bool from_SV_check(SV* point_sv); - SV* to_SV_pureperl() const; - #endif }; class Pointf3 : public Pointf diff --git a/xs/src/libslic3r/Polygon.cpp b/xs/src/libslic3r/Polygon.cpp index 93a191acb..102838809 100644 --- a/xs/src/libslic3r/Polygon.cpp +++ b/xs/src/libslic3r/Polygon.cpp @@ -1,4 +1,3 @@ -#include <myinit.h> #include "ClipperUtils.hpp" #include "Polygon.hpp" #include "Polyline.hpp" @@ -266,17 +265,4 @@ Polygon::convex_points(double angle) const return points; } -#ifdef SLIC3RXS -REGISTER_CLASS(Polygon, "Polygon"); - -void -Polygon::from_SV_check(SV* poly_sv) -{ - if (sv_isobject(poly_sv) && !sv_isa(poly_sv, perl_class_name(this)) && !sv_isa(poly_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object", perl_class_name(this)); - - MultiPoint::from_SV_check(poly_sv); -} -#endif - } diff --git a/xs/src/libslic3r/Polygon.hpp b/xs/src/libslic3r/Polygon.hpp index bed80e177..ff8ec0d80 100644 --- a/xs/src/libslic3r/Polygon.hpp +++ b/xs/src/libslic3r/Polygon.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Polygon_hpp_ #define slic3r_Polygon_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <vector> #include <string> #include "Line.hpp" @@ -42,10 +42,6 @@ class Polygon : public MultiPoint { std::string wkt() const; Points concave_points(double angle = PI) const; Points convex_points(double angle = PI) const; - - #ifdef SLIC3RXS - void from_SV_check(SV* poly_sv); - #endif }; } diff --git a/xs/src/libslic3r/Polyline.cpp b/xs/src/libslic3r/Polyline.cpp index c0ba0092b..db2a9fdac 100644 --- a/xs/src/libslic3r/Polyline.cpp +++ b/xs/src/libslic3r/Polyline.cpp @@ -247,18 +247,4 @@ Polyline::wkt() const return wkt.str(); } - -#ifdef SLIC3RXS -REGISTER_CLASS(Polyline, "Polyline"); - -void -Polyline::from_SV_check(SV* poly_sv) -{ - if (!sv_isa(poly_sv, perl_class_name(this)) && !sv_isa(poly_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object",perl_class_name(this)); - - MultiPoint::from_SV_check(poly_sv); -} -#endif - } diff --git a/xs/src/libslic3r/Polyline.hpp b/xs/src/libslic3r/Polyline.hpp index cf91b7184..ef327cbb3 100644 --- a/xs/src/libslic3r/Polyline.hpp +++ b/xs/src/libslic3r/Polyline.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_Polyline_hpp_ #define slic3r_Polyline_hpp_ +#include "libslic3r.h" #include "Line.hpp" #include "MultiPoint.hpp" #include <string> @@ -28,10 +29,6 @@ class Polyline : public MultiPoint { void split_at(const Point &point, Polyline* p1, Polyline* p2) const; bool is_straight() const; std::string wkt() const; - - #ifdef SLIC3RXS - void from_SV_check(SV* poly_sv); - #endif }; } diff --git a/xs/src/libslic3r/PolylineCollection.cpp b/xs/src/libslic3r/PolylineCollection.cpp index b7e34b670..f3077b0e1 100644 --- a/xs/src/libslic3r/PolylineCollection.cpp +++ b/xs/src/libslic3r/PolylineCollection.cpp @@ -56,8 +56,4 @@ PolylineCollection::append(const Polylines &pp) this->polylines.insert(this->polylines.end(), pp.begin(), pp.end()); } -#ifdef SLIC3RXS -REGISTER_CLASS(PolylineCollection, "Polyline::Collection"); -#endif - } diff --git a/xs/src/libslic3r/PolylineCollection.hpp b/xs/src/libslic3r/PolylineCollection.hpp index d903b35c5..d41e8c465 100644 --- a/xs/src/libslic3r/PolylineCollection.hpp +++ b/xs/src/libslic3r/PolylineCollection.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_PolylineCollection_hpp_ #define slic3r_PolylineCollection_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "Polyline.hpp" namespace Slic3r { diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 84730dded..19dc63263 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -842,10 +842,4 @@ Print::auto_assign_extruders(ModelObject* model_object) const } } - -#ifdef SLIC3RXS -REGISTER_CLASS(Print, "Print"); -#endif - - } diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index e5f085ff1..fcf6d0a79 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_Print_hpp_ #define slic3r_Print_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <set> #include <vector> #include <stdexcept> diff --git a/xs/src/libslic3r/PrintConfig.cpp b/xs/src/libslic3r/PrintConfig.cpp index 34e3dd747..460b036fb 100644 --- a/xs/src/libslic3r/PrintConfig.cpp +++ b/xs/src/libslic3r/PrintConfig.cpp @@ -1316,13 +1316,4 @@ PrintConfigBase::min_object_distance() const : duplicate_distance; } -#ifdef SLIC3RXS -REGISTER_CLASS(DynamicPrintConfig, "Config"); -REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject"); -REGISTER_CLASS(PrintRegionConfig, "Config::PrintRegion"); -REGISTER_CLASS(GCodeConfig, "Config::GCode"); -REGISTER_CLASS(PrintConfig, "Config::Print"); -REGISTER_CLASS(FullPrintConfig, "Config::Full"); -#endif - } diff --git a/xs/src/libslic3r/PrintConfig.hpp b/xs/src/libslic3r/PrintConfig.hpp index 2df6dd8d2..b14e669c6 100644 --- a/xs/src/libslic3r/PrintConfig.hpp +++ b/xs/src/libslic3r/PrintConfig.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_PrintConfig_hpp_ #define slic3r_PrintConfig_hpp_ +#include "libslic3r.h" #include "Config.hpp" #define OPT_PTR(KEY) if (opt_key == #KEY) return &this->KEY diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index ab25be577..23d9e74e1 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -485,9 +485,4 @@ PrintObject::bridge_over_infill() } } - -#ifdef SLIC3RXS -REGISTER_CLASS(PrintObject, "Print::Object"); -#endif - } diff --git a/xs/src/libslic3r/PrintRegion.cpp b/xs/src/libslic3r/PrintRegion.cpp index 1807f84bc..e6ef456bc 100644 --- a/xs/src/libslic3r/PrintRegion.cpp +++ b/xs/src/libslic3r/PrintRegion.cpp @@ -65,8 +65,4 @@ PrintRegion::flow(FlowRole role, double layer_height, bool bridge, bool first_la return Flow::new_from_config_width(role, config_width, nozzle_diameter, layer_height, bridge ? (float)this->config.bridge_flow_ratio : 0.0); } -#ifdef SLIC3RXS -REGISTER_CLASS(PrintRegion, "Print::Region"); -#endif - } diff --git a/xs/src/libslic3r/SVG.hpp b/xs/src/libslic3r/SVG.hpp index cbc546402..def1f13f0 100644 --- a/xs/src/libslic3r/SVG.hpp +++ b/xs/src/libslic3r/SVG.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_SVG_hpp_ #define slic3r_SVG_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include "ExPolygon.hpp" #include "Line.hpp" #include "TriangleMesh.hpp" diff --git a/xs/src/libslic3r/Surface.cpp b/xs/src/libslic3r/Surface.cpp index e7d66c17b..4d2234e4d 100644 --- a/xs/src/libslic3r/Surface.cpp +++ b/xs/src/libslic3r/Surface.cpp @@ -54,18 +54,4 @@ Surface::is_bridge() const || this->surface_type == stInternalBridge; } -#ifdef SLIC3RXS - -REGISTER_CLASS(Surface, "Surface"); - -void -Surface::from_SV_check(SV* surface_sv) -{ - if (!sv_isa(surface_sv, perl_class_name(this)) && !sv_isa(surface_sv, perl_class_name_ref(this))) - CONFESS("Not a valid %s object", perl_class_name(this)); - // a XS Surface was supplied - *this = *(Surface *)SvIV((SV*)SvRV( surface_sv )); -} -#endif - } diff --git a/xs/src/libslic3r/Surface.hpp b/xs/src/libslic3r/Surface.hpp index a4a28a2c3..21395bdc6 100644 --- a/xs/src/libslic3r/Surface.hpp +++ b/xs/src/libslic3r/Surface.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_Surface_hpp_ #define slic3r_Surface_hpp_ +#include "libslic3r.h" #include "ExPolygon.hpp" namespace Slic3r { @@ -28,10 +29,6 @@ class Surface bool is_internal() const; bool is_bottom() const; bool is_bridge() const; - - #ifdef SLIC3RXS - void from_SV_check(SV* surface_sv); - #endif }; typedef std::vector<Surface> Surfaces; diff --git a/xs/src/libslic3r/SurfaceCollection.cpp b/xs/src/libslic3r/SurfaceCollection.cpp index 2e96d4b1e..2cb244c7a 100644 --- a/xs/src/libslic3r/SurfaceCollection.cpp +++ b/xs/src/libslic3r/SurfaceCollection.cpp @@ -117,8 +117,4 @@ SurfaceCollection::append(const SurfaceCollection &coll) this->surfaces.insert(this->surfaces.end(), coll.surfaces.begin(), coll.surfaces.end()); } -#ifdef SLIC3RXS -REGISTER_CLASS(SurfaceCollection, "Surface::Collection"); -#endif - } diff --git a/xs/src/libslic3r/SurfaceCollection.hpp b/xs/src/libslic3r/SurfaceCollection.hpp index 40e36c5f0..a4a3a7e5d 100644 --- a/xs/src/libslic3r/SurfaceCollection.hpp +++ b/xs/src/libslic3r/SurfaceCollection.hpp @@ -1,6 +1,7 @@ #ifndef slic3r_SurfaceCollection_hpp_ #define slic3r_SurfaceCollection_hpp_ +#include "libslic3r.h" #include "Surface.hpp" #include <vector> diff --git a/xs/src/libslic3r/TriangleMesh.cpp b/xs/src/libslic3r/TriangleMesh.cpp index 6df4eba5c..8bc5f9d00 100644 --- a/xs/src/libslic3r/TriangleMesh.cpp +++ b/xs/src/libslic3r/TriangleMesh.cpp @@ -405,52 +405,6 @@ TriangleMesh::require_shared_vertices() if (this->stl.v_shared == NULL) stl_generate_shared_vertices(&(this->stl)); } -#ifdef SLIC3RXS - -REGISTER_CLASS(TriangleMesh, "TriangleMesh"); - -SV* -TriangleMesh::to_SV() { - SV* sv = newSV(0); - sv_setref_pv( sv, perl_class_name(this), (void*)this ); - return sv; -} - -void TriangleMesh::ReadFromPerl(SV* vertices, SV* facets) -{ - stl.error = 0; - stl.stats.type = inmemory; - - // count facets and allocate memory - AV* facets_av = (AV*)SvRV(facets); - stl.stats.number_of_facets = av_len(facets_av)+1; - stl.stats.original_num_facets = stl.stats.number_of_facets; - stl_allocate(&stl); - - // read geometry - AV* vertices_av = (AV*)SvRV(vertices); - for (int i = 0; i < stl.stats.number_of_facets; i++) { - AV* facet_av = (AV*)SvRV(*av_fetch(facets_av, i, 0)); - stl_facet facet; - facet.normal.x = 0; - facet.normal.y = 0; - facet.normal.z = 0; - for (unsigned int v = 0; v <= 2; v++) { - AV* vertex_av = (AV*)SvRV(*av_fetch(vertices_av, SvIV(*av_fetch(facet_av, v, 0)), 0)); - facet.vertex[v].x = SvNV(*av_fetch(vertex_av, 0, 0)); - facet.vertex[v].y = SvNV(*av_fetch(vertex_av, 1, 0)); - facet.vertex[v].z = SvNV(*av_fetch(vertex_av, 2, 0)); - } - facet.extra[0] = 0; - facet.extra[1] = 0; - - stl.facet_start[i] = facet; - } - - stl_get_size(&(this->stl)); -} -#endif - void TriangleMeshSlicer::slice(const std::vector<float> &z, std::vector<Polygons>* layers) { diff --git a/xs/src/libslic3r/TriangleMesh.hpp b/xs/src/libslic3r/TriangleMesh.hpp index 8fd92863c..cf129809a 100644 --- a/xs/src/libslic3r/TriangleMesh.hpp +++ b/xs/src/libslic3r/TriangleMesh.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_TriangleMesh_hpp_ #define slic3r_TriangleMesh_hpp_ -#include <myinit.h> +#include "libslic3r.h" #include <admesh/stl.h> #include <vector> #include "BoundingBox.hpp" @@ -53,11 +53,6 @@ class TriangleMesh stl_file stl; bool repaired; - #ifdef SLIC3RXS - SV* to_SV(); - void ReadFromPerl(SV* vertices, SV* facets); - #endif - private: void require_shared_vertices(); friend class TriangleMeshSlicer; diff --git a/xs/src/libslic3r/utils.cpp b/xs/src/libslic3r/utils.cpp index d0b1e879b..3f3ed326b 100644 --- a/xs/src/libslic3r/utils.cpp +++ b/xs/src/libslic3r/utils.cpp @@ -1,4 +1,4 @@ -#include <myinit.h> +#include <xsinit.h> void confess_at(const char *file, int line, const char *func, diff --git a/xs/src/myinit.h b/xs/src/myinit.h deleted file mode 100644 index fd7c5a07d..000000000 --- a/xs/src/myinit.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _myinit_h_ -#define _myinit_h_ - -// undef some macros set by Perl which cause compilation errors on Win32 -#undef read -#undef seekdir -#undef bind -#undef send -#undef connect -#undef wait -#undef accept -#undef close -#undef open -#undef write -#undef socket -#undef listen -#undef shutdown -#undef ioctl -#undef getpeername -#undef rect -#undef setsockopt -#undef getsockopt -#undef getsockname -#undef gethostname -#undef select -#undef socketpair -#undef recvfrom -#undef sendto - -// these need to be included early for Win32 (listing it in Build.PL is not enough) -#include <ostream> -#include <iostream> -#include <sstream> - -#ifdef SLIC3RXS -extern "C" { -#include "EXTERN.h" -#include "perl.h" -#include "XSUB.h" -#include "ppport.h" -#undef do_open -#undef do_close -} -#include "perlglue.hpp" -#endif - -#include "libslic3r/libslic3r.h" - -#endif diff --git a/xs/src/perlglue.cpp b/xs/src/perlglue.cpp new file mode 100644 index 000000000..22769e774 --- /dev/null +++ b/xs/src/perlglue.cpp @@ -0,0 +1,537 @@ +#ifdef SLIC3RXS +#include <xsinit.h> + +namespace Slic3r { + +REGISTER_CLASS(ExPolygon, "ExPolygon"); +REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection"); +REGISTER_CLASS(Extruder, "Extruder"); +REGISTER_CLASS(ExtrusionPath, "ExtrusionPath"); +REGISTER_CLASS(ExtrusionLoop, "ExtrusionLoop"); +// there is no ExtrusionLoop::Collection or ExtrusionEntity::Collection +REGISTER_CLASS(ExtrusionEntityCollection, "ExtrusionPath::Collection"); +REGISTER_CLASS(Flow, "Flow"); +REGISTER_CLASS(AvoidCrossingPerimeters, "GCode::AvoidCrossingPerimeters"); +REGISTER_CLASS(OozePrevention, "GCode::OozePrevention"); +REGISTER_CLASS(Wipe, "GCode::Wipe"); +REGISTER_CLASS(GCode, "GCode"); +REGISTER_CLASS(GCodeSender, "GCode::Sender"); +REGISTER_CLASS(GCodeWriter, "GCode::Writer"); +REGISTER_CLASS(Layer, "Layer"); +REGISTER_CLASS(SupportLayer, "Layer::Support"); +REGISTER_CLASS(LayerRegion, "Layer::Region"); +REGISTER_CLASS(Line, "Line"); +REGISTER_CLASS(Linef3, "Linef3"); +REGISTER_CLASS(PerimeterGenerator, "Layer::PerimeterGenerator"); +REGISTER_CLASS(PlaceholderParser, "GCode::PlaceholderParser"); +REGISTER_CLASS(Polygon, "Polygon"); +REGISTER_CLASS(Polyline, "Polyline"); +REGISTER_CLASS(PolylineCollection, "Polyline::Collection"); +REGISTER_CLASS(Print, "Print"); +REGISTER_CLASS(PrintObject, "Print::Object"); +REGISTER_CLASS(PrintRegion, "Print::Region"); +REGISTER_CLASS(Model, "Model"); +REGISTER_CLASS(ModelMaterial, "Model::Material"); +REGISTER_CLASS(ModelObject, "Model::Object"); +REGISTER_CLASS(ModelVolume, "Model::Volume"); +REGISTER_CLASS(ModelInstance, "Model::Instance"); +REGISTER_CLASS(MotionPlanner, "MotionPlanner"); +REGISTER_CLASS(BoundingBox, "Geometry::BoundingBox"); +REGISTER_CLASS(BoundingBoxf, "Geometry::BoundingBoxf"); +REGISTER_CLASS(BoundingBoxf3, "Geometry::BoundingBoxf3"); +REGISTER_CLASS(BridgeDetector, "BridgeDetector"); +REGISTER_CLASS(Point, "Point"); +REGISTER_CLASS(Point3, "Point3"); +REGISTER_CLASS(Pointf, "Pointf"); +REGISTER_CLASS(Pointf3, "Pointf3"); +REGISTER_CLASS(DynamicPrintConfig, "Config"); +REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject"); +REGISTER_CLASS(PrintRegionConfig, "Config::PrintRegion"); +REGISTER_CLASS(GCodeConfig, "Config::GCode"); +REGISTER_CLASS(PrintConfig, "Config::Print"); +REGISTER_CLASS(FullPrintConfig, "Config::Full"); +REGISTER_CLASS(Surface, "Surface"); +REGISTER_CLASS(SurfaceCollection, "Surface::Collection"); +REGISTER_CLASS(TriangleMesh, "TriangleMesh"); +REGISTER_CLASS(GLVertexArray, "GUI::_3DScene::GLVertexArray"); + +SV* +ConfigBase__as_hash(ConfigBase* THIS) { + HV* hv = newHV(); + + t_config_option_keys opt_keys = THIS->keys(); + for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) + (void)hv_store( hv, it->c_str(), it->length(), ConfigBase__get(THIS, *it), 0 ); + + return newRV_noinc((SV*)hv); +} + +SV* +ConfigBase__get(ConfigBase* THIS, const t_config_option_key &opt_key) { + ConfigOption* opt = THIS->option(opt_key); + if (opt == NULL) return &PL_sv_undef; + + const ConfigOptionDef* def = THIS->def->get(opt_key); + if (def->type == coFloat) { + ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt); + return newSVnv(optv->value); + } else if (def->type == coFloats) { + ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt); + AV* av = newAV(); + av_fill(av, optv->values.size()-1); + for (std::vector<double>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) + av_store(av, it - optv->values.begin(), newSVnv(*it)); + return newRV_noinc((SV*)av); + } else if (def->type == coPercent) { + ConfigOptionPercent* optv = dynamic_cast<ConfigOptionPercent*>(opt); + return newSVnv(optv->value); + } else if (def->type == coInt) { + ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt); + return newSViv(optv->value); + } else if (def->type == coInts) { + ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt); + AV* av = newAV(); + av_fill(av, optv->values.size()-1); + for (std::vector<int>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) + av_store(av, it - optv->values.begin(), newSViv(*it)); + return newRV_noinc((SV*)av); + } else if (def->type == coString) { + ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt); + // we don't serialize() because that would escape newlines + return newSVpvn_utf8(optv->value.c_str(), optv->value.length(), true); + } else if (def->type == coStrings) { + ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt); + AV* av = newAV(); + av_fill(av, optv->values.size()-1); + for (std::vector<std::string>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) + av_store(av, it - optv->values.begin(), newSVpvn_utf8(it->c_str(), it->length(), true)); + return newRV_noinc((SV*)av); + } else if (def->type == coPoint) { + ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt); + return perl_to_SV_clone_ref(optv->value); + } else if (def->type == coPoints) { + ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt); + AV* av = newAV(); + av_fill(av, optv->values.size()-1); + for (Pointfs::iterator it = optv->values.begin(); it != optv->values.end(); ++it) + av_store(av, it - optv->values.begin(), perl_to_SV_clone_ref(*it)); + return newRV_noinc((SV*)av); + } else if (def->type == coBool) { + ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt); + return newSViv(optv->value ? 1 : 0); + } else if (def->type == coBools) { + ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt); + AV* av = newAV(); + av_fill(av, optv->values.size()-1); + for (std::vector<bool>::iterator it = optv->values.begin(); it != optv->values.end(); ++it) + av_store(av, it - optv->values.begin(), newSViv(*it ? 1 : 0)); + return newRV_noinc((SV*)av); + } else { + std::string serialized = opt->serialize(); + return newSVpvn_utf8(serialized.c_str(), serialized.length(), true); + } +} + +SV* +ConfigBase__get_at(ConfigBase* THIS, const t_config_option_key &opt_key, size_t i) { + ConfigOption* opt = THIS->option(opt_key); + if (opt == NULL) return &PL_sv_undef; + + const ConfigOptionDef* def = THIS->def->get(opt_key); + if (def->type == coFloats) { + ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt); + return newSVnv(optv->get_at(i)); + } else if (def->type == coInts) { + ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt); + return newSViv(optv->get_at(i)); + } else if (def->type == coStrings) { + ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt); + // we don't serialize() because that would escape newlines + std::string val = optv->get_at(i); + return newSVpvn_utf8(val.c_str(), val.length(), true); + } else if (def->type == coPoints) { + ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt); + return perl_to_SV_clone_ref(optv->get_at(i)); + } else if (def->type == coBools) { + ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt); + return newSViv(optv->get_at(i) ? 1 : 0); + } else { + return &PL_sv_undef; + } +} + +bool +ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value) { + ConfigOption* opt = THIS->option(opt_key, true); + if (opt == NULL) CONFESS("Trying to set non-existing option"); + + const ConfigOptionDef* def = THIS->def->get(opt_key); + if (def->type == coFloat) { + if (!looks_like_number(value)) return false; + ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt); + optv->value = SvNV(value); + } else if (def->type == coFloats) { + ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt); + std::vector<double> values; + AV* av = (AV*)SvRV(value); + const size_t len = av_len(av)+1; + for (size_t i = 0; i < len; i++) { + SV** elem = av_fetch(av, i, 0); + if (elem == NULL || !looks_like_number(*elem)) return false; + values.push_back(SvNV(*elem)); + } + optv->values = values; + } else if (def->type == coInt) { + if (!looks_like_number(value)) return false; + ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt); + optv->value = SvIV(value); + } else if (def->type == coInts) { + ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt); + std::vector<int> values; + AV* av = (AV*)SvRV(value); + const size_t len = av_len(av)+1; + for (size_t i = 0; i < len; i++) { + SV** elem = av_fetch(av, i, 0); + if (elem == NULL || !looks_like_number(*elem)) return false; + values.push_back(SvIV(*elem)); + } + optv->values = values; + } else if (def->type == coString) { + ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt); + optv->value = std::string(SvPV_nolen(value), SvCUR(value)); + } else if (def->type == coStrings) { + ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt); + optv->values.clear(); + AV* av = (AV*)SvRV(value); + const size_t len = av_len(av)+1; + for (size_t i = 0; i < len; i++) { + SV** elem = av_fetch(av, i, 0); + if (elem == NULL) return false; + optv->values.push_back(std::string(SvPV_nolen(*elem), SvCUR(*elem))); + } + } else if (def->type == coPoint) { + ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt); + return from_SV_check(value, &optv->value); + } else if (def->type == coPoints) { + ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt); + std::vector<Pointf> values; + AV* av = (AV*)SvRV(value); + const size_t len = av_len(av)+1; + for (size_t i = 0; i < len; i++) { + SV** elem = av_fetch(av, i, 0); + Pointf point; + if (elem == NULL || !from_SV_check(*elem, &point)) return false; + values.push_back(point); + } + optv->values = values; + } else if (def->type == coBool) { + ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt); + optv->value = SvTRUE(value); + } else if (def->type == coBools) { + ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt); + optv->values.clear(); + AV* av = (AV*)SvRV(value); + const size_t len = av_len(av)+1; + for (size_t i = 0; i < len; i++) { + SV** elem = av_fetch(av, i, 0); + if (elem == NULL) return false; + optv->values.push_back(SvTRUE(*elem)); + } + } else { + if (!opt->deserialize( std::string(SvPV_nolen(value)) )) return false; + } + return true; +} + +/* This method is implemented as a workaround for this typemap bug: + https://rt.cpan.org/Public/Bug/Display.html?id=94110 */ +bool +ConfigBase__set_deserialize(ConfigBase* THIS, const t_config_option_key &opt_key, SV* str) { + size_t len; + const char * c = SvPV(str, len); + std::string value(c, len); + + return THIS->set_deserialize(opt_key, value); +} + +void +ConfigBase__set_ifndef(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value, bool deserialize) +{ + if (!THIS->has(opt_key)) { + if (deserialize) { + ConfigBase__set_deserialize(THIS, opt_key, value); + } else { + ConfigBase__set(THIS, opt_key, value); + } + } +} + +bool +StaticConfig__set(StaticConfig* THIS, const t_config_option_key &opt_key, SV* value) { + const ConfigOptionDef* optdef = THIS->def->get(opt_key); + if (!optdef->shortcut.empty()) { + for (std::vector<t_config_option_key>::const_iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it) { + if (!StaticConfig__set(THIS, *it, value)) return false; + } + return true; + } + + return ConfigBase__set(THIS, opt_key, value); +} + +SV* to_AV(ExPolygon* expolygon) +{ + const unsigned int num_holes = expolygon->holes.size(); + AV* av = newAV(); + av_extend(av, num_holes); // -1 +1 + + av_store(av, 0, perl_to_SV_ref(expolygon->contour)); + + for (unsigned int i = 0; i < num_holes; i++) { + av_store(av, i+1, perl_to_SV_ref(expolygon->holes[i])); + } + return newRV_noinc((SV*)av); +} + +SV* to_SV_pureperl(const ExPolygon* expolygon) +{ + const unsigned int num_holes = expolygon->holes.size(); + AV* av = newAV(); + av_extend(av, num_holes); // -1 +1 + av_store(av, 0, to_SV_pureperl(&expolygon->contour)); + for (unsigned int i = 0; i < num_holes; i++) { + av_store(av, i+1, to_SV_pureperl(&expolygon->holes[i])); + } + return newRV_noinc((SV*)av); +} + +void from_SV(SV* expoly_sv, ExPolygon* expolygon) +{ + AV* expoly_av = (AV*)SvRV(expoly_sv); + const unsigned int num_polygons = av_len(expoly_av)+1; + expolygon->holes.resize(num_polygons-1); + + SV** polygon_sv = av_fetch(expoly_av, 0, 0); + from_SV(*polygon_sv, &expolygon->contour); + for (unsigned int i = 0; i < num_polygons-1; i++) { + polygon_sv = av_fetch(expoly_av, i+1, 0); + from_SV(*polygon_sv, &expolygon->holes[i]); + } +} + +void from_SV_check(SV* expoly_sv, ExPolygon* expolygon) +{ + if (sv_isobject(expoly_sv) && (SvTYPE(SvRV(expoly_sv)) == SVt_PVMG)) { + if (!sv_isa(expoly_sv, perl_class_name(expolygon)) && !sv_isa(expoly_sv, perl_class_name_ref(expolygon))) + CONFESS("Not a valid %s object", perl_class_name(expolygon)); + // a XS ExPolygon was supplied + *expolygon = *(ExPolygon *)SvIV((SV*)SvRV( expoly_sv )); + } else { + // a Perl arrayref was supplied + from_SV(expoly_sv, expolygon); + } +} + +void from_SV(SV* line_sv, Line* THIS) +{ + AV* line_av = (AV*)SvRV(line_sv); + from_SV_check(*av_fetch(line_av, 0, 0), &THIS->a); + from_SV_check(*av_fetch(line_av, 1, 0), &THIS->b); +} + +void from_SV_check(SV* line_sv, Line* THIS) +{ + if (sv_isobject(line_sv) && (SvTYPE(SvRV(line_sv)) == SVt_PVMG)) { + if (!sv_isa(line_sv, perl_class_name(THIS)) && !sv_isa(line_sv, perl_class_name_ref(THIS))) + CONFESS("Not a valid %s object", perl_class_name(THIS)); + *THIS = *(Line*)SvIV((SV*)SvRV( line_sv )); + } else { + from_SV(line_sv, THIS); + } +} + +SV* to_AV(Line* THIS) +{ + AV* av = newAV(); + av_extend(av, 1); + + av_store(av, 0, perl_to_SV_ref(THIS->a)); + av_store(av, 1, perl_to_SV_ref(THIS->b)); + + return newRV_noinc((SV*)av); +} + +SV* to_SV_pureperl(const Line* THIS) +{ + AV* av = newAV(); + av_extend(av, 1); + av_store(av, 0, to_SV_pureperl(&THIS->a)); + av_store(av, 1, to_SV_pureperl(&THIS->b)); + return newRV_noinc((SV*)av); +} + +void from_SV(SV* poly_sv, MultiPoint* THIS) +{ + AV* poly_av = (AV*)SvRV(poly_sv); + const unsigned int num_points = av_len(poly_av)+1; + THIS->points.resize(num_points); + + for (unsigned int i = 0; i < num_points; i++) { + SV** point_sv = av_fetch(poly_av, i, 0); + from_SV_check(*point_sv, &THIS->points[i]); + } +} + +void from_SV_check(SV* poly_sv, MultiPoint* THIS) +{ + if (sv_isobject(poly_sv) && (SvTYPE(SvRV(poly_sv)) == SVt_PVMG)) { + *THIS = *(MultiPoint*)SvIV((SV*)SvRV( poly_sv )); + } else { + from_SV(poly_sv, THIS); + } +} + +SV* to_AV(MultiPoint* THIS) +{ + const unsigned int num_points = THIS->points.size(); + AV* av = newAV(); + if (num_points > 0) av_extend(av, num_points-1); + for (unsigned int i = 0; i < num_points; i++) { + av_store(av, i, perl_to_SV_ref(THIS->points[i])); + } + return newRV_noinc((SV*)av); +} + +SV* to_SV_pureperl(const MultiPoint* THIS) +{ + const unsigned int num_points = THIS->points.size(); + AV* av = newAV(); + if (num_points > 0) av_extend(av, num_points-1); + for (unsigned int i = 0; i < num_points; i++) { + av_store(av, i, to_SV_pureperl(&THIS->points[i])); + } + return newRV_noinc((SV*)av); +} + +void from_SV_check(SV* poly_sv, Polygon* THIS) +{ + if (sv_isobject(poly_sv) && !sv_isa(poly_sv, perl_class_name(THIS)) && !sv_isa(poly_sv, perl_class_name_ref(THIS))) + CONFESS("Not a valid %s object", perl_class_name(THIS)); + + from_SV_check(poly_sv, (MultiPoint*)THIS); +} + +void from_SV_check(SV* poly_sv, Polyline* THIS) +{ + if (!sv_isa(poly_sv, perl_class_name(THIS)) && !sv_isa(poly_sv, perl_class_name_ref(THIS))) + CONFESS("Not a valid %s object", perl_class_name(THIS)); + + from_SV_check(poly_sv, (MultiPoint*)THIS); +} + +SV* to_SV_pureperl(const Point* THIS) +{ + AV* av = newAV(); + av_fill(av, 1); + av_store(av, 0, newSViv(THIS->x)); + av_store(av, 1, newSViv(THIS->y)); + return newRV_noinc((SV*)av); +} + +void from_SV(SV* point_sv, Point* point) +{ + AV* point_av = (AV*)SvRV(point_sv); + // get a double from Perl and round it, otherwise + // it would get truncated + point->x = lrint(SvNV(*av_fetch(point_av, 0, 0))); + point->y = lrint(SvNV(*av_fetch(point_av, 1, 0))); +} + +void from_SV_check(SV* point_sv, Point* point) +{ + if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { + if (!sv_isa(point_sv, perl_class_name(point)) && !sv_isa(point_sv, perl_class_name_ref(point))) + CONFESS("Not a valid %s object (got %s)", perl_class_name(point), HvNAME(SvSTASH(SvRV(point_sv)))); + *point = *(Point*)SvIV((SV*)SvRV( point_sv )); + } else { + from_SV(point_sv, point); + } +} + +SV* to_SV_pureperl(const Pointf* point) +{ + AV* av = newAV(); + av_fill(av, 1); + av_store(av, 0, newSVnv(point->x)); + av_store(av, 1, newSVnv(point->y)); + return newRV_noinc((SV*)av); +} + +bool from_SV(SV* point_sv, Pointf* point) +{ + AV* point_av = (AV*)SvRV(point_sv); + SV* sv_x = *av_fetch(point_av, 0, 0); + SV* sv_y = *av_fetch(point_av, 1, 0); + if (!looks_like_number(sv_x) || !looks_like_number(sv_y)) return false; + + point->x = SvNV(sv_x); + point->y = SvNV(sv_y); + return true; +} + +bool from_SV_check(SV* point_sv, Pointf* point) +{ + if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { + if (!sv_isa(point_sv, perl_class_name(point)) && !sv_isa(point_sv, perl_class_name_ref(point))) + CONFESS("Not a valid %s object (got %s)", perl_class_name(point), HvNAME(SvSTASH(SvRV(point_sv)))); + *point = *(Pointf*)SvIV((SV*)SvRV( point_sv )); + return true; + } else { + return from_SV(point_sv, point); + } +} + +void from_SV_check(SV* surface_sv, Surface* THIS) +{ + if (!sv_isa(surface_sv, perl_class_name(THIS)) && !sv_isa(surface_sv, perl_class_name_ref(THIS))) + CONFESS("Not a valid %s object", perl_class_name(THIS)); + // a XS Surface was supplied + *THIS = *(Surface *)SvIV((SV*)SvRV( surface_sv )); +} + +SV* to_SV(TriangleMesh* THIS) +{ + SV* sv = newSV(0); + sv_setref_pv( sv, perl_class_name(THIS), (void*)THIS ); + return sv; +} + +SV* +polynode_children_2_perl(const ClipperLib::PolyNode& node) +{ + AV* av = newAV(); + const int len = node.ChildCount(); + if (len > 0) av_extend(av, len-1); + for (int i = 0; i < len; ++i) { + av_store(av, i, polynode2perl(*node.Childs[i])); + } + return (SV*)newRV_noinc((SV*)av); +} + +SV* +polynode2perl(const ClipperLib::PolyNode& node) +{ + HV* hv = newHV(); + Slic3r::Polygon p; + ClipperPath_to_Slic3rMultiPoint(node.Contour, &p); + if (node.IsHole()) { + (void)hv_stores( hv, "hole", Slic3r::perl_to_SV_clone_ref(p) ); + } else { + (void)hv_stores( hv, "outer", Slic3r::perl_to_SV_clone_ref(p) ); + } + (void)hv_stores( hv, "children", polynode_children_2_perl(node) ); + return (SV*)newRV_noinc((SV*)hv); +} + +} +#endif diff --git a/xs/src/perlglue.hpp b/xs/src/perlglue.hpp deleted file mode 100644 index b10cbcf11..000000000 --- a/xs/src/perlglue.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef slic3r_perlglue_hpp_ -#define slic3r_perlglue_hpp_ - -namespace Slic3r { - -template<class T> -struct ClassTraits { - static const char* name; - static const char* name_ref; -}; - -// use this for typedefs for which the forward prototype -// in REGISTER_CLASS won't work -#define __REGISTER_CLASS(cname, perlname) \ - template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \ - template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref"; - -#define REGISTER_CLASS(cname,perlname) \ - class cname; \ - __REGISTER_CLASS(cname, perlname); - -template<class T> -const char* perl_class_name(const T*) { return ClassTraits<T>::name; } -template<class T> -const char* perl_class_name_ref(const T*) { return ClassTraits<T>::name_ref; } - -template<class T> -SV* perl_to_SV_ref(T &t) { - SV* sv = newSV(0); - sv_setref_pv( sv, perl_class_name_ref(&t), &t ); - return sv; -} - -template<class T> -SV* perl_to_SV_clone_ref(const T &t) { - SV* sv = newSV(0); - sv_setref_pv( sv, perl_class_name(&t), new T(t) ); - return sv; -} - -template <class T> -class Ref { - T* val; -public: - Ref() : val(NULL) {} - Ref(T* t) : val(t) {} - Ref(const T* t) : val(const_cast<T*>(t)) {} - operator T*() const { return val; } - static const char* CLASS() { return ClassTraits<T>::name_ref; } -}; - -template <class T> -class Clone { - T* val; -public: - Clone() : val(NULL) {} - Clone(T* t) : val(new T(*t)) {} - Clone(const T& t) : val(new T(t)) {} - operator T*() const { return val; } - static const char* CLASS() { return ClassTraits<T>::name; } -}; -}; - -#endif diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 5f61b37b3..e398a1c37 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -241,8 +241,4 @@ GLVertexArray::load_mesh(const TriangleMesh &mesh) } } -#ifdef SLIC3RXS -REGISTER_CLASS(GLVertexArray, "GUI::_3DScene::GLVertexArray"); -#endif - } diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 5552b7310..85b6d08ec 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -1,7 +1,7 @@ #ifndef slic3r_3DScene_hpp_ #define slic3r_3DScene_hpp_ -#include <myinit.h> +#include "../../libslic3r/libslic3r.h" #include "../../libslic3r/Point.hpp" #include "../../libslic3r/Line.hpp" #include "../../libslic3r/TriangleMesh.hpp" diff --git a/xs/src/xsinit.h b/xs/src/xsinit.h new file mode 100644 index 000000000..b5b1d83f4 --- /dev/null +++ b/xs/src/xsinit.h @@ -0,0 +1,149 @@ +#ifndef _xsinit_h_ +#define _xsinit_h_ + +// undef some macros set by Perl which cause compilation errors on Win32 +#undef read +#undef seekdir +#undef bind +#undef send +#undef connect +#undef wait +#undef accept +#undef close +#undef open +#undef write +#undef socket +#undef listen +#undef shutdown +#undef ioctl +#undef getpeername +#undef rect +#undef setsockopt +#undef getsockopt +#undef getsockname +#undef gethostname +#undef select +#undef socketpair +#undef recvfrom +#undef sendto + +// these need to be included early for Win32 (listing it in Build.PL is not enough) +#include <ostream> +#include <iostream> +#include <sstream> + +#ifdef SLIC3RXS +extern "C" { +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" +#include "ppport.h" +#undef do_open +#undef do_close +} +#endif + +#include <libslic3r.h> +#include <ClipperUtils.hpp> +#include <Config.hpp> +#include <ExPolygon.hpp> +#include <MultiPoint.hpp> +#include <Point.hpp> +#include <Polygon.hpp> +#include <Polyline.hpp> +#include <TriangleMesh.hpp> + +namespace Slic3r { + +template<class T> +struct ClassTraits { + static const char* name; + static const char* name_ref; +}; + +// use this for typedefs for which the forward prototype +// in REGISTER_CLASS won't work +#define __REGISTER_CLASS(cname, perlname) \ + template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \ + template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref"; + +#define REGISTER_CLASS(cname,perlname) \ + class cname; \ + __REGISTER_CLASS(cname, perlname); + +template<class T> +const char* perl_class_name(const T*) { return ClassTraits<T>::name; } +template<class T> +const char* perl_class_name_ref(const T*) { return ClassTraits<T>::name_ref; } + +template<class T> +SV* perl_to_SV_ref(T &t) { + SV* sv = newSV(0); + sv_setref_pv( sv, perl_class_name_ref(&t), &t ); + return sv; +} + +template<class T> +SV* perl_to_SV_clone_ref(const T &t) { + SV* sv = newSV(0); + sv_setref_pv( sv, perl_class_name(&t), new T(t) ); + return sv; +} + +template <class T> +class Ref { + T* val; +public: + Ref() : val(NULL) {} + Ref(T* t) : val(t) {} + Ref(const T* t) : val(const_cast<T*>(t)) {} + operator T*() const { return val; } + static const char* CLASS() { return ClassTraits<T>::name_ref; } +}; + +template <class T> +class Clone { + T* val; +public: + Clone() : val(NULL) {} + Clone(T* t) : val(new T(*t)) {} + Clone(const T& t) : val(new T(t)) {} + operator T*() const { return val; } + static const char* CLASS() { return ClassTraits<T>::name; } +}; + +SV* ConfigBase__as_hash(ConfigBase* THIS); +SV* ConfigBase__get(ConfigBase* THIS, const t_config_option_key &opt_key); +SV* ConfigBase__get_at(ConfigBase* THIS, const t_config_option_key &opt_key, size_t i); +bool ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value); +bool ConfigBase__set_deserialize(ConfigBase* THIS, const t_config_option_key &opt_key, SV* str); +void ConfigBase__set_ifndef(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value, bool deserialize = false); +bool StaticConfig__set(StaticConfig* THIS, const t_config_option_key &opt_key, SV* value); +SV* to_AV(ExPolygon* expolygon); +SV* to_SV_pureperl(const ExPolygon* expolygon); +void from_SV(SV* expoly_sv, ExPolygon* expolygon); +void from_SV_check(SV* expoly_sv, ExPolygon* expolygon); +void from_SV(SV* line_sv, Line* THIS); +void from_SV_check(SV* line_sv, Line* THIS); +SV* to_AV(Line* THIS); +SV* to_SV_pureperl(const Line* THIS); +void from_SV(SV* poly_sv, MultiPoint* THIS); +void from_SV_check(SV* poly_sv, MultiPoint* THIS); +SV* to_AV(MultiPoint* THIS); +SV* to_SV_pureperl(const MultiPoint* THIS); +void from_SV_check(SV* poly_sv, Polygon* THIS); +void from_SV_check(SV* poly_sv, Polyline* THIS); +SV* to_SV_pureperl(const Point* THIS); +void from_SV(SV* point_sv, Point* point); +void from_SV_check(SV* point_sv, Point* point); +SV* to_SV_pureperl(const Pointf* point); +bool from_SV(SV* point_sv, Pointf* point); +bool from_SV_check(SV* point_sv, Pointf* point); +void from_SV_check(SV* surface_sv, Surface* THIS); +SV* to_SV(TriangleMesh* THIS); +SV* polynode_children_2_perl(const ClipperLib::PolyNode& node); +SV* polynode2perl(const ClipperLib::PolyNode& node); + +} + +#endif |