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

#include <src/libslic3r/Preset.hpp>

+ Collaboration diagram for Slic3r::ExtruderFilaments:

Public Types

typedef std::deque< Filament >::iterator Iterator
 
typedef std::deque< Filament >::const_iterator ConstIterator
 

Public Member Functions

 ExtruderFilaments (PresetCollection *filaments_collection, size_t extruder_id=0, std::string selected_name=std::string())
 
Iterator begin ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
Iterator end ()
 
ConstIterator end () const
 
ConstIterator cend () const
 
bool empty () const
 
const std::deque< Filament > & operator() () const
 
Filamentfilament (size_t idx)
 
const Filamentfilament (size_t idx) const
 
bool select_filament (const std::string &name, bool force=false)
 
void select_filament (size_t idx)
 
std::string get_selected_preset_name () const
 
const Presetget_selected_preset () const
 
const Filamentget_selected_filament () const
 
size_t get_selected_idx () const
 
 ExtruderFilaments ()=default
 
ExtruderFilamentsoperator= (const ExtruderFilaments &other)=default
 

Private Member Functions

std::deque< Filament >::iterator find_filament_internal (const std::string &name)
 
std::deque< Filament >::const_iterator find_filament_internal (const std::string &name) const
 
void cache_selected_name ()
 
std::string get_cached_selected_name () const
 
template<typename PreferedCondition >
size_t first_compatible_idx (PreferedCondition prefered_condition) const
 
size_t first_compatible_idx () const
 
template<typename PreferedCondition >
const Presetfirst_compatible (PreferedCondition prefered_condition)
 
const Presetfirst_compatible ()
 
const std::string & get_preset_name_by_alias (const std::string &alias) const
 
size_t update_compatible_internal (const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible)
 
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)
 

Private Attributes

PresetCollectionm_filaments { nullptr }
 
size_t m_idx_selected { size_t(-1) }
 
std::deque< Filamentm_extr_filaments
 
size_t m_extruder_id
 
std::string m_cached_selected_name { std::string() }
 

Friends

class PresetBundle
 

Detailed Description

Member Typedef Documentation

◆ ConstIterator

typedef std::deque<Filament>::const_iterator Slic3r::ExtruderFilaments::ConstIterator

◆ Iterator

typedef std::deque<Filament>::iterator Slic3r::ExtruderFilaments::Iterator

Constructor & Destructor Documentation

◆ ExtruderFilaments() [1/2]

Slic3r::ExtruderFilaments::ExtruderFilaments ( PresetCollection filaments_collection,
size_t  extruder_id = 0,
std::string  selected_name = std::string() 
)
2108: m_filaments (filaments_collection)
2109, m_extruder_id(extruder_id)
2110{
2111 const std::deque<Preset>& presets = m_filaments->get_presets();
2112 for (size_t id = 0; id < presets.size(); id ++)
2113 m_extr_filaments.emplace_back(&(presets[id]));
2114
2115 select_filament(selected_name.empty() ? m_filaments->get_selected_preset_name() : selected_name);
2116}
std::deque< Filament > m_extr_filaments
Definition Preset.hpp:855
size_t m_extruder_id
Definition Preset.hpp:857
PresetCollection * m_filaments
Definition Preset.hpp:851
bool select_filament(const std::string &name, bool force=false)
Definition Preset.cpp:2133
const std::deque< Preset > & get_presets() const
Definition Preset.hpp:393
std::string get_selected_preset_name() const
Definition Preset.hpp:369

References Slic3r::PresetCollection::get_presets(), Slic3r::PresetCollection::get_selected_preset_name(), m_extr_filaments, m_filaments, and select_filament().

+ Here is the call graph for this function:

◆ ExtruderFilaments() [2/2]

Slic3r::ExtruderFilaments::ExtruderFilaments ( )
default

Member Function Documentation

◆ begin() [1/2]

Iterator Slic3r::ExtruderFilaments::begin ( )
inline
866{ return m_extr_filaments.begin(); }

References m_extr_filaments.

◆ begin() [2/2]

ConstIterator Slic3r::ExtruderFilaments::begin ( ) const
inline
867{ return m_extr_filaments.cbegin(); }

References m_extr_filaments.

◆ cache_selected_name()

void Slic3r::ExtruderFilaments::cache_selected_name ( )
inlineprivate
std::string m_cached_selected_name
Definition Preset.hpp:859
std::string get_selected_preset_name() const
Definition Preset.hpp:886

References get_selected_preset_name(), and m_cached_selected_name.

+ Here is the call graph for this function:

◆ cbegin()

ConstIterator Slic3r::ExtruderFilaments::cbegin ( ) const
inline
868{ return m_extr_filaments.cbegin(); }

References m_extr_filaments.

◆ cend()

ConstIterator Slic3r::ExtruderFilaments::cend ( ) const
inline
871{ return m_extr_filaments.cend(); }

References m_extr_filaments.

◆ empty()

bool Slic3r::ExtruderFilaments::empty ( ) const
inline
873{ return m_extr_filaments.empty(); }

References m_extr_filaments.

◆ end() [1/2]

Iterator Slic3r::ExtruderFilaments::end ( )
inline
869{ return m_extr_filaments.end(); }

References m_extr_filaments.

◆ end() [2/2]

ConstIterator Slic3r::ExtruderFilaments::end ( ) const
inline
870{ return m_extr_filaments.cend(); }

References m_extr_filaments.

◆ filament() [1/2]

Filament & Slic3r::ExtruderFilaments::filament ( size_t  idx)
inline
878{ return m_extr_filaments[idx]; }

References m_extr_filaments.

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

+ Here is the caller graph for this function:

◆ filament() [2/2]

const Filament & Slic3r::ExtruderFilaments::filament ( size_t  idx) const
inline
879{ return const_cast<ExtruderFilaments*>(this)->filament(idx); }
Filament & filament(size_t idx)
Definition Preset.hpp:878

References filament().

Referenced by filament().

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

◆ find_filament_internal() [1/2]

std::deque< Filament >::iterator Slic3r::ExtruderFilaments::find_filament_internal ( const std::string &  name)
inlineprivate
902 {
903 return Slic3r::lower_bound_by_predicate(m_extr_filaments.begin(), m_extr_filaments.end(), [&name](const auto& l) {
904 return l.preset->name < name;
905 });
906 }
ForwardIt lower_bound_by_predicate(ForwardIt first, ForwardIt last, LowerThanKeyPredicate lower_than_key)
Definition libslic3r.h:203

References Slic3r::lower_bound_by_predicate(), and m_extr_filaments.

Referenced by find_filament_internal(), get_preset_name_by_alias(), and select_filament().

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

◆ find_filament_internal() [2/2]

std::deque< Filament >::const_iterator Slic3r::ExtruderFilaments::find_filament_internal ( const std::string &  name) const
inlineprivate
908 {
909 return const_cast<ExtruderFilaments*>(this)->find_filament_internal(name);
910 }
std::deque< Filament >::iterator find_filament_internal(const std::string &name)
Definition Preset.hpp:901

References find_filament_internal().

+ Here is the call graph for this function:

◆ first_compatible() [1/2]

const Preset * Slic3r::ExtruderFilaments::first_compatible ( )
inlineprivate
948{ return m_extr_filaments[this->first_compatible_idx()].preset; }
size_t first_compatible_idx() const
Definition Preset.hpp:944

References first_compatible_idx(), and m_extr_filaments.

+ Here is the call graph for this function:

◆ first_compatible() [2/2]

template<typename PreferedCondition >
const Preset * Slic3r::ExtruderFilaments::first_compatible ( PreferedCondition  prefered_condition)
inlineprivate
947{ return m_extr_filaments[this->first_compatible_idx(prefered_condition)].preset;}

References first_compatible_idx(), and m_extr_filaments.

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

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

◆ first_compatible_idx() [1/2]

size_t Slic3r::ExtruderFilaments::first_compatible_idx ( ) const
inlineprivate
944{ return this->first_compatible_idx([](const /*Filament*/Preset&) -> int { return 0; }); }

References first_compatible_idx().

Referenced by 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::ExtruderFilaments::first_compatible_idx ( PreferedCondition  prefered_condition) const
inlineprivate
919 {
921 size_t n = m_extr_filaments.size();
922 size_t i_compatible = n;
923 int match_quality = -1;
924 for (; i < n; ++i)
925 // Since we use the filament selection from Wizard, it's needed to control the preset visibility too
926 if (m_extr_filaments[i].is_compatible && m_filaments->preset(i).is_visible) {
927 int this_match_quality = prefered_condition(*(m_extr_filaments[i].preset));
928 if (this_match_quality > match_quality) {
929 if (match_quality == std::numeric_limits<int>::max())
930 // Better match will not be found.
931 return i;
932 // Store the first compatible profile with highest match quality into i_compatible.
933 i_compatible = i;
934 match_quality = this_match_quality;
935 }
936 }
937 return (i_compatible == n) ?
938 // No compatible preset found, return the default preset.
939 0 :
940 // Compatible preset found.
941 i_compatible;
942 }
size_t num_default_presets() const
Definition Preset.hpp:511
Preset & preset(size_t idx, bool respect_active_preset=true)
Definition Preset.hpp:402
bool is_default_suppressed() const
Definition Preset.hpp:360
bool is_visible
Definition Preset.hpp:138

References Slic3r::PresetCollection::is_default_suppressed(), Slic3r::Preset::is_visible, m_extr_filaments, m_filaments, Slic3r::PresetCollection::num_default_presets(), and Slic3r::PresetCollection::preset().

+ Here is the call graph for this function:

◆ get_cached_selected_name()

std::string Slic3r::ExtruderFilaments::get_cached_selected_name ( ) const
inlineprivate
913{ return m_cached_selected_name; }

References m_cached_selected_name.

◆ get_preset_name_by_alias()

const std::string & Slic3r::ExtruderFilaments::get_preset_name_by_alias ( const std::string &  alias) const
private
2119{
2120 const auto& aliases_map = m_filaments->map_alias_to_profile_name();
2121 for (
2122 // Find the 1st profile name with the alias.
2123 auto it = Slic3r::lower_bound_by_predicate(aliases_map.begin(), aliases_map.end(), [&alias](auto& l) { return l.first < alias; });
2124 // Continue over all profile names with the same alias.
2125 it != aliases_map.end() && it->first == alias; ++it)
2126 if (auto it_filament = find_filament_internal(it->second);
2127 it_filament != m_extr_filaments.end() && it_filament->preset->name == it->second &&
2128 it_filament->preset->is_visible && (it_filament->is_compatible || size_t(it_filament - m_extr_filaments.begin()) == m_idx_selected))
2129 return it_filament->preset->name;
2130 return alias;
2131}
size_t m_idx_selected
Definition Preset.hpp:853
const std::vector< std::pair< std::string, std::string > > & map_alias_to_profile_name()
Definition Preset.hpp:571

References find_filament_internal(), Slic3r::lower_bound_by_predicate(), m_extr_filaments, m_filaments, m_idx_selected, and Slic3r::PresetCollection::map_alias_to_profile_name().

+ Here is the call graph for this function:

◆ get_selected_filament()

const Filament * Slic3r::ExtruderFilaments::get_selected_filament ( ) const
inline
888{ return m_idx_selected == size_t(-1) ? nullptr : &m_extr_filaments[m_idx_selected]; }

References m_extr_filaments, and m_idx_selected.

Referenced by Slic3r::GUI::PlaterPresetComboBox::update(), and Slic3r::PresetBundle::update_filaments_compatible().

+ Here is the caller graph for this function:

◆ get_selected_idx()

size_t Slic3r::ExtruderFilaments::get_selected_idx ( ) const
inline
889{ return m_idx_selected; }

References m_idx_selected.

Referenced by Slic3r::GUI::TabPresetComboBox::update().

+ Here is the caller graph for this function:

◆ get_selected_preset()

const Preset * Slic3r::ExtruderFilaments::get_selected_preset ( ) const
inline
887{ return m_idx_selected == size_t(-1) ? nullptr : m_extr_filaments[m_idx_selected].preset; }

References m_extr_filaments, and m_idx_selected.

Referenced by Slic3r::GUI::PlaterPresetComboBox::update().

+ Here is the caller graph for this function:

◆ get_selected_preset_name()

std::string Slic3r::ExtruderFilaments::get_selected_preset_name ( ) const
inline
886{ return m_idx_selected == size_t(-1) ? std::string() : m_extr_filaments[m_idx_selected].preset->name; }

References m_extr_filaments, and m_idx_selected.

Referenced by cache_selected_name(), and Slic3r::PresetBundle::update_filaments_compatible().

+ Here is the caller graph for this function:

◆ operator()()

const std::deque< Filament > & Slic3r::ExtruderFilaments::operator() ( ) const
inline
875{ return m_extr_filaments; }

References m_extr_filaments.

◆ operator=()

ExtruderFilaments & Slic3r::ExtruderFilaments::operator= ( const ExtruderFilaments other)
default

◆ select_filament() [1/2]

bool Slic3r::ExtruderFilaments::select_filament ( const std::string &  name,
bool  force = false 
)
2134{
2135 std::string name = Preset::remove_suffix_modified(name_w_suffix);
2136 // 1) Try to find the preset by its name.
2137 auto it = this->find_filament_internal(name);
2138 size_t idx = 0;
2139 if (it != m_extr_filaments.end() && it->preset->name == name && it->preset->is_visible)
2140 // Preset found by its name and it is visible.
2141 idx = it - m_extr_filaments.begin();
2142 else {
2143 // Find the first visible preset.
2144 for (size_t i = 0; i < m_extr_filaments.size(); ++i)
2145 if (m_extr_filaments[i].preset->is_visible/* && m_extr_filaments[i].is_compatible*/) {
2146 idx = i;
2147 break;
2148 }
2149 // If the first visible preset was not found, return the 0th element, which is the default preset.
2150 }
2151 // 2) Select the new preset.
2152 if (m_idx_selected != idx || force) {
2153 this->select_filament(idx);
2154 return true;
2155 }
2156
2157 return false;
2158}
static std::string remove_suffix_modified(const std::string &name)
Definition Preset.cpp:258

References find_filament_internal(), m_extr_filaments, m_idx_selected, Slic3r::Preset::remove_suffix_modified(), and select_filament().

Referenced by ExtruderFilaments(), select_filament(), update_compatible(), and Slic3r::PresetBundle::update_filaments_compatible().

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

◆ select_filament() [2/2]

void Slic3r::ExtruderFilaments::select_filament ( size_t  idx)
inline
884{ m_idx_selected = idx; }

References m_idx_selected.

◆ update_compatible() [1/2]

void Slic3r::ExtruderFilaments::update_compatible ( const PresetWithVendorProfile active_printer,
const PresetWithVendorProfile active_print,
PresetSelectCompatibleType  select_other_if_incompatible 
)
inlineprivate
963 {
964 this->update_compatible(active_printer, active_print, select_other_if_incompatible, [](const /*Filament*/Preset&) -> int { return 0; });
965 }
void update_compatible(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType select_other_if_incompatible, PreferedCondition prefered_condition)
Definition Preset.hpp:956

References update_compatible().

+ Here is the call graph for this function:

◆ update_compatible() [2/2]

template<typename PreferedCondition >
void Slic3r::ExtruderFilaments::update_compatible ( const PresetWithVendorProfile active_printer,
const PresetWithVendorProfile active_print,
PresetSelectCompatibleType  select_other_if_incompatible,
PreferedCondition  prefered_condition 
)
inlineprivate
957 {
958 if (this->update_compatible_internal(active_printer, active_print, select_other_if_incompatible) == (size_t)-1)
959 // Find some other compatible preset, or the "-- default --" preset.
960 this->select_filament(this->first_compatible_idx(prefered_condition));
961 }
size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible)
Definition Preset.cpp:2160

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

Referenced by update_compatible(), and Slic3r::PresetBundle::update_filaments_compatible().

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

◆ update_compatible_internal()

size_t Slic3r::ExtruderFilaments::update_compatible_internal ( const PresetWithVendorProfile active_printer,
const PresetWithVendorProfile active_print,
PresetSelectCompatibleType  unselect_if_incompatible 
)
private
2163{
2164 DynamicPrintConfig config;
2165 config.set_key_value("printer_preset", new ConfigOptionString(active_printer.preset.name));
2166 const ConfigOption* opt = active_printer.preset.config.option("nozzle_diameter");
2167 if (opt)
2168 config.set_key_value("num_extruders", new ConfigOptionInt((int)static_cast<const ConfigOptionFloats*>(opt)->values.size()));
2169 bool some_compatible = false;
2170
2171 // Adjust printer preset config to the first extruder from m_extruder_id
2172 Preset printer_preset_adjusted = active_printer.preset;
2173 if (m_extruder_id > 0 && !printer_preset_adjusted.config.opt_bool("single_extruder_multi_material")) {
2174 DynamicPrintConfig& active_printer_config = printer_preset_adjusted.config;
2175 for (const std::string& key : print_config_def.extruder_option_keys()) {
2176 if (key == "default_filament_profile")
2177 continue;// Ignore this field, because this parameter is not related to the extruder but to whole printer.
2178 auto* opt = active_printer_config.option(key, false);
2179 if (opt != nullptr && opt->is_vector())
2180 static_cast<ConfigOptionVectorBase*>(opt)->set_at(opt, 0, m_extruder_id);
2181 }
2182 }
2183 PresetWithVendorProfile active_printer_adjusted(printer_preset_adjusted, active_printer.vendor);
2184
2185 std::vector<size_t> indices_of_template_presets;
2186 indices_of_template_presets.reserve(m_extr_filaments.size());
2187
2188 size_t num_default_presets = m_filaments->num_default_presets();
2189 for (size_t idx_preset = num_default_presets; idx_preset < m_extr_filaments.size(); ++idx_preset) {
2190 const bool is_selected = idx_preset == m_idx_selected;
2191 const Preset* preset = m_extr_filaments[idx_preset].preset;
2192 Filament& extr_filament = m_extr_filaments[idx_preset];
2193
2194 const PresetWithVendorProfile this_preset_with_vendor_profile = m_filaments->get_preset_with_vendor_profile(*preset);
2195 bool was_compatible = extr_filament.is_compatible;
2196 extr_filament.is_compatible = is_compatible_with_printer(this_preset_with_vendor_profile, active_printer_adjusted, &config);
2197 some_compatible |= extr_filament.is_compatible;
2198 if (active_print != nullptr)
2199 extr_filament.is_compatible &= is_compatible_with_print(this_preset_with_vendor_profile, *active_print, active_printer_adjusted);
2200 if (!extr_filament.is_compatible && is_selected &&
2201 (unselect_if_incompatible == PresetSelectCompatibleType::Always || (unselect_if_incompatible == PresetSelectCompatibleType::OnlyIfWasCompatible && was_compatible)))
2202 m_idx_selected = size_t(-1);
2203 if (preset->vendor && preset->vendor->templates_profile) {
2204 if (preset->is_visible)
2205 indices_of_template_presets.push_back(idx_preset);
2206 else {
2207 extr_filament.is_compatible = false;
2208 if (is_selected)
2209 m_idx_selected = size_t(-1);
2210 }
2211 }
2212 }
2213
2214 // filter out template profiles where profile with same alias and compability exists
2215 if (!indices_of_template_presets.empty()) {
2216 for (size_t idx = num_default_presets; idx < m_extr_filaments.size(); ++idx) {
2217 const Filament& filament = m_extr_filaments[idx];
2218 const VendorProfile* vendor = filament.preset->vendor;
2219 if (vendor && !vendor->templates_profile && filament.is_compatible) {
2220 const std::string& preset_alias = filament.preset->alias;
2221 for (const auto& template_idx : indices_of_template_presets) {
2222 if (m_extr_filaments[template_idx].preset->alias == preset_alias) {
2223 m_extr_filaments[template_idx].is_compatible = false;
2224 // unselect selected template filament if there is non-template alias compatible
2225 if (template_idx == m_idx_selected && (unselect_if_incompatible != PresetSelectCompatibleType::Never))
2226 m_idx_selected = size_t(-1);
2227 break;
2228 }
2229 }
2230 }
2231 }
2232 }
2233
2234 return m_idx_selected;
2235}
bool is_compatible
Definition Preset.hpp:845
const Preset * preset
Definition Preset.hpp:844
PresetWithVendorProfile get_preset_with_vendor_profile(const Preset &preset) const
Definition Preset.cpp:1122
std::string alias
Definition Preset.hpp:162
const VendorProfile * vendor
Definition Preset.hpp:153
bool is_compatible_with_printer(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_printer, const DynamicPrintConfig *extra_config)
Definition Preset.cpp:361
const PrintConfigDef print_config_def
Definition PrintConfig.cpp:4288
bool is_compatible_with_print(const PresetWithVendorProfile &preset, const PresetWithVendorProfile &active_print, const PresetWithVendorProfile &active_printer)
Definition Preset.cpp:338
ConfigOptionFloatsTempl< false > ConfigOptionFloats
Definition Config.hpp:716

