Print.xsp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. size_t support_layer_count();
  98. void clear_support_layers();
  99. Ref<SupportLayer> get_support_layer(int idx);
  100. Ref<SupportLayer> add_support_layer(int id, coordf_t height, coordf_t print_z);
  101. void delete_support_layer(int idx);
  102. bool invalidate_step(PrintObjectStep step);
  103. bool invalidate_all_steps();
  104. bool step_done(PrintObjectStep step)
  105. %code%{ RETVAL = THIS->state.is_done(step); %};
  106. void set_step_done(PrintObjectStep step)
  107. %code%{ THIS->state.set_done(step); %};
  108. void set_step_started(PrintObjectStep step)
  109. %code%{ THIS->state.set_started(step); %};
  110. %name{_detect_surfaces_type} void detect_surfaces_type();
  111. void process_external_surfaces();
  112. void bridge_over_infill();
  113. void _slice();
  114. SV* _slice_region(size_t region_id, std::vector<double> z, bool modifier)
  115. %code%{
  116. std::vector<float> z_f(z.begin(), z.end());
  117. std::vector<ExPolygons> layers = THIS->_slice_region(region_id, z_f, modifier);
  118. AV* layers_av = newAV();
  119. size_t len = layers.size();
  120. if (len > 0) av_extend(layers_av, len-1);
  121. for (unsigned int i = 0; i < layers.size(); i++) {
  122. AV* expolygons_av = newAV();
  123. len = layers[i].size();
  124. if (len > 0) av_extend(expolygons_av, len-1);
  125. unsigned int j = 0;
  126. for (ExPolygons::iterator it = layers[i].begin(); it != layers[i].end(); ++it) {
  127. av_store(expolygons_av, j++, perl_to_SV_clone_ref(*it));
  128. }
  129. av_store(layers_av, i, newRV_noinc((SV*)expolygons_av));
  130. }
  131. RETVAL = (SV*)newRV_noinc((SV*)layers_av);
  132. %};
  133. void _make_perimeters();
  134. void _infill();
  135. int ptr()
  136. %code%{ RETVAL = (int)(intptr_t)THIS; %};
  137. };
  138. %name{Slic3r::Print} class Print {
  139. Print();
  140. ~Print();
  141. Ref<StaticPrintConfig> config()
  142. %code%{ RETVAL = &THIS->config; %};
  143. Ref<StaticPrintConfig> default_object_config()
  144. %code%{ RETVAL = &THIS->default_object_config; %};
  145. Ref<StaticPrintConfig> default_region_config()
  146. %code%{ RETVAL = &THIS->default_region_config; %};
  147. Ref<PlaceholderParser> placeholder_parser()
  148. %code%{ RETVAL = &THIS->placeholder_parser; %};
  149. // TODO: status_cb
  150. Ref<ExtrusionEntityCollection> skirt()
  151. %code%{ RETVAL = &THIS->skirt; %};
  152. Ref<ExtrusionEntityCollection> brim()
  153. %code%{ RETVAL = &THIS->brim; %};
  154. PrintObjectPtrs* objects()
  155. %code%{ RETVAL = &THIS->objects; %};
  156. void clear_objects();
  157. Ref<PrintObject> get_object(int idx);
  158. void delete_object(int idx);
  159. void reload_object(int idx);
  160. bool reload_model_instances();
  161. size_t object_count()
  162. %code%{ RETVAL = THIS->objects.size(); %};
  163. PrintRegionPtrs* regions()
  164. %code%{ RETVAL = &THIS->regions; %};
  165. Ref<PrintRegion> get_region(int idx);
  166. Ref<PrintRegion> add_region();
  167. size_t region_count()
  168. %code%{ RETVAL = THIS->regions.size(); %};
  169. bool invalidate_step(PrintStep step);
  170. bool invalidate_all_steps();
  171. bool step_done(PrintStep step)
  172. %code%{ RETVAL = THIS->state.is_done(step); %};
  173. bool object_step_done(PrintObjectStep step)
  174. %code%{ RETVAL = THIS->step_done(step); %};
  175. void set_step_done(PrintStep step)
  176. %code%{ THIS->state.set_done(step); %};
  177. void set_step_started(PrintStep step)
  178. %code%{ THIS->state.set_started(step); %};
  179. std::vector<int> object_extruders()
  180. %code%{
  181. std::set<size_t> extruders = THIS->object_extruders();
  182. RETVAL.reserve(extruders.size());
  183. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  184. RETVAL.push_back(*e);
  185. }
  186. %};
  187. std::vector<int> support_material_extruders()
  188. %code%{
  189. std::set<size_t> extruders = THIS->support_material_extruders();
  190. RETVAL.reserve(extruders.size());
  191. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  192. RETVAL.push_back(*e);
  193. }
  194. %};
  195. std::vector<int> extruders()
  196. %code%{
  197. std::set<size_t> extruders = THIS->extruders();
  198. RETVAL.reserve(extruders.size());
  199. for (std::set<size_t>::const_iterator e = extruders.begin(); e != extruders.end(); ++e) {
  200. RETVAL.push_back(*e);
  201. }
  202. %};
  203. int brim_extruder();
  204. void clear_filament_stats()
  205. %code%{
  206. THIS->filament_stats.clear();
  207. %};
  208. void set_filament_stats(int extruder_id, float length)
  209. %code%{
  210. THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
  211. THIS->filament_stats[extruder_id] += length;
  212. %};
  213. SV* filament_stats()
  214. %code%{
  215. HV* hv = newHV();
  216. for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
  217. // stringify extruder_id
  218. std::ostringstream ss;
  219. ss << it->first;
  220. std::string str = ss.str();
  221. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  222. RETVAL = newRV_noinc((SV*)hv);
  223. }
  224. %};
  225. void _simplify_slices(double distance);
  226. double max_allowed_layer_height() const;
  227. bool has_support_material() const;
  228. void auto_assign_extruders(ModelObject* model_object);
  229. std::string output_filename();
  230. std::string output_filepath(std::string path = "");
  231. void add_model_object(ModelObject* model_object, int idx = -1);
  232. bool apply_config(DynamicPrintConfig* config)
  233. %code%{ RETVAL = THIS->apply_config(*config); %};
  234. bool apply_static_config(StaticPrintConfig* config)
  235. %code%{
  236. DynamicPrintConfig dpc;
  237. dpc.apply(*config);
  238. RETVAL = THIS->apply_config(dpc);
  239. %};
  240. bool has_infinite_skirt();
  241. bool has_skirt();
  242. std::string _validate()
  243. %code%{ RETVAL = THIS->validate(); %};
  244. Clone<BoundingBox> bounding_box();
  245. Clone<BoundingBox> total_bounding_box();
  246. double skirt_first_layer_height();
  247. Clone<Flow> brim_flow();
  248. Clone<Flow> skirt_flow();
  249. void _make_brim();
  250. %{
  251. double
  252. Print::total_used_filament(...)
  253. CODE:
  254. if (items > 1) {
  255. THIS->total_used_filament = (double)SvNV(ST(1));
  256. }
  257. RETVAL = THIS->total_used_filament;
  258. OUTPUT:
  259. RETVAL
  260. double
  261. Print::total_extruded_volume(...)
  262. CODE:
  263. if (items > 1) {
  264. THIS->total_extruded_volume = (double)SvNV(ST(1));
  265. }
  266. RETVAL = THIS->total_extruded_volume;
  267. OUTPUT:
  268. RETVAL
  269. double
  270. Print::total_weight(...)
  271. CODE:
  272. if (items > 1) {
  273. THIS->total_weight = (double)SvNV(ST(1));
  274. }
  275. RETVAL = THIS->total_weight;
  276. OUTPUT:
  277. RETVAL
  278. double
  279. Print::total_cost(...)
  280. CODE:
  281. if (items > 1) {
  282. THIS->total_cost = (double)SvNV(ST(1));
  283. }
  284. RETVAL = THIS->total_cost;
  285. OUTPUT:
  286. RETVAL
  287. %}
  288. };