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

#include <src/libslic3r/Preset.hpp>

+ Collaboration diagram for Slic3r::PhysicalPrinterCollection:

Public Types

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

Public Member Functions

 PhysicalPrinterCollection (const std::vector< std::string > &keys)
 
Iterator begin ()
 
ConstIterator begin () const
 
ConstIterator cbegin () const
 
Iterator end ()
 
ConstIterator end () const
 
ConstIterator cend () const
 
bool empty () const
 
void reset (bool delete_files)
 
const std::deque< PhysicalPrinter > & operator() () const
 
void load_printers (const std::string &dir_path, const std::string &subdir, PresetsConfigSubstitutions &substitutions, ForwardCompatibilitySubstitutionRule rule)
 
void load_printers_from_presets (PrinterPresetCollection &printer_presets)
 
void load_printer (const std::string &path, const std::string &name, DynamicPrintConfig &&config, bool select, bool save=false)
 
void save_printer (PhysicalPrinter &printer, const std::string &renamed_from="")
 
bool delete_printer (const std::string &name)
 
bool delete_selected_printer ()
 
bool delete_preset_from_printers (const std::string &preset_name)
 
void rename_preset_in_printers (const std::string &old_name, const std::string &new_name)
 
std::vector< std::string > get_printers_with_preset (const std::string &preset_name, bool respect_only_preset=true)
 
std::vector< std::string > get_printers_with_only_preset (const std::string &preset_name)
 
PhysicalPrinterget_selected_printer ()
 
const PhysicalPrinterget_selected_printer () const
 
size_t get_selected_idx () const
 
std::string get_selected_printer_name () const
 
DynamicPrintConfigget_selected_printer_config ()
 
PrinterTechnology get_selected_printer_technology ()
 
std::string get_selected_full_printer_name () const
 
std::string get_selected_printer_preset_name () const
 
void select_printer (const std::string &full_name)
 
void select_printer (const PhysicalPrinter &printer)
 
void select_printer (const std::string &printer_name, const std::string &preset_name)
 
bool has_selection () const
 
void unselect_printer ()
 
bool is_selected (ConstIterator it, const std::string &preset_name) const
 
PhysicalPrinterprinter (size_t idx)
 
const PhysicalPrinterprinter (size_t idx) const
 
PhysicalPrinterfind_printer (const std::string &name, bool case_sensitive_search=true)
 
const PhysicalPrinterfind_printer (const std::string &name, bool case_sensitive_search=true) const
 
std::string path_from_name (const std::string &new_name) const
 
const DynamicPrintConfigdefault_config () const
 

Private Member Functions

 PhysicalPrinterCollection ()=default
 
PhysicalPrinterCollectionoperator= (const PhysicalPrinterCollection &other)=default
 
std::deque< PhysicalPrinter >::iterator find_printer_internal (const std::string &name, bool case_sensitive_search=true)
 
std::deque< PhysicalPrinter >::const_iterator find_printer_internal (const std::string &name, bool case_sensitive_search=true) const
 
PhysicalPrinterfind_printer_with_same_config (const DynamicPrintConfig &config)
 

Private Attributes

std::deque< PhysicalPrinterm_printers
 
DynamicPrintConfig m_default_config
 
size_t m_idx_selected = size_t(-1)
 
std::string m_selected_preset
 
std::string m_dir_path
 

Friends

class PresetBundle
 

Detailed Description

Member Typedef Documentation

◆ ConstIterator

◆ Iterator

Constructor & Destructor Documentation

◆ PhysicalPrinterCollection() [1/2]

Slic3r::PhysicalPrinterCollection::PhysicalPrinterCollection ( const std::vector< std::string > &  keys)
1745{
1746 // Default config for a physical printer containing all key/value pairs of PhysicalPrinter::printer_options().
1747 for (const std::string &key : keys) {
1748 const ConfigOptionDef *opt = print_config_def.get(key);
1749 assert(opt);
1750 assert(opt->default_value);
1751 m_default_config.set_key_value(key, opt->default_value->clone());
1752 }
1753}
const ConfigOptionDef * get(const t_config_option_key &opt_key) const
Definition Config.hpp:2069
bool set_key_value(const std::string &opt_key, ConfigOption *opt)
Definition Config.hpp:2431
DynamicPrintConfig m_default_config
Definition Preset.hpp:821
const PrintConfigDef print_config_def
Definition PrintConfig.cpp:4288

References Slic3r::ConfigOptionDef::default_value, Slic3r::ConfigDef::get(), m_default_config, Slic3r::print_config_def, and Slic3r::DynamicConfig::set_key_value().

+ Here is the call graph for this function:

◆ PhysicalPrinterCollection() [2/2]

Slic3r::PhysicalPrinterCollection::PhysicalPrinterCollection ( )
privatedefault

Member Function Documentation

◆ begin() [1/2]

Iterator Slic3r::PhysicalPrinterCollection::begin ( )
inline
713{ return m_printers.begin(); }
std::deque< PhysicalPrinter > m_printers
Definition Preset.hpp:818

References m_printers.

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

+ Here is the caller graph for this function:

◆ begin() [2/2]

ConstIterator Slic3r::PhysicalPrinterCollection::begin ( ) const
inline
714{ return m_printers.cbegin(); }

References m_printers.

◆ cbegin()

ConstIterator Slic3r::PhysicalPrinterCollection::cbegin ( ) const
inline
715{ return m_printers.cbegin(); }

References m_printers.

◆ cend()

ConstIterator Slic3r::PhysicalPrinterCollection::cend ( ) const
inline
718{ return m_printers.cend(); }

References m_printers.

◆ default_config()

const DynamicPrintConfig & Slic3r::PhysicalPrinterCollection::default_config ( ) const
inline
797{ return m_default_config; }

References m_default_config.

Referenced by Slic3r::PresetBundle::load_configbundle(), load_printers(), and load_printers_from_presets().

+ Here is the caller graph for this function:

◆ delete_preset_from_printers()

bool Slic3r::PhysicalPrinterCollection::delete_preset_from_printers ( const std::string &  preset_name)
1999{
2000 std::vector<std::string> printers_for_delete;
2001 for (PhysicalPrinter& printer : m_printers) {
2002 if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name)
2003 printers_for_delete.emplace_back(printer.name);
2004 else if (printer.delete_preset(preset_name))
2006 }
2007
2008 if (!printers_for_delete.empty())
2009 for (const std::string& printer_name : printers_for_delete)
2010 delete_printer(printer_name);
2011
2013 return true;
2014}
PhysicalPrinter & printer(size_t idx)
Definition Preset.hpp:782
bool delete_printer(const std::string &name)
Definition Preset.cpp:1969
void unselect_printer()
Definition Preset.cpp:2095
void save_printer(PhysicalPrinter &printer, const std::string &renamed_from="")
Definition Preset.cpp:1929
std::string name
Definition Preset.hpp:641
std::set< std::string > preset_names
Definition Preset.hpp:647
bool delete_preset(const std::string &preset_name)
Definition Preset.cpp:1697

References Slic3r::PhysicalPrinter::delete_preset(), delete_printer(), m_printers, Slic3r::PhysicalPrinter::name, Slic3r::PhysicalPrinter::preset_names, printer(), save_printer(), and unselect_printer().

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

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

◆ delete_printer()

bool Slic3r::PhysicalPrinterCollection::delete_printer ( const std::string &  name)
1970{
1971 auto it = this->find_printer_internal(name);
1972 if (it == m_printers.end())
1973 return false;
1974
1975 const PhysicalPrinter& printer = *it;
1976 // Erase the preset file.
1977 boost::nowide::remove(printer.file.c_str());
1978 m_printers.erase(it);
1979 return true;
1980}
std::deque< PhysicalPrinter >::iterator find_printer_internal(const std::string &name, bool case_sensitive_search=true)
Definition Preset.cpp:1889
std::string file
Definition Preset.hpp:643

References Slic3r::PhysicalPrinter::file, find_printer_internal(), m_printers, and printer().

Referenced by delete_preset_from_printers().

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

◆ delete_selected_printer()

bool Slic3r::PhysicalPrinterCollection::delete_selected_printer ( )
1983{
1984 if (!has_selection())
1985 return false;
1986 const PhysicalPrinter& printer = this->get_selected_printer();
1987
1988 // Erase the preset file.
1989 boost::nowide::remove(printer.file.c_str());
1990 // Remove the preset from the list.
1991 m_printers.erase(m_printers.begin() + m_idx_selected);
1992 // unselect all printers
1994
1995 return true;
1996}
size_t m_idx_selected
Definition Preset.hpp:824
bool has_selection() const
Definition Preset.cpp:2090
PhysicalPrinter & get_selected_printer()
Definition Preset.hpp:754

References Slic3r::PhysicalPrinter::file, get_selected_printer(), has_selection(), m_idx_selected, m_printers, printer(), and unselect_printer().

Referenced by Slic3r::GUI::PresetComboBox::del_physical_printer().

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

◆ empty()

bool Slic3r::PhysicalPrinterCollection::empty ( ) const
inline
720{return m_printers.empty(); }

References m_printers.

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

+ Here is the caller graph for this function:

◆ end() [1/2]

Iterator Slic3r::PhysicalPrinterCollection::end ( )
inline
716{ return m_printers.end(); }

References m_printers.

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

+ Here is the caller graph for this function:

◆ end() [2/2]

ConstIterator Slic3r::PhysicalPrinterCollection::end ( ) const
inline
717{ return m_printers.cend(); }

References m_printers.

◆ find_printer() [1/2]

PhysicalPrinter * Slic3r::PhysicalPrinterCollection::find_printer ( const std::string &  name,
bool  case_sensitive_search = true 
)
1874{
1875 auto it = this->find_printer_internal(name, case_sensitive_search);
1876
1877 // Ensure that a temporary copy is returned if the preset found is currently selected.
1878 auto is_equal_name = [name, case_sensitive_search](const std::string& in_name) {
1879 if (case_sensitive_search)
1880 return in_name == name;
1881 return boost::to_lower_copy<std::string>(in_name) == boost::to_lower_copy<std::string>(name);
1882 };
1883
1884 if (it == m_printers.end() || !is_equal_name(it->name))
1885 return nullptr;
1886 return &this->printer(it - m_printers.begin());
1887}

References find_printer_internal(), m_printers, and printer().

Referenced by Slic3r::GUI::PhysicalPrinterDialog::PhysicalPrinterDialog(), find_printer(), find_printer_with_same_config(), Slic3r::PresetBundle::load_config_file_config(), Slic3r::PresetBundle::load_configbundle(), load_printers(), load_printers_from_presets(), and Slic3r::GUI::PhysicalPrinterDialog::OnOK().

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

◆ find_printer() [2/2]

const PhysicalPrinter * Slic3r::PhysicalPrinterCollection::find_printer ( const std::string &  name,
bool  case_sensitive_search = true 
) const
inline
790 {
791 return const_cast<PhysicalPrinterCollection*>(this)->find_printer(name, case_sensitive_search);
792 }
PhysicalPrinter * find_printer(const std::string &name, bool case_sensitive_search=true)
Definition Preset.cpp:1873

References find_printer().

+ Here is the call graph for this function:

◆ find_printer_internal() [1/2]

std::deque< PhysicalPrinter >::iterator Slic3r::PhysicalPrinterCollection::find_printer_internal ( const std::string &  name,
bool  case_sensitive_search = true 
)
private
1890{
1891 if (case_sensitive_search)
1892 return Slic3r::lower_bound_by_predicate(m_printers.begin(), m_printers.end(), [&name](const auto& l) { return l.name < name; });
1893
1894 std::string low_name = boost::to_lower_copy<std::string>(name);
1895
1896 size_t i = 0;
1897 for (const PhysicalPrinter& printer : m_printers) {
1898 if (boost::to_lower_copy<std::string>(printer.name) == low_name)
1899 break;
1900 i++;
1901 }
1902 if (i == m_printers.size())
1903 return m_printers.end();
1904
1905 return m_printers.begin() + i;
1906}
ForwardIt lower_bound_by_predicate(ForwardIt first, ForwardIt last, LowerThanKeyPredicate lower_than_key)
Definition libslic3r.h:203

References Slic3r::lower_bound_by_predicate(), m_printers, Slic3r::PhysicalPrinter::name, and printer().

Referenced by delete_printer(), find_printer(), find_printer_internal(), load_printer(), save_printer(), and select_printer().

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

◆ find_printer_internal() [2/2]

std::deque< PhysicalPrinter >::const_iterator Slic3r::PhysicalPrinterCollection::find_printer_internal ( const std::string &  name,
bool  case_sensitive_search = true 
) const
inlineprivate
809 {
810 return const_cast<PhysicalPrinterCollection*>(this)->find_printer_internal(name);
811 }

References find_printer_internal().

+ Here is the call graph for this function:

◆ find_printer_with_same_config()

PhysicalPrinter * Slic3r::PhysicalPrinterCollection::find_printer_with_same_config ( const DynamicPrintConfig config)
private
1909{
1910 for (const PhysicalPrinter& printer :*this) {
1911 bool is_equal = true;
1912 for (const char *opt : legacy_print_host_options)
1913 if (is_equal && printer.config.opt_string(opt) != config.opt_string(opt))
1914 is_equal = false;
1915
1916 if (is_equal)
1917 return find_printer(printer.name);
1918 }
1919 return nullptr;
1920}
if(!(yy_init))
Definition lexer.c:1190
static constexpr auto legacy_print_host_options
Definition Preset.cpp:1591

References Slic3r::PhysicalPrinter::config, find_printer(), Slic3r::legacy_print_host_options, Slic3r::PhysicalPrinter::name, Slic3r::ConfigBase::opt_string(), and printer().

Referenced by load_printers_from_presets().

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

◆ get_printers_with_only_preset()

std::vector< std::string > Slic3r::PhysicalPrinterCollection::get_printers_with_only_preset ( const std::string &  preset_name)
2043{
2044 std::vector<std::string> printers;
2045
2046 for (const PhysicalPrinter& printer : m_printers)
2047 if (printer.preset_names.size() == 1 && *printer.preset_names.begin() == preset_name)
2048 printers.emplace_back(printer.name);
2049
2050 return printers;
2051}
Iterator begin()
Definition Preset.hpp:713
constexpr auto size(const C &c) -> decltype(c.size())
Definition span.hpp:183

References m_printers, Slic3r::PhysicalPrinter::name, Slic3r::PhysicalPrinter::preset_names, and printer().

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

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

◆ get_printers_with_preset()

std::vector< std::string > Slic3r::PhysicalPrinterCollection::get_printers_with_preset ( const std::string &  preset_name,
bool  respect_only_preset = true 
)
2028{
2029 std::vector<std::string> printers;
2030
2031 for (auto printer : m_printers) {
2032 if (!respect_only_preset && printer.preset_names.size() == 1)
2033 continue;
2034 if (printer.preset_names.find(preset_name) != printer.preset_names.end())
2035 printers.emplace_back(printer.name);
2036 }
2037
2038 return printers;
2039}

References m_printers, Slic3r::PhysicalPrinter::name, Slic3r::PhysicalPrinter::preset_names, and printer().

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

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

◆ get_selected_full_printer_name()

std::string Slic3r::PhysicalPrinterCollection::get_selected_full_printer_name ( ) const
2054{
2055 return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().get_full_name(m_selected_preset);
2056}
std::string m_selected_preset
Definition Preset.hpp:826

References Slic3r::PhysicalPrinter::get_full_name(), get_selected_printer(), m_idx_selected, and m_selected_preset.

Referenced by Slic3r::GUI::PresetComboBox::del_physical_printer(), Slic3r::PresetBundle::export_selections(), Slic3r::GUI::PlaterPresetComboBox::get_selected_ph_printer_name(), and Slic3r::GUI::PresetComboBox::selection_is_changed_according_to_physical_printers().

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

◆ get_selected_idx()

size_t Slic3r::PhysicalPrinterCollection::get_selected_idx ( ) const
inline
757{ return m_idx_selected; }

References m_idx_selected.

◆ get_selected_printer() [1/2]

PhysicalPrinter & Slic3r::PhysicalPrinterCollection::get_selected_printer ( )
inline

◆ get_selected_printer() [2/2]

const PhysicalPrinter & Slic3r::PhysicalPrinterCollection::get_selected_printer ( ) const
inline
755{ return m_printers[m_idx_selected]; }

References m_idx_selected, and m_printers.

◆ get_selected_printer_config()

DynamicPrintConfig * Slic3r::PhysicalPrinterCollection::get_selected_printer_config ( )
inline
761{ return (m_idx_selected == size_t(-1)) ? nullptr : &(this->get_selected_printer().config); }
DynamicPrintConfig config
Definition Preset.hpp:645

References Slic3r::PhysicalPrinter::config, get_selected_printer(), and m_idx_selected.

+ Here is the call graph for this function:

◆ get_selected_printer_name()

std::string Slic3r::PhysicalPrinterCollection::get_selected_printer_name ( ) const
inline
759{ return (m_idx_selected == size_t(-1)) ? std::string() : this->get_selected_printer().name; }

References get_selected_printer(), m_idx_selected, and Slic3r::PhysicalPrinter::name.

Referenced by Slic3r::GUI::SavePresetDialog::add_info_for_edit_ph_printer(), Slic3r::PresetBundle::full_fff_config(), Slic3r::PresetBundle::full_sla_config(), and Slic3r::GUI::PhysicalPrinterDialog::OnOK().

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

◆ get_selected_printer_preset_name()

std::string Slic3r::PhysicalPrinterCollection::get_selected_printer_preset_name ( ) const
inline

◆ get_selected_printer_technology()

PrinterTechnology Slic3r::PhysicalPrinterCollection::get_selected_printer_technology ( )
inline
static PrinterTechnology printer_technology(const DynamicPrintConfig &cfg)
Definition Preset.hpp:676
@ ptAny
Definition Config.hpp:213

References get_selected_printer(), m_idx_selected, Slic3r::PhysicalPrinter::printer_technology(), and Slic3r::ptAny.

+ Here is the call graph for this function:

◆ has_selection()

bool Slic3r::PhysicalPrinterCollection::has_selection ( ) const

◆ is_selected()

bool Slic3r::PhysicalPrinterCollection::is_selected ( PhysicalPrinterCollection::ConstIterator  it,
const std::string &  preset_name 
) const
2102{
2103 return m_idx_selected == size_t(it - m_printers.begin()) &&
2104 m_selected_preset == preset_name;
2105}

References m_idx_selected, m_printers, and m_selected_preset.

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

+ Here is the caller graph for this function:

◆ load_printer()

void Slic3r::PhysicalPrinterCollection::load_printer ( const std::string &  path,
const std::string &  name,
DynamicPrintConfig &&  config,
bool  select,
bool  save = false 
)
1811{
1812 auto it = this->find_printer_internal(name);
1813 if (it == m_printers.end() || it->name != name) {
1814 // The preset was not found. Create a new preset.
1815 it = m_printers.emplace(it, PhysicalPrinter(name, config));
1816 }
1817
1818 it->file = path;
1819 it->config = std::move(config);
1820 it->loaded = true;
1821 if (select)
1822 this->select_printer(*it);
1823
1824 if (save)
1825 it->save();
1826}
void save(Archive &archive, wxString const &d)
Definition GLGizmoEmboss.cpp:1557
void select_printer(const std::string &full_name)
Definition Preset.cpp:2058

References find_printer_internal(), m_printers, save(), and select_printer().

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

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

◆ load_printers()

void Slic3r::PhysicalPrinterCollection::load_printers ( const std::string &  dir_path,
const std::string &  subdir,
PresetsConfigSubstitutions substitutions,
ForwardCompatibilitySubstitutionRule  rule 
)
1760{
1761 // Don't use boost::filesystem::canonical() on Windows, it is broken in regard to reparse points,
1762 // see https://github.com/prusa3d/PrusaSlicer/issues/732
1763 boost::filesystem::path dir = boost::filesystem::absolute(boost::filesystem::path(dir_path) / subdir).make_preferred();
1764 m_dir_path = dir.string();
1765 std::string errors_cummulative;
1766 // Store the loaded printers into a new vector, otherwise the binary search for already existing presets would be broken.
1767 std::deque<PhysicalPrinter> printers_loaded;
1768 for (auto& dir_entry : boost::filesystem::directory_iterator(dir))
1769 if (Slic3r::is_ini_file(dir_entry)) {
1770 std::string name = dir_entry.path().filename().string();
1771 // Remove the .ini suffix.
1772 name.erase(name.size() - 4);
1773 if (this->find_printer(name, false)) {
1774 // This happens when there's is a preset (most likely legacy one) with the same name as a system preset
1775 // that's already been loaded from a bundle.
1776 BOOST_LOG_TRIVIAL(warning) << "Printer already present, not loading: " << name;
1777 continue;
1778 }
1779 try {
1780 PhysicalPrinter printer(name, this->default_config());
1781 printer.file = dir_entry.path().string();
1782 // Load the preset file, apply preset values on top of defaults.
1783 try {
1784 DynamicPrintConfig config;
1785 ConfigSubstitutions config_substitutions = config.load_from_ini(printer.file, substitution_rule);
1786 if (! config_substitutions.empty())
1787 substitutions.push_back({ name, Preset::TYPE_PHYSICAL_PRINTER, PresetConfigSubstitutions::Source::UserFile, printer.file, std::move(config_substitutions) });
1789 printer.loaded = true;
1790 }
1791 catch (const std::ifstream::failure& err) {
1792 throw Slic3r::RuntimeError(std::string("The selected preset cannot be loaded: ") + printer.file + "\n\tReason: " + err.what());
1793 }
1794 catch (const std::runtime_error& err) {
1795 throw Slic3r::RuntimeError(std::string("Failed loading the preset file: ") + printer.file + "\n\tReason: " + err.what());
1796 }
1797 printers_loaded.emplace_back(printer);
1798 }
1799 catch (const std::runtime_error& err) {
1800 errors_cummulative += err.what();
1801 errors_cummulative += "\n";
1802 }
1803 }
1804 m_printers.insert(m_printers.end(), std::make_move_iterator(printers_loaded.begin()), std::make_move_iterator(printers_loaded.end()));
1805 std::sort(m_printers.begin(), m_printers.end());
1806 if (!errors_cummulative.empty())
1807 throw Slic3r::RuntimeError(errors_cummulative);
1808}
std::string m_dir_path
Definition Preset.hpp:829
const DynamicPrintConfig & default_config() const
Definition Preset.hpp:797
void update_from_config(const DynamicPrintConfig &new_config)
Definition Preset.cpp:1671
bool loaded
Definition Preset.hpp:650
@ TYPE_PHYSICAL_PRINTER
Definition Preset.hpp:120
Definition avrdude-slic3r.cpp:16
std::vector< ConfigSubstitution > ConfigSubstitutions
Definition Config.hpp:246
bool is_ini_file(const boost::filesystem::directory_entry &dir_entry)
Definition utils.cpp:773
Definition args.hpp:18

References default_config(), Slic3r::PhysicalPrinter::file, find_printer(), Slic3r::is_ini_file(), Slic3r::ConfigBase::load_from_ini(), Slic3r::PhysicalPrinter::loaded, m_dir_path, m_printers, printer(), Slic3r::Preset::TYPE_PHYSICAL_PRINTER, Slic3r::PhysicalPrinter::update_from_config(), and Slic3r::PresetConfigSubstitutions::UserFile.

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

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

◆ load_printers_from_presets()

void Slic3r::PhysicalPrinterCollection::load_printers_from_presets ( PrinterPresetCollection printer_presets)
1832{
1833 int cnt=0;
1834 for (Preset& preset: printer_presets) {
1835 DynamicPrintConfig& config = preset.config;
1836 for(const char* option : legacy_print_host_options) {
1837 if (!config.opt_string(option).empty()) {
1838 // check if printer with those "Print Host upload" options already exist
1839 PhysicalPrinter* existed_printer = find_printer_with_same_config(config);
1840 if (existed_printer)
1841 // just add preset for this printer
1842 existed_printer->add_preset(preset.name);
1843 else {
1844 std::string new_printer_name = (boost::format("Printer %1%") % ++cnt ).str();
1845 while (find_printer(new_printer_name))
1846 new_printer_name = (boost::format("Printer %1%") % ++cnt).str();
1847
1848 // create new printer from this preset
1849 PhysicalPrinter printer(new_printer_name, this->default_config(), preset);
1850 printer.loaded = true;
1852 }
1853
1854 // erase "Print Host upload" information from the preset
1855 for (const char *opt : legacy_print_host_options)
1856 config.opt_string(opt).clear();
1857 // save changes for preset
1858 preset.save();
1859
1860 // update those changes for edited preset if it's equal to the preset
1861 Preset& edited = printer_presets.get_edited_preset();
1862 if (preset.name == edited.name) {
1863 for (const char *opt : legacy_print_host_options)
1864 edited.config.opt_string(opt).clear();
1865 }
1866
1867 break;
1868 }
1869 }
1870 }
1871}
PhysicalPrinter * find_printer_with_same_config(const DynamicPrintConfig &config)
Definition Preset.cpp:1908
Definition getopt.h:102

References Slic3r::PhysicalPrinter::add_preset(), Slic3r::Preset::config, default_config(), find_printer(), find_printer_with_same_config(), Slic3r::PresetCollection::get_edited_preset(), Slic3r::legacy_print_host_options, Slic3r::PhysicalPrinter::loaded, Slic3r::Preset::name, Slic3r::ConfigBase::opt_string(), printer(), and save_printer().

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

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

◆ operator()()

const std::deque< PhysicalPrinter > & Slic3r::PhysicalPrinterCollection::operator() ( ) const
inline
724{ return m_printers; }

References m_printers.

◆ operator=()

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

◆ path_from_name()

std::string Slic3r::PhysicalPrinterCollection::path_from_name ( const std::string &  new_name) const
1924{
1925 std::string file_name = boost::iends_with(new_name, ".ini") ? new_name : (new_name + ".ini");
1926 return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string();
1927}

References m_dir_path.

Referenced by save_printer().

+ Here is the caller graph for this function:

◆ printer() [1/2]

PhysicalPrinter & Slic3r::PhysicalPrinterCollection::printer ( size_t  idx)
inline
782{ return m_printers[idx]; }

References m_printers.

Referenced by delete_preset_from_printers(), delete_printer(), delete_selected_printer(), find_printer(), find_printer_internal(), find_printer_with_same_config(), get_printers_with_only_preset(), get_printers_with_preset(), load_printers(), load_printers_from_presets(), rename_preset_in_printers(), save_printer(), and select_printer().

+ Here is the caller graph for this function:

◆ printer() [2/2]

const PhysicalPrinter & Slic3r::PhysicalPrinterCollection::printer ( size_t  idx) const
inline
783{ return const_cast<PhysicalPrinterCollection*>(this)->printer(idx); }

References printer().

Referenced by printer().

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

◆ rename_preset_in_printers()

void Slic3r::PhysicalPrinterCollection::rename_preset_in_printers ( const std::string &  old_name,
const std::string &  new_name 
)
2017{
2018 for (PhysicalPrinter& printer : m_printers)
2019 if (printer.delete_preset(old_preset_name)) {
2020 printer.add_preset(new_preset_name);
2022 printer.save();
2023 }
2024}
void update_preset_names_in_config()
Definition Preset.cpp:1641
bool add_preset(const std::string &preset_name)
Definition Preset.cpp:1692
void save()
Definition Preset.hpp:663

References Slic3r::PhysicalPrinter::add_preset(), Slic3r::PhysicalPrinter::delete_preset(), m_printers, printer(), Slic3r::PhysicalPrinter::save(), and Slic3r::PhysicalPrinter::update_preset_names_in_config().

+ Here is the call graph for this function:

◆ reset()

void Slic3r::PhysicalPrinterCollection::reset ( bool  delete_files)
inline
722{};

◆ save_printer()

void Slic3r::PhysicalPrinterCollection::save_printer ( PhysicalPrinter printer,
const std::string &  renamed_from = "" 
)
1930{
1931 // controll and update preset_names in edited_printer config
1932 edited_printer.update_preset_names_in_config();
1933
1934 std::string name = renamed_from.empty() ? edited_printer.name : renamed_from;
1935 // 1) Find the printer with a new_name or create a new one,
1936 // initialize it with the edited config.
1937 auto it = this->find_printer_internal(name);
1938 if (it != m_printers.end() && it->name == name) {
1939 // Printer with the same name found.
1940 // Overwriting an existing preset.
1941 it->config = std::move(edited_printer.config);
1942 it->name = edited_printer.name;
1943 it->preset_names = edited_printer.preset_names;
1944 // sort printers and get new it
1945 std::sort(m_printers.begin(), m_printers.end());
1946 it = this->find_printer_internal(edited_printer.name);
1947 }
1948 else {
1949 // Creating a new printer.
1950 it = m_printers.emplace(it, edited_printer);
1951 }
1952 assert(it != m_printers.end());
1953
1954 // 2) Save printer
1955 PhysicalPrinter& printer = *it;
1956 if (printer.file.empty())
1957 printer.file = this->path_from_name(printer.name);
1958
1959 if (printer.file == this->path_from_name(printer.name))
1960 printer.save();
1961 else
1962 // if printer was renamed, we should rename a file and than save the config
1963 printer.save(printer.file, this->path_from_name(printer.name));
1964
1965 // update idx_selected
1966 m_idx_selected = it - m_printers.begin();
1967}
std::string path_from_name(const std::string &new_name) const
Definition Preset.cpp:1923

References Slic3r::PhysicalPrinter::config, Slic3r::PhysicalPrinter::file, find_printer_internal(), m_idx_selected, m_printers, Slic3r::PhysicalPrinter::name, path_from_name(), Slic3r::PhysicalPrinter::preset_names, printer(), Slic3r::PhysicalPrinter::save(), and Slic3r::PhysicalPrinter::update_preset_names_in_config().

Referenced by delete_preset_from_printers(), load_printers_from_presets(), Slic3r::GUI::PhysicalPrinterDialog::OnOK(), and Slic3r::GUI::SavePresetDialog::update_physical_printers().

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

◆ select_printer() [1/3]

void Slic3r::PhysicalPrinterCollection::select_printer ( const PhysicalPrinter printer)
2086{
2087 return select_printer(printer.name);
2088}

References Slic3r::PhysicalPrinter::name, printer(), and select_printer().

+ Here is the call graph for this function:

◆ select_printer() [2/3]

void Slic3r::PhysicalPrinterCollection::select_printer ( const std::string &  full_name)
2059{
2060 std::string printer_name = PhysicalPrinter::get_short_name(full_name);
2061 auto it = this->find_printer_internal(printer_name);
2062 if (it == m_printers.end()) {
2064 return;
2065 }
2066
2067 // update idx_selected
2068 m_idx_selected = it - m_printers.begin();
2069
2070 // update name of the currently selected preset
2071 if (printer_name == full_name)
2072 // use first preset in the list
2073 m_selected_preset = *it->preset_names.begin();
2074 else
2075 m_selected_preset = it->get_preset_name(full_name);
2076}
static std::string get_short_name(std::string full_name)
Definition Preset.cpp:1724

References find_printer_internal(), Slic3r::PhysicalPrinter::get_short_name(), m_idx_selected, m_printers, m_selected_preset, and unselect_printer().

Referenced by Slic3r::GUI::Tab::delete_preset(), Slic3r::PresetBundle::load_config_file_config(), load_printer(), Slic3r::PresetBundle::load_selections(), Slic3r::GUI::PhysicalPrinterDialog::OnOK(), select_printer(), select_printer(), Slic3r::GUI::PresetComboBox::selection_is_changed_according_to_physical_printers(), and Slic3r::GUI::SavePresetDialog::update_physical_printers().

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

◆ select_printer() [3/3]

void Slic3r::PhysicalPrinterCollection::select_printer ( const std::string &  printer_name,
const std::string &  preset_name 
)
2079{
2080 if (preset_name.empty())
2081 return select_printer(printer_name);
2082 return select_printer(printer_name + PhysicalPrinter::separator() + preset_name);
2083}
static std::string separator()
Definition Preset.cpp:1565

References select_printer(), and Slic3r::PhysicalPrinter::separator().

+ Here is the call graph for this function:

◆ unselect_printer()

void Slic3r::PhysicalPrinterCollection::unselect_printer ( )
2096{
2097 m_idx_selected = size_t(-1);
2098 m_selected_preset.clear();
2099}

References m_idx_selected, and m_selected_preset.

Referenced by delete_preset_from_printers(), delete_selected_printer(), Slic3r::PresetBundle::load_config_file_config(), select_printer(), Slic3r::GUI::PresetComboBox::selection_is_changed_according_to_physical_printers(), Slic3r::GUI::TabPresetComboBox::update(), and Slic3r::GUI::SavePresetDialog::update_physical_printers().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ PresetBundle

friend class PresetBundle
friend

Member Data Documentation

◆ m_default_config

DynamicPrintConfig Slic3r::PhysicalPrinterCollection::m_default_config
private

◆ m_dir_path

std::string Slic3r::PhysicalPrinterCollection::m_dir_path
private

Referenced by load_printers(), and path_from_name().

◆ m_idx_selected

◆ m_printers

◆ m_selected_preset

std::string Slic3r::PhysicalPrinterCollection::m_selected_preset
private

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