orcaslicer/xs/xsp/ExtrusionPath.xsp
Petr Ledvina 115aa6885f 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.
2014-04-27 19:38:56 +02:00

129 lines
3.3 KiB
Text

%module{Slic3r::XS};
%{
#include <myinit.h>
#include "ExtrusionEntity.hpp"
#include "ExtrusionEntityCollection.hpp"
%}
%name{Slic3r::ExtrusionPath} class ExtrusionPath {
~ExtrusionPath();
SV* arrayref()
%code{% RETVAL = THIS->polyline.to_AV(); %};
SV* pp()
%code{% RETVAL = THIS->polyline.to_SV_pureperl(); %};
void pop_back()
%code{% THIS->polyline.points.pop_back(); %};
void reverse();
Lines lines()
%code{% RETVAL = THIS->polyline.lines(); %};
Clone<Point> first_point();
Clone<Point> last_point();
void clip_end(double distance);
void simplify(double tolerance);
double length();
bool is_perimeter();
bool is_fill();
bool is_bridge();
std::string gcode(SV* extruder, double e, double F,
double xofs, double yofs, std::string extrusion_axis,
std::string gcode_line_suffix);
%{
ExtrusionPath*
_new(CLASS, polyline_sv, role, mm3_per_mm)
char* CLASS;
SV* polyline_sv;
ExtrusionRole role;
double mm3_per_mm;
CODE:
RETVAL = new ExtrusionPath ();
RETVAL->polyline.from_SV_check(polyline_sv);
RETVAL->role = role;
RETVAL->mm3_per_mm = mm3_per_mm;
OUTPUT:
RETVAL
Ref<Polyline>
ExtrusionPath::polyline(...)
CODE:
if (items > 1) {
THIS->polyline.from_SV_check( ST(1) );
}
RETVAL = &(THIS->polyline);
OUTPUT:
RETVAL
ExtrusionRole
ExtrusionPath::role(...)
CODE:
if (items > 1) {
THIS->role = (ExtrusionRole)SvUV(ST(1));
}
RETVAL = THIS->role;
OUTPUT:
RETVAL
double
ExtrusionPath::mm3_per_mm(...)
CODE:
if (items > 1) {
THIS->mm3_per_mm = (double)SvNV(ST(1));
}
RETVAL = THIS->mm3_per_mm;
OUTPUT:
RETVAL
void
ExtrusionPath::append(...)
CODE:
for (unsigned int i = 1; i < items; i++) {
Point p;
p.from_SV_check(ST(i));
THIS->polyline.points.push_back(p);
}
ExtrusionEntityCollection*
ExtrusionPath::intersect_expolygons(ExPolygonCollection* collection)
CODE:
RETVAL = new ExtrusionEntityCollection ();
THIS->intersect_expolygons(*collection, RETVAL);
OUTPUT:
RETVAL
ExtrusionEntityCollection*
ExtrusionPath::subtract_expolygons(ExPolygonCollection* collection)
CODE:
RETVAL = new ExtrusionEntityCollection ();
THIS->subtract_expolygons(*collection, RETVAL);
OUTPUT:
RETVAL
%}
};
%package{Slic3r::ExtrusionPath};
%{
IV
_constant()
ALIAS:
EXTR_ROLE_PERIMETER = erPerimeter
EXTR_ROLE_EXTERNAL_PERIMETER = erExternalPerimeter
EXTR_ROLE_OVERHANG_PERIMETER = erOverhangPerimeter
EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER = erContourInternalPerimeter
EXTR_ROLE_FILL = erFill
EXTR_ROLE_SOLIDFILL = erSolidFill
EXTR_ROLE_TOPSOLIDFILL = erTopSolidFill
EXTR_ROLE_BRIDGE = erBrige
EXTR_ROLE_INTERNALBRIDGE = erInternalBridge
EXTR_ROLE_SKIRT = erSkirt
EXTR_ROLE_SUPPORTMATERIAL = erSupportMaterial
EXTR_ROLE_GAPFILL = erGapFill
PROTOTYPE:
CODE:
RETVAL = ix;
OUTPUT: RETVAL
%}