Print.xsp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. Clone<BoundingBox> bounding_box();
  42. size_t layer_count();
  43. Ref<Layer> get_layer(int idx);
  44. size_t support_layer_count();
  45. Ref<SupportLayer> get_support_layer(int idx);
  46. bool step_done(PrintObjectStep step)
  47. %code%{ RETVAL = THIS->is_step_done(step); %};
  48. void slice();
  49. };
  50. %name{Slic3r::Print} class Print {
  51. Print();
  52. ~Print();
  53. Ref<Model> model()
  54. %code%{ RETVAL = const_cast<Model*>(&THIS->model()); %};
  55. Ref<StaticPrintConfig> config()
  56. %code%{ RETVAL = const_cast<GCodeConfig*>(static_cast<const GCodeConfig*>(&THIS->config())); %};
  57. Ref<PlaceholderParser> placeholder_parser()
  58. %code%{ RETVAL = const_cast<PlaceholderParser*>(&THIS->placeholder_parser()); %};
  59. Ref<ExtrusionEntityCollection> skirt()
  60. %code%{ RETVAL = const_cast<ExtrusionEntityCollection*>(&THIS->skirt()); %};
  61. Ref<ExtrusionEntityCollection> brim()
  62. %code%{ RETVAL = const_cast<ExtrusionEntityCollection*>(&THIS->brim()); %};
  63. std::string estimated_normal_print_time()
  64. %code%{ RETVAL = THIS->print_statistics().estimated_normal_print_time; %};
  65. std::string estimated_silent_print_time()
  66. %code%{ RETVAL = THIS->print_statistics().estimated_silent_print_time; %};
  67. double total_used_filament()
  68. %code%{ RETVAL = THIS->print_statistics().total_used_filament; %};
  69. double total_extruded_volume()
  70. %code%{ RETVAL = THIS->print_statistics().total_extruded_volume; %};
  71. double total_weight()
  72. %code%{ RETVAL = THIS->print_statistics().total_weight; %};
  73. double total_cost()
  74. %code%{ RETVAL = THIS->print_statistics().total_cost; %};
  75. double total_wipe_tower_cost()
  76. %code%{ RETVAL = THIS->print_statistics().total_wipe_tower_cost; %};
  77. double total_wipe_tower_filament()
  78. %code%{ RETVAL = THIS->print_statistics().total_wipe_tower_filament; %};
  79. int wipe_tower_number_of_toolchanges()
  80. %code%{ RETVAL = THIS->wipe_tower_data().number_of_toolchanges; %};
  81. PrintObjectPtrs* objects()
  82. %code%{ RETVAL = const_cast<PrintObjectPtrs*>(&THIS->objects()); %};
  83. Ref<PrintObject> get_object(int idx)
  84. %code%{ RETVAL = THIS->objects()[idx]; %};
  85. size_t object_count()
  86. %code%{ RETVAL = THIS->objects().size(); %};
  87. PrintRegionPtrs* regions()
  88. %code%{ RETVAL = const_cast<PrintRegionPtrs*>(&THIS->regions()); %};
  89. Ref<PrintRegion> get_region(int idx)
  90. %code%{ RETVAL = THIS->regions()[idx]; %};
  91. size_t region_count()
  92. %code%{ RETVAL = THIS->regions().size(); %};
  93. bool step_done(PrintStep step)
  94. %code%{ RETVAL = THIS->is_step_done(step); %};
  95. bool object_step_done(PrintObjectStep step)
  96. %code%{ RETVAL = THIS->is_step_done(step); %};
  97. SV* filament_stats()
  98. %code%{
  99. HV* hv = newHV();
  100. for (std::map<size_t,float>::const_iterator it = THIS->print_statistics().filament_stats.begin(); it != THIS->print_statistics().filament_stats.end(); ++it) {
  101. // stringify extruder_id
  102. std::ostringstream ss;
  103. ss << it->first;
  104. std::string str = ss.str();
  105. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  106. RETVAL = newRV_noinc((SV*)hv);
  107. }
  108. %};
  109. double max_allowed_layer_height() const;
  110. bool has_support_material() const;
  111. void auto_assign_extruders(ModelObject* model_object);
  112. std::string output_filepath(std::string path = "")
  113. %code%{
  114. try {
  115. RETVAL = THIS->output_filepath(path);
  116. } catch (std::exception& e) {
  117. croak("%s\n", e.what());
  118. }
  119. %};
  120. bool apply(Model *model, DynamicPrintConfig* config)
  121. %code%{ RETVAL = THIS->apply(*model, *config); %};
  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. };