2011-09-01 23:06:28 +04:00
|
|
|
package Slic3r;
|
|
|
|
|
2012-01-18 23:04:18 +04:00
|
|
|
# Copyright holder: Alessandro Ranellucci
|
|
|
|
# This application is licensed under the GNU Affero General Public License, version 3
|
|
|
|
|
2011-09-01 23:06:28 +04:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2012-01-22 16:56:15 +04:00
|
|
|
require v5.10;
|
2011-09-01 23:06:28 +04:00
|
|
|
|
2012-08-31 02:12:13 +04:00
|
|
|
our $VERSION = "0.9.3-dev";
|
2011-11-14 01:57:58 +04:00
|
|
|
|
2011-09-05 15:33:09 +04:00
|
|
|
our $debug = 0;
|
|
|
|
sub debugf {
|
|
|
|
printf @_ if $debug;
|
|
|
|
}
|
|
|
|
|
2012-05-19 22:25:59 +04:00
|
|
|
# load threads before Moo as required by it
|
2012-05-21 21:16:42 +04:00
|
|
|
our $have_threads;
|
2012-05-21 20:44:31 +04:00
|
|
|
BEGIN {
|
|
|
|
use Config;
|
2012-05-21 21:16:42 +04:00
|
|
|
$have_threads = $Config{useithreads} && eval "use threads; use Thread::Queue; 1";
|
2012-05-21 20:44:31 +04:00
|
|
|
}
|
2012-05-19 22:25:59 +04:00
|
|
|
|
2012-09-11 18:02:26 +04:00
|
|
|
warn "Running Slic3r under Perl >= 5.16 is not supported nor recommended\n"
|
|
|
|
if $^V >= v5.16;
|
|
|
|
|
2012-05-29 16:19:14 +04:00
|
|
|
use FindBin;
|
|
|
|
our $var = "$FindBin::Bin/var";
|
|
|
|
|
2012-06-24 01:27:57 +04:00
|
|
|
use Moo 0.091009;
|
2011-10-03 13:55:32 +04:00
|
|
|
use Slic3r::Config;
|
2011-10-15 13:36:05 +04:00
|
|
|
use Slic3r::ExPolygon;
|
2011-09-26 13:42:08 +04:00
|
|
|
use Slic3r::Extruder;
|
2011-09-26 01:15:45 +04:00
|
|
|
use Slic3r::ExtrusionLoop;
|
2011-09-04 14:04:01 +04:00
|
|
|
use Slic3r::ExtrusionPath;
|
2011-10-20 20:11:59 +04:00
|
|
|
use Slic3r::ExtrusionPath::Arc;
|
2011-09-26 12:52:58 +04:00
|
|
|
use Slic3r::ExtrusionPath::Collection;
|
2011-09-05 14:21:27 +04:00
|
|
|
use Slic3r::Fill;
|
2012-06-06 20:05:03 +04:00
|
|
|
use Slic3r::Flow;
|
2012-02-25 20:35:25 +04:00
|
|
|
use Slic3r::Format::AMF;
|
2012-05-20 13:40:37 +04:00
|
|
|
use Slic3r::Format::OBJ;
|
2012-02-25 20:35:25 +04:00
|
|
|
use Slic3r::Format::STL;
|
2012-06-28 16:44:54 +04:00
|
|
|
use Slic3r::GCode;
|
2011-12-07 22:33:59 +04:00
|
|
|
use Slic3r::Geometry qw(PI);
|
2011-09-01 23:06:28 +04:00
|
|
|
use Slic3r::Layer;
|
2012-09-23 04:52:31 +04:00
|
|
|
use Slic3r::Layer::Region;
|
2011-09-01 23:06:28 +04:00
|
|
|
use Slic3r::Line;
|
2012-08-29 18:49:38 +04:00
|
|
|
use Slic3r::Model;
|
2011-09-01 23:06:28 +04:00
|
|
|
use Slic3r::Point;
|
2011-10-15 13:36:05 +04:00
|
|
|
use Slic3r::Polygon;
|
2011-09-01 23:06:28 +04:00
|
|
|
use Slic3r::Polyline;
|
|
|
|
use Slic3r::Print;
|
2012-04-29 14:51:20 +04:00
|
|
|
use Slic3r::Print::Object;
|
2012-09-23 04:52:31 +04:00
|
|
|
use Slic3r::Print::Region;
|
2011-09-01 23:06:28 +04:00
|
|
|
use Slic3r::Surface;
|
2011-11-27 14:40:03 +04:00
|
|
|
use Slic3r::TriangleMesh;
|
2012-05-29 16:19:14 +04:00
|
|
|
eval "use Slic3r::Build";
|
2011-09-01 23:06:28 +04:00
|
|
|
|
2012-07-27 23:13:03 +04:00
|
|
|
use constant SCALING_FACTOR => 0.000001;
|
|
|
|
use constant RESOLUTION => 0.01;
|
|
|
|
use constant OVERLAP_FACTOR => 0.5;
|
|
|
|
use constant SMALL_PERIMETER_LENGTH => (6.5 / SCALING_FACTOR) * 2 * PI;
|
|
|
|
|
|
|
|
# The following variables hold the objects used throughout the slicing
|
|
|
|
# process. They should belong to the Print object, but we are keeping
|
|
|
|
# them here because it makes accessing them slightly faster.
|
|
|
|
our $Config;
|
2012-09-23 04:40:25 +04:00
|
|
|
our $flow;
|
2012-06-19 00:27:57 +04:00
|
|
|
|
2012-04-09 14:29:47 +04:00
|
|
|
sub parallelize {
|
|
|
|
my %params = @_;
|
|
|
|
|
2012-07-27 23:13:03 +04:00
|
|
|
if (!$params{disable} && $Slic3r::have_threads && $Config->threads > 1) {
|
2012-09-22 21:04:36 +04:00
|
|
|
my @items = (ref $params{items} eq 'CODE') ? $params{items}->() : @{$params{items}};
|
2012-04-09 14:29:47 +04:00
|
|
|
my $q = Thread::Queue->new;
|
2012-09-22 21:04:36 +04:00
|
|
|
$q->enqueue(@items, (map undef, 1..$Config->threads));
|
2012-04-09 14:29:47 +04:00
|
|
|
|
|
|
|
my $thread_cb = sub { $params{thread_cb}->($q) };
|
2012-07-27 23:13:03 +04:00
|
|
|
foreach my $th (map threads->create($thread_cb), 1..$Config->threads) {
|
2012-04-09 14:29:47 +04:00
|
|
|
$params{collect_cb}->($th->join);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$params{no_threads_cb}->();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-01 23:06:28 +04:00
|
|
|
1;
|