diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index c3abbc3e03..f94f3408d3 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -143,6 +143,7 @@ sub thread_cleanup { *Slic3r::Polygon::DESTROY = sub {}; *Slic3r::Polyline::DESTROY = sub {}; *Slic3r::Polyline::Collection::DESTROY = sub {}; + *Slic3r::Print::State::DESTROY = sub {}; *Slic3r::Surface::DESTROY = sub {}; *Slic3r::Surface::Collection::DESTROY = sub {}; *Slic3r::TriangleMesh::DESTROY = sub {}; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 5b1aed7b07..6b88250b43 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -350,10 +350,10 @@ sub process { my ($step, $cb) = @_; for my $obj_idx (0..$#{$self->objects}) { my $object = $self->objects->[$obj_idx]; - if (!$object->_state->done($step, $obj_idx)) { - $object->_state->set_started($step, $obj_idx); + if (!$object->_state->done($step)) { + $object->_state->set_started($step); $cb->($obj_idx); - $object->_state->set_done($step, $obj_idx); + $object->_state->set_done($step); } } }; diff --git a/lib/Slic3r/Print/State.pm b/lib/Slic3r/Print/State.pm index 3da121f2cb..bd76e3805b 100644 --- a/lib/Slic3r/Print/State.pm +++ b/lib/Slic3r/Print/State.pm @@ -1,5 +1,6 @@ package Slic3r::Print::State; -use Moo; +use strict; +use warnings; require Exporter; our @ISA = qw(Exporter); @@ -7,18 +8,6 @@ our @EXPORT_OK = qw(STEP_INIT_EXTRUDERS STEP_SLICE STEP_PERIMETERS STEP_PREPAR STEP_INFILL STEP_SUPPORTMATERIAL STEP_SKIRT STEP_BRIM); our %EXPORT_TAGS = (steps => \@EXPORT_OK); -has '_started' => (is => 'ro', default => sub {{}}); # { step => 1, ... } -has '_done' => (is => 'ro', default => sub {{}}); # { step => 1, ... } - -use constant STEP_INIT_EXTRUDERS => 0; -use constant STEP_SLICE => 1; -use constant STEP_PERIMETERS => 2; -use constant STEP_PREPARE_INFILL => 3; -use constant STEP_INFILL => 4; -use constant STEP_SUPPORTMATERIAL => 5; -use constant STEP_SKIRT => 6; -use constant STEP_BRIM => 7; - our %print_steps = map { $_ => 1 } ( STEP_INIT_EXTRUDERS, STEP_SKIRT, @@ -36,33 +25,4 @@ our %prereqs = ( STEP_BRIM => [STEP_PERIMETERS, STEP_INFILL, STEP_SKIRT], ); -sub started { - my ($self, $step) = @_; - return $self->_started->{$step}; -} - -sub done { - my ($self, $step) = @_; - return $self->_done->{$step}; -} - -sub set_started { - my ($self, $step) = @_; - - $self->_started->{$step} = 1; - delete $self->_done->{$step}; -} - -sub set_done { - my ($self, $step) = @_; - $self->_done->{$step} = 1; -} - -sub invalidate { - my ($self, $step) = @_; - - delete $self->_started->{$step}; - delete $self->_done->{$step}; -} - 1; diff --git a/xs/MANIFEST b/xs/MANIFEST index 5256bba423..903b39deb9 100644 --- a/xs/MANIFEST +++ b/xs/MANIFEST @@ -35,6 +35,8 @@ src/Polyline.cpp src/Polyline.hpp src/PolylineCollection.cpp src/PolylineCollection.hpp +src/PrintState.cpp +src/PrintState.hpp src/ppport.h src/Surface.cpp src/Surface.hpp @@ -72,6 +74,7 @@ xsp/Point.xsp xsp/Polygon.xsp xsp/Polyline.xsp xsp/PolylineCollection.xsp +xsp/PrintState.xsp xsp/Surface.xsp xsp/SurfaceCollection.xsp xsp/TriangleMesh.xsp diff --git a/xs/src/Print.cpp b/xs/src/Print.cpp new file mode 100644 index 0000000000..f5dd9fe7d9 --- /dev/null +++ b/xs/src/Print.cpp @@ -0,0 +1,36 @@ +#include "Print.hpp" + +namespace Slic3r { + +bool +PrintState::started(PrintStep step) const +{ + return this->_started.find(step) != this->_started.end(); +} + +bool +PrintState::done(PrintStep step) const +{ + return this->_done.find(step) != this->_done.end(); +} + +void +PrintState::set_started(PrintStep step) +{ + this->_started.insert(step); +} + +void +PrintState::set_done(PrintStep step) +{ + this->_done.insert(step); +} + +void +PrintState::invalidate(PrintStep step) +{ + this->_started.erase(step); + this->_done.erase(step); +} + +} diff --git a/xs/src/Print.hpp b/xs/src/Print.hpp new file mode 100644 index 0000000000..a79d544dfc --- /dev/null +++ b/xs/src/Print.hpp @@ -0,0 +1,29 @@ +#ifndef slic3r_Print_hpp_ +#define slic3r_Print_hpp_ + +#include + +namespace Slic3r { + +enum PrintStep { + psInitExtruders, psSlice, psPerimeters, prPrepareInfill, + psInfill, psSupportMaterial, psSkirt, psBrim, +}; + +class PrintState +{ + private: + std::set _started; + std::set _done; + + public: + bool started(PrintStep step) const; + bool done(PrintStep step) const; + void set_started(PrintStep step); + void set_done(PrintStep step); + void invalidate(PrintStep step); +}; + +} + +#endif diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp new file mode 100644 index 0000000000..0eef527eae --- /dev/null +++ b/xs/xsp/Print.xsp @@ -0,0 +1,41 @@ +%module{Slic3r::XS}; + +%{ +#include +#include "Print.hpp" +%} + +%name{Slic3r::Print::State} class PrintState { + PrintState(); + ~PrintState(); + bool started(PrintStep step) const; + bool done(PrintStep step) const; + void set_started(PrintStep step); + void set_done(PrintStep step); + void invalidate(PrintStep step); +%{ + +%} +}; + +%package{Slic3r::Print::State}; +%{ + +IV +_constant() + ALIAS: + STEP_INIT_EXTRUDERS = psInitExtruders + STEP_SLICE = psSlice + STEP_PERIMETERS = psPerimeters + STEP_PREPARE_INFILL = prPrepareInfill + STEP_INFILL = psInfill + STEP_SUPPORTMATERIAL = psSupportMaterial + STEP_SKIRT = psSkirt + STEP_BRIM = psBrim + PROTOTYPE: + CODE: + RETVAL = ix; + OUTPUT: RETVAL + +%} + diff --git a/xs/xsp/my.map b/xs/xsp/my.map index dcd0293f87..415b9a58c9 100644 --- a/xs/xsp/my.map +++ b/xs/xsp/my.map @@ -12,10 +12,12 @@ ExPolygonCollection* O_OBJECT ExtrusionEntityCollection* O_OBJECT ExtrusionPath* O_OBJECT ExtrusionLoop* O_OBJECT +PrintState* O_OBJECT Surface* O_OBJECT SurfaceCollection* O_OBJECT ExtrusionRole T_UV +PrintStep T_UV SurfaceType T_UV ClipperLib::JoinType T_UV ClipperLib::PolyFillType T_UV diff --git a/xs/xsp/typemap.xspt b/xs/xsp/typemap.xspt index 559dba8438..6457717e3a 100644 --- a/xs/xsp/typemap.xspt +++ b/xs/xsp/typemap.xspt @@ -18,6 +18,7 @@ %typemap{Lines}; %typemap{Polygons}; %typemap{Polylines}; +%typemap{PrintState}; %typemap{ExPolygons}; %typemap{Surfaces}; %typemap{Polygons*}; @@ -35,3 +36,9 @@ $CVar = (ExtrusionRole)SvUV($PerlVar); %}; }; +%typemap{PrintStep}{parsed}{ + %cpp_type{PrintStep}; + %precall_code{% + $CVar = (PrintStep)SvUV($PerlVar); + %}; +};