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:
YuSanka 2018-02-16 15:41:33 +01:00
parent 53006384d5
commit 12b9a513c1
7 changed files with 358 additions and 67 deletions

File diff suppressed because it is too large Load Diff

View File

@ -47,24 +47,24 @@ void BedShapePanel::build_panel(ConfigOptionPoints* default_pt)
ConfigOptionDef def;
def.type = coPoints;
def.default_value = new ConfigOptionPoints{ Pointf(200, 200) };
def.label = _LU8("Size");
def.tooltip = _LU8("Size in X and Y of the rectangular plate.");
def.label = _LS("Size");
def.tooltip = _LS("Size in X and Y of the rectangular plate.");
Option option(def, "rect_size");
optgroup->append_single_option_line(option);
def.type = coPoints;
def.default_value = new ConfigOptionPoints{ Pointf(0, 0) };
def.label = _LU8("Origin");
def.tooltip = _LU8("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
def.label = _LS("Origin");
def.tooltip = _LS("Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.");
option = Option(def, "rect_origin");
optgroup->append_single_option_line(option);
optgroup = init_shape_options_page(_L("Circular"));
def.type = coFloat;
def.default_value = new ConfigOptionFloat(200);
def.sidetext = _LU8("mm");
def.label = _LU8("Diameter");
def.tooltip = _LU8("Diameter of the print bed. It is assumed that origin (0,0) is located in the center.");
def.sidetext = _LS("mm");
def.label = _LS("Diameter");
def.tooltip = _LS("Diameter of the print bed. It is assumed that origin (0,0) is located in the center.");
option = Option(def, "diameter");
optgroup->append_single_option_line(option);

View File

@ -24,8 +24,9 @@ class TabIface;
//! macro used to localization, return wxString
#define _L(s) wxGetTranslation(s)
//! macro used to localization, return const CharType *
#define _LU8(s) wxGetTranslation(s).ToUTF8().data()
//! macro used to mark string used at localization,
//! return same string
#define _LS(s) s
namespace GUI {

View File

@ -7,6 +7,9 @@
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) {
return build_field(opt.opt_id, opt.opt);
}

View File

@ -90,9 +90,21 @@ public:
void append_single_option_line(const Option& option) { append_line(create_single_option_line(option)); }
// 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; } }
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; } }
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; }
inline Field* get_field(t_config_option_key id) const{
if (m_fields.find(id) == m_fields.end()) return nullptr;
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 disable() { for (auto& field : m_fields) field.second->disable(); }

View File

@ -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}.
auto icon_idx = 0;
if (!icon.empty()) {
try { icon_idx = m_icon_index.at(icon);}
catch (std::out_of_range e) { icon_idx = -1; }
if (m_icon_index.find(icon) == m_icon_index.end())
icon_idx = -1;
if (icon_idx == -1) {
// Add a new icon to the icon list.
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;
def.type = coInt,
def.default_value = new ConfigOptionInt(1);
def.label = _LU8("Extruders");
def.tooltip = _LU8("Number of extruders of the printer.");
def.label = _LS("Extruders");
def.tooltip = _LS("Number of extruders of the printer.");
def.min = 1;
Option option(def, "extruders_count");
optgroup->append_single_option_line(option);
@ -1558,17 +1558,9 @@ void Tab::save_preset(std::string name /*= ""*/)
return;
}
}
try
{
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
m_presets->save_current_preset(name);
}
catch (const std::exception &e)
{
show_error(this, _L("Something is wrong. It can't be saved."));
return;
}
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
m_presets->save_current_preset(name);
// Mark the print & filament enabled if they are compatible with the currently selected preset.
m_preset_bundle->update_compatible_with_printer(false);
// Add the new item into the UI component, remove dirty flags and activate the saved item.