Print.xsp 9.5 KB

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