Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Matena <lukasmatena@seznam.cz>2021-05-24 13:22:46 +0300
committerLukas Matena <lukasmatena@seznam.cz>2021-05-24 13:23:39 +0300
commit4960b125c54ca4ae59b9143116c6eaed884cca26 (patch)
treebd328f4b4fd653ab24aea6f43e1125d2c861fb7e
parentc05b8210f24c6d127778a8762ba1d5af1411e7fd (diff)
Fixed incorrect locales handling in the UI (Field, ObjectManipulation, etc)
-rw-r--r--src/slic3r/GUI/ConfigWizard.cpp16
-rw-r--r--src/slic3r/GUI/DoubleSlider.cpp4
-rw-r--r--src/slic3r/GUI/ExtruderSequenceDialog.cpp9
-rw-r--r--src/slic3r/GUI/Field.cpp33
-rw-r--r--src/slic3r/GUI/GUI_ObjectLayers.cpp10
-rw-r--r--src/slic3r/GUI/GUI_ObjectManipulation.cpp12
6 files changed, 56 insertions, 28 deletions
diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp
index c35172752..f7d16d843 100644
--- a/src/slic3r/GUI/ConfigWizard.cpp
+++ b/src/slic3r/GUI/ConfigWizard.cpp
@@ -1388,17 +1388,21 @@ static void focus_event(wxFocusEvent& e, wxTextCtrl* ctrl, double def_value)
{
e.Skip();
wxString str = ctrl->GetValue();
- // Replace the first occurence of comma in decimal number.
- bool was_replace = str.Replace(",", ".", false) > 0;
+
+ const char dec_sep = is_decimal_separator_point() ? '.' : ',';
+ const char dec_sep_alt = dec_sep == '.' ? ',' : '.';
+ // Replace the first incorrect separator in decimal number.
+ bool was_replaced = str.Replace(dec_sep_alt, dec_sep, false) != 0;
+
double val = 0.0;
- if (!str.ToCDouble(&val)) {
+ if (!str.ToDouble(&val)) {
if (val == 0.0)
val = def_value;
ctrl->SetValue(double_to_string(val));
show_error(nullptr, _L("Invalid numeric input."));
ctrl->SetFocus();
}
- else if (was_replace)
+ else if (was_replaced)
ctrl->SetValue(double_to_string(val));
}
@@ -1447,12 +1451,12 @@ PageDiameters::PageDiameters(ConfigWizard *parent)
void PageDiameters::apply_custom_config(DynamicPrintConfig &config)
{
double val = 0.0;
- diam_nozzle->GetValue().ToCDouble(&val);
+ diam_nozzle->GetValue().ToDouble(&val);
auto *opt_nozzle = new ConfigOptionFloats(1, val);
config.set_key_value("nozzle_diameter", opt_nozzle);
val = 0.0;
- diam_filam->GetValue().ToCDouble(&val);
+ diam_filam->GetValue().ToDouble(&val);
auto * opt_filam = new ConfigOptionFloats(1, val);
config.set_key_value("filament_diameter", opt_filam);
diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp
index 6d41e3c82..9c280dee6 100644
--- a/src/slic3r/GUI/DoubleSlider.cpp
+++ b/src/slic3r/GUI/DoubleSlider.cpp
@@ -2162,7 +2162,7 @@ static void upgrade_text_entry_dialog(wxTextEntryDialog* dlg, double min = -1.0,
bool disable = textctrl->IsEmpty();
if (!disable && min >= 0.0 && max >= 0.0) {
double value = -1.0;
- if (!textctrl->GetValue().ToCDouble(&value)) // input value couldn't be converted to double
+ if (!textctrl->GetValue().ToDouble(&value)) // input value couldn't be converted to double
disable = true;
else
disable = value < min - epsilon() || value > max + epsilon(); // is input value is out of valid range ?
@@ -2231,7 +2231,7 @@ static double get_value_to_jump(double active_value, double min_z, double max_z,
return -1.0;
double value = -1.0;
- return dlg.GetValue().ToCDouble(&value) ? value : -1.0;
+ return dlg.GetValue().ToDouble(&value) ? value : -1.0;
}
void Control::add_code_as_tick(Type type, int selected_extruder/* = -1*/)
diff --git a/src/slic3r/GUI/ExtruderSequenceDialog.cpp b/src/slic3r/GUI/ExtruderSequenceDialog.cpp
index e505f1470..8ae5e9f32 100644
--- a/src/slic3r/GUI/ExtruderSequenceDialog.cpp
+++ b/src/slic3r/GUI/ExtruderSequenceDialog.cpp
@@ -98,9 +98,14 @@ ExtruderSequenceDialog::ExtruderSequenceDialog(const DoubleSlider::ExtrudersSequ
return;
}
- str.Replace(",", ".", false);
+ char dec_sep = '.';
+ if (! is_decimal_separator_point()) {
+ str.Replace(".", ",", false);
+ dec_sep = ',';
+ }
+
double val;
- if (str == "." || !str.ToCDouble(&val) || val <= 0.0)
+ if (str == dec_sep || !str.ToDouble(&val) || val <= 0.0)
val = 3.0; // default value
if (fabs(m_sequence.interval_by_layers - val) < 0.001)
diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp
index 677577054..de8d3c104 100644
--- a/src/slic3r/GUI/Field.cpp
+++ b/src/slic3r/GUI/Field.cpp
@@ -37,12 +37,13 @@ wxString double_to_string(double const value, const int max_precision /*= 4*/)
// with the exception that here one sets the decimal separator explicitely to dot.
// If number is in scientific format, trailing zeroes belong to the exponent and cannot be removed.
if (s.find_first_of("eE") == wxString::npos) {
- const size_t posDecSep = s.find(".");
+ char dec_sep = is_decimal_separator_point() ? '.' : ',';
+ const size_t posDecSep = s.find(dec_sep);
// No decimal point => removing trailing zeroes irrelevant for integer number.
if (posDecSep != wxString::npos) {
// Find the last character to keep.
size_t posLastNonZero = s.find_last_not_of("0");
- // If it's the decimal separator itself, don't keep it neither.
+ // If it's the decimal separator itself, don't keep it either.
if (posLastNonZero == posDecSep)
-- posLastNonZero;
s.erase(posLastNonZero + 1);
@@ -236,16 +237,22 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
m_value = double(m_opt.min);
break;
}
- double val;
- // Replace the first occurence of comma in decimal number.
- str.Replace(",", ".", false);
- if (str == ".")
+ double val;
+
+ const char dec_sep = is_decimal_separator_point() ? '.' : ',';
+ const char dec_sep_alt = dec_sep == '.' ? ',' : '.';
+ // Replace the first incorrect separator in decimal number.
+ if (str.Replace(dec_sep_alt, dec_sep, false) != 0)
+ set_value(str, false);
+
+
+ if (str == dec_sep)
val = 0.0;
else
{
if (m_opt.nullable && str == na_value())
val = ConfigOptionFloatsNullable::nil_value();
- else if (!str.ToCDouble(&val))
+ else if (!str.ToDouble(&val))
{
if (!check_value) {
m_value.clear();
@@ -293,14 +300,18 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
if (m_opt.type == coFloatOrPercent && !str.IsEmpty() && str.Last() != '%')
{
double val = 0.;
- // Replace the first occurence of comma in decimal number.
- str.Replace(",", ".", false);
+ const char dec_sep = is_decimal_separator_point() ? '.' : ',';
+ const char dec_sep_alt = dec_sep == '.' ? ',' : '.';
+ // Replace the first incorrect separator in decimal number.
+ if (str.Replace(dec_sep_alt, dec_sep, false) != 0)
+ set_value(str, false);
+
// remove space and "mm" substring, if any exists
str.Replace(" ", "", true);
str.Replace("m", "", true);
- if (!str.ToCDouble(&val))
+ if (!str.ToDouble(&val))
{
if (!check_value) {
m_value.clear();
@@ -1478,7 +1489,7 @@ boost::any& PointCtrl::get_value()
!y_textctrl->GetValue().ToDouble(&y))
{
set_value(m_value.empty() ? Vec2d(0.0, 0.0) : m_value, true);
- show_error(m_parent, _L("Invalid numeric input."));
+ show_error(m_parent, _L("Invalid numeric input."));
}
else
if (m_opt.min > x || x > m_opt.max ||
diff --git a/src/slic3r/GUI/GUI_ObjectLayers.cpp b/src/slic3r/GUI/GUI_ObjectLayers.cpp
index d079a6ebd..7c13c20d6 100644
--- a/src/slic3r/GUI/GUI_ObjectLayers.cpp
+++ b/src/slic3r/GUI/GUI_ObjectLayers.cpp
@@ -397,12 +397,16 @@ coordf_t LayerRangeEditor::get_value()
wxString str = GetValue();
coordf_t layer_height;
- // Replace the first occurence of comma in decimal number.
- str.Replace(",", ".", false);
+ const char dec_sep = is_decimal_separator_point() ? '.' : ',';
+ const char dec_sep_alt = dec_sep == '.' ? ',' : '.';
+ // Replace the first incorrect separator in decimal number.
+ if (str.Replace(dec_sep_alt, dec_sep, false) != 0)
+ SetValue(str);
+
if (str == ".")
layer_height = 0.0;
else {
- if (!str.ToCDouble(&layer_height) || layer_height < 0.0f) {
+ if (!str.ToDouble(&layer_height) || layer_height < 0.0f) {
show_error(m_parent, _L("Invalid numeric input."));
SetValue(double_to_string(layer_height));
}
diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp
index 095a926ad..cdffbc88d 100644
--- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp
+++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp
@@ -1095,15 +1095,19 @@ double ManipulationEditor::get_value()
wxString str = GetValue();
double value;
- // Replace the first occurence of comma in decimal number.
- str.Replace(",", ".", false);
+ const char dec_sep = is_decimal_separator_point() ? '.' : ',';
+ const char dec_sep_alt = dec_sep == '.' ? ',' : '.';
+ // Replace the first incorrect separator in decimal number.
+ if (str.Replace(dec_sep_alt, dec_sep, false) != 0)
+ SetValue(str);
+
if (str == ".")
value = 0.0;
- if ((str.IsEmpty() || !str.ToCDouble(&value)) && !m_valid_value.IsEmpty()) {
+ if ((str.IsEmpty() || !str.ToDouble(&value)) && !m_valid_value.IsEmpty()) {
str = m_valid_value;
SetValue(str);
- str.ToCDouble(&value);
+ str.ToDouble(&value);
}
return value;