OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::PrinterPresetCollection Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/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
typedef std::function< void(Preset *preset, std::string sync_info)> SyncFunc

Public Member Functions

 PrinterPresetCollection (Preset::Type type, const std::vector< std::string > &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name="Default Printer")
const Preset & default_preset_for (const DynamicPrintConfig &config) const override
const Preset * find_system_preset_by_model_and_variant (const std::string &model_id, const std::string &variant) const
const Preset * find_custom_preset_by_model_and_variant (const std::string &model_id, const std::string &variant) const
bool only_default_printers () const
Iterator lbegin ()
bool validate_preset (const std::string &name, std::string &inherit)
Iterator begin ()
ConstIterator begin () const
ConstIterator cbegin () const
Iterator end ()
ConstIterator end () const
ConstIterator cend () const
Iterator erase (Iterator it)
void set_sync_func (SyncFunc func)
void lock ()
void unlock ()
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, std::function< void(Preset &)> preset_loaded_fn=nullptr, const PresetOrigin &load_origin=PresetOrigin(), bool read_only=false)
void update_user_presets_directory (const std::string &dir_path, const std::string &type)
void save_user_presets (const std::string &dir_path, const std::string &type, std::map< std::string, std::string > &need_to_delete_list)
bool load_user_preset (std::string name, std::map< std::string, std::string > preset_values, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule, const PresetOrigin &load_origin=PresetOrigin(PresetOrigin::Kind::User))
void update_after_user_presets_loaded ()
std::vector< LegacyUserFilamentPreset > legacy_user_filament_presets (const std::map< std::string, std::vector< std::string > > &printers_by_parent)
void apply_legacy_user_filament_presets (const std::vector< LegacyUserFilamentPreset > &written)
int get_user_presets (PresetBundle *preset_bundle, std::vector< Preset > &result_presets)
void set_sync_info_and_save (std::string name, std::string setting_id, std::string syncinfo, long long update_time, const std::string &user_id)
bool need_sync (std::string name, std::string setting_id, long long update_time)
Preset * get_preset_differed_for_save (Preset &preset)
int get_differed_values_to_update (Preset &preset, std::map< std::string, std::string > &key_values)
void load_project_embedded_presets (std::vector< Preset * > &project_presets, const std::string &type, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule)
std::vector< Preset * > get_project_embedded_presets ()
bool reset_project_embedded_presets ()
Preset & load_preset (const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select=true, Semver file_version=Semver())
Preset & load_preset (const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select=true, Semver file_version=Semver())
bool clone_presets (std::vector< Preset const * > const &presets, std::vector< std::string > &failures, std::function< void(Preset &, Preset::Type &)> modifier, bool force_rewritten=false)
bool clone_presets_for_printer (std::vector< Preset const * > const &templates, std::vector< std::string > &failures, std::string const &printer, std::function< std::string(std::string)> create_filament_id, bool force_rewritten=false)
bool clone_presets_for_filament (Preset const *const &preset, std::vector< std::string > &failures, std::string const &filament_name, std::string const &filament_id, const DynamicConfig &dynamic_config, const std::string &compatible_printers, bool force_rewritten=false)
std::map< std::string, std::vector< Preset const * > > get_filament_presets () const
std::pair< Preset *, bool > load_external_preset (const std::string &path, const std::string &name, const std::string &original_name, const DynamicPrintConfig &config, const std::set< std::string > &different_settings_list, LoadAndSelect select=LoadAndSelect::Always, const Semver file_version=Semver(), const std::string filament_id=std::string())
void save_current_preset (const std::string &new_name, bool detach=false, bool save_to_project=false, Preset *_curr_preset=nullptr)
std::string add_detached_preset (const std::string &name_base, DynamicPrintConfig config, const std::string &filament_id=std::string())
bool delete_current_preset ()
bool delete_preset (const std::string &name, bool force=false)
void check_and_fix_syncinfo (Preset &preset, const std::string &user_id)
void set_default_suppressed (bool default_suppressed)
bool is_default_suppressed () const
Preset & select_preset (size_t idx)
Preset & get_selected_preset ()
const Preset & get_selected_preset () const
size_t get_selected_idx () const
std::string get_selected_preset_name () const
const Preset * get_selected_preset_parent () const
const Preset * get_preset_parent (const Preset &child) const
const Preset * get_preset_base (const Preset &child) const
Preset & get_edited_preset ()
const Preset & get_edited_preset () const
const Preset & get_selected_preset_base () 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
bool is_alias_exist (const std::string &alias, Preset *preset=nullptr)
void set_printer_hold_alias (const std::string &alias, Preset &preset, bool remove=false)
const std::deque< Preset > & get_presets () const
size_t get_idx_selected ()
Preset & default_preset (size_t idx=0)
const Preset & default_preset (size_t idx=0) const
Preset & preset (size_t idx, bool real=false)
const Preset & preset (size_t idx) const
void discard_current_changes ()
Preset * find_preset (const std::string &name, bool first_visible_if_not_found=false, bool real=false, bool only_from_library=false)
const Preset * find_preset (const std::string &name, bool first_visible_if_not_found=false) const
Preset * find_preset2 (const std::string &name, bool auto_match=true)
const Preset * find_preset2 (const std::string &name, bool auto_match=true) const
size_t first_visible_idx () const
size_t first_visible_idx_by_type (const std::string &filament_type) const
std::string filament_id_by_type (const std::string &filament_type) const
template<typename PreferedCondition>
size_t first_compatible_idx (PreferedCondition prefered_condition) const
size_t first_compatible_idx () const
std::vector< std::string > diameters_of_selected_printer ()
Preset & first_visible ()
const Preset & first_visible () const
Preset & first_compatible ()
template<typename PreferedCondition>
Preset & first_compatible (PreferedCondition prefered_condition)
const Preset & first_compatible () const
size_t size () const
bool has_defaults_only () const
int error_count () 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)
bool is_base_preset (const Preset &preset) const
std::string path_from_name (const std::string &new_name, bool detach=false) const
std::string path_for_preset (const Preset &preset) const
std::string get_preset_alias (Preset &preset, bool force=false)
size_t num_default_presets ()

Static Public Member Functions

static bool write_legacy_user_filament_preset (const LegacyUserFilamentPreset &legacy)
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 std::vector< std::string > dirty_options_without_option_list (const Preset *edited, const Preset *reference, const std::set< std::string > &option_ignore_list, const bool deep_compare=false)

Public Attributes

SyncFunc sync_func { nullptr }

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::vector< std::string > > merge_presets (const std::vector< PresetCollection * > &others, const VendorMap &new_vendors)
void update_map_alias_to_profile_name ()
void update_map_system_profile_renamed ()
void update_library_profile_excluded_from ()
void set_custom_preset_alias (Preset &preset)

Private Member Functions

 PrinterPresetCollection ()=default
 PrinterPresetCollection (const PrinterPresetCollection &other)=delete
PrinterPresetCollection & operator= (const PrinterPresetCollection &other)=default
UserPresetLoad resolve_user_preset (const boost::filesystem::path &file, const std::string &canonical_name, const PresetOrigin &load_origin, ForwardCompatibilitySubstitutionRule substitution_rule, const std::string &extruder_id_name, const std::string &extruder_variant_name, std::set< std::string > *key_set1, std::set< std::string > *key_set2, bool read_only) const
void commit_user_preset (UserPresetLoad &&loaded, std::deque< Preset > &presets_loaded, PresetsConfigSubstitutions &substitutions, const std::function< void(Preset &)> &preset_loaded_fn, bool read_only)
std::string canonical_preset_name (const std::string &name, const PresetOrigin &load_origin=PresetOrigin()) const
Preset & append_preset (std::string &&path, const std::string &name, DynamicPrintConfig &&config)
void sort_presets ()
std::deque< Preset >::iterator find_preset_internal (const std::string &name, bool from_orca_lib_only=false)
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)

Static Private Member Functions

static bool filament_preset_less (const Preset &a, const Preset &b)

Private Attributes

Preset::Type m_type
std::deque< Preset > m_presets
std::map< std::string, std::vector< std::string > > m_map_alias_to_profile_name
std::unordered_map< std::string, std::unordered_set< std::string > > m_printer_hold_alias
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
std::recursive_mutex m_mutex
int m_errors = 0

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

◆ SyncFunc

typedef std::function<void(Preset* preset, std::string sync_info)> Slic3r::PresetCollection::SyncFunc
inherited

Member Enumeration Documentation

◆ LoadAndSelect

enum class Slic3r::PresetCollection::LoadAndSelect
stronginherited
Enumerator
Never 
Always 
OnlyIfModified 
667 {
668 // Never select
669 Never,
670 // Always select
671 Always,
672 // Select a profile only if it was modified.
673 OnlyIfModified,
674 };
@ Always
Definition Preset.hpp:527
@ Never
Definition Preset.hpp:523

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 Printer" )
inline
1119 :
1120 PresetCollection(type, keys, defaults, default_name) {}
Preset::Type type() const
Definition Preset.hpp:600

References Slic3r::PresetCollection::PresetCollection(), and Slic3r::PresetCollection::type().

Referenced by PrinterPresetCollection(), and operator=().

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

◆ PrinterPresetCollection() [2/3]

Slic3r::PrinterPresetCollection::PrinterPresetCollection ( )
privatedefault

◆ PrinterPresetCollection() [3/3]

Slic3r::PrinterPresetCollection::PrinterPresetCollection ( const PrinterPresetCollection & other)
privatedelete

References PrinterPresetCollection().

Here is the call graph for this function:

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
1788{
1789 // Insert just the default preset.
1790 m_presets.emplace_back(Preset(this->type(), preset_name, true));
1791 m_presets.back().config.apply_only(defaults, keys.empty() ? defaults.keys() : keys);
1792 m_presets.back().loaded = true;
1794}
size_t m_num_default_presets
Definition Preset.hpp:1099
std::deque< Preset > m_presets
Definition Preset.hpp:1084
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:2017
@ Preset
Definition calib.hpp:39

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

Referenced by PresetCollection().

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

◆ add_detached_preset()

std::string Slic3r::PresetCollection::add_detached_preset ( const std::string & name_base,
DynamicPrintConfig config,
const std::string & filament_id = std::string() )
inherited
3491{
3492 if (name_base.empty())
3493 return std::string();
3494 Preset stored(m_type, name_base);
3495 stored.config = std::move(config);
3496 stored.filament_id = filament_id;
3497
3498 // Uniquify verbatim; only on collision append " (Published)" then " (Published 2)".
3499 const std::string base_name = name_base;
3500 std::string final_name = base_name;
3501 auto exists = [this](const std::string &candidate) -> bool {
3502 const auto it = this->find_preset_internal(candidate);
3503 return it != m_presets.end() && it->name == candidate;
3504 };
3505 if (exists(final_name)) {
3506 final_name = base_name + " (Published)";
3507 for (int i = 2; exists(final_name); ++i)
3508 final_name = base_name + " (Published " + std::to_string(i) + ")";
3509 }
3510
3511 // Creation branch of save_current_preset(detach=true), without its selection side
3512 // effects or project-embedded path.
3513 lock();
3514 const auto it = this->find_preset_internal(final_name);
3515 if (m_presets.begin() + m_idx_selected >= it)
3517 Preset &preset = *m_presets.insert(it, stored);
3518 preset.name = final_name;
3519 preset.vendor = nullptr;
3520 preset.alias.clear();
3521 preset.renamed_from.clear();
3522 preset.m_excluded_from.clear();
3523 preset.setting_id.clear();
3524 preset.inherits().clear();
3525 preset.version = Semver::parse(SoftFever_VERSION).value_or(Semver());
3526 preset.is_default = false;
3527 preset.is_system = false;
3528 preset.is_external = false;
3529 preset.bundle_id.clear();
3530 preset.file = this->path_for_preset(preset);
3531 preset.is_visible = true;
3532 preset.is_project_embedded = true;
3534 preset.config.option<ConfigOptionString>("print_settings_id", true)->value = final_name;
3535 else if (m_type == Preset::TYPE_FILAMENT)
3536 preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = final_name;
3537 else if (m_type == Preset::TYPE_PRINTER)
3538 preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = final_name;
3539 unlock();
3540
3541 return final_name;
3542}
void unlock()
Definition Preset.hpp:596
std::string path_for_preset(const Preset &preset) const
Definition Preset.cpp:4494
Preset::Type m_type
Definition Preset.hpp:1080
size_t m_idx_selected
Definition Preset.hpp:1096
Preset & preset(size_t idx, bool real=false)
Definition Preset.hpp:790
std::deque< Preset >::iterator find_preset_internal(const std::string &name, bool from_orca_lib_only=false)
Definition Preset.hpp:1039
void lock()
Definition Preset.hpp:595
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
@ TYPE_FILAMENT
Definition Preset.hpp:248
static boost::optional< Semver > parse(const std::string &str)
Definition Semver.hpp:63
zaa_minimize_perimeter_height ConfigOptionString
Definition PrintConfig.hpp:1702

References Slic3r::Preset::config, Slic3r::Preset::filament_id, find_preset_internal(), lock(), m_idx_selected, m_presets, m_type, Slic3r::Semver::parse(), path_for_preset(), preset(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, and unlock().

Here is the call graph for this function:

◆ append_preset()

Preset & Slic3r::PresetCollection::append_preset ( std::string && path,
const std::string & name,
DynamicPrintConfig && config )
privateinherited
3199{
3200 lock();
3201 Preset &preset = m_presets.emplace_back(m_type, name, false);
3202 preset.file = std::move(path);
3203 preset.config = std::move(config);
3204 preset.loaded = true;
3205 preset.is_dirty = false;
3206 unlock();
3207 return preset;
3208}
std::string name() const
Definition Preset.cpp:4438

References lock(), m_presets, m_type, name(), preset(), and unlock().

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

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

◆ apply_legacy_user_filament_presets()

void Slic3r::PresetCollection::apply_legacy_user_filament_presets ( const std::vector< LegacyUserFilamentPreset > & written)
inherited
2859{
2860 lock();
2861 for (const LegacyUserFilamentPreset &legacy : written) {
2862 auto it = this->find_preset_internal(legacy.preset);
2863 if (it == m_presets.end() || it->name != legacy.preset)
2864 continue; // deleted by the preset sync thread meanwhile
2865 std::vector<std::string> &saved = it->config.option<ConfigOptionStrings>("compatible_printers", true)->values;
2866 std::vector<std::string> &edited = m_edited_preset.config.option<ConfigOptionStrings>("compatible_printers", true)->values;
2867 // Added to the list the preset holds now rather than replacing it: the cloud sync may have given the
2868 // preset a newer list since it was found, and that list is still to be written out.
2869 std::vector<std::string> printers = saved;
2870 for (const std::string &printer : legacy.printers)
2871 if (std::find(printers.begin(), printers.end(), printer) == printers.end())
2872 printers.push_back(printer);
2873 // A change to the list pending in the settings tab stays pending. Without one, the edited copy and the
2874 // snapshot unsaved changes are measured against take the written list, so nothing reads as modified.
2875 if (m_idx_selected == static_cast<size_t>(it - m_presets.begin()) && edited == saved) {
2876 edited = printers;
2877 if (m_saved_preset.name == it->name)
2878 m_saved_preset.config.option<ConfigOptionStrings>("compatible_printers", true)->values = printers;
2879 }
2880 saved = printers;
2881 // Push the change to the cloud copy, as an edit in the settings tab would. A sync already pending for
2882 // the preset (a download waiting to be saved, a deletion) keeps its state.
2883 if (!it->setting_id.empty() && it->sync_info.empty()) {
2884 it->sync_info = "update";
2885 it->save_info();
2886 }
2887 }
2888 unlock();
2889}
Preset m_edited_preset
Definition Preset.hpp:1091
Preset m_saved_preset
Definition Preset.hpp:1093

References find_preset_internal(), lock(), m_edited_preset, m_idx_selected, m_presets, m_saved_preset, and unlock().

Here is the call graph for this function:

◆ begin() [1/2]

◆ begin() [2/2]

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

References m_num_default_presets, and m_presets.

◆ canonical_preset_name()

std::string Slic3r::PresetCollection::canonical_preset_name ( const std::string & name,
const PresetOrigin & load_origin = PresetOrigin() ) const
privateinherited
1797{
1798 const ParsedName parsed = parse_preset_name(name);
1799 PresetOrigin origin = load_origin;
1800 if (origin.kind == PresetOrigin::Kind::Auto) {
1801 origin.kind = parsed.kind;
1802 origin.bundle_id = parsed.bundle_id;
1803 } else if (origin.is_bundle() && origin.bundle_id.empty()) {
1804 origin.bundle_id = parsed.bundle_id;
1805 }
1806 return get_preset_canonical_name(parsed.bare, origin);
1807}
static ParsedName parse_preset_name(const std::string &raw_name)
Definition Preset.cpp:107
std::string get_preset_canonical_name(const std::string &preset_bare_name, const PresetOrigin &origin)
Definition Preset.cpp:134
@ Auto
Definition Preset.hpp:495

References Slic3r::PresetOrigin::Auto, Slic3r::PresetOrigin::bundle_id, Slic3r::get_preset_canonical_name(), Slic3r::PresetOrigin::is_bundle(), Slic3r::PresetOrigin::kind, and name().

Referenced by load_presets(), load_user_preset(), select_preset_by_name(), select_preset_by_name_strict(), set_sync_info_and_save(), and validate_preset().

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

◆ cbegin()

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

References m_num_default_presets, and m_presets.

Referenced by Slic3r::PrinterPresetCollection::find_custom_preset_by_model_and_variant(), and Slic3r::PrinterPresetCollection::find_system_preset_by_model_and_variant().

Here is the caller graph for this function:

◆ cend()

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

References m_presets.

Referenced by Slic3r::PrinterPresetCollection::find_custom_preset_by_model_and_variant(), and Slic3r::PrinterPresetCollection::find_system_preset_by_model_and_variant().

Here is the caller graph for this function:

◆ check_and_fix_syncinfo()

void Slic3r::PresetCollection::check_and_fix_syncinfo ( Preset & preset,
const std::string & user_id )
inherited
3606{
3607 // user id can't be empty
3608 if (user_id.empty())
3609 return;
3610 // correct the sync info if preset.user_id is empty(the profile json file is copied to the user folder with missing .info file) or preset.user_id
3611 // is not equal to the current user id or preset.setting_id is not in expected format(the .info is copied from the older format)
3612 if (preset.user_id.empty() || preset.user_id != user_id || preset.setting_id.find('-') == std::string::npos) {
3613 preset.user_id = user_id;
3614 preset.setting_id = "";
3615
3616 if (preset.base_id.empty()) {
3617 const std::string inherits = Preset::inherits(preset.config);
3618 Preset* parent_preset = find_preset2(inherits, true);
3619 if (parent_preset)
3620 preset.base_id = parent_preset->setting_id;
3621 }
3622 // tell the sync logic to sync it as a new preset
3623 preset.updated_time = 0;
3624 preset.sync_info = "create";
3625 preset.save_info();
3626 return;
3627 }
3628
3629 const auto inherits = Preset::inherits(preset.config);
3630 Preset* parent = find_preset2(inherits, true);
3631 if (!inherits.empty() && parent) {
3632 const std::string expected = parent->setting_id;
3633 if (expected.empty()) {
3634 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": Direct parent of " << preset.name << " does not have a setting_id";
3635 return;
3636 }
3637 // Reconcile a missing or stale base_id against the direct parent's setting_id.
3638 if (preset.base_id != expected) {
3639 preset.base_id = expected;
3640 // Already-synced preset whose base changed -> re-push it.
3641 if (!preset.setting_id.empty() && preset.sync_info.empty())
3642 preset.sync_info = "update";
3643 preset.save_info();
3644 }
3645 }
3646}
Preset * find_preset2(const std::string &name, bool auto_match=true)
Definition Preset.cpp:3790
std::string & inherits()
Definition Preset.hpp:358

References find_preset2(), Slic3r::Preset::inherits(), preset(), and Slic3r::Preset::setting_id.

Here is the call graph for this function:

◆ clone_presets()

bool Slic3r::PresetCollection::clone_presets ( std::vector< Preset const * > const & presets,
std::vector< std::string > & failures,
std::function< void(Preset &, Preset::Type &)> modifier,
bool force_rewritten = false )
inherited
3238{
3239 std::vector<Preset> new_presets;
3240 for (auto curr_preset : presets) {
3241 new_presets.push_back(*curr_preset);
3242 auto &preset = new_presets.back();
3243 preset.vendor = nullptr;
3244 preset.renamed_from.clear();
3245 preset.m_excluded_from.clear();
3246 preset.setting_id.clear();
3247 preset.inherits().clear();
3248 preset.is_default = false;
3249 preset.is_system = false;
3250 preset.is_external = false;
3251 preset.is_visible = true;
3252 preset.is_project_embedded = false;
3253 modifier(preset, m_type);
3254 if (find_preset(preset.name) && !force_rewritten) {
3255 failures.push_back(preset.name);
3256 }
3257 preset.file = this->path_for_preset(preset);
3259 preset.config.option<ConfigOptionString>("print_settings_id", true)->value = preset.name;
3260 else if (m_type == Preset::TYPE_FILAMENT)
3261 preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = preset.name;
3262 else if (m_type == Preset::TYPE_PRINTER)
3263 preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = preset.name;
3264 }
3265 if (!failures.empty() && !force_rewritten)
3266 return false;
3267 lock();
3268 auto old_name = this->get_edited_preset().name;
3269 for (auto preset : new_presets) {
3270 preset.alias.clear();
3272 preset.base_id.clear();
3273 auto it = this->find_preset_internal(preset.name);
3274 assert((it == m_presets.end() || it->name != preset.name) || force_rewritten);
3275 if (it == m_presets.end() || it->name != preset.name) {
3276 Preset &new_preset = *m_presets.insert(it, preset);
3277 new_preset.save(nullptr);
3278 } else if (force_rewritten) {
3279 *it = preset;
3280 (*it).save(nullptr);
3281 }
3282 }
3283 this->select_preset_by_name(old_name, true);
3284 unlock();
3285 return true;
3286}
bool select_preset_by_name(const std::string &name, bool force)
Definition Preset.cpp:4166
void set_custom_preset_alias(Preset &preset)
Definition Preset.cpp:4350
Preset & get_edited_preset()
Definition Preset.hpp:756
Preset * find_preset(const std::string &name, bool first_visible_if_not_found=false, bool real=false, bool only_from_library=false)
Definition Preset.cpp:3772
std::string name
Definition Preset.hpp:288

References find_preset(), find_preset_internal(), get_edited_preset(), lock(), m_presets, m_type, Slic3r::Preset::name, path_for_preset(), preset(), Slic3r::Preset::save(), select_preset_by_name(), set_custom_preset_alias(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, and unlock().

Referenced by clone_presets_for_filament(), and clone_presets_for_printer().

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

◆ clone_presets_for_filament()

bool Slic3r::PresetCollection::clone_presets_for_filament ( Preset const *const & preset,
std::vector< std::string > & failures,
std::string const & filament_name,
std::string const & filament_id,
const DynamicConfig & dynamic_config,
const std::string & compatible_printers,
bool force_rewritten = false )
inherited
3315{
3316 std::vector<Preset const *> const presets = {preset};
3317 return clone_presets(presets, failures, [&filament_name, &filament_id, &dynamic_config, &compatible_printers](Preset &preset, Preset::Type &type) {
3318 preset.name = filament_name + " @" + compatible_printers;
3319 if (type == Preset::TYPE_FILAMENT) {
3320 preset.config.apply_only(dynamic_config, {"filament_vendor", "compatible_printers", "filament_type"},true);
3321
3322 preset.filament_id = filament_id;
3323 auto compatible = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
3324 if (compatible->values.empty()) {
3325 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " " << __LINE__ << preset.name << " apply compatible_printer failed";
3326 compatible->values.push_back(compatible_printers);
3327 }
3328 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << preset.name << " is cloned and filament_id: " << filament_id;
3329 }
3330 },
3331 force_rewritten);
3332}
bool clone_presets(std::vector< Preset const * > const &presets, std::vector< std::string > &failures, std::function< void(Preset &, Preset::Type &)> modifier, bool force_rewritten=false)
Definition Preset.cpp:3237
Type
Definition Preset.hpp:244

References clone_presets(), preset(), type(), and Slic3r::Preset::TYPE_FILAMENT.

Referenced by Slic3r::GUI::CreatePresetForPrinterDialog::create_dialog_buttons().

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

◆ clone_presets_for_printer()

bool Slic3r::PresetCollection::clone_presets_for_printer ( std::vector< Preset const * > const & templates,
std::vector< std::string > & failures,
std::string const & printer,
std::function< std::string(std::string)> create_filament_id,
bool force_rewritten = false )
inherited
3293{
3294 return clone_presets(templates, failures, [printer, create_filament_id](Preset &preset, Preset::Type &type) {
3295 std::string prefix = preset.name.substr(0, preset.name.find(" @"));
3296 std::replace(prefix.begin(), prefix.end(), '/', '-');
3297 preset.name = prefix + " @" + printer;
3298 auto *compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
3299 compatible_printers->values = std::vector<std::string>{printer};
3300 preset.is_visible = true;
3301 if (type == Preset::TYPE_FILAMENT) {
3302 preset.filament_id = create_filament_id(prefix);
3303 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << preset.name << " create filament_id: " << preset.filament_id;
3304 }
3305 }, force_rewritten);
3306}

References clone_presets(), preset(), type(), Slic3r::Preset::TYPE_FILAMENT, and Slic3r::ConfigOptionVector< T >::values.

Referenced by Slic3r::GUI::CreatePrinterPresetDialog::create_page2_dialog_buttons().

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

◆ commit_user_preset()

void Slic3r::PresetCollection::commit_user_preset ( UserPresetLoad && loaded,
std::deque< Preset > & presets_loaded,
PresetsConfigSubstitutions & substitutions,
const std::function< void(Preset &)> & preset_loaded_fn,
bool read_only )
privateinherited
1951{
1952 Preset &preset = loaded.preset;
1953 if (! loaded.info_file.empty())
1954 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " load info from: " << loaded.info_file << " and base_id: " << preset.base_id;
1955 append(substitutions, std::move(loaded.substitutions));
1956 for (const std::string &error : loaded.errors) {
1957 ++m_errors;
1958 BOOST_LOG_TRIVIAL(error) << error;
1959 }
1960 if (loaded.discard_file)
1961 remove_preset_files(loaded.preset.file, read_only);
1962 if (!loaded.install)
1963 return;
1964
1965 if (loaded.complete) {
1966 if (loaded.save_compatible_printers) {
1967 // A filesystem error from the rewrite is counted, and the preset still loads.
1968 try {
1969 if (read_only)
1970 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " added compatible_printers for preset: " << preset.name << " (not written back)";
1971 else if (preset.save(nullptr))
1972 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " added compatible_printers for preset: " << preset.name;
1973 else
1974 ++m_errors; // save() logged why
1975 } catch (const std::runtime_error &err) {
1976 ++m_errors;
1977 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " can not write compatible_printers back to " << preset.file << ": " << err.what();
1978 }
1979 }
1980 //BBS: add some workaround for previous incorrect settings
1981 if ((!preset.setting_id.empty())&&(preset.setting_id == preset.base_id))
1982 preset.setting_id.clear();
1983 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " load preset: " << preset.name << " and filament_id: " << preset.filament_id << " and base_id: " << preset.base_id;
1984 //BBS: add config related logs
1985 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", preset type %1%, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_visible;
1986 // add alias for custom filament preset
1988 }
1989
1990 if (preset_loaded_fn != nullptr)
1991 preset_loaded_fn(preset);
1992
1993 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << __LINE__ << " load config successful and preset name is:" << preset.name;
1994 presets_loaded.emplace_back(std::move(preset));
1995}
int m_errors
Definition Preset.hpp:1111
static std::string get_type_string(Preset::Type type)
Definition Preset.cpp:590
static void remove_preset_files(const std::string &preset_file, bool read_only)
Definition Preset.cpp:154
void append(std::vector< T, Alloc > &dest, const std::vector< T, Alloc2 > &src)
Definition libslic3r.h:157

References Slic3r::append(), Slic3r::Preset::get_type_string(), m_errors, m_type, preset(), Slic3r::remove_preset_files(), and set_custom_preset_alias().

Here is the call 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
893 { 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:4092
const Preset * get_selected_preset_parent() const
Definition Preset.cpp:3648

References dirty_options(), get_edited_preset(), and 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
890 { return dirty_options(&this->get_edited_preset(), &this->get_selected_preset(), deep_compare); }
Preset & get_selected_preset()
Definition Preset.hpp:731

References dirty_options(), get_edited_preset(), and get_selected_preset().

Referenced by Slic3r::collect_dirty_settings_keys(), and Slic3r::PresetBundle::reload_local_bundle().

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

◆ current_is_dirty()

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

References get_edited_preset(), get_selected_preset(), and is_dirty().

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

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

◆ default_preset() [1/2]

Preset & Slic3r::PresetCollection::default_preset ( size_t idx = 0)
inlineinherited
786{ assert(idx < m_num_default_presets); return m_presets[idx]; }

References m_num_default_presets, and m_presets.

Referenced by default_preset_for(), Slic3r::PrinterPresetCollection::default_preset_for(), get_selected_preset_parent(), load_preset(), load_project_embedded_presets(), load_user_preset(), resolve_user_preset(), and Slic3r::CLI::run().

Here is the caller graph for this function:

◆ default_preset() [2/2]

const Preset & Slic3r::PresetCollection::default_preset ( size_t idx = 0) const
inlineinherited
787{ assert(idx < m_num_default_presets); return m_presets[idx]; }

References m_num_default_presets, and m_presets.

◆ default_preset_for()

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

Reimplemented from Slic3r::PresetCollection.

4500{
4501 const ConfigOptionEnumGeneric *opt_printer_technology = config.opt<ConfigOptionEnumGeneric>("printer_technology");
4502 return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1);
4503}
Preset & default_preset(size_t idx=0)
Definition Preset.hpp:786
@ ptFFF
Definition Config.hpp:231

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

Referenced by Slic3r::CLI::run().

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

◆ delete_current_preset()

bool Slic3r::PresetCollection::delete_current_preset ( )
inherited
3545{
3546 Preset &selected = this->get_selected_preset();
3547 if (!selected.can_overwrite())
3548 return false;
3549
3550 if (get_preset_base(selected) == &selected) {
3551 for (auto &preset2 : m_presets)
3552 if (preset2.inherits() == selected.name)
3553 return false;
3554 }
3555
3556 //BBS: add project embedded preset logic and refine is_external
3557 //if (! selected.is_external && ! selected.is_system) {
3558 if (! selected.is_system) {
3559 //BBS Erase the preset file.
3560 selected.remove_files();
3561 }
3562 //BBS: add lock logic for sync preset in background
3563 lock();
3564 // Remove the preset from the list.
3565 m_presets.erase(m_presets.begin() + m_idx_selected);
3566 unlock();
3567
3568 // Find the next visible preset.
3569 size_t new_selected_idx = m_idx_selected;
3570 if (new_selected_idx < m_presets.size())
3571 for (; new_selected_idx < m_presets.size() && ! m_presets[new_selected_idx].is_visible; ++ new_selected_idx) ;
3572 if (new_selected_idx == m_presets.size())
3573 for (--new_selected_idx; new_selected_idx > 0 && !m_presets[new_selected_idx].is_visible; --new_selected_idx);
3574 this->select_preset(new_selected_idx);
3575 return true;
3576}
Preset & select_preset(size_t idx)
Definition Preset.cpp:4141
const Preset * get_preset_base(const Preset &child) const
Definition Preset.cpp:3693

References Slic3r::Preset::can_overwrite(), get_preset_base(), get_selected_preset(), Slic3r::Preset::is_system, lock(), m_idx_selected, m_presets, Slic3r::Preset::name, Slic3r::Preset::remove_files(), select_preset(), and unlock().

Here is the call graph for this function:

◆ delete_preset()

bool Slic3r::PresetCollection::delete_preset ( const std::string & name,
bool force = false )
inherited
3579{
3580 Preset *preset_ptr = this->find_preset(name, false, true);
3581 if (preset_ptr == nullptr)
3582 return false;
3583
3584 auto it = this->find_preset_internal(preset_ptr->name);
3585 if (it == m_presets.end() || it->name != preset_ptr->name)
3586 return false;
3587
3588 Preset& preset = *it;
3589 // ORCA: if the preset can't be overridden then don't allow deletion
3590 // force=true bypasses this for bundle preset cleanup from cloud sync
3591 if (!force && !preset.can_overwrite())
3592 return false;
3593
3594 preset.remove_files();
3595
3596 //BBS: add lock logic for sync preset in background
3597 lock();
3598 set_printer_hold_alias(it->alias, *it, true);
3599 m_presets.erase(it);
3600 unlock();
3601
3602 return true;
3603}
void set_printer_hold_alias(const std::string &alias, Preset &preset, bool remove=false)
Definition Preset.cpp:4398

References find_preset(), find_preset_internal(), lock(), m_presets, Slic3r::Preset::name, name(), preset(), set_printer_hold_alias(), and unlock().

Referenced by Slic3r::GUI::delete_filament_preset_by_name(), save_user_presets(), Slic3r::GUI::Tab::select_preset(), and Slic3r::PresetBundle::update_subscribed_presets().

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

◆ diameters_of_selected_printer()

std::vector< std::string > Slic3r::PresetCollection::diameters_of_selected_printer ( )
inherited
3881{
3882 std::set<std::string> diameters;
3883 auto printer_model = m_edited_preset.config.opt_string("printer_model");
3884 for (auto &preset : m_presets) {
3885 if (preset.config.opt_string("printer_model") == printer_model)
3886 diameters.insert(preset.config.opt_string("printer_variant"));
3887 }
3888 return std::vector<std::string>{diameters.begin(), diameters.end()};
3889}

References m_edited_preset, m_presets, and preset().

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
4093{
4094 std::vector<std::string> changed;
4095 if (edited != nullptr && reference != nullptr) {
4096 // Only compares options existing in both configs.
4097 changed = deep_compare ?
4098 deep_diff(edited->config, reference->config) :
4099 reference->config.diff(edited->config);
4100 // The "compatible_printers" option key is handled differently from the others:
4101 // It is not mandatory. If the key is missing, it means it is compatible with any printer.
4102 // If the key exists and it is empty, it means it is compatible with no printer.
4103 for (auto &opt_key : optional_keys)
4104 if (reference->config.has(opt_key) != edited->config.has(opt_key))
4105 changed.emplace_back(opt_key);
4106 }
4107 return changed;
4108}
static constexpr const std::initializer_list< const char * > optional_keys
Definition Preset.cpp:4072
t_config_option_keys deep_diff(const ConfigBase &config_this, const ConfigBase &config_other, bool strict=true)
Definition Preset.cpp:4003
Slic3r::Polygons diff(const Slic3r::Polygon &subject, const Slic3r::Polygon &clip, ApplySafetyOffset do_safety_offset)
Definition ClipperUtils.cpp:731

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

Referenced by current_different_from_parent_options(), current_dirty_options(), get_differed_values_to_update(), get_preset_differed_for_save(), Slic3r::PresetBundle::reload_local_bundle(), and Slic3r::GUI::DiffPresetDialog::update_tree().

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

◆ dirty_options_without_option_list()

std::vector< std::string > Slic3r::PresetCollection::dirty_options_without_option_list ( const Preset * edited,
const Preset * reference,
const std::set< std::string > & option_ignore_list,
const bool deep_compare = false )
staticinherited
4112{
4113 std::vector<std::string> changed;
4114 if (edited != nullptr && reference != nullptr) {
4115 // Only compares options existing in both configs.
4116 changed = deep_compare ?
4117 deep_diff(edited->config, reference->config) :
4118 reference->config.diff(edited->config);
4119 // The "compatible_printers" option key is handled differently from the others:
4120 // It is not mandatory. If the key is missing, it means it is compatible with any printer.
4121 // If the key exists and it is empty, it means it is compatible with no printer.
4122 for (auto &opt_key : optional_keys) {
4123 if (reference->config.has(opt_key) != edited->config.has(opt_key))
4124 changed.emplace_back(opt_key);
4125 }
4126 auto iter = changed.begin();
4127 while (iter != changed.end()) {
4128 if (option_ignore_list.find(*iter) != option_ignore_list.end()) {
4129 iter = changed.erase(iter);
4130 }
4131 else {
4132 ++iter;
4133 }
4134 }
4135 }
4136 return changed;
4137}

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

Here is the call graph for this function:

◆ discard_current_changes()

void Slic3r::PresetCollection::discard_current_changes ( )
inlineinherited
795 {
796 m_presets[m_idx_selected].reset_dirty();
798// update_saved_preset_from_current_preset();
799 }

References m_edited_preset, m_idx_selected, and m_presets.

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

Here is the caller graph for this function:

◆ end() [1/2]

◆ end() [2/2]

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

References m_presets.

◆ erase()

Iterator Slic3r::PresetCollection::erase ( Iterator it)
inlineinherited
591{ return m_presets.erase(it); }

References m_presets.

◆ error_count()

int Slic3r::PresetCollection::error_count ( ) const
inlineinherited
868{ return m_errors; }

References m_errors.

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

Here is the caller graph for this function:

◆ filament_id_by_type()

std::string Slic3r::PresetCollection::filament_id_by_type ( const std::string & filament_type) const
inherited
3876{
3878}
size_t first_visible_idx_by_type(const std::string &filament_type) const
Definition Preset.cpp:3840
std::string filament_id
Definition Preset.hpp:326
zaa_minimize_perimeter_height filament_type((ConfigOptionBools, filament_soluble))((ConfigOptionStrings

References Slic3r::Preset::filament_id, Slic3r::filament_type(), first_visible_idx_by_type(), and preset().

Referenced by Slic3r::CrealityPrintAgent::match_filament_preset().

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

◆ filament_preset_less()

bool Slic3r::PresetCollection::filament_preset_less ( const Preset & a,
const Preset & b )
inlinestaticprivateinherited
1014 {
1015 bool a_generic = boost::starts_with(a.name, GENERIC_PREFIX);
1016 bool b_generic = boost::starts_with(b.name, GENERIC_PREFIX);
1017 if (a_generic != b_generic)
1018 return a_generic; // generics first
1019 return a.name < b.name;
1020 }
static constexpr const char * GENERIC_PREFIX
Definition Preset.hpp:99

References GENERIC_PREFIX, and Slic3r::Preset::name.

Referenced by merge_presets(), and sort_presets().

Here is the caller graph for this function:

◆ find_custom_preset_by_model_and_variant()

const Preset * Slic3r::PrinterPresetCollection::find_custom_preset_by_model_and_variant ( const std::string & model_id,
const std::string & variant ) const
4521{
4522 if (model_id.empty()) { return nullptr; }
4523
4524 const auto it = std::find_if(cbegin(), cend(), [&](const Preset &preset) {
4525 if (preset.config.opt_string("printer_model") != model_id)
4526 return false;
4527 if (variant.empty())
4528 return true;
4529 return preset.config.opt_string("printer_variant") == variant;
4530 });
4531
4532 return it != cend() ? &*it : nullptr;
4533}
ConstIterator cbegin() const
Definition Preset.hpp:585
ConstIterator cend() const
Definition Preset.hpp:588

References Slic3r::PresetCollection::cbegin(), Slic3r::PresetCollection::cend(), and Slic3r::PresetCollection::preset().

Referenced by Slic3r::GUI::CreatePrinterPresetDialog::load_system_and_user_presets_with_curr_model().

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

◆ find_preset() [1/2]

const Preset * Slic3r::PresetCollection::find_preset ( const std::string & name,
bool first_visible_if_not_found = false ) const
inlineinherited
806 {
807 return const_cast<PresetCollection*>(this)->find_preset(name, first_visible_if_not_found);
808 }
PresetCollection(Preset::Type type, const std::vector< std::string > &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name="Default Setting")
Definition Preset.cpp:1735

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

Here is the call graph for this function:

◆ find_preset() [2/2]

Preset * Slic3r::PresetCollection::find_preset ( const std::string & name,
bool first_visible_if_not_found = false,
bool real = false,
bool only_from_library = false )
inherited
3773{
3774 const ParsedName parsed = parse_preset_name(name);
3775 const std::string canonical = get_preset_canonical_name(parsed.bare, PresetOrigin(parsed.kind, parsed.bundle_id));
3776 auto it = this->find_preset_internal(canonical, only_from_library);
3777 if (it != m_presets.end() && it->name == canonical)
3778 return &this->preset(it - m_presets.begin(), real);
3779 // Resolve the "renamed_from" field: a system preset may have been renamed (e.g. by a
3780 // vendor profile sync), which records its old name in "renamed_from". Try the rename
3781 // map before the first-visible fallback so every caller - including those passing
3782 // real/only_from_library or first_visible_if_not_found - resolves to the renamed preset
3783 // rather than a mismatched one. Recursion follows multi-step renames (A->B->C) and
3784 // terminates as soon as a name resolves or has no further rename entry.
3785 if (const std::string* renamed = get_preset_name_renamed(name))
3786 return find_preset(*renamed, first_visible_if_not_found, real, only_from_library);
3787 return first_visible_if_not_found ? &this->first_visible() : nullptr;
3788}
Preset & first_visible()
Definition Preset.hpp:857
const std::string * get_preset_name_renamed(const std::string &old_name) const
Definition Preset.cpp:3736

References find_preset(), find_preset_internal(), first_visible(), Slic3r::get_preset_canonical_name(), get_preset_name_renamed(), m_presets, name(), and preset().

Referenced by Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_filament_target(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_preset_target(), Slic3r::GUI::UnsavedChangesDialog::build(), Slic3r::capabilities_in_use(), Slic3r::GUI::ConfigWizard::priv::check_and_install_missing_materials(), clone_presets(), Slic3r::GUI::collect_imex_warnings(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), Slic3r::GUI::CreatePrinterPresetDialog::create_page2_dialog_buttons(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::current_filament_presets(), Slic3r::GUI::delete_filament_preset_by_name(), delete_preset(), find_preset(), find_preset(), find_preset2(), Slic3r::GUI::Plater::force_filament_colors_update(), generate_custom_presets(), Slic3r::GUI::get_cached_selected_filament(), Slic3r::GUI::get_cached_selected_filament_for_multi_extruder(), get_differed_values_to_update(), Slic3r::GUI::CreateFilamentPresetDialog::get_filament_presets_by_machine(), Slic3r::GUI::AMSMaterialsSetting::get_filament_variant_index(), get_preset_differed_for_save(), get_preset_parent(), get_selected_preset_parent(), Slic3r::GUI::PublishSettingsDialog::GetPublishedMaterialKeys(), Slic3r::PresetBundle::import_json_presets(), load_presets(), load_project_embedded_presets(), Slic3r::GUI::ConfigWizard::priv::load_vendors(), Slic3r::GUI::anonymous_namespace{PublishSettingsDialog.cpp}::material_title(), Slic3r::GUI::GLCanvas3D::CenterOfMass::model_markers(), need_sync(), Slic3r::normalize_compatible_field(), Slic3r::GUI::FlowRateWizard::on_cali_start(), Slic3r::GUI::ExportPresetBundleDialog::OnRequestPresets(), Slic3r::refresh_missing_plugins(), Slic3r::PresetBundle::reload_local_bundle(), Slic3r::GUI::GUI_App::reload_settings(), Slic3r::PresetBundle::resolve_system_preset(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::resolved_slot_preset(), Slic3r::GUI::CalibrationWizard::save_preset(), Slic3r::GUI::CalibrationWizard::save_preset_with_index(), save_user_presets(), Slic3r::GUI::ExportConfigsDialog::select_curr_radiobox(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_all_printers(), Slic3r::GUI::DiffPresetDialog::update_compatibility(), Slic3r::GUI::Sidebar::update_presets(), Slic3r::PresetBundle::update_subscribed_presets(), Slic3r::PresetBundle::update_system_preset_setting_ids(), and Slic3r::GUI::DiffPresetDialog::update_tree().

Here is the call graph for this function:

◆ find_preset2() [1/2]

Preset * Slic3r::PresetCollection::find_preset2 ( const std::string & name,
bool auto_match = true )
inherited
3791{
3792 auto preset = find_preset(name, false, true);
3793 if (preset == nullptr) {
3794 if (auto_match) {
3795 //Orca: one more try, find the most likely preset in OrcaFilamentLibrary
3796 if (name.find("Generic") != std::string::npos) {
3797 // The regex pattern matches an optional prefix ending in '_' then "Generic" followed by the material name.
3798 static const std::regex re(R"(^(?:.*?\b(?:\w+_)?)(Generic)\b\s+([^@]+?)\s*(?:@.*)?$)");
3799 auto alter_name = std::regex_replace(name, re, "Generic $2 @System");
3800 preset = find_preset2(alter_name, false);
3801 // print preset file name
3802 if (preset != nullptr) {
3803 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << " " << "Failed to find: " << name
3804 << ". fallback to library preset: " << preset->file;
3805 }
3806 }
3807 }
3808 }
3809 return preset;
3810}

References find_preset(), find_preset2(), name(), and preset().

Referenced by check_and_fix_syncinfo(), find_preset2(), find_preset2(), get_preset_base(), Slic3r::PresetBundle::import_json_presets(), load_external_preset(), load_project_embedded_presets(), load_user_preset(), resolve_user_preset(), Slic3r::CLI::run(), save_current_preset(), and Slic3r::PresetBundle::save_preset_to_bundle_dir().

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

◆ find_preset2() [2/2]

const Preset * Slic3r::PresetCollection::find_preset2 ( const std::string & name,
bool auto_match = true ) const
inlineinherited
813 {
814 return const_cast<PresetCollection*>(this)->find_preset2(name, auto_match);
815 }

References PresetCollection(), find_preset2(), and name().

Here is the call graph for this function:

◆ find_preset_internal() [1/2]

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

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

Here is the call graph for this function:

◆ find_preset_internal() [2/2]

std::deque< Preset >::iterator Slic3r::PresetCollection::find_preset_internal ( const std::string & name,
bool from_orca_lib_only = false )
inlineprivateinherited
1040 {
1042 [&name, this](const auto& l) {
1043 if (m_type == Preset::TYPE_FILAMENT) {
1044 bool l_generic = boost::starts_with(l.name, GENERIC_PREFIX);
1045 bool name_generic = boost::starts_with(name, GENERIC_PREFIX);
1046 if (l_generic && !name_generic) return true;
1047 if (!l_generic && name_generic) return false;
1048 }
1049 return l.name < name;
1050 });
1051 if (it == m_presets.end() || it->name != name) {
1052 // Preset has not been not found in the sorted list of non-default presets. Try the defaults.
1053 for (size_t i = 0; i < m_num_default_presets; ++ i)
1054 if (m_presets[i].name == name && (!from_orca_lib_only || m_presets[i].m_from_orca_filament_lib)) {
1055 it = m_presets.begin() + i;
1056 break;
1057 }
1058 }
1059 return it;
1060 }
ForwardIt lower_bound_by_predicate(ForwardIt first, ForwardIt last, LowerThanKeyPredicate lower_than_key)
Definition libslic3r.h:246

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

Referenced by add_detached_preset(), apply_legacy_user_filament_presets(), clone_presets(), delete_preset(), find_preset(), find_preset_internal(), find_preset_renamed(), get_preset_name_by_alias(), load_external_preset(), load_preset(), load_user_preset(), save_current_preset(), select_preset_by_name(), select_preset_by_name_strict(), and validate_preset().

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

◆ find_preset_renamed() [1/2]

std::deque< Preset >::iterator Slic3r::PresetCollection::find_preset_renamed ( const std::string & name)
inlineprivateinherited
1063 {
1064 auto it_renamed = m_map_system_profile_renamed.find(name);
1065 auto it = (it_renamed == m_map_system_profile_renamed.end()) ? m_presets.end() : this->find_preset_internal(it_renamed->second);
1066 assert((it_renamed == m_map_system_profile_renamed.end()) || (it != m_presets.end() && it->name == it_renamed->second));
1067 return it;
1068 }
std::map< std::string, std::string > m_map_system_profile_renamed
Definition Preset.hpp:1089

References find_preset_internal(), m_map_system_profile_renamed, m_presets, and name().

Referenced by find_preset_renamed(), load_external_preset(), and validate_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
1070 { return const_cast<PresetCollection*>(this)->find_preset_renamed(name); }
std::deque< Preset >::iterator find_preset_renamed(const std::string &name)
Definition Preset.hpp:1063

References PresetCollection(), find_preset_renamed(), and 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
4506{
4507 if (model_id.empty()) { return nullptr; }
4508
4509 const auto it = std::find_if(cbegin(), cend(), [&](const Preset &preset) {
4510 if (!preset.is_system || preset.config.opt_string("printer_model") != model_id)
4511 return false;
4512 if (variant.empty())
4513 return true;
4514 return preset.config.opt_string("printer_variant") == variant;
4515 });
4516
4517 return it != cend() ? &*it : nullptr;
4518}

References Slic3r::PresetCollection::cbegin(), Slic3r::PresetCollection::cend(), and Slic3r::PresetCollection::preset().

Referenced by Slic3r::GUI::CreatePrinterPresetDialog::load_system_and_user_presets_with_curr_model().

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
859{ return this->preset(this->first_compatible_idx()); }
size_t first_compatible_idx() const
Definition Preset.hpp:851

References first_compatible_idx(), and preset().

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

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

◆ first_compatible() [2/3]

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

References first_compatible_idx(), and 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
861{ return this->preset(this->first_compatible_idx(prefered_condition)); }

References first_compatible_idx(), and preset().

Here is the call graph for this function:

◆ first_compatible_idx() [1/2]

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

References first_compatible_idx().

Referenced by first_compatible(), first_compatible(), first_compatible(), first_compatible_idx(), and 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
826 {
828 size_t n = this->m_presets.size();
829 size_t i_compatible = n;
830 int match_quality = -1;
831 for (; i < n; ++i)
832 // Since we use the filament selection from Wizard, it's needed to control the preset visibility too
833 if (m_presets[i].is_compatible && m_presets[i].is_visible) {
834 int this_match_quality = prefered_condition(m_presets[i]);
835 if (this_match_quality > match_quality) {
836 if (match_quality == std::numeric_limits<int>::max())
837 // Better match will not be found.
838 return i;
839 // Store the first compatible profile with highest match quality into i_compatible.
840 i_compatible = i;
841 match_quality = this_match_quality;
842 }
843 }
844 return (i_compatible == n) ?
845 // No compatible preset found, return the default preset.
846 0 :
847 // Compatible preset found.
848 i_compatible;
849}
bool m_default_suppressed
Definition Preset.hpp:1098

References m_default_suppressed, m_num_default_presets, and m_presets.

◆ first_visible() [1/2]

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

References first_visible_idx(), and preset().

Referenced by find_preset(), and first_visible_idx().

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
858{ return this->preset(this->first_visible_idx()); }

References first_visible_idx(), and preset().

Here is the call graph for this function:

◆ first_visible_idx()

size_t Slic3r::PresetCollection::first_visible_idx ( ) const
inherited
3814{
3815 //BBS: set first visible filament to fla
3816 size_t first_visible = -1;
3818 for (; idx < m_presets.size(); ++ idx)
3819 if (m_presets[idx].is_visible && m_presets[idx].get_printer_id() == PresetBundle::ORCA_FILAMENT_LIBRARY) {
3820 if (first_visible == -1)
3821 first_visible = idx;
3823 break;
3824 else {
3825 if (m_presets[idx].name.find("PLA") != std::string::npos) {
3826 first_visible = idx;
3827 break;
3828 }
3829 }
3830 }
3831 if (first_visible == -1) {
3832 if (m_presets.size() > 1 && m_default_suppressed)
3834 else
3835 first_visible = 0;
3836 }
3837 return first_visible;
3838}
static const char * ORCA_FILAMENT_LIBRARY
Definition PresetBundle.hpp:690

References first_visible(), m_default_suppressed, m_num_default_presets, m_presets, m_type, name(), Slic3r::PresetBundle::ORCA_FILAMENT_LIBRARY, and Slic3r::Preset::TYPE_FILAMENT.

Referenced by first_visible(), first_visible(), first_visible_idx_by_type(), get_selected_preset(), Slic3r::PresetBundle::reload_local_bundle(), and select_preset().

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

◆ first_visible_idx_by_type()

size_t Slic3r::PresetCollection::first_visible_idx_by_type ( const std::string & filament_type) const
inherited
3841{
3842 size_t start = m_default_suppressed ? m_num_default_presets : 0;
3843
3844 // Find the first visible, compatible, system base preset whose filament_type matches target.
3845 auto find_by_type = [&](const std::string& target) -> size_t {
3846 for (size_t i = start; i < m_presets.size(); ++i) {
3847 const auto& p = m_presets[i];
3848 if (p.is_visible && p.is_compatible && p.is_system
3849 && get_preset_base(p) == &p
3850 && p.config.opt_string("filament_type", 0u) == target)
3851 return i;
3852 }
3853 return size_t(-1);
3854 };
3855
3856 // 1. Exact filament_type match
3857 size_t idx = find_by_type(filament_type);
3858 if (idx != size_t(-1))
3859 return idx;
3860
3861 // 2. Base type fallback: strip modifier after first space
3862 // e.g. "PLA High Speed" -> "PLA"
3863 // Dash-separated types like "PA-CF", "PET-CF" are distinct materials, not modifiers.
3864 auto sep = filament_type.find(' ');
3865 if (sep != std::string::npos) {
3866 idx = find_by_type(filament_type.substr(0, sep));
3867 if (idx != size_t(-1))
3868 return idx;
3869 }
3870
3871 // 3. Any visible preset
3872 return first_visible_idx();
3873}

References Slic3r::filament_type(), first_visible_idx(), get_preset_base(), m_default_suppressed, m_num_default_presets, and m_presets.

Referenced by filament_id_by_type().

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

◆ get_differed_values_to_update()

int Slic3r::PresetCollection::get_differed_values_to_update ( Preset & preset,
std::map< std::string, std::string > & key_values )
inherited
2165{
2166 if (preset.is_system || preset.is_default || preset.is_project_embedded) {
2167 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" Error: not a user preset! Should not happen, name %1%") %preset.name;
2168 ++m_errors;
2169 return -1;
2170 }
2171
2172 //BBS: only save difference for user preset
2173 std::string& inherit_preset = preset.inherits();
2174 Preset* parent_preset = nullptr;
2175 if (!inherit_preset.empty()) {
2176 parent_preset = this->find_preset(inherit_preset, false, true);
2177 }
2178 if (parent_preset) {
2179 DynamicPrintConfig temp_config;
2180 std::vector<std::string> dirty_options = preset.config.diff(parent_preset->config);
2181
2182 // Send the variant layout even when it matches the parent's, as the local save does: the loader
2183 // sizes the per-variant values by it and would otherwise keep only the first one.
2184 std::string extruder_id_name, extruder_variant_name;
2185 std::set<std::string> *key_set1 = nullptr, *key_set2 = nullptr;
2186 Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2);
2187 if (!extruder_id_name.empty())
2188 dirty_options.emplace_back(extruder_id_name);
2189 if (!extruder_variant_name.empty())
2190 dirty_options.emplace_back(extruder_variant_name);
2191
2192 for (auto option: dirty_options)
2193 {
2194 ConfigOption *opt_src = preset.config.option(option);
2195 if (opt_src)
2196 key_values[option] = opt_src->serialize();
2197 }
2198
2199 // Orca: force-emit nullable filament override keys whenever they hold a nil ("off")
2200 // value, even when the diff dropped them because the parent is nil too. Otherwise the
2201 // key is absent from the synced profile and the cloud re-materializes it against the
2202 // option's non-nil default (e.g. filament_retract_before_wipe -> 100%), silently
2203 // resurrecting an override the user turned off. See GitHub issue on Retract Before Wipe.
2205 for (const std::string& opt_key : preset.config.keys()) {
2206 if (!is_filament_extruder_override_key(opt_key) || key_values.count(opt_key))
2207 continue; // not an override, or already carried by the diff
2208 const ConfigOptionDef *def = print_config_def.get(opt_key);
2209 if (def == nullptr || !def->default_value || def->default_value->is_nil())
2210 continue; // the option's default is nil too, so an absent key cannot come back as a value
2211 const auto* opt_vec = dynamic_cast<const ConfigOptionVectorBase*>(preset.config.option(opt_key));
2212 if (opt_vec == nullptr)
2213 continue;
2214 bool has_nil = false;
2215 for (size_t i = 0; i < opt_vec->size(); ++i)
2216 if (opt_vec->is_nil(i)) { has_nil = true; break; }
2217 if (has_nil)
2218 key_values[opt_key] = opt_vec->serialize();
2219 }
2220 }
2221 }
2222 else {
2223 for (auto iter = preset.config.cbegin(); iter != preset.config.cend(); ++iter)
2224 {
2225 key_values[iter->first] = iter->second->serialize();
2226 }
2227 }
2228
2229 //add other values
2230 key_values[BBL_JSON_KEY_VERSION] = preset.version.to_string();
2231 if (!preset.base_id.empty()) {
2232 key_values[BBL_JSON_KEY_BASE_ID] = preset.base_id;
2233 } else {
2234 key_values.erase(BBL_JSON_KEY_BASE_ID);
2235 if (get_preset_base(preset) == &preset && !preset.filament_id.empty()) {
2236 key_values[BBL_JSON_KEY_FILAMENT_ID] = preset.filament_id;
2237 }
2238 }
2239 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " uploading user preset name is: " << preset.name << "and create filament_id is: " << preset.filament_id
2240 << " and base_id is: " << preset.base_id;
2241 key_values[ORCA_JSON_KEY_UPDATE_TIME] = std::to_string(preset.updated_time);
2243 return 0;
2244}
#define BBL_JSON_KEY_BASE_ID
Definition Preset.hpp:69
#define BBL_JSON_KEY_VERSION
Definition Preset.hpp:55
#define ORCA_JSON_KEY_UPDATE_TIME
Definition Preset.hpp:73
#define BBL_JSON_KEY_TYPE
Definition Preset.hpp:66
#define BBL_JSON_KEY_FILAMENT_ID
Definition Preset.hpp:71
const ConfigOptionDef * get(const t_config_option_key &opt_key) const
Definition Config.hpp:2662
static std::string get_iot_type_string(Preset::Type type)
Definition Preset.cpp:641
static void get_extruder_names_and_keysets(Type type, std::string &extruder_id_name, std::string &extruder_variant_name, std::set< std::string > **p_key_set1, std::set< std::string > **p_key_set2)
Definition Preset.cpp:1034
bool is_filament_extruder_override_key(const std::string &opt_key)
Definition PrintConfig.cpp:130
const PrintConfigDef print_config_def
Definition PrintConfig.cpp:10099

References BBL_JSON_KEY_BASE_ID, BBL_JSON_KEY_FILAMENT_ID, BBL_JSON_KEY_TYPE, BBL_JSON_KEY_VERSION, Slic3r::Preset::config, Slic3r::ConfigOptionDef::default_value, dirty_options(), find_preset(), Slic3r::Preset::get_extruder_names_and_keysets(), Slic3r::Preset::get_iot_type_string(), get_preset_base(), Slic3r::is_filament_extruder_override_key(), m_errors, m_type, ORCA_JSON_KEY_UPDATE_TIME, preset(), Slic3r::print_config_def, Slic3r::ConfigOption::serialize(), and Slic3r::Preset::TYPE_FILAMENT.

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

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

◆ get_edited_preset() [1/2]

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

References m_edited_preset.

Referenced by Slic3r::GUI::_collect_sorted_machines(), Slic3r::active_capability_config(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_filament_target(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_preset_target(), Slic3r::GUI::UnsavedChangesDialog::build(), Slic3r::GUI::SelectMachineDialog::build_nozzles_info(), Slic3r::GUI::SyncAmsInfoDialog::build_nozzles_info(), Slic3r::GUI::PartPlate::calc_imex_zones(), Slic3r::capabilities_in_use(), Slic3r::GUI::Plater::priv::check_ams_status_impl(), clone_presets(), Slic3r::GUI::collect_imex_warnings(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::PresetTransaction::commit(), Slic3r::GUI::DiffPresetDialog::create_buttons(), current_different_from_parent_options(), current_dirty_options(), current_is_dirty(), Slic3r::GUI::PluginsConfigDialog::current_preset(), Slic3r::GUI::delete_filament_preset_by_name(), Slic3r::effective_physical_extruder_map(), Slic3r::GUI::Plater::export_3mf(), Slic3r::GUI::Plater::export_gcode(), Slic3r::GUI::extruder_supports_tpu_high_flow(), get_edited_preset_with_vendor_profile(), Slic3r::GUI::Plater::priv::get_machine_sync_status(), Slic3r::Preset::get_printer_type(), get_selected_preset_parent(), Slic3r::GUI::getExtruderNozzleCount(), Slic3r::GUI::getExtruderNozzleCountTotal(), Slic3r::Preset::has_lidar(), Slic3r::GUI::PartPlate::imex_wipe_tower_hull(), Slic3r::GUI::SyncAmsInfoDialog::is_dirty_filament(), Slic3r::GUI::Plater::is_same_printer_for_connected_and_selected(), Slic3r::GUI::SelectMachineDialog::is_same_printer_model(), Slic3r::GUI::SyncAmsInfoDialog::is_same_printer_model(), Slic3r::GUI::Sidebar::priv::layout_printer(), load_external_preset(), Slic3r::GUI::MainFrame::load_printer_url(), Slic3r::PhysicalPrinterCollection::load_printers_from_presets(), Slic3r::GUI::manuallySetNozzleCount(), Slic3r::GUI::Tab::may_discard_current_dirty_preset(), Slic3r::GUI::Plater::priv::on_select_preset(), Slic3r::GUI::anonymous_namespace{PublishSettingsDialog.cpp}::project_used_filament_slots(), Slic3r::GUI::PartPlate::refresh_imex_icon(), Slic3r::refresh_missing_plugins(), Slic3r::GUI::PartPlate::register_raycasters_for_picking(), Slic3r::PresetBundle::reload_local_bundle(), Slic3r::GUI::GUI_App::reload_settings(), Slic3r::GUI::PartPlate::render_icons(), Slic3r::GUI::GCodeViewer::render_markers(), Slic3r::PresetBundle::restore_selection(), Slic3r::GUI::s_get_slicing_extuder_nozzles(), Slic3r::GUI::UnsavedChangesDialog::save(), Slic3r::PresetBundle::save_changes_for_preset(), Slic3r::GUI::CalibrationWizard::save_preset(), Slic3r::GUI::CalibrationWizard::save_preset_with_index(), saved_is_dirty(), Slic3r::GUI::seedExtruderNozzleStats(), Slic3r::GUI::Tab::select_preset(), Slic3r::PresetBundle::selection(), Slic3r::GUI::PartPlate::set_shape(), Slic3r::GUI::setExtruderNozzleCount(), Slic3r::GUI::Sidebar::should_show_SEMM_buttons(), Slic3r::GUI::SelectMachineDialog::show_status(), Slic3r::GUI::SyncAmsInfoDialog::show_status(), Slic3r::GUI::TabPrinter::toggle_options(), Slic3r::GUI::ConfigManipulation::toggle_print_fff_options(), Slic3r::GUI::UnsavedChangesDialog::update(), Slic3r::GUI::Sidebar::update_all_preset_comboboxes(), update_dirty(), Slic3r::GUI::Sidebar::update_presets(), Slic3r::GUI::SelectMachineDialog::update_show_status(), Slic3r::GUI::Sidebar::priv::update_sync_status(), and Slic3r::GUI::updateNozzleCountDisplay().

◆ get_edited_preset() [2/2]

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

References m_edited_preset.

◆ get_edited_preset_with_vendor_profile()

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

References get_edited_preset(), and get_preset_with_vendor_profile().

Referenced by Slic3r::GUI::Tab::select_preset(), and anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_all_printers().

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

◆ get_filament_presets()

std::map< std::string, std::vector< Preset const * > > Slic3r::PresetCollection::get_filament_presets ( ) const
inherited
3335{
3336 std::map<std::string, std::vector<Preset const *>> filament_presets;
3337 for (auto &preset : m_presets) {
3338 if (preset.is_user()) {
3339 if (preset.inherits() == "") { filament_presets[preset.filament_id].push_back(&preset); }
3340 continue;
3341 }
3342 if (get_preset_base(preset) == &preset) { filament_presets[preset.filament_id].push_back(&preset); }
3343 }
3344 return filament_presets;
3345}

References get_preset_base(), m_presets, and preset().

Referenced by Slic3r::GUI::get_filament_id(), and Slic3r::GUI::update_custom_filaments().

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
782{ return m_idx_selected; }

References m_idx_selected.

Referenced by Slic3r::GUI::delete_filament_preset_by_name().

Here is the caller graph for this function:

◆ get_preset_alias()

std::string Slic3r::PresetCollection::get_preset_alias ( Preset & preset,
bool force = false )
inherited
4379{
4380 if (!preset.alias.empty())
4381 return preset.alias;
4382 else
4384
4385 if (!preset.alias.empty() || !force)
4386 return preset.alias;
4387
4388 std::string alias_name;
4389 std::string preset_name = preset.name;
4390 size_t end_pos = preset_name.find_first_of("@");
4391 if (end_pos != std::string::npos) {
4392 alias_name = preset_name.substr(0, end_pos);
4393 boost::trim_right(alias_name);
4394 }
4395 return alias_name;
4396}

References preset(), and set_custom_preset_alias().

Referenced by Slic3r::GUI::NewCalibrationHistoryDialog::get_all_filaments(), and Slic3r::GUI::AMSMaterialsSetting::Popup().

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

◆ get_preset_base()

const Preset * Slic3r::PresetCollection::get_preset_base ( const Preset & child) const
inherited
3694{
3695 if (child.is_system || child.is_default)
3696 return &child;
3697 // Handle user preset
3698 if (child.inherits().empty())
3699 return &child; // this is user root
3700 auto inherits = find_preset2(child.inherits(), true);
3701 return inherits ? get_preset_base(*inherits) : nullptr;
3702}

References find_preset2(), get_preset_base(), Slic3r::Preset::inherits(), Slic3r::Preset::is_default, and Slic3r::Preset::is_system.

Referenced by Slic3r::GUI::ExportConfigsDialog::data_init(), delete_current_preset(), Slic3r::anonymous_namespace{SnapmakerPrinterAgent.cpp}::find_closest_color_preset_by_vendor_and_type(), first_visible_idx_by_type(), get_differed_values_to_update(), get_filament_presets(), get_preset_base(), get_selected_preset_base(), get_selected_preset_parent(), Slic3r::anonymous_namespace{CrealityPrintAgent.cpp}::has_visible_base_preset(), Slic3r::anonymous_namespace{QidiPrinterAgent.cpp}::has_visible_base_preset(), Slic3r::GUI::ExportPresetBundleDialog::InitExportData(), Slic3r::GUI::ExportPresetBundleDialog::OnRequestPresets(), Slic3r::GUI::ExportConfigsDialog::select_curr_radiobox(), Slic3r::GUI::CreatePrinterPresetDialog::set_current_visible_printer(), set_sync_info_and_save(), and Slic3r::warn_ambiguous_filament_id_match().

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

◆ get_preset_differed_for_save()

Preset * Slic3r::PresetCollection::get_preset_differed_for_save ( Preset & preset)
inherited
2105{
2106 if (preset.is_system || preset.is_default)
2107 return nullptr;
2108
2109 Preset* new_preset = nullptr;
2110 //BBS: only save difference for user preset
2111 std::string& inherits = preset.inherits();
2112 Preset* parent_preset = nullptr;
2113 if (!inherits.empty()) {
2114 parent_preset = this->find_preset(inherits, false, true);
2115 }
2116 if (parent_preset) {
2117 new_preset = new Preset();
2118 *new_preset = preset;
2119
2120 DynamicPrintConfig temp_config;
2121 std::vector<std::string> dirty_options = preset.config.diff(parent_preset->config);
2122
2123 std::string extruder_id_name, extruder_variant_name;
2124 std::set<std::string> *key_set1 = nullptr, *key_set2 = nullptr;
2125 Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2);
2126
2127 if (!extruder_id_name.empty()) {
2128 dirty_options.emplace_back(extruder_id_name);
2129 }
2130 if (!extruder_variant_name.empty()) {
2131 dirty_options.emplace_back(extruder_variant_name);
2132 }
2133
2134 for (auto option: dirty_options)
2135 {
2136 ConfigOption *opt_src = preset.config.option(option);
2137 ConfigOption *opt_dst = temp_config.option(option, true);
2138 if (opt_dst->is_scalar() || !(opt_dst->nullable()) || is_filament_extruder_override_key(option))
2139 opt_dst->set(opt_src);
2140 else {
2141 ConfigOptionVectorBase* opt_vec_src = static_cast<ConfigOptionVectorBase*>(opt_src);
2142 ConfigOptionVectorBase* opt_vec_dst = static_cast<ConfigOptionVectorBase*>(opt_dst);
2143 ConfigOptionVectorBase* opt_vec_inherit = static_cast<ConfigOptionVectorBase*>(parent_preset->config.option(option));
2144 if (opt_vec_src->size() == 1)
2145 opt_dst->set(opt_src);
2146 else if (key_set1->find(option) != key_set1->end()) {
2147 opt_vec_dst->set_with_nil(opt_vec_src, opt_vec_inherit, 1);
2148 }
2149 else if (key_set2->find(option) != key_set2->end()) {
2150 opt_vec_dst->set_with_nil(opt_vec_src, opt_vec_inherit, 2);
2151 }
2152 else
2153 opt_dst->set(opt_src);
2154 }
2155 }
2156
2157 new_preset->config = temp_config;
2158 }
2159
2160 return new_preset;
2161}

References Slic3r::Preset::config, dirty_options(), find_preset(), Slic3r::Preset::get_extruder_names_and_keysets(), Slic3r::is_filament_extruder_override_key(), Slic3r::ConfigOption::is_scalar(), m_type, Slic3r::ConfigOption::nullable(), Slic3r::ConfigBase::option(), Slic3r::Preset, preset(), Slic3r::ConfigOption::set(), Slic3r::ConfigOptionVectorBase::set_with_nil(), and Slic3r::ConfigOptionVectorBase::size().

Referenced by Slic3r::PresetBundle::get_preset_differed_for_save(), and get_project_embedded_presets().

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

◆ get_preset_name_by_alias()

const std::string & Slic3r::PresetCollection::get_preset_name_by_alias ( const std::string & alias) const
inherited
3720{
3721 for (
3722 // Find the 1st profile name with the alias.
3723 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; });
3724 // Continue over all profile names with the same alias.
3725 it != m_map_alias_to_profile_name.end() && it->first == alias; ++ it)
3726 for (const std::string &preset_name : it->second) {
3727 if (auto it_preset = this->find_preset_internal(preset_name);
3728 it_preset != m_presets.end() && it_preset->name == preset_name &&
3729 it_preset->is_visible && (it_preset->is_compatible || size_t(it_preset - m_presets.begin()) == m_idx_selected))
3730 return it_preset->name;
3731 }
3732
3733 return alias;
3734}
std::map< std::string, std::vector< std::string > > m_map_alias_to_profile_name
Definition Preset.hpp:1086

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

Referenced by Slic3r::anonymous_namespace{PluginHostPresets.cpp}::bind_filament_target(), Slic3r::PresetBundle::get_preset_name_by_alias(), Slic3r::GUI::CalibrationWizard::save_preset(), and Slic3r::GUI::CalibrationWizard::save_preset_with_index().

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
3737{
3738 auto it_renamed = m_map_system_profile_renamed.find(old_name);
3739 if (it_renamed != m_map_system_profile_renamed.end())
3740 return &it_renamed->second;
3741 return nullptr;
3742}

References m_map_system_profile_renamed.

Referenced by find_preset().

Here is the caller graph for this function:

◆ get_preset_parent()

const Preset * Slic3r::PresetCollection::get_preset_parent ( const Preset & child) const
inherited
3674{
3675 const std::string &inherits = child.inherits();
3676 if (inherits.empty())
3677// return this->get_selected_preset().is_system ? &this->get_selected_preset() : nullptr;
3678 return nullptr;
3679 // find_preset() already resolves "renamed_from" internally.
3680 const Preset* preset = this->find_preset(inherits, false);
3681 return
3682 // not found
3683 (preset == nullptr/* || preset->is_default */||
3684 // this should not happen, user profile should not derive from an external profile
3685 //BBS: add project embedded preset logic and refine is_external
3686 /*preset->is_external ||*/
3687 // this should not happen, however people are creative, see GH #4996
3688 preset == &child) ?
3689 nullptr :
3690 preset;
3691}

References find_preset(), Slic3r::Preset::inherits(), and preset().

Referenced by get_preset_with_vendor_profile(), legacy_user_filament_presets(), and Slic3r::PresetBundle::reload_local_bundle().

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
3706{
3707 const Preset *p = &preset;
3708 const VendorProfile *v = nullptr;
3709 do {
3710 if (p->vendor != nullptr) {
3711 v = p->vendor;
3712 break;
3713 }
3714 p = this->get_preset_parent(*p);
3715 } while (p != nullptr);
3716 return PresetWithVendorProfile(preset, v);
3717}
const Preset * get_preset_parent(const Preset &child) const
Definition Preset.cpp:3673

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

Referenced by generate_custom_presets(), get_edited_preset_with_vendor_profile(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_all_printers(), Slic3r::GUI::ExtrusionCalibration::update_combobox_filaments(), and 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

◆ get_project_embedded_presets()

std::vector< Preset * > Slic3r::PresetCollection::get_project_embedded_presets ( )
inherited
2336{
2337 std::vector<Preset*> project_presets;
2338
2339 lock();
2340 for (Preset &preset : m_presets) {
2341 //if (preset.type != Preset::get_type_from_string(type)) continue;
2342 if (!preset.is_project_embedded) continue;
2343
2345
2346 if (new_preset)
2347 project_presets.push_back(new_preset);
2348 }
2349 unlock();
2350 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , total preset counts %2%")%Preset::get_type_string(m_type) %project_presets.size();
2351 return project_presets;
2352}
Preset * get_preset_differed_for_save(Preset &preset)
Definition Preset.cpp:2104

References get_preset_differed_for_save(), Slic3r::Preset::get_type_string(), lock(), m_presets, m_type, preset(), and unlock().

Here is the call graph for this function:

◆ get_selected_idx()

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

References m_idx_selected.

Referenced by Slic3r::GUI::DiffPresetDialog::create_presets_sizer(), and get_selected_preset_parent().

Here is the caller graph for this function:

◆ get_selected_preset() [1/2]

Preset & Slic3r::PresetCollection::get_selected_preset ( )
inlineinherited
731 {
732 //BBS fix crash when m_idx_selected == -1, give a default value
733 if ((m_idx_selected < 0) || (m_idx_selected >= m_presets.size())) {
735 }
737 }

References first_visible_idx(), m_idx_selected, m_presets, and select_preset().

Referenced by Slic3r::GUI::EditFilamentPresetDialog::create_dialog_buttons(), Slic3r::GUI::DiffPresetDialog::create_presets_sizer(), current_dirty_options(), current_is_dirty(), delete_current_preset(), Slic3r::GUI::NewCalibrationHistoryDialog::get_all_filaments(), get_selected_preset_name(), get_selected_preset_parent(), Slic3r::GUI::Plater::get_selected_printer_name_in_combox(), Slic3r::GUI::PresetComboBox::get_tooltip(), Slic3r::GUI::GCodeViewer::init(), load_external_preset(), Slic3r::GUI::Tab::may_discard_current_dirty_preset(), Slic3r::GUI::Sidebar::need_auto_sync_extruder_list_after_connect_priner(), Slic3r::GUI::AMSMaterialsSetting::on_select_filament(), Slic3r::GUI::AMSMaterialsSetting::Popup(), Slic3r::GUI::GUI_App::reload_settings(), Slic3r::anonymous_namespace{PluginHostPresets.cpp}::require_tab(), Slic3r::PresetBundle::save_changes_for_preset(), save_current_preset(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::select_printer_default_presets(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_all_printers(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_config(), Slic3r::GUI::Sidebar::priv::sync_extruder_list(), Slic3r::GUI::UnsavedChangesDialog::update(), Slic3r::GUI::DiffPresetDialog::update_compatibility(), and update_dirty().

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

◆ get_selected_preset() [2/2]

const Preset & Slic3r::PresetCollection::get_selected_preset ( ) const
inlineinherited
738{ return m_presets[m_idx_selected]; }

References m_idx_selected, and m_presets.

◆ get_selected_preset_base()

const Preset & Slic3r::PresetCollection::get_selected_preset_base ( ) const
inlineinherited
762 {
763 const Preset &selected = m_presets[m_idx_selected];
764 const Preset *base = get_preset_base(selected);
765 return base ? *base : selected;
766 }

References get_preset_base(), m_idx_selected, and m_presets.

Here is the call graph for this function:

◆ get_selected_preset_name()

std::string Slic3r::PresetCollection::get_selected_preset_name ( ) const
inlineinherited
741 {
742 if (m_idx_selected == size_t(-1) || m_idx_selected >= m_presets.size())
743 return std::string();
744 return this->get_selected_preset().name;
745 }

References get_selected_preset(), m_idx_selected, m_presets, and Slic3r::Preset::name.

Referenced by Slic3r::GUI::GUI_App::get_selected_presets(), Slic3r::GUI::Plater::priv::on_select_bed_type(), Slic3r::PresetBundle::reload_local_bundle(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::select_printer_default_presets(), Slic3r::PresetBundle::selection(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_all_printers(), update_after_user_presets_loaded(), Slic3r::GUI::Sidebar::update_all_preset_comboboxes(), and Slic3r::GUI::Sidebar::update_presets().

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

◆ get_selected_preset_parent()

const Preset * Slic3r::PresetCollection::get_selected_preset_parent ( ) const
inherited
3649{
3650 if (this->get_selected_idx() == size_t(-1))
3651 // This preset collection has no preset activated yet. Only the get_edited_preset() is valid.
3652 return nullptr;
3653
3654 const Preset &selected_preset = this->get_selected_preset();
3655 if (get_preset_base(selected_preset) == &selected_preset)
3656 return &selected_preset;
3657
3658 const Preset &edited_preset = this->get_edited_preset();
3659 const std::string &inherits = edited_preset.inherits();
3660 const Preset *preset = nullptr;
3661 if (inherits.empty()) {
3662 if (selected_preset.is_external)
3663 return nullptr;
3664 preset = &this->default_preset(m_type == Preset::Type::TYPE_PRINTER && edited_preset.printer_technology() == ptSLA ? 1 : 0);
3665 } else
3666 // find_preset() already resolves "renamed_from" internally.
3667 preset = this->find_preset(inherits, false);
3668 //BBS: add project embedded preset logic and refine is_external
3669 return (preset == nullptr/* || preset->is_default || preset->is_external*/) ? nullptr : preset;
3670 //return (preset == nullptr/* || preset->is_default*/ || preset->is_external) ? nullptr : preset;
3671}
size_t get_selected_idx() const
Definition Preset.hpp:739
@ ptSLA
Definition Config.hpp:233

References default_preset(), find_preset(), get_edited_preset(), get_preset_base(), get_selected_idx(), get_selected_preset(), Slic3r::Preset::inherits(), Slic3r::Preset::is_external, m_type, preset(), Slic3r::Preset::printer_technology(), Slic3r::ptSLA, and Slic3r::Preset::TYPE_PRINTER.

Referenced by 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
3766 {
3767 return g_suffix_modified;
3768}
static std::string g_suffix_modified
Definition Preset.cpp:504

References Slic3r::g_suffix_modified.

Referenced by Slic3r::GUI::EditDevNameDialog::on_edit_name(), Slic3r::GUI::AuFile::on_input_enter(), Slic3r::GUI::SelectMachineDialog::on_rename_enter(), Slic3r::GUI::SendMultiMachinePage::on_rename_enter(), Slic3r::GUI::SendToPrinterDialog::on_rename_enter(), Slic3r::GUI::SavePresetDialog::Item::update(), and Slic3r::GUI::PhysicalPrinterDialog::update_preset_input().

Here is the caller graph for this function:

◆ get_user_presets()

int Slic3r::PresetCollection::get_user_presets ( PresetBundle * preset_bundle,
std::vector< Preset > & result_presets )
inherited
2433{
2434 int count = 0;
2435 result_presets.clear();
2436
2437 lock();
2438 for (Preset &preset : m_presets) {
2439 if (!preset.is_user()) continue;
2440 if (preset.base_id.empty() && preset.inherits() != "") continue;
2441 if (!preset.setting_id.empty() && preset.sync_info.empty()) continue;
2442 //if (!preset.is_bbl_vendor_preset(preset_bundle)) continue;
2443 if (preset.sync_info == "hold") continue;
2444
2445 result_presets.push_back(preset);
2446 count++;
2447 }
2448 unlock();
2449
2450 return count;
2451}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246

References count, lock(), m_presets, preset(), PresetBundle, and unlock().

Here is the call graph for this function:

◆ has_defaults_only()

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

References m_num_default_presets, and m_presets.

◆ is_alias_exist()

bool Slic3r::PresetCollection::is_alias_exist ( const std::string & alias,
Preset * preset = nullptr )
inherited
3745{
3746 auto it = m_map_alias_to_profile_name.find(alias);
3747 if (m_map_alias_to_profile_name.end() == it) return false;
3748 if (!preset) return true;
3749
3750 auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset->config.option("compatible_printers"));
3751 if (compatible_printers == nullptr) return true;
3752
3753 for (const std::string &printer_name : compatible_printers->values) {
3754 auto printer_iter = m_printer_hold_alias.find(printer_name);
3755 if (m_printer_hold_alias.end() != printer_iter) {
3756 auto alias_iter = m_printer_hold_alias[printer_name].find(alias);
3757 if (m_printer_hold_alias[printer_name].end() != alias_iter) {
3758 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << " The alias already exists: " << alias << " and the preset name: " << preset->name;
3759 return true;
3760 }
3761 }
3762 }
3763 return false;
3764}
std::unordered_map< std::string, std::unordered_set< std::string > > m_printer_hold_alias
Definition Preset.hpp:1087
Iterator end()
Definition Preset.hpp:586

References end(), m_map_alias_to_profile_name, m_printer_hold_alias, and preset().

Here is the call graph for this function:

◆ is_base_preset()

bool Slic3r::PresetCollection::is_base_preset ( const Preset & preset) const
inlineinherited
917{ return preset.is_system || (preset.is_user() && preset.inherits().empty()); }

References preset().

Referenced by path_for_preset(), and save_current_preset().

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

◆ is_default_suppressed()

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

References m_default_suppressed.

◆ is_dirty()

bool Slic3r::PresetCollection::is_dirty ( const Preset * edited,
const Preset * reference )
staticinherited
4077{
4078 if (edited != nullptr && reference != nullptr) {
4079 // Only compares options existing in both configs.
4080 if (! reference->config.equals(edited->config, &skipped_in_dirty))
4081 return true;
4082 // The "compatible_printers" option key is handled differently from the others:
4083 // It is not mandatory. If the key is missing, it means it is compatible with any printer.
4084 // If the key exists and it is empty, it means it is compatible with no printer.
4085 for (auto &opt_key : optional_keys)
4086 if (reference->config.has(opt_key) != edited->config.has(opt_key))
4087 return true;
4088 }
4089 return false;
4090}
static std::set< std::string > skipped_in_dirty
Definition Preset.cpp:4074

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

Referenced by current_is_dirty(), load_external_preset(), saved_is_dirty(), and update_dirty().

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

◆ lbegin()

Iterator Slic3r::PresetCollection::lbegin ( )
inlineinherited
579{ return m_presets.begin(); }

References m_presets.

◆ legacy_user_filament_presets()

std::vector< LegacyUserFilamentPreset > Slic3r::PresetCollection::legacy_user_filament_presets ( const std::map< std::string, std::vector< std::string > > & printers_by_parent)
inherited
2788{
2789 auto has_entry = [&printers_by_parent](const std::string &name) { return printers_by_parent.count(name) > 0; };
2790 std::vector<LegacyUserFilamentPreset> legacy_presets;
2791 // The preset sync thread can add or delete presets meanwhile.
2792 lock();
2793 for (const Preset &preset : m_presets) {
2794 if (!preset.is_user() || preset.inherits().empty())
2795 continue;
2796 const Preset *parent = get_preset_parent(preset);
2797 if (parent == nullptr || !parent->is_system)
2798 continue;
2799 // An empty list already covers every printer.
2800 const std::vector<std::string> &own = preset.config.option<ConfigOptionStrings>("compatible_printers")->values;
2801 if (own.empty())
2802 continue;
2803 // The parent's name in the older release is its current name or one in its renamed_from, so only the
2804 // files of presets whose parent has an entry under one of those are read.
2805 if (!has_entry(parent->name) && std::none_of(parent->renamed_from.begin(), parent->renamed_from.end(), has_entry))
2806 continue;
2807 LegacyUserFilamentPreset legacy{preset.name, parent->name, {}, {}, preset.file, own};
2808 try {
2809 const json j = read_user_preset_file(preset.file);
2810 // A preset whose file sets compatible_printers, even to an empty list, was given its printers on
2811 // purpose and keeps exactly those.
2812 if (j.contains("compatible_printers"))
2813 continue;
2814 legacy.inherits = j.value(BBL_JSON_KEY_INHERITS, std::string());
2815 } catch (const std::exception &err) {
2816 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": can not read " << preset.file << ": " << err.what();
2817 continue;
2818 }
2819 auto it = printers_by_parent.find(legacy.inherits);
2820 if (it == printers_by_parent.end())
2821 continue;
2822 for (const std::string &printer : it->second)
2823 if (std::find(own.begin(), own.end(), printer) == own.end()) {
2824 legacy.printers.push_back(printer);
2825 legacy.compatible_printers.push_back(printer);
2826 }
2827 if (!legacy.printers.empty())
2828 legacy_presets.push_back(std::move(legacy));
2829 }
2830 unlock();
2831 return legacy_presets;
2832}
#define BBL_JSON_KEY_INHERITS
Definition Preset.hpp:75
nlohmann::json json
Definition AssembleList.cpp:42
static json read_user_preset_file(const std::string &file)
Definition Preset.cpp:2781

References BBL_JSON_KEY_INHERITS, Slic3r::LegacyUserFilamentPreset::compatible_printers, get_preset_parent(), Slic3r::LegacyUserFilamentPreset::inherits, Slic3r::Preset::is_system, lock(), m_presets, Slic3r::Preset::name, name(), preset(), Slic3r::LegacyUserFilamentPreset::printers, Slic3r::read_user_preset_file(), Slic3r::Preset::renamed_from, and unlock().

Here is the call 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,
const std::set< std::string > & different_settings_list,
LoadAndSelect select = LoadAndSelect::Always,
const Semver file_version = Semver(),
const std::string filament_id = std::string() )
inherited
2977{
2978 std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
2979 bool found = it != m_presets.end() && it->name == original_name;
2980 if (! found) {
2981 // Try to match the original_name against the "renamed_from" profile names of loaded system profiles.
2982 it = this->find_preset_renamed(original_name);
2983 found = it != m_presets.end();
2984 }
2985
2987 DynamicPrintConfig cfg = Preset::load_external_config(m_type, this->default_preset_for(combined_config).config, combined_config, different_settings_list,
2988 [this, &original_name, &path, found, it](const std::string &inherits) -> DynamicPrintConfig * {
2989 if (!inherits.empty()) {
2990 auto iter = this->find_preset_internal(inherits);
2991 if (iter == m_presets.end() || iter->name != inherits)
2992 iter = this->find_preset_renamed(inherits);
2993 if (iter == m_presets.end())
2994 return nullptr;
2995 BOOST_LOG_TRIVIAL(info) << "load_external_preset" << boost::format(": change preset %1% inherit %2% 's value to %3% 's values")%original_name %inherits %path;
2996 return &iter->config;
2997 }
2998 if (found && it->is_system) {
2999 BOOST_LOG_TRIVIAL(info) << "load_external_preset" << boost::format(": change preset %1% 's value to %2% 's values")%original_name %path;
3000 return &it->config;
3001 }
3002 return nullptr;
3003 }, &keys);
3004 std::string &inherits = Preset::inherits(cfg);
3005
3006 //BBS: add config related logs
3007 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , path %2%, name %3%, original_name %4%, inherits %5%")%Preset::get_type_string(m_type) %path %name %original_name %inherits;
3008 if (select == LoadAndSelect::Never) {
3009 // Some filament profile has been selected and modified already.
3010 // Check whether this profile is equal to the modified edited profile.
3011 const Preset &edited = this->get_edited_preset();
3012 if ((edited.name == original_name || edited.name == inherits) && profile_print_params_same(edited.config, cfg)) {
3013 // Just point to that already selected and edited profile.
3014 //BBS: add config related logs
3015 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" Just point to that already selected and edited profile %1%")%edited.name;
3016 return std::make_pair(&(*this->find_preset_internal(edited.name)), false);
3017 }
3018 }
3019 // Is there a preset already loaded with the name stored inside the config?
3020 /*std::deque<Preset>::iterator it = this->find_preset_internal(original_name);
3021 bool found = it != m_presets.end() && it->name == original_name;
3022 if (! found) {
3023 // Try to match the original_name against the "renamed_from" profile names of loaded system profiles.
3024 it = this->find_preset_renamed(original_name);
3025 found = it != m_presets.end();
3026 }*/
3027 if (found && profile_print_params_same(it->config, cfg)) {
3028 // The preset exists and it matches the values stored inside config.
3029 if (select == LoadAndSelect::Always)
3030 this->select_preset(it - m_presets.begin());
3031 //BBS: set the preset to visible
3032 if ( !it->is_visible ) {
3033 it->is_visible = true;
3034 //AppConfig* app_config = get_app_config();
3035 //if (app_config)
3036 // app_config->set(AppConfig::SECTION_FILAMENTS, it->name, "1");
3037 }
3038 //BBS: add config related logs
3039 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" The preset exists and it matches the values stored inside config. using original_name %1%")%original_name;
3040 return std::make_pair(&(*it), false);
3041 }
3042 if (! found && select != LoadAndSelect::Never && ! inherits.empty()) {
3043 // Try to use a system profile as a base to select the system profile
3044 // and override its settings with the loaded ones.
3045 assert(it == m_presets.end());
3046 it = this->find_preset_internal(inherits);
3047 if (it == m_presets.end() || it->name != inherits)
3048 it = this->find_preset_renamed(inherits);
3049 found = it != m_presets.end();
3050 if (found && profile_print_params_same(it->config, cfg)) {
3051 // The system preset exists and it matches the values stored inside config.
3052 if (select == LoadAndSelect::Always)
3053 this->select_preset(it - m_presets.begin());
3054 //BBS: set the preset to visible
3055 if ( !it->is_visible ) {
3056 it->is_visible = true;
3057 //AppConfig* app_config = get_app_config();
3058 //if (app_config)
3059 // app_config->set(AppConfig::SECTION_FILAMENTS, it->name, "1");
3060 }
3061 //BBS: add config related logs
3062 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" The preset exists and it matches the values stored inside config. using inherits %1%")%inherits;
3063 return std::make_pair(&(*it), false);
3064 }
3065 }
3066 if (found) {
3067 //BBS: only select preset for always
3068 //if (select != LoadAndSelect::Never) {
3069 if (select == LoadAndSelect::Always) {
3070 // Select the existing preset and override it with new values, so that
3071 // the differences will be shown in the preset editor against the referenced profile.
3072 this->select_preset(it - m_presets.begin());
3073 // The source config may contain keys from many possible preset types. Just copy those that relate to this preset.
3074 //this->get_edited_preset().config.apply_only(combined_config, keys, true);
3075 this->get_edited_preset().config.apply_only(cfg, keys, true);
3076 this->update_dirty();
3078 assert(this->get_edited_preset().is_dirty);
3079 //BBS: set the preset to visible
3080 if ( !it->is_visible ) {
3081 it->is_visible = true;
3082 //AppConfig* app_config = get_app_config();
3083 //if (app_config)
3084 // app_config->set(AppConfig::SECTION_FILAMENTS, it->name, "1");
3085 }
3086 //BBS: add config related logs
3087 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" Select the existing preset %1% and override it with new values")%it->name;
3088 return std::make_pair(&(*it), this->get_edited_preset().is_dirty);
3089 }
3090
3091 //BBS: for other filaments under AMS
3092 if (it->is_project_embedded) {
3093 //update the properties back to the preset
3094 it->config.apply_only(cfg, keys, true);
3095 it->is_dirty = false;
3096
3097 return std::make_pair(&(*it), false);
3098 }
3099 if (inherits.empty()) {
3100 // Update the "inherits" field.
3101 // There is a profile with the same name already loaded. Should we update the "inherits" field?
3102 inherits = it->vendor ? it->name : it->inherits();
3103 }
3104 }
3105
3106 // The external preset does not match an internal preset, load the external preset.
3107 std::string new_name;
3108 //BBS: add project embedded preset logic
3109 //BBS: refine the name logic
3110 for (size_t idx = 0;; ++ idx) {
3111 std::string prefix;
3112 if (original_name.empty()) {
3113 if (!inherits.empty()) {
3114 if (idx == 0)
3115 prefix = inherits;
3116 else
3117 prefix = inherits + "-" + std::to_string(idx);
3118 }
3119 else {
3120 if (idx > 0)
3121 prefix = std::to_string(idx);
3122 }
3123 } else {
3124 std::string reduced_name = original_name;
3125 //TODO
3126 //boost::regex rx("3mf\‍(*\‍)");
3127 //boost::iterator_range<std::string::iterator> result = boost::algorithm::find_regex(reduced_name, rx);
3128 //if (!result.empty()) {
3129 // reduced_name = std::string(result.begin(), result.end());
3130 //}
3131
3132 if (idx == 0)
3133 prefix = reduced_name;
3134 else
3135 prefix = reduced_name + "-" + std::to_string(idx) ;
3136 }
3137 //new_name = name + suffix;
3138 new_name = prefix + "(" + name + ")";
3139 it = this->find_preset_internal(new_name);
3140 if (it == m_presets.end() || it->name != new_name)
3141 // Unique profile name. Insert a new profile.
3142 break;
3143 if (profile_print_params_same(it->config, cfg)) {
3144 // The preset exists and it matches the values stored inside config.
3145 if (select == LoadAndSelect::Always)
3146 this->select_preset(it - m_presets.begin());
3147 //BBS: add config related logs
3148 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" The preset %1% exists and it matches the values stored inside config.")%new_name;
3149 return std::make_pair(&(*it), false);
3150 }
3151 // Form another profile name.
3152 }
3153 // Insert a new profile.
3154 //BBS: add project embedded preset logic
3155 // A G-code's settings are shown like a project's, so a preset made from them lives with the project
3156 // rather than in the user's library.
3157 bool from_project = boost::algorithm::iends_with(name, ".3mf") || is_gcode_file(name);
3159 cfg.option<ConfigOptionString >("print_settings_id", true)->value = new_name;
3160 else if (m_type == Preset::TYPE_FILAMENT)
3161 cfg.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
3162 else if (m_type == Preset::TYPE_PRINTER)
3163 cfg.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
3164 Preset &preset = this->load_preset(path, new_name, std::move(cfg), select == LoadAndSelect::Always);
3165 preset.is_external = true;
3166 preset.version = file_version;
3167 if (!filament_id.empty())
3168 preset.filament_id = filament_id;
3169 else {
3170 if (!inherits.empty()) {
3171 // Orca: resolve via find_preset2 so a renamed/removed-and-matched parent still
3172 // yields its filament_id (external presets store a full config, so the dangling
3173 // "inherits" itself is normalized on the next load_presets pass).
3174 Preset *parent = this->find_preset2(inherits, true);
3175 if (parent)
3176 preset.filament_id = parent->filament_id;
3177 }
3178 }
3179 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << preset.name << " filament_id: " << preset.filament_id << " base_id: " << preset.base_id;
3180 if (from_project) {
3181 preset.is_project_embedded = true;
3182 }
3183 else {
3184 //external config
3186 //BBS: save full config here for external
3187 //we can not reach here
3188 preset.save(nullptr);
3189 }
3190 if (&this->get_selected_preset() == &preset)
3191 this->get_edited_preset().is_external = true;
3192
3193 //BBS: add config related logs
3194 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", type %1% added a preset, name %2%, path %3%, is_system %4%, is_default %5% is_external %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_external;
3195 return std::make_pair(&preset, false);
3196}
void apply_only(const ConfigBase &other, const t_config_option_keys &keys, bool ignore_nonexistent=false)
Definition Config.cpp:484
@ Always
Definition Preset.hpp:671
@ Never
Definition Preset.hpp:669
void update_saved_preset_from_current_preset()
Definition Preset.hpp:902
virtual const Preset & default_preset_for(const DynamicPrintConfig &) const
Definition Preset.hpp:788
bool update_dirty()
Definition Preset.cpp:3950
Preset & load_preset(const std::string &path, const std::string &name, const DynamicPrintConfig &config, bool select=true, Semver file_version=Semver())
Definition Preset.cpp:2936
static DynamicPrintConfig load_external_config(Type type, const DynamicPrintConfig &default_config, const DynamicPrintConfig &project_config, const std::set< std::string > &different_settings_list, const std::function< DynamicPrintConfig *(const std::string &inherits)> &find_base, t_config_option_keys *keys=nullptr)
Definition Preset.cpp:1059
bool is_external
Definition Preset.hpp:268
DynamicPrintConfig config
Definition Preset.hpp:300
bool is_gcode_file(const std::string &path)
Definition utils.cpp:1208
std::vector< std::string > t_config_option_keys
Definition Config.hpp:97
static bool profile_print_params_same(const DynamicPrintConfig &cfg_old, const DynamicPrintConfig &cfg_new)
Definition Preset.cpp:2943

References Always, Slic3r::ConfigBase::apply_only(), Slic3r::Preset::config, default_preset_for(), Slic3r::Preset::filament_id, find_preset2(), find_preset_internal(), find_preset_renamed(), get_edited_preset(), get_selected_preset(), Slic3r::Preset::get_type_string(), Slic3r::Preset::inherits(), is_dirty(), Slic3r::Preset::is_external, Slic3r::is_gcode_file(), Slic3r::Preset::load_external_config(), load_preset(), m_presets, m_type, Slic3r::Preset::name, name(), Never, Slic3r::ConfigBase::option(), path_for_preset(), preset(), Slic3r::profile_print_params_same(), select_preset(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, update_dirty(), and update_saved_preset_from_current_preset().

Here is the call 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,
Semver file_version = Semver() )
inherited
2937{
2938 DynamicPrintConfig cfg(this->default_preset().config);
2939 cfg.apply_only(config, cfg.keys(), true);
2940 return this->load_preset(path, name, std::move(cfg), select, file_version);
2941}

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

Referenced by Slic3r::PresetBundle::import_json_presets(), load_external_preset(), and 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,
Semver file_version = Semver() )
inherited
3211{
3212 lock();
3213 auto it = this->find_preset_internal(name);
3214 if (it == m_presets.end() || it->name != name) {
3215 // The preset was not found. Create a new preset.
3216 if (m_presets.begin() + m_idx_selected >= it)
3218 it = m_presets.emplace(it, Preset(m_type, name, false));
3219 }
3220 Preset &preset = *it;
3221 preset.file = path;
3222 preset.config = std::move(config);
3223 preset.loaded = true;
3224 preset.is_dirty = false;
3225
3226 //BBS
3227 if (file_version.valid())
3228 preset.version = file_version;
3229 if (select)
3230 this->select_preset_by_name(name, true);
3231 unlock();
3232 //BBS: add config related logs
3233 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", preset type %1%, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset.name %preset.file %preset.is_system %preset.is_default %preset.is_visible;
3234 return preset;
3235}

References find_preset_internal(), Slic3r::Preset::get_type_string(), lock(), m_idx_selected, m_presets, m_type, name(), Slic3r::Preset, preset(), select_preset_by_name(), unlock(), and Slic3r::Semver::valid().

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,
std::function< void(Preset &)> preset_loaded_fn = nullptr,
const PresetOrigin & load_origin = PresetOrigin(),
bool read_only = false )
inherited
2003{
2004 // Don't use boost::filesystem::canonical() on Windows, it is broken in regard to reparse points,
2005 // see https://github.com/prusa3d/PrusaSlicer/issues/732
2006 boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / subdir).make_preferred();
2007 const PresetOrigin resolved_origin = detect_origin_from_path(dir, load_origin);
2008
2009 // Load custom roots first
2010 if (fs::exists(dir / "base")) {
2011 load_presets(dir.string(), "base", substitutions, substitution_rule, nullptr, resolved_origin, read_only);
2012 }
2013
2014 //BBS: add config related logs
2015 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, load presets from %1%, current type %2%")%dir %Preset::get_type_string(m_type);
2016 //BBS do not parse folder if not exists
2017 m_dir_path = dir.string();
2018 if (!fs::exists(dir)) {
2019 if (!read_only)
2020 fs::create_directory(dir);
2021 return;
2022 }
2023
2024 std::string errors_cummulative;
2025 // Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
2026 // (see the "Preset already present, not loading" message).
2027 std::deque<Preset> presets_loaded;
2028
2029 //BBS: get the extruder related info for this preset collection
2030 std::string extruder_id_name, extruder_variant_name;
2031 std::set<std::string> *key_set1 = nullptr, *key_set2 = nullptr;
2032 Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2);
2033
2034 struct UserPresetFile { fs::path path; std::string canonical_name; };
2035 std::vector<UserPresetFile> files;
2036 //BBS: change to json format
2037 for (auto &dir_entry : boost::filesystem::directory_iterator(dir))
2038 {
2039 std::string file_name = dir_entry.path().filename().string();
2040 //if (Slic3r::is_ini_file(dir_entry)) {
2041 if (Slic3r::is_json_file(file_name)) {
2042 // Remove the .ini suffix.
2043 std::string name = file_name.erase(file_name.size() - 5);
2044 std::string canonical_name = this->canonical_preset_name(name, resolved_origin);
2045 if (this->find_preset(canonical_name, false)) {
2046 // This happens when there's is a preset (most likely legacy one) with the same name as a system preset
2047 // that's already been loaded from a bundle.
2048 BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << canonical_name;
2049 continue;
2050 }
2051 files.push_back({ dir_entry.path(), std::move(canonical_name) });
2052 }
2053 }
2054
2056 [&](size_t i) {
2057 return this->resolve_user_preset(files[i].path, files[i].canonical_name, resolved_origin, substitution_rule,
2058 extruder_id_name, extruder_variant_name, key_set1, key_set2, read_only);
2059 },
2060 [&](size_t i, UserPresetLoad &&loaded) {
2061 // Resolve read the files without the lock, so another instance may have saved
2062 // over them since. A file that changed is resolved again under the lock before
2063 // commit removes or rewrites it, which also keeps its .json and .info from two
2064 // different saves apart. Without the lock nothing is checked, so commit leaves
2065 // the files alone.
2066 const std::string lock_path = user_presets_lock_path(read_only);
2067 InstanceLock instance_lock(lock_path);
2068 if (instance_lock.locked()) {
2069 const PresetFilesOnDisk on_disk = PresetFilesOnDisk::read(files[i].path);
2070 boost::system::error_code ec;
2071 // The link itself, and a stat error counts as present, so a file that is
2072 // there but cannot be read is still counted and removed by commit.
2073 if (! on_disk.json && fs::symlink_status(files[i].path, ec).type() == fs::file_not_found)
2074 return; // removed by another instance since it was read
2075 if (! (on_disk == loaded.on_disk)) {
2076 CNumericLocalesSetter locales_setter;
2077 loaded = this->resolve_user_preset(files[i].path, files[i].canonical_name, resolved_origin, substitution_rule,
2078 extruder_id_name, extruder_variant_name, key_set1, key_set2, read_only);
2079 }
2080 }
2081 const bool leave_files = read_only || (! lock_path.empty() && ! instance_lock.locked());
2082 // Committing can remove an unreadable preset's file, and a filesystem error
2083 // there is reported without stopping the rest of the directory.
2084 try {
2085 this->commit_user_preset(std::move(loaded), presets_loaded, substitutions, preset_loaded_fn, leave_files);
2086 } catch (const std::runtime_error &err) {
2087 errors_cummulative += err.what();
2088 errors_cummulative += "\n";
2089 }
2090 });
2091
2092 if (presets_loaded.size() > 0)
2093 m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
2094 sort_presets();
2095 //BBS: add config related logs
2096 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": loaded %1% presets from %2%, type %3%")%presets_loaded.size() %dir %Preset::get_type_string(m_type);
2097 //this->select_preset(first_visible_idx());
2098 if (! errors_cummulative.empty())
2099 throw Slic3r::RuntimeError(errors_cummulative);
2100}
void sort_presets()
Definition Preset.hpp:1027
void load_presets(const std::string &dir_path, const std::string &subdir, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule, std::function< void(Preset &)> preset_loaded_fn=nullptr, const PresetOrigin &load_origin=PresetOrigin(), bool read_only=false)
Definition Preset.cpp:1999
std::string canonical_preset_name(const std::string &name, const PresetOrigin &load_origin=PresetOrigin()) const
Definition Preset.cpp:1796
std::string m_dir_path
Definition Preset.hpp:1102
bool is_json_file(const std::string &path)
Definition utils.cpp:1214
PresetOrigin detect_origin_from_path(const boost::filesystem::path &path, const PresetOrigin &explicit_origin)
Definition Preset.cpp:178
void resolve_then_commit(size_t count, Resolve resolve, Commit commit)
Definition ParallelResolve.hpp:40

References canonical_preset_name(), Slic3r::detect_origin_from_path(), find_preset(), Slic3r::Preset::get_extruder_names_and_keysets(), Slic3r::Preset::get_type_string(), Slic3r::is_json_file(), load_presets(), m_dir_path, m_type, name(), and Slic3r::resolve_then_commit().

Referenced by load_presets().

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

◆ load_project_embedded_presets()

void Slic3r::PresetCollection::load_project_embedded_presets ( std::vector< Preset * > & project_presets,
const std::string & type,
PresetsConfigSubstitutions & substitutions,
ForwardCompatibilitySubstitutionRule rule )
inherited
2248{
2249 std::string errors_cummulative;
2250 // Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
2251 // (see the "Preset already present, not loading" message).
2252 std::deque<Preset> presets_loaded;
2253 std::vector<Preset*>::iterator it;
2254
2255 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" enter, type %1% , total preset counts %2%")%Preset::get_type_string(m_type) %project_presets.size();
2256 std::string extruder_id_name, extruder_variant_name;
2257 std::set<std::string> *key_set1 = nullptr, *key_set2 = nullptr;
2258 Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2);
2259
2260 lock();
2261 for (it = project_presets.begin(); it != project_presets.end(); it++) {
2262 Preset* preset = *it;
2263 if (preset->type != Preset::get_type_from_string(type)) continue;
2264 if (!preset->is_project_embedded) continue;
2265 std::string name = preset->name;
2266 if (this->find_preset(name, false)) {
2267 BOOST_LOG_TRIVIAL(warning) << "Preset already present, not loading: " << name;
2268 continue;
2269 }
2270 try {
2271 DynamicPrintConfig config = preset->config;
2272 if (preset->loading_substitutions && ! preset->loading_substitutions->empty()) {
2273 substitutions.push_back({ preset->name, m_type, PresetConfigSubstitutions::Source::ProjectFile, preset->name, std::move(*(preset->loading_substitutions))});
2274 free(preset->loading_substitutions);
2275 preset->loading_substitutions = NULL;
2276 }
2277 //BBS: use inherit config as the base
2278 Preset* inherit_preset = nullptr;
2279 ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS);
2280 if (inherits_config) {
2281 ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
2282 std::string inherits_value = option_str->value;
2283 /*size_t pos = inherits_value.find_first_of('*');
2284 if (pos != std::string::npos) {
2285 inherits_value.replace(pos, 1, 1, '~');
2286 option_str->value = inherits_value;
2287 }*/
2288 inherit_preset = this->find_preset2(inherits_value, true);
2289 Preset::normalize_inherits(config, inherit_preset);
2290 }
2291 const Preset& default_preset = this->default_preset_for(config);
2292 if (inherit_preset) {
2293 preset->config = inherit_preset->config;
2294 preset->filament_id = inherit_preset->filament_id;
2295 }
2296 else {
2297 // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
2298 //BBS 202407: don't load project embedded preset when can not find inherit
2299 //preset->config = default_preset.config;
2300 BOOST_LOG_TRIVIAL(error) << boost::format("can not find parent for config %1%!")%preset->file;
2301 continue;
2302 }
2303 extend_default_config_length(config, false, {});
2304 preset->config.update_diff_values_to_child_config(config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2);
2305 //preset->config.apply(std::move(config));
2306 Preset::normalize(preset->config);
2307 // Report configuration fields, which are misplaced into a wrong group.
2308 std::string incorrect_keys = Preset::remove_invalid_keys(preset->config, default_preset.config);
2309 if (!incorrect_keys.empty()) {
2310 ++m_errors;
2311 BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" << preset->name
2312 << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
2313 }
2314 preset->loaded = true;
2315 presets_loaded.emplace_back(*preset);
2316 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", %1% got preset, name %2%, path %3%, is_system %4%, is_default %5% is_visible %6%")%Preset::get_type_string(m_type) %preset->name %preset->file %preset->is_system %preset->is_default %preset->is_visible;
2317 } catch (const std::runtime_error &err) {
2318 errors_cummulative += err.what();
2319 errors_cummulative += "\n";
2320 }
2321 }
2322
2323 m_presets.insert(m_presets.end(), std::make_move_iterator(presets_loaded.begin()), std::make_move_iterator(presets_loaded.end()));
2324 sort_presets();
2325 //don't select it here
2326 //this->select_preset(first_visible_idx());
2327 unlock();
2328
2329 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, %1% got %2% presets, errors_cummulative %3%")%Preset::get_type_string(m_type) %presets_loaded.size() %errors_cummulative;
2330 if (! errors_cummulative.empty())
2331 throw Slic3r::RuntimeError(errors_cummulative);
2332}
static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config, const DynamicPrintConfig *added=nullptr)
Definition Preset.cpp:573
static void normalize_inherits(DynamicPrintConfig &cfg, const Preset *resolved_parent)
Definition Preset.hpp:366
static Preset::Type get_type_from_string(std::string type_str)
Definition Preset.cpp:657
static void normalize(DynamicPrintConfig &config)
Definition Preset.cpp:524
void extend_default_config_length(DynamicPrintConfig &config, const bool set_nil_to_default, const DynamicPrintConfig &defaults)
Definition Preset.cpp:301
@ ProjectFile
Definition Preset.hpp:541

