Print.xsp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. int region_count()
  36. %code%{ RETVAL = THIS->print()->regions().size(); %};
  37. Ref<Print> print();
  38. Ref<ModelObject> model_object();
  39. Ref<StaticPrintConfig> config()
  40. %code%{ RETVAL = &THIS->config(); %};
  41. Points copies();
  42. Clone<BoundingBox> bounding_box();
  43. Points _shifted_copies()
  44. %code%{ RETVAL = THIS->copies(); %};
  45. size_t layer_count();
  46. Ref<Layer> get_layer(int idx);
  47. size_t support_layer_count();
  48. Ref<SupportLayer> get_support_layer(int idx);
  49. bool step_done(PrintObjectStep step)
  50. %code%{ RETVAL = THIS->is_step_done(step); %};
  51. void slice();
  52. };
  53. %name{Slic3r::Print} class Print {
  54. Print();
  55. ~Print();
  56. Ref<Model> model()
  57. %code%{ RETVAL = const_cast<Model*>(&THIS->model()); %};
  58. Ref<StaticPrintConfig> config()
  59. %code%{ RETVAL = const_cast<GCodeConfig*>(static_cast<const GCodeConfig*>(&THIS->config())); %};
  60. Ref<PlaceholderParser> placeholder_parser()
  61. %code%{ RETVAL = const_cast<PlaceholderParser*>(&THIS->placeholder_parser()); %};
  62. Ref<ExtrusionEntityCollection> skirt()
  63. %code%{ RETVAL = const_cast<ExtrusionEntityCollection*>(&THIS->skirt()); %};
  64. Ref<ExtrusionEntityCollection> brim()
  65. %code%{ RETVAL = const_cast<ExtrusionEntityCollection*>(&THIS->brim()); %};
  66. std::string estimated_normal_print_time()
  67. %code%{ RETVAL = THIS->print_statistics().estimated_normal_print_time; %};
  68. std::string estimated_silent_print_time()
  69. %code%{ RETVAL = THIS->print_statistics().estimated_silent_print_time; %};
  70. double total_used_filament()
  71. %code%{ RETVAL = THIS->print_statistics().total_used_filament; %};
  72. double total_extruded_volume()
  73. %code%{ RETVAL = THIS->print_statistics().total_extruded_volume; %};
  74. double total_weight()
  75. %code%{ RETVAL = THIS->print_statistics().total_weight; %};
  76. double total_cost()
  77. %code%{ RETVAL = THIS->print_statistics().total_cost; %};
  78. double total_wipe_tower_cost()
  79. %code%{ RETVAL = THIS->print_statistics().total_wipe_tower_cost; %};
  80. double total_wipe_tower_filament()
  81. %code%{ RETVAL = THIS->print_statistics().total_wipe_tower_filament; %};
  82. int wipe_tower_number_of_toolchanges()
  83. %code%{ RETVAL = THIS->wipe_tower_data().number_of_toolchanges; %};
  84. PrintObjectPtrs* objects()
  85. %code%{ RETVAL = const_cast<PrintObjectPtrs*>(&THIS->objects()); %};
  86. Ref<PrintObject> get_object(int idx)
  87. %code%{ RETVAL = THIS->objects()[idx]; %};
  88. size_t object_count()
  89. %code%{ RETVAL = THIS->objects().size(); %};
  90. PrintRegionPtrs* regions()
  91. %code%{ RETVAL = const_cast<PrintRegionPtrs*>(&THIS->regions()); %};
  92. Ref<PrintRegion> get_region(int idx)
  93. %code%{ RETVAL = THIS->regions()[idx]; %};
  94. size_t region_count()
  95. %code%{ RETVAL = THIS->regions().size(); %};
  96. bool step_done(PrintStep step)
  97. %code%{ RETVAL = THIS->is_step_done(step); %};
  98. bool object_step_done(PrintObjectStep step)
  99. %code%{ RETVAL = THIS->is_step_done(step); %};
  100. SV* filament_stats()
  101. %code%{
  102. HV* hv = newHV();
  103. for (std::map<size_t,float>::const_iterator it = THIS->print_statistics().filament_stats.begin(); it != THIS->print_statistics().filament_stats.end(); ++it) {
  104. // stringify extruder_id
  105. std::ostringstream ss;
  106. ss << it->first;
  107. std::string str = ss.str();
  108. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  109. RETVAL = newRV_noinc((SV*)hv);
  110. }
  111. %};
  112. double max_allowed_layer_height() const;
  113. bool has_support_material() const;
  114. void auto_assign_extruders(ModelObject* model_object);
  115. std::string output_filepath(std::string path = "")
  116. %code%{
  117. try {
  118. RETVAL = THIS->output_filepath(path);
  119. } catch (std::exception& e) {
  120. croak("%s\n", e.what());
  121. }
  122. %};
  123. bool apply(Model *model, DynamicPrintConfig* config)
  124. %code%{ RETVAL = THIS->apply(*model, *config); %};
  125. bool has_infinite_skirt();
  126. std::vector<unsigned int> extruders() const;
  127. int validate() %code%{
  128. std::string err = THIS->validate();
  129. if (! err.empty())
  130. croak("Configuration is not valid: %s\n", err.c_str());
  131. RETVAL = 1;
  132. %};
  133. Clone<BoundingBox> bounding_box();
  134. Clone<BoundingBox> total_bounding_box();
  135. Clone<Point> size() %code%{ RETVAL = THIS->bounding_box().size(); %};
  136. void set_callback_event(int evt) %code%{
  137. %};
  138. void set_status_silent();
  139. void set_status(int percent, const char *message);
  140. void process() %code%{
  141. try {
  142. THIS->process();
  143. } catch (std::exception& e) {
  144. croak("%s\n", e.what());
  145. }
  146. %};
  147. void export_gcode(char *path_template) %code%{
  148. try {
  149. THIS->export_gcode(path_template, nullptr);
  150. } catch (std::exception& e) {
  151. croak("%s\n", e.what());
  152. }
  153. %};
  154. };