OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::CrealityDiscoveryDialog Class Reference

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

Inheritance diagram for Slic3r::GUI::CrealityDiscoveryDialog:
Collaboration diagram for Slic3r::GUI::CrealityDiscoveryDialog:

Classes

struct  Row

Public Member Functions

 CrealityDiscoveryDialog (wxWindow *parent)
 ~CrealityDiscoveryDialog () override=default
std::string selected_ip () const

Private Member Functions

void run_discovery ()
void on_ok ()

Private Attributes

wxListView * m_list = nullptr
wxStaticText * m_status = nullptr
std::vector< Row > m_rows
std::string m_selected_ip

Detailed Description


Class Documentation

◆ Slic3r::GUI::CrealityDiscoveryDialog::Row

struct Slic3r::GUI::CrealityDiscoveryDialog::Row
Collaboration diagram for Slic3r::GUI::CrealityDiscoveryDialog::Row:
Class Members
string hostname
string ip
string model

Constructor & Destructor Documentation

◆ CrealityDiscoveryDialog()

Slic3r::GUI::CrealityDiscoveryDialog::CrealityDiscoveryDialog ( wxWindow * parent)
28 : wxDialog(parent, wxID_ANY, _L("Detect Creality K-series printer"),
29 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
30{
31 const int em = wxGetApp().em_unit();
32
33 m_status = new wxStaticText(this, wxID_ANY, _L("Click Scan to look for K-series printers on your network."));
34
35 m_list = new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
36 wxLC_REPORT | wxSIMPLE_BORDER | wxLC_SINGLE_SEL);
37 m_list->SetMinSize(wxSize(50 * em, 18 * em));
38 m_list->AppendColumn(_L_CONTEXT("Model", "Printer model"), wxLIST_FORMAT_LEFT, 8 * em);
39 m_list->AppendColumn(_L("Hostname"), wxLIST_FORMAT_LEFT, 14 * em);
40 m_list->AppendColumn(_L("IP"), wxLIST_FORMAT_LEFT, 14 * em);
41
42 auto* dlg_btns = new DialogButtons(this, {L("Scan"), "OK", "Cancel"}, "", 1 /*left_aligned*/);
43 auto* ok_btn = dlg_btns->GetOK();
44 ok_btn->SetLabel(_L("Use Selected"));
45 ok_btn->Disable();
46
47 auto* vsizer = new wxBoxSizer(wxVERTICAL);
48 vsizer->Add(m_status, 0, wxEXPAND | wxALL, em);
49 vsizer->Add(m_list, 1, wxEXPAND | wxALL, em);
50 vsizer->Add(dlg_btns, 0, wxEXPAND);
51 SetSizerAndFit(vsizer);
52
53 dlg_btns->GetFIRST()->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { run_discovery(); });
54
55 m_list->Bind(wxEVT_LIST_ITEM_SELECTED, [ok_btn](wxListEvent&) { ok_btn->Enable(); });
56 m_list->Bind(wxEVT_LIST_ITEM_DESELECTED, [ok_btn](wxListEvent&) { ok_btn->Disable(); });
57 m_list->Bind(wxEVT_LIST_ITEM_ACTIVATED, [this](wxListEvent&) { on_ok(); EndModal(wxID_OK); });
58
59 ok_btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { on_ok(); EndModal(wxID_OK); });
60 dlg_btns->GetCANCEL()->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { EndModal(wxID_CANCEL); });
61
62 wxGetApp().UpdateDlgDarkUI(this);
63
64 // Run discovery synchronously from the ctor so results are ready by the
65 // time the dialog is shown. Posting an async CallAfter from a ShowModal
66 // override risked the event firing after the modal loop had exited -- the
67 // captured `this` would then be a dangling stack pointer and subsequent
68 // UI access could fault.
70}
#define L(s)
Definition ExtrusionEntity.cpp:25
#define _L(s)
Definition OBJ.cpp:34
class WXDLLIMPEXP_FWD_CORE wxStaticText
Definition ProgressDialog.hpp:30
void run_discovery()
Definition CrealityDiscoveryDialog.cpp:72
void on_ok()
Definition CrealityDiscoveryDialog.cpp:119
wxListView * m_list
Definition CrealityDiscoveryDialog.hpp:42
wxStaticText * m_status
Definition CrealityDiscoveryDialog.hpp:43
#define _L_CONTEXT(s, ctx)
Definition I18N.hpp:15

References _L, _L_CONTEXT, Slic3r::GUI::DialogButtons::GetCANCEL(), Slic3r::GUI::DialogButtons::GetOK(), L, m_list, m_status, on_ok(), run_discovery(), and wxStaticText.

