More refactoring on Config XS bindings

This commit is contained in:
Alessandro Ranellucci 2015-12-16 12:58:06 +01:00
parent 3c862836f2
commit 934bd43e35
7 changed files with 56 additions and 41 deletions

View file

@ -304,7 +304,7 @@ PrintConfigDef::PrintConfigDef()
Options["filament_settings_id"].type = coString;
Options["filament_settings_id"].default_value = new ConfigOptionString("");
Options["fill_angle"].type = coInt;
Options["fill_angle"].type = coFloat;
Options["fill_angle"].label = "Fill angle";
Options["fill_angle"].category = "Infill";
Options["fill_angle"].tooltip = "Default base angle for infill orientation. Cross-hatching will be applied to this. Bridges will be infilled using the best direction Slic3r can detect, so this setting does not affect them.";
@ -1220,19 +1220,19 @@ PrintConfigDef::PrintConfigDef()
Options["use_firmware_retraction"].label = "Use firmware retraction";
Options["use_firmware_retraction"].tooltip = "This experimental setting uses G10 and G11 commands to have the firmware handle the retraction. This is only supported in recent Marlin.";
Options["use_firmware_retraction"].cli = "use-firmware-retraction!";
Options["use_firmware_retraction"].default_value = new ConfigOptionFloat(false);
Options["use_firmware_retraction"].default_value = new ConfigOptionBool(false);
Options["use_relative_e_distances"].type = coBool;
Options["use_relative_e_distances"].label = "Use relative E distances";
Options["use_relative_e_distances"].tooltip = "If your firmware requires relative E values, check this, otherwise leave it unchecked. Most firmwares use absolute values.";
Options["use_relative_e_distances"].cli = "use-relative-e-distances!";
Options["use_relative_e_distances"].default_value = new ConfigOptionFloat(false);
Options["use_relative_e_distances"].default_value = new ConfigOptionBool(false);
Options["use_volumetric_e"].type = coBool;
Options["use_volumetric_e"].label = "Use volumetric E";
Options["use_volumetric_e"].tooltip = "This experimental setting uses outputs the E values in cubic millimeters instead of linear millimeters. If your firmware doesn't already know filament diameter(s), you can put commands like 'M200 D[filament_diameter_0] T0' in your start G-code in order to turn volumetric mode on and use the filament diameter associated to the filament selected in Slic3r. This is only supported in recent Marlin.";
Options["use_volumetric_e"].cli = "use-volumetric-e!";
Options["use_volumetric_e"].default_value = new ConfigOptionFloat(false);
Options["use_volumetric_e"].default_value = new ConfigOptionBool(false);
Options["vibration_limit"].type = coFloat;
Options["vibration_limit"].label = "Vibration limit (deprecated)";

View file

@ -170,7 +170,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig
ConfigOptionFloatOrPercent external_perimeter_speed;
ConfigOptionBool external_perimeters_first;
ConfigOptionBool extra_perimeters;
ConfigOptionInt fill_angle;
ConfigOptionFloat fill_angle;
ConfigOptionPercent fill_density;
ConfigOptionEnum<InfillPattern> fill_pattern;
ConfigOptionFloat gap_fill_speed;

View file

@ -73,62 +73,76 @@ ConfigBase__get(ConfigBase* THIS, const t_config_option_key &opt_key) {
if (opt == NULL) return &PL_sv_undef;
const ConfigOptionDef* def = THIS->def->get(opt_key);
if (def->type == coFloat) {
ConfigOptionFloat* optv = dynamic_cast<ConfigOptionFloat*>(opt);
return ConfigOption_to_SV(*opt, *def);
}
SV*
ConfigOption_to_SV(const ConfigOption &opt, const ConfigOptionDef &def) {
if (def.type == coFloat) {
const ConfigOptionFloat* optv = dynamic_cast<const ConfigOptionFloat*>(&opt);
if (optv == NULL) {
printf("opt_key = %s\n", def.label.c_str());
}
return newSVnv(optv->value);
} else if (def->type == coFloats) {
ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt);
} else if (def.type == coFloats) {
const ConfigOptionFloats* optv = dynamic_cast<const ConfigOptionFloats*>(&opt);
AV* av = newAV();
av_fill(av, optv->values.size()-1);
for (std::vector<double>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
for (std::vector<double>::const_iterator it = optv->values.begin(); it != optv->values.end(); ++it)
av_store(av, it - optv->values.begin(), newSVnv(*it));
return newRV_noinc((SV*)av);
} else if (def->type == coPercent) {
ConfigOptionPercent* optv = dynamic_cast<ConfigOptionPercent*>(opt);
} else if (def.type == coPercent) {
const ConfigOptionPercent* optv = dynamic_cast<const ConfigOptionPercent*>(&opt);
return newSVnv(optv->value);
} else if (def->type == coInt) {
ConfigOptionInt* optv = dynamic_cast<ConfigOptionInt*>(opt);
} else if (def.type == coInt) {
const ConfigOptionInt* optv = dynamic_cast<const ConfigOptionInt*>(&opt);
if (optv == NULL) {
printf("opt_key = %s\n", def.label.c_str());
}
return newSViv(optv->value);
} else if (def->type == coInts) {
ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt);
} else if (def.type == coInts) {
const ConfigOptionInts* optv = dynamic_cast<const ConfigOptionInts*>(&opt);
AV* av = newAV();
av_fill(av, optv->values.size()-1);
for (std::vector<int>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
for (std::vector<int>::const_iterator it = optv->values.begin(); it != optv->values.end(); ++it)
av_store(av, it - optv->values.begin(), newSViv(*it));
return newRV_noinc((SV*)av);
} else if (def->type == coString) {
ConfigOptionString* optv = dynamic_cast<ConfigOptionString*>(opt);
} else if (def.type == coString) {
const ConfigOptionString* optv = dynamic_cast<const ConfigOptionString*>(&opt);
// we don't serialize() because that would escape newlines
return newSVpvn_utf8(optv->value.c_str(), optv->value.length(), true);
} else if (def->type == coStrings) {
ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt);
} else if (def.type == coStrings) {
const ConfigOptionStrings* optv = dynamic_cast<const ConfigOptionStrings*>(&opt);
AV* av = newAV();
av_fill(av, optv->values.size()-1);
for (std::vector<std::string>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
for (std::vector<std::string>::const_iterator it = optv->values.begin(); it != optv->values.end(); ++it)
av_store(av, it - optv->values.begin(), newSVpvn_utf8(it->c_str(), it->length(), true));
return newRV_noinc((SV*)av);
} else if (def->type == coPoint) {
ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt);
} else if (def.type == coPoint) {
const ConfigOptionPoint* optv = dynamic_cast<const ConfigOptionPoint*>(&opt);
return perl_to_SV_clone_ref(optv->value);
} else if (def->type == coPoints) {
ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt);
} else if (def.type == coPoints) {
const ConfigOptionPoints* optv = dynamic_cast<const ConfigOptionPoints*>(&opt);
AV* av = newAV();
av_fill(av, optv->values.size()-1);
for (Pointfs::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
for (Pointfs::const_iterator it = optv->values.begin(); it != optv->values.end(); ++it)
av_store(av, it - optv->values.begin(), perl_to_SV_clone_ref(*it));
return newRV_noinc((SV*)av);
} else if (def->type == coBool) {
ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt);
} else if (def.type == coBool) {
const ConfigOptionBool* optv = dynamic_cast<const ConfigOptionBool*>(&opt);
if (optv == NULL) {
printf("opt_key = %s\n", def.label.c_str());
}
return newSViv(optv->value ? 1 : 0);
} else if (def->type == coBools) {
ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt);
} else if (def.type == coBools) {
const ConfigOptionBools* optv = dynamic_cast<const ConfigOptionBools*>(&opt);
AV* av = newAV();
av_fill(av, optv->values.size()-1);
for (std::vector<bool>::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
for (std::vector<bool>::const_iterator it = optv->values.begin(); it != optv->values.end(); ++it)
av_store(av, it - optv->values.begin(), newSViv(*it ? 1 : 0));
return newRV_noinc((SV*)av);
} else {
std::string serialized = opt->serialize();
std::string serialized = opt.serialize();
return newSVpvn_utf8(serialized.c_str(), serialized.length(), true);
}
}

View file

@ -113,6 +113,7 @@ public:
};
SV* ConfigBase__as_hash(ConfigBase* THIS);
SV* ConfigOption_to_SV(const ConfigOption &opt, const ConfigOptionDef &def);
SV* ConfigBase__get(ConfigBase* THIS, const t_config_option_key &opt_key);
SV* ConfigBase__get_at(ConfigBase* THIS, const t_config_option_key &opt_key, size_t i);
bool ConfigBase__set(ConfigBase* THIS, const t_config_option_key &opt_key, SV* value);