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

#include <src/libslic3r/Preset.hpp>

+ Inheritance diagram for Slic3r::PrinterPresetCollection:
+ Collaboration diagram for Slic3r::PrinterPresetCollection:

Public Types

enum class  LoadAndSelect { Never , Always , OnlyIfModified }
 
typedef std::deque< Preset >::iterator Iterator
 
typedef std::deque< Preset >::const_iterator ConstIterator
 

Public Member Functions

 PrinterPresetCollection (Preset::Type type, const std::vector< std::string > &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name="- default -")
 
const Presetdefault_preset_for (const DynamicPrintConfig &config) const override
 
const Presetfind_system_preset_by_model_and_variant (const std::string &model_id, const std::string &variant) const
 
bool only_default_printers () const
 
Iterator begin ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
Iterator end ()
 
ConstIterator end () const
 
ConstIterator cend () const
 
void reset (bool delete_files)
 
Preset::Type type () const
 
std::string name () const
 
std::string section_name () const
 
const std::deque< Preset > & operator() () const
 
void add_default_preset (const std::vector< std::string > &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &preset_name)
 
void load_presets (const std::string &dir_path, const std::string &subdir, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule)
 
Presetload_preset (const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select=true)
 
Presetload_preset (const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select=true)
 
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)
 
bool save_current_preset (const std::string &new_name, bool detach=false)
 
Presetget_preset_with_name (const std::string &new_name, const Preset *initial_preset)
 
bool delete_current_preset ()
 
bool delete_preset (const std::string &name)
 
void set_default_suppressed (bool default_suppressed)
 
bool is_default_suppressed () const
 
Presetselect_preset (size_t idx)
 
Presetget_selected_preset ()
 
const Presetget_selected_preset () const
 
size_t get_selected_idx () const
 
std::string get_selected_preset_name () const
 
const Presetget_selected_preset_parent () const
 
const Presetget_preset_parent (const Preset &child) const
 
Presetget_edited_preset ()
 
const Presetget_edited_preset () const
 
PresetWithVendorProfile get_preset_with_vendor_profile (const Preset &preset) const
 
PresetWithVendorProfile get_edited_preset_with_vendor_profile () const
 
const std::string & get_preset_name_by_alias (const std::string &alias) const
 
const std::string * get_preset_name_renamed (const std::string &old_name) const
 
const std::deque< Preset > & get_presets () const
 
size_t get_idx_selected ()
 
Presetdefault_preset (size_t idx=0)
 
const Presetdefault_preset (size_t idx=0) const
 
Presetpreset (size_t idx, bool respect_active_preset=true)
 
const Presetpreset (size_t idx, bool respect_active_preset=true) const
 
void discard_current_changes ()
 
Presetfind_preset (const std::string &name, bool first_visible_if_not_found=false, bool respect_active_preset=true)
 
const Presetfind_preset (const std::string &name, bool first_visible_if_not_found=false, bool respect_active_preset=true) const
 
size_t first_visible_idx () const
 
template<typename PreferedCondition >
size_t first_compatible_idx (PreferedCondition prefered_condition) const
 
size_t first_compatible_idx () const
 
Presetfirst_visible ()
 
const Presetfirst_visible () const
 
Presetfirst_compatible ()
 
template<typename PreferedCondition >
Presetfirst_compatible (PreferedCondition prefered_condition)
 
const Presetfirst_compatible () const
 
size_t size () const
 
bool has_defaults_only () const
 
template<typename PreferedCondition >
void update_compatible (const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible, PreferedCondition prefered_condition)
 
void update_compatible (const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible)
 
size_t num_visible () const
 
bool current_is_dirty () const
 
std::vector< std::string > current_dirty_options (const bool deep_compare=false) const
 
std::vector< std::string > current_different_from_parent_options (const bool deep_compare=false) const
 
bool saved_is_dirty () const
 
void update_saved_preset_from_current_preset ()
 
std::vector< std::string > system_preset_names () const
 
bool update_dirty ()
 
bool select_preset_by_name (const std::string &name, bool force)
 
std::string path_from_name (const std::string &new_name) const
 
size_t num_default_presets () const
 
const std::vector< std::pair< std::string, std::string > > & map_alias_to_profile_name ()
 

Static Public Member Functions

static const std::string & get_suffix_modified ()
 
static bool is_dirty (const Preset *edited, const Preset *reference)
 
static std::vector< std::string > dirty_options (const Preset *edited, const Preset *reference, const bool deep_compare=false)
 
static bool is_independent_from_extruder_number_option (const std::string &opt_key)
 

Protected Member Functions

void update_vendor_ptrs_after_copy (const VendorMap &vendors)
 
bool select_preset_by_name_strict (const std::string &name)
 
std::vector< std::string > merge_presets (PresetCollection &&other, const VendorMap &new_vendors)
 
void update_map_alias_to_profile_name ()
 
void update_map_system_profile_renamed ()
 

Private Member Functions

 PrinterPresetCollection ()=default
 
 PrinterPresetCollection (const PrinterPresetCollection &other)=default
 
PrinterPresetCollectionoperator= (const PrinterPresetCollection &other)=default
 
std::deque< Preset >::iterator find_preset_internal (const std::string &name)
 
std::deque< Preset >::const_iterator find_preset_internal (const std::string &name) const
 
std::deque< Preset >::iterator find_preset_renamed (const std::string &name)
 
std::deque< Preset >::const_iterator find_preset_renamed (const std::string &name) const
 
size_t update_compatible_internal (const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible)
 

Private Attributes

Preset::Type m_type
 
std::deque< Presetm_presets
 
std::vector< std::pair< std::string, std::string > > m_map_alias_to_profile_name
 
std::map< std::string, std::string > m_map_system_profile_renamed
 
Preset m_edited_preset
 
Preset m_saved_preset
 
size_t m_idx_selected
 
bool m_default_suppressed = true
 
size_t m_num_default_presets = 0
 
std::string m_dir_path
 

Friends

class PresetBundle
 

Detailed Description

Member Typedef Documentation

◆ ConstIterator

typedef std::deque<Preset>::const_iterator Slic3r::PresetCollection::ConstIterator
inherited

◆ Iterator

typedef std::deque<Preset>::iterator Slic3r::PresetCollection::Iterator
inherited

Member Enumeration Documentation

◆ LoadAndSelect

enum class Slic3r::PresetCollection::LoadAndSelect
stronginherited
Enumerator
Never 
Always 
OnlyIfModified 
321 {
322 // Never select
323 Never,
324 // Always select
325 Always,
326 // Select a profile only if it was modified.
328 };

Constructor & Destructor Documentation

◆ PrinterPresetCollection() [1/3]

Slic3r::PrinterPresetCollection::PrinterPresetCollection ( Preset::Type  type,
const std::vector< std::string > &  keys,
const Slic3r::StaticPrintConfig defaults,
const std::string &  default_name = "- default -" 
)
inline
606 :
607 PresetCollection(type, keys, defaults, default_name) {}
Preset::Type type() const
Definition Preset.hpp:300

◆ PrinterPresetCollection() [2/3]

Slic3r::PrinterPresetCollection::PrinterPresetCollection ( )
privatedefault

◆ PrinterPresetCollection() [3/3]

Slic3r::PrinterPresetCollection::PrinterPresetCollection ( const PrinterPresetCollection other)
privatedefault

Member Function Documentation

◆ add_default_preset()

void Slic3r::PresetCollection::add_default_preset ( const std::vector< std::string > &  keys,
const Slic3r::StaticPrintConfig defaults,
const std::string &  preset_name 
)
inherited
670{
671 // Insert just the default preset.
672 m_presets.emplace_back(Preset(this->type(), preset_name, true));
673 m_presets.back().config.apply_only(defaults, keys.empty() ? defaults.keys() : keys);
674 m_presets.back().loaded = true;
676}
size_t m_num_default_presets
Definition Preset.hpp:592
std::deque< Preset > m_presets
Definition Preset.hpp:578
t_config_option_keys keys() const
Gets list of config option names for each config option of this->def, which has a static counter-part...
Definition Config.cpp:1256

References Slic3r::StaticConfig::keys(), Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::type().

Referenced by Slic3r::PresetBundle::PresetBundle(), and Slic3r::PresetCollection::PresetCollection().

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

◆ begin() [1/2]

Iterator Slic3r::PresetCollection::begin ( )
inlineinherited

◆ begin() [2/2]

ConstIterator Slic3r::PresetCollection::begin ( ) const
inlineinherited

◆ cbegin()

ConstIterator Slic3r::PresetCollection::cbegin ( ) const
inlineinherited
293{ return m_presets.cbegin() + m_num_default_presets; }

References Slic3r::PresetCollection::m_num_default_presets, and Slic3r::PresetCollection::m_presets.

Referenced by find_system_preset_by_model_and_variant().

+ Here is the caller graph for this function:

◆ cend()

ConstIterator Slic3r::PresetCollection::cend ( ) const
inlineinherited
296{ return m_presets.cend(); }

References Slic3r::PresetCollection::m_presets.

Referenced by find_system_preset_by_model_and_variant().

+ Here is the caller graph for this function:

◆ current_different_from_parent_options()

std::vector< std::string > Slic3r::PresetCollection::current_different_from_parent_options ( const bool  deep_compare = false) const
inlineinherited
483 { return dirty_options(&this->get_edited_preset(), this->get_selected_preset_parent(), deep_compare); }
static std::vector< std::string > dirty_options(const Preset *edited, const Preset *reference, const bool deep_compare=false)
Definition Preset.cpp:1349
Preset & get_edited_preset()
Definition Preset.hpp:379
const Preset * get_selected_preset_parent() const
Definition Preset.cpp:1069

References Slic3r::PresetCollection::dirty_options(), Slic3r::PresetCollection::get_edited_preset(), and Slic3r::PresetCollection::get_selected_preset_parent().

+ Here is the call graph for this function:

◆ current_dirty_options()

std::vector< std::string > Slic3r::PresetCollection::current_dirty_options ( const bool  deep_compare = false) const
inlineinherited
480 { return dirty_options(&this->get_edited_preset(), &this->get_selected_preset(), deep_compare); }
Preset & get_selected_preset()
Definition Preset.hpp:365

References Slic3r::PresetCollection::dirty_options(), Slic3r::PresetCollection::get_edited_preset(), and Slic3r::PresetCollection::get_selected_preset().

+ Here is the call graph for this function:

◆ current_is_dirty()

bool Slic3r::PresetCollection::current_is_dirty ( ) const
inlineinherited
477 { return is_dirty(&this->get_edited_preset(), &this->get_selected_preset()); }
static bool is_dirty(const Preset *edited, const Preset *reference)
Definition Preset.cpp:1333

References Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_selected_preset(), and Slic3r::PresetCollection::is_dirty().

Referenced by Slic3r::GUI::PresetComboBox::OnSelect(), Slic3r::GUI::PlaterPresetComboBox::OnSelect(), Slic3r::GUI::TabPresetComboBox::OnSelect(), Slic3r::GUI::Tab::select_preset(), and Slic3r::PresetCollection::update_dirty().

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

◆ default_preset() [1/2]

◆ default_preset() [2/2]

const Preset & Slic3r::PresetCollection::default_preset ( size_t  idx = 0) const
inlineinherited

◆ default_preset_for()

const Preset & Slic3r::PrinterPresetCollection::default_preset_for ( const DynamicPrintConfig config) const
overridevirtual

Reimplemented from Slic3r::PresetCollection.

1533{
1534 const ConfigOptionEnumGeneric *opt_printer_technology = config.opt<ConfigOptionEnumGeneric>("printer_technology");
1535 return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1);
1536}
Preset & default_preset(size_t idx=0)
Definition Preset.hpp:398
@ ptFFF
Definition Config.hpp:207

References Slic3r::PresetCollection::default_preset(), Slic3r::ConfigBase::opt(), Slic3r::ptFFF, and Slic3r::ConfigOptionSingle< T >::value.

+ Here is the call graph for this function:

◆ delete_current_preset()

bool Slic3r::PresetCollection::delete_current_preset ( )
inherited
1025{
1026 const Preset &selected = this->get_selected_preset();
1027 if (selected.is_default)
1028 return false;
1029 if (! selected.is_external && ! selected.is_system) {
1030 // Erase the preset file.
1031 boost::nowide::remove(selected.file.c_str());
1032 }
1033 // Remove the preset from the list.
1034 m_presets.erase(m_presets.begin() + m_idx_selected);
1035 // Find the next visible preset.
1036 size_t new_selected_idx = m_idx_selected;
1037 if (new_selected_idx < m_presets.size())
1038 for (; new_selected_idx < m_presets.size() && ! m_presets[new_selected_idx].is_visible; ++ new_selected_idx) ;
1039 if (new_selected_idx == m_presets.size())
1040 for (--new_selected_idx; new_selected_idx > 0 && !m_presets[new_selected_idx].is_visible; --new_selected_idx);
1041 this->select_preset(new_selected_idx);
1042 return true;
1043}
Preset & select_preset(size_t idx)
Definition Preset.cpp:1369
size_t m_idx_selected
Definition Preset.hpp:589

References Slic3r::Preset::file, Slic3r::PresetCollection::get_selected_preset(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::select_preset().

Referenced by Slic3r::PresetCollection::delete_preset().

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

◆ delete_preset()

bool Slic3r::PresetCollection::delete_preset ( const std::string &  name)
inherited
1046{
1047 if (name == this->get_selected_preset().name)
1048 return delete_current_preset();
1049
1050 const std::string selected_preset_name = this->get_selected_preset_name();
1051
1052 auto it = this->find_preset_internal(name);
1053
1054 const Preset& preset = *it;
1055 if (preset.is_default)
1056 return false;
1058 // Erase the preset file.
1059 boost::nowide::remove(preset.file.c_str());
1060 }
1061 m_presets.erase(it);
1062
1063 // update selected preset
1064 this->select_preset_by_name(selected_preset_name, true);
1065
1066 return true;
1067}
std::deque< Preset >::iterator find_preset_internal(const std::string &name)
Definition Preset.hpp:541
bool select_preset_by_name(const std::string &name, bool force)
Definition Preset.cpp:1383
bool delete_current_preset()
Definition Preset.cpp:1024
Preset & preset(size_t idx, bool respect_active_preset=true)
Definition Preset.hpp:402
std::string get_selected_preset_name() const
Definition Preset.hpp:369
std::string name() const
Definition Preset.cpp:1482
bool is_system
Definition Preset.hpp:134
bool is_external
Definition Preset.hpp:132
bool is_default
Definition Preset.hpp:129
std::string file
Definition Preset.hpp:151

References Slic3r::PresetCollection::delete_current_preset(), Slic3r::Preset::file, Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::name(), Slic3r::PresetCollection::preset(), and Slic3r::PresetCollection::select_preset_by_name().

+ Here is the call graph for this function:

◆ dirty_options()

std::vector< std::string > Slic3r::PresetCollection::dirty_options ( const Preset edited,
const Preset reference,
const bool  deep_compare = false 
)
staticinherited
1350{
1351 std::vector<std::string> changed;
1352 if (edited != nullptr && reference != nullptr) {
1353 // Only compares options existing in both configs.
1354 changed = deep_compare ?
1355 deep_diff(edited->config, reference->config) :
1356 reference->config.diff(edited->config);
1357 // The "compatible_printers" option key is handled differently from the others:
1358 // It is not mandatory. If the key is missing, it means it is compatible with any printer.
1359 // If the key exists and it is empty, it means it is compatible with no printer.
1360 for (auto &opt_key : optional_keys)
1361 if (reference->config.has(opt_key) != edited->config.has(opt_key))
1362 changed.emplace_back(opt_key);
1363 }
1364 return changed;
1365}
if(!(yy_init))
Definition lexer.c:1190
static constexpr const std::initializer_list< const char * > optional_keys
Definition Preset.cpp:1331
Slic3r::Polygons diff(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:672
t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other)
Definition Preset.cpp:1299

References Slic3r::Preset::config, Slic3r::deep_diff(), Slic3r::DynamicConfig::diff(), Slic3r::ConfigOptionResolver::has(), and Slic3r::optional_keys.

Referenced by Slic3r::PresetCollection::current_different_from_parent_options(), Slic3r::PresetCollection::current_dirty_options(), and Slic3r::GUI::DiffPresetDialog::update_tree().

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

◆ discard_current_changes()

void Slic3r::PresetCollection::discard_current_changes ( )
inlineinherited
404 {
405 m_presets[m_idx_selected].reset_dirty();
407 // Don't save the resetted preset state as a "saved into project" state.
408// update_saved_preset_from_current_preset();
409 }
Preset m_edited_preset
Definition Preset.hpp:584

References Slic3r::PresetCollection::m_edited_preset, Slic3r::PresetCollection::m_idx_selected, and Slic3r::PresetCollection::m_presets.

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

+ Here is the caller graph for this function:

◆ end() [1/2]

Iterator Slic3r::PresetCollection::end ( )
inlineinherited
294{ return m_presets.end(); }

References Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::PresetBundle::load_selections().

+ Here is the caller graph for this function:

◆ end() [2/2]

ConstIterator Slic3r::PresetCollection::end ( ) const
inlineinherited
295{ return m_presets.cend(); }

References Slic3r::PresetCollection::m_presets.

◆ find_preset() [1/2]

Preset * Slic3r::PresetCollection::find_preset ( const std::string &  name,
bool  first_visible_if_not_found = false,
bool  respect_active_preset = true 
)
inherited
1165{
1166 Preset key(m_type, name, false);
1167 auto it = this->find_preset_internal(name);
1168 // Ensure that a temporary copy is returned if the preset found is currently selected.
1169 return (it != m_presets.end() && it->name == key.name) ? &this->preset(it - m_presets.begin(), respect_active_preset) :
1170 first_visible_if_not_found ? &this->first_visible() : nullptr;
1171}
Preset & first_visible()
Definition Preset.hpp:451
Preset::Type m_type
Definition Preset.hpp:574

References Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::first_visible(), Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::m_type, Slic3r::Preset::name, Slic3r::PresetCollection::name(), and Slic3r::PresetCollection::preset().

Referenced by Slic3r::GUI::UnsavedChangesDialog::UnsavedChangesDialog(), Slic3r::GUI::UnsavedChangesDialog::build(), Slic3r::GUI::ConfigWizard::priv::check_and_install_missing_materials(), Slic3r::GUI::Plater::check_selected_presets_visibility(), Slic3r::PresetCollection::find_preset(), Slic3r::GUI::SavePresetDialog::Item::get_existing_preset(), Slic3r::PresetCollection::get_preset_parent(), Slic3r::PresetCollection::get_selected_preset_parent(), Slic3r::PresetBundle::load_configbundle(), Slic3r::PresetCollection::load_presets(), Slic3r::PresetBundle::load_selections(), Slic3r::GUI::ConfigWizard::priv::load_vendors(), Slic3r::PresetBundle::transfer_and_save(), Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GUI::TabPresetComboBox::update(), Slic3r::GUI::DiffPresetDialog::update_compatibility(), Slic3r::GUI::TabPresetComboBox::update_dirty(), Slic3r::GUI::Plater::update_filament_colors_in_full_config(), and Slic3r::GUI::DiffPresetDialog::update_tree().

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

◆ find_preset() [2/2]

const Preset * Slic3r::PresetCollection::find_preset ( const std::string &  name,
bool  first_visible_if_not_found = false,
bool  respect_active_preset = true 
) const
inlineinherited
415 { return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found, respect_active_preset); }
Preset * find_preset(const std::string &name, bool first_visible_if_not_found=false, bool respect_active_preset=true)
Definition Preset.cpp:1164

References Slic3r::PresetCollection::find_preset(), and Slic3r::PresetCollection::name().

+ Here is the call graph for this function:

◆ find_preset_internal() [1/2]

std::deque< Preset >::iterator Slic3r::PresetCollection::find_preset_internal ( const std::string &  name)
inlineprivateinherited
542 {
543 auto it = Slic3r::lower_bound_by_predicate(m_presets.begin() + m_num_default_presets, m_presets.end(), [&name](const auto& l) { return l.name < name; });
544 if (it == m_presets.end() || it->name != name) {
545 // Preset has not been not found in the sorted list of non-default presets. Try the defaults.
546 for (size_t i = 0; i < m_num_default_presets; ++ i)
547 if (m_presets[i].name == name) {
548 it = m_presets.begin() + i;
549 break;
550 }
551 }
552 return it;
553 }
ForwardIt lower_bound_by_predicate(ForwardIt first, ForwardIt last, LowerThanKeyPredicate lower_than_key)
Definition libslic3r.h:203

References Slic3r::lower_bound_by_predicate(), Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::name().

Referenced by Slic3r::PresetCollection::delete_preset(), Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetCollection::get_preset_name_by_alias(), Slic3r::PresetCollection::get_preset_with_name(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetBundle::load_selections(), Slic3r::PresetCollection::save_current_preset(), Slic3r::PresetCollection::select_preset_by_name(), and Slic3r::PresetCollection::select_preset_by_name_strict().

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

◆ find_preset_internal() [2/2]

std::deque< Preset >::const_iterator Slic3r::PresetCollection::find_preset_internal ( const std::string &  name) const
inlineprivateinherited
555 { return const_cast<PresetCollection*>(this)->find_preset_internal(name); }

References Slic3r::PresetCollection::find_preset_internal(), and Slic3r::PresetCollection::name().

+ Here is the call graph for this function:

◆ find_preset_renamed() [1/2]

std::deque< Preset >::iterator Slic3r::PresetCollection::find_preset_renamed ( const std::string &  name)
inlineprivateinherited
556 {
557 auto it_renamed = m_map_system_profile_renamed.find(name);
558 auto it = (it_renamed == m_map_system_profile_renamed.end()) ? m_presets.end() : this->find_preset_internal(it_renamed->second);
559 assert((it_renamed == m_map_system_profile_renamed.end()) || (it != m_presets.end() && it->name == it_renamed->second));
560 return it;
561 }
std::map< std::string, std::string > m_map_system_profile_renamed
Definition Preset.hpp:582

References Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::m_map_system_profile_renamed, Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::name().

Referenced by Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetCollection::get_preset_parent(), Slic3r::PresetCollection::get_selected_preset_parent(), and Slic3r::PresetCollection::load_external_preset().

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

◆ find_preset_renamed() [2/2]

std::deque< Preset >::const_iterator Slic3r::PresetCollection::find_preset_renamed ( const std::string &  name) const
inlineprivateinherited
563 { return const_cast<PresetCollection*>(this)->find_preset_renamed(name); }
std::deque< Preset >::iterator find_preset_renamed(const std::string &name)
Definition Preset.hpp:556

References Slic3r::PresetCollection::find_preset_renamed(), and Slic3r::PresetCollection::name().

+ Here is the call graph for this function:

◆ find_system_preset_by_model_and_variant()

const Preset * Slic3r::PrinterPresetCollection::find_system_preset_by_model_and_variant ( const std::string &  model_id,
const std::string &  variant 
) const
1539{
1540 if (model_id.empty()) { return nullptr; }
1541
1542 const auto it = std::find_if(cbegin(), cend(), [&](const Preset &preset) {
1543 if (!preset.is_system || preset.config.opt_string("printer_model") != model_id)
1544 return false;
1545 if (variant.empty())
1546 return true;
1547 return preset.config.opt_string("printer_variant") == variant;
1548 });
1549
1550 return it != cend() ? &*it : nullptr;
1551}
std::string & opt_string(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2276
ConstIterator cbegin() const
Definition Preset.hpp:293
ConstIterator cend() const
Definition Preset.hpp:296
DynamicPrintConfig config
Definition Preset.hpp:159

References Slic3r::PresetCollection::cbegin(), Slic3r::PresetCollection::cend(), Slic3r::Preset::config, Slic3r::Preset::is_system, Slic3r::ConfigBase::opt_string(), and Slic3r::PresetCollection::preset().

Referenced by Slic3r::PresetBundle::load_selections().

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

◆ first_compatible() [1/3]

Preset & Slic3r::PresetCollection::first_compatible ( )
inlineinherited
453{ return this->preset(this->first_compatible_idx()); }
size_t first_compatible_idx() const
Definition Preset.hpp:447

References Slic3r::PresetCollection::first_compatible_idx(), and Slic3r::PresetCollection::preset().

+ Here is the call graph for this function:

◆ first_compatible() [2/3]

const Preset & Slic3r::PresetCollection::first_compatible ( ) const
inlineinherited
456{ return this->preset(this->first_compatible_idx()); }

References Slic3r::PresetCollection::first_compatible_idx(), and Slic3r::PresetCollection::preset().

+ Here is the call graph for this function:

◆ first_compatible() [3/3]

template<typename PreferedCondition >
Preset & Slic3r::PresetCollection::first_compatible ( PreferedCondition  prefered_condition)
inlineinherited
455{ return this->preset(this->first_compatible_idx(prefered_condition)); }

References Slic3r::PresetCollection::first_compatible_idx(), and Slic3r::PresetCollection::preset().

+ Here is the call graph for this function:

◆ first_compatible_idx() [1/2]

size_t Slic3r::PresetCollection::first_compatible_idx ( ) const
inlineinherited
447{ return this->first_compatible_idx([](const Preset&) -> int { return 0; }); }

References Slic3r::PresetCollection::first_compatible_idx().

Referenced by Slic3r::PresetCollection::first_compatible(), Slic3r::PresetCollection::first_compatible(), Slic3r::PresetCollection::first_compatible(), Slic3r::PresetCollection::first_compatible_idx(), and Slic3r::PresetCollection::update_compatible().

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

◆ first_compatible_idx() [2/2]

template<typename PreferedCondition >
size_t Slic3r::PresetCollection::first_compatible_idx ( PreferedCondition  prefered_condition) const
inlineinherited
422 {
424 size_t n = m_presets.size();
425 size_t i_compatible = n;
426 int match_quality = -1;
427 for (; i < n; ++ i)
428 // Since we use the filament selection from Wizard, it's needed to control the preset visibility too
429 if (m_presets[i].is_compatible && m_presets[i].is_visible) {
430 int this_match_quality = prefered_condition(m_presets[i]);
431 if (this_match_quality > match_quality) {
432 if (match_quality == std::numeric_limits<int>::max())
433 // Better match will not be found.
434 return i;
435 // Store the first compatible profile with highest match quality into i_compatible.
436 i_compatible = i;
437 match_quality = this_match_quality;
438 }
439 }
440 return (i_compatible == n) ?
441 // No compatible preset found, return the default preset.
442 0 :
443 // Compatible preset found.
444 i_compatible;
445 }
bool m_default_suppressed
Definition Preset.hpp:591

References Slic3r::PresetCollection::m_default_suppressed, Slic3r::PresetCollection::m_num_default_presets, and Slic3r::PresetCollection::m_presets.

◆ first_visible() [1/2]

Preset & Slic3r::PresetCollection::first_visible ( )
inlineinherited
451{ return this->preset(this->first_visible_idx()); }
size_t first_visible_idx() const
Definition Preset.cpp:1174

References Slic3r::PresetCollection::first_visible_idx(), and Slic3r::PresetCollection::preset().

Referenced by Slic3r::PresetCollection::find_preset().

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

◆ first_visible() [2/2]

const Preset & Slic3r::PresetCollection::first_visible ( ) const
inlineinherited
452{ return this->preset(this->first_visible_idx()); }

References Slic3r::PresetCollection::first_visible_idx(), and Slic3r::PresetCollection::preset().

+ Here is the call graph for this function:

◆ first_visible_idx()

size_t Slic3r::PresetCollection::first_visible_idx ( ) const
inherited
1175{
1177 for (; idx < m_presets.size(); ++ idx)
1178 if (m_presets[idx].is_visible)
1179 break;
1180 if (idx == m_presets.size())
1181 idx = 0;
1182 return idx;
1183}

References Slic3r::PresetCollection::m_default_suppressed, Slic3r::PresetCollection::m_num_default_presets, and Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::PresetCollection::first_visible(), Slic3r::PresetCollection::first_visible(), Slic3r::PresetCollection::load_presets(), and Slic3r::PresetCollection::select_preset().

+ Here is the caller graph for this function:

◆ get_edited_preset() [1/2]

Preset & Slic3r::PresetCollection::get_edited_preset ( )
inlineinherited
379{ return m_edited_preset; }

References Slic3r::PresetCollection::m_edited_preset.

Referenced by Slic3r::GUI::UnsavedChangesDialog::UnsavedChangesDialog(), Slic3r::GUI::GUI_App::apply_keeped_preset_modifications(), Slic3r::GUI::UnsavedChangesDialog::build(), Slic3r::GUI::GUI_App::check_and_keep_current_preset_changes(), Slic3r::GUI::Plater::check_selected_presets_visibility(), Slic3r::GUI::DiffPresetDialog::create_buttons(), Slic3r::PresetCollection::current_different_from_parent_options(), Slic3r::PresetCollection::current_dirty_options(), Slic3r::PresetCollection::current_is_dirty(), Slic3r::PresetBundle::export_selections(), Slic3r::GUI::GUI_App::extruders_edited_cnt(), Slic3r::PresetBundle::full_config(), Slic3r::PresetBundle::full_fff_config(), Slic3r::PresetBundle::full_sla_config(), Slic3r::GUI::GUI_App::get_active_preset_collections(), Slic3r::PresetCollection::get_edited_preset_with_vendor_profile(), Slic3r::PresetCollection::get_selected_preset_parent(), Slic3r::GUI::GUI_App::has_current_preset_changes(), Slic3r::GUI::GUI_App::has_unsaved_preset_changes(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::GUI::GUI_App::load_current_presets(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PhysicalPrinterCollection::load_printers_from_presets(), Slic3r::PresetHints::maximum_volumetric_flow_description(), Slic3r::GUI::Tab::may_discard_current_dirty_preset(), Slic3r::PresetHints::recommended_thin_wall_thickness(), Slic3r::GUI::GUI_App::run_wizard(), Slic3r::GUI::UnsavedChangesDialog::save(), Slic3r::PresetBundle::save_changes_for_preset(), Slic3r::PresetCollection::saved_is_dirty(), Slic3r::GUI::PresetComboBox::selection_is_changed_according_to_physical_printers(), Slic3r::PresetHints::top_bottom_shell_thickness_explanation(), Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GUI::UnsavedChangesDialog::update(), Slic3r::GUI::Sidebar::update_all_preset_comboboxes(), Slic3r::PresetCollection::update_dirty(), Slic3r::GUI::Sidebar::update_presets(), and Slic3r::GUI::GUI_App::update_saved_preset_from_current_preset().

+ Here is the caller graph for this function:

◆ get_edited_preset() [2/2]

const Preset & Slic3r::PresetCollection::get_edited_preset ( ) const
inlineinherited

◆ get_edited_preset_with_vendor_profile()

PresetWithVendorProfile Slic3r::PresetCollection::get_edited_preset_with_vendor_profile ( ) const
inlineinherited
387{ return this->get_preset_with_vendor_profile(this->get_edited_preset()); }
PresetWithVendorProfile get_preset_with_vendor_profile(const Preset &preset) const
Definition Preset.cpp:1122

References Slic3r::PresetCollection::get_edited_preset(), and Slic3r::PresetCollection::get_preset_with_vendor_profile().

Referenced by Slic3r::GUI::Tab::select_preset().

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

◆ get_idx_selected()

size_t Slic3r::PresetCollection::get_idx_selected ( )
inlineinherited

◆ get_preset_name_by_alias()

const std::string & Slic3r::PresetCollection::get_preset_name_by_alias ( const std::string &  alias) const
inherited
1137{
1138 for (
1139 // Find the 1st profile name with the alias.
1140 auto it = Slic3r::lower_bound_by_predicate(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [&alias](auto &l){ return l.first < alias; });
1141 // Continue over all profile names with the same alias.
1142 it != m_map_alias_to_profile_name.end() && it->first == alias; ++ it)
1143 if (auto it_preset = this->find_preset_internal(it->second);
1144 it_preset != m_presets.end() && it_preset->name == it->second &&
1145 it_preset->is_visible && (it_preset->is_compatible || size_t(it_preset - m_presets.begin()) == m_idx_selected))
1146 return it_preset->name;
1147 return alias;
1148}
std::vector< std::pair< std::string, std::string > > m_map_alias_to_profile_name
Definition Preset.hpp:580

References Slic3r::PresetCollection::find_preset_internal(), Slic3r::lower_bound_by_predicate(), Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_map_alias_to_profile_name, and Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::PresetBundle::get_preset_name_by_alias().

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

◆ get_preset_name_renamed()

const std::string * Slic3r::PresetCollection::get_preset_name_renamed ( const std::string &  old_name) const
inherited
1151{
1152 auto it_renamed = m_map_system_profile_renamed.find(old_name);
1153 if (it_renamed != m_map_system_profile_renamed.end())
1154 return &it_renamed->second;
1155 return nullptr;
1156}

References Slic3r::PresetCollection::m_map_system_profile_renamed.

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

+ Here is the caller graph for this function:

◆ get_preset_parent()

const Preset * Slic3r::PresetCollection::get_preset_parent ( const Preset child) const
inherited
1099{
1100 const std::string &inherits = child.inherits();
1101 if (inherits.empty())
1102// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
1103 return nullptr;
1104 const Preset* preset = this->find_preset(inherits, false);
1105 if (preset == nullptr) {
1106 auto it = this->find_preset_renamed(inherits);
1107 if (it != m_presets.end())
1108 preset = &(*it);
1109 }
1110 return
1111 // not found
1112 (preset == nullptr/* || preset->is_default */||
1113 // this should not happen, user profile should not derive from an external profile
1115 // this should not happen, however people are creative, see GH #4996
1116 preset == &child) ?
1117 nullptr :
1118 preset;
1119}

References Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::Preset::inherits(), Slic3r::Preset::is_external, Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::preset().

Referenced by Slic3r::PresetCollection::get_preset_with_vendor_profile().

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

◆ get_preset_with_name()

Preset & Slic3r::PresetCollection::get_preset_with_name ( const std::string &  new_name,
const Preset initial_preset 
)
inherited
965{
966 // 1) Find the preset with a new_name or create a new one,
967 // initialize it with the preset_to config.
968 auto it = this->find_preset_internal(new_name);
969 if (it != m_presets.end() && it->name == new_name) {
970 // Preset with the same name found.
971 Preset& preset = *it;
972 if (!preset.is_default && !preset.is_external && !preset.is_system && initial_preset->name != new_name) {
973 // Overwriting an existing preset if it isn't default/external/system or isn't an initial_preset
974 preset.config = initial_preset->config;
975 // The newly saved preset can be activated -> make it visible.
976 preset.is_visible = true;
977 }
978 return preset;
979 }
980
981 const std::string selected_preset_name = this->get_selected_preset_name();
982
983 // Creating a new preset.
984 Preset& preset = *m_presets.insert(it, *initial_preset);
985 std::string& inherits = preset.inherits();
986 std::string old_name = preset.name;
987 preset.name = new_name;
988 preset.file = this->path_from_name(new_name);
989 preset.vendor = nullptr;
990 preset.alias.clear();
991 preset.renamed_from.clear();
992 if (preset.is_system) {
993 // Inheriting from a system preset.
994 inherits = old_name;
995 }
996 else if (inherits.empty()) {
997 // Inheriting from a user preset. Link the new preset to the old preset.
998 // inherits = old_name;
999 }
1000 else {
1001 // Inherited from a user preset. Just maintain the "inherited" flag,
1002 // meaning it will inherit from either the system preset, or the inherited user preset.
1003 }
1004 preset.is_default = false;
1005 preset.is_system = false;
1006 preset.is_external = false;
1007 // The newly saved preset can be activated -> make it visible.
1008 preset.is_visible = true;
1009 // Just system presets have aliases
1010 preset.alias.clear();
1011
1012 // sort printers and get new it
1013 std::sort(m_presets.begin(), m_presets.end());
1014
1015 // set initial preset selection
1016 this->select_preset_by_name(selected_preset_name, true);
1017
1018 it = this->find_preset_internal(new_name);
1019 assert(it != m_presets.end());
1020
1021 return *it;
1022}
std::string path_from_name(const std::string &new_name) const
Definition Preset.cpp:1526
std::string name
Definition Preset.hpp:147
static std::string & inherits(DynamicPrintConfig &cfg)
Definition Preset.hpp:179
std::vector< std::string > renamed_from
Definition Preset.hpp:166
std::string alias
Definition Preset.hpp:162
bool is_visible
Definition Preset.hpp:138
const VendorProfile * vendor
Definition Preset.hpp:153

References Slic3r::Preset::alias, Slic3r::Preset::config, Slic3r::Preset::file, Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::get_selected_preset_name(), Slic3r::Preset::inherits(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::Preset::is_visible, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, Slic3r::PresetCollection::path_from_name(), Slic3r::PresetCollection::preset(), Slic3r::Preset::renamed_from, Slic3r::PresetCollection::select_preset_by_name(), and Slic3r::Preset::vendor.

Referenced by Slic3r::PresetBundle::transfer_and_save().

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

◆ get_preset_with_vendor_profile()

PresetWithVendorProfile Slic3r::PresetCollection::get_preset_with_vendor_profile ( const Preset preset) const
inherited
1123{
1124 const Preset *p = &preset;
1125 const VendorProfile *v = nullptr;
1126 do {
1127 if (p->vendor != nullptr) {
1128 v = p->vendor;
1129 break;
1130 }
1131 p = this->get_preset_parent(*p);
1132 } while (p != nullptr);
1133 return PresetWithVendorProfile(preset, v);
1134}
const Preset * get_preset_parent(const Preset &child) const
Definition Preset.cpp:1098

References Slic3r::PresetCollection::get_preset_parent(), Slic3r::PresetCollection::preset(), and Slic3r::Preset::vendor.

Referenced by Slic3r::PresetCollection::get_edited_preset_with_vendor_profile(), Slic3r::PresetBundle::load_installed_filaments(), Slic3r::PresetBundle::load_installed_sla_materials(), Slic3r::PresetCollection::update_compatible_internal(), and Slic3r::ExtruderFilaments::update_compatible_internal().

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

◆ get_presets()

const std::deque< Preset > & Slic3r::PresetCollection::get_presets ( ) const
inlineinherited
393{ return m_presets; }

References Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::ExtruderFilaments::ExtruderFilaments(), Slic3r::GUI::SavePresetDialog::Item::get_existing_preset(), only_default_printers(), Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GUI::TabPresetComboBox::update(), and Slic3r::GUI::PresetComboBox::update().

+ Here is the caller graph for this function:

◆ get_selected_idx()

size_t Slic3r::PresetCollection::get_selected_idx ( ) const
inlineinherited
367{ return m_idx_selected; }

References Slic3r::PresetCollection::m_idx_selected.

Referenced by Slic3r::GUI::DiffPresetDialog::create_presets_sizer(), Slic3r::PresetCollection::get_selected_preset_parent(), Slic3r::GUI::PlaterPresetComboBox::update(), and Slic3r::GUI::TabPresetComboBox::update().

+ Here is the caller graph for this function:

◆ get_selected_preset() [1/2]

◆ get_selected_preset() [2/2]

const Preset & Slic3r::PresetCollection::get_selected_preset ( ) const
inlineinherited

◆ get_selected_preset_name()

std::string Slic3r::PresetCollection::get_selected_preset_name ( ) const
inlineinherited

◆ get_selected_preset_parent()

const Preset * Slic3r::PresetCollection::get_selected_preset_parent ( ) const
inherited
1070{
1071 if (this->get_selected_idx() == size_t(-1))
1072 // This preset collection has no preset activated yet. Only the get_edited_preset() is valid.
1073 return nullptr;
1074
1075 const Preset &selected_preset = this->get_selected_preset();
1076 if (selected_preset.is_system || selected_preset.is_default)
1077 return &selected_preset;
1078
1079 const Preset &edited_preset = this->get_edited_preset();
1080 const std::string &inherits = edited_preset.inherits();
1081 const Preset *preset = nullptr;
1082 if (inherits.empty()) {
1083 if (selected_preset.is_external)
1084 return nullptr;
1085 preset = &this->default_preset(m_type == Preset::Type::TYPE_PRINTER && edited_preset.printer_technology() == ptSLA ? 1 : 0);
1086 } else
1087 preset = this->find_preset(inherits, false);
1088 if (preset == nullptr) {
1089 // Resolve the "renamed_from" field.
1090 assert(! inherits.empty());
1091 auto it = this->find_preset_renamed(inherits);
1092 if (it != m_presets.end())
1093 preset = &(*it);
1094 }
1095 return (preset == nullptr/* || preset->is_default*/ || preset->is_external) ? nullptr : preset;
1096}
size_t get_selected_idx() const
Definition Preset.hpp:367
@ TYPE_PRINTER
Definition Preset.hpp:116
@ ptSLA
Definition Config.hpp:209

References Slic3r::PresetCollection::default_preset(), Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_selected_idx(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::Preset::inherits(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::m_type, Slic3r::PresetCollection::preset(), Slic3r::Preset::printer_technology(), Slic3r::ptSLA, and Slic3r::Preset::TYPE_PRINTER.

Referenced by Slic3r::PresetCollection::current_different_from_parent_options().

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

◆ get_suffix_modified()

const std::string & Slic3r::PresetCollection::get_suffix_modified ( )
staticinherited
1158 {
1159 return g_suffix_modified;
1160}
static std::string g_suffix_modified
Definition Preset.cpp:246

References Slic3r::g_suffix_modified.

Referenced by Slic3r::GUI::SavePresetDialog::Item::update().

+ Here is the caller graph for this function:

◆ has_defaults_only()

bool Slic3r::PresetCollection::has_defaults_only ( ) const
inlineinherited
460{ return m_presets.size() <= m_num_default_presets; }

References Slic3r::PresetCollection::m_num_default_presets, and Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::PresetBundle::has_defauls_only().

+ Here is the caller graph for this function:

◆ is_default_suppressed()

bool Slic3r::PresetCollection::is_default_suppressed ( ) const
inlineinherited
360{ return m_default_suppressed; }

References Slic3r::PresetCollection::m_default_suppressed.

Referenced by Slic3r::ExtruderFilaments::first_compatible_idx().

+ Here is the caller graph for this function:

◆ is_dirty()

bool Slic3r::PresetCollection::is_dirty ( const Preset edited,
const Preset reference 
)
staticinherited
1334{
1335 if (edited != nullptr && reference != nullptr) {
1336 // Only compares options existing in both configs.
1337 if (! reference->config.equals(edited->config))
1338 return true;
1339 // The "compatible_printers" option key is handled differently from the others:
1340 // It is not mandatory. If the key is missing, it means it is compatible with any printer.
1341 // If the key exists and it is empty, it means it is compatible with no printer.
1342 for (auto &opt_key : optional_keys)
1343 if (reference->config.has(opt_key) != edited->config.has(opt_key))
1344 return true;
1345 }
1346 return false;
1347}

References Slic3r::Preset::config, Slic3r::DynamicConfig::equals(), Slic3r::ConfigOptionResolver::has(), and Slic3r::optional_keys.

Referenced by Slic3r::PresetCollection::current_is_dirty(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::saved_is_dirty(), and Slic3r::PresetCollection::update_dirty().

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

◆ is_independent_from_extruder_number_option()

bool Slic3r::PresetCollection::is_independent_from_extruder_number_option ( const std::string &  opt_key)
staticinherited
1294{
1296}
static const std::set< std::string > independent_from_extruder_number_options
Definition Preset.cpp:1283

References Slic3r::independent_from_extruder_number_options.

Referenced by Slic3r::Search::OptionsSearcher::append_options(), Slic3r::deep_diff(), and Slic3r::GUI::Tab::init_options_list().

+ Here is the caller graph for this function:

◆ load_external_preset()

std::pair< Preset *, bool > Slic3r::PresetCollection::load_external_preset ( const std::string &  path,
const std::string &  name,
const std::string &  original_name,
const DynamicPrintConfig config,
LoadAndSelect  select = LoadAndSelect::Always 
)
inherited
781{
782 // Load the preset over a default preset, so that the missing fields are filled in from the default preset.
783 DynamicPrintConfig cfg(this->default_preset_for(combined_config).config);
784 t_config_option_keys keys = cfg.keys();
785 cfg.apply_only(combined_config, keys, true);
786 std::string &inherits = Preset::inherits(cfg);
787 if (select == LoadAndSelect::Never) {
788 // Some filament profile has been selected and modified already.
789 // Check whether this profile is equal to the modified edited profile.
790 const Preset &edited = this->get_edited_preset();
791 if ((edited.name == original_name || edited.name == inherits) && profile_print_params_same(edited.config, cfg))
792 // Just point to that already selected and edited profile.
793 return std::make_pair(&(*this->find_preset_internal(edited.name)), false);
794 }
795 // Is there a preset already loaded with the name stored inside the config?
796 std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
797 bool found = it != m_presets.end() && it->name == original_name;
798 if (! found) {
799 // Try to match the original_name against the "renamed_from" profile names of loaded system profiles.
800 it = this->find_preset_renamed(original_name);
801 found = it != m_presets.end();
802 }
803 if (found && profile_print_params_same(it->config, cfg)) {
804 // The preset exists and it matches the values stored inside config.
805 if (select == LoadAndSelect::Always)
806 this->select_preset(it - m_presets.begin());
807 return std::make_pair(&(*it), false);
808 }
809 if (! found && select != LoadAndSelect::Never && ! inherits.empty()) {
810 // Try to use a system profile as a base to select the system profile
811 // and override its settings with the loaded ones.
812 assert(it == m_presets.end());
813 it = this->find_preset_internal(inherits);
814 found = it != m_presets.end() && it->name == inherits;
815 if (found && profile_print_params_same(it->config, cfg)) {
816 // The system preset exists and it matches the values stored inside config.
817 if (select == LoadAndSelect::Always)
818 this->select_preset(it - m_presets.begin());
819 return std::make_pair(&(*it), false);
820 }
821 }
822 if (found) {
823 if (select != LoadAndSelect::Never) {
824 // Select the existing preset and override it with new values, so that
825 // the differences will be shown in the preset editor against the referenced profile.
826 this->select_preset(it - m_presets.begin());
827 // The source config may contain keys from many possible preset types. Just copy those that relate to this preset.
828
829 // Following keys are not used neither by the UI nor by the slicing core, therefore they are not important
830 // Erase them from config appl to avoid redundant "dirty" parameter in loaded preset.
831 for (const char* key : { "print_settings_id", "filament_settings_id", "sla_print_settings_id", "sla_material_settings_id", "printer_settings_id",
832 "printer_model", "printer_variant", "default_print_profile", "default_filament_profile", "default_sla_print_profile", "default_sla_material_profile" })
833 keys.erase(std::remove(keys.begin(), keys.end(), key), keys.end());
834
835 this->get_edited_preset().config.apply_only(combined_config, keys, true);
836 this->update_dirty();
837 // Don't save the newly loaded project as a "saved into project" state.
838 //update_saved_preset_from_current_preset();
839 assert(this->get_edited_preset().is_dirty);
840 return std::make_pair(&(*it), this->get_edited_preset().is_dirty);
841 }
842 if (inherits.empty()) {
843 // Update the "inherits" field.
844 // There is a profile with the same name already loaded. Should we update the "inherits" field?
845 inherits = it->vendor ? it->name : it->inherits();
846 }
847 }
848
849 // The external preset does not match an internal preset, load the external preset.
850 std::string new_name;
851 for (size_t idx = 0;; ++ idx) {
852 std::string suffix;
853 if (original_name.empty()) {
854 if (idx > 0)
855 suffix = " (" + std::to_string(idx) + ")";
856 } else {
857 if (idx == 0)
858 suffix = " (" + original_name + ")";
859 else
860 suffix = " (" + original_name + "-" + std::to_string(idx) + ")";
861 }
862 new_name = name + suffix;
863 it = this->find_preset_internal(new_name);
864 if (it == m_presets.end() || it->name != new_name)
865 // Unique profile name. Insert a new profile.
866 break;
867 if (profile_print_params_same(it->config, cfg)) {
868 // The preset exists and it matches the values stored inside config.
869 if (select == LoadAndSelect::Always)
870 this->select_preset(it - m_presets.begin());
871 return std::make_pair(&(*it), false);
872 }
873 // Form another profile name.
874 }
875 // Insert a new profile.
876 Preset &preset = this->load_preset(path, new_name, std::move(cfg), select == LoadAndSelect::Always);
877 preset.is_external = true;
878 if (this->m_idx_selected != size_t(-1) && &this->get_selected_preset() == &preset)
879 this->get_edited_preset().is_external = true;
880
881 return std::make_pair(&preset, false);
882}
void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent=false)
Definition Config.cpp:466
Preset & load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select=true)
Definition Preset.cpp:743
virtual const Preset & default_preset_for(const DynamicPrintConfig &) const
Definition Preset.hpp:400
bool update_dirty()
Definition Preset.cpp:1258
std::string & inherits()
Definition Preset.hpp:180
std::vector< std::string > t_config_option_keys
Definition Config.hpp:77
static bool profile_print_params_same(const DynamicPrintConfig &cfg_old, const DynamicPrintConfig &cfg_new)
Definition Preset.cpp:750

References Slic3r::PresetCollection::Always, Slic3r::ConfigBase::apply_only(), Slic3r::Preset::config, Slic3r::PresetCollection::default_preset_for(), Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::Preset::inherits(), Slic3r::PresetCollection::is_dirty(), Slic3r::Preset::is_external, Slic3r::DynamicConfig::keys(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, Slic3r::PresetCollection::name(), Slic3r::PresetCollection::Never, Slic3r::PresetCollection::preset(), Slic3r::profile_print_params_same(), Slic3r::PresetCollection::select_preset(), and Slic3r::PresetCollection::update_dirty().

Referenced by Slic3r::PresetBundle::load_config_file_config().

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

◆ load_preset() [1/2]

Preset & Slic3r::PresetCollection::load_preset ( const std::string &  path,
const std::string &  name,
const DynamicPrintConfig config,
bool  select = true 
)
inherited
744{
745 DynamicPrintConfig cfg(this->default_preset().config);
746 cfg.apply_only(config, cfg.keys(), true);
747 return this->load_preset(path, name, std::move(cfg), select);
748}

References Slic3r::ConfigBase::apply_only(), Slic3r::PresetCollection::default_preset(), Slic3r::DynamicConfig::keys(), Slic3r::PresetCollection::load_preset(), and Slic3r::PresetCollection::name().

Referenced by Slic3r::PresetBundle::load_config_file_config(), Slic3r::PresetBundle::load_configbundle(), Slic3r::PresetCollection::load_external_preset(), and Slic3r::PresetCollection::load_preset().

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

◆ load_preset() [2/2]

Preset & Slic3r::PresetCollection::load_preset ( const std::string &  path,
const std::string &  name,
DynamicPrintConfig &&  config,
bool  select = true 
)
inherited
885{
886 auto it = this->find_preset_internal(name);
887 if (it == m_presets.end() || it->name != name) {
888 // The preset was not found. Create a new preset.
889 it = m_presets.emplace(it, Preset(m_type, name, false));
890 }
891 Preset &preset = *it;
892 preset.file = path;
893 preset.config = std::move(config);
894 preset.loaded = true;
895 preset.is_dirty = false;
896 if (select)
897 this->select_preset_by_name(name, true);
898 return preset;
899}
bool loaded
Definition Preset.hpp:156
bool is_dirty
Definition Preset.hpp:140

References Slic3r::Preset::config, Slic3r::Preset::file, Slic3r::PresetCollection::find_preset_internal(), Slic3r::Preset::is_dirty, Slic3r::Preset::loaded, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::m_type, Slic3r::PresetCollection::name(), Slic3r::PresetCollection::preset(), and Slic3r::PresetCollection::select_preset_by_name().

+ Here is the call graph for this function:

◆ load_presets()

void Slic3r::PresetCollection::load_presets ( const std::string &  dir_path,
const std::string &  subdir,
PresetsConfigSubstitutions substitutions,
ForwardCompatibilitySubstitutionRule  rule 
)
inherited
683{
684 // Don't use boost::filesystem::canonical() on Windows, it is broken in regard to reparse points,
685 // see https://github.com/prusa3d/PrusaSlicer/issues/732
686 boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / subdir).make_preferred();
687 m_dir_path = dir.string();
688 std::string errors_cummulative;
689 // Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
690 // (see the "Preset already present, not loading" message).
691 std::deque<Preset> presets_loaded;
692 for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
693 if (Slic3r::is_ini_file(dir_entry)) {
694 std::string name = dir_entry.path().filename().string();
695 // Remove the .ini suffix.
696 name.erase(name.size() - 4);
697 if (this->find_preset(name, false)) {
698 // This happens when there's is a preset (most likely legacy one) with the same name as a system preset
699 // that's already been loaded from a bundle.
700 BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << name;
701 continue;
702 }
703 try {
704 Preset preset(m_type, name, false);
705 preset.file = dir_entry.path().string();
706 // Load the preset file, apply preset values on top of defaults.
707 try {
708 DynamicPrintConfig config;
709 ConfigSubstitutions config_substitutions = config.load_from_ini(preset.file, substitution_rule);
710 if (! config_substitutions.empty())
711 substitutions.push_back({ preset.name, m_type, PresetConfigSubstitutions::Source::UserFile, preset.file, std::move(config_substitutions) });
712 // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
713 const Preset &default_preset = this->default_preset_for(config);
715 preset.config.apply(std::move(config));
717 // Report configuration fields, which are misplaced into a wrong group.
718 std::string incorrect_keys = Preset::remove_invalid_keys(config, default_preset.config);
719 if (! incorrect_keys.empty())
720 BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" <<
721 preset.file << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
722 preset.loaded = true;
723 } catch (const std::ifstream::failure &err) {
724 throw Slic3r::RuntimeError(std::string("The selected preset cannot be loaded: ") + preset.file + "\n\tReason: " + err.what());
725 } catch (const std::runtime_error &err) {
726 throw Slic3r::RuntimeError(std::string("Failed loading the preset file: ") + preset.file + "\n\tReason: " + err.what());
727 }
728 presets_loaded.emplace_back(preset);
729 } catch (const std::runtime_error &err) {
730 errors_cummulative += err.what();
731 errors_cummulative += "\n";
732 }
733 }
734 m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
735 std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
737 if (! errors_cummulative.empty())
738 throw Slic3r::RuntimeError(errors_cummulative);
739}
void apply(const ConfigBase &other, bool ignore_nonexistent=false)
Definition Config.hpp:2209
std::string m_dir_path
Definition Preset.hpp:595
static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config)
Definition Preset.cpp:311
static void normalize(DynamicPrintConfig &config)
Definition Preset.cpp:266
Definition avrdude-slic3r.cpp:16
std::vector< ConfigSubstitution > ConfigSubstitutions
Definition Config.hpp:246
bool is_ini_file(const boost::filesystem::directory_entry &dir_entry)
Definition utils.cpp:773
Definition args.hpp:18
static char error[256]
Definition tga.cpp:50

References Slic3r::ConfigBase::apply(), Slic3r::Preset::config, Slic3r::PresetCollection::default_preset(), Slic3r::PresetCollection::default_preset_for(), error, Slic3r::Preset::file, Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::first_visible_idx(), Slic3r::is_ini_file(), Slic3r::ConfigBase::load_from_ini(), Slic3r::Preset::loaded, Slic3r::PresetCollection::m_dir_path, Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::m_type, Slic3r::Preset::name, Slic3r::PresetCollection::name(), Slic3r::Preset::normalize(), Slic3r::PresetCollection::preset(), Slic3r::Preset::remove_invalid_keys(), Slic3r::PresetCollection::select_preset(), and Slic3r::PresetConfigSubstitutions::UserFile.

Referenced by Slic3r::PresetBundle::load_presets().

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

◆ map_alias_to_profile_name()

const std::vector< std::pair< std::string, std::string > > & Slic3r::PresetCollection::map_alias_to_profile_name ( )
inlineinherited

References Slic3r::PresetCollection::m_map_alias_to_profile_name.

Referenced by Slic3r::ExtruderFilaments::get_preset_name_by_alias().

+ Here is the caller graph for this function:

◆ merge_presets()

std::vector< std::string > Slic3r::PresetCollection::merge_presets ( PresetCollection &&  other,
const VendorMap new_vendors 
)
protectedinherited
1430{
1431 std::vector<std::string> duplicates;
1432 for (Preset &preset : other.m_presets) {
1434 continue;
1435 Preset key(m_type, preset.name);
1436 auto it = std::lower_bound(m_presets.begin() + m_num_default_presets, m_presets.end(), key);
1437 if (it == m_presets.end() || it->name != preset.name) {
1438 if (preset.vendor != nullptr) {
1439 // Re-assign a pointer to the vendor structure in the new PresetBundle.
1440 auto it = new_vendors.find(preset.vendor->id);
1441 assert(it != new_vendors.end());
1442 preset.vendor = &it->second;
1443 }
1444 m_presets.emplace(it, std::move(preset));
1445 } else
1446 duplicates.emplace_back(std::move(preset.name));
1447 }
1448 return duplicates;
1449}
std::string id
Definition Preset.hpp:33

References Slic3r::VendorProfile::id, Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::m_type, Slic3r::Preset::name, Slic3r::PresetCollection::preset(), and Slic3r::Preset::vendor.

Referenced by Slic3r::PresetBundle::merge_presets().

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

◆ name()

std::string Slic3r::PresetCollection::name ( ) const
inherited
1483{
1484 switch (this->type()) {
1485 case Preset::TYPE_PRINT: return L("print");
1486 case Preset::TYPE_FILAMENT: return L("filament");
1487 case Preset::TYPE_SLA_PRINT: return L("SLA print");
1488 case Preset::TYPE_SLA_MATERIAL: return L("SLA material");
1489 case Preset::TYPE_PRINTER: return L("printer");
1490 default: return "invalid";
1491 }
1492}
@ TYPE_SLA_PRINT
Definition Preset.hpp:113
@ TYPE_PRINT
Definition Preset.hpp:112
@ TYPE_SLA_MATERIAL
Definition Preset.hpp:115
@ TYPE_FILAMENT
Definition Preset.hpp:114
#define L(s)
Definition I18N.hpp:18

References L, Slic3r::PresetCollection::type(), 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::PresetCollection::delete_preset(), Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetBundle::load_configbundle(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetCollection::load_presets(), Slic3r::GUI::Tab::name(), Slic3r::PresetCollection::select_preset_by_name(), and Slic3r::PresetCollection::select_preset_by_name_strict().

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

◆ num_default_presets()

size_t Slic3r::PresetCollection::num_default_presets ( ) const
inlineinherited
511{ return m_num_default_presets; }

References Slic3r::PresetCollection::m_num_default_presets.

Referenced by Slic3r::ExtruderFilaments::first_compatible_idx(), Slic3r::GUI::PlaterPresetComboBox::update(), Slic3r::GUI::TabPresetComboBox::update(), Slic3r::GUI::PresetComboBox::update(), and Slic3r::ExtruderFilaments::update_compatible_internal().

+ Here is the caller graph for this function:

◆ num_visible()

size_t Slic3r::PresetCollection::num_visible ( ) const
inlineinherited
473{ return std::count_if(m_presets.begin(), m_presets.end(), [](const Preset &preset){return preset.is_visible;}); }

References Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::preset().

+ Here is the call graph for this function:

◆ only_default_printers()

bool Slic3r::PrinterPresetCollection::only_default_printers ( ) const
1554{
1555 for (const auto& printer : get_presets()) {
1556 if (! printer.is_default)
1557 return false;
1558 }
1559 return true;
1560}
const std::deque< Preset > & get_presets() const
Definition Preset.hpp:393

References Slic3r::PresetCollection::get_presets().

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

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

◆ operator()()

const std::deque< Preset > & Slic3r::PresetCollection::operator() ( ) const
inlineinherited
305{ return m_presets; }

References Slic3r::PresetCollection::m_presets.

◆ operator=()

PrinterPresetCollection & Slic3r::PrinterPresetCollection::operator= ( const PrinterPresetCollection other)
privatedefault

◆ path_from_name()

std::string Slic3r::PresetCollection::path_from_name ( const std::string &  new_name) const
inherited
1527{
1528 std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini");
1529 return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
1530}

References Slic3r::PresetCollection::m_dir_path.

Referenced by Slic3r::PresetCollection::get_preset_with_name(), Slic3r::PresetBundle::load_config_file_config(), and Slic3r::PresetCollection::save_current_preset().

+ Here is the caller graph for this function:

◆ preset() [1/2]

Preset & Slic3r::PresetCollection::preset ( size_t  idx,
bool  respect_active_preset = true 
)
inlineinherited
402{ return (idx == m_idx_selected && respect_active_preset) ? m_edited_preset : m_presets[idx]; }

References Slic3r::PresetCollection::m_edited_preset, Slic3r::PresetCollection::m_idx_selected, and Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::PresetBundle::PresetBundle(), Slic3r::GUI::Tab::compatible_widget_create(), Slic3r::PresetCollection::delete_preset(), Slic3r::PresetCollection::find_preset(), find_system_preset_by_model_and_variant(), Slic3r::PresetCollection::first_compatible(), Slic3r::PresetCollection::first_compatible(), Slic3r::PresetCollection::first_compatible(), Slic3r::ExtruderFilaments::first_compatible_idx(), Slic3r::PresetCollection::first_visible(), Slic3r::PresetCollection::first_visible(), Slic3r::PresetCollection::get_preset_parent(), Slic3r::PresetCollection::get_preset_with_name(), Slic3r::PresetCollection::get_preset_with_vendor_profile(), Slic3r::PresetCollection::get_selected_preset_parent(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetCollection::load_presets(), Slic3r::PresetCollection::merge_presets(), Slic3r::PresetCollection::num_visible(), Slic3r::PresetCollection::reset(), Slic3r::PresetCollection::save_current_preset(), Slic3r::PresetCollection::select_preset(), Slic3r::PresetCollection::system_preset_names(), Slic3r::PresetCollection::update_map_alias_to_profile_name(), Slic3r::PresetCollection::update_map_system_profile_renamed(), and Slic3r::PresetCollection::update_vendor_ptrs_after_copy().

+ Here is the caller graph for this function:

◆ preset() [2/2]

const Preset & Slic3r::PresetCollection::preset ( size_t  idx,
bool  respect_active_preset = true 
) const
inlineinherited
403{ return const_cast<PresetCollection*>(this)->preset(idx); }

References Slic3r::PresetCollection::preset().

Referenced by Slic3r::PresetCollection::preset().

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

◆ reset()

void Slic3r::PresetCollection::reset ( bool  delete_files)
inherited
653{
654 if (m_presets.size() > m_num_default_presets) {
655 if (delete_files) {
656 // Erase the preset files.
657 for (Preset &preset : m_presets)
658 if (! preset.is_default && ! preset.is_external && ! preset.is_system)
659 boost::nowide::remove(preset.file.c_str());
660 }
661 // Don't use m_presets.resize() here as it requires a default constructor for Preset.
662 m_presets.erase(m_presets.begin() + m_num_default_presets, m_presets.end());
663 this->select_preset(0);
664 }
667}

References Slic3r::Preset::file, Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::PresetCollection::m_map_alias_to_profile_name, Slic3r::PresetCollection::m_map_system_profile_renamed, Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::preset(), and Slic3r::PresetCollection::select_preset().

Referenced by Slic3r::PresetBundle::reset().

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

◆ save_current_preset()

bool Slic3r::PresetCollection::save_current_preset ( const std::string &  new_name,
bool  detach = false 
)
inherited
902{
903 bool is_saved_as_new{ false };
904 // 1) Find the preset with a new_name or create a new one,
905 // initialize it with the edited config.
906 auto it = this->find_preset_internal(new_name);
907 if (it != m_presets.end() && it->name == new_name) {
908 // Preset with the same name found.
909 Preset &preset = *it;
911 // Cannot overwrite the default preset.
912 return false;
913 // Overwriting an existing preset.
914 preset.config = std::move(m_edited_preset.config);
915 // The newly saved preset will be activated -> make it visible.
916 preset.is_visible = true;
917 if (detach) {
918 // Clear the link to the parent profile.
919 preset.vendor = nullptr;
920 preset.inherits().clear();
921 preset.alias.clear();
922 preset.renamed_from.clear();
923 }
924 } else {
925 is_saved_as_new = true;
926 // Creating a new preset.
927 Preset &preset = *m_presets.insert(it, m_edited_preset);
928 std::string &inherits = preset.inherits();
929 std::string old_name = preset.name;
930 preset.name = new_name;
931 preset.file = this->path_from_name(new_name);
932 preset.vendor = nullptr;
933 preset.alias.clear();
934 preset.renamed_from.clear();
935 if (detach) {
936 // Clear the link to the parent profile.
937 inherits.clear();
938 } else if (preset.is_system) {
939 // Inheriting from a system preset.
940 inherits = /* preset.vendor->name + "/" + */ old_name;
941 } else if (inherits.empty()) {
942 // Inheriting from a user preset. Link the new preset to the old preset.
943 // inherits = old_name;
944 } else {
945 // Inherited from a user preset. Just maintain the "inherited" flag,
946 // meaning it will inherit from either the system preset, or the inherited user preset.
947 }
948 preset.is_default = false;
949 preset.is_system = false;
950 preset.is_external = false;
951 // The newly saved preset will be activated -> make it visible.
952 preset.is_visible = true;
953 // Just system presets have aliases
954 preset.alias.clear();
955 }
956 // 2) Activate the saved preset.
957 this->select_preset_by_name(new_name, true);
958 // 2) Store the active preset to disk.
959 this->get_selected_preset().save();
960
961 return is_saved_as_new;
962}
void save()
Definition Preset.cpp:327

References Slic3r::Preset::alias, Slic3r::Preset::config, Slic3r::Preset::file, Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::Preset::inherits(), Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::Preset::is_system, Slic3r::Preset::is_visible, Slic3r::PresetCollection::m_edited_preset, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, Slic3r::PresetCollection::path_from_name(), Slic3r::PresetCollection::preset(), Slic3r::Preset::renamed_from, Slic3r::Preset::save(), Slic3r::PresetCollection::select_preset_by_name(), and Slic3r::Preset::vendor.

Referenced by Slic3r::PresetBundle::save_changes_for_preset().

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

◆ saved_is_dirty()

bool Slic3r::PresetCollection::saved_is_dirty ( ) const
inlineinherited
487 { return is_dirty(&this->get_edited_preset(), &m_saved_preset); }
Preset m_saved_preset
Definition Preset.hpp:586

References Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::is_dirty(), and Slic3r::PresetCollection::m_saved_preset.

+ Here is the call graph for this function:

◆ section_name()

std::string Slic3r::PresetCollection::section_name ( ) const
inherited
1495{
1496 switch (this->type()) {
1497 case Preset::TYPE_PRINT: return "print";
1498 case Preset::TYPE_FILAMENT: return "filament";
1499 case Preset::TYPE_SLA_PRINT: return "sla_print";
1500 case Preset::TYPE_SLA_MATERIAL: return "sla_material";
1501 case Preset::TYPE_PRINTER: return "printer";
1502 default: return "invalid";
1503 }
1504}

References Slic3r::PresetCollection::type(), 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::PresetBundle::load_configbundle().

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

◆ select_preset()

Preset & Slic3r::PresetCollection::select_preset ( size_t  idx)
inherited
1370{
1371 for (Preset &preset : m_presets)
1372 preset.is_dirty = false;
1373 if (idx >= m_presets.size())
1374 idx = first_visible_idx();
1375 m_idx_selected = idx;
1377 bool default_visible = ! m_default_suppressed || m_idx_selected < m_num_default_presets;
1378 for (size_t i = 0; i < m_num_default_presets; ++i)
1379 m_presets[i].is_visible = default_visible;
1380 return m_presets[idx];
1381}

References Slic3r::PresetCollection::first_visible_idx(), Slic3r::Preset::is_dirty, Slic3r::PresetCollection::m_default_suppressed, Slic3r::PresetCollection::m_edited_preset, Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, and Slic3r::PresetCollection::preset().

Referenced by Slic3r::PresetBundle::PresetBundle(), Slic3r::PresetCollection::delete_current_preset(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_presets(), Slic3r::PresetCollection::reset(), Slic3r::PresetCollection::select_preset_by_name(), Slic3r::PresetCollection::select_preset_by_name_strict(), and Slic3r::PresetCollection::update_compatible().

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

◆ select_preset_by_name()

bool Slic3r::PresetCollection::select_preset_by_name ( const std::string &  name,
bool  force 
)
inherited
1384{
1385 std::string name = Preset::remove_suffix_modified(name_w_suffix);
1386 // 1) Try to find the preset by its name.
1387 auto it = this->find_preset_internal(name);
1388 size_t idx = 0;
1389 if (it != m_presets.end() && it->name == name && it->is_visible)
1390 // Preset found by its name and it is visible.
1391 idx = it - m_presets.begin();
1392 else {
1393 // Find the first visible preset.
1394 for (size_t i = m_default_suppressed ? m_num_default_presets : 0; i < m_presets.size(); ++ i)
1395 if (m_presets[i].is_visible) {
1396 idx = i;
1397 break;
1398 }
1399 // If the first visible preset was not found, return the 0th element, which is the default preset.
1400 }
1401
1402 // 2) Select the new preset.
1403 if (m_idx_selected != idx || force) {
1404 this->select_preset(idx);
1405 return true;
1406 }
1407
1408 return false;
1409}
static std::string remove_suffix_modified(const std::string &name)
Definition Preset.cpp:258

References Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::m_default_suppressed, Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::name(), Slic3r::Preset::remove_suffix_modified(), and Slic3r::PresetCollection::select_preset().

Referenced by Slic3r::PresetCollection::delete_preset(), Slic3r::PresetCollection::get_preset_with_name(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetBundle::load_selections(), Slic3r::PresetCollection::save_current_preset(), and Slic3r::GUI::DiffPresetDialog::update_compatibility().

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

◆ select_preset_by_name_strict()

bool Slic3r::PresetCollection::select_preset_by_name_strict ( const std::string &  name)
protectedinherited
1412{
1413 // 1) Try to find the preset by its name.
1414 auto it = this->find_preset_internal(name);
1415 size_t idx = (size_t)-1;
1416 if (it != m_presets.end() && it->name == name && it->is_visible)
1417 // Preset found by its name.
1418 idx = it - m_presets.begin();
1419 // 2) Select the new preset.
1420 if (idx != (size_t)-1) {
1421 this->select_preset(idx);
1422 return true;
1423 }
1424 m_idx_selected = idx;
1425 return false;
1426}

References Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::name(), and Slic3r::PresetCollection::select_preset().

Referenced by Slic3r::PresetBundle::load_selections().

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

◆ set_default_suppressed()

void Slic3r::PresetCollection::set_default_suppressed ( bool  default_suppressed)
inherited
1186{
1187 if (m_default_suppressed != default_suppressed) {
1188 m_default_suppressed = default_suppressed;
1189 bool default_visible = ! default_suppressed || m_idx_selected < m_num_default_presets;
1190 for (size_t i = 0; i < m_num_default_presets; ++ i)
1191 m_presets[i].is_visible = default_visible;
1192 }
1193}

References Slic3r::PresetCollection::m_default_suppressed, Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_num_default_presets, and Slic3r::PresetCollection::m_presets.

◆ size()

size_t Slic3r::PresetCollection::size ( ) const
inlineinherited
459{ return m_presets.size(); }

References Slic3r::PresetCollection::m_presets.

Referenced by Slic3r::GUI::Tab::compatible_widget_create(), Slic3r::PresetUpdater::priv::perform_updates(), and Slic3r::GUI::TabPresetComboBox::update().

+ Here is the caller graph for this function:

◆ system_preset_names()

std::vector< std::string > Slic3r::PresetCollection::system_preset_names ( ) const
inherited
1509{
1510 size_t num = 0;
1511 for (const Preset &preset : m_presets)
1512 if (preset.is_system)
1513 ++ num;
1514 std::vector<std::string> out;
1515 out.reserve(num);
1516 for (const Preset &preset : m_presets)
1517 if (preset.is_system) {
1518 out.emplace_back(preset.name);
1519 out.insert(out.end(), preset.renamed_from.begin(), preset.renamed_from.end());
1520 }
1521 std::sort(out.begin(), out.end());
1522 return out;
1523}

References Slic3r::Preset::is_system, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, Slic3r::PresetCollection::preset(), and Slic3r::Preset::renamed_from.

Referenced by Slic3r::flatten_configbundle_hierarchy().

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

◆ type()

◆ update_compatible() [1/2]

void Slic3r::PresetCollection::update_compatible ( const PresetWithVendorProfile active_printer,
const PresetWithVendorProfile active_print,
PresetSelectCompatibleType  select_other_if_incompatible 
)
inlineinherited
471 { this->update_compatible(active_printer, active_print, select_other_if_incompatible, [](const Preset&) -> int { return 0; }); }
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible, PreferedCondition prefered_condition)
Definition Preset.hpp:464

References Slic3r::PresetCollection::update_compatible().

+ Here is the call graph for this function:

◆ update_compatible() [2/2]

template<typename PreferedCondition >
void Slic3r::PresetCollection::update_compatible ( const PresetWithVendorProfile active_printer,
const PresetWithVendorProfile active_print,
PresetSelectCompatibleType  select_other_if_incompatible,
PreferedCondition  prefered_condition 
)
inlineinherited
465 {
466 if (this->update_compatible_internal(active_printer, active_print, select_other_if_incompatible) == (size_t)-1)
467 // Find some other compatible preset, or the "-- default --" preset.
468 this->select_preset(this->first_compatible_idx(prefered_condition));
469 }
size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible)
Definition Preset.cpp:1195

References Slic3r::PresetCollection::first_compatible_idx(), Slic3r::PresetCollection::select_preset(), and Slic3r::PresetCollection::update_compatible_internal().

Referenced by Slic3r::PresetCollection::update_compatible().

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

◆ update_compatible_internal()

size_t Slic3r::PresetCollection::update_compatible_internal ( const PresetWithVendorProfile active_printer,
const PresetWithVendorProfile active_print,
PresetSelectCompatibleType  unselect_if_incompatible 
)
privateinherited
1196{
1197 DynamicPrintConfig config;
1198 config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
1199 const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
1200 if (opt)
1201 config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
1202 bool some_compatible = false;
1203 std::vector<size_t> indices_of_template_presets;
1204 for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++ idx_preset) {
1205 bool selected = idx_preset == m_idx_selected;
1206 Preset &preset_selected = m_presets[idx_preset];
1207 Preset &preset_edited = selected ? m_edited_preset : preset_selected;
1208
1209 const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited);
1210 bool was_compatible = preset_edited.is_compatible;
1211 preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config);
1212 some_compatible |= preset_edited.is_compatible;
1213 if (active_print != nullptr)
1214 preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer);
1215 if (! preset_edited.is_compatible && selected &&
1216 (unselect_if_incompatible == PresetSelectCompatibleType::Always || (unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible && was_compatible)))
1217 m_idx_selected = size_t(-1);
1218 if (selected)
1219 preset_selected.is_compatible = preset_edited.is_compatible;
1220 if (preset_edited.vendor && preset_edited.vendor->templates_profile) {
1221 if (preset_selected.is_visible)
1222 indices_of_template_presets.push_back(idx_preset);
1223 else {
1224 preset_selected.is_compatible = false;
1225 if (selected)
1226 m_idx_selected = size_t(-1);
1227 }
1228 }
1229 }
1230 // filter out template profiles where profile with same alias and compability exists
1231 if (!indices_of_template_presets.empty()) {
1232 for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++idx_preset) {
1233 if (m_presets[idx_preset].vendor && !m_presets[idx_preset].vendor->templates_profile && m_presets[idx_preset].is_compatible) {
1234 std::string preset_alias = m_presets[idx_preset].alias;
1235 for (size_t idx_of_template_in_presets : indices_of_template_presets) {
1236 if (m_presets[idx_of_template_in_presets].alias == preset_alias) {
1237 // unselect selected template filament if there is non-template alias compatible
1238 if (idx_of_template_in_presets == m_idx_selected && (unselect_if_incompatible == PresetSelectCompatibleType::Always || unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible)) {
1239 m_idx_selected = size_t(-1);
1240 }
1241 m_presets[idx_of_template_in_presets].is_compatible = false;
1242 break;
1243 }
1244 }
1245 }
1246 }
1247 }
1248
1249 // Update visibility of the default profiles here if the defaults are suppressed, the current profile is not compatible and we don't want to select another compatible profile.
1251 for (size_t i = 0; i < m_num_default_presets; ++ i)
1252 m_presets[i].is_visible = ! some_compatible;
1253 return m_idx_selected;
1254}
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config)
Definition Preset.cpp:361
bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer)
Definition Preset.cpp:338
ConfigOptionFloatsTempl< false > ConfigOptionFloats
Definition Config.hpp:716

