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

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

Collaboration diagram for Slic3r::GUI::HMSQuery:

Public Member Functions

 HMSQuery ()
 ~HMSQuery ()
void clear_hms_info ()
wxString query_hms_msg (const MachineObject *obj, const std::string &long_error_code)
wxString query_hms_msg (const std::string &dev_id, const std::string &long_error_code)
bool is_internal_error (const MachineObject *obj, int print_error)
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_image_action (const MachineObject *obj, int print_error, std::vector< int > &button_action)
wxImage query_image_from_local (const wxString &image_name)

Static Public Member Functions

static std::string hms_language_code ()
static std::string build_query_params (std::string &lang)

Protected Attributes

std::unordered_map< std::string, nlohmann::json > m_hms_info_jsons
std::unordered_map< std::string, nlohmann::json > m_hms_action_jsons
std::unordered_map< wxString, wxImage > m_hms_local_images
std::mutex m_hms_mutex
std::unordered_map< std::string, std::time_t > m_cloud_hms_last_update_time

Private Member Functions

void init_hms_info (const std::string &dev_type_id)
void copy_from_data_dir_to_local ()
int download_hms_related (const std::string &hms_type, const std::string &dev_id_type, nlohmann::json *receive_json)
int load_from_local (const std::string &hms_type, const std::string &dev_id_type, nlohmann::json *receive_json, std::string &version_info)
int save_to_local (std::string lang, std::string hms_type, std::string dev_id_type, nlohmann::json save_json)
std::string get_hms_file (std::string hms_type, std::string lang=std::string("en"), std::string dev_id_type="")
std::string get_dev_id_type (const MachineObject *obj) const
wxString _query_hms_msg (const std::string &dev_id_type, const std::string &long_error_code, const std::string &lang_code=std::string("en"))
bool _is_internal_error (const std::string &dev_id_type, const std::string &long_error_code, const std::string &lang_code=std::string("en"))
wxString _query_error_msg (const std::string &dev_id_type, const std::string &long_error_code, const std::string &lang_code=std::string("en"))
wxString _query_error_image_action (const std::string &dev_id_type, const std::string &long_error_code, std::vector< int > &button_action)

Detailed Description

Constructor & Destructor Documentation

◆ HMSQuery()

Slic3r::GUI::HMSQuery::HMSQuery ( )
inline
42{ }

◆ ~HMSQuery()

Slic3r::GUI::HMSQuery::~HMSQuery ( )
inline
43{ clear_hms_info(); };
void clear_hms_info()
Definition HMS.cpp:622

References clear_hms_info().

Here is the call graph for this function:

Member Function Documentation

◆ _is_internal_error()

bool Slic3r::GUI::HMSQuery::_is_internal_error ( const std::string & dev_id_type,
const std::string & long_error_code,
const std::string & lang_code = std::string("en") )
private
432{
433 init_hms_info(dev_id_type);
434 auto iter = m_hms_info_jsons.find(dev_id_type);
435 if (iter == m_hms_info_jsons.end()) { return false; }
436
437 const json &m_hms_info_json = iter->second;
438 if (m_hms_info_json.contains("device_error")) {
439 if (m_hms_info_json["device_error"].contains(lang_code)) {
440 for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) {
441 if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
442 if (item->contains("intro")) { return wxString::FromUTF8((*item)["intro"].get<std::string>()).IsEmpty(); }
443 }
444 }
445 } else {
446 // return first language
447 if (!m_hms_info_json["device_error"].empty()) {
448 for (auto lang : m_hms_info_json["device_error"]) {
449 for (auto item = lang.begin(); item != lang.end(); item++) {
450 if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
451 if (item->contains("intro")) { return wxString::FromUTF8((*item)["intro"].get<std::string>()).IsEmpty(); }
452 }
453 }
454 }
455 }
456 }
457 }
458
459 return false;
460}
void init_hms_info(const std::string &dev_type_id)
Definition HMS.cpp:630
std::unordered_map< std::string, nlohmann::json > m_hms_info_jsons
Definition HMS.hpp:34
T * begin(Slic3r::Mat< N, M, T > &mat)
Definition Point.hpp:838
bool contains(const std::vector< T > &vector, const Point &point)
Definition Geometry.cpp:55
nlohmann::json json
Definition AssembleList.cpp:42
bool empty(const BoundingBoxBase< PointType, PointsType > &bb)
Definition BoundingBox.hpp:273

References Slic3r::Geometry::contains(), Slic3r::empty(), init_hms_info(), and m_hms_info_jsons.

Referenced by is_internal_error().

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

◆ _query_error_image_action()

wxString Slic3r::GUI::HMSQuery::_query_error_image_action ( const std::string & dev_id_type,
const std::string & long_error_code,
std::vector< int > & button_action )
private
509{
510 init_hms_info(dev_id_type);
511
512 auto iter = m_hms_action_jsons.find(dev_id_type);
513 if (iter == m_hms_action_jsons.end())
514 {
515 return wxEmptyString;
516 }
517
518 const json& m_hms_action_json = iter->second;
519 if (m_hms_action_json.contains("data")) {
520 for (auto item = m_hms_action_json["data"].begin(); item != m_hms_action_json["data"].end(); item++) {
521 if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == long_error_code) {
522 if (item->contains("device") && (boost::to_upper_copy((*item)["device"].get<std::string>()) == dev_id_type ||
523 (*item)["device"].get<std::string>() == "default")) {
524 if (item->contains("actions")) {
525 for (auto item_actions = (*item)["actions"].begin(); item_actions != (*item)["actions"].end(); item_actions++) {
526 button_action.emplace_back(item_actions->get<int>());
527 }
528 }
529 if (item->contains("image")) {
530 return wxString::FromUTF8((*item)["image"].get<std::string>());
531 }
532 }
533 }
534 }
535 }
536 else {
537 BOOST_LOG_TRIVIAL(info) << "data is not exists";
538 return wxEmptyString;
539 }
540 return wxEmptyString;
541}
std::unordered_map< std::string, nlohmann::json > m_hms_action_jsons
Definition HMS.hpp:35

References init_hms_info(), and m_hms_action_jsons.

Referenced by query_print_image_action().

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

◆ _query_error_msg()

wxString Slic3r::GUI::HMSQuery::_query_error_msg ( const std::string & dev_id_type,
const std::string & long_error_code,
const std::string & lang_code = std::string("en") )
private
465{
466 init_hms_info(dev_id_type);
467 auto iter = m_hms_info_jsons.find(dev_id_type);
468 if (iter == m_hms_info_jsons.end())
469 {
470 return wxEmptyString;
471 }
472
473 const json& m_hms_info_json = iter->second;
474 if (m_hms_info_json.contains("device_error")) {
475 if (m_hms_info_json["device_error"].contains(lang_code)) {
476 for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) {
477 if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
478 if (item->contains("intro")) {
479 return wxString::FromUTF8((*item)["intro"].get<std::string>());
480 }
481 }
482 }
483 BOOST_LOG_TRIVIAL(info) << "hms: query_error_msg, not found error_code = " << error_code;
484 } else {
485 BOOST_LOG_TRIVIAL(error) << "hms: query_error_msg, do not contains lang_code = " << lang_code;
486 // return first language
487 if (!m_hms_info_json["device_error"].empty()) {
488 for (auto lang : m_hms_info_json["device_error"]) {
489 for (auto item = lang.begin(); item != lang.end(); item++) {
490 if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
491 if (item->contains("intro")) {
492 return wxString::FromUTF8((*item)["intro"].get<std::string>());
493 }
494 }
495 }
496 }
497 }
498 }
499 }
500 else {
501 BOOST_LOG_TRIVIAL(info) << "device_error is not exists";
502 return wxEmptyString;
503 }
504
505 return wxEmptyString;
506}

References Slic3r::Geometry::contains(), Slic3r::empty(), init_hms_info(), and m_hms_info_jsons.

Referenced by query_print_error_msg(), and query_print_error_msg().

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

