Ported Config::setenv() to XS
This commit is contained in:
parent
f361d8ad43
commit
249088b4f8
@ -192,14 +192,6 @@ sub save {
|
|||||||
__PACKAGE__->write_ini($file, $self->as_ini);
|
__PACKAGE__->write_ini($file, $self->as_ini);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub setenv {
|
|
||||||
my $self = shift;
|
|
||||||
|
|
||||||
foreach my $opt_key (@{$self->get_keys}) {
|
|
||||||
$ENV{"SLIC3R_" . uc $opt_key} = $self->serialize($opt_key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# this method is idempotent by design and only applies to ::DynamicConfig or ::Full
|
# this method is idempotent by design and only applies to ::DynamicConfig or ::Full
|
||||||
# objects because it performs cross checks
|
# objects because it performs cross checks
|
||||||
sub validate {
|
sub validate {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "Config.hpp"
|
#include "Config.hpp"
|
||||||
|
#include <stdlib.h> // for setenv()
|
||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
@ -10,8 +11,7 @@ ConfigBase::has(const t_config_option_key opt_key) {
|
|||||||
void
|
void
|
||||||
ConfigBase::apply(const ConfigBase &other, bool ignore_nonexistent) {
|
ConfigBase::apply(const ConfigBase &other, bool ignore_nonexistent) {
|
||||||
// get list of option keys to apply
|
// get list of option keys to apply
|
||||||
t_config_option_keys opt_keys;
|
t_config_option_keys opt_keys = other.keys();
|
||||||
other.keys(&opt_keys);
|
|
||||||
|
|
||||||
// loop through options and apply them
|
// loop through options and apply them
|
||||||
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
|
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
|
||||||
@ -37,8 +37,7 @@ t_config_option_keys
|
|||||||
ConfigBase::diff(ConfigBase &other) {
|
ConfigBase::diff(ConfigBase &other) {
|
||||||
t_config_option_keys diff;
|
t_config_option_keys diff;
|
||||||
|
|
||||||
t_config_option_keys my_keys;
|
t_config_option_keys my_keys = this->keys();
|
||||||
this->keys(&my_keys);
|
|
||||||
for (t_config_option_keys::const_iterator opt_key = my_keys.begin(); opt_key != my_keys.end(); ++opt_key) {
|
for (t_config_option_keys::const_iterator opt_key = my_keys.begin(); opt_key != my_keys.end(); ++opt_key) {
|
||||||
if (other.has(*opt_key) && other.serialize(*opt_key) != this->serialize(*opt_key)) {
|
if (other.has(*opt_key) && other.serialize(*opt_key) != this->serialize(*opt_key)) {
|
||||||
diff.push_back(*opt_key);
|
diff.push_back(*opt_key);
|
||||||
@ -98,14 +97,31 @@ ConfigBase::get_abs_value(const t_config_option_key opt_key, double ratio_over)
|
|||||||
return opt->get_abs_value(ratio_over);
|
return opt->get_abs_value(ratio_over);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ConfigBase::setenv_()
|
||||||
|
{
|
||||||
|
t_config_option_keys opt_keys = this->keys();
|
||||||
|
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
|
||||||
|
// prepend the SLIC3R_ prefix
|
||||||
|
std::ostringstream ss;
|
||||||
|
ss << "SLIC3R_";
|
||||||
|
ss << *it;
|
||||||
|
std::string envname = ss.str();
|
||||||
|
|
||||||
|
// capitalize environment variable name
|
||||||
|
for (size_t i = 0; i < envname.size(); ++i)
|
||||||
|
envname[i] = (envname[i] <= 'z' && envname[i] >= 'a') ? envname[i]-('a'-'A') : envname[i];
|
||||||
|
|
||||||
|
setenv(envname.c_str(), this->serialize(*it).c_str(), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
SV*
|
SV*
|
||||||
ConfigBase::as_hash() {
|
ConfigBase::as_hash() {
|
||||||
HV* hv = newHV();
|
HV* hv = newHV();
|
||||||
|
|
||||||
t_config_option_keys opt_keys;
|
t_config_option_keys opt_keys = this->keys();
|
||||||
this->keys(&opt_keys);
|
|
||||||
|
|
||||||
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it)
|
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it)
|
||||||
(void)hv_store( hv, it->c_str(), it->length(), this->get(*it), 0 );
|
(void)hv_store( hv, it->c_str(), it->length(), this->get(*it), 0 );
|
||||||
|
|
||||||
@ -368,10 +384,12 @@ DynamicConfig::option(const t_config_option_key opt_key) const {
|
|||||||
return const_cast<DynamicConfig*>(this)->option(opt_key, false);
|
return const_cast<DynamicConfig*>(this)->option(opt_key, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
t_config_option_keys
|
||||||
DynamicConfig::keys(t_config_option_keys *keys) const {
|
DynamicConfig::keys() const {
|
||||||
|
t_config_option_keys keys;
|
||||||
for (t_options_map::const_iterator it = this->options.begin(); it != this->options.end(); ++it)
|
for (t_options_map::const_iterator it = this->options.begin(); it != this->options.end(); ++it)
|
||||||
keys->push_back(it->first);
|
keys.push_back(it->first);
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -379,12 +397,14 @@ DynamicConfig::erase(const t_config_option_key opt_key) {
|
|||||||
this->options.erase(opt_key);
|
this->options.erase(opt_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
t_config_option_keys
|
||||||
StaticConfig::keys(t_config_option_keys *keys) const {
|
StaticConfig::keys() const {
|
||||||
|
t_config_option_keys keys;
|
||||||
for (t_optiondef_map::const_iterator it = this->def->begin(); it != this->def->end(); ++it) {
|
for (t_optiondef_map::const_iterator it = this->def->begin(); it != this->def->end(); ++it) {
|
||||||
const ConfigOption* opt = this->option(it->first);
|
const ConfigOption* opt = this->option(it->first);
|
||||||
if (opt != NULL) keys->push_back(it->first);
|
if (opt != NULL) keys.push_back(it->first);
|
||||||
}
|
}
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ConfigOption*
|
const ConfigOption*
|
||||||
|
@ -515,7 +515,7 @@ class ConfigBase
|
|||||||
bool has(const t_config_option_key opt_key);
|
bool has(const t_config_option_key opt_key);
|
||||||
virtual ConfigOption* option(const t_config_option_key opt_key, bool create = false) = 0;
|
virtual ConfigOption* option(const t_config_option_key opt_key, bool create = false) = 0;
|
||||||
virtual const ConfigOption* option(const t_config_option_key opt_key) const = 0;
|
virtual const ConfigOption* option(const t_config_option_key opt_key) const = 0;
|
||||||
virtual void keys(t_config_option_keys *keys) const = 0;
|
virtual t_config_option_keys keys() const = 0;
|
||||||
void apply(const ConfigBase &other, bool ignore_nonexistent = false);
|
void apply(const ConfigBase &other, bool ignore_nonexistent = false);
|
||||||
bool equals(ConfigBase &other);
|
bool equals(ConfigBase &other);
|
||||||
t_config_option_keys diff(ConfigBase &other);
|
t_config_option_keys diff(ConfigBase &other);
|
||||||
@ -524,6 +524,7 @@ class ConfigBase
|
|||||||
void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false);
|
void set_ifndef(t_config_option_key opt_key, SV* value, bool deserialize = false);
|
||||||
double get_abs_value(const t_config_option_key opt_key);
|
double get_abs_value(const t_config_option_key opt_key);
|
||||||
double get_abs_value(const t_config_option_key opt_key, double ratio_over);
|
double get_abs_value(const t_config_option_key opt_key, double ratio_over);
|
||||||
|
void setenv_();
|
||||||
|
|
||||||
#ifdef SLIC3RXS
|
#ifdef SLIC3RXS
|
||||||
SV* as_hash();
|
SV* as_hash();
|
||||||
@ -545,7 +546,7 @@ class DynamicConfig : public ConfigBase
|
|||||||
template<class T> T* opt(const t_config_option_key opt_key, bool create = false);
|
template<class T> T* opt(const t_config_option_key opt_key, bool create = false);
|
||||||
ConfigOption* option(const t_config_option_key opt_key, bool create = false);
|
ConfigOption* option(const t_config_option_key opt_key, bool create = false);
|
||||||
const ConfigOption* option(const t_config_option_key opt_key) const;
|
const ConfigOption* option(const t_config_option_key opt_key) const;
|
||||||
void keys(t_config_option_keys *keys) const;
|
t_config_option_keys keys() const;
|
||||||
void erase(const t_config_option_key opt_key);
|
void erase(const t_config_option_key opt_key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -556,7 +557,7 @@ class DynamicConfig : public ConfigBase
|
|||||||
class StaticConfig : public ConfigBase
|
class StaticConfig : public ConfigBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void keys(t_config_option_keys *keys) const;
|
t_config_option_keys keys() const;
|
||||||
virtual ConfigOption* option(const t_config_option_key opt_key, bool create = false) = 0;
|
virtual ConfigOption* option(const t_config_option_key opt_key, bool create = false) = 0;
|
||||||
const ConfigOption* option(const t_config_option_key opt_key) const;
|
const ConfigOption* option(const t_config_option_key opt_key) const;
|
||||||
|
|
||||||
|
@ -27,10 +27,10 @@
|
|||||||
%code{% RETVAL = THIS->equals(*other); %};
|
%code{% RETVAL = THIS->equals(*other); %};
|
||||||
void apply_static(FullPrintConfig* other)
|
void apply_static(FullPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
%name{get_keys} std::vector<std::string> keys();
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
|
||||||
void erase(t_config_option_key opt_key);
|
void erase(t_config_option_key opt_key);
|
||||||
void normalize();
|
void normalize();
|
||||||
|
%name{setenv} void setenv_();
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Config::GCode} class GCodeConfig {
|
%name{Slic3r::Config::GCode} class GCodeConfig {
|
||||||
@ -51,9 +51,9 @@
|
|||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
void apply_dynamic(DynamicPrintConfig* other)
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
%name{get_keys} std::vector<std::string> keys();
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
|
||||||
std::string get_extrusion_axis();
|
std::string get_extrusion_axis();
|
||||||
|
%name{setenv} void setenv_();
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Config::Print} class PrintConfig {
|
%name{Slic3r::Config::Print} class PrintConfig {
|
||||||
@ -72,9 +72,9 @@
|
|||||||
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
double get_abs_value(t_config_option_key opt_key, double ratio_over);
|
||||||
void apply_dynamic(DynamicPrintConfig* other)
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
%name{get_keys} std::vector<std::string> keys();
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
|
||||||
std::string get_extrusion_axis();
|
std::string get_extrusion_axis();
|
||||||
|
%name{setenv} void setenv_();
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Config::PrintRegion} class PrintRegionConfig {
|
%name{Slic3r::Config::PrintRegion} class PrintRegionConfig {
|
||||||
@ -95,8 +95,8 @@
|
|||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
void apply_dynamic(DynamicPrintConfig* other)
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
%name{get_keys} std::vector<std::string> keys();
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
%name{setenv} void setenv_();
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Config::PrintObject} class PrintObjectConfig {
|
%name{Slic3r::Config::PrintObject} class PrintObjectConfig {
|
||||||
@ -117,8 +117,8 @@
|
|||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
void apply_dynamic(DynamicPrintConfig* other)
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
%name{get_keys} std::vector<std::string> keys();
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
%name{setenv} void setenv_();
|
||||||
};
|
};
|
||||||
|
|
||||||
%name{Slic3r::Config::Full} class FullPrintConfig {
|
%name{Slic3r::Config::Full} class FullPrintConfig {
|
||||||
@ -143,9 +143,9 @@
|
|||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
void apply_dynamic(DynamicPrintConfig* other)
|
void apply_dynamic(DynamicPrintConfig* other)
|
||||||
%code{% THIS->apply(*other, true); %};
|
%code{% THIS->apply(*other, true); %};
|
||||||
std::vector<std::string> get_keys()
|
%name{get_keys} std::vector<std::string> keys();
|
||||||
%code{% THIS->keys(&RETVAL); %};
|
|
||||||
std::string get_extrusion_axis();
|
std::string get_extrusion_axis();
|
||||||
|
%name{setenv} void setenv_();
|
||||||
};
|
};
|
||||||
|
|
||||||
%package{Slic3r::Config};
|
%package{Slic3r::Config};
|
||||||
|
Loading…
Reference in New Issue
Block a user