Slic3r/lib/Slic3r.pm

82 lines
2.1 KiB
Perl
Raw Normal View History

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-19 11:49:43 +04:00
our $VERSION = "0.9.2-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;
BEGIN {
use Config;
2012-05-21 21:16:42 +04:00
$have_threads = $Config{useithreads} && eval "use threads; use Thread::Queue; 1";
}
2012-05-19 22:25:59 +04:00
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;
use Slic3r::ExPolygon;
use Slic3r::Extruder;
use Slic3r::ExtrusionLoop;
use Slic3r::ExtrusionPath;
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;
use Slic3r::Flow;
use Slic3r::Format::AMF;
2012-05-20 13:40:37 +04:00
use Slic3r::Format::OBJ;
use Slic3r::Format::STL;
use Slic3r::GCode;
use Slic3r::Geometry qw(PI);
2011-09-01 23:06:28 +04:00
use Slic3r::Layer;
use Slic3r::Line;
use Slic3r::Point;
use Slic3r::Polygon;
2011-09-01 23:06:28 +04:00
use Slic3r::Polyline;
use Slic3r::Print;
use Slic3r::Print::Object;
2011-09-01 23:06:28 +04:00
use Slic3r::Surface;
use Slic3r::TriangleMesh;
2012-05-29 16:19:14 +04:00
eval "use Slic3r::Build";
2011-09-01 23:06:28 +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;
our $extruders;
our ($flow, $first_layer_flow, $perimeter_flow, $infill_flow, $support_material_flow);
2012-06-19 00:27:57 +04:00
2012-04-09 14:29:47 +04:00
sub parallelize {
my %params = @_;
if (!$params{disable} && $Slic3r::have_threads && $Config->threads > 1) {
2012-04-09 14:29:47 +04:00
my $q = Thread::Queue->new;
$q->enqueue(@{ $params{items} }, (map undef, 1..$Config->threads));
2012-04-09 14:29:47 +04:00
my $thread_cb = sub { $params{thread_cb}->($q) };
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;