1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
#ifndef slic3r_SearchComboBox_hpp_
#define slic3r_SearchComboBox_hpp_
#include <vector>
#include <map>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/listctrl.h>
#include <wx/combo.h>
#include "Preset.hpp"
#include "wxExtensions.hpp"
namespace Slic3r {
namespace Search{
struct InputInfo
{
DynamicPrintConfig* config {nullptr};
Preset::Type type {Preset::TYPE_INVALID};
ConfigOptionMode mode {comSimple};
};
struct GroupAndCategory {
wxString group;
wxString category;
};
// fuzzy_match flag
enum FMFlag
{
fmUndef = 0, // didn't find
fmOptKey,
fmLabel,
fmLabelLocal,
fmGroup,
fmGroupLocal,
fmCategory,
fmCategoryLocal
};
struct Option {
bool operator<(const Option& other) const { return other.label > this->label; }
bool operator>(const Option& other) const { return other.label < this->label; }
std::string opt_key;
Preset::Type type {Preset::TYPE_INVALID};
wxString label;
wxString label_local;
wxString group;
wxString group_local;
wxString category;
wxString category_local;
FMFlag fuzzy_match_simple(char const *search_pattern) const;
FMFlag fuzzy_match_simple(const wxString& search) const;
FMFlag fuzzy_match_simple(const std::string &search) const;
FMFlag fuzzy_match(char const *search_pattern, int &outScore) const;
FMFlag fuzzy_match(const wxString &search, int &outScore) const ;
FMFlag fuzzy_match(const std::string &search, int &outScore) const ;
};
struct FoundOption {
wxString label;
wxString marked_label;
size_t option_idx {0};
int outScore {0};
void get_label(const char** out_text) const;
void get_marked_label(const char** out_text) const;
};
class OptionsSearcher
{
std::string search_line;
std::map<std::string, GroupAndCategory> groups_and_categories;
std::vector<Option> options {};
std::vector<FoundOption> found {};
void append_options(DynamicPrintConfig* config, Preset::Type type, ConfigOptionMode mode);
void sort_options() {
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
return o1.label < o2.label; });
}
void sort_found() {
std::sort(found.begin(), found.end(), [](const FoundOption& f1, const FoundOption& f2) {
return f1.outScore > f2.outScore; });
};
size_t options_size() const { return options.size(); }
size_t found_size() const { return found.size(); }
public:
bool category{ false };
bool group{ true };
void init(std::vector<InputInfo> input_values);
void apply(DynamicPrintConfig *config,
Preset::Type type,
ConfigOptionMode mode);
bool search(const std::string& search, bool force = false);
void add_key(const std::string& opt_key, const wxString& group, const wxString& category);
size_t size() const { return found_size(); }
const FoundOption& operator[](const size_t pos) const noexcept { return found[pos]; }
const Option& get_option(size_t pos_in_filter) const;
const std::vector<FoundOption>& found_options() { return found; }
const GroupAndCategory& get_group_and_category (const std::string& opt_key) { return groups_and_categories[opt_key]; }
};
class SearchComboPopup : public wxListBox, public wxComboPopup
{
public:
// Initialize member variables
void Init();
// Create popup control
virtual bool Create(wxWindow* parent);
// Return pointer to the created control
virtual wxWindow* GetControl() { return this; }
// Translate string into a list selection
virtual void SetStringValue(const wxString& s);
// Get list selection as a string
virtual wxString GetStringValue() const {
// we shouldn't change a combo control's string
return m_input_string;
}
void ProcessSelection(int selection);
// Do mouse hot-tracking (which is typical in list popups)
void OnMouseMove(wxMouseEvent& event);
// On mouse left up, set the value and close the popup
void OnMouseClick(wxMouseEvent& WXUNUSED(event));
// process Up/Down arrows and Enter press
void OnKeyDown(wxKeyEvent& event);
protected:
wxString m_input_string;
};
class SearchCtrl : public wxComboCtrl
{
SearchComboPopup* popupListBox {nullptr};
bool prevent_update { false };
wxString default_string;
bool editing {false};
void PopupList(wxCommandEvent& event);
void OnInputText(wxCommandEvent& event);
void OnSelect(wxCommandEvent& event);
void OnLeftUpInTextCtrl(wxEvent& event);
public:
SearchCtrl(wxWindow* parent);
~SearchCtrl() {}
void set_search_line(const std::string& search_line);
void msw_rescale();
void update_list(const std::vector<FoundOption>& filters);
};
} // Search namespace
}
#endif //slic3r_SearchComboBox_hpp_
|