2013-12-20 15:37:28 +00:00
|
|
|
%module{Slic3r::XS};
|
|
|
|
|
|
|
|
%{
|
2015-12-07 23:39:54 +00:00
|
|
|
#include <xsinit.h>
|
2014-08-03 17:42:29 +00:00
|
|
|
#include "libslic3r/PrintConfig.hpp"
|
2013-12-20 15:37:28 +00:00
|
|
|
%}
|
|
|
|
|
2013-12-21 15:15:41 +00:00
|
|
|
%name{Slic3r::Config} class DynamicPrintConfig {
|
|
|
|
DynamicPrintConfig();
|
|
|
|
~DynamicPrintConfig();
|
2019-10-16 09:34:45 +00:00
|
|
|
static DynamicPrintConfig* new_from_defaults()
|
2019-10-16 09:16:50 +00:00
|
|
|
%code{% RETVAL = DynamicPrintConfig::new_from_defaults_keys(FullPrintConfig::defaults().keys()); %};
|
2017-10-27 16:52:35 +00:00
|
|
|
static DynamicPrintConfig* new_from_defaults_keys(std::vector<std::string> keys);
|
|
|
|
DynamicPrintConfig* clone() %code{% RETVAL = new DynamicPrintConfig(*THIS); %};
|
2017-11-02 20:51:06 +00:00
|
|
|
DynamicPrintConfig* clone_only(std::vector<std::string> keys)
|
|
|
|
%code{% RETVAL = new DynamicPrintConfig(); RETVAL->apply_only(*THIS, keys, true); %};
|
2013-12-21 20:06:45 +00:00
|
|
|
bool has(t_config_option_key opt_key);
|
2015-12-07 23:39:54 +00:00
|
|
|
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); %};
|
2017-10-27 16:52:35 +00:00
|
|
|
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);
|
|
|
|
%};
|
2015-12-07 23:39:54 +00:00
|
|
|
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); %};
|
2019-06-27 09:02:45 +00:00
|
|
|
std::string opt_serialize(t_config_option_key opt_key);
|
2013-12-22 00:38:10 +00:00
|
|
|
double get_abs_value(t_config_option_key opt_key);
|
2014-01-02 09:44:54 +00:00
|
|
|
%name{get_abs_value_over}
|
|
|
|
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
2013-12-21 20:06:45 +00:00
|
|
|
void apply(DynamicPrintConfig* other)
|
|
|
|
%code{% THIS->apply(*other, true); %};
|
2014-11-09 11:25:59 +00:00
|
|
|
std::vector<std::string> diff(DynamicPrintConfig* other)
|
|
|
|
%code{% RETVAL = THIS->diff(*other); %};
|
2014-12-25 16:35:31 +00:00
|
|
|
bool equals(DynamicPrintConfig* other)
|
|
|
|
%code{% RETVAL = THIS->equals(*other); %};
|
2015-12-16 11:33:19 +00:00
|
|
|
void apply_static(StaticPrintConfig* other)
|
2013-12-21 20:06:45 +00:00
|
|
|
%code{% THIS->apply(*other, true); %};
|
2015-07-01 16:18:25 +00:00
|
|
|
%name{get_keys} std::vector<std::string> keys();
|
2014-01-22 20:14:47 +00:00
|
|
|
void erase(t_config_option_key opt_key);
|
2020-09-24 18:32:52 +00:00
|
|
|
void normalize_fdm();
|
2015-07-01 16:18:25 +00:00
|
|
|
%name{setenv} void setenv_();
|
2020-04-23 16:17:37 +00:00
|
|
|
double min_object_distance() %code{% RETVAL = Slic3r::min_object_distance(*THIS); %};
|
2017-10-27 14:11:06 +00:00
|
|
|
static DynamicPrintConfig* load(char *path)
|
2017-06-14 18:18:46 +00:00
|
|
|
%code%{
|
2017-10-27 14:11:06 +00:00
|
|
|
auto config = new DynamicPrintConfig();
|
2017-06-14 18:18:46 +00:00
|
|
|
try {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config->load(path, ForwardCompatibilitySubstitutionRule::Disable);
|
2017-10-27 14:11:06 +00:00
|
|
|
RETVAL = config;
|
2017-06-14 18:18:46 +00:00
|
|
|
} catch (std::exception& e) {
|
2017-10-27 14:11:06 +00:00
|
|
|
delete config;
|
|
|
|
croak("Error extracting configuration from %s:\n%s\n", path, e.what());
|
2017-06-14 18:18:46 +00:00
|
|
|
}
|
|
|
|
%};
|
2017-10-17 14:01:18 +00:00
|
|
|
void save(std::string file);
|
2017-10-27 14:11:06 +00:00
|
|
|
int validate() %code%{
|
|
|
|
std::string err = THIS->validate();
|
|
|
|
if (! err.empty())
|
|
|
|
croak("Configuration is not valid: %s\n", err.c_str());
|
|
|
|
RETVAL = 1;
|
|
|
|
%};
|
2014-01-01 16:29:15 +00:00
|
|
|
};
|
2013-12-20 15:37:28 +00:00
|
|
|
|
2015-12-16 11:33:19 +00:00
|
|
|
%name{Slic3r::Config::Static} class StaticPrintConfig {
|
|
|
|
static StaticPrintConfig* new_GCodeConfig()
|
2017-10-17 14:01:18 +00:00
|
|
|
%code{% RETVAL = new GCodeConfig(); %};
|
2015-12-16 11:33:19 +00:00
|
|
|
static StaticPrintConfig* new_PrintConfig()
|
2018-06-20 11:57:37 +00:00
|
|
|
%code{% RETVAL = static_cast<GCodeConfig*>(new PrintConfig()); %};
|
2015-12-16 11:33:19 +00:00
|
|
|
static StaticPrintConfig* new_FullPrintConfig()
|
2018-06-20 11:57:37 +00:00
|
|
|
%code{% RETVAL = static_cast<GCodeConfig*>(new FullPrintConfig()); %};
|
2015-12-16 11:33:19 +00:00
|
|
|
~StaticPrintConfig();
|
2014-10-18 15:41:21 +00:00
|
|
|
bool has(t_config_option_key opt_key);
|
2015-12-07 23:39:54 +00:00
|
|
|
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); %};
|
2019-06-27 09:02:45 +00:00
|
|
|
std::string opt_serialize(t_config_option_key opt_key);
|
2014-10-18 15:41:21 +00:00
|
|
|
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);
|
2015-12-16 11:33:19 +00:00
|
|
|
void apply_static(StaticPrintConfig* other)
|
2014-10-18 15:41:21 +00:00
|
|
|
%code{% THIS->apply(*other, true); %};
|
|
|
|
void apply_dynamic(DynamicPrintConfig* other)
|
|
|
|
%code{% THIS->apply(*other, true); %};
|
2015-07-01 16:18:25 +00:00
|
|
|
%name{get_keys} std::vector<std::string> keys();
|
2015-12-16 11:33:19 +00:00
|
|
|
std::string get_extrusion_axis()
|
|
|
|
%code{%
|
|
|
|
if (GCodeConfig* config = dynamic_cast<GCodeConfig*>(THIS)) {
|
2021-04-26 16:37:10 +00:00
|
|
|
RETVAL = get_extrusion_axis(*config);
|
2015-12-16 11:33:19 +00:00
|
|
|
} else {
|
|
|
|
CONFESS("This StaticConfig object does not provide get_extrusion_axis()");
|
|
|
|
}
|
|
|
|
%};
|
2015-07-01 16:18:25 +00:00
|
|
|
%name{setenv} void setenv_();
|
2020-04-23 16:17:37 +00:00
|
|
|
double min_object_distance() %code{% RETVAL = Slic3r::min_object_distance(*THIS); %};
|
2017-10-27 14:11:06 +00:00
|
|
|
static StaticPrintConfig* load(char *path)
|
|
|
|
%code%{
|
|
|
|
auto config = new FullPrintConfig();
|
|
|
|
try {
|
Support for forward compatibility of configurations, user and system
config bundles, project files (3MFs, AMFs). When loading these files,
the caller may decide whether to substitute some of the configuration
values the current PrusaSlicer version does not understand with
some reasonable default value, and whether to report it. If substitution
is disabled, an exception is being thrown as before this commit.
If substitution is enabled, list of substitutions is returned by the
API to be presented to the user. This allows us to introduce for example
new firmware flavor key in PrusaSlicer 2.4 while letting PrusaSlicer
2.3.2 to fall back to some default and to report it to the user.
When slicing from command line, substutions are performed by default
and reported into the console, however substitutions may be either
disabled or made silent with the new "config-compatibility" command
line option.
Substitute enums and bools only. Allow booleans to be parsed as
true: "1", "enabled", "on" case insensitive
false: "0", "disabled", "off" case insensitive
This will allow us in the future for example to switch the draft_shield
boolean to an enum with the following values: "disabled" / "enabled" / "limited".
Added "enum_bitmask.hpp" - support for type safe sets of options.
See for example PresetBundle::load_configbundle(...
LoadConfigBundleAttributes flags) for an example of intended usage.
WIP: GUI for reporting the list of config substitutions needs to be
implemented by @YuSanka.
2021-06-27 14:04:23 +00:00
|
|
|
config->load(path, ForwardCompatibilitySubstitutionRule::Disable);
|
2018-06-20 11:57:37 +00:00
|
|
|
RETVAL = static_cast<GCodeConfig*>(config);
|
2017-10-27 14:11:06 +00:00
|
|
|
} catch (std::exception& e) {
|
|
|
|
delete config;
|
|
|
|
croak("Error extracting configuration from %s:\n%s\n", path, e.what());
|
|
|
|
}
|
|
|
|
%};
|
|
|
|
|
2017-10-17 14:01:18 +00:00
|
|
|
void save(std::string file);
|
2013-12-21 15:32:11 +00:00
|
|
|
};
|
2013-12-21 20:06:45 +00:00
|
|
|
|
|
|
|
%package{Slic3r::Config};
|
|
|
|
|
|
|
|
%{
|
|
|
|
PROTOTYPES: DISABLE
|
|
|
|
|
|
|
|
SV*
|
|
|
|
print_config_def()
|
|
|
|
CODE:
|
2018-09-20 14:48:13 +00:00
|
|
|
t_optiondef_map &def = *const_cast<t_optiondef_map*>(&Slic3r::print_config_def.options);
|
2013-12-21 20:06:45 +00:00
|
|
|
|
|
|
|
HV* options_hv = newHV();
|
2015-12-07 18:39:49 +00:00
|
|
|
for (t_optiondef_map::iterator oit = def.begin(); oit != def.end(); ++oit) {
|
2013-12-21 20:06:45 +00:00
|
|
|
HV* hv = newHV();
|
|
|
|
|
|
|
|
t_config_option_key opt_key = oit->first;
|
|
|
|
ConfigOptionDef* optdef = &oit->second;
|
|
|
|
|
|
|
|
const char* opt_type;
|
2022-12-14 18:33:07 +00:00
|
|
|
if (optdef->type == coFloat || optdef->type == coFloats || optdef->type == coFloatOrPercent || optdef->type == coFloatsOrPercents) {
|
2013-12-21 20:06:45 +00:00
|
|
|
opt_type = "f";
|
2017-05-19 17:24:21 +00:00
|
|
|
} else if (optdef->type == coPercent || optdef->type == coPercents) {
|
2014-03-22 15:23:33 +00:00
|
|
|
opt_type = "percent";
|
2013-12-21 20:06:45 +00:00
|
|
|
} else if (optdef->type == coInt || optdef->type == coInts) {
|
|
|
|
opt_type = "i";
|
|
|
|
} else if (optdef->type == coString) {
|
|
|
|
opt_type = "s";
|
2013-12-21 23:39:03 +00:00
|
|
|
} else if (optdef->type == coStrings) {
|
|
|
|
opt_type = "s@";
|
2013-12-21 20:06:45 +00:00
|
|
|
} else if (optdef->type == coPoint || optdef->type == coPoints) {
|
|
|
|
opt_type = "point";
|
2019-03-13 15:53:08 +00:00
|
|
|
} else if (optdef->type == coPoint3) {
|
2019-03-13 14:44:50 +00:00
|
|
|
opt_type = "point3";
|
2013-12-21 20:06:45 +00:00
|
|
|
} 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
|
2013-12-24 00:16:51 +00:00
|
|
|
if (!optdef->aliases.empty()) {
|
2013-12-21 20:06:45 +00:00
|
|
|
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
|
2013-12-24 00:16:51 +00:00
|
|
|
if (!optdef->shortcut.empty()) {
|
2013-12-21 20:06:45 +00:00
|
|
|
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
|
2013-12-24 00:16:51 +00:00
|
|
|
if (!optdef->enum_values.empty()) {
|
2013-12-21 20:06:45 +00:00
|
|
|
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()));
|
2013-12-21 23:39:03 +00:00
|
|
|
(void)hv_stores( hv, "values", newRV_noinc((SV*)av) );
|
2013-12-21 20:06:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// enum_labels
|
2013-12-24 00:16:51 +00:00
|
|
|
if (!optdef->enum_labels.empty()) {
|
2013-12-21 20:06:45 +00:00
|
|
|
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)
|
2014-02-14 08:35:38 +00:00
|
|
|
av_store(av, it - optdef->enum_labels.begin(), newSVpvn_utf8(it->c_str(), it->length(), true));
|
2013-12-21 23:39:03 +00:00
|
|
|
(void)hv_stores( hv, "labels", newRV_noinc((SV*)av) );
|
2013-12-21 20:06:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 16:01:39 +00:00
|
|
|
if (optdef->default_value)
|
|
|
|
(void)hv_stores( hv, "default", ConfigOption_to_SV(*optdef->default_value.get(), *optdef) );
|
2013-12-21 20:06:45 +00:00
|
|
|
(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
|
|
|
|
%}
|