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

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

Inheritance diagram for Slic3r::GUI::Downloader:
Collaboration diagram for Slic3r::GUI::Downloader:

Public Member Functions

 Downloader ()
bool get_initialized ()
void init (const boost::filesystem::path &dest_folder)
void start_download (const std::string &full_url)
bool user_action_callback (DownloaderUserAction action, int id)

Private Member Functions

size_t get_next_id ()
void on_progress (wxCommandEvent &event)
void on_error (wxCommandEvent &event)
void on_complete (wxCommandEvent &event)
void on_name_change (wxCommandEvent &event)
void on_paused (wxCommandEvent &event)
void on_canceled (wxCommandEvent &event)
void set_download_state (int id, DownloadState state)

Private Attributes

bool m_initialized { false }
std::vector< std::unique_ptr< Download > > m_downloads
boost::filesystem::path m_dest_folder
size_t m_next_id { 0 }

Detailed Description

Constructor & Destructor Documentation

◆ Downloader()

Slic3r::GUI::Downloader::Downloader ( )
129 : wxEvtHandler()
130{
131 //Bind(EVT_DWNLDR_FILE_COMPLETE, [](const wxCommandEvent& evt) {});
132 //Bind(EVT_DWNLDR_FILE_PROGRESS, [](const wxCommandEvent& evt) {});
133 //Bind(EVT_DWNLDR_FILE_ERROR, [](const wxCommandEvent& evt) {});
134 //Bind(EVT_DWNLDR_FILE_NAME_CHANGE, [](const wxCommandEvent& evt) {});
135
136 Bind(EVT_DWNLDR_FILE_COMPLETE, &Downloader::on_complete, this);
137 Bind(EVT_DWNLDR_FILE_PROGRESS, &Downloader::on_progress, this);
138 Bind(EVT_DWNLDR_FILE_ERROR, &Downloader::on_error, this);
139 Bind(EVT_DWNLDR_FILE_NAME_CHANGE, &Downloader::on_name_change, this);
140 Bind(EVT_DWNLDR_FILE_PAUSED, &Downloader::on_paused, this);
141 Bind(EVT_DWNLDR_FILE_CANCELED, &Downloader::on_canceled, this);
142}
void on_name_change(wxCommandEvent &event)
Definition Downloader.cpp:241
void on_paused(wxCommandEvent &event)
Definition Downloader.cpp:246
void on_canceled(wxCommandEvent &event)
Definition Downloader.cpp:253
void on_error(wxCommandEvent &event)
Definition Downloader.cpp:198
void on_progress(wxCommandEvent &event)
Definition Downloader.cpp:189
void on_complete(wxCommandEvent &event)
Definition Downloader.cpp:207

References on_canceled(), on_complete(), on_error(), on_name_change(), on_paused(), and on_progress().

Here is the call graph for this function:

Member Function Documentation

◆ get_initialized()

bool Slic3r::GUI::Downloader::get_initialized ( )
inline
65{ return m_initialized; }
bool m_initialized
Definition Downloader.hpp:75

References m_initialized.

◆ get_next_id()

size_t Slic3r::GUI::Downloader::get_next_id ( )
inlineprivate
81{ return ++m_next_id; }
size_t m_next_id
Definition Downloader.hpp:80

References m_next_id.

Referenced by start_download().

Here is the caller graph for this function:

◆ init()

void Slic3r::GUI::Downloader::init ( const boost::filesystem::path & dest_folder)
inline
67 {
68 m_dest_folder = dest_folder;
69 m_initialized = true;
70 }
boost::filesystem::path m_dest_folder
Definition Downloader.hpp:78

References m_dest_folder, and m_initialized.

◆ on_canceled()

void Slic3r::GUI::Downloader::on_canceled ( wxCommandEvent & event)
private
254{
255 size_t id = event.GetInt();
256 NotificationManager* ntf_mngr = wxGetApp().notification_manager();
257 ntf_mngr->set_download_URL_canceled(id);
258}

References Slic3r::GUI::NotificationManager::set_download_URL_canceled().

Referenced by Downloader().

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

◆ on_complete()

void Slic3r::GUI::Downloader::on_complete ( wxCommandEvent & event)
private
208{
209 // TODO: is this always true? :
210 // here we open the file itself, notification should get 1.f progress from on progress.
212 wxArrayString paths;
213 paths.Add(event.GetString());
214 wxGetApp().plater()->load_files(paths);
215}
void set_download_state(int id, DownloadState state)
Definition Downloader.cpp:260
@ DownloadDone
Definition Downloader.hpp:24

References Slic3r::GUI::DownloadDone, and set_download_state().

Referenced by Downloader().

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

