mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 00:31:11 -06:00
Wizard runs from the new Config menu,
snapshots could be rolled back / forward.
This commit is contained in:
parent
4275b15dcd
commit
da2878958b
13 changed files with 165 additions and 86 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "Snapshot.hpp"
|
||||
#include "../GUI/AppConfig.hpp"
|
||||
#include "../GUI/PresetBundle.hpp"
|
||||
#include "../Utils/Time.hpp"
|
||||
|
||||
#include <time.h>
|
||||
|
@ -172,6 +173,14 @@ void Snapshot::export_selections(AppConfig &config) const
|
|||
config.set("presets", "printer", printer);
|
||||
}
|
||||
|
||||
void Snapshot::export_vendor_configs(AppConfig &config) const
|
||||
{
|
||||
std::map<std::string, std::map<std::string, std::set<std::string>>> vendors;
|
||||
for (const VendorConfig &vc : vendor_configs)
|
||||
vendors[vc.name] = vc.models_variants_installed;
|
||||
config.set_vendors(std::move(vendors));
|
||||
}
|
||||
|
||||
size_t SnapshotDB::load_db()
|
||||
{
|
||||
boost::filesystem::path snapshots_dir = SnapshotDB::create_db_dir();
|
||||
|
@ -199,7 +208,8 @@ size_t SnapshotDB::load_db()
|
|||
}
|
||||
m_snapshots.emplace_back(std::move(snapshot));
|
||||
}
|
||||
|
||||
// Sort the snapshots by their date/time.
|
||||
std::sort(m_snapshots.begin(), m_snapshots.end(), [](const Snapshot &s1, const Snapshot &s2) { return s1.time_captured < s2.time_captured; });
|
||||
if (! errors_cummulative.empty())
|
||||
throw std::runtime_error(errors_cummulative);
|
||||
return m_snapshots.size();
|
||||
|
@ -266,6 +276,30 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
|
|||
snapshot.filaments.emplace_back(app_config.get("presets", name));
|
||||
}
|
||||
// Vendor specific config bundles and installed printers.
|
||||
for (const std::pair<std::string, std::map<std::string, std::set<std::string>>> &vendor : app_config.vendors()) {
|
||||
Snapshot::VendorConfig cfg;
|
||||
cfg.name = vendor.first;
|
||||
cfg.models_variants_installed = vendor.second;
|
||||
// Read the active config bundle, parse the config version.
|
||||
PresetBundle bundle;
|
||||
bundle.load_configbundle((data_dir / "vendor" / (cfg.name + ".ini")).string(), PresetBundle::LOAD_CFGBUNDLE_VENDOR_ONLY);
|
||||
for (const VendorProfile &vp : bundle.vendors)
|
||||
if (vp.id == cfg.name)
|
||||
cfg.version = *Semver::parse(vp.config_version);
|
||||
// Fill-in the min/max slic3r version from the config index, if possible.
|
||||
try {
|
||||
// Load the config index for the vendor.
|
||||
Index index;
|
||||
index.load(data_dir / "vendor" / (cfg.name + ".idx"));
|
||||
auto it = index.find(cfg.version);
|
||||
if (it != index.end()) {
|
||||
cfg.min_slic3r_version = it->min_slic3r_version;
|
||||
cfg.max_slic3r_version = it->max_slic3r_version;
|
||||
}
|
||||
} catch (const std::runtime_error &err) {
|
||||
}
|
||||
snapshot.vendor_configs.emplace_back(std::move(cfg));
|
||||
}
|
||||
|
||||
boost::filesystem::path snapshot_dir = snapshot_db_dir / snapshot.id;
|
||||
boost::filesystem::create_directory(snapshot_dir);
|
||||
|
@ -274,6 +308,7 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
|
|||
for (const char *subdir : { "print", "filament", "printer", "vendor" })
|
||||
copy_config_dir_single_level(data_dir / subdir, snapshot_dir / subdir);
|
||||
snapshot.save_ini((snapshot_dir / "snapshot.ini").string());
|
||||
assert(m_snapshots.empty() || m_snapshots.back().time_captured <= snapshot.time_captured);
|
||||
m_snapshots.emplace_back(std::move(snapshot));
|
||||
return m_snapshots.back();
|
||||
}
|
||||
|
@ -293,18 +328,15 @@ void SnapshotDB::restore_snapshot(const Snapshot &snapshot, AppConfig &app_confi
|
|||
boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
|
||||
boost::filesystem::path snapshot_db_dir = SnapshotDB::create_db_dir();
|
||||
boost::filesystem::path snapshot_dir = snapshot_db_dir / snapshot.id;
|
||||
|
||||
// Remove existing ini files and restore the ini files from the snapshot.
|
||||
for (const char *subdir : { "print", "filament", "printer", "vendor" }) {
|
||||
delete_existing_ini_files(data_dir / subdir);
|
||||
copy_config_dir_single_level(snapshot_dir / subdir, data_dir / subdir);
|
||||
}
|
||||
|
||||
// Update app_config from the snapshot.
|
||||
// Update AppConfig with the selections of the print / filament / printer profiles
|
||||
// and about the installed printer types and variants.
|
||||
snapshot.export_selections(app_config);
|
||||
|
||||
// Store information about the snapshot.
|
||||
|
||||
snapshot.export_vendor_configs(app_config);
|
||||
}
|
||||
|
||||
boost::filesystem::path SnapshotDB::create_db_dir()
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef slic3r_GUI_Snapshot_
|
||||
#define slic3r_GUI_Snapshot_
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -17,6 +19,7 @@ namespace GUI {
|
|||
namespace Config {
|
||||
|
||||
class Version;
|
||||
class Index;
|
||||
|
||||
// A snapshot contains:
|
||||
// Slic3r.ini
|
||||
|
@ -42,6 +45,7 @@ public:
|
|||
|
||||
// Export the print / filament / printer selections to be activated into the AppConfig.
|
||||
void export_selections(AppConfig &config) const;
|
||||
void export_vendor_configs(AppConfig &config) const;
|
||||
|
||||
// ID of a snapshot should equal to the name of the snapshot directory.
|
||||
// The ID contains the date/time, reason and comment to be human readable.
|
||||
|
@ -70,6 +74,8 @@ public:
|
|||
Semver min_slic3r_version = Semver::zero();
|
||||
// Maximum Slic3r version compatible with this vendor configuration, or empty.
|
||||
Semver max_slic3r_version = Semver::inf();
|
||||
// Which printer models of this vendor were installed, and which variants of the models?
|
||||
std::map<std::string, std::set<std::string>> models_variants_installed;
|
||||
};
|
||||
// List of vendor configs contained in this snapshot.
|
||||
std::vector<VendorConfig> vendor_configs;
|
||||
|
|
|
@ -71,6 +71,9 @@ public:
|
|||
bool get_variant(const std::string &vendor, const std::string &model, const std::string &variant) const;
|
||||
void set_variant(const std::string &vendor, const std::string &model, const std::string &variant, bool enable);
|
||||
void set_vendors(const AppConfig &from);
|
||||
void set_vendors(const std::map<std::string, std::map<std::string, std::set<std::string>>> &vendors) { m_vendors = vendors; m_dirty = true; }
|
||||
void set_vendors(std::map<std::string, std::map<std::string, std::set<std::string>>> &&vendors) { m_vendors = std::move(vendors); m_dirty = true; }
|
||||
const std::map<std::string, std::map<std::string, std::set<std::string>>> vendors() const { return m_vendors; }
|
||||
|
||||
// return recent/skein_directory or recent/config_directory or empty string.
|
||||
std::string get_last_dir() const;
|
||||
|
|
|
@ -26,7 +26,19 @@ static std::string generate_html_row(const Config::Snapshot &snapshot, bool row_
|
|||
text += "printer: " + snapshot.printer + "<br>";
|
||||
|
||||
for (const Config::Snapshot::VendorConfig &vc : snapshot.vendor_configs) {
|
||||
text += "vendor: " + vc.name + ", ver: " + vc.version.to_string() + ", min slic3r ver: " + vc.min_slic3r_version.to_string() + ", max slic3r ver: " + vc.max_slic3r_version.to_string() + "<br>";
|
||||
text += "vendor: " + vc.name + ", ver: " + vc.version.to_string() + ", min slic3r ver: " + vc.min_slic3r_version.to_string();
|
||||
if (vc.max_slic3r_version != Semver::inf())
|
||||
text += ", max slic3r ver: " + vc.max_slic3r_version.to_string();
|
||||
text += "<br>";
|
||||
for (const std::pair<std::string, std::set<std::string>> &model : vc.models_variants_installed) {
|
||||
text += "model: " + model.first + ", variants: ";
|
||||
for (const std::string &variant : model.second) {
|
||||
if (&variant != &*model.second.begin())
|
||||
text += ", ";
|
||||
text += variant;
|
||||
}
|
||||
text += "<br>";
|
||||
}
|
||||
}
|
||||
|
||||
text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">Activate</a></p>";
|
||||
|
@ -43,7 +55,7 @@ static std::string generate_html_page(const Config::SnapshotDB &snapshot_db)
|
|||
"<font color=\"#000000\">";
|
||||
text += "<table style=\"width:100%\">";
|
||||
for (size_t i_row = 0; i_row < snapshot_db.snapshots().size(); ++ i_row) {
|
||||
const Config::Snapshot &snapshot = snapshot_db.snapshots()[i_row];
|
||||
const Config::Snapshot &snapshot = snapshot_db.snapshots()[snapshot_db.snapshots().size() - i_row - 1];
|
||||
text += generate_html_row(snapshot, i_row & 1);
|
||||
}
|
||||
text +=
|
||||
|
@ -96,8 +108,9 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
|
|||
|
||||
void ConfigSnapshotDialog::onLinkClicked(wxHtmlLinkEvent &event)
|
||||
{
|
||||
wxLaunchDefaultBrowser(event.GetLinkInfo().GetHref());
|
||||
event.Skip(false);
|
||||
m_snapshot_to_activate = event.GetLinkInfo().GetHref();
|
||||
this->EndModal(wxID_CLOSE);
|
||||
this->Close();
|
||||
}
|
||||
|
||||
void ConfigSnapshotDialog::onCloseDialog(wxEvent &)
|
||||
|
|
|
@ -19,9 +19,13 @@ class ConfigSnapshotDialog : public wxDialog
|
|||
public:
|
||||
ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db);
|
||||
|
||||
const std::string& snapshot_to_activate() const { return m_snapshot_to_activate; }
|
||||
|
||||
private:
|
||||
void onLinkClicked(wxHtmlLinkEvent &event);
|
||||
void onCloseDialog(wxEvent &);
|
||||
|
||||
std::string m_snapshot_to_activate;
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
|
|
|
@ -349,9 +349,17 @@ void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_l
|
|||
{
|
||||
auto local_menu = new wxMenu();
|
||||
wxWindowID config_id_base = wxWindow::NewControlId((int)ConfigMenuCnt);
|
||||
|
||||
|
||||
// A different naming convention is used for the Wizard on Windows vs. OSX & GTK.
|
||||
#if WIN32
|
||||
std::string config_wizard_menu = _(L("Configuration Wizard"));
|
||||
std::string config_wizard_tooltip = _(L("Run configuration wizard"));
|
||||
#else
|
||||
std::string config_wizard_menu = _(L("Configuration Assistant"));
|
||||
std::string config_wizard_tooltip = _(L("Run configuration Assistant"));
|
||||
#endif
|
||||
// Cmd+, is standard on OS X - what about other operating systems?
|
||||
local_menu->Append(config_id_base + ConfigMenuWizard, _(L("Configuration Wizard\u2026")), _(L("Run configuration wizard")));
|
||||
local_menu->Append(config_id_base + ConfigMenuWizard, config_wizard_menu + "\u2026", config_wizard_tooltip);
|
||||
local_menu->Append(config_id_base + ConfigMenuSnapshots, _(L("Configuration Snapshots\u2026")), _(L("Inspect / activate configuration snapshots")));
|
||||
local_menu->Append(config_id_base + ConfigMenuTakeSnapshot, _(L("Take Configuration Snapshot")), _(L("Capture a configuration snapshot")));
|
||||
local_menu->Append(config_id_base + ConfigMenuUpdate, _(L("Check for updates")), _(L("Check for configuration updates")));
|
||||
|
@ -361,21 +369,35 @@ void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_l
|
|||
local_menu->Append(config_id_base + ConfigMenuLanguage, _(L("Change Application Language")));
|
||||
local_menu->Bind(wxEVT_MENU, [config_id_base, event_language_change, event_preferences_changed](wxEvent &event){
|
||||
switch (event.GetId() - config_id_base) {
|
||||
case ConfigMenuWizard:
|
||||
config_wizard(0);
|
||||
break;
|
||||
case ConfigMenuTakeSnapshot:
|
||||
// Take a configuration snapshot.
|
||||
Slic3r::GUI::Config::SnapshotDB::singleton().take_snapshot(*g_AppConfig, Slic3r::GUI::Config::Snapshot::SNAPSHOT_USER, "");
|
||||
if (check_unsaved_changes()) {
|
||||
wxTextEntryDialog dlg(nullptr, _(L("Taking configuration snapshot")), _(L("Snapshot name")));
|
||||
if (dlg.ShowModal() == wxID_OK)
|
||||
Slic3r::GUI::Config::SnapshotDB::singleton().take_snapshot(
|
||||
*g_AppConfig, Slic3r::GUI::Config::Snapshot::SNAPSHOT_USER, dlg.GetValue().ToUTF8().data());
|
||||
}
|
||||
break;
|
||||
case ConfigMenuSnapshots:
|
||||
{
|
||||
ConfigSnapshotDialog dlg(Slic3r::GUI::Config::SnapshotDB::singleton());
|
||||
dlg.ShowModal();
|
||||
dlg.Destroy();
|
||||
if (check_unsaved_changes()) {
|
||||
ConfigSnapshotDialog dlg(Slic3r::GUI::Config::SnapshotDB::singleton());
|
||||
dlg.ShowModal();
|
||||
if (! dlg.snapshot_to_activate().empty()) {
|
||||
Config::SnapshotDB::singleton().restore_snapshot(dlg.snapshot_to_activate(), *g_AppConfig);
|
||||
g_PresetBundle->load_presets(*g_AppConfig);
|
||||
// Load the currently selected preset into the GUI, update the preset selection box.
|
||||
for (Tab *tab : g_tabs_list)
|
||||
tab->load_current_preset();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ConfigMenuPreferences:
|
||||
{
|
||||
auto dlg = new PreferencesDialog(g_wxMainFrame, event_preferences_changed);
|
||||
dlg->ShowModal();
|
||||
PreferencesDialog dlg(g_wxMainFrame, event_preferences_changed);
|
||||
dlg.ShowModal();
|
||||
break;
|
||||
}
|
||||
case ConfigMenuLanguage:
|
||||
|
@ -398,13 +420,45 @@ void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_l
|
|||
menu->Append(local_menu, _(L("&Configuration")));
|
||||
}
|
||||
|
||||
bool open_config_wizard(PresetBundle *preset_bundle)
|
||||
// This is called when closing the application, when loading a config file or when starting the config wizard
|
||||
// to notify the user whether he is aware that some preset changes will be lost.
|
||||
bool check_unsaved_changes()
|
||||
{
|
||||
if (g_wxMainFrame == nullptr) {
|
||||
throw std::runtime_error("Main frame not set");
|
||||
}
|
||||
std::string dirty;
|
||||
for (Tab *tab : g_tabs_list)
|
||||
if (tab->current_preset_is_dirty())
|
||||
if (dirty.empty())
|
||||
dirty = tab->name();
|
||||
else
|
||||
dirty += std::string(", ") + tab->name();
|
||||
if (dirty.empty())
|
||||
// No changes, the application may close or reload presets.
|
||||
return true;
|
||||
// Ask the user.
|
||||
auto dialog = new wxMessageDialog(g_wxMainFrame,
|
||||
_(L("You have unsaved changes ")) + dirty + _(L(". Discard changes and continue anyway?")),
|
||||
_(L("Unsaved Presets")),
|
||||
wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT);
|
||||
return dialog->ShowModal() == wxID_YES;
|
||||
}
|
||||
|
||||
return ConfigWizard::run(g_wxMainFrame, preset_bundle);
|
||||
bool config_wizard(bool fresh_start)
|
||||
{
|
||||
if (g_wxMainFrame == nullptr)
|
||||
throw std::runtime_error("Main frame not set");
|
||||
|
||||
// Exit wizard if there are unsaved changes and the user cancels the action.
|
||||
if (! check_unsaved_changes())
|
||||
return false;
|
||||
|
||||
// TODO: Offer "reset user profile" ???
|
||||
if (! ConfigWizard::run(g_wxMainFrame, g_PresetBundle))
|
||||
return false;
|
||||
|
||||
// Load the currently selected preset into the GUI, update the preset selection box.
|
||||
for (Tab *tab : g_tabs_list)
|
||||
tab->load_current_preset();
|
||||
return true;
|
||||
}
|
||||
|
||||
void open_preferences_dialog(int event_preferences)
|
||||
|
|
|
@ -82,13 +82,17 @@ wxApp* get_app();
|
|||
wxColour* get_modified_label_clr();
|
||||
wxColour* get_sys_label_clr();
|
||||
|
||||
void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_language_change);
|
||||
extern void add_config_menu(wxMenuBar *menu, int event_preferences_changed, int event_language_change);
|
||||
|
||||
// This is called when closing the application, when loading a config file or when starting the config wizard
|
||||
// to notify the user whether he is aware that some preset changes will be lost.
|
||||
extern bool check_unsaved_changes();
|
||||
|
||||
// Opens the first-time configuration wizard, returns true if wizard is finished & accepted.
|
||||
bool open_config_wizard(PresetBundle *preset_bundle);
|
||||
extern bool config_wizard(bool fresh_start);
|
||||
|
||||
// Create "Preferences" dialog after selecting menu "Preferences" in Perl part
|
||||
void open_preferences_dialog(int event_preferences);
|
||||
extern void open_preferences_dialog(int event_preferences);
|
||||
|
||||
// Create a new preset tab (print, filament and printer),
|
||||
void create_preset_tabs(bool no_controller, int event_value_change, int event_presets_changed);
|
||||
|
|
|
@ -2061,9 +2061,9 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox
|
|||
presets.Add(preset.name);
|
||||
}
|
||||
|
||||
auto dlg = new wxMultiChoiceDialog(parent,
|
||||
_(L("Select the printers this profile is compatible with.")),
|
||||
_(L("Compatible printers")), presets);
|
||||
wxMultiChoiceDialog dlg(parent,
|
||||
_(L("Select the printers this profile is compatible with.")),
|
||||
_(L("Compatible printers")), presets);
|
||||
// # Collect and set indices of printers marked as compatible.
|
||||
wxArrayInt selections;
|
||||
auto *compatible_printers = dynamic_cast<const ConfigOptionStrings*>(m_config->option("compatible_printers"));
|
||||
|
@ -2075,12 +2075,12 @@ wxSizer* Tab::compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox
|
|||
selections.Add(idx);
|
||||
break;
|
||||
}
|
||||
dlg->SetSelections(selections);
|
||||
dlg.SetSelections(selections);
|
||||
std::vector<std::string> value;
|
||||
// Show the dialog.
|
||||
if (dlg->ShowModal() == wxID_OK) {
|
||||
if (dlg.ShowModal() == wxID_OK) {
|
||||
selections.Clear();
|
||||
selections = dlg->GetSelections();
|
||||
selections = dlg.GetSelections();
|
||||
for (auto idx : selections)
|
||||
value.push_back(presets[idx].ToStdString());
|
||||
if (value.empty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue