XS.pm 7.9 KB

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