Merge pull request #1968 from sapir/extrudercpp
Translate Extruder class to C++
This commit is contained in:
commit
4c330b6c59
16 changed files with 314 additions and 74 deletions
|
@ -1660,6 +1660,8 @@ src/ExPolygon.cpp
|
|||
src/ExPolygon.hpp
|
||||
src/ExPolygonCollection.cpp
|
||||
src/ExPolygonCollection.hpp
|
||||
src/Extruder.cpp
|
||||
src/Extruder.hpp
|
||||
src/ExtrusionEntity.cpp
|
||||
src/ExtrusionEntity.hpp
|
||||
src/ExtrusionEntityCollection.cpp
|
||||
|
@ -1721,6 +1723,7 @@ xsp/Clipper.xsp
|
|||
xsp/Config.xsp
|
||||
xsp/ExPolygon.xsp
|
||||
xsp/ExPolygonCollection.xsp
|
||||
xsp/Extruder.xsp
|
||||
xsp/ExtrusionEntityCollection.xsp
|
||||
xsp/ExtrusionLoop.xsp
|
||||
xsp/ExtrusionPath.xsp
|
||||
|
|
|
@ -28,6 +28,11 @@ our @ISA = 'Slic3r::Point';
|
|||
|
||||
sub DESTROY {}
|
||||
|
||||
package Slic3r::Pointf;
|
||||
use overload
|
||||
'@{}' => sub { [ $_[0]->x, $_[0]->y ] }, #,
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Pointf3;
|
||||
use overload
|
||||
'@{}' => sub { [ $_[0]->x, $_[0]->y, $_[0]->z ] }, #,
|
||||
|
@ -221,4 +226,9 @@ use overload
|
|||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Config::Print::Ref;
|
||||
our @ISA = 'Slic3r::Config::Print';
|
||||
|
||||
sub DESTROY {}
|
||||
|
||||
1;
|
||||
|
|
|
@ -33,7 +33,7 @@ class ConfigOptionVector
|
|||
virtual ~ConfigOptionVector() {};
|
||||
std::vector<T> values;
|
||||
|
||||
T get_at(size_t i) {
|
||||
T get_at(size_t i) const {
|
||||
try {
|
||||
return this->values.at(i);
|
||||
} catch (const std::out_of_range& oor) {
|
||||
|
|
153
xs/src/Extruder.cpp
Normal file
153
xs/src/Extruder.cpp
Normal file
|
@ -0,0 +1,153 @@
|
|||
#include "Extruder.hpp"
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
#endif
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
Extruder::Extruder(int id, PrintConfig *config)
|
||||
: id(id),
|
||||
config(config)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void
|
||||
Extruder::reset()
|
||||
{
|
||||
this->E = 0;
|
||||
this->absolute_E = 0;
|
||||
this->retracted = 0;
|
||||
this->restart_extra = 0;
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::extrude(double dE)
|
||||
{
|
||||
if (this->use_relative_e_distances()) {
|
||||
this->E = 0;
|
||||
}
|
||||
|
||||
this->E += dE;
|
||||
this->absolute_E += dE;
|
||||
return this->E;
|
||||
}
|
||||
|
||||
template <typename Val, class OptType> Val
|
||||
Extruder::get_config(const char *name) const
|
||||
{
|
||||
// TODO: figure out way to avoid static_cast to access hidden const method
|
||||
const ConfigOption *opt = static_cast<const ConfigBase*>(this->config)
|
||||
->option(name);
|
||||
return dynamic_cast<const OptType *>(opt)->get_at(this->id);
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::use_relative_e_distances() const
|
||||
{
|
||||
// not using get_config because use_relative_e_distances is global
|
||||
// for all extruders
|
||||
|
||||
// TODO: figure out way to avoid static_cast to access hidden const method
|
||||
const ConfigOption *opt = static_cast<const ConfigBase*>(this->config)
|
||||
->option("use_relative_e_distances");
|
||||
return *static_cast<const ConfigOptionBool*>(opt);
|
||||
}
|
||||
|
||||
Pointf
|
||||
Extruder::extruder_offset() const
|
||||
{
|
||||
return get_config<Pointf, ConfigOptionPoints>("extruder_offset");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::nozzle_diameter() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("nozzle_diameter");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::filament_diameter() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("filament_diameter");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::extrusion_multiplier() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("extrusion_multiplier");
|
||||
}
|
||||
|
||||
int
|
||||
Extruder::temperature() const
|
||||
{
|
||||
return get_config<int, ConfigOptionInts>("temperature");
|
||||
}
|
||||
|
||||
int
|
||||
Extruder::first_layer_temperature() const
|
||||
{
|
||||
return get_config<int, ConfigOptionInts>("first_layer_temperature");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_length() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_length");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_lift() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_lift");
|
||||
}
|
||||
|
||||
int
|
||||
Extruder::retract_speed() const
|
||||
{
|
||||
return get_config<int, ConfigOptionInts>("retract_speed");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_restart_extra() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_restart_extra");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_before_travel() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_before_travel");
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::retract_layer_change() const
|
||||
{
|
||||
return get_config<bool, ConfigOptionBools>("retract_layer_change");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_length_toolchange() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>("retract_length_toolchange");
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::retract_restart_extra_toolchange() const
|
||||
{
|
||||
return get_config<double, ConfigOptionFloats>(
|
||||
"retract_restart_extra_toolchange");
|
||||
}
|
||||
|
||||
bool
|
||||
Extruder::wipe() const
|
||||
{
|
||||
return get_config<bool, ConfigOptionBools>("wipe");
|
||||
}
|
||||
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
REGISTER_CLASS(Extruder, "Extruder");
|
||||
#endif
|
||||
|
||||
}
|
54
xs/src/Extruder.hpp
Normal file
54
xs/src/Extruder.hpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef slic3r_Extruder_hpp_
|
||||
#define slic3r_Extruder_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Point.hpp"
|
||||
#include "PrintConfig.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Extruder
|
||||
{
|
||||
public:
|
||||
Extruder(int id, PrintConfig *config);
|
||||
virtual ~Extruder() {}
|
||||
void reset();
|
||||
double extrude(double dE);
|
||||
|
||||
|
||||
bool use_relative_e_distances() const;
|
||||
Pointf extruder_offset() const;
|
||||
double nozzle_diameter() const;
|
||||
double filament_diameter() const;
|
||||
double extrusion_multiplier() const;
|
||||
int temperature() const;
|
||||
int first_layer_temperature() const;
|
||||
double retract_length() const;
|
||||
double retract_lift() const;
|
||||
int retract_speed() const;
|
||||
double retract_restart_extra() const;
|
||||
double retract_before_travel() const;
|
||||
bool retract_layer_change() const;
|
||||
double retract_length_toolchange() const;
|
||||
double retract_restart_extra_toolchange() const;
|
||||
bool wipe() const;
|
||||
|
||||
int id;
|
||||
double E;
|
||||
double absolute_E;
|
||||
double retracted;
|
||||
double restart_extra;
|
||||
|
||||
PrintConfig *config;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// get value from a ConfigOptionVector subtype, indexed by extruder id
|
||||
template <typename Val, class OptType>
|
||||
Val get_config(const char *name) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,6 +2,7 @@
|
|||
#include "ExtrusionEntityCollection.hpp"
|
||||
#include "ExPolygonCollection.hpp"
|
||||
#include "ClipperUtils.hpp"
|
||||
#include "Extruder.hpp"
|
||||
#include <sstream>
|
||||
#ifdef SLIC3RXS
|
||||
#include "perlglue.hpp"
|
||||
|
@ -109,7 +110,7 @@ ExtrusionPath::_inflate_collection(const Polylines &polylines, ExtrusionEntityCo
|
|||
REGISTER_CLASS(ExtrusionPath, "ExtrusionPath");
|
||||
|
||||
std::string
|
||||
ExtrusionPath::gcode(SV* extruder, double e, double F,
|
||||
ExtrusionPath::gcode(Extruder* extruder, double e, double F,
|
||||
double xofs, double yofs, std::string extrusion_axis,
|
||||
std::string gcode_line_suffix) const
|
||||
{
|
||||
|
@ -127,19 +128,7 @@ ExtrusionPath::gcode(SV* extruder, double e, double F,
|
|||
const double line_length = line_it->length() * SCALING_FACTOR;
|
||||
|
||||
// calculate extrusion length for this line
|
||||
double E = 0;
|
||||
if (e != 0) {
|
||||
PUSHMARK(SP);
|
||||
XPUSHs(extruder);
|
||||
XPUSHs(sv_2mortal(newSVnv(e * line_length)));
|
||||
PUTBACK;
|
||||
|
||||
const int count = call_method("extrude", G_SCALAR);
|
||||
SPAGAIN;
|
||||
|
||||
// TODO: check that count is 1
|
||||
E = POPn;
|
||||
}
|
||||
double E = (e == 0) ? 0 : extruder->extrude(e * line_length);
|
||||
|
||||
// compose G-code line
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Slic3r {
|
|||
|
||||
class ExPolygonCollection;
|
||||
class ExtrusionEntityCollection;
|
||||
class Extruder;
|
||||
|
||||
enum ExtrusionRole {
|
||||
erPerimeter,
|
||||
|
@ -57,7 +58,7 @@ class ExtrusionPath : public ExtrusionEntity
|
|||
double length() const;
|
||||
|
||||
#ifdef SLIC3RXS
|
||||
std::string gcode(SV* extruder, double e, double F,
|
||||
std::string gcode(Extruder* extruder, double e, double F,
|
||||
double xofs, double yofs, std::string extrusion_axis,
|
||||
std::string gcode_line_suffix) const;
|
||||
#endif
|
||||
|
|
51
xs/xsp/Extruder.xsp
Normal file
51
xs/xsp/Extruder.xsp
Normal file
|
@ -0,0 +1,51 @@
|
|||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "Extruder.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::Extruder} class Extruder {
|
||||
Extruder(int id, PrintConfig *config);
|
||||
|
||||
~Extruder();
|
||||
void reset();
|
||||
double extrude(double dE);
|
||||
|
||||
int id() const
|
||||
%code%{ RETVAL = THIS->id; %};
|
||||
|
||||
|
||||
double E() const
|
||||
%code%{ RETVAL = THIS->E; %};
|
||||
double set_E(double val) const
|
||||
%code%{ RETVAL = THIS->E = val; %};
|
||||
double absolute_E() const
|
||||
%code%{ RETVAL = THIS->absolute_E; %};
|
||||
double set_absolute_E(double val) const
|
||||
%code%{ RETVAL = THIS->absolute_E = val; %};
|
||||
double retracted() const
|
||||
%code%{ RETVAL = THIS->retracted; %};
|
||||
double set_retracted(double val) const
|
||||
%code%{ RETVAL = THIS->retracted = val; %};
|
||||
double restart_extra() const
|
||||
%code%{ RETVAL = THIS->restart_extra; %};
|
||||
double set_restart_extra(double val) const
|
||||
%code%{ RETVAL = THIS->restart_extra = val; %};
|
||||
|
||||
Clone<Pointf> extruder_offset() const;
|
||||
double nozzle_diameter() const;
|
||||
double filament_diameter() const;
|
||||
double extrusion_multiplier() const;
|
||||
int temperature() const;
|
||||
int first_layer_temperature() const;
|
||||
double retract_length() const;
|
||||
double retract_lift() const;
|
||||
int retract_speed() const;
|
||||
double retract_restart_extra() const;
|
||||
double retract_before_travel() const;
|
||||
bool retract_layer_change() const;
|
||||
double retract_length_toolchange() const;
|
||||
double retract_restart_extra_toolchange() const;
|
||||
bool wipe() const;
|
||||
};
|
|
@ -25,7 +25,7 @@
|
|||
bool is_perimeter();
|
||||
bool is_fill();
|
||||
bool is_bridge();
|
||||
std::string gcode(SV* extruder, double e, double F,
|
||||
std::string gcode(Extruder* extruder, double e, double F,
|
||||
double xofs, double yofs, std::string extrusion_axis,
|
||||
std::string gcode_line_suffix);
|
||||
%{
|
||||
|
|
|
@ -56,6 +56,17 @@ Point::coincides_with(point_sv)
|
|||
|
||||
};
|
||||
|
||||
%name{Slic3r::Pointf} class Pointf {
|
||||
Pointf(double _x = 0, double _y = 0);
|
||||
~Pointf();
|
||||
Clone<Pointf> clone()
|
||||
%code{% RETVAL = THIS; %};
|
||||
double x()
|
||||
%code{% RETVAL = THIS->x; %};
|
||||
double y()
|
||||
%code{% RETVAL = THIS->y; %};
|
||||
};
|
||||
|
||||
%name{Slic3r::Pointf3} class Pointf3 {
|
||||
Pointf3(double _x = 0, double _y = 0, double _z = 0);
|
||||
~Pointf3();
|
||||
|
|
|
@ -25,6 +25,10 @@ Point* O_OBJECT_SLIC3R
|
|||
Ref<Point> O_OBJECT_SLIC3R_T
|
||||
Clone<Point> O_OBJECT_SLIC3R_T
|
||||
|
||||
Pointf* O_OBJECT_SLIC3R
|
||||
Ref<Pointf> O_OBJECT_SLIC3R_T
|
||||
Clone<Pointf> O_OBJECT_SLIC3R_T
|
||||
|
||||
Pointf3* O_OBJECT_SLIC3R
|
||||
Ref<Pointf3> O_OBJECT_SLIC3R_T
|
||||
Clone<Pointf3> O_OBJECT_SLIC3R_T
|
||||
|
@ -77,6 +81,8 @@ Clone<Surface> O_OBJECT_SLIC3R_T
|
|||
|
||||
SurfaceCollection* O_OBJECT_SLIC3R
|
||||
|
||||
Extruder* O_OBJECT_SLIC3R
|
||||
|
||||
ExtrusionRole T_UV
|
||||
FlowRole T_UV
|
||||
PrintStep T_UV
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
%typemap{Point*};
|
||||
%typemap{Ref<Point>}{simple};
|
||||
%typemap{Clone<Point>}{simple};
|
||||
%typemap{Pointf*};
|
||||
%typemap{Ref<Pointf>}{simple};
|
||||
%typemap{Clone<Pointf>}{simple};
|
||||
%typemap{Pointf3*};
|
||||
%typemap{Ref<Pointf3>}{simple};
|
||||
%typemap{Clone<Pointf3>}{simple};
|
||||
|
@ -70,6 +73,7 @@
|
|||
%typemap{Surfaces};
|
||||
%typemap{Polygons*};
|
||||
%typemap{TriangleMeshPtrs};
|
||||
%typemap{Extruder*};
|
||||
|
||||
%typemap{SurfaceType}{parsed}{
|
||||
%cpp_type{SurfaceType};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue