Print.xsp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. bool step_done(PrintObjectStep step)
  79. %code%{ RETVAL = THIS->state.is_done(step); %};
  80. void set_step_done(PrintObjectStep step)
  81. %code%{ THIS->state.set_done(step); %};
  82. void set_step_started(PrintObjectStep step)
  83. %code%{ THIS->state.set_started(step); %};
  84. void _slice();
  85. std::string _fix_slicing_errors();
  86. void _simplify_slices(double distance);
  87. void _prepare_infill();
  88. void detect_surfaces_type();
  89. void process_external_surfaces();
  90. void _make_perimeters();
  91. void _infill();
  92. void _generate_support_material();
  93. std::vector<double> get_layer_height_min_max()
  94. %code%{
  95. SlicingParameters slicing_params = THIS->slicing_parameters();
  96. RETVAL.push_back(slicing_params.min_layer_height);
  97. RETVAL.push_back(slicing_params.max_layer_height);
  98. RETVAL.push_back(slicing_params.first_print_layer_height);
  99. RETVAL.push_back(slicing_params.first_object_layer_height);
  100. RETVAL.push_back(slicing_params.layer_height);
  101. %};
  102. void adjust_layer_height_profile(coordf_t z, coordf_t layer_thickness_delta, coordf_t band_width, int action)
  103. %code%{
  104. THIS->update_layer_height_profile(THIS->model_object()->layer_height_profile);
  105. adjust_layer_height_profile(
  106. THIS->slicing_parameters(), THIS->model_object()->layer_height_profile, z, layer_thickness_delta, band_width, LayerHeightEditActionType(action));
  107. THIS->model_object()->layer_height_profile_valid = true;
  108. THIS->layer_height_profile_valid = false;
  109. %};
  110. void reset_layer_height_profile();
  111. int ptr()
  112. %code%{ RETVAL = (int)(intptr_t)THIS; %};
  113. };
  114. %name{Slic3r::Print} class Print {
  115. Print();
  116. ~Print();
  117. Ref<StaticPrintConfig> config()
  118. %code%{ RETVAL = &THIS->config; %};
  119. Ref<StaticPrintConfig> default_object_config()
  120. %code%{ RETVAL = &THIS->default_object_config; %};
  121. Ref<StaticPrintConfig> default_region_config()
  122. %code%{ RETVAL = &THIS->default_region_config; %};
  123. Ref<PlaceholderParser> placeholder_parser()
  124. %code%{ RETVAL = &THIS->placeholder_parser; %};
  125. // TODO: status_cb
  126. Ref<ExtrusionEntityCollection> skirt()
  127. %code%{ RETVAL = &THIS->skirt; %};
  128. Ref<ExtrusionEntityCollection> brim()
  129. %code%{ RETVAL = &THIS->brim; %};
  130. PrintObjectPtrs* objects()
  131. %code%{ RETVAL = &THIS->objects; %};
  132. void clear_objects();
  133. Ref<PrintObject> get_object(int idx);
  134. void delete_object(int idx);
  135. void reload_object(int idx);
  136. bool reload_model_instances();
  137. size_t object_count()
  138. %code%{ RETVAL = THIS->objects.size(); %};
  139. PrintRegionPtrs* regions()
  140. %code%{ RETVAL = &THIS->regions; %};
  141. Ref<PrintRegion> get_region(int idx);
  142. Ref<PrintRegion> add_region();
  143. size_t region_count()
  144. %code%{ RETVAL = THIS->regions.size(); %};
  145. bool step_done(PrintStep step)
  146. %code%{ RETVAL = THIS->state.is_done(step); %};
  147. bool object_step_done(PrintObjectStep step)
  148. %code%{ RETVAL = THIS->step_done(step); %};
  149. void set_step_done(PrintStep step)
  150. %code%{ THIS->state.set_done(step); %};
  151. void set_step_started(PrintStep step)
  152. %code%{ THIS->state.set_started(step); %};
  153. void clear_filament_stats()
  154. %code%{
  155. THIS->filament_stats.clear();
  156. %};
  157. void set_filament_stats(int extruder_id, float length)
  158. %code%{
  159. THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
  160. THIS->filament_stats[extruder_id] += length;
  161. %};
  162. SV* filament_stats()
  163. %code%{
  164. HV* hv = newHV();
  165. for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
  166. // stringify extruder_id
  167. std::ostringstream ss;
  168. ss << it->first;
  169. std::string str = ss.str();
  170. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  171. RETVAL = newRV_noinc((SV*)hv);
  172. }
  173. %};
  174. void _simplify_slices(double distance);
  175. double max_allowed_layer_height() const;
  176. bool has_support_material() const;
  177. void auto_assign_extruders(ModelObject* model_object);
  178. std::string output_filepath(std::string path = "")
  179. %code%{
  180. try {
  181. RETVAL = THIS->output_filepath(path);
  182. } catch (std::exception& e) {
  183. croak(e.what());
  184. }
  185. %};
  186. void add_model_object(ModelObject* model_object, int idx = -1);
  187. bool apply_config(DynamicPrintConfig* config)
  188. %code%{ RETVAL = THIS->apply_config(*config); %};
  189. bool has_infinite_skirt();
  190. bool has_skirt();
  191. std::vector<unsigned int> extruders() const;
  192. int validate() %code%{
  193. std::string err = THIS->validate();
  194. if (! err.empty())
  195. croak("Configuration is not valid: %s\n", err.c_str());
  196. RETVAL = 1;
  197. %};
  198. Clone<BoundingBox> bounding_box();
  199. Clone<BoundingBox> total_bounding_box();
  200. double skirt_first_layer_height();
  201. Clone<Flow> brim_flow();
  202. Clone<Flow> skirt_flow();
  203. void _make_skirt();
  204. void _make_brim();
  205. bool has_wipe_tower();
  206. void _clear_wipe_tower();
  207. void _make_wipe_tower();
  208. %{
  209. double
  210. Print::total_used_filament(...)
  211. CODE:
  212. if (items > 1) {
  213. THIS->total_used_filament = (double)SvNV(ST(1));
  214. }
  215. RETVAL = THIS->total_used_filament;
  216. OUTPUT:
  217. RETVAL
  218. double
  219. Print::total_extruded_volume(...)
  220. CODE:
  221. if (items > 1) {
  222. THIS->total_extruded_volume = (double)SvNV(ST(1));
  223. }
  224. RETVAL = THIS->total_extruded_volume;
  225. OUTPUT:
  226. RETVAL
  227. double
  228. Print::total_weight(...)
  229. CODE:
  230. if (items > 1) {
  231. THIS->total_weight = (double)SvNV(ST(1));
  232. }
  233. RETVAL = THIS->total_weight;
  234. OUTPUT:
  235. RETVAL
  236. double
  237. Print::total_cost(...)
  238. CODE:
  239. if (items > 1) {
  240. THIS->total_cost = (double)SvNV(ST(1));
  241. }
  242. RETVAL = THIS->total_cost;
  243. OUTPUT:
  244. RETVAL
  245. %}
  246. };