mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-23 00:31:11 -06:00
Merge branch 'config_snapshots' into updating
This commit is contained in:
commit
7710b541da
21 changed files with 323 additions and 553 deletions
|
@ -133,6 +133,21 @@ void Snapshot::load_ini(const std::string &path)
|
|||
}
|
||||
}
|
||||
|
||||
static std::string reason_string(const Snapshot::Reason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
case Snapshot::SNAPSHOT_UPGRADE:
|
||||
return "upgrade";
|
||||
case Snapshot::SNAPSHOT_DOWNGRADE:
|
||||
return "downgrade";
|
||||
case Snapshot::SNAPSHOT_USER:
|
||||
return "user";
|
||||
case Snapshot::SNAPSHOT_UNKNOWN:
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void Snapshot::save_ini(const std::string &path)
|
||||
{
|
||||
boost::nowide::ofstream c;
|
||||
|
@ -145,7 +160,7 @@ void Snapshot::save_ini(const std::string &path)
|
|||
c << "time_captured = " << Slic3r::Utils::format_time_ISO8601Z(this->time_captured) << std::endl;
|
||||
c << "slic3r_version_captured = " << this->slic3r_version_captured.to_string() << std::endl;
|
||||
c << "comment = " << this->comment << std::endl;
|
||||
c << "reason = " << this->reason << std::endl;
|
||||
c << "reason = " << reason_string(this->reason) << std::endl;
|
||||
|
||||
// Export the active presets at the time of the snapshot.
|
||||
c << std::endl << "[presets]" << std::endl;
|
||||
|
@ -294,6 +309,11 @@ const Snapshot& SnapshotDB::take_snapshot(const AppConfig &app_config, Snapshot:
|
|||
Snapshot::VendorConfig cfg;
|
||||
cfg.name = vendor.first;
|
||||
cfg.models_variants_installed = vendor.second;
|
||||
for (auto it = cfg.models_variants_installed.begin(); it != cfg.models_variants_installed.end();)
|
||||
if (it->second.empty())
|
||||
cfg.models_variants_installed.erase(it ++);
|
||||
else
|
||||
++ it;
|
||||
// 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);
|
||||
|
|
|
@ -57,6 +57,8 @@ public:
|
|||
std::string comment;
|
||||
Reason reason;
|
||||
|
||||
std::string format_reason() const;
|
||||
|
||||
// Active presets at the time of the snapshot.
|
||||
std::string print;
|
||||
std::vector<std::string> filaments;
|
||||
|
|
|
@ -15,11 +15,131 @@ namespace Config {
|
|||
|
||||
static boost::optional<Semver> s_current_slic3r_semver = Semver::parse(SLIC3R_VERSION);
|
||||
|
||||
// Optimized lexicographic compare of two pre-release versions, ignoring the numeric suffix.
|
||||
static int compare_prerelease(const char *p1, const char *p2)
|
||||
{
|
||||
for (;;) {
|
||||
char c1 = *p1 ++;
|
||||
char c2 = *p2 ++;
|
||||
bool a1 = std::isalpha(c1) && c1 != 0;
|
||||
bool a2 = std::isalpha(c2) && c2 != 0;
|
||||
if (a1) {
|
||||
if (a2) {
|
||||
if (c1 != c2)
|
||||
return (c1 < c2) ? -1 : 1;
|
||||
} else
|
||||
return 1;
|
||||
} else {
|
||||
if (a2)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// This shall never happen.
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Version::is_slic3r_supported(const Semver &slic3r_version) const
|
||||
{
|
||||
if (! slic3r_version.in_range(min_slic3r_version, max_slic3r_version))
|
||||
return false;
|
||||
// Now verify, whether the configuration pre-release status is compatible with the Slic3r's pre-release status.
|
||||
// Alpha Slic3r will happily load any configuration, while beta Slic3r will ignore alpha configurations etc.
|
||||
const char *prerelease_slic3r = slic3r_version.prerelease();
|
||||
const char *prerelease_config = this->config_version.prerelease();
|
||||
if (prerelease_config == nullptr)
|
||||
// Released config is always supported.
|
||||
return true;
|
||||
else if (prerelease_slic3r == nullptr)
|
||||
// Released slic3r only supports released configs.
|
||||
return false;
|
||||
// Compare the pre-release status of Slic3r against the config.
|
||||
// If the prerelease status of slic3r is lexicographically lower or equal
|
||||
// to the prerelease status of the config, accept it.
|
||||
return compare_prerelease(prerelease_slic3r, prerelease_config) != 1;
|
||||
}
|
||||
|
||||
bool Version::is_current_slic3r_supported() const
|
||||
{
|
||||
return this->is_slic3r_supported(*s_current_slic3r_semver);
|
||||
}
|
||||
|
||||
#if 0
|
||||
//TODO: This test should be moved to a unit test, once we have C++ unit tests in place.
|
||||
static int version_test()
|
||||
{
|
||||
Version v;
|
||||
v.config_version = *Semver::parse("1.1.2");
|
||||
v.min_slic3r_version = *Semver::parse("1.38.0");
|
||||
v.max_slic3r_version = Semver::inf();
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.38.0")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha")));
|
||||
// Test the prerelease status.
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0")));
|
||||
v.config_version = *Semver::parse("1.1.2-alpha");
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
|
||||
v.config_version = *Semver::parse("1.1.2-alpha1");
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
|
||||
v.config_version = *Semver::parse("1.1.2-beta");
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
|
||||
v.config_version = *Semver::parse("1.1.2-rc");
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
|
||||
v.config_version = *Semver::parse("1.1.2-rc2");
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-alpha1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-beta1")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc")));
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.39.0-rc2")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.39.0")));
|
||||
// Test the upper boundary.
|
||||
v.config_version = *Semver::parse("1.1.2");
|
||||
v.max_slic3r_version = *Semver::parse("1.39.3-beta1");
|
||||
assert(v.is_slic3r_supported(*Semver::parse("1.38.0")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.38.0-alpha1")));
|
||||
assert(! v.is_slic3r_supported(*Semver::parse("1.37.0-alpha")));
|
||||
return 0;
|
||||
}
|
||||
static int version_test_run = version_test();
|
||||
#endif
|
||||
|
||||
inline char* left_trim(char *c)
|
||||
{
|
||||
for (; *c == ' ' || *c == '\t'; ++ c);
|
||||
|
@ -141,6 +261,15 @@ size_t Index::load(const boost::filesystem::path &path)
|
|||
return m_configs.size();
|
||||
}
|
||||
|
||||
Semver Index::version() const
|
||||
{
|
||||
Semver ver = Semver::zero();
|
||||
for (const Version &cv : m_configs)
|
||||
if (cv.config_version >= ver)
|
||||
ver = cv.config_version;
|
||||
return ver;
|
||||
}
|
||||
|
||||
Index::const_iterator Index::find(const Semver &ver) const
|
||||
{
|
||||
Version key;
|
||||
|
|
|
@ -27,7 +27,7 @@ struct Version
|
|||
// Single comment line.
|
||||
std::string comment;
|
||||
|
||||
bool is_slic3r_supported(const Semver &slicer_version) const { return slicer_version.in_range(min_slic3r_version, max_slic3r_version); }
|
||||
bool is_slic3r_supported(const Semver &slicer_version) const;
|
||||
bool is_current_slic3r_supported() const;
|
||||
};
|
||||
|
||||
|
@ -59,6 +59,9 @@ public:
|
|||
size_t load(const boost::filesystem::path &path);
|
||||
|
||||
const std::string& vendor() const { return m_vendor; }
|
||||
// Returns version of the index as the highest version of all the configs.
|
||||
// If there is no config, Semver::zero() is returned.
|
||||
Semver version() const;
|
||||
|
||||
const_iterator begin() const { return m_configs.begin(); }
|
||||
const_iterator end() const { return m_configs.end(); }
|
||||
|
|
|
@ -8,6 +8,21 @@
|
|||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
static std::string format_reason(const Config::Snapshot::Reason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
case Config::Snapshot::SNAPSHOT_UPGRADE:
|
||||
return std::string(_(L("Upgrade")));
|
||||
case Config::Snapshot::SNAPSHOT_DOWNGRADE:
|
||||
return std::string(_(L("Downgrade")));
|
||||
case Config::Snapshot::SNAPSHOT_USER:
|
||||
return std::string(_(L("User")));
|
||||
case Config::Snapshot::SNAPSHOT_UNKNOWN:
|
||||
default:
|
||||
return std::string(_(L("Unknown")));
|
||||
}
|
||||
}
|
||||
|
||||
static std::string generate_html_row(const Config::Snapshot &snapshot, bool row_even)
|
||||
{
|
||||
// Start by declaring a row with an alternating background color.
|
||||
|
@ -15,11 +30,15 @@ static std::string generate_html_row(const Config::Snapshot &snapshot, bool row_
|
|||
text += row_even ? "#FFFFFF" : "#C0C0C0";
|
||||
text += "\">";
|
||||
text += "<td>";
|
||||
// text += _(L("ID:")) + " " + snapshot.id + "<br>";
|
||||
text += _(L("time captured:")) + " " + Utils::format_local_date_time(snapshot.time_captured) + "<br>";
|
||||
text += _(L("slic3r version:")) + " " + snapshot.slic3r_version_captured.to_string() + "<br>";
|
||||
// Format the row header.
|
||||
text += std::string("<font size=\"5\"><b>") + Utils::format_local_date_time(snapshot.time_captured) + ": " + format_reason(snapshot.reason);
|
||||
if (! snapshot.comment.empty())
|
||||
text += _(L("user comment:")) + " " + snapshot.comment + "<br>";
|
||||
text += " (" + snapshot.comment + ")";
|
||||
text += "</b></font><br>";
|
||||
// End of row header.
|
||||
// text += _(L("ID:")) + " " + snapshot.id + "<br>";
|
||||
// text += _(L("time captured:")) + " " + Utils::format_local_date_time(snapshot.time_captured) + "<br>";
|
||||
text += _(L("slic3r version:")) + " " + snapshot.slic3r_version_captured.to_string() + "<br>";
|
||||
// text += "reason: " + snapshot.reason + "<br>";
|
||||
text += "print: " + snapshot.print + "<br>";
|
||||
text += "filaments: " + snapshot.filaments.front() + "<br>";
|
||||
|
@ -79,9 +98,9 @@ ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db
|
|||
{
|
||||
wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
#ifdef __WXMSW__
|
||||
int size[] = {8,8,8,8,8,8,8};
|
||||
int size[] = {8,8,8,8,11,11,11};
|
||||
#else
|
||||
int size[] = {11,11,11,11,11,11,11};
|
||||
int size[] = {11,11,11,11,14,14,14};
|
||||
#endif
|
||||
html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
|
||||
html->SetBorders(2);
|
||||
|
|
|
@ -720,7 +720,8 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
app_config->set_vendors(appconfig_vendors);
|
||||
app_config->set("version_check", page_update->version_check ? "1" : "0");
|
||||
app_config->set("preset_update", page_update->preset_update ? "1" : "0");
|
||||
app_config->reset_selections();
|
||||
if (fresh_start)
|
||||
app_config->reset_selections();
|
||||
// ^ TODO: replace with appropriate printer selection
|
||||
preset_bundle->load_presets(*app_config);
|
||||
} else {
|
||||
|
@ -729,14 +730,17 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
}
|
||||
preset_bundle->load_config("My Settings", *custom_config);
|
||||
}
|
||||
// Update the selections from the compatibilty.
|
||||
preset_bundle->export_selections(*app_config);
|
||||
}
|
||||
|
||||
// Public
|
||||
|
||||
ConfigWizard::ConfigWizard(wxWindow *parent) :
|
||||
ConfigWizard::ConfigWizard(wxWindow *parent, bool fresh_start) :
|
||||
wxDialog(parent, wxID_ANY, _(L("Configuration Assistant")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
||||
p(new priv(this))
|
||||
{
|
||||
p->fresh_start = fresh_start;
|
||||
p->load_vendors();
|
||||
p->custom_config.reset(DynamicPrintConfig::new_from_defaults_keys({
|
||||
"gcode_flavor", "bed_shape", "nozzle_diameter", "filament_diameter", "temperature", "bed_temperature",
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace GUI {
|
|||
class ConfigWizard: public wxDialog
|
||||
{
|
||||
public:
|
||||
ConfigWizard(wxWindow *parent);
|
||||
ConfigWizard(wxWindow *parent, bool fresh_start);
|
||||
ConfigWizard(ConfigWizard &&) = delete;
|
||||
ConfigWizard(const ConfigWizard &) = delete;
|
||||
ConfigWizard &operator=(ConfigWizard &&) = delete;
|
||||
|
|
|
@ -188,6 +188,7 @@ private:
|
|||
struct ConfigWizard::priv
|
||||
{
|
||||
ConfigWizard *q;
|
||||
bool fresh_start;
|
||||
AppConfig appconfig_vendors; // TODO: use order-preserving container
|
||||
std::unordered_map<std::string, VendorProfile> vendors; // TODO: just set?
|
||||
std::unordered_map<std::string, std::string> vendors_rsrc;
|
||||
|
|
|
@ -489,7 +489,7 @@ void config_wizard(bool fresh_start) // TODO: fresh_start useful ?
|
|||
return;
|
||||
|
||||
// TODO: Offer "reset user profile" ???
|
||||
ConfigWizard wizard(g_wxMainFrame);
|
||||
ConfigWizard wizard(g_wxMainFrame, fresh_start);
|
||||
wizard.run(g_PresetBundle, g_PresetUpdater);
|
||||
|
||||
// Load the currently selected preset into the GUI, update the preset selection box.
|
||||
|
|
|
@ -528,18 +528,6 @@ size_t PresetCollection::first_visible_idx() const
|
|||
return idx;
|
||||
}
|
||||
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
size_t PresetCollection::first_compatible_idx() const
|
||||
{
|
||||
size_t idx = m_default_suppressed ? 1 : 0;
|
||||
for (; idx < this->m_presets.size(); ++ idx)
|
||||
if (m_presets[idx].is_compatible)
|
||||
break;
|
||||
if (idx == this->m_presets.size())
|
||||
idx = 0;
|
||||
return idx;
|
||||
}
|
||||
|
||||
void PresetCollection::set_default_suppressed(bool default_suppressed)
|
||||
{
|
||||
if (m_default_suppressed != default_suppressed) {
|
||||
|
@ -548,7 +536,7 @@ void PresetCollection::set_default_suppressed(bool default_suppressed)
|
|||
}
|
||||
}
|
||||
|
||||
void PresetCollection::update_compatible_with_printer(const Preset &active_printer, bool select_other_if_incompatible)
|
||||
size_t PresetCollection::update_compatible_with_printer_internal(const Preset &active_printer, bool unselect_if_incompatible)
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.set_key_value("printer_preset", new ConfigOptionString(active_printer.name));
|
||||
|
@ -559,14 +547,12 @@ void PresetCollection::update_compatible_with_printer(const Preset &active_print
|
|||
Preset &preset_selected = m_presets[idx_preset];
|
||||
Preset &preset_edited = selected ? m_edited_preset : preset_selected;
|
||||
if (! preset_edited.update_compatible_with_printer(active_printer, &config) &&
|
||||
selected && select_other_if_incompatible)
|
||||
selected && unselect_if_incompatible)
|
||||
m_idx_selected = (size_t)-1;
|
||||
if (selected)
|
||||
preset_selected.is_compatible = preset_edited.is_compatible;
|
||||
}
|
||||
if (m_idx_selected == (size_t)-1)
|
||||
// Find some other compatible preset, or the "-- default --" preset.
|
||||
this->select_preset(first_compatible_idx());
|
||||
return m_idx_selected;
|
||||
}
|
||||
|
||||
// Save the preset under a new name. If the name is different from the old one,
|
||||
|
@ -696,8 +682,8 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
|
|||
// 1) Try to find the preset by its name.
|
||||
auto it = this->find_preset_internal(name);
|
||||
size_t idx = 0;
|
||||
if (it != m_presets.end() && it->name == name)
|
||||
// Preset found by its name.
|
||||
if (it != m_presets.end() && it->name == name && it->is_visible)
|
||||
// Preset found by its name and it is visible.
|
||||
idx = it - m_presets.begin();
|
||||
else {
|
||||
// Find the first visible preset.
|
||||
|
@ -718,6 +704,23 @@ bool PresetCollection::select_preset_by_name(const std::string &name_w_suffix, b
|
|||
return false;
|
||||
}
|
||||
|
||||
bool PresetCollection::select_preset_by_name_strict(const std::string &name)
|
||||
{
|
||||
// 1) Try to find the preset by its name.
|
||||
auto it = this->find_preset_internal(name);
|
||||
size_t idx = (size_t)-1;
|
||||
if (it != m_presets.end() && it->name == name && it->is_visible)
|
||||
// Preset found by its name.
|
||||
idx = it - m_presets.begin();
|
||||
// 2) Select the new preset.
|
||||
if (idx != (size_t)-1) {
|
||||
this->select_preset(idx);
|
||||
return true;
|
||||
}
|
||||
m_idx_selected = idx;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string PresetCollection::name() const
|
||||
{
|
||||
switch (this->type()) {
|
||||
|
|
|
@ -18,6 +18,7 @@ class wxItemContainer;
|
|||
namespace Slic3r {
|
||||
|
||||
class AppConfig;
|
||||
class PresetBundle;
|
||||
|
||||
enum ConfigFileType
|
||||
{
|
||||
|
@ -244,19 +245,49 @@ public:
|
|||
{ return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found); }
|
||||
|
||||
size_t first_visible_idx() const;
|
||||
size_t first_compatible_idx() const;
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
// If one of the prefered_alternates is compatible, select it.
|
||||
template<typename PreferedCondition>
|
||||
size_t first_compatible_idx(PreferedCondition prefered_condition) const
|
||||
{
|
||||
size_t i = m_default_suppressed ? 1 : 0;
|
||||
size_t n = this->m_presets.size();
|
||||
size_t i_compatible = n;
|
||||
for (; i < n; ++ i)
|
||||
if (m_presets[i].is_compatible) {
|
||||
if (prefered_condition(m_presets[i].name))
|
||||
return i;
|
||||
if (i_compatible == n)
|
||||
// Store the first compatible profile into i_compatible.
|
||||
i_compatible = i;
|
||||
}
|
||||
return (i_compatible == n) ? 0 : i_compatible;
|
||||
}
|
||||
// Return index of the first compatible preset. Certainly at least the '- default -' preset shall be compatible.
|
||||
size_t first_compatible_idx() const { return this->first_compatible_idx([](const std::string&){return true;}); }
|
||||
|
||||
// Return index of the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
// Return the first visible preset. Certainly at least the '- default -' preset shall be visible.
|
||||
Preset& first_visible() { return this->preset(this->first_visible_idx()); }
|
||||
const Preset& first_visible() const { return this->preset(this->first_visible_idx()); }
|
||||
Preset& first_compatible() { return this->preset(this->first_compatible_idx()); }
|
||||
template<typename PreferedCondition>
|
||||
Preset& first_compatible(PreferedCondition prefered_condition) { return this->preset(this->first_compatible_idx(prefered_condition)); }
|
||||
const Preset& first_compatible() const { return this->preset(this->first_compatible_idx()); }
|
||||
|
||||
// Return number of presets including the "- default -" preset.
|
||||
size_t size() const { return this->m_presets.size(); }
|
||||
|
||||
// For Print / Filament presets, disable those, which are not compatible with the printer.
|
||||
void update_compatible_with_printer(const Preset &active_printer, bool select_other_if_incompatible);
|
||||
template<typename PreferedCondition>
|
||||
void update_compatible_with_printer(const Preset &active_printer, bool select_other_if_incompatible, PreferedCondition prefered_condition)
|
||||
{
|
||||
if (this->update_compatible_with_printer_internal(active_printer, select_other_if_incompatible) == (size_t)-1)
|
||||
// Find some other compatible preset, or the "-- default --" preset.
|
||||
this->select_preset(this->first_compatible_idx(prefered_condition));
|
||||
}
|
||||
void update_compatible_with_printer(const Preset &active_printer, bool select_other_if_incompatible)
|
||||
{ this->update_compatible_with_printer(active_printer, select_other_if_incompatible, [](const std::string&){return true;}); }
|
||||
|
||||
size_t num_visible() const { return std::count_if(m_presets.begin(), m_presets.end(), [](const Preset &preset){return preset.is_visible;}); }
|
||||
|
||||
|
@ -292,6 +323,11 @@ public:
|
|||
// Generate a file path from a profile name. Add the ".ini" suffix if it is missing.
|
||||
std::string path_from_name(const std::string &new_name) const;
|
||||
|
||||
protected:
|
||||
// Select a preset, if it exists. If it does not exist, select an invalid (-1) index.
|
||||
// This is a temporary state, which shall be fixed immediately by the following step.
|
||||
bool select_preset_by_name_strict(const std::string &name);
|
||||
|
||||
private:
|
||||
PresetCollection();
|
||||
PresetCollection(const PresetCollection &other);
|
||||
|
@ -309,6 +345,8 @@ private:
|
|||
std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const
|
||||
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
|
||||
|
||||
size_t update_compatible_with_printer_internal(const Preset &active_printer, bool unselect_if_incompatible);
|
||||
|
||||
static std::vector<std::string> dirty_options(const Preset *edited, const Preset *reference);
|
||||
|
||||
// Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER.
|
||||
|
@ -334,6 +372,9 @@ private:
|
|||
wxBitmap *m_bitmap_main_frame;
|
||||
// Path to the directory to store the config files into.
|
||||
std::string m_dir_path;
|
||||
|
||||
// to access select_preset_by_name_strict()
|
||||
friend class PresetBundle;
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -209,22 +209,34 @@ void PresetBundle::load_installed_printers(const AppConfig &config)
|
|||
// This is done just once on application start up.
|
||||
void PresetBundle::load_selections(const AppConfig &config)
|
||||
{
|
||||
prints.select_preset_by_name(remove_ini_suffix(config.get("presets", "print")), true);
|
||||
filaments.select_preset_by_name(remove_ini_suffix(config.get("presets", "filament")), true);
|
||||
printers.select_preset_by_name(remove_ini_suffix(config.get("presets", "printer")), true);
|
||||
// Update visibility of presets based on application vendor / model / variant configuration.
|
||||
this->load_installed_printers(config);
|
||||
|
||||
// Parse the initial print / filament / printer profile names.
|
||||
std::string initial_print_profile_name = remove_ini_suffix(config.get("presets", "print"));
|
||||
std::vector<std::string> initial_filament_profile_names;
|
||||
std::string initial_printer_profile_name = remove_ini_suffix(config.get("presets", "printer"));
|
||||
|
||||
auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(printers.get_selected_preset().config.option("nozzle_diameter"));
|
||||
size_t num_extruders = nozzle_diameter->values.size();
|
||||
this->set_filament_preset(0, filaments.get_selected_preset().name);
|
||||
initial_filament_profile_names.emplace_back(remove_ini_suffix(config.get("presets", "filament")));
|
||||
this->set_filament_preset(0, initial_filament_profile_names.back());
|
||||
for (unsigned int i = 1; i < (unsigned int)num_extruders; ++ i) {
|
||||
char name[64];
|
||||
sprintf(name, "filament_%d", i);
|
||||
if (! config.has("presets", name))
|
||||
break;
|
||||
this->set_filament_preset(i, remove_ini_suffix(config.get("presets", name)));
|
||||
initial_filament_profile_names.emplace_back(remove_ini_suffix(config.get("presets", name)));
|
||||
this->set_filament_preset(i, initial_filament_profile_names.back());
|
||||
}
|
||||
|
||||
// Update visibility of presets based on application vendor / model / variant configuration.
|
||||
this->load_installed_printers(config);
|
||||
// Activate print / filament / printer profiles from the config.
|
||||
// If the printer profile enumerated by the config are not visible, select an alternate preset.
|
||||
// Do not select alternate profiles for the print / filament profiles as those presets
|
||||
// will be selected by the following call of this->update_compatible_with_printer(true).
|
||||
prints.select_preset_by_name_strict(initial_print_profile_name);
|
||||
filaments.select_preset_by_name_strict(initial_filament_profile_names.front());
|
||||
printers.select_preset_by_name(initial_printer_profile_name, true);
|
||||
|
||||
// Update visibility of presets based on their compatibility with the active printer.
|
||||
// Always try to select a compatible print and filament preset to the current printer preset,
|
||||
|
@ -860,14 +872,35 @@ void PresetBundle::update_multi_material_filament_presets()
|
|||
|
||||
void PresetBundle::update_compatible_with_printer(bool select_other_if_incompatible)
|
||||
{
|
||||
this->prints.update_compatible_with_printer(this->printers.get_edited_preset(), select_other_if_incompatible);
|
||||
this->filaments.update_compatible_with_printer(this->printers.get_edited_preset(), select_other_if_incompatible);
|
||||
const Preset &printer_preset = this->printers.get_edited_preset();
|
||||
const std::string &prefered_print_profile = printer_preset.config.opt_string("default_print_profile");
|
||||
const std::vector<std::string> &prefered_filament_profiles = printer_preset.config.option<ConfigOptionStrings>("default_filament_profile")->values;
|
||||
prefered_print_profile.empty() ?
|
||||
this->prints.update_compatible_with_printer(printer_preset, select_other_if_incompatible) :
|
||||
this->prints.update_compatible_with_printer(printer_preset, select_other_if_incompatible,
|
||||
[&prefered_print_profile](const std::string& profile_name){ return profile_name == prefered_print_profile; });
|
||||
prefered_filament_profiles.empty() ?
|
||||
this->filaments.update_compatible_with_printer(printer_preset, select_other_if_incompatible) :
|
||||
this->filaments.update_compatible_with_printer(printer_preset, select_other_if_incompatible,
|
||||
[&prefered_filament_profiles](const std::string& profile_name)
|
||||
{ return std::find(prefered_filament_profiles.begin(), prefered_filament_profiles.end(), profile_name) != prefered_filament_profiles.end(); });
|
||||
if (select_other_if_incompatible) {
|
||||
// Verify validity of the current filament presets.
|
||||
for (std::string &filament_name : this->filament_presets) {
|
||||
Preset *preset = this->filaments.find_preset(filament_name, false);
|
||||
if (preset == nullptr || ! preset->is_compatible)
|
||||
filament_name = this->filaments.first_compatible().name;
|
||||
this->filament_presets.front() = this->filaments.get_edited_preset().name;
|
||||
for (size_t idx = 1; idx < this->filament_presets.size(); ++ idx) {
|
||||
std::string &filament_name = this->filament_presets[idx];
|
||||
Preset *preset = this->filaments.find_preset(filament_name, false);
|
||||
if (preset == nullptr || ! preset->is_compatible) {
|
||||
// Pick a compatible profile. If there are prefered_filament_profiles, use them.
|
||||
if (prefered_filament_profiles.empty())
|
||||
filament_name = this->filaments.first_compatible().name;
|
||||
else {
|
||||
const std::string &preferred = (idx < prefered_filament_profiles.size()) ?
|
||||
prefered_filament_profiles[idx] : prefered_filament_profiles.front();
|
||||
filament_name = this->filaments.first_compatible(
|
||||
[&preferred](const std::string& profile_name){ return profile_name == preferred; }).name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -540,7 +540,8 @@ void Tab::load_key_value(std::string opt_key, boost::any value)
|
|||
change_opt_value(*m_config, opt_key, value);
|
||||
// Mark the print & filament enabled if they are compatible with the currently selected preset.
|
||||
if (opt_key.compare("compatible_printers") == 0) {
|
||||
m_preset_bundle->update_compatible_with_printer(0);
|
||||
// Don't select another profile if this profile happens to become incompatible.
|
||||
m_preset_bundle->update_compatible_with_printer(false);
|
||||
}
|
||||
m_presets->update_dirty_ui(m_presets_choice);
|
||||
on_presets_changed();
|
||||
|
@ -1772,7 +1773,7 @@ void Tab::rebuild_page_tree()
|
|||
// Called by the UI combo box when the user switches profiles.
|
||||
// Select a preset by a name.If !defined(name), then the default preset is selected.
|
||||
// If the current profile is modified, user is asked to save the changes.
|
||||
void Tab::select_preset(std::string preset_name /*= ""*/)
|
||||
void Tab::select_preset(const std::string &preset_name /*= ""*/)
|
||||
{
|
||||
std::string name = preset_name;
|
||||
auto force = false;
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
void create_preset_tab(PresetBundle *preset_bundle);
|
||||
void load_current_preset();
|
||||
void rebuild_page_tree();
|
||||
void select_preset(std::string preset_name = "");
|
||||
void select_preset(const std::string &preset_name = "");
|
||||
bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, std::string new_printer_name = "");
|
||||
wxSizer* compatible_printers_widget(wxWindow* parent, wxCheckBox** checkbox, wxButton** btn);
|
||||
|
||||
|
|
|
@ -76,6 +76,13 @@ public:
|
|||
|
||||
~Semver() { ::semver_free(&ver); }
|
||||
|
||||
// const accessors
|
||||
int major() const { return ver.major; }
|
||||
int minor() const { return ver.minor; }
|
||||
int patch() const { return ver.patch; }
|
||||
const char* prerelease() const { return ver.prerelease; }
|
||||
const char* metadata() const { return ver.metadata; }
|
||||
|
||||
// Comparison
|
||||
bool operator<(const Semver &b) const { return ::semver_compare(ver, b.ver) == -1; }
|
||||
bool operator<=(const Semver &b) const { return ::semver_compare(ver, b.ver) <= 0; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue