XS.pm 7.7 KB

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