Convert Extruder object (mostly) to C++ with lots of fields.
This commit is contained in:
parent
2738a304e8
commit
66d23a2416
@ -140,6 +140,7 @@ sub thread_cleanup {
|
||||
*Slic3r::Config::PrintRegion::DESTROY = sub {};
|
||||
*Slic3r::ExPolygon::DESTROY = sub {};
|
||||
*Slic3r::ExPolygon::Collection::DESTROY = sub {};
|
||||
*Slic3r::Extruder::DESTROY = sub {};
|
||||
*Slic3r::ExtrusionLoop::DESTROY = sub {};
|
||||
*Slic3r::ExtrusionPath::DESTROY = sub {};
|
||||
*Slic3r::ExtrusionPath::Collection::DESTROY = sub {};
|
||||
|
@ -1,5 +1,6 @@
|
||||
package Slic3r::Extruder;
|
||||
use Moo;
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
require Exporter;
|
||||
our @ISA = qw(Exporter);
|
||||
@ -16,16 +17,8 @@ use constant OPTIONS => [qw(
|
||||
retract_layer_change retract_length_toolchange retract_restart_extra_toolchange wipe
|
||||
)];
|
||||
|
||||
has 'id' => (is => 'rw', required => 1);
|
||||
has $_ => (is => 'ro', required => 1) for @{&OPTIONS};
|
||||
has 'use_relative_e_distances' => (is => 'ro', default => sub {0});
|
||||
|
||||
has 'E' => (is => 'rw', default => sub {0} );
|
||||
has 'absolute_E' => (is => 'rw', default => sub {0} );
|
||||
has 'retracted' => (is => 'rw', default => sub {0} );
|
||||
has 'restart_extra' => (is => 'rw', default => sub {0} );
|
||||
has 'e_per_mm3' => (is => 'lazy');
|
||||
has 'retract_speed_mm_min' => (is => 'lazy');
|
||||
# has 'e_per_mm3' => (is => 'lazy');
|
||||
# has 'retract_speed_mm_min' => (is => 'lazy');
|
||||
|
||||
use constant EXTRUDER_ROLE_PERIMETER => 1;
|
||||
use constant EXTRUDER_ROLE_INFILL => 2;
|
||||
@ -45,25 +38,16 @@ sub new_from_config {
|
||||
return $class->new(%conf);
|
||||
}
|
||||
|
||||
sub _build_e_per_mm3 {
|
||||
sub e_per_mm3 {
|
||||
my $self = shift;
|
||||
return $self->extrusion_multiplier * (4 / (($self->filament_diameter ** 2) * PI));
|
||||
}
|
||||
|
||||
sub _build_retract_speed_mm_min {
|
||||
sub retract_speed_mm_min {
|
||||
my $self = shift;
|
||||
return $self->retract_speed * 60;
|
||||
}
|
||||
|
||||
sub reset {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->E(0);
|
||||
$self->absolute_E(0);
|
||||
$self->retracted(0);
|
||||
$self->restart_extra(0);
|
||||
}
|
||||
|
||||
sub scaled_wipe_distance {
|
||||
my ($self, $travel_speed) = @_;
|
||||
|
||||
@ -74,14 +58,6 @@ sub scaled_wipe_distance {
|
||||
return scale($self->retract_length / $self->retract_speed * $travel_speed * 0.8);
|
||||
}
|
||||
|
||||
sub extrude {
|
||||
my ($self, $E) = @_;
|
||||
|
||||
$self->E(0) if $self->use_relative_e_distances;
|
||||
$self->absolute_E($self->absolute_E + $E);
|
||||
return $self->E($self->E + $E);
|
||||
}
|
||||
|
||||
sub extruded_volume {
|
||||
my ($self, $E) = @_;
|
||||
return $E * ($self->filament_diameter**2) * PI/4;
|
||||
|
@ -508,8 +508,8 @@ sub retract {
|
||||
$gcode .= $self->G1(@$lift);
|
||||
}
|
||||
}
|
||||
$self->extruder->retracted($self->extruder->retracted + $length);
|
||||
$self->extruder->restart_extra($restart_extra);
|
||||
$self->extruder->set_retracted($self->extruder->retracted + $length);
|
||||
$self->extruder->set_restart_extra($restart_extra);
|
||||
$self->lifted($self->_retract_lift) if $lift;
|
||||
|
||||
# reset extrusion distance during retracts
|
||||
@ -547,8 +547,8 @@ sub unretract {
|
||||
$gcode .= " ; compensate retraction" if $self->print_config->gcode_comments;
|
||||
$gcode .= "\n";
|
||||
}
|
||||
$self->extruder->retracted(0);
|
||||
$self->extruder->restart_extra(0);
|
||||
$self->extruder->set_retracted(0);
|
||||
$self->extruder->set_restart_extra(0);
|
||||
}
|
||||
|
||||
return $gcode;
|
||||
@ -558,7 +558,7 @@ sub reset_e {
|
||||
my ($self) = @_;
|
||||
return "" if $self->print_config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/;
|
||||
|
||||
$self->extruder->E(0) if $self->extruder;
|
||||
$self->extruder->set_E(0) if $self->extruder;
|
||||
return sprintf "G92 %s0%s\n", $self->_extrusion_axis, ($self->print_config->gcode_comments ? ' ; reset extrusion distance' : '')
|
||||
if $self->_extrusion_axis && !$self->print_config->use_relative_e_distances;
|
||||
}
|
||||
|
@ -221,4 +221,20 @@ use overload
|
||||
'@{}' => sub { $_[0]->arrayref },
|
||||
'fallback' => 1;
|
||||
|
||||
package Slic3r::Extruder;
|
||||
|
||||
sub new {
|
||||
my ($class, %args) = @_;
|
||||
|
||||
$args{extruder_offset} = Slic3r::Point->new($args{extruder_offset});
|
||||
|
||||
return $class->_new(@args{qw(
|
||||
id use_relative_e_distances
|
||||
extruder_offset
|
||||
nozzle_diameter filament_diameter extrusion_multiplier temperature
|
||||
first_layer_temperature retract_length retract_lift retract_speed
|
||||
retract_restart_extra retract_before_travel retract_layer_change
|
||||
retract_length_toolchange retract_restart_extra_toolchange wipe)});
|
||||
}
|
||||
|
||||
1;
|
||||
|
63
xs/src/Extruder.cpp
Normal file
63
xs/src/Extruder.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "Extruder.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
Extruder::Extruder(int id, bool use_relative_e_distances,
|
||||
const Point *extruder_offset,
|
||||
double nozzle_diameter,
|
||||
double filament_diameter,
|
||||
double extrusion_multiplier,
|
||||
int temperature,
|
||||
int first_layer_temperature,
|
||||
double retract_length,
|
||||
double retract_lift,
|
||||
int retract_speed,
|
||||
double retract_restart_extra,
|
||||
double retract_before_travel,
|
||||
bool retract_layer_change,
|
||||
double retract_length_toolchange,
|
||||
double retract_restart_extra_toolchange,
|
||||
double wipe)
|
||||
: id(id),
|
||||
use_relative_e_distances(use_relative_e_distances),
|
||||
extruder_offset(*extruder_offset),
|
||||
nozzle_diameter(nozzle_diameter),
|
||||
filament_diameter(filament_diameter),
|
||||
extrusion_multiplier(extrusion_multiplier),
|
||||
temperature(temperature),
|
||||
first_layer_temperature(first_layer_temperature),
|
||||
retract_length(retract_length),
|
||||
retract_lift(retract_lift),
|
||||
retract_speed(retract_speed),
|
||||
retract_restart_extra(retract_restart_extra),
|
||||
retract_before_travel(retract_before_travel),
|
||||
retract_layer_change(retract_layer_change),
|
||||
retract_length_toolchange(retract_length_toolchange),
|
||||
retract_restart_extra_toolchange(retract_restart_extra_toolchange),
|
||||
wipe(wipe)
|
||||
{
|
||||
reset();
|
||||
}
|
||||
|
||||
void
|
||||
Extruder::reset()
|
||||
{
|
||||
this->E = 0;
|
||||
this->absolute_E = 0;
|
||||
this->retracted = 0;
|
||||
this->restart_extra = 0;
|
||||
}
|
||||
|
||||
double
|
||||
Extruder::extrude(double dE)
|
||||
{
|
||||
if (use_relative_e_distances) {
|
||||
this->E = 0;
|
||||
}
|
||||
|
||||
this->E += dE;
|
||||
this->absolute_E += dE;
|
||||
return this->E;
|
||||
}
|
||||
|
||||
}
|
59
xs/src/Extruder.hpp
Normal file
59
xs/src/Extruder.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef slic3r_Extruder_hpp_
|
||||
#define slic3r_Extruder_hpp_
|
||||
|
||||
#include <myinit.h>
|
||||
#include "Point.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
class Extruder
|
||||
{
|
||||
public:
|
||||
Extruder(int id, bool use_relative_e_distances,
|
||||
const Point *extruder_offset,
|
||||
double nozzle_diameter,
|
||||
double filament_diameter,
|
||||
double extrusion_multiplier,
|
||||
int temperature,
|
||||
int first_layer_temperature,
|
||||
double retract_length,
|
||||
double retract_lift,
|
||||
int retract_speed,
|
||||
double retract_restart_extra,
|
||||
double retract_before_travel,
|
||||
bool retract_layer_change,
|
||||
double retract_length_toolchange,
|
||||
double retract_restart_extra_toolchange,
|
||||
double wipe);
|
||||
virtual ~Extruder() {}
|
||||
void reset();
|
||||
double extrude(double dE);
|
||||
|
||||
int id;
|
||||
bool use_relative_e_distances;
|
||||
double E;
|
||||
double absolute_E;
|
||||
double retracted;
|
||||
double restart_extra;
|
||||
|
||||
// options:
|
||||
Point extruder_offset;
|
||||
double nozzle_diameter;
|
||||
double filament_diameter;
|
||||
double extrusion_multiplier;
|
||||
int temperature;
|
||||
int first_layer_temperature;
|
||||
double retract_length;
|
||||
double retract_lift;
|
||||
int retract_speed;
|
||||
double retract_restart_extra;
|
||||
double retract_before_travel;
|
||||
bool retract_layer_change;
|
||||
double retract_length_toolchange;
|
||||
double retract_restart_extra_toolchange;
|
||||
double wipe;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
84
xs/xsp/Extruder.xsp
Normal file
84
xs/xsp/Extruder.xsp
Normal file
@ -0,0 +1,84 @@
|
||||
%module{Slic3r::XS};
|
||||
|
||||
%{
|
||||
#include <myinit.h>
|
||||
#include "Extruder.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::Extruder} class Extruder {
|
||||
%name{_new} Extruder(int id, bool use_relative_e_distances,
|
||||
Point *extruder_offset,
|
||||
double nozzle_diameter,
|
||||
double filament_diameter,
|
||||
double extrusion_multiplier,
|
||||
int temperature,
|
||||
int first_layer_temperature,
|
||||
double retract_length,
|
||||
double retract_lift,
|
||||
int retract_speed,
|
||||
double retract_restart_extra,
|
||||
double retract_before_travel,
|
||||
bool retract_layer_change,
|
||||
double retract_length_toolchange,
|
||||
double retract_restart_extra_toolchange,
|
||||
double wipe);
|
||||
|
||||
~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; %};
|
||||
|
||||
Point *extruder_offset() const
|
||||
%code%{
|
||||
const char *CLASS = "Slic3r::Point";
|
||||
RETVAL = new Point(THIS->extruder_offset);
|
||||
%};
|
||||
|
||||
double nozzle_diameter() const
|
||||
%code%{ RETVAL = THIS->nozzle_diameter; %};
|
||||
double filament_diameter() const
|
||||
%code%{ RETVAL = THIS->filament_diameter; %};
|
||||
double extrusion_multiplier() const
|
||||
%code%{ RETVAL = THIS->extrusion_multiplier; %};
|
||||
int temperature() const
|
||||
%code%{ RETVAL = THIS->temperature; %};
|
||||
int first_layer_temperature() const
|
||||
%code%{ RETVAL = THIS->first_layer_temperature; %};
|
||||
double retract_length() const
|
||||
%code%{ RETVAL = THIS->retract_length; %};
|
||||
double retract_lift() const
|
||||
%code%{ RETVAL = THIS->retract_lift; %};
|
||||
int retract_speed() const
|
||||
%code%{ RETVAL = THIS->retract_speed; %};
|
||||
double retract_restart_extra() const
|
||||
%code%{ RETVAL = THIS->retract_restart_extra; %};
|
||||
double retract_before_travel() const
|
||||
%code%{ RETVAL = THIS->retract_before_travel; %};
|
||||
bool retract_layer_change() const
|
||||
%code%{ RETVAL = THIS->retract_layer_change; %};
|
||||
double retract_length_toolchange() const
|
||||
%code%{ RETVAL = THIS->retract_length_toolchange; %};
|
||||
double retract_restart_extra_toolchange() const
|
||||
%code%{ RETVAL = THIS->retract_restart_extra_toolchange; %};
|
||||
double wipe() const
|
||||
%code%{ RETVAL = THIS->wipe; %};
|
||||
};
|
@ -77,6 +77,8 @@ Clone<Surface> O_OBJECT_SLIC3R_T
|
||||
|
||||
SurfaceCollection* O_OBJECT_SLIC3R
|
||||
|
||||
Extruder* O_OBJECT_SLIC3R
|
||||
|
||||
ExtrusionRole T_UV
|
||||
FlowRole T_UV
|
||||
PrintStep T_UV
|
||||
|
@ -70,6 +70,7 @@
|
||||
%typemap{Surfaces};
|
||||
%typemap{Polygons*};
|
||||
%typemap{TriangleMeshPtrs};
|
||||
%typemap{Extruder*};
|
||||
|
||||
%typemap{SurfaceType}{parsed}{
|
||||
%cpp_type{SurfaceType};
|
||||
|
Loading…
Reference in New Issue
Block a user