Load default filament/material selections from vendor profiles
This commit is contained in:
parent
34b3548102
commit
87b7b1cc1d
6 changed files with 45 additions and 33 deletions
|
@ -28,6 +28,9 @@ static const std::string VENDOR_PREFIX = "vendor:";
|
|||
static const std::string MODEL_PREFIX = "model:";
|
||||
static const std::string VERSION_CHECK_URL = "https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/PrusaSlicer.version";
|
||||
|
||||
const std::string AppConfig::SECTION_FILAMENTS = "filaments";
|
||||
const std::string AppConfig::SECTION_MATERIALS = "sla_materials";
|
||||
|
||||
void AppConfig::reset()
|
||||
{
|
||||
m_storage.clear();
|
||||
|
|
|
@ -131,6 +131,8 @@ public:
|
|||
std::vector<std::string> get_recent_projects() const;
|
||||
void set_recent_projects(const std::vector<std::string>& recent_projects);
|
||||
|
||||
static const std::string SECTION_FILAMENTS;
|
||||
static const std::string SECTION_MATERIALS;
|
||||
private:
|
||||
// Map of section, name -> value
|
||||
std::map<std::string, std::map<std::string, std::string>> m_storage;
|
||||
|
|
|
@ -1049,12 +1049,10 @@ void ConfigWizardIndex::msw_rescale()
|
|||
// Materials
|
||||
|
||||
const std::string Materials::UNKNOWN = "(Unknown)";
|
||||
const std::string Materials::SECTION_FILAMENTS = "filaments";
|
||||
const std::string Materials::SECTION_MATERIALS = "sla_materials";
|
||||
|
||||
const std::string& Materials::appconfig_section() const
|
||||
{
|
||||
return (technology & T_FFF) ? SECTION_FILAMENTS : SECTION_MATERIALS;
|
||||
return (technology & T_FFF) ? AppConfig::SECTION_FILAMENTS : AppConfig::SECTION_MATERIALS;
|
||||
}
|
||||
|
||||
const std::string& Materials::get_type(Preset &preset) const
|
||||
|
@ -1236,7 +1234,7 @@ void ConfigWizard::priv::load_vendors()
|
|||
}
|
||||
|
||||
// Load up the set of vendors / models / variants the user has had enabled up till now
|
||||
const AppConfig *app_config = GUI::get_app_config();
|
||||
AppConfig *app_config = GUI::get_app_config();
|
||||
if (! app_config->legacy_datadir()) {
|
||||
appconfig_new.set_vendors(*app_config);
|
||||
} else {
|
||||
|
@ -1253,27 +1251,13 @@ void ConfigWizard::priv::load_vendors()
|
|||
}
|
||||
}
|
||||
|
||||
// Load up the materials enabled till now
|
||||
if (app_config->has_section(Materials::SECTION_FILAMENTS)) {
|
||||
appconfig_new.set_section(Materials::SECTION_FILAMENTS, app_config->get_section(Materials::SECTION_FILAMENTS));
|
||||
} else {
|
||||
// No AppConfig settings, load up defaults from vendor section(s)
|
||||
for (const auto &vendor : bundle.vendors) {
|
||||
for (const auto &profile : vendor.default_filaments) {
|
||||
appconfig_new.set(Materials::SECTION_FILAMENTS, profile, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (app_config->has_section(Materials::SECTION_MATERIALS)) {
|
||||
appconfig_new.set_section(Materials::SECTION_MATERIALS, app_config->get_section(Materials::SECTION_MATERIALS));
|
||||
} else {
|
||||
// No AppConfig settings, load up defaults from vendor section(s)
|
||||
for (const auto &vendor : bundle.vendors) {
|
||||
for (const auto &profile : vendor.default_sla_materials) {
|
||||
appconfig_new.set(Materials::SECTION_MATERIALS, profile, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Load up the materials enabled till now,
|
||||
// apply defaults from vendor profiles if there are no selections yet.
|
||||
bundle.init_materials_selection(*app_config);
|
||||
wxCHECK_RET(app_config->has_section(AppConfig::SECTION_FILAMENTS) && app_config->has_section(AppConfig::SECTION_MATERIALS),
|
||||
"Failed to initialize default material selections");
|
||||
appconfig_new.set_section(AppConfig::SECTION_FILAMENTS, app_config->get_section(AppConfig::SECTION_FILAMENTS));
|
||||
appconfig_new.set_section(AppConfig::SECTION_MATERIALS, app_config->get_section(AppConfig::SECTION_MATERIALS));
|
||||
}
|
||||
|
||||
void ConfigWizard::priv::add_page(ConfigWizardPage *page)
|
||||
|
@ -1361,11 +1345,11 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
}
|
||||
|
||||
app_config->set_vendors(appconfig_new);
|
||||
if (appconfig_new.has_section(Materials::SECTION_FILAMENTS)) {
|
||||
app_config->set_section(Materials::SECTION_FILAMENTS, appconfig_new.get_section(Materials::SECTION_FILAMENTS));
|
||||
if (appconfig_new.has_section(AppConfig::SECTION_FILAMENTS)) {
|
||||
app_config->set_section(AppConfig::SECTION_FILAMENTS, appconfig_new.get_section(AppConfig::SECTION_FILAMENTS));
|
||||
}
|
||||
if (appconfig_new.has_section(Materials::SECTION_MATERIALS)) {
|
||||
app_config->set_section(Materials::SECTION_MATERIALS, appconfig_new.get_section(Materials::SECTION_MATERIALS));
|
||||
if (appconfig_new.has_section(AppConfig::SECTION_MATERIALS)) {
|
||||
app_config->set_section(AppConfig::SECTION_MATERIALS, appconfig_new.get_section(AppConfig::SECTION_MATERIALS));
|
||||
}
|
||||
app_config->set("version_check", page_update->version_check ? "1" : "0");
|
||||
app_config->set("preset_update", page_update->preset_update ? "1" : "0");
|
||||
|
|
|
@ -152,8 +152,6 @@ struct Materials
|
|||
}
|
||||
|
||||
static const std::string UNKNOWN;
|
||||
static const std::string SECTION_FILAMENTS;
|
||||
static const std::string SECTION_MATERIALS;
|
||||
static const std::string& get_filament_type(const Preset &preset);
|
||||
static const std::string& get_filament_vendor(const Preset &preset);
|
||||
static const std::string& get_material_type(Preset &preset);
|
||||
|
|
|
@ -194,7 +194,7 @@ void PresetBundle::setup_directories()
|
|||
}
|
||||
}
|
||||
|
||||
void PresetBundle::load_presets(const AppConfig &config, const std::string &preferred_model_id)
|
||||
void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_model_id)
|
||||
{
|
||||
// First load the vendor specific system presets.
|
||||
std::string errors_cummulative = this->load_system_presets();
|
||||
|
@ -237,6 +237,10 @@ void PresetBundle::load_presets(const AppConfig &config, const std::string &pref
|
|||
if (! errors_cummulative.empty())
|
||||
throw std::runtime_error(errors_cummulative);
|
||||
|
||||
// Make sure there are filament / material selections in the AppConfig,
|
||||
// if there are none, load up defaults from vendor profiles.
|
||||
this->init_materials_selection(config);
|
||||
|
||||
this->load_selections(config, preferred_model_id);
|
||||
}
|
||||
|
||||
|
@ -407,6 +411,23 @@ void PresetBundle::export_selections(AppConfig &config)
|
|||
config.set("presets", "printer", printers.get_selected_preset_name());
|
||||
}
|
||||
|
||||
void PresetBundle::init_materials_selection(AppConfig &config) const {
|
||||
if (! config.has_section(AppConfig::SECTION_FILAMENTS)) {
|
||||
for (const auto &vendor : this->vendors) {
|
||||
for (const auto &profile : vendor.default_filaments) {
|
||||
config.set(AppConfig::SECTION_FILAMENTS, profile, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (! config.has_section(AppConfig::SECTION_MATERIALS)) {
|
||||
for (const auto &vendor : this->vendors) {
|
||||
for (const auto &profile : vendor.default_sla_materials) {
|
||||
config.set(AppConfig::SECTION_MATERIALS, profile, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PresetBundle::load_compatible_bitmaps(wxWindow *window)
|
||||
{
|
||||
// We don't actually pass the window pointer here and instead generate
|
||||
|
|
|
@ -31,11 +31,15 @@ public:
|
|||
// Load ini files of all types (print, filament, printer) from Slic3r::data_dir() / presets.
|
||||
// Load selections (current print, current filaments, current printer) from config.ini
|
||||
// This is done just once on application start up.
|
||||
void load_presets(const AppConfig &config, const std::string &preferred_model_id = "");
|
||||
void load_presets(AppConfig &config, const std::string &preferred_model_id = "");
|
||||
|
||||
// Export selections (current print, current filaments, current printer) into config.ini
|
||||
void export_selections(AppConfig &config);
|
||||
|
||||
// Make sure filament and sla_materials section in AppConfig are initialized
|
||||
// to defaults from vendor profiles if they don't exist already
|
||||
void init_materials_selection(AppConfig &config) const;
|
||||
|
||||
PresetCollection prints;
|
||||
PresetCollection sla_prints;
|
||||
PresetCollection filaments;
|
||||
|
|
Loading…
Reference in a new issue