2016-09-13 11:24:55 +02:00
|
|
|
# This package loads all the non-GUI Slic3r perl packages.
|
|
|
|
# In addition, it implements utility functions for file handling and threading.
|
|
|
|
|
2011-09-01 21:06:28 +02:00
|
|
|
package Slic3r;
|
|
|
|
|
2012-01-18 20:04:18 +01:00
|
|
|
# Copyright holder: Alessandro Ranellucci
|
|
|
|
# This application is licensed under the GNU Affero General Public License, version 3
|
|
|
|
|
2011-09-01 21:06:28 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2017-02-19 16:04:57 +01:00
|
|
|
use Config;
|
2012-01-22 13:56:15 +01:00
|
|
|
require v5.10;
|
2011-09-01 21:06:28 +02:00
|
|
|
|
2014-11-09 20:41:27 +01:00
|
|
|
our $VERSION = VERSION();
|
2017-02-19 16:04:57 +01:00
|
|
|
our $BUILD = BUILD();
|
2016-10-21 16:53:42 +02:00
|
|
|
our $FORK_NAME = FORK_NAME();
|
2011-11-13 22:57:58 +01:00
|
|
|
|
2011-09-05 13:33:09 +02:00
|
|
|
our $debug = 0;
|
|
|
|
sub debugf {
|
|
|
|
printf @_ if $debug;
|
|
|
|
}
|
|
|
|
|
2016-11-24 13:44:51 +01:00
|
|
|
our $loglevel = 0;
|
|
|
|
|
2012-05-19 20:25:59 +02:00
|
|
|
# load threads before Moo as required by it
|
2012-05-21 18:44:31 +02:00
|
|
|
BEGIN {
|
2016-09-14 11:22:41 +02:00
|
|
|
# Test, whether the perl was compiled with ithreads support and ithreads actually work.
|
2012-05-21 18:44:31 +02:00
|
|
|
use Config;
|
2013-07-24 10:06:02 +02:00
|
|
|
use Moo;
|
2017-11-02 16:21:34 +01:00
|
|
|
my $have_threads = $Config{useithreads} && eval "use threads; use threads::shared; use Thread::Queue; 1";
|
|
|
|
die "Slic3r Prusa Edition requires working Perl threads.\n" if ! $have_threads;
|
|
|
|
die "threads.pm >= 1.96 is required, please update\n" if $threads::VERSION < 1.96;
|
|
|
|
die "Perl threading is broken with this Moo version: " . $Moo::VERSION . "\n" if $Moo::VERSION == 1.003000;
|
2016-09-26 12:57:15 +02:00
|
|
|
$debug = 1 if (defined($ENV{'SLIC3R_DEBUGOUT'}) && $ENV{'SLIC3R_DEBUGOUT'} == 1);
|
|
|
|
print "Debugging output enabled\n" if $debug;
|
2012-05-21 18:44:31 +02:00
|
|
|
}
|
2012-05-19 20:25:59 +02:00
|
|
|
|
2016-09-13 11:24:55 +02:00
|
|
|
warn "Running Slic3r under Perl 5.16 is neither supported nor recommended\n"
|
2014-12-24 00:19:20 +01:00
|
|
|
if $^V == v5.16;
|
2012-09-11 16:02:26 +02:00
|
|
|
|
2012-05-29 14:19:14 +02:00
|
|
|
use FindBin;
|
2017-10-25 12:53:31 +02:00
|
|
|
|
|
|
|
# Let the XS module know where the GUI resources reside.
|
2017-12-10 23:27:22 +01:00
|
|
|
set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/../Resources' : '/resources'));
|
2017-12-10 21:14:03 +01:00
|
|
|
set_var_dir(resources_dir() . "/icons");
|
2018-02-12 08:57:32 +01:00
|
|
|
set_local_dir(resources_dir() . "/localization/");
|
2012-05-29 14:19:14 +02:00
|
|
|
|
2013-09-12 11:09:03 +02:00
|
|
|
use Moo 1.003001;
|
2013-01-13 10:18:34 +01:00
|
|
|
|
2013-07-14 13:05:55 +02:00
|
|
|
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
|
2011-10-03 11:55:32 +02:00
|
|
|
use Slic3r::Config;
|
2011-10-15 11:36:05 +02:00
|
|
|
use Slic3r::ExPolygon;
|
2011-09-25 23:15:45 +02:00
|
|
|
use Slic3r::ExtrusionLoop;
|
2011-09-04 12:04:01 +02:00
|
|
|
use Slic3r::ExtrusionPath;
|
2012-06-06 18:05:03 +02:00
|
|
|
use Slic3r::Flow;
|
2013-05-13 20:14:33 +02:00
|
|
|
use Slic3r::GCode::Reader;
|
2013-06-07 23:16:02 +02:00
|
|
|
use Slic3r::Geometry::Clipper;
|
2011-09-01 21:06:28 +02:00
|
|
|
use Slic3r::Layer;
|
|
|
|
use Slic3r::Line;
|
2012-08-29 16:49:38 +02:00
|
|
|
use Slic3r::Model;
|
2011-09-01 21:06:28 +02:00
|
|
|
use Slic3r::Point;
|
2011-10-15 11:36:05 +02:00
|
|
|
use Slic3r::Polygon;
|
2011-09-01 21:06:28 +02:00
|
|
|
use Slic3r::Polyline;
|
|
|
|
use Slic3r::Print;
|
2012-04-29 12:51:20 +02:00
|
|
|
use Slic3r::Print::Object;
|
2017-06-14 12:05:23 +02:00
|
|
|
use Slic3r::Print::Simple;
|
2011-09-01 21:06:28 +02:00
|
|
|
use Slic3r::Surface;
|
2013-04-27 20:55:43 +02:00
|
|
|
our $build = eval "use Slic3r::Build; 1";
|
2014-07-12 11:41:18 +02:00
|
|
|
use Thread::Semaphore;
|
2011-09-01 21:06:28 +02:00
|
|
|
|
2016-09-13 11:24:55 +02:00
|
|
|
# Scaling between the float and integer coordinates.
|
|
|
|
# Floats are in mm.
|
2012-07-27 21:13:03 +02:00
|
|
|
use constant SCALING_FACTOR => 0.000001;
|
|
|
|
|
2017-06-08 18:53:33 +02:00
|
|
|
# Keep track of threads we created. Perl worker threads shall not create further threads.
|
|
|
|
my @threads = ();
|
2014-12-13 15:01:53 +01:00
|
|
|
my $pause_sema = Thread::Semaphore->new;
|
2014-07-12 11:41:18 +02:00
|
|
|
my $paused = 0;
|
2014-07-01 19:00:23 +02:00
|
|
|
|
2016-11-24 13:44:51 +01:00
|
|
|
# Set the logging level at the Slic3r XS module.
|
|
|
|
$Slic3r::loglevel = (defined($ENV{'SLIC3R_LOGLEVEL'}) && $ENV{'SLIC3R_LOGLEVEL'} =~ /^[1-9]/) ? $ENV{'SLIC3R_LOGLEVEL'} : 0;
|
|
|
|
set_logging_level($Slic3r::loglevel);
|
|
|
|
|
2017-12-18 12:14:09 +01:00
|
|
|
# Let the palceholder parser evaluate one expression to initialize its local static macro_processor
|
|
|
|
# class instance in a thread safe manner.
|
|
|
|
Slic3r::GCode::PlaceholderParser->new->evaluate_boolean_expression('1==1');
|
|
|
|
|
2014-07-01 19:00:23 +02:00
|
|
|
sub spawn_thread {
|
|
|
|
my ($cb) = @_;
|
2014-07-12 11:41:18 +02:00
|
|
|
@_ = ();
|
|
|
|
my $thread = threads->create(sub {
|
2017-06-08 18:53:33 +02:00
|
|
|
Slic3r::debugf "Starting thread %d...\n", threads->tid;
|
2014-07-12 11:41:18 +02:00
|
|
|
local $SIG{'KILL'} = sub {
|
2014-12-23 00:39:22 +01:00
|
|
|
Slic3r::debugf "Exiting thread %d...\n", threads->tid;
|
2014-07-12 11:41:18 +02:00
|
|
|
Slic3r::thread_cleanup();
|
|
|
|
threads->exit();
|
|
|
|
};
|
|
|
|
local $SIG{'STOP'} = sub {
|
2014-12-13 15:01:53 +01:00
|
|
|
$pause_sema->down;
|
|
|
|
$pause_sema->up;
|
2014-07-12 11:41:18 +02:00
|
|
|
};
|
|
|
|
$cb->();
|
|
|
|
});
|
2014-07-01 19:00:23 +02:00
|
|
|
push @threads, $thread->tid;
|
|
|
|
return $thread;
|
|
|
|
}
|
2014-06-13 19:23:51 +02:00
|
|
|
|
2013-07-11 16:17:36 +02:00
|
|
|
# call this at the very end of each thread (except the main one)
|
|
|
|
# so that it does not try to free existing objects.
|
|
|
|
# at that stage, existing objects are only those that we
|
|
|
|
# inherited at the thread creation (thus shared) and those
|
|
|
|
# that we are returning: destruction will be handled by the
|
|
|
|
# main thread in both cases.
|
2013-09-17 23:14:49 +02:00
|
|
|
# reminder: do not destroy inherited objects in other threads,
|
|
|
|
# as the main thread will still try to destroy them when they
|
|
|
|
# go out of scope; in other words, if you're undef()'ing an
|
|
|
|
# object in a thread, make sure the main thread still holds a
|
|
|
|
# reference so that it won't be destroyed in thread.
|
2013-07-11 16:17:36 +02:00
|
|
|
sub thread_cleanup {
|
|
|
|
# prevent destruction of shared objects
|
|
|
|
no warnings 'redefine';
|
2014-11-15 22:41:22 +01:00
|
|
|
*Slic3r::BridgeDetector::DESTROY = sub {};
|
2013-12-22 00:39:03 +01:00
|
|
|
*Slic3r::Config::DESTROY = sub {};
|
2014-01-02 10:44:54 +01:00
|
|
|
*Slic3r::Config::Full::DESTROY = sub {};
|
2014-11-09 19:24:17 +01:00
|
|
|
*Slic3r::Config::GCode::DESTROY = sub {};
|
2013-12-22 00:39:03 +01:00
|
|
|
*Slic3r::Config::Print::DESTROY = sub {};
|
2014-01-02 10:44:54 +01:00
|
|
|
*Slic3r::Config::PrintObject::DESTROY = sub {};
|
|
|
|
*Slic3r::Config::PrintRegion::DESTROY = sub {};
|
2015-12-16 12:33:19 +01:00
|
|
|
*Slic3r::Config::Static::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::ExPolygon::DESTROY = sub {};
|
2013-07-14 00:38:01 +02:00
|
|
|
*Slic3r::ExPolygon::Collection::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::ExtrusionLoop::DESTROY = sub {};
|
2017-01-19 13:35:55 +01:00
|
|
|
*Slic3r::ExtrusionMultiPath::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::ExtrusionPath::DESTROY = sub {};
|
2013-07-18 22:29:12 +02:00
|
|
|
*Slic3r::ExtrusionPath::Collection::DESTROY = sub {};
|
2016-04-11 17:05:58 +02:00
|
|
|
*Slic3r::ExtrusionSimulator::DESTROY = sub {};
|
2014-01-14 20:11:08 +01:00
|
|
|
*Slic3r::Flow::DESTROY = sub {};
|
2015-07-01 21:47:17 +02:00
|
|
|
*Slic3r::GCode::DESTROY = sub {};
|
2014-05-06 11:07:18 +03:00
|
|
|
*Slic3r::GCode::PlaceholderParser::DESTROY = sub {};
|
2018-02-14 20:35:59 +01:00
|
|
|
*Slic3r::GCode::PreviewData::DESTROY = sub {};
|
2015-01-03 23:25:55 +01:00
|
|
|
*Slic3r::GCode::Sender::DESTROY = sub {};
|
2014-01-14 20:11:08 +01:00
|
|
|
*Slic3r::Geometry::BoundingBox::DESTROY = sub {};
|
2014-09-21 10:51:36 +02:00
|
|
|
*Slic3r::Geometry::BoundingBoxf::DESTROY = sub {};
|
2014-01-14 20:11:08 +01:00
|
|
|
*Slic3r::Geometry::BoundingBoxf3::DESTROY = sub {};
|
2015-07-23 15:53:02 +02:00
|
|
|
*Slic3r::Layer::PerimeterGenerator::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::Line::DESTROY = sub {};
|
2014-12-16 01:12:37 +01:00
|
|
|
*Slic3r::Linef3::DESTROY = sub {};
|
2014-04-30 02:04:49 +03:00
|
|
|
*Slic3r::Model::DESTROY = sub {};
|
|
|
|
*Slic3r::Model::Object::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::Point::DESTROY = sub {};
|
2014-04-28 22:02:34 +02:00
|
|
|
*Slic3r::Pointf::DESTROY = sub {};
|
2014-01-14 20:11:08 +01:00
|
|
|
*Slic3r::Pointf3::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::Polygon::DESTROY = sub {};
|
|
|
|
*Slic3r::Polyline::DESTROY = sub {};
|
2013-09-12 11:09:03 +02:00
|
|
|
*Slic3r::Polyline::Collection::DESTROY = sub {};
|
2014-05-06 11:07:18 +03:00
|
|
|
*Slic3r::Print::DESTROY = sub {};
|
2015-01-24 23:35:29 +01:00
|
|
|
*Slic3r::Print::Object::DESTROY = sub {};
|
2014-05-06 11:07:18 +03:00
|
|
|
*Slic3r::Print::Region::DESTROY = sub {};
|
2013-07-16 09:49:34 +02:00
|
|
|
*Slic3r::Surface::DESTROY = sub {};
|
|
|
|
*Slic3r::Surface::Collection::DESTROY = sub {};
|
2016-10-16 16:30:56 +02:00
|
|
|
*Slic3r::Print::SupportMaterial2::DESTROY = sub {};
|
2013-09-12 11:09:03 +02:00
|
|
|
*Slic3r::TriangleMesh::DESTROY = sub {};
|
2017-11-02 16:21:34 +01:00
|
|
|
*Slic3r::GUI::AppConfig::DESTROY = sub {};
|
2018-04-17 10:55:18 +02:00
|
|
|
*Slic3r::GUI::GCodePreviewData::DESTROY = sub {};
|
2017-10-02 17:35:00 +02:00
|
|
|
*Slic3r::GUI::PresetBundle::DESTROY = sub {};
|
2018-04-18 18:57:34 +02:00
|
|
|
*Slic3r::GUI::Tab::DESTROY = sub {};
|
2018-04-17 10:55:18 +02:00
|
|
|
*Slic3r::GUI::PresetHints::DESTROY = sub {};
|
|
|
|
*Slic3r::GUI::TabIface::DESTROY = sub {};
|
2018-04-27 12:04:43 +02:00
|
|
|
*Slic3r::OctoPrint::DESTROY = sub {};
|
2018-04-20 11:06:12 +02:00
|
|
|
*Slic3r::PresetUpdater::DESTROY = sub {};
|
2013-09-19 16:00:47 +02:00
|
|
|
return undef; # this prevents a "Scalars leaked" warning
|
2013-07-11 16:17:36 +02:00
|
|
|
}
|
|
|
|
|
2017-06-08 18:53:33 +02:00
|
|
|
sub _get_running_threads {
|
|
|
|
return grep defined($_), map threads->object($_), @threads;
|
2014-07-12 11:41:18 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 19:00:23 +02:00
|
|
|
sub kill_all_threads {
|
2017-06-08 18:53:33 +02:00
|
|
|
# Send SIGKILL to all the running threads to let them die.
|
|
|
|
foreach my $thread (_get_running_threads) {
|
|
|
|
Slic3r::debugf "Thread %d killing %d...\n", threads->tid, $thread->tid;
|
|
|
|
$thread->kill('KILL');
|
2014-07-01 19:00:23 +02:00
|
|
|
}
|
2017-06-08 18:53:33 +02:00
|
|
|
# unlock semaphore before we block on wait
|
|
|
|
# otherwise we'd get a deadlock if threads were paused
|
|
|
|
resume_all_threads();
|
2014-12-13 15:01:53 +01:00
|
|
|
# in any thread we wait for our children
|
2017-06-08 18:53:33 +02:00
|
|
|
foreach my $thread (_get_running_threads) {
|
2014-12-23 00:39:22 +01:00
|
|
|
Slic3r::debugf " Thread %d waiting for %d...\n", threads->tid, $thread->tid;
|
2014-12-13 00:01:24 +01:00
|
|
|
$thread->join; # block until threads are killed
|
2014-12-23 00:39:22 +01:00
|
|
|
Slic3r::debugf " Thread %d finished waiting for %d...\n", threads->tid, $thread->tid;
|
2014-12-13 00:01:24 +01:00
|
|
|
}
|
2017-06-08 18:53:33 +02:00
|
|
|
@threads = ();
|
2014-07-01 19:00:23 +02:00
|
|
|
}
|
|
|
|
|
2014-12-22 19:47:39 +01:00
|
|
|
sub pause_all_threads {
|
2014-07-12 11:41:18 +02:00
|
|
|
return if $paused;
|
|
|
|
$paused = 1;
|
2014-12-13 15:01:53 +01:00
|
|
|
$pause_sema->down;
|
2017-06-08 18:53:33 +02:00
|
|
|
$_->kill('STOP') for _get_running_threads;
|
2014-07-12 11:41:18 +02:00
|
|
|
}
|
|
|
|
|
2014-12-22 19:47:39 +01:00
|
|
|
sub resume_all_threads {
|
2014-07-12 11:41:18 +02:00
|
|
|
return unless $paused;
|
|
|
|
$paused = 0;
|
2014-12-13 15:01:53 +01:00
|
|
|
$pause_sema->up;
|
2014-07-12 11:41:18 +02:00
|
|
|
}
|
|
|
|
|
2016-09-13 11:24:55 +02:00
|
|
|
# Open a file by converting $filename to local file system locales.
|
2013-01-13 10:18:34 +01:00
|
|
|
sub open {
|
|
|
|
my ($fh, $mode, $filename) = @_;
|
2013-02-22 18:40:00 +01:00
|
|
|
return CORE::open $$fh, $mode, encode_path($filename);
|
2013-01-13 10:18:34 +01:00
|
|
|
}
|
|
|
|
|
2017-02-19 16:04:57 +01:00
|
|
|
sub tags {
|
|
|
|
my ($format) = @_;
|
|
|
|
$format //= '';
|
|
|
|
my %tags;
|
|
|
|
# End of line
|
|
|
|
$tags{eol} = ($format eq 'html') ? '<br>' : "\n";
|
|
|
|
# Heading
|
2017-02-19 19:08:58 +01:00
|
|
|
$tags{h2start} = ($format eq 'html') ? '<b>' : '';
|
|
|
|
$tags{h2end} = ($format eq 'html') ? '</b>' : '';
|
2017-02-19 16:04:57 +01:00
|
|
|
# Bold font
|
|
|
|
$tags{bstart} = ($format eq 'html') ? '<b>' : '';
|
|
|
|
$tags{bend} = ($format eq 'html') ? '</b>' : '';
|
|
|
|
# Verbatim
|
|
|
|
$tags{vstart} = ($format eq 'html') ? '<pre>' : '';
|
|
|
|
$tags{vend} = ($format eq 'html') ? '</pre>' : '';
|
|
|
|
return %tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub slic3r_info
|
|
|
|
{
|
|
|
|
my (%params) = @_;
|
|
|
|
my %tag = Slic3r::tags($params{format});
|
|
|
|
my $out = '';
|
|
|
|
$out .= "$tag{bstart}$Slic3r::FORK_NAME$tag{bend}$tag{eol}";
|
|
|
|
$out .= "$tag{bstart}Version: $tag{bend}$Slic3r::VERSION$tag{eol}";
|
|
|
|
$out .= "$tag{bstart}Build: $tag{bend}$Slic3r::BUILD$tag{eol}";
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub copyright_info
|
|
|
|
{
|
|
|
|
my (%params) = @_;
|
|
|
|
my %tag = Slic3r::tags($params{format});
|
|
|
|
my $out =
|
|
|
|
'Copyright © 2016 Vojtech Bubnik, Prusa Research. <br />' .
|
|
|
|
'Copyright © 2011-2016 Alessandro Ranellucci. <br />' .
|
|
|
|
'<a href="http://slic3r.org/">Slic3r</a> is licensed under the ' .
|
|
|
|
'<a href="http://www.gnu.org/licenses/agpl-3.0.html">GNU Affero General Public License, version 3</a>.' .
|
|
|
|
'<br /><br /><br />' .
|
|
|
|
'Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Y. Sapir, Mike Sheldrake and numerous others. ' .
|
|
|
|
'Manual by Gary Hodgson. Inspired by the RepRap community. <br />' .
|
|
|
|
'Slic3r logo designed by Corey Daniels, <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon Set</a> designed by Mark James. ';
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub system_info
|
|
|
|
{
|
|
|
|
my (%params) = @_;
|
|
|
|
my %tag = Slic3r::tags($params{format});
|
|
|
|
|
|
|
|
my $out = '';
|
|
|
|
$out .= "$tag{bstart}Operating System: $tag{bend}$Config{osname}$tag{eol}";
|
|
|
|
$out .= "$tag{bstart}System Architecture: $tag{bend}$Config{archname}$tag{eol}";
|
|
|
|
if ($^O eq 'MSWin32') {
|
|
|
|
$out .= "$tag{bstart}Windows Version: $tag{bend}" . `ver` . $tag{eol};
|
|
|
|
} else {
|
|
|
|
# Hopefully some kind of unix / linux.
|
|
|
|
$out .= "$tag{bstart}System Version: $tag{bend}" . `uname -a` . $tag{eol};
|
|
|
|
}
|
|
|
|
$out .= $tag{vstart} . Config::myconfig . $tag{vend};
|
|
|
|
$out .= " $tag{bstart}\@INC:$tag{bend}$tag{eol}$tag{vstart}";
|
|
|
|
foreach my $i (@INC) {
|
|
|
|
$out .= " $i\n";
|
|
|
|
}
|
|
|
|
$out .= "$tag{vend}";
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
2013-12-13 12:18:30 +01:00
|
|
|
# this package declaration prevents an ugly fatal warning to be emitted when
|
|
|
|
# spawning a new thread
|
|
|
|
package GLUquadricObjPtr;
|
2018-04-18 18:48:32 +02:00
|
|
|
package Wx::Printout;
|
2013-12-13 12:18:30 +01:00
|
|
|
|
2011-09-01 21:06:28 +02:00
|
|
|
1;
|