Escape from try/catch in Tab and OptionsGroup
* Deleted macro _LU8 from GUI.hpp. It's used only in Option class now. * Added macro _LS to mark string used at localization (It returns same string)
This commit is contained in:
parent
53006384d5
commit
12b9a513c1
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -47,24 +47,24 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
|
|||||||
ConfigOptionDef def;
|
ConfigOptionDef def;
|
||||||
def.type = coPoints;
|
def.type = coPoints;
|
||||||
def.default_value = new ConfigOptionPoints{ Pointf(200, 200) };
|
def.default_value = new ConfigOptionPoints{ Pointf(200, 200) };
|
||||||
def.label = _LU8("Size");
|
def.label = _LS("Size");
|
||||||
def.tooltip = _LU8("Size in X and Y of the rectangular plate.");
|
def.tooltip = _LS("Size in X and Y of the rectangular plate.");
|
||||||
Option option(def, "rect_size");
|
Option option(def, "rect_size");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
|
|
||||||
def.type = coPoints;
|
def.type = coPoints;
|
||||||
def.default_value = new ConfigOptionPoints{ Pointf(0, 0) };
|
def.default_value = new ConfigOptionPoints{ Pointf(0, 0) };
|
||||||
def.label = _LU8("Origin");
|
def.label = _LS("Origin");
|
||||||
def.tooltip = _LU8("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
|
def.tooltip = _LS("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
|
||||||
option = Option(def, "rect_origin");
|
option = Option(def, "rect_origin");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
|
|
||||||
optgroup = init_shape_options_page(_L("Circular"));
|
optgroup = init_shape_options_page(_L("Circular"));
|
||||||
def.type = coFloat;
|
def.type = coFloat;
|
||||||
def.default_value = new ConfigOptionFloat(200);
|
def.default_value = new ConfigOptionFloat(200);
|
||||||
def.sidetext = _LU8("mm");
|
def.sidetext = _LS("mm");
|
||||||
def.label = _LU8("Diameter");
|
def.label = _LS("Diameter");
|
||||||
def.tooltip = _LU8("Diameter of the print bed. It is assumed that origin (0,0) is located in the center.");
|
def.tooltip = _LS("Diameter of the print bed. It is assumed that origin (0,0) is located in the center.");
|
||||||
option = Option(def, "diameter");
|
option = Option(def, "diameter");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
|
|
||||||
|
@ -24,8 +24,9 @@ class TabIface;
|
|||||||
|
|
||||||
//! macro used to localization, return wxString
|
//! macro used to localization, return wxString
|
||||||
#define _L(s) wxGetTranslation(s)
|
#define _L(s) wxGetTranslation(s)
|
||||||
//! macro used to localization, return const CharType *
|
//! macro used to mark string used at localization,
|
||||||
#define _LU8(s) wxGetTranslation(s).ToUTF8().data()
|
//! return same string
|
||||||
|
#define _LS(s) s
|
||||||
|
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
//! macro used to localization, return const CharType *
|
||||||
|
#define _LU8(s) wxGetTranslation(s).ToUTF8().data()
|
||||||
|
|
||||||
const t_field& OptionsGroup::build_field(const Option& opt) {
|
const t_field& OptionsGroup::build_field(const Option& opt) {
|
||||||
return build_field(opt.opt_id, opt.opt);
|
return build_field(opt.opt_id, opt.opt);
|
||||||
}
|
}
|
||||||
|
@ -90,9 +90,21 @@ public:
|
|||||||
void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
|
void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
|
||||||
|
|
||||||
// return a non-owning pointer reference
|
// return a non-owning pointer reference
|
||||||
inline /*const*/ Field* get_field(t_config_option_key id) const { try { return m_fields.at(id).get(); } catch (std::out_of_range e) { return nullptr; } }
|
inline Field* get_field(t_config_option_key id) const{
|
||||||
bool set_value(t_config_option_key id, boost::any value) { try { m_fields.at(id)->set_value(value); return true; } catch (std::out_of_range e) { return false; } }
|
if (m_fields.find(id) == m_fields.end()) return nullptr;
|
||||||
boost::any get_value(t_config_option_key id) { boost::any out; try { out = m_fields.at(id)->get_value(); } catch (std::out_of_range e) { ; } return out; }
|
return m_fields.at(id).get();
|
||||||
|
}
|
||||||
|
bool set_value(t_config_option_key id, boost::any value) {
|
||||||
|
if (m_fields.find(id) == m_fields.end()) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
boost::any get_value(t_config_option_key id) {
|
||||||
|
boost::any out;
|
||||||
|
if (m_fields.find(id) == m_fields.end()) ;
|
||||||
|
else
|
||||||
|
out = m_fields.at(id)->get_value();
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
inline void enable() { for (auto& field : m_fields) field.second->enable(); }
|
||||||
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
inline void disable() { for (auto& field : m_fields) field.second->disable(); }
|
||||||
|
@ -113,8 +113,8 @@ PageShp Tab::add_options_page(wxString title, std::string icon, bool is_extruder
|
|||||||
// Index of icon in an icon list $self->{icons}.
|
// Index of icon in an icon list $self->{icons}.
|
||||||
auto icon_idx = 0;
|
auto icon_idx = 0;
|
||||||
if (!icon.empty()) {
|
if (!icon.empty()) {
|
||||||
try { icon_idx = m_icon_index.at(icon);}
|
if (m_icon_index.find(icon) == m_icon_index.end())
|
||||||
catch (std::out_of_range e) { icon_idx = -1; }
|
icon_idx = -1;
|
||||||
if (icon_idx == -1) {
|
if (icon_idx == -1) {
|
||||||
// Add a new icon to the icon list.
|
// Add a new icon to the icon list.
|
||||||
const auto img_icon = new wxIcon(wxString::FromUTF8(Slic3r::var(icon).c_str()), wxBITMAP_TYPE_PNG);
|
const auto img_icon = new wxIcon(wxString::FromUTF8(Slic3r::var(icon).c_str()), wxBITMAP_TYPE_PNG);
|
||||||
@ -962,8 +962,8 @@ void TabPrinter::build()
|
|||||||
ConfigOptionDef def;
|
ConfigOptionDef def;
|
||||||
def.type = coInt,
|
def.type = coInt,
|
||||||
def.default_value = new ConfigOptionInt(1);
|
def.default_value = new ConfigOptionInt(1);
|
||||||
def.label = _LU8("Extruders");
|
def.label = _LS("Extruders");
|
||||||
def.tooltip = _LU8("Number of extruders of the printer.");
|
def.tooltip = _LS("Number of extruders of the printer.");
|
||||||
def.min = 1;
|
def.min = 1;
|
||||||
Option option(def, "extruders_count");
|
Option option(def, "extruders_count");
|
||||||
optgroup->append_single_option_line(option);
|
optgroup->append_single_option_line(option);
|
||||||
@ -1558,17 +1558,9 @@ void Tab::save_preset(std::string name /*= ""*/)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try
|
|
||||||
{
|
|
||||||
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
|
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
|
||||||
m_presets->save_current_preset(name);
|
m_presets->save_current_preset(name);
|
||||||
}
|
|
||||||
catch (const std::exception &e)
|
|
||||||
{
|
|
||||||
show_error(this, _L("Something is wrong. It can't be saved."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
||||||
m_preset_bundle->update_compatible_with_printer(false);
|
m_preset_bundle->update_compatible_with_printer(false);
|
||||||
// Add the new item into the UI component, remove dirty flags and activate the saved item.
|
// Add the new item into the UI component, remove dirty flags and activate the saved item.
|
||||||
|
Loading…
Reference in New Issue
Block a user