diff options
author | Vojtech Kral <vojtech@kral.hk> | 2019-01-02 17:11:05 +0300 |
---|---|---|
committer | Vojtech Kral <vojtech@kral.hk> | 2019-01-02 17:53:52 +0300 |
commit | 2db0906071495ea2ddedef0a30a076954fb49007 (patch) | |
tree | 08d93d1400002cecf817cc3f89dc7bbe0117ec40 | |
parent | 760b1cd9bc9485c4995f25aa20f80f77ec6205e6 (diff) |
Fix fs::path <-> wxString conversions
-rw-r--r-- | src/slic3r/GUI/GUI.cpp | 15 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI.hpp | 15 | ||||
-rw-r--r-- | src/slic3r/GUI/GUI_App.cpp | 2 | ||||
-rw-r--r-- | src/slic3r/GUI/MainFrame.cpp | 2 | ||||
-rw-r--r-- | src/slic3r/GUI/Plater.cpp | 41 | ||||
-rw-r--r-- | src/slic3r/GUI/PrintHostDialogs.cpp | 2 |
6 files changed, 51 insertions, 26 deletions
diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 04e9a315c..0761845b6 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -4,6 +4,7 @@ #include "WipeTowerDialog.hpp" #include <assert.h> +#include <string> #include <boost/lexical_cast.hpp> #include <boost/algorithm/string.hpp> @@ -314,6 +315,20 @@ std::string into_u8(const wxString &str) return std::string(buffer_utf8.data()); } +wxString from_path(const boost::filesystem::path &path) +{ +#ifdef _WIN32 + return wxString(path.string<std::wstring>()); +#else + return wxString::FromUTF8(path.string<std::string>()); +#endif +} + +boost::filesystem::path into_path(const wxString &str) +{ + return boost::filesystem::path(str.wx_str()); +} + bool get_current_screen_size(wxWindow *window, unsigned &width, unsigned &height) { const auto idx = wxDisplay::GetFromWindow(window); diff --git a/src/slic3r/GUI/GUI.hpp b/src/slic3r/GUI/GUI.hpp index 3ca4292a9..79b21b503 100644 --- a/src/slic3r/GUI/GUI.hpp +++ b/src/slic3r/GUI/GUI.hpp @@ -1,6 +1,10 @@ #ifndef slic3r_GUI_hpp_ #define slic3r_GUI_hpp_ +#include <boost/filesystem/path.hpp> + +#include <wx/string.h> + #include "libslic3r/Config.hpp" class wxWindow; @@ -8,7 +12,6 @@ class wxMenuBar; class wxNotebook; class wxComboCtrl; class wxFileDialog; -class wxString; class wxTopLevelWindow; namespace Slic3r { @@ -53,10 +56,16 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string // encoded inside an int. int combochecklist_get_flags(wxComboCtrl* comboCtrl); -// Return wxString from std::string in UTF8 +// wxString conversions: + +// wxString from std::string in UTF8 wxString from_u8(const std::string &str); -// Return std::string in UTF8 from wxString +// std::string in UTF8 from wxString std::string into_u8(const wxString &str); +// wxString from boost path +wxString from_path(const boost::filesystem::path &path); +// boost path from wxString +boost::filesystem::path into_path(const wxString &str); // Returns the dimensions of the screen on which the main frame is displayed bool get_current_screen_size(wxWindow *window, unsigned &width, unsigned &height); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 5db2a95cd..0138c1229 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -382,7 +382,7 @@ void GUI_App::import_model(wxWindow *parent, wxArrayString& input_files) input_files.Clear(); wxFileDialog dialog(parent ? parent : GetTopWindow(), _(L("Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):")), - app_config->get_last_dir(), "", + from_u8(app_config->get_last_dir()), "", file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() == wxID_OK) diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 41339262b..33c4cf32b 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -224,7 +224,7 @@ void MainFrame::init_menubar() wxMenuItem* item_open = append_menu_item(fileMenu, wxID_ANY, _(L("Open…\tCtrl+O")), _(L("Open a project file")), [this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, "brick_add.png"); wxMenuItem* item_save = append_menu_item(fileMenu, wxID_ANY, _(L("Save\tCtrl+S")), _(L("Save current project file")), - [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(m_plater->get_project_filename().wx_str()); }, "disk.png"); + [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(into_path(m_plater->get_project_filename())); }, "disk.png"); wxMenuItem* item_save_as = append_menu_item(fileMenu, wxID_ANY, _(L("Save as…\tCtrl+Alt+S")), _(L("Save current project file as")), [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(); }, "disk.png"); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 82fa99bac..92c408670 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -863,7 +863,7 @@ bool PlaterDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &fi std::vector<fs::path> paths; for (const auto &filename : filenames) { - fs::path path(filename); + fs::path path(into_path(filename)); if (std::regex_match(path.string(), pattern_drop)) { paths.push_back(std::move(path)); @@ -1396,7 +1396,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_ for (size_t i = 0; i < input_files.size(); i++) { const auto &path = input_files[i]; const auto filename = path.filename(); - const auto dlg_info = wxString::Format(_(L("Processing input file %s\n")), filename.string()); + const auto dlg_info = wxString::Format(_(L("Processing input file %s\n")), from_path(filename)); dlg.Update(100 * i / input_files.size(), dlg_info); const bool type_3mf = std::regex_match(path.string(), pattern_3mf); @@ -1470,7 +1470,7 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_ if ( obj->volumes.size()>1 ) { Slic3r::GUI::show_error(nullptr, wxString::Format(_(L("You can't to add the object(s) from %s because of one or some of them is(are) multi-part")), - filename.string())); + from_path(filename))); return std::vector<size_t>(); } } @@ -1609,8 +1609,8 @@ std::unique_ptr<CheckboxFileDialog> Plater::priv::get_export_file(GUI::FileType ((file_type == FT_AMF) || (file_type == FT_3MF)) ? _(L("Export print config")) : "", true, _(L("Save file as:")), - output_file.parent_path().string(), - output_file.filename().string(), + from_path(output_file.parent_path()), + from_path(output_file.filename()), wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); @@ -1619,7 +1619,7 @@ std::unique_ptr<CheckboxFileDialog> Plater::priv::get_export_file(GUI::FileType return nullptr; } - fs::path path(dlg->GetPath()); + fs::path path(into_path(dlg->GetPath())); wxGetApp().app_config->update_last_output_dir(path.parent_path().string()); return dlg; @@ -2855,7 +2855,7 @@ void Plater::load_project() p->project_filename = input_file; std::vector<fs::path> input_paths; - input_paths.push_back(input_file.wx_str()); + input_paths.push_back(into_path(input_file)); load_files(input_paths); } @@ -2868,7 +2868,7 @@ void Plater::add_model() std::vector<fs::path> input_paths; for (const auto &file : input_files) { - input_paths.push_back(file.wx_str()); + input_paths.push_back(into_path(file)); } load_files(input_paths, true, false); } @@ -2882,7 +2882,7 @@ void Plater::extract_config_from_project() return; std::vector<fs::path> input_paths; - input_paths.push_back(input_file.wx_str()); + input_paths.push_back(into_path(input_file)); load_files(input_paths, false, true); } @@ -3033,15 +3033,15 @@ void Plater::export_gcode(fs::path output_path) wxFileDialog dlg(this, (printer_technology() == ptFFF) ? _(L("Save G-code file as:")) : _(L("Save Zip file as:")), start_dir, - default_output_file.filename().string(), + from_path(default_output_file.filename()), GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_PNGZIP, default_output_file.extension().string()), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); if (dlg.ShowModal() == wxID_OK) { - fs::path path(dlg.GetPath()); + fs::path path = into_path(dlg.GetPath()); wxGetApp().app_config->update_last_output_dir(path.parent_path().string()); - output_path = path; + output_path = std::move(path); } } else { try { @@ -3065,8 +3065,8 @@ void Plater::export_stl(bool selection_only) if (! dialog) { return; } // Store a binary STL - wxString path = dialog->GetPath(); - auto path_cstr = path.c_str(); + const wxString path = dialog->GetPath(); + const std::string path_u8 = into_u8(path); TriangleMesh mesh; if (selection_only) { @@ -3080,7 +3080,7 @@ void Plater::export_stl(bool selection_only) auto mesh = p->model.mesh(); } - Slic3r::store_stl(path_cstr, &mesh, true); + Slic3r::store_stl(path_u8.c_str(), &mesh, true); p->statusbar()->set_status_text(wxString::Format(_(L("STL file exported to %s")), path)); } @@ -3091,11 +3091,11 @@ void Plater::export_amf() auto dialog = p->get_export_file(FT_AMF); if (! dialog) { return; } - wxString path = dialog->GetPath(); - auto path_cstr = path.c_str(); + const wxString path = dialog->GetPath(); + const std::string path_u8 = into_u8(path); DynamicPrintConfig cfg = wxGetApp().preset_bundle->full_config_secure(); - if (Slic3r::store_amf(path_cstr, &p->model, dialog->get_checkbox_value() ? &cfg : nullptr)) { + if (Slic3r::store_amf(path_u8.c_str(), &p->model, dialog->get_checkbox_value() ? &cfg : nullptr)) { // Success p->statusbar()->set_status_text(wxString::Format(_(L("AMF file exported to %s")), path)); } else { @@ -3118,13 +3118,14 @@ void Plater::export_3mf(const boost::filesystem::path& output_path) export_config = dialog->get_checkbox_value(); } else - path = output_path.string(); + path = from_path(output_path); if (!path.Lower().EndsWith(".3mf")) return; DynamicPrintConfig cfg = wxGetApp().preset_bundle->full_config_secure(); - if (Slic3r::store_3mf(path.c_str(), &p->model, export_config ? &cfg : nullptr)) { + const std::string path_u8 = into_u8(path); + if (Slic3r::store_3mf(path_u8.c_str(), &p->model, export_config ? &cfg : nullptr)) { // Success p->statusbar()->set_status_text(wxString::Format(_(L("3MF file exported to %s")), path)); } else { diff --git a/src/slic3r/GUI/PrintHostDialogs.cpp b/src/slic3r/GUI/PrintHostDialogs.cpp index 8c0c0fc85..c2a94181e 100644 --- a/src/slic3r/GUI/PrintHostDialogs.cpp +++ b/src/slic3r/GUI/PrintHostDialogs.cpp @@ -49,7 +49,7 @@ PrintHostSendDialog::PrintHostSendDialog(const fs::path &path) fs::path PrintHostSendDialog::filename() const { - return fs::path(txt_filename->GetValue().wx_str()); + return into_path(txt_filename->GetValue()); } bool PrintHostSendDialog::start_print() const |