References Slic3r::Preset::alias, Slic3r::Always, Slic3r::Preset::config, Slic3r::PrintConfigDef::extruder_option_keys(), filament(), Slic3r::PresetCollection::get_preset_with_vendor_profile(), Slic3r::Filament::is_compatible, Slic3r::is_compatible_with_print(), Slic3r::is_compatible_with_printer(), Slic3r::ConfigOption::is_vector(), Slic3r::Preset::is_visible, m_extr_filaments, m_extruder_id, m_filaments, m_idx_selected, Slic3r::Preset::name, Slic3r::Never, Slic3r::PresetCollection::num_default_presets(), Slic3r::OnlyIfWasCompatible, Slic3r::ConfigBase::opt_bool(), Slic3r::ConfigBase::option(), Slic3r::PresetWithVendorProfile::preset, Slic3r::Filament::preset, Slic3r::print_config_def, Slic3r::ConfigOptionVectorBase::set_at(), Slic3r::DynamicConfig::set_key_value(), Slic3r::ConfigOptionVector< T >::size(), Slic3r::VendorProfile::templates_profile, Slic3r::PresetWithVendorProfile::vendor, and Slic3r::Preset::vendor.

Referenced by update_compatible().

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

Friends And Related Symbol Documentation

◆ PresetBundle

friend class PresetBundle
friend

Member Data Documentation

◆ m_cached_selected_name

std::string Slic3r::ExtruderFilaments::m_cached_selected_name { std::string() }
private

◆ m_extr_filaments

◆ m_extruder_id

size_t Slic3r::ExtruderFilaments::m_extruder_id
private

◆ m_filaments

PresetCollection* Slic3r::ExtruderFilaments::m_filaments { nullptr }
private

◆ m_idx_selected


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