Config.xsp 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. %module{Slic3r::XS};
  2. %{
  3. #include <xsinit.h>
  4. #include "libslic3r/PrintConfig.hpp"
  5. %}
  6. %name{Slic3r::Config} class DynamicPrintConfig {
  7. DynamicPrintConfig();
  8. ~DynamicPrintConfig();
  9. bool has(t_config_option_key opt_key);
  10. SV* as_hash()
  11. %code{% RETVAL = ConfigBase__as_hash(THIS); %};
  12. SV* get(t_config_option_key opt_key)
  13. %code{% RETVAL = ConfigBase__get(THIS, opt_key); %};
  14. SV* get_at(t_config_option_key opt_key, int i)
  15. %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %};
  16. bool set(t_config_option_key opt_key, SV* value)
  17. %code{% RETVAL = ConfigBase__set(THIS, opt_key, value); %};
  18. bool set_deserialize(t_config_option_key opt_key, SV* str)
  19. %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %};
  20. void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false)
  21. %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %};
  22. std::string serialize(t_config_option_key opt_key);
  23. double get_abs_value(t_config_option_key opt_key);
  24. %name{get_abs_value_over}
  25. double get_abs_value(t_config_option_key opt_key, double ratio_over);
  26. void apply(DynamicPrintConfig* other)
  27. %code{% THIS->apply(*other, true); %};
  28. void apply_only(DynamicPrintConfig* other, std::vector<std::string> opt_keys)
  29. %code{% THIS->apply_only(*other, opt_keys, true, false); %};
  30. std::vector<std::string> diff(DynamicPrintConfig* other)
  31. %code{% RETVAL = THIS->diff(*other); %};
  32. std::vector<std::string> diff_static(StaticPrintConfig* other)
  33. %code{% RETVAL = THIS->diff(*other); %};
  34. bool equals(DynamicPrintConfig* other)
  35. %code{% RETVAL = THIS->equals(*other); %};
  36. void apply_static(StaticPrintConfig* other)
  37. %code{% THIS->apply(*other, true); %};
  38. %name{get_keys} std::vector<std::string> keys();
  39. void erase(t_config_option_key opt_key);
  40. void clear();
  41. bool empty();
  42. void normalize();
  43. %name{setenv} void setenv_();
  44. double min_object_distance();
  45. %name{_load} void load(std::string file);
  46. %name{_save} void save(std::string file);
  47. std::vector<std::string> read_cli(std::vector<std::string> _argv)
  48. %code{% THIS->read_cli(_argv, &RETVAL); %};
  49. };
  50. %name{Slic3r::Config::Static} class StaticPrintConfig {
  51. static StaticPrintConfig* new_GCodeConfig()
  52. %code{% RETVAL = new GCodeConfig (); %};
  53. static StaticPrintConfig* new_PrintConfig()
  54. %code{% RETVAL = new PrintConfig (); %};
  55. static StaticPrintConfig* new_PrintObjectConfig()
  56. %code{% RETVAL = new PrintObjectConfig (); %};
  57. static StaticPrintConfig* new_PrintRegionConfig()
  58. %code{% RETVAL = new PrintRegionConfig (); %};
  59. static StaticPrintConfig* new_FullPrintConfig()
  60. %code{% RETVAL = new FullPrintConfig (); %};
  61. static StaticPrintConfig* new_SLAPrintConfig()
  62. %code{% RETVAL = new SLAPrintConfig (); %};
  63. ~StaticPrintConfig();
  64. bool has(t_config_option_key opt_key);
  65. SV* as_hash()
  66. %code{% RETVAL = ConfigBase__as_hash(THIS); %};
  67. SV* get(t_config_option_key opt_key)
  68. %code{% RETVAL = ConfigBase__get(THIS, opt_key); %};
  69. SV* get_at(t_config_option_key opt_key, int i)
  70. %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %};
  71. bool set(t_config_option_key opt_key, SV* value)
  72. %code{% RETVAL = StaticConfig__set(THIS, opt_key, value); %};
  73. bool set_deserialize(t_config_option_key opt_key, SV* str)
  74. %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %};
  75. void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false)
  76. %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %};
  77. std::string serialize(t_config_option_key opt_key);
  78. double get_abs_value(t_config_option_key opt_key);
  79. %name{get_abs_value_over}
  80. double get_abs_value(t_config_option_key opt_key, double ratio_over);
  81. void apply_static(StaticPrintConfig* other)
  82. %code{% THIS->apply(*other, true); %};
  83. void apply_dynamic(DynamicPrintConfig* other)
  84. %code{% THIS->apply(*other, true); %};
  85. %name{get_keys} std::vector<std::string> keys();
  86. std::string get_extrusion_axis()
  87. %code{%
  88. if (GCodeConfig* config = dynamic_cast<GCodeConfig*>(THIS)) {
  89. RETVAL = config->get_extrusion_axis();
  90. } else {
  91. CONFESS("This StaticConfig object does not provide get_extrusion_axis()");
  92. }
  93. %};
  94. %name{setenv} void setenv_();
  95. double min_object_distance();
  96. %name{_load} void load(std::string file);
  97. %name{_save} void save(std::string file);
  98. DynamicPrintConfig* dynamic()
  99. %code{% RETVAL = new DynamicPrintConfig (); RETVAL->apply(*THIS, true); %};
  100. };
  101. %package{Slic3r::Config};
  102. %{
  103. PROTOTYPES: DISABLE
  104. SV*
  105. print_config_def()
  106. CODE:
  107. HV* options_hv = newHV();
  108. for (const auto &oit : Slic3r::print_config_def.options) {
  109. HV* hv = newHV();
  110. const t_config_option_key &opt_key = oit.first;
  111. const ConfigOptionDef &optdef = oit.second;
  112. const char* opt_type;
  113. if (optdef.type == coFloat || optdef.type == coFloats || optdef.type == coFloatOrPercent) {
  114. opt_type = "f";
  115. } else if (optdef.type == coPercent) {
  116. opt_type = "percent";
  117. } else if (optdef.type == coInt || optdef.type == coInts) {
  118. opt_type = "i";
  119. } else if (optdef.type == coString) {
  120. opt_type = "s";
  121. } else if (optdef.type == coStrings) {
  122. opt_type = "s@";
  123. } else if (optdef.type == coPoint || optdef.type == coPoints) {
  124. opt_type = "point";
  125. } else if (optdef.type == coPoint3 ){
  126. opt_type = "point3";
  127. } else if (optdef.type == coBool || optdef.type == coBools) {
  128. opt_type = "bool";
  129. } else if (optdef.type == coEnum) {
  130. opt_type = "select";
  131. } else {
  132. throw "Unknown option type";
  133. }
  134. (void)hv_stores( hv, "type", newSVpv(opt_type, 0) );
  135. (void)hv_stores( hv, "gui_type", newSVpvn(optdef.gui_type.c_str(), optdef.gui_type.length()) );
  136. (void)hv_stores( hv, "gui_flags", newSVpvn(optdef.gui_flags.c_str(), optdef.gui_flags.length()) );
  137. (void)hv_stores( hv, "label", newSVpvn_utf8(optdef.label.c_str(), optdef.label.length(), true) );
  138. if (!optdef.full_label.empty())
  139. (void)hv_stores( hv, "full_label", newSVpvn_utf8(optdef.full_label.c_str(), optdef.full_label.length(), true) );
  140. (void)hv_stores( hv, "category", newSVpvn_utf8(optdef.category.c_str(), optdef.category.length(), true) );
  141. (void)hv_stores( hv, "tooltip", newSVpvn_utf8(optdef.tooltip.c_str(), optdef.tooltip.length(), true) );
  142. (void)hv_stores( hv, "sidetext", newSVpvn_utf8(optdef.sidetext.c_str(), optdef.sidetext.length(), true) );
  143. (void)hv_stores( hv, "cli", newSVpvn(optdef.cli.c_str(), optdef.cli.length()) );
  144. (void)hv_stores( hv, "ratio_over", newSVpvn(optdef.ratio_over.c_str(), optdef.ratio_over.length()) );
  145. (void)hv_stores( hv, "multiline", newSViv(optdef.multiline ? 1 : 0) );
  146. (void)hv_stores( hv, "full_width", newSViv(optdef.full_width ? 1 : 0) );
  147. (void)hv_stores( hv, "readonly", newSViv(optdef.readonly ? 1 : 0) );
  148. (void)hv_stores( hv, "height", newSViv(optdef.height) );
  149. (void)hv_stores( hv, "width", newSViv(optdef.width) );
  150. (void)hv_stores( hv, "min", newSViv(optdef.min) );
  151. (void)hv_stores( hv, "max", newSViv(optdef.max) );
  152. // aliases
  153. if (!optdef.aliases.empty()) {
  154. AV* av = newAV();
  155. av_fill(av, optdef.aliases.size()-1);
  156. for (std::vector<t_config_option_key>::const_iterator it = optdef.aliases.begin(); it != optdef.aliases.end(); ++it)
  157. av_store(av, it - optdef.aliases.begin(), newSVpvn(it->c_str(), it->length()));
  158. (void)hv_stores( hv, "aliases", newRV_noinc((SV*)av) );
  159. }
  160. // shortcut
  161. if (!optdef.shortcut.empty()) {
  162. AV* av = newAV();
  163. av_fill(av, optdef.shortcut.size()-1);
  164. for (std::vector<t_config_option_key>::const_iterator it = optdef.shortcut.begin(); it != optdef.shortcut.end(); ++it)
  165. av_store(av, it - optdef.shortcut.begin(), newSVpvn(it->c_str(), it->length()));
  166. (void)hv_stores( hv, "shortcut", newRV_noinc((SV*)av) );
  167. }
  168. // enum_values
  169. if (!optdef.enum_values.empty()) {
  170. AV* av = newAV();
  171. av_fill(av, optdef.enum_values.size()-1);
  172. for (std::vector<std::string>::const_iterator it = optdef.enum_values.begin(); it != optdef.enum_values.end(); ++it)
  173. av_store(av, it - optdef.enum_values.begin(), newSVpvn(it->c_str(), it->length()));
  174. (void)hv_stores( hv, "values", newRV_noinc((SV*)av) );
  175. }
  176. // enum_labels
  177. if (!optdef.enum_labels.empty()) {
  178. AV* av = newAV();
  179. av_fill(av, optdef.enum_labels.size()-1);
  180. for (std::vector<std::string>::const_iterator it = optdef.enum_labels.begin(); it != optdef.enum_labels.end(); ++it)
  181. av_store(av, it - optdef.enum_labels.begin(), newSVpvn_utf8(it->c_str(), it->length(), true));
  182. (void)hv_stores( hv, "labels", newRV_noinc((SV*)av) );
  183. }
  184. if (optdef.default_value != NULL)
  185. (void)hv_stores( hv, "default", ConfigOption_to_SV(*optdef.default_value, optdef) );
  186. (void)hv_store( options_hv, opt_key.c_str(), opt_key.length(), newRV_noinc((SV*)hv), 0 );
  187. }
  188. RETVAL = newRV_noinc((SV*)options_hv);
  189. OUTPUT:
  190. RETVAL
  191. %}