Slic3r.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package Slic3r;
  2. # Copyright holder: Alessandro Ranellucci
  3. # This application is licensed under the GNU Affero General Public License, version 3
  4. use strict;
  5. use warnings;
  6. require v5.10;
  7. our $VERSION = "0.9.9-dev";
  8. our $debug = 0;
  9. sub debugf {
  10. printf @_ if $debug;
  11. }
  12. # load threads before Moo as required by it
  13. our $have_threads;
  14. BEGIN {
  15. use Config;
  16. $have_threads = $Config{useithreads} && eval "use threads; use Thread::Queue; 1";
  17. }
  18. warn "Running Slic3r under Perl >= 5.16 is not supported nor recommended\n"
  19. if $^V >= v5.16;
  20. use FindBin;
  21. our $var = "$FindBin::Bin/var";
  22. use Encode;
  23. use Encode::Locale;
  24. use Boost::Geometry::Utils 0.06;
  25. use Moo 0.091009;
  26. use Slic3r::Config;
  27. use Slic3r::ExPolygon;
  28. use Slic3r::Extruder;
  29. use Slic3r::ExtrusionLoop;
  30. use Slic3r::ExtrusionPath;
  31. use Slic3r::ExtrusionPath::Arc;
  32. use Slic3r::ExtrusionPath::Collection;
  33. use Slic3r::Fill;
  34. use Slic3r::Flow;
  35. use Slic3r::Format::AMF;
  36. use Slic3r::Format::OBJ;
  37. use Slic3r::Format::STL;
  38. use Slic3r::GCode;
  39. use Slic3r::GCode::MotionPlanner;
  40. use Slic3r::Geometry qw(PI);
  41. use Slic3r::Layer;
  42. use Slic3r::Layer::Region;
  43. use Slic3r::Line;
  44. use Slic3r::Model;
  45. use Slic3r::Point;
  46. use Slic3r::Polygon;
  47. use Slic3r::Polyline;
  48. use Slic3r::Print;
  49. use Slic3r::Print::Object;
  50. use Slic3r::Print::Region;
  51. use Slic3r::Surface;
  52. use Slic3r::TriangleMesh;
  53. eval "use Slic3r::Build";
  54. use constant SCALING_FACTOR => 0.000001;
  55. use constant RESOLUTION => 0.0125;
  56. use constant SCALED_RESOLUTION => RESOLUTION / SCALING_FACTOR;
  57. use constant OVERLAP_FACTOR => 1;
  58. use constant SMALL_PERIMETER_LENGTH => (6.5 / SCALING_FACTOR) * 2 * PI;
  59. use constant LOOP_CLIPPING_LENGTH_OVER_SPACING => 0.15;
  60. use constant PERIMETER_INFILL_OVERLAP_OVER_SPACING => 0.45;
  61. # The following variables hold the objects used throughout the slicing
  62. # process. They should belong to the Print object, but we are keeping
  63. # them here because it makes accessing them slightly faster.
  64. our $Config;
  65. our $flow;
  66. our $first_layer_flow;
  67. sub parallelize {
  68. my %params = @_;
  69. if (!$params{disable} && $Slic3r::have_threads && $Config->threads > 1) {
  70. my @items = (ref $params{items} eq 'CODE') ? $params{items}->() : @{$params{items}};
  71. my $q = Thread::Queue->new;
  72. $q->enqueue(@items, (map undef, 1..$Config->threads));
  73. my $thread_cb = sub { $params{thread_cb}->($q) };
  74. foreach my $th (map threads->create($thread_cb), 1..$Config->threads) {
  75. $params{collect_cb}->($th->join);
  76. }
  77. } else {
  78. $params{no_threads_cb}->();
  79. }
  80. }
  81. sub open {
  82. my ($fh, $mode, $filename) = @_;
  83. return CORE::open $$fh, $mode, encode('locale_fs', $filename);
  84. }
  85. 1;