Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
Slic3r::ConfigOptionVector< T > Class Template Referenceabstract

#include <src/libslic3r/Config.hpp>

+ Inheritance diagram for Slic3r::ConfigOptionVector< T >:
+ Collaboration diagram for Slic3r::ConfigOptionVector< T >:

Public Member Functions

 ConfigOptionVector ()
 
 ConfigOptionVector (size_t n, const T &value)
 
 ConfigOptionVector (std::initializer_list< T > il)
 
 ConfigOptionVector (const std::vector< T > &values)
 
 ConfigOptionVector (std::vector< T > &&values)
 
void set (const ConfigOption *rhs) override
 
void set (const std::vector< const ConfigOption * > &rhs) override
 
void set_at (const ConfigOption *rhs, size_t i, size_t j) override
 
const T & get_at (size_t i) const
 
T & get_at (size_t i)
 
void resize (size_t n, const ConfigOption *opt_default=nullptr) override
 
void clear () override
 
size_t size () const override
 
bool empty () const override
 
bool operator== (const ConfigOption &rhs) const override
 
bool operator== (const std::vector< T > &rhs) const throw ()
 
bool operator!= (const std::vector< T > &rhs) const throw ()
 
size_t hash () const override throw ()
 
bool overriden_by (const ConfigOption *rhs) const override
 
bool apply_override (const ConfigOption *rhs) override
 
virtual std::vector< std::string > vserialize () const =0
 
virtual bool is_nil (size_t idx) const =0
 
virtual bool is_nil () const
 
virtual ConfigOptionType type () const =0
 
virtual std::string serialize () const =0
 
virtual bool deserialize (const std::string &str, bool append=false)=0
 
virtual ConfigOptionclone () const =0
 
virtual int getInt () const
 
virtual double getFloat () const
 
virtual bool getBool () const
 
virtual void setInt (int)
 
bool operator!= (const ConfigOption &rhs) const
 
bool is_scalar () const
 
bool is_vector () const
 
virtual bool nullable () const
 

Public Attributes

std::vector< T > values
 

Protected Member Functions

ConfigOptionType scalar_type () const
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar)
 

Friends

class cereal::access
 

Detailed Description

template<class T>
class Slic3r::ConfigOptionVector< T >

Constructor & Destructor Documentation

◆ ConfigOptionVector() [1/5]

template<class T >
Slic3r::ConfigOptionVector< T >::ConfigOptionVector ( )
inline
377{}

◆ ConfigOptionVector() [2/5]

template<class T >
Slic3r::ConfigOptionVector< T >::ConfigOptionVector ( size_t  n,
const T &  value 
)
inlineexplicit
378: values(n, value) {}
std::vector< T > values
Definition Config.hpp:382

◆ ConfigOptionVector() [3/5]

template<class T >
Slic3r::ConfigOptionVector< T >::ConfigOptionVector ( std::initializer_list< T >  il)
inlineexplicit
379: values(std::move(il)) {}

◆ ConfigOptionVector() [4/5]

template<class T >
Slic3r::ConfigOptionVector< T >::ConfigOptionVector ( const std::vector< T > &  values)
inlineexplicit
380: values(values) {}

◆ ConfigOptionVector() [5/5]

template<class T >
Slic3r::ConfigOptionVector< T >::ConfigOptionVector ( std::vector< T > &&  values)
inlineexplicit
381: values(std::move(values)) {}

Member Function Documentation

◆ apply_override()

template<class T >
bool Slic3r::ConfigOptionVector< T >::apply_override ( const ConfigOption rhs)
inlineoverridevirtual

Reimplemented from Slic3r::ConfigOption.

515 {
516 if (this->nullable())
517 throw ConfigurationError("Cannot override a nullable ConfigOption.");
518 if (rhs->type() != this->type())
519 throw ConfigurationError("ConfigOptionVector.apply_override() applied to different types.");
520 auto rhs_vec = static_cast<const ConfigOptionVector<T>*>(rhs);
521 if (! rhs->nullable()) {
522 // Overridding a non-nullable object with another non-nullable object.
523 if (this->values != rhs_vec->values) {
524 this->values = rhs_vec->values;
525 return true;
526 }
527 return false;
528 }
529 size_t i = 0;
530 size_t cnt = std::min(this->size(), rhs_vec->size());
531 bool modified = false;
532 for (; i < cnt; ++ i)
533 if (! rhs_vec->is_nil(i) && this->values[i] != rhs_vec->values[i]) {
534 this->values[i] = rhs_vec->values[i];
535 modified = true;
536 }
537 for (; i < rhs_vec->size(); ++ i)
538 if (! rhs_vec->is_nil(i)) {
539 if (this->values.empty())
540 this->values.resize(i + 1);
541 else
542 this->values.resize(i + 1, this->values.front());
543 this->values[i] = rhs_vec->values[i];
544 modified = true;
545 }
546 return modified;
547 }
virtual bool nullable() const
Definition Config.hpp:280
size_t size() const override
Definition Config.hpp:471

References Slic3r::ConfigOption::nullable(), Slic3r::ConfigOptionVector< T >::size(), Slic3r::ConfigOption::type(), and Slic3r::ConfigOptionVector< T >::values.

+ Here is the call graph for this function:

◆ clear()

template<class T >
void Slic3r::ConfigOptionVector< T >::clear ( )
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

470{ this->values.clear(); }

Referenced by Slic3r::GUI::SubstitutionManager::delete_all(), Slic3r::PresetBundle::full_fff_config(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::PresetBundle::load_config_file_config_bundle(), and Slic3r::PhysicalPrinter::update_preset_names_in_config().

+ Here is the caller graph for this function:

◆ clone()

◆ deserialize()

◆ empty()

template<class T >
bool Slic3r::ConfigOptionVector< T >::empty ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

472{ return this->values.empty(); }

Referenced by Slic3r::GUI::TextCtrl::BUILD(), Slic3r::GUI::Tab::compatible_widget_reload(), Slic3r::GUI::get_string_value(), and Slic3r::GUI::SubstitutionManager::is_empty_substitutions().

+ Here is the caller graph for this function:

◆ get_at() [1/2]

template<class T >
T & Slic3r::ConfigOptionVector< T >::get_at ( size_t  i)
inline
442{ return const_cast<T&>(std::as_const(*this).get_at(i)); }

◆ get_at() [2/2]

template<class T >
const T & Slic3r::ConfigOptionVector< T >::get_at ( size_t  i) const
inline
437 {
438 assert(! this->values.empty());
439 return (i < this->values.size()) ? this->values[i] : this->values.front();
440 }

References Slic3r::ConfigOptionVector< T >::values.

Referenced by Slic3r::GUI::TextCtrl::BUILD(), Slic3r::GUI::get_string_value(), and Slic3r::OozePrevention::pre_toolchange().

+ Here is the caller graph for this function:

◆ getBool()

virtual bool Slic3r::ConfigOption::getBool ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::ConfigOptionBool.

272{ throw BadOptionTypeException("Calling ConfigOption::getBool on a non-boolean ConfigOption"); }

Referenced by Slic3r::client::MyContext::scalar_variable_to_expr().

+ Here is the caller graph for this function:

◆ getFloat()

virtual double Slic3r::ConfigOption::getFloat ( ) const
inlinevirtualinherited

Reimplemented in Slic3r::ConfigOptionFloat.

271{ throw BadOptionTypeException("Calling ConfigOption::getFloat on a non-float ConfigOption"); }

Referenced by Slic3r::GUI::TabSLAMaterial::build(), Slic3r::GUI::get_string_value(), Slic3r::client::MyContext::scalar_variable_to_expr(), and Slic3r::GUI::Sidebar::update_sliced_info_sizer().

+ Here is the caller graph for this function:

◆ getInt()

virtual int Slic3r::ConfigOption::getInt ( ) const
inlinevirtualinherited

◆ hash()

template<class T >
size_t Slic3r::ConfigOptionVector< T >::hash ( ) const
throw (
)
inlineoverridevirtual

Implements Slic3r::ConfigOption.

485 {
486 std::hash<T> hasher;
487 size_t seed = 0;
488 for (const auto &v : this->values)
489 boost::hash_combine(seed, hasher(v));
490 return seed;
491 }
Definition args.hpp:18

References Slic3r::ConfigOptionVector< T >::values.

◆ is_nil() [1/2]

virtual bool Slic3r::ConfigOption::is_nil ( ) const
inlinevirtualinherited

Reimplemented from Slic3r::ConfigOption.

282{ return false; }

◆ is_nil() [2/2]

virtual bool Slic3r::ConfigOptionVectorBase::is_nil ( size_t  idx) const
pure virtualinherited

◆ is_scalar()

bool Slic3r::ConfigOption::is_scalar ( ) const
inlineinherited
277{ return (int(this->type()) & int(coVectorType)) == 0; }
virtual ConfigOptionType type() const =0
@ coVectorType
Definition Config.hpp:161

References Slic3r::coVectorType, and Slic3r::ConfigOption::type().

Referenced by Slic3r::PresetBundle::full_fff_config(), Slic3r::client::MyContext::is_nil_test(), Slic3r::ConfigOption::is_vector(), Slic3r::client::MyContext::legacy_variable_expansion(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::client::MyContext::scalar_variable_assign_scalar(), Slic3r::client::MyContext::scalar_variable_to_expr(), Slic3r::client::MyContext::vector_variable_assign_array(), Slic3r::client::MyContext::vector_variable_assign_initializer_list(), and Slic3r::client::MyContext::vector_variable_new_from_array().

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

◆ is_vector()

◆ nullable()

virtual bool Slic3r::ConfigOption::nullable ( ) const
inlinevirtualinherited

◆ operator!=() [1/2]

bool Slic3r::ConfigOption::operator!= ( const ConfigOption rhs) const
inlineinherited
275{ return ! (*this == rhs); }

◆ operator!=() [2/2]

template<class T >
bool Slic3r::ConfigOptionVector< T >::operator!= ( const std::vector< T > &  rhs) const
throw (
)
inline
483{ return this->values != rhs; }

◆ operator==() [1/2]

template<class T >
bool Slic3r::ConfigOptionVector< T >::operator== ( const ConfigOption rhs) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

475 {
476 if (rhs.type() != this->type())
477 throw ConfigurationError("ConfigOptionVector: Comparing incompatible types");
478 assert(dynamic_cast<const ConfigOptionVector<T>*>(&rhs));
479 return this->values == static_cast<const ConfigOptionVector<T>*>(&rhs)->values;
480 }

References Slic3r::ConfigOption::type(), and Slic3r::ConfigOptionVector< T >::values.

+ Here is the call graph for this function:

◆ operator==() [2/2]

template<class T >
bool Slic3r::ConfigOptionVector< T >::operator== ( const std::vector< T > &  rhs) const
throw (
)
inline
482{ return this->values == rhs; }

◆ overriden_by()

template<class T >
bool Slic3r::ConfigOptionVector< T >::overriden_by ( const ConfigOption rhs) const
inlineoverridevirtual

Reimplemented from Slic3r::ConfigOption.

495 {
496 if (this->nullable())
497 throw ConfigurationError("Cannot override a nullable ConfigOption.");
498 if (rhs->type() != this->type())
499 throw ConfigurationError("ConfigOptionVector.overriden_by() applied to different types.");
500 auto rhs_vec = static_cast<const ConfigOptionVector<T>*>(rhs);
501 if (! rhs->nullable())
502 // Overridding a non-nullable object with another non-nullable object.
503 return this->values != rhs_vec->values;
504 size_t i = 0;
505 size_t cnt = std::min(this->size(), rhs_vec->size());
506 for (; i < cnt; ++ i)
507 if (! rhs_vec->is_nil(i) && this->values[i] != rhs_vec->values[i])
508 return true;
509 for (; i < rhs_vec->size(); ++ i)
510 if (! rhs_vec->is_nil(i))
511 return true;
512 return false;
513 }

References Slic3r::ConfigOption::nullable(), Slic3r::ConfigOptionVector< T >::size(), Slic3r::ConfigOption::type(), and Slic3r::ConfigOptionVector< T >::values.

+ Here is the call graph for this function:

◆ resize()

template<class T >
void Slic3r::ConfigOptionVector< T >::resize ( size_t  n,
const ConfigOption opt_default = nullptr 
)
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

447 {
448 assert(opt_default == nullptr || opt_default->is_vector());
449// assert(opt_default == nullptr || dynamic_cast<ConfigOptionVector<T>>(opt_default));
450 assert(! this->values.empty() || opt_default != nullptr);
451 if (n == 0)
452 this->values.clear();
453 else if (n < this->values.size())
454 this->values.erase(this->values.begin() + n, this->values.end());
455 else if (n > this->values.size()) {
456 if (this->values.empty()) {
457 if (opt_default == nullptr)
458 throw ConfigurationError("ConfigOptionVector::resize(): No default value provided.");
459 if (opt_default->type() != this->type())
460 throw ConfigurationError("ConfigOptionVector::resize(): Extending with an incompatible type.");
461 this->values.resize(n, static_cast<const ConfigOptionVector<T>*>(opt_default)->values.front());
462 } else {
463 // Resize by duplicating the last value.
464 this->values.resize(n, this->values./*back*/front());
465 }
466 }
467 }

References Slic3r::ConfigOptionVector< T >::values.

Referenced by Slic3r::Preset::normalize().

+ Here is the caller graph for this function:

◆ scalar_type()

ConfigOptionType Slic3r::ConfigOptionVectorBase::scalar_type ( ) const
inlineprotectedinherited
369{ return static_cast<ConfigOptionType>(this->type() - coVectorType); }
ConfigOptionType
Definition Config.hpp:160

References Slic3r::coVectorType, and Slic3r::ConfigOption::type().

Referenced by Slic3r::ConfigOptionVector< T >::set(), and Slic3r::ConfigOptionVector< T >::set_at().

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

◆ serialize() [1/2]

◆ serialize() [2/2]

template<class T >
template<class Archive >
void Slic3r::ConfigOptionVector< T >::serialize ( Archive &  ar)
inlineprivate
551{ ar(this->values); }

◆ set() [1/2]

template<class T >
void Slic3r::ConfigOptionVector< T >::set ( const ConfigOption rhs)
inlineoverridevirtual

Implements Slic3r::ConfigOption.

385 {
386 if (rhs->type() != this->type())
387 throw ConfigurationError("ConfigOptionVector: Assigning an incompatible type");
388 assert(dynamic_cast<const ConfigOptionVector<T>*>(rhs));
389 this->values = static_cast<const ConfigOptionVector<T>*>(rhs)->values;
390 }

References Slic3r::ConfigOption::type(), and Slic3r::ConfigOptionVector< T >::values.

+ Here is the call graph for this function:

◆ set() [2/2]

template<class T >
void Slic3r::ConfigOptionVector< T >::set ( const std::vector< const ConfigOption * > &  rhs)
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

397 {
398 this->values.clear();
399 this->values.reserve(rhs.size());
400 for (const ConfigOption *opt : rhs) {
401 if (opt->type() == this->type()) {
402 auto other = static_cast<const ConfigOptionVector<T>*>(opt);
403 if (other->values.empty())
404 throw ConfigurationError("ConfigOptionVector::set(): Assigning from an empty vector");
405 this->values.emplace_back(other->values.front());
406 } else if (opt->type() == this->scalar_type())
407 this->values.emplace_back(static_cast<const ConfigOptionSingle<T>*>(opt)->value);
408 else
409 throw ConfigurationError("ConfigOptionVector::set():: Assigning an incompatible type");
410 }
411 }
ConfigOptionType scalar_type() const
Definition Config.hpp:369

References Slic3r::ConfigOptionVectorBase::scalar_type(), Slic3r::ConfigOption::type(), and Slic3r::ConfigOptionSingle< T >::value.

+ Here is the call graph for this function:

◆ set_at()

template<class T >
void Slic3r::ConfigOptionVector< T >::set_at ( const ConfigOption rhs,
size_t  i,
size_t  j 
)
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

416 {
417 // It is expected that the vector value has at least one value, which is the default, if not overwritten.
418 assert(! this->values.empty());
419 if (this->values.size() <= i) {
420 // Resize this vector, fill in the new vector fields with the copy of the first field.
421 T v = this->values.front();
422 this->values.resize(i + 1, v);
423 }
424 if (rhs->type() == this->type()) {
425 // Assign the first value of the rhs vector.
426 auto other = static_cast<const ConfigOptionVector<T>*>(rhs);
427 if (other->values.empty())
428 throw ConfigurationError("ConfigOptionVector::set_at(): Assigning from an empty vector");
429 this->values[i] = other->get_at(j);
430 } else if (rhs->type() == this->scalar_type())
431 this->values[i] = static_cast<const ConfigOptionSingle<T>*>(rhs)->value;
432 else
433 throw ConfigurationError("ConfigOptionVector::set_at(): Assigning an incompatible type");
434 }

References Slic3r::ConfigOptionVectorBase::scalar_type(), Slic3r::ConfigOption::type(), and Slic3r::ConfigOptionSingle< T >::value.

+ Here is the call graph for this function:

◆ setInt()

virtual void Slic3r::ConfigOption::setInt ( int  )
inlinevirtualinherited

Reimplemented in Slic3r::ConfigOptionInt, and Slic3r::ConfigOptionEnum< T >.

273{ throw BadOptionTypeException("Calling ConfigOption::setInt on a non-int ConfigOption"); }

◆ size()

◆ type()

virtual ConfigOptionType Slic3r::ConfigOption::type ( ) const
pure virtualinherited

Implemented in Slic3r::ConfigOptionFloat, Slic3r::ConfigOptionFloatsTempl< NULLABLE >, Slic3r::ConfigOptionInt, Slic3r::ConfigOptionIntsTempl< NULLABLE >, Slic3r::ConfigOptionString, Slic3r::ConfigOptionStrings, Slic3r::ConfigOptionPercent, Slic3r::ConfigOptionPercentsTempl< NULLABLE >, Slic3r::ConfigOptionFloatOrPercent, Slic3r::ConfigOptionFloatsOrPercentsTempl< NULLABLE >, Slic3r::ConfigOptionPoint, Slic3r::ConfigOptionPoints, Slic3r::ConfigOptionPoint3, Slic3r::ConfigOptionBool, Slic3r::ConfigOptionBoolsTempl< NULLABLE >, Slic3r::ConfigOptionEnum< T >, and Slic3r::ConfigOptionEnumGeneric.

Referenced by Slic3r::Search::OptionsSearcher::append_options(), Slic3r::ConfigOptionVector< T >::apply_override(), Slic3r::client::MyContext::copy_vector_variable_to_vector_variable(), Slic3r::deep_diff(), Slic3r::ConfigBase::get_abs_value(), Slic3r::ConfigBase::get_abs_value(), Slic3r::ConfigOption::is_scalar(), Slic3r::client::MyContext::legacy_variable_expansion2(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::PresetBundle::load_config_file_config_bundle(), Slic3r::ConfigOptionSingle< T >::operator==(), Slic3r::ConfigOptionVector< T >::operator==(), Slic3r::ConfigOptionFloatsTempl< NULLABLE >::operator==(), Slic3r::ConfigOptionFloatOrPercent::operator==(), Slic3r::ConfigOptionFloatsOrPercentsTempl< NULLABLE >::operator==(), Slic3r::ConfigOptionEnum< T >::operator==(), Slic3r::ConfigOptionEnumGeneric::operator==(), Slic3r::ConfigOptionResolver::option(), Slic3r::ConfigBase::option(), Slic3r::ConfigOptionResolver::option_throw(), Slic3r::ConfigBase::option_throw(), Slic3r::ConfigOptionVector< T >::overriden_by(), Slic3r::DynamicConfig::read_cli(), Slic3r::ConfigOptionVectorBase::scalar_type(), Slic3r::client::MyContext::scalar_variable_assign_scalar(), Slic3r::client::MyContext::scalar_variable_to_expr(), Slic3r::ConfigOptionSingle< T >::set(), Slic3r::ConfigOptionVector< T >::set(), Slic3r::ConfigOptionFloatOrPercent::set(), Slic3r::ConfigOptionEnum< T >::set(), Slic3r::ConfigOptionEnumGeneric::set(), Slic3r::ConfigBase::set(), Slic3r::ConfigBase::set(), Slic3r::ConfigOptionVector< T >::set(), Slic3r::ConfigOptionVector< T >::set_at(), Slic3r::validate(), Slic3r::client::MyContext::vector_element_to_expr(), Slic3r::client::MyContext::vector_variable_assign_expr_with_count(), Slic3r::client::MyContext::vector_variable_assign_initializer_list(), Slic3r::client::MyContext::vector_variable_element_assign_scalar(), and Slic3r::client::MyContext::vector_variable_new_from_copy().

+ Here is the caller graph for this function:

◆ vserialize()

virtual std::vector< std::string > Slic3r::ConfigOptionVectorBase::vserialize ( ) const
pure virtualinherited

Friends And Related Symbol Documentation

◆ cereal::access

template<class T >
friend class cereal::access
friend

Member Data Documentation

◆ values

template<class T >
std::vector<T> Slic3r::ConfigOptionVector< T >::values

Referenced by Slic3r::GUI::BedShape::BedShape(), Slic3r::GCodeProcessor::apply_config(), Slic3r::ConfigOptionVector< T >::apply_override(), Slic3r::GUI::TextCtrl::BUILD(), Slic3r::GUI::TabPrinter::build_extruder_pages(), Slic3r::GUI::TabPrinter::build_fff(), Slic3r::GUI::BedShapePanel::build_panel(), Slic3r::GUI::TabPrinter::cache_extruder_cnt(), Slic3r::GUI::Bed3D::detect_type(), Slic3r::GUI::TabPrinter::extruders_count_changed(), Slic3r::GUI::Plater::force_filament_colors_update(), Slic3r::PresetBundle::full_fff_config(), Slic3r::ConfigOptionVector< T >::get_at(), Slic3r::GUI::ConfigOptionsGroup::get_config_value(), Slic3r::GUI::Materials::get_filament_type(), Slic3r::GUI::get_string_value(), Slic3r::ConfigOptionVector< T >::hash(), Slic3r::PrintConfigDef::init_fff_params(), Slic3r::GUI::MainFrame::init_tabpanel(), Slic3r::is_compatible_with_print(), Slic3r::is_compatible_with_printer(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::GUI::TabPrinter::on_preset_loaded(), Slic3r::ConfigOptionVector< T >::operator==(), Slic3r::ConfigOptionVector< T >::overriden_by(), Slic3r::GCode::placeholder_parser_process(), Slic3r::ConfigOptionVector< T >::resize(), Slic3r::ConfigOptionVector< T >::set(), Slic3r::GUI::Plater::set_bed_shape(), Slic3r::GUI::BedShapePanel::set_shape(), Slic3r::GUI::PointCtrl::set_value(), Slic3r::GUI::TabPrinter::toggle_options(), Slic3r::GLVolumeCollection::update_colors_by_extruder(), Slic3r::PresetBundle::update_multi_material_filament_presets(), Slic3r::GUI::DiffPresetDialog::update_tree(), Slic3r::GUI::UnsavedChangesDialog::update_tree(), Slic3r::validate(), Slic3r::client::MyContext::vector_element_to_expr(), and Slic3r::client::MyContext::vector_variable_new_from_copy().


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