XS.pm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. package Slic3r::XS;
  2. use warnings;
  3. use strict;
  4. our $VERSION = '0.01';
  5. # We have to load these modules in order to have Wx.pm find the correct paths
  6. # for wxWidgets dlls on MSW.
  7. # We avoid loading these on OS X because Wx::Load() initializes a Wx App
  8. # automatically and it steals focus even when we're not running Slic3r in GUI mode.
  9. # TODO: only load these when compiling with GUI support
  10. BEGIN {
  11. if ($^O eq 'MSWin32') {
  12. eval "use Wx";
  13. eval "use Wx::GLCanvas";
  14. eval "use Wx::GLContext";
  15. eval "use Wx::Html";
  16. eval "use Wx::Print"; # because of some Wx bug, thread creation fails if we don't have this (looks like Wx::Printout is hard-coded in some thread cleanup code)
  17. }
  18. }
  19. use Carp qw();
  20. use XSLoader;
  21. XSLoader::load(__PACKAGE__, $VERSION);
  22. package Slic3r::Line;
  23. use overload
  24. '@{}' => sub { $_[0]->arrayref },
  25. 'fallback' => 1;
  26. package Slic3r::Point;
  27. use overload
  28. '@{}' => sub { $_[0]->arrayref },
  29. 'fallback' => 1;
  30. package Slic3r::Pointf;
  31. use overload
  32. '@{}' => sub { $_[0]->arrayref },
  33. 'fallback' => 1;
  34. package Slic3r::Pointf3;
  35. use overload
  36. '@{}' => sub { [ $_[0]->x, $_[0]->y, $_[0]->z ] }, #,
  37. 'fallback' => 1;
  38. sub pp {
  39. my ($self) = @_;
  40. return [ @$self ];
  41. }
  42. package Slic3r::ExPolygon;
  43. use overload
  44. '@{}' => sub { $_[0]->arrayref },
  45. 'fallback' => 1;
  46. package Slic3r::Polyline;
  47. use overload
  48. '@{}' => sub { $_[0]->arrayref },
  49. 'fallback' => 1;
  50. package Slic3r::Polyline::Collection;
  51. use overload
  52. '@{}' => sub { $_[0]->arrayref },
  53. 'fallback' => 1;
  54. package Slic3r::Polygon;
  55. use overload
  56. '@{}' => sub { $_[0]->arrayref },
  57. 'fallback' => 1;
  58. package Slic3r::ExPolygon::Collection;
  59. use overload
  60. '@{}' => sub { $_[0]->arrayref },
  61. 'fallback' => 1;
  62. package Slic3r::ExtrusionPath::Collection;
  63. use overload
  64. '@{}' => sub { $_[0]->arrayref },
  65. 'fallback' => 1;
  66. sub new {
  67. my ($class, @paths) = @_;
  68. my $self = $class->_new;
  69. $self->append(@paths);
  70. return $self;
  71. }
  72. package Slic3r::ExtrusionLoop;
  73. use overload
  74. '@{}' => sub { $_[0]->arrayref },
  75. 'fallback' => 1;
  76. sub new_from_paths {
  77. my ($class, @paths) = @_;
  78. my $loop = $class->new;
  79. $loop->append($_) for @paths;
  80. return $loop;
  81. }
  82. package Slic3r::ExtrusionMultiPath;
  83. use overload
  84. '@{}' => sub { $_[0]->arrayref },
  85. 'fallback' => 1;
  86. package Slic3r::ExtrusionPath;
  87. use overload
  88. '@{}' => sub { $_[0]->arrayref },
  89. 'fallback' => 1;
  90. sub new {
  91. my ($class, %args) = @_;
  92. return $class->_new(
  93. $args{polyline}, # required
  94. $args{role}, # required
  95. $args{mm3_per_mm} // die("Missing required mm3_per_mm in ExtrusionPath constructor"),
  96. $args{width} // -1,
  97. $args{height} // -1,
  98. );
  99. }
  100. sub clone {
  101. my ($self, %args) = @_;
  102. return __PACKAGE__->_new(
  103. $args{polyline} // $self->polyline,
  104. $args{role} // $self->role,
  105. $args{mm3_per_mm} // $self->mm3_per_mm,
  106. $args{width} // $self->width,
  107. $args{height} // $self->height,
  108. );
  109. }
  110. package Slic3r::ExtrusionSimulator;
  111. sub new {
  112. my ($class, %args) = @_;
  113. return $class->_new();
  114. }
  115. package Slic3r::Filler;
  116. sub fill_surface {
  117. my ($self, $surface, %args) = @_;
  118. $self->set_density($args{density}) if defined($args{density});
  119. $self->set_dont_adjust($args{dont_adjust}) if defined($args{dont_adjust});
  120. $self->set_complete($args{complete}) if defined($args{complete});
  121. return $self->_fill_surface($surface);
  122. }
  123. package Slic3r::Flow;
  124. sub new {
  125. my ($class, %args) = @_;
  126. my $self = $class->_new(
  127. @args{qw(width height nozzle_diameter)},
  128. );
  129. return $self;
  130. }
  131. sub new_from_width {
  132. my ($class, %args) = @_;
  133. return $class->_new_from_width(
  134. @args{qw(role width nozzle_diameter layer_height)},
  135. );
  136. }
  137. package Slic3r::Surface;
  138. sub new {
  139. my ($class, %args) = @_;
  140. # defensive programming: make sure no negative bridge_angle is supplied
  141. die "Error: invalid negative bridge_angle\n"
  142. if defined $args{bridge_angle} && $args{bridge_angle} < 0;
  143. return $class->_new(
  144. $args{expolygon} // (die "Missing required expolygon\n"),
  145. $args{surface_type} // (die "Missing required surface_type\n"),
  146. $args{thickness} // -1,
  147. $args{thickness_layers} // 1,
  148. $args{bridge_angle} // -1,
  149. $args{extra_perimeters} // 0,
  150. );
  151. }
  152. sub clone {
  153. my ($self, %args) = @_;
  154. return (ref $self)->_new(
  155. delete $args{expolygon} // $self->expolygon,
  156. delete $args{surface_type} // $self->surface_type,
  157. delete $args{thickness} // $self->thickness,
  158. delete $args{thickness_layers} // $self->thickness_layers,
  159. delete $args{bridge_angle} // $self->bridge_angle,
  160. delete $args{extra_perimeters} // $self->extra_perimeters,
  161. );
  162. }
  163. package Slic3r::Surface::Collection;
  164. use overload
  165. '@{}' => sub { $_[0]->arrayref },
  166. 'fallback' => 1;
  167. sub new {
  168. my ($class, @surfaces) = @_;
  169. my $self = $class->_new;
  170. $self->append($_) for @surfaces;
  171. return $self;
  172. }
  173. package Slic3r::Print::SupportMaterial2;
  174. sub new {
  175. my ($class, %args) = @_;
  176. return $class->_new(
  177. $args{print_config}, # required
  178. $args{object_config}, # required
  179. $args{first_layer_flow}, # required
  180. $args{flow}, # required
  181. $args{interface_flow}, # required
  182. $args{soluble_interface} // 0
  183. );
  184. }
  185. package Slic3r::GUI::_3DScene::GLVolume::Collection;
  186. use overload
  187. '@{}' => sub { $_[0]->arrayref },
  188. 'fallback' => 1;
  189. package Slic3r::GUI::PresetCollection;
  190. use overload
  191. '@{}' => sub { $_[0]->arrayref },
  192. 'fallback' => 1;
  193. package main;
  194. for my $class (qw(
  195. Slic3r::BridgeDetector
  196. Slic3r::Config
  197. Slic3r::Config::Full
  198. Slic3r::Config::GCode
  199. Slic3r::Config::Print
  200. Slic3r::Config::PrintObject
  201. Slic3r::Config::PrintRegion
  202. Slic3r::Config::Static
  203. Slic3r::ExPolygon
  204. Slic3r::ExPolygon::Collection
  205. Slic3r::ExtrusionLoop
  206. Slic3r::ExtrusionMultiPath
  207. Slic3r::ExtrusionPath
  208. Slic3r::ExtrusionPath::Collection
  209. Slic3r::ExtrusionSimulator
  210. Slic3r::Filler
  211. Slic3r::Flow
  212. Slic3r::GCode
  213. Slic3r::GCode::PlaceholderParser
  214. Slic3r::Geometry::BoundingBox
  215. Slic3r::Geometry::BoundingBoxf
  216. Slic3r::Geometry::BoundingBoxf3
  217. Slic3r::GUI::_3DScene::GLShader
  218. Slic3r::GUI::_3DScene::GLVolume
  219. Slic3r::GUI::Preset
  220. Slic3r::GUI::PresetCollection
  221. Slic3r::GUI::Tab
  222. Slic3r::Layer
  223. Slic3r::Layer::Region
  224. Slic3r::Layer::Support
  225. Slic3r::Line
  226. Slic3r::Linef3
  227. Slic3r::Model
  228. Slic3r::Model::Instance
  229. Slic3r::Model::Material
  230. Slic3r::Model::Object
  231. Slic3r::Model::Volume
  232. Slic3r::Point
  233. Slic3r::Point3
  234. Slic3r::Pointf
  235. Slic3r::Pointf3
  236. Slic3r::Polygon
  237. Slic3r::Polyline
  238. Slic3r::Polyline::Collection
  239. Slic3r::Print
  240. Slic3r::Print::Object
  241. Slic3r::Print::Region
  242. Slic3r::Print::State
  243. Slic3r::Surface
  244. Slic3r::Surface::Collection
  245. Slic3r::Print::SupportMaterial2
  246. Slic3r::TriangleMesh
  247. ))
  248. {
  249. no strict 'refs';
  250. my $ref_class = $class . "::Ref";
  251. eval "package $ref_class; our \@ISA = '$class'; sub DESTROY {};";
  252. }
  253. 1;