diff --git a/src/libslic3r/Format/SLAArchiveFormatRegistry.cpp b/src/libslic3r/Format/SLAArchiveFormatRegistry.cpp index 17d3fa9a0..0a72cbcf3 100644 --- a/src/libslic3r/Format/SLAArchiveFormatRegistry.cpp +++ b/src/libslic3r/Format/SLAArchiveFormatRegistry.cpp @@ -11,20 +11,17 @@ namespace Slic3r { -static std::mutex arch_mtx; - class Registry { static std::unique_ptr registry; std::set entries; -public: Registry () { entries = { { "SL1", // id - L("SL1 archive format"), // description + L("SL1 archive"), // description "sl1", // main extension {"sl1s", "zip"}, // extension aliases @@ -38,22 +35,14 @@ public: }, { "SL1SVG", - L("SL1SVG archive files"), + L("SL1 SVG archive"), "sl1_svg", - {}, + {"zip"}, [] (const auto &cfg) { return std::make_unique(cfg); }, [] (const std::string &fname, SLAImportQuality quality, const ProgrFn &progr) { return std::make_unique(fname, quality, progr); } }, - { - "SL2", - "", - "sl1_svg", - {}, - [] (const auto &cfg) { return std::make_unique(cfg); }, - nullptr - }, anycubic_sla_format("pwmo", "Photon Mono"), anycubic_sla_format("pwmx", "Photon Mono X"), anycubic_sla_format("pwms", "Photon Mono SE"), @@ -85,28 +74,26 @@ public: }; } - static Registry& get_instance() +public: + + static const Registry& get_instance() { if (!registry) - registry = std::make_unique(); + registry.reset(new Registry()); return *registry; } - static std::set& get() + static const std::set& get() { return get_instance().entries; } - - std::set& get_entries() { return entries; } }; std::unique_ptr Registry::registry = nullptr; -std::set registered_sla_archives() +const std::set& registered_sla_archives() { - std::lock_guard lk{arch_mtx}; - return Registry::get(); } @@ -123,8 +110,6 @@ std::vector get_extensions(const ArchiveEntry &entry) ArchiveWriterFactory get_writer_factory(const char *formatid) { - std::lock_guard lk{arch_mtx}; - ArchiveWriterFactory ret; auto entry = Registry::get().find(ArchiveEntry{formatid}); if (entry != Registry::get().end()) @@ -135,7 +120,6 @@ ArchiveWriterFactory get_writer_factory(const char *formatid) ArchiveReaderFactory get_reader_factory(const char *formatid) { - std::lock_guard lk{arch_mtx}; ArchiveReaderFactory ret; auto entry = Registry::get().find(ArchiveEntry{formatid}); @@ -145,4 +129,28 @@ ArchiveReaderFactory get_reader_factory(const char *formatid) return ret; } +const char *get_default_extension(const char *formatid) +{ + static constexpr const char *Empty = ""; + + const char * ret = Empty; + + auto entry = Registry::get().find(ArchiveEntry{formatid}); + if (entry != Registry::get().end()) + ret = entry->ext; + + return ret; +} + +const ArchiveEntry * get_archive_entry(const char *formatid) +{ + const ArchiveEntry *ret = nullptr; + + auto entry = Registry::get().find(ArchiveEntry{formatid}); + if (entry != Registry::get().end()) + ret = &(*entry); + + return ret; +} + } // namespace Slic3r::sla diff --git a/src/libslic3r/Format/SLAArchiveFormatRegistry.hpp b/src/libslic3r/Format/SLAArchiveFormatRegistry.hpp index fb1a18ca5..896888bd5 100644 --- a/src/libslic3r/Format/SLAArchiveFormatRegistry.hpp +++ b/src/libslic3r/Format/SLAArchiveFormatRegistry.hpp @@ -48,9 +48,9 @@ struct ArchiveEntry { : id{formatid} , desc{description} , ext{extension} - , ext_aliases{extaliases} , wrfactoryfn{wrfn} , rdfactoryfn{rdfn} + , ext_aliases{extaliases} {} bool operator <(const ArchiveEntry &other) const @@ -61,8 +61,10 @@ struct ArchiveEntry { std::vector get_extensions(const ArchiveEntry &entry); -std::set registered_sla_archives(); +const std::set& registered_sla_archives(); +const ArchiveEntry * get_archive_entry(const char *formatid); +const char * get_default_extension(const char *formatid); ArchiveWriterFactory get_writer_factory(const char *formatid); ArchiveReaderFactory get_reader_factory(const char *formatid); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index ca8aa76d3..aa1601fd8 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -1983,7 +1983,7 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("You can use all configuration options as variables inside this template. " "For example: [layer_height], [fill_density] etc. You can also use [timestamp], " "[year], [month], [day], [hour], [minute], [second], [version], [input_filename], " - "[input_filename_base]."); + "[input_filename_base], [default_output_extension]."); def->full_width = true; def->mode = comExpert; def->set_default_value(new ConfigOptionString("[input_filename_base].gcode")); diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 1598cd46b..1fcbcd00d 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -4,6 +4,8 @@ #include "CSGMesh/PerformCSGMeshBooleans.hpp" #include "format.hpp" +#include "Format/SLAArchiveFormatRegistry.hpp" + #include "Geometry.hpp" #include "Thread.hpp" @@ -522,6 +524,10 @@ SLAPrint::ApplyStatus SLAPrint::apply(const Model &model, DynamicPrintConfig con #endif /* _DEBUG */ m_full_print_config = std::move(config); + + const char *default_ext = get_default_extension(m_printer_config.sla_archive_format.value.c_str()); + m_placeholder_parser.set("default_output_extension", default_ext); + return static_cast(apply_status); } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index ec7f43ae1..859c25f6f 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -54,6 +54,7 @@ #include "libslic3r/Model.hpp" #include "libslic3r/PresetBundle.hpp" #include "libslic3r/Color.hpp" +#include "libslic3r/Format/SLAArchiveFormatRegistry.hpp" #include "GUI.hpp" #include "GUI_Utils.hpp" @@ -490,15 +491,13 @@ static const FileWildcards file_wildcards_by_type[FT_SIZE] = { /* FT_TEX */ { "Texture"sv, { ".png"sv, ".svg"sv } }, - /* FT_SL1 */ { "Masked SLA files"sv, { ".sl1"sv, ".sl1s"sv, ".pwmx"sv } }, + /* FT_SL1 (deprecated, overriden by sla_wildcards) */ { "Masked SLA files"sv, { ".sl1"sv, ".sl1s"sv, ".pwmx"sv } }, /* FT_ZIP */ { "Zip files"sv, { ".zip"sv } }, }; -#if ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR -wxString file_wildcards(FileType file_type) +static wxString file_wildcards(const FileWildcards& data) { - const FileWildcards& data = file_wildcards_by_type[file_type]; std::string title; std::string mask; @@ -532,6 +531,14 @@ wxString file_wildcards(FileType file_type) return ret; } + +#if ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR +wxString file_wildcards(FileType file_type) +{ + const FileWildcards& data = file_wildcards_by_type[file_type]; + + return file_wildcards(data); +} #else // This function produces a Win32 file dialog file template mask to be consumed by wxWidgets on all platforms. // The function accepts a custom extension parameter. If the parameter is provided, the custom extension @@ -590,6 +597,34 @@ wxString file_wildcards(FileType file_type, const std::string &custom_extension) } #endif // ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR +wxString sla_wildcards(const char *formatid) +{ + const ArchiveEntry *entry = get_archive_entry(formatid); + wxString ret; + + if (entry) { + FileWildcards wc; + std::string tr_title = I18N::translate_utf8(entry->desc); + tr_title = GUI::format(_u8L("%s files"), tr_title); + wc.title = tr_title; + + std::vector exts = get_extensions(*entry); + + wc.file_extensions.reserve(exts.size()); + for (std::string &ext : exts) { + ext.insert(ext.begin(), '.'); + wc.file_extensions.emplace_back(ext); + } + + ret = file_wildcards(wc); + } + + if (ret.empty()) + ret = file_wildcards(FT_SL1); + + return ret; +} + static std::string libslic3r_translate_callback(const char *s) { return wxGetTranslation(wxString(s, wxConvUTF8)).utf8_str().data(); } #ifdef WIN32 diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 51900a9b6..6773806df 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -84,6 +84,8 @@ extern wxString file_wildcards(FileType file_type); extern wxString file_wildcards(FileType file_type, const std::string &custom_extension = std::string{}); #endif // ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR +wxString sla_wildcards(const char *formatid); + enum ConfigMenuIDs { ConfigMenuWizard, ConfigMenuSnapshots, diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 187e2737d..fa6eed5fb 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -6377,9 +6377,11 @@ void Plater::export_gcode(bool prefer_removable) start_dir, from_path(default_output_file.filename()), #if ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR - GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_SL1), + printer_technology() == ptFFF ? GUI::file_wildcards(FT_GCODE) : + GUI::sla_wildcards(p->sla_print.printer_config().sla_archive_format.value.c_str()), #else - GUI::file_wildcards((printer_technology() == ptFFF) ? FT_GCODE : FT_SL1, ext), + printer_technology() == ptFFF ? GUI::file_wildcards(FT_GCODE, ext) : + GUI::sla_wildcards(p->sla_print.printer_config().sla_archive_format.value.c_str()), #endif // ENABLE_ALTERNATIVE_FILE_WILDCARDS_GENERATOR wxFD_SAVE | wxFD_OVERWRITE_PROMPT );