Here is the call graph for this function:

◆ ~CrealityDiscoveryDialog()

Slic3r::GUI::CrealityDiscoveryDialog::~CrealityDiscoveryDialog ( )
overridedefault

Member Function Documentation

◆ on_ok()

void Slic3r::GUI::CrealityDiscoveryDialog::on_ok ( )
private
120{
121 auto sel = m_list->GetFirstSelected();
122 if (sel >= 0 && sel < int(m_rows.size())) {
123 m_selected_ip = m_rows[sel].ip;
124 }
125}
std::vector< Row > m_rows
Definition CrealityDiscoveryDialog.hpp:44
std::string m_selected_ip
Definition CrealityDiscoveryDialog.hpp:45

References m_list, m_rows, and m_selected_ip.

Referenced by CrealityDiscoveryDialog().

Here is the caller graph for this function:

◆ run_discovery()

void Slic3r::GUI::CrealityDiscoveryDialog::run_discovery ( )
private
73{
74 m_status->SetLabel(_L("Scanning the LAN for K-series printers... this takes a few seconds."));
75 m_list->DeleteAllItems();
76 m_rows.clear();
77 Layout();
78 Update();
79
80 std::vector<CrealityHost> hosts;
81 {
82 wxBusyCursor cursor;
83 wxWindowDisabler disabler(this);
84 hosts = CrealityHostDiscovery::scan(/*probe_info=*/true);
85 }
86
87 for (const auto& h : hosts) {
88 Row row;
89 row.ip = h.ip;
90 row.hostname = h.hostname;
91 if (!h.model_name.empty())
92 row.model = h.model_name;
93 else if (h.cfs_capable)
94 row.model = _u8L("(unknown K-series)");
95 else
96 row.model = "Creality";
97 m_rows.push_back(std::move(row));
98 }
99
100 for (size_t i = 0; i < m_rows.size(); ++i) {
101 long idx = m_list->InsertItem(i, wxString::FromUTF8(m_rows[i].model));
102 m_list->SetItem(idx, 1, wxString::FromUTF8(m_rows[i].hostname));
103 m_list->SetItem(idx, 2, wxString::FromUTF8(m_rows[i].ip));
104 }
105
106 if (m_rows.empty()) {
107 m_status->SetLabel(_L(
108 "No K-series printers found. Make sure the printer is on the same "
109 "network and not blocked by Wi-Fi client isolation, then click Scan again."));
110 } else {
111 m_status->SetLabel(wxString::Format(
112 _L_PLURAL("Found %zu Creality printer. Select it and click Use Selected.",
113 "Found %zu Creality printers. Select one and click Use Selected.", m_rows.size()),
114 m_rows.size()));
115 m_list->Select(0);
116 }
117}
class WXDLLIMPEXP_FWD_CORE wxWindowDisabler
Definition ProgressDialog.hpp:31
static std::vector< CrealityHost > scan(bool probe_info=true)
Definition CrealityHostDiscovery.cpp:82
std::string ip
Definition CrealityDiscoveryDialog.hpp:40
Definition CrealityDiscoveryDialog.hpp:40
#define _u8L(s)
Definition I18N.hpp:11
#define _L_PLURAL(s, plural, n)
Definition I18N.hpp:96

References _L, _L_PLURAL, _u8L, Slic3r::GUI::CrealityDiscoveryDialog::Row::hostname, Slic3r::GUI::CrealityDiscoveryDialog::Row::ip, m_list, m_rows, m_status, Slic3r::GUI::CrealityDiscoveryDialog::Row::model, Slic3r::CrealityHostDiscovery::scan(), and wxWindowDisabler.

Referenced by CrealityDiscoveryDialog().

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

◆ selected_ip()

std::string Slic3r::GUI::CrealityDiscoveryDialog::selected_ip ( ) const
inline
34{ return m_selected_ip; }

References m_selected_ip.

Referenced by Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings().

Here is the caller graph for this function:

Member Data Documentation

◆ m_list

wxListView* Slic3r::GUI::CrealityDiscoveryDialog::m_list = nullptr
private

◆ m_rows

std::vector<Row> Slic3r::GUI::CrealityDiscoveryDialog::m_rows
private

Referenced by on_ok(), and run_discovery().

◆ m_selected_ip

std::string Slic3r::GUI::CrealityDiscoveryDialog::m_selected_ip
private

Referenced by on_ok(), and selected_ip().

◆ m_status

wxStaticText* Slic3r::GUI::CrealityDiscoveryDialog::m_status = nullptr
private

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