OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::Search::SettingsIndex Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/SettingsIndex.hpp>

Collaboration diagram for Slic3r::Search::SettingsIndex:

Public Member Functions

void init (std::vector< InputInfo > input_values)
bool apply (DynamicPrintConfig *config, Preset::Type type, ConfigOptionMode mode)
void add_key (const std::string &opt_key, Preset::Type type, const wxString &group, const wxString &category, const wxString &icon=wxEmptyString)
void set_path (const std::string &opt_key, Preset::Type type, const std::string &path)
void set_line_label (const std::string &opt_key, Preset::Type type, const wxString &label, const wxString &label_en)
const std::vector< Option > & options () const
const std::vector< Option > & all_options () const
const Option & option_at (size_t pos) const
const Option & get_option (const std::string &opt_key, Preset::Type type, int &variant_index) const
Option get_option (const std::string &opt_key, const wxString &label, Preset::Type type) const
const GroupAndCategory & get_group_and_category (const std::string &opt_key)
void sort_options_by_key ()
void sort_options_by_label ()

Private Member Functions

void append_options (DynamicPrintConfig *config, Preset::Type type, ConfigOptionMode mode)
void sort_options ()

Private Attributes

std::map< std::string, GroupAndCategory > m_groups_and_categories
std::vector< Option > m_options
std::vector< Option > m_all_modes

Detailed Description

Member Function Documentation

◆ add_key()

void Slic3r::Search::SettingsIndex::add_key ( const std::string & opt_key,
Preset::Type type,
const wxString & group,
const wxString & category,
const wxString & icon = wxEmptyString )
237{
238 // Update fields in place so a page rebuild (get_option after set_path) doesn't drop the
239 // previously recorded wiki path.
240 GroupAndCategory &gc = m_groups_and_categories[get_key(opt_key, type)];
241 gc.group = group;
242 gc.category = category;
243 gc.icon = icon;
244}
std::map< std::string, GroupAndCategory > m_groups_and_categories
Definition SettingsIndex.hpp:88
static std::string get_key(const std::string &opt_key, Preset::Type type)
Definition SettingsIndex.cpp:26

References Slic3r::Search::GroupAndCategory::category, Slic3r::Search::get_key(), Slic3r::Search::GroupAndCategory::group, Slic3r::Search::GroupAndCategory::icon, and m_groups_and_categories.

Referenced by Slic3r::GUI::TabPrinter::create_bed_shape_widget().

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

◆ all_options()

const std::vector< Option > & Slic3r::Search::SettingsIndex::all_options ( ) const
inline
109{ return m_all_modes; }
std::vector< Option > m_all_modes
Definition SettingsIndex.hpp:91

References m_all_modes.

◆ append_options()

void Slic3r::Search::SettingsIndex::append_options ( DynamicPrintConfig * config,
Preset::Type type,
ConfigOptionMode mode )
private
71{
72 for (std::string opt_key : config->keys()) {
73 const ConfigOptionDef &opt = config->def()->options.at(opt_key);
74 const bool in_filtered = opt.mode <= mode;
75
76 int cnt = 0;
77
78 if ((type == Preset::TYPE_SLA_MATERIAL || type == Preset::TYPE_PRINTER || type == Preset::TYPE_PRINT) && opt_key != "printable_area")
79 switch (config->option(opt_key)->type()) {
80 case coInts: change_opt_key<ConfigOptionInts>(opt_key, config, cnt); break;
81 case coBools: change_opt_key<ConfigOptionBools>(opt_key, config, cnt); break;
82 case coFloats: change_opt_key<ConfigOptionFloats>(opt_key, config, cnt); break;
83 case coStrings: change_opt_key<ConfigOptionStrings>(opt_key, config, cnt); break;
84 case coPercents: change_opt_key<ConfigOptionPercents>(opt_key, config, cnt); break;
86 case coPoints: change_opt_key<ConfigOptionPoints>(opt_key, config, cnt); break;
87 // BBS
88 case coEnums: change_opt_key<ConfigOptionInts>(opt_key, config, cnt); break;
89 default: break;
90 }
91
93 opt_key += "#0";
94
95 wxString label = opt.full_label.empty() ? opt.label : opt.full_label;
96
97 std::string key = get_key(opt_key, type);
98 auto add = [&](const std::string &k) {
99 const GroupAndCategory &gc = m_groups_and_categories[k];
100 if (gc.group.IsEmpty() || gc.category.IsEmpty() || label.IsEmpty()) return;
101
102 const std::string tooltip = into_u8(_(opt.tooltip));
103 if (in_filtered)
104 m_options.emplace_back(make_option(k, type, label, gc, opt.mode, tooltip, false));
105 m_all_modes.emplace_back(make_option(k, type, label, gc, opt.mode, tooltip, false));
106 };
107 if (cnt == 0)
108 add(key);
109 else
110 for (int i = 0; i < cnt; ++i)
111 // ! It's very important to use "#". opt_key#n is a real option key used in GroupAndCategory
112 add(key + "#" + std::to_string(i));
113 }
114}
#define _(s)
Definition 3mf.cpp:306
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
@ TYPE_SLA_MATERIAL
Definition Preset.hpp:249
@ TYPE_FILAMENT
Definition Preset.hpp:248
std::vector< Option > m_options
Definition SettingsIndex.hpp:90
static Option make_option(const std::string &key, Preset::Type type, const wxString &label, const GroupAndCategory &gc, ConfigOptionMode mode, const std::string &tooltip, bool rewrite_extruder_category)
Definition SettingsIndex.cpp:43
void change_opt_key(std::string &opt_key, DynamicPrintConfig *config, int &cnt)
Definition SettingsIndex.cpp:32
SpiralVase::SpiralPoint add(SpiralVase::SpiralPoint a, SpiralVase::SpiralPoint b)
Definition SpiralVase.cpp:26
std::string into_u8(const wxString &str)
Definition GUI.cpp:549
@ coFloatsOrPercents
Definition Config.hpp:202
@ coBools
Definition Config.hpp:212
@ coPercents
Definition Config.hpp:198
@ coInts
Definition Config.hpp:190
@ coPoints
Definition Config.hpp:206
@ coEnums
Definition Config.hpp:216
@ coStrings
Definition Config.hpp:194
@ coFloats
Definition Config.hpp:186
std::set< std::string > filament_options_with_variant
Definition PrintConfig.cpp:10150

References _, Slic3r::Search::GroupAndCategory::category, Slic3r::Search::change_opt_key(), Slic3r::coBools, Slic3r::coEnums, Slic3r::coFloats, Slic3r::coFloatsOrPercents, Slic3r::coInts, Slic3r::coPercents, Slic3r::coPoints, Slic3r::coStrings, Slic3r::DynamicPrintConfig::def(), Slic3r::filament_options_with_variant, Slic3r::Search::get_key(), Slic3r::Search::GroupAndCategory::group, Slic3r::into_u8(), Slic3r::DynamicConfig::keys(), m_all_modes, m_groups_and_categories, m_options, Slic3r::Search::make_option(), Slic3r::ConfigBase::option(), Slic3r::ConfigDef::options, Slic3r::ConfigOption::type(), Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, and Slic3r::Preset::TYPE_SLA_MATERIAL.

Referenced by apply(), and init().

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

◆ apply()

bool Slic3r::Search::SettingsIndex::apply ( DynamicPrintConfig * config,
Preset::Type type,
ConfigOptionMode mode )
145{
146 // m_all_modes is a separate consumer (the Speed Dial), so "nothing initialised yet" means both
147 // views are empty - the mode-filtered m_options can be empty while m_all_modes is not.
148 if (m_options.empty() && m_all_modes.empty()) return false;
149
150 m_options.erase(std::remove_if(m_options.begin(), m_options.end(), [type](Option opt) { return opt.type == type; }), m_options.end());
151 m_all_modes.erase(std::remove_if(m_all_modes.begin(), m_all_modes.end(), [type](Option opt) { return opt.type == type; }), m_all_modes.end());
152
153 append_options(config, type, mode);
154
155 sort_options();
156
157 return true;
158}
void append_options(DynamicPrintConfig *config, Preset::Type type, ConfigOptionMode mode)
Definition SettingsIndex.cpp:70
void sort_options()
Definition SettingsIndex.cpp:116

References append_options(), m_all_modes, m_options, and sort_options().

Here is the call graph for this function:

◆ get_group_and_category()

const GroupAndCategory & Slic3r::Search::SettingsIndex::get_group_and_category ( const std::string & opt_key)
inline
115{ return m_groups_and_categories[opt_key]; }

References m_groups_and_categories.

Referenced by Slic3r::GUI::TabPrinter::create_bed_shape_widget().

Here is the caller graph for this function:

◆ get_option() [1/2]

Option Slic3r::Search::SettingsIndex::get_option ( const std::string & opt_key,
const wxString & label,
Preset::Type type ) const
213{
214 std::string key = get_key(opt_key, type);
215 auto it = std::lower_bound(m_options.begin(), m_options.end(), Option({boost::nowide::widen(key)}));
216 // BBS: return the 0th option when not found in searcher caused by mode difference
217 if (it == m_options.end()) return m_options[0];
218 if (it->key == boost::nowide::widen(key)) return m_options[it - m_options.begin()];
219 if (m_groups_and_categories.find(key) == m_groups_and_categories.end()) {
220 size_t pos = key.find('#');
221 if (pos == std::string::npos) return m_options[it - m_options.begin()];
222
223 std::string zero_opt_key = key.substr(0, pos + 1) + "0";
224
225 if (m_groups_and_categories.find(zero_opt_key) == m_groups_and_categories.end()) return m_options[it - m_options.begin()];
226
227 return create_option(opt_key, label, type, m_groups_and_categories.at(zero_opt_key));
228 }
229
230 const GroupAndCategory &gc = m_groups_and_categories.at(key);
231 if (gc.group.IsEmpty() || gc.category.IsEmpty()) return m_options[it - m_options.begin()];
232
233 return create_option(opt_key, label, type, gc);
234}
static Option create_option(const std::string &opt_key, const wxString &label, Preset::Type type, const GroupAndCategory &gc)
Definition SettingsIndex.cpp:207
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References Slic3r::Search::GroupAndCategory::category, Slic3r::Search::create_option(), Slic3r::Search::get_key(), Slic3r::Search::GroupAndCategory::group, m_groups_and_categories, and m_options.

Here is the call graph for this function:

◆ get_option() [2/2]

const Option & Slic3r::Search::SettingsIndex::get_option ( const std::string & opt_key,
Preset::Type type,
int & variant_index ) const
161{
162 auto not_found = [&variant_index]() -> const Option & {
163 static const Option empty_option;
164 variant_index = -2;
165 return empty_option;
166 };
167
168 variant_index = -1;
169 std::string opt_key2 = opt_key;
170 if (auto n = opt_key.find('#'); n != std::string::npos) {
171 variant_index = std::atoi(opt_key.c_str() + n + 1);
172 opt_key2 = opt_key.substr(0, n);
173 }
174 const std::wstring key = boost::nowide::widen(get_key(opt_key2, type));
175 auto it = std::lower_bound(m_options.begin(), m_options.end(), Option({key}));
176 if (it == m_options.end()) return not_found();
177 if (it->key == key) {
178 variant_index = -1;
179 } else {
180 const std::wstring prefix = key + L"#";
181 it = std::lower_bound(it, m_options.end(), Option({prefix}));
182 if (it == m_options.end() || it->key.compare(0, prefix.length(), prefix) != 0)
183 return not_found();
184 // Orca: Copy-parameters dialogs request the base key, without a vector index.
185 if (variant_index < 0) return *it;
186
187 const bool has_mode = type == Preset::TYPE_PRINTER && printer_options_with_variant_2.count(opt_key2) > 0;
188 const bool has_variant =
189 (type == Preset::TYPE_PRINT && print_options_with_variant.count(opt_key2) > 0) ||
190 (type == Preset::TYPE_FILAMENT && filament_options_with_variant.count(opt_key2) > 0) ||
191 (type == Preset::TYPE_PRINTER && printer_options_with_variant_1.count(opt_key2) > 0) || has_mode;
192 if (!has_variant || has_mode) {
193 // Orca: Machine limits store (Normal, Silent) pairs per variant; the UI registers only #0/#1.
194 const std::wstring indexed_key = has_mode ? prefix + std::to_wstring(variant_index % 2) :
195 boost::nowide::widen(get_key(opt_key, type));
196 it = std::lower_bound(it, m_options.end(), Option({indexed_key}));
197 if (it == m_options.end() || it->key != indexed_key)
198 return not_found();
199 if (!has_variant)
200 variant_index = -1;
201 }
202 }
203
204 return m_options[it - m_options.begin()];
205}
#define L(s)
Definition ExtrusionEntity.cpp:25
std::set< std::string > printer_options_with_variant_1
Definition PrintConfig.cpp:10236
std::set< std::string > printer_options_with_variant_2
Definition PrintConfig.cpp:10270
std::set< std::string > print_options_with_variant
Definition PrintConfig.cpp:10102

References Slic3r::filament_options_with_variant, Slic3r::Search::get_key(), L, m_options, Slic3r::print_options_with_variant, Slic3r::printer_options_with_variant_1, Slic3r::printer_options_with_variant_2, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, and Slic3r::Preset::TYPE_PRINTER.

Referenced by Slic3r::GUI::DiffPresetDialog::update_tree(), Slic3r::GUI::UnsavedChangesDialog::update_tree(), and Slic3r::GUI::UnsavedChangesDialog::update_tree().

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

◆ init()

void Slic3r::Search::SettingsIndex::init ( std::vector< InputInfo > input_values)
137{
138 m_options.clear();
139 m_all_modes.clear();
140 for (auto i : input_values) append_options(i.config, i.type, i.mode);
141 sort_options();
142}

References append_options(), m_all_modes, m_options, and sort_options().

Here is the call graph for this function:

◆ option_at()

const Option & Slic3r::Search::SettingsIndex::option_at ( size_t pos) const
inline
110{ return m_options[pos]; }

References m_options.

◆ options()

const std::vector< Option > & Slic3r::Search::SettingsIndex::options ( ) const
inline
108{ return m_options; }

References m_options.

◆ set_line_label()

void Slic3r::Search::SettingsIndex::set_line_label ( const std::string & opt_key,
Preset::Type type,
const wxString & label,
const wxString & label_en )
254{
255 if (label.IsEmpty())
256 return;
257 GroupAndCategory &gc = m_groups_and_categories[get_key(opt_key, type)];
258 gc.line_label = label;
259 gc.line_label_en = label_en;
260}

References Slic3r::Search::get_key(), Slic3r::Search::GroupAndCategory::line_label, Slic3r::Search::GroupAndCategory::line_label_en, and m_groups_and_categories.

Referenced by Slic3r::GUI::OptionsGroup::append_line().

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

◆ set_path()

void Slic3r::Search::SettingsIndex::set_path ( const std::string & opt_key,
Preset::Type type,
const std::string & path )
247{
248 if (path.empty())
249 return;
250 m_groups_and_categories[get_key(opt_key, type)].path = path;
251}

References Slic3r::Search::get_key(), and m_groups_and_categories.

Referenced by Slic3r::GUI::OptionsGroup::append_line().

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

◆ sort_options()

void Slic3r::Search::SettingsIndex::sort_options ( )
private
117{
118 // Both views are label-sorted and multi_category-marked. They are separate consumers (the sidebar
119 // search and the Speed Dial); keeping them in sync here prevents the all-modes view from silently
120 // diverging in order or flags.
121 auto sort_and_mark = [](std::vector<Option> &v) {
122 std::sort(v.begin(), v.end(), [](const Option &o1, const Option &o2) { return o1.label < o2.label; });
123 Option *last = nullptr;
124 for (auto &opt : v) {
125 if (last && last->label == opt.label && last->group == opt.group && last->type == opt.type && last->category != opt.category) {
126 last->multi_category = true;
127 opt.multi_category = true;
128 }
129 last = &opt;
130 }
131 };
132 sort_and_mark(m_options);
133 sort_and_mark(m_all_modes);
134}

References Slic3r::Search::Option::category, Slic3r::Search::Option::group, Slic3r::Search::Option::label, m_all_modes, m_options, Slic3r::Search::Option::multi_category, and Slic3r::Search::Option::type.

Referenced by apply(), init(), and sort_options_by_label().

Here is the caller graph for this function:

◆ sort_options_by_key()

void Slic3r::Search::SettingsIndex::sort_options_by_key ( )
inline
118 {
119 std::sort(m_options.begin(), m_options.end(), [](const Option &o1, const Option &o2) { return o1.key < o2.key; });
120 }

References m_options.

Referenced by Slic3r::GUI::DiffPresetDialog::update_tree(), Slic3r::GUI::UnsavedChangesDialog::update_tree(), and Slic3r::GUI::UnsavedChangesDialog::update_tree().

Here is the caller graph for this function:

◆ sort_options_by_label()

void Slic3r::Search::SettingsIndex::sort_options_by_label ( )
inline
121{ sort_options(); }

References sort_options().

Referenced by Slic3r::GUI::DiffPresetDialog::update_tree(), and Slic3r::GUI::UnsavedChangesDialog::update_tree().

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

Member Data Documentation

◆ m_all_modes

std::vector<Option> Slic3r::Search::SettingsIndex::m_all_modes
private

◆ m_groups_and_categories

std::map<std::string, GroupAndCategory> Slic3r::Search::SettingsIndex::m_groups_and_categories
private

◆ m_options

std::vector<Option> Slic3r::Search::SettingsIndex::m_options
private

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