References BBL_JSON_KEY_INHERITS, Slic3r::Preset::config, default_preset(), default_preset_for(), Slic3r::extend_default_config_length(), Slic3r::Preset::filament_id, find_preset(), find_preset2(), Slic3r::Preset::get_extruder_names_and_keysets(), Slic3r::Preset::get_type_from_string(), Slic3r::Preset::get_type_string(), lock(), m_errors, m_presets, m_type, name(), Slic3r::Preset::normalize(), Slic3r::Preset::normalize_inherits(), Slic3r::ConfigBase::option(), preset(), Slic3r::PresetConfigSubstitutions::ProjectFile, Slic3r::Preset::remove_invalid_keys(), sort_presets(), type(), unlock(), and Slic3r::ConfigOptionSingle< T >::value.

Here is the call graph for this function:

◆ load_user_preset()

bool Slic3r::PresetCollection::load_user_preset ( std::string name,
std::map< std::string, std::string > preset_values,
PresetsConfigSubstitutions & substitutions,
ForwardCompatibilitySubstitutionRule rule,
const PresetOrigin & load_origin = PresetOrigin(PresetOrigin::Kind::User) )
inherited
2520{
2521 std::string errors_cummulative;
2522 // Store the loaded presets into a new vector, otherwise the binary search for already existing presets would be broken.
2523 // (see the "Preset already present, not loading" message).
2524 //std::deque<Preset> presets_loaded;
2525 int count = 0;
2526 const std::string canonical_name = this->canonical_preset_name(name, load_origin);
2527 auto update_alias = [this](Preset &preset) {
2528 if (! preset.alias.empty())
2529 return;
2531 };
2532
2533 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" enter, name %1% , total value counts %2%")%canonical_name %preset_values.size();
2534
2535 //if the version is not matching, skip it
2536 if (preset_values.find(BBL_JSON_KEY_VERSION) == preset_values.end()) {
2537 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find version, not loading for user preset %1%")%canonical_name;
2538 return false;
2539 }
2540 std::string version_str = preset_values[BBL_JSON_KEY_VERSION];
2541 boost::optional<Semver> cloud_version = Semver::parse(version_str);
2542 if (!cloud_version) {
2543 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("invalid version %1%, not loading for user preset %2%")%version_str %canonical_name;
2544 return false;
2545 }
2546
2547 //setting_id
2548 if (preset_values.find(BBL_JSON_KEY_SETTING_ID) == preset_values.end()) {
2549 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find setting_id, not loading for user preset %1%")%canonical_name;
2550 return false;
2551 }
2552 std::string cloud_setting_id = preset_values[BBL_JSON_KEY_SETTING_ID];
2553
2554 //update_time
2555 long long cloud_update_time = 0;
2556 if (preset_values.find(ORCA_JSON_KEY_UPDATE_TIME) != preset_values.end()) {
2557 cloud_update_time = std::atoll(preset_values[ORCA_JSON_KEY_UPDATE_TIME].c_str());
2558 }
2559
2560 //user_id
2561 if (preset_values.find(BBL_JSON_KEY_USER_ID) == preset_values.end()) {
2562 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format("can not find user_id, not loading for user preset %1%")%canonical_name;
2563 return false;
2564 }
2565 std::string cloud_user_id = preset_values[BBL_JSON_KEY_USER_ID];
2566
2567 lock();
2568 //std::string name = preset->name;
2569 auto iter = this->find_preset_internal(canonical_name);
2570 bool need_update = false;
2571 if ((iter != m_presets.end()) && (iter->name == canonical_name)) {
2572 BOOST_LOG_TRIVIAL(info) << "Found the Preset locally: " << canonical_name;
2573 //BBS: we should compare the time between cloud and local
2574 if ((cloud_update_time == 0) || (cloud_update_time <= iter->updated_time)) {
2575 if (cloud_update_time < iter->updated_time)
2576 iter->sync_info = "update";
2577 else
2578 iter->sync_info.clear();
2579 // Fixup possible data lost
2580 iter->setting_id = cloud_setting_id;
2581 fs::path idx_file(iter->file);
2582 idx_file.replace_extension(".info");
2583 iter->save_info(idx_file.string());
2584 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("preset %1%'s update_time is eqaul or newer, cloud update_time %2%, local update_time %3%")%canonical_name %cloud_update_time %iter->updated_time;
2585 unlock();
2586 return false;
2587 }
2588 else {
2589 //update the one from cloud which is newer
2590 need_update = true;
2591 }
2592 }
2593
2594 // base_id is only required for presets inheriting from a parent. Root presets
2595 // with an empty "inherits" field intentionally have no base_id.
2596 std::string based_id;
2597 const auto base_id = preset_values.find(BBL_JSON_KEY_BASE_ID);
2598 if (base_id != preset_values.end()) {
2599 based_id = base_id->second;
2600 } else {
2601 const auto inherits_iter = preset_values.find(BBL_JSON_KEY_INHERITS);
2602 const bool preset_inherits_from_parent = inherits_iter != preset_values.end() && !inherits_iter->second.empty();
2603 if (preset_inherits_from_parent) {
2604 // No base_id stored although the preset inherits from a parent. Rather than
2605 // dropping the preset, derive base_id on the fly from the resolved parent's
2606 // setting_id below (the parent is found by its "inherits" name). Only the
2607 // genuinely unresolvable-parent case is skipped, further down.
2608 BOOST_LOG_TRIVIAL(info) << __FUNCTION__
2609 << boost::format("no base_id for user preset %1%, will derive it from the parent") % canonical_name;
2610 }
2611 }
2612
2613 //filament_id
2614 std::string cloud_filament_id;
2615 if ((m_type == Preset::TYPE_FILAMENT) && preset_values.find(BBL_JSON_KEY_FILAMENT_ID) != preset_values.end()) {
2616 cloud_filament_id = preset_values[BBL_JSON_KEY_FILAMENT_ID];
2617 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << canonical_name << " filament_id: " << cloud_filament_id << " base_id: " << based_id;
2618 }
2619
2620 DynamicPrintConfig new_config, cloud_config;
2621 try {
2622 ConfigSubstitutions config_substitutions = cloud_config.load_string_map(preset_values, rule);
2623 if (! config_substitutions.empty())
2624 substitutions.push_back({ canonical_name, m_type, PresetConfigSubstitutions::Source::UserCloud, canonical_name, std::move(config_substitutions) });
2625
2626 //BBS: use inherit config as the base
2627 Preset* inherit_preset = nullptr;
2628 ConfigOption* inherits_config = cloud_config.option(BBL_JSON_KEY_INHERITS);
2629 if (inherits_config) {
2630 ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
2631 std::string inherits_value = option_str->value;
2632 inherit_preset = this->find_preset2(inherits_value, true);
2633 Preset::normalize_inherits(cloud_config, inherit_preset);
2634 }
2635 const Preset& default_preset = this->default_preset_for(cloud_config);
2636 if (inherit_preset) {
2637 new_config = inherit_preset->config;
2638 // Derive base_id from the resolved parent when it was not supplied. The
2639 // parent's setting_id is itself computed deterministically at load time, so
2640 // this stays stable. Does not affect the preset's own (cloud) setting_id.
2641 if (based_id.empty())
2642 based_id = inherit_preset->setting_id;
2643 if (cloud_filament_id == "null") {
2644 cloud_filament_id = inherit_preset->filament_id;
2645 }
2646 }
2647 else {
2648 // We support custom root preset now
2649 auto inherits_config2 = dynamic_cast<ConfigOptionString *>(inherits_config);
2650 if (inherits_config2 && !inherits_config2->value.empty()) {
2651 //we should skip this preset here
2652 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(", can not find inherit preset for user preset %1%, just skip")%canonical_name;
2653 unlock();
2654 return false;
2655 }
2656 // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
2657 new_config = default_preset.config;
2658 }
2659
2660 std::string extruder_id_name, extruder_variant_name;
2661 std::set<std::string> *key_set1 = nullptr, *key_set2 = nullptr;
2662 Preset::get_extruder_names_and_keysets(m_type, extruder_id_name, extruder_variant_name, &key_set1, &key_set2);
2663
2664 // Older uploads left out a variant layout equal to the parent's but still sent one value per
2665 // parent variant. Read those values against the parent's layout instead of cutting them to one.
2666 if (inherit_preset && !cloud_config.has(extruder_variant_name)) {
2667 const auto *parent_variants = inherit_preset->config.option<ConfigOptionStrings>(extruder_variant_name);
2668 const size_t variant_count = parent_variants ? parent_variants->size() : 0;
2669 bool values_per_variant = false;
2670 for (const std::string &key : cloud_config.keys()) {
2671 const size_t stride = key_set2->count(key) ? 2 : key_set1->count(key) ? 1 : 0;
2672 const auto *values = dynamic_cast<const ConfigOptionVectorBase *>(cloud_config.option(key));
2673 if (stride > 0 && key != extruder_id_name && values && variant_count > 1 && values->size() == variant_count * stride) {
2674 values_per_variant = true;
2675 break;
2676 }
2677 }
2678 if (values_per_variant)
2679 for (const std::string &key : {extruder_id_name, extruder_variant_name})
2680 if (!key.empty() && !cloud_config.has(key) && inherit_preset->config.has(key))
2681 cloud_config.set_key_value(key, inherit_preset->config.option(key)->clone());
2682 }
2683
2684 extend_default_config_length(cloud_config, false, {});
2685
2686 if (inherit_preset)
2687 new_config.update_diff_values_to_child_config(cloud_config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2);
2688 else{
2689 new_config.apply(std::move(cloud_config));
2690 extend_default_config_length(new_config, true, default_preset.config);
2691 }
2692 Preset::normalize(new_config);
2693 // Report configuration fields, which are misplaced into a wrong group.
2694 std::string incorrect_keys = Preset::remove_invalid_keys(new_config, default_preset.config);
2695 if (!incorrect_keys.empty()) {
2696 ++m_errors;
2697 BOOST_LOG_TRIVIAL(error) << "Error in a preset file: The preset \"" << canonical_name
2698 << "\" contains the following incorrect keys: " << incorrect_keys << ", which were removed";
2699 }
2700 if (need_update) {
2701 if (iter->name == m_edited_preset.name && iter->is_dirty) {
2702 // Keep modifies when update from remote
2703 new_config.apply_only(m_edited_preset.config, m_edited_preset.config.diff(iter->config));
2704 } else if (iter->name == m_edited_preset.name) {
2705 // Preset is not dirty (no local unsaved changes) — also update the edited preset
2706 // to prevent a false "dirty" indication (orange highlight) after a silent cloud sync
2707 m_edited_preset.config = new_config;
2708 }
2709 iter->config = new_config;
2710 iter->updated_time = cloud_update_time;
2711 iter->sync_info = "save";
2712 iter->version = cloud_version.value();
2713 iter->user_id = cloud_user_id;
2714 iter->setting_id = cloud_setting_id;
2715 iter->base_id = based_id;
2716 iter->filament_id = cloud_filament_id;
2717 update_alias(*iter);
2718 // Persist the cloud-assigned identity to disk, mirroring the equal/newer branch
2719 // above; otherwise the id stays only in memory and the next launch rewrites it.
2720 iter->save_info();
2721 //presets_loaded.emplace_back(*it->second);
2722 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", update the user preset %1% from cloud, type %2%, setting_id %3%, base_id %4%, sync_info %5% inherits %6%, filament_id %7%")
2723 % iter->name %Preset::get_type_string(m_type) %iter->setting_id %iter->base_id %iter->sync_info %iter->inherits() % iter->filament_id;
2724 }
2725 else {
2726 //create a new one
2727 Preset preset(m_type, canonical_name, false);
2728 preset.is_system = false;
2729 preset.loaded = true;
2730 preset.bundle_id = load_origin.bundle_id;
2731 preset.config = new_config;
2732 preset.updated_time = cloud_update_time;
2733 preset.sync_info = "save";
2734 preset.version = cloud_version.value();
2735 preset.user_id = cloud_user_id;
2736 preset.setting_id = cloud_setting_id;
2737 preset.base_id = based_id;
2738 preset.filament_id = cloud_filament_id;
2739 update_alias(preset);
2740
2741 size_t cur_index = iter - m_presets.begin();
2742 m_presets.insert(iter, preset);
2743 //m_presets.emplace_back (preset);
2744 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", insert a new user preset %1%, type %2%, setting_id %3%, base_id %4%, sync_info %5% inherits %6%, filament_id %7%")
2745 %preset.name %Preset::get_type_string(m_type) %preset.setting_id %preset.base_id %preset.sync_info %preset.inherits() %preset.filament_id;
2746 if (cur_index <= m_idx_selected) {
2747 m_idx_selected ++;
2748 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(", increase m_idx_selected to %1%, due to user preset inserted")%m_idx_selected;
2749 }
2750 }
2751 } catch (const std::runtime_error &err) {
2752 errors_cummulative += err.what();
2753 errors_cummulative += "\n";
2754 }
2755
2756 unlock();
2757
2758 if (! errors_cummulative.empty())
2759 throw Slic3r::RuntimeError(errors_cummulative);
2760
2761 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" finished, load user preset %1% , type %2%, errors_cummulative %3%")%canonical_name %Preset::get_type_string(m_type) %errors_cummulative;
2762 return (need_update)?false:true;
2763}
#define BBL_JSON_KEY_USER_ID
Definition Preset.hpp:70
#define BBL_JSON_KEY_SETTING_ID
Definition Preset.hpp:68
std::vector< ConfigSubstitution > ConfigSubstitutions
Definition Config.hpp:269
@ UserCloud
Definition Preset.hpp:540

References Slic3r::ConfigBase::apply(), Slic3r::ConfigBase::apply_only(), BBL_JSON_KEY_BASE_ID, BBL_JSON_KEY_FILAMENT_ID, BBL_JSON_KEY_INHERITS, BBL_JSON_KEY_SETTING_ID, BBL_JSON_KEY_USER_ID, BBL_JSON_KEY_VERSION, Slic3r::PresetOrigin::bundle_id, canonical_preset_name(), Slic3r::ConfigOption::clone(), Slic3r::Preset::config, count, default_preset(), default_preset_for(), Slic3r::extend_default_config_length(), Slic3r::Preset::filament_id, find_preset2(), find_preset_internal(), Slic3r::Preset::get_extruder_names_and_keysets(), Slic3r::Preset::get_type_string(), Slic3r::ConfigOptionResolver::has(), Slic3r::DynamicConfig::keys(), Slic3r::ConfigBase::load_string_map(), lock(), m_edited_preset, m_errors, m_idx_selected, m_presets, m_type, name(), Slic3r::Preset::normalize(), Slic3r::Preset::normalize_inherits(), Slic3r::ConfigBase::option(), ORCA_JSON_KEY_UPDATE_TIME, Slic3r::Semver::parse(), preset(), Slic3r::Preset::remove_invalid_keys(), set_custom_preset_alias(), Slic3r::DynamicConfig::set_key_value(), Slic3r::Preset::setting_id, Slic3r::ConfigOptionVector< T >::size(), Slic3r::Preset::TYPE_FILAMENT, unlock(), Slic3r::DynamicPrintConfig::update_diff_values_to_child_config(), Slic3r::PresetConfigSubstitutions::UserCloud, and Slic3r::ConfigOptionSingle< T >::value.

Referenced by Slic3r::PresetBundle::load_user_presets(), and Slic3r::PresetBundle::update_subscribed_presets().

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

◆ lock()

void Slic3r::PresetCollection::lock ( )
inlineinherited

◆ merge_presets()

std::vector< std::vector< std::string > > Slic3r::PresetCollection::merge_presets ( const std::vector< PresetCollection * > & others,
const VendorMap & new_vendors )
protectedinherited
4230{
4231 auto less = [this](const Preset &a, const Preset &b) {
4232 return m_type == Preset::TYPE_FILAMENT ? filament_preset_less(a, b) : a < b;
4233 };
4234 struct Incoming { Preset *preset; size_t source; };
4235 auto incoming_less = [&less](const Incoming &a, const Incoming &b) { return less(*a.preset, *b.preset); };
4236 // Each of `others` is sorted, so its presets form one sorted run.
4237 std::vector<Incoming> incoming;
4238 std::vector<size_t> run_ends { 0 };
4239 for (size_t source = 0; source < others.size(); ++ source) {
4240 for (Preset &preset : others[source]->m_presets)
4241 if (! preset.is_default && ! preset.is_external)
4242 incoming.push_back({ &preset, source });
4243 assert(std::is_sorted(incoming.begin() + run_ends.back(), incoming.end(), incoming_less));
4244 run_ends.push_back(incoming.size());
4245 }
4246 // Merged pairwise and stably, so equal names stay in the order of `others`.
4247 const size_t runs = others.size();
4248 for (size_t width = 1; width < runs; width *= 2)
4249 for (size_t i = 0; i + width < runs; i += 2 * width)
4250 std::inplace_merge(incoming.begin() + run_ends[i], incoming.begin() + run_ends[i + width],
4251 incoming.begin() + run_ends[std::min(i + 2 * width, runs)], incoming_less);
4252
4253 std::vector<std::vector<std::string>> duplicates(others.size());
4254 std::deque<Preset> merged;
4255 auto own = m_presets.begin() + m_num_default_presets;
4256 std::move(m_presets.begin(), own, std::back_inserter(merged));
4257 // On equal names this collection's preset is kept, else the earliest of `others`,
4258 // and each repeat is listed under the collection it came from.
4259 for (auto next = incoming.begin(); own != m_presets.end() || next != incoming.end();) {
4260 if (next == incoming.end() || (own != m_presets.end() && ! less(*next->preset, *own)))
4261 merged.emplace_back(std::move(*own ++));
4262 else {
4263 Preset &preset = *(next ++)->preset;
4264 if (preset.vendor != nullptr) {
4265 // Re-assign a pointer to the vendor structure in the new PresetBundle.
4266 auto it = new_vendors.find(preset.vendor->id);
4267 assert(it != new_vendors.end());
4268 preset.vendor = &it->second;
4269 }
4270 merged.emplace_back(std::move(preset));
4271 }
4272 for (; next != incoming.end() && next->preset->name == merged.back().name; ++ next)
4273 duplicates[next->source].emplace_back(next->preset->name);
4274 }
4275 m_presets = std::move(merged);
4276 return duplicates;
4277}
static bool filament_preset_less(const Preset &a, const Preset &b)
Definition Preset.hpp:1014
coord_t width(const BoundingBox &box)
Definition Arrange.cpp:1184

References filament_preset_less(), m_num_default_presets, m_presets, m_type, preset(), and Slic3r::Preset::TYPE_FILAMENT.

Here is the call graph for this function:

◆ name()

std::string Slic3r::PresetCollection::name ( ) const
inherited
4439{
4440 switch (this->type()) {
4443 //case Preset::TYPE_SLA_PRINT: return L("SLA print");
4444 //case Preset::TYPE_SLA_MATERIAL: return L("SLA material");
4446 default: return "invalid";
4447 }
4448}
#define L(s)
Definition ExtrusionEntity.cpp:25
#define PRESET_PRINTER_NAME
Definition Preset.hpp:35
#define PRESET_PRINT_NAME
Definition Preset.hpp:34
#define PRESET_FILAMENT_NAME
Definition Preset.hpp:33

References L, PRESET_FILAMENT_NAME, PRESET_PRINT_NAME, PRESET_PRINTER_NAME, type(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, and Slic3r::Preset::TYPE_PRINTER.

Referenced by PresetCollection(), append_preset(), canonical_preset_name(), delete_preset(), find_preset(), find_preset(), find_preset2(), find_preset2(), find_preset_internal(), find_preset_internal(), find_preset_renamed(), find_preset_renamed(), first_visible_idx(), legacy_user_filament_presets(), load_external_preset(), load_preset(), load_preset(), load_presets(), load_project_embedded_presets(), load_user_preset(), need_sync(), select_preset_by_name(), select_preset_by_name_strict(), and set_sync_info_and_save().

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

◆ need_sync()

bool Slic3r::PresetCollection::need_sync ( std::string name,
std::string setting_id,
long long update_time )
inherited
2423{
2424 lock();
2425 auto preset = find_preset(name, false, true);
2426 bool need = preset == nullptr || preset->setting_id != setting_id || preset->updated_time < update_time;
2427 unlock();
2428 return need;
2429}

References find_preset(), lock(), name(), preset(), and unlock().

Here is the call graph for this function:

◆ num_default_presets()

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

References m_num_default_presets.

◆ num_visible()

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

References m_presets, and preset().

Here is the call graph for this function:

◆ only_default_printers()

bool Slic3r::PrinterPresetCollection::only_default_printers ( ) const
4536{
4537 for (const auto& printer : get_presets()) {
4538 if (!boost::starts_with(printer.name,"Default") && printer.is_visible)
4539 return false;
4540 }
4541 return true;
4542}
const std::deque< Preset > & get_presets() const
Definition Preset.hpp:781

References Slic3r::PresetCollection::get_presets().

Referenced by Slic3r::GUI::GuideFrame::run().

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
605{ return m_presets; }

References m_presets.

◆ operator=()

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

References PrinterPresetCollection().

Here is the call graph for this function:

◆ path_for_preset()

std::string Slic3r::PresetCollection::path_for_preset ( const Preset & preset) const
inherited
4495{
4497}
std::string path_from_name(const std::string &new_name, bool detach=false) const
Definition Preset.cpp:4483
bool is_base_preset(const Preset &preset) const
Definition Preset.hpp:917
std::string get_preset_bare_name(const std::string &canonical_name)
Definition Preset.cpp:172

References Slic3r::get_preset_bare_name(), is_base_preset(), path_from_name(), and preset().

Referenced by add_detached_preset(), clone_presets(), load_external_preset(), save_current_preset(), and save_user_presets().

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

◆ path_from_name()

std::string Slic3r::PresetCollection::path_from_name ( const std::string & new_name,
bool detach = false ) const
inherited
4484{
4485 //BBS: change to json format
4486 //std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini");
4487 std::string file_name = boost::iends_with(new_name, ".json") ? new_name : (new_name + ".json");
4488 if (detach)
4489 return (boost::filesystem::path(m_dir_path) / "base" / file_name).make_preferred().string();
4490 else
4491 return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
4492}

References m_dir_path.

Referenced by Slic3r::PresetBundle::import_json_presets(), and path_for_preset().

Here is the caller graph for this function:

◆ preset() [1/2]

const Preset & Slic3r::PresetCollection::preset ( size_t idx) const
inlineinherited
794{ return const_cast<PresetCollection*>(this)->preset(idx); }

References PresetCollection(), and preset().

Referenced by preset().

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

◆ preset() [2/2]

Preset & Slic3r::PresetCollection::preset ( size_t idx,
bool real = false )
inlineinherited
790 {
791 if (real) return m_presets[idx];
792 return (idx == m_idx_selected) ? m_edited_preset : m_presets[idx];
793 }

References m_edited_preset, m_idx_selected, and m_presets.

Referenced by PresetCollection(), add_detached_preset(), append_preset(), check_and_fix_syncinfo(), clone_presets(), clone_presets_for_filament(), clone_presets_for_printer(), commit_user_preset(), Slic3r::GUI::Tab::compatible_widget_create(), delete_preset(), diameters_of_selected_printer(), filament_id_by_type(), Slic3r::PrinterPresetCollection::find_custom_preset_by_model_and_variant(), find_preset(), find_preset2(), Slic3r::PrinterPresetCollection::find_system_preset_by_model_and_variant(), first_compatible(), first_compatible(), first_compatible(), first_visible(), first_visible(), Slic3r::GUI::SyncAmsInfoDialog::generate_override_fix_ams_list(), get_differed_values_to_update(), get_filament_presets(), get_preset_alias(), get_preset_differed_for_save(), get_preset_parent(), get_preset_with_vendor_profile(), get_project_embedded_presets(), get_selected_preset_parent(), get_user_presets(), is_alias_exist(), is_base_preset(), legacy_user_filament_presets(), load_external_preset(), load_preset(), load_project_embedded_presets(), load_user_preset(), merge_presets(), need_sync(), num_visible(), path_for_preset(), reset(), Slic3r::GUI::SelectMachineDialog::reset_and_sync_ams_list(), Slic3r::GUI::SyncAmsInfoDialog::reset_and_sync_ams_list(), resolve_user_preset(), save_current_preset(), save_user_presets(), select_preset(), set_custom_preset_alias(), set_printer_hold_alias(), set_sync_info_and_save(), Slic3r::GUI::SendMultiMachinePage::sync_ams_list(), system_preset_names(), update_library_profile_excluded_from(), update_map_alias_to_profile_name(), update_map_system_profile_renamed(), and update_vendor_ptrs_after_copy().

◆ reset()

void Slic3r::PresetCollection::reset ( bool delete_files)
inherited
1765{
1766 //BBS: add lock logic for sync preset in background
1767 lock();
1768 if (m_presets.size() > m_num_default_presets) {
1769 if (delete_files) {
1770 // Erase the preset files.
1771 for (Preset &preset : m_presets)
1772 if (! preset.is_default && ! preset.is_external && ! preset.is_system) {
1773 //BBS remove idx and ini files
1774 preset.remove_files();
1775 }
1776 }
1777 // Don't use m_presets.resize() here as it requires a default constructor for Preset.
1778 m_presets.erase(m_presets.begin() + m_num_default_presets, m_presets.end());
1779 this->select_preset(0);
1780 }
1781 //BBS: add lock logic for sync preset in background
1782 unlock();
1785}

References lock(), m_map_alias_to_profile_name, m_map_system_profile_renamed, m_num_default_presets, m_presets, preset(), select_preset(), and unlock().

Here is the call graph for this function:

◆ reset_project_embedded_presets()

bool Slic3r::PresetCollection::reset_project_embedded_presets ( )
inherited
2356{
2357 std::deque<Preset>::iterator it = m_presets.begin();
2358 bool re_select = false;
2359 int count = -1;
2360
2361 lock();
2362 while ( it!=m_presets.end() )
2363 {
2364 count++;
2365 //if (preset.type != Preset::get_type_from_string(type)) continue;
2366 if (it->is_project_embedded) {
2367 BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" type %1% , delete preset %2%")%Preset::get_type_string(m_type) % it->name;
2368 if ((!re_select) && (m_idx_selected == count))
2369 re_select = true;
2370 if (m_idx_selected > count) {
2372 count--;
2373 }
2374 it = m_presets.erase(it);
2375 }
2376 else
2377 it++;
2378 }
2379
2380 if (re_select)
2381 m_idx_selected = -1;
2382
2383 unlock();
2384
2385 return re_select;
2386}

References count, Slic3r::Preset::get_type_string(), lock(), m_idx_selected, m_presets, m_type, and unlock().

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

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

◆ resolve_user_preset()

PresetCollection::UserPresetLoad Slic3r::PresetCollection::resolve_user_preset ( const boost::filesystem::path & file,
const std::string & canonical_name,
const PresetOrigin & load_origin,
ForwardCompatibilitySubstitutionRule substitution_rule,
const std::string & extruder_id_name,
const std::string & extruder_variant_name,
std::set< std::string > * key_set1,
std::set< std::string > * key_set2,
bool read_only ) const
privateinherited
1830{
1831 UserPresetLoad out;
1832 out.preset = Preset(m_type, canonical_name, false);
1833 Preset &preset = out.preset;
1834 preset.bundle_id = load_origin.bundle_id;
1835 preset.file = file.string();
1836 // Before either file is parsed, so a save that lands during the parse still shows
1837 // up as a difference when commit compares.
1838 out.on_disk = PresetFilesOnDisk::read(file);
1839 // Load the preset file, apply preset values on top of defaults.
1840 try {
1841 fs::path idx_path(preset.file);
1842 idx_path.replace_extension(".info");
1843 if (fs::exists(idx_path)) {
1844 out.info_file = idx_path.string();
1845 preset.load_info(out.info_file);
1846 }
1847 DynamicPrintConfig config;
1848 //BBS: change to json format
1849 //ConfigSubstitutions config_substitutions = config.load_from_ini(preset.file, substitution_rule);
1850 std::map<std::string, std::string> key_values;
1851 std::string reason;
1852 ConfigSubstitutions config_substitutions = config.load_from_json(preset.file, substitution_rule, key_values, reason);
1853 if (! config_substitutions.empty())
1854 out.substitutions.push_back({ preset.name, m_type, PresetConfigSubstitutions::Source::UserFile, preset.file, std::move(config_substitutions) });
1855 if (!reason.empty()) {
1856 out.discard_file = true;
1857 out.errors.push_back((boost::format("parse config %1% failed") % preset.file).str());
1858 return out;
1859 }
1860
1861 std::string version_str = key_values[BBL_JSON_KEY_VERSION];
1862 boost::optional<Semver> version = Semver::parse(version_str);
1863 if (!version) {
1864 out.errors.push_back((boost::format("invalid version %1% in config %2%") % version_str % preset.file).str());
1865 return out;
1866 }
1867 preset.version = *version;
1868
1869 if (key_values.find(BBL_JSON_KEY_FILAMENT_ID) != key_values.end())
1870 preset.filament_id = key_values[BBL_JSON_KEY_FILAMENT_ID];
1871 if (key_values.find(BBL_JSON_KEY_DESCRIPTION) != key_values.end())
1872 preset.description = key_values[BBL_JSON_KEY_DESCRIPTION];
1873 if (key_values.find(BBL_JSON_KEY_INSTANTIATION) != key_values.end())
1874 preset.is_visible = key_values[BBL_JSON_KEY_INSTANTIATION] != "false";
1875
1876 //Orca: find and use the inherit config as the base
1877 const Preset* inherit_preset = nullptr;
1878 ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS);
1879
1880 // check inherits_config
1881 if (inherits_config) {
1882 ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
1883 std::string inherits_value = option_str->value;
1884 // Orca: try to find if the parent preset has been renamed
1885 inherit_preset = this->find_preset2(inherits_value);
1886 Preset::normalize_inherits(config, inherit_preset);
1887 }
1888 // Local hot reload only supports FFF; no SLA default printer is installed.
1889 if (read_only && load_origin.kind == PresetOrigin::Kind::LocalBundle && m_type == Preset::TYPE_PRINTER &&
1890 Preset::printer_technology(config) != ptFFF) {
1891 out.errors.push_back((boost::format("local bundle printer %1% is not FFF") % preset.file).str());
1892 return out;
1893 }
1894 const Preset& default_preset = this->default_preset_for(config);
1895 if (inherit_preset) {
1896 preset.config = inherit_preset->config;
1897 preset.filament_id = inherit_preset->filament_id;
1898 extend_default_config_length(config, false, {});
1899 preset.config.update_diff_values_to_child_config(config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2);
1900 }
1901 else {
1902 auto inherits_config2 = dynamic_cast<ConfigOptionString *>(inherits_config);
1903 if ((inherits_config2 && !inherits_config2->value.empty())) {
1904 out.errors.push_back((boost::format("can not find parent %1% for config %2%!") % inherits_config2->value % preset.file).str());
1905 return out;
1906 }
1907 // We support custom root preset now
1908 // Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
1909 preset.config = default_preset.config;
1910 preset.config.apply(std::move(config));
1912 }
1913
1914 Preset::normalize(preset.config);
1915 // Report configuration fields, which are misplaced into a wrong group.
1916 std::string incorrect_keys = Preset::remove_invalid_keys(preset.config, default_preset.config);
1917 if (!incorrect_keys.empty())
1918 out.errors.push_back("Error in a preset file: The preset \"" + preset.file +
1919 "\" contains the following incorrect keys: " + incorrect_keys + ", which were removed");
1920
1921 if (preset.type == Preset::TYPE_FILAMENT && preset.is_user() && preset.inherits().empty()) {
1922 auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers", true));
1923 if (compatible_printers && compatible_printers->values.empty()) {
1924 size_t at_pos = canonical_name.find('@');
1925 if (at_pos != std::string::npos && at_pos + 1 < canonical_name.length()) {
1926 compatible_printers->values.push_back(canonical_name.substr(at_pos + 1));
1927 out.save_compatible_printers = true;
1928 }
1929 }
1930 }
1931
1932 preset.loaded = true;
1933 out.complete = true;
1934 } catch (const std::ifstream::failure &err) {
1935 out.discard_file = true;
1936 out.errors.push_back((boost::format("The user-config cannot be loaded: %1%. Reason: %2%") % preset.file % err.what()).str());
1937 //throw Slic3r::RuntimeError(std::string("The selected preset cannot be loaded: ") + preset.file + "\n\tReason: " + err.what());
1938 } catch (const std::runtime_error &err) {
1939 out.discard_file = true;
1940 out.errors.push_back((boost::format("Failed loading the user-config file: %1%. Reason: %2%") % preset.file % err.what()).str());
1941 //throw Slic3r::RuntimeError(std::string("Failed loading the preset file: ") + preset.file + "\n\tReason: " + err.what());
1942 }
1943 out.install = true;
1944 return out;
1945}
#define BBL_JSON_KEY_DESCRIPTION
Definition Preset.hpp:59
#define BBL_JSON_KEY_INSTANTIATION
Definition Preset.hpp:77
Preset preset
Definition Preset.hpp:974
PrinterTechnology printer_technology() const
Definition Preset.hpp:399
static PresetFilesOnDisk read(const boost::filesystem::path &file)
Definition Preset.cpp:1809
@ UserFile
Definition Preset.hpp:537
@ LocalBundle
Definition Preset.hpp:495

References BBL_JSON_KEY_DESCRIPTION, BBL_JSON_KEY_FILAMENT_ID, BBL_JSON_KEY_INHERITS, BBL_JSON_KEY_INSTANTIATION, BBL_JSON_KEY_VERSION, Slic3r::PresetOrigin::bundle_id, Slic3r::PresetCollection::UserPresetLoad::complete, Slic3r::Preset::config, default_preset(), default_preset_for(), Slic3r::PresetCollection::UserPresetLoad::discard_file, Slic3r::PresetCollection::UserPresetLoad::errors, Slic3r::extend_default_config_length(), Slic3r::Preset::filament_id, find_preset2(), Slic3r::PresetCollection::UserPresetLoad::info_file, Slic3r::PresetCollection::UserPresetLoad::install, Slic3r::PresetOrigin::kind, Slic3r::ConfigBase::load_from_json(), Slic3r::PresetOrigin::LocalBundle, m_type, Slic3r::Preset::normalize(), Slic3r::Preset::normalize_inherits(), Slic3r::PresetCollection::UserPresetLoad::on_disk, Slic3r::ConfigBase::option(), Slic3r::Semver::parse(), Slic3r::Preset, preset(), Slic3r::PresetCollection::UserPresetLoad::preset, Slic3r::Preset::printer_technology(), Slic3r::ptFFF, Slic3r::PresetCollection::PresetFilesOnDisk::read(), Slic3r::Preset::remove_invalid_keys(), Slic3r::PresetCollection::UserPresetLoad::save_compatible_printers, Slic3r::PresetCollection::UserPresetLoad::substitutions, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINTER, Slic3r::PresetConfigSubstitutions::UserFile, and Slic3r::ConfigOptionSingle< T >::value.

Here is the call graph for this function:

◆ save_current_preset()

void Slic3r::PresetCollection::save_current_preset ( const std::string & new_name,
bool detach = false,
bool save_to_project = false,
Preset * _curr_preset = nullptr )
inherited
3349{
3350 Preset curr_preset = _curr_preset ? *_curr_preset : m_edited_preset;
3351 //BBS: add lock logic for sync preset in background
3352 std::string final_inherits;
3353 lock();
3354 // 1) Find the preset with a new_name or create a new one,
3355 // initialize it with the edited config.
3356 auto it = this->find_preset_internal(new_name);
3357 const bool preset_existed = (it != m_presets.end() && it->name == new_name);
3358 if (it != m_presets.end() && it->name == new_name) {
3359 // Preset with the same name found.
3360 Preset &preset = *it;
3361 //BBS: add project embedded preset logic
3362 if (!preset.can_overwrite()) {
3363 //if (preset.is_default || preset.is_external || preset.is_system)
3364 // Cannot overwrite the default preset.
3365 //BBS: add lock logic for sync preset in background
3366 unlock();
3367 return;
3368 }
3369 // Overwriting an existing preset.
3370 preset.config = std::move(curr_preset.config);
3371 // The newly saved preset will be activated -> make it visible.
3372 preset.is_visible = true;
3373 //TODO: remove the detach logic
3374 if (detach) {
3375 // Clear the link to the parent profile.
3376 preset.vendor = nullptr;
3377 preset.inherits().clear();
3378 preset.alias.clear();
3379 preset.renamed_from.clear();
3380 preset.m_excluded_from.clear();
3381 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": save preset %1% , with detach")%new_name;
3382 }
3383 //BBS: add lock logic for sync preset in background
3384
3386 preset.config.option<ConfigOptionString>("print_settings_id", true)->value = new_name;
3387 else if (m_type == Preset::TYPE_FILAMENT)
3388 preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
3389 else if (m_type == Preset::TYPE_PRINTER)
3390 preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
3391 final_inherits = preset.inherits();
3392 unlock();
3393 // TODO: apply change from custom root to devided presets.
3394 if (preset.inherits().empty()) {
3395 for (auto &preset2 : m_presets)
3396 if (preset2.inherits() == preset.name)
3397 preset2.reload(preset);
3398 }
3399 } else {
3400 // Creating a new preset.
3401 Preset &preset = *m_presets.insert(it, curr_preset);
3402 std::string &inherits = preset.inherits();
3403 std::string old_name = preset.name;
3404 preset.name = new_name;
3405 preset.vendor = nullptr;
3406 preset.alias.clear();
3407 preset.renamed_from.clear();
3408 preset.m_excluded_from.clear();
3409 preset.setting_id.clear();
3410 if (detach) {
3411 // Clear the link to the parent profile.
3412 inherits.clear();
3413 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": save preset %1% , with detach")%new_name;
3414 } else if (is_base_preset(preset)) {
3415 inherits = old_name;
3416 }
3417
3418 preset.is_default = false;
3419 preset.is_system = false;
3420 preset.is_external = false;
3421
3422 preset.bundle_id.clear();
3423
3424 preset.file = this->path_for_preset(preset);
3425 // The newly saved preset will be activated -> make it visible.
3426 preset.is_visible = true;
3427 // Just system presets have aliases
3428 preset.alias.clear();
3429 //BBS: add project embedded preset logic
3430 if (save_to_project) {
3431 preset.is_project_embedded = true;
3432 }
3433 else
3434 preset.is_project_embedded = false;
3436 preset.config.option<ConfigOptionString>("print_settings_id", true)->value = new_name;
3437 else if (m_type == Preset::TYPE_FILAMENT)
3438 preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
3439 else if (m_type == Preset::TYPE_PRINTER)
3440 preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
3441 //BBS: add lock logic for sync preset in background
3442 final_inherits = inherits;
3443 unlock();
3444 }
3445 // 2) Activate the saved preset.
3446 this->select_preset_by_name(new_name, true);
3447 // 2) Store the active preset to disk.
3448 //BBS: only save difference for user preset
3449 Preset* parent_preset = nullptr;
3450 if (!final_inherits.empty()) {
3451 parent_preset = this->find_preset2(final_inherits, true);
3452 if (parent_preset) {
3453 // Orca: take the saved diff against the resolved parent (renamed / library-matched).
3454 Preset::normalize_inherits(this->get_selected_preset().config, parent_preset);
3455 if (this->get_selected_preset().base_id.empty()) {
3456 this->get_selected_preset().base_id = parent_preset->setting_id;
3457 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " base_id: " << parent_preset->setting_id;
3458 }
3459 }
3460 }
3461 if (parent_preset)
3462 this->get_selected_preset().save(&(parent_preset->config));
3463 else
3464 this->get_selected_preset().save(nullptr);
3465
3466 {
3467 LifecycleEventContext ctx;
3468 ctx.name = new_name;
3469 ctx.msg = preset_existed ? "overwrite" : "new";
3470 ctx.code = LifecycleEvtCode::Ok;
3472 }
3473}
std::string base_id
Definition Preset.hpp:328
bool save(DynamicPrintConfig *parent_config)
Definition Preset.cpp:754
@ PresetSaved
Definition LifecycleEvents.hpp:48
@ Ok
Definition LifecycleEvents.hpp:68
void fire_lifecycle_event(LifecycleEvent event, const LifecycleEventContext &ctx)
Definition LifecycleEvents.hpp:234

References Slic3r::Preset::base_id, Slic3r::LifecycleEventContext::code, Slic3r::Preset::config, find_preset2(), find_preset_internal(), Slic3r::fire_lifecycle_event(), get_selected_preset(), is_base_preset(), lock(), m_edited_preset, m_presets, m_type, Slic3r::LifecycleEventContext::msg, Slic3r::LifecycleEventContext::name, Slic3r::Preset::normalize_inherits(), Slic3r::Ok, path_for_preset(), preset(), Slic3r::PresetSaved, Slic3r::Preset::save(), select_preset_by_name(), Slic3r::Preset::setting_id, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, and unlock().

Referenced by Slic3r::GUI::CreatePrinterPresetDialog::create_page2_dialog_buttons(), generate_custom_presets(), Slic3r::PresetBundle::save_changes_for_preset(), Slic3r::GUI::CalibrationWizard::save_preset(), and Slic3r::GUI::CalibrationWizard::save_preset_with_index().

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

◆ save_user_presets()

void Slic3r::PresetCollection::save_user_presets ( const std::string & dir_path,
const std::string & type,
std::map< std::string, std::string > & need_to_delete_list )
inherited
2466{
2467 boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / type).make_preferred();
2468
2469 if (!fs::exists(dir))
2470 fs::create_directory(dir);
2471
2472 m_dir_path = dir.string();
2473
2474 std::vector<std::string> delete_name_list;
2475 //std::map<std::string, Preset*>::iterator it;
2476 //for (it = my_presets.begin(); it != my_presets.end(); it++) {
2477 for (auto it = m_presets.begin(); it != m_presets.end(); it++) {
2478 Preset* preset = &m_presets[it - m_presets.begin()];
2479 if (!preset->is_user()) continue;
2480 if (preset->sync_info != "save") continue;
2481 preset->sync_info.clear();
2482 preset->file = path_for_preset(*preset);
2483
2484 //BBS: only save difference for user preset
2485 std::string inherits = Preset::inherits(preset->config);
2486 if (inherits.empty()) {
2487 // We support custom root preset now
2488 //BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find inherits for %1% , should not happen")%preset->name;
2490 //preset->sync_info = "delete";
2491 //need_to_delete_list.push_back(preset->setting_id);
2492 //delete_name_list.push_back(preset->name);
2493 preset->save(nullptr);
2494 continue;
2495 }
2496 Preset* parent_preset = this->find_preset(inherits, false, true);
2497 if (!parent_preset) {
2498 ++m_errors;
2499 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" can not find parent preset for %1% , inherits %2%")%preset->name %inherits;
2500 continue;
2501 }
2502
2503 if (preset->base_id.empty())
2504 preset->base_id = parent_preset->setting_id;
2505 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << preset->name << " filament_id: " << preset->filament_id << " base_id: " << preset->base_id;
2506 preset->save(&(parent_preset->config));
2507 }
2508
2509 for (auto delete_name: delete_name_list)
2510 {
2511 this->delete_preset(delete_name);
2512 }
2513 delete_name_list.clear();
2514
2515 return;
2516}
bool delete_preset(const std::string &name, bool force=false)
Definition Preset.cpp:3578

References Slic3r::Preset::config, delete_preset(), find_preset(), Slic3r::Preset::inherits(), m_dir_path, m_errors, m_presets, path_for_preset(), preset(), Slic3r::Preset::setting_id, and type().

Referenced by generate_custom_presets().

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
897 { return is_dirty(&this->get_edited_preset(), &m_saved_preset); }

References get_edited_preset(), is_dirty(), and m_saved_preset.

Here is the call graph for this function:

◆ section_name()

std::string Slic3r::PresetCollection::section_name ( ) const
inherited
4452{
4453 switch (this->type()) {
4456 //case Preset::TYPE_SLA_PRINT: return PRESET_SLA_PRINT_NAME;
4457 //case Preset::TYPE_SLA_MATERIAL: return PRESET_SLA_MATERIALS_NAME;
4459 default: return "invalid";
4460 }
4461}

References PRESET_FILAMENT_NAME, PRESET_PRINT_NAME, PRESET_PRINTER_NAME, type(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, and Slic3r::Preset::TYPE_PRINTER.

Here is the call graph for this function:

◆ select_preset()

Preset & Slic3r::PresetCollection::select_preset ( size_t idx)
inherited
4142{
4143 //BBS: add config related logs
4144 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% try to select preset %2%")%Preset::get_type_string(m_type) %idx;
4145 for (Preset &preset : m_presets)
4146 preset.is_dirty = false;
4147 if (idx >= m_presets.size())
4148 idx = first_visible_idx();
4149 m_idx_selected = idx;
4152 bool default_visible = ! m_default_suppressed || m_idx_selected < m_num_default_presets;
4153 for (size_t i = 0; i < m_num_default_presets; ++i)
4154 m_presets[i].is_visible = default_visible;
4155
4156 //set this preset to true
4157 if (!m_presets[idx].is_visible) {
4158 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% set %2%, idx %3% to visible") % Preset::get_type_string(m_type) % m_presets[idx].name % idx;
4159 m_presets[idx].is_visible = true;
4160 }
4161 //BBS: add config related logs
4162 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1% select success, m_idx_selected %2%, name %3%, is_system %4%, is_default %5%")%Preset::get_type_string(m_type) % m_idx_selected % m_edited_preset.name % m_edited_preset.is_system % m_edited_preset.is_default;
4163 return m_presets[idx];
4164}

References first_visible_idx(), Slic3r::Preset::get_type_string(), m_default_suppressed, m_edited_preset, m_idx_selected, m_num_default_presets, m_presets, m_type, preset(), and update_saved_preset_from_current_preset().

Referenced by delete_current_preset(), get_selected_preset(), load_external_preset(), Slic3r::PresetBundle::reload_local_bundle(), reset(), select_preset_by_name(), select_preset_by_name_strict(), and 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
4167{
4168 //BBS: add config related logs
4169 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%, force %3%")%Preset::get_type_string(m_type) %name_w_suffix %force;
4170 std::string name = Preset::remove_suffix_modified(name_w_suffix);
4171 const std::string normalized_name = this->canonical_preset_name(name);
4172 // 1) Try to find the preset by its name.
4173 auto it = this->find_preset_internal(normalized_name);
4174 size_t idx = 0;
4175 if (it != m_presets.end() && it->name == normalized_name && it->is_visible)
4176 // Preset found by its name and it is visible.
4177 idx = it - m_presets.begin();
4178 else {
4179 // Find the first visible preset.
4180 for (size_t i = m_default_suppressed ? m_num_default_presets : 0; i < m_presets.size(); ++ i)
4181 if (m_presets[i].is_visible) {
4182 idx = i;
4183 break;
4184 }
4185 // If the first visible preset was not found, return the 0th element, which is the default preset.
4186 }
4187
4188 // 2) Select the new preset.
4189 if (m_idx_selected != idx || force) {
4190 this->select_preset(idx);
4191 //BBS: add config related logs
4192 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name_w_suffix;
4193 return true;
4194 }
4195
4196 //BBS: add config related logs
4197 if (m_idx_selected == idx)
4198 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, already selected before") % Preset::get_type_string(m_type);
4199 else
4200 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name_w_suffix;
4201 return false;
4202}
static std::string remove_suffix_modified(const std::string &name)
Definition Preset.cpp:516

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

Referenced by clone_presets(), Slic3r::GUI::ExportConfigsDialog::data_init(), Slic3r::GUI::ExportPresetBundleDialog::InitExportData(), load_preset(), Slic3r::GUI::CreatePrinterPresetDialog::load_system_and_user_presets_with_curr_model(), Slic3r::PresetBundle::reload_local_bundle(), Slic3r::GUI::GUI_App::reload_settings(), Slic3r::PresetBundle::restore_selection(), save_current_preset(), Slic3r::GUI::Tab::select_preset(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::select_printer_default_presets(), anonymous_namespace{OrcaSlicer_profile_validator.cpp}::slice_all_printers(), update_after_user_presets_loaded(), 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
4205{
4206 //BBS: add config related logs
4207 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, try to select by name %2%")%Preset::get_type_string(m_type) %name;
4208 const std::string canonical_name = this->canonical_preset_name(name);
4209 // 1) Try to find the preset by its name.
4210 auto it = this->find_preset_internal(canonical_name);
4211
4212 size_t idx = (size_t)-1;
4213 if (it != m_presets.end() && it->name == canonical_name && it->is_visible)
4214 // Preset found by its name.
4215 idx = it - m_presets.begin();
4216 // 2) Select the new preset.
4217 if (idx != (size_t)-1) {
4218 this->select_preset(idx);
4219 //BBS: add config related logs
4220 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, success")%Preset::get_type_string(m_type) %name;
4221 return true;
4222 }
4223 m_idx_selected = idx;
4224 //BBS: add config related logs
4225 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": %1%, select %2%, failed")%Preset::get_type_string(m_type) %name;
4226 return false;
4227}

References canonical_preset_name(), find_preset_internal(), Slic3r::Preset::get_type_string(), m_idx_selected, m_presets, m_type, name(), and select_preset().

Here is the call graph for this function:

◆ set_custom_preset_alias()

void Slic3r::PresetCollection::set_custom_preset_alias ( Preset & preset)
protectedinherited
4351{
4352 // For filaments, remove the postfix
4353 // For printers, there is nothing to remove
4354 // For prints AKA processes, the postfix should be kept
4355 // Alias should be set here, as the preset name may be augmented further later (i.e., prefixing relative path for bundles)
4356 std::string bare_preset_name = get_preset_bare_name(preset.name);
4357 std::string alias_name = bare_preset_name;
4358
4359 const bool is_root_filament_preset =
4361 preset.config.has(BBL_JSON_KEY_INHERITS) &&
4362 preset.config.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS)->value.empty();
4363 if (is_root_filament_preset) {
4364 const size_t suffix_separator_pos = bare_preset_name.find_first_of("@");
4365 if (suffix_separator_pos != std::string::npos) {
4366 alias_name = bare_preset_name.substr(0, suffix_separator_pos);
4367 boost::trim_right(alias_name);
4368 if (alias_name.empty())
4369 alias_name = bare_preset_name;
4370 }
4371 }
4372
4373 preset.alias = std::move(alias_name);
4374 m_map_alias_to_profile_name[preset.alias].push_back(preset.name);
4376}

References BBL_JSON_KEY_INHERITS, Slic3r::ConfigOptionString::empty(), Slic3r::get_preset_bare_name(), m_map_alias_to_profile_name, m_type, preset(), set_printer_hold_alias(), and Slic3r::Preset::TYPE_FILAMENT.

Referenced by clone_presets(), commit_user_preset(), get_preset_alias(), Slic3r::PresetBundle::import_json_presets(), and load_user_preset().

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
3892{
3893 if (m_default_suppressed != default_suppressed) {
3894 m_default_suppressed = default_suppressed;
3895 bool default_visible = ! default_suppressed || m_idx_selected < m_num_default_presets;
3896 for (size_t i = 0; i < m_num_default_presets; ++ i)
3897 m_presets[i].is_visible = default_visible;
3898 }
3899}

References m_default_suppressed, m_idx_selected, m_num_default_presets, and m_presets.

◆ set_printer_hold_alias()

void Slic3r::PresetCollection::set_printer_hold_alias ( const std::string & alias,
Preset & preset,
bool remove = false )
inherited
4399{
4400 auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset.config.option("compatible_printers"));
4401 if (compatible_printers == nullptr) return;
4402 for (const std::string &printer_name : compatible_printers->values) {
4403 auto printer_iter = m_printer_hold_alias.find(printer_name);
4404 bool insert_success = false, remove_success = false;
4405 if (m_printer_hold_alias.end() == printer_iter) {
4406 if (!remove) {
4407 insert_success = true;
4408 m_printer_hold_alias[printer_name].insert(alias);
4409 }
4410 } else {
4411 auto &printer_filament_alias = m_printer_hold_alias[printer_name];
4412 auto alias_iter = printer_filament_alias.find(alias);
4413 if (printer_filament_alias.end() == alias_iter) {
4414 if (!remove) {
4415 insert_success = true;
4416 printer_filament_alias.insert(alias);
4417 }
4418 } else {
4419 if (remove) {
4420 if (preset.inherits() == "") {
4421 remove_success = true;
4422 printer_filament_alias.erase(alias);
4423 }
4424 if (auto alias_iter = m_map_alias_to_profile_name.find(alias); alias_iter != m_map_alias_to_profile_name.end()) {
4425 auto& presets = alias_iter->second;
4426 auto new_end = std::remove(presets.begin(), presets.end(), preset.name);
4427 presets.erase(new_end, presets.end());
4428 if (presets.empty()) { m_map_alias_to_profile_name.erase(alias); }
4429 }
4430 }
4431 }
4432 }
4433 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << " preset name : " << preset.name << " remove action: " << remove << " insert success: "
4434 << insert_success << " remove success: " << remove_success << " alias: " << alias;
4435 }
4436}

References m_map_alias_to_profile_name, m_printer_hold_alias, and preset().

Referenced by delete_preset(), and set_custom_preset_alias().

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

◆ set_sync_func()

void Slic3r::PresetCollection::set_sync_func ( SyncFunc func)
inlineinherited
593{ sync_func = func; }
SyncFunc sync_func
Definition Preset.hpp:592

References sync_func.

◆ set_sync_info_and_save()

void Slic3r::PresetCollection::set_sync_info_and_save ( std::string name,
std::string setting_id,
std::string syncinfo,
long long update_time,
const std::string & user_id )
inherited
2389{
2390 lock();
2391 const std::string canonical_name = this->canonical_preset_name(name);
2392 for (auto it = m_presets.begin(); it != m_presets.end(); it++) {
2393 Preset* preset = &m_presets[it - m_presets.begin()];
2394 if (preset->name == canonical_name) {
2395 if (syncinfo.empty())
2396 preset->sync_info.clear();
2397 else
2398 preset->sync_info = syncinfo;
2399 if (get_preset_base(*preset) == preset) {
2400 for (auto & preset2 : m_presets)
2401 if (preset2.inherits() == preset->name) {
2402 preset2.base_id = setting_id;
2403 preset2.save_info();
2404 }
2405 }
2406 if (!setting_id.empty())
2407 preset->setting_id = setting_id;
2408 if (!user_id.empty())
2409 preset->user_id = user_id;
2410 if (update_time > 0)
2411 preset->updated_time = update_time;
2412 if (preset->sync_info == "update")
2413 preset->save(nullptr);
2414 else
2415 preset->save_info();
2416 break;
2417 }
2418 }
2419 unlock();
2420}

References canonical_preset_name(), get_preset_base(), lock(), m_presets, name(), preset(), and unlock().

Here is the call graph for this function:

◆ size()

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

References m_presets.

Referenced by Slic3r::GUI::Tab::compatible_widget_create(), generate_custom_presets(), Slic3r::GUI::NewCalibrationHistoryDialog::get_all_filaments(), Slic3r::GUI::AMSMaterialsSetting::Popup(), Slic3r::PresetBundle::reload_local_bundle(), and Slic3r::GUI::ExtrusionCalibration::update_combobox_filaments().

Here is the caller graph for this function:

◆ sort_presets()

void Slic3r::PresetCollection::sort_presets ( )
inlineprivateinherited
1027 {
1030 else
1031 std::sort(m_presets.begin() + m_num_default_presets, m_presets.end());
1032 }

References filament_preset_less(), m_num_default_presets, m_presets, m_type, and Slic3r::Preset::TYPE_FILAMENT.

Referenced by load_project_embedded_presets(), Slic3r::PresetBundle::reload_local_bundle(), and update_after_user_presets_loaded().

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

◆ system_preset_names()

std::vector< std::string > Slic3r::PresetCollection::system_preset_names ( ) const
inherited
4466{
4467 size_t num = 0;
4468 for (const Preset &preset : m_presets)
4469 if (preset.is_system)
4470 ++ num;
4471 std::vector<std::string> out;
4472 out.reserve(num);
4473 for (const Preset &preset : m_presets)
4474 if (preset.is_system) {
4475 out.emplace_back(preset.name);
4476 out.insert(out.end(), preset.renamed_from.begin(), preset.renamed_from.end());
4477 }
4478 std::sort(out.begin(), out.end());
4479 return out;
4480}

References m_presets, and preset().

Here is the call graph for this function:

◆ type()

◆ unlock()

void Slic3r::PresetCollection::unlock ( )
inlineinherited

◆ update_after_user_presets_loaded()

void Slic3r::PresetCollection::update_after_user_presets_loaded ( )
inherited
2767{
2768 lock();
2769 std::string selected_name = get_selected_preset_name();
2770 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", before sort, type %1%, selected_idx %2%, selected_name %3%") %m_type %m_idx_selected %selected_name;
2771 sort_presets();
2772 this->select_preset_by_name(selected_name, false);
2773 unlock();
2774 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", after sort, type %1%, selected_idx %2%") %m_type %m_idx_selected;
2775
2776 return;
2777}
std::string get_selected_preset_name() const
Definition Preset.hpp:741

References get_selected_preset_name(), lock(), m_idx_selected, m_type, select_preset_by_name(), sort_presets(), and unlock().

Here is the call graph for this function:

◆ update_compatible() [1/2]

void Slic3r::PresetCollection::update_compatible ( const PresetWithVendorProfile & active_printer,
const PresetWithVendorProfile * active_print,
PresetSelectCompatibleType select_other_if_incompatible )
inlineinherited
881 { 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:872

References 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
873 {
874 if (this->update_compatible_internal(active_printer, active_print, select_other_if_incompatible) == (size_t)-1) {
875 // Find some other compatible preset, or the "-- default --" preset.
876 size_t index = this->first_compatible_idx(prefered_condition);
877 this->select_preset(index);
878 }
879 }
size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible)
Definition Preset.cpp:3901

References first_compatible_idx(), select_preset(), and update_compatible_internal().

Referenced by 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
3902{
3903 DynamicPrintConfig config;
3904 config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
3905 const ConfigOption *opt = active_printer.preset.config.option("nozzle_diameter");
3906 if (opt)
3907 config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
3908 int some_compatible = 0;
3909
3910 if (active_print)
3911 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": active printer %1%, print %2%, unselect_if_incompatible %3%")%active_printer.preset.name %active_print->preset.name % (int)unselect_if_incompatible;
3912 else
3913 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": active printer %1%, unselect_if_incompatible %2%")%active_printer.preset.name % (int)unselect_if_incompatible;
3914 for (size_t idx_preset = m_num_default_presets; idx_preset < m_presets.size(); ++ idx_preset) {
3915 bool selected = idx_preset == m_idx_selected;
3916 Preset &preset_selected = m_presets[idx_preset];
3917 Preset &preset_edited = selected ? m_edited_preset : preset_selected;
3918
3919 const PresetWithVendorProfile this_preset_with_vendor_profile = this->get_preset_with_vendor_profile(preset_edited);
3920 bool was_compatible = preset_edited.is_compatible;
3921 preset_edited.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer, &config);
3922 if (preset_edited.is_compatible)
3923 some_compatible++;
3924 if (active_print != nullptr)
3925 preset_edited.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer);
3926 if (! preset_edited.is_compatible && selected &&
3927 (unselect_if_incompatible == PresetSelectCompatibleType::Always || (unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible && was_compatible)))
3928 {
3929 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": type %1% , previous selected %2% becomes uncompatible, will select later")%Preset::get_type_string(m_type) %m_idx_selected;
3930 m_idx_selected = size_t(-1);
3931 }
3932 if (selected)
3933 preset_selected.is_compatible = preset_edited.is_compatible;
3934 }
3935 // 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.
3937 {
3938 for (size_t i = 0; i < m_num_default_presets; ++ i)
3939 {
3940 m_presets[i].is_visible = (some_compatible == 0);
3941 }
3942 }
3943
3944 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": type %1% returned m_idx_selected %2%, some_compatible %3%")%Preset::get_type_string(m_type) %m_idx_selected %some_compatible;
3945 return m_idx_selected;
3946}
size_t size() const override
Definition Config.hpp:722
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config)
Definition Preset.cpp:909
bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer)
Definition Preset.cpp:871
ConfigOptionFloatsTempl< false > ConfigOptionFloats
Definition Config.hpp:1015
@ OnlyIfWasCompatible
Definition Preset.hpp:525

References Slic3r::Always, Slic3r::Preset::config, Slic3r::ConfigOptionString, get_preset_with_vendor_profile(), Slic3r::Preset::get_type_string(), Slic3r::Preset::is_compatible, Slic3r::is_compatible_with_print(), Slic3r::is_compatible_with_printer(), m_default_suppressed, m_edited_preset, m_idx_selected, m_num_default_presets, m_presets, m_type, Slic3r::Preset::name, Slic3r::OnlyIfWasCompatible, Slic3r::ConfigBase::option(), Slic3r::PresetWithVendorProfile::preset, and Slic3r::DynamicConfig::set_key_value().

Referenced by 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
3951{
3952 bool was_dirty = this->get_selected_preset().is_dirty;
3953 bool is_dirty = current_is_dirty();
3956
3957 return was_dirty != is_dirty;
3958}
bool current_is_dirty() const
Definition Preset.hpp:886
bool is_dirty
Definition Preset.hpp:276

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

Referenced by load_external_preset(), Slic3r::PresetBundle::reload_local_bundle(), and Slic3r::PresetBundle::restore_selection().

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

◆ update_library_profile_excluded_from()

void Slic3r::PresetCollection::update_library_profile_excluded_from ( )
protectedinherited
4302{
4303 // Orca: Collect all filament presets that has empty compatible_printers and belongs to the Orca Filament Library.
4304 std::map<std::string, std::set<std::string>*> excluded_froms;
4305 for (Preset& preset : m_presets) {
4306 if (preset.vendor != nullptr && preset.vendor->name == PresetBundle::ORCA_FILAMENT_LIBRARY) {
4307 // check if the preset has empty compatible_printers
4308 const auto* compatible_printers = dynamic_cast<const ConfigOptionStrings*>(preset.config.option("compatible_printers"));
4309 if (compatible_printers == nullptr || compatible_printers->values.empty())
4310 excluded_froms[preset.alias] = &preset.m_excluded_from;
4311 }
4312 }
4313
4314 // Check all presets that has the same alias as the filament presets with empty compatible_printers in Orca Filament Library.
4315 // A printer specific profile supersedes the generic one, no matter whether it lives in a vendor bundle or in the
4316 // library itself.
4317 for (const Preset& preset : m_presets) {
4318 if (preset.vendor == nullptr)
4319 continue;
4320
4321 const auto* compatible_printers = dynamic_cast<const ConfigOptionStrings*>(preset.config.option("compatible_printers"));
4322 // Profiles with empty compatible_printers are the generic ones, they never supersede anything.
4323 if (compatible_printers == nullptr || compatible_printers->values.empty())
4324 continue;
4325 auto itr = excluded_froms.find(preset.alias);
4326 if (itr != excluded_froms.end()) {
4327 // Add the printer models to the excluded_from list.
4328 for (const std::string& printer_name : compatible_printers->values) {
4329 itr->second->insert(printer_name);
4330 }
4331 }
4332 }
4333}

References m_presets, Slic3r::PresetBundle::ORCA_FILAMENT_LIBRARY, and preset().

Here is the call graph for this function:

◆ update_map_alias_to_profile_name()

void Slic3r::PresetCollection::update_map_alias_to_profile_name ( )
protectedinherited
4292{
4294 for (const Preset &preset : m_presets) {
4295 m_map_alias_to_profile_name[preset.alias].push_back(preset.name);
4296 }
4297 // now m_map_alias_to_profile_name is map, not need sort
4298 //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; });
4299}

References m_map_alias_to_profile_name, m_presets, and preset().

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

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
4336{
4338 for (Preset &preset : m_presets)
4339 for (const std::string &renamed_from : preset.renamed_from) {
4340 const auto [it, success] = m_map_system_profile_renamed.insert(std::pair<std::string, std::string>(renamed_from, preset.name));
4341 if (!success) {
4342 ++m_errors;
4343 BOOST_LOG_TRIVIAL(error) << boost::format("Preset name \"%1%\" was marked as renamed from \"%2%\", though preset name "
4344 "\"%3%\" was marked as renamed from \"%2%\" as well.") %
4345 preset.name % renamed_from % it->second;
4346 }
4347 }
4348}

References m_errors, m_map_system_profile_renamed, m_presets, and preset().

Here is the call graph for this function:

◆ update_saved_preset_from_current_preset()

void Slic3r::PresetCollection::update_saved_preset_from_current_preset ( )
inlineinherited

References m_edited_preset, and m_saved_preset.

Referenced by PresetCollection(), load_external_preset(), and select_preset().

Here is the caller graph for this function:

◆ update_user_presets_directory()

void Slic3r::PresetCollection::update_user_presets_directory ( const std::string & dir_path,
const std::string & type )
inherited
2455{
2456 boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / type).make_preferred();
2457
2458 if (!fs::exists(dir))
2459 fs::create_directory(dir);
2460
2461 m_dir_path = dir.string();
2462}

References m_dir_path, and type().

Here is the call graph for this function:

◆ update_vendor_ptrs_after_copy()

void Slic3r::PresetCollection::update_vendor_ptrs_after_copy ( const VendorMap & vendors)
protectedinherited
4280{
4281 for (Preset &preset : m_presets)
4282 if (preset.vendor != nullptr) {
4283 assert(! preset.is_default && ! preset.is_external);
4284 // Re-assign a pointer to the vendor structure in the new PresetBundle.
4285 auto it = new_vendors.find(preset.vendor->id);
4286 assert(it != new_vendors.end());
4287 preset.vendor = &it->second;
4288 }
4289}

References m_presets, and preset().

Here is the call graph for this function:

◆ validate_preset()

bool Slic3r::PresetCollection::validate_preset ( const std::string & name,
std::string & inherit )
inherited
2893{
2894 // Presets that came from system vendors, the built-in defaults, or any loaded bundle (local or
2895 // subscribed) are trusted — their g-code isn't user-authored, so the 3MF importer should not
2896 // warn about them.
2897 auto is_trusted = [](const Preset &p) { return p.is_system || p.is_default || p.is_from_bundle(); };
2898
2899 const std::string canonical_name = this->canonical_preset_name(preset_name);
2900 std::deque<Preset>::iterator it = this->find_preset_internal(canonical_name);
2901 bool found = (it != m_presets.end()) && (it->name == canonical_name) && is_trusted(*it);
2902 if (!found) {
2903 it = this->find_preset_renamed(canonical_name);
2904 found = it != m_presets.end() && is_trusted(*it);
2905 }
2906 if (!found) {
2907 if (!inherit_name.empty()) {
2908 const std::string canonical_inherit_name = this->canonical_preset_name(inherit_name);
2909 it = this->find_preset_internal(canonical_inherit_name);
2910 found = it != m_presets.end() && it->name == canonical_inherit_name && is_trusted(*it);
2911 if (!found) {
2912 it = this->find_preset_renamed(canonical_inherit_name);
2913 found = it != m_presets.end() && is_trusted(*it);
2914 }
2915 if (found)
2916 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, found inherit in list")%preset_name %inherit_name;
2917 else
2918 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, inherit_name %2%, can not found preset and inherit in list")%preset_name %inherit_name;
2919 }
2920 else {
2921 //inherit is null , should not happen , just consider it as valid
2922 found = false;
2923 BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": preset_name %1%, no inherit, set to not found")%preset_name;
2924 }
2925 }
2926 else {
2927 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": preset_name %1%, found in list")%preset_name;
2928 }
2929
2930 return found;
2931}

References canonical_preset_name(), find_preset_internal(), find_preset_renamed(), and m_presets.

Here is the call graph for this function:

◆ write_legacy_user_filament_preset()

bool Slic3r::PresetCollection::write_legacy_user_filament_preset ( const LegacyUserFilamentPreset & legacy)
staticinherited
2835{
2836 // Only compatible_printers changes in the file. Saving the whole preset would also rewrite an inherits that
2837 // names a renamed parent by its old name, the only name older releases know it by.
2838 try {
2839 json j = read_user_preset_file(legacy.file);
2840 // Changed by hand or by another instance since the preset was found: a list of its own stands, and
2841 // another parent would need other printers.
2842 if (j.contains("compatible_printers") || j.value(BBL_JSON_KEY_INHERITS, std::string()) != legacy.inherits)
2843 return false;
2844 j["compatible_printers"] = legacy.compatible_printers;
2845 if (const std::error_code ec = write_file_atomically(legacy.file, j.dump(1, '\t') + "\n")) {
2846 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed to save " << legacy.file << ": " << ec.message();
2847 return false;
2848 }
2849 } catch (const std::exception &err) {
2850 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": can not migrate " << legacy.file << ": " << err.what();
2851 return false;
2852 }
2853 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": user preset " << legacy.preset << " gets " << legacy.printers.size()
2854 << " printer(s) its parent listed in an older release";
2855 return true;
2856}
std::error_code write_file_atomically(const std::string &path, std::initializer_list< std::string_view > chunks, bool binary)
Definition utils.cpp:796

References BBL_JSON_KEY_INHERITS, Slic3r::LegacyUserFilamentPreset::compatible_printers, Slic3r::LegacyUserFilamentPreset::file, Slic3r::LegacyUserFilamentPreset::inherits, Slic3r::LegacyUserFilamentPreset::preset, Slic3r::LegacyUserFilamentPreset::printers, Slic3r::read_user_preset_file(), and Slic3r::write_file_atomically().

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

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

◆ PresetBundle

friend class PresetBundle
friend

References PresetBundle.

Referenced by PresetBundle.

Member Data Documentation

◆ m_default_suppressed

◆ m_dir_path

◆ m_edited_preset

◆ m_errors

◆ m_idx_selected

◆ m_map_alias_to_profile_name

std::map<std::string, std::vector<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_mutex

std::recursive_mutex Slic3r::PresetCollection::m_mutex
privateinherited

Referenced by lock(), and unlock().

◆ m_num_default_presets

◆ m_presets

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

Referenced by PresetCollection(), add_default_preset(), add_detached_preset(), append_preset(), apply_legacy_user_filament_presets(), begin(), begin(), cbegin(), cend(), clone_presets(), default_preset(), default_preset(), delete_current_preset(), delete_preset(), diameters_of_selected_printer(), discard_current_changes(), end(), end(), erase(), find_preset(), find_preset_internal(), find_preset_renamed(), first_compatible_idx(), first_visible_idx(), first_visible_idx_by_type(), get_filament_presets(), get_preset_name_by_alias(), get_presets(), get_project_embedded_presets(), get_selected_preset(), get_selected_preset(), get_selected_preset_base(), get_selected_preset_name(), get_user_presets(), has_defaults_only(), lbegin(), legacy_user_filament_presets(), load_external_preset(), load_preset(), load_project_embedded_presets(), load_user_preset(), merge_presets(), num_visible(), operator()(), operator=(), preset(), Slic3r::PresetBundle::reload_local_bundle(), reset(), reset_project_embedded_presets(), Slic3r::PresetBundle::restore_selection(), save_current_preset(), save_user_presets(), select_preset(), select_preset_by_name(), select_preset_by_name_strict(), Slic3r::PresetBundle::selection(), set_default_suppressed(), set_sync_info_and_save(), size(), sort_presets(), system_preset_names(), update_compatible_internal(), update_library_profile_excluded_from(), update_map_alias_to_profile_name(), update_map_system_profile_renamed(), update_vendor_ptrs_after_copy(), and validate_preset().

◆ m_printer_hold_alias

std::unordered_map<std::string, std::unordered_set<std::string> > Slic3r::PresetCollection::m_printer_hold_alias
privateinherited

◆ m_saved_preset

◆ m_type

◆ sync_func

SyncFunc Slic3r::PresetCollection::sync_func { nullptr }
inherited
592{ nullptr };

Referenced by set_sync_func().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Preset.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libslic3r/Preset.cpp