Slic3r.pm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # This package loads all the non-GUI Slic3r perl packages.
  2. package Slic3r;
  3. # Copyright holder: Alessandro Ranellucci
  4. # This application is licensed under the GNU Affero General Public License, version 3
  5. use strict;
  6. use warnings;
  7. use Config;
  8. require v5.10;
  9. our $VERSION = VERSION();
  10. our $BUILD = BUILD();
  11. our $FORK_NAME = FORK_NAME();
  12. our $debug = 0;
  13. sub debugf {
  14. printf @_ if $debug;
  15. }
  16. our $loglevel = 0;
  17. BEGIN {
  18. $debug = 1 if (defined($ENV{'SLIC3R_DEBUGOUT'}) && $ENV{'SLIC3R_DEBUGOUT'} == 1);
  19. print "Debugging output enabled\n" if $debug;
  20. }
  21. use FindBin;
  22. # Let the XS module know where the GUI resources reside.
  23. set_resources_dir(decode_path($FindBin::Bin) . (($^O eq 'darwin') ? '/../Resources' : '/resources'));
  24. set_var_dir(resources_dir() . "/icons");
  25. set_local_dir(resources_dir() . "/localization/");
  26. use Moo 1.003001;
  27. use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
  28. use Slic3r::Config;
  29. use Slic3r::ExPolygon;
  30. use Slic3r::ExtrusionLoop;
  31. use Slic3r::ExtrusionPath;
  32. use Slic3r::Flow;
  33. use Slic3r::GCode::Reader;
  34. use Slic3r::Geometry::Clipper;
  35. use Slic3r::Layer;
  36. use Slic3r::Line;
  37. use Slic3r::Model;
  38. use Slic3r::Point;
  39. use Slic3r::Polygon;
  40. use Slic3r::Polyline;
  41. use Slic3r::Print::Object;
  42. use Slic3r::Surface;
  43. our $build = eval "use Slic3r::Build; 1";
  44. # Scaling between the float and integer coordinates.
  45. # Floats are in mm.
  46. use constant SCALING_FACTOR => 0.000001;
  47. # Set the logging level at the Slic3r XS module.
  48. $Slic3r::loglevel = (defined($ENV{'SLIC3R_LOGLEVEL'}) && $ENV{'SLIC3R_LOGLEVEL'} =~ /^[1-9]/) ? $ENV{'SLIC3R_LOGLEVEL'} : 0;
  49. set_logging_level($Slic3r::loglevel);
  50. # Let the palceholder parser evaluate one expression to initialize its local static macro_processor
  51. # class instance in a thread safe manner.
  52. Slic3r::GCode::PlaceholderParser->new->evaluate_boolean_expression('1==1');
  53. # Open a file by converting $filename to local file system locales.
  54. sub open {
  55. my ($fh, $mode, $filename) = @_;
  56. return CORE::open $$fh, $mode, encode_path($filename);
  57. }
  58. sub tags {
  59. my ($format) = @_;
  60. $format //= '';
  61. my %tags;
  62. # End of line
  63. $tags{eol} = ($format eq 'html') ? '<br>' : "\n";
  64. # Heading
  65. $tags{h2start} = ($format eq 'html') ? '<b>' : '';
  66. $tags{h2end} = ($format eq 'html') ? '</b>' : '';
  67. # Bold font
  68. $tags{bstart} = ($format eq 'html') ? '<b>' : '';
  69. $tags{bend} = ($format eq 'html') ? '</b>' : '';
  70. # Verbatim
  71. $tags{vstart} = ($format eq 'html') ? '<pre>' : '';
  72. $tags{vend} = ($format eq 'html') ? '</pre>' : '';
  73. return %tags;
  74. }
  75. sub slic3r_info
  76. {
  77. my (%params) = @_;
  78. my %tag = Slic3r::tags($params{format});
  79. my $out = '';
  80. $out .= "$tag{bstart}$Slic3r::FORK_NAME$tag{bend}$tag{eol}";
  81. $out .= "$tag{bstart}Version: $tag{bend}$Slic3r::VERSION$tag{eol}";
  82. $out .= "$tag{bstart}Build: $tag{bend}$Slic3r::BUILD$tag{eol}";
  83. return $out;
  84. }
  85. sub copyright_info
  86. {
  87. my (%params) = @_;
  88. my %tag = Slic3r::tags($params{format});
  89. my $out =
  90. 'Copyright &copy; 2018 Durand Rémi. <br />' .
  91. 'Copyright &copy; 2016 Vojtech Bubnik, Prusa Research. <br />' .
  92. 'Copyright &copy; 2011-2016 Alessandro Ranellucci. <br />' .
  93. '<a href="http://slic3r.org/">Slic3r</a> is licensed under the ' .
  94. '<a href="http://www.gnu.org/licenses/agpl-3.0.html">GNU Affero General Public License, version 3</a>.' .
  95. '<br /><br /><br />' .
  96. 'Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Y. Sapir, Mike Sheldrake, Durand Rémi and numerous others. ' .
  97. 'Manual by Gary Hodgson. Inspired by the RepRap community. <br />' .
  98. 'Slic3r logo designed by Corey Daniels, <a href="http://www.famfamfam.com/lab/icons/silk/">Silk Icon Set</a> designed by Mark James. ';
  99. return $out;
  100. }
  101. sub system_info
  102. {
  103. my (%params) = @_;
  104. my %tag = Slic3r::tags($params{format});
  105. my $out = '';
  106. $out .= "$tag{bstart}Operating System: $tag{bend}$Config{osname}$tag{eol}";
  107. $out .= "$tag{bstart}System Architecture: $tag{bend}$Config{archname}$tag{eol}";
  108. if ($^O eq 'MSWin32') {
  109. $out .= "$tag{bstart}Windows Version: $tag{bend}" . `ver` . $tag{eol};
  110. } else {
  111. # Hopefully some kind of unix / linux.
  112. $out .= "$tag{bstart}System Version: $tag{bend}" . `uname -a` . $tag{eol};
  113. }
  114. $out .= $tag{vstart} . Config::myconfig . $tag{vend};
  115. $out .= " $tag{bstart}\@INC:$tag{bend}$tag{eol}$tag{vstart}";
  116. foreach my $i (@INC) {
  117. $out .= " $i\n";
  118. }
  119. $out .= "$tag{vend}";
  120. return $out;
  121. }
  122. 1;