diff options
Diffstat (limited to 'xs/src/slic3r')
-rw-r--r-- | xs/src/slic3r/GUI/3DScene.cpp | 8 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/Field.cpp | 3 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/GUI.cpp | 25 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/GUI.hpp | 3 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/OptionsGroup.cpp | 7 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/Tab.cpp | 46 | ||||
-rw-r--r-- | xs/src/slic3r/GUI/Tab.hpp | 2 |
7 files changed, 60 insertions, 34 deletions
diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index f492ed342..04e7f7dc6 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -27,6 +27,8 @@ #include <wx/image.h> #include <wx/settings.h> +#include "GUI.hpp" + namespace Slic3r { void GLIndexedVertexArray::load_mesh_flat_shading(const TriangleMesh &mesh) @@ -1144,7 +1146,7 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con m_data.clear(); // collects items to render - const std::string& title = preview_data.get_legend_title(); + auto title = GUI::L_str(preview_data.get_legend_title()); const GCodePreviewData::LegendItemsList& items = preview_data.get_legend_items(tool_colors); unsigned int items_count = (unsigned int)items.size(); @@ -1166,7 +1168,7 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con unsigned int max_text_height = 0; for (const GCodePreviewData::LegendItem& item : items) { - memDC.GetTextExtent(item.text, &w, &h); + memDC.GetTextExtent(GUI::from_u8(item.text), &w, &h); max_text_width = std::max(max_text_width, (unsigned int)w); max_text_height = std::max(max_text_height, (unsigned int)h); } @@ -1243,7 +1245,7 @@ bool _3DScene::LegendTexture::generate(const GCodePreviewData& preview_data, con memDC.DrawRectangle(wxRect(icon_x_inner, icon_y + 1, px_inner_square, px_inner_square)); // draw text - memDC.DrawText(item.text, text_x, icon_y + text_y_offset); + memDC.DrawText(GUI::from_u8(item.text), text_x, icon_y + text_y_offset); // update y icon_y += icon_y_step; diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index 532d3d106..045c55d96 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -23,8 +23,7 @@ namespace Slic3r { namespace GUI { // Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all // non-command events to allow the default handling to take place." event.Skip(); - std::cerr << "calling Field::on_kill_focus from " << m_opt_id<< "\n"; - // call the registered function if it is available + // call the registered function if it is available if (m_on_kill_focus!=nullptr) m_on_kill_focus(); } diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index f053d7b16..6b8613cb0 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -336,7 +336,7 @@ void add_debug_menu(wxMenuBar *menu, int event_language_change) } } }); - menu->Append(local_menu, _T("&Localization")); + menu->Append(local_menu, _(L("&Localization"))); //#endif } @@ -405,11 +405,15 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b val = boost::any_cast<double>(value); break; } - case coPercents: - case coFloats:{ - double& val = config.opt_float(opt_key, 0); - val = boost::any_cast<double>(value); + case coPercents:{ + ConfigOptionPercents* vec_new = new ConfigOptionPercents{ boost::any_cast<double>(value) }; + config.option<ConfigOptionPercents>(opt_key)->set_at(vec_new, opt_index, opt_index); break; + } + case coFloats:{ + ConfigOptionFloats* vec_new = new ConfigOptionFloats{ boost::any_cast<double>(value) }; + config.option<ConfigOptionFloats>(opt_key)->set_at(vec_new, opt_index, opt_index); + break; } case coString: config.set_key_value(opt_key, new ConfigOptionString(boost::any_cast<std::string>(value))); @@ -422,7 +426,7 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b } else{ ConfigOptionStrings* vec_new = new ConfigOptionStrings{ boost::any_cast<std::string>(value) }; - config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, opt_index); + config.option<ConfigOptionStrings>(opt_key)->set_at(vec_new, opt_index, 0); } } break; @@ -431,14 +435,14 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b break; case coBools:{ ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<bool>(value) }; - config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, opt_index); + config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0); break;} case coInt: config.set_key_value(opt_key, new ConfigOptionInt(boost::any_cast<int>(value))); break; case coInts:{ ConfigOptionInts* vec_new = new ConfigOptionInts{ boost::any_cast<int>(value) }; - config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, opt_index); + config.option<ConfigOptionInts>(opt_key)->set_at(vec_new, opt_index, 0); } break; case coEnum:{ @@ -473,7 +477,6 @@ void change_opt_value(DynamicPrintConfig& config, t_config_option_key opt_key, b void add_created_tab(Tab* panel, PresetBundle *preset_bundle) { - panel->m_show_btn_incompatible_presets = g_AppConfig->get("show_incompatible_presets").empty(); panel->create_preset_tab(preset_bundle); // Load the currently selected preset into the GUI, update the preset selection box. @@ -516,7 +519,7 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string comboCtrl->EnablePopupAnimation(false); comboCtrl->SetPopupControl(popup); - popup->SetStringValue(text); + popup->SetStringValue(from_u8(text)); popup->Bind(wxEVT_CHECKLISTBOX, [popup](wxCommandEvent& evt) { popup->OnCheckListBox(evt); }); popup->Bind(wxEVT_LISTBOX, [popup](wxCommandEvent& evt) { popup->OnListBoxSelection(evt); }); popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); @@ -527,7 +530,7 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string for (const std::string& item : items_str) { - popup->Append(item); + popup->Append(from_u8(item)); } for (unsigned int i = 0; i < popup->GetCount(); ++i) diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index e913a9450..d9760ebf3 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -35,6 +35,9 @@ class TabIface; //! With wxConvUTF8 explicitly specify that the source string is already in UTF-8 encoding #define _CHB(s) wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str() +// Minimal buffer length for translated string (char buf[MIN_BUF_LENGTH_FOR_L]) +#define MIN_BUF_LENGTH_FOR_L 128 + namespace GUI { class Tab; diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index d0084313c..f88b3f8c0 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -151,7 +151,12 @@ void OptionsGroup::append_line(const Line& line) { ConfigOptionDef option = opt.opt; // add label if any if (option.label != "") { - auto field_label = new wxStaticText(parent(), wxID_ANY, L_str(option.label) + ":", wxDefaultPosition, wxDefaultSize); + wxString str_label = L_str(option.label); +//! To correct translation by context have to use wxGETTEXT_IN_CONTEXT macro from wxWidget 3.1.1 +// wxString str_label = (option.label == "Top" || option.label == "Bottom") ? +// wxGETTEXT_IN_CONTEXT("Layers", wxString(option.label.c_str()): +// L_str(option.label); + auto field_label = new wxStaticText(parent(), wxID_ANY, str_label + ":", wxDefaultPosition, wxDefaultSize); field_label->SetFont(label_font); sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL, 0); } diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index 00c749ce3..7ce6790a1 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -113,8 +113,7 @@ 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()) { - if (m_icon_index.find(icon) == m_icon_index.end()) - icon_idx = -1; + icon_idx = (m_icon_index.find(icon) == m_icon_index.end()) ? -1 : m_icon_index.at(icon); if (icon_idx == -1) { // Add a new icon to the icon list. const auto img_icon = new wxIcon(from_u8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG); @@ -147,12 +146,25 @@ void Tab::update_tab_ui() m_presets->update_tab_ui(m_presets_choice, m_show_incompatible_presets); } +template<class T> +boost::any get_new_value(const DynamicPrintConfig &config_new, const DynamicPrintConfig &config_old, std::string opt_key, int &index) +{ + for (int i = 0; i < config_new.option<T>(opt_key)->values.size(); i++) + if (config_new.option<T>(opt_key)->values[i] != + config_old.option<T>(opt_key)->values[i]){ + index = i; + break; + } + return config_new.option<T>(opt_key)->values[index]; +} + // Load a provied DynamicConfig into the tab, modifying the active preset. // This could be used for example by setting a Wipe Tower position by interactive manipulation in the 3D view. void Tab::load_config(DynamicPrintConfig config) { bool modified = 0; boost::any value; + int opt_index = 0; for(auto opt_key : m_config->diff(config)) { switch ( config.def()->get(opt_key)->type ){ case coFloatOrPercent: @@ -168,28 +180,26 @@ void Tab::load_config(DynamicPrintConfig config) value = config.opt_string(opt_key); break; case coPercents: - value = config.option<ConfigOptionPercents>(opt_key)->values.at(0); + value = get_new_value<ConfigOptionPercents>(config, *m_config, opt_key, opt_index); break; case coFloats: - value = config.opt_float(opt_key, 0); + value = get_new_value<ConfigOptionFloats>(config, *m_config, opt_key, opt_index); break; case coStrings: - if (config.option<ConfigOptionStrings>(opt_key)->values.empty()) - value = ""; - else - value = config.opt_string(opt_key, static_cast<unsigned int>(0)); + value = config.option<ConfigOptionStrings>(opt_key)->values.empty() ? "" : + get_new_value<ConfigOptionStrings>(config, *m_config, opt_key, opt_index); break; case coBool: value = config.opt_bool(opt_key); break; case coBools: - value = config.opt_bool(opt_key, 0); + value = get_new_value<ConfigOptionBools>(config, *m_config, opt_key, opt_index); break; case coInt: value = config.opt_int(opt_key); break; case coInts: - value = config.opt_int(opt_key, 0); + value = get_new_value<ConfigOptionInts>(config, *m_config, opt_key, opt_index); break; case coEnum:{ if (opt_key.compare("external_fill_pattern") == 0 || @@ -210,7 +220,7 @@ void Tab::load_config(DynamicPrintConfig config) default: break; } - change_opt_value(*m_config, opt_key, value); + change_opt_value(*m_config, opt_key, value, opt_index); modified = 1; } if (modified) { @@ -768,14 +778,15 @@ void TabPrint::update() get_field(el)->toggle(have_wipe_tower); m_recommended_thin_wall_thickness_description_line->SetText( - PresetHints::recommended_thin_wall_thickness(*m_preset_bundle)); + from_u8(PresetHints::recommended_thin_wall_thickness(*m_preset_bundle))); Thaw(); } void TabPrint::OnActivate() { - m_recommended_thin_wall_thickness_description_line->SetText(PresetHints::recommended_thin_wall_thickness(*m_preset_bundle)); + m_recommended_thin_wall_thickness_description_line->SetText( + from_u8(PresetHints::recommended_thin_wall_thickness(*m_preset_bundle))); } void TabFilament::build() @@ -1044,7 +1055,7 @@ void TabPrinter::build() btn->Bind(wxEVT_BUTTON, [this, parent](wxCommandEvent e){ if (m_event_button_browse > 0){ wxCommandEvent event(m_event_button_browse); - event.SetString(_(L("Button BROWSE was clicked!"))); + event.SetString("Button BROWSE was clicked!"); g_wxMainFrame->ProcessWindowEvent(event); } // // # look for devices @@ -1079,7 +1090,7 @@ void TabPrinter::build() btn->Bind(wxEVT_BUTTON, [this, parent](wxCommandEvent e) { if (m_event_button_test > 0){ wxCommandEvent event(m_event_button_test); - event.SetString(_(L("Button TEST was clicked!"))); + event.SetString("Button TEST was clicked!"); g_wxMainFrame->ProcessWindowEvent(event); } // my $ua = LWP::UserAgent->new; @@ -1183,7 +1194,9 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){ void TabPrinter::build_extruder_pages(){ for (auto extruder_idx = m_extruder_pages.size(); extruder_idx < m_extruders_count; ++extruder_idx){ //# build page - auto page = add_options_page(_(L("Extruder ")) + wxString::Format(_T("%i"), extruder_idx + 1), "funnel.png", true); + char buf[MIN_BUF_LENGTH_FOR_L]; + sprintf(buf, _CHB(L("Extruder %d")), extruder_idx + 1); + auto page = add_options_page(from_u8(buf), "funnel.png", true); m_extruder_pages.push_back(page); auto optgroup = page->new_optgroup(_(L("Size"))); @@ -1613,6 +1626,7 @@ void Tab::update_ui_from_settings() { // Show the 'show / hide presets' button only for the print and filament tabs, and only if enabled // in application preferences. + m_show_btn_incompatible_presets = get_app_config()->get("show_incompatible_presets")[0] == '1' ? true : false; bool show = m_show_btn_incompatible_presets && m_presets->name().compare("printer") != 0; show ? m_btn_hide_incompatible_presets->Show() : m_btn_hide_incompatible_presets->Hide(); // If the 'show / hide presets' button is hidden, hide the incompatible presets. diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index d684005fb..208f99fec 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -106,7 +106,7 @@ protected: public: PresetBundle* m_preset_bundle; - bool m_show_btn_incompatible_presets; + bool m_show_btn_incompatible_presets = false; PresetCollection* m_presets; DynamicPrintConfig* m_config; |