OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::BonjourDialog Class Reference

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

Inheritance diagram for Slic3r::BonjourDialog:
Collaboration diagram for Slic3r::BonjourDialog:

Public Member Functions

 BonjourDialog (wxWindow *parent, Slic3r::PrinterTechnology)
 BonjourDialog (BonjourDialog &&)=delete
 BonjourDialog (const BonjourDialog &)=delete
BonjourDialog & operator= (BonjourDialog &&)=delete
BonjourDialog & operator= (const BonjourDialog &)=delete
 ~BonjourDialog ()
bool show_and_lookup ()
wxString get_selected () const

Private Member Functions

virtual void on_reply (BonjourReplyEvent &)
void on_timer (wxTimerEvent &)
void on_timer_process ()

Private Attributes

wxListView * list
std::unique_ptr< ReplySet > replies
wxStaticText * label
std::shared_ptr< Bonjour > bonjour
std::unique_ptr< wxTimer > timer
unsigned timer_state
Slic3r::PrinterTechnology tech

Detailed Description

Constructor & Destructor Documentation

◆ BonjourDialog() [1/3]

Slic3r::BonjourDialog::BonjourDialog ( wxWindow * parent,
Slic3r::PrinterTechnology tech )
70 : wxDialog(parent, wxID_ANY, _(L("Network lookup")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
71 , list(new wxListView(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSIMPLE_BORDER))
72 , replies(new ReplySet)
73 , label(new wxStaticText(this, wxID_ANY, ""))
74 , timer(new wxTimer())
75 , timer_state(0)
76 , tech(tech)
77{
78 SetBackgroundColour(*wxWHITE);
79
80 const int em = GUI::wxGetApp().em_unit();
81 list->SetMinSize(wxSize(80 * em, 30 * em));
82
83 wxBoxSizer *vsizer = new wxBoxSizer(wxVERTICAL);
84
85 label->SetFont(Label::Body_14);
86 vsizer->Add(label, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, em);
87
88 list->SetSingleStyle(wxLC_SINGLE_SEL);
89 list->SetSingleStyle(wxLC_SORT_DESCENDING);
90 list->AppendColumn(_(L("Address")), wxLIST_FORMAT_LEFT, 20 * em);
91 list->AppendColumn(_(L("Hostname")), wxLIST_FORMAT_LEFT, 10 * em);
92 list->AppendColumn(_(L("Service name")), wxLIST_FORMAT_LEFT, 20 * em);
93 if (tech == ptFFF) {
94 list->AppendColumn(_(L("OctoPrint version")), wxLIST_FORMAT_LEFT, 15 * em);
95 }
96
97 vsizer->Add(list, 1, wxEXPAND | wxALL, em);
98
99 auto dlg_btns = new GUI::DialogButtons(this, {"OK", "Cancel"});
100
101 vsizer->Add(dlg_btns, 0, wxEXPAND);
102 SetSizerAndFit(vsizer);
103
104 Bind(EVT_BONJOUR_REPLY, &BonjourDialog::on_reply, this);
105
106 Bind(EVT_BONJOUR_COMPLETE, [this](wxCommandEvent &) {
107 this->timer_state = 0;
108 });
109
110 Bind(wxEVT_TIMER, &BonjourDialog::on_timer, this);
111 GUI::wxGetApp().UpdateDlgDarkUI(this);
112}
#define _(s)
Definition 3mf.cpp:306
#define L(s)
Definition ExtrusionEntity.cpp:25
class WXDLLIMPEXP_FWD_CORE wxStaticText
Definition ProgressDialog.hpp:30
static wxFont Body_14
Definition Label.hpp:53
void on_timer(wxTimerEvent &)
Definition BonjourDialog.cpp:230
Slic3r::PrinterTechnology tech
Definition BonjourDialog.hpp:50
std::unique_ptr< ReplySet > replies
Definition BonjourDialog.hpp:45
std::unique_ptr< wxTimer > timer
Definition BonjourDialog.hpp:48
wxStaticText * label
Definition BonjourDialog.hpp:46
virtual void on_reply(BonjourReplyEvent &)
Definition BonjourDialog.cpp:178
wxListView * list
Definition BonjourDialog.hpp:44
unsigned timer_state
Definition BonjourDialog.hpp:49
@ ptFFF
Definition Config.hpp:231

References _, Label::Body_14, L, label, list, on_reply(), on_timer(), Slic3r::ptFFF, replies, tech, timer, timer_state, and wxStaticText.

Referenced by BonjourDialog(), BonjourDialog(), operator=(), and operator=().

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

◆ BonjourDialog() [2/3]

Slic3r::BonjourDialog::BonjourDialog ( BonjourDialog && )
delete

References BonjourDialog().

Here is the call graph for this function:

◆ BonjourDialog() [3/3]

Slic3r::BonjourDialog::BonjourDialog ( const BonjourDialog & )
delete

References BonjourDialog().

Here is the call graph for this function:

◆ ~BonjourDialog()

Slic3r::BonjourDialog::~BonjourDialog ( )
115{
116 // Needed bacuse of forward defs
117}

Member Function Documentation

◆ get_selected()

wxString Slic3r::BonjourDialog::get_selected ( ) const
170{
171 auto sel = list->GetFirstSelected();
172 return sel >= 0 ? list->GetItemText(sel) : wxString();
173}

References list.

Referenced by Slic3r::GUI::PhysicalPrinterDialog::build_printhost_settings(), and on_reply().

Here is the caller graph for this function:

◆ on_reply()

void Slic3r::BonjourDialog::on_reply ( BonjourReplyEvent & e)
privatevirtual
179{
180 if (replies->find(e.reply) != replies->end()) {
181 // We already have this reply
182 return;
183 }
184
185 // Filter replies based on selected technology
186 const auto model = e.reply.txt_data.find("model");
187 const bool sl1 = model != e.reply.txt_data.end() && model->second == "SL1";
188 if ((tech == ptFFF && sl1) || (tech == ptSLA && !sl1)) {
189 return;
190 }
191
192 replies->insert(std::move(e.reply));
193
194 auto selected = get_selected();
195
196 wxWindowUpdateLocker freeze_guard(this);
197 (void)freeze_guard;
198
199 list->DeleteAllItems();
200
201 // The whole list is recreated so that we benefit from it already being sorted in the set.
202 // (And also because wxListView's sorting API is bananas.)
203 for (const auto &reply : *replies) {
204 auto item = list->InsertItem(0, reply.full_address);
205 list->SetItem(item, 1, reply.hostname);
206 list->SetItem(item, 2, reply.service_name);
207
208 if (tech == ptFFF) {
209 const auto it = reply.txt_data.find("version");
210 if (it != reply.txt_data.end()) {
211 list->SetItem(item, 3, GUI::from_u8(it->second));
212 }
213 }
214 }
215
216 const int em = GUI::wxGetApp().em_unit();
217
218 for (int i = 0; i < list->GetColumnCount(); i++) {
219 list->SetColumnWidth(i, wxLIST_AUTOSIZE);
220 if (list->GetColumnWidth(i) < 10 * em) { list->SetColumnWidth(i, 10 * em); }
221 }
222
223 if (!selected.IsEmpty()) {
224 // Attempt to preserve selection
225 auto hit = list->FindItem(-1, selected);
226 if (hit >= 0) { list->SetItemState(hit, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); }
227 }
228}
wxString get_selected() const
Definition BonjourDialog.cpp:169
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
@ ptSLA
Definition Config.hpp:233

References Slic3r::GUI::from_u8(), get_selected(), list, Slic3r::ptFFF, Slic3r::ptSLA, replies, Slic3r::BonjourReplyEvent::reply, tech, and Slic3r::BonjourReply::txt_data.

Referenced by BonjourDialog().

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

◆ on_timer()

void Slic3r::BonjourDialog::on_timer ( wxTimerEvent & )
private
231{
233}
void on_timer_process()
Definition BonjourDialog.cpp:237

References on_timer_process().

Referenced by BonjourDialog().

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

◆ on_timer_process()

void Slic3r::BonjourDialog::on_timer_process ( )
private
238{
239 const auto search_str = _L("Searching for devices");
240
241 if (timer_state > 0) {
242 const std::string dots(timer_state, '.');
243 label->SetLabel(search_str + dots);
244 timer_state = (timer_state) % 3 + 1;
245 } else {
246 label->SetLabel(search_str + ": " + _L("Finished") + ".");
247 timer->Stop();
248 }
249}
#define _L(s)
Definition OBJ.cpp:34

References _L, label, timer, and timer_state.

Referenced by on_timer(), and show_and_lookup().

Here is the caller graph for this function:

◆ operator=() [1/2]

BonjourDialog & Slic3r::BonjourDialog::operator= ( BonjourDialog && )
delete

References BonjourDialog().

Here is the call graph for this function:

◆ operator=() [2/2]

BonjourDialog & Slic3r::BonjourDialog::operator= ( const BonjourDialog & )
delete

References BonjourDialog().

Here is the call graph for this function:

◆ show_and_lookup()

bool Slic3r::BonjourDialog::show_and_lookup ( )
120{
121 Show(); // Because we need GetId() to work before ShowModal()
122
123 timer->Stop();
124 timer->SetOwner(this);
125 timer_state = 1;
126 timer->Start(1000);
128
129 // The background thread needs to queue messages for this dialog
130 // and for that it needs a valid pointer to it (mandated by the wxWidgets API).
131 // Here we put the pointer under a shared_ptr and protect it by a mutex,
132 // so that both threads can access it safely.
133 auto dguard = std::make_shared<LifetimeGuard>(this);
134
135 // Note: More can be done here when we support discovery of hosts other than Octoprint and SL1
136 Bonjour::TxtKeys txt_keys { "version", "model" };
137
138 bonjour = Bonjour("octoprint")
139 .set_txt_keys(std::move(txt_keys))
140 .set_retries(3)
141 .set_timeout(4)
142 .on_reply([dguard](BonjourReply &&reply) {
143 std::lock_guard<std::mutex> lock_guard(dguard->mutex);
144 auto dialog = dguard->dialog;
145 if (dialog != nullptr) {
146 auto evt = new BonjourReplyEvent(EVT_BONJOUR_REPLY, dialog->GetId(), std::move(reply));
147 wxQueueEvent(dialog, evt);
148 }
149 })
150 .on_complete([dguard]() {
151 std::lock_guard<std::mutex> lock_guard(dguard->mutex);
152 auto dialog = dguard->dialog;
153 if (dialog != nullptr) {
154 auto evt = new wxCommandEvent(EVT_BONJOUR_COMPLETE, dialog->GetId());
155 wxQueueEvent(dialog, evt);
156 }
157 })
158 .lookup();
159
160 bool res = ShowModal() == wxID_OK && list->GetFirstSelected() >= 0;
161 {
162 // Tell the background thread the dialog is going away...
163 std::lock_guard<std::mutex> lock_guard(dguard->mutex);
164 dguard->dialog = nullptr;
165 }
166 return res;
167}
std::shared_ptr< Bonjour > bonjour
Definition BonjourDialog.hpp:47
std::set< std::string > TxtKeys
Definition Bonjour.hpp:70

References bonjour, list, Slic3r::Bonjour::on_reply(), on_timer_process(), Slic3r::Bonjour::set_retries(), Slic3r::Bonjour::set_timeout(), Slic3r::Bonjour::set_txt_keys(), timer, and timer_state.

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

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

Member Data Documentation

◆ bonjour

std::shared_ptr<Bonjour> Slic3r::BonjourDialog::bonjour
private

Referenced by show_and_lookup().

◆ label

wxStaticText* Slic3r::BonjourDialog::label
private

Referenced by BonjourDialog(), and on_timer_process().

◆ list

wxListView* Slic3r::BonjourDialog::list
private

◆ replies

std::unique_ptr<ReplySet> Slic3r::BonjourDialog::replies
private

Referenced by BonjourDialog(), and on_reply().

◆ tech

Slic3r::PrinterTechnology Slic3r::BonjourDialog::tech
private

Referenced by BonjourDialog(), and on_reply().

◆ timer

std::unique_ptr<wxTimer> Slic3r::BonjourDialog::timer
private

◆ timer_state

unsigned Slic3r::BonjourDialog::timer_state
private

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