Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::PresetBundle Class Reference

#include <src/libslic3r/PresetBundle.hpp>

+ Collaboration diagram for Slic3r::PresetBundle:

Classes

struct  ObsoletePresets
 
struct  PresetPreferences
 

Public Types

enum  LoadConfigBundleAttribute { SaveImported , ResetUserProfile , LoadSystem , LoadVendorOnly }
 
using LoadConfigBundleAttributes = enum_bitmask< LoadConfigBundleAttribute >
 

Public Member Functions

 PresetBundle ()
 
 PresetBundle (const PresetBundle &rhs)
 
PresetBundleoperator= (const PresetBundle &rhs)
 
void reset (bool delete_files)
 
void setup_directories ()
 
void import_newer_configs (const std::string &from)
 
PresetsConfigSubstitutions load_presets (AppConfig &config, ForwardCompatibilitySubstitutionRule rule, const PresetPreferences &preferred_selection=PresetPreferences())
 
void export_selections (AppConfig &config)
 
PresetCollectionmaterials (PrinterTechnology pt)
 
const PresetCollectionmaterials (PrinterTechnology pt) const
 
void cache_extruder_filaments_names ()
 
void reset_extruder_filaments ()
 
PresetCollectionget_presets (Preset::Type preset_type)
 
bool has_defauls_only () const
 
DynamicPrintConfig full_config () const
 
DynamicPrintConfig full_config_secure () const
 
void load_config_from_wizard (const std::string &name, DynamicPrintConfig config)
 
void load_config_model (const std::string &name, DynamicPrintConfig config)
 
