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

#include <src/libslic3r/Config.hpp>

+ Inheritance diagram for Slic3r::ConfigOptionPoints:
+ Collaboration diagram for Slic3r::ConfigOptionPoints:

Public Member Functions

 ConfigOptionPoints ()
 
 ConfigOptionPoints (size_t n, const Vec2d &value)
 
 ConfigOptionPoints (std::initializer_list< Vec2d > il)
 
 ConfigOptionPoints (const std::vector< Vec2d > &values)
 
ConfigOptionType type () const override
 
ConfigOptionclone () const override
 
ConfigOptionPointsoperator= (const ConfigOption *opt)
 
bool operator== (const ConfigOptionPoints &rhs) const throw ()
 
bool operator< (const ConfigOptionPoints &rhs) const throw ()
 
bool is_nil (size_t) const override
 
std::string serialize () const override
 
std::vector< std::string > vserialize () const override
 
bool deserialize (const std::string &str, bool append=false) override
 
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 Vec2dget_at (size_t i) const
 
Vec2dget_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< Vec2d > &rhs) const throw ()
 
bool operator!= (const std::vector< Vec2d > &rhs) const throw ()
 
bool operator!= (const ConfigOption &rhs) const
 
size_t hash () const override throw ()
 
bool overriden_by (const ConfigOption *rhs) const override
 
bool apply_override (const ConfigOption *rhs) override
 
virtual bool is_nil () const
 
virtual int getInt () const
 
virtual double getFloat () const
 
virtual bool getBool () const
 
virtual void setInt (int)
 
bool is_scalar () const
 
bool is_vector () const
 
virtual bool nullable () const
 

Static Public Member Functions

static ConfigOptionType static_type ()
 

Public Attributes

std::vector< Vec2dvalues
 

Protected Member Functions

ConfigOptionType scalar_type () const
 

Private Member Functions

template<class Archive >
void save (Archive &archive) const
 
template<class Archive >
void load (Archive &archive)
 

Friends

class cereal::access
 

Detailed Description

Constructor & Destructor Documentation

◆ ConfigOptionPoints() [1/4]

Slic3r::ConfigOptionPoints::ConfigOptionPoints ( )
inline
1237: ConfigOptionVector<Vec2d>() {}

Referenced by clone().

+ Here is the caller graph for this function:

◆ ConfigOptionPoints() [2/4]

Slic3r::ConfigOptionPoints::ConfigOptionPoints ( size_t  n,
const Vec2d value 
)
inlineexplicit
1238: ConfigOptionVector<Vec2d>(n, value) {}

◆ ConfigOptionPoints() [3/4]

Slic3r::ConfigOptionPoints::ConfigOptionPoints ( std::initializer_list< Vec2d il)
inlineexplicit
1239: ConfigOptionVector<Vec2d>(std::move(il)) {}

◆ ConfigOptionPoints() [4/4]

Slic3r::ConfigOptionPoints::ConfigOptionPoints ( const std::vector< Vec2d > &  values)
inlineexplicit
1240: ConfigOptionVector<Vec2d>(values) {}
std::vector< Vec2d > values
Definition Config.hpp:382

Member Function Documentation

◆ apply_override()

bool Slic3r::ConfigOptionVector< Vec2d >::apply_override ( const ConfigOption rhs)
inlineoverridevirtualinherited

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

◆ clear()

void Slic3r::ConfigOptionVector< Vec2d >::clear ( )
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

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

◆ clone()

ConfigOption * Slic3r::ConfigOptionPoints::clone ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

1244{ return new ConfigOptionPoints(*this); }
ConfigOptionPoints()
Definition Config.hpp:1237

References ConfigOptionPoints().

+ Here is the call graph for this function:

◆ deserialize()

bool Slic3r::ConfigOptionPoints::deserialize ( const std::string &  str,
bool  append = false 
)
inlineoverridevirtual

Implements Slic3r::ConfigOption.

1275 {
1276 if (! append)
1277 this->values.clear();
1278 std::istringstream is(str);
1279 std::string point_str;
1280 while (std::getline(is, point_str, ',')) {
1281 Vec2d point(Vec2d::Zero());
1282 std::istringstream iss(point_str);
1283 std::string coord_str;
1284 if (std::getline(iss, coord_str, 'x')) {
1285 std::istringstream(coord_str) >> point(0);
1286 if (std::getline(iss, coord_str, 'x')) {
1287 std::istringstream(coord_str) >> point(1);
1288 }
1289 }
1290 this->values.push_back(point);
1291 }
1292 return true;
1293 }
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:51
void append(std::vector< T, Alloc > &dest, const std::vector< T, Alloc2 > &src)
Definition libslic3r.h:110

References Slic3r::append().

+ Here is the call graph for this function:

◆ empty()

bool Slic3r::ConfigOptionVector< Vec2d >::empty ( ) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

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

◆ get_at() [1/2]

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

◆ get_at() [2/2]

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

◆ 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()

size_t Slic3r::ConfigOptionVector< Vec2d >::hash ( ) const
throw (
)
inlineoverridevirtualinherited

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

◆ is_nil() [1/2]

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

Reimplemented from Slic3r::ConfigOption.

282{ return false; }

◆ is_nil() [2/2]

bool Slic3r::ConfigOptionPoints::is_nil ( size_t  ) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

1249{ return false; }

◆ 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()

◆ load()

template<class Archive >
void Slic3r::ConfigOptionPoints::load ( Archive &  archive)
inlineprivate
1302 {
1303 size_t cnt;
1304 archive(cnt);
1305 this->values.assign(cnt, Vec2d());
1306 archive.loadBinary((char*)this->values.data(), sizeof(Vec2d) * cnt);
1307 }

◆ 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]

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

◆ operator<()

bool Slic3r::ConfigOptionPoints::operator< ( const ConfigOptionPoints rhs) const
throw (
)
inline
1248 { return std::lexicographical_compare(this->values.begin(), this->values.end(), rhs.values.begin(), rhs.values.end(), [](const auto &l, const auto &r){ return l < r; }); }

◆ operator=()

ConfigOptionPoints & Slic3r::ConfigOptionPoints::operator= ( const ConfigOption opt)
inline
1245{ this->set(opt); return *this; }
void set(const ConfigOption *rhs) override
Definition Config.hpp:384

References Slic3r::ConfigOptionVector< Vec2d >::set().

+ Here is the call graph for this function:

◆ operator==() [1/3]

bool Slic3r::ConfigOptionVector< Vec2d >::operator== ( const ConfigOption rhs) const
inlineoverridevirtualinherited

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 }

◆ operator==() [2/3]

bool Slic3r::ConfigOptionPoints::operator== ( const ConfigOptionPoints rhs) const
throw (
)
inline
1246{ return this->values == rhs.values; }

◆ operator==() [3/3]

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

◆ overriden_by()

bool Slic3r::ConfigOptionVector< Vec2d >::overriden_by ( const ConfigOption rhs) const
inlineoverridevirtualinherited

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 }

◆ resize()

void Slic3r::ConfigOptionVector< Vec2d >::resize ( size_t  n,
const ConfigOption opt_default = nullptr 
)
inlineoverridevirtualinherited

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 }

◆ save()

template<class Archive >
void Slic3r::ConfigOptionPoints::save ( Archive &  archive) const
inlineprivate
1297 {
1298 size_t cnt = this->values.size();
1299 archive(cnt);
1300 archive.saveBinary((const char*)this->values.data(), sizeof(Vec2d) * cnt);
1301 }

◆ 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()

std::string Slic3r::ConfigOptionPoints::serialize ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

1252 {
1253 std::ostringstream ss;
1254 for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
1255 if (it - this->values.begin() != 0) ss << ",";
1256 ss << (*it)(0);
1257 ss << "x";
1258 ss << (*it)(1);
1259 }
1260 return ss.str();
1261 }

◆ set() [1/2]

void Slic3r::ConfigOptionVector< Vec2d >::set ( const ConfigOption rhs)
inlineoverridevirtualinherited

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 }

◆ set() [2/2]

void Slic3r::ConfigOptionVector< Vec2d >::set ( const std::vector< const ConfigOption * > &  rhs)
inlineoverridevirtualinherited

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

◆ set_at()

void Slic3r::ConfigOptionVector< Vec2d >::set_at ( const ConfigOption rhs,
size_t  i,
size_t  j 
)
inlineoverridevirtualinherited

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 }

◆ 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()

size_t Slic3r::ConfigOptionVector< Vec2d >::size ( ) const
inlineoverridevirtualinherited

Implements Slic3r::ConfigOptionVectorBase.

471{ return this->values.size(); }

◆ static_type()

static ConfigOptionType Slic3r::ConfigOptionPoints::static_type ( )
inlinestatic
1242{ return coPoints; }
@ coPoints
Definition Config.hpp:186

References Slic3r::coPoints.

Referenced by type().

+ Here is the caller graph for this function:

◆ type()

ConfigOptionType Slic3r::ConfigOptionPoints::type ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOption.

1243{ return static_type(); }
static ConfigOptionType static_type()
Definition Config.hpp:1242

References static_type().

+ Here is the call graph for this function:

◆ vserialize()

std::vector< std::string > Slic3r::ConfigOptionPoints::vserialize ( ) const
inlineoverridevirtual

Implements Slic3r::ConfigOptionVectorBase.

1264 {
1265 std::vector<std::string> vv;
1266 for (Pointfs::const_iterator it = this->values.begin(); it != this->values.end(); ++it) {
1267 std::ostringstream ss;
1268 ss << *it;
1269 vv.push_back(ss.str());
1270 }
1271 return vv;
1272 }

Friends And Related Symbol Documentation

◆ cereal::access

friend class cereal::access
friend

Member Data Documentation

◆ values

std::vector<Vec2d > Slic3r::ConfigOptionVector< Vec2d >::values
inherited

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