3
# Copyright holder: Alessandro Ranellucci
4
# This application is licensed under the GNU Affero General Public License, version 3
10
our $VERSION = "1.1.4";
17
# load threads before Moo as required by it
21
$have_threads = $Config{useithreads} && eval "use threads; use threads::shared; use Thread::Queue; 1";
23
### temporarily disable threads if using the broken Moo version
25
$have_threads = 0 if $Moo::VERSION == 1.003000;
28
warn "Running Slic3r under Perl >= 5.16 is not supported nor recommended\n"
32
our $var = "$FindBin::Bin/var";
38
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
40
use Slic3r::ExPolygon;
42
use Slic3r::ExtrusionLoop;
43
use Slic3r::ExtrusionPath;
44
use Slic3r::ExtrusionPath::Collection;
47
use Slic3r::Format::AMF;
48
use Slic3r::Format::OBJ;
49
use Slic3r::Format::STL;
51
use Slic3r::GCode::ArcFitting;
52
use Slic3r::GCode::CoolingBuffer;
53
use Slic3r::GCode::Layer;
54
use Slic3r::GCode::MotionPlanner;
55
use Slic3r::GCode::PlaceholderParser;
56
use Slic3r::GCode::Reader;
57
use Slic3r::GCode::SpiralVase;
58
use Slic3r::GCode::VibrationLimit;
59
use Slic3r::Geometry qw(PI);
60
use Slic3r::Geometry::Clipper;
62
use Slic3r::Layer::BridgeDetector;
63
use Slic3r::Layer::Region;
70
use Slic3r::Print::Object;
71
use Slic3r::Print::Region;
72
use Slic3r::Print::Simple;
73
use Slic3r::Print::SupportMaterial;
75
use Slic3r::TriangleMesh;
76
our $build = eval "use Slic3r::Build; 1";
78
use constant SCALING_FACTOR => 0.000001;
79
use constant RESOLUTION => 0.0125;
80
use constant SCALED_RESOLUTION => RESOLUTION / SCALING_FACTOR;
81
use constant SMALL_PERIMETER_LENGTH => (6.5 / SCALING_FACTOR) * 2 * PI;
82
use constant LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER => 0.15;
83
use constant INFILL_OVERLAP_OVER_SPACING => 0.45;
84
use constant EXTERNAL_INFILL_MARGIN => 3;
85
use constant INSET_OVERLAP_TOLERANCE => 0.2;
90
if (!$params{disable} && $Slic3r::have_threads && $params{threads} > 1) {
91
my @items = (ref $params{items} eq 'CODE') ? $params{items}->() : @{$params{items}};
92
my $q = Thread::Queue->new;
93
$q->enqueue(@items, (map undef, 1..$params{threads}));
96
$params{thread_cb}->($q);
97
Slic3r::thread_cleanup();
99
# This explicit exit avoids an untrappable
100
# "Attempt to free unreferenced scalar" error
101
# triggered on Ubuntu 12.04 32-bit when we're running
102
# from the Wx plater and
103
# we're reusing the same plater object more than once.
104
# The downside to using this exit is that we can't return
105
# any value to the main thread but we're not doing that
107
# collect_cb is completely useless now
108
# and should be removed from the codebase.
111
$params{collect_cb} ||= sub {};
114
foreach my $th (map threads->create($thread_cb), 1..$params{threads}) {
115
$params{collect_cb}->($th->join);
118
$params{no_threads_cb}->();
122
# call this at the very end of each thread (except the main one)
123
# so that it does not try to free existing objects.
124
# at that stage, existing objects are only those that we
125
# inherited at the thread creation (thus shared) and those
126
# that we are returning: destruction will be handled by the
127
# main thread in both cases.
128
# reminder: do not destroy inherited objects in other threads,
129
# as the main thread will still try to destroy them when they
130
# go out of scope; in other words, if you're undef()'ing an
131
# object in a thread, make sure the main thread still holds a
132
# reference so that it won't be destroyed in thread.
134
# prevent destruction of shared objects
135
no warnings 'redefine';
136
*Slic3r::Config::DESTROY = sub {};
137
*Slic3r::Config::Full::DESTROY = sub {};
138
*Slic3r::Config::Print::DESTROY = sub {};
139
*Slic3r::Config::PrintObject::DESTROY = sub {};
140
*Slic3r::Config::PrintRegion::DESTROY = sub {};
141
*Slic3r::ExPolygon::DESTROY = sub {};
142
*Slic3r::ExPolygon::Collection::DESTROY = sub {};
143
*Slic3r::Extruder::DESTROY = sub {};
144
*Slic3r::ExtrusionLoop::DESTROY = sub {};
145
*Slic3r::ExtrusionPath::DESTROY = sub {};
146
*Slic3r::ExtrusionPath::Collection::DESTROY = sub {};
147
*Slic3r::Flow::DESTROY = sub {};
148
*Slic3r::Geometry::BoundingBox::DESTROY = sub {};
149
*Slic3r::Geometry::BoundingBoxf3::DESTROY = sub {};
150
*Slic3r::Line::DESTROY = sub {};
151
*Slic3r::Model::DESTROY = sub {};
152
*Slic3r::Model::Object::DESTROY = sub {};
153
*Slic3r::Point::DESTROY = sub {};
154
*Slic3r::Pointf::DESTROY = sub {};
155
*Slic3r::Pointf3::DESTROY = sub {};
156
*Slic3r::Polygon::DESTROY = sub {};
157
*Slic3r::Polyline::DESTROY = sub {};
158
*Slic3r::Polyline::Collection::DESTROY = sub {};
159
*Slic3r::Print::State::DESTROY = sub {};
160
*Slic3r::Surface::DESTROY = sub {};
161
*Slic3r::Surface::Collection::DESTROY = sub {};
162
*Slic3r::TriangleMesh::DESTROY = sub {};
163
return undef; # this prevents a "Scalars leaked" warning
168
return encode('locale_fs', $filename);
172
my ($fh, $mode, $filename) = @_;
173
return CORE::open $$fh, $mode, encode_path($filename);
176
# this package declaration prevents an ugly fatal warning to be emitted when
177
# spawning a new thread
178
package GLUquadricObjPtr;