123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- %module{Slic3r::XS};
- %{
- #include <xsinit.h>
- #include "libslic3r/PrintConfig.hpp"
- %}
- %name{Slic3r::Config} class DynamicPrintConfig {
- DynamicPrintConfig();
- ~DynamicPrintConfig();
- static DynamicPrintConfig* new_from_defaults()
- %code{% RETVAL = DynamicPrintConfig::new_from_defaults_keys(FullPrintConfig::defaults().keys()); %};
- static DynamicPrintConfig* new_from_defaults_keys(std::vector<std::string> keys);
- DynamicPrintConfig* clone() %code{% RETVAL = new DynamicPrintConfig(*THIS); %};
- DynamicPrintConfig* clone_only(std::vector<std::string> keys)
- %code{% RETVAL = new DynamicPrintConfig(); RETVAL->apply_only(*THIS, keys, true); %};
- bool has(t_config_option_key opt_key);
- SV* as_hash()
- %code{% RETVAL = ConfigBase__as_hash(THIS); %};
- SV* get(t_config_option_key opt_key)
- %code{% RETVAL = ConfigBase__get(THIS, opt_key); %};
- SV* get_at(t_config_option_key opt_key, int i)
- %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %};
- SV* get_value(t_config_option_key opt_key)
- %code{%
- const ConfigOptionDef *def = THIS->def()->get(opt_key);
- RETVAL = (def != nullptr && ! def->ratio_over.empty()) ?
- newSVnv(THIS->get_abs_value(opt_key)) :
- ConfigBase__get(THIS, opt_key);
- %};
- bool set(t_config_option_key opt_key, SV* value)
- %code{% RETVAL = ConfigBase__set(THIS, opt_key, value); %};
- bool set_deserialize(t_config_option_key opt_key, SV* str)
- %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %};
- void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false)
- %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %};
- std::string opt_serialize(t_config_option_key opt_key);
- double get_abs_value(t_config_option_key opt_key);
- %name{get_abs_value_over}
- double get_abs_value(t_config_option_key opt_key, double ratio_over);
- void apply(DynamicPrintConfig* other)
- %code{% THIS->apply(*other, true); %};
- std::vector<std::string> diff(DynamicPrintConfig* other)
- %code{% RETVAL = THIS->diff(*other); %};
- bool equals(DynamicPrintConfig* other)
- %code{% RETVAL = THIS->equals(*other); %};
- void apply_static(StaticPrintConfig* other)
- %code{% THIS->apply(*other, true); %};
- %name{get_keys} std::vector<std::string> keys();
- void erase(t_config_option_key opt_key);
- void normalize_fdm();
- %name{setenv} void setenv_();
- double min_object_distance() %code{% RETVAL = Slic3r::min_object_distance(*THIS); %};
- static DynamicPrintConfig* load(char *path)
- %code%{
- auto config = new DynamicPrintConfig();
- try {
- config->load(path, ForwardCompatibilitySubstitutionRule::Disable);
- RETVAL = config;
- } catch (std::exception& e) {
- delete config;
- croak("Error extracting configuration from %s:\n%s\n", path, e.what());
- }
- %};
- void save(std::string file);
- int validate() %code%{
- std::string err = THIS->validate();
- if (! err.empty())
- croak("Configuration is not valid: %s\n", err.c_str());
- RETVAL = 1;
- %};
- };
- %name{Slic3r::Config::Static} class StaticPrintConfig {
- static StaticPrintConfig* new_GCodeConfig()
- %code{% RETVAL = new GCodeConfig(); %};
- static StaticPrintConfig* new_PrintConfig()
- %code{% RETVAL = static_cast<GCodeConfig*>(new PrintConfig()); %};
- static StaticPrintConfig* new_PrintObjectConfig()
- %code{% RETVAL = new PrintObjectConfig(); %};
- static StaticPrintConfig* new_PrintRegionConfig()
- %code{% RETVAL = new PrintRegionConfig(); %};
- static StaticPrintConfig* new_FullPrintConfig()
- %code{% RETVAL = static_cast<GCodeConfig*>(new FullPrintConfig()); %};
- ~StaticPrintConfig();
- bool has(t_config_option_key opt_key);
- SV* as_hash()
- %code{% RETVAL = ConfigBase__as_hash(THIS); %};
- SV* get(t_config_option_key opt_key)
- %code{% RETVAL = ConfigBase__get(THIS, opt_key); %};
- SV* get_at(t_config_option_key opt_key, int i)
- %code{% RETVAL = ConfigBase__get_at(THIS, opt_key, i); %};
- bool set(t_config_option_key opt_key, SV* value)
- %code{% RETVAL = StaticConfig__set(THIS, opt_key, value); %};
- bool set_deserialize(t_config_option_key opt_key, SV* str)
- %code{% RETVAL = ConfigBase__set_deserialize(THIS, opt_key, str); %};
- void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false)
- %code{% ConfigBase__set_ifndef(THIS, opt_key, value, deserialize); %};
- std::string opt_serialize(t_config_option_key opt_key);
- double get_abs_value(t_config_option_key opt_key);
- %name{get_abs_value_over}
- double get_abs_value(t_config_option_key opt_key, double ratio_over);
- void apply_static(StaticPrintConfig* other)
- %code{% THIS->apply(*other, true); %};
- void apply_dynamic(DynamicPrintConfig* other)
- %code{% THIS->apply(*other, true); %};
- %name{get_keys} std::vector<std::string> keys();
- std::string get_extrusion_axis()
- %code{%
- if (GCodeConfig* config = dynamic_cast<GCodeConfig*>(THIS)) {
- RETVAL = get_extrusion_axis(*config);
- } else {
- CONFESS("This StaticConfig object does not provide get_extrusion_axis()");
- }
- %};
- %name{setenv} void setenv_();
- double min_object_distance() %code{% RETVAL = Slic3r::min_object_distance(*THIS); %};
- static StaticPrintConfig* load(char *path)
- %code%{
- auto config = new FullPrintConfig();
- try {
- config->load(path, ForwardCompatibilitySubstitutionRule::Disable);
- RETVAL = static_cast<GCodeConfig*>(config);
- } catch (std::exception& e) {
- delete config;
- croak("Error extracting configuration from %s:\n%s\n", path, e.what());
- }
- %};
- void save(std::string file);
- };
- %package{Slic3r::Config};
- %{
- PROTOTYPES: DISABLE
- SV*
- print_config_def()
- CODE:
- t_optiondef_map &def = *const_cast<t_optiondef_map*>(&Slic3r::print_config_def.options);
-
- HV* options_hv = newHV();
- for (t_optiondef_map::iterator oit = def.begin(); oit != def.end(); ++oit) {
- HV* hv = newHV();
-
- t_config_option_key opt_key = oit->first;
- ConfigOptionDef* optdef = &oit->second;
-
- const char* opt_type;
- if (optdef->type == coFloat || optdef->type == coFloats || optdef->type == coFloatOrPercent) {
- opt_type = "f";
- } else if (optdef->type == coPercent || optdef->type == coPercents) {
- opt_type = "percent";
- } else if (optdef->type == coInt || optdef->type == coInts) {
- opt_type = "i";
- } else if (optdef->type == coString) {
- opt_type = "s";
- } else if (optdef->type == coStrings) {
- opt_type = "s@";
- } else if (optdef->type == coPoint || optdef->type == coPoints) {
- opt_type = "point";
- } else if (optdef->type == coPoint3) {
- opt_type = "point3";
- } else if (optdef->type == coBool || optdef->type == coBools) {
- opt_type = "bool";
- } else if (optdef->type == coEnum) {
- opt_type = "select";
- } else {
- throw "Unknown option type";
- }
- (void)hv_stores( hv, "type", newSVpv(opt_type, 0) );
- (void)hv_stores( hv, "height", newSViv(optdef->height) );
- (void)hv_stores( hv, "width", newSViv(optdef->width) );
- (void)hv_stores( hv, "min", newSViv(optdef->min) );
- (void)hv_stores( hv, "max", newSViv(optdef->max) );
-
- // aliases
- if (!optdef->aliases.empty()) {
- AV* av = newAV();
- av_fill(av, optdef->aliases.size()-1);
- for (std::vector<t_config_option_key>::iterator it = optdef->aliases.begin(); it != optdef->aliases.end(); ++it)
- av_store(av, it - optdef->aliases.begin(), newSVpvn(it->c_str(), it->length()));
- (void)hv_stores( hv, "aliases", newRV_noinc((SV*)av) );
- }
-
- // shortcut
- if (!optdef->shortcut.empty()) {
- AV* av = newAV();
- av_fill(av, optdef->shortcut.size()-1);
- for (std::vector<t_config_option_key>::iterator it = optdef->shortcut.begin(); it != optdef->shortcut.end(); ++it)
- av_store(av, it - optdef->shortcut.begin(), newSVpvn(it->c_str(), it->length()));
- (void)hv_stores( hv, "shortcut", newRV_noinc((SV*)av) );
- }
-
- // enum_values
- if (!optdef->enum_values.empty()) {
- AV* av = newAV();
- av_fill(av, optdef->enum_values.size()-1);
- for (std::vector<std::string>::iterator it = optdef->enum_values.begin(); it != optdef->enum_values.end(); ++it)
- av_store(av, it - optdef->enum_values.begin(), newSVpvn(it->c_str(), it->length()));
- (void)hv_stores( hv, "values", newRV_noinc((SV*)av) );
- }
-
- // enum_labels
- if (!optdef->enum_labels.empty()) {
- AV* av = newAV();
- av_fill(av, optdef->enum_labels.size()-1);
- for (std::vector<std::string>::iterator it = optdef->enum_labels.begin(); it != optdef->enum_labels.end(); ++it)
- av_store(av, it - optdef->enum_labels.begin(), newSVpvn_utf8(it->c_str(), it->length(), true));
- (void)hv_stores( hv, "labels", newRV_noinc((SV*)av) );
- }
-
- if (optdef->default_value)
- (void)hv_stores( hv, "default", ConfigOption_to_SV(*optdef->default_value.get(), *optdef) );
- (void)hv_store( options_hv, opt_key.c_str(), opt_key.length(), newRV_noinc((SV*)hv), 0 );
- }
-
- RETVAL = newRV_noinc((SV*)options_hv);
- OUTPUT:
- RETVAL
- %}
|