PrusaSlicer-NonPlainar/xs/xsp/Surface.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

121 lines
3.0 KiB
Plaintext

%module{Slic3r::XS};
%{
#include <myinit.h>
#include "Surface.hpp"
#include "ClipperUtils.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Surface} class Surface {
~Surface();
Ref<ExPolygon> expolygon()
%code{% RETVAL = &(THIS->expolygon); %};
double thickness()
%code{% RETVAL = THIS->thickness; %};
unsigned short thickness_layers()
%code{% RETVAL = THIS->thickness_layers; %};
double area();
bool is_solid() const;
bool is_external() const;
bool is_bottom() const;
bool is_bridge() const;
%{
Surface*
_new(CLASS, expolygon, surface_type, thickness, thickness_layers, bridge_angle, extra_perimeters)
char* CLASS;
ExPolygon* expolygon;
SurfaceType surface_type;
double thickness;
unsigned short thickness_layers;
double bridge_angle;
unsigned short extra_perimeters;
CODE:
RETVAL = new Surface ();
RETVAL->expolygon = *expolygon;
RETVAL->surface_type = surface_type;
RETVAL->thickness = thickness;
RETVAL->thickness_layers = thickness_layers;
RETVAL->bridge_angle = bridge_angle;
RETVAL->extra_perimeters = extra_perimeters;
// we don't delete expolygon here because it's referenced by a Perl SV
// whose DESTROY will take care of destruction
OUTPUT:
RETVAL
SurfaceType
Surface::surface_type(...)
CODE:
if (items > 1) {
THIS->surface_type = (SurfaceType)SvUV(ST(1));
}
RETVAL = THIS->surface_type;
OUTPUT:
RETVAL
double
Surface::bridge_angle(...)
CODE:
if (items > 1) {
THIS->bridge_angle = (double)SvNV(ST(1));
}
RETVAL = THIS->bridge_angle;
OUTPUT:
RETVAL
unsigned short
Surface::extra_perimeters(...)
CODE:
if (items > 1) {
THIS->extra_perimeters = (double)SvUV(ST(1));
}
RETVAL = THIS->extra_perimeters;
OUTPUT:
RETVAL
Polygons
Surface::polygons()
CODE:
RETVAL.push_back(THIS->expolygon.contour);
for (Polygons::iterator it = THIS->expolygon.holes.begin(); it != THIS->expolygon.holes.end(); ++it) {
RETVAL.push_back((*it));
}
OUTPUT:
RETVAL
Surfaces
Surface::offset(delta, scale = CLIPPER_OFFSET_SCALE, joinType = ClipperLib::jtMiter, miterLimit = 3)
const float delta
double scale
ClipperLib::JoinType joinType
double miterLimit
CODE:
offset(*THIS, RETVAL, delta, scale, joinType, miterLimit);
OUTPUT:
RETVAL
%}
};
%package{Slic3r::Surface};
%{
IV
_constant()
ALIAS:
S_TYPE_TOP = stTop
S_TYPE_BOTTOM = stBottom
S_TYPE_BOTTOMBRIDGE = stBottomBridge
S_TYPE_INTERNAL = stInternal
S_TYPE_INTERNALSOLID = stInternalSolid
S_TYPE_INTERNALBRIDGE = stInternalBridge
S_TYPE_INTERNALVOID = stInternalVoid
PROTOTYPE:
CODE:
RETVAL = ix;
OUTPUT: RETVAL
%}