Print.xsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "libslic3r/Print.hpp"
  5. #include "libslic3r/PlaceholderParser.hpp"
  6. %}
  7. %package{Slic3r::Print::State};
  8. %{
  9. IV
  10. _constant()
  11. ALIAS:
  12. STEP_LAYERS = posLayers
  13. STEP_SLICE = posSlice
  14. STEP_PERIMETERS = posPerimeters
  15. STEP_DETECT_SURFACES = posDetectSurfaces
  16. STEP_PREPARE_INFILL = posPrepareInfill
  17. STEP_INFILL = posInfill
  18. STEP_SUPPORTMATERIAL = posSupportMaterial
  19. STEP_SKIRT = psSkirt
  20. STEP_BRIM = psBrim
  21. PROTOTYPE:
  22. CODE:
  23. RETVAL = ix;
  24. OUTPUT: RETVAL
  25. %}
  26. %name{Slic3r::Print::Region} class PrintRegion {
  27. // owned by Print, no constructor/destructor
  28. Ref<StaticPrintConfig> config()
  29. %code%{ RETVAL = &THIS->config; %};
  30. Ref<Print> print();
  31. Clone<Flow> flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, PrintObject* object)
  32. %code%{ RETVAL = THIS->flow(role, layer_height, bridge, first_layer, width, *object); %};
  33. };
  34. %name{Slic3r::Print::Object} class PrintObject {
  35. // owned by Print, no constructor/destructor
  36. void add_region_volume(int region_id, int volume_id);
  37. std::vector<int> get_region_volumes(int region_id)
  38. %code%{
  39. if (0 <= region_id && region_id < THIS->region_volumes.size())
  40. RETVAL = THIS->region_volumes[region_id];
  41. %};
  42. int region_count()
  43. %code%{ RETVAL = THIS->print()->regions.size(); %};
  44. Ref<Print> print();
  45. Ref<ModelObject> model_object();
  46. Ref<StaticPrintConfig> config()
  47. %code%{ RETVAL = &THIS->config; %};
  48. Points copies();
  49. t_layer_height_ranges layer_height_ranges()
  50. %code%{ RETVAL = THIS->layer_height_ranges; %};
  51. Ref<LayerHeightSpline> layer_height_spline()
  52. %code%{ RETVAL = &THIS->layer_height_spline; %};
  53. Ref<Point3> size()
  54. %code%{ RETVAL = &THIS->size; %};
  55. Clone<BoundingBox> bounding_box();
  56. Ref<Point> _copies_shift()
  57. %code%{ RETVAL = &THIS->_copies_shift; %};
  58. std::vector<int> support_material_extruders()
  59. %code%{
  60. std::set<size_t> extruders = THIS->support_material_extruders();
  61. RETVAL.reserve(extruders.size());
  62. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  63. RETVAL.push_back(*e);
  64. }
  65. %};
  66. std::vector<int> extruders()
  67. %code%{
  68. std::set<size_t> extruders = THIS->extruders();
  69. RETVAL.reserve(extruders.size());
  70. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  71. RETVAL.push_back(*e);
  72. }
  73. %};
  74. bool typed_slices()
  75. %code%{ RETVAL = THIS->typed_slices; %};
  76. void set_typed_slices(bool value)
  77. %code%{ THIS->typed_slices = value; %};
  78. Points _shifted_copies()
  79. %code%{ RETVAL = THIS->_shifted_copies; %};
  80. void set_shifted_copies(Points value)
  81. %code%{ THIS->_shifted_copies = value; %};
  82. bool add_copy(Pointf* point)
  83. %code%{ RETVAL = THIS->add_copy(*point); %};
  84. bool delete_last_copy();
  85. bool delete_all_copies();
  86. bool set_copies(Points copies);
  87. bool reload_model_instances();
  88. void set_layer_height_ranges(t_layer_height_ranges layer_height_ranges)
  89. %code%{ THIS->layer_height_ranges = layer_height_ranges; %};
  90. size_t total_layer_count();
  91. size_t layer_count();
  92. void clear_layers();
  93. Ref<Layer> get_layer(int idx);
  94. Ref<Layer> add_layer(int id, coordf_t height, coordf_t print_z,
  95. coordf_t slice_z);
  96. void delete_layer(int idx);
  97. %name{support_material_flow} Clone<Flow> _support_material_flow(FlowRole role = frSupportMaterial);
  98. size_t support_layer_count();
  99. void clear_support_layers();
  100. Ref<SupportLayer> get_support_layer(int idx);
  101. Ref<SupportLayer> add_support_layer(int id, coordf_t height, coordf_t print_z);
  102. void delete_support_layer(int idx);
  103. bool invalidate_step(PrintObjectStep step);
  104. bool invalidate_all_steps();
  105. bool step_done(PrintObjectStep step)
  106. %code%{ RETVAL = THIS->state.is_done(step); %};
  107. void set_step_done(PrintObjectStep step)
  108. %code%{ THIS->state.set_done(step); %};
  109. void set_step_started(PrintObjectStep step)
  110. %code%{ THIS->state.set_started(step); %};
  111. void detect_surfaces_type();
  112. void process_external_surfaces();
  113. void bridge_over_infill();
  114. void combine_infill();
  115. void discover_horizontal_shells();
  116. void clip_fill_surfaces();
  117. void slice();
  118. void _slice();
  119. SV* _slice_region(size_t region_id, std::vector<double> z, bool modifier)
  120. %code%{
  121. std::vector<float> z_f(z.begin(), z.end());
  122. std::vector<ExPolygons> layers = THIS->_slice_region(region_id, z_f, modifier);
  123. AV* layers_av = newAV();
  124. size_t len = layers.size();
  125. if (len > 0) av_extend(layers_av, len-1);
  126. for (unsigned int i = 0; i < layers.size(); i++) {
  127. AV* expolygons_av = newAV();
  128. len = layers[i].size();
  129. if (len > 0) av_extend(expolygons_av, len-1);
  130. unsigned int j = 0;
  131. for (ExPolygons::iterator it = layers[i].begin(); it != layers[i].end(); ++it) {
  132. av_store(expolygons_av, j++, perl_to_SV_clone_ref(*it));
  133. }
  134. av_store(layers_av, i, newRV_noinc((SV*)expolygons_av));
  135. }
  136. RETVAL = (SV*)newRV_noinc((SV*)layers_av);
  137. %};
  138. void make_perimeters();
  139. void prepare_infill();
  140. void infill();
  141. void _simplify_slices(double distance);
  142. int ptr()
  143. %code%{ RETVAL = (int)(intptr_t)THIS; %};
  144. };
  145. %name{Slic3r::Print} class Print {
  146. Print();
  147. ~Print();
  148. Ref<StaticPrintConfig> config()
  149. %code%{ RETVAL = &THIS->config; %};
  150. Ref<StaticPrintConfig> default_object_config()
  151. %code%{ RETVAL = &THIS->default_object_config; %};
  152. Ref<StaticPrintConfig> default_region_config()
  153. %code%{ RETVAL = &THIS->default_region_config; %};
  154. Ref<PlaceholderParser> placeholder_parser()
  155. %code%{ RETVAL = &THIS->placeholder_parser; %};
  156. // TODO: status_cb
  157. Ref<ExtrusionEntityCollection> skirt()
  158. %code%{ RETVAL = &THIS->skirt; %};
  159. Ref<ExtrusionEntityCollection> brim()
  160. %code%{ RETVAL = &THIS->brim; %};
  161. PrintObjectPtrs* objects()
  162. %code%{ RETVAL = &THIS->objects; %};
  163. void clear_objects();
  164. Ref<PrintObject> get_object(int idx);
  165. void delete_object(int idx);
  166. void reload_object(int idx);
  167. bool reload_model_instances();
  168. size_t object_count()
  169. %code%{ RETVAL = THIS->objects.size(); %};
  170. PrintRegionPtrs* regions()
  171. %code%{ RETVAL = &THIS->regions; %};
  172. Ref<PrintRegion> get_region(int idx);
  173. Ref<PrintRegion> add_region();
  174. size_t region_count()
  175. %code%{ RETVAL = THIS->regions.size(); %};
  176. bool invalidate_step(PrintStep step);
  177. bool invalidate_all_steps();
  178. bool step_done(PrintStep step)
  179. %code%{ RETVAL = THIS->state.is_done(step); %};
  180. bool object_step_done(PrintObjectStep step)
  181. %code%{ RETVAL = THIS->step_done(step); %};
  182. void set_step_done(PrintStep step)
  183. %code%{ THIS->state.set_done(step); %};
  184. void set_step_started(PrintStep step)
  185. %code%{ THIS->state.set_started(step); %};
  186. std::vector<int> object_extruders()
  187. %code%{
  188. std::set<size_t> extruders = THIS->object_extruders();
  189. RETVAL.reserve(extruders.size());
  190. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  191. RETVAL.push_back(*e);
  192. }
  193. %};
  194. std::vector<int> support_material_extruders()
  195. %code%{
  196. std::set<size_t> extruders = THIS->support_material_extruders();
  197. RETVAL.reserve(extruders.size());
  198. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  199. RETVAL.push_back(*e);
  200. }
  201. %};
  202. std::vector<int> extruders()
  203. %code%{
  204. std::set<size_t> extruders = THIS->extruders();
  205. RETVAL.reserve(extruders.size());
  206. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  207. RETVAL.push_back(*e);
  208. }
  209. %};
  210. int brim_extruder();
  211. void clear_filament_stats()
  212. %code%{
  213. THIS->filament_stats.clear();
  214. %};
  215. void set_filament_stats(int extruder_id, float length)
  216. %code%{
  217. THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
  218. THIS->filament_stats[extruder_id] += length;
  219. %};
  220. SV* filament_stats()
  221. %code%{
  222. HV* hv = newHV();
  223. for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
  224. // stringify extruder_id
  225. std::ostringstream ss;
  226. ss << it->first;
  227. std::string str = ss.str();
  228. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  229. RETVAL = newRV_noinc((SV*)hv);
  230. }
  231. %};
  232. void _simplify_slices(double distance);
  233. double max_allowed_layer_height() const;
  234. bool has_support_material() const;
  235. void auto_assign_extruders(ModelObject* model_object);
  236. std::string output_filename();
  237. std::string output_filepath(std::string path = "");
  238. void add_model_object(ModelObject* model_object, int idx = -1);
  239. bool apply_config(DynamicPrintConfig* config)
  240. %code%{ RETVAL = THIS->apply_config(*config); %};
  241. bool apply_static_config(StaticPrintConfig* config)
  242. %code%{
  243. DynamicPrintConfig dpc;
  244. dpc.apply(*config);
  245. RETVAL = THIS->apply_config(dpc);
  246. %};
  247. bool has_infinite_skirt();
  248. bool has_skirt();
  249. std::string _validate()
  250. %code%{
  251. try {
  252. THIS->validate();
  253. } catch (std::exception &e) {
  254. RETVAL = e.what();
  255. }
  256. %};
  257. Clone<BoundingBox> bounding_box();
  258. Clone<BoundingBox> total_bounding_box();
  259. double skirt_first_layer_height();
  260. Clone<Flow> brim_flow();
  261. Clone<Flow> skirt_flow();
  262. void make_skirt();
  263. void _make_brim();
  264. %{
  265. double
  266. Print::total_used_filament(...)
  267. CODE:
  268. if (items > 1) {
  269. THIS->total_used_filament = (double)SvNV(ST(1));
  270. }
  271. RETVAL = THIS->total_used_filament;
  272. OUTPUT:
  273. RETVAL
  274. double
  275. Print::total_extruded_volume(...)
  276. CODE:
  277. if (items > 1) {
  278. THIS->total_extruded_volume = (double)SvNV(ST(1));
  279. }
  280. RETVAL = THIS->total_extruded_volume;
  281. OUTPUT:
  282. RETVAL
  283. double
  284. Print::total_weight(...)
  285. CODE:
  286. if (items > 1) {
  287. THIS->total_weight = (double)SvNV(ST(1));
  288. }
  289. RETVAL = THIS->total_weight;
  290. OUTPUT:
  291. RETVAL
  292. double
  293. Print::total_cost(...)
  294. CODE:
  295. if (items > 1) {
  296. THIS->total_cost = (double)SvNV(ST(1));
  297. }
  298. RETVAL = THIS->total_cost;
  299. OUTPUT:
  300. RETVAL
  301. %}
  302. };