mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 09:17:52 -06:00
NEW:support for launching studio from the model web
Change-Id: I931fc8633c057228441daf2ab4c9c37f97e898ab
This commit is contained in:
parent
6f141ea740
commit
7481da52d6
7 changed files with 78 additions and 124 deletions
|
@ -973,6 +973,20 @@ static void generic_exception_handle()
|
|||
//#endif
|
||||
}
|
||||
|
||||
static vector<string> split_str(const string& src, const string& separator)
|
||||
{
|
||||
size_t pos;
|
||||
size_t start_pos = 0;
|
||||
vector<string> 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,8 +995,29 @@ 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;
|
||||
|
||||
|
||||
|
||||
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 {
|
||||
switch_to_3d = true;
|
||||
if (this->init_params->input_gcode) {
|
||||
mainframe->select_tab(size_t(MainFrame::tp3DEditor));
|
||||
|
@ -1004,6 +1039,7 @@ void GUI_App::post_init()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//#if BBL_HAS_FIRST_PAGE
|
||||
bool slow_bootup = false;
|
||||
if (app_config->get("slow_bootup") == "true") {
|
||||
|
@ -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<std::string>();
|
||||
|
||||
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>();
|
||||
|
||||
std::string filename = "";
|
||||
if (j["data"].contains("filename"))
|
||||
download_url = j["data"]["filename"].get<std::string>();
|
||||
|
||||
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);
|
||||
|
||||
// Keep alphanumeric and other accepted characters intact
|
||||
if (isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
|
||||
escaped << c;
|
||||
continue;
|
||||
char GUI_App::from_hex(char ch) {
|
||||
return isdigit(ch) ? ch - '0' : tolower(ch) - 'a' + 10;
|
||||
}
|
||||
|
||||
// Any other characters are percent-encoded
|
||||
escaped << std::uppercase;
|
||||
escaped << '%' << std::setw(2) << int((unsigned char)c);
|
||||
escaped << std::nouppercase;
|
||||
std::string GUI_App::url_decode(std::string value) {
|
||||
return Http::url_decode(value);
|
||||
}
|
||||
return escaped.str();
|
||||
|
||||
std::string GUI_App::url_encode(std::string value) {
|
||||
return Http::url_encode(value);
|
||||
}
|
||||
|
||||
void GUI_App::remove_mall_system_dialog()
|
||||
|
|
|
@ -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 };
|
||||
|
||||
|
|
|
@ -128,31 +128,7 @@ namespace GUI {
|
|||
|
||||
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>();
|
||||
|
||||
std::string profile_id = "";
|
||||
if (j["data"].contains("profile_id"))
|
||||
profile_id = j["data"]["profile_id"].get<std::string>();
|
||||
|
||||
std::string download_url = "";
|
||||
if (j["data"].contains("download_url"))
|
||||
download_url = j["data"]["download_url"].get<std::string>();
|
||||
|
||||
std::string filename = "";
|
||||
if (j["data"].contains("filename"))
|
||||
filename = j["data"]["filename"].get<std::string>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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<std::string, std::vector<json>> Reload(wxString aux_path);
|
||||
std::string formatBytes(unsigned long bytes);
|
||||
wxString to_base64(std::string path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue