Implement type checking for XS objects

Type handling is mainly done using templates.
Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used.
Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type).

Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return.

Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments).
It is overloaded to be able to return type, type* and type&.

Typechecking in ExtrusionEntityCollection updated to check all passed types.
This commit is contained in:
Petr Ledvina 2014-04-27 19:18:53 +02:00
parent e68b6b6f4c
commit 115aa6885f
35 changed files with 426 additions and 173 deletions

View file

@ -1675,6 +1675,7 @@ src/Model.hpp
src/MultiPoint.cpp src/MultiPoint.cpp
src/MultiPoint.hpp src/MultiPoint.hpp
src/myinit.h src/myinit.h
src/perlglue.hpp
src/Point.cpp src/Point.cpp
src/Point.hpp src/Point.hpp
src/Polygon.cpp src/Polygon.cpp

View file

@ -1,5 +1,8 @@
#include "BoundingBox.hpp" #include "BoundingBox.hpp"
#include <algorithm> #include <algorithm>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -156,4 +159,10 @@ BoundingBox3Base<PointClass>::center() const
} }
template Pointf3 BoundingBox3Base<Pointf3>::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
} }

View file

@ -4,6 +4,9 @@
#include "Line.hpp" #include "Line.hpp"
#include "ClipperUtils.hpp" #include "ClipperUtils.hpp"
#include "polypartition.h" #include "polypartition.h"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
#include <list> #include <list>
@ -240,6 +243,9 @@ ExPolygon::triangulate2(Polygons* polygons) const
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(ExPolygon, "ExPolygon");
SV* SV*
ExPolygon::to_AV() { ExPolygon::to_AV() {
const unsigned int num_holes = this->holes.size(); const unsigned int num_holes = this->holes.size();
@ -257,14 +263,14 @@ ExPolygon::to_AV() {
SV* SV*
ExPolygon::to_SV_ref() { ExPolygon::to_SV_ref() {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::ExPolygon::Ref", this ); sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv; return sv;
} }
SV* SV*
ExPolygon::to_SV_clone_ref() const { ExPolygon::to_SV_clone_ref() const {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::ExPolygon", new ExPolygon(*this) ); sv_setref_pv( sv, perl_class_name(this), new ExPolygon(*this) );
return sv; return sv;
} }
@ -300,8 +306,8 @@ void
ExPolygon::from_SV_check(SV* expoly_sv) ExPolygon::from_SV_check(SV* expoly_sv)
{ {
if (sv_isobject(expoly_sv) && (SvTYPE(SvRV(expoly_sv)) == SVt_PVMG)) { if (sv_isobject(expoly_sv) && (SvTYPE(SvRV(expoly_sv)) == SVt_PVMG)) {
if (!sv_isa(expoly_sv, "Slic3r::ExPolygon") && !sv_isa(expoly_sv, "Slic3r::ExPolygon::Ref")) if (!sv_isa(expoly_sv, perl_class_name(this)) && !sv_isa(expoly_sv, perl_class_name_ref(this)))
CONFESS("Not a valid Slic3r::ExPolygon object"); CONFESS("Not a valid %s object", perl_class_name(this));
// a XS ExPolygon was supplied // a XS ExPolygon was supplied
*this = *(ExPolygon *)SvIV((SV*)SvRV( expoly_sv )); *this = *(ExPolygon *)SvIV((SV*)SvRV( expoly_sv ));
} else { } else {

View file

@ -1,5 +1,8 @@
#include "ExPolygonCollection.hpp" #include "ExPolygonCollection.hpp"
#include "Geometry.hpp" #include "Geometry.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -67,4 +70,8 @@ ExPolygonCollection::convex_hull(Polygon* hull) const
Slic3r::Geometry::convex_hull(pp, hull); Slic3r::Geometry::convex_hull(pp, hull);
} }
#ifdef SLIC3RXS
REGISTER_CLASS(ExPolygonCollection, "ExPolygon::Collection");
#endif
} }

View file

@ -1,8 +1,11 @@
#include <sstream>
#include "ExtrusionEntity.hpp" #include "ExtrusionEntity.hpp"
#include "ExtrusionEntityCollection.hpp" #include "ExtrusionEntityCollection.hpp"
#include "ExPolygonCollection.hpp" #include "ExPolygonCollection.hpp"
#include "ClipperUtils.hpp" #include "ClipperUtils.hpp"
#include <sstream>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -102,6 +105,9 @@ ExtrusionPath::_inflate_collection(const Polylines &polylines, ExtrusionEntityCo
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(ExtrusionPath, "ExtrusionPath");
std::string std::string
ExtrusionPath::gcode(SV* extruder, double e, double F, ExtrusionPath::gcode(SV* extruder, double e, double F,
double xofs, double yofs, std::string extrusion_axis, double xofs, double yofs, std::string extrusion_axis,
@ -212,4 +218,8 @@ ExtrusionLoop::last_point() const
return this->polygon.points.front(); // in polygons, first == last return this->polygon.points.front(); // in polygons, first == last
} }
#ifdef SLIC3RXS
REGISTER_CLASS(ExtrusionLoop, "ExtrusionLoop");
#endif
} }

View file

@ -1,6 +1,9 @@
#include "ExtrusionEntityCollection.hpp" #include "ExtrusionEntityCollection.hpp"
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -107,4 +110,9 @@ ExtrusionEntityCollection::chained_path_from(Point start_near, ExtrusionEntityCo
} }
} }
#ifdef SLIC3RXS
// there is no ExtrusionLoop::Collection or ExtrusionEntity::Collection
REGISTER_CLASS(ExtrusionEntityCollection, "ExtrusionPath::Collection");
#endif
} }

View file

@ -1,5 +1,8 @@
#include "Flow.hpp" #include "Flow.hpp"
#include <cmath> #include <cmath>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -112,4 +115,8 @@ Flow::_spacing(float width, float nozzle_diameter, float height, float bridge_fl
return width - OVERLAP_FACTOR * (width - min_flow_spacing); return width - OVERLAP_FACTOR * (width - min_flow_spacing);
} }
#ifdef SLIC3RXS
REGISTER_CLASS(Flow, "Flow");
#endif
} }

View file

@ -3,6 +3,9 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <sstream> #include <sstream>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -115,6 +118,9 @@ Line::vector() const
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(Line, "Line");
void void
Line::from_SV(SV* line_sv) Line::from_SV(SV* line_sv)
{ {
@ -127,8 +133,8 @@ void
Line::from_SV_check(SV* line_sv) Line::from_SV_check(SV* line_sv)
{ {
if (sv_isobject(line_sv) && (SvTYPE(SvRV(line_sv)) == SVt_PVMG)) { if (sv_isobject(line_sv) && (SvTYPE(SvRV(line_sv)) == SVt_PVMG)) {
if (!sv_isa(line_sv, "Slic3r::Line") && !sv_isa(line_sv, "Slic3r::Line::Ref")) if (!sv_isa(line_sv, perl_class_name(this)) && !sv_isa(line_sv, perl_class_name_ref(this)))
CONFESS("Not a valid Slic3r::Line object"); CONFESS("Not a valid %s object", perl_class_name(this));
*this = *(Line*)SvIV((SV*)SvRV( line_sv )); *this = *(Line*)SvIV((SV*)SvRV( line_sv ));
} else { } else {
this->from_SV(line_sv); this->from_SV(line_sv);
@ -141,11 +147,11 @@ Line::to_AV() {
av_extend(av, 1); av_extend(av, 1);
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Point::Ref", &(this->a) ); sv_setref_pv( sv, perl_class_name_ref(&this->a), &(this->a) );
av_store(av, 0, sv); av_store(av, 0, sv);
sv = newSV(0); sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Point::Ref", &(this->b) ); sv_setref_pv( sv, perl_class_name_ref(&this->b), &(this->b) );
av_store(av, 1, sv); av_store(av, 1, sv);
return newRV_noinc((SV*)av); return newRV_noinc((SV*)av);
@ -154,14 +160,14 @@ Line::to_AV() {
SV* SV*
Line::to_SV_ref() { Line::to_SV_ref() {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Line::Ref", this ); sv_setref_pv( sv, perl_class_name_ref(this), this );
return sv; return sv;
} }
SV* SV*
Line::to_SV_clone_ref() const { Line::to_SV_clone_ref() const {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Line", new Line(*this) ); sv_setref_pv( sv, perl_class_name(this), new Line(*this) );
return sv; return sv;
} }

View file

@ -1,7 +1,10 @@
#include <cmath>
#include <sstream>
#include "Point.hpp" #include "Point.hpp"
#include "Line.hpp" #include "Line.hpp"
#include <cmath>
#include <sstream>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -139,17 +142,20 @@ Point::ccw(const Line &line) const
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(Point, "Point");
SV* SV*
Point::to_SV_ref() { Point::to_SV_ref() {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Point::Ref", (void*)this ); sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv; return sv;
} }
SV* SV*
Point::to_SV_clone_ref() const { Point::to_SV_clone_ref() const {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Point", new Point(*this) ); sv_setref_pv( sv, perl_class_name(this), new Point(*this) );
return sv; return sv;
} }
@ -176,14 +182,34 @@ void
Point::from_SV_check(SV* point_sv) Point::from_SV_check(SV* point_sv)
{ {
if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) { if (sv_isobject(point_sv) && (SvTYPE(SvRV(point_sv)) == SVt_PVMG)) {
if (!sv_isa(point_sv, "Slic3r::Point") && !sv_isa(point_sv, "Slic3r::Point::Ref")) if (!sv_isa(point_sv, perl_class_name(this)) && !sv_isa(point_sv, perl_class_name_ref(this)))
CONFESS("Not a valid Slic3r::Point object"); CONFESS("Not a valid %s object (got %s)", perl_class_name(this), HvNAME(SvSTASH(SvRV(point_sv))));
*this = *(Point*)SvIV((SV*)SvRV( point_sv )); *this = *(Point*)SvIV((SV*)SvRV( point_sv ));
} else { } else {
this->from_SV(point_sv); this->from_SV(point_sv);
} }
} }
#endif
void
Pointf::scale(double factor)
{
this->x *= factor;
this->y *= factor;
}
void
Pointf::translate(double x, double y)
{
this->x += x;
this->y += y;
}
#ifdef SLIC3RXS
REGISTER_CLASS(Pointf, "Pointf");
SV* SV*
Pointf::to_SV_pureperl() const { Pointf::to_SV_pureperl() const {
AV* av = newAV(); AV* av = newAV();
@ -207,20 +233,6 @@ Pointf::from_SV(SV* point_sv)
} }
#endif #endif
void
Pointf::scale(double factor)
{
this->x *= factor;
this->y *= factor;
}
void
Pointf::translate(double x, double y)
{
this->x += x;
this->y += y;
}
void void
Pointf3::scale(double factor) Pointf3::scale(double factor)
{ {
@ -235,4 +247,8 @@ Pointf3::translate(double x, double y, double z)
this->z += z; this->z += z;
} }
#ifdef SLIC3RXS
REGISTER_CLASS(Pointf3, "Pointf3");
#endif
} }

View file

@ -2,6 +2,9 @@
#include "ClipperUtils.hpp" #include "ClipperUtils.hpp"
#include "Polygon.hpp" #include "Polygon.hpp"
#include "Polyline.hpp" #include "Polyline.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -175,25 +178,28 @@ Polygon::triangulate_convex(Polygons* polygons) const
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(Polygon, "Polygon");
SV* SV*
Polygon::to_SV_ref() { Polygon::to_SV_ref() {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Polygon::Ref", (void*)this ); sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv; return sv;
} }
SV* SV*
Polygon::to_SV_clone_ref() const { Polygon::to_SV_clone_ref() const {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Polygon", new Polygon(*this) ); sv_setref_pv( sv, perl_class_name(this), new Polygon(*this) );
return sv; return sv;
} }
void void
Polygon::from_SV_check(SV* poly_sv) Polygon::from_SV_check(SV* poly_sv)
{ {
if (sv_isobject(poly_sv) && !sv_isa(poly_sv, "Slic3r::Polygon") && !sv_isa(poly_sv, "Slic3r::Polygon::Ref")) 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 Slic3r::Polygon object"); CONFESS("Not a valid %s object", perl_class_name(this));
MultiPoint::from_SV_check(poly_sv); MultiPoint::from_SV_check(poly_sv);
} }

View file

@ -1,5 +1,8 @@
#include "Polyline.hpp" #include "Polyline.hpp"
#include "Polygon.hpp" #include "Polygon.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -122,11 +125,14 @@ Polyline::simplify(double tolerance)
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(Polyline, "Polyline");
SV* SV*
Polyline::to_SV_ref() Polyline::to_SV_ref()
{ {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Polyline::Ref", (void*)this ); sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv; return sv;
} }
@ -134,15 +140,15 @@ SV*
Polyline::to_SV_clone_ref() const Polyline::to_SV_clone_ref() const
{ {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Polyline", new Polyline(*this) ); sv_setref_pv( sv, perl_class_name(this), new Polyline(*this) );
return sv; return sv;
} }
void void
Polyline::from_SV_check(SV* poly_sv) Polyline::from_SV_check(SV* poly_sv)
{ {
if (!sv_isa(poly_sv, "Slic3r::Polyline") && !sv_isa(poly_sv, "Slic3r::Polyline::Ref")) if (!sv_isa(poly_sv, perl_class_name(this)) && !sv_isa(poly_sv, perl_class_name_ref(this)))
CONFESS("Not a valid Slic3r::Polyline object"); CONFESS("Not a valid %s object",perl_class_name(this));
MultiPoint::from_SV_check(poly_sv); MultiPoint::from_SV_check(poly_sv);
} }

View file

@ -1,4 +1,7 @@
#include "PolylineCollection.hpp" #include "PolylineCollection.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -50,4 +53,8 @@ PolylineCollection::leftmost_point() const
return p; return p;
} }
#ifdef SLIC3RXS
REGISTER_CLASS(PolylineCollection, "Polyline::Collection");
#endif
} }

View file

@ -1,4 +1,7 @@
#include "Print.hpp" #include "Print.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -40,4 +43,8 @@ PrintState::invalidate_all()
this->_done.clear(); this->_done.clear();
} }
#ifdef SLIC3RXS
REGISTER_CLASS(PrintState, "Print::State");
#endif
} }

View file

@ -1,7 +1,18 @@
#include "PrintConfig.hpp" #include "PrintConfig.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def(); t_optiondef_map PrintConfigDef::def = PrintConfigDef::build_def();
#ifdef SLIC3RXS
REGISTER_CLASS(DynamicPrintConfig, "Config");
REGISTER_CLASS(PrintObjectConfig, "Config::PrintObject");
REGISTER_CLASS(PrintRegionConfig, "Config::PrintRegion");
REGISTER_CLASS(PrintConfig, "Config::Print");
REGISTER_CLASS(FullPrintConfig, "Config::Full");
#endif
} }

View file

@ -1,4 +1,7 @@
#include "Surface.hpp" #include "Surface.hpp"
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -40,11 +43,14 @@ Surface::is_bridge() const
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(Surface, "Surface");
void void
Surface::from_SV_check(SV* surface_sv) Surface::from_SV_check(SV* surface_sv)
{ {
if (!sv_isa(surface_sv, "Slic3r::Surface") && !sv_isa(surface_sv, "Slic3r::Surface::Ref")) if (!sv_isa(surface_sv, perl_class_name(this)) && !sv_isa(surface_sv, perl_class_name_ref(this)))
CONFESS("Not a valid Slic3r::Surface object"); CONFESS("Not a valid %s object", perl_class_name(this));
// a XS Surface was supplied // a XS Surface was supplied
*this = *(Surface *)SvIV((SV*)SvRV( surface_sv )); *this = *(Surface *)SvIV((SV*)SvRV( surface_sv ));
} }
@ -52,14 +58,14 @@ Surface::from_SV_check(SV* surface_sv)
SV* SV*
Surface::to_SV_ref() { Surface::to_SV_ref() {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Surface::Ref", (void*)this ); sv_setref_pv( sv, perl_class_name_ref(this), (void*)this );
return sv; return sv;
} }
SV* SV*
Surface::to_SV_clone_ref() const { Surface::to_SV_clone_ref() const {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::Surface", new Surface(*this) ); sv_setref_pv( sv, perl_class_name(this), new Surface(*this) );
return sv; return sv;
} }
#endif #endif

View file

@ -1,5 +1,8 @@
#include "SurfaceCollection.hpp" #include "SurfaceCollection.hpp"
#include <map> #include <map>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
namespace Slic3r { namespace Slic3r {
@ -48,4 +51,8 @@ SurfaceCollection::group(std::vector<SurfacesPtr> *retval)
} }
} }
#ifdef SLIC3RXS
REGISTER_CLASS(SurfaceCollection, "Surface::Collection");
#endif
} }

View file

@ -11,6 +11,9 @@
#include <algorithm> #include <algorithm>
#include <math.h> #include <math.h>
#include <assert.h> #include <assert.h>
#ifdef SLIC3RXS
#include "perlglue.hpp"
#endif
#ifdef SLIC3R_DEBUG #ifdef SLIC3R_DEBUG
#include "SVG.hpp" #include "SVG.hpp"
@ -320,10 +323,13 @@ TriangleMesh::require_shared_vertices()
} }
#ifdef SLIC3RXS #ifdef SLIC3RXS
REGISTER_CLASS(TriangleMesh, "TriangleMesh");
SV* SV*
TriangleMesh::to_SV() { TriangleMesh::to_SV() {
SV* sv = newSV(0); SV* sv = newSV(0);
sv_setref_pv( sv, "Slic3r::TriangleMesh", (void*)this ); sv_setref_pv( sv, perl_class_name(this), (void*)this );
return sv; return sv;
} }

44
xs/src/perlglue.hpp Normal file
View file

@ -0,0 +1,44 @@
#ifndef slic3r_perlglue_hpp_
#define slic3r_perlglue_hpp_
namespace Slic3r {
template<class T>
struct ClassTraits {
static const char* name;
static const char* name_ref;
};
#define REGISTER_CLASS(cname,perlname) \
class cname; \
template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \
template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref";
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>
class Ref {
T* val;
public:
Ref() {}
Ref(T* t) : val(t) {}
operator T*() const {return val; }
static const char* CLASS() { return ClassTraits<T>::name_ref; }
};
template <class T>
class Clone {
T* val;
public:
Clone() {}
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

View file

@ -4,26 +4,23 @@
#include <myinit.h> #include <myinit.h>
#include "BoundingBox.hpp" #include "BoundingBox.hpp"
#include "Point.hpp" #include "Point.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Geometry::BoundingBox} class BoundingBox { %name{Slic3r::Geometry::BoundingBox} class BoundingBox {
~BoundingBox(); ~BoundingBox();
BoundingBox* clone() Clone<BoundingBox> clone()
%code{% const char* CLASS = "Slic3r::Geometry::BoundingBox"; RETVAL = new BoundingBox(*THIS); %}; %code{% RETVAL = THIS; %};
void merge(BoundingBox* bb) %code{% THIS->merge(*bb); %}; void merge(BoundingBox* bb) %code{% THIS->merge(*bb); %};
void merge_point(Point* point) %code{% THIS->merge(*point); %}; void merge_point(Point* point) %code{% THIS->merge(*point); %};
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
Polygon* polygon() Polygon* polygon()
%code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(); THIS->polygon(RETVAL); %}; %code{% RETVAL = new Polygon(); THIS->polygon(RETVAL); %};
Point* size() Clone<Point> size();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->size()); %}; Clone<Point> center();
Point* center() Clone<Point> min_point() %code{% RETVAL = THIS->min; %};
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->center()); %}; Clone<Point> max_point() %code{% RETVAL = THIS->max; %};
Point* min_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->min); %};
Point* max_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->max); %};
double x_min() %code{% RETVAL = THIS->min.x; %}; double x_min() %code{% RETVAL = THIS->min.x; %};
double x_max() %code{% RETVAL = THIS->max.x; %}; double x_max() %code{% RETVAL = THIS->max.x; %};
double y_min() %code{% RETVAL = THIS->min.y; %}; double y_min() %code{% RETVAL = THIS->min.y; %};
@ -45,15 +42,13 @@ new_from_points(CLASS, points)
%name{Slic3r::Geometry::BoundingBoxf3} class BoundingBoxf3 { %name{Slic3r::Geometry::BoundingBoxf3} class BoundingBoxf3 {
~BoundingBoxf3(); ~BoundingBoxf3();
BoundingBoxf3* clone() Clone<BoundingBoxf3> clone()
%code{% const char* CLASS = "Slic3r::Geometry::BoundingBoxf3"; RETVAL = new BoundingBoxf3(*THIS); %}; %code{% RETVAL = THIS; %};
void merge(BoundingBoxf3* bb) %code{% THIS->merge(*bb); %}; void merge(BoundingBoxf3* bb) %code{% THIS->merge(*bb); %};
void scale(double factor); void scale(double factor);
void translate(double x, double y, double z); void translate(double x, double y, double z);
Pointf3* size() Clone<Pointf3> size();
%code{% const char* CLASS = "Slic3r::Pointf3"; RETVAL = new Pointf3(THIS->size()); %}; Clone<Pointf3> center();
Pointf3* center()
%code{% const char* CLASS = "Slic3r::Pointf3"; RETVAL = new Pointf3(THIS->center()); %};
double x_min() %code{% RETVAL = THIS->min.x; %}; double x_min() %code{% RETVAL = THIS->min.x; %};
double x_max() %code{% RETVAL = THIS->max.x; %}; double x_max() %code{% RETVAL = THIS->max.x; %};
double y_min() %code{% RETVAL = THIS->min.y; %}; double y_min() %code{% RETVAL = THIS->min.y; %};

View file

@ -3,18 +3,19 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "ExPolygon.hpp" #include "ExPolygon.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::ExPolygon} class ExPolygon { %name{Slic3r::ExPolygon} class ExPolygon {
~ExPolygon(); ~ExPolygon();
ExPolygon* clone() Clone<ExPolygon> clone()
%code{% const char* CLASS = "Slic3r::ExPolygon"; RETVAL = new ExPolygon(*THIS); %}; %code{% RETVAL = THIS; %};
SV* arrayref() SV* arrayref()
%code{% RETVAL = THIS->to_AV(); %}; %code{% RETVAL = THIS->to_AV(); %};
SV* pp() SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %}; %code{% RETVAL = THIS->to_SV_pureperl(); %};
Polygon* contour() Ref<Polygon> contour()
%code{% const char* CLASS = "Slic3r::Polygon::Ref"; RETVAL = &(THIS->contour); %}; %code{% RETVAL = &(THIS->contour); %};
Polygons* holes() Polygons* holes()
%code{% RETVAL = &(THIS->holes); %}; %code{% RETVAL = &(THIS->holes); %};
void scale(double factor); void scale(double factor);

View file

@ -3,12 +3,13 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "ExPolygonCollection.hpp" #include "ExPolygonCollection.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::ExPolygon::Collection} class ExPolygonCollection { %name{Slic3r::ExPolygon::Collection} class ExPolygonCollection {
~ExPolygonCollection(); ~ExPolygonCollection();
ExPolygonCollection* clone() Clone<ExPolygonCollection> clone()
%code{% const char* CLASS = "Slic3r::ExPolygon::Collection"; RETVAL = new ExPolygonCollection(*THIS); %}; %code{% RETVAL = THIS; %};
void clear() void clear()
%code{% THIS->expolygons.clear(); %}; %code{% THIS->expolygons.clear(); %};
void scale(double factor); void scale(double factor);
@ -72,8 +73,6 @@ ExPolygonCollection::append(...)
Polygon* Polygon*
ExPolygonCollection::convex_hull() ExPolygonCollection::convex_hull()
PREINIT:
const char* CLASS = "Slic3r::Polygon";
CODE: CODE:
RETVAL = new Polygon (); RETVAL = new Polygon ();
THIS->convex_hull(RETVAL); THIS->convex_hull(RETVAL);

View file

@ -3,6 +3,7 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "ExtrusionEntityCollection.hpp" #include "ExtrusionEntityCollection.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::ExtrusionPath::Collection} class ExtrusionEntityCollection { %name{Slic3r::ExtrusionPath::Collection} class ExtrusionEntityCollection {
@ -12,20 +13,16 @@
%code{% THIS->entities.clear(); %}; %code{% THIS->entities.clear(); %};
ExtrusionEntityCollection* chained_path(bool no_reverse) ExtrusionEntityCollection* chained_path(bool no_reverse)
%code{% %code{%
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
RETVAL = new ExtrusionEntityCollection(); RETVAL = new ExtrusionEntityCollection();
THIS->chained_path(RETVAL, no_reverse); THIS->chained_path(RETVAL, no_reverse);
%}; %};
ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse) ExtrusionEntityCollection* chained_path_from(Point* start_near, bool no_reverse)
%code{% %code{%
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
RETVAL = new ExtrusionEntityCollection(); RETVAL = new ExtrusionEntityCollection();
THIS->chained_path_from(*start_near, RETVAL, no_reverse); THIS->chained_path_from(*start_near, RETVAL, no_reverse);
%}; %};
Point* first_point() Clone<Point> first_point();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %}; Clone<Point> last_point();
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
int count() int count()
%code{% RETVAL = THIS->entities.size(); %}; %code{% RETVAL = THIS->entities.size(); %};
std::vector<size_t> orig_indices() std::vector<size_t> orig_indices()
@ -50,11 +47,13 @@ ExtrusionEntityCollection::arrayref()
SV* sv = newSV(0); SV* sv = newSV(0);
// return our item by reference // return our item by reference
if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(*it)) { if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(*it)) {
sv_setref_pv( sv, "Slic3r::ExtrusionPath::Ref", path ); sv_setref_pv( sv, perl_class_name_ref(path), path );
} else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(*it)) { } else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(*it)) {
sv_setref_pv( sv, "Slic3r::ExtrusionLoop::Ref", loop ); sv_setref_pv( sv, perl_class_name_ref(loop), loop );
} else if (ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(*it)) {
sv_setref_pv( sv, perl_class_name_ref(collection), collection );
} else { } else {
sv_setref_pv( sv, "Slic3r::ExtrusionPath::Collection::Ref", *it ); croak("Unexpected type in ExtrusionEntityCollection");
} }
av_store(av, i++, sv); av_store(av, i++, sv);
} }
@ -66,14 +65,19 @@ void
ExtrusionEntityCollection::append(...) ExtrusionEntityCollection::append(...)
CODE: CODE:
for (unsigned int i = 1; i < items; i++) { for (unsigned int i = 1; i < items; i++) {
if(!sv_isobject( ST(i) ) || (SvTYPE(SvRV( ST(i) )) != SVt_PVMG)) {
croak("Argument %d is not object", i);
}
ExtrusionEntity* entity = (ExtrusionEntity *)SvIV((SV*)SvRV( ST(i) )); ExtrusionEntity* entity = (ExtrusionEntity *)SvIV((SV*)SvRV( ST(i) ));
// append COPIES // append COPIES
if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(entity)) { if (ExtrusionPath* path = dynamic_cast<ExtrusionPath*>(entity)) {
THIS->entities.push_back( new ExtrusionPath(*path) ); THIS->entities.push_back( new ExtrusionPath(*path) );
} else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(entity)) { } else if (ExtrusionLoop* loop = dynamic_cast<ExtrusionLoop*>(entity)) {
THIS->entities.push_back( new ExtrusionLoop(*loop) ); THIS->entities.push_back( new ExtrusionLoop(*loop) );
} else if(ExtrusionEntityCollection* collection = dynamic_cast<ExtrusionEntityCollection*>(entity)) {
THIS->entities.push_back( collection->clone() );
} else { } else {
THIS->entities.push_back( (*(ExtrusionEntityCollection*)entity).clone() ); croak("Argument %d is of unknown type", i);
} }
} }
@ -89,8 +93,6 @@ ExtrusionEntityCollection::no_sort(...)
ExtrusionEntityCollection* ExtrusionEntityCollection*
ExtrusionEntityCollection::chained_path_indices(bool no_reverse) ExtrusionEntityCollection::chained_path_indices(bool no_reverse)
PREINIT:
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE: CODE:
RETVAL = new ExtrusionEntityCollection(); RETVAL = new ExtrusionEntityCollection();
THIS->chained_path(RETVAL, no_reverse, &RETVAL->orig_indices); THIS->chained_path(RETVAL, no_reverse, &RETVAL->orig_indices);