◆ _query_hms_msg()

wxString Slic3r::GUI::HMSQuery::_query_hms_msg ( const std::string & dev_id_type,
const std::string & long_error_code,
const std::string & lang_code = std::string("en") )
private
359{
360 if (long_error_code.empty())
361 {
362 return wxEmptyString;
363 }
364
365 init_hms_info(dev_id_type);
366 auto iter = m_hms_info_jsons.find(dev_id_type);
367 if (iter == m_hms_info_jsons.end())
368 {
369 BOOST_LOG_TRIVIAL(error) << "there are no hms info for the device";
370 return wxEmptyString;
371 }
372
373 const json& m_hms_info_json = iter->second;
374 if (!m_hms_info_json.is_object())
375 {
376 BOOST_LOG_TRIVIAL(error) << "the hms info is not a valid json object";
377 return wxEmptyString;
378 }
379
380 const json& device_hms_json = m_hms_info_json.value("device_hms", json());
381 if (device_hms_json.is_null() || !device_hms_json.is_object())
382 {
383 BOOST_LOG_TRIVIAL(error) << "there are no valid json object named device_hms";
384 return wxEmptyString;
385 }
386
387 const json& device_hms_msg_json = device_hms_json.value(lang_code, json());
388 if (device_hms_msg_json.is_null())
389 {
390 BOOST_LOG_TRIVIAL(error) << "hms: query_hms_msg, do not contains lang_code = " << lang_code;
391 if (lang_code.empty()) /*traverse all if lang_code is empty*/
392 {
393 for (const auto& lang_item : device_hms_json)
394 {
395 for (const auto& msg_item : lang_item)
396 {
397 if (msg_item.is_object())
398 {
399 const std::string& error_code = msg_item.value("ecode", json()).get<std::string>();
400 if (boost::to_upper_copy(error_code) == long_error_code && msg_item.contains("intro"))
401 {
402 BOOST_LOG_TRIVIAL(info) << "retry without lang_code successed.";
403 return wxString::FromUTF8(msg_item["intro"].get<std::string>());
404 }
405 }
406 }
407 }
408 }
409
410 return wxEmptyString;
411 }
412
413 for (const auto& item : device_hms_msg_json)
414 {
415 if (item.is_object())
416 {
417 const std::string& error_code = item.value("ecode", json()).get<std::string>();
418 if (boost::to_upper_copy(error_code) == long_error_code && item.contains("intro"))
419 {
420 return wxString::FromUTF8(item["intro"].get<std::string>());
421 }
422 }
423 }
424
425 BOOST_LOG_TRIVIAL(error) << "hms: query_hms_msg, do not contains valid message, lang_code = " << lang_code << " long_error_code = " << long_error_code;
426 return wxEmptyString;
427}

References init_hms_info(), and m_hms_info_jsons.

Referenced by query_hms_msg(), and query_hms_msg().

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

◆ build_query_params()

std::string Slic3r::GUI::HMSQuery::build_query_params ( std::string & lang)
static
310{
311 std::string lang_code = HMSQuery::hms_language_code();
312 lang = lang_code;
313 std::string query_params = (boost::format("lang=%1%") % lang_code).str();
314 return query_params;
315}
static std::string hms_language_code()
Definition HMS.cpp:283

References hms_language_code().

Referenced by download_hms_related(), and Slic3r::GUI::get_hms_info_version().

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

◆ clear_hms_info()

void Slic3r::GUI::HMSQuery::clear_hms_info ( )
623{
624 std::unique_lock unique_lock(m_hms_mutex);
625 m_hms_info_jsons.clear();
626 m_hms_action_jsons.clear();
628}
std::unordered_map< std::string, std::time_t > m_cloud_hms_last_update_time
Definition HMS.hpp:39
std::mutex m_hms_mutex
Definition HMS.hpp:37

References m_cloud_hms_last_update_time, m_hms_action_jsons, m_hms_info_jsons, and m_hms_mutex.

Referenced by ~HMSQuery().

Here is the caller graph for this function:

◆ copy_from_data_dir_to_local()

void Slic3r::GUI::HMSQuery::copy_from_data_dir_to_local ( )
private
210{
211 const fs::path& from_dir = fs::path(Slic3r::resources_dir()) / HMS_PATH;
212 const fs::path& to_dir = fs::path(Slic3r::data_dir()) / HMS_PATH;
213 _copy_dir(from_dir, to_dir);
214}
static const char * HMS_PATH
Definition HMS.cpp:31
static void _copy_dir(const fs::path &from_dir, const fs::path &to_dir)
Definition HMS.cpp:168
const std::string & data_dir()
Definition utils.cpp:365
const std::string & resources_dir()
Definition utils.cpp:296

References Slic3r::GUI::_copy_dir(), Slic3r::data_dir(), HMS_PATH, and Slic3r::resources_dir().

Referenced by init_hms_info().

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

◆ download_hms_related()

int Slic3r::GUI::HMSQuery::download_hms_related ( const std::string & hms_type,
const std::string & dev_id_type,
nlohmann::json * receive_json )
private
88{
89 std::string local_version = "0";
90 load_from_local(hms_type, dev_id_type, receive_json, local_version);
91
92 AppConfig* config = wxGetApp().app_config;
93 if (!config) return -1;
94 if (should_disable_hms()) return -1;
95
96 std::string hms_host = wxGetApp().app_config->get_hms_host();
97 std::string lang;
98 std::string query_params = HMSQuery::build_query_params(lang);
99 std::string url;
100 if (hms_type.compare(QUERY_HMS_INFO) == 0) {
101 url = (boost::format("https://%1%/query.php?%2%") % hms_host % query_params).str();
102 }
103 else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
104 url = (boost::format("https://%1%/hms/GetActionImage.php?") % hms_host).str();
105 }
106
107 if (!local_version.empty()) { url += (url.find('?') != std::string::npos ? "&" : "?") + (boost::format("v=%1%") % local_version).str(); }
108
109 if (!dev_id_type.empty()) { url += (url.find('?') != std::string::npos ? "&" : "?") + (boost::format("d=%1%") % dev_id_type).str(); }
110
111
112 bool to_save_local = false;
113 json j;
114
115 BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
117 http.on_complete([receive_json, hms_type, &to_save_local, &j, & local_version](std::string body, unsigned status) {
118 try {
119 j = json::parse(body);
120 if (j.contains("result")) {
121 if (j["result"] == 0 && j.contains("data")) {
122
123 if (!j.contains("ver"))
124 {
125 return;
126 }
127
128 const std::string& remote_ver = DevJsonValParser::get_longlong_val(j["ver"]);
129 if (remote_ver <= local_version)
130 {
131 return;
132 }
133 (*receive_json)["version"] = remote_ver;
134
135 if (hms_type.compare(QUERY_HMS_INFO) == 0)
136 {
137 (*receive_json) = j["data"];
138 to_save_local = true;
139 }
140 else if (hms_type.compare(QUERY_HMS_ACTION) == 0)
141 {
142 (*receive_json)["data"] = j["data"];
143 to_save_local = true;
144 }
145 } else if (j["result"] == 201){
146 BOOST_LOG_TRIVIAL(info) << "HMSQuery: HMS info is the latest version";
147 }else{
148 BOOST_LOG_TRIVIAL(info) << "HMSQuery: update hms info error = " << j["result"].get<int>();
149 }
150 }
151 } catch (...) {
152 ;
153 }
154 })
155 .timeout_max(20)
156 .on_error([](std::string body, std::string error, unsigned status) {
157 BOOST_LOG_TRIVIAL(error) << "HMSQuery: update hms info error = " << error << ", body = " << body << ", status = " << status;
158 }).perform_sync();
159
160 if (to_save_local && !receive_json->empty()) {
161 save_to_local(lang, hms_type, dev_id_type, j);
162 }
163 return 0;
164}
static bool should_disable_hms()
Definition HMS.cpp:39
#define QUERY_HMS_INFO
Definition HMS.hpp:28
#define QUERY_HMS_ACTION
Definition HMS.hpp:29
static std::string get_longlong_val(const nlohmann::json &j)
Definition DevUtil.cpp:173
int load_from_local(const std::string &hms_type, const std::string &dev_id_type, nlohmann::json *receive_json, std::string &version_info)
Definition HMS.cpp:216
static std::string build_query_params(std::string &lang)
Definition HMS.cpp:309
int save_to_local(std::string lang, std::string hms_type, std::string dev_id_type, nlohmann::json save_json)
Definition HMS.cpp:262
static Http get(std::string url)
Definition Http.cpp:886
@ http
Definition IPrinterAgent.hpp:64
@ Http
Definition PluginAuditManager.hpp:49

References build_query_params(), Slic3r::Http::get(), Slic3r::AppConfig::get_hms_host(), Slic3r::DevJsonValParser::get_longlong_val(), Slic3r::http, load_from_local(), QUERY_HMS_ACTION, QUERY_HMS_INFO, save_to_local(), and should_disable_hms().

Referenced by init_hms_info().

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

◆ get_dev_id_type()

std::string Slic3r::GUI::HMSQuery::get_dev_id_type ( const MachineObject * obj) const
private
349{
350 if (obj)
351 {
352 return obj->get_dev_id().substr(0, 3);
353 }
354
355 return std::string();
356}

References Slic3r::MachineObject::get_dev_id().

Referenced by is_internal_error(), query_hms_msg(), query_print_error_msg(), and query_print_image_action().

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

◆ get_hms_file()

std::string Slic3r::GUI::HMSQuery::get_hms_file ( std::string hms_type,
std::string lang = std::string("en"),
std::string dev_id_type = "" )
private
318{
319 //return hms action filename
320 if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
321 return (boost::format("hms_action_%1%.json") % dev_id_type).str();
322 }
323 //return hms filename
324 return (boost::format("hms_%1%_%2%.json") % lang % dev_id_type).str();
325}

References QUERY_HMS_ACTION.

Referenced by load_from_local(), and save_to_local().

Here is the caller graph for this function:

◆ hms_language_code()

std::string Slic3r::GUI::HMSQuery::hms_language_code ( )
static
284{
285 AppConfig* config = wxGetApp().app_config;
286 if (!config)
287 // set language code to en by default
288 return "en";
289 std::string lang_code = wxGetApp().app_config->get_language_code();
290 // Orca: the HMS host ships no catalog for these locales, so fall back to english to avoid empty texts + retries
291 if (lang_code.compare("uk") == 0
292 || lang_code.compare("cs") == 0
293 || lang_code.compare("ru") == 0
294 || lang_code.compare("tr") == 0
295 || lang_code.compare("pt") == 0
296 || lang_code.compare("ko") == 0
297 )
298 {
299 BOOST_LOG_TRIVIAL(info) << "HMS: using english for lang_code = " << lang_code;
300 return "en";
301 }
302 else if (lang_code.empty()) {
303 // set language code to en by default
304 return "en";
305 }
306 return lang_code;
307}

References Slic3r::AppConfig::get_language_code().

Referenced by build_query_params(), Slic3r::GUI::get_hms_wiki_url(), is_internal_error(), load_from_local(), query_hms_msg(), query_hms_msg(), query_print_error_msg(), and query_print_error_msg().

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

◆ init_hms_info()

void Slic3r::GUI::HMSQuery::init_hms_info ( const std::string & dev_type_id)
private
631{
632 std::unique_lock unique_lock(m_hms_mutex);
633 if (package_dev_id_types.count(dev_type_id) != 0)
634 {
635 /*the local one only load once*/
636 if (m_hms_info_jsons.count(dev_type_id) == 0) {
637
638 std::string load_version;
639 load_from_local(QUERY_HMS_INFO, dev_type_id, &m_hms_info_jsons[dev_type_id], load_version);/*load from local first*/
640 if (load_version.empty() || load_version == "0") {
641 copy_from_data_dir_to_local(); // STUDIO-9512
642 load_from_local(QUERY_HMS_INFO, dev_type_id, &m_hms_info_jsons[dev_type_id], load_version);/*copy files to local, and retry load*/
643 }
644 }
645
646 if (m_hms_action_jsons.count(dev_type_id) == 0) {
647 std::string load_version;
648 load_from_local(QUERY_HMS_ACTION, dev_type_id, &m_hms_action_jsons[dev_type_id], load_version);/*load from local first*/
649 if (load_version.empty() || load_version == "0") {
650 copy_from_data_dir_to_local(); // STUDIO-9512
651 load_from_local(QUERY_HMS_ACTION, dev_type_id, &m_hms_action_jsons[dev_type_id], load_version);/*copy files to local, and retry load*/
652 }
653 }
654 }
655
656 /*download from cloud*/
657 time_t info_last_update_time = m_cloud_hms_last_update_time[dev_type_id];
658
659 /* check hms is valid or not */
660 bool retry = false;
661 if(m_hms_info_jsons[dev_type_id].empty() || m_hms_action_jsons[dev_type_id].empty()){
662 retry =time(nullptr) - info_last_update_time > (60 * 1); // retry after 1 minute
663 }
664
665 if (time(nullptr) - info_last_update_time > (60 * 60 * 24) || retry)/*do not update in one day to reduce waiting*/
666 {
667 download_hms_related(QUERY_HMS_INFO, dev_type_id, &m_hms_info_jsons[dev_type_id]);
668 download_hms_related(QUERY_HMS_ACTION, dev_type_id, &m_hms_action_jsons[dev_type_id]);
669 m_cloud_hms_last_update_time[dev_type_id] = time(nullptr);
670 }
671}
static std::unordered_set< std::string > package_dev_id_types
Definition HMS.cpp:36
void copy_from_data_dir_to_local()
Definition HMS.cpp:209
int download_hms_related(const std::string &hms_type, const std::string &dev_id_type, nlohmann::json *receive_json)
Definition HMS.cpp:87

References copy_from_data_dir_to_local(), download_hms_related(), Slic3r::empty(), load_from_local(), m_cloud_hms_last_update_time, m_hms_action_jsons, m_hms_info_jsons, m_hms_mutex, package_dev_id_types, QUERY_HMS_ACTION, and QUERY_HMS_INFO.

Referenced by _is_internal_error(), _query_error_image_action(), _query_error_msg(), and _query_hms_msg().

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

◆ is_internal_error()

bool Slic3r::GUI::HMSQuery::is_internal_error ( const MachineObject * obj,
int print_error )
545{
546 char buf[32];
547 ::sprintf(buf, "%08X", print_error);
548 std::string lang_code = HMSQuery::hms_language_code();
549 return _is_internal_error(get_dev_id_type(obj), std::string(buf), lang_code);
550}
bool _is_internal_error(const std::string &dev_id_type, const std::string &long_error_code, const std::string &lang_code=std::string("en"))
Definition HMS.cpp:429
std::string get_dev_id_type(const MachineObject *obj) const
Definition HMS.cpp:348

References _is_internal_error(), get_dev_id_type(), and hms_language_code().

Here is the call graph for this function:

◆ load_from_local()

int Slic3r::GUI::HMSQuery::load_from_local ( const std::string & hms_type,
const std::string & dev_id_type,
nlohmann::json * receive_json,
std::string & version_info )
private
217{
218 if (data_dir().empty()) {
219 load_version = "0";
220 BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty";
221 return -1;
222 }
223 std::string filename = get_hms_file(hms_type, HMSQuery::hms_language_code(), dev_id_type);
224 auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
225 if (!fs::exists(hms_folder))
226 fs::create_directory(hms_folder);
227
228 std::string dir_str = (hms_folder / filename).make_preferred().string();
229 std::ifstream json_file(encode_path(dir_str.c_str()));
230 try {
231 if (json_file.is_open())
232 {
233 const json &j = json::parse(json_file);
234 if (hms_type.compare(QUERY_HMS_INFO) == 0) {
235 if (j.contains("data")) { (*load_json) = j["data"]; }
236 } else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
237 if (j.contains("data")) { (*load_json)["data"] = j["data"]; }
238 }
239
240 if (j.contains("version")) {
241 load_version = DevJsonValParser::get_longlong_val(j["version"]);
242 }
243 else if (j.contains("ver")) {
244 load_version = DevJsonValParser::get_longlong_val(j["ver"]);
245 }
246 else
247 {
248 BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info";
249 }
250
251 return 0;
252 }
253 } catch(...) {
254 load_version = "0";
255 BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local failed";
256 return -1;
257 }
258 load_version = "0";
259 return 0;
260}
std::string get_hms_file(std::string hms_type, std::string lang=std::string("en"), std::string dev_id_type="")
Definition HMS.cpp:317
std::string encode_path(const char *src)
Definition utils.cpp:1382

References Slic3r::data_dir(), Slic3r::empty(), Slic3r::encode_path(), get_hms_file(), Slic3r::DevJsonValParser::get_longlong_val(), hms_language_code(), QUERY_HMS_ACTION, and QUERY_HMS_INFO.

Referenced by download_hms_related(), and init_hms_info().

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

◆ query_hms_msg() [1/2]

wxString Slic3r::GUI::HMSQuery::query_hms_msg ( const MachineObject * obj,
const std::string & long_error_code )
328{
329 if (!obj)
330 {
331 return wxEmptyString;
332 }
333
334 AppConfig* config = wxGetApp().app_config;
335 if (!config) return wxEmptyString;
336 const std::string& lang_code = HMSQuery::hms_language_code();
337 return _query_hms_msg(get_dev_id_type(obj),long_error_code, lang_code);
338}
wxString _query_hms_msg(const std::string &dev_id_type, const std::string &long_error_code, const std::string &lang_code=std::string("en"))
Definition HMS.cpp:358

References _query_hms_msg(), get_dev_id_type(), and hms_language_code().

Here is the call graph for this function:

◆ query_hms_msg() [2/2]

wxString Slic3r::GUI::HMSQuery::query_hms_msg ( const std::string & dev_id,
const std::string & long_error_code )
341{
342 AppConfig* config = wxGetApp().app_config;
343 if (!config) return wxEmptyString;
344 const std::string& lang_code = HMSQuery::hms_language_code();
345 return _query_hms_msg(dev_id.substr(0, 3), long_error_code, lang_code);
346}

References _query_hms_msg(), and hms_language_code().

Here is the call graph for this function:

◆ query_image_from_local()

wxImage Slic3r::GUI::HMSQuery::query_image_from_local ( const wxString & image_name)
592{
593 if (image_name.empty() || image_name.Contains("http"))
594 {
595 return wxImage();
596 }
597
598 if (m_hms_local_images.empty())
599 {
600 const fs::path& local_img_dir = fs::path(Slic3r::data_dir()) / HMS_LOCAL_IMG_PATH;
601 if (fs::exists(local_img_dir))
602 {
603 for (const auto &entry : fs::directory_iterator(local_img_dir))
604 {
605 const fs::path& image_path = entry.path();
606 const fs::path& image_name = fs::relative(image_path, local_img_dir);
607 // Orca: from_path() for correct UTF-8 path encoding
608 m_hms_local_images[from_path(image_name)] = wxImage(from_path(image_path));
609 }
610 }
611 }
612
613 auto iter = m_hms_local_images.find(image_name);
614 if (iter != m_hms_local_images.end())
615 {
616 return iter->second;
617 }
618
619 return wxImage();
620}
static const char * HMS_LOCAL_IMG_PATH
Definition HMS.cpp:32
std::unordered_map< wxString, wxImage > m_hms_local_images
Definition HMS.hpp:36
wxString from_path(const boost::filesystem::path &path)
Definition GUI.cpp:555

References Slic3r::data_dir(), Slic3r::GUI::from_path(), HMS_LOCAL_IMG_PATH, and m_hms_local_images.

Here is the call graph for this function:

◆ query_print_error_msg() [1/2]

wxString Slic3r::GUI::HMSQuery::query_print_error_msg ( const MachineObject * obj,
int print_error )
553{
554 if (!obj)
555 {
556 return wxEmptyString;
557 }
558
559 char buf[32];
560 ::sprintf(buf, "%08X", print_error);
561 std::string lang_code = HMSQuery::hms_language_code();
562 return _query_error_msg(get_dev_id_type(obj), std::string(buf), lang_code);
563}
wxString _query_error_msg(const std::string &dev_id_type, const std::string &long_error_code, const std::string &lang_code=std::string("en"))
Definition HMS.cpp:462

References _query_error_msg(), get_dev_id_type(), and hms_language_code().

Here is the call graph for this function:

◆ query_print_error_msg() [2/2]

wxString Slic3r::GUI::HMSQuery::query_print_error_msg ( const std::string & dev_id,
int print_error )
566{
567 char buf[32];
568 ::sprintf(buf, "%08X", print_error);
569 std::string lang_code = HMSQuery::hms_language_code();
570 return _query_error_msg(dev_id.substr(0, 3), std::string(buf), lang_code);
571}

References _query_error_msg(), and hms_language_code().

Here is the call graph for this function:

◆ query_print_image_action()

wxString Slic3r::GUI::HMSQuery::query_print_image_action ( const MachineObject * obj,
int print_error,
std::vector< int > & button_action )
575{
576 if (!obj)
577 {
578 return wxEmptyString;
579 }
580
581 char buf[32];
582 ::sprintf(buf, "%08X", print_error);
583 //The first three digits of SN number
584 const auto result = _query_error_image_action(get_dev_id_type(obj),std::string(buf), button_action);
585 if (should_disable_hms() && result.Contains("http")) {
586 return wxEmptyString;
587 }
588 return result;
589}
wxString _query_error_image_action(const std::string &dev_id_type, const std::string &long_error_code, std::vector< int > &button_action)
Definition HMS.cpp:508

References _query_error_image_action(), get_dev_id_type(), and should_disable_hms().

Here is the call graph for this function:

◆ save_to_local()

int Slic3r::GUI::HMSQuery::save_to_local ( std::string lang,
std::string hms_type,
std::string dev_id_type,
nlohmann::json save_json )
private
263{
264 if (data_dir().empty()) {
265 BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local, data_dir() is empty";
266 return -1;
267 }
268 std::string filename = get_hms_file(hms_type,lang, dev_id_type);
269 auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
270 if (!fs::exists(hms_folder))
271 fs::create_directory(hms_folder);
272 std::string dir_str = (hms_folder / filename).make_preferred().string();
273 std::ofstream json_file(encode_path(dir_str.c_str()));
274 if (json_file.is_open()) {
275 json_file << save_json.dump(1, '\t') << std::endl; // Orca: tab-indented dump
276 json_file.close();
277 return 0;
278 }
279 BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local failed";
280 return -1;
281}

References Slic3r::data_dir(), Slic3r::empty(), Slic3r::encode_path(), and get_hms_file().

Referenced by download_hms_related().

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

Member Data Documentation

◆ m_cloud_hms_last_update_time

std::unordered_map<std::string, std::time_t> Slic3r::GUI::HMSQuery::m_cloud_hms_last_update_time
protected

Referenced by clear_hms_info(), and init_hms_info().

◆ m_hms_action_jsons

std::unordered_map<std::string, nlohmann::json> Slic3r::GUI::HMSQuery::m_hms_action_jsons
protected

◆ m_hms_info_jsons

std::unordered_map<std::string, nlohmann::json> Slic3r::GUI::HMSQuery::m_hms_info_jsons
protected

◆ m_hms_local_images

std::unordered_map<wxString, wxImage> Slic3r::GUI::HMSQuery::m_hms_local_images
protected

Referenced by query_image_from_local().

◆ m_hms_mutex

std::mutex Slic3r::GUI::HMSQuery::m_hms_mutex
mutableprotected

Referenced by clear_hms_info(), and init_hms_info().


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