ConfigSubstitutions load_config_file (const std::string &path, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
std::pair< PresetsConfigSubstitutions, size_t > load_configbundle (const std::string &path, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
void export_configbundle (const std::string &path, bool export_system_settings=false, bool export_physical_printers=false)
 
void set_default_suppressed (bool default_suppressed)
 
void set_filament_preset (size_t idx, const std::string &name)
 
void update_multi_material_filament_presets ()
 
void update_filaments_compatible (PresetSelectCompatibleType select_other_filament_if_incompatible, int extruder_idx=-1)
 
void update_compatible (PresetSelectCompatibleType select_other_print_if_incompatible, PresetSelectCompatibleType select_other_filament_if_incompatible)
 
void update_compatible (PresetSelectCompatibleType select_other_if_incompatible)
 
void load_installed_printers (const AppConfig &config)
 
const std::string & get_preset_name_by_alias (const Preset::Type &preset_type, const std::string &alias, int extruder_id=-1)
 
void save_changes_for_preset (const std::string &new_name, Preset::Type type, const std::vector< std::string > &unselected_options)
 
bool transfer_and_save (Preset::Type type, const std::string &preset_from_name, const std::string &preset_to_name, const std::string &new_name, const std::vector< std::string > &options)
 

Static Public Member Functions

static std::array< Preset::Type, 3 > types_list (PrinterTechnology pt)
 

Public Attributes

PresetCollection prints
 
PresetCollection sla_prints
 
PresetCollection filaments
 
PresetCollection sla_materials
 
PrinterPresetCollection printers
 
PhysicalPrinterCollection physical_printers
 
std::vector< ExtruderFilamentsextruders_filaments
 
DynamicPrintConfig project_config
 
VendorMap vendors
 
ObsoletePresets obsolete_presets
 

Static Public Attributes

static const char * PRUSA_BUNDLE = "PrusaResearch"
 

Private Member Functions

std::pair< PresetsConfigSubstitutions, std::string > load_system_presets (ForwardCompatibilitySubstitutionRule compatibility_rule)
 
std::vector< std::string > merge_presets (PresetBundle &&other)
 
void update_system_maps ()
 
void load_installed_filaments (AppConfig &config)
 
void load_installed_sla_materials (AppConfig &config)
 
void load_selections (AppConfig &config, const PresetPreferences &preferred_selection=PresetPreferences())
 
void load_config_file_config (const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config)
 
ConfigSubstitutions load_config_file_config_bundle (const std::string &path, const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule)
 
DynamicPrintConfig full_fff_config () const
 
DynamicPrintConfig full_sla_config () const
 

Detailed Description


Class Documentation

◆ Slic3r::PresetBundle::ObsoletePresets

struct Slic3r::PresetBundle::ObsoletePresets
+ Collaboration diagram for Slic3r::PresetBundle::ObsoletePresets:
Class Members
vector< string > filaments
vector< string > printers
vector< string > prints
vector< string > sla_materials
vector< string > sla_prints

◆ Slic3r::PresetBundle::PresetPreferences

struct Slic3r::PresetBundle::PresetPreferences
+ Collaboration diagram for Slic3r::PresetBundle::PresetPreferences:
Class Members
string filament
string printer_model_id
string printer_variant
string sla_material

Member Typedef Documentation

◆ LoadConfigBundleAttributes

Member Enumeration Documentation

◆ LoadConfigBundleAttribute

Enumerator
SaveImported 
ResetUserProfile 
LoadSystem 
LoadVendorOnly 
109 {
110 // Save the profiles, which have been loaded.
112 // Delete all old config profiles before loading.
114 // Load a system config bundle.
117 };
@ ResetUserProfile
Definition PresetBundle.hpp:113
@ LoadSystem
Definition PresetBundle.hpp:115
@ LoadVendorOnly
Definition PresetBundle.hpp:116
@ SaveImported
Definition PresetBundle.hpp:111

Constructor & Destructor Documentation

◆ PresetBundle() [1/2]

Slic3r::PresetBundle::PresetBundle ( )
40 :
41 prints(Preset::TYPE_PRINT, Preset::print_options(), static_cast<const PrintRegionConfig&>(FullPrintConfig::defaults())),
42 filaments(Preset::TYPE_FILAMENT, Preset::filament_options(), static_cast<const PrintRegionConfig&>(FullPrintConfig::defaults())),
43 sla_materials(Preset::TYPE_SLA_MATERIAL, Preset::sla_material_options(), static_cast<const SLAMaterialConfig&>(SLAFullPrintConfig::defaults())),
44 sla_prints(Preset::TYPE_SLA_PRINT, Preset::sla_print_options(), static_cast<const SLAPrintObjectConfig&>(SLAFullPrintConfig::defaults())),
45 printers(Preset::TYPE_PRINTER, Preset::printer_options(), static_cast<const PrintRegionConfig&>(FullPrintConfig::defaults()), "- default FFF -"),
47{
48 // The following keys are handled by the UI, they do not have a counterpart in any StaticPrintConfig derived classes,
49 // therefore they need to be handled differently. As they have no counterpart in StaticPrintConfig, they are not being
50 // initialized based on PrintConfigDef(), but to empty values (zeros, empty vectors, empty strings).
51 //
52 // "compatible_printers", "compatible_printers_condition", "inherits",
53 // "print_settings_id", "filament_settings_id", "printer_settings_id", "printer_settings_id"
54 // "printer_vendor", "printer_model", "printer_variant", "default_print_profile", "default_filament_profile"
55
56 // Create the ID config keys, as they are not part of the Static print config classes.
57 this->prints.default_preset().config.optptr("print_settings_id", true);
60
61 this->filaments.default_preset().config.option<ConfigOptionStrings>("filament_settings_id", true)->values = { "" };
64 // Set all the nullable values to nils.
66
67 this->sla_materials.default_preset().config.optptr("sla_material_settings_id", true);
70
71 this->sla_prints.default_preset().config.optptr("sla_print_settings_id", true);
72 this->sla_prints.default_preset().config.opt_string("output_filename_format", true) = "[input_filename_base].sl1";
75
76 this->printers.add_default_preset(Preset::sla_printer_options(), static_cast<const SLAMaterialConfig&>(SLAFullPrintConfig::defaults()), "- default SLA -");
78 for (size_t i = 0; i < 2; ++ i) {
79 // The following ugly switch is to avoid printers.preset(0) to return the edited instance, as the 0th default is the current one.
80 Preset &preset = this->printers.default_preset(i);
81 for (const char *key : {
82 "printer_settings_id", "printer_vendor", "printer_model", "printer_variant", "thumbnails",
83 //FIXME the following keys are only created here for compatibility to be able to parse legacy Printer profiles.
84 // These keys are converted to Physical Printer profile. After the conversion, they shall be removed.
85 "host_type", "print_host", "printhost_apikey", "printhost_cafile"})
86 preset.config.optptr(key, true);
87 if (i == 0) {
88 preset.config.optptr("default_print_profile", true);
89 preset.config.option<ConfigOptionStrings>("default_filament_profile", true);
90 } else {
91 preset.config.optptr("default_sla_print_profile", true);
92 preset.config.optptr("default_sla_material_profile", true);
93 }
94 // default_sla_material_profile
95 preset.inherits();
96 }
97
98 // Re-activate the default presets, so their "edited" preset copies will be updated with the additional configuration values above.
99 this->prints .select_preset(0);
100 this->sla_prints .select_preset(0);
101 this->filaments .select_preset(0);
103 this->printers .select_preset(0);
104
105 this->project_config.apply_only(FullPrintConfig::defaults(), s_project_options);
106}
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2169
void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent=false)
Definition Config.cpp:466
std::string & opt_string(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2276
void null_nullables()
Definition Config.cpp:1041
const ConfigOption * optptr(const t_config_option_key &opt_key) const override
Definition Config.cpp:1106
static const std::vector< std::string > & printer_options()
Definition Preset.cpp:1586
PresetCollection sla_prints
Definition PresetBundle.hpp:47
PrinterPresetCollection printers
Definition PresetBundle.hpp:52
DynamicPrintConfig project_config
Definition PresetBundle.hpp:66
PresetCollection sla_materials
Definition PresetBundle.hpp:49
PresetCollection prints
Definition PresetBundle.hpp:46
PresetCollection filaments
Definition PresetBundle.hpp:48
PhysicalPrinterCollection physical_printers
Definition PresetBundle.hpp:53
Preset & select_preset(size_t idx)
Definition Preset.cpp:1369
void add_default_preset(const std::vector< std::string > &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name)
Definition Preset.cpp:669
Preset & preset(size_t idx, bool respect_active_preset=true)
Definition Preset.hpp:402
Preset & default_preset(size_t idx=0)
Definition Preset.hpp:398
static const std::vector< std::string > & sla_printer_options()
Definition Preset.cpp:627
static std::string & inherits(DynamicPrintConfig &cfg)
Definition Preset.hpp:179
static const std::vector< std::string > & sla_material_options()
Definition Preset.cpp:626
DynamicPrintConfig config
Definition Preset.hpp:159
static std::string & compatible_printers_condition(DynamicPrintConfig &cfg)
Definition Preset.hpp:192
static const std::vector< std::string > & print_options()
Definition Preset.cpp:619
PrinterTechnology & printer_technology_ref()
Definition Preset.hpp:209
static const std::vector< std::string > & printer_options()
Definition Preset.cpp:629
static const std::vector< std::string > & filament_options()
Definition Preset.cpp:620
@ TYPE_SLA_PRINT
Definition Preset.hpp:113
@ TYPE_PRINTER
Definition Preset.hpp:116
@ TYPE_PRINT
Definition Preset.hpp:112
@ TYPE_SLA_MATERIAL
Definition Preset.hpp:115
@ TYPE_FILAMENT
Definition Preset.hpp:114
static const std::vector< std::string > & sla_print_options()
Definition Preset.cpp:625
@ ptSLA
Definition Config.hpp:209
PrintRegionConfig
Definition PrintConfig.hpp:840
SLAPrintObjectConfig
Definition PrintConfig.hpp:1111
static std::vector< std::string > s_project_options
Definition PresetBundle.cpp:32

References Slic3r::PresetCollection::add_default_preset(), Slic3r::ConfigBase::apply_only(), Slic3r::Preset::compatible_printers_condition(), Slic3r::Preset::config, Slic3r::PresetCollection::default_preset(), filaments, Slic3r::Preset::inherits(), Slic3r::ConfigBase::null_nullables(), Slic3r::ConfigBase::opt_string(), Slic3r::ConfigBase::option(), Slic3r::DynamicConfig::optptr(), Slic3r::PresetCollection::preset(), Slic3r::Preset::printer_technology_ref(), printers, prints, project_config, Slic3r::ptSLA, Slic3r::s_project_options, Slic3r::PresetCollection::select_preset(), sla_materials, Slic3r::Preset::sla_printer_options(), and sla_prints.

+ Here is the call graph for this function:

◆ PresetBundle() [2/2]

Slic3r::PresetBundle::PresetBundle ( const PresetBundle rhs)
109{
110 *this = rhs;
111}

Member Function Documentation

◆ cache_extruder_filaments_names()

void Slic3r::PresetBundle::cache_extruder_filaments_names ( )
429{
430 for (ExtruderFilaments& extr_filaments : extruders_filaments)
431 extr_filaments.cache_selected_name();
432}
std::vector< ExtruderFilaments > extruders_filaments
Definition PresetBundle.hpp:57

References extruders_filaments.

Referenced by save_changes_for_preset().

+ Here is the caller graph for this function:

◆ export_configbundle()

void Slic3r::PresetBundle::export_configbundle ( const std::string &  path,
bool  export_system_settings = false,
bool  export_physical_printers = false 
)
1895{
1896 boost::nowide::ofstream c;
1897 c.open(path, std::ios::out | std::ios::trunc);
1898
1899 // Put a comment at the first line including the time stamp and Slic3r version.
1900 c << "# " << Slic3r::header_slic3r_generated() << std::endl;
1901
1902 // Export the print, filament and printer profiles.
1903
1904 for (const PresetCollection *presets : {
1905 (const PresetCollection*)&this->prints, (const PresetCollection*)&this->filaments,
1906 (const PresetCollection*)&this->sla_prints, (const PresetCollection*)&this->sla_materials,
1907 (const PresetCollection*)&this->printers }) {
1908 for (const Preset &preset : (*presets)()) {
1909 if (preset.is_default || preset.is_external || (preset.is_system && ! export_system_settings))
1910 // Only export the common presets, not external files or the default preset.
1911 continue;
1912 c << std::endl << "[" << presets->section_name() << ":" << preset.name << "]" << std::endl;
1913 for (const std::string &opt_key : preset.config.keys())
1914 c << opt_key << " = " << preset.config.opt_serialize(opt_key) << std::endl;
1915 }
1916 }
1917
1918 if (export_physical_printers) {
1919 for (const PhysicalPrinter& ph_printer : this->physical_printers) {
1920 c << std::endl << "[physical_printer:" << ph_printer.name << "]" << std::endl;
1921 for (const std::string& opt_key : ph_printer.config.keys())
1922 c << opt_key << " = " << ph_printer.config.opt_serialize(opt_key) << std::endl;
1923 }
1924 }
1925
1926 // Export the names of the active presets.
1927 c << std::endl << "[presets]" << std::endl;
1928 c << "print = " << this->prints.get_selected_preset_name() << std::endl;
1929 c << "sla_print = " << this->sla_prints.get_selected_preset_name() << std::endl;
1930 c << "sla_material = " << this->sla_materials.get_selected_preset_name() << std::endl;
1931 c << "printer = " << this->printers.get_selected_preset_name() << std::endl;
1932 for (size_t i = 0; i < this->extruders_filaments.size(); ++ i) {
1933 char suffix[64];
1934 if (i > 0)
1935 sprintf(suffix, "_%d", (int)i);
1936 else
1937 suffix[0] = 0;
1938 c << "filament" << suffix << " = " << this->extruders_filaments[i].get_selected_preset_name() << std::endl;
1939 }
1940
1941 if (export_physical_printers && this->physical_printers.get_selected_idx() >= 0)
1942 c << "physical_printer = " << this->physical_printers.get_selected_printer_name() << std::endl;
1943#if 0
1944 // Export the following setting values from the provided setting repository.
1945 static const char *settings_keys[] = { "autocenter" };
1946 c << "[settings]" << std::endl;
1947 for (size_t i = 0; i < sizeof(settings_keys) / sizeof(settings_keys[0]); ++ i)
1948 c << settings_keys[i] << " = " << settings.serialize(settings_keys[i]) << std::endl;
1949#endif
1950
1951 c.close();
1952}
std::string get_selected_printer_name() const
Definition Preset.hpp:759
size_t get_selected_idx() const
Definition Preset.hpp:757
std::string get_selected_preset_name() const
Definition Preset.hpp:369
std::string header_slic3r_generated()
Definition utils.cpp:914
STL namespace.

References Slic3r::header_slic3r_generated().

+ Here is the call graph for this function:

◆ export_selections()

void Slic3r::PresetBundle::export_selections ( AppConfig config)
676{
677 assert(this->printers.get_edited_preset().printer_technology() != ptFFF || extruders_filaments.size() >= 1);
678 assert(this->printers.get_edited_preset().printer_technology() != ptFFF || extruders_filaments.size() > 1 || filaments.get_selected_preset().alias == extruders_filaments.front().get_selected_preset()->alias);
679 config.clear_section("presets");
680 config.set("presets", "print", prints.get_selected_preset_name());
681 config.set("presets", "filament", extruders_filaments.front().get_selected_preset_name());
682 for (unsigned i = 1; i < extruders_filaments.size(); ++i) {
683 char name[64];
684 sprintf(name, "filament_%u", i);
685 config.set("presets", name, extruders_filaments[i].get_selected_preset_name());
686 }
687
688 config.set("presets", "sla_print", sla_prints.get_selected_preset_name());
689 config.set("presets", "sla_material", sla_materials.get_selected_preset_name());
690 config.set("presets", "printer", printers.get_selected_preset_name());
691 config.set("presets", "physical_printer", physical_printers.get_selected_full_printer_name());
692}
std::string get_selected_full_printer_name() const
Definition Preset.cpp:2053
Preset & get_selected_preset()
Definition Preset.hpp:365
Preset & get_edited_preset()
Definition Preset.hpp:379
std::string alias
Definition Preset.hpp:162
static PrinterTechnology printer_technology(const DynamicPrintConfig &cfg)
Definition Preset.hpp:200
@ ptFFF
Definition Config.hpp:207

References Slic3r::Preset::alias, Slic3r::AppConfig::clear_section(), extruders_filaments, filaments, Slic3r::PresetCollection::get_edited_preset(), Slic3r::PhysicalPrinterCollection::get_selected_full_printer_name(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::PresetCollection::get_selected_preset_name(), physical_printers, Slic3r::Preset::printer_technology(), printers, prints, Slic3r::ptFFF, Slic3r::AppConfig::set(), sla_materials, and sla_prints.

Referenced by Slic3r::GUI::ConfigWizard::priv::apply_config(), Slic3r::GUI::GUI_App::check_and_keep_current_preset_changes(), Slic3r::GUI::GUI_App::check_and_save_current_preset_changes(), and Slic3r::GUI::PresetComboBox::selection_is_changed_according_to_physical_printers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ full_config()

DynamicPrintConfig Slic3r::PresetBundle::full_config ( ) const
695{
696 return (this->printers.get_edited_preset().printer_technology() == ptFFF) ?
697 this->full_fff_config() :
698 this->full_sla_config();
699}
DynamicPrintConfig full_fff_config() const
Definition PresetBundle.cpp:711
DynamicPrintConfig full_sla_config() const
Definition PresetBundle.cpp:820

References full_fff_config(), full_sla_config(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::Preset::printer_technology(), printers, and Slic3r::ptFFF.

Referenced by full_config_secure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ full_config_secure()

DynamicPrintConfig Slic3r::PresetBundle::full_config_secure ( ) const
702{
703 DynamicPrintConfig config = this->full_config();
704 //FIXME legacy, the keys should not be there after conversion to a Physical Printer profile.
705 config.erase("print_host");
706 config.erase("printhost_apikey");
707 config.erase("printhost_cafile");
708 return config;
709}
DynamicPrintConfig full_config() const
Definition PresetBundle.cpp:694

References Slic3r::DynamicConfig::erase(), and full_config().

+ Here is the call graph for this function:

◆ full_fff_config()

DynamicPrintConfig Slic3r::PresetBundle::full_fff_config ( ) const
private
712{
713 DynamicPrintConfig out;
714 out.apply(FullPrintConfig::defaults());
715 out.apply(this->prints.get_edited_preset().config);
716 // Add the default filament preset to have the "filament_preset_id" defined.
717 out.apply(this->filaments.default_preset().config);
718 out.apply(this->printers.get_edited_preset().config);
719 out.apply(this->project_config);
720
721 auto *nozzle_diameter = dynamic_cast<const ConfigOptionFloats*>(out.option("nozzle_diameter"));
722 size_t num_extruders = nozzle_diameter->values.size();
723 // Collect the "compatible_printers_condition" and "inherits" values over all presets (print, filaments, printers) into a single vector.
724 std::vector<std::string> compatible_printers_condition;
725 std::vector<std::string> compatible_prints_condition;
726 std::vector<std::string> inherits;
727 compatible_printers_condition.emplace_back(this->prints.get_edited_preset().compatible_printers_condition());
728 inherits .emplace_back(this->prints.get_edited_preset().inherits());
729
730 if (num_extruders <= 1) {
731 out.apply(this->filaments.get_edited_preset().config);
732 compatible_printers_condition.emplace_back(this->filaments.get_edited_preset().compatible_printers_condition());
733 compatible_prints_condition .emplace_back(this->filaments.get_edited_preset().compatible_prints_condition());
734 inherits .emplace_back(this->filaments.get_edited_preset().inherits());
735 } else {
736 // Retrieve filament presets and build a single config object for them.
737 // First collect the filament configurations based on the user selection of this->filament_presets.
738 // Here this->filaments.find_preset() and this->filaments.first_visible() return the edited copy of the preset if active.
739 std::vector<const DynamicPrintConfig*> filament_configs;
740 for (const auto& extr_filaments : this->extruders_filaments)
741 filament_configs.emplace_back(&this->filaments.find_preset(extr_filaments.get_selected_preset_name(), true)->config);
742 while (filament_configs.size() < num_extruders)
743 filament_configs.emplace_back(&this->filaments.first_visible().config);
744 for (const DynamicPrintConfig *cfg : filament_configs) {
745 // The compatible_prints/printers_condition() returns a reference to configuration key, which may not yet exist.
746 DynamicPrintConfig &cfg_rw = *const_cast<DynamicPrintConfig*>(cfg);
747 compatible_printers_condition.emplace_back(Preset::compatible_printers_condition(cfg_rw));
748 compatible_prints_condition .emplace_back(Preset::compatible_prints_condition(cfg_rw));
749 inherits .emplace_back(Preset::inherits(cfg_rw));
750 }
751 // Option values to set a ConfigOptionVector from.
752 std::vector<const ConfigOption*> filament_opts(num_extruders, nullptr);
753 // loop through options and apply them to the resulting config.
754 for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
755 if (key == "compatible_prints" || key == "compatible_printers")
756 continue;
757 // Get a destination option.
758 ConfigOption *opt_dst = out.option(key, false);
759 if (opt_dst->is_scalar()) {
760 // Get an option, do not create if it does not exist.
761 const ConfigOption *opt_src = filament_configs.front()->option(key);
762 if (opt_src != nullptr)
763 opt_dst->set(opt_src);
764 } else {
765 // Setting a vector value from all filament_configs.
766 for (size_t i = 0; i < filament_opts.size(); ++ i)
767 filament_opts[i] = filament_configs[i]->option(key);
768 static_cast<ConfigOptionVectorBase*>(opt_dst)->set(filament_opts);
769 }
770 }
771 }
772
773 // Don't store the "compatible_printers_condition" for the printer profile, there is none.
774 inherits.emplace_back(this->printers.get_edited_preset().inherits());
775
776 // These value types clash between the print and filament profiles. They should be renamed.
777 out.erase("compatible_prints");
778 out.erase("compatible_prints_condition");
779 out.erase("compatible_printers");
780 out.erase("compatible_printers_condition");
781 out.erase("inherits");
782
783 static const char *keys[] = { "perimeter", "infill", "solid_infill", "support_material", "support_material_interface" };
784 for (size_t i = 0; i < sizeof(keys) / sizeof(keys[0]); ++ i) {
785 std::string key = std::string(keys[i]) + "_extruder";
786 auto *opt = dynamic_cast<ConfigOptionInt*>(out.option(key, false));
787 assert(opt != nullptr);
788 opt->value = boost::algorithm::clamp<int>(opt->value, 0, int(num_extruders));
789 }
790
791 out.option<ConfigOptionString >("print_settings_id", true)->value = this->prints.get_selected_preset_name();
792 auto& filament_settings_id = out.option<ConfigOptionStrings>("filament_settings_id", true)->values;
793 filament_settings_id.clear();
794 for (const auto& extr_filaments : this->extruders_filaments)
795 filament_settings_id.emplace_back(extr_filaments.get_selected_preset_name());
796 out.option<ConfigOptionString >("printer_settings_id", true)->value = this->printers.get_selected_preset_name();
797 out.option<ConfigOptionString >("physical_printer_settings_id", true)->value = this->physical_printers.get_selected_printer_name();
798
799 // Serialize the collected "compatible_printers_condition" and "inherits" fields.
800 // There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored.
801 // The vector will not be stored if all fields are empty strings.
802 auto add_if_some_non_empty = [&out](std::vector<std::string> &&values, const std::string &key) {
803 bool nonempty = false;
804 for (const std::string &v : values)
805 if (! v.empty()) {
806 nonempty = true;
807 break;
808 }
809 if (nonempty)
810 out.set_key_value(key, new ConfigOptionStrings(std::move(values)));
811 };
812 add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_printers_condition_cummulative");
813 add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_prints_condition_cummulative");
814 add_if_some_non_empty(std::move(inherits), "inherits_cummulative");
815
816 out.option<ConfigOptionEnumGeneric>("printer_technology", true)->value = ptFFF;
817 return out;
818}
Preset & first_visible()
Definition Preset.hpp:451
std::string & inherits()
Definition Preset.hpp:180
std::string & compatible_prints_condition()
Definition Preset.hpp:185
std::string & compatible_printers_condition()
Definition Preset.hpp:193
static std::string & compatible_prints_condition(DynamicPrintConfig &cfg)
Definition Preset.hpp:184
Definition getopt.h:102
if(!(yy_init))
Definition lexer.c:1190
std::string t_config_option_key
Definition Config.hpp:76
ConfigOptionFloatsTempl< false > ConfigOptionFloats
Definition Config.hpp:716
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:229

References Slic3r::ConfigBase::apply(), Slic3r::ConfigOptionVector< T >::clear(), Slic3r::Preset::compatible_printers_condition(), Slic3r::Preset::compatible_printers_condition(), Slic3r::Preset::compatible_prints_condition(), Slic3r::Preset::compatible_prints_condition(), Slic3r::Preset::config, Slic3r::PresetCollection::default_preset(), Slic3r::DynamicConfig::erase(), extruders_filaments, filaments, Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::PhysicalPrinterCollection::get_selected_printer_name(), Slic3r::Preset::inherits(), Slic3r::Preset::inherits(), Slic3r::ConfigOption::is_scalar(), Slic3r::DynamicConfig::keys(), Slic3r::ConfigBase::option(), physical_printers, printers, prints, project_config, Slic3r::ptFFF, Slic3r::ConfigOption::set(), Slic3r::DynamicConfig::set_key_value(), and Slic3r::ConfigOptionVector< T >::values.

Referenced by full_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ full_sla_config()

DynamicPrintConfig Slic3r::PresetBundle::full_sla_config ( ) const
private
821{
822 DynamicPrintConfig out;
823 out.apply(SLAFullPrintConfig::defaults());
824 out.apply(this->sla_prints.get_edited_preset().config);
825 out.apply(this->sla_materials.get_edited_preset().config);
826 out.apply(this->printers.get_edited_preset().config);
827 // There are no project configuration values as of now, the project_config is reserved for FFF printers.
828// out.apply(this->project_config);
829
830 // Collect the "compatible_printers_condition" and "inherits" values over all presets (sla_prints, sla_materials, printers) into a single vector.
831 std::vector<std::string> compatible_printers_condition;
832 std::vector<std::string> compatible_prints_condition;
833 std::vector<std::string> inherits;
834 compatible_printers_condition.emplace_back(this->sla_prints.get_edited_preset().compatible_printers_condition());
835 inherits .emplace_back(this->sla_prints.get_edited_preset().inherits());
836 compatible_printers_condition.emplace_back(this->sla_materials.get_edited_preset().compatible_printers_condition());
837 compatible_prints_condition .emplace_back(this->sla_materials.get_edited_preset().compatible_prints_condition());
838 inherits .emplace_back(this->sla_materials.get_edited_preset().inherits());
839 inherits .emplace_back(this->printers.get_edited_preset().inherits());
840
841 // These two value types clash between the print and filament profiles. They should be renamed.
842 out.erase("compatible_printers");
843 out.erase("compatible_printers_condition");
844 out.erase("inherits");
845
846 out.option<ConfigOptionString >("sla_print_settings_id", true)->value = this->sla_prints.get_selected_preset_name();
847 out.option<ConfigOptionString >("sla_material_settings_id", true)->value = this->sla_materials.get_selected_preset_name();
848 out.option<ConfigOptionString >("printer_settings_id", true)->value = this->printers.get_selected_preset_name();
849 out.option<ConfigOptionString >("physical_printer_settings_id", true)->value = this->physical_printers.get_selected_printer_name();
850
851 // Serialize the collected "compatible_printers_condition" and "inherits" fields.
852 // There will be 1 + num_exturders fields for "inherits" and 2 + num_extruders for "compatible_printers_condition" stored.
853 // The vector will not be stored if all fields are empty strings.
854 auto add_if_some_non_empty = [&out](std::vector<std::string> &&values, const std::string &key) {
855 bool nonempty = false;
856 for (const std::string &v : values)
857 if (! v.empty()) {
858 nonempty = true;
859 break;
860 }
861 if (nonempty)
862 out.set_key_value(key, new ConfigOptionStrings(std::move(values)));
863 };
864 add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_printers_condition_cummulative");
865 add_if_some_non_empty(std::move(compatible_prints_condition), "compatible_prints_condition_cummulative");
866 add_if_some_non_empty(std::move(inherits), "inherits_cummulative");
867
868 out.option<ConfigOptionEnumGeneric>("printer_technology", true)->value = ptSLA;
869 return out;
870}

References Slic3r::ConfigBase::apply(), Slic3r::Preset::compatible_printers_condition(), Slic3r::Preset::compatible_prints_condition(), Slic3r::Preset::config, Slic3r::DynamicConfig::erase(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::PhysicalPrinterCollection::get_selected_printer_name(), Slic3r::Preset::inherits(), Slic3r::ConfigBase::option(), physical_printers, printers, Slic3r::ptSLA, Slic3r::DynamicConfig::set_key_value(), sla_materials, and sla_prints.

Referenced by full_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_preset_name_by_alias()

const std::string & Slic3r::PresetBundle::get_preset_name_by_alias ( const Preset::Type preset_type,
const std::string &  alias,
int  extruder_id = -1 
)
459{
460 // there are not aliases for Printers profiles
461 if (preset_type == Preset::TYPE_PRINTER || preset_type == Preset::TYPE_INVALID)
462 return alias;
463
464 if (preset_type == Preset::TYPE_FILAMENT)
465 return extruders_filaments[extruder_id].get_preset_name_by_alias(alias);
466
467 const PresetCollection& presets = get_presets(preset_type);
468
469 return presets.get_preset_name_by_alias(alias);
470}
PresetCollection & get_presets(Preset::Type preset_type)
Definition PresetBundle.cpp:447
@ TYPE_INVALID
Definition Preset.hpp:111

References extruders_filaments, Slic3r::PresetCollection::get_preset_name_by_alias(), get_presets(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_INVALID, and Slic3r::Preset::TYPE_PRINTER.

Referenced by load_selections().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_presets()

PresetCollection & Slic3r::PresetBundle::get_presets ( Preset::Type  preset_type)
448{
449 assert(type >= Preset::TYPE_PRINT && type <= Preset::TYPE_PRINTER);
450
451 return type == Preset::TYPE_PRINT ? prints :
455}

References filaments, printers, prints, sla_materials, sla_prints, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, Slic3r::Preset::TYPE_SLA_MATERIAL, and Slic3r::Preset::TYPE_SLA_PRINT.

Referenced by Slic3r::GUI::SavePresetDialog::Item::get_init_preset_name(), get_preset_name_by_alias(), save_changes_for_preset(), and transfer_and_save().

+ Here is the caller graph for this function:

◆ has_defauls_only()

bool Slic3r::PresetBundle::has_defauls_only ( ) const
inline
bool has_defaults_only() const
Definition Preset.hpp:460

References filaments, Slic3r::PresetCollection::has_defaults_only(), printers, and prints.

+ Here is the call graph for this function:

◆ import_newer_configs()

void Slic3r::PresetBundle::import_newer_configs ( const std::string &  from)
217{
218 boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
219 // Clean-up vendors from the target directory, as the existing vendors will not be referenced
220 // by the copied PrusaSlicer.ini
221 try {
222 boost::filesystem::remove_all(data_dir / "cache");
223 } catch (const std::exception &ex) {
224 BOOST_LOG_TRIVIAL(error) << "Error deleting old cache " << (data_dir / "cache").string() << ": " << ex.what();
225 }
226 try {
227 boost::filesystem::remove_all(data_dir / "vendor");
228 } catch (const std::exception &ex) {
229 BOOST_LOG_TRIVIAL(error) << "Error deleting old vendors " << (data_dir / "vendor").string() << ": " << ex.what();
230 }
231 // list of searched paths based on current directory system in setup_directories()
232 // do not copy cache and snapshots
233 boost::filesystem::path from_data_dir = boost::filesystem::path(from);
234 std::initializer_list<boost::filesystem::path> from_dirs= {
235 from_data_dir / "cache",
236 from_data_dir / "vendor",
237 from_data_dir / "shapes",
238#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
239 // Store the print/filament/printer presets into a "presets" directory.
240 data_dir / "presets" / "print",
241 data_dir / "presets" / "filament",
242 data_dir / "presets" / "sla_print",
243 data_dir / "presets" / "sla_material",
244 data_dir / "presets" / "printer",
245 data_dir / "presets" / "physical_printer"
246#else
247 // Store the print/filament/printer presets at the same location as the upstream Slic3r.
248 from_data_dir / "print",
249 from_data_dir / "filament",
250 from_data_dir / "sla_print",
251 from_data_dir / "sla_material",
252 from_data_dir / "printer",
253 from_data_dir / "physical_printer"
254#endif
255 };
256 // copy recursively all files
257 for (const boost::filesystem::path& from_dir : from_dirs) {
258 copy_dir(from_dir, data_dir / from_dir.filename());
259 }
260}
static void copy_dir(const boost::filesystem::path &from_dir, const boost::filesystem::path &to_dir)
Definition PresetBundle.cpp:192
const std::string & data_dir()
Definition utils.cpp:206
static char error[256]
Definition tga.cpp:50

References Slic3r::copy_dir(), Slic3r::data_dir(), and error.

Referenced by Slic3r::GUI::GUI_App::on_init_inner().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_config_file()

ConfigSubstitutions Slic3r::PresetBundle::load_config_file ( const std::string &  path,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
877{
878 if (is_gcode_file(path)) {
879 DynamicPrintConfig config;
880 config.apply(FullPrintConfig::defaults());
881 ConfigSubstitutions config_substitutions = config.load_from_gcode_file(path, compatibility_rule);
882 Preset::normalize(config);
883 load_config_file_config(path, true, std::move(config));
884 return config_substitutions;
885 }
886
887 // 1) Try to load the config file into a boost property tree.
888 boost::property_tree::ptree tree;
889 try {
890 boost::nowide::ifstream ifs(path);
891 boost::property_tree::read_ini(ifs, tree);
892 } catch (const std::ifstream::failure &err) {
893 throw Slic3r::RuntimeError(std::string("The Config Bundle cannot be loaded: ") + path + "\n\tReason: " + err.what());
894 } catch (const boost::property_tree::file_parser_error &err) {
895 throw Slic3r::RuntimeError(format("Failed loading the Config Bundle \"%1%\": %2% at line %3%",
896 err.filename(), err.message(), err.line()));
897 } catch (const std::runtime_error &err) {
898 throw Slic3r::RuntimeError(std::string("Failed loading the preset file: ") + path + "\n\tReason: " + err.what());
899 }
900
901 // 2) Continue based on the type of the configuration file.
902 ConfigFileType config_file_type = guess_config_file_type(tree);
903 ConfigSubstitutions config_substitutions;
904 try {
905 switch (config_file_type) {
907 throw Slic3r::RuntimeError(std::string("Unknown configuration file type: ") + path);
909 throw Slic3r::RuntimeError(std::string("Invalid configuration file: ") + path + ". This is an application config file.");
911 {
912 // Initialize a config from full defaults.
913 DynamicPrintConfig config;
914 config.apply(FullPrintConfig::defaults());
915 config_substitutions = config.load(tree, compatibility_rule);
916 Preset::normalize(config);
917 load_config_file_config(path, true, std::move(config));
918 return config_substitutions;
919 }
921 return load_config_file_config_bundle(path, tree, compatibility_rule);
922 }
923 } catch (const ConfigurationError &e) {
924 throw Slic3r::RuntimeError(format("Invalid configuration file %1%: %2%", path, e.what()));
925 }
926
927 // This shall never happen. Suppres compiler warnings.
928 assert(false);
929 return ConfigSubstitutions{};
930}
void load_config_file_config(const std::string &name_or_path, bool is_external, DynamicPrintConfig &&config)
Definition PresetBundle.cpp:934
ConfigSubstitutions load_config_file_config_bundle(const std::string &path, const boost::property_tree::ptree &tree, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition PresetBundle.cpp:1104
static void normalize(DynamicPrintConfig &config)
Definition Preset.cpp:266
ConfigFileType guess_config_file_type(const ptree &tree)
Definition Preset.cpp:42
bool is_gcode_file(const std::string &path)
Definition utils.cpp:783
std::vector< ConfigSubstitution > ConfigSubstitutions
Definition Config.hpp:246
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:44
ConfigFileType
Definition Preset.hpp:20
@ CONFIG_FILE_TYPE_UNKNOWN
Definition Preset.hpp:21
@ CONFIG_FILE_TYPE_CONFIG
Definition Preset.hpp:23
@ CONFIG_FILE_TYPE_APP_CONFIG
Definition Preset.hpp:22
@ CONFIG_FILE_TYPE_CONFIG_BUNDLE
Definition Preset.hpp:24

References Slic3r::ConfigBase::apply(), Slic3r::CONFIG_FILE_TYPE_APP_CONFIG, Slic3r::CONFIG_FILE_TYPE_CONFIG, Slic3r::CONFIG_FILE_TYPE_CONFIG_BUNDLE, Slic3r::CONFIG_FILE_TYPE_UNKNOWN, Slic3r::format(), Slic3r::guess_config_file_type(), Slic3r::is_gcode_file(), Slic3r::ConfigBase::load(), load_config_file_config(), load_config_file_config_bundle(), Slic3r::ConfigBase::load_from_gcode_file(), and Slic3r::Preset::normalize().

+ Here is the call graph for this function:

◆ load_config_file_config()

void Slic3r::PresetBundle::load_config_file_config ( const std::string &  name_or_path,
bool  is_external,
DynamicPrintConfig &&  config 
)
private
935{
937
938 // The "compatible_printers" field should not have been exported into a config.ini or a G-code anyway,
939 // but some of the alpha versions of Slic3r did.
940 {
941 ConfigOption *opt_compatible = config.optptr("compatible_printers");
942 if (opt_compatible != nullptr) {
943 assert(opt_compatible->type() == coStrings);
944 if (opt_compatible->type() == coStrings)
945 static_cast<ConfigOptionStrings*>(opt_compatible)->values.clear();
946 }
947 }
948
949 size_t num_extruders = (printer_technology == ptFFF) ?
950 std::min(config.option<ConfigOptionFloats>("nozzle_diameter" )->values.size(),
951 config.option<ConfigOptionFloats>("filament_diameter")->values.size()) :
952 // 1 SLA material
953 1;
954 // Make a copy of the "compatible_printers_condition_cummulative" and "inherits_cummulative" vectors, which
955 // accumulate values over all presets (print, filaments, printers).
956 // These values will be distributed into their particular presets when loading.
957 std::vector<std::string> compatible_printers_condition_values = std::move(config.option<ConfigOptionStrings>("compatible_printers_condition_cummulative", true)->values);
958 std::vector<std::string> compatible_prints_condition_values = std::move(config.option<ConfigOptionStrings>("compatible_prints_condition_cummulative", true)->values);
959 std::vector<std::string> inherits_values = std::move(config.option<ConfigOptionStrings>("inherits_cummulative", true)->values);
960 std::string &compatible_printers_condition = Preset::compatible_printers_condition(config);
961 std::string &compatible_prints_condition = Preset::compatible_prints_condition(config);
962 std::string &inherits = Preset::inherits(config);
963 compatible_printers_condition_values.resize(num_extruders + 2, std::string());
964 compatible_prints_condition_values.resize(num_extruders, std::string());
965 inherits_values.resize(num_extruders + 2, std::string());
966 // The "default_filament_profile" will be later extracted into the printer profile.
967 switch (printer_technology) {
968 case ptFFF:
969 config.option<ConfigOptionString>("default_print_profile", true);
970 config.option<ConfigOptionStrings>("default_filament_profile", true);
971 break;
972 case ptSLA:
973 config.option<ConfigOptionString>("default_sla_print_profile", true);
974 config.option<ConfigOptionString>("default_sla_material_profile", true);
975 break;
976 default: break;
977 }
978
979 // 1) Create a name from the file name.
980 // Keep the suffix (.ini, .gcode, .amf, .3mf etc) to differentiate it from the normal profiles.
981 std::string name = is_external ? boost::filesystem::path(name_or_path).filename().string() : name_or_path;
982
983 // 2) If the loading succeeded, split and load the config into print / filament / printer settings.
984 // First load the print and printer presets.
985
986 auto load_preset =
987 [&config, &inherits, &inherits_values,
988 &compatible_printers_condition, &compatible_printers_condition_values,
989 &compatible_prints_condition, &compatible_prints_condition_values,
990 is_external, &name, &name_or_path]
991 (PresetCollection &presets, size_t idx, const std::string &key) {
992 // Split the "compatible_printers_condition" and "inherits" values one by one from a single vector to the print & printer profiles.
993 inherits = inherits_values[idx];
994 compatible_printers_condition = compatible_printers_condition_values[idx];
995 if (idx > 0 && idx - 1 < compatible_prints_condition_values.size())
996 compatible_prints_condition = compatible_prints_condition_values[idx - 1];
997 if (is_external)
998 presets.load_external_preset(name_or_path, name, config.opt_string(key, true), config);
999 else
1000 presets.load_preset(presets.path_from_name(name), name, config).save();
1001 };
1002
1003 switch (Preset::printer_technology(config)) {
1004 case ptFFF:
1005 {
1006 load_preset(this->prints, 0, "print_settings_id");
1007 load_preset(this->printers, num_extruders + 1, "printer_settings_id");
1008
1009 // 3) Now load the filaments. If there are multiple filament presets, split them and load them.
1010 auto old_filament_profile_names = config.option<ConfigOptionStrings>("filament_settings_id", true);
1011 old_filament_profile_names->values.resize(num_extruders, std::string());
1012
1013 this->extruders_filaments.clear();
1014 if (num_extruders <= 1) {
1015 // Split the "compatible_printers_condition" and "inherits" from the cummulative vectors to separate filament presets.
1016 inherits = inherits_values[1];
1017 compatible_printers_condition = compatible_printers_condition_values[1];
1018 compatible_prints_condition = compatible_prints_condition_values.front();
1019 Preset *loaded = nullptr;
1020 if (is_external)
1021 loaded = this->filaments.load_external_preset(name_or_path, name, old_filament_profile_names->values.front(), config).first;
1022 else {
1023 // called from Config Wizard.
1024 loaded= &this->filaments.load_preset(this->filaments.path_from_name(name), name, config);
1025 loaded->save();
1026 }
1027 this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments));
1028 } else {
1029 assert(is_external);
1030 // Split the filament presets, load each of them separately.
1031 std::vector<DynamicPrintConfig> configs(num_extruders, this->filaments.default_preset().config);
1032 // loop through options and scatter them into configs.
1033 for (const t_config_option_key &key : this->filaments.default_preset().config.keys()) {
1034 const ConfigOption *other_opt = config.option(key);
1035 if (other_opt == nullptr)
1036 continue;
1037 if (other_opt->is_scalar()) {
1038 for (size_t i = 0; i < configs.size(); ++ i)
1039 configs[i].option(key, false)->set(other_opt);
1040 } else if (key != "compatible_printers" && key != "compatible_prints") {
1041 for (size_t i = 0; i < configs.size(); ++ i)
1042 static_cast<ConfigOptionVectorBase*>(configs[i].option(key, false))->set_at(other_opt, 0, i);
1043 }
1044 }
1045 // Load the configs into this->filaments and make them active.
1046 std::vector<std::string> extr_names = std::vector<std::string>(configs.size());
1047 // To avoid incorrect selection of the first filament preset (means a value of Preset->m_idx_selected)
1048 // in a case when next added preset take a place of previosly selected preset,
1049 // we should add presets from last to first
1050 bool any_modified = false;
1051 for (int i = (int)configs.size()-1; i >= 0; i--) {
1052 DynamicPrintConfig &cfg = configs[i];
1053 // Split the "compatible_printers_condition" and "inherits" from the cummulative vectors to separate filament presets.
1054 cfg.opt_string("compatible_printers_condition", true) = compatible_printers_condition_values[i + 1];
1055 cfg.opt_string("compatible_prints_condition", true) = compatible_prints_condition_values[i];
1056 cfg.opt_string("inherits", true) = inherits_values[i + 1];
1057 // Load all filament presets, but only select the first one in the preset dialog.
1058 auto [loaded, modified] = this->filaments.load_external_preset(name_or_path, name,
1059 (i < int(old_filament_profile_names->values.size())) ? old_filament_profile_names->values[i] : "",
1060 std::move(cfg),
1061 i == 0 ?
1063 any_modified ?
1066 any_modified |= modified;
1067 extr_names[i] = loaded->name;
1068 }
1069 // create extruders_filaments only when all filaments are loaded
1070 for (size_t id = 0; id < extr_names.size(); ++id)
1071 this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments, id, extr_names[id]));
1072 }
1073
1074 // 4) Load the project config values (the per extruder wipe matrix etc).
1076
1077 break;
1078 }
1079 case ptSLA:
1080 load_preset(this->sla_prints, 0, "sla_print_settings_id");
1081 load_preset(this->sla_materials, 1, "sla_material_settings_id");
1082 load_preset(this->printers, 2, "printer_settings_id");
1083 break;
1084 default:
1085 break;
1086 }
1087
1089
1090 const std::string &physical_printer = config.option<ConfigOptionString>("physical_printer_settings_id", true)->value;
1091 if (this->printers.get_edited_preset().is_external || physical_printer.empty()) {
1093 } else {
1094 // Activate the physical printer profile if possible.
1095 PhysicalPrinter *pp = this->physical_printers.find_printer(physical_printer, true);
1096 if (pp != nullptr && std::find(pp->preset_names.begin(), pp->preset_names.end(), this->printers.get_edited_preset().name) != pp->preset_names.end())
1097 this->physical_printers.select_printer(pp->name, this->printers.get_edited_preset().name);
1098 else
1100 }
1101}
void save(Archive &archive, wxString const &d)
Definition GLGizmoEmboss.cpp:1557
void select_printer(const std::string &full_name)
Definition Preset.cpp:2058
PhysicalPrinter * find_printer(const std::string &name, bool case_sensitive_search=true)
Definition Preset.cpp:1873
void unselect_printer()
Definition Preset.cpp:2095
void update_compatible(PresetSelectCompatibleType select_other_print_if_incompatible, PresetSelectCompatibleType select_other_filament_if_incompatible)
Definition PresetBundle.cpp:1811
std::pair< Preset *, bool > load_external_preset(const std::string &path, const std::string &name, const std::string &original_name, const DynamicPrintConfig &config, LoadAndSelect select=LoadAndSelect::Always)
Definition Preset.cpp:770
Preset & load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select=true)
Definition Preset.cpp:743
std::string path_from_name(const std::string &new_name) const
Definition Preset.cpp:1526
bool is_external
Definition Preset.hpp:132
PrinterTechnology printer_technology() const
Definition Preset.hpp:207
void save()
Definition Preset.cpp:327
PrinterTechnology
Definition Config.hpp:205
printer_technology((ConfigOptionPoints, bed_shape))((ConfigOptionFloat
@ coStrings
Definition Config.hpp:174

References Slic3r::PresetCollection::Always, Slic3r::ConfigBase::apply_only(), Slic3r::ConfigOptionVector< T >::clear(), Slic3r::Preset::compatible_printers_condition(), Slic3r::Preset::compatible_prints_condition(), Slic3r::Preset::config, Slic3r::coStrings, Slic3r::PresetCollection::default_preset(), extruders_filaments, filaments, Slic3r::PhysicalPrinterCollection::find_printer(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::Preset::inherits(), Slic3r::Preset::is_external, Slic3r::ConfigOption::is_scalar(), Slic3r::DynamicConfig::keys(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::PhysicalPrinter::name, Slic3r::Never, Slic3r::PresetCollection::Never, Slic3r::PresetCollection::OnlyIfModified, Slic3r::ConfigBase::opt_string(), Slic3r::PresetCollection::path_from_name(), physical_printers, Slic3r::PhysicalPrinter::preset_names, Slic3r::printer_technology(), Slic3r::Preset::printer_technology(), printers, prints, project_config, Slic3r::ptFFF, Slic3r::ptSLA, Slic3r::s_project_options, Slic3r::Preset::save(), save(), Slic3r::PhysicalPrinterCollection::select_printer(), Slic3r::ConfigOptionVector< T >::size(), sla_materials, sla_prints, Slic3r::ConfigOption::type(), Slic3r::PhysicalPrinterCollection::unselect_printer(), update_compatible(), and Slic3r::ConfigOptionVector< T >::values.

Referenced by load_config_file(), load_config_from_wizard(), and load_config_model().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_config_file_config_bundle()

ConfigSubstitutions Slic3r::PresetBundle::load_config_file_config_bundle ( const std::string &  path,
const boost::property_tree::ptree &  tree,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
private
1106{
1107 // 1) Load the config bundle into a temp data.
1108 PresetBundle tmp_bundle;
1109 // Load the config bundle, but don't save the loaded presets to user profile directory, as only the presets marked as active in the loaded preset bundle
1110 // will be loaded into the master PresetBundle and activated.
1111 auto [presets_substitutions, presets_imported] = tmp_bundle.load_configbundle(path, {}, compatibility_rule);
1112 UNUSED(presets_imported);
1113
1114 std::string bundle_name = std::string(" - ") + boost::filesystem::path(path).filename().string();
1115
1116 // 2) Extract active configs from the config bundle, copy them and activate them in this bundle.
1117 ConfigSubstitutions config_substitutions;
1118 auto load_one = [&path, &bundle_name, &presets_substitutions = presets_substitutions, &config_substitutions](
1119 PresetCollection &collection_dst, PresetCollection &collection_src, const std::string &preset_name_src, bool activate) -> std::string {
1120 // If there are substitutions reported for this preset, move them to config_substitutions.
1121 if (auto it = std::find_if(presets_substitutions.begin(), presets_substitutions.end(), [&preset_name_src](const PresetConfigSubstitutions& subs){ return subs.preset_name == preset_name_src; });
1122 it != presets_substitutions.end() && ! it->substitutions.empty())
1123 append(config_substitutions, std::move(it->substitutions));
1124 Preset *preset_src = collection_src.find_preset(preset_name_src, false);
1125 Preset *preset_dst = collection_dst.find_preset(preset_name_src, false);
1126 assert(preset_src != nullptr);
1127 std::string preset_name_dst;
1128 if (preset_dst != nullptr && preset_dst->is_default) {
1129 // No need to copy a default preset, it always exists in collection_dst.
1130 if (activate)
1131 collection_dst.select_preset(0);
1132 return preset_name_src;
1133 } else if (preset_dst != nullptr && preset_src->config == preset_dst->config) {
1134 // Don't save as the config exists in the current bundle and its content is the same.
1135 return preset_name_src;
1136 } else {
1137 // Generate a new unique name.
1138 preset_name_dst = preset_name_src + bundle_name;
1139 Preset *preset_dup = nullptr;
1140 for (size_t i = 1; (preset_dup = collection_dst.find_preset(preset_name_dst, false)) != nullptr; ++ i) {
1141 if (preset_src->config == preset_dup->config)
1142 // The preset has been already copied into collection_dst.
1143 return preset_name_dst;
1144 // Try to generate another name.
1145 char buf[64];
1146 sprintf(buf, " (%d)", (int)i);
1147 preset_name_dst = preset_name_src + buf + bundle_name;
1148 }
1149 }
1150 assert(! preset_name_dst.empty());
1151 // Save preset_src->config into collection_dst under preset_name_dst.
1152 // The "compatible_printers" field should not have been exported into a config.ini or a G-code anyway,
1153 // but some of the alpha versions of Slic3r did.
1154 ConfigOption *opt_compatible = preset_src->config.optptr("compatible_printers");
1155 if (opt_compatible != nullptr) {
1156 assert(opt_compatible->type() == coStrings);
1157 if (opt_compatible->type() == coStrings)
1158 static_cast<ConfigOptionStrings*>(opt_compatible)->values.clear();
1159 }
1160 (collection_dst.type() == Preset::TYPE_FILAMENT ?
1161 collection_dst.load_preset(path, preset_name_dst, preset_src->config, activate) :
1162 // Only move the source config for non filament profiles, as single filament profile may be referenced multiple times.
1163 collection_dst.load_preset(path, preset_name_dst, std::move(preset_src->config), activate))
1164 .is_external = true;
1165 return preset_name_dst;
1166 };
1167 load_one(this->prints, tmp_bundle.prints, tmp_bundle.prints .get_selected_preset_name(), true);
1168 load_one(this->sla_prints, tmp_bundle.sla_prints, tmp_bundle.sla_prints .get_selected_preset_name(), true);
1169 load_one(this->filaments, tmp_bundle.filaments, tmp_bundle.filaments .get_selected_preset_name(), true);
1170 load_one(this->sla_materials, tmp_bundle.sla_materials, tmp_bundle.sla_materials.get_selected_preset_name(), true);
1171 load_one(this->printers, tmp_bundle.printers, tmp_bundle.printers .get_selected_preset_name(), true);
1172
1173 this->extruders_filaments.clear();
1175 for (size_t i = 1; i < std::min(tmp_bundle.extruders_filaments.size(), this->extruders_filaments.size()); ++i)
1176 this->extruders_filaments[i].select_filament(load_one(this->filaments, tmp_bundle.filaments, tmp_bundle.extruders_filaments[i].get_selected_preset_name(), false));
1177
1179
1180 sort_remove_duplicates(config_substitutions);
1181 return config_substitutions;
1182}
PresetBundle()
Definition PresetBundle.cpp:40
void update_multi_material_filament_presets()
Definition PresetBundle.cpp:1671
#define UNUSED(x)
Definition libslic3r.h:74
void sort_remove_duplicates(std::vector< T > &vec)
Definition libslic3r.h:188
void append(std::vector< T, Alloc > &dest, const std::vector< T, Alloc2 > &src)
Definition libslic3r.h:110

References Slic3r::append(), Slic3r::ConfigOptionVector< T >::clear(), Slic3r::Preset::config, Slic3r::coStrings, extruders_filaments, filaments, Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::Preset::is_default, load_configbundle(), Slic3r::Never, Slic3r::DynamicConfig::optptr(), printers, prints, sla_materials, sla_prints, Slic3r::sort_remove_duplicates(), Slic3r::ConfigOption::type(), Slic3r::Preset::TYPE_FILAMENT, UNUSED, update_compatible(), and update_multi_material_filament_presets().

Referenced by load_config_file().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_config_from_wizard()

void Slic3r::PresetBundle::load_config_from_wizard ( const std::string &  name,
DynamicPrintConfig  config 
)
inline
91 { this->load_config_file_config(name, false, std::move(config)); }

References load_config_file_config().

Referenced by Slic3r::GUI::ConfigWizard::priv::apply_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_config_model()

void Slic3r::PresetBundle::load_config_model ( const std::string &  name,
DynamicPrintConfig  config 
)
inline
96 { this->load_config_file_config(name, true, std::move(config)); }

References load_config_file_config().

Referenced by Slic3r::GUI::Plater::priv::load_files().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_configbundle()

std::pair< PresetsConfigSubstitutions, size_t > Slic3r::PresetBundle::load_configbundle ( const std::string &  path,
LoadConfigBundleAttributes  flags,
ForwardCompatibilitySubstitutionRule  compatibility_rule 
)
1328{
1329 // Enable substitutions for user config bundle, throw an exception when loading a system profile.
1330 ConfigSubstitutionContext substitution_context { compatibility_rule };
1331 PresetsConfigSubstitutions substitutions;
1332
1334 // Reset this bundle, delete user profile files if SaveImported.
1336
1337 // 1) Read the complete config file into a boost::property_tree.
1338 namespace pt = boost::property_tree;
1339 pt::ptree tree;
1340 {
1341 boost::nowide::ifstream ifs(path);
1342 try {
1343 pt::read_ini(ifs, tree);
1344 } catch (const boost::property_tree::ini_parser::ini_parser_error &err) {
1345 throw Slic3r::RuntimeError(format("Failed loading config bundle \"%1%\"\nError: \"%2%\" at line %3%", path, err.message(), err.line()).c_str());
1346 }
1347 }
1348
1349 const VendorProfile *vendor_profile = nullptr;
1351 VendorProfile vp = VendorProfile::from_ini(tree, path);
1352 if (vp.models.size() == 0 && !vp.templates_profile) {
1353 BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No printer model defined.") % path;
1354 return std::make_pair(PresetsConfigSubstitutions{}, 0);
1355 } else if (vp.num_variants() == 0 && !vp.templates_profile) {
1356 BOOST_LOG_TRIVIAL(error) << boost::format("Vendor bundle: `%1%`: No printer variant defined") % path;
1357 return std::make_pair(PresetsConfigSubstitutions{}, 0);
1358 }
1359 vendor_profile = &this->vendors.insert({vp.id, vp}).first->second;
1360 }
1361
1363 return std::make_pair(PresetsConfigSubstitutions{}, 0);
1364
1365 // 1.5) Flatten the config bundle by applying the inheritance rules. Internal profiles (with names starting with '*') are removed.
1366 // If loading a user config bundle, do not flatten with the system profiles, but keep the "inherits" flag intact.
1368
1369 // 2) Parse the property_tree, extract the active preset names and the profiles, save them into local config files.
1370 // Parse the obsolete preset names, to be deleted when upgrading from the old configuration structure.
1371 std::vector<std::string> loaded_prints;
1372 std::vector<std::string> loaded_filaments;
1373 std::vector<std::string> loaded_sla_prints;
1374 std::vector<std::string> loaded_sla_materials;
1375 std::vector<std::string> loaded_printers;
1376 std::vector<std::string> loaded_physical_printers;
1377 std::string active_print;
1378 std::vector<std::string> active_filaments;
1379 std::string active_sla_print;
1380 std::string active_sla_material;
1381 std::string active_printer;
1382 std::string active_physical_printer;
1383 size_t presets_loaded = 0;
1384 size_t ph_printers_loaded = 0;
1385
1386 for (const auto &section : tree) {
1387 PresetCollection *presets = nullptr;
1388 std::string preset_name;
1389 PhysicalPrinterCollection *ph_printers = nullptr;
1390 std::string ph_printer_name;
1391 if (boost::starts_with(section.first, "print:")) {
1392 presets = &this->prints;
1393 preset_name = section.first.substr(6);
1394 } else if (boost::starts_with(section.first, "filament:")) {
1395 presets = &this->filaments;
1396 preset_name = section.first.substr(9);
1397 if (vendor_profile && vendor_profile->templates_profile) {
1398 preset_name += " @Template";
1399 }
1400 } else if (boost::starts_with(section.first, "sla_print:")) {
1401 presets = &this->sla_prints;
1402 preset_name = section.first.substr(10);
1403 } else if (boost::starts_with(section.first, "sla_material:")) {
1404 presets = &this->sla_materials;
1405 preset_name = section.first.substr(13);
1406 } else if (boost::starts_with(section.first, "printer:")) {
1407 presets = &this->printers;
1408 preset_name = section.first.substr(8);
1409 } else if (boost::starts_with(section.first, "physical_printer:")) {
1410 ph_printers = &this->physical_printers;
1411 ph_printer_name = section.first.substr(17);
1412 } else if (section.first == "presets") {
1413 // Load the names of the active presets.
1414 for (auto &kvp : section.second) {
1415 if (kvp.first == "print") {
1416 active_print = kvp.second.data();
1417 } else if (boost::starts_with(kvp.first, "filament")) {
1418 int idx = 0;
1419 if (kvp.first == "filament" || sscanf(kvp.first.c_str(), "filament_%d", &idx) == 1) {
1420 if (int(active_filaments.size()) <= idx)
1421 active_filaments.resize(idx + 1, std::string());
1422 active_filaments[idx] = kvp.second.data();
1423 }
1424 } else if (kvp.first == "sla_print") {
1425 active_sla_print = kvp.second.data();
1426 } else if (kvp.first == "sla_material") {
1427 active_sla_material = kvp.second.data();
1428 } else if (kvp.first == "printer") {
1429 active_printer = kvp.second.data();
1430 } else if (kvp.first == "physical_printer") {
1431 active_physical_printer = kvp.second.data();
1432 }
1433 }
1434 } else if (section.first == "obsolete_presets") {
1435 // Parse the names of obsolete presets. These presets will be deleted from user's
1436 // profile directory on installation of this vendor preset.
1437 for (auto &kvp : section.second) {
1438 std::vector<std::string> *dst = nullptr;
1439 if (kvp.first == "print")
1440 dst = &this->obsolete_presets.prints;
1441 else if (kvp.first == "filament")
1442 dst = &this->obsolete_presets.filaments;
1443 else if (kvp.first == "sla_print")
1444 dst = &this->obsolete_presets.sla_prints;
1445 else if (kvp.first == "sla_material")
1446 dst = &this->obsolete_presets.sla_materials;
1447 else if (kvp.first == "printer")
1448 dst = &this->obsolete_presets.printers;
1449 if (dst)
1450 unescape_strings_cstyle(kvp.second.data(), *dst);
1451 }
1452 } else if (section.first == "settings") {
1453 // Load the settings.
1454 for (auto &kvp : section.second) {
1455 if (kvp.first == "autocenter") {
1456 }
1457 }
1458 } else
1459 // Ignore an unknown section.
1460 continue;
1461 if (presets != nullptr) {
1462 // Load the print, filament or printer preset.
1463 const DynamicPrintConfig *default_config = nullptr;
1464 DynamicPrintConfig config;
1465 std::string alias_name;
1466 std::vector<std::string> renamed_from;
1467 try {
1468 auto parse_config_section = [&section, &alias_name, &renamed_from, &substitution_context, &path](DynamicPrintConfig &config) {
1469 substitution_context.substitutions.clear();
1470 for (auto &kvp : section.second) {
1471 if (kvp.first == "alias")
1472 alias_name = kvp.second.data();
1473 else if (kvp.first == "renamed_from") {
1474 if (! unescape_strings_cstyle(kvp.second.data(), renamed_from)) {
1475 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The preset \"" <<
1476 section.first << "\" contains invalid \"renamed_from\" key, which is being ignored.";
1477 }
1478 }
1479 // Throws on parsing error. For system presets, no substituion is being done, but an exception is thrown.
1480 config.set_deserialize(kvp.first, kvp.second.data(), substitution_context);
1481 }
1482 };
1483 if (presets == &this->printers) {
1484 // Select the default config based on the printer_technology field extracted from kvp.
1485 DynamicPrintConfig config_src;
1486 parse_config_section(config_src);
1487 default_config = &presets->default_preset_for(config_src).config;
1488 config = *default_config;
1489 config.apply(config_src);
1490 } else {
1491 default_config = &presets->default_preset().config;
1492 config = *default_config;
1493 parse_config_section(config);
1494 }
1495 } catch (const ConfigurationError &e) {
1496 throw ConfigurationError(format("Invalid configuration bundle \"%1%\", section [%2%]: ", path, section.first) + e.what());
1497 }
1498 Preset::normalize(config);
1499 // Report configuration fields, which are misplaced into a wrong group.
1500 std::string incorrect_keys = Preset::remove_invalid_keys(config, *default_config);
1501 if (! incorrect_keys.empty())
1502 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" <<
1503 section.first << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
1504 if (flags.has(LoadConfigBundleAttribute::LoadSystem) && presets == &printers) {
1505 // Filter out printer presets, which are not mentioned in the vendor profile.
1506 // These presets are considered not installed.
1507 auto printer_model = config.opt_string("printer_model");
1508 if (printer_model.empty()) {
1509 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" <<
1510 section.first << "\" defines no printer model, it will be ignored.";
1511 continue;
1512 }
1513 auto printer_variant = config.opt_string("printer_variant");
1514 if (printer_variant.empty()) {
1515 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" <<
1516 section.first << "\" defines no printer variant, it will be ignored.";
1517 continue;
1518 }
1519 auto it_model = std::find_if(vendor_profile->models.cbegin(), vendor_profile->models.cend(),
1520 [&](const VendorProfile::PrinterModel &m) { return m.id == printer_model; }
1521 );
1522 if (it_model == vendor_profile->models.end()) {
1523 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" <<
1524 section.first << "\" defines invalid printer model \"" << printer_model << "\", it will be ignored.";
1525 continue;
1526 }
1527 auto it_variant = it_model->variant(printer_variant);
1528 if (it_variant == nullptr) {
1529 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" <<
1530 section.first << "\" defines invalid printer variant \"" << printer_variant << "\", it will be ignored.";
1531 continue;
1532 }
1533 const Preset *preset_existing = presets->find_preset(section.first, false);
1534 if (preset_existing != nullptr) {
1535 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The printer preset \"" <<
1536 section.first << "\" has already been loaded from another Confing Bundle.";
1537 continue;
1538 }
1539 } else if (! flags.has(LoadConfigBundleAttribute::LoadSystem)) {
1540 // This is a user config bundle.
1541 const Preset *existing = presets->find_preset(preset_name, false);
1542 if (existing != nullptr) {
1543 if (existing->is_system) {
1544 assert(existing->vendor != nullptr);
1545 BOOST_LOG_TRIVIAL(error) << "Error in a user provided Config Bundle \"" << path << "\": The " << presets->name() << " preset \"" <<
1546 existing->name << "\" is a system preset of vendor " << existing->vendor->name << " and it will be ignored.";
1547 continue;
1548 } else {
1549 assert(existing->vendor == nullptr);
1550 BOOST_LOG_TRIVIAL(trace) << "A " << presets->name() << " preset \"" << existing->name << "\" was overwritten with a preset from user Config Bundle \"" << path << "\"";
1551 }
1552 } else {
1553 BOOST_LOG_TRIVIAL(trace) << "A new " << presets->name() << " preset \"" << preset_name << "\" was imported from user Config Bundle \"" << path << "\"";
1554 }
1555 }
1556 // Decide a full path to this .ini file.
1557 auto file_name = boost::algorithm::iends_with(preset_name, ".ini") ? preset_name : preset_name + ".ini";
1558 auto file_path = (boost::filesystem::path(data_dir())
1559#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
1560 // Store the print/filament/printer presets into a "presets" directory.
1561 / "presets"
1562#else
1563 // Store the print/filament/printer presets at the same location as the upstream Slic3r.
1564#endif
1565 / presets->section_name() / file_name).make_preferred();
1566 // Load the preset into the list of presets, save it to disk.
1567 Preset &loaded = presets->load_preset(file_path.string(), preset_name, std::move(config), false);
1569 loaded.save();
1571 loaded.is_system = true;
1572 loaded.vendor = vendor_profile;
1573 }
1574
1575 // Derive the profile logical name aka alias from the preset name if the alias was not stated explicitely.
1576 if (alias_name.empty()) {
1577 size_t end_pos = preset_name.find_first_of("@");
1578 if (end_pos != std::string::npos) {
1579 alias_name = preset_name.substr(0, end_pos);
1580 if (renamed_from.empty())
1581 // Add the preset name with the '@' character removed into the "renamed_from" list.
1582 renamed_from.emplace_back(alias_name + preset_name.substr(end_pos + 1));
1583 boost::trim_right(alias_name);
1584 }
1585 }
1586 if (alias_name.empty())
1587 loaded.alias = preset_name;
1588 else
1589 loaded.alias = std::move(alias_name);
1590 loaded.renamed_from = std::move(renamed_from);
1591 if (! substitution_context.empty())
1592 substitutions.push_back({
1593 preset_name, presets->type(), PresetConfigSubstitutions::Source::ConfigBundle,
1594 std::string(), std::move(substitution_context.substitutions) });
1595 ++ presets_loaded;
1596 }
1597
1598 if (ph_printers != nullptr) {
1599 // Load the physical printer
1600 const DynamicPrintConfig& default_config = ph_printers->default_config();
1601 DynamicPrintConfig config = default_config;
1602
1603 substitution_context.substitutions.clear();
1604 try {
1605 for (auto& kvp : section.second)
1606 config.set_deserialize(kvp.first, kvp.second.data(), substitution_context);
1607 } catch (const ConfigurationError &e) {
1608 throw ConfigurationError(format("Invalid configuration bundle \"%1%\", section [%2%]: ", path, section.first) + e.what());
1609 }
1610
1611 // Report configuration fields, which are misplaced into a wrong group.
1612 std::string incorrect_keys = Preset::remove_invalid_keys(config, default_config);
1613 if (!incorrect_keys.empty())
1614 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The physical printer \"" <<
1615 section.first << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
1616
1617 const PhysicalPrinter* ph_printer_existing = ph_printers->find_printer(ph_printer_name, false);
1618 if (ph_printer_existing != nullptr) {
1619 BOOST_LOG_TRIVIAL(error) << "Error in a Vendor Config Bundle \"" << path << "\": The physical printer \"" <<
1620 section.first << "\" has already been loaded from another Confing Bundle.";
1621 continue;
1622 }
1623
1624 // Decide a full path to this .ini file.
1625 auto file_name = boost::algorithm::iends_with(ph_printer_name, ".ini") ? ph_printer_name : ph_printer_name + ".ini";
1626 auto file_path = (boost::filesystem::path(data_dir())
1627#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
1628 // Store the physical printers into a "presets" directory.
1629 / "presets"
1630#else
1631 // Store the physical printers at the same location as the upstream Slic3r.
1632#endif
1633 / "physical_printer" / file_name).make_preferred();
1634 // Load the preset into the list of presets, save it to disk.
1635 ph_printers->load_printer(file_path.string(), ph_printer_name, std::move(config), false, flags.has(LoadConfigBundleAttribute::SaveImported));
1636 if (! substitution_context.empty())
1637 substitutions.push_back({
1639 std::string(), std::move(substitution_context.substitutions) });
1640 ++ ph_printers_loaded;
1641 }
1642 }
1643
1644 // 3) Activate the presets and physical printer if any exists.
1645 if (! flags.has(LoadConfigBundleAttribute::LoadSystem)) {
1646 if (! active_print.empty())
1647 prints.select_preset_by_name(active_print, true);
1648 if (! active_sla_print.empty())
1649 sla_prints.select_preset_by_name(active_sla_print, true);
1650 if (! active_sla_material.empty())
1651 sla_materials.select_preset_by_name(active_sla_material, true);
1652 if (! active_printer.empty())
1653 printers.select_preset_by_name(active_printer, true);
1654 if (! active_physical_printer.empty())
1655 physical_printers.select_printer(active_physical_printer, active_printer);
1656 // Activate the first filament preset.
1657 if (! active_filaments.empty() && ! active_filaments.front().empty())
1658 filaments.select_preset_by_name(active_filaments.front(), true);
1659
1660 // Extruder_filaments have to be recreated with new loaded filaments
1661 this->extruders_filaments.clear();
1663 for (size_t i = 0; i < std::min(this->extruders_filaments.size(), active_filaments.size()); ++ i)
1664 this->extruders_filaments[i].select_filament(filaments.find_preset(active_filaments[i], true)->name);
1666 }
1667
1668 return std::make_pair(std::move(substitutions), presets_loaded + ph_printers_loaded);
1669}
ObsoletePresets obsolete_presets
Definition PresetBundle.hpp:79
void reset(bool delete_files)
Definition PresetBundle.cpp:137
std::vector< std::string > filaments
Definition PresetBundle.hpp:75
std::vector< std::string > sla_materials
Definition PresetBundle.hpp:76
std::vector< std::string > prints
Definition PresetBundle.hpp:73
std::vector< std::string > printers
Definition PresetBundle.hpp:77
VendorMap vendors
Definition PresetBundle.hpp:70
std::vector< std::string > sla_prints
Definition PresetBundle.hpp:74
bool select_preset_by_name(const std::string &name, bool force)
Definition Preset.cpp:1383
Preset * find_preset(const std::string &name, bool first_visible_if_not_found=false, bool respect_active_preset=true)
Definition Preset.cpp:1164
std::string name
Definition Preset.hpp:147
static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config)
Definition Preset.cpp:311
@ TYPE_PHYSICAL_PRINTER
Definition Preset.hpp:120
static VendorProfile from_ini(const boost::filesystem::path &path, bool load_all=true)
Definition Preset.cpp:76
bool unescape_strings_cstyle(const std::string &str, std::vector< std::string > &out)
Definition Config.cpp:130
std::vector< PresetConfigSubstitutions > PresetsConfigSubstitutions
Definition Preset.hpp:280
static void flatten_configbundle_hierarchy(boost::property_tree::ptree &tree, const std::string &group_name, const std::vector< std::string > &system_profiles)
Definition PresetBundle.cpp:1190
constexpr auto data(C &c) -> decltype(c.data())
Definition span.hpp:195

References Slic3r::Preset::alias, Slic3r::ConfigBase::apply(), Slic3r::DynamicConfig::clear(), Slic3r::Preset::config, Slic3r::PresetConfigSubstitutions::ConfigBundle, Slic3r::data_dir(), Slic3r::PhysicalPrinterCollection::default_config(), Slic3r::PresetCollection::default_preset(), Slic3r::PresetCollection::default_preset_for(), error, filaments, Slic3r::PresetBundle::ObsoletePresets::filaments, Slic3r::PresetCollection::find_preset(), Slic3r::PhysicalPrinterCollection::find_printer(), Slic3r::flatten_configbundle_hierarchy(), Slic3r::format(), Slic3r::VendorProfile::from_ini(), Slic3r::enum_bitmask< option_type, typename >::has(), Slic3r::VendorProfile::id, Slic3r::Preset::is_system, Slic3r::PresetCollection::load_preset(), Slic3r::PhysicalPrinterCollection::load_printer(), LoadSystem, LoadVendorOnly, Slic3r::VendorProfile::models, Slic3r::VendorProfile::name, Slic3r::Preset::name, Slic3r::PresetCollection::name(), Slic3r::Preset::normalize(), Slic3r::VendorProfile::num_variants(), obsolete_presets, Slic3r::ConfigBase::opt_string(), physical_printers, printers, Slic3r::PresetBundle::ObsoletePresets::printers, prints, Slic3r::PresetBundle::ObsoletePresets::prints, Slic3r::Preset::remove_invalid_keys(), Slic3r::Preset::renamed_from, reset(), ResetUserProfile, Slic3r::Preset::save(), SaveImported, Slic3r::PresetCollection::section_name(), Slic3r::ConfigBase::set_deserialize(), sla_materials, Slic3r::PresetBundle::ObsoletePresets::sla_materials, sla_prints, Slic3r::PresetBundle::ObsoletePresets::sla_prints, Slic3r::VendorProfile::templates_profile, Slic3r::PresetCollection::type(), Slic3r::Preset::TYPE_PHYSICAL_PRINTER, Slic3r::unescape_strings_cstyle(), Slic3r::Preset::vendor, and vendors.

Referenced by load_config_file_config_bundle(), load_system_presets(), Slic3r::PresetUpdater::priv::perform_updates(), and Slic3r::GUI::Config::SnapshotDB::take_snapshot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_installed_filaments()

void Slic3r::PresetBundle::load_installed_filaments ( AppConfig config)
private
545{
546 if (! config.has_section(AppConfig::SECTION_FILAMENTS)) {
547 // Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet.
548 // Find all filament profiles, which are compatible with installed printers, and act as if these filament profiles
549 // were installed.
550 std::unordered_set<const Preset*> compatible_filaments;
551 for (const Preset &printer : printers)
552 if (printer.is_visible && printer.printer_technology() == ptFFF) {
553 const PresetWithVendorProfile printer_with_vendor_profile = printers.get_preset_with_vendor_profile(printer);
554 for (const Preset &filament : filaments)
555 if (filament.is_system && is_compatible_with_printer(filaments.get_preset_with_vendor_profile(filament), printer_with_vendor_profile))
556 compatible_filaments.insert(&filament);
557 }
558 // and mark these filaments as installed, therefore this code will not be executed at the next start of the application.
559 for (const auto &filament: compatible_filaments)
560 config.set(AppConfig::SECTION_FILAMENTS, filament->name, "1");
561 }
562
563 for (auto &preset : filaments)
564 preset.set_visible_from_appconfig(config);
565}
static const std::string SECTION_FILAMENTS
Definition AppConfig.hpp:171
PresetWithVendorProfile get_preset_with_vendor_profile(const Preset &preset) const
Definition Preset.cpp:1122
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config)
Definition Preset.cpp:361

References filaments, Slic3r::PresetCollection::get_preset_with_vendor_profile(), Slic3r::AppConfig::has_section(), Slic3r::is_compatible_with_printer(), printers, Slic3r::ptFFF, Slic3r::AppConfig::SECTION_FILAMENTS, and Slic3r::AppConfig::set().

Referenced by load_selections().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_installed_printers()

void Slic3r::PresetBundle::load_installed_printers ( const AppConfig config)
422{
423 this->update_system_maps();
424 for (auto &preset : printers)
425 preset.set_visible_from_appconfig(config);
426}
void update_system_maps()
Definition PresetBundle.cpp:396

References printers, and update_system_maps().

Referenced by load_selections().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_installed_sla_materials()

void Slic3r::PresetBundle::load_installed_sla_materials ( AppConfig config)
private
568{
569 if (! config.has_section(AppConfig::SECTION_MATERIALS)) {
570 std::unordered_set<const Preset*> comp_sla_materials;
571 // Compatibility with the PrusaSlicer 2.1.1 and older, where the SLA material profiles were not installable yet.
572 // Find all SLA material profiles, which are compatible with installed printers, and act as if these SLA material profiles
573 // were installed.
574 for (const Preset &printer : printers)
575 if (printer.is_visible && printer.printer_technology() == ptSLA) {
576 const PresetWithVendorProfile printer_with_vendor_profile = printers.get_preset_with_vendor_profile(printer);
577 for (const Preset &material : sla_materials)
578 if (material.is_system && is_compatible_with_printer(sla_materials.get_preset_with_vendor_profile(material), printer_with_vendor_profile))
579 comp_sla_materials.insert(&material);
580 }
581 // and mark these SLA materials as installed, therefore this code will not be executed at the next start of the application.
582 for (const auto &material: comp_sla_materials)
583 config.set(AppConfig::SECTION_MATERIALS, material->name, "1");
584 }
585
586 for (auto &preset : sla_materials)
587 preset.set_visible_from_appconfig(config);
588}
static const std::string SECTION_MATERIALS
Definition AppConfig.hpp:172

References Slic3r::PresetCollection::get_preset_with_vendor_profile(), Slic3r::AppConfig::has_section(), Slic3r::is_compatible_with_printer(), printers, Slic3r::ptSLA, Slic3r::AppConfig::SECTION_MATERIALS, Slic3r::AppConfig::set(), and sla_materials.

Referenced by load_selections().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_presets()

PresetsConfigSubstitutions Slic3r::PresetBundle::load_presets ( AppConfig config,
ForwardCompatibilitySubstitutionRule  rule,
const PresetPreferences preferred_selection = PresetPreferences() 
)
264{
265 // First load the vendor specific system presets.
266 PresetsConfigSubstitutions substitutions;
267 std::string errors_cummulative;
268 std::tie(substitutions, errors_cummulative) = this->load_system_presets(substitution_rule);
269
270 const std::string& dir_user_presets = data_dir()
271#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
272 // Store the print/filament/printer presets into a "presets" directory.
273 + "/presets"
274#else
275 // Store the print/filament/printer presets at the same location as the upstream Slic3r.
276#endif
277 ;
278
279 try {
280 this->prints.load_presets(dir_user_presets, "print", substitutions, substitution_rule);
281 } catch (const std::runtime_error &err) {
282 errors_cummulative += err.what();
283 }
284 try {
285 this->sla_prints.load_presets(dir_user_presets, "sla_print", substitutions, substitution_rule);
286 } catch (const std::runtime_error &err) {
287 errors_cummulative += err.what();
288 }
289 try {
290 this->filaments.load_presets(dir_user_presets, "filament", substitutions, substitution_rule);
291 } catch (const std::runtime_error &err) {
292 errors_cummulative += err.what();
293 }
294 try {
295 this->sla_materials.load_presets(dir_user_presets, "sla_material", substitutions, substitution_rule);
296 } catch (const std::runtime_error &err) {
297 errors_cummulative += err.what();
298 }
299 try {
300 this->printers.load_presets(dir_user_presets, "printer", substitutions, substitution_rule);
301 } catch (const std::runtime_error &err) {
302 errors_cummulative += err.what();
303 }
304 try {
305 this->physical_printers.load_printers(dir_user_presets, "physical_printer", substitutions, substitution_rule);
306 } catch (const std::runtime_error &err) {
307 errors_cummulative += err.what();
308 }
311 if (! errors_cummulative.empty())
312 throw Slic3r::RuntimeError(errors_cummulative);
313
314 this->load_selections(config, preferred_selection);
315
316 return substitutions;
317}
void load_printers(const std::string &dir_path, const std::string &subdir, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule)
Definition Preset.cpp:1757
std::pair< PresetsConfigSubstitutions, std::string > load_system_presets(ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition PresetBundle.cpp:321
void load_selections(AppConfig &config, const PresetPreferences &preferred_selection=PresetPreferences())
Definition PresetBundle.cpp:592
void load_presets(const std::string &dir_path, const std::string &subdir, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule)
Definition Preset.cpp:680

References Slic3r::data_dir(), filaments, Slic3r::PresetCollection::load_presets(), Slic3r::PhysicalPrinterCollection::load_printers(), load_selections(), load_system_presets(), Slic3r::Never, physical_printers, printers, prints, sla_materials, sla_prints, update_compatible(), and update_multi_material_filament_presets().

Referenced by Slic3r::GUI::GUI_App::add_config_menu(), and Slic3r::GUI::ConfigWizard::priv::apply_config().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_selections()

void Slic3r::PresetBundle::load_selections ( AppConfig config,
const PresetPreferences preferred_selection = PresetPreferences() 
)
private
593{
594 // Update visibility of presets based on application vendor / model / variant configuration.
595 this->load_installed_printers(config);
596
597 // Update visibility of filament and sla material presets
598 this->load_installed_filaments(config);
599 this->load_installed_sla_materials(config);
600
601 // Parse the initial print / filament / printer profile names.
602 std::string initial_print_profile_name = remove_ini_suffix(config.get("presets", "print"));
603 std::string initial_sla_print_profile_name = remove_ini_suffix(config.get("presets", "sla_print"));
604 std::string initial_filament_profile_name = remove_ini_suffix(config.get("presets", "filament"));
605 std::string initial_sla_material_profile_name = remove_ini_suffix(config.get("presets", "sla_material"));
606 std::string initial_printer_profile_name = remove_ini_suffix(config.get("presets", "printer"));
607
608 // Activate print / filament / printer profiles from either the config,
609 // or from the preferred_model_id suggestion passed in by ConfigWizard.
610 // If the printer profile enumerated by the config are not visible, select an alternate preset.
611 // Do not select alternate profiles for the print / filament profiles as those presets
612 // will be selected by the following call of this->update_compatible(PresetSelectCompatibleType::Always).
613
614 const Preset *initial_printer = printers.find_preset(initial_printer_profile_name);
615 // If executed due to a Config Wizard update, preferred_printer contains the first newly installed printer, otherwise nullptr.
616 const Preset *preferred_printer = printers.find_system_preset_by_model_and_variant(preferred_selection.printer_model_id, preferred_selection.printer_variant);
617 printers.select_preset_by_name(preferred_printer ? preferred_printer->name : initial_printer_profile_name, true);
618
619 // Selects the profile, leaves it to -1 if the initial profile name is empty or if it was not found.
620 prints.select_preset_by_name_strict(initial_print_profile_name);
621 filaments.select_preset_by_name_strict(initial_filament_profile_name);
622 sla_prints.select_preset_by_name_strict(initial_sla_print_profile_name);
623 sla_materials.select_preset_by_name_strict(initial_sla_material_profile_name);
624
625 // Load the names of the other filament profiles selected for a multi-material printer.
626 // Load it even if the current printer technology is SLA.
627 // The possibly excessive filament names will be later removed with this->update_multi_material_filament_presets()
628 // once the FFF technology gets selected.
629 this->extruders_filaments.clear();
630 this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments));
631 for (unsigned int i = 1; i < 1000; ++ i) {
632 char name[64];
633 sprintf(name, "filament_%u", i);
634 if (! config.has("presets", name))
635 break;
636 this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments, i, remove_ini_suffix(config.get("presets", name))));
637 }
638
639 // ! update MM filaments presets before update compatibility
641 // Update visibility of presets based on their compatibility with the active printer.
642 // Always try to select a compatible print and filament preset to the current printer preset,
643 // as the application may have been closed with an active "external" preset, which does not
644 // exist.
646
647 if (initial_printer != nullptr && (preferred_printer == nullptr || initial_printer == preferred_printer)) {
648 // Don't run the following code, as we want to activate default filament / SLA material profiles when installing and selecting a new printer.
649 // Only run this code if just a filament / SLA material was installed by Config Wizard for an active Printer.
651 if (printer_technology == ptFFF && ! preferred_selection.filament.empty()) {
652 const std::string& preferred_preset_name = get_preset_name_by_alias(Preset::Type::TYPE_FILAMENT, preferred_selection.filament, 0);
653 if (auto it = filaments.find_preset_internal(preferred_preset_name);
654 it != filaments.end() && it->is_visible && it->is_compatible) {
655 filaments.select_preset_by_name_strict(preferred_preset_name);
656 this->extruders_filaments.front().select_filament(filaments.get_selected_preset_name());
657 }
658 } else if (printer_technology == ptSLA && ! preferred_selection.sla_material.empty()) {
659 const std::string& preferred_preset_name = get_preset_name_by_alias(Preset::Type::TYPE_SLA_MATERIAL, preferred_selection.sla_material);
660 if (auto it = sla_materials.find_preset_internal(preferred_preset_name);
661 it != sla_materials.end() && it->is_visible && it->is_compatible)
662 sla_materials.select_preset_by_name_strict(preferred_preset_name);
663 }
664 }
665
666 // Parse the initial physical printer name.
667 std::string initial_physical_printer_name = remove_ini_suffix(config.get("presets", "physical_printer"));
668
669 // Activate physical printer from the config
670 if (!initial_physical_printer_name.empty())
671 physical_printers.select_printer(initial_physical_printer_name);
672}
void load_installed_printers(const AppConfig &config)
Definition PresetBundle.cpp:421
const std::string & get_preset_name_by_alias(const Preset::Type &preset_type, const std::string &alias, int extruder_id=-1)
Definition PresetBundle.cpp:458
void load_installed_sla_materials(AppConfig &config)
Definition PresetBundle.cpp:567
void load_installed_filaments(AppConfig &config)
Definition PresetBundle.cpp:544
std::deque< Preset >::iterator find_preset_internal(const std::string &name)
Definition Preset.hpp:541
Iterator end()
Definition Preset.hpp:294
bool select_preset_by_name_strict(const std::string &name)
Definition Preset.cpp:1411
const Preset * find_system_preset_by_model_and_variant(const std::string &model_id, const std::string &variant) const
Definition Preset.cpp:1538
static std::string remove_ini_suffix(const std::string &name)
Definition PresetBundle.cpp:410

References Slic3r::Always, Slic3r::PresetCollection::end(), extruders_filaments, Slic3r::PresetBundle::PresetPreferences::filament, filaments, Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset_internal(), Slic3r::PrinterPresetCollection::find_system_preset_by_model_and_variant(), Slic3r::AppConfig::get(), get_preset_name_by_alias(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::AppConfig::has(), load_installed_filaments(), load_installed_printers(), load_installed_sla_materials(), Slic3r::Preset::name, physical_printers, Slic3r::PresetBundle::PresetPreferences::printer_model_id, Slic3r::printer_technology(), Slic3r::Preset::printer_technology(), Slic3r::PresetBundle::PresetPreferences::printer_variant, printers, prints, Slic3r::ptFFF, Slic3r::ptSLA, Slic3r::remove_ini_suffix(), Slic3r::PresetCollection::select_preset_by_name(), Slic3r::PresetCollection::select_preset_by_name_strict(), Slic3r::PhysicalPrinterCollection::select_printer(), Slic3r::PresetBundle::PresetPreferences::sla_material, sla_materials, sla_prints, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_SLA_MATERIAL, update_compatible(), and update_multi_material_filament_presets().

Referenced by load_presets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ load_system_presets()

std::pair< PresetsConfigSubstitutions, std::string > Slic3r::PresetBundle::load_system_presets ( ForwardCompatibilitySubstitutionRule  compatibility_rule)
private
322{
324 // Loading system presets, don't log substitutions.
327 // Loading system presets, throw on unknown option value.
329
330 // Here the vendor specific read only Config Bundles are stored.
331 boost::filesystem::path dir = (boost::filesystem::path(data_dir()) / "vendor").make_preferred();
332 PresetsConfigSubstitutions substitutions;
333 std::string errors_cummulative;
334 bool first = true;
335 for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
336 if (Slic3r::is_ini_file(dir_entry)) {
337 std::string name = dir_entry.path().filename().string();
338 // Remove the .ini suffix.
339 name.erase(name.size() - 4);
340 try {
341 // Load the config bundle, flatten it.
342 if (first) {
343 // Reset this PresetBundle and load the first vendor config.
344 append(substitutions, this->load_configbundle(dir_entry.path().string(), PresetBundle::LoadSystem, compatibility_rule).first);
345 first = false;
346 } else {
347 // Load the other vendor configs, merge them with this PresetBundle.
348 // Report duplicate profiles.
349 PresetBundle other;
350 append(substitutions, other.load_configbundle(dir_entry.path().string(), PresetBundle::LoadSystem, compatibility_rule).first);
351 std::vector<std::string> duplicates = this->merge_presets(std::move(other));
352 if (! duplicates.empty()) {
353 errors_cummulative += "Vendor configuration file " + name + " contains the following presets with names used by other vendors: ";
354 for (size_t i = 0; i < duplicates.size(); ++ i) {
355 if (i > 0)
356 errors_cummulative += ", ";
357 errors_cummulative += duplicates[i];
358 }
359 }
360 }
361 } catch (const std::runtime_error &err) {
362 errors_cummulative += err.what();
363 errors_cummulative += "\n";
364 }
365 }
366 if (first) {
367 // No config bundle loaded, reset.
368 this->reset(false);
369 }
370
371 this->update_system_maps();
372 return std::make_pair(std::move(substitutions), errors_cummulative);
373}
std::pair< PresetsConfigSubstitutions, size_t > load_configbundle(const std::string &path, LoadConfigBundleAttributes flags, ForwardCompatibilitySubstitutionRule compatibility_rule)
Definition PresetBundle.cpp:1326
std::vector< std::string > merge_presets(PresetBundle &&other)
Definition PresetBundle.cpp:376
Definition avrdude-slic3r.cpp:16
@ Disable
Definition Config.hpp:219
@ EnableSystemSilent
Definition Config.hpp:225
@ EnableSilent
Definition Config.hpp:223
@ EnableSilentDisableSystem
Definition Config.hpp:227
bool is_ini_file(const boost::filesystem::directory_entry &dir_entry)
Definition utils.cpp:773
Definition args.hpp:18

References Slic3r::append(), Slic3r::data_dir(), Slic3r::Disable, Slic3r::EnableSilent, Slic3r::EnableSilentDisableSystem, Slic3r::EnableSystemSilent, Slic3r::is_ini_file(), load_configbundle(), LoadSystem, merge_presets(), reset(), and update_system_maps().

Referenced by load_presets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ materials() [1/2]

PresetCollection & Slic3r::PresetBundle::materials ( PrinterTechnology  pt)
inline
50{ return pt == ptFFF ? this->filaments : this->sla_materials; }

References filaments, Slic3r::ptFFF, and sla_materials.

◆ materials() [2/2]

const PresetCollection & Slic3r::PresetBundle::materials ( PrinterTechnology  pt) const
inline
51{ return pt == ptFFF ? this->filaments : this->sla_materials; }

References filaments, Slic3r::ptFFF, and sla_materials.

◆ merge_presets()

std::vector< std::string > Slic3r::PresetBundle::merge_presets ( PresetBundle &&  other)
private
377{
378 this->vendors.insert(other.vendors.begin(), other.vendors.end());
379 std::vector<std::string> duplicate_prints = this->prints .merge_presets(std::move(other.prints), this->vendors);
380 std::vector<std::string> duplicate_sla_prints = this->sla_prints .merge_presets(std::move(other.sla_prints), this->vendors);
381 std::vector<std::string> duplicate_filaments = this->filaments .merge_presets(std::move(other.filaments), this->vendors);
382 std::vector<std::string> duplicate_sla_materials = this->sla_materials.merge_presets(std::move(other.sla_materials), this->vendors);
383 std::vector<std::string> duplicate_printers = this->printers .merge_presets(std::move(other.printers), this->vendors);
384 append(this->obsolete_presets.prints, std::move(other.obsolete_presets.prints));
385 append(this->obsolete_presets.sla_prints, std::move(other.obsolete_presets.sla_prints));
386 append(this->obsolete_presets.filaments, std::move(other.obsolete_presets.filaments));
387 append(this->obsolete_presets.sla_materials, std::move(other.obsolete_presets.sla_materials));
388 append(this->obsolete_presets.printers, std::move(other.obsolete_presets.printers));
389 append(duplicate_prints, std::move(duplicate_sla_prints));
390 append(duplicate_prints, std::move(duplicate_filaments));
391 append(duplicate_prints, std::move(duplicate_sla_materials));
392 append(duplicate_prints, std::move(duplicate_printers));
393 return duplicate_prints;
394}
std::vector< std::string > merge_presets(PresetCollection &&other, const VendorMap &new_vendors)
Definition Preset.cpp:1429

References Slic3r::append(), filaments, Slic3r::PresetBundle::ObsoletePresets::filaments, Slic3r::PresetCollection::merge_presets(), obsolete_presets, printers, Slic3r::PresetBundle::ObsoletePresets::printers, prints, Slic3r::PresetBundle::ObsoletePresets::prints, sla_materials, Slic3r::PresetBundle::ObsoletePresets::sla_materials, sla_prints, Slic3r::PresetBundle::ObsoletePresets::sla_prints, and vendors.

Referenced by load_system_presets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=()

PresetBundle & Slic3r::PresetBundle::operator= ( const PresetBundle rhs)
114{
115 prints = rhs.prints;
116 sla_prints = rhs.sla_prints;
117 filaments = rhs.filaments;
118 sla_materials = rhs.sla_materials;
119 printers = rhs.printers;
120 physical_printers = rhs.physical_printers;
121
122 extruders_filaments = rhs.extruders_filaments;
123 project_config = rhs.project_config;
124 vendors = rhs.vendors;
125 obsolete_presets = rhs.obsolete_presets;
126
127 // Adjust Preset::vendor pointers to point to the copied vendors map.
133
134 return *this;
135}
void update_vendor_ptrs_after_copy(const VendorMap &vendors)
Definition Preset.cpp:1451

References extruders_filaments, filaments, obsolete_presets, physical_printers, printers, prints, project_config, sla_materials, sla_prints, Slic3r::PresetCollection::update_vendor_ptrs_after_copy(), and vendors.

+ Here is the call graph for this function:

◆ reset()

void Slic3r::PresetBundle::reset ( bool  delete_files)
138{
139 // Clear the existing presets, delete their respective files.
140 this->vendors.clear();
141 this->prints .reset(delete_files);
142 this->sla_prints .reset(delete_files);
143 this->filaments .reset(delete_files);
144 this->sla_materials.reset(delete_files);
145 this->printers .reset(delete_files);
146 this->extruders_filaments.clear();
147 this->obsolete_presets.prints.clear();
148 this->obsolete_presets.sla_prints.clear();
149 this->obsolete_presets.filaments.clear();
150 this->obsolete_presets.sla_materials.clear();
151 this->obsolete_presets.printers.clear();
152}
void reset(bool delete_files)
Definition Preset.cpp:652

References extruders_filaments, filaments, Slic3r::PresetBundle::ObsoletePresets::filaments, obsolete_presets, printers, Slic3r::PresetBundle::ObsoletePresets::printers, prints, Slic3r::PresetBundle::ObsoletePresets::prints, Slic3r::PresetCollection::reset(), sla_materials, Slic3r::PresetBundle::ObsoletePresets::sla_materials, sla_prints, Slic3r::PresetBundle::ObsoletePresets::sla_prints, and vendors.

Referenced by Slic3r::GUI::ConfigWizard::priv::apply_config(), load_configbundle(), and load_system_presets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset_extruder_filaments()

void Slic3r::PresetBundle::reset_extruder_filaments ( )
435{
436 // save previously cached selected names
437 std::vector<std::string> names;
438 for (const ExtruderFilaments& extr_filaments : extruders_filaments)
439 names.push_back(extr_filaments.get_cached_selected_name());
440
441 // Reset extruder_filaments and set names
442 this->extruders_filaments.clear();
443 for (size_t id = 0; id < names.size(); ++id)
444 this->extruders_filaments.emplace_back(ExtruderFilaments(&filaments, id, names[id]));
445}

References extruders_filaments, and filaments.

Referenced by save_changes_for_preset().

+ Here is the caller graph for this function:

◆ save_changes_for_preset()

void Slic3r::PresetBundle::save_changes_for_preset ( const std::string &  new_name,
Preset::Type  type,
const std::vector< std::string > &  unselected_options 
)
474{
475 PresetCollection& presets = get_presets(type);
476
477 // if we want to save just some from selected options
478 if (!unselected_options.empty()) {
479 // revert unselected options to the old values
480 presets.get_edited_preset().config.apply_only(presets.get_selected_preset().config, unselected_options);
481 }
482
483 if (type == Preset::TYPE_PRINTER)
484 copy_bed_model_and_texture_if_needed(presets.get_edited_preset().config);
485
486 if (type == Preset::TYPE_FILAMENT)
488 // Save the preset into Slic3r::data_dir / presets / section_name / preset_name.ini
489 if (presets.save_current_preset(new_name) && type == Preset::TYPE_FILAMENT)
491 // Mark the print & filament enabled if they are compatible with the currently selected preset.
492 // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible.
494
495 if (type == Preset::TYPE_FILAMENT) {
496 // synchronize the first filament presets.
498 }
499}
void set_filament_preset(size_t idx, const std::string &name)
Definition PresetBundle.cpp:1956
void cache_extruder_filaments_names()
Definition PresetBundle.cpp:428
void reset_extruder_filaments()
Definition PresetBundle.cpp:434
void copy_bed_model_and_texture_if_needed(DynamicPrintConfig &config)
Definition PresetBundle.cpp:1974

References Slic3r::ConfigBase::apply_only(), cache_extruder_filaments_names(), Slic3r::Preset::config, Slic3r::copy_bed_model_and_texture_if_needed(), filaments, Slic3r::PresetCollection::get_edited_preset(), get_presets(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::Never, reset_extruder_filaments(), Slic3r::PresetCollection::save_current_preset(), set_filament_preset(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINTER, and update_compatible().

Referenced by Slic3r::GUI::GUI_App::check_and_keep_current_preset_changes(), and Slic3r::GUI::GUI_App::check_and_save_current_preset_changes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_default_suppressed()

void Slic3r::PresetBundle::set_default_suppressed ( bool  default_suppressed)
1966{
1967 prints.set_default_suppressed(default_suppressed);
1968 filaments.set_default_suppressed(default_suppressed);
1969 sla_prints.set_default_suppressed(default_suppressed);
1970 sla_materials.set_default_suppressed(default_suppressed);
1971 printers.set_default_suppressed(default_suppressed);
1972}
void set_default_suppressed(bool default_suppressed)
Definition Preset.cpp:1185

◆ set_filament_preset()

void Slic3r::PresetBundle::set_filament_preset ( size_t  idx,
const std::string &  name 
)
1957{
1958 if (idx >= extruders_filaments.size()) {
1959 for (size_t id = extruders_filaments.size(); id < idx; id++)
1960 extruders_filaments.emplace_back(ExtruderFilaments(&filaments, id, filaments.default_preset().name));
1961 }
1962 extruders_filaments[idx].select_filament(Preset::remove_suffix_modified(name));
1963}
static std::string remove_suffix_modified(const std::string &name)
Definition Preset.cpp:258

Referenced by save_changes_for_preset(), and transfer_and_save().

+ Here is the caller graph for this function:

◆ setup_directories()

void Slic3r::PresetBundle::setup_directories ( )
155{
156 boost::filesystem::path data_dir = boost::filesystem::path(Slic3r::data_dir());
157 std::initializer_list<boost::filesystem::path> paths = {
158 data_dir,
159 data_dir / "vendor",
160 data_dir / "cache",
161 data_dir / "cache" / "vendor",
162 data_dir / "shapes",
163#ifdef SLIC3R_PROFILE_USE_PRESETS_SUBDIR
164 // Store the print/filament/printer presets into a "presets" directory.
165 data_dir / "presets",
166 data_dir / "presets" / "print",
167 data_dir / "presets" / "filament",
168 data_dir / "presets" / "sla_print",
169 data_dir / "presets" / "sla_material",
170 data_dir / "presets" / "printer",
171 data_dir / "presets" / "physical_printer"
172#else
173 // Store the print/filament/printer presets at the same location as the upstream Slic3r.
174 data_dir / "print",
175 data_dir / "filament",
176 data_dir / "sla_print",
177 data_dir / "sla_material",
178 data_dir / "printer",
179 data_dir / "physical_printer"
180#endif
181 };
182 for (const boost::filesystem::path &path : paths) {
183 boost::filesystem::path subdir = path;
184 subdir.make_preferred();
185 if (! boost::filesystem::is_directory(subdir) &&
186 ! boost::filesystem::create_directory(subdir))
187 throw Slic3r::RuntimeError(std::string("Slic3r was unable to create its data directory at ") + subdir.string());
188 }
189}

References Slic3r::data_dir().

Referenced by Slic3r::GUI::GUI_App::on_init_inner().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ transfer_and_save()

bool Slic3r::PresetBundle::transfer_and_save ( Preset::Type  type,
const std::string &  preset_from_name,
const std::string &  preset_to_name,
const std::string &  new_name,
const std::vector< std::string > &  options 
)
503{
504 if (options.empty())
505 return false;
506
507 PresetCollection& presets = get_presets(type);
508
509 const Preset* preset_to = presets.find_preset(preset_to_name, false, false);
510 if (!preset_to)
511 return false;
512
513 // Find the preset with a new_name or create a new one,
514 // initialize it with the preset_to config.
515 Preset& preset = presets.get_preset_with_name(preset_new_name, preset_to);
516 if (preset.is_default || preset.is_external || preset.is_system)
517 // Cannot overwrite the default preset.
518 return false;
519
520 // Apply options from the preset_from_name.
521 const Preset* preset_from = presets.find_preset(preset_from_name, false, false);
522 if (!preset_from)
523 return false;
524 preset.config.apply_only(preset_from->config, options);
525
526 // Store new_name preset to disk.
527 preset.save();
528
529 // Mark the print & filament enabled if they are compatible with the currently selected preset.
530 // If saving the preset changes compatibility with other presets, keep the now incompatible dependent presets selected, however with a "red flag" icon showing that they are no more compatible.
532
533 if (type == Preset::TYPE_PRINTER)
535
536 if (type == Preset::TYPE_FILAMENT) {
537 // synchronize the first filament presets.
539 }
540
541 return true;
542}

References Slic3r::ConfigBase::apply_only(), Slic3r::Preset::config, Slic3r::copy_bed_model_and_texture_if_needed(), filaments, Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::get_preset_with_name(), get_presets(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::Never, Slic3r::Preset::save(), set_filament_preset(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINTER, and update_compatible().

+ Here is the call graph for this function:

◆ types_list()

static std::array< Preset::Type, 3 > Slic3r::PresetBundle::types_list ( PrinterTechnology  pt)
inlinestatic

References Slic3r::ptFFF, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, Slic3r::Preset::TYPE_SLA_MATERIAL, and Slic3r::Preset::TYPE_SLA_PRINT.

Referenced by Slic3r::GUI::SavePresetDialog::Item::get_existing_preset(), and Slic3r::GUI::DiffPresetDialog::types_list().

+ Here is the caller graph for this function:

◆ update_compatible() [1/2]

void Slic3r::PresetBundle::update_compatible ( PresetSelectCompatibleType  select_other_if_incompatible)
inline
146{ this->update_compatible(select_other_if_incompatible, select_other_if_incompatible); }

References update_compatible().

Referenced by update_compatible().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_compatible() [2/2]

void Slic3r::PresetBundle::update_compatible ( PresetSelectCompatibleType  select_other_print_if_incompatible,
PresetSelectCompatibleType  select_other_filament_if_incompatible 
)
1812{
1813 const Preset &printer_preset = this->printers.get_edited_preset();
1814 const PresetWithVendorProfile printer_preset_with_vendor_profile = this->printers.get_preset_with_vendor_profile(printer_preset);
1815
1816 class PreferedProfileMatch
1817 {
1818 public:
1819 PreferedProfileMatch(const std::string &prefered_alias, const std::string &prefered_name) :
1820 m_prefered_alias(prefered_alias), m_prefered_name(prefered_name) {}
1821
1822 int operator()(const Preset &preset) const
1823 {
1824 return
1825 preset.is_default || preset.is_external ?
1826 // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile.
1827 0 :
1828 ! m_prefered_alias.empty() && m_prefered_alias == preset.alias ?
1829 // Matching an alias, always take this preset with priority.
1830 std::numeric_limits<int>::max() :
1831 // Otherwise take the prefered profile, or the first compatible.
1832 preset.name == m_prefered_name;
1833 }
1834
1835 private:
1836 const std::string m_prefered_alias;
1837 const std::string &m_prefered_name;
1838 };
1839
1840 // Matching by the layer height in addition.
1841 class PreferedPrintProfileMatch : public PreferedProfileMatch
1842 {
1843 public:
1844 PreferedPrintProfileMatch(const Preset *preset, const std::string &prefered_name) :
1845 PreferedProfileMatch(preset ? preset->alias : std::string(), prefered_name), m_prefered_layer_height(preset ? preset->config.opt_float("layer_height") : 0) {}
1846
1847 int operator()(const Preset &preset) const
1848 {
1849 // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile.
1850 if (preset.is_default || preset.is_external)
1851 return 0;
1852 int match_quality = PreferedProfileMatch::operator()(preset);
1853 if (match_quality < std::numeric_limits<int>::max()) {
1854 match_quality += 1;
1855 if (m_prefered_layer_height > 0. && std::abs(preset.config.opt_float("layer_height") - m_prefered_layer_height) < 0.0005)
1856 match_quality *= 10;
1857 }
1858 return match_quality;
1859 }
1860
1861 private:
1862 const double m_prefered_layer_height;
1863 };
1864
1865 switch (printer_preset.printer_technology()) {
1866 case ptFFF:
1867 {
1868 assert(printer_preset.config.has("default_print_profile"));
1869 assert(printer_preset.config.has("default_filament_profile"));
1870
1871 this->prints.update_compatible(printer_preset_with_vendor_profile, nullptr, select_other_print_if_incompatible,
1872 PreferedPrintProfileMatch(this->prints.get_selected_idx() == size_t(-1) ? nullptr : &this->prints.get_edited_preset(), printer_preset.config.opt_string("default_print_profile")));
1873
1874 // Update compatibility for all currently existent extruder_filaments.
1875 update_filaments_compatible(select_other_filament_if_incompatible);
1876
1877 break;
1878 }
1879 case ptSLA:
1880 {
1881 assert(printer_preset.config.has("default_sla_print_profile"));
1882 assert(printer_preset.config.has("default_sla_material_profile"));
1883 this->sla_prints.update_compatible(printer_preset_with_vendor_profile, nullptr, select_other_print_if_incompatible,
1884 PreferedPrintProfileMatch(this->sla_prints.get_selected_idx() == size_t(-1) ? nullptr : &this->sla_prints.get_edited_preset(), printer_preset.config.opt_string("default_sla_print_profile")));
1885 const PresetWithVendorProfile sla_print_preset_with_vendor_profile = this->sla_prints.get_edited_preset_with_vendor_profile();
1886 this->sla_materials.update_compatible(printer_preset_with_vendor_profile, &sla_print_preset_with_vendor_profile, select_other_filament_if_incompatible,
1887 PreferedProfileMatch(this->sla_materials.get_selected_idx() == size_t(-1) ? std::string() : this->sla_materials.get_edited_preset().alias, printer_preset.config.opt_string("default_sla_material_profile")));
1888 break;
1889 }
1890 default: break;
1891 }
1892}
void update_filaments_compatible(PresetSelectCompatibleType select_other_filament_if_incompatible, int extruder_idx=-1)
Definition PresetBundle.cpp:1718
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible, PreferedCondition prefered_condition)
Definition Preset.hpp:464
PresetWithVendorProfile get_edited_preset_with_vendor_profile() const
Definition Preset.hpp:387
size_t get_selected_idx() const
Definition Preset.hpp:367
TOKEN * string(char *text)
Definition config.c:233

References Slic3r::Preset::alias, Slic3r::Preset::config, Slic3r::ConfigOptionResolver::has(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::name, Slic3r::ConfigBase::opt_float(), Slic3r::ConfigBase::opt_string(), Slic3r::Preset::printer_technology(), Slic3r::ptFFF, and Slic3r::ptSLA.

Referenced by Slic3r::GUI::Plater::check_selected_presets_visibility(), load_config_file_config(), load_config_file_config_bundle(), load_presets(), load_selections(), save_changes_for_preset(), transfer_and_save(), and Slic3r::GUI::DiffPresetDialog::update_compatibility().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_filaments_compatible()

void Slic3r::PresetBundle::update_filaments_compatible ( PresetSelectCompatibleType  select_other_filament_if_incompatible,
int  extruder_idx = -1 
)

ysFIXME - delete after testing // First select a first compatible profile for the preset editor. this->filaments.update_compatible(printer_preset_with_vendor_profile, &print_preset_with_vendor_profile, select_other_filament_if_incompatible, PreferedFilamentsProfileMatch(this->filaments.get_selected_idx() == size_t(-1) ? nullptr : &this->filaments.get_edited_preset(), prefered_filament_profiles));

1719{
1720 const Preset& printer_preset = this->printers.get_edited_preset();
1721 const PresetWithVendorProfile printer_preset_with_vendor_profile = this->printers.get_preset_with_vendor_profile(printer_preset);
1722 const PresetWithVendorProfile print_preset_with_vendor_profile = this->prints.get_edited_preset_with_vendor_profile();
1723 const std::vector<std::string>& prefered_filament_profiles = printer_preset.config.option<ConfigOptionStrings>("default_filament_profile")->values;
1724
1725 class PreferedFilamentsProfileMatch
1726 {
1727 public:
1728 PreferedFilamentsProfileMatch(const Preset* preset, const std::vector<std::string>& prefered_names, int extruder_id = 0) :
1729 m_extruder_id(extruder_id),
1730 m_prefered_alias(preset ? preset->alias : std::string()),
1731 m_prefered_filament_type(preset ? preset->config.opt_string("filament_type", extruder_id) : std::string()),
1732 m_prefered_names(prefered_names) {}
1733
1734 int operator()(const Preset& preset) const
1735 {
1736 // Don't match any properties of the "-- default --" profile or the external profiles when switching printer profile.
1737 if (preset.is_default || preset.is_external)
1738 return 0;
1739 if (!m_prefered_alias.empty() && m_prefered_alias == preset.alias)
1740 // Matching an alias, always take this preset with priority.
1741 return std::numeric_limits<int>::max();
1742 int match_quality = (std::find(m_prefered_names.begin(), m_prefered_names.end(), preset.name) != m_prefered_names.end()) + 1;
1743 if (!m_prefered_filament_type.empty() && m_prefered_filament_type == preset.config.opt_string("filament_type", m_extruder_id))
1744 match_quality *= 10;
1745 return match_quality;
1746 }
1747
1748 private:
1749 int m_extruder_id;
1750 const std::string m_prefered_alias;
1751 const std::string m_prefered_filament_type;
1752 const std::vector<std::string>& m_prefered_names;
1753 };
1754
1759
1760 // Update compatible for extruder filaments
1761
1762 auto update_filament_compatible = [this, select_other_filament_if_incompatible, printer_preset_with_vendor_profile, print_preset_with_vendor_profile, prefered_filament_profiles](int idx)
1763 {
1764 ExtruderFilaments& extr_filaments = extruders_filaments[idx];
1765
1766 // Remember whether the filament profiles were compatible before updating the filament compatibility.
1767 bool filament_preset_was_compatible = false;
1768 const Filament* filament_old = extr_filaments.get_selected_filament();
1769 if (select_other_filament_if_incompatible != PresetSelectCompatibleType::Never)
1770 filament_preset_was_compatible = filament_old && filament_old->is_compatible;
1771
1772 extr_filaments.update_compatible(printer_preset_with_vendor_profile, &print_preset_with_vendor_profile, select_other_filament_if_incompatible,
1773 PreferedFilamentsProfileMatch(filament_old ? filament_old->preset : nullptr, prefered_filament_profiles, idx));
1774
1775 const Filament* filament = extr_filaments.get_selected_filament();
1776 const bool is_compatible = filament && filament->is_compatible;
1777
1778 if (is_compatible || select_other_filament_if_incompatible == PresetSelectCompatibleType::Never)
1779 return;
1780
1781 // Verify validity of the current filament presets.
1782 if (this->extruders_filaments.size() == 1) {
1783 // The compatible profile should have been already selected for the preset editor. Just use it.
1784 if (select_other_filament_if_incompatible == PresetSelectCompatibleType::Always || filament_preset_was_compatible)
1785 extr_filaments.select_filament(this->filaments.get_edited_preset().name);
1786 }
1787 else {
1788 const std::string filament_name = extr_filaments.get_selected_preset_name();
1789 if (!filament || (!is_compatible && (select_other_filament_if_incompatible == PresetSelectCompatibleType::Always || filament_preset_was_compatible))) {
1790 // Pick a compatible profile. If there are prefered_filament_profiles, use them.
1791 std::string compat_filament_name = extr_filaments.first_compatible(PreferedFilamentsProfileMatch(filament->preset, prefered_filament_profiles, idx))->name;
1792 if (filament_name != compat_filament_name)
1793 extr_filaments.select_filament(compat_filament_name);
1794 }
1795 }
1796 };
1797
1798 if (extruder_idx < 0) {
1799 // update compatibility for all extruders
1800 const size_t num_extruders = static_cast<const ConfigOptionFloats*>(printer_preset.config.option("nozzle_diameter"))->values.size();
1801 for (size_t idx = 0; idx < std::min(this->extruders_filaments.size(), num_extruders); idx++)
1802 update_filament_compatible(idx);
1803 }
1804 else
1805 update_filament_compatible(extruder_idx);
1806
1807 if (this->filaments.get_idx_selected() == size_t(-1))
1808 this->filaments.select_preset(extruders_filaments[0].get_selected_idx());
1809}
size_t get_idx_selected()
Definition Preset.hpp:394

References Slic3r::Preset::alias, Slic3r::Preset::config, Slic3r::ExtruderFilaments::first_compatible(), Slic3r::ExtruderFilaments::get_selected_filament(), Slic3r::ExtruderFilaments::get_selected_preset_name(), Slic3r::Filament::is_compatible, Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::name, Slic3r::ConfigBase::opt_string(), Slic3r::ConfigBase::option(), Slic3r::Filament::preset, Slic3r::ExtruderFilaments::select_filament(), Slic3r::ConfigOptionVector< T >::size(), and Slic3r::ExtruderFilaments::update_compatible().

+ Here is the call graph for this function:

◆ update_multi_material_filament_presets()

void Slic3r::PresetBundle::update_multi_material_filament_presets ( )
1672{
1674 return;
1675
1676 // Verify and select the filament presets.
1677 auto *nozzle_diameter = static_cast<const ConfigOptionFloats*>(printers.get_edited_preset().config.option("nozzle_diameter"));
1678 size_t num_extruders = nozzle_diameter->values.size();
1679 // Verify validity of the current filament presets.
1680 for (size_t i = 0; i < std::min(this->extruders_filaments.size(), num_extruders); ++i)
1681 this->extruders_filaments[i].select_filament(this->filaments.find_preset(this->extruders_filaments[i].get_selected_preset_name(), true)->name);
1682
1683 if (this->extruders_filaments.size() > num_extruders)
1684 this->extruders_filaments.resize(num_extruders);
1685 else
1686 // Append the rest of filament presets.
1687 for (size_t id = extruders_filaments.size(); id < num_extruders; id++)
1688 extruders_filaments.emplace_back(ExtruderFilaments(&filaments, id, id == 0 ? filaments.first_visible().name : extruders_filaments[id - 1].get_selected_preset_name()));
1689
1690 // Now verify if wiping_volumes_matrix has proper size (it is used to deduce number of extruders in wipe tower generator):
1691 std::vector<double> old_matrix = this->project_config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values;
1692 size_t old_number_of_extruders = size_t(sqrt(old_matrix.size())+EPSILON);
1693 if (num_extruders != old_number_of_extruders) {
1694 // First verify if purging volumes presets for each extruder matches number of extruders
1695 std::vector<double>& extruders = this->project_config.option<ConfigOptionFloats>("wiping_volumes_extruders")->values;
1696 while (extruders.size() < 2*num_extruders) {
1697 extruders.push_back(extruders.size()>1 ? extruders[0] : 50.); // copy the values from the first extruder
1698 extruders.push_back(extruders.size()>1 ? extruders[1] : 50.);
1699 }
1700 while (extruders.size() > 2*num_extruders) {
1701 extruders.pop_back();
1702 extruders.pop_back();
1703 }
1704
1705 std::vector<double> new_matrix;
1706 for (unsigned int i=0;i<num_extruders;++i)
1707 for (unsigned int j=0;j<num_extruders;++j) {
1708 // append the value for this pair from the old matrix (if it's there):
1709 if (i<old_number_of_extruders && j<old_number_of_extruders)
1710 new_matrix.push_back(old_matrix[i*old_number_of_extruders + j]);
1711 else
1712 new_matrix.push_back( i==j ? 0. : extruders[2*i]+extruders[2*j+1]); // so it matches new extruder volumes
1713 }
1714 this->project_config.option<ConfigOptionFloats>("wiping_volumes_matrix")->values = new_matrix;
1715 }
1716}
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition ArrayCwiseUnaryOps.h:152
static constexpr double EPSILON
Definition libslic3r.h:51

References EPSILON, Slic3r::ptFFF, sqrt(), and Slic3r::ConfigOptionVector< T >::values.

Referenced by load_config_file_config_bundle(), load_presets(), and load_selections().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_system_maps()

void Slic3r::PresetBundle::update_system_maps ( )
private

References filaments, printers, prints, sla_materials, sla_prints, Slic3r::PresetCollection::update_map_alias_to_profile_name(), and Slic3r::PresetCollection::update_map_system_profile_renamed().

Referenced by load_installed_printers(), and load_system_presets().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ extruders_filaments

◆ filaments

◆ obsolete_presets

◆ physical_printers

◆ printers

PrinterPresetCollection Slic3r::PresetBundle::printers

Referenced by PresetBundle(), Slic3r::GUI::PresetComboBox::PresetComboBox(), Slic3r::GUI::GUI_App::apply_keeped_preset_modifications(), Slic3r::GUI::GUI_App::check_and_keep_current_preset_changes(), Slic3r::GUI::GUI_App::check_printer_presets(), Slic3r::GUI::Plater::check_selected_presets_visibility(), Slic3r::GUI::GUI_App::config_wizard_startup(), export_selections(), Slic3r::GUI::GUI_App::extruders_cnt(), Slic3r::GUI::GUI_App::extruders_edited_cnt(), Slic3r::flatten_configbundle_hierarchy(), full_config(), full_fff_config(), full_sla_config(), Slic3r::GUI::GUI_App::get_active_preset_collections(), get_presets(), Slic3r::GUI::GUI_App::has_current_preset_changes(), has_defauls_only(), Slic3r::GUI::GUI_App::has_unsaved_preset_changes(), load_config_file_config(), load_config_file_config_bundle(), load_configbundle(), Slic3r::GUI::GUI_App::load_current_presets(), load_installed_filaments(), load_installed_printers(), load_installed_sla_materials(), load_presets(), load_selections(), Slic3r::PresetHints::maximum_volumetric_flow_description(), merge_presets(), operator=(), Slic3r::PresetUpdater::priv::perform_updates(), Slic3r::PresetHints::recommended_thin_wall_thickness(), reset(), Slic3r::GUI::GUI_App::run_wizard(), Slic3r::PresetHints::top_bottom_shell_thickness_explanation(), Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GUI::TabSLAMaterial::update(), Slic3r::GUI::TabSLAPrint::update(), Slic3r::GUI::Sidebar::update_all_preset_comboboxes(), Slic3r::GUI::DiffPresetDialog::update_compatibility(), Slic3r::GUI::Sidebar::update_presets(), Slic3r::GUI::GUI_App::update_saved_preset_from_current_preset(), and update_system_maps().

◆ prints

◆ project_config

◆ PRUSA_BUNDLE

◆ sla_materials

◆ sla_prints

◆ vendors


The documentation for this class was generated from the following files: