FIX: support internal HMS

jira: [STUDIO-9617]
Change-Id: I5c073966244171a85f43e4bb014b02c00886fef3
This commit is contained in:
xin.zhang 2025-01-09 16:08:13 +08:00 committed by lane.wei
parent 753e2ac708
commit d5a8675bad
47 changed files with 226573 additions and 29960 deletions

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_de_094.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_es_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_fr_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_hu_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_it_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_ja_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_ko_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_nl_094.json Normal file

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_pl_094.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

15061
resources/hms/hms_sv_094.json Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

View File

@ -4,6 +4,7 @@
#include <boost/log/trivial.hpp>
static const char* HMS_PATH = "hms";
static const char* HMS_LOCAL_IMG_PATH = "hms/local_image";
namespace Slic3r {
namespace GUI {
@ -120,43 +121,49 @@ int HMSQuery::download_hms_related(const std::string& hms_type, const std::strin
return 0;
}
static void
_copy_dir(const fs::path& from_dir, const fs::path& to_dir) /* the copy will not override files*/
{
try
{
if (!fs::exists(from_dir))
{
return;
}
if (!fs::exists(to_dir))
{
fs::create_directory(to_dir);
}
for (const auto &entry : fs::directory_iterator(from_dir))
{
const fs::path &source_path = entry.path();
const fs::path &relative_path = fs::relative(source_path, from_dir);
const fs::path &dest_path = to_dir / relative_path;
if (fs::is_regular_file(source_path) && !fs::exists(dest_path))
{
copy_file(source_path, dest_path);
}
else if (fs::is_directory(source_path))
{
_copy_dir(source_path, dest_path);
}
}
}
catch (...)
{
}
}
void HMSQuery::copy_from_data_dir_to_local()
{
const fs::path& from_dir = fs::path(Slic3r::resources_dir()) / HMS_PATH;
if (!fs::exists(from_dir))
{
assert(0);
return;
}
const fs::path& to_dir = fs::path(Slic3r::data_dir()) / HMS_PATH;
if (!fs::exists(to_dir))
{
fs::create_directory(to_dir);
}
try
{
for (const auto& entry : fs::directory_iterator(from_dir))
{
const fs::path& source_path = entry.path();
const fs::path& relative_path = fs::relative(source_path, from_dir);
const fs::path& dest_path = to_dir / relative_path;
if (fs::exists(dest_path))
{
continue;
}
if (fs::is_regular_file(source_path))
{
copy_file(source_path, dest_path);
}
}
}
catch (const std::exception&)
{
}
_copy_dir(from_dir, to_dir);
}
int HMSQuery::load_from_local(const std::string& hms_type, const std::string& dev_id_type, json* load_json, std::string& load_version)
@ -405,7 +412,7 @@ wxString HMSQuery::_query_error_msg(const std::string& dev_id_type,
return wxEmptyString;
}
wxString HMSQuery::_query_error_url_action(const std::string& dev_id_type, const std::string& long_error_code, std::vector<int>& button_action)
wxString HMSQuery::_query_error_image_action(const std::string& dev_id_type, const std::string& long_error_code, std::vector<int>& button_action)
{
init_hms_info(dev_id_type);
@ -462,7 +469,8 @@ wxString HMSQuery::query_print_error_msg(const std::string& dev_id, int print_er
return _query_error_msg(dev_id.substr(0, 3), std::string(buf), lang_code);
}
wxString HMSQuery::query_print_error_url_action(const MachineObject* obj, int print_error, std::vector<int>& button_action)
wxString HMSQuery::query_print_image_action(const MachineObject* obj, int print_error, std::vector<int>& button_action)
{
if (!obj)
{
@ -472,7 +480,37 @@ wxString HMSQuery::query_print_error_url_action(const MachineObject* obj, int pr
char buf[32];
::sprintf(buf, "%08X", print_error);
//The first three digits of SN number
return _query_error_url_action(get_dev_id_type(obj),std::string(buf), button_action);
return _query_error_image_action(get_dev_id_type(obj),std::string(buf), button_action);
}
wxImage HMSQuery::query_image_from_local(const wxString& image_name)
{
if (image_name.empty() || image_name.Contains("http"))
{
return wxImage();
}
if (m_hms_local_images.empty())
{
const fs::path& local_img_dir = fs::path(Slic3r::data_dir()) / HMS_LOCAL_IMG_PATH;
if (fs::exists(local_img_dir))
{
for (const auto &entry : fs::directory_iterator(local_img_dir))
{
const fs::path& image_path = entry.path();
const fs::path& image_name = fs::relative(image_path, local_img_dir);
m_hms_local_images[image_name.string()] = wxImage(wxString::FromUTF8(image_path.string()));
}
}
}
auto iter = m_hms_local_images.find(image_name);
if (iter != m_hms_local_images.end())
{
return iter->second;
}
return wxImage();
}
void HMSQuery::clear_hms_info()

View File

@ -28,6 +28,7 @@ class HMSQuery {
protected:
std::unordered_map<string, json> m_hms_info_jsons; // key-> device id type, the first three digits of SN number
std::unordered_map<string, json> m_hms_action_jsons;// key-> device id type
std::unordered_map<wxString, wxImage> m_hms_local_images; // key-> image name
mutable std::mutex m_hms_mutex;
public:
@ -43,7 +44,10 @@ public:
wxString query_hms_msg(const std::string& dev_id, const std::string& long_error_code);
wxString query_print_error_msg(const MachineObject* obj, int print_error);
wxString query_print_error_msg(const std::string& dev_id, int print_error);
wxString query_print_error_url_action(const MachineObject* obj, int print_error, std::vector<int>& button_action);
wxString query_print_image_action(const MachineObject* obj, int print_error, std::vector<int>& button_action);
// query local images
wxImage query_image_from_local(const wxString& image_name);
public:
static std::string hms_language_code();
@ -62,7 +66,7 @@ private:
string get_dev_id_type(const MachineObject* obj) const;
wxString _query_hms_msg(const string& dev_id_type, const string& long_error_code, const string& lang_code = std::string("en"));
wxString _query_error_msg(const string& dev_id_type, const std::string& long_error_code, const std::string& lang_code = std::string("en"));
wxString _query_error_url_action(const string& dev_id_type, const std::string& long_error_code, std::vector<int>& button_action);
wxString _query_error_image_action(const string& dev_id_type, const std::string& long_error_code, std::vector<int>& button_action);
};
int get_hms_info_version(std::string &version);

View File

@ -965,11 +965,23 @@ void PrintErrorDialog::update_text_image(const wxString& text, const wxString& e
m_vebview_release_note->SetSizer(sizer_text_release_note);
if (!image_url.empty()) {
web_request = wxWebSession::GetDefault().CreateRequest(this, image_url);
BOOST_LOG_TRIVIAL(trace) << "monitor: create new webrequest, state = " << web_request.GetState() << ", url = " << image_url;
if (web_request.GetState() == wxWebRequest::State_Idle)
web_request.Start();
BOOST_LOG_TRIVIAL(trace) << "monitor: start new webrequest, state = " << web_request.GetState() << ", url = " << image_url;
const wxImage& img = wxGetApp().get_hms_query()->query_image_from_local(image_url);
if (!img.IsOk() && image_url.Contains("http"))
{
web_request = wxWebSession::GetDefault().CreateRequest(this, image_url);
BOOST_LOG_TRIVIAL(trace) << "monitor: create new webrequest, state = " << web_request.GetState() << ", url = " << image_url;
if (web_request.GetState() == wxWebRequest::State_Idle) web_request.Start();
BOOST_LOG_TRIVIAL(trace) << "monitor: start new webrequest, state = " << web_request.GetState() << ", url = " << image_url;
}
else
{
const wxImage& resize_img = img.Scale(FromDIP(320), FromDIP(180), wxIMAGE_QUALITY_HIGH);
m_error_prompt_pic_static->SetBitmap(wxBitmap(resize_img));
Layout();
Fit();
}
m_error_prompt_pic_static->Show();
}

View File

@ -2794,7 +2794,7 @@ void StatusPanel::update_error_message()
wxString error_msg = wxGetApp().get_hms_query()->query_print_error_msg(obj, obj->print_error);
std::vector<int> used_button;
wxString error_image_url = wxGetApp().get_hms_query()->query_print_error_url_action(obj, obj->print_error, used_button);
wxString error_image_url = wxGetApp().get_hms_query()->query_print_image_action(obj, obj->print_error, used_button);
// special case
if (print_error_str == "0300-8003" || print_error_str == "0300-8002" || print_error_str == "0300-800A") {
used_button.emplace_back(PrintErrorDialog::PrintErrorButton::JUMP_TO_LIVEVIEW);

View File

@ -614,8 +614,7 @@ protected:
void on_subtask_pause_resume(wxCommandEvent &event);
void on_subtask_abort(wxCommandEvent &event);
void on_print_error_clean(wxCommandEvent &event);
void show_error_message(
MachineObject *obj, bool is_exist, wxString msg, std::string print_error_str = "", wxString image_url = "", std::vector<int> used_button = std::vector<int>());
void show_error_message(MachineObject *obj, bool is_exist, wxString msg, std::string print_error_str = "", wxString image_url = "", std::vector<int> used_button = std::vector<int>());
void error_info_reset();
void show_recenter_dialog();