mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-22 00:01:09 -06:00
Make tests pass
This commit is contained in:
parent
a2cbb261cb
commit
07b9b12475
16 changed files with 159 additions and 82 deletions
|
@ -130,9 +130,9 @@ ConfigBase::get(t_config_option_key opt_key) {
|
|||
return optv->point.to_SV_pureperl();
|
||||
} else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) {
|
||||
AV* av = newAV();
|
||||
av_fill(av, optv->points.size()-1);
|
||||
for (Pointfs::iterator it = optv->points.begin(); it != optv->points.end(); ++it)
|
||||
av_store(av, it - optv->points.begin(), it->to_SV_pureperl());
|
||||
av_fill(av, optv->values.size()-1);
|
||||
for (Pointfs::iterator it = optv->values.begin(); it != optv->values.end(); ++it)
|
||||
av_store(av, it - optv->values.begin(), it->to_SV_pureperl());
|
||||
return newRV_noinc((SV*)av);
|
||||
} else if (ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt)) {
|
||||
return newSViv(optv->value ? 1 : 0);
|
||||
|
@ -148,6 +148,28 @@ ConfigBase::get(t_config_option_key opt_key) {
|
|||
}
|
||||
}
|
||||
|
||||
SV*
|
||||
ConfigBase::get_at(t_config_option_key opt_key, size_t i) {
|
||||
ConfigOption* opt = this->option(opt_key);
|
||||
if (opt == NULL) return &PL_sv_undef;
|
||||
|
||||
if (ConfigOptionFloats* optv = dynamic_cast<ConfigOptionFloats*>(opt)) {
|
||||
return newSVnv(optv->get_at(i));
|
||||
} else if (ConfigOptionInts* optv = dynamic_cast<ConfigOptionInts*>(opt)) {
|
||||
return newSViv(optv->get_at(i));
|
||||
} else if (ConfigOptionStrings* optv = dynamic_cast<ConfigOptionStrings*>(opt)) {
|
||||
// we don't serialize() because that would escape newlines
|
||||
std::string val = optv->get_at(i);
|
||||
return newSVpvn(val.c_str(), val.length());
|
||||
} else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) {
|
||||
return optv->get_at(i).to_SV_pureperl();
|
||||
} else if (ConfigOptionBools* optv = dynamic_cast<ConfigOptionBools*>(opt)) {
|
||||
return newSViv(optv->get_at(i) ? 1 : 0);
|
||||
} else {
|
||||
return &PL_sv_undef;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ConfigBase::set(t_config_option_key opt_key, SV* value) {
|
||||
ConfigOption* opt = this->option(opt_key, true);
|
||||
|
@ -193,14 +215,14 @@ ConfigBase::set(t_config_option_key opt_key, SV* value) {
|
|||
} else if (ConfigOptionPoint* optv = dynamic_cast<ConfigOptionPoint*>(opt)) {
|
||||
optv->point.from_SV(value);
|
||||
} else if (ConfigOptionPoints* optv = dynamic_cast<ConfigOptionPoints*>(opt)) {
|
||||
optv->points.clear();
|
||||
optv->values.clear();
|
||||
AV* av = (AV*)SvRV(value);
|
||||
const size_t len = av_len(av)+1;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
SV** elem = av_fetch(av, i, 0);
|
||||
Pointf point;
|
||||
point.from_SV(*elem);
|
||||
optv->points.push_back(point);
|
||||
optv->values.push_back(point);
|
||||
}
|
||||
} else if (ConfigOptionBool* optv = dynamic_cast<ConfigOptionBool*>(opt)) {
|
||||
optv->value = SvTRUE(value);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Point.hpp"
|
||||
|
@ -24,6 +25,22 @@ class ConfigOption {
|
|||
virtual void deserialize(std::string str) = 0;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class ConfigOptionVector
|
||||
{
|
||||
public:
|
||||
virtual ~ConfigOptionVector() {};
|
||||
std::vector<T> values;
|
||||
|
||||
T get_at(size_t i) {
|
||||
try {
|
||||
return this->values.at(i);
|
||||
} catch (const std::out_of_range& oor) {
|
||||
return this->values.front();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
class ConfigOptionFloat : public ConfigOption
|
||||
{
|
||||
public:
|
||||
|
@ -43,10 +60,9 @@ class ConfigOptionFloat : public ConfigOption
|
|||
};
|
||||
};
|
||||
|
||||
class ConfigOptionFloats : public ConfigOption
|
||||
class ConfigOptionFloats : public ConfigOption, public ConfigOptionVector<double>
|
||||
{
|
||||
public:
|
||||
std::vector<double> values;
|
||||
|
||||
std::string serialize() {
|
||||
std::ostringstream ss;
|
||||
|
@ -86,10 +102,9 @@ class ConfigOptionInt : public ConfigOption
|
|||
};
|
||||
};
|
||||
|
||||
class ConfigOptionInts : public ConfigOption
|
||||
class ConfigOptionInts : public ConfigOption, public ConfigOptionVector<int>
|
||||
{
|
||||
public:
|
||||
std::vector<int> values;
|
||||
|
||||
std::string serialize() {
|
||||
std::ostringstream ss;
|
||||
|
@ -144,10 +159,9 @@ class ConfigOptionString : public ConfigOption
|
|||
};
|
||||
|
||||
// semicolon-separated strings
|
||||
class ConfigOptionStrings : public ConfigOption
|
||||
class ConfigOptionStrings : public ConfigOption, public ConfigOptionVector<std::string>
|
||||
{
|
||||
public:
|
||||
std::vector<std::string> values;
|
||||
|
||||
std::string serialize() {
|
||||
std::ostringstream ss;
|
||||
|
@ -215,15 +229,14 @@ class ConfigOptionPoint : public ConfigOption
|
|||
};
|
||||
};
|
||||
|
||||
class ConfigOptionPoints : public ConfigOption
|
||||
class ConfigOptionPoints : public ConfigOption, public ConfigOptionVector<Pointf>
|
||||
{
|
||||
public:
|
||||
Pointfs points;
|
||||
|
||||
std::string serialize() {
|
||||
std::ostringstream ss;
|
||||
for (Pointfs::const_iterator it = this->points.begin(); it != this->points.end(); ++it) {
|
||||
if (it - this->points.begin() != 0) ss << ",";
|
||||
for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
|
||||
if (it - this->values.begin() != 0) ss << ",";
|
||||
ss << it->x;
|
||||
ss << "x";
|
||||
ss << it->y;
|
||||
|
@ -232,13 +245,13 @@ class ConfigOptionPoints : public ConfigOption
|
|||
};
|
||||
|
||||
void deserialize(std::string str) {
|
||||
this->points.clear();
|
||||
this->values.clear();
|
||||
std::istringstream is(str);
|
||||
std::string point_str;
|
||||
while (std::getline(is, point_str, ',')) {
|
||||
Pointf point;
|
||||
sscanf(point_str.c_str(), "%lfx%lf", &point.x, &point.y);
|
||||
this->points.push_back(point);
|
||||
this->values.push_back(point);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -260,10 +273,9 @@ class ConfigOptionBool : public ConfigOption
|
|||
};
|
||||
};
|
||||
|
||||
class ConfigOptionBools : public ConfigOption
|
||||
class ConfigOptionBools : public ConfigOption, public ConfigOptionVector<bool>
|
||||
{
|
||||
public:
|
||||
std::vector<bool> values;
|
||||
|
||||
std::string serialize() {
|
||||
std::ostringstream ss;
|
||||
|
@ -398,6 +410,7 @@ class ConfigBase
|
|||
#ifdef SLIC3RXS
|
||||
SV* as_hash();
|
||||
SV* get(t_config_option_key opt_key);
|
||||
SV* get_at(t_config_option_key opt_key, size_t i);
|
||||
void set(t_config_option_key opt_key, SV* value);
|
||||
#endif
|
||||
};
|
||||
|
|
|
@ -1131,8 +1131,8 @@ class PrintConfig : public virtual StaticConfig
|
|||
this->external_perimeters_first.value = false;
|
||||
this->extruder_clearance_height.value = 20;
|
||||
this->extruder_clearance_radius.value = 20;
|
||||
this->extruder_offset.points.resize(1);
|
||||
this->extruder_offset.points[0] = Pointf(0,0);
|
||||
this->extruder_offset.values.resize(1);
|
||||
this->extruder_offset.values[0] = Pointf(0,0);
|
||||
this->extrusion_axis.value = "E";
|
||||
this->extrusion_multiplier.values.resize(1);
|
||||
this->extrusion_multiplier.values[0] = 1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue