Print.xsp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_SLICE = posSlice
  13. STEP_PERIMETERS = posPerimeters
  14. STEP_PREPARE_INFILL = posPrepareInfill
  15. STEP_INFILL = posInfill
  16. STEP_SUPPORTMATERIAL = posSupportMaterial
  17. STEP_SKIRT = psSkirt
  18. STEP_BRIM = psBrim
  19. STEP_WIPE_TOWER = psWipeTower
  20. PROTOTYPE:
  21. CODE:
  22. RETVAL = ix;
  23. OUTPUT: RETVAL
  24. %}
  25. %name{Slic3r::Print::Region} class PrintRegion {
  26. // owned by Print, no constructor/destructor
  27. Ref<StaticPrintConfig> config()
  28. %code%{ RETVAL = &THIS->config; %};
  29. Ref<Print> print();
  30. Clone<Flow> flow(FlowRole role, double layer_height, bool bridge, bool first_layer, double width, PrintObject* object)
  31. %code%{ RETVAL = THIS->flow(role, layer_height, bridge, first_layer, width, *object); %};
  32. };
  33. %name{Slic3r::Print::Object} class PrintObject {
  34. // owned by Print, no constructor/destructor
  35. void add_region_volume(int region_id, int volume_id);
  36. std::vector<int> get_region_volumes(int region_id)
  37. %code%{
  38. if (0 <= region_id && region_id < THIS->region_volumes.size())
  39. RETVAL = THIS->region_volumes[region_id];
  40. %};
  41. int region_count()
  42. %code%{ RETVAL = THIS->print()->regions.size(); %};
  43. int region_volumes_count()
  44. %code%{ RETVAL = THIS->region_volumes.size(); %};
  45. Ref<Print> print();
  46. Ref<ModelObject> model_object();
  47. Ref<StaticPrintConfig> config()
  48. %code%{ RETVAL = &THIS->config; %};
  49. Points copies();
  50. t_layer_height_ranges layer_height_ranges()
  51. %code%{ RETVAL = THIS->layer_height_ranges; %};
  52. std::vector<double> layer_height_profile()
  53. %code%{ RETVAL = THIS->layer_height_profile; %};
  54. Ref<Point3> size()
  55. %code%{ RETVAL = &THIS->size; %};
  56. Clone<BoundingBox> bounding_box();
  57. Points _shifted_copies()
  58. %code%{ RETVAL = THIS->_shifted_copies; %};
  59. void set_shifted_copies(Points value)
  60. %code%{ THIS->_shifted_copies = value; %};
  61. bool add_copy(Pointf* point)
  62. %code%{ RETVAL = THIS->add_copy(*point); %};
  63. bool delete_last_copy();
  64. bool delete_all_copies();
  65. bool set_copies(Points copies);
  66. bool reload_model_instances();
  67. void set_layer_height_ranges(t_layer_height_ranges layer_height_ranges)
  68. %code%{ THIS->layer_height_ranges = layer_height_ranges; %};
  69. void set_layer_height_profile(std::vector<double> profile)
  70. %code%{ THIS->layer_height_profile = profile; %};
  71. size_t total_layer_count();
  72. size_t layer_count();
  73. void clear_layers();
  74. Ref<Layer> get_layer(int idx);
  75. Ref<Layer> add_layer(int id, coordf_t height, coordf_t print_z,
  76. coordf_t slice_z);
  77. size_t support_layer_count();
  78. void clear_support_layers();
  79. Ref<SupportLayer> get_support_layer(int idx);
  80. bool step_done(PrintObjectStep step)
  81. %code%{ RETVAL = THIS->state.is_done(step); %};
  82. void set_step_done(PrintObjectStep step)
  83. %code%{ THIS->state.set_done(step); %};
  84. void set_step_started(PrintObjectStep step)
  85. %code%{ THIS->state.set_started(step); %};
  86. void _slice();
  87. std::string _fix_slicing_errors();
  88. void _simplify_slices(double distance);
  89. void _prepare_infill();
  90. void detect_surfaces_type();
  91. void process_external_surfaces();
  92. void _make_perimeters();
  93. void _infill();
  94. void _generate_support_material();
  95. std::vector<double> get_layer_height_min_max()
  96. %code%{
  97. SlicingParameters slicing_params = THIS->slicing_parameters();
  98. RETVAL.push_back(slicing_params.min_layer_height);
  99. RETVAL.push_back(slicing_params.max_layer_height);
  100. RETVAL.push_back(slicing_params.first_print_layer_height);
  101. RETVAL.push_back(slicing_params.first_object_layer_height);
  102. RETVAL.push_back(slicing_params.layer_height);
  103. %};
  104. void reset_layer_height_profile();
  105. int ptr()
  106. %code%{ RETVAL = (int)(intptr_t)THIS; %};
  107. };
  108. %name{Slic3r::Print} class Print {
  109. Print();
  110. ~Print();
  111. Ref<StaticPrintConfig> config()
  112. %code%{ RETVAL = &THIS->config; %};
  113. Ref<StaticPrintConfig> default_object_config()
  114. %code%{ RETVAL = &THIS->default_object_config; %};
  115. Ref<StaticPrintConfig> default_region_config()
  116. %code%{ RETVAL = &THIS->default_region_config; %};
  117. Ref<PlaceholderParser> placeholder_parser()
  118. %code%{ RETVAL = &THIS->placeholder_parser; %};
  119. // TODO: status_cb
  120. Ref<ExtrusionEntityCollection> skirt()
  121. %code%{ RETVAL = &THIS->skirt; %};
  122. Ref<ExtrusionEntityCollection> brim()
  123. %code%{ RETVAL = &THIS->brim; %};
  124. std::string estimated_print_time()
  125. %code%{ RETVAL = THIS->estimated_print_time; %};
  126. PrintObjectPtrs* objects()
  127. %code%{ RETVAL = &THIS->objects; %};
  128. void clear_objects();
  129. Ref<PrintObject> get_object(int idx);
  130. void delete_object(int idx);
  131. void reload_object(int idx);
  132. bool reload_model_instances();
  133. size_t object_count()
  134. %code%{ RETVAL = THIS->objects.size(); %};
  135. PrintRegionPtrs* regions()
  136. %code%{ RETVAL = &THIS->regions; %};
  137. Ref<PrintRegion> get_region(int idx);
  138. Ref<PrintRegion> add_region();
  139. size_t region_count()
  140. %code%{ RETVAL = THIS->regions.size(); %};
  141. bool step_done(PrintStep step)
  142. %code%{ RETVAL = THIS->state.is_done(step); %};
  143. bool object_step_done(PrintObjectStep step)
  144. %code%{ RETVAL = THIS->step_done(step); %};
  145. void set_step_done(PrintStep step)
  146. %code%{ THIS->state.set_done(step); %};
  147. void set_step_started(PrintStep step)
  148. %code%{ THIS->state.set_started(step); %};
  149. void clear_filament_stats()
  150. %code%{
  151. THIS->filament_stats.clear();
  152. %};
  153. void set_filament_stats(int extruder_id, float length)
  154. %code%{
  155. THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
  156. THIS->filament_stats[extruder_id] += length;
  157. %};
  158. SV* filament_stats()
  159. %code%{
  160. HV* hv = newHV();
  161. for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
  162. // stringify extruder_id
  163. std::ostringstream ss;
  164. ss << it->first;
  165. std::string str = ss.str();
  166. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  167. RETVAL = newRV_noinc((SV*)hv);
  168. }
  169. %};
  170. void _simplify_slices(double distance);
  171. double max_allowed_layer_height() const;
  172. bool has_support_material() const;
  173. void auto_assign_extruders(ModelObject* model_object);
  174. std::string output_filepath(std::string path = "")
  175. %code%{
  176. try {
  177. RETVAL = THIS->output_filepath(path);
  178. } catch (std::exception& e) {
  179. croak("%s\n", e.what());
  180. }
  181. %};
  182. void add_model_object(ModelObject* model_object, int idx = -1);
  183. bool apply_config(DynamicPrintConfig* config)
  184. %code%{ RETVAL = THIS->apply_config(*config); %};
  185. bool has_infinite_skirt();
  186. bool has_skirt();
  187. std::vector<unsigned int> extruders() const;
  188. int validate() %code%{
  189. std::string err = THIS->validate();
  190. if (! err.empty())
  191. croak("Configuration is not valid: %s\n", err.c_str());
  192. RETVAL = 1;
  193. %};
  194. Clone<BoundingBox> bounding_box();
  195. Clone<BoundingBox> total_bounding_box();
  196. double skirt_first_layer_height();
  197. Clone<Flow> brim_flow();
  198. Clone<Flow> skirt_flow();
  199. void _make_skirt();
  200. void _make_brim();
  201. bool has_wipe_tower();
  202. void _clear_wipe_tower();
  203. void _make_wipe_tower();
  204. %{
  205. double
  206. Print::total_used_filament(...)
  207. CODE:
  208. if (items > 1) {
  209. THIS->total_used_filament = (double)SvNV(ST(1));
  210. }
  211. RETVAL = THIS->total_used_filament;
  212. OUTPUT:
  213. RETVAL
  214. double
  215. Print::total_extruded_volume(...)
  216. CODE:
  217. if (items > 1) {
  218. THIS->total_extruded_volume = (double)SvNV(ST(1));
  219. }
  220. RETVAL = THIS->total_extruded_volume;
  221. OUTPUT:
  222. RETVAL
  223. double
  224. Print::total_weight(...)
  225. CODE:
  226. if (items > 1) {
  227. THIS->total_weight = (double)SvNV(ST(1));
  228. }
  229. RETVAL = THIS->total_weight;
  230. OUTPUT:
  231. RETVAL
  232. double
  233. Print::total_cost(...)
  234. CODE:
  235. if (items > 1) {
  236. THIS->total_cost = (double)SvNV(ST(1));
  237. }
  238. RETVAL = THIS->total_cost;
  239. OUTPUT:
  240. RETVAL
  241. %}
  242. };