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

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/MediaFilePanel.h>

Inheritance diagram for Slic3r::GUI::MediaFilePanel:
Collaboration diagram for Slic3r::GUI::MediaFilePanel:

Public Member Functions

 MediaFilePanel (wxWindow *parent)
 ~MediaFilePanel ()
void UpdateByObj (MachineObject *obj)
void SwitchStorage (bool external)
void Rescale ()
void SetSelecting (bool selecting)

Private Member Functions

void modeChanged (wxCommandEvent &e)
void fetchUrl (boost::weak_ptr< PrinterFileSystem > fs)
void doAction (size_t index, int action)

Private Attributes

ScalableBitmap m_bmp_loading
ScalableBitmap m_bmp_failed
ScalableBitmap m_bmp_empty
::StaticBox * m_time_panel = nullptr
::Button * m_button_year = nullptr
::Button * m_button_month = nullptr
::Button * m_button_all = nullptr
::StaticBox * m_type_panel = nullptr
::Button * m_button_video = nullptr
::Button * m_button_timelapse = nullptr
::Button * m_button_model = nullptr
::StaticBox * m_manage_panel = nullptr
::Button * m_button_delete = nullptr
::Button * m_button_download = nullptr
::Button * m_button_refresh = nullptr
::Button * m_button_management = nullptr
ImageGrid * m_image_grid = nullptr
bool m_external = true
std::string m_machine
std::string m_lan_ip
std::string m_lan_user
std::string m_lan_passwd
std::string m_dev_ver
bool m_lan_mode = false
bool m_sdcard_exist = false
int m_local_proto = false
int m_remote_proto = false
bool m_model_download_support = false
bool m_device_busy = false
bool m_waiting_enable = false
bool m_waiting_support = false
int m_last_mode = 0
int m_last_type = 0
std::set< int > m_last_errors

Detailed Description

Constructor & Destructor Documentation

◆ MediaFilePanel()

Slic3r::GUI::MediaFilePanel::MediaFilePanel ( wxWindow * parent)
55 : wxPanel(parent, wxID_ANY)
56 , m_bmp_loading(this, "media_loading", 0)
57 , m_bmp_failed(this, "media_failed", 0)
58 , m_bmp_empty(this, "media_empty", 0)
59 , m_machine("<null>")
60{
61 SetBackgroundColour(0xEEEEEE);
62 Hide();
63
64 wxBoxSizer * sizer = new wxBoxSizer(wxVERTICAL);
65
66 wxBoxSizer * top_sizer = new wxBoxSizer(wxHORIZONTAL);
67 top_sizer->SetMinSize({-1, 75 * em_unit(this) / 10});
68
69 // Time group
70 auto time_panel = new wxWindow(this, wxID_ANY);
71 time_panel->SetBackgroundColour(0xEEEEEE);
72 m_time_panel = new ::StaticBox(time_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
73 m_time_panel->SetCornerRadius(0);
74 m_button_year = new ::Button(m_time_panel, _L("Year"), "", wxBORDER_NONE);
75 m_button_month = new ::Button(m_time_panel, _L("Month"), "", wxBORDER_NONE);
76 m_button_all = new ::Button(m_time_panel, _L("All Files"), "", wxBORDER_NONE);
77 m_button_year->SetToolTip(_L("Group files by year, recent first."));
78 m_button_month->SetToolTip(_L("Group files by month, recent first."));
79 m_button_all->SetToolTip(_L("Show all files, recent first."));
80 m_button_all->SetFont(Label::Head_14); // sync with m_last_mode
81 for (auto b : {m_button_year, m_button_month, m_button_all}) {
82 b->SetBackgroundColor(StateColor());
83 b->SetTextColor(StateColor(
84 std::make_pair(0x3B4446, (int) StateColor::Checked),
85 std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
86 std::make_pair(0xABACAC, (int) StateColor::Normal)
87 ));
88 }
89
90 wxBoxSizer *time_sizer = new wxBoxSizer(wxHORIZONTAL);
91 time_sizer->Add(m_button_year, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24);
92 time_sizer->Add(m_button_month, 0, wxALIGN_CENTER_VERTICAL);
93 time_sizer->Add(m_button_all, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24);
94 m_time_panel->SetSizer(time_sizer);
95 wxBoxSizer *time_sizer2 = new wxBoxSizer(wxHORIZONTAL);
96 time_sizer2->Add(m_time_panel, 1, wxEXPAND);
97 time_panel->SetSizer(time_sizer2);
98 top_sizer->Add(time_panel, 1, wxEXPAND);
99
100 // File type
101 StateColor background(
102 std::make_pair(0xEEEEEE, (int) StateColor::Checked),
103 std::make_pair(*wxLIGHT_GREY, (int) StateColor::Hovered),
104 std::make_pair(*wxWHITE, (int) StateColor::Normal));
105 m_type_panel = new ::StaticBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
106 m_type_panel->SetBackgroundColor(*wxWHITE);
107 m_type_panel->SetCornerRadius(FromDIP(5));
108 m_type_panel->SetMinSize({-1, 48 * em_unit(this) / 10});
109 m_button_timelapse = new ::Button(m_type_panel, _L("Timelapse"), "", wxBORDER_NONE);
110 m_button_timelapse->SetToolTip(_L("Switch to timelapse files."));
111 m_button_video = new ::Button(m_type_panel, _L("Video"), "", wxBORDER_NONE);
112 m_button_video->SetToolTip(_L("Switch to video files."));
113 m_button_model = new ::Button(m_type_panel, _L("Model"), "", wxBORDER_NONE);
114 m_button_video->SetToolTip(_L("Switch to 3MF model files."));
116 b->SetBackgroundColor(background);
117 b->SetCanFocus(false);
118 }
119
120 wxBoxSizer *type_sizer = new wxBoxSizer(wxHORIZONTAL);
121 type_sizer->Add(m_button_timelapse, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24);
122 //type_sizer->Add(m_button_video, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 24);
123 m_button_video->Hide();
124 type_sizer->Add(m_button_model, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 24);
125 m_type_panel->SetSizer(type_sizer);
126 top_sizer->Add(m_type_panel, 0, wxALIGN_CENTER_VERTICAL);
127
128 // File management
129 m_manage_panel = new ::StaticBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
130 m_manage_panel->SetBackgroundColor(StateColor());
131 m_button_delete = new ::Button(m_manage_panel, _L("Delete"));
132 m_button_delete->SetToolTip(_L("Delete selected files from printer."));
133 m_button_download = new ::Button(m_manage_panel, _L("Download"));
134 m_button_download->SetToolTip(_L("Download selected files from printer."));
135 m_button_management = new ::Button(m_manage_panel, _L("Select"));
136 m_button_management->SetToolTip(_L("Batch manage files."));
137 m_button_refresh = new ::Button(m_manage_panel, _L("Refresh"));
138 m_button_refresh->SetToolTip(_L("Reload file list from printer."));
140 b->SetFont(Label::Body_12);
141 b->SetCornerRadius(12);
142 b->SetPaddingSize({10, 6});
143 b->SetCanFocus(false);
144 }
145 m_button_delete->SetBorderColorNormal(wxColor("#FF6F00"));
146 m_button_delete->SetTextColorNormal(wxColor("#FF6F00"));
147 m_button_management->SetBorderWidth(0);
148 m_button_management->SetBackgroundColorNormal(wxColor("#009688"));
149 m_button_management->SetTextColorNormal(*wxWHITE);
150 m_button_management->Enable(false);
151 m_button_refresh->SetBorderWidth(0);
152 m_button_refresh->SetBackgroundColorNormal(wxColor("#009688"));
153 m_button_refresh->SetTextColorNormal(*wxWHITE);
154 m_button_refresh->Enable(false);
155
156 wxBoxSizer *manage_sizer = new wxBoxSizer(wxHORIZONTAL);
157 manage_sizer->AddStretchSpacer(1);
158 manage_sizer->Add(m_button_download, 0, wxALIGN_CENTER_VERTICAL)->Show(false);
159 manage_sizer->Add(m_button_delete, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24)->Show(false);
160 manage_sizer->Add(m_button_refresh, 0, wxALIGN_CENTER_VERTICAL);
161 manage_sizer->Add(m_button_management, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 24);
162 m_manage_panel->SetSizer(manage_sizer);
163 top_sizer->Add(m_manage_panel, 1, wxEXPAND);
164
165 sizer->Add(top_sizer, 0, wxEXPAND);
166
167 m_image_grid = new ImageGrid(this);
168 m_image_grid->Bind(EVT_ITEM_ACTION, [this](wxCommandEvent &e) { doAction(size_t(e.GetExtraLong()), e.GetInt()); });
169 m_image_grid->SetStatus(m_bmp_failed, _L("No printers."));
170 sizer->Add(m_image_grid, 1, wxEXPAND);
171
172 SetSizer(sizer);
173
174 // Time group
175 auto time_button_clicked = [this](wxEvent &e) {
176 auto mode = PrinterFileSystem::G_NONE;
177 if (e.GetEventObject() == m_button_year)
179 else if (e.GetEventObject() == m_button_month)
181 m_image_grid->SetGroupMode(mode);
182 };
183 m_button_year->Bind(wxEVT_COMMAND_BUTTON_CLICKED, time_button_clicked);
184 m_button_month->Bind(wxEVT_COMMAND_BUTTON_CLICKED, time_button_clicked);
185 m_button_all->Bind(wxEVT_COMMAND_BUTTON_CLICKED, time_button_clicked);
186 m_button_all->SetValue(true);
187
188 // File type
189 auto type_button_clicked = [this](wxEvent &e) {
191 auto type = std::find(buttons, buttons + sizeof(buttons) / sizeof(buttons[0]), e.GetEventObject()) - buttons;
192 if (m_last_type == type)
193 return;
194 m_image_grid->SetFileType(type, m_external ? "" : "internal");
195 buttons[m_last_type]->SetValue(!buttons[m_last_type]->GetValue());
196 m_last_type = type;
197 buttons[m_last_type]->SetValue(!buttons[m_last_type]->GetValue());
198 if (type == PrinterFileSystem::F_MODEL)
200 };
201 m_button_timelapse->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
202 m_button_video->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
203 m_button_model->Bind(wxEVT_COMMAND_BUTTON_CLICKED, type_button_clicked);
204 m_button_timelapse->SetValue(true);
205
206 // File management
207 m_button_management->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &e) {
208 e.Skip();
209 SetSelecting(!m_image_grid->IsSelecting());
210 });
211 m_button_refresh->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &e) {
212 e.Skip();
213 if (auto fs = m_image_grid->GetFileSystem())
214 fs->ListAllFiles();
215 });
216 m_button_download->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &e) {
217 m_image_grid->DoActionOnSelection(1);
218 SetSelecting(false);
219 });
220 m_button_delete->Bind(wxEVT_COMMAND_BUTTON_CLICKED, [this](auto &e) {
221 m_image_grid->DoActionOnSelection(0);
222 SetSelecting(false);
223 });
224
225 auto onShowHide = [this](auto &e) {
226 e.Skip();
227 if (auto w = dynamic_cast<wxWindow *>(e.GetEventObject()); !w || w->IsBeingDeleted())
228 return;
229 CallAfter([this] {
230 auto fs = m_image_grid ? m_image_grid->GetFileSystem() : nullptr;
231 if (fs) IsShownOnScreen() ? fs->Start() : fs->Stop();
232 });
233 };
234 Bind(wxEVT_SHOW, onShowHide);
235 parent->GetParent()->Bind(wxEVT_SHOW, onShowHide);
236
237 m_lan_user = "bblp";
238}
#define _L(s)
Definition OBJ.cpp:34
void SetValue(bool state)
Definition Button.cpp:167
static wxFont Head_14
Definition Label.hpp:45
static wxFont Body_12
Definition Label.hpp:55
@ F_MODEL
Definition PrinterFileSystem.h:94
@ G_MONTH
Definition PrinterFileSystem.h:100
@ G_YEAR
Definition PrinterFileSystem.h:101
@ G_NONE
Definition PrinterFileSystem.h:99
std::string m_machine
Definition MediaFilePanel.h:85
::Button * m_button_year
Definition MediaFilePanel.h:66
void doAction(size_t index, int action)
Definition MediaFilePanel.cpp:564
::Button * m_button_month
Definition MediaFilePanel.h:67
::Button * m_button_timelapse
Definition MediaFilePanel.h:72
::Button * m_button_video
Definition MediaFilePanel.h:71
::StaticBox * m_time_panel
Definition MediaFilePanel.h:65
ScalableBitmap m_bmp_empty
Definition MediaFilePanel.h:63
::StaticBox * m_type_panel
Definition MediaFilePanel.h:70
::Button * m_button_download
Definition MediaFilePanel.h:77
::Button * m_button_all
Definition MediaFilePanel.h:68
::Button * m_button_management
Definition MediaFilePanel.h:79
ScalableBitmap m_bmp_loading
Definition MediaFilePanel.h:61
ScalableBitmap m_bmp_failed
Definition MediaFilePanel.h:62
::StaticBox * m_manage_panel
Definition MediaFilePanel.h:75
void SetSelecting(bool selecting)
Definition MediaFilePanel.cpp:439
::Button * m_button_delete
Definition MediaFilePanel.h:76
std::string m_lan_user
Definition MediaFilePanel.h:87
int m_last_type
Definition MediaFilePanel.h:100
::Button * m_button_model
Definition MediaFilePanel.h:73
ImageGrid * m_image_grid
Definition MediaFilePanel.h:81
::Button * m_button_refresh
Definition MediaFilePanel.h:78
bool m_external
Definition MediaFilePanel.h:83
@ Hovered
Definition StateColor.hpp:20
@ Normal
Definition StateColor.hpp:16
@ Checked
Definition StateColor.hpp:18
int em_unit(wxWindow *win)
Definition wxExtensions.cpp:424

References _L, Label::Body_12, StateColor::Checked, doAction(), em_unit(), PrinterFileSystem::F_MODEL, PrinterFileSystem::G_MONTH, PrinterFileSystem::G_NONE, PrinterFileSystem::G_YEAR, Label::Head_14, StateColor::Hovered, m_bmp_empty, m_bmp_failed, m_bmp_loading, m_button_all, m_button_delete, m_button_download, m_button_management, m_button_model, m_button_month, m_button_refresh, m_button_timelapse, m_button_video, m_button_year, m_external, m_image_grid, m_lan_user, m_last_type, m_machine, m_manage_panel, m_time_panel, m_type_panel, StateColor::Normal, SetSelecting(), and Button::SetValue().

Here is the call graph for this function:

◆ ~MediaFilePanel()

Slic3r::GUI::MediaFilePanel::~MediaFilePanel ( )
241{
242 UpdateByObj(nullptr);
243}
void UpdateByObj(MachineObject *obj)
Definition MediaFilePanel.cpp:245

References UpdateByObj().

Here is the call graph for this function:

Member Function Documentation

◆ doAction()

void Slic3r::GUI::MediaFilePanel::doAction ( size_t index,
int action )
private
565{
566 auto fs = m_image_grid->GetFileSystem();
567 if (action == 0) {
568 if (index == -1) {
569 MessageDialog dlg(this,
570 wxString::Format(_L_PLURAL("You are going to delete %u file from printer. Are you sure to continue?",
571 "You are going to delete %u files from printer. Are you sure to continue?", fs->GetSelectCount()),
572 fs->GetSelectCount()),
573 _L("Delete files"), wxYES_NO | wxICON_WARNING);
574 if (dlg.ShowModal() != wxID_YES)
575 return;
576 } else {
577 MessageDialog dlg(this,
578 wxString::Format(_L("Do you want to delete the file '%s' from printer?"), from_u8(fs->GetFile(index).name)),
579 _L("Delete file"), wxYES_NO | wxICON_WARNING);
580 if (dlg.ShowModal() != wxID_YES)
581 return;
582 }
583 fs->DeleteFiles(index);
584 } else if (action == 1) {
585 if (fs->GetFileType() == PrinterFileSystem::F_MODEL) {
586 if (index != -1) {
587 auto dlg = new MediaProgressDialog(_L_CONTEXT("Print", "Verb"), this, [fs] { fs->FetchModelCancel(); });
588 dlg->Update(0, _L("Fetching model information..."));
589 fs->FetchModel(index, [this, fs, dlg, index](int result, std::string const &data) {
590 dlg->Destroy();
592 return;
593 if (result != 0) {
594 wxString msg = data.empty() ? _L("Failed to fetch model information from printer.") :
595 from_u8(data);
596 CallAfter([this, msg] {
597 MessageDialog(this, msg, _L_CONTEXT("Print", "Verb"), wxOK).ShowModal();
598 });
599 return;
600 }
601 Slic3r::DynamicPrintConfig config;
602 Slic3r::Model model;
603 Slic3r::PlateDataPtrs plate_data_list;
604 Slic3r::Semver file_version;
605 std::istringstream is(data);
606 if (!Slic3r::load_gcode_3mf_from_stream(is, &config, &model, &plate_data_list, &file_version)
607 || plate_data_list.empty()) {
608 MessageDialog(this,
609 _L("Failed to parse model information."),
610 _L_CONTEXT("Print", "Verb"), wxOK).ShowModal();
611 return;
612 }
613
614
615 auto &file = fs->GetFile(index);
616
617 std::string file_path = file.path;
618 if (!file_path.empty() && file_path[0] == '/') {
619 file_path.erase(0, 1);
620 }
621
622 int gcode_file_count = Slic3r::GUI::wxGetApp().plater()->update_print_required_data(config, model, plate_data_list, file.name, file_path);
623
624 if (gcode_file_count > 0) {
625 wxPostEvent(Slic3r::GUI::wxGetApp().plater(), SimpleEvent(EVT_PRINT_FROM_SDCARD_VIEW));
626 }
627 else {
628 MessageDialog dlg(this, _L("The .gcode.3mf file contains no G-code data. Please slice it with Orca Slicer and export a new .gcode.3mf file."),
629 wxEmptyString, wxICON_WARNING | wxOK);
630 auto res = dlg.ShowModal();
631 }
632
633 });
634 return;
635 }
636 }
637 if (index != -1) {
638 auto &file = fs->GetFile(index);
639 if (file.IsDownload() && file.DownloadProgress() >= -1) {
640 if (!file.local_path.empty()) {
641 if (!fs->DownloadCheckFile(index)) {
642 MessageDialog(this,
643 wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
644 _L("Error"), wxOK).ShowModal();
645 Refresh();
646 return;
647 }
648#ifdef __WXMSW__
649 auto wfile = boost::filesystem::path(file.local_path).wstring();
650 SHELLEXECUTEINFO info{sizeof(info), 0, NULL, NULL, wfile.c_str(), L"", SW_HIDE};
651 ::ShellExecuteEx(&info);
652#else
653 wxShell("open " + file.local_path);
654#endif
655 } else {
656 fs->DownloadCancel(index);
657 }
658 return;
659 }
660 }
661 fs->DownloadFiles(index, wxGetApp().app_config->get("download_path"));
662 } else if (action == 2) {
663 if (index != -1) {
664 auto &file = fs->GetFile(index);
665 if (file.IsDownload() && file.DownloadProgress() >= -1) {
666 if (!file.local_path.empty()) {
667 if (!fs->DownloadCheckFile(index)) {
668 MessageDialog(this,
669 wxString::Format(_L("File '%s' was lost! Please download it again."), from_u8(file.name)),
670 _L("Error"), wxOK).ShowModal();
671 Refresh();
672 return;
673 }
674 desktop_open_any_folder(file.local_path);
675 } else if (fs->GetFileType() == PrinterFileSystem::F_MODEL) {
676 fs->DownloadCancel(index);
677 }
678 return;
679 }
680 }
681 fs->DownloadFiles(index, wxGetApp().app_config->get("download_path"));
682 }
683}
#define L(s)
Definition ExtrusionEntity.cpp:25
@ ERROR_CANCEL
Definition PrinterFileSystem.h:63
void desktop_open_any_folder(const std::string &path)
Definition GUI.cpp:626
static Plater * plater()
Definition GUI_Factories.cpp:400
wxString from_u8(const std::string &str)
Definition GUI.cpp:544
std::vector< PlateData * > PlateDataPtrs
Definition bbs_3mf.hpp:278
bool load_gcode_3mf_from_stream(std::istream &data, DynamicPrintConfig *config, Model *model, PlateDataPtrs *plate_data_list, Semver *file_version)
Definition bbs_3mf.cpp:9714
#define _L_PLURAL(s, plural, n)
Definition I18N.hpp:96
#define _L_CONTEXT(s, ctx)
Definition I18N.hpp:15

References _L, _L_CONTEXT, _L_PLURAL, Slic3r::GUI::desktop_open_any_folder(), doAction(), PrinterFileSystem::ERROR_CANCEL, PrinterFileSystem::F_MODEL, Slic3r::from_u8(), L, Slic3r::load_gcode_3mf_from_stream(), m_image_grid, Slic3r::GUI::plater(), Slic3r::GUI::DPIAware< P >::ShowModal(), and Slic3r::GUI::ProgressDialog::Update().

Referenced by MediaFilePanel(), and doAction().

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

◆ fetchUrl()

void Slic3r::GUI::MediaFilePanel::fetchUrl ( boost::weak_ptr< PrinterFileSystem > fs)
private
472{
473 boost::shared_ptr fs(wfs.lock());
474 if (!fs || fs != m_image_grid->GetFileSystem()) return;
475 if (!IsEnabled()) {
476 m_waiting_enable = true;
477 m_image_grid->SetStatus(m_bmp_failed, _L("Please confirm if the printer is connected."));
478 fs->SetUrl("0");
479 return;
480 }
481 m_waiting_enable = false;
482 if (!m_local_proto && !m_remote_proto) {
483 m_waiting_support = true;
484 m_image_grid->SetStatus(m_bmp_failed, _L("Browsing file in storage is not supported in current firmware. Please update the printer firmware."));
485 fs->SetUrl("0");
486 return;
487 }
488 if (m_device_busy) {
489 m_image_grid->SetStatus(m_bmp_failed, _L("The printer is currently busy downloading. Please try again after it finishes."));
490 fs->SetUrl("0");
491 return;
492 }
493 BOOST_LOG_TRIVIAL(info) << "MediaFilePanel::fetchUrl: " << m_local_proto << m_remote_proto;
494 m_waiting_support = false;
495 NetworkAgent *agent = wxGetApp().getAgent();
496 std::string agent_version = agent ? agent->get_version() : "";
497 if ((m_lan_mode || !m_remote_proto) && m_local_proto && !m_lan_ip.empty()) {
498 std::string url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd;
499 url += "&device=" + m_machine;
500 url += "&net_ver=" + agent_version;
501 url += "&dev_ver=" + m_dev_ver;
502 url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid");
503 url += "&cli_ver=" + std::string(SLIC3R_VERSION);
504 fs->SetUrl(url);
505 return;
506 }
507 if (!m_remote_proto && m_local_proto) { // not support tutk
508 m_image_grid->SetStatus(m_bmp_failed, _L("Please enter the IP of the printer to connect."));
509 fs->SetUrl("0");
510 fs.reset();
511 if (wxGetApp().show_modal_ip_address_enter_dialog(false, _L("LAN Connection Failed (Failed to view sdcard)"))) {
512 if (auto fs = wfs.lock())
513 fs->Retry();
514 }
515 return;
516 }
517 if (m_lan_mode) {
518 m_image_grid->SetStatus(m_bmp_failed, _L("Browsing file in storage is not supported in LAN Only Mode."));
519 fs->SetUrl("0");
520 return;
521 }
522 if (agent) {
523 std::string protocols[] = {"", "\"tutk\"", "\"agora\"", "\"tutk\",\"agora\""};
524 agent->get_camera_url(m_machine + "|" + m_dev_ver + "|" + protocols[m_remote_proto],
525 [this, wfs, m = m_machine, v = agent->get_version(), dv = m_dev_ver](std::string url) {
526 if (boost::algorithm::starts_with(url, "bambu:///")) {
527 url += "&device=" + m;
528 url += "&net_ver=" + v;
529 url += "&dev_ver=" + dv;
530 url += "&refresh_url=" + boost::lexical_cast<std::string>(&refresh_agora_url);
531 url += "&cli_id=" + wxGetApp().app_config->get("slicer_uuid");
532 url += "&cli_ver=" + std::string(SLIC3R_VERSION);
533 }
534 BOOST_LOG_TRIVIAL(info) << "MediaFilePanel::fetchUrl: camera_url: " << hide_passwd(url, {"?uid=", "authkey=", "passwd="});
535 CallAfter([=] {
536 boost::shared_ptr fs(wfs.lock());
537 if (!fs || fs != m_image_grid->GetFileSystem()) return;
538 if (boost::algorithm::starts_with(url, "bambu:///")) {
539 fs->SetUrl(url);
540 } else {
541 m_image_grid->SetStatus(m_bmp_failed, _L("Connection Failed. Please check the network and try again"));
542 std::string res = "3";
543 if (boost::ends_with(url, "]")) {
544 size_t n = url.find_last_of('[');
545 if (n != std::string::npos)
546 res = url.substr(n + 1, url.length() - n - 2);
547 }
548 fs->SetUrl(res);
549 }
550 });
551 }, wxGetApp().get_printer_cloud_provider());
552 }
553}
int m_remote_proto
Definition MediaFilePanel.h:93
bool m_device_busy
Definition MediaFilePanel.h:95
bool m_lan_mode
Definition MediaFilePanel.h:90
std::string m_dev_ver
Definition MediaFilePanel.h:89
std::string m_lan_ip
Definition MediaFilePanel.h:86
bool m_waiting_support
Definition MediaFilePanel.h:97
int m_local_proto
Definition MediaFilePanel.h:92
bool m_waiting_enable
Definition MediaFilePanel.h:96
std::string m_lan_passwd
Definition MediaFilePanel.h:88
bool IsEnabled()
Definition dark_mode.cpp:32
wxString hide_passwd(wxString url, std::vector< wxString > const &passwords)
Definition MediaPlayCtrl.cpp:351

References _L, Slic3r::NetworkAgent::get_camera_url(), Slic3r::NetworkAgent::get_version(), Slic3r::GUI::hide_passwd(), m_bmp_failed, m_dev_ver, m_device_busy, m_image_grid, m_lan_ip, m_lan_mode, m_lan_passwd, m_lan_user, m_local_proto, m_machine, m_remote_proto, m_waiting_enable, and m_waiting_support.

Referenced by UpdateByObj().

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

◆ modeChanged()

void Slic3r::GUI::MediaFilePanel::modeChanged ( wxCommandEvent & e)
private
452{
453 e1.Skip();
454 auto fs = m_image_grid->GetFileSystem();
455 auto mode = fs ? fs->GetGroupMode() : 0;
456 if (m_last_mode == mode)
457 return;
458 ::Button* buttons[] = {m_button_all, m_button_month, m_button_year};
459 auto b = buttons[m_last_mode];
461 b->SetValue(false);
462 b = buttons[mode];
464 b->SetValue(true);
465 m_last_mode = mode;
466}
bool SetFont(const wxFont &font) override
Definition Button.cpp:81
static wxFont Body_14
Definition Label.hpp:53
int m_last_mode
Definition MediaFilePanel.h:99

References Label::Body_14, Label::Head_14, m_button_all, m_button_month, m_button_year, m_image_grid, m_last_mode, and Button::SetFont().

Referenced by UpdateByObj().

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

◆ Rescale()

void Slic3r::GUI::MediaFilePanel::Rescale ( )
415{
416 m_bmp_loading.msw_rescale();
417 m_bmp_failed.msw_rescale();
418 m_bmp_empty.msw_rescale();
419
420 auto top_sizer = GetSizer()->GetItem((size_t) 0)->GetSizer();
421 top_sizer->SetMinSize({-1, 75 * em_unit(this) / 10});
422 m_button_year->Rescale();
423 m_button_month->Rescale();
424 m_button_all->Rescale();
425
426 m_button_video->Rescale();
427 m_button_timelapse->Rescale();
428 m_button_model->Rescale();
429 m_type_panel->SetMinSize({-1, 48 * em_unit(this) / 10});
430
431 m_button_download->Rescale();
432 m_button_delete->Rescale();
433 m_button_refresh->Rescale();
434 m_button_management->Rescale();
435
436 m_image_grid->Rescale();
437}

References em_unit(), m_bmp_empty, m_bmp_failed, m_bmp_loading, m_button_all, m_button_delete, m_button_download, m_button_management, m_button_model, m_button_month, m_button_refresh, m_button_timelapse, m_button_video, m_button_year, m_image_grid, and m_type_panel.

Here is the call graph for this function:

◆ SetSelecting()

void Slic3r::GUI::MediaFilePanel::SetSelecting ( bool selecting)
440{
441 m_image_grid->SetSelecting(selecting);
442 m_button_management->SetLabel(selecting ? _L("Cancel") : _L("Select"));
443 auto fs = m_image_grid->GetFileSystem();
444 bool download_support = (fs && fs->GetFileType() < PrinterFileSystem::F_MODEL) || m_model_download_support;
445 m_manage_panel->GetSizer()->Show(m_button_download, selecting && download_support);
446 m_manage_panel->GetSizer()->Show(m_button_delete, selecting);
447 m_manage_panel->GetSizer()->Show(m_button_refresh, !selecting);
448 m_manage_panel->Layout();
449}
bool m_model_download_support
Definition MediaFilePanel.h:94

References _L, PrinterFileSystem::F_MODEL, m_button_delete, m_button_download, m_button_management, m_button_refresh, m_image_grid, m_manage_panel, and m_model_download_support.

Referenced by MediaFilePanel(), and UpdateByObj().

Here is the caller graph for this function:

◆ SwitchStorage()

void Slic3r::GUI::MediaFilePanel::SwitchStorage ( bool external)
399{
400 if (m_external == external)
401 return;
402 m_external = external;
403 m_type_panel->Show(external);
404 if (!external) {
406 auto button = buttons[PrinterFileSystem::F_MODEL];
407 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId());
408 event.SetEventObject(button);
409 wxPostEvent(button, event);
410 }
411 m_image_grid->SetFileType(m_last_type, m_external ? "" : "internal");
412}
bool button(const IconManager::Icon &activ, const IconManager::Icon &hover, const IconManager::Icon &disable, bool disabled)
Use icon as button with 3 states activ hover and disabled.
Definition IconManager.cpp:418

References Slic3r::GUI::button(), PrinterFileSystem::F_MODEL, m_button_model, m_button_timelapse, m_button_video, m_external, m_image_grid, m_last_type, and m_type_panel.

Here is the call graph for this function:

◆ UpdateByObj()

void Slic3r::GUI::MediaFilePanel::UpdateByObj ( MachineObject * obj)
246{
247 bool sdcard_state_changed = false;
248 std::string machine = obj ? obj->get_dev_id() : "";
249 if (obj) {
250 m_lan_mode = obj->is_lan_mode_printer();
251 m_lan_ip = obj->get_dev_ip();
252 m_lan_passwd = obj->get_access_code();
253 m_dev_ver = obj->get_ota_version();
254 m_device_busy = obj->is_camera_busy_off();
255 m_local_proto = obj->file_local;
256 m_remote_proto = obj->get_file_remote();
257 m_model_download_support = obj->file_model_download;
258
259 if (m_sdcard_exist != (obj->GetStorage()->get_sdcard_state() == DevStorage::HAS_SDCARD_NORMAL)) {
260 m_sdcard_exist = obj->GetStorage()->get_sdcard_state() == DevStorage::HAS_SDCARD_NORMAL;
261 sdcard_state_changed = true;
262 }
263 } else {
264 m_lan_mode = false;
265 m_lan_ip.clear();
266 m_lan_passwd.clear();
267 m_dev_ver.clear();
268 m_device_busy = false;
269 m_local_proto = 0;
270 m_remote_proto = 0;
272
273 if (m_sdcard_exist) {
274 m_sdcard_exist = false; // reset sdcard state when no object
275 sdcard_state_changed = true;
276 }
277 }
278
279 Enable(obj && obj->is_info_ready() && obj->m_push_count > 0);
280 if (machine == m_machine && !sdcard_state_changed) {
282 auto fs = m_image_grid->GetFileSystem();
283 if (fs) fs->Retry();
284 }
285 return;
286 }
287 m_machine.swap(machine);
288 m_last_errors.clear();
289 auto fs = m_image_grid->GetFileSystem();
290 if (fs) {
291 m_image_grid->SetFileSystem(nullptr);
292 fs->Unbind(EVT_MODE_CHANGED, &MediaFilePanel::modeChanged, this);
293 fs->Stop(true);
294 }
295 m_button_refresh->Enable(false);
296 m_button_management->Enable(false);
297 SetSelecting(false);
298 if (m_machine.empty()) {
299 m_image_grid->SetStatus(m_bmp_failed, _L("Please confirm if the printer is connected."));
300 } else {
301 boost::shared_ptr<PrinterFileSystem> fs(new PrinterFileSystem);
302 fs->Attached();
303 m_image_grid->SetFileSystem(fs);
304 m_image_grid->SetFileType(m_last_type, m_external ? "" : "internal");
305 fs->Bind(EVT_FILE_CHANGED, [this, wfs = boost::weak_ptr(fs)](auto &e) {
306 e.Skip();
307 boost::shared_ptr fs(wfs.lock());
308 if (fs == nullptr || m_image_grid->GetFileSystem() != fs) // canceled
309 return;
310 m_time_panel->Show(fs->GetFileType() < PrinterFileSystem::F_MODEL);
311 //m_manage_panel->Show(fs->GetFileType() < PrinterFileSystem::F_MODEL);
312 m_button_refresh->Enable(fs->GetStatus() == PrinterFileSystem::ListReady);
313 m_button_management->Enable(fs->GetCount() > 0);
314 bool download_support = fs->GetFileType() < PrinterFileSystem::F_MODEL || m_model_download_support;
315 m_image_grid->ShowDownload(download_support);
316 if (fs->GetCount() == 0)
317 SetSelecting(false);
318 });
319 fs->Bind(EVT_SELECT_CHANGED, [this, wfs = boost::weak_ptr(fs)](auto &e) {
320 e.Skip();
321 boost::shared_ptr fs(wfs.lock());
322 if (fs == nullptr || m_image_grid->GetFileSystem() != fs) // canceled
323 return;
324 m_button_delete->Enable(e.GetInt() > 0);
325 m_button_download->Enable(e.GetInt() > 0);
326 });
327 fs->Bind(EVT_MODE_CHANGED, &MediaFilePanel::modeChanged, this);
328 fs->Bind(EVT_STATUS_CHANGED, [this, wfs = boost::weak_ptr(fs)](auto& e) {
329 e.Skip();
330 boost::shared_ptr fs(wfs.lock());
331 if (fs == nullptr || m_image_grid->GetFileSystem() != fs) // canceled
332 return;
333 ScalableBitmap icon;
334 wxString msg;
335 int status = e.GetInt();
336 int extra = e.GetExtraLong();
337 switch (status) {
338 case PrinterFileSystem::Initializing: icon = m_bmp_loading; msg = _L("Initializing..."); break;
339 case PrinterFileSystem::Connecting: icon = m_bmp_loading; msg = _L("Connecting..."); break;
340 case PrinterFileSystem::Failed: icon = m_bmp_failed; if (extra != 1) msg = _L("Please check the network and try again. You can restart or update the printer if the issue persists."); break;
342 icon = m_bmp_loading;
343 msg = _L("Loading file list...");
344 fs->ListAllFiles();
345 break;
346 }
347 case PrinterFileSystem::ListReady: icon = extra == 0 ? m_bmp_empty : m_bmp_failed; msg = extra == 0 ? _L("No files") : _L("Load failed"); break;
348 }
349 int err = fs->GetLastError();
350 if (!e.GetString().IsEmpty())
351 msg = e.GetString();
352 if (err != 0)
353 msg += " [%d]";
354 if (fs->GetCount() == 0 && !msg.empty())
355 m_image_grid->SetStatus(icon, msg);
356 if (e.GetInt() == PrinterFileSystem::Initializing)
357 fetchUrl(boost::weak_ptr(fs));
358
359 if ((status == PrinterFileSystem::Failed && m_last_errors.find(err) == m_last_errors.end()) ||
361 m_last_errors.insert(fs->GetLastError());
362 }
363 });
364 fs->Bind(EVT_DOWNLOAD, [this, wfs = boost::weak_ptr(fs)](auto& e) {
365 e.Skip();
366 boost::shared_ptr fs(wfs.lock());
367 if (fs == nullptr || m_image_grid->GetFileSystem() != fs) // canceled
368 return;
369
370 int result = e.GetExtraLong();
371 if (result > 1 && !e.GetString().IsEmpty())
372 CallAfter([this, m = e.GetString()] {
373 MessageDialog(this, m, _L("Download failed"), wxOK | wxICON_ERROR).ShowModal();
374 });
375
376 NetworkAgent* agent = wxGetApp().getAgent();
377 if (result > 1 || result == 0) {
378 json j;
379 j["code"] = result;
380 j["dev_id"] = m_machine;
381 j["dev_ip"] = m_lan_ip;
382 if (result > 1) {
383 // download failed
384 j["result"] = "failed";
385 } else if (result == 0) {
386 // download success
387 j["result"] = "success";
388 }
389 }
390 return;
391 });
392 if (IsShown()) fs->Start();
393 }
394 wxCommandEvent e(EVT_MODE_CHANGED);
395 modeChanged(e);
396}
@ Initializing
Definition PrinterFileSystem.h:235
@ ListSyncing
Definition PrinterFileSystem.h:237
@ Connecting
Definition PrinterFileSystem.h:236
@ ListReady
Definition PrinterFileSystem.h:238
@ Failed
Definition PrinterFileSystem.h:239
@ HAS_SDCARD_NORMAL
Definition DevStorage.h:19
void modeChanged(wxCommandEvent &e)
Definition MediaFilePanel.cpp:451
std::set< int > m_last_errors
Definition MediaFilePanel.h:101
void fetchUrl(boost::weak_ptr< PrinterFileSystem > fs)
Definition MediaFilePanel.cpp:471
bool m_sdcard_exist
Definition MediaFilePanel.h:91
@ Enable
Definition Config.hpp:245
nlohmann::json json
Definition AssembleList.cpp:42

References _L, PrinterFileSystem::Connecting, Slic3r::Enable, PrinterFileSystem::F_MODEL, PrinterFileSystem::Failed, fetchUrl(), Slic3r::MachineObject::file_local, Slic3r::MachineObject::file_model_download, Slic3r::MachineObject::get_access_code(), Slic3r::MachineObject::get_dev_id(), Slic3r::MachineObject::get_dev_ip(), Slic3r::MachineObject::get_file_remote(), Slic3r::MachineObject::get_ota_version(), Slic3r::DevStorage::get_sdcard_state(), Slic3r::MachineObject::GetStorage(), Slic3r::DevStorage::HAS_SDCARD_NORMAL, PrinterFileSystem::Initializing, Slic3r::MachineObject::is_camera_busy_off(), Slic3r::MachineObject::is_info_ready(), Slic3r::MachineObject::is_lan_mode_printer(), PrinterFileSystem::ListReady, PrinterFileSystem::ListSyncing, m_bmp_empty, m_bmp_failed, m_bmp_loading, m_button_delete, m_button_download, m_button_management, m_button_refresh, m_dev_ver, m_device_busy, m_external, m_image_grid, m_lan_ip, m_lan_mode, m_lan_passwd, m_last_errors, m_last_type, m_local_proto, m_machine, m_model_download_support, Slic3r::MachineObject::m_push_count, m_remote_proto, m_sdcard_exist, m_time_panel, m_waiting_enable, m_waiting_support, modeChanged(), and SetSelecting().

Referenced by ~MediaFilePanel().

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

Member Data Documentation

◆ m_bmp_empty

ScalableBitmap Slic3r::GUI::MediaFilePanel::m_bmp_empty
private

◆ m_bmp_failed

ScalableBitmap Slic3r::GUI::MediaFilePanel::m_bmp_failed
private

◆ m_bmp_loading

ScalableBitmap Slic3r::GUI::MediaFilePanel::m_bmp_loading
private

◆ m_button_all

::Button* Slic3r::GUI::MediaFilePanel::m_button_all = nullptr
private

◆ m_button_delete

::Button* Slic3r::GUI::MediaFilePanel::m_button_delete = nullptr
private

◆ m_button_download

::Button* Slic3r::GUI::MediaFilePanel::m_button_download = nullptr
private

◆ m_button_management

::Button* Slic3r::GUI::MediaFilePanel::m_button_management = nullptr
private

◆ m_button_model

::Button* Slic3r::GUI::MediaFilePanel::m_button_model = nullptr
private

◆ m_button_month

::Button* Slic3r::GUI::MediaFilePanel::m_button_month = nullptr
private

◆ m_button_refresh

::Button* Slic3r::GUI::MediaFilePanel::m_button_refresh = nullptr
private

◆ m_button_timelapse

::Button* Slic3r::GUI::MediaFilePanel::m_button_timelapse = nullptr
private

◆ m_button_video

::Button* Slic3r::GUI::MediaFilePanel::m_button_video = nullptr
private

◆ m_button_year

::Button* Slic3r::GUI::MediaFilePanel::m_button_year = nullptr
private

◆ m_dev_ver

std::string Slic3r::GUI::MediaFilePanel::m_dev_ver
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_device_busy

bool Slic3r::GUI::MediaFilePanel::m_device_busy = false
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_external

bool Slic3r::GUI::MediaFilePanel::m_external = true
private

◆ m_image_grid

ImageGrid* Slic3r::GUI::MediaFilePanel::m_image_grid = nullptr
private

◆ m_lan_ip

std::string Slic3r::GUI::MediaFilePanel::m_lan_ip
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_lan_mode

bool Slic3r::GUI::MediaFilePanel::m_lan_mode = false
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_lan_passwd

std::string Slic3r::GUI::MediaFilePanel::m_lan_passwd
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_lan_user

std::string Slic3r::GUI::MediaFilePanel::m_lan_user
private

Referenced by MediaFilePanel(), and fetchUrl().

◆ m_last_errors

std::set<int> Slic3r::GUI::MediaFilePanel::m_last_errors
private

Referenced by UpdateByObj().

◆ m_last_mode

int Slic3r::GUI::MediaFilePanel::m_last_mode = 0
private

Referenced by modeChanged().

◆ m_last_type

int Slic3r::GUI::MediaFilePanel::m_last_type = 0
private

◆ m_local_proto

int Slic3r::GUI::MediaFilePanel::m_local_proto = false
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_machine

std::string Slic3r::GUI::MediaFilePanel::m_machine
private

◆ m_manage_panel

::StaticBox* Slic3r::GUI::MediaFilePanel::m_manage_panel = nullptr
private

Referenced by MediaFilePanel(), and SetSelecting().

◆ m_model_download_support

bool Slic3r::GUI::MediaFilePanel::m_model_download_support = false
private

Referenced by SetSelecting(), and UpdateByObj().

◆ m_remote_proto

int Slic3r::GUI::MediaFilePanel::m_remote_proto = false
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_sdcard_exist

bool Slic3r::GUI::MediaFilePanel::m_sdcard_exist = false
private

Referenced by UpdateByObj().

◆ m_time_panel

::StaticBox* Slic3r::GUI::MediaFilePanel::m_time_panel = nullptr
private

Referenced by MediaFilePanel(), and UpdateByObj().

◆ m_type_panel

::StaticBox* Slic3r::GUI::MediaFilePanel::m_type_panel = nullptr
private

◆ m_waiting_enable

bool Slic3r::GUI::MediaFilePanel::m_waiting_enable = false
private

Referenced by fetchUrl(), and UpdateByObj().

◆ m_waiting_support

bool Slic3r::GUI::MediaFilePanel::m_waiting_support = false
private

Referenced by fetchUrl(), and UpdateByObj().


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