Print.xsp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. Ref<Print> print();
  44. Ref<ModelObject> model_object();
  45. Ref<StaticPrintConfig> config()
  46. %code%{ RETVAL = &THIS->config; %};
  47. Points copies();
  48. t_layer_height_ranges layer_height_ranges()
  49. %code%{ RETVAL = THIS->layer_height_ranges; %};
  50. std::vector<double> layer_height_profile()
  51. %code%{ RETVAL = THIS->layer_height_profile; %};
  52. Ref<Point3> size()
  53. %code%{ RETVAL = &THIS->size; %};
  54. Clone<BoundingBox> bounding_box();
  55. Points _shifted_copies()
  56. %code%{ RETVAL = THIS->_shifted_copies; %};
  57. void set_shifted_copies(Points value)
  58. %code%{ THIS->_shifted_copies = value; %};
  59. bool add_copy(Pointf* point)
  60. %code%{ RETVAL = THIS->add_copy(*point); %};
  61. bool delete_last_copy();
  62. bool delete_all_copies();
  63. bool set_copies(Points copies);
  64. bool reload_model_instances();
  65. void set_layer_height_ranges(t_layer_height_ranges layer_height_ranges)
  66. %code%{ THIS->layer_height_ranges = layer_height_ranges; %};
  67. void set_layer_height_profile(std::vector<double> profile)
  68. %code%{ THIS->layer_height_profile = profile; %};
  69. size_t total_layer_count();
  70. size_t layer_count();
  71. void clear_layers();
  72. Ref<Layer> get_layer(int idx);
  73. Ref<Layer> add_layer(int id, coordf_t height, coordf_t print_z,
  74. coordf_t slice_z);
  75. size_t support_layer_count();
  76. void clear_support_layers();
  77. Ref<SupportLayer> get_support_layer(int idx);
  78. Ref<SupportLayer> add_support_layer(int id, coordf_t height, coordf_t print_z);
  79. bool step_done(PrintObjectStep step)
  80. %code%{ RETVAL = THIS->state.is_done(step); %};
  81. void set_step_done(PrintObjectStep step)
  82. %code%{ THIS->state.set_done(step); %};
  83. void set_step_started(PrintObjectStep step)
  84. %code%{ THIS->state.set_started(step); %};
  85. void _slice();
  86. std::string _fix_slicing_errors();
  87. void _simplify_slices(double distance);
  88. void _prepare_infill();
  89. void detect_surfaces_type();
  90. void process_external_surfaces();
  91. void _make_perimeters();
  92. void _infill();
  93. void _generate_support_material();
  94. std::vector<double> get_layer_height_min_max()
  95. %code%{
  96. SlicingParameters slicing_params = THIS->slicing_parameters();
  97. RETVAL.push_back(slicing_params.min_layer_height);
  98. RETVAL.push_back(slicing_params.max_layer_height);
  99. RETVAL.push_back(slicing_params.first_print_layer_height);
  100. RETVAL.push_back(slicing_params.first_object_layer_height);
  101. RETVAL.push_back(slicing_params.layer_height);
  102. %};
  103. void adjust_layer_height_profile(coordf_t z, coordf_t layer_thickness_delta, coordf_t band_width, int action)
  104. %code%{
  105. THIS->update_layer_height_profile(THIS->model_object()->layer_height_profile);
  106. adjust_layer_height_profile(
  107. THIS->slicing_parameters(), THIS->model_object()->layer_height_profile, z, layer_thickness_delta, band_width, LayerHeightEditActionType(action));
  108. THIS->model_object()->layer_height_profile_valid = true;
  109. THIS->layer_height_profile_valid = false;
  110. %};
  111. void reset_layer_height_profile();
  112. int ptr()
  113. %code%{ RETVAL = (int)(intptr_t)THIS; %};
  114. };
  115. %name{Slic3r::Print} class Print {
  116. Print();
  117. ~Print();
  118. Ref<StaticPrintConfig> config()
  119. %code%{ RETVAL = &THIS->config; %};
  120. Ref<StaticPrintConfig> default_object_config()
  121. %code%{ RETVAL = &THIS->default_object_config; %};
  122. Ref<StaticPrintConfig> default_region_config()
  123. %code%{ RETVAL = &THIS->default_region_config; %};
  124. Ref<PlaceholderParser> placeholder_parser()
  125. %code%{ RETVAL = &THIS->placeholder_parser; %};
  126. // TODO: status_cb
  127. Ref<ExtrusionEntityCollection> skirt()
  128. %code%{ RETVAL = &THIS->skirt; %};
  129. Ref<ExtrusionEntityCollection> brim()
  130. %code%{ RETVAL = &THIS->brim; %};
  131. PrintObjectPtrs* objects()
  132. %code%{ RETVAL = &THIS->objects; %};
  133. void clear_objects();
  134. Ref<PrintObject> get_object(int idx);
  135. void delete_object(int idx);
  136. void reload_object(int idx);
  137. bool reload_model_instances();
  138. size_t object_count()
  139. %code%{ RETVAL = THIS->objects.size(); %};
  140. PrintRegionPtrs* regions()
  141. %code%{ RETVAL = &THIS->regions; %};
  142. Ref<PrintRegion> get_region(int idx);
  143. Ref<PrintRegion> add_region();
  144. size_t region_count()
  145. %code%{ RETVAL = THIS->regions.size(); %};
  146. bool step_done(PrintStep step)
  147. %code%{ RETVAL = THIS->state.is_done(step); %};
  148. bool object_step_done(PrintObjectStep step)
  149. %code%{ RETVAL = THIS->step_done(step); %};
  150. void set_step_done(PrintStep step)
  151. %code%{ THIS->state.set_done(step); %};
  152. void set_step_started(PrintStep step)
  153. %code%{ THIS->state.set_started(step); %};
  154. void clear_filament_stats()
  155. %code%{
  156. THIS->filament_stats.clear();
  157. %};
  158. void set_filament_stats(int extruder_id, float length)
  159. %code%{
  160. THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
  161. THIS->filament_stats[extruder_id] += length;
  162. %};
  163. SV* filament_stats()
  164. %code%{
  165. HV* hv = newHV();
  166. for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
  167. // stringify extruder_id
  168. std::ostringstream ss;
  169. ss << it->first;
  170. std::string str = ss.str();
  171. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  172. RETVAL = newRV_noinc((SV*)hv);
  173. }
  174. %};
  175. void _simplify_slices(double distance);
  176. double max_allowed_layer_height() const;
  177. bool has_support_material() const;
  178. void auto_assign_extruders(ModelObject* model_object);
  179. std::string output_filename();
  180. std::string output_filepath(std::string path = "");
  181. void add_model_object(ModelObject* model_object, int idx = -1);
  182. bool apply_config(DynamicPrintConfig* config)
  183. %code%{ RETVAL = THIS->apply_config(*config); %};
  184. bool has_infinite_skirt();
  185. bool has_skirt();
  186. std::vector<unsigned int> extruders() const;
  187. std::string _validate()
  188. %code%{ RETVAL = THIS->validate(); %};
  189. Clone<BoundingBox> bounding_box();
  190. Clone<BoundingBox> total_bounding_box();
  191. double skirt_first_layer_height();
  192. Clone<Flow> brim_flow();
  193. Clone<Flow> skirt_flow();
  194. void _make_skirt();
  195. void _make_brim();
  196. bool has_wipe_tower();
  197. void _clear_wipe_tower();
  198. void _make_wipe_tower();
  199. %{
  200. double
  201. Print::total_used_filament(...)
  202. CODE:
  203. if (items > 1) {
  204. THIS->total_used_filament = (double)SvNV(ST(1));
  205. }
  206. RETVAL = THIS->total_used_filament;
  207. OUTPUT:
  208. RETVAL
  209. double
  210. Print::total_extruded_volume(...)
  211. CODE:
  212. if (items > 1) {
  213. THIS->total_extruded_volume = (double)SvNV(ST(1));
  214. }
  215. RETVAL = THIS->total_extruded_volume;
  216. OUTPUT:
  217. RETVAL
  218. double
  219. Print::total_weight(...)
  220. CODE:
  221. if (items > 1) {
  222. THIS->total_weight = (double)SvNV(ST(1));
  223. }
  224. RETVAL = THIS->total_weight;
  225. OUTPUT:
  226. RETVAL
  227. double
  228. Print::total_cost(...)
  229. CODE:
  230. if (items > 1) {
  231. THIS->total_cost = (double)SvNV(ST(1));
  232. }
  233. RETVAL = THIS->total_cost;
  234. OUTPUT:
  235. RETVAL
  236. %}
  237. };