mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-29 00:21:56 -05:00
fix: warn on preset save when plugin not found (#16929)
* fix: warn on preset save when plugin not found * refactor: build the unsaved-changes save config in one place * Fixes clang-tidy --------- Co-authored-by: Lam Wei Lun <weilun.lam@gmail.com>
This commit is contained in:
1 parent
3322f6101c
commit
3a0517831f
15 files changed
+411
-66
No files matched your search
+53
-35
@@ -1588,7 +1588,9 @@ void ConfigBase::save_to_json(std::ostream &os, const std::string &name, const s
|
||||
// Serialize the top-level "plugins" manifest: the individual plugin-backed options keep bare
|
||||
// capability names; the full "name;uuid;capability" references are derived here (same helper as
|
||||
// update_plugin_manifest). Only with a resolver (GUI); without one (CLI/headless) leave whatever
|
||||
// the "plugins" option already serialized above, so a round-trip never drops the manifest.
|
||||
// the "plugins" option already serialized above, so a round-trip never drops the manifest. A value
|
||||
// the resolver cannot map is omitted; unresolved_plugin_capabilities() reports it so a GUI save
|
||||
// entry point can prompt before writing.
|
||||
if (resolve_capability_fn) {
|
||||
std::vector<std::string> unique_refs = this->collect_plugin_manifest();
|
||||
if (unique_refs.empty())
|
||||
@@ -1623,40 +1625,32 @@ void ConfigBase::null_nullables()
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigBase::save_plugin_collection(const std::string& opt_key, const ConfigOption* opt, std::vector<std::string>& plugin_refs) const {
|
||||
// Full plugin capability references ("name;uuid;capability") can only be derived through the
|
||||
// resolver registered by the GUI once plugins are loaded. In non-GUI/headless contexts (e.g.
|
||||
// the CLI) it stays null, so skip silently rather than calling an empty std::function.
|
||||
if (!resolve_capability_fn)
|
||||
return;
|
||||
|
||||
void ConfigBase::for_each_plugin_capability(const std::function<void(const std::string& opt_key, const std::string& plugin_type, const std::string& capability_name)>& fn) const
|
||||
{
|
||||
// A plugin-backed option declares its capability type via ConfigOptionDef::plugin_type (the same
|
||||
// metadata PluginResolver::find_option_for_capability scans). Deriving off the def rather than a
|
||||
// per-key branch keeps this generic across every plugin-backed option.
|
||||
const ConfigDef* def = this->def();
|
||||
const ConfigOptionDef* opt_def = def ? def->get(opt_key) : nullptr;
|
||||
if (opt_def == nullptr || !opt_def->is_plugin_backed())
|
||||
const ConfigDef* def = this->def();
|
||||
if (def == nullptr)
|
||||
return;
|
||||
const std::string& type = opt_def->plugin_type;
|
||||
|
||||
// Resolve a single bare capability value into its full reference and append it, skipping unset
|
||||
// values, capabilities that could not be resolved (resolver returns ""), and duplicates already
|
||||
// collected (preserving insertion order).
|
||||
const auto append_ref = [&plugin_refs, &type](const std::string& capability_value) {
|
||||
if (capability_value.empty())
|
||||
return;
|
||||
std::string ref = resolve_capability_fn(capability_value, type);
|
||||
if (!ref.empty() && std::find(plugin_refs.begin(), plugin_refs.end(), ref) == plugin_refs.end())
|
||||
plugin_refs.emplace_back(std::move(ref));
|
||||
};
|
||||
for (const std::string& opt_key : this->keys()) {
|
||||
const ConfigOptionDef* opt_def = def->get(opt_key);
|
||||
const ConfigOption* opt = this->option(opt_key);
|
||||
if (opt_def == nullptr || opt == nullptr || !opt_def->is_plugin_backed())
|
||||
continue;
|
||||
|
||||
// Scalar options carry a single capability name; vector options carry a list. Same scalar/vector
|
||||
// dispatch as PluginResolver::find_option_for_capability.
|
||||
if (const auto* string_option = dynamic_cast<const ConfigOptionString*>(opt))
|
||||
append_ref(string_option->value);
|
||||
else if (const auto* vector_option = dynamic_cast<const ConfigOptionVectorBase*>(opt))
|
||||
for (const std::string& val : vector_option->vserialize())
|
||||
append_ref(val);
|
||||
// Scalar options carry a single capability name; vector options carry a list. Same
|
||||
// scalar/vector dispatch as PluginResolver::find_option_for_capability.
|
||||
if (const auto* scalar_option = dynamic_cast<const ConfigOptionString*>(opt)) {
|
||||
if (!scalar_option->value.empty())
|
||||
fn(opt_key, opt_def->plugin_type, scalar_option->value);
|
||||
} else if (const auto* vector_option = dynamic_cast<const ConfigOptionVectorBase*>(opt)) {
|
||||
for (const std::string& capability_name : vector_option->vserialize())
|
||||
if (!capability_name.empty())
|
||||
fn(opt_key, opt_def->plugin_type, capability_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ConfigBase::collect_plugin_manifest() const
|
||||
@@ -1665,15 +1659,39 @@ std::vector<std::string> ConfigBase::collect_plugin_manifest() const
|
||||
if (!resolve_capability_fn)
|
||||
return refs;
|
||||
|
||||
// Each plugin-backed option (ConfigOptionDef::is_plugin_backed) contributes its resolved
|
||||
// reference(s) via save_plugin_collection, which appends in order and skips duplicates, so no
|
||||
// second de-duplication pass is needed here.
|
||||
for (const std::string& opt_key : this->keys())
|
||||
if (const ConfigOption* opt = this->option(opt_key))
|
||||
this->save_plugin_collection(opt_key, opt, refs);
|
||||
// Resolve each capability value and append its full reference, dropping duplicates (preserving
|
||||
// insertion order). A value that resolves nowhere has no reference to write, so it is skipped;
|
||||
// unresolved_plugin_capabilities() reports those values so a GUI save can prompt.
|
||||
this->for_each_plugin_capability([&refs](const std::string& /* opt_key */, const std::string& plugin_type, const std::string& capability_name) {
|
||||
std::string ref = resolve_capability_fn(capability_name, plugin_type);
|
||||
if (!ref.empty() && std::find(refs.begin(), refs.end(), ref) == refs.end())
|
||||
refs.emplace_back(std::move(ref));
|
||||
});
|
||||
return refs;
|
||||
}
|
||||
|
||||
std::vector<UnresolvedPluginCapability> ConfigBase::unresolved_plugin_capabilities() const
|
||||
{
|
||||
std::vector<UnresolvedPluginCapability> unresolved;
|
||||
// Without a resolver (CLI/headless) serialization leaves the manifest loaded from disk untouched,
|
||||
// so no value is lost and there is nothing to warn about.
|
||||
if (!resolve_capability_fn)
|
||||
return unresolved;
|
||||
|
||||
// Same walk and same resolver call as collect_plugin_manifest: a value is reported here exactly
|
||||
// when the serializer would omit it.
|
||||
this->for_each_plugin_capability([&unresolved](const std::string& opt_key, const std::string& plugin_type, const std::string& capability_name) {
|
||||
if (!resolve_capability_fn(capability_name, plugin_type).empty())
|
||||
return;
|
||||
const auto matches = [&opt_key, &capability_name](const UnresolvedPluginCapability& entry) {
|
||||
return entry.opt_key == opt_key && entry.capability_name == capability_name;
|
||||
};
|
||||
if (std::none_of(unresolved.begin(), unresolved.end(), matches))
|
||||
unresolved.push_back(UnresolvedPluginCapability{ opt_key, capability_name });
|
||||
});
|
||||
return unresolved;
|
||||
}
|
||||
|
||||
void ConfigBase::update_plugin_manifest()
|
||||
{
|
||||
// Writes the derived manifest back into this config's "plugins" option (save_to_json writes the
|
||||
|
||||
@@ -2725,6 +2725,19 @@ public:
|
||||
|
||||
|
||||
|
||||
// A plugin-backed option value that the registered capability resolver cannot map to a plugin
|
||||
// reference, i.e. a capability whose plugin is not available here. save_to_json() and
|
||||
// update_plugin_manifest() cannot derive a reference for such a value and omit it, so a GUI save
|
||||
// entry point queries this first and lets the user decide before writing a preset that loses the
|
||||
// reference. See ConfigBase::unresolved_plugin_capabilities().
|
||||
struct UnresolvedPluginCapability
|
||||
{
|
||||
// Option holding the capability name, e.g. "printer_agent".
|
||||
t_config_option_key opt_key;
|
||||
// Bare capability name as stored in the option, e.g. "agent".
|
||||
std::string capability_name;
|
||||
};
|
||||
|
||||
// An abstract configuration store.
|
||||
class ConfigBase : public ConfigOptionResolver
|
||||
{
|
||||
@@ -2883,9 +2896,18 @@ public:
|
||||
// dispatchers consume) from the plugin-backed options via the registered resolver. save_to_json()
|
||||
// derives the same manifest, but only when a preset is written to disk; a config assembled in
|
||||
// memory for the backend (PresetBundle::full_config -> Print::apply) must refresh it here or a
|
||||
// picked-but-unsaved plugin never resolves at slice/export time. No-op without a resolver.
|
||||
// picked-but-unsaved plugin never resolves at slice/export time. A capability the resolver cannot
|
||||
// map is omitted from the derived manifest; unresolved_plugin_capabilities() reports those
|
||||
// values. No-op without a resolver.
|
||||
void update_plugin_manifest();
|
||||
|
||||
// The plugin-backed option values the registered resolver cannot map to a plugin reference --
|
||||
// exactly the values save_to_json()/update_plugin_manifest() omit from the manifest. GUI save
|
||||
// entry points call this before writing a preset so the user can be warned that the reference
|
||||
// will be lost. Returns empty without a resolver (CLI/headless), where the manifest is left as
|
||||
// loaded and nothing is lost.
|
||||
std::vector<UnresolvedPluginCapability> unresolved_plugin_capabilities() const;
|
||||
|
||||
// Set all the nullable values to nils.
|
||||
void null_nullables();
|
||||
|
||||
@@ -2894,12 +2916,17 @@ public:
|
||||
private:
|
||||
// Set a configuration value from a string.
|
||||
bool set_deserialize_raw(const t_config_option_key& opt_key_src, const std::string& value, ConfigSubstitutionContext& substitutions, bool append);
|
||||
void save_plugin_collection(const std::string& opt_key, const ConfigOption* opt, std::vector<std::string>& plugin_refs) const;
|
||||
// Collect the de-duplicated "name;uuid;capability" plugin references derived from this config's
|
||||
// plugin-backed options via the resolver. Shared by save_to_json (serializes them into the JSON
|
||||
// manifest) and update_plugin_manifest (writes them back into the "plugins" option). Order is
|
||||
// preserved and empties are dropped; returns empty without a resolver (CLI/headless).
|
||||
// preserved and values that do not resolve are dropped; returns empty without a resolver
|
||||
// (CLI/headless).
|
||||
std::vector<std::string> collect_plugin_manifest() const;
|
||||
// Calls fn(opt_key, plugin_type, capability_name) for every non-empty capability name held by a
|
||||
// plugin-backed option of this config, in key order. A single walk feeds both the serializer
|
||||
// (collect_plugin_manifest) and unresolved_plugin_capabilities, so they cannot disagree on which
|
||||
// values resolve.
|
||||
void for_each_plugin_capability(const std::function<void(const std::string& opt_key, const std::string& plugin_type, const std::string& capability_name)>& fn) const;
|
||||
|
||||
static std::function<std::string(std::string, std::string)> resolve_capability_fn;
|
||||
};
|
||||
|
||||
@@ -2,12 +2,17 @@
|
||||
#include "GUI_Utils.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
#include "format.hpp"
|
||||
#include "libslic3r/Config.hpp"
|
||||
#include "slic3r/Utils/NetworkAgentFactory.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <wx/event.h>
|
||||
@@ -47,8 +52,6 @@
|
||||
#include <wx/display.h>
|
||||
#include <wx/utils.h>
|
||||
|
||||
#include "libslic3r/Config.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
@@ -230,6 +233,122 @@ void open_ms_store_product_page()
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// True when this unresolved value is worth warning about. printer_agent also stores ids of
|
||||
// built-in agents (Orca, Bambu Lab, Qidi, ...): those are not plugin capabilities, so the resolver
|
||||
// cannot map them and they need no manifest reference. Only a plugin-provided agent that is
|
||||
// unavailable is reportable.
|
||||
bool is_reportable_unresolved_plugin(const UnresolvedPluginCapability& item)
|
||||
{
|
||||
if (item.opt_key != "printer_agent")
|
||||
return true;
|
||||
const PrinterAgentInfo* agent = NetworkAgentFactory::get_printer_agent_info(item.capability_name);
|
||||
return agent == nullptr || agent->is_plugin();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool has_unresolved_plugin_capabilities(const ConfigBase& config)
|
||||
{
|
||||
for (const UnresolvedPluginCapability& item : config.unresolved_plugin_capabilities())
|
||||
if (is_reportable_unresolved_plugin(item))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// Appends one row per unresolved plugin-backed value. `preset_name` is empty for a single-preset
|
||||
// or project warning and set when several presets are reported together. Returns true if any row
|
||||
// was appended, so a batch whose entries are all built-in printer agents stays silent.
|
||||
bool append_unresolved_plugin_rows(const ConfigBase& config, const wxString& preset_name, wxString& rows)
|
||||
{
|
||||
const std::vector<UnresolvedPluginCapability> unresolved = config.unresolved_plugin_capabilities();
|
||||
if (unresolved.empty())
|
||||
return false;
|
||||
|
||||
const ConfigDef* def = config.def();
|
||||
bool appended = false;
|
||||
for (const UnresolvedPluginCapability& item : unresolved) {
|
||||
if (!is_reportable_unresolved_plugin(item))
|
||||
continue;
|
||||
|
||||
const ConfigOptionDef* opt_def = def != nullptr ? def->get(item.opt_key) : nullptr;
|
||||
wxString label = opt_def != nullptr && !opt_def->label.empty() ? _L(opt_def->label) : from_u8(item.opt_key);
|
||||
wxString value = from_u8(item.capability_name);
|
||||
// The message is rendered as a Label, where '&' introduces a mnemonic. Escape both the
|
||||
// translated label and the stored value.
|
||||
label.Replace("&", "&&");
|
||||
value.Replace("&", "&&");
|
||||
if (!rows.IsEmpty())
|
||||
rows += "\n";
|
||||
if (preset_name.IsEmpty()) {
|
||||
// TRN %1% is a setting's label and %2% the plugin capability name stored in that setting.
|
||||
rows += format_wxstr(_L("• %1%: %2%"), label, value);
|
||||
} else {
|
||||
wxString escaped_name = preset_name;
|
||||
escaped_name.Replace("&", "&&");
|
||||
// TRN %1% is a preset name, %2% a setting's label and %3% the plugin capability name.
|
||||
rows += format_wxstr(_L("• %1% — %2%: %3%"), escaped_name, label, value);
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(warning) << "Unresolved plugin capability on save: " << item.opt_key
|
||||
<< " = " << item.capability_name;
|
||||
appended = true;
|
||||
}
|
||||
return appended;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool confirm_save_with_unresolved_plugins(wxWindow* parent, const ConfigBase& config, SaveSubject subject)
|
||||
{
|
||||
wxString rows;
|
||||
if (!append_unresolved_plugin_rows(config, wxString(), rows))
|
||||
return true;
|
||||
|
||||
// TRN %1% is the list of affected settings built above, one "label: value" per line.
|
||||
const wxString message =
|
||||
subject == SaveSubject::Preset
|
||||
? format_wxstr(_L("The following settings refer to plugins Orca Slicer can't identify on this computer:\n\n%1%\n\n"
|
||||
"If you save anyway, the preset won't keep the plugin references for these settings. On another computer, "
|
||||
"Orca Slicer won't know which plugins to offer, and the settings may not work there."),
|
||||
rows)
|
||||
: format_wxstr(_L("The following settings refer to plugins Orca Slicer can't identify on this computer:\n\n%1%\n\n"
|
||||
"If you save anyway, the project won't keep the plugin references for these settings. On another computer, "
|
||||
"Orca Slicer won't know which plugins to offer, and the settings may not work there."),
|
||||
rows);
|
||||
|
||||
MessageDialog dlg(parent, message, _L("Plugin Not Identified"), wxOK | wxCANCEL | wxICON_WARNING);
|
||||
dlg.SetButtonLabel(wxID_OK, _L("Save anyway"));
|
||||
dlg.SetButtonLabel(wxID_CANCEL, _L("Cancel"), true); // the safe choice gets the focus
|
||||
return dlg.ShowModal() == wxID_OK;
|
||||
}
|
||||
|
||||
bool confirm_save_presets_with_unresolved_plugins(wxWindow* parent, const std::vector<SaveConfigToCheck>& configs)
|
||||
{
|
||||
wxString rows;
|
||||
bool any = false;
|
||||
for (const SaveConfigToCheck& entry : configs)
|
||||
if (entry.config != nullptr && append_unresolved_plugin_rows(*entry.config, entry.name, rows))
|
||||
any = true;
|
||||
if (!any)
|
||||
return true;
|
||||
|
||||
// TRN %1% is the list of affected presets and settings built above, one "preset — setting: value" per line.
|
||||
const wxString message = format_wxstr(
|
||||
_L("The presets being saved refer to plugins Orca Slicer can't identify on this computer:\n\n%1%\n\n"
|
||||
"If you save anyway, the presets won't keep the plugin references for these settings. On another computer, "
|
||||
"Orca Slicer won't know which plugins to offer, and the settings may not work there."),
|
||||
rows);
|
||||
|
||||
MessageDialog dlg(parent, message, _L("Plugin Not Identified"), wxOK | wxCANCEL | wxICON_WARNING);
|
||||
dlg.SetButtonLabel(wxID_OK, _L("Save anyway"));
|
||||
dlg.SetButtonLabel(wxID_CANCEL, _L("Cancel"), true); // the safe choice gets the focus
|
||||
return dlg.ShowModal() == wxID_OK;
|
||||
}
|
||||
|
||||
// If called with nullptr, a DPI for the primary monitor is returned.
|
||||
int get_dpi_for_window(const wxWindow *window)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
@@ -51,6 +52,7 @@ class wxRect;
|
||||
#define ICON_SINGLE_SIZE FromDIP(16)//don't change,if need new value,self create in cpp
|
||||
#define ICON_SIZE wxSize(FromDIP(16), FromDIP(16))//don't change,if need new value,self create in cpp
|
||||
namespace Slic3r {
|
||||
class ConfigBase;
|
||||
namespace GUI {
|
||||
|
||||
inline int hex_to_int(const char c)
|
||||
@@ -88,6 +90,35 @@ bool is_running_in_msix();
|
||||
// Opens the Microsoft Store product page for the current package. No-op when not packaged.
|
||||
void open_ms_store_product_page();
|
||||
|
||||
// What a save entry point is about to write, for the unresolved-plugin warning below.
|
||||
enum class SaveSubject { Preset, Project };
|
||||
|
||||
// Shows a warning when `config` holds plugin-backed values that the capability resolver cannot map:
|
||||
// the save will omit their "name;uuid;capability" references, so another computer cannot be told
|
||||
// which plugin to install. Returns false only when the user chose Cancel; the caller must then not
|
||||
// write. Returns true when nothing is unresolved or the user chose "Save anyway". Cancel is the
|
||||
// focused button and the result of ESC and the close box.
|
||||
bool confirm_save_with_unresolved_plugins(wxWindow* parent, const ConfigBase& config, SaveSubject subject);
|
||||
|
||||
// True when `config` holds at least one value worth warning about (same built-in printer-agent
|
||||
// filtering as the warning), without showing a dialog. Used to decide whether a remembered
|
||||
// "Save" choice must fall back to the dialog instead of skipping the warning.
|
||||
bool has_unresolved_plugin_capabilities(const ConfigBase& config);
|
||||
|
||||
// One preset's exact partial save config (edited config with unselected options reverted) to check
|
||||
// before a batch save. `name` is shown in the warning so the user knows which preset is affected.
|
||||
struct SaveConfigToCheck
|
||||
{
|
||||
wxString name;
|
||||
const ConfigBase* config;
|
||||
|
||||
SaveConfigToCheck(const wxString& name_, const ConfigBase* config_) : name(name_), config(config_) {}
|
||||
};
|
||||
|
||||
// Batch variant used when one Save action writes several presets: shows a single warning listing
|
||||
// every affected preset. Returns false only when the user chose Cancel.
|
||||
bool confirm_save_presets_with_unresolved_plugins(wxWindow* parent, const std::vector<SaveConfigToCheck>& configs);
|
||||
|
||||
void on_window_geometry(wxTopLevelWindow *tlw, std::function<void()> callback);
|
||||
|
||||
enum { DPI_DEFAULT = 96 };
|
||||
|
||||
@@ -784,7 +784,7 @@ std::string OptionsGroup::pick_plugin(const ConfigOptionDef& opt)
|
||||
return {};
|
||||
|
||||
// Only the bare capability name is stored; the full "name;uuid;capability" reference is derived when
|
||||
// the preset is serialized (see ConfigBase::save_plugin_collection). Resolve here to reject bad picks.
|
||||
// the preset is serialized (see ConfigBase::collect_plugin_manifest). Resolve here to reject bad picks.
|
||||
Slic3r::PluginDescriptor descriptor;
|
||||
if (!manager.try_get_plugin_descriptor(selection.plugin_key, descriptor) || descriptor.name.empty())
|
||||
return {};
|
||||
|
||||
@@ -835,7 +835,10 @@ void PhysicalPrinterDialog::check_host_key_valid()
|
||||
|
||||
void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
||||
{
|
||||
wxGetApp().get_tab(Preset::TYPE_PRINTER)->save_preset("", false, false, true, m_preset_name);
|
||||
// Keep this dialog open when the save was cancelled (e.g. the unresolved-plugin warning), or it
|
||||
// would close as if the physical printer's preset had been saved.
|
||||
if (!wxGetApp().get_tab(Preset::TYPE_PRINTER)->save_preset("", false, false, true, m_preset_name))
|
||||
return;
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
|
||||
@@ -16327,6 +16327,13 @@ int Plater::save_project(bool saveAs)
|
||||
if (filename == "<cancel>")
|
||||
return wxID_CANCEL;
|
||||
|
||||
// The project file records "name;uuid;capability" references for its plugin-backed settings. A
|
||||
// value the resolver cannot map loses its reference when written. Ask before writing; Cancel
|
||||
// leaves the project file, its dirty state and its lifecycle events untouched.
|
||||
const DynamicPrintConfig full_config = wxGetApp().preset_bundle->full_config_secure();
|
||||
if (!confirm_save_with_unresolved_plugins(this, full_config, SaveSubject::Project))
|
||||
return wxID_CANCEL;
|
||||
|
||||
//BBS export 3mf without gcode
|
||||
auto save_strategy = SaveStrategy::SplitModel | SaveStrategy::ShareMesh;
|
||||
bool full_pathnames = wxGetApp().app_config->get_bool("export_sources_full_pathnames");
|
||||
@@ -19236,12 +19243,10 @@ int GUI::Plater::close_with_confirm(std::function<bool(bool)> second_check)
|
||||
wxGetApp().app_config->set("save_project_choise", result == wxID_YES ? "yes" : "no");
|
||||
if (result == wxID_YES) {
|
||||
result = save_project();
|
||||
if (result == wxID_CANCEL) {
|
||||
if (choise.empty())
|
||||
return result;
|
||||
else
|
||||
result = wxID_NO;
|
||||
}
|
||||
// A Cancel from the save (including the unresolved-plugin warning) must abort the close
|
||||
// even when "Remember my choice" previously selected Save.
|
||||
if (result == wxID_CANCEL)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -557,7 +557,16 @@ wxBoxSizer *PreferencesDialog::create_item_language_combobox(wxString title, wxS
|
||||
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE).ShowModal();
|
||||
|
||||
if (result == wxID_YES) {
|
||||
wxGetApp().plater()->save_project();
|
||||
if (wxGetApp().plater()->save_project() != wxID_YES) {
|
||||
// The save was cancelled (e.g. the unresolved-plugin warning): do not
|
||||
// switch languages as if the project had been saved.
|
||||
combobox->SetSelection(m_current_language_selected);
|
||||
return;
|
||||
}
|
||||
} else if (result != wxID_NO) {
|
||||
// Cancel or ESC on the save prompt: keep the current language.
|
||||
combobox->SetSelection(m_current_language_selected);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-5
@@ -7828,9 +7828,16 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection *presets /*= nullptr
|
||||
if (m_type == presets->type()) // save changes for the current preset from this tab
|
||||
{
|
||||
// revert unselected options to the old values
|
||||
DynamicPrintConfig config_before_revert = presets->get_edited_preset().config;
|
||||
presets->get_edited_preset().config.apply_only(presets->get_selected_preset().config, unselected_options);
|
||||
//BBS: add project embedded preset relate logic
|
||||
save_preset(name, false, save_to_project);
|
||||
// A cancelled save (no name, unresolved-plugin warning, temperature check) must leave the
|
||||
// edited preset and the pending switch untouched. UnsavedChangesDialog::save already ran
|
||||
// the plugin warning for the selected presets, so do not ask again.
|
||||
if (!save_preset(name, false, save_to_project, false, "", true)) {
|
||||
presets->get_edited_preset().config = std::move(config_before_revert);
|
||||
return false;
|
||||
}
|
||||
//save_preset(name);
|
||||
}
|
||||
else
|
||||
@@ -8213,11 +8220,19 @@ void Tab::transfer_options(const std::string &name_from, const std::string &name
|
||||
// Wizard calls save_preset with a name "My Settings", otherwise no name is provided and this method
|
||||
// opens a Slic3r::GUI::SavePresetDialog dialog.
|
||||
//BBS: add project embedded preset relate logic
|
||||
void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_project, bool from_input, std::string input_name )
|
||||
bool Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_project, bool from_input, std::string input_name, bool plugin_warning_confirmed )
|
||||
{
|
||||
// ORCA: Validate before opening any save-name UI for filament presets.
|
||||
if (!validate_filament_temperature_pairs())
|
||||
return;
|
||||
return false;
|
||||
|
||||
// A plugin-backed setting whose plugin is unavailable here loses its "name;uuid;capability"
|
||||
// reference when the preset is written. Ask before any save-name UI: accepting that dialog can
|
||||
// already delete an overwritten preset, so a Cancel here must happen before it. A caller that
|
||||
// came through UnsavedChangesDialog (which already warned for the selected presets) skips it.
|
||||
if (!plugin_warning_confirmed &&
|
||||
!confirm_save_with_unresolved_plugins(parent(), m_presets->get_edited_preset().config, SaveSubject::Preset))
|
||||
return false;
|
||||
|
||||
// since buttons(and choices too) don't get focus on Mac, we set focus manually
|
||||
// to the treectrl so that the EVT_* events are fired for the input field having
|
||||
@@ -8238,7 +8253,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
|
||||
SavePresetDialog dlg(m_parent, m_type, m_mode, detach ? _u8L("Detached") : "");
|
||||
if (!m_just_edit) {
|
||||
if (dlg.ShowModal() != wxID_OK)
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
name = dlg.get_name();
|
||||
//BBS: add project embedded preset relate logic
|
||||
@@ -8267,6 +8282,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
|
||||
if (nullptr != _curr_printer && compatible_printers && compatible_printers->values.empty())
|
||||
compatible_printers->values.push_back(_curr_printer->name);
|
||||
}
|
||||
|
||||
// Save the preset into Slic3r::data_dir / presets / section_name / preset_name.json
|
||||
m_presets->save_current_preset(name, detach, save_to_project, nullptr);
|
||||
|
||||
@@ -8275,7 +8291,7 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
|
||||
//Preset* preset = &m_presets.preset(it - m_presets.begin(), true);
|
||||
if (!new_preset) {
|
||||
BOOST_LOG_TRIVIAL(info) << "create new preset failed";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// set sync_info for sync service
|
||||
@@ -8352,6 +8368,8 @@ void Tab::save_preset(std::string name /*= ""*/, bool detach, bool save_to_proje
|
||||
DiffPresetDialog* diff_dialog = DiffPresetDialog::if_built();
|
||||
if (diff_dialog != nullptr && diff_dialog->IsShown())
|
||||
diff_dialog->update_presets(m_type);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Called for a currently selected preset.
|
||||
|
||||
@@ -379,7 +379,11 @@ public:
|
||||
void compare_preset();
|
||||
void transfer_options(const std::string&name_from, const std::string&name_to, std::vector<std::string> options);
|
||||
//BBS: add project embedded preset relate logic
|
||||
void save_preset(std::string name = std::string(), bool detach = false, bool save_to_project = false, bool from_input = false, std::string input_name = "");
|
||||
// Returns false when the save was cancelled (the unresolved-plugin warning, the temperature
|
||||
// safety check or the save-name dialog), so callers that were about to discard the edited
|
||||
// preset can abort instead. `plugin_warning_confirmed` is set only by a caller that already ran
|
||||
// the warning (UnsavedChangesDialog::save) and must not repeat it.
|
||||
bool save_preset(std::string name = std::string(), bool detach = false, bool save_to_project = false, bool from_input = false, std::string input_name = "", bool plugin_warning_confirmed = false);
|
||||
//void save_preset(std::string name = std::string(), bool detach = false);
|
||||
|
||||
void delete_preset();
|
||||
|
||||
@@ -1019,9 +1019,10 @@ void TroubleshootDialog::PackAll()
|
||||
_L("Select NO to close dialog and review project."),
|
||||
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE
|
||||
).ShowModal();
|
||||
if (res == wxID_YES)
|
||||
wxGetApp().plater()->save_project();
|
||||
else {
|
||||
if (res == wxID_YES) {
|
||||
if (wxGetApp().plater()->save_project() != wxID_YES)
|
||||
return; // do not package as if the project had been saved
|
||||
} else {
|
||||
if (res == wxID_NO)
|
||||
EndModal(wxID_CLOSE);
|
||||
return;
|
||||
@@ -1048,9 +1049,10 @@ void TroubleshootDialog::RebuildSystemProfiles()
|
||||
_L("Select NO to close dialog and review project."),
|
||||
wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Save"), wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE
|
||||
).ShowModal();
|
||||
if (res == wxID_YES)
|
||||
wxGetApp().plater()->save_project();
|
||||
else {
|
||||
if (res == wxID_YES) {
|
||||
if (wxGetApp().plater()->save_project() != wxID_YES)
|
||||
return; // do not rebuild profiles as if the project had been saved
|
||||
} else {
|
||||
if (res == wxID_NO)
|
||||
EndModal(wxID_CLOSE);
|
||||
return;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <set>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
@@ -78,6 +79,8 @@ namespace GUI {
|
||||
|
||||
wxDEFINE_EVENT(EVT_DIFF_DIALOG_TRANSFER, SimpleEvent);
|
||||
|
||||
static PresetCollection* get_preset_collection(Preset::Type type, PresetBundle* preset_bundle = nullptr);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ModelNode: a node inside DiffModel
|
||||
@@ -848,7 +851,8 @@ UnsavedChangesDialog::UnsavedChangesDialog(const wxString &caption, const wxStri
|
||||
}
|
||||
|
||||
UnsavedChangesDialog::UnsavedChangesDialog(Preset::Type type, PresetCollection *dependent_presets, const std::string &new_selected_preset, bool no_transfer)
|
||||
: m_new_selected_preset_name(new_selected_preset)
|
||||
: m_dependent_presets(dependent_presets)
|
||||
, m_new_selected_preset_name(new_selected_preset)
|
||||
, DPIDialog(static_cast<wxWindow *>(wxGetApp().mainframe),
|
||||
wxID_ANY,
|
||||
_L("Transfer or discard changes"),
|
||||
@@ -870,8 +874,13 @@ inline int UnsavedChangesDialog::ShowModal()
|
||||
auto choise = wxGetApp().app_config->get(choise_key);
|
||||
long result = 0;
|
||||
if ((m_buttons & REMEMBER_CHOISE) && !choise.empty() && wxString(choise).ToLong(&result) && (1 << result) & (m_buttons | DONT_SAVE)) {
|
||||
m_exit_action = Action(result);
|
||||
return 0;
|
||||
const Action remembered = Action(result);
|
||||
// A remembered Save would otherwise skip the unresolved-plugin warning in save(). Show the
|
||||
// dialog when the presets being saved need it; remembered Transfer/Discard keep the shortcut.
|
||||
if (remembered != Action::Save || !selected_save_needs_plugin_warning()) {
|
||||
m_exit_action = remembered;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
int r = DPIDialog::ShowModal();
|
||||
if (r != wxID_CANCEL && dynamic_cast<::CheckBox*>(FindWindowById(wxID_APPLY))->GetValue()) {
|
||||
@@ -1176,6 +1185,30 @@ void UnsavedChangesDialog::close(Action action)
|
||||
this->EndModal(wxID_CLOSE);
|
||||
}
|
||||
|
||||
DynamicPrintConfig UnsavedChangesDialog::make_save_config(PresetCollection& presets)
|
||||
{
|
||||
DynamicPrintConfig config = presets.get_edited_preset().config;
|
||||
const std::vector<std::string> unselected_options = get_unselected_options(presets.type());
|
||||
if (!unselected_options.empty())
|
||||
config.apply_only(presets.get_selected_preset().config, unselected_options);
|
||||
return config;
|
||||
}
|
||||
|
||||
bool UnsavedChangesDialog::selected_save_needs_plugin_warning()
|
||||
{
|
||||
if (m_dependent_presets != nullptr)
|
||||
return has_unresolved_plugin_capabilities(make_save_config(*m_dependent_presets));
|
||||
|
||||
const PrinterTechnology printer_technology = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();
|
||||
for (Tab* tab : wxGetApp().tabs_list)
|
||||
if (tab->supports_printer_technology(printer_technology) && tab->current_preset_is_dirty()) {
|
||||
PresetCollection* presets = tab->get_presets();
|
||||
if (presets != nullptr && has_unresolved_plugin_capabilities(make_save_config(*presets)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UnsavedChangesDialog::save(PresetCollection* dependent_presets, bool show_save_preset_dialog/* = true*/)
|
||||
{
|
||||
names_and_types.clear();
|
||||
@@ -1188,6 +1221,14 @@ bool UnsavedChangesDialog::save(PresetCollection* dependent_presets, bool show_s
|
||||
// for system/default/external presets we should take an edited name
|
||||
//BBS: add project embedded preset logic and refine is_external
|
||||
bool save_to_project = false;
|
||||
|
||||
// Warn before the save-name dialog: accepting that dialog can delete an overwritten preset,
|
||||
// so a Cancel must be decided before it. Transfer reaches save() with
|
||||
// show_save_preset_dialog == false and must not warn.
|
||||
if (show_save_preset_dialog &&
|
||||
!confirm_save_with_unresolved_plugins(this, make_save_config(*dependent_presets), SaveSubject::Preset))
|
||||
return false;
|
||||
|
||||
if (!preset.can_overwrite()) {
|
||||
//if (preset.is_system || preset.is_default || preset.is_external) {
|
||||
SavePresetDialog save_dlg(this, preset.type);
|
||||
@@ -1226,6 +1267,30 @@ bool UnsavedChangesDialog::save(PresetCollection* dependent_presets, bool show_s
|
||||
}
|
||||
|
||||
|
||||
// One Save can write several presets. Build each exact partial config the same way
|
||||
// PresetBundle::save_changes_for_preset will, and warn once before any SavePresetDialog can
|
||||
// delete an overwritten preset. Transfer/Discard must not warn.
|
||||
if (show_save_preset_dialog && !names_and_types.empty()) {
|
||||
std::vector<std::unique_ptr<DynamicPrintConfig>> configs;
|
||||
std::vector<SaveConfigToCheck> checks;
|
||||
checks.reserve(names_and_types.size());
|
||||
for (const PresetData& nt : names_and_types) {
|
||||
PresetCollection* presets = get_preset_collection(nt.type, wxGetApp().preset_bundle);
|
||||
if (!presets)
|
||||
continue;
|
||||
auto config = std::make_unique<DynamicPrintConfig>(make_save_config(*presets));
|
||||
checks.push_back({from_u8(nt.name), config.get()});
|
||||
configs.emplace_back(std::move(config));
|
||||
}
|
||||
if (!checks.empty()) {
|
||||
const bool confirmed = checks.size() == 1
|
||||
? confirm_save_with_unresolved_plugins(this, *checks.front().config, SaveSubject::Preset)
|
||||
: confirm_save_presets_with_unresolved_plugins(this, checks);
|
||||
if (!confirmed)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (show_save_preset_dialog && !types_for_save.empty()) {
|
||||
SavePresetDialog save_dlg(this, types_for_save);
|
||||
if (save_dlg.ShowModal() != wxID_OK) {
|
||||
@@ -1774,7 +1839,7 @@ FullCompareDialog::FullCompareDialog(const wxString& option_name, const wxString
|
||||
}
|
||||
|
||||
|
||||
static PresetCollection* get_preset_collection(Preset::Type type, PresetBundle* preset_bundle = nullptr) {
|
||||
static PresetCollection* get_preset_collection(Preset::Type type, PresetBundle* preset_bundle) {
|
||||
if (!preset_bundle)
|
||||
preset_bundle = wxGetApp().preset_bundle;
|
||||
return type == Preset::Type::TYPE_PRINTER ? &preset_bundle->printers :
|
||||
|
||||
@@ -338,9 +338,18 @@ private:
|
||||
//std::vector<std::pair<std::string, Preset::Type>> names_and_types;
|
||||
// additional action buttons used in dialog
|
||||
int m_buttons { ActionButtons::TRANSFER | ActionButtons::SAVE };
|
||||
// Set only by the preset-switch constructor; used to re-check a remembered Save choice.
|
||||
PresetCollection* m_dependent_presets { nullptr };
|
||||
|
||||
std::string m_new_selected_preset_name;
|
||||
|
||||
// The config PresetBundle::save_changes_for_preset writes for this collection's edited preset:
|
||||
// the edited values with the unselected options reverted to the selected preset's values.
|
||||
DynamicPrintConfig make_save_config(PresetCollection& presets);
|
||||
// True when the presets this Save action would write contain a reportable unresolved plugin
|
||||
// value. Checks the same configs as save(), without showing a dialog.
|
||||
bool selected_save_needs_plugin_warning();
|
||||
|
||||
public:
|
||||
|
||||
struct SyncExtruderParams
|
||||
|
||||
@@ -372,7 +372,7 @@ bool prune_stale_plugin_overrides(DynamicConfig& config, const std::string& over
|
||||
|
||||
// Capability names currently referenced by a plugin-backed option's value(s) — e.g.
|
||||
// slicing_pipeline_plugin's ConfigOptionStrings entries name SlicingPipeline capabilities
|
||||
// directly, the same raw values save_plugin_collection() resolves into the "plugins" manifest.
|
||||
// directly, the same raw values ConfigBase::collect_plugin_manifest() resolves into the manifest.
|
||||
std::set<std::pair<PluginCapabilityType, std::string>> referenced;
|
||||
const ConfigDef* def = config.def();
|
||||
for (const std::string& opt_key : config.keys()) {
|
||||
|
||||
@@ -881,6 +881,41 @@ TEST_CASE_METHOD(PluginResolverFixture,
|
||||
CHECK(manifest == std::vector<std::string>{"x;;slicing-pipeline"});
|
||||
}
|
||||
|
||||
TEST_CASE("unresolved_plugin_capabilities reports exactly the values the manifest drops", "[Config][plugins]") {
|
||||
// GUI save entry points use this query to warn before a preset loses a plugin reference, so it
|
||||
// must match the serializer's notion of "unresolved" -- same options, same resolver calls.
|
||||
ConfigBase::set_resolve_capability_fn([](const std::string& name, const std::string& type) {
|
||||
return name == "offline" ? std::string() : name + ";;" + type;
|
||||
});
|
||||
std::unique_ptr<DynamicPrintConfig> config(DynamicPrintConfig::new_from_defaults_keys(
|
||||
{"slicing_pipeline_plugin", "printer_agent", "plugins"}));
|
||||
config->option<ConfigOptionStrings>("slicing_pipeline_plugin", true)->values = {"offline", "here"};
|
||||
config->option<ConfigOptionString>("printer_agent", true)->value = "agent";
|
||||
|
||||
const std::vector<UnresolvedPluginCapability> unresolved = config->unresolved_plugin_capabilities();
|
||||
config->update_plugin_manifest();
|
||||
const std::vector<std::string> manifest = config->option<ConfigOptionStrings>("plugins")->values;
|
||||
ConfigBase::set_resolve_capability_fn(nullptr);
|
||||
|
||||
// Only the value no plugin can provide is reported; the resolved ones are not.
|
||||
REQUIRE(unresolved.size() == 1);
|
||||
CHECK(unresolved.front().opt_key == "slicing_pipeline_plugin");
|
||||
CHECK(unresolved.front().capability_name == "offline");
|
||||
// ... and the manifest holds the complementary set of references (keys() is in sorted order,
|
||||
// so printer_agent comes first).
|
||||
CHECK(manifest == std::vector<std::string>{"agent;;printer-connection", "here;;slicing-pipeline"});
|
||||
}
|
||||
|
||||
TEST_CASE("unresolved_plugin_capabilities is empty without a resolver", "[Config][plugins]") {
|
||||
// CLI/headless leaves the loaded manifest untouched when it serializes, so nothing is lost and
|
||||
// there is nothing to prompt about.
|
||||
ConfigBase::set_resolve_capability_fn(nullptr);
|
||||
std::unique_ptr<DynamicPrintConfig> config(DynamicPrintConfig::new_from_defaults_keys(
|
||||
{"slicing_pipeline_plugin", "plugins"}));
|
||||
config->option<ConfigOptionStrings>("slicing_pipeline_plugin", true)->values = {"offline"};
|
||||
CHECK(config->unresolved_plugin_capabilities().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("H2C/A2L-era multi-nozzle and pre-heat config keys exist", "[config]") {
|
||||
// Foundation keys backing H2C 6-nozzle cluster grouping, the pre-heat/pre-cool time
|
||||
// model, and wipe-tower nozzle-change handling. Defaults must keep existing
|
||||
|
||||
Reference in new issue
Block a user