Snapshots extended to capture and restore sla_print, sla_material,

physical_printers.
Updated the snapshots dialog to display sla_print and sla_material.
Updated the snapshots dialog to display physical_printer instead of
printer if the physical_printer key is nonempty.
The "physical_printer" key was moved from [extras] to [presets] section
of PrusaSlicer.ini
This commit is contained in:
Vojtech Bubnik 2020-10-27 12:48:20 +01:00
parent 15a75ec6b0
commit 06c16b085d
6 changed files with 74 additions and 26 deletions

View file

@ -205,6 +205,20 @@ std::string AppConfig::load()
m_legacy_datadir = ini_ver < Semver(1, 40, 0);
}
// Legacy conversion
if (m_mode == EAppMode::Editor) {
// Convert [extras] "physical_printer" to [presets] "physical_printer",
// remove the [extras] section if it becomes empty.
if (auto it_section = m_storage.find("extras"); it_section != m_storage.end()) {
if (auto it_physical_printer = it_section->second.find("physical_printer"); it_physical_printer != it_section->second.end()) {
m_storage["presets"]["physical_printer"] = it_physical_printer->second;
it_section->second.erase(it_physical_printer);
}
if (it_section->second.empty())
m_storage.erase(it_section);
}
}
// Override missing or keys with their defaults.
this->set_defaults();
m_dirty = false;
@ -428,6 +442,7 @@ void AppConfig::reset_selections()
it->second.erase("sla_print");
it->second.erase("sla_material");
it->second.erase("printer");
it->second.erase("physical_printer");
m_dirty = true;
}
}

View file

@ -142,20 +142,20 @@ public:
#endif // ENABLE_GCODE_VIEWER
// Returns true if the user's data directory comes from before Slic3r 1.40.0 (no updating)
bool legacy_datadir() const { return m_legacy_datadir; }
void set_legacy_datadir(bool value) { m_legacy_datadir = value; }
bool legacy_datadir() const { return m_legacy_datadir; }
void set_legacy_datadir(bool value) { m_legacy_datadir = value; }
// Get the Slic3r version check url.
// This returns a hardcoded string unless it is overriden by "version_check_url" in the ini file.
std::string version_check_url() const;
std::string version_check_url() const;
// Returns the original Slic3r version found in the ini file before it was overwritten
// by the current version
Semver orig_version() const { return m_orig_version; }
Semver orig_version() const { return m_orig_version; }
// Does the config file exist?
#if ENABLE_GCODE_VIEWER
bool exists();
bool exists();
#else
static bool exists();
#endif // ENABLE_GCODE_VIEWER

View file

@ -458,7 +458,7 @@ void PresetBundle::load_selections(AppConfig &config, const std::string &preferr
this->update_multi_material_filament_presets();
// Parse the initial physical printer name.
std::string initial_physical_printer_name = remove_ini_suffix(config.get("extras", "physical_printer"));
std::string initial_physical_printer_name = remove_ini_suffix(config.get("presets", "physical_printer"));
// Activate physical printer from the config
if (!initial_physical_printer_name.empty())
@ -482,8 +482,7 @@ void PresetBundle::export_selections(AppConfig &config)
config.set("presets", "sla_print", sla_prints.get_selected_preset_name());
config.set("presets", "sla_material", sla_materials.get_selected_preset_name());
config.set("presets", "printer", printers.get_selected_preset_name());
config.set("extras", "physical_printer", physical_printers.get_selected_full_printer_name());
config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name());
}
DynamicPrintConfig PresetBundle::full_config() const

View file

@ -31,8 +31,11 @@ void Snapshot::clear()
this->comment.clear();
this->reason = SNAPSHOT_UNKNOWN;
this->print.clear();
this->sla_print.clear();
this->filaments.clear();
this->sla_material.clear();
this->printer.clear();
this->physical_printer.clear();
}
void Snapshot::load_ini(const std::string &path)
@ -94,6 +97,8 @@ void Snapshot::load_ini(const std::string &path)
for (auto &kvp : section.second) {
if (kvp.first == "print") {
this->print = kvp.second.data();
} else if (kvp.first == "sla_print") {
this->sla_print = kvp.second.data();
} else if (boost::starts_with(kvp.first, "filament")) {
int idx = 0;
if (kvp.first == "filament" || sscanf(kvp.first.c_str(), "filament_%d", &idx) == 1) {
@ -101,8 +106,12 @@ void Snapshot::load_ini(const std::string &path)
this->filaments.resize(idx + 1, std::string());
this->filaments[idx] = kvp.second.data();
}
} else if (kvp.first == "sla_material") {
this->sla_material = kvp.second.data();
} else if (kvp.first == "printer") {
this->printer = kvp.second.data();
} else if (kvp.first == "physical_printer") {
this->physical_printer = kvp.second.data();
}
}
} else if (boost::starts_with(section.first, group_name_vendor) && section.first.size() > group_name_vendor.size()) {
@ -172,10 +181,13 @@ void Snapshot::save_ini(const std::string &path)
// Export the active presets at the time of the snapshot.
c << std::endl << "[presets]" << std::endl;
c << "print = " << this->print << std::endl;
c << "sla_print = " << this->sla_print << std::endl;
c << "filament = " << this->filaments.front() << std::endl;
for (size_t i = 1; i < this->filaments.size(); ++ i)
c << "filament_" << std::to_string(i) << " = " << this->filaments[i] << std::endl;
c << "sla_material = " << this->sla_material << std::endl;
c << "printer = " << this->printer << std::endl;
c << "physical_printer = " << this->physical_printer << std::endl;
// Export the vendor configs.
for (const VendorConfig &vc : this->vendor_configs) {
@ -199,14 +211,17 @@ void Snapshot::export_selections(AppConfig &config) const
{
assert(filaments.size() >= 1);
config.clear_section("presets");
config.set("presets", "print", print);
config.set("presets", "filament", filaments.front());
config.set("presets", "print", print);
config.set("presets", "sla_print", sla_print);
config.set("presets", "filament", filaments.front());
for (unsigned i = 1; i < filaments.size(); ++i) {
char name[64];
sprintf(name, "filament_%u", i);
config.set("presets", name, filaments[i]);
}
config.set("presets", "printer", printer);
config.set("presets", "sla_material", sla_material);
config.set("presets", "printer", printer);
config.set("presets", "physical_printer", physical_printer);
}
void Snapshot::export_vendor_configs(AppConfig &config) const
@ -217,8 +232,10 @@ void Snapshot::export_vendor_configs(AppConfig &config) const
config.set_vendors(std::move(vendors));
}
// Perform a deep compare of the active print / filament / printer / vendor directories.
// Return true if the content of the current print / filament / printer / vendor directories
static constexpr auto snapshot_subdirs = { "print", "sla_print", "filament", "sla_material", "printer", "physical_printer", "vendor" };
// Perform a deep compare of the active print / sla_print / filament / sla_material / printer / physical_printer / vendor directories.
// Return true if the content of the current print / sla_print / filament / sla_material / printer / physical_printer / vendor directories
// matches the state stored in this snapshot.
bool Snapshot::equal_to_active(const AppConfig &app_config) const
{
@ -243,7 +260,7 @@ bool Snapshot::equal_to_active(const AppConfig &app_config) const
// 2) Check, whether this snapshot references the same set of ini files as the current state.
boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
boost::filesystem::path snapshot_dir = boost::filesystem::path(Slic3r::data_dir()) / SLIC3R_SNAPSHOTS_DIR / this->id;
for (const char *subdir : { "print", "filament", "printer", "vendor" }) {
for (const char *subdir : snapshot_subdirs) {
boost::filesystem::path path1 = data_dir / subdir;
boost::filesystem::path path2 = snapshot_dir / subdir;
std::vector<std::string> files1, files2;
@ -369,9 +386,12 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
snapshot.comment = comment;
snapshot.reason = reason;
// Active presets at the time of the snapshot.
snapshot.print = app_config.get("presets", "print");
snapshot.print = app_config.get("presets", "print");
snapshot.sla_print = app_config.get("presets", "sla_print");
snapshot.filaments.emplace_back(app_config.get("presets", "filament"));
snapshot.printer = app_config.get("presets", "printer");
snapshot.sla_material = app_config.get("presets", "sla_material");
snapshot.printer = app_config.get("presets", "printer");
snapshot.physical_printer = app_config.get("presets", "physical_printer");
for (unsigned i = 1; i < 1000; ++ i) {
char name[64];
sprintf(name, "filament_%u", i);
@ -414,7 +434,7 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
boost::filesystem::create_directory(snapshot_dir);
// Backup the presets.
for (const char *subdir : { "print", "filament", "printer", "vendor" })
for (const char *subdir : snapshot_subdirs)
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);
@ -438,11 +458,11 @@ void SnapshotDB::restore_snapshot(const Snapshot &snapshot, AppConfig &app_confi
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" }) {
for (const char *subdir : snapshot_subdirs) {
delete_existing_ini_files(data_dir / subdir);
copy_config_dir_single_level(snapshot_dir / subdir, data_dir / subdir);
}
// Update AppConfig with the selections of the print / filament / printer profiles
// Update AppConfig with the selections of the print / sla_print / filament / sla_material / printer profiles
// and about the installed printer types and variants.
snapshot.export_selections(app_config);
snapshot.export_vendor_configs(app_config);

View file

@ -23,8 +23,11 @@ namespace Config {
// Slic3r.ini
// vendor/
// print/
// sla_print/
// filament/
// sla_material
// printer/
// physical_printer/
class Snapshot
{
public:
@ -42,12 +45,12 @@ public:
void load_ini(const std::string &path);
void save_ini(const std::string &path);
// Export the print / filament / printer selections to be activated into the AppConfig.
// Export the print / sla_print / filament / sla_material / printer selections to be activated into the AppConfig.
void export_selections(AppConfig &config) const;
void export_vendor_configs(AppConfig &config) const;
// Perform a deep compare of the active print / filament / printer / vendor directories.
// Return true if the content of the current print / filament / printer / vendor directories
// Perform a deep compare of the active print / sla_print / filament / sla_material / printer / physical_printer / vendor directories.
// Return true if the content of the current print / sla_print / filament / sla_material / printer / physical_printer / vendor directories
// matches the state stored in this snapshot.
bool equal_to_active(const AppConfig &app_config) const;
@ -65,8 +68,11 @@ public:
// Active presets at the time of the snapshot.
std::string print;
std::string sla_print;
std::vector<std::string> filaments;
std::string sla_material;
std::string printer;
std::string physical_printer;
// Annotation of the vendor configuration stored in the snapshot.
// This information is displayed to the user and used to decide compatibility
@ -97,7 +103,7 @@ public:
size_t load_db();
void update_slic3r_versions(std::vector<Index> &index_db);
// Create a snapshot directory, copy the vendor config bundles, user print/filament/printer profiles,
// Create a snapshot directory, copy the vendor config bundles, user print / sla_print / filament / sla_material / printer / physical_printer profiles,
// create an index.
const Snapshot& take_snapshot(const AppConfig &app_config, Snapshot::Reason reason, const std::string &comment = "");
const Snapshot& restore_snapshot(const std::string &id, AppConfig &app_config);

View file

@ -48,9 +48,17 @@ static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_eve
text += "</b></font><br>";
// End of row header.
text += _(L("PrusaSlicer version")) + ": " + snapshot.slic3r_version_captured.to_string() + "<br>";
text += _(L("print")) + ": " + snapshot.print + "<br>";
text += _(L("filaments")) + ": " + snapshot.filaments.front() + "<br>";
text += _(L("printer")) + ": " + snapshot.printer + "<br>";
bool has_fff = ! snapshot.print.empty() || ! snapshot.filaments.empty();
bool has_sla = ! snapshot.sla_print.empty() || ! snapshot.sla_material.empty();
if (has_fff || ! has_sla) {
text += _(L("print")) + ": " + snapshot.print + "<br>";
text += _(L("filaments")) + ": " + snapshot.filaments.front() + "<br>";
}
if (has_sla) {
text += _(L("SLA print")) + ": " + snapshot.sla_print + "<br>";
text += _(L("SLA material")) + ": " + snapshot.sla_material + "<br>";
}
text += _(L("printer")) + ": " + (snapshot.physical_printer.empty() ? snapshot.printer : snapshot.physical_printer) + "<br>";
bool compatible = true;
for (const Config::Snapshot::VendorConfig &vc : snapshot.vendor_configs) {