Print.xsp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. std::string estimated_print_time()
  131. %code%{ RETVAL = THIS->estimated_print_time; %};
  132. PrintObjectPtrs* objects()
  133. %code%{ RETVAL = &THIS->objects; %};
  134. void clear_objects();
  135. Ref<PrintObject> get_object(int idx);
  136. void delete_object(int idx);
  137. void reload_object(int idx);
  138. bool reload_model_instances();
  139. size_t object_count()
  140. %code%{ RETVAL = THIS->objects.size(); %};
  141. PrintRegionPtrs* regions()
  142. %code%{ RETVAL = &THIS->regions; %};
  143. Ref<PrintRegion> get_region(int idx);
  144. Ref<PrintRegion> add_region();
  145. size_t region_count()
  146. %code%{ RETVAL = THIS->regions.size(); %};
  147. bool step_done(PrintStep step)
  148. %code%{ RETVAL = THIS->state.is_done(step); %};
  149. bool object_step_done(PrintObjectStep step)
  150. %code%{ RETVAL = THIS->step_done(step); %};
  151. void set_step_done(PrintStep step)
  152. %code%{ THIS->state.set_done(step); %};
  153. void set_step_started(PrintStep step)
  154. %code%{ THIS->state.set_started(step); %};
  155. void clear_filament_stats()
  156. %code%{
  157. THIS->filament_stats.clear();
  158. %};
  159. void set_filament_stats(int extruder_id, float length)
  160. %code%{
  161. THIS->filament_stats.insert(std::pair<size_t,float>(extruder_id, 0));
  162. THIS->filament_stats[extruder_id] += length;
  163. %};
  164. SV* filament_stats()
  165. %code%{
  166. HV* hv = newHV();
  167. for (std::map<size_t,float>::const_iterator it = THIS->filament_stats.begin(); it != THIS->filament_stats.end(); ++it) {
  168. // stringify extruder_id
  169. std::ostringstream ss;
  170. ss << it->first;
  171. std::string str = ss.str();
  172. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  173. RETVAL = newRV_noinc((SV*)hv);
  174. }
  175. %};
  176. void _simplify_slices(double distance);
  177. double max_allowed_layer_height() const;
  178. bool has_support_material() const;
  179. void auto_assign_extruders(ModelObject* model_object);
  180. std::string output_filepath(std::string path = "")
  181. %code%{
  182. try {
  183. RETVAL = THIS->output_filepath(path);
  184. } catch (std::exception& e) {
  185. croak(e.what());
  186. }
  187. %};
  188. void add_model_object(ModelObject* model_object, int idx = -1);
  189. bool apply_config(DynamicPrintConfig* config)
  190. %code%{ RETVAL = THIS->apply_config(*config); %};
  191. bool has_infinite_skirt();
  192. bool has_skirt();
  193. std::vector<unsigned int> extruders() const;
  194. int validate() %code%{
  195. std::string err = THIS->validate();
  196. if (! err.empty())
  197. croak("Configuration is not valid: %s\n", err.c_str());
  198. RETVAL = 1;
  199. %};
  200. Clone<BoundingBox> bounding_box();
  201. Clone<BoundingBox> total_bounding_box();
  202. double skirt_first_layer_height();
  203. Clone<Flow> brim_flow();
  204. Clone<Flow> skirt_flow();
  205. void _make_skirt();
  206. void _make_brim();
  207. bool has_wipe_tower();
  208. void _clear_wipe_tower();
  209. void _make_wipe_tower();
  210. %{
  211. double
  212. Print::total_used_filament(...)
  213. CODE:
  214. if (items > 1) {
  215. THIS->total_used_filament = (double)SvNV(ST(1));
  216. }
  217. RETVAL = THIS->total_used_filament;
  218. OUTPUT:
  219. RETVAL
  220. double
  221. Print::total_extruded_volume(...)
  222. CODE:
  223. if (items > 1) {
  224. THIS->total_extruded_volume = (double)SvNV(ST(1));
  225. }
  226. RETVAL = THIS->total_extruded_volume;
  227. OUTPUT:
  228. RETVAL
  229. double
  230. Print::total_weight(...)
  231. CODE:
  232. if (items > 1) {
  233. THIS->total_weight = (double)SvNV(ST(1));
  234. }
  235. RETVAL = THIS->total_weight;
  236. OUTPUT:
  237. RETVAL
  238. double
  239. Print::total_cost(...)
  240. CODE:
  241. if (items > 1) {
  242. THIS->total_cost = (double)SvNV(ST(1));
  243. }
  244. RETVAL = THIS->total_cost;
  245. OUTPUT:
  246. RETVAL
  247. %}
  248. };