Print.xsp 6.2 KB

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