OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::PrinterPicker Struct Reference

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

Inheritance diagram for Slic3r::GUI::PrinterPicker:
Collaboration diagram for Slic3r::GUI::PrinterPicker:

Classes

struct  Checkbox

Public Member Functions

 PrinterPicker (wxWindow *parent, const VendorProfile &vendor, wxString title, size_t max_cols, const AppConfig &appconfig, const ModelFilter &filter)
 PrinterPicker (wxWindow *parent, const VendorProfile &vendor, wxString title, size_t max_cols, const AppConfig &appconfig)
void select_all (bool select, bool alternates=false)
void select_one (size_t i, bool select)
bool any_selected () const
std::set< std::string > get_selected_models () const
int get_width () const
const std::vector< int > & get_button_indexes ()

Public Attributes

const std::string vendor_id
std::vector< Checkbox * > cboxes
std::vector< Checkbox * > cboxes_alt

Static Public Attributes

static const std::string PRINTER_PLACEHOLDER = "printer_placeholder.png"

Private Member Functions

void on_checkbox (const Checkbox *cbox, bool checked)

Private Attributes

int width
std::vector< int > m_button_indexes

Detailed Description

Constructor & Destructor Documentation

◆ PrinterPicker() [1/2]

Slic3r::GUI::PrinterPicker::PrinterPicker ( wxWindow * parent,
const VendorProfile & vendor,
wxString title,
size_t max_cols,
const AppConfig & appconfig,
const ModelFilter & filter )
233 : wxPanel(parent)
234 , vendor_id(vendor.id)
235 , width(0)
236{
237 wxGetApp().UpdateDarkUI(this);
238 const auto &models = vendor.models;
239
240 auto *sizer = new wxBoxSizer(wxVERTICAL);
241
242 const auto font_title = GetFont().MakeBold().Scaled(1.3f);
243 const auto font_name = GetFont().MakeBold();
244 const auto font_alt_nozzle = GetFont().Scaled(0.9f);
245
246 // wxGrid appends widgets by rows, but we need to construct them in columns.
247 // These vectors are used to hold the elements so that they can be appended in the right order.
248 std::vector<wxStaticText*> titles;
249 std::vector<wxStaticBitmap*> bitmaps;
250 std::vector<wxPanel*> variants_panels;
251
252 int max_row_width = 0;
253 int current_row_width = 0;
254
255 bool is_variants = false;
256
257 for (const auto &model : models) {
258 if (! filter(model)) { continue; }
259
260 wxBitmap bitmap;
261 int bitmap_width = 0;
262 auto load_bitmap = [](const wxString& bitmap_file, wxBitmap& bitmap, int& bitmap_width)->bool {
263 if (wxFileExists(bitmap_file)) {
264 bitmap.LoadFile(bitmap_file, wxBITMAP_TYPE_PNG);
265 bitmap_width = bitmap.GetWidth();
266 return true;
267 }
268 return false;
269 };
270 if (!load_bitmap(GUI::from_u8(Slic3r::data_dir() + "/vendor/" + vendor.id + "/" + model.id + "_thumbnail.png"), bitmap, bitmap_width)) {
271 if (!load_bitmap(GUI::from_u8(Slic3r::resources_dir() + "/profiles/" + vendor.id + "/" + model.id + "_thumbnail.png"), bitmap, bitmap_width)) {
272 BOOST_LOG_TRIVIAL(warning) << boost::format("Can't find bitmap file `%1%` for vendor `%2%`, printer `%3%`, using placeholder icon instead")
273 % (Slic3r::resources_dir() + "/profiles/" + vendor.id + "/" + model.id + "_thumbnail.png")
274 % vendor.id
275 % model.id;
276 load_bitmap(Slic3r::var(PRINTER_PLACEHOLDER), bitmap, bitmap_width);
277 }
278 }
279 auto *title = new wxStaticText(this, wxID_ANY, from_u8(model.name), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
280 title->SetFont(font_name);
281 const int wrap_width = std::max((int)MODEL_MIN_WRAP, bitmap_width);
282 title->Wrap(wrap_width);
283
284 current_row_width += wrap_width;
285 if (titles.size() % max_cols == max_cols - 1) {
286 max_row_width = std::max(max_row_width, current_row_width);
287 current_row_width = 0;
288 }
289
290 titles.push_back(title);
291
292 auto *bitmap_widget = new wxStaticBitmap(this, wxID_ANY, bitmap);
293 bitmaps.push_back(bitmap_widget);
294
295 auto *variants_panel = new wxPanel(this);
296 wxGetApp().UpdateDarkUI(variants_panel);
297 auto *variants_sizer = new wxBoxSizer(wxVERTICAL);
298 variants_panel->SetSizer(variants_sizer);
299 const auto model_id = model.id;
300
301 for (size_t i = 0; i < model.variants.size(); i++) {
302 const auto &variant = model.variants[i];
303
304 const auto label = model.technology == ptFFF
305 ? from_u8((boost::format("%1% %2% %3%") % variant.name % _utf8(L("mm")) % _utf8(L("nozzle"))).str())
306 : from_u8(model.name);
307
308 if (i == 1) {
309 auto *alt_label = new wxStaticText(variants_panel, wxID_ANY, _L("Alternate nozzles:"));
310 alt_label->SetFont(font_alt_nozzle);
311 variants_sizer->Add(alt_label, 0, wxBOTTOM, 3);
312 is_variants = true;
313 }
314
315 auto *cbox = new Checkbox(variants_panel, label, model_id, variant.name);
316 i == 0 ? cboxes.push_back(cbox) : cboxes_alt.push_back(cbox);
317
318 const bool enabled = appconfig.get_variant(vendor.id, model_id, variant.name);
319 cbox->SetValue(enabled);
320
321 variants_sizer->Add(cbox, 0, wxBOTTOM, 3);
322
323 cbox->Bind(wxEVT_CHECKBOX, [this, cbox](wxCommandEvent &event) {
324 on_checkbox(cbox, event.IsChecked());
325 });
326 }
327
328 variants_panels.push_back(variants_panel);
329 }
330
331 width = std::max(max_row_width, current_row_width);
332
333 const size_t cols = std::min(max_cols, titles.size());
334
335 auto *printer_grid = new wxFlexGridSizer(cols, 0, 20);
336 printer_grid->SetFlexibleDirection(wxVERTICAL | wxHORIZONTAL);
337
338 if (titles.size() > 0) {
339 const size_t odd_items = titles.size() % cols;
340
341 for (size_t i = 0; i < titles.size() - odd_items; i += cols) {
342 for (size_t j = i; j < i + cols; j++) { printer_grid->Add(bitmaps[j], 0, wxBOTTOM, 20); }
343 for (size_t j = i; j < i + cols; j++) { printer_grid->Add(titles[j], 0, wxBOTTOM, 3); }
344 for (size_t j = i; j < i + cols; j++) { printer_grid->Add(variants_panels[j]); }
345
346 // Add separator space to multiliners
347 if (titles.size() > cols) {
348 for (size_t j = i; j < i + cols; j++) { printer_grid->Add(1, 30); }
349 }
350 }
351 if (odd_items > 0) {
352 const size_t rem = titles.size() - odd_items;
353
354 for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(bitmaps[i], 0, wxBOTTOM, 20); }
355 for (size_t i = 0; i < cols - odd_items; i++) { printer_grid->AddSpacer(1); }
356 for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(titles[i], 0, wxBOTTOM, 3); }
357 for (size_t i = 0; i < cols - odd_items; i++) { printer_grid->AddSpacer(1); }
358 for (size_t i = rem; i < titles.size(); i++) { printer_grid->Add(variants_panels[i]); }
359 }
360 }
361
362 auto *title_sizer = new wxBoxSizer(wxHORIZONTAL);
363 if (! title.IsEmpty()) {
364 auto *title_widget = new wxStaticText(this, wxID_ANY, title);
365 title_widget->SetFont(font_title);
366 title_sizer->Add(title_widget);
367 }
368 title_sizer->AddStretchSpacer();
369
370 if (titles.size() > 1 || is_variants) {
371 // It only makes sense to add the All / None buttons if there's multiple printers
372 // All Standard button is added when there are more variants for at least one printer
373 auto *sel_all_std = new Button(this, titles.size() > 1 ? _L("All standard") : _L("Standard"));
374 auto *sel_all = new Button(this, _L("All"));
375 auto *sel_none = new Button(this, _L("None"));
376
377 wxGetApp().UpdateDarkUI(sel_all_std);
378 wxGetApp().UpdateDarkUI(sel_all);
379 wxGetApp().UpdateDarkUI(sel_none);
380
381 if (is_variants)
382 sel_all_std->Bind(wxEVT_BUTTON, [this](const wxCommandEvent& event) { this->select_all(true, false); });
383 sel_all->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &event) { this->select_all(true, true); });
384 sel_none->Bind(wxEVT_BUTTON, [this](const wxCommandEvent &event) { this->select_all(false); });
385 if (is_variants)
386 title_sizer->Add(sel_all_std, 0, wxRIGHT, BTN_SPACING);
387 title_sizer->Add(sel_all, 0, wxRIGHT, BTN_SPACING);
388 title_sizer->Add(sel_none);
389
390 wxGetApp().UpdateDarkUI(sel_all_std);
391 wxGetApp().UpdateDarkUI(sel_all);
392 wxGetApp().UpdateDarkUI(sel_none);
393
394 // fill button indexes used later for buttons rescaling
395 if (is_variants)
396 m_button_indexes = { sel_all_std->GetId(), sel_all->GetId(), sel_none->GetId() };
397 else {
398 sel_all_std->Destroy();
399 m_button_indexes = { sel_all->GetId(), sel_none->GetId() };
400 }
401 }
402
403 sizer->Add(title_sizer, 0, wxEXPAND | wxBOTTOM, BTN_SPACING);
404 sizer->Add(printer_grid);
405
406 SetSizer(sizer);
407}
#define L(s)
Definition ExtrusionEntity.cpp:25
#define _L(s)
Definition OBJ.cpp:34
class WXDLLIMPEXP_FWD_CORE wxStaticText
Definition ProgressDialog.hpp:30
@ MODEL_MIN_WRAP
Definition ConfigWizard_private.hpp:51
@ BTN_SPACING
Definition ConfigWizard_private.hpp:55
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
std::string var(const std::string &file_name)
Definition utils.cpp:278
@ ptFFF
Definition Config.hpp:231
const std::string & data_dir()
Definition utils.cpp:365
const std::string & resources_dir()
Definition utils.cpp:296
size_t cols(const T &raster)
Definition MarchingSquares.hpp:173
#define _utf8(s)
Definition I18N.hpp:10
Definition ConfigWizard_private.hpp:182
int width
Definition ConfigWizard_private.hpp:210
void select_all(bool select, bool alternates=false)
Definition ConfigWizard.cpp:413
std::vector< Checkbox * > cboxes_alt
Definition ConfigWizard_private.hpp:195
void on_checkbox(const Checkbox *cbox, bool checked)
Definition ConfigWizard.cpp:468
std::vector< Checkbox * > cboxes
Definition ConfigWizard_private.hpp:194
std::vector< int > m_button_indexes
Definition ConfigWizard_private.hpp:211
static const std::string PRINTER_PLACEHOLDER
Definition ConfigWizard_private.hpp:208
const std::string vendor_id
Definition ConfigWizard_private.hpp:193

