Incomplete work for adapting the application to the new XS-based Config

This commit is contained in:
Alessandro Ranellucci 2013-12-21 21:06:45 +01:00
parent e0c0a42a8b
commit 9836e963a5
8 changed files with 200 additions and 98 deletions

View file

@ -2,6 +2,11 @@
namespace Slic3r {
bool
ConfigBase::has(const t_config_option_key opt_key) {
return (this->option(opt_key, false) != NULL);
}
void
ConfigBase::apply(ConfigBase &other, bool ignore_nonexistent) {
// get list of option keys to apply
@ -10,7 +15,7 @@ ConfigBase::apply(ConfigBase &other, bool ignore_nonexistent) {
// loop through options and apply them
for (t_config_option_keys::const_iterator it = opt_keys.begin(); it != opt_keys.end(); ++it) {
ConfigOption* my_opt = this->option(*it);
ConfigOption* my_opt = this->option(*it, true);
if (my_opt == NULL) {
if (ignore_nonexistent == false) throw "Attempt to apply non-existent option";
continue;
@ -57,6 +62,19 @@ ConfigBase::get_abs_value(const t_config_option_key opt_key) {
}
#ifdef SLIC3RXS
SV*
ConfigBase::as_hash() {
HV* hv = newHV();
t_config_option_keys opt_keys;
this->keys(&opt_keys);
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 );
return newRV_noinc((SV*)hv);
}
SV*
ConfigBase::get(t_config_option_key opt_key) {
ConfigOption* opt = this->option(opt_key);
@ -212,11 +230,6 @@ DynamicConfig::keys(t_config_option_keys *keys) {
keys->push_back(it->first);
}
bool
DynamicConfig::has(const t_config_option_key opt_key) const {
return (this->options.count(opt_key) != 0);
}
void
StaticConfig::keys(t_config_option_keys *keys) {
for (t_optiondef_map::const_iterator it = this->def->begin(); it != this->def->end(); ++it) {

View file

@ -327,21 +327,39 @@ class ConfigOptionDef
public:
ConfigOptionType type;
std::string label;
std::string category;
std::string tooltip;
std::string ratio_over;
std::string sidetext;
std::string cli;
std::string scope;
t_config_option_key ratio_over;
bool multiline;
bool full_label;
bool full_width;
bool readonly;
int height;
int width;
int min;
int max;
std::vector<t_config_option_key> aliases;
std::vector<t_config_option_key> shortcut;
std::vector<std::string> enum_values;
std::vector<std::string> enum_labels;
t_config_enum_values enum_keys_map;
ConfigOptionDef() : multiline(false), full_label(false), full_width(false), readonly(false),
height(0), width(0), min(0), max(0) {};
};
typedef std::map<t_config_option_key,ConfigOptionDef> t_optiondef_map;
ConfigOptionDef* get_config_option_def(const t_config_option_key opt_key);
class ConfigBase
{
public:
t_optiondef_map* def;
ConfigBase() : def(NULL) {};
bool has(const t_config_option_key opt_key);
virtual ConfigOption* option(const t_config_option_key opt_key, bool create = false) = 0;
virtual void keys(t_config_option_keys *keys) = 0;
void apply(ConfigBase &other, bool ignore_nonexistent = false);
@ -350,6 +368,7 @@ class ConfigBase
float get_abs_value(const t_config_option_key opt_key);
#ifdef SLIC3RXS
SV* as_hash();
SV* get(t_config_option_key opt_key);
void set(t_config_option_key opt_key, SV* value);
#endif
@ -358,11 +377,10 @@ class ConfigBase
class DynamicConfig : public ConfigBase
{
public:
DynamicConfig(){};
DynamicConfig() {};
~DynamicConfig();
ConfigOption* option(const t_config_option_key opt_key, bool create = false);
void keys(t_config_option_keys *keys);
bool has(const t_config_option_key opt_key) const;
private:
DynamicConfig(const DynamicConfig& other); // we disable this by making it private and unimplemented

View file

@ -57,7 +57,6 @@ class PrintConfig : public StaticConfig
};
ConfigOption* option(const t_config_option_key opt_key, bool create = false) {
assert(!create); // can't create options in StaticConfig
if (opt_key == "layer_height") return &this->layer_height;
if (opt_key == "first_layer_height") return &this->first_layer_height;
if (opt_key == "perimeters") return &this->perimeters;
@ -70,6 +69,7 @@ class PrintConfig : public StaticConfig
if (opt_key == "nozzle_diameter") return &this->nozzle_diameter;
if (opt_key == "temperature") return &this->temperature;
if (opt_key == "wipe") return &this->wipe;
if (create) throw "Attempt to create non-existing option in StaticConfig object";
return NULL;
};