XS.pm 6.5 KB

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