References _L, _utf8, Slic3r::GUI::BTN_SPACING, cboxes, cboxes_alt, Slic3r::data_dir(), Slic3r::GUI::from_u8(), Slic3r::AppConfig::get_variant(), Slic3r::VendorProfile::id, L, m_button_indexes, Slic3r::GUI::MODEL_MIN_WRAP, Slic3r::VendorProfile::models, on_checkbox(), PRINTER_PLACEHOLDER, Slic3r::ptFFF, Slic3r::resources_dir(), select_all(), Slic3r::var(), vendor_id, width, and wxStaticText.

Referenced by PrinterPicker().

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

◆ PrinterPicker() [2/2]

Slic3r::GUI::PrinterPicker::PrinterPicker ( wxWindow * parent,
const VendorProfile & vendor,
wxString title,
size_t max_cols,
const AppConfig & appconfig )
410 : PrinterPicker(parent, vendor, std::move(title), max_cols, appconfig, [](const VendorProfile::PrinterModel&) { return true; })
411{}
PrinterPicker(wxWindow *parent, const VendorProfile &vendor, wxString title, size_t max_cols, const AppConfig &appconfig, const ModelFilter &filter)
Definition ConfigWizard.cpp:232

References PrinterPicker().

Here is the call graph for this function:

Member Function Documentation

