Print.xsp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. std::vector<double> layer_height_profile()
  43. %code%{ RETVAL = THIS->layer_height_profile; %};
  44. Clone<BoundingBox> bounding_box();
  45. Points _shifted_copies()
  46. %code%{ RETVAL = THIS->copies(); %};
  47. size_t layer_count();
  48. Ref<Layer> get_layer(int idx);
  49. size_t support_layer_count();
  50. Ref<SupportLayer> get_support_layer(int idx);
  51. bool step_done(PrintObjectStep step)
  52. %code%{ RETVAL = THIS->is_step_done(step); %};
  53. void slice();
  54. };
  55. %name{Slic3r::Print} class Print {
  56. Print();
  57. ~Print();
  58. Ref<StaticPrintConfig> config()
  59. %code%{ RETVAL = const_cast<GCodeConfig*>(static_cast<const GCodeConfig*>(&THIS->config())); %};
  60. Ref<PlaceholderParser> placeholder_parser()
  61. %code%{ RETVAL = &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. void reload_object(int idx);
  89. size_t object_count()
  90. %code%{ RETVAL = THIS->objects().size(); %};
  91. PrintRegionPtrs* regions()
  92. %code%{ RETVAL = const_cast<PrintRegionPtrs*>(&THIS->regions()); %};
  93. Ref<PrintRegion> get_region(int idx)
  94. %code%{ RETVAL = THIS->regions()[idx]; %};
  95. size_t region_count()
  96. %code%{ RETVAL = THIS->regions().size(); %};
  97. bool step_done(PrintStep step)
  98. %code%{ RETVAL = THIS->is_step_done(step); %};
  99. bool object_step_done(PrintObjectStep step)
  100. %code%{ RETVAL = THIS->is_step_done(step); %};
  101. SV* filament_stats()
  102. %code%{
  103. HV* hv = newHV();
  104. for (std::map<size_t,float>::const_iterator it = THIS->print_statistics().filament_stats.begin(); it != THIS->print_statistics().filament_stats.end(); ++it) {
  105. // stringify extruder_id
  106. std::ostringstream ss;
  107. ss << it->first;
  108. std::string str = ss.str();
  109. (void)hv_store( hv, str.c_str(), str.length(), newSViv(it->second), 0 );
  110. RETVAL = newRV_noinc((SV*)hv);
  111. }
  112. %};
  113. double max_allowed_layer_height() const;
  114. bool has_support_material() const;
  115. void auto_assign_extruders(ModelObject* model_object);
  116. std::string output_filepath(std::string path = "")
  117. %code%{
  118. try {
  119. RETVAL = THIS->output_filepath(path);
  120. } catch (std::exception& e) {
  121. croak("%s\n", e.what());
  122. }
  123. %};
  124. void add_model_object(ModelObject* model_object, int idx = -1);
  125. bool apply_config(DynamicPrintConfig* config)
  126. %code%{ RETVAL = THIS->apply_config(*config); %};
  127. bool has_infinite_skirt();
  128. std::vector<unsigned int> extruders() const;
  129. int validate() %code%{
  130. std::string err = THIS->validate();
  131. if (! err.empty())
  132. croak("Configuration is not valid: %s\n", err.c_str());
  133. RETVAL = 1;
  134. %};
  135. Clone<BoundingBox> bounding_box();
  136. Clone<BoundingBox> total_bounding_box();
  137. Clone<Point> size() %code%{ RETVAL = THIS->bounding_box().size(); %};
  138. void set_callback_event(int evt) %code%{
  139. %};
  140. void set_status_silent();
  141. void set_status(int percent, const char *message);
  142. void process() %code%{
  143. try {
  144. THIS->process();
  145. } catch (std::exception& e) {
  146. croak(e.what());
  147. }
  148. %};
  149. void export_gcode(char *path_template) %code%{
  150. try {
  151. THIS->export_gcode(path_template, nullptr);
  152. } catch (std::exception& e) {
  153. croak(e.what());
  154. }
  155. %};
  156. };