View file

@ -3,6 +3,7 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "ExtrusionEntity.hpp" #include "ExtrusionEntity.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::ExtrusionLoop} class ExtrusionLoop { %name{Slic3r::ExtrusionLoop} class ExtrusionLoop {
@ -13,15 +14,11 @@
%code{% RETVAL = THIS->polygon.to_SV_pureperl(); %}; %code{% RETVAL = THIS->polygon.to_SV_pureperl(); %};
void reverse() void reverse()
%code{% THIS->polygon.reverse(); %}; %code{% THIS->polygon.reverse(); %};
ExtrusionPath* split_at_index(int index) ExtrusionPath* split_at_index(int index);
%code{% const char* CLASS = "Slic3r::ExtrusionPath"; RETVAL = THIS->split_at_index(index); %}; ExtrusionPath* split_at_first_point();
ExtrusionPath* split_at_first_point()
%code{% const char* CLASS = "Slic3r::ExtrusionPath"; RETVAL = THIS->split_at_first_point(); %};
bool make_counter_clockwise(); bool make_counter_clockwise();
Point* first_point() Clone<Point> first_point();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %}; Clone<Point> last_point();
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
bool is_perimeter(); bool is_perimeter();
bool is_fill(); bool is_fill();
bool is_bridge(); bool is_bridge();
@ -41,10 +38,8 @@ _new(CLASS, polygon_sv, role, mm3_per_mm)
OUTPUT: OUTPUT:
RETVAL RETVAL
Polygon* Ref<Polygon>
ExtrusionLoop::polygon(...) ExtrusionLoop::polygon(...)
PREINIT:
const char* CLASS = "Slic3r::Polygon::Ref";
CODE: CODE:
if (items > 1) { if (items > 1) {
THIS->polygon.from_SV_check( ST(1) ); THIS->polygon.from_SV_check( ST(1) );

View file

@ -17,10 +17,8 @@
void reverse(); void reverse();
Lines lines() Lines lines()
%code{% RETVAL = THIS->polyline.lines(); %}; %code{% RETVAL = THIS->polyline.lines(); %};
Point* first_point() Clone<Point> first_point();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %}; Clone<Point> last_point();
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
void clip_end(double distance); void clip_end(double distance);
void simplify(double tolerance); void simplify(double tolerance);
double length(); double length();
@ -46,10 +44,8 @@ _new(CLASS, polyline_sv, role, mm3_per_mm)
OUTPUT: OUTPUT:
RETVAL RETVAL
Polyline* Ref<Polyline>
ExtrusionPath::polyline(...) ExtrusionPath::polyline(...)
PREINIT:
const char* CLASS = "Slic3r::Polyline::Ref";
CODE: CODE:
if (items > 1) { if (items > 1) {
THIS->polyline.from_SV_check( ST(1) ); THIS->polyline.from_SV_check( ST(1) );
@ -89,8 +85,6 @@ ExtrusionPath::append(...)
ExtrusionEntityCollection* ExtrusionEntityCollection*
ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection) ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection)
PREINIT:
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE: CODE:
RETVAL = new ExtrusionEntityCollection (); RETVAL = new ExtrusionEntityCollection ();
THIS->intersect_expolygons(*collection, RETVAL); THIS->intersect_expolygons(*collection, RETVAL);
@ -99,8 +93,6 @@ ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection)
ExtrusionEntityCollection* ExtrusionEntityCollection*
ExtrusionPath::subtract_expolygons(ExPolygonCollection* collection) ExtrusionPath::subtract_expolygons(ExPolygonCollection* collection)
PREINIT:
const char* CLASS = "Slic3r::ExtrusionPath::Collection";
CODE: CODE:
RETVAL = new ExtrusionEntityCollection (); RETVAL = new ExtrusionEntityCollection ();
THIS->subtract_expolygons(*collection, RETVAL); THIS->subtract_expolygons(*collection, RETVAL);

View file

@ -3,6 +3,7 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "Flow.hpp" #include "Flow.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Flow} class Flow { %name{Slic3r::Flow} class Flow {
@ -10,8 +11,8 @@
%name{_new} Flow(float width, float spacing, float nozzle_diameter); %name{_new} Flow(float width, float spacing, float nozzle_diameter);
void set_bridge(bool bridge) void set_bridge(bool bridge)
%code{% THIS->bridge = bridge; %}; %code{% THIS->bridge = bridge; %};
Flow* clone() Clone<Flow> clone()
%code{% const char* CLASS = "Slic3r::Flow"; RETVAL = new Flow(*THIS); %}; %code{% RETVAL = THIS; %};
float width() float width()
%code{% RETVAL = THIS->width; %}; %code{% RETVAL = THIS->width; %};

View file

@ -13,8 +13,6 @@
Polygon* Polygon*
convex_hull(points) convex_hull(points)
Points points Points points
PREINIT:
const char* CLASS = "Slic3r::Polygon";
CODE: CODE:
RETVAL = new Polygon (); RETVAL = new Polygon ();
Slic3r::Geometry::convex_hull(points, RETVAL); Slic3r::Geometry::convex_hull(points, RETVAL);

View file

