diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 373ee1f91c..11713efbfb 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -973,6 +973,20 @@ static void generic_exception_handle() //#endif } +static vector split_str(const string& src, const string& separator) +{ + size_t pos; + size_t start_pos = 0; + vector result_str; + while ((pos = src.find(separator, start_pos)) != string::npos) + { + result_str.emplace_back(src.substr(start_pos, pos - start_pos)); + start_pos = pos + separator.size(); + } + result_str.emplace_back(src.substr(start_pos, src.size() - pos - separator.size())); + return result_str; +} + void GUI_App::post_init() { assert(initialized()); @@ -981,25 +995,47 @@ void GUI_App::post_init() bool switch_to_3d = false; if (!this->init_params->input_files.empty()) { + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", init with input files, size %1%, input_gcode %2%") %this->init_params->input_files.size() %this->init_params->input_gcode; - switch_to_3d = true; - if (this->init_params->input_gcode) { - mainframe->select_tab(size_t(MainFrame::tp3DEditor)); - plater_->select_view_3D("3D"); - this->plater()->load_gcode(from_u8(this->init_params->input_files.front())); + + + + if (this->init_params->input_files.size() == 1 && + boost::starts_with(this->init_params->input_files.front(), "bambustudio://open")) { + auto input_str_arr = split_str(this->init_params->input_files.front(), "bambustudio://open/?file="); + + std::string download_origin_url; + for (auto input_str:input_str_arr) { + if (!input_str.empty()) download_origin_url = input_str; + } + + std::string download_file_url = url_decode(download_origin_url); + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << download_file_url; + if (!download_file_url.empty() && ( boost::starts_with(download_file_url, "http://") || boost::starts_with(download_file_url, "https://")) ) { + request_model_download(download_origin_url); + } } else { - mainframe->select_tab(size_t(MainFrame::tp3DEditor)); - plater_->select_view_3D("3D"); - const std::vector res = this->plater()->load_files(this->init_params->input_files); - if (!res.empty()) { - if (this->init_params->input_files.size() == 1) { - // Update application titlebar when opening a project file - const std::string& filename = this->init_params->input_files.front(); - //BBS: remove amf logic as project - if (boost::algorithm::iends_with(filename, ".3mf")) - this->plater()->set_project_filename(from_u8(filename)); + switch_to_3d = true; + if (this->init_params->input_gcode) { + mainframe->select_tab(size_t(MainFrame::tp3DEditor)); + plater_->select_view_3D("3D"); + this->plater()->load_gcode(from_u8(this->init_params->input_files.front())); + } + else { + mainframe->select_tab(size_t(MainFrame::tp3DEditor)); + plater_->select_view_3D("3D"); + const std::vector res = this->plater()->load_files(this->init_params->input_files); + if (!res.empty()) { + if (this->init_params->input_files.size() == 1) { + // Update application titlebar when opening a project file + const std::string& filename = this->init_params->input_files.front(); + //BBS: remove amf logic as project + if (boost::algorithm::iends_with(filename, ".3mf")) + this->plater()->set_project_filename(from_u8(filename)); + } } } } @@ -3451,22 +3487,6 @@ std::string GUI_App::handle_web_request(std::string cmd) { try { //BBS use nlohmann json format - json j = json::parse(cmd); - - std::string web_cmd = j["command"].get(); - - if (web_cmd == "request_model_download") { - std::string download_url = ""; - if (j["data"].contains("download_url")) - download_url = j["data"]["download_url"].get(); - - std::string filename = ""; - if (j["data"].contains("filename")) - download_url = j["data"]["filename"].get(); - - this->request_model_download(download_url, filename); - } - std::stringstream ss(cmd), oss; pt::ptree root, response; pt::read_json(ss, root); @@ -3646,12 +3666,10 @@ void GUI_App::handle_script_message(std::string msg) } } -void GUI_App::request_model_download(std::string url, std::string filename) +void GUI_App::request_model_download(std::string url) { - if (!check_login()) return; - if (plater_) { - plater_->request_model_download(); + plater_->request_model_download(url); } } @@ -5523,25 +5541,16 @@ void GUI_App::open_publish_page_dialog() wxLaunchDefaultBrowser(link_url); } -std::string GUI_App::url_encode(const std::string& value) { - std::ostringstream escaped; - escaped.fill('0'); - escaped << std::hex; - for (std::string::const_iterator i = value.begin(), n = value.end(); i != n; ++i) { - std::string::value_type c = (*i); +char GUI_App::from_hex(char ch) { + return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; +} - // Keep alphanumeric and other accepted characters intact - if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') { - escaped << c; - continue; - } +std::string GUI_App::url_decode(std::string value) { + return Http::url_decode(value); +} - // Any other characters are percent-encoded - escaped << std::uppercase; - escaped << '%' << std::setw(2) << int((unsigned char)c); - escaped << std::nouppercase; - } - return escaped.str(); +std::string GUI_App::url_encode(std::string value) { + return Http::url_encode(value); } void GUI_App::remove_mall_system_dialog() diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 45465aac9c..41c691a1a0 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -402,7 +402,7 @@ public: int request_user_unbind(std::string dev_id); std::string handle_web_request(std::string cmd); void handle_script_message(std::string msg); - void request_model_download(std::string url, std::string filename); + void request_model_download(std::string url); void download_project(std::string project_id); void request_project_download(std::string project_id); void request_open_project(std::string project_id); @@ -519,13 +519,16 @@ public: void load_url(wxString url); void open_mall_page_dialog(); - std::string url_encode(const std::string& value); void open_publish_page_dialog(); void remove_mall_system_dialog(); void run_script(wxString js); bool is_adding_script_handler() { return m_adding_script_handler; } void set_adding_script_handler(bool status) { m_adding_script_handler = status; } + char from_hex(char ch); + std::string url_encode(std::string value); + std::string url_decode(std::string value); + // Parameters extracted from the command line to be passed to GUI after initialization. GUI_InitParams* init_params { nullptr }; diff --git a/src/slic3r/GUI/ModelMall.cpp b/src/slic3r/GUI/ModelMall.cpp index bcc0a7e554..8fabd073e4 100644 --- a/src/slic3r/GUI/ModelMall.cpp +++ b/src/slic3r/GUI/ModelMall.cpp @@ -127,32 +127,8 @@ namespace GUI { json j = json::parse(strInput); wxString strCmd = j["command"]; - - if (strCmd == "request_model_download") { - - std::string model_id = ""; - if (j["data"].contains("download_url")) - model_id = j["data"]["model_id"].get(); - - std::string profile_id = ""; - if (j["data"].contains("profile_id")) - profile_id = j["data"]["profile_id"].get(); - - std::string download_url = ""; - if (j["data"].contains("download_url")) - download_url = j["data"]["download_url"].get(); - - std::string filename = ""; - if (j["data"].contains("filename")) - filename = j["data"]["filename"].get(); - - if (download_url.empty()) return; - - wxGetApp().set_download_model_url(download_url); - wxGetApp().set_download_model_name(filename); - wxGetApp().plater()->request_model_download(); - } - else if(strCmd == "request_close_publish_window") { + + if(strCmd == "request_close_publish_window") { this->Hide(); } diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index d42e3d8d25..751a233b43 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -7760,15 +7760,13 @@ int Plater::save_project(bool saveAs) //BBS import model by model id void Plater::import_model_id(const std::string& download_info) { - std::string download_url = wxGetApp().get_download_model_url(); - std::string filename = wxGetApp().get_download_model_name(); + std::string download_url; + std::string filename; - /* auto selection_data_arr = wxSplit(download_info, '|'); - - if (selection_data_arr.size() == 2) { - download_url = selection_data_arr[0].ToStdString(); - filename = selection_data_arr[1].ToStdString(); - }*/ + std::string download_origin_url = wxGetApp().url_decode(download_info); + fs::path download_path = fs::path(download_origin_url); + download_url = download_origin_url; + filename = download_path.filename().string(); bool download_ok = false; @@ -7945,9 +7943,10 @@ void Plater::download_project(const wxString& project_id) return; } -void Plater::request_model_download() +void Plater::request_model_download(std::string url) { wxCommandEvent* event = new wxCommandEvent(EVT_IMPORT_MODEL_ID); + event->SetString(url); wxQueueEvent(this, event); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index a132f3d38c..130b20f174 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -211,7 +211,7 @@ public: //BBS download project by project id void import_model_id(const std::string& download_info); void download_project(const wxString& project_id); - void request_model_download(); + void request_model_download(std::string url); void request_download_project(std::string project_id); // BBS: check snapshot bool up_to_date(bool saved, bool backup); diff --git a/src/slic3r/GUI/Project.cpp b/src/slic3r/GUI/Project.cpp index 18fb956c8b..57f43d13db 100644 --- a/src/slic3r/GUI/Project.cpp +++ b/src/slic3r/GUI/Project.cpp @@ -170,7 +170,7 @@ void ProjectPanel::OnScriptMessage(wxWebViewEvent& evt) wxString accessory_path = j["accessory_path"]; if (!accessory_path.empty()) { - std::string decode_path = url_decode(accessory_path.ToStdString()); + std::string decode_path = wxGetApp().url_decode(accessory_path.ToStdString()); fs::path path(decode_path); if (fs::exists(path)) { @@ -352,36 +352,6 @@ void ProjectPanel::RunScript(std::string content) WebView::RunScript(m_browser, content); } -char ProjectPanel::from_hex(char ch) { - return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10; -} - -std::string ProjectPanel::url_decode(string text) { - char h; - ostringstream escaped; - escaped.fill('0'); - - for (auto i = text.begin(), n = text.end(); i != n; ++i) { - string::value_type c = (*i); - - if (c == '%') { - if (i[1] && i[2]) { - h = from_hex(i[1]) << 4 | from_hex(i[2]); - escaped << h; - i += 2; - } - } - else if (c == '+') { - escaped << ' '; - } - else { - escaped << c; - } - } - - return escaped.str(); -} - bool ProjectPanel::Show(bool show) { if (show) update_model_data(); diff --git a/src/slic3r/GUI/Project.hpp b/src/slic3r/GUI/Project.hpp index d001f013e1..952f05d2c5 100644 --- a/src/slic3r/GUI/Project.hpp +++ b/src/slic3r/GUI/Project.hpp @@ -85,9 +85,6 @@ public: void OnScriptMessage(wxWebViewEvent& evt); void RunScript(std::string content); - char from_hex(char ch); - std::string url_decode(string text); - std::string url_encode(const std::string& value); std::map> Reload(wxString aux_path); std::string formatBytes(unsigned long bytes); wxString to_base64(std::string path);