◆ any_selected()

bool Slic3r::GUI::PrinterPicker::any_selected ( ) const
441{
442 for (const auto &cb : cboxes) {
443 if (cb->GetValue()) { return true; }
444 }
445
446 for (const auto &cb : cboxes_alt) {
447 if (cb->GetValue()) { return true; }
448 }
449
450 return false;
451}

References cboxes, and cboxes_alt.

◆ get_button_indexes()

const std::vector< int > & Slic3r::GUI::PrinterPicker::get_button_indexes ( )
inline
206{ return m_button_indexes; }

References m_button_indexes.

◆ get_selected_models()

std::set< std::string > Slic3r::GUI::PrinterPicker::get_selected_models ( ) const
454{
455 std::set<std::string> ret_set;
456
457 for (const auto& cb : cboxes)
458 if (cb->GetValue())
459 ret_set.emplace(cb->model);
460
461 for (const auto& cb : cboxes_alt)
462 if (cb->GetValue())
463 ret_set.emplace(cb->model);
464
465 return ret_set;
466}

References cboxes, and cboxes_alt.

◆ get_width()

int Slic3r::GUI::PrinterPicker::get_width ( ) const
inline
205{ return width; }

References width.

◆ on_checkbox()

void Slic3r::GUI::PrinterPicker::on_checkbox ( const Checkbox * cbox,
bool checked )
private
469{
470 PrinterPickerEvent evt(EVT_PRINTER_PICK, GetId(), vendor_id, cbox->model, cbox->variant, checked);
471 AddPendingEvent(evt);
472}

References Slic3r::GUI::PrinterPicker::Checkbox::model, Slic3r::GUI::PrinterPicker::Checkbox::variant, and vendor_id.

Referenced by PrinterPicker(), select_all(), and select_one().

Here is the caller graph for this function:

◆ select_all()

void Slic3r::GUI::PrinterPicker::select_all ( bool select,
bool alternates = false )
414{
415 for (const auto &cb : cboxes) {
416 if (cb->GetValue() != select) {
417 cb->SetValue(select);
418 on_checkbox(cb, select);
419 }
420 }
421
422 if (! select) { alternates = false; }
423
424 for (const auto &cb : cboxes_alt) {
425 if (cb->GetValue() != alternates) {
426 cb->SetValue(alternates);
427 on_checkbox(cb, alternates);
428 }
429 }
430}

References cboxes, cboxes_alt, and on_checkbox().

Referenced by PrinterPicker().

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

◆ select_one()

void Slic3r::GUI::PrinterPicker::select_one ( size_t i,
bool select )
433{
434 if (i < cboxes.size() && cboxes[i]->GetValue() != select) {
435 cboxes[i]->SetValue(select);
436 on_checkbox(cboxes[i], select);
437 }
438}

References cboxes, and on_checkbox().

Here is the call graph for this function:

Member Data Documentation

◆ cboxes

std::vector<Checkbox*> Slic3r::GUI::PrinterPicker::cboxes

◆ cboxes_alt

std::vector<Checkbox*> Slic3r::GUI::PrinterPicker::cboxes_alt

◆ m_button_indexes

std::vector<int> Slic3r::GUI::PrinterPicker::m_button_indexes
private

◆ PRINTER_PLACEHOLDER

const std::string Slic3r::GUI::PrinterPicker::PRINTER_PLACEHOLDER = "printer_placeholder.png"
static

◆ vendor_id

const std::string Slic3r::GUI::PrinterPicker::vendor_id

Referenced by PrinterPicker(), and on_checkbox().

◆ width

int Slic3r::GUI::PrinterPicker::width
private

Referenced by PrinterPicker(), and get_width().


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