FIX: coPoint type couldn't display

This causes the printer setting page unable to display becase I added a
coPoint type option best_object_pos.

Add reading and writing coPoint type configs solves the problem.

Jira: STUDIO-4303

Change-Id: I34e40e567236d28ab1a7be265128275191fcc935
This commit is contained in:
Arthur 2023-08-31 19:29:52 +08:00 committed by Lane.Wei
parent 7beed5d6dd
commit c7e78511f5
5 changed files with 72 additions and 11 deletions

View file

@ -66,6 +66,12 @@ wxString double_to_string(double const value, const int max_precision /*= 4*/)
return s;
}
wxString get_thumbnail_string(const Vec2d& value)
{
wxString ret_str = wxString::Format("%.2fx%.2f", value[0], value[1]);
return ret_str;
}
wxString get_thumbnails_string(const std::vector<Vec2d>& values)
{
wxString ret_str;
@ -367,6 +373,34 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
m_value = into_u8(str);
break; }
case coPoint:{
Vec2d out_value;
str.Replace(" ", wxEmptyString, true);
if (!str.IsEmpty()) {
bool invalid_val = true;
double x, y;
wxStringTokenizer thumbnail(str, "x");
if (thumbnail.HasMoreTokens()) {
wxString x_str = thumbnail.GetNextToken();
if (x_str.ToDouble(&x) && thumbnail.HasMoreTokens()) {
wxString y_str = thumbnail.GetNextToken();
if (y_str.ToDouble(&y) && !thumbnail.HasMoreTokens()) {
out_value = Vec2d(x, y);
invalid_val = false;
}
}
}
if (invalid_val) {
wxString text_value;
if (!m_value.empty()) text_value = get_thumbnail_string(boost::any_cast<Vec2d>(m_value));
set_value(text_value, true);
show_error(m_parent, format_wxstr(_L("Invalid format. Expected vector format: \"%1%\""), "XxY, XxY, ..."));
}
}
m_value = out_value;
break; }
case coPoints: {
std::vector<Vec2d> out_values;
@ -446,7 +480,7 @@ void Field::sys_color_changed()
template<class T>
bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type)
{
if (!win || (static_cast<T*>(win)->GetValue().empty() && type != coString && type != coStrings && type != coPoints))
if (!win || (static_cast<T*>(win)->GetValue().empty() && type != coString && type != coStrings && type != coPoints && type != coPoint))
return false;
return true;
}
@ -495,6 +529,9 @@ void TextCtrl::BUILD() {
text_value = vec->get_at(m_opt_idx);
break;
}
case coPoint:
text_value = get_thumbnail_string(m_opt.get_default_value<ConfigOptionPoint>()->value);
break;
case coPoints:
text_value = get_thumbnails_string(m_opt.get_default_value<ConfigOptionPoints>()->values);
break;
@ -1621,8 +1658,11 @@ void PointCtrl::BUILD()
auto temp = new wxBoxSizer(wxHORIZONTAL);
const wxSize field_size(4 * m_em_unit, -1);
auto default_pt = m_opt.get_default_value<ConfigOptionPoints>()->values.at(0);
Slic3r::Vec2d default_pt;
if(m_opt.type == coPoints)
default_pt = m_opt.get_default_value<ConfigOptionPoints>()->values.at(0);
else
default_pt = m_opt.get_default_value<ConfigOptionPoint>()->value;
double val = default_pt(0);
wxString X = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
val = default_pt(1);
@ -1733,14 +1773,19 @@ void PointCtrl::set_value(const Vec2d& value, bool change_event)
void PointCtrl::set_value(const boost::any& value, bool change_event)
{
Vec2d pt(Vec2d::Zero());
const Vec2d *ptf = boost::any_cast<Vec2d>(&value);
if (!ptf)
{
ConfigOptionPoints* pts = boost::any_cast<ConfigOptionPoints*>(value);
pt = pts->values.at(0);
}
else
pt = *ptf;
const Vec2d* ptf = boost::any_cast<Vec2d>(&value);
if (!ptf) {
if (m_opt.type == coPoint) {
ConfigOptionPoint* pts = boost::any_cast<ConfigOptionPoint*>(value);
pt = pts->value;
}
else {
ConfigOptionPoints* pts = boost::any_cast<ConfigOptionPoints*>(value);
pt = pts->values.at(0);
}
}
else
pt = *ptf;
set_value(pt, change_event);
}