Corrected initialization of the SLA presets with their default values.

This commit is contained in:
bubnikv 2018-08-03 14:14:25 +02:00
parent 884f1ff4c0
commit f65aadebef
3 changed files with 17 additions and 21 deletions

View File

@ -209,12 +209,9 @@ void Preset::normalize(DynamicPrintConfig &config)
} }
} }
// Load a config file, return a C++ class Slic3r::DynamicPrintConfig with $keys initialized from the config file. DynamicPrintConfig& Preset::load(const std::vector<std::string> &keys, const StaticPrintConfig &defaults)
// In case of a "default" config item, return the default values.
DynamicPrintConfig& Preset::load(const std::vector<std::string> &keys)
{ {
// Set the configuration from the defaults. // Set the configuration from the defaults.
Slic3r::FullPrintConfig defaults;
this->config.apply_only(defaults, keys.empty() ? defaults.keys() : keys); this->config.apply_only(defaults, keys.empty() ? defaults.keys() : keys);
if (! this->is_default) { if (! this->is_default) {
// Load the preset file, apply preset values on top of defaults. // Load the preset file, apply preset values on top of defaults.
@ -396,7 +393,7 @@ const std::vector<std::string>& Preset::sla_material_options()
return s_opts; return s_opts;
} }
PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const std::string &default_name) : PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name) :
m_type(type), m_type(type),
m_edited_preset(type, "", false), m_edited_preset(type, "", false),
m_idx_selected(0), m_idx_selected(0),
@ -404,8 +401,7 @@ PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::str
m_bitmap_cache(new GUI::BitmapCache) m_bitmap_cache(new GUI::BitmapCache)
{ {
// Insert just the default preset. // Insert just the default preset.
this->add_default_preset(keys, default_name); this->add_default_preset(keys, defaults, default_name);
m_presets.front().load(keys);
m_edited_preset.config.apply(m_presets.front().config); m_edited_preset.config.apply(m_presets.front().config);
} }
@ -432,11 +428,11 @@ void PresetCollection::reset(bool delete_files)
} }
} }
void PresetCollection::add_default_preset(const std::vector<std::string> &keys, const std::string &preset_name) void PresetCollection::add_default_preset(const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name)
{ {
// Insert just the default preset. // Insert just the default preset.
m_presets.emplace_back(Preset(this->type(), preset_name, true)); m_presets.emplace_back(Preset(this->type(), preset_name, true));
m_presets.back().load(keys); m_presets.back().load(keys, defaults);
++ m_num_default_presets; ++ m_num_default_presets;
} }
@ -462,7 +458,8 @@ void PresetCollection::load_presets(const std::string &dir_path, const std::stri
try { try {
Preset preset(m_type, name, false); Preset preset(m_type, name, false);
preset.file = dir_entry.path().string(); preset.file = dir_entry.path().string();
preset.load(keys); //FIXME One should initialize with SLAFullPrintConfig for the SLA profiles!
preset.load(keys, static_cast<const HostConfig&>(FullPrintConfig::defaults()));
m_presets.emplace_back(preset); m_presets.emplace_back(preset);
} catch (const std::runtime_error &err) { } catch (const std::runtime_error &err) {
errors_cummulative += err.what(); errors_cummulative += err.what();

View File

@ -125,8 +125,7 @@ public:
DynamicPrintConfig config; DynamicPrintConfig config;
// Load this profile for the following keys only. // Load this profile for the following keys only.
// Throws std::runtime_error in case the file cannot be read. DynamicPrintConfig& load(const std::vector<std::string> &keys, const StaticPrintConfig &defaults);
DynamicPrintConfig& load(const std::vector<std::string> &keys);
void save(); void save();
@ -194,7 +193,7 @@ class PresetCollection
{ {
public: public:
// Initialize the PresetCollection with the "- default -" preset. // Initialize the PresetCollection with the "- default -" preset.
PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const std::string &default_name = "- default -"); PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name = "- default -");
~PresetCollection(); ~PresetCollection();
typedef std::deque<Preset>::iterator Iterator; typedef std::deque<Preset>::iterator Iterator;
@ -211,7 +210,7 @@ public:
const std::deque<Preset>& operator()() const { return m_presets; } const std::deque<Preset>& operator()() const { return m_presets; }
// Add default preset at the start of the collection, increment the m_default_preset counter. // Add default preset at the start of the collection, increment the m_default_preset counter.
void add_default_preset(const std::vector<std::string> &keys, const std::string &preset_name); void add_default_preset(const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name);
// Load ini files of the particular type from the provided directory path. // Load ini files of the particular type from the provided directory path.
void load_presets(const std::string &dir_path, const std::string &subdir); void load_presets(const std::string &dir_path, const std::string &subdir);

View File

@ -40,10 +40,10 @@ static std::vector<std::string> s_project_options {
}; };
PresetBundle::PresetBundle() : PresetBundle::PresetBundle() :
prints(Preset::TYPE_PRINT, Preset::print_options()), prints(Preset::TYPE_PRINT, Preset::print_options(), static_cast<const HostConfig&>(FullPrintConfig::defaults())),
filaments(Preset::TYPE_FILAMENT, Preset::filament_options()), filaments(Preset::TYPE_FILAMENT, Preset::filament_options(), static_cast<const HostConfig&>(FullPrintConfig::defaults())),
sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options()), sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options(), static_cast<const SLAMaterialConfig&>(SLAFullPrintConfig::defaults())),
printers(Preset::TYPE_PRINTER, Preset::printer_options(), "- default FFF -"), printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast<const HostConfig&>(FullPrintConfig::defaults()), "- default FFF -"),
m_bitmapCompatible(new wxBitmap), m_bitmapCompatible(new wxBitmap),
m_bitmapIncompatible(new wxBitmap), m_bitmapIncompatible(new wxBitmap),
m_bitmapLock(new wxBitmap), m_bitmapLock(new wxBitmap),
@ -74,7 +74,7 @@ PresetBundle::PresetBundle() :
this->sla_materials.default_preset().compatible_printers_condition(); this->sla_materials.default_preset().compatible_printers_condition();
this->sla_materials.default_preset().inherits(); this->sla_materials.default_preset().inherits();
this->printers.add_default_preset(Preset::sla_printer_options(), "- default SLA -"); this->printers.add_default_preset(Preset::sla_printer_options(), static_cast<const SLAMaterialConfig&>(SLAFullPrintConfig::defaults()), "- default SLA -");
this->printers.preset(1).printer_technology() = ptSLA; this->printers.preset(1).printer_technology() = ptSLA;
for (size_t i = 0; i < 2; ++ i) { for (size_t i = 0; i < 2; ++ i) {
Preset &preset = this->printers.preset(i); Preset &preset = this->printers.preset(i);
@ -419,7 +419,7 @@ DynamicPrintConfig PresetBundle::full_config() const
DynamicPrintConfig PresetBundle::full_fff_config() const DynamicPrintConfig PresetBundle::full_fff_config() const
{ {
DynamicPrintConfig out; DynamicPrintConfig out;
out.apply(FullPrintConfig()); out.apply(FullPrintConfig::defaults());
out.apply(this->prints.get_edited_preset().config); out.apply(this->prints.get_edited_preset().config);
// Add the default filament preset to have the "filament_preset_id" defined. // Add the default filament preset to have the "filament_preset_id" defined.
out.apply(this->filaments.default_preset().config); out.apply(this->filaments.default_preset().config);
@ -514,7 +514,7 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
DynamicPrintConfig PresetBundle::full_sla_config() const DynamicPrintConfig PresetBundle::full_sla_config() const
{ {
DynamicPrintConfig out; DynamicPrintConfig out;
out.apply(SLAFullPrintConfig()); out.apply(SLAFullPrintConfig::defaults());
out.apply(this->sla_materials.get_edited_preset().config); out.apply(this->sla_materials.get_edited_preset().config);
out.apply(this->printers.get_edited_preset().config); out.apply(this->printers.get_edited_preset().config);
// There are no project configuration values as of now, the project_config is reserved for FFF printers. // There are no project configuration values as of now, the project_config is reserved for FFF printers.