mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 15:37:30 -06:00
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:
parent
7beed5d6dd
commit
c7e78511f5
5 changed files with 72 additions and 11 deletions
|
@ -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);
|
||||
|
@ -1734,11 +1774,16 @@ 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)
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -38,6 +38,7 @@ using t_change = std::function<void(const t_config_option_key&, const boost::any
|
|||
using t_back_to_init = std::function<void(const std::string&)>;
|
||||
|
||||
wxString double_to_string(double const value, const int max_precision = 4);
|
||||
wxString get_thumbnail_string(const Vec2d& value);
|
||||
wxString get_thumbnails_string(const std::vector<Vec2d>& values);
|
||||
|
||||
class Field {
|
||||
|
|
|
@ -198,6 +198,10 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
|
|||
config.option<ConfigOptionEnumsGeneric>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
}
|
||||
break;
|
||||
case coPoint:{
|
||||
config.set_key_value(opt_key, new ConfigOptionPoint(boost::any_cast<Vec2d>(value)));
|
||||
}
|
||||
break;
|
||||
case coPoints:{
|
||||
if (opt_key == "printable_area" || opt_key == "bed_exclude_area" || opt_key=="thumbnail_size") {
|
||||
config.option<ConfigOptionPoints>(opt_key)->values = boost::any_cast<std::vector<Vec2d>>(value);
|
||||
|
|
|
@ -77,6 +77,7 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co
|
|||
case coEnums:
|
||||
m_fields.emplace(id, Choice::Create<Choice>(this->ctrl_parent(), opt, id));
|
||||
break;
|
||||
case coPoint:
|
||||
case coPoints:
|
||||
m_fields.emplace(id, PointCtrl::Create<PointCtrl>(this->ctrl_parent(), opt, id));
|
||||
break;
|
||||
|
@ -1032,6 +1033,9 @@ boost::any ConfigOptionsGroup::get_config_value(const DynamicPrintConfig& config
|
|||
case coEnums:
|
||||
ret = config.opt_int(opt_key, idx);
|
||||
break;
|
||||
case coPoint:
|
||||
ret = config.option<ConfigOptionPoint>(opt_key)->value;
|
||||
break;
|
||||
case coPoints:
|
||||
if (opt_key == "printable_area")
|
||||
ret = config.option<ConfigOptionPoints>(opt_key)->values;
|
||||
|
@ -1144,6 +1148,9 @@ boost::any ConfigOptionsGroup::get_config_value2(const DynamicPrintConfig& confi
|
|||
case coEnums:
|
||||
ret = config.opt_int(opt_key, idx);
|
||||
break;
|
||||
case coPoint:
|
||||
ret = config.option<ConfigOptionPoint>(opt_key)->value;
|
||||
break;
|
||||
case coPoints:
|
||||
if (opt_key == "printable_area")
|
||||
ret = config.option<ConfigOptionPoints>(opt_key)->values;
|
||||
|
|
|
@ -1349,6 +1349,10 @@ static wxString get_string_value(std::string opt_key, const DynamicPrintConfig&
|
|||
opt_key == "sparse_infill_pattern",
|
||||
opt_idx);
|
||||
}
|
||||
case coPoint: {
|
||||
Vec2d val = config.opt<ConfigOptionPoint>(opt_key)->value;
|
||||
return from_u8((boost::format("[%1%]") % ConfigOptionPoint(val).serialize()).str());
|
||||
}
|
||||
case coPoints: {
|
||||
//BBS: add bed_exclude_area
|
||||
if (opt_key == "printable_area") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue