From fbbfcf70d3140b62925722f380a0582bd508091f Mon Sep 17 00:00:00 2001 From: bubnikv Date: Thu, 6 Dec 2018 17:32:49 +0100 Subject: [PATCH] File wildcards now include an extension of a file provided as a default. This is useful for the G-code or SLA export, as one may chose his own file extension for the export file. --- src/slic3r/GUI/BedShapeDialog.cpp | 2 +- src/slic3r/GUI/GUI_App.cpp | 38 +++++++++++++++++++------------ src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 14 ++++++------ src/slic3r/GUI/Plater.cpp | 8 ++++--- 5 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/slic3r/GUI/BedShapeDialog.cpp b/src/slic3r/GUI/BedShapeDialog.cpp index 491a9f75d..dbc9e36d8 100644 --- a/src/slic3r/GUI/BedShapeDialog.cpp +++ b/src/slic3r/GUI/BedShapeDialog.cpp @@ -296,7 +296,7 @@ void BedShapePanel::update_shape() void BedShapePanel::load_stl() { auto dialog = new wxFileDialog(this, _(L("Choose a file to import bed shape from (STL/OBJ/AMF/3MF/PRUSA):")), "", "", - file_wildcards[FT_MODEL], wxFD_OPEN | wxFD_FILE_MUST_EXIST); + file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog->ShowModal() != wxID_OK) { dialog->Destroy(); return; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index c3fe273e9..1aba14406 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -39,20 +39,30 @@ namespace Slic3r { namespace GUI { -const wxString file_wildcards[FT_SIZE] = { - /* FT_STL */ "STL files (*.stl)|*.stl;*.STL", - /* FT_OBJ */ "OBJ files (*.obj)|*.obj;*.OBJ", - /* FT_AMF */ "AMF files (*.amf)|*.zip.amf;*.amf;*.AMF;*.xml;*.XML", - /* FT_3MF */ "3MF files (*.3mf)|*.3mf;*.3MF;", - /* FT_PRUSA */ "Prusa Control files (*.prusa)|*.prusa;*.PRUSA", - /* FT_GCODE */ "G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC", - /* FT_MODEL */ "Known files (*.stl, *.obj, *.amf, *.xml, *.3mf, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.3mf;*.3MF;*.prusa;*.PRUSA", +wxString file_wildcards(FileType file_type, const std::string &custom_extension) +{ + static const wxString defaults[FT_SIZE] = { + /* FT_STL */ "STL files (*.stl)|*.stl;*.STL", + /* FT_OBJ */ "OBJ files (*.obj)|*.obj;*.OBJ", + /* FT_AMF */ "AMF files (*.amf)|*.zip.amf;*.amf;*.AMF;*.xml;*.XML", + /* FT_3MF */ "3MF files (*.3mf)|*.3mf;*.3MF;", + /* FT_PRUSA */ "Prusa Control files (*.prusa)|*.prusa;*.PRUSA", + /* FT_GCODE */ "G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC", + /* FT_MODEL */ "Known files (*.stl, *.obj, *.amf, *.xml, *.3mf, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.3mf;*.3MF;*.prusa;*.PRUSA", - /* FT_INI */ "INI files *.ini|*.ini;*.INI", - /* FT_SVG */ "SVG files *.svg|*.svg;*.SVG", - /* FT_PNGZIP */"Zipped PNG files *.zip|*.zip;*.ZIP", // This is lame, but that's what we use for SLA -}; + /* FT_INI */ "INI files (*.ini)|*.ini;*.INI", + /* FT_SVG */ "SVG files (*.svg)|*.svg;*.SVG", + /* FT_PNGZIP */"Zipped PNG files (*.zip)|*.zip;*.ZIP", // This is lame, but that's what we use for SLA + }; + wxString out = defaults[file_type]; + if (! custom_extension.empty()) { + // Append the custom extension to the wildcards, so that the file dialog would not add the default extension to it. + out += ";*"; + out += from_u8(custom_extension); + } + return out; +} static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); } @@ -324,7 +334,7 @@ void GUI_App::load_project(wxWindow *parent, wxString& input_file) wxFileDialog dialog(parent ? parent : GetTopWindow(), _(L("Choose one file (3MF):")), app_config->get_last_dir(), "", - file_wildcards[FT_3MF], wxFD_OPEN | wxFD_FILE_MUST_EXIST); + file_wildcards(FT_3MF), wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() == wxID_OK) input_file = dialog.GetPath(); @@ -336,7 +346,7 @@ void GUI_App::import_model(wxWindow *parent, wxArrayString& input_files) wxFileDialog dialog(parent ? parent : GetTopWindow(), _(L("Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):")), app_config->get_last_dir(), "", - file_wildcards[FT_MODEL], wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST); + file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST); if (dialog.ShowModal() == wxID_OK) dialog.GetPaths(input_files); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 55447428d..9df90259a 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -48,7 +48,7 @@ enum FileType FT_SIZE, }; -extern const wxString file_wildcards[FT_SIZE]; +extern wxString file_wildcards(FileType file_type, const std::string &custom_extension = std::string()); enum ConfigMenuIDs { ConfigMenuWizard, diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 205ddbdf3..ea96466db 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -446,7 +446,7 @@ void MainFrame::quick_slice(const int qs) if (!(qs & qsReslice)) { auto dlg = new wxFileDialog(this, _(L("Choose a file to slice (STL/OBJ/AMF/3MF/PRUSA):")), wxGetApp().app_config->get_last_dir(), "", - file_wildcards[FT_MODEL], wxFD_OPEN | wxFD_FILE_MUST_EXIST); + file_wildcards(FT_MODEL), wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dlg->ShowModal() != wxID_OK) { dlg->Destroy(); return; @@ -505,7 +505,7 @@ void MainFrame::quick_slice(const int qs) // output_file = ~s / \.[gG][cC][oO][dD][eE]$ / .svg /; auto dlg = new wxFileDialog(this, _(L("Save ")) + (qs & qsExportSVG ? _(L("SVG")) : _(L("G-code"))) + _(L(" file as:")), wxGetApp().app_config->get_last_output_dir(get_dir_name(output_file)), get_base_name(input_file), - qs & qsExportSVG ? file_wildcards[FT_SVG] : file_wildcards[FT_GCODE], + qs & qsExportSVG ? file_wildcards(FT_SVG) : file_wildcards(FT_GCODE), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if (dlg->ShowModal() != wxID_OK) { dlg->Destroy(); @@ -574,7 +574,7 @@ void MainFrame::repair_stl() { auto dlg = new wxFileDialog(this, _(L("Select the STL file to repair:")), wxGetApp().app_config->get_last_dir(), "", - file_wildcards[FT_STL], wxFD_OPEN | wxFD_FILE_MUST_EXIST); + file_wildcards(FT_STL), wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dlg->ShowModal() != wxID_OK) { dlg->Destroy(); return; @@ -588,7 +588,7 @@ void MainFrame::repair_stl() // output_file = ~s / \.[sS][tT][lL]$ / _fixed.obj / ; auto dlg = new wxFileDialog( this, L("Save OBJ file (less prone to coordinate errors than STL) as:"), get_dir_name(output_file), get_base_name(output_file), - file_wildcards[FT_OBJ], wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + file_wildcards(FT_OBJ), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if (dlg->ShowModal() != wxID_OK) { dlg->Destroy(); return /*undef*/; @@ -618,7 +618,7 @@ void MainFrame::export_config() auto dlg = new wxFileDialog(this, _(L("Save configuration as:")), !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(), !m_last_config.IsEmpty() ? get_base_name(m_last_config) : "config.ini", - file_wildcards[FT_INI], wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + file_wildcards(FT_INI), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); wxString file; if (dlg->ShowModal() == wxID_OK) file = dlg->GetPath(); @@ -669,7 +669,7 @@ void MainFrame::export_configbundle() auto dlg = new wxFileDialog(this, _(L("Save presets bundle as:")), !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(), "Slic3r_config_bundle.ini", - file_wildcards[FT_INI], wxFD_SAVE | wxFD_OVERWRITE_PROMPT); + file_wildcards(FT_INI), wxFD_SAVE | wxFD_OVERWRITE_PROMPT); wxString file; if (dlg->ShowModal() == wxID_OK) file = dlg->GetPath(); @@ -695,7 +695,7 @@ void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool re if (file.IsEmpty()) { auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")), !m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(), - "config.ini", file_wildcards[FT_INI], wxFD_OPEN | wxFD_FILE_MUST_EXIST); + "config.ini", file_wildcards(FT_INI), wxFD_OPEN | wxFD_FILE_MUST_EXIST); if (dlg->ShowModal() != wxID_OK) return; file = dlg->GetPath(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b6480856c..6d2af3b8d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include #include @@ -1563,10 +1565,10 @@ std::unique_ptr Plater::priv::get_export_file(GUI::FileType case FT_AMF: case FT_3MF: case FT_GCODE: - wildcard = file_wildcards[file_type]; + wildcard = file_wildcards(file_type); break; default: - wildcard = file_wildcards[FT_MODEL]; + wildcard = file_wildcards(FT_MODEL); break; } @@ -2812,7 +2814,7 @@ 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(), - GUI::file_wildcards[(printer_technology() == ptFFF) ? FT_GCODE : FT_PNGZIP], + GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_PNGZIP, default_output_file.extension().string()), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );