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

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

Collaboration diagram for Slic3r::Search::OptionsSearcher:

Public Member Functions

 OptionsSearcher ()
 ~OptionsSearcher ()
SettingsIndex & index ()
const SettingsIndex & index () const
void init (std::vector< InputInfo > input_values)
void apply (DynamicPrintConfig *config, Preset::Type type, ConfigOptionMode mode)
bool search ()
bool search (const std::string &search, bool force=false, Preset::Type type=Preset::TYPE_INVALID)
size_t size () const
const FoundOption & operator[] (const size_t pos) const noexcept
const Option & get_option (size_t pos_in_filter) const
const std::vector< FoundOption > & found_options ()
std::string & search_string ()
void set_printer_technology (PrinterTechnology pt)
void show_dialog (Preset::Type type, wxWindow *parent, TextInput *input, wxWindow *ssearch_btn)
void dlg_sys_color_changed ()
void dlg_msw_rescale ()

Public Attributes

OptionViewParameters view_params
SearchDialog * search_dialog {nullptr}

Private Member Functions

void sort_found ()
size_t found_size () const

Private Attributes

SettingsIndex m_index
std::string search_line
Preset::Type search_type = Preset::TYPE_INVALID
PrinterTechnology printer_technology
std::vector< FoundOption > found {}

Detailed Description

Constructor & Destructor Documentation

◆ OptionsSearcher()

Slic3r::Search::OptionsSearcher::OptionsSearcher ( )
248{}

◆ ~OptionsSearcher()

Slic3r::Search::OptionsSearcher::~OptionsSearcher ( )
250{}

Member Function Documentation

◆ apply()

void Slic3r::Search::OptionsSearcher::apply ( DynamicPrintConfig * config,
Preset::Type type,
ConfigOptionMode mode )
260{
261 if (m_index.apply(config, type, mode))
263}
SettingsIndex m_index
Definition Search.hpp:74
Preset::Type search_type
Definition Search.hpp:77
std::string search_line
Definition Search.hpp:76
bool search()
Definition Search.cpp:125

References m_index, search(), search_line, and search_type.

Here is the call graph for this function:

◆ dlg_msw_rescale()

void Slic3r::Search::OptionsSearcher::dlg_msw_rescale ( )
292{
293 if (search_dialog) search_dialog->msw_rescale();
294}
SearchDialog * search_dialog
Definition Search.hpp:92

References search_dialog.

◆ dlg_sys_color_changed()

void Slic3r::Search::OptionsSearcher::dlg_sys_color_changed ( )
286{
287 /*if (search_dialog)
288 search_dialog->on_sys_color_changed();*/
289}

◆ found_options()

const std::vector< FoundOption > & Slic3r::Search::OptionsSearcher::found_options ( )
inline
112{ return found; }
std::vector< FoundOption > found
Definition Search.hpp:79

References found.

◆ found_size()

size_t Slic3r::Search::OptionsSearcher::found_size ( ) const
inlineprivate
87{ return found.size(); }

References found.

Referenced by size().

Here is the caller graph for this function:

◆ get_option()

const Option & Slic3r::Search::OptionsSearcher::get_option ( size_t pos_in_filter) const
266{
267 assert(pos_in_filter != size_t(-1) && found[pos_in_filter].option_idx != size_t(-1));
268 return m_index.option_at(found[pos_in_filter].option_idx);
269}

References found, and m_index.

◆ index() [1/2]

SettingsIndex & Slic3r::Search::OptionsSearcher::index ( )
inline
97{ return m_index; }

References m_index.

◆ index() [2/2]

const SettingsIndex & Slic3r::Search::OptionsSearcher::index ( ) const
inline
98{ return m_index; }

References m_index.

◆ init()

void Slic3r::Search::OptionsSearcher::init ( std::vector< InputInfo > input_values)
253{
254 m_index.init(std::move(input_values));
255
257}

References m_index, search(), search_line, and search_type.

Here is the call graph for this function:

◆ operator[]()

const FoundOption & Slic3r::Search::OptionsSearcher::operator[] ( const size_t pos) const
inlinenoexcept
109{ return found[pos]; }
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References found.

◆ search() [1/2]

bool Slic3r::Search::OptionsSearcher::search ( )
125{ return search(search_line, true); }

References search(), and search_line.

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

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

◆ search() [2/2]

bool Slic3r::Search::OptionsSearcher::search ( const std::string & search,
bool force = false,
Preset::Type type = Preset::TYPE_INVALID )
143{
144 if (search_line == search && search_type == type && !force) return false;
145
146 found.clear();
147
148 bool full_list = search.empty();
149 wxString sep = L" : ";
150
151 auto get_label = [this, &sep](const Option &opt, bool marked = true) {
152 std::wstring out;
153 if (marked) out += marker_by_type(opt.type, printer_technology);
154 const std::wstring *prev = nullptr;
155 for (const std::wstring *const s : {view_params.category || opt.multi_category ? &opt.category_local : nullptr, &opt.group_local, &opt.label_local})
156 if (s != nullptr && (prev == nullptr || *prev != *s)) {
157 if (out.size() > 2) out += sep;
158 out += *s;
159 prev = s;
160 }
161 return out;
162 };
163
164 auto get_label_english = [this, &sep](const Option &opt, bool marked = true) {
165 std::wstring out;
166 if (marked) out += marker_by_type(opt.type, printer_technology);
167 const std::wstring *prev = nullptr;
168 for (const std::wstring *const s : {view_params.category || opt.multi_category ? &opt.category : nullptr, &opt.group, &opt.label})
169 if (s != nullptr && (prev == nullptr || *prev != *s)) {
170 if (out.size() > 2) out += sep;
171 out += *s;
172 prev = s;
173 }
174 return out;
175 };
176
177 auto get_tooltip = [this, &sep](const Option &opt) {
178 return wxString(marker_by_type(opt.type, printer_technology)) + opt.category_local + sep + opt.group_local + sep + opt.label_local;
179 };
180
181 std::vector<uint16_t> matches, matches2;
182 const std::vector<Option> &options = m_index.options();
183 for (size_t i = 0; i < options.size(); i++) {
184 const Option &opt = options[i];
185 if (full_list) {
186 std::string label = into_u8(get_label(opt));
187 //all
188 if (type == Preset::TYPE_INVALID) {
189 found.emplace_back(FoundOption{label, label, into_u8(get_tooltip(opt)), i, 0});
190 } else if (type == opt.type){
191 found.emplace_back(FoundOption{label, label, into_u8(get_tooltip(opt)), i, 0});
192 }
193
194 continue;
195 }
196
197 std::wstring wsearch = boost::nowide::widen(search);
198 boost::trim_left(wsearch);
199 std::wstring label = get_label(opt, false);
200 std::wstring label_english = get_label_english(opt, false);
201 int score = std::numeric_limits<int>::min();
202 int score2;
203 matches.clear();
204 fuzzy_match(wsearch, label, score, matches);
205 // bbs hide the contents in parentheses
206 /* if (fuzzy_match(wsearch, opt.key, score2, matches2) && score2 > score) {
207 for (fts::pos_type &pos : matches2) pos += label.size() + 1;
208 label += L"(" + opt.key + L")";
209 append(matches, matches2);
210 score = score2;
211 }*/
212 if (view_params.english && fuzzy_match(wsearch, label_english, score2, matches2) && score2 > score) {
213 label = std::move(label_english);
214 matches = std::move(matches2);
215 score = score2;
216 }
217 if (score > 90 /*std::numeric_limits<int>::min()*/) {
218 label = mark_string(label, matches, opt.type, printer_technology);
219 //label += L" [" + std::to_wstring(score) + L"]"; // add score value
220 std::string label_u8 = into_u8(label);
221 std::string label_plain = label_u8;
222
223#ifdef SUPPORTS_MARKUP
224 boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)), "<b>");
225 boost::replace_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)), "</b>");
226#else
227 boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerStart)));
228 boost::erase_all(label_plain, std::string(1, char(ImGui::ColorMarkerEnd)));
229#endif
230
231 if (type == Preset::TYPE_INVALID) {
232 found.emplace_back(FoundOption{label_plain, label_u8, into_u8(get_tooltip(opt)), i, score});
233 } else if (type == opt.type) {
234 found.emplace_back(FoundOption{label_plain, label_u8, into_u8(get_tooltip(opt)), i, score});
235 }
236
237 }
238 }
239
240 if (!full_list) sort_found();
241
243 if (search_type != type) search_type = type;
244
245 return true;
246}
#define L(s)
Definition ExtrusionEntity.cpp:25
@ TYPE_INVALID
Definition Preset.hpp:245
void sort_found()
Definition Search.hpp:81
OptionViewParameters view_params
Definition Search.hpp:90
PrinterTechnology printer_technology
Definition Search.hpp:78
static char marker_by_type(Preset::Type type, PrinterTechnology pt)
Definition Search.cpp:79
static bool fuzzy_match(const std::wstring &search_pattern, const std::wstring &label, int &out_score, std::vector< uint16_t > &out_matches)
Definition Search.cpp:127
static std::wstring mark_string(const std::wstring &str, const std::vector< uint16_t > &matches, Preset::Type type, PrinterTechnology pt)
Definition Search.cpp:98
std::string into_u8(const wxString &str)
Definition GUI.cpp:549

References found, Slic3r::Search::fuzzy_match(), Slic3r::into_u8(), L, m_index, Slic3r::Search::mark_string(), Slic3r::Search::marker_by_type(), printer_technology, search(), search_line, search_type, sort_found(), Slic3r::Preset::TYPE_INVALID, and view_params.

Here is the call graph for this function:

◆ search_string()

std::string & Slic3r::Search::OptionsSearcher::search_string ( )
inline
113{ return search_line; }

References search_line.

◆ set_printer_technology()

void Slic3r::Search::OptionsSearcher::set_printer_technology ( PrinterTechnology pt)
inline
115{ printer_technology = pt; }

References printer_technology.

◆ show_dialog()

void Slic3r::Search::OptionsSearcher::show_dialog ( Preset::Type type,
wxWindow * parent,
TextInput * input,
wxWindow * ssearch_btn )
272{
273 if (parent == nullptr || input == nullptr) return;
274 auto search_dialog = new SearchDialog(this, type, parent, input, ssearch_btn);
275 wxPoint pos = input->GetParent()->ClientToScreen(wxPoint(0, 0));
276#ifndef __WXGTK__
277 pos.y += input->GetParent()->GetRect().height;
278#else
279 input->GetParent()->Hide();
280#endif
281 search_dialog->SetPosition(pos);
282 search_dialog->Popup();
283}

References search_dialog.

◆ size()

size_t Slic3r::Search::OptionsSearcher::size ( ) const
inline
107{ return found_size(); }
size_t found_size() const
Definition Search.hpp:87

References found_size().

Referenced by Slic3r::GUI::Plater::search_string_getter().

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

◆ sort_found()

void Slic3r::Search::OptionsSearcher::sort_found ( )
inlineprivate
82 {
83 std::sort(found.begin(), found.end(),
84 [](const FoundOption &f1, const FoundOption &f2) { return f1.outScore > f2.outScore || (f1.outScore == f2.outScore && f1.label < f2.label); });
85 };

References found.

Referenced by search().

Here is the caller graph for this function:

Member Data Documentation

◆ found

std::vector<FoundOption> Slic3r::Search::OptionsSearcher::found {}
private

◆ m_index

SettingsIndex Slic3r::Search::OptionsSearcher::m_index
private

◆ printer_technology

PrinterTechnology Slic3r::Search::OptionsSearcher::printer_technology
private

Referenced by search(), and set_printer_technology().

◆ search_dialog

SearchDialog* Slic3r::Search::OptionsSearcher::search_dialog {nullptr}
92{nullptr};

Referenced by dlg_msw_rescale(), and show_dialog().

◆ search_line

std::string Slic3r::Search::OptionsSearcher::search_line
private

◆ search_type

Preset::Type Slic3r::Search::OptionsSearcher::search_type = Preset::TYPE_INVALID
private

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

◆ view_params

OptionViewParameters Slic3r::Search::OptionsSearcher::view_params

Referenced by search().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Search.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Search.cpp