Print.xsp 5.9 KB

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