GUI_Preset.xsp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "slic3r/GUI/Preset.hpp"
  5. #include "slic3r/GUI/PresetBundle.hpp"
  6. #include "slic3r/GUI/PresetHints.hpp"
  7. %}
  8. %name{Slic3r::GUI::Preset} class Preset {
  9. // owned by PresetCollection, no constructor/destructor
  10. bool default() %code%{ RETVAL = THIS->is_default; %};
  11. bool external() %code%{ RETVAL = THIS->is_external; %};
  12. bool visible() %code%{ RETVAL = THIS->is_visible; %};
  13. bool dirty() %code%{ RETVAL = THIS->is_dirty; %};
  14. bool compatible() %code%{ RETVAL = THIS->is_compatible; %};
  15. bool is_compatible_with_printer(Preset *active_printer)
  16. %code%{ RETVAL = THIS->is_compatible_with_printer(*active_printer); %};
  17. const char* name() %code%{ RETVAL = THIS->name.c_str(); %};
  18. const char* file() %code%{ RETVAL = THIS->file.c_str(); %};
  19. bool loaded() %code%{ RETVAL = THIS->loaded; %};
  20. Ref<DynamicPrintConfig> config() %code%{ RETVAL = &THIS->config; %};
  21. void set_num_extruders(int num_extruders);
  22. };
  23. %name{Slic3r::GUI::PresetCollection} class PresetCollection {
  24. Ref<Preset> preset(size_t idx) %code%{ RETVAL = &THIS->preset(idx); %};
  25. Ref<Preset> default_preset() %code%{ RETVAL = &THIS->default_preset(); %};
  26. size_t size() const;
  27. size_t num_visible() const;
  28. std::string name() const;
  29. Ref<Preset> get_selected_preset() %code%{ RETVAL = &THIS->get_selected_preset(); %};
  30. Ref<Preset> get_current_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
  31. std::string get_current_preset_name() %code%{ RETVAL = THIS->get_selected_preset().name; %};
  32. Ref<Preset> get_edited_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
  33. Ref<Preset> find_preset(char *name, bool first_visible_if_not_found = false) %code%{ RETVAL = THIS->find_preset(name, first_visible_if_not_found); %};
  34. bool current_is_dirty();
  35. std::vector<std::string> current_dirty_options();
  36. void update_tab_ui(SV *ui, bool show_incompatible)
  37. %code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object( aTHX_ ui, "Wx::BitmapComboBox" );
  38. THIS->update_tab_ui(cb, show_incompatible); %};
  39. void update_platter_ui(SV *ui)
  40. %code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object( aTHX_ ui, "Wx::BitmapComboBox" );
  41. THIS->update_platter_ui(cb); %};
  42. bool update_dirty_ui(SV *ui)
  43. %code%{ RETVAL = THIS->update_dirty_ui((wxBitmapComboBox*)wxPli_sv_2_object(aTHX_ ui, "Wx::BitmapComboBox")); %};
  44. void select_preset(int idx);
  45. bool select_preset_by_name(char *name) %code%{ RETVAL = THIS->select_preset_by_name(name, true); %};
  46. void discard_current_changes();
  47. void save_current_preset(char *new_name)
  48. %code%{
  49. try {
  50. THIS->save_current_preset(new_name);
  51. } catch (std::exception& e) {
  52. croak("Error saving a preset %s:\n%s\n", new_name, e.what());
  53. }
  54. %};
  55. void delete_current_preset()
  56. %code%{
  57. try {
  58. THIS->delete_current_preset();
  59. } catch (std::exception& e) {
  60. croak("Error deleting a preset file %s:\n%s\n", THIS->get_selected_preset().file.c_str(), e.what());
  61. }
  62. %};
  63. %{
  64. SV*
  65. PresetCollection::arrayref()
  66. CODE:
  67. AV* av = newAV();
  68. av_fill(av, THIS->size()-1);
  69. for (int i = 0; i < int(THIS->size()); ++ i) {
  70. Preset &preset = THIS->preset(i);
  71. av_store(av, i, perl_to_SV_ref(preset));
  72. }
  73. RETVAL = newRV_noinc((SV*)av);
  74. OUTPUT:
  75. RETVAL
  76. %}
  77. };
  78. %name{Slic3r::GUI::PresetBundle} class PresetBundle {
  79. PresetBundle();
  80. ~PresetBundle();
  81. void reset(bool delete_files);
  82. void setup_directories()
  83. %code%{
  84. try {
  85. THIS->setup_directories();
  86. } catch (std::exception& e) {
  87. croak("Cannot create configuration directories:\n%s\n", e.what());
  88. }
  89. %};
  90. void load_presets()
  91. %code%{
  92. try {
  93. THIS->load_presets();
  94. } catch (std::exception& e) {
  95. croak("Loading of Slic3r presets from %s failed.\n\n%s\n",
  96. Slic3r::data_dir().c_str(), e.what());
  97. }
  98. %};
  99. void load_config(const char *name, DynamicPrintConfig *config)
  100. %code%{
  101. try {
  102. THIS->load_config(name, *config);
  103. } catch (std::exception& e) {
  104. croak("Loading a configuration %s failed:\n%s\n", name, e.what());
  105. }
  106. %};
  107. void load_config_file(const char *path)
  108. %code%{
  109. try {
  110. THIS->load_config_file(path);
  111. } catch (std::exception& e) {
  112. croak("Loading a configuration file %s failed:\n%s\n", path, e.what());
  113. }
  114. %};
  115. size_t load_configbundle(const char *path)
  116. %code%{
  117. try {
  118. RETVAL = THIS->load_configbundle(path, PresetBundle::LOAD_CFGBNDLE_SAVE);
  119. } catch (std::exception& e) {
  120. croak("Loading of a config bundle %s failed:\n%s\n", path, e.what());
  121. }
  122. %};
  123. void export_configbundle(char *path)
  124. %code%{
  125. try {
  126. THIS->export_configbundle(path);
  127. } catch (std::exception& e) {
  128. croak("Export of a config bundle %s failed:\n%s\n", path, e.what());
  129. }
  130. %};
  131. void set_default_suppressed(bool default_suppressed);
  132. void load_selections (AppConfig *config) %code%{ THIS->load_selections(*config); %};
  133. void export_selections(AppConfig *config) %code%{ THIS->export_selections(*config); %};
  134. void export_selections_pp(PlaceholderParser *pp) %code%{ THIS->export_selections(*pp); %};
  135. Ref<PresetCollection> print() %code%{ RETVAL = &THIS->prints; %};
  136. Ref<PresetCollection> filament() %code%{ RETVAL = &THIS->filaments; %};
  137. Ref<PresetCollection> printer() %code%{ RETVAL = &THIS->printers; %};
  138. bool has_defauls_only();
  139. std::vector<std::string> filament_presets() %code%{ RETVAL = THIS->filament_presets; %};
  140. void set_filament_preset(int idx, const char *name);
  141. void update_multi_material_filament_presets();
  142. void update_compatible_with_printer(bool select_other_if_incompatible);
  143. Clone<DynamicPrintConfig> full_config() %code%{ RETVAL = THIS->full_config(); %};
  144. void update_platter_filament_ui(int extruder_idx, SV *ui)
  145. %code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object(aTHX_ ui, "Wx::BitmapComboBox");
  146. THIS->update_platter_filament_ui(extruder_idx, cb); %};
  147. };
  148. %name{Slic3r::GUI::PresetHints} class PresetHints {
  149. PresetHints();
  150. ~PresetHints();
  151. static std::string cooling_description(Preset *preset)
  152. %code%{ RETVAL = PresetHints::cooling_description(*preset); %};
  153. static std::string maximum_volumetric_flow_description(PresetBundle *preset)
  154. %code%{ RETVAL = PresetHints::maximum_volumetric_flow_description(*preset); %};
  155. static std::string recommended_thin_wall_thickness(PresetBundle *preset)
  156. %code%{ RETVAL = PresetHints::recommended_thin_wall_thickness(*preset); %};
  157. };