References Slic3r::Always, Slic3r::Preset::config, Slic3r::PresetCollection::get_preset_with_vendor_profile(), Slic3r::Preset::is_compatible, Slic3r::is_compatible_with_print(), Slic3r::is_compatible_with_printer(), Slic3r::Preset::is_visible, Slic3r::PresetCollection::m_default_suppressed, Slic3r::PresetCollection::m_edited_preset, Slic3r::PresetCollection::m_idx_selected, Slic3r::PresetCollection::m_num_default_presets, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, Slic3r::OnlyIfWasCompatible, Slic3r::ConfigBase::option(), Slic3r::PresetWithVendorProfile::preset, Slic3r::DynamicConfig::set_key_value(), Slic3r::ConfigOptionVector< T >::size(), Slic3r::VendorProfile::templates_profile, and Slic3r::Preset::vendor.

Referenced by Slic3r::PresetCollection::update_compatible().

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

◆ update_dirty()

bool Slic3r::PresetCollection::update_dirty ( )
inherited
1259{
1260 bool was_dirty = this->get_selected_preset().is_dirty;
1261 bool is_dirty = current_is_dirty();
1264
1265 return was_dirty != is_dirty;
1266}
bool current_is_dirty() const
Definition Preset.hpp:476

References Slic3r::PresetCollection::current_is_dirty(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::Preset::is_dirty, and Slic3r::PresetCollection::is_dirty().

Referenced by Slic3r::PresetCollection::load_external_preset(), and Slic3r::GUI::TabPresetComboBox::update_dirty().

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

◆ update_map_alias_to_profile_name()

void Slic3r::PresetCollection::update_map_alias_to_profile_name ( )
protectedinherited
1464{
1466 for (const Preset &preset : m_presets)
1467 m_map_alias_to_profile_name.emplace_back(preset.alias, preset.name);
1468 std::sort(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [](auto &l, auto &r) { return l.first < r.first; });
1469}

References Slic3r::Preset::alias, Slic3r::PresetCollection::m_map_alias_to_profile_name, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, and Slic3r::PresetCollection::preset().

Referenced by Slic3r::PresetBundle::update_system_maps().

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

◆ update_map_system_profile_renamed()

void Slic3r::PresetCollection::update_map_system_profile_renamed ( )
protectedinherited
1472{
1474 for (Preset &preset : m_presets)
1475 for (const std::string &renamed_from : preset.renamed_from) {
1476 const auto [it, success] = m_map_system_profile_renamed.insert(std::pair<std::string, std::string>(renamed_from, preset.name));
1477 if (! success)
1478 BOOST_LOG_TRIVIAL(error) << boost::format("Preset name \"%1%\" was marked as renamed from \"%2%\", though preset name \"%3%\" was marked as renamed from \"%2%\" as well.") % preset.name % renamed_from % it->second;
1479 }
1480}
TOKEN * string(char *text)
Definition config.c:233
#define const
Definition getopt.c:38
STL namespace.

References error, Slic3r::PresetCollection::m_map_system_profile_renamed, Slic3r::PresetCollection::m_presets, Slic3r::Preset::name, Slic3r::PresetCollection::preset(), and Slic3r::Preset::renamed_from.

Referenced by Slic3r::PresetBundle::update_system_maps().

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

◆ update_saved_preset_from_current_preset()

void Slic3r::PresetCollection::update_saved_preset_from_current_preset ( )
inlineinherited

References Slic3r::PresetCollection::m_edited_preset, and Slic3r::PresetCollection::m_saved_preset.

Referenced by Slic3r::PresetCollection::PresetCollection().

+ Here is the caller graph for this function:

◆ update_vendor_ptrs_after_copy()

void Slic3r::PresetCollection::update_vendor_ptrs_after_copy ( const VendorMap vendors)
protectedinherited
1452{
1453 for (Preset &preset : m_presets)
1454 if (preset.vendor != nullptr) {
1455 assert(! preset.is_default && ! preset.is_external);
1456 // Re-assign a pointer to the vendor structure in the new PresetBundle.
1457 auto it = new_vendors.find(preset.vendor->id);
1458 assert(it != new_vendors.end());
1459 preset.vendor = &it->second;
1460 }
1461}

References Slic3r::VendorProfile::id, Slic3r::Preset::is_default, Slic3r::Preset::is_external, Slic3r::PresetCollection::m_presets, Slic3r::PresetCollection::preset(), and Slic3r::Preset::vendor.

Referenced by Slic3r::PresetBundle::operator=().

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

Friends And Related Symbol Documentation

◆ PresetBundle

friend class PresetBundle
friend

Member Data Documentation

◆ m_default_suppressed

◆ m_dir_path

std::string Slic3r::PresetCollection::m_dir_path
privateinherited

◆ m_edited_preset

◆ m_idx_selected

◆ m_map_alias_to_profile_name

std::vector<std::pair<std::string, std::string> > Slic3r::PresetCollection::m_map_alias_to_profile_name
privateinherited

◆ m_map_system_profile_renamed

std::map<std::string, std::string> Slic3r::PresetCollection::m_map_system_profile_renamed
privateinherited

◆ m_num_default_presets

◆ m_presets

std::deque<Preset> Slic3r::PresetCollection::m_presets
privateinherited

Referenced by Slic3r::PresetCollection::PresetCollection(), Slic3r::PresetCollection::add_default_preset(), Slic3r::PresetCollection::begin(), Slic3r::PresetCollection::begin(), Slic3r::PresetCollection::cbegin(), Slic3r::PresetCollection::cend(), Slic3r::PresetCollection::default_preset(), Slic3r::PresetCollection::default_preset(), Slic3r::PresetCollection::delete_current_preset(), Slic3r::PresetCollection::delete_preset(), Slic3r::PresetCollection::discard_current_changes(), Slic3r::PresetCollection::end(), Slic3r::PresetCollection::end(), Slic3r::PresetCollection::find_preset(), Slic3r::PresetCollection::find_preset_internal(), Slic3r::PresetCollection::find_preset_renamed(), Slic3r::PresetCollection::first_compatible_idx(), Slic3r::PresetCollection::first_visible_idx(), Slic3r::PresetCollection::get_preset_name_by_alias(), Slic3r::PresetCollection::get_preset_parent(), Slic3r::PresetCollection::get_preset_with_name(), Slic3r::PresetCollection::get_presets(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::PresetCollection::get_selected_preset(), Slic3r::PresetCollection::get_selected_preset_parent(), Slic3r::PresetCollection::has_defaults_only(), Slic3r::PresetCollection::load_external_preset(), Slic3r::PresetCollection::load_preset(), Slic3r::PresetCollection::load_presets(), Slic3r::PresetCollection::merge_presets(), Slic3r::PresetCollection::num_visible(), Slic3r::PresetCollection::operator()(), Slic3r::PresetCollection::preset(), Slic3r::PresetCollection::reset(), Slic3r::PresetCollection::save_current_preset(), Slic3r::PresetCollection::select_preset(), Slic3r::PresetCollection::select_preset_by_name(), Slic3r::PresetCollection::select_preset_by_name_strict(), Slic3r::PresetCollection::set_default_suppressed(), Slic3r::PresetCollection::size(), Slic3r::PresetCollection::system_preset_names(), Slic3r::PresetCollection::update_compatible_internal(), Slic3r::PresetCollection::update_map_alias_to_profile_name(), Slic3r::PresetCollection::update_map_system_profile_renamed(), and Slic3r::PresetCollection::update_vendor_ptrs_after_copy().

◆ m_saved_preset

Preset Slic3r::PresetCollection::m_saved_preset
privateinherited

◆ m_type


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