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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
|
#ifndef slic3r_SearchComboBox_hpp_
#define slic3r_SearchComboBox_hpp_
#include <vector>
#include <map>
#include <boost/nowide/convert.hpp>
#include <wx/panel.h>
#include <wx/sizer.h>
#include <wx/listctrl.h>
#include <wx/combo.h>
#include <wx/checkbox.h>
#include <wx/dialog.h>
#include "GUI_Utils.hpp"
#include "wxExtensions.hpp"
#include "libslic3r/Preset.hpp"
namespace Slic3r {
wxDECLARE_EVENT(wxCUSTOMEVT_JUMP_TO_OPTION, wxCommandEvent);
namespace Search{
class SearchDialog;
struct InputInfo
{
DynamicPrintConfig* config {nullptr};
Preset::Type type {Preset::TYPE_INVALID};
ConfigOptionMode mode {comSimple};
};
struct GroupAndCategory {
wxString group;
wxString category;
};
struct Option {
//private:
//Option() {}
//public:
// bool operator<(const Option& other) const { return other.label > this->label; }
bool operator<(const Option& other) const { return other.key > this->key; }
// Fuzzy matching works at a character level. Thus matching with wide characters is a safer bet than with short characters,
// though for some languages (Chinese?) it may not work correctly.
std::wstring key;
Preset::Type type {Preset::TYPE_INVALID};
ConfigOptionMode tags;
std::wstring label;
std::wstring label_local;
std::wstring group;
std::wstring group_local;
std::wstring category;
std::wstring category_local;
std::wstring tooltip;
std::wstring tooltip_local;
std::string opt_key() const;
};
struct FoundOption {
// UTF8 encoding, to be consumed by ImGUI by reference.
std::string label;
std::string marked_label;
std::string tooltip;
size_t option_idx {0};
int outScore {0};
// Returning pointers to contents of std::string members, to be used by ImGUI for rendering.
void get_marked_label_and_tooltip(const char** label, const char** tooltip) const;
};
struct OptionViewParameters
{
bool category {true};
bool english {false};
bool exact {false};
bool all_mode {true};
int hovered_id {0};
};
class OptionsSearcher
{
std::string search_line;
std::map<std::string, GroupAndCategory> groups_and_categories;
PrinterTechnology printer_technology;
ConfigOptionMode current_tags;
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 || (f1.outScore == f2.outScore && f1.label < f2.label); });
};
size_t options_size() const { return options.size(); }
size_t found_size() const { return found.size(); }
public:
OptionViewParameters view_params;
SearchDialog* search_dialog { nullptr };
OptionsSearcher();
~OptionsSearcher();
void init(std::vector<InputInfo> input_values, ConfigOptionMode current_tags);
void apply(DynamicPrintConfig *config,
Preset::Type type,
ConfigOptionMode mode);
bool search();
bool search(const std::string& search, bool force = false);
void add_key(const std::string& opt_key, Preset::Type type, 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 Option& get_option(const std::string& opt_key, Preset::Type type) const;
Option get_option(const std::string& opt_key, const wxString& label, Preset::Type type) 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]; }
std::string& search_string() { return search_line; }
void set_printer_technology(PrinterTechnology pt) { printer_technology = pt; }
void sort_options_by_key() {
std::sort(options.begin(), options.end(), [](const Option& o1, const Option& o2) {
return o1.key < o2.key; });
}
void sort_options_by_label() { sort_options(); }
void show_dialog();
void dlg_sys_color_changed();
void dlg_msw_rescale();
static void register_label_override(t_config_option_key key, std::string label, std::string full_label, std::string tooltip) {
label_override.insert({ key, {label, full_label, tooltip} });
}
private:
inline static std::unordered_map< t_config_option_key, std::array<std::string, 3>> label_override;};
//------------------------------------------
// SearchDialog
//------------------------------------------
class SearchListModel;
class SearchDialog : public GUI::DPIDialog
{
wxString search_str;
wxString default_string;
bool prevent_list_events {false};
wxTextCtrl* search_line { nullptr };
wxDataViewCtrl* search_list { nullptr };
SearchListModel* search_list_model { nullptr };
wxCheckBox* check_category { nullptr };
wxCheckBox* check_english { nullptr };
wxCheckBox* check_exact { nullptr };
wxCheckBox* check_all_mode { nullptr };
OptionsSearcher* searcher { nullptr };
void OnInputText(wxCommandEvent& event);
void OnLeftUpInTextCtrl(wxEvent& event);
void OnKeyDown(wxKeyEvent& event);
void OnActivate(wxDataViewEvent& event);
void OnSelect(wxDataViewEvent& event);
void OnCheck(wxCommandEvent& event);
void OnMotion(wxMouseEvent& event);
void OnLeftDown(wxMouseEvent& event);
void update_list();
public:
SearchDialog(OptionsSearcher* searcher);
~SearchDialog() {}
void Popup(wxPoint position = wxDefaultPosition);
void ProcessSelection(wxDataViewItem selection);
void msw_rescale();
void on_sys_color_changed() override;
protected:
void on_dpi_changed(const wxRect& suggested_rect) override { msw_rescale(); }
};
// ----------------------------------------------------------------------------
// SearchListModel
// ----------------------------------------------------------------------------
class SearchListModel : public wxDataViewVirtualListModel
{
std::vector<std::pair<wxString, int>> m_values;
ScalableBitmap m_icon[5];
public:
enum {
colIcon,
colMarkedText,
colMax
};
SearchListModel(wxWindow* parent);
// helper methods to change the model
void Clear();
void Prepend(const std::string& text);
void msw_rescale();
// implementation of base class virtuals to define model
unsigned int GetColumnCount() const override { return colMax; }
wxString GetColumnType(unsigned int col) const override;
void GetValueByRow(wxVariant& variant, unsigned int row, unsigned int col) const override;
bool GetAttrByRow(unsigned int row, unsigned int col, wxDataViewItemAttr& attr) const override { return true; }
bool SetValueByRow(const wxVariant& variant, unsigned int row, unsigned int col) override { return false; }
};
} // Search namespace
}
#endif //slic3r_SearchComboBox_hpp_
|