ENH:support jumping from project to makerworld

jira:[STUDIO-6462]

Change-Id: I35c5612e4aa9f387b30f6fad12419aee2e244217
This commit is contained in:
tao wang 2024-03-14 11:38:29 +08:00 committed by Lane.Wei
parent 1934c96bbb
commit ef118017cd
6 changed files with 94 additions and 4 deletions

View File

@ -116,6 +116,7 @@ const std::string BBL_MODEL_NAME_TAG = "Title";
const std::string BBL_ORIGIN_TAG = "Origin";
const std::string BBL_DESIGNER_TAG = "Designer";
const std::string BBL_DESIGNER_USER_ID_TAG = "DesignerUserId";
//const std::string BBL_DESIGNER_MODEL_ID_TAG = "DesignModelId";
const std::string BBL_DESIGNER_COVER_FILE_TAG = "DesignerCover";
const std::string BBL_DESCRIPTION_TAG = "Description";
const std::string BBL_COPYRIGHT_TAG = "CopyRight";
@ -935,6 +936,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
std::string m_model_id;
std::string m_contry_code;
std::string m_designer;
std::string m_designer_id;
std::string m_designer_user_id;
std::string m_designer_cover;
ModelInfo model_info;
@ -1356,6 +1358,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
if (!m_designer.empty()) {
m_model->design_info = std::make_shared<ModelDesignInfo>();
m_model->design_info->DesignId = m_designer_id;
m_model->design_info->DesignerUserId = m_designer_user_id;
m_model->design_info->Designer = m_designer;
}
@ -1648,6 +1651,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
if (!m_designer.empty()) {
m_model->design_info = std::make_shared<ModelDesignInfo>();
m_model->design_info->DesignId = m_designer_id;
m_model->design_info->DesignerUserId = m_designer_user_id;
m_model->design_info->Designer = m_designer;
}
@ -3581,7 +3585,10 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result)
} else if (m_curr_metadata_name == BBL_DESIGNER_USER_ID_TAG) {
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_user_id = " << m_curr_characters;
m_designer_user_id = xml_unescape(m_curr_characters);
} else if (m_curr_metadata_name == BBL_DESIGNER_COVER_FILE_TAG) {
}else if (m_curr_metadata_name == BBL_DESIGNER_MODEL_ID_TAG) {
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_model_id = " << m_curr_characters;
m_designer_id = xml_unescape(m_curr_characters);
}else if (m_curr_metadata_name == BBL_DESIGNER_COVER_FILE_TAG) {
BOOST_LOG_TRIVIAL(trace) << "design_info, load_3mf found designer_cover = " << m_curr_characters;
model_info.cover_file = xml_unescape(m_curr_characters);
} else if (m_curr_metadata_name == BBL_DESCRIPTION_TAG) {

View File

@ -99,6 +99,7 @@ void ProjectPanel::on_reload(wxCommandEvent& evt)
std::string p_author;
std::string p_description;
std::string p_cover_file;
std::string model_id;
Model model = wxGetApp().plater()->model();
@ -109,6 +110,18 @@ void ProjectPanel::on_reload(wxCommandEvent& evt)
update_type = model.model_info->origin;
if (!model.design_info->DesignId.empty()) {
if (m_model_id_map.count(model.design_info->DesignId) > 0) {
model_id = m_model_id_map[model.design_info->DesignId];
}
else {
model_id = get_model_id(model.design_info->DesignId);
m_model_id_map[model.design_info->DesignId] = model_id;
}
}
try {
if (!model.model_info->copyright.empty()) {
json copy_right = json::parse(model.model_info->copyright);
@ -154,6 +167,7 @@ void ProjectPanel::on_reload(wxCommandEvent& evt)
j["model"]["description"] = wxGetApp().url_encode(description);
j["model"]["preview_img"] = files["Model Pictures"];
j["model"]["upload_type"] = update_type;
j["model"]["model_id"] = model_id;
j["file"]["BOM"] = files["Bill of Materials"];
j["file"]["Assembly"] = files["Assembly Guide"];
@ -180,6 +194,34 @@ void ProjectPanel::on_reload(wxCommandEvent& evt)
});
}
std::string ProjectPanel::get_model_id(std::string desgin_id)
{
std::string model_id;
auto host = wxGetApp().get_http_url(wxGetApp().app_config->get_country_code(), "v1/design-service/model/" + desgin_id);
Http http = Http::get(host);
http.header("accept", "application/json")
//.header("Authorization")
.on_complete([this, &model_id](std::string body, unsigned status) {
try {
json j = json::parse(body);
if (j.contains("id")) {
int mid = j["id"].get<int>();
if (mid > 0) {
model_id = std::to_string(mid);
}
}
}
catch (...) {
;
}
})
.on_error([this](std::string body, std::string error, unsigned status) {
})
.perform_sync();
return model_id;
}
void ProjectPanel::msw_rescale()
{
}
@ -216,6 +258,26 @@ void ProjectPanel::OnScriptMessage(wxWebViewEvent& evt)
}
else if (strCmd == "request_3mf_info") {
m_web_init_completed = true;
}
else if (strCmd == "modelmall_model_open") {
if (j.contains("data")) {
json data = j["data"];
if (data.contains("id")) {
wxString model_id = j["data"]["id"];
if (!model_id.empty()) {
std::string h = wxGetApp().get_model_http_url(wxGetApp().app_config->get_country_code());
auto l = wxGetApp().current_language_code_safe();
if (auto n = l.find('_'); n != std::string::npos)
l = l.substr(0, n);
auto url = (boost::format("%1%%2%/models/%3%") % h % l % model_id).str();
wxLaunchDefaultBrowser(url);
}
}
}
}
else if (strCmd == "debug_info") {
//wxString msg = j["msg"];

View File

@ -65,6 +65,7 @@ private:
wxWebView* m_browser = {nullptr};
wxString m_project_home_url;
wxString m_root_dir;
std::map<std::string, std::string> m_model_id_map;
static inline int m_sequence_id = 8000;
@ -75,7 +76,7 @@ public:
void onWebNavigating(wxWebViewEvent& evt);
void on_reload(wxCommandEvent& evt);
void on_size(wxSizeEvent &event);
void on_size(wxSizeEvent& event);
void on_navigated(wxWebViewEvent& event);
void msw_rescale();
@ -88,6 +89,7 @@ public:
std::map<std::string, std::vector<json>> Reload(wxString aux_path);
std::string formatBytes(unsigned long bytes);
std::string get_model_id(std::string desgin_id);
wxString to_base64(std::string path);
};

View File

@ -67,6 +67,7 @@ func_get_user_nickanme NetworkAgent::get_user_nickanme_ptr = nullpt
func_build_login_cmd NetworkAgent::build_login_cmd_ptr = nullptr;
func_build_logout_cmd NetworkAgent::build_logout_cmd_ptr = nullptr;
func_build_login_info NetworkAgent::build_login_info_ptr = nullptr;
func_get_model_id_from_desgin_id NetworkAgent::get_model_id_from_desgin_id_ptr = nullptr;
func_bind NetworkAgent::bind_ptr = nullptr;
func_unbind NetworkAgent::unbind_ptr = nullptr;
func_get_bambulab_host NetworkAgent::get_bambulab_host_ptr = nullptr;
@ -227,6 +228,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
build_login_cmd_ptr = reinterpret_cast<func_build_login_cmd>(get_network_function("bambu_network_build_login_cmd"));
build_logout_cmd_ptr = reinterpret_cast<func_build_logout_cmd>(get_network_function("bambu_network_build_logout_cmd"));
build_login_info_ptr = reinterpret_cast<func_build_login_info>(get_network_function("bambu_network_build_login_info"));
get_model_id_from_desgin_id_ptr = reinterpret_cast<func_get_model_id_from_desgin_id>(get_network_function("bambu_network_get_model_id_from_desgin_id"));
bind_ptr = reinterpret_cast<func_bind>(get_network_function("bambu_network_bind"));
unbind_ptr = reinterpret_cast<func_unbind>(get_network_function("bambu_network_unbind"));
get_bambulab_host_ptr = reinterpret_cast<func_get_bambulab_host>(get_network_function("bambu_network_get_bambulab_host"));
@ -341,6 +343,7 @@ int NetworkAgent::unload_network_module()
build_login_cmd_ptr = nullptr;
build_logout_cmd_ptr = nullptr;
build_login_info_ptr = nullptr;
get_model_id_from_desgin_id_ptr = nullptr;
bind_ptr = nullptr;
unbind_ptr = nullptr;
get_bambulab_host_ptr = nullptr;
@ -860,6 +863,18 @@ std::string NetworkAgent::build_login_info()
return ret;
}
int NetworkAgent::get_model_id_from_desgin_id(std::string& desgin_id, std::string& model_id)
{
int ret = 0;
if (network_agent && get_model_id_from_desgin_id_ptr) {
ret = get_model_id_from_desgin_id_ptr(network_agent, desgin_id, model_id);
if (ret)
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%, ping code=%3%")
% network_agent % ret % desgin_id;
}
return ret;
}
int NetworkAgent::bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn)
{
int ret = 0;

View File

@ -47,6 +47,7 @@ typedef std::string (*func_get_user_nickanme)(void *agent);
typedef std::string (*func_build_login_cmd)(void *agent);
typedef std::string (*func_build_logout_cmd)(void *agent);
typedef std::string (*func_build_login_info)(void *agent);
typedef int (*func_get_model_id_from_desgin_id)(void *agent, std::string& desgin_id, std::string& model_id);
typedef int (*func_bind)(void *agent, std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
typedef int (*func_unbind)(void *agent, std::string dev_id);
typedef std::string (*func_get_bambulab_host)(void *agent);
@ -151,7 +152,8 @@ public:
std::string build_login_cmd();
std::string build_logout_cmd();
std::string build_login_info();
int bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
int get_model_id_from_desgin_id(std::string& desgin_id, std::string& model_id);
int bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
int unbind(std::string dev_id);
std::string get_bambulab_host();
std::string get_user_selected_machine();
@ -243,6 +245,7 @@ private:
static func_build_login_cmd build_login_cmd_ptr;
static func_build_logout_cmd build_logout_cmd_ptr;
static func_build_login_info build_login_info_ptr;
static func_get_model_id_from_desgin_id get_model_id_from_desgin_id_ptr;
static func_bind bind_ptr;
static func_unbind unbind_ptr;
static func_get_bambulab_host get_bambulab_host_ptr;

View File

@ -14,4 +14,5 @@ set(BBL_INTERNAL_TESTING "1")
endif()
# The build_version should start from 50 in master branch
set(SLIC3R_VERSION "01.08.05.53")
set(SLIC3R_VERSION "01.08.06.51")