2011-09-01 19:06:28 +00:00
|
|
|
package Slic3r;
|
|
|
|
|
2012-01-18 19:04:18 +00:00
|
|
|
# Copyright holder: Alessandro Ranellucci
|
|
|
|
# This application is licensed under the GNU Affero General Public License, version 3
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2012-01-22 12:56:15 +00:00
|
|
|
require v5.10;
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2013-01-17 16:44:56 +00:00
|
|
|
our $VERSION = "0.9.9-dev";
|
2011-11-13 21:57:58 +00:00
|
|
|
|
2011-09-05 11:33:09 +00:00
|
|
|
our $debug = 0;
|
|
|
|
sub debugf {
|
|
|
|
printf @_ if $debug;
|
|
|
|
}
|
|
|
|
|
2012-05-19 18:25:59 +00:00
|
|
|
# load threads before Moo as required by it
|
2012-05-21 17:16:42 +00:00
|
|
|
our $have_threads;
|
2012-05-21 16:44:31 +00:00
|
|
|
BEGIN {
|
|
|
|
use Config;
|
2012-05-21 17:16:42 +00:00
|
|
|
$have_threads = $Config{useithreads} && eval "use threads; use Thread::Queue; 1";
|
2012-05-21 16:44:31 +00:00
|
|
|
}
|
2012-05-19 18:25:59 +00:00
|
|
|
|
2012-09-11 14:02:26 +00:00
|
|
|
warn "Running Slic3r under Perl >= 5.16 is not supported nor recommended\n"
|
|
|
|
if $^V >= v5.16;
|
|
|
|
|
2012-05-29 12:19:14 +00:00
|
|
|
use FindBin;
|
|
|
|
our $var = "$FindBin::Bin/var";
|
|
|
|
|
2013-01-13 09:18:34 +00:00
|
|
|
use Encode;
|
|
|
|
use Encode::Locale;
|
2013-01-27 23:34:09 +00:00
|
|
|
use Boost::Geometry::Utils 0.06;
|
2012-06-23 21:27:57 +00:00
|
|
|
use Moo 0.091009;
|
2013-01-13 09:18:34 +00:00
|
|
|
|
2011-10-03 09:55:32 +00:00
|
|
|
use Slic3r::Config;
|
2011-10-15 09:36:05 +00:00
|
|
|
use Slic3r::ExPolygon;
|
2011-09-26 09:42:08 +00:00
|
|
|
use Slic3r::Extruder;
|
2011-09-25 21:15:45 +00:00
|
|
|
use Slic3r::ExtrusionLoop;
|
2011-09-04 10:04:01 +00:00
|
|
|
use Slic3r::ExtrusionPath;
|
2011-10-20 16:11:59 +00:00
|
|
|
use Slic3r::ExtrusionPath::Arc;
|
2011-09-26 08:52:58 +00:00
|
|
|
use Slic3r::ExtrusionPath::Collection;
|
2011-09-05 10:21:27 +00:00
|
|
|
use Slic3r::Fill;
|
2012-06-06 16:05:03 +00:00
|
|
|
use Slic3r::Flow;
|
2012-02-25 16:35:25 +00:00
|
|
|
use Slic3r::Format::AMF;
|
2012-05-20 09:40:37 +00:00
|
|
|
use Slic3r::Format::OBJ;
|
2012-02-25 16:35:25 +00:00
|
|
|
use Slic3r::Format::STL;
|
2012-06-28 12:44:54 +00:00
|
|
|
use Slic3r::GCode;
|
2012-08-23 13:42:58 +00:00
|
|
|
use Slic3r::GCode::MotionPlanner;
|
2011-12-07 18:33:59 +00:00
|
|
|
use Slic3r::Geometry qw(PI);
|
2011-09-01 19:06:28 +00:00
|
|
|
use Slic3r::Layer;
|
2012-09-23 00:52:31 +00:00
|
|
|
use Slic3r::Layer::Region;
|
2011-09-01 19:06:28 +00:00
|
|
|
use Slic3r::Line;
|
2012-08-29 14:49:38 +00:00
|
|
|
use Slic3r::Model;
|
2011-09-01 19:06:28 +00:00
|
|
|
use Slic3r::Point;
|
2011-10-15 09:36:05 +00:00
|
|
|
use Slic3r::Polygon;
|
2011-09-01 19:06:28 +00:00
|
|
|
use Slic3r::Polyline;
|
|
|
|
use Slic3r::Print;
|
2012-04-29 10:51:20 +00:00
|
|
|
use Slic3r::Print::Object;
|
2012-09-23 00:52:31 +00:00
|
|
|
use Slic3r::Print::Region;
|
2011-09-01 19:06:28 +00:00
|
|
|
use Slic3r::Surface;
|
2011-11-27 10:40:03 +00:00
|
|
|
use Slic3r::TriangleMesh;
|
2012-05-29 12:19:14 +00:00
|
|
|
eval "use Slic3r::Build";
|
2011-09-01 19:06:28 +00:00
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
use constant SCALING_FACTOR => 0.000001;
|
2012-11-18 16:38:08 +00:00
|
|
|
use constant RESOLUTION => 0.0125;
|
|
|
|
use constant SCALED_RESOLUTION => RESOLUTION / SCALING_FACTOR;
|
2012-11-16 17:11:06 +00:00
|
|
|
use constant OVERLAP_FACTOR => 1;
|
2012-07-27 19:13:03 +00:00
|
|
|
use constant SMALL_PERIMETER_LENGTH => (6.5 / SCALING_FACTOR) * 2 * PI;
|
2012-10-30 13:07:01 +00:00
|
|
|
use constant LOOP_CLIPPING_LENGTH_OVER_SPACING => 0.15;
|
2012-10-30 13:21:59 +00:00
|
|
|
use constant PERIMETER_INFILL_OVERLAP_OVER_SPACING => 0.45;
|
2012-07-27 19:13:03 +00:00
|
|
|
|
|
|
|
our $Config;
|
2012-06-18 20:27:57 +00:00
|
|
|
|
2012-04-09 10:29:47 +00:00
|
|
|
sub parallelize {
|
|
|
|
my %params = @_;
|
|
|
|
|
2012-07-27 19:13:03 +00:00
|
|
|
if (!$params{disable} && $Slic3r::have_threads && $Config->threads > 1) {
|
2012-09-22 17:04:36 +00:00
|
|
|
my @items = (ref $params{items} eq 'CODE') ? $params{items}->() : @{$params{items}};
|
2012-04-09 10:29:47 +00:00
|
|
|
my $q = Thread::Queue->new;
|
2012-09-22 17:04:36 +00:00
|
|
|
$q->enqueue(@items, (map undef, 1..$Config->threads));
|
2012-04-09 10:29:47 +00:00
|
|
|
|
|
|
|
my $thread_cb = sub { $params{thread_cb}->($q) };
|
2012-07-27 19:13:03 +00:00
|
|
|
foreach my $th (map threads->create($thread_cb), 1..$Config->threads) {
|
2012-04-09 10:29:47 +00:00
|
|
|
$params{collect_cb}->($th->join);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$params{no_threads_cb}->();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 17:40:00 +00:00
|
|
|
sub encode_path {
|
|
|
|
my ($filename) = @_;
|
|
|
|
return encode('locale_fs', $filename);
|
|
|
|
}
|
|
|
|
|
2013-01-13 09:18:34 +00:00
|
|
|
sub open {
|
|
|
|
my ($fh, $mode, $filename) = @_;
|
2013-02-22 17:40:00 +00:00
|
|
|
return CORE::open $$fh, $mode, encode_path($filename);
|
2013-01-13 09:18:34 +00:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:06:28 +00:00
|
|
|
1;
|