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

82 lines
2.1 KiB
Plaintext

%module{Slic3r::XS};
%{
#include <myinit.h>
#include "Flow.hpp"
#include "perlglue.hpp"
%}
%name{Slic3r::Flow} class Flow {
~Flow();
%name{_new} Flow(float width, float spacing, float nozzle_diameter);
void set_bridge(bool bridge)
%code{% THIS->bridge = bridge; %};
Clone<Flow> clone()
%code{% RETVAL = THIS; %};
float width()
%code{% RETVAL = THIS->width; %};
float spacing()
%code{% RETVAL = THIS->spacing; %};
float nozzle_diameter()
%code{% RETVAL = THIS->nozzle_diameter; %};
bool bridge()
%code{% RETVAL = THIS->bridge; %};
long scaled_width()
%code{% RETVAL = THIS->scaled_width; %};
long scaled_spacing()
%code{% RETVAL = THIS->scaled_spacing; %};
double mm3_per_mm(float height);
%{
Flow*
_new_from_width(CLASS, role, width, nozzle_diameter, height, bridge_flow_ratio)
char* CLASS;
FlowRole role;
std::string width;
float nozzle_diameter;
float height;
float bridge_flow_ratio;
CODE:
ConfigOptionFloatOrPercent optwidth;
optwidth.deserialize(width);
RETVAL = new Flow(Flow::new_from_config_width(role, optwidth, nozzle_diameter, height, bridge_flow_ratio));
OUTPUT:
RETVAL
Flow*
_new_from_spacing(CLASS, spacing, nozzle_diameter, height, bridge)
char* CLASS;
float spacing;
float nozzle_diameter;
float height;
bool bridge;
CODE:
RETVAL = new Flow(Flow::new_from_spacing(spacing, nozzle_diameter, height, bridge));
OUTPUT:
RETVAL
%}
};
%package{Slic3r::Flow};
%{
IV
_constant()
ALIAS:
FLOW_ROLE_PERIMETER = frPerimeter
FLOW_ROLE_INFILL = frInfill
FLOW_ROLE_SOLID_INFILL = frSolidInfill
FLOW_ROLE_TOP_SOLID_INFILL = frTopSolidInfill
FLOW_ROLE_SUPPORT_MATERIAL = frSupportMaterial
FLOW_ROLE_SUPPORT_MATERIAL_INTERFACE = frSupportMaterialInterface
PROTOTYPE:
CODE:
RETVAL = ix;
OUTPUT: RETVAL
%}