OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::SavePresetDialog::Item Class Reference
Inheritance diagram for Slic3r::GUI::SavePresetDialog::Item:
Collaboration diagram for Slic3r::GUI::SavePresetDialog::Item:

Public Types

enum  ValidationType { Valid , NoValid , Warning }

Public Member Functions

 Item (Preset::Type type, const std::string &suffix, wxBoxSizer *sizer, SavePresetDialog *parent)
void update_valid_bmp ()
void accept ()
virtual void DoSetSize (int x, int y, int width, int height, int sizeFlags=wxSIZE_AUTO)
bool is_valid () const
Preset::Type type () const
std::string preset_name () const
bool save_to_project () const
bool is_detached () const
void update ()

Public Attributes

Preset::Type m_type
ValidationType m_valid_type
std::string m_preset_name
SavePresetDialog * m_parent {nullptr}
wxStaticBitmap * m_valid_bmp {nullptr}
wxComboBox * m_combo {nullptr}
TextInput * m_input_ctrl {nullptr}
wxStaticText * m_valid_label {nullptr}
PresetCollection * m_presets {nullptr}
bool m_save_to_project {false}
RadioGroup * m_radio_group
bool m_detach {false}

Detailed Description

Member Enumeration Documentation

◆ ValidationType

Enumerator
Valid 
NoValid 
Warning 
45 {
46 Valid,
47 NoValid,
49 };
@ NoValid
Definition SavePresetDialog.hpp:47
@ Warning
Definition SavePresetDialog.hpp:48
@ Valid
Definition SavePresetDialog.hpp:46

Constructor & Destructor Documentation

◆ Item()

Slic3r::GUI::SavePresetDialog::Item::Item ( Preset::Type type,
const std::string & suffix,
wxBoxSizer * sizer,
SavePresetDialog * parent )
53 : m_type(type), m_parent(parent)
54{
55 Tab *tab = wxGetApp().get_tab(m_type);
56 assert(tab);
57 m_presets = tab->get_presets();
58
59 const Preset &sel_preset = m_presets->get_selected_preset();
60 std::string preset_name = sel_preset.is_default ? _u8L("Untitled") : sel_preset.is_system ? (boost::format(("%1% - %2%")) % sel_preset.name % suffix).str() : sel_preset.is_from_bundle() && !sel_preset.alias.empty() ? sel_preset.alias : sel_preset.name;
61
62 // if name contains extension
63 if (boost::iends_with(preset_name, ".ini")) {
64 size_t len = preset_name.length() - 4;
65 preset_name.resize(len);
66 }
67
68 std::vector<std::string> values;
69 for (const Preset &preset : *m_presets) {
70 // BBS: add project embedded preset logic and refine is_external
71 if (preset.is_default || preset.is_system)
72 // if (preset.is_default || preset.is_system || preset.is_external)
73 continue;
74 values.push_back(preset.name);
75 }
76
77 wxStaticText *label_top = new wxStaticText(m_parent, wxID_ANY, from_u8((boost::format(_utf8(L("Save %s as"))) % into_u8(tab->title())).str()));
78 label_top->SetFont(::Label::Body_14);
79 label_top->SetForegroundColour(wxColour(38,46,48));
80
81
82 // m_valid_bmp = new wxStaticBitmap(m_parent, wxID_ANY, create_scaled_bitmap("blank_16", m_parent));
83 //
84 // m_combo = new wxComboBox(m_parent, wxID_ANY, from_u8(preset_name), wxDefaultPosition, wxSize(35 * wxGetApp().em_unit(), -1));
85 // for (const std::string& value : values)
86 // m_combo->Append(from_u8(value));
87 //
88 // m_combo->Bind(wxEVT_TEXT, [this](wxCommandEvent&) { update(); });
89 //#ifdef __WXOSX__
90 // // Under OSX wxEVT_TEXT wasn't invoked after change selection in combobox,
91 // // So process wxEVT_COMBOBOX too
92 // m_combo->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent&) { update(); });
93 //#endif //__WXOSX__
94 // wxBoxSizer *combo_sizer = new wxBoxSizer(wxHORIZONTAL);
95 // combo_sizer->Add(m_valid_bmp, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W);
96 // combo_sizer->Add(m_combo, 1, wxEXPAND, BORDER_W);
97
98
99
100 wxBoxSizer *input_sizer_h = new wxBoxSizer(wxHORIZONTAL);
101 wxBoxSizer *input_sizer_v = new wxBoxSizer(wxVERTICAL);
102
103 /*m_input_ctrl = new wxTextCtrl(this, wxID_ANY, from_u8(preset_name), wxDefaultPosition, wxDefaultSize,wxBORDER_NONE);*/
104
105
106 m_input_ctrl = new ::TextInput(parent, from_u8(preset_name), wxEmptyString, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
107 StateColor input_bg(std::pair<wxColour, int>(wxColour("#F0F0F1"), StateColor::Disabled), std::pair<wxColour, int>(*wxWHITE, StateColor::Enabled));
108 m_input_ctrl->SetBackgroundColor(input_bg);
109 m_input_ctrl->Bind(wxEVT_TEXT, [this](wxCommandEvent &) { update(); });
110 m_input_ctrl->SetMinSize(wxSize(SAVE_PRESET_DIALOG_INPUT_SIZE));
111 m_input_ctrl->SetMaxSize(wxSize(SAVE_PRESET_DIALOG_INPUT_SIZE));
112
113
114 input_sizer_v->Add(m_input_ctrl, 1, wxEXPAND, 0);
115 input_sizer_h->Add(input_sizer_v, 1, wxALIGN_CENTER, 0);
116 input_sizer_h->Layout();
117
118 m_valid_label = new wxStaticText(m_parent, wxID_ANY, "");
119 m_valid_label->SetForegroundColour(wxColor(255, 111, 0));
120
121 sizer->Add(label_top, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, BORDER_W);
122 sizer->Add(input_sizer_h, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, BORDER_W);
123 sizer->Add(m_valid_label, 0, wxEXPAND | wxLEFT | wxRIGHT, BORDER_W);
124
125 if (m_type == Preset::TYPE_PRINTER) m_parent->add_info_for_edit_ph_printer(sizer);
126
127 // ORCA RadioGroup
128 m_radio_group = new RadioGroup(m_parent, {
129 _L("User Preset"), // 0
130 _L("Preset Inside Project") // 1
131 }, wxVERTICAL);
132
133 sizer->Add(m_radio_group, 0, wxEXPAND | wxTOP | wxLEFT, BORDER_W);
134
135 if (parent->m_mode == comDevelop) {
136 // A new user copy of a system preset inherits from the selected system preset.
137 const std::string parent_name = sel_preset.is_system ? sel_preset.name : sel_preset.inherits();
138 const bool has_parent = !parent_name.empty();
139
140 wxBoxSizer *detach_sizer = new wxBoxSizer(wxHORIZONTAL);
141
142 auto detach_tooltip = _L("Copies all inherited values from the parent into this preset and removes the parent relationship. Presets compatible only with the parent may become unsupported.");
143
144 auto detach_checkbox = new ::CheckBox(parent);
145 detach_checkbox->SetToolTip(detach_tooltip);
146
147 auto detach_label = new wxStaticText(parent, wxID_ANY, has_parent ? _L("Detach from parent") : _L("Save without parent"));
148 detach_label->SetFont(::Label::Body_14);
149 detach_label->SetForegroundColour(wxColour("#363636"));
150 detach_label->SetToolTip(detach_tooltip);
151
152 detach_sizer->Add(detach_checkbox, 0, wxALIGN_LEFT | wxLEFT, BORDER_W);
153 detach_sizer->Add(detach_label , 0, wxALIGN_CENTRE_VERTICAL | wxLEFT, FromDIP(5));
154 sizer->Add(detach_sizer, 0, wxEXPAND | wxTOP, BORDER_W);
155 sizer->AddSpacer(FromDIP(5));
156
157 const wxString parent_text = has_parent ? from_u8(parent_name) : _L("Unique preset");
158 auto parent_label = new wxStaticText(parent, wxID_ANY, parent_text);
159 parent_label->SetFont(::Label::Body_12);
160 parent_label->SetForegroundColour(wxColour("#6B6B6B"));
161 parent_label->SetToolTip(has_parent ? _L("Parent preset") : _L("This preset does not inherit from another preset."));
162 sizer->Add(parent_label, 0, wxEXPAND | wxLEFT, BORDER_W + FromDIP(24));
163
164 sizer->AddSpacer(FromDIP(5));
165
166 // Set initial state (unchecked by default)
167 detach_checkbox->SetValue(m_detach);
168 // Bind the checkbox event to update the detach state for this item
169 detach_checkbox->Bind(wxEVT_TOGGLEBUTTON, [this, detach_checkbox](wxCommandEvent& event) {
170 m_detach = detach_checkbox->GetValue();
171 event.Skip(); // Let CheckBox update its bitmap for the new state.
172 });
173
174 auto on_toggle = [detach_checkbox]() {
175 detach_checkbox->SetValue(!detach_checkbox->GetValue());
176 wxCommandEvent ev(wxEVT_TOGGLEBUTTON, detach_checkbox->GetId());
177 ev.SetEventObject(detach_checkbox);
178 detach_checkbox->GetEventHandler()->ProcessEvent(ev);
179 };
180 detach_label->Bind(wxEVT_LEFT_DOWN, [on_toggle](wxMouseEvent& e) {if(!e.LeftDClick()) on_toggle();});
181 detach_label->Bind(wxEVT_LEFT_DCLICK, [on_toggle](wxMouseEvent& e) {on_toggle();});
182 }
183
184 m_radio_group->Bind(wxEVT_COMMAND_RADIOBOX_SELECTED, [this](wxCommandEvent &e) {
185 m_save_to_project = m_radio_group->GetSelection() == 1;
186 });
187
188 bool is_project_embedded = m_presets->get_edited_preset().is_project_embedded;
189 m_radio_group->SetSelection(is_project_embedded ? 1 : 0);
190
191 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ", create item: type" << Preset::get_type_string(m_type) << ", preset " << m_preset_name
192 << ", is_project_embedded = " << is_project_embedded;
193 update();
194}
#define BORDER_W
Definition BitmapComboBox.cpp:48
#define L(s)
Definition ExtrusionEntity.cpp:25
#define _L(s)
Definition OBJ.cpp:34
class WXDLLIMPEXP_FWD_CORE wxStaticText
Definition ProgressDialog.hpp:30
#define SAVE_PRESET_DIALOG_INPUT_SIZE
Definition SavePresetDialog.hpp:25
static wxFont Body_12
Definition Label.hpp:55
static wxFont Body_14
Definition Label.hpp:53
bool m_save_to_project
Definition SavePresetDialog.hpp:79
wxStaticText * m_valid_label
Definition SavePresetDialog.hpp:74
Preset::Type type() const
Definition SavePresetDialog.hpp:58
bool m_detach
Definition SavePresetDialog.hpp:81
PresetCollection * m_presets
Definition SavePresetDialog.hpp:76
Preset::Type m_type
Definition SavePresetDialog.hpp:66
void update()
Definition SavePresetDialog.cpp:196
SavePresetDialog * m_parent
Definition SavePresetDialog.hpp:70
TextInput * m_input_ctrl
Definition SavePresetDialog.hpp:73
RadioGroup * m_radio_group
Definition SavePresetDialog.hpp:80
std::string m_preset_name
Definition SavePresetDialog.hpp:68
std::string preset_name() const
Definition SavePresetDialog.hpp:59
static std::string get_type_string(Preset::Type type)
Definition Preset.cpp:590
@ TYPE_PRINTER
Definition Preset.hpp:250
@ Disabled
Definition StateColor.hpp:22
@ Enabled
Definition StateColor.hpp:17
wxMouseEvent
Definition CameraPopup.cpp:47
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
std::string into_u8(const wxString &str)
Definition GUI.cpp:549
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
@ comDevelop
Definition Config.hpp:225
@ Preset
Definition calib.hpp:39
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273
#define _utf8(s)
Definition I18N.hpp:10
#define _u8L(s)
Definition I18N.hpp:11

References Slic3r::GUI::SavePresetDialog::SavePresetDialog(), _L, _u8L, _utf8, Slic3r::Preset::alias, Label::Body_12, Label::Body_14, BORDER_W, Slic3r::comDevelop, StateColor::Disabled, StateColor::Enabled, Slic3r::GUI::from_u8(), Slic3r::GUI::Tab::get_presets(), Slic3r::Preset::get_type_string(), Slic3r::Preset::inherits(), Slic3r::GUI::into_u8(), Slic3r::Preset::is_default, Slic3r::Preset::is_from_bundle(), Slic3r::Preset::is_system, L, m_detach, m_input_ctrl, Slic3r::GUI::SavePresetDialog::m_mode, m_parent, m_preset_name, m_presets, m_radio_group, m_save_to_project, m_type, m_valid_label, Slic3r::Preset::name, preset_name(), SAVE_PRESET_DIALOG_INPUT_SIZE, Slic3r::GUI::Tab::title(), type(), Slic3r::Preset::TYPE_PRINTER, update(), Slic3r::GUI::wxMouseEvent, and wxStaticText.

Here is the call graph for this function:

Member Function Documentation

◆ accept()

void Slic3r::GUI::SavePresetDialog::Item::accept ( )
292{
293 if (m_valid_type == Warning) {
294 auto it = m_presets->find_preset(m_preset_name, false);
295 Preset &current_preset = *it;
296 if (!current_preset.setting_id.empty()) {
297 BOOST_LOG_TRIVIAL(info) << "delete preset = " << current_preset.name << ", setting_id = " << current_preset.setting_id;
298 wxGetApp().delete_preset_from_cloud(current_preset.setting_id, current_preset.file);
299 }
300 m_presets->delete_preset(m_preset_name);
301 }
302}
ValidationType m_valid_type
Definition SavePresetDialog.hpp:67

References Slic3r::Preset::file, m_preset_name, m_presets, m_valid_type, Slic3r::Preset::name, Slic3r::Preset::setting_id, and Warning.

◆ DoSetSize()

void Slic3r::GUI::SavePresetDialog::Item::DoSetSize ( int x,
int y,
int width,
int height,
int sizeFlags = wxSIZE_AUTO )
virtual
305{
306 wxWindow::DoSetSize(x, y, width, height, sizeFlags);
307}

◆ is_detached()

bool Slic3r::GUI::SavePresetDialog::Item::is_detached ( ) const
inline
64{ return m_detach; }

References m_detach.

◆ is_valid()

bool Slic3r::GUI::SavePresetDialog::Item::is_valid ( ) const
inline
57{ return m_valid_type != NoValid; }

References m_valid_type, and NoValid.

◆ preset_name()

std::string Slic3r::GUI::SavePresetDialog::Item::preset_name ( ) const
inline
59{ return m_preset_name; }

References m_preset_name.

Referenced by Item().

Here is the caller graph for this function:

◆ save_to_project()

bool Slic3r::GUI::SavePresetDialog::Item::save_to_project ( ) const
inline
61{ return m_save_to_project; }

References m_save_to_project.

◆ type()

Preset::Type Slic3r::GUI::SavePresetDialog::Item::type ( ) const
inline
58{ return m_type; }

References m_type.

Referenced by Item().

Here is the caller graph for this function:

◆ update()

void Slic3r::GUI::SavePresetDialog::Item::update ( )
197{
198 m_preset_name = into_u8(m_input_ctrl->GetTextCtrl()->GetValue());
199
201 wxString info_line;
202
203 const char *unusable_symbols = "<>[]:/\\|?*\"";
204
205 const std::string unusable_suffix = PresetCollection::get_suffix_modified(); //"(modified)";
206 for (size_t i = 0; i < std::strlen(unusable_symbols); i++) {
207 if (m_preset_name.find_first_of(unusable_symbols[i]) != std::string::npos) {
208 info_line = _L("Name is invalid;") + "\n" + _L("illegal characters:") + " " + unusable_symbols;
210 break;
211 }
212 }
213
214 if (m_valid_type == Valid && m_preset_name.find(unusable_suffix) != std::string::npos) {
215 info_line = _L("Name is invalid;") + "\n" + _L("illegal suffix:") + "\n\t" + from_u8(PresetCollection::get_suffix_modified());
217 }
218
219 if (m_valid_type == Valid &&
220 (m_preset_name == "Default Setting" || m_preset_name == PresetBundle::ORCA_DEFAULT_FILAMENT_PLACEHOLDER || m_preset_name == "Default Printer")) {
221 info_line = _L("Name is unavailable.");
223 }
224
225 const Preset *existing = m_presets->find_preset(m_preset_name, false);
226 if (m_valid_type == Valid && existing && !existing->can_overwrite()) {
227 info_line = _L("Overwriting a system profile is not allowed.");
229 }
230
231 if (m_valid_type == Valid && existing && m_preset_name != m_presets->get_selected_preset_name()) {
232 if (existing->is_compatible)
233 info_line = from_u8((boost::format(_u8L("Preset \"%1%\" already exists.")) % m_preset_name).str());
234 else
235 info_line = from_u8((boost::format(_u8L("Preset \"%1%\" already exists and is incompatible with the current printer.")) % m_preset_name).str());
236 info_line += "\n" + _L("Please note that saving will overwrite the current preset.");
238 }
239
240 if (m_valid_type == Valid && m_preset_name.empty()) {
241 info_line = _L("The name field is not allowed to be empty.");
243 }
244
245 if (m_valid_type == Valid && m_preset_name.find_first_of(' ') == 0) {
246 info_line = _L("The name is not allowed to start with a space.");
248 }
249
250 if (m_valid_type == Valid && m_preset_name.find_last_of(' ') == m_preset_name.length() - 1) {
251 info_line = _L("The name is not allowed to end with a space.");
253 }
254
255 if (m_valid_type == Valid && m_presets->get_preset_name_by_alias(m_preset_name) != m_preset_name) {
256 info_line = _L("The name cannot be the same as a preset alias name.");
258 }
259
260 // BBS: add project embedded presets logic
261 if (existing) { // ORCA RadioGroup
262 if (existing->is_project_embedded) {
263 m_radio_group->SetSelection(1);
264 m_save_to_project = true;
265 } else {
266 m_radio_group->SetSelection(0);
267 m_save_to_project = false;
268 }
269 m_radio_group->Disable();
270 } else {
271 m_radio_group->Enable();
272 m_radio_group->SetSelection(m_save_to_project ? 1 : 0);
273 }
274
275 m_valid_label->SetLabel(info_line);
276 m_valid_label->Show(!info_line.IsEmpty());
277
278 // update_valid_bmp();
279
280 if (m_type == Preset::TYPE_PRINTER) m_parent->update_info_for_edit_ph_printer(m_preset_name);
281
282 m_parent->layout();
283}
static const char * ORCA_DEFAULT_FILAMENT_PLACEHOLDER
Definition PresetBundle.hpp:691
static const std::string & get_suffix_modified()
Definition Preset.cpp:3766

References _L, _u8L, Slic3r::Preset::can_overwrite(), Slic3r::GUI::from_u8(), Slic3r::PresetCollection::get_suffix_modified(), Slic3r::GUI::into_u8(), Slic3r::Preset::is_compatible, Slic3r::Preset::is_project_embedded, m_input_ctrl, m_parent, m_preset_name, m_presets, m_radio_group, m_save_to_project, m_type, m_valid_label, m_valid_type, NoValid, Slic3r::PresetBundle::ORCA_DEFAULT_FILAMENT_PLACEHOLDER, Slic3r::Preset::TYPE_PRINTER, Valid, and Warning.

Referenced by Item().

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

◆ update_valid_bmp()

void Slic3r::GUI::SavePresetDialog::Item::update_valid_bmp ( )
286{
287 std::string bmp_name = m_valid_type == Warning ? "obj_warning" : m_valid_type == NoValid ? "cross" : "blank_16";
288 m_valid_bmp->SetBitmap(create_scaled_bitmap(bmp_name, m_parent));
289}
wxStaticBitmap * m_valid_bmp
Definition SavePresetDialog.hpp:71
wxBitmap create_scaled_bitmap(const std::string &bmp_name_in, wxWindow *win, const int px_cnt, const bool grayscale, const std::string &new_color, const bool menu_bitmap, const bool resize, const bool bitmap2, const std::vector< std::string > &array_new_color)
Definition wxExtensions.cpp:448

References create_scaled_bitmap(), m_parent, m_valid_bmp, m_valid_type, NoValid, and Warning.

Here is the call graph for this function:

Member Data Documentation

◆ m_combo

wxComboBox* Slic3r::GUI::SavePresetDialog::Item::m_combo {nullptr}
72{nullptr};

◆ m_detach

bool Slic3r::GUI::SavePresetDialog::Item::m_detach {false}
81{false};

Referenced by Item(), and is_detached().

◆ m_input_ctrl

TextInput* Slic3r::GUI::SavePresetDialog::Item::m_input_ctrl {nullptr}

◆ m_parent

SavePresetDialog* Slic3r::GUI::SavePresetDialog::Item::m_parent {nullptr}
70{nullptr};

Referenced by Item(), update(), and update_valid_bmp().

◆ m_preset_name

std::string Slic3r::GUI::SavePresetDialog::Item::m_preset_name

Referenced by Item(), accept(), preset_name(), and update().

◆ m_presets

PresetCollection* Slic3r::GUI::SavePresetDialog::Item::m_presets {nullptr}
76{nullptr};

Referenced by Item(), accept(), and update().

◆ m_radio_group

RadioGroup* Slic3r::GUI::SavePresetDialog::Item::m_radio_group

Referenced by Item(), and update().

◆ m_save_to_project

bool Slic3r::GUI::SavePresetDialog::Item::m_save_to_project {false}
79{false};

Referenced by Item(), save_to_project(), and update().

◆ m_type

Preset::Type Slic3r::GUI::SavePresetDialog::Item::m_type

Referenced by Item(), type(), and update().

◆ m_valid_bmp

wxStaticBitmap* Slic3r::GUI::SavePresetDialog::Item::m_valid_bmp {nullptr}
71{nullptr};

Referenced by update_valid_bmp().

◆ m_valid_label

wxStaticText* Slic3r::GUI::SavePresetDialog::Item::m_valid_label {nullptr}
74{nullptr};

Referenced by Item(), and update().

◆ m_valid_type

ValidationType Slic3r::GUI::SavePresetDialog::Item::m_valid_type

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