GUI_Preset.xsp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 system() %code%{ RETVAL = THIS->is_system; %};
  13. bool visible() %code%{ RETVAL = THIS->is_visible; %};
  14. bool dirty() %code%{ RETVAL = THIS->is_dirty; %};
  15. bool compatible() %code%{ RETVAL = THIS->is_compatible; %};
  16. bool is_compatible_with_printer(Preset *active_printer)
  17. %code%{ RETVAL = THIS->is_compatible_with_printer(*active_printer); %};
  18. std::string name() %code%{ RETVAL = THIS->name; %};
  19. std::string file() %code%{ RETVAL = THIS->file; %};
  20. bool loaded() %code%{ RETVAL = THIS->loaded; %};
  21. Ref<DynamicPrintConfig> config() %code%{ RETVAL = &THIS->config; %};
  22. void set_num_extruders(int num_extruders);
  23. };
  24. %name{Slic3r::GUI::PresetCollection} class PresetCollection {
  25. Ref<Preset> preset(size_t idx) %code%{ RETVAL = &THIS->preset(idx); %};
  26. Ref<Preset> default_preset() %code%{ RETVAL = &THIS->default_preset(); %};
  27. size_t size() const;
  28. size_t num_visible() const;
  29. std::string name() const;
  30. Ref<Preset> get_selected_preset() %code%{ RETVAL = &THIS->get_selected_preset(); %};
  31. Ref<Preset> get_current_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
  32. std::string get_current_preset_name() %code%{ RETVAL = THIS->get_selected_preset().name; %};
  33. Ref<Preset> get_edited_preset() %code%{ RETVAL = &THIS->get_edited_preset(); %};
  34. Ref<Preset> find_preset(char *name, bool first_visible_if_not_found = false) %code%{ RETVAL = THIS->find_preset(name, first_visible_if_not_found); %};
  35. void update_tab_ui(SV *ui, bool show_incompatible)
  36. %code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object( aTHX_ ui, "Wx::BitmapComboBox" );
  37. THIS->update_tab_ui(cb, show_incompatible); %};
  38. void update_platter_ui(SV *ui)
  39. %code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object( aTHX_ ui, "Wx::BitmapComboBox" );
  40. THIS->update_platter_ui(cb); %};
  41. %{
  42. SV*
  43. PresetCollection::arrayref()
  44. CODE:
  45. AV* av = newAV();
  46. av_fill(av, THIS->size()-1);
  47. for (int i = 0; i < int(THIS->size()); ++ i) {
  48. Preset &preset = THIS->preset(i);
  49. av_store(av, i, perl_to_SV_ref(preset));
  50. }
  51. RETVAL = newRV_noinc((SV*)av);
  52. OUTPUT:
  53. RETVAL
  54. %}
  55. };
  56. %name{Slic3r::GUI::PresetBundle} class PresetBundle {
  57. PresetBundle();
  58. ~PresetBundle();
  59. void reset(bool delete_files);
  60. void setup_directories()
  61. %code%{
  62. try {
  63. THIS->setup_directories();
  64. } catch (std::exception& e) {
  65. croak("Cannot create configuration directories:\n%s\n", e.what());
  66. }
  67. %};
  68. void load_presets(AppConfig *config)
  69. %code%{
  70. try {
  71. THIS->load_presets(*config);
  72. } catch (std::exception& e) {
  73. croak("Loading of Slic3r presets from %s failed.\n\n%s\n",
  74. Slic3r::data_dir().c_str(), e.what());
  75. }
  76. %};
  77. void load_config(const char *name, DynamicPrintConfig *config)
  78. %code%{
  79. try {
  80. THIS->load_config(name, *config);
  81. } catch (std::exception& e) {
  82. croak("Loading a configuration %s failed:\n%s\n", name, e.what());
  83. }
  84. %};
  85. void load_config_file(const char *path)
  86. %code%{
  87. try {
  88. THIS->load_config_file(path);
  89. } catch (std::exception& e) {
  90. croak("Loading a configuration file %s failed:\n%s\n", path, e.what());
  91. }
  92. %};
  93. size_t load_configbundle(const char *path)
  94. %code%{
  95. try {
  96. RETVAL = THIS->load_configbundle(path, PresetBundle::LOAD_CFGBNDLE_SAVE);
  97. } catch (std::exception& e) {
  98. croak("Loading of a config bundle %s failed:\n%s\n", path, e.what());
  99. }
  100. %};
  101. void export_configbundle(char *path)
  102. %code%{
  103. try {
  104. THIS->export_configbundle(path);
  105. } catch (std::exception& e) {
  106. croak("Export of a config bundle %s failed:\n%s\n", path, e.what());
  107. }
  108. %};
  109. void set_default_suppressed(bool default_suppressed);
  110. void export_selections(AppConfig *config) %code%{ THIS->export_selections(*config); %};
  111. void export_selections_pp(PlaceholderParser *pp) %code%{ THIS->export_selections(*pp); %};
  112. Ref<PresetCollection> print() %code%{ RETVAL = &THIS->prints; %};
  113. Ref<PresetCollection> filament() %code%{ RETVAL = &THIS->filaments; %};
  114. Ref<PresetCollection> printer() %code%{ RETVAL = &THIS->printers; %};
  115. Ref<DynamicPrintConfig> project_config() %code%{ RETVAL = &THIS->project_config; %};
  116. bool has_defauls_only();
  117. std::vector<std::string> filament_presets() %code%{ RETVAL = THIS->filament_presets; %};
  118. void set_filament_preset(int idx, const char *name);
  119. Clone<DynamicPrintConfig> full_config() %code%{ RETVAL = THIS->full_config(); %};
  120. void update_platter_filament_ui(int extruder_idx, SV *ui)
  121. %code%{ auto cb = (wxBitmapComboBox*)wxPli_sv_2_object(aTHX_ ui, "Wx::BitmapComboBox");
  122. THIS->update_platter_filament_ui(extruder_idx, cb); %};
  123. };