◆ on_error()

void Slic3r::GUI::Downloader::on_error ( wxCommandEvent & event)
private
199{
200 size_t id = event.GetInt();
202 BOOST_LOG_TRIVIAL(error) << "Download error: " << event.GetString();
203 NotificationManager* ntf_mngr = wxGetApp().notification_manager();
204 ntf_mngr->set_download_URL_error(id, into_u8(event.GetString()));
205 show_error(nullptr, format_wxstr(L"%1%\n%2%", _L("The download has failed") + ":", event.GetString()));
206}
#define L(s)
Definition ExtrusionEntity.cpp:25
#define _L(s)
Definition OBJ.cpp:34
wxString format_wxstr(const char *fmt, TArgs &&... args)
Definition format.hpp:22
void show_error(wxWindow *parent, const wxString &message, bool has_code_excerpts)
Definition GUI.cpp:296
@ DownloadError
Definition Downloader.hpp:25
std::string into_u8(const wxString &str)
Definition GUI.cpp:549

References _L, Slic3r::GUI::DownloadError, Slic3r::GUI::format_wxstr(), Slic3r::GUI::into_u8(), L, set_download_state(), Slic3r::GUI::NotificationManager::set_download_URL_error(), and Slic3r::GUI::show_error().

Referenced by Downloader().

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

◆ on_name_change()

void Slic3r::GUI::Downloader::on_name_change ( wxCommandEvent & event)
private
242{
243
244}

Referenced by Downloader().

Here is the caller graph for this function:

◆ on_paused()

void Slic3r::GUI::Downloader::on_paused ( wxCommandEvent & event)
private
247{
248 size_t id = event.GetInt();
249 NotificationManager* ntf_mngr = wxGetApp().notification_manager();
250 ntf_mngr->set_download_URL_paused(id);
251}

References Slic3r::GUI::NotificationManager::set_download_URL_paused().

Referenced by Downloader().

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

◆ on_progress()

void Slic3r::GUI::Downloader::on_progress ( wxCommandEvent & event)
private
190{
191 size_t id = event.GetInt();
192 float percent = (float)std::stoi(into_u8(event.GetString())) / 100.f;
193 //BOOST_LOG_TRIVIAL(error) << "progress " << id << ": " << percent;
194 NotificationManager* ntf_mngr = wxGetApp().notification_manager();
195 BOOST_LOG_TRIVIAL(trace) << "Download "<< id << ": " << percent;
196 ntf_mngr->set_download_URL_progress(id, percent);
197}
void trace(unsigned int level, const char *message)
Definition utils.cpp:247

References Slic3r::GUI::into_u8(), Slic3r::GUI::NotificationManager::set_download_URL_progress(), and Slic3r::trace().

Referenced by Downloader().

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

◆ set_download_state()

void Slic3r::GUI::Downloader::set_download_state ( int id,
DownloadState state )
private
261{
262 for (size_t i = 0; i < m_downloads.size(); ++i) {
263 if (m_downloads[i]->get_id() == id) {
264 m_downloads[i]->set_state(state);
265 return;
266 }
267 }
268}
std::vector< std::unique_ptr< Download > > m_downloads
Definition Downloader.hpp:77

References m_downloads.

Referenced by on_complete(), and on_error().

Here is the caller graph for this function:

◆ start_download()

void Slic3r::GUI::Downloader::start_download ( const std::string & full_url)
145{
146 assert(m_initialized);
147
148 // Orca: Move to the 3D view
149 MainFrame* mainframe = wxGetApp().mainframe;
150 Plater* plater = wxGetApp().plater();
151
152 mainframe->Freeze();
153 mainframe->select_tab(TAB_ID_PREPARE);
154 plater->select_view_3D("3D");
155 plater->select_view("plate");
157 mainframe->Thaw();
158
159 // Orca: Replace PS workaround for "mysterious slash" with a more dynamic approach
160 // Windows seems to have fixed the issue and this provides backwards compatability for those it still affects
161 boost::regex re(R"(^(orcaslicer|prusaslicer|bambustudio|cura):\/\/open[\/]?\?file=)", boost::regbase::icase);
162 boost::regex re2(R"(^(bambustudioopen):\/\/)", boost::regex::icase);
163 boost::smatch results;
164
165 if (!boost::regex_search(full_url, results, re) && !boost::regex_search(full_url, results, re2)) {
166 BOOST_LOG_TRIVIAL(error) << "Could not start download due to wrong URL: " << full_url;
167 // Orca: show error
168 NotificationManager* ntf_mngr = wxGetApp().notification_manager();
170 _u8L("Could not start download due to malformed URL"));
171 return;
172 }
173 size_t id = get_next_id();
174 std::string escaped_url = FileGet::escape_url(full_url.substr(results.length()));
175 if (is_bambustudio_open(full_url) || (is_orca_open(full_url) && is_makerworld_link(full_url)))
176 plater->request_model_download(wxString::FromUTF8(escaped_url));
177 else {
178 std::string text(escaped_url);
179 m_downloads.emplace_back(std::make_unique<Download>(id, std::move(escaped_url), this, m_dest_folder));
180 NotificationManager* ntf_mngr = wxGetApp().notification_manager();
181 ntf_mngr->push_download_URL_progress_notification(id, m_downloads.back()->get_filename(),
182 std::bind(&Downloader::user_action_callback, this, std::placeholders::_1,
183 std::placeholders::_2));
184 m_downloads.back()->start();
185 }
186 BOOST_LOG_TRIVIAL(debug) << "started download";
187}
#define TAB_ID_PREPARE
Definition MainFrame.hpp:60
size_t get_next_id()
Definition Downloader.hpp:81
bool user_action_callback(DownloaderUserAction action, int id)
Definition Downloader.cpp:216
static std::string escape_url(const std::string &url)
Definition DownloaderFileGet.cpp:37
void zoom_to_bed()
Definition GLCanvas3D.cpp:2345
@ ErrorNotificationLevel
Definition NotificationManager.hpp:228
GLCanvas3D * get_current_canvas3D(bool exclude_preview=false)
Definition Plater.cpp:22126
void request_model_download(wxString url)
Definition Plater.cpp:16599
void select_view(const std::string &direction)
Definition Plater.cpp:19116
void select_view_3D(const std::string &name, bool no_slice=true)
Definition Plater.cpp:19119
static Plater * plater()
Definition GUI_Factories.cpp:400
@ CustomNotification
Definition NotificationManager.hpp:66
@ Plater
Definition Shortcuts.hpp:21
bool is_makerworld_link(const std::string &url)
Definition utils.cpp:2307
bool is_bambustudio_open(const std::string &url)
Definition Utils.hpp:315
bool is_orca_open(const std::string &url)
Definition Utils.hpp:313
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::GUI::CustomNotification, Slic3r::GUI::NotificationManager::ErrorNotificationLevel, Slic3r::GUI::FileGet::escape_url(), get_next_id(), Slic3r::is_bambustudio_open(), Slic3r::is_makerworld_link(), Slic3r::is_orca_open(), m_dest_folder, m_downloads, m_initialized, Slic3r::GUI::plater(), Slic3r::GUI::NotificationManager::push_download_URL_progress_notification(), Slic3r::GUI::NotificationManager::push_notification(), Slic3r::GUI::MainFrame::select_tab(), TAB_ID_PREPARE, and user_action_callback().

Here is the call graph for this function:

◆ user_action_callback()

bool Slic3r::GUI::Downloader::user_action_callback ( DownloaderUserAction action,
int id )
217{
218 for (size_t i = 0; i < m_downloads.size(); ++i) {
219 if (m_downloads[i]->get_id() == id) {
220 switch (action) {
222 m_downloads[i]->cancel();
223 return true;
225 m_downloads[i]->pause();
226 return true;
228 m_downloads[i]->resume();
229 return true;
231 open_folder(m_downloads[i]->get_dest_folder());
232 return true;
233 default:
234 return false;
235 }
236 }
237 }
238 return false;
239}
void open_folder(const std::string &path)
Definition Downloader.cpp:31
@ DownloadUserContinued
Definition Downloader.hpp:34
@ DownloadUserCanceled
Definition Downloader.hpp:32
@ DownloadUserPaused
Definition Downloader.hpp:33
@ DownloadUserOpenedFolder
Definition Downloader.hpp:35

References Slic3r::GUI::DownloadUserCanceled, Slic3r::GUI::DownloadUserContinued, Slic3r::GUI::DownloadUserOpenedFolder, Slic3r::GUI::DownloadUserPaused, and m_downloads.

Referenced by start_download().

Here is the caller graph for this function:

Member Data Documentation

◆ m_dest_folder

boost::filesystem::path Slic3r::GUI::Downloader::m_dest_folder
private

Referenced by init(), and start_download().

◆ m_downloads

std::vector<std::unique_ptr<Download> > Slic3r::GUI::Downloader::m_downloads
private

◆ m_initialized

bool Slic3r::GUI::Downloader::m_initialized { false }
private
75{ false };

Referenced by get_initialized(), init(), and start_download().

◆ m_next_id

size_t Slic3r::GUI::Downloader::m_next_id { 0 }
private
80{ 0 };

Referenced by get_next_id().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Downloader.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Downloader.cpp