From c0070a8d54f1d2897060f1f323ddf33a958d7e7c Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 22 Dec 2013 01:38:10 +0100 Subject: [PATCH] Satisfy test suite with new XS based config --- lib/Slic3r/Print.pm | 6 +++--- xs/src/Config.cpp | 4 ++-- xs/src/Config.hpp | 14 +++++++------- xs/src/Point.hpp | 6 +++--- xs/xsp/Config.xsp | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index e79585b1a..8327791d2 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -905,13 +905,13 @@ sub write_gcode { $extruder->absolute_E, $extruder->extruded_volume/1000; } - if ($Slic3r::Config->gcode_comments) { + if ($self->config->gcode_comments) { # append full config print $fh "\n"; - foreach my $opt_key (sort keys %{$Slic3r::Config}) { + foreach my $opt_key (sort @{$self->config->get_keys}) { next if $Slic3r::Config::Options->{$opt_key}{shortcut}; next if $Slic3r::Config::Options->{$opt_key}{gui_only}; - printf $fh "; %s = %s\n", $opt_key, $Slic3r::Config->serialize($opt_key); + printf $fh "; %s = %s\n", $opt_key, $self->config->serialize($opt_key); } } diff --git a/xs/src/Config.cpp b/xs/src/Config.cpp index d884e7f14..c97eb51cd 100644 --- a/xs/src/Config.cpp +++ b/xs/src/Config.cpp @@ -40,7 +40,7 @@ ConfigBase::set_deserialize(const t_config_option_key opt_key, std::string str) opt->deserialize(str); } -float +double ConfigBase::get_abs_value(const t_config_option_key opt_key) { // get option definition assert(this->def->count(opt_key) != 0); @@ -84,7 +84,7 @@ ConfigBase::get(t_config_option_key opt_key) { } else if (ConfigOptionFloats* optv = dynamic_cast(opt)) { AV* av = newAV(); av_fill(av, optv->values.size()-1); - for (std::vector::iterator it = optv->values.begin(); it != optv->values.end(); ++it) + for (std::vector::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 (ConfigOptionInt* optv = dynamic_cast(opt)) { diff --git a/xs/src/Config.hpp b/xs/src/Config.hpp index 7c3daaa33..e222651c8 100644 --- a/xs/src/Config.hpp +++ b/xs/src/Config.hpp @@ -46,11 +46,11 @@ class ConfigOptionFloat : public ConfigOption class ConfigOptionFloats : public ConfigOption { public: - std::vector values; + std::vector values; std::string serialize() { std::ostringstream ss; - for (std::vector::const_iterator it = this->values.begin(); it != this->values.end(); ++it) { + for (std::vector::const_iterator it = this->values.begin(); it != this->values.end(); ++it) { if (it - this->values.begin() != 0) ss << ","; ss << *it; } @@ -171,7 +171,7 @@ class ConfigOptionStrings : public ConfigOption class ConfigOptionFloatOrPercent : public ConfigOption { public: - float value; + double value; bool percent; ConfigOptionFloatOrPercent() : value(0), percent(false) {}; @@ -185,7 +185,7 @@ class ConfigOptionFloatOrPercent : public ConfigOption void deserialize(std::string str) { if (str.find_first_of("%") != std::string::npos) { - sscanf(str.c_str(), "%f%%", &this->value); + sscanf(str.c_str(), "%lf%%", &this->value); this->percent = true; } else { this->value = ::atof(str.c_str()); @@ -211,7 +211,7 @@ class ConfigOptionPoint : public ConfigOption }; void deserialize(std::string str) { - sscanf(str.c_str(), "%f%*1[,x]%f", &this->point.x, &this->point.y); + sscanf(str.c_str(), "%lf%*1[,x]%lf", &this->point.x, &this->point.y); }; }; @@ -237,7 +237,7 @@ class ConfigOptionPoints : public ConfigOption std::string point_str; while (std::getline(is, point_str, ',')) { Pointf point; - sscanf(point_str.c_str(), "%fx%f", &point.x, &point.y); + sscanf(point_str.c_str(), "%lfx%lf", &point.x, &point.y); this->points.push_back(point); } }; @@ -392,7 +392,7 @@ class ConfigBase void apply(ConfigBase &other, bool ignore_nonexistent = false); std::string serialize(const t_config_option_key opt_key); void set_deserialize(const t_config_option_key opt_key, std::string str); - float get_abs_value(const t_config_option_key opt_key); + double get_abs_value(const t_config_option_key opt_key); #ifdef SLIC3RXS SV* as_hash(); diff --git a/xs/src/Point.hpp b/xs/src/Point.hpp index 61592a805..507d082c9 100644 --- a/xs/src/Point.hpp +++ b/xs/src/Point.hpp @@ -47,9 +47,9 @@ class Point class Pointf { public: - float x; - float y; - explicit Pointf(float _x = 0, float _y = 0): x(_x), y(_y) {}; + double x; + double y; + explicit Pointf(double _x = 0, double _y = 0): x(_x), y(_y) {}; #ifdef SLIC3RXS void from_SV(SV* point_sv); diff --git a/xs/xsp/Config.xsp b/xs/xsp/Config.xsp index fb1a0c463..7373dbee9 100644 --- a/xs/xsp/Config.xsp +++ b/xs/xsp/Config.xsp @@ -14,7 +14,7 @@ void set(t_config_option_key opt_key, SV* value); void set_deserialize(t_config_option_key opt_key, std::string str); std::string serialize(t_config_option_key opt_key); - float get_abs_value(t_config_option_key opt_key); + double get_abs_value(t_config_option_key opt_key); void apply(DynamicPrintConfig* other) %code{% THIS->apply(*other, true); %}; void apply_static(PrintConfig* other) @@ -35,7 +35,7 @@ void set(t_config_option_key opt_key, SV* value); void set_deserialize(t_config_option_key opt_key, std::string str); std::string serialize(t_config_option_key opt_key); - float get_abs_value(t_config_option_key opt_key); + double get_abs_value(t_config_option_key opt_key); void apply_dynamic(DynamicPrintConfig* other) %code{% THIS->apply(*other, true); %}; std::vector get_keys()