Add get_point3 to interface; add I/O

This commit is contained in:
Joseph Lenox 2018-07-04 16:31:55 -05:00 committed by Joseph Lenox
parent fbdccb0c96
commit e66cda51bf
2 changed files with 17 additions and 4 deletions

View File

@ -5,6 +5,7 @@
#include <string>
#include <limits>
#include <regex>
#include <tuple>
#include <boost/any.hpp>
#include "ConfigBase.hpp"
@ -49,6 +50,7 @@ public:
virtual std::string get_string() { Slic3r::Log::warn(this->LogChannel(), "get_string does not exist"s); return 0; } //< return 0 all the time if this is not implemented.
virtual Slic3r::Pointf get_point() { Slic3r::Log::warn(this->LogChannel(), "get_point does not exist"s); return Slic3r::Pointf(); } //< return 0 all the time if this is not implemented.
virtual Slic3r::Pointf3 get_point3() { Slic3r::Log::warn(this->LogChannel(), "get_point3 does not exist"s); return Slic3r::Pointf3(); } //< return 0 all the time if this is not implemented.
/// Provide access in a generic fashion to the underlying Window.
virtual wxWindow* get_window() { return this->window; }
@ -300,10 +302,8 @@ public:
void set_value(boost::any value) override; //< Implements set_value
Pointf get_point() override; /// return a Slic3r::Pointf corresponding to the textctrl contents.
/// Return the underlying sizer.
wxSizer* get_sizer() { return _sizer; };
Slic3r::Pointf get_point() override; //< return a Slic3r::Pointf corresponding to the textctrl contents.
Slic3r::Pointf3 get_point3() override; //< return a Slic3r::Pointf3 corresponding to the textctrl contents.
/// Function to call when the contents of this change.
std::function<void (const std::string&, std::tuple<std::string, std::string> value)> on_change {nullptr};
@ -339,6 +339,7 @@ private:
wxBoxSizer* _sizer {nullptr};
void _set_value(Slic3r::Pointf value);
void _set_value(Slic3r::Pointf3 value);
void _set_value(std::string value);
/// Remove extra zeroes generated from std::to_string on doubles

View File

@ -20,10 +20,19 @@ Slic3r::Pointf UI_Point::get_point() {
return Pointf(std::stod(this->_ctrl_x->GetValue().ToStdString()), std::stod(this->_ctrl_y->GetValue().ToStdString()));
}
Slic3r::Pointf3 UI_Point::get_point3() {
return Pointf3(
std::stod(this->_ctrl_x->GetValue().ToStdString()),
std::stod(this->_ctrl_y->GetValue().ToStdString()),
0.0);
}
void UI_Point::set_value(boost::any value) {
// type detection and handing off to children
if (value.type() == typeid(Slic3r::Pointf)) {
this->_set_value(boost::any_cast<Pointf>(value));
} else if (value.type() == typeid(Slic3r::Pointf3)) {
this->_set_value(boost::any_cast<Pointf3>(value));
} else if (value.type() == typeid(std::string)) {
this->_set_value(boost::any_cast<std::string>(value));
} else if (value.type() == typeid(wxString)) {
@ -38,6 +47,9 @@ void UI_Point::_set_value(Slic3r::Pointf value) {
this->_ctrl_x->SetValue(trim_zeroes(std::to_string(value.x)));
this->_ctrl_y->SetValue(trim_zeroes(std::to_string(value.y)));
}
void UI_Point::_set_value(Slic3r::Pointf3 value) {
this->_set_value(Pointf(value.x, value.y));
}
void UI_Point::_set_value(std::string value) {
/// parse the string into the two parts.