@ -3,32 +3,31 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "Line.hpp" #include "Line.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Line} class Line { %name{Slic3r::Line} class Line {
~Line(); ~Line();
Line* clone() Clone<Line> clone()
%code{% const char* CLASS = "Slic3r::Line"; RETVAL = new Line(*THIS); %}; %code{% RETVAL = THIS; %};
SV* arrayref() SV* arrayref()
%code{% RETVAL = THIS->to_AV(); %}; %code{% RETVAL = THIS->to_AV(); %};
SV* pp() SV* pp()
%code{% RETVAL = THIS->to_SV_pureperl(); %}; %code{% RETVAL = THIS->to_SV_pureperl(); %};
Point* a() Ref<Point> a()
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = &(THIS->a); %}; %code{% RETVAL=&THIS->a; %};
Point* b() Ref<Point> b()
%code{% const char* CLASS = "Slic3r::Point::Ref"; RETVAL = &(THIS->b); %}; %code{% RETVAL=&THIS->b; %};
void reverse(); void reverse();
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
double length(); double length();
double atan2_(); double atan2_();
double direction(); double direction();
Point* midpoint() Point* midpoint();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = THIS->midpoint(); %}; Clone<Point> point_at(double distance);
Point* point_at(double distance)
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->point_at(distance)); %};
Polyline* as_polyline() Polyline* as_polyline()
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = new Polyline(*THIS); %}; %code{% RETVAL = new Polyline(*THIS); %};
%{ %{
Line* Line*

View file

@ -3,13 +3,14 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "Point.hpp" #include "Point.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Point} class Point { %name{Slic3r::Point} class Point {
Point(long _x = 0, long _y = 0); Point(long _x = 0, long _y = 0);
~Point(); ~Point();
Point* clone() Clone<Point> clone()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(*THIS); %}; %code{% RETVAL=THIS; %};
void scale(double factor); void scale(double factor);
void translate(double x, double y); void translate(double x, double y);
SV* arrayref() SV* arrayref()
@ -22,7 +23,7 @@
%code{% RETVAL = THIS->y; %}; %code{% RETVAL = THIS->y; %};
int nearest_point_index(Points points); int nearest_point_index(Points points);
Point* nearest_point(Points points) Point* nearest_point(Points points)
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(); THIS->nearest_point(points, RETVAL); %}; %code{% RETVAL = new Point(); THIS->nearest_point(points, RETVAL); %};
double distance_to(Point* point) double distance_to(Point* point)
%code{% RETVAL = THIS->distance_to(*point); %}; %code{% RETVAL = THIS->distance_to(*point); %};
double distance_to_line(Line* line) double distance_to_line(Line* line)
@ -58,8 +59,8 @@ Point::coincides_with(point_sv)
%name{Slic3r::Pointf3} class Pointf3 { %name{Slic3r::Pointf3} class Pointf3 {
Pointf3(double _x = 0, double _y = 0, double _z = 0); Pointf3(double _x = 0, double _y = 0, double _z = 0);
~Pointf3(); ~Pointf3();
Pointf3* clone() Clone<Pointf3> clone()
%code{% const char* CLASS = "Slic3r::Pointf3"; RETVAL = new Pointf3(*THIS); %}; %code{% RETVAL = THIS; %};
double x() double x()
%code{% RETVAL = THIS->x; %}; %code{% RETVAL = THIS->x; %};
double y() double y()

View file

@ -3,12 +3,13 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "Polygon.hpp" #include "Polygon.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Polygon} class Polygon { %name{Slic3r::Polygon} class Polygon {
~Polygon(); ~Polygon();
Polygon* clone() Clone<Polygon> clone()
%code{% const char* CLASS = "Slic3r::Polygon"; RETVAL = new Polygon(*THIS); %}; %code{% RETVAL = THIS; %};
SV* arrayref() SV* arrayref()
%code{% RETVAL = THIS->to_AV(); %}; %code{% RETVAL = THIS->to_AV(); %};
SV* pp() SV* pp()
@ -18,11 +19,11 @@
void reverse(); void reverse();
Lines lines(); Lines lines();
Polyline* split_at(Point* point) Polyline* split_at(Point* point)
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at(*point); %}; %code{% RETVAL = THIS->split_at(*point); %};
Polyline* split_at_index(int index) Polyline* split_at_index(int index)
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_index(index); %}; %code{% RETVAL = THIS->split_at_index(index); %};
Polyline* split_at_first_point() Polyline* split_at_first_point()
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = THIS->split_at_first_point(); %}; %code{% RETVAL = THIS->split_at_first_point(); %};
Points equally_spaced_points(double distance); Points equally_spaced_points(double distance);
double length(); double length();
double area(); double area();
@ -31,8 +32,7 @@
bool make_counter_clockwise(); bool make_counter_clockwise();
bool make_clockwise(); bool make_clockwise();
bool is_valid(); bool is_valid();
Point* first_point() Clone<Point> first_point();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %};
bool contains_point(Point* point) bool contains_point(Point* point)
%code{% RETVAL = THIS->contains_point(*point); %}; %code{% RETVAL = THIS->contains_point(*point); %};
Polygons simplify(double tolerance); Polygons simplify(double tolerance);

View file

@ -4,12 +4,13 @@
#include <myinit.h> #include <myinit.h>
#include "ClipperUtils.hpp" #include "ClipperUtils.hpp"
#include "Polyline.hpp" #include "Polyline.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Polyline} class Polyline { %name{Slic3r::Polyline} class Polyline {
~Polyline(); ~Polyline();
Polyline* clone() Clone<Polyline> clone()
%code{% const char* CLASS = "Slic3r::Polyline"; RETVAL = new Polyline(*THIS); %}; %code{% RETVAL = THIS; %};
SV* arrayref() SV* arrayref()
%code{% RETVAL = THIS->to_AV(); %}; %code{% RETVAL = THIS->to_AV(); %};
SV* pp() SV* pp()
@ -20,10 +21,8 @@
%code{% THIS->points.pop_back(); %}; %code{% THIS->points.pop_back(); %};
void reverse(); void reverse();
Lines lines(); Lines lines();
Point* first_point() Clone<Point> first_point();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->first_point()); %}; Clone<Point> last_point();
Point* last_point()
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->last_point()); %};
Points equally_spaced_points(double distance); Points equally_spaced_points(double distance);
double length(); double length();
bool is_valid(); bool is_valid();

View file

@ -3,30 +3,28 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "PolylineCollection.hpp" #include "PolylineCollection.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Polyline::Collection} class PolylineCollection { %name{Slic3r::Polyline::Collection} class PolylineCollection {
~PolylineCollection(); ~PolylineCollection();
PolylineCollection* clone() Clone<PolylineCollection> clone()
%code{% const char* CLASS = "Slic3r::Polyline::Collection"; RETVAL = new PolylineCollection(*THIS); %}; %code{% RETVAL = THIS; %};
void clear() void clear()
%code{% THIS->polylines.clear(); %}; %code{% THIS->polylines.clear(); %};
PolylineCollection* chained_path(bool no_reverse) PolylineCollection* chained_path(bool no_reverse)
%code{% %code{%
const char* CLASS = "Slic3r::Polyline::Collection";
RETVAL = new PolylineCollection(); RETVAL = new PolylineCollection();
THIS->chained_path(RETVAL, no_reverse); THIS->chained_path(RETVAL, no_reverse);
%}; %};
PolylineCollection* chained_path_from(Point* start_near, bool no_reverse) PolylineCollection* chained_path_from(Point* start_near, bool no_reverse)
%code{% %code{%
const char* CLASS = "Slic3r::Polyline::Collection";
RETVAL = new PolylineCollection(); RETVAL = new PolylineCollection();
THIS->chained_path_from(*start_near, RETVAL, no_reverse); THIS->chained_path_from(*start_near, RETVAL, no_reverse);
%}; %};
int count() int count()
%code{% RETVAL = THIS->polylines.size(); %}; %code{% RETVAL = THIS->polylines.size(); %};
Point* leftmost_point() Clone<Point> leftmost_point();
%code{% const char* CLASS = "Slic3r::Point"; RETVAL = new Point(THIS->leftmost_point()); %};
%{ %{
PolylineCollection* PolylineCollection*

View file

@ -4,12 +4,13 @@
#include <myinit.h> #include <myinit.h>
#include "Surface.hpp" #include "Surface.hpp"
#include "ClipperUtils.hpp" #include "ClipperUtils.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::Surface} class Surface { %name{Slic3r::Surface} class Surface {
~Surface(); ~Surface();
ExPolygon* expolygon() Ref<ExPolygon> expolygon()
%code{% const char* CLASS = "Slic3r::ExPolygon::Ref"; RETVAL = &(THIS->expolygon); %}; %code{% RETVAL = &(THIS->expolygon); %};
double thickness() double thickness()
%code{% RETVAL = THIS->thickness; %}; %code{% RETVAL = THIS->thickness; %};
unsigned short thickness_layers() unsigned short thickness_layers()

View file

@ -3,13 +3,14 @@
%{ %{
#include <myinit.h> #include <myinit.h>
#include "TriangleMesh.hpp" #include "TriangleMesh.hpp"
#include "perlglue.hpp"
%} %}
%name{Slic3r::TriangleMesh} class TriangleMesh { %name{Slic3r::TriangleMesh} class TriangleMesh {
TriangleMesh(); TriangleMesh();
~TriangleMesh(); ~TriangleMesh();
TriangleMesh* clone() Clone<TriangleMesh> clone()
%code{% const char* CLASS = "Slic3r::TriangleMesh"; RETVAL = new TriangleMesh(*THIS); %}; %code{% RETVAL = THIS; %};
void ReadSTLFile(char* input_file); void ReadSTLFile(char* input_file);
void write_ascii(char* output_file); void write_ascii(char* output_file);
void write_binary(char* output_file); void write_binary(char* output_file);
@ -31,7 +32,6 @@
%code{% THIS->horizontal_projection(RETVAL); %}; %code{% THIS->horizontal_projection(RETVAL); %};
BoundingBoxf3* bounding_box() BoundingBoxf3* bounding_box()
%code{% %code{%
const char* CLASS = "Slic3r::Geometry::BoundingBoxf3";
RETVAL = new BoundingBoxf3(); RETVAL = new BoundingBoxf3();
THIS->bounding_box(RETVAL); THIS->bounding_box(RETVAL);
%}; %};
@ -189,8 +189,6 @@ TriangleMesh::bb3()
Polygon* Polygon*
TriangleMesh::convex_hull() TriangleMesh::convex_hull()
PREINIT:
const char* CLASS = "Slic3r::Polygon";
CODE: CODE:
RETVAL = new Polygon (); RETVAL = new Polygon ();
THIS->convex_hull(RETVAL); THIS->convex_hull(RETVAL);

View file

@ -2,30 +2,80 @@ std::vector<Points::size_type> T_STD_VECTOR_INT
std::vector<size_t> T_STD_VECTOR_INT std::vector<size_t> T_STD_VECTOR_INT
t_config_option_key T_STD_STRING t_config_option_key T_STD_STRING
BoundingBox* O_OBJECT BoundingBox* O_OBJECT_SLIC3R
BoundingBoxf3* O_OBJECT Ref<BoundingBox> O_OBJECT_SLIC3R_T
DynamicPrintConfig* O_OBJECT Clone<BoundingBox> O_OBJECT_SLIC3R_T
PrintObjectConfig* O_OBJECT
PrintRegionConfig* O_OBJECT BoundingBoxf3* O_OBJECT_SLIC3R
PrintConfig* O_OBJECT Ref<BoundingBoxf3> O_OBJECT_SLIC3R_T
FullPrintConfig* O_OBJECT Clone<BoundingBoxf3> O_OBJECT_SLIC3R_T
ZTable* O_OBJECT
TriangleMesh* O_OBJECT DynamicPrintConfig* O_OBJECT_SLIC3R
Point* O_OBJECT PrintObjectConfig* O_OBJECT_SLIC3R
Pointf3* O_OBJECT PrintRegionConfig* O_OBJECT_SLIC3R
Line* O_OBJECT PrintConfig* O_OBJECT_SLIC3R
Polyline* O_OBJECT FullPrintConfig* O_OBJECT_SLIC3R
PolylineCollection* O_OBJECT ZTable* O_OBJECT
Polygon* O_OBJECT
ExPolygon* O_OBJECT TriangleMesh* O_OBJECT_SLIC3R
ExPolygonCollection* O_OBJECT Ref<TriangleMesh> O_OBJECT_SLIC3R_T
ExtrusionEntityCollection* O_OBJECT Clone<TriangleMesh> O_OBJECT_SLIC3R_T
ExtrusionPath* O_OBJECT
ExtrusionLoop* O_OBJECT Point* O_OBJECT_SLIC3R
Flow* O_OBJECT Ref<Point> O_OBJECT_SLIC3R_T
PrintState* O_OBJECT Clone<Point> O_OBJECT_SLIC3R_T
Surface* O_OBJECT
SurfaceCollection* O_OBJECT Pointf3* O_OBJECT_SLIC3R
Ref<Pointf3> O_OBJECT_SLIC3R_T
Clone<Pointf3> O_OBJECT_SLIC3R_T
Line* O_OBJECT_SLIC3R
Ref<Line> O_OBJECT_SLIC3R_T
Clone<Line> O_OBJECT_SLIC3R_T
Polyline* O_OBJECT_SLIC3R
Ref<Polyline> O_OBJECT_SLIC3R_T
Clone<Polyline> O_OBJECT_SLIC3R_T
PolylineCollection* O_OBJECT_SLIC3R
Ref<PolylineCollection> O_OBJECT_SLIC3R_T
Clone<PolylineCollection> O_OBJECT_SLIC3R_T
Polygon* O_OBJECT_SLIC3R
Ref<Polygon> O_OBJECT_SLIC3R_T
Clone<Polygon> O_OBJECT_SLIC3R_T
ExPolygon* O_OBJECT_SLIC3R
Ref<ExPolygon> O_OBJECT_SLIC3R_T
Clone<ExPolygon> O_OBJECT_SLIC3R_T
ExPolygonCollection* O_OBJECT_SLIC3R
Ref<ExPolygonCollection> O_OBJECT_SLIC3R_T
Clone<ExPolygonCollection> O_OBJECT_SLIC3R_T
ExtrusionEntityCollection* O_OBJECT_SLIC3R
Ref<ExtrusionEntityCollection> O_OBJECT_SLIC3R_T
Clone<ExtrusionEntityCollection> O_OBJECT_SLIC3R_T
ExtrusionPath* O_OBJECT_SLIC3R
Ref<ExtrusionPath> O_OBJECT_SLIC3R_T
Clone<ExtrusionPath> O_OBJECT_SLIC3R_T
ExtrusionLoop* O_OBJECT_SLIC3R
Ref<ExtrusionLoop> O_OBJECT_SLIC3R_T
Clone<ExtrusionLoop> O_OBJECT_SLIC3R_T
Flow* O_OBJECT_SLIC3R
Ref<Flow> O_OBJECT_SLIC3R_T
Clone<Flow> O_OBJECT_SLIC3R_T
PrintState* O_OBJECT_SLIC3R
Surface* O_OBJECT_SLIC3R
Ref<Surface> O_OBJECT_SLIC3R_T
Clone<Surface> O_OBJECT_SLIC3R_T
SurfaceCollection* O_OBJECT_SLIC3R
ExtrusionRole T_UV ExtrusionRole T_UV
FlowRole T_UV FlowRole T_UV
@ -55,6 +105,19 @@ TriangleMeshPtrs T_PTR_ARRAYREF
INPUT INPUT
O_OBJECT_SLIC3R
if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) {
if ( sv_isa($arg, perl_class_name($var) ) || sv_isa($arg, perl_class_name_ref($var) )) {
$var = ($type)SvIV((SV*)SvRV( $arg ));
} else {
croak(\"$var is not of type %s (got %s)\", perl_class_name($var), HvNAME(SvSTASH(SvRV($arg))));
XSRETURN_UNDEF;
}
} else {
warn( \"${Package}::$func_name() -- $var is not a blessed SV reference\" );
XSRETURN_UNDEF;
}
T_ARRAYREF T_ARRAYREF
if (SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVAV) { if (SvROK($arg) && SvTYPE(SvRV($arg)) == SVt_PVAV) {
AV* av = (AV*)SvRV($arg); AV* av = (AV*)SvRV($arg);
@ -72,6 +135,14 @@ T_ARRAYREF
\"$var\"); \"$var\");
OUTPUT OUTPUT
# return object from pointer
O_OBJECT_SLIC3R
sv_setref_pv( $arg, perl_class_name($var), (void*)$var );
# return value handled by template class
O_OBJECT_SLIC3R_T
sv_setref_pv( $arg, $type\::CLASS(), (void*)$var );
T_ARRAYREF T_ARRAYREF
AV* av = newAV(); AV* av = newAV();

View file

@ -10,23 +10,56 @@
%typemap{SV*}; %typemap{SV*};
%typemap{AV*}; %typemap{AV*};
%typemap{Point*}; %typemap{Point*};
%typemap{Ref<Point>}{simple};
%typemap{Clone<Point>}{simple};
%typemap{Pointf3*}; %typemap{Pointf3*};
%typemap{Ref<Pointf3>}{simple};
%typemap{Clone<Pointf3>}{simple};
%typemap{BoundingBox*}; %typemap{BoundingBox*};
%typemap{Ref<BoundingBox>}{simple};
%typemap{Clone<BoundingBox>}{simple};
%typemap{BoundingBoxf3*}; %typemap{BoundingBoxf3*};
%typemap{Ref<BoundingBoxf3>}{simple};
%typemap{Clone<BoundingBoxf3>}{simple};
%typemap{DynamicPrintConfig*}; %typemap{DynamicPrintConfig*};
%typemap{PrintObjectConfig*}; %typemap{PrintObjectConfig*};
%typemap{PrintRegionConfig*}; %typemap{PrintRegionConfig*};
%typemap{PrintConfig*}; %typemap{PrintConfig*};
%typemap{FullPrintConfig*}; %typemap{FullPrintConfig*};
%typemap{ExPolygon*}; %typemap{ExPolygon*};
%typemap{Ref<ExPolygon>}{simple};
%typemap{Clone<ExPolygon>}{simple};
%typemap{ExPolygonCollection*}; %typemap{ExPolygonCollection*};
%typemap{Ref<ExPolygonCollection>}{simple};
%typemap{Clone<ExPolygonCollection>}{simple};
%typemap{Flow*}; %typemap{Flow*};
%typemap{Ref<Flow>}{simple};
%typemap{Clone<Flow>}{simple};
%typemap{Line*}; %typemap{Line*};
%typemap{Ref<Line>}{simple};
%typemap{Clone<Line>}{simple};
%typemap{Polyline*}; %typemap{Polyline*};
%typemap{Ref<Polyline>}{simple};
%typemap{Clone<Polyline>}{simple};
%typemap{Polygon*}; %typemap{Polygon*};
%typemap{Ref<Polygon>}{simple};
%typemap{Clone<Polygon>}{simple};
%typemap{ExtrusionEntityCollection*}; %typemap{ExtrusionEntityCollection*};
%typemap{Ref<ExtrusionEntityCollection>}{simple};
%typemap{Clone<ExtrusionEntityCollection>}{simple};
%typemap{ExtrusionPath*}; %typemap{ExtrusionPath*};
%typemap{Ref<ExtrusionPath>}{simple};
%typemap{Clone<ExtrusionPath>}{simple};
%typemap{ExtrusionLoop*}; %typemap{ExtrusionLoop*};
%typemap{Ref<ExtrusionLoop>}{simple};
%typemap{Clone<ExtrusionLoop>}{simple};
%typemap{TriangleMesh*};
%typemap{Ref<TriangleMesh>}{simple};
%typemap{Clone<TriangleMesh>}{simple};
%typemap{PolylineCollection*};
%typemap{Ref<PolylineCollection>}{simple};
%typemap{Clone<PolylineCollection>}{simple};
%typemap{Points}; %typemap{Points};
%typemap{Pointfs}; %typemap{Pointfs};
%typemap{Lines}; %typemap{Lines};