NEW:revert hms error code

Change-Id: Ib5cc8bb8b8ced0f70d5bbe4751a1f97258218c6f
This commit is contained in:
七喜 2024-03-22 12:04:58 +08:00 committed by Lane.Wei
parent b0330dff36
commit 61f8004acd
7 changed files with 120 additions and 456 deletions

View File

@ -67,11 +67,11 @@ std::string AppConfig::get_hms_host()
std::string host = "";
#if !BBL_RELEASE_TO_PUBLIC
if (sel == ENV_DEV_HOST)
host = "e-dev.bambulab.net";
host = "e-dev.bambu-lab.com";
else if (sel == ENV_QAT_HOST)
host = "e-qa.bambulab.net";
host = "e-qa.bambu-lab.com";
else if (sel == ENV_PRE_HOST)
host = "e-pre.bambulab.net";
host = "e-pre.bambu-lab.com";
else if (sel == ENV_PRODUCT_HOST)
host = "e.bambulab.com";
return host;

View File

@ -40,45 +40,30 @@ int get_hms_info_version(std::string& version)
return result;
}
int HMSQuery::download_hms_related(std::string hms_type, json* receive_json)
int HMSQuery::download_hms_info()
{
std::string local_version = "0";
load_from_local(local_version, hms_type, receive_json);
AppConfig* config = wxGetApp().app_config;
if (!config) return -1;
std::string hms_host = wxGetApp().app_config->get_hms_host();
std::string lang;
std::string query_params = HMSQuery::build_query_params(lang);
std::string url;
if (hms_type.compare(QUERY_HMS_INFO) == 0) {
url = (boost::format("https://%1%/query.php?%2%&v=%3%") % hms_host % query_params % local_version).str();
}
else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
url = (boost::format("https://%1%/hms/GetActionImage.php?v=%2%") % hms_host % local_version).str();
}
std::string url = (boost::format("https://%1%/query.php?%2%") % hms_host % query_params).str();
BOOST_LOG_TRIVIAL(info) << "hms: download url = " << url;
Slic3r::Http http = Slic3r::Http::get(url);
http.on_complete([this, receive_json, hms_type](std::string body, unsigned status) {
m_hms_json.clear();
http.on_complete([this](std::string body, unsigned status) {
try {
json j = json::parse(body);
if (j.contains("result")) {
if (j["result"] == 0 && j.contains("data")) {
if (hms_type.compare(QUERY_HMS_INFO) == 0) {
(*receive_json) = j["data"];
this->save_local = true;
}
else if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
(*receive_json)["data"] = j["data"];
this->save_local = true;
}
this->m_hms_json = j["data"];
if (j.contains("ver"))
(*receive_json)["version"] = std::to_string(j["ver"].get<long long>());
} else if (j["result"] == 201){
BOOST_LOG_TRIVIAL(info) << "HMSQuery: HMS info is the latest version";
}else{
receive_json->clear();
m_hms_json["version"] = std::to_string(j["ver"].get<long long>());
} else {
this->m_hms_json.clear();
BOOST_LOG_TRIVIAL(info) << "HMSQuery: update hms info error = " << j["result"].get<int>();
}
}
@ -91,21 +76,19 @@ int HMSQuery::download_hms_related(std::string hms_type, json* receive_json)
BOOST_LOG_TRIVIAL(error) << "HMSQuery: update hms info error = " << error << ", body = " << body << ", status = " << status;
}).perform_sync();
if (!receive_json->empty() && save_local == true) {
save_to_local(lang, hms_type, *receive_json);
save_local = false;
}
if (!m_hms_json.empty())
save_to_local(lang);
return 0;
}
int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, json* load_json)
int HMSQuery::load_from_local(std::string &version_info)
{
if (data_dir().empty()) {
version_info = "0";
version_info = "";
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local, data_dir() is empty";
return -1;
}
std::string filename = get_hms_file(hms_type, HMSQuery::hms_language_code());
std::string filename = get_hms_file(HMSQuery::hms_language_code());
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
if (!fs::exists(hms_folder))
fs::create_directory(hms_folder);
@ -114,9 +97,9 @@ int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, j
std::ifstream json_file(encode_path(dir_str.c_str()));
try {
if (json_file.is_open()) {
json_file >> (*load_json);
if ((*load_json).contains("version")) {
version_info = (*load_json)["version"].get<std::string>();
json_file >> m_hms_json;
if (m_hms_json.contains("version")) {
version_info = m_hms_json["version"].get<std::string>();
return 0;
} else {
BOOST_LOG_TRIVIAL(warning) << "HMS: load_from_local, no version info";
@ -124,28 +107,28 @@ int HMSQuery::load_from_local(std::string& version_info, std::string hms_type, j
}
}
} catch(...) {
version_info = "0";
version_info = "";
BOOST_LOG_TRIVIAL(error) << "HMS: load_from_local failed";
return -1;
}
version_info = "0";
version_info = "";
return 0;
}
int HMSQuery::save_to_local(std::string lang, std::string hms_type, json save_json)
int HMSQuery::save_to_local(std::string lang)
{
if (data_dir().empty()) {
BOOST_LOG_TRIVIAL(error) << "HMS: save_to_local, data_dir() is empty";
return -1;
}
std::string filename = get_hms_file(hms_type,lang);
std::string filename = get_hms_file(lang);
auto hms_folder = (boost::filesystem::path(data_dir()) / "hms");
if (!fs::exists(hms_folder))
fs::create_directory(hms_folder);
std::string dir_str = (hms_folder / filename).make_preferred().string();
std::ofstream json_file(encode_path(dir_str.c_str()));
if (json_file.is_open()) {
json_file << std::setw(4) << save_json << std::endl;
json_file << std::setw(4) << m_hms_json << std::endl;
json_file.close();
return 0;
}
@ -181,13 +164,9 @@ std::string HMSQuery::build_query_params(std::string& lang)
return query_params;
}
std::string HMSQuery::get_hms_file(std::string hms_type, std::string lang)
std::string HMSQuery::get_hms_file(std::string lang)
{
//return hms action filename
if (hms_type.compare(QUERY_HMS_ACTION) == 0) {
return (boost::format("hms_action.json")).str();
}
//return hms filename
//std::string lang_code = HMSQuery::hms_language_code();
return (boost::format("hms_%1%.json") % lang).str();
}
@ -204,9 +183,9 @@ wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_
if (long_error_code.empty())
return wxEmptyString;
if (m_hms_info_json.contains("device_hms")) {
if (m_hms_info_json["device_hms"].contains(lang_code)) {
for (auto item = m_hms_info_json["device_hms"][lang_code].begin(); item != m_hms_info_json["device_hms"][lang_code].end(); item++) {
if (m_hms_json.contains("device_hms")) {
if (m_hms_json["device_hms"].contains(lang_code)) {
for (auto item = m_hms_json["device_hms"][lang_code].begin(); item != m_hms_json["device_hms"][lang_code].end(); item++) {
if (item->contains("ecode")) {
std::string temp_string = (*item)["ecode"].get<std::string>();
if (boost::to_upper_copy(temp_string) == long_error_code) {
@ -220,8 +199,8 @@ wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_
} else {
BOOST_LOG_TRIVIAL(error) << "hms: query_hms_msg, do not contains lang_code = " << lang_code;
// return first language
if (!m_hms_info_json["device_hms"].empty()) {
for (auto lang : m_hms_info_json["device_hms"]) {
if (!m_hms_json["device_hms"].empty()) {
for (auto lang : m_hms_json["device_hms"]) {
for (auto item = lang.begin(); item != lang.end(); item++) {
if (item->contains("ecode")) {
std::string temp_string = (*item)["ecode"].get<std::string>();
@ -244,9 +223,9 @@ wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_
wxString HMSQuery::_query_error_msg(std::string error_code, std::string lang_code)
{
if (m_hms_info_json.contains("device_error")) {
if (m_hms_info_json["device_error"].contains(lang_code)) {
for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) {
if (m_hms_json.contains("device_error")) {
if (m_hms_json["device_error"].contains(lang_code)) {
for (auto item = m_hms_json["device_error"][lang_code].begin(); item != m_hms_json["device_error"][lang_code].end(); item++) {
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
if (item->contains("intro")) {
return wxString::FromUTF8((*item)["intro"].get<std::string>());
@ -257,8 +236,8 @@ wxString HMSQuery::_query_error_msg(std::string error_code, std::string lang_cod
} else {
BOOST_LOG_TRIVIAL(error) << "hms: query_error_msg, do not contains lang_code = " << lang_code;
// return first language
if (!m_hms_info_json["device_error"].empty()) {
for (auto lang : m_hms_info_json["device_error"]) {
if (!m_hms_json["device_error"].empty()) {
for (auto lang : m_hms_json["device_error"]) {
for (auto item = lang.begin(); item != lang.end(); item++) {
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
if (item->contains("intro")) {
@ -277,33 +256,6 @@ wxString HMSQuery::_query_error_msg(std::string error_code, std::string lang_cod
return wxEmptyString;
}
wxString HMSQuery::_query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action)
{
if (m_hms_action_json.contains("data")) {
for (auto item = m_hms_action_json["data"].begin(); item != m_hms_action_json["data"].end(); item++) {
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == long_error_code) {
if (item->contains("device") && (boost::to_upper_copy((*item)["device"].get<std::string>()) == dev_id ||
(*item)["device"].get<std::string>() == "default")) {
if (item->contains("actions")) {
for (auto item_actions = (*item)["actions"].begin(); item_actions != (*item)["actions"].end(); item_actions++) {
button_action.emplace_back(item_actions->get<int>());
}
}
if (item->contains("image")) {
return wxString::FromUTF8((*item)["image"].get<std::string>());
}
}
}
}
}
else {
BOOST_LOG_TRIVIAL(info) << "data is not exists";
return wxEmptyString;
}
return wxEmptyString;
}
wxString HMSQuery::query_print_error_msg(int print_error)
{
char buf[32];
@ -312,22 +264,29 @@ wxString HMSQuery::query_print_error_msg(int print_error)
return _query_error_msg(std::string(buf), lang_code);
}
wxString HMSQuery::query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action)
{
char buf[32];
::sprintf(buf, "%08X", print_error);
//The first three digits of SN number
dev_id = dev_id.substr(0, 3);
return _query_error_url_action(std::string(buf), dev_id, button_action);
}
int HMSQuery::check_hms_info()
{
boost::thread check_thread = boost::thread([this] {
bool download_new_hms_info = true;
// load local hms json file
std::string version = "";
if (load_from_local(version) == 0) {
BOOST_LOG_TRIVIAL(info) << "HMS: check_hms_info current version = " << version;
std::string new_version;
get_hms_info_version(new_version);
BOOST_LOG_TRIVIAL(info) << "HMS: check_hms_info latest version = " << new_version;
download_hms_related(QUERY_HMS_INFO, &m_hms_info_json);
download_hms_related(QUERY_HMS_ACTION, &m_hms_action_json);
if (new_version.empty()) {return 0;}
if (!version.empty() && version == new_version) {
download_new_hms_info = false;
}
}
BOOST_LOG_TRIVIAL(info) << "HMS: check_hms_info need download new hms info = " << download_new_hms_info;
// download if version is update
if (download_new_hms_info) {
download_hms_info();
}
return 0;
});
return 0;

View File

@ -16,30 +16,23 @@ namespace Slic3r {
namespace GUI {
#define HMS_INFO_FILE "hms.json"
#define QUERY_HMS_INFO "query_hms_info"
#define QUERY_HMS_ACTION "query_hms_action"
class HMSQuery {
protected:
json m_hms_info_json;
json m_hms_action_json;
int download_hms_related(std::string hms_type,json* receive_json);
int load_from_local(std::string& version_info, std::string hms_type, json* load_json);
int save_to_local(std::string lang, std::string hms_type,json save_json);
std::string get_hms_file(std::string hms_type, std::string lang = std::string("en"));
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en"));
wxString _query_error_msg(std::string long_error_code, std::string lang_code = std::string("en"));
wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action);
json m_hms_json;
int download_hms_info();
int load_from_local(std::string& version_info);
int save_to_local(std::string lang);
std::string get_hms_file(std::string lang);
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = "en");
wxString _query_error_msg(std::string long_error_code, std::string lang_code = "en");
public:
HMSQuery() {}
int check_hms_info();
wxString query_hms_msg(std::string long_error_code);
wxString query_print_error_msg(int print_error);
wxString query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action);
static std::string hms_language_code();
static std::string build_query_params(std::string& lang);
bool save_local = false;
};
int get_hms_info_version(std::string &version);

View File

@ -33,7 +33,6 @@ wxDEFINE_EVENT(EVT_ENTER_IP_ADDRESS, wxCommandEvent);
wxDEFINE_EVENT(EVT_CLOSE_IPADDRESS_DLG, wxCommandEvent);
wxDEFINE_EVENT(EVT_CHECK_IP_ADDRESS_FAILED, wxCommandEvent);
wxDEFINE_EVENT(EVT_SECONDARY_CHECK_RETRY, wxCommandEvent);
wxDEFINE_EVENT(EVT_PRINT_ERROR_STOP, wxCommandEvent);
wxDEFINE_EVENT(EVT_UPDATE_NOZZLE, wxCommandEvent);
ReleaseNoteDialog::ReleaseNoteDialog(Plater *plater /*= nullptr*/)
@ -842,291 +841,6 @@ void SecondaryCheckDialog::rescale()
m_button_cancel->Rescale();
}
PrintErrorDialog::PrintErrorDialog(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style)
:DPIFrame(parent, id, title, pos, size, style)
{
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
SetBackgroundColour(*wxWHITE);
m_error_prompt_pic_static = new wxStaticBitmap(this, wxID_ANY, wxBitmap(), wxDefaultPosition, wxSize(FromDIP(300), FromDIP(180)));
m_sizer_main = new wxBoxSizer(wxVERTICAL);
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(350), 1));
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0);
m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5));
wxBoxSizer* m_sizer_right = new wxBoxSizer(wxVERTICAL);
m_sizer_right->Add(0, 0, 1, wxTOP, FromDIP(15));
m_vebview_release_note = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL);
m_vebview_release_note->SetScrollRate(0, 5);
m_vebview_release_note->SetBackgroundColour(*wxWHITE);
m_vebview_release_note->SetMinSize(wxSize(FromDIP(320), FromDIP(250)));
m_sizer_right->Add(m_vebview_release_note, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(15));
auto bottom_sizer = new wxBoxSizer(wxVERTICAL);
m_sizer_button = new wxBoxSizer(wxVERTICAL);
bottom_sizer->Add(m_sizer_button, 0, wxEXPAND | wxRIGHT | wxLEFT, 0);
m_sizer_right->Add(bottom_sizer, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(15));
m_sizer_right->Add(0, 0, 0, wxTOP, FromDIP(10));
m_sizer_main->Add(m_sizer_right, 0, wxBOTTOM | wxEXPAND, FromDIP(5));
Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {this->on_hide(); });
Bind(wxEVT_ACTIVATE, [this](auto& e) { if (!e.GetActive()) this->RequestUserAttention(wxUSER_ATTENTION_ERROR); });
Bind(wxEVT_WEBREQUEST_STATE, &PrintErrorDialog::on_webrequest_state, this);
SetSizer(m_sizer_main);
Layout();
m_sizer_main->Fit(this);
init_button_list();
CenterOnParent();
wxGetApp().UpdateFrameDarkUI(this);
}
void PrintErrorDialog::post_event(wxCommandEvent&& event)
{
if (event_parent) {
event.SetString("");
event.SetEventObject(event_parent);
wxPostEvent(event_parent, event);
event.Skip();
}
}
void PrintErrorDialog::on_webrequest_state(wxWebRequestEvent& evt)
{
BOOST_LOG_TRIVIAL(trace) << "monitor: monitor_panel web request state = " << evt.GetState();
switch (evt.GetState()) {
case wxWebRequest::State_Completed: {
wxImage img(*evt.GetResponse().GetStream());
wxImage resize_img = img.Scale(FromDIP(320), FromDIP(180), wxIMAGE_QUALITY_HIGH);
wxBitmap error_prompt_pic = resize_img;
m_error_prompt_pic_static->SetBitmap(error_prompt_pic);
break;
}
case wxWebRequest::State_Failed:
case wxWebRequest::State_Cancelled:
case wxWebRequest::State_Unauthorized: {
m_error_prompt_pic_static->SetBitmap(wxBitmap());
break;
}
case wxWebRequest::State_Active:
case wxWebRequest::State_Idle: break;
default: break;
}
}
void PrintErrorDialog::update_text_image(wxString text, wxString image_url)
{
//if (!m_sizer_text_release_note) {
// m_sizer_text_release_note = new wxBoxSizer(wxVERTICAL);
//}
wxBoxSizer* sizer_text_release_note = new wxBoxSizer(wxVERTICAL);
if (!m_staticText_release_note) {
m_staticText_release_note = new Label(m_vebview_release_note, text, LB_AUTO_WRAP);
sizer_text_release_note->Add(0, 0, 0, wxTOP, FromDIP(5));
sizer_text_release_note->Add(m_error_prompt_pic_static, 0, wxLEFT, FromDIP(10));
sizer_text_release_note->Add(m_staticText_release_note, 0, wxLEFT | wxRIGHT, FromDIP(5));
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;
m_error_prompt_pic_static->Show();
}
else {
m_error_prompt_pic_static->Hide();
}
sizer_text_release_note->Layout();
m_staticText_release_note->SetMaxSize(wxSize(FromDIP(300), -1));
m_staticText_release_note->SetMinSize(wxSize(FromDIP(300), -1));
m_staticText_release_note->SetLabelText(text);
//m_staticText_release_note->SetForegroundColour(wxColour("#5C5C5C"));
m_vebview_release_note->Layout();
auto text_size = m_staticText_release_note->GetBestSize();
if (text_size.y < FromDIP(360))
if (!image_url.empty()) {
m_vebview_release_note->SetMinSize(wxSize(FromDIP(320), text_size.y + FromDIP(220)));
}
else {
m_vebview_release_note->SetMinSize(wxSize(FromDIP(320), text_size.y + FromDIP(25)));
}
else {
m_vebview_release_note->SetMinSize(wxSize(FromDIP(320), FromDIP(340)));
}
Layout();
Fit();
}
void PrintErrorDialog::on_show()
{
wxGetApp().UpdateFrameDarkUI(this);
this->Show();
this->Raise();
}
void PrintErrorDialog::on_hide()
{
//m_sizer_button->Clear();
//m_sizer_button->Layout();
//m_used_button.clear();
this->Hide();
if (web_request.IsOk() && web_request.GetState() == wxWebRequest::State_Active) {
BOOST_LOG_TRIVIAL(info) << "web_request: cancelled";
web_request.Cancel();
}
m_error_prompt_pic_static->SetBitmap(wxBitmap());
if (wxGetApp().mainframe != nullptr) {
wxGetApp().mainframe->Show();
wxGetApp().mainframe->Raise();
}
}
void PrintErrorDialog::update_title_style(wxString title, std::vector<int> button_style, wxWindow* parent)
{
SetTitle(title);
event_parent = parent;
for (int used_button_id : m_used_button) {
if (m_button_list.find(used_button_id) != m_button_list.end()) {
m_button_list[used_button_id]->Hide();
}
}
m_sizer_button->Clear();
m_used_button = button_style;
for (int button_id : button_style) {
if (m_button_list.find(button_id) != m_button_list.end()) {
m_sizer_button->Add(m_button_list[button_id], 0, wxALL, FromDIP(5));
m_button_list[button_id]->Show();
}
}
Layout();
Fit();
}
void PrintErrorDialog::init_button(PrintErrorButton style,wxString buton_text) {
Button* print_error_button = new Button(this, buton_text);
print_error_button->SetBorderColor(wxColour("#C2C2C2"));
print_error_button->SetTextColor(wxColour("#1F1F1F"));
print_error_button->SetFont(Label::Body_14);
print_error_button->SetSize(wxSize(FromDIP(300), FromDIP(30)));
print_error_button->SetMinSize(wxSize(FromDIP(300), FromDIP(30)));
print_error_button->SetMaxSize(wxSize(-1, FromDIP(30)));
print_error_button->SetCornerRadius(FromDIP(5));
print_error_button->Hide();
m_button_list[style] = print_error_button;
}
void PrintErrorDialog::init_button_list() {
init_button(RESUME_PRINTING, _L("Resume Printing"));
m_button_list[RESUME_PRINTING]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
post_event(wxCommandEvent(EVT_SECONDARY_CHECK_RESUME));
e.Skip();
});
init_button(RESUME_PRINTING_DEFECTS, _L("Resume Printing(defects acceptable)"));
m_button_list[RESUME_PRINTING_DEFECTS]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
post_event(wxCommandEvent(EVT_SECONDARY_CHECK_RESUME));
e.Skip();
});
init_button(RESUME_PRINTING_PROBELM_SOLVED, _L("Resume Printing(problem solved)"));
m_button_list[RESUME_PRINTING_PROBELM_SOLVED]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
post_event(wxCommandEvent(EVT_SECONDARY_CHECK_RESUME));
e.Skip();
});
init_button(STOP_PRINTING, _L("Stop Printing"));
m_button_list[STOP_PRINTING]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
post_event(wxCommandEvent(EVT_PRINT_ERROR_STOP));
e.Skip();
});
init_button(FILAMENT_EXTRUDED, _L("Filament Extruded,Continue"));
m_button_list[FILAMENT_EXTRUDED]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
wxCommandEvent evt(EVT_SECONDARY_CHECK_CONFIRM, GetId());
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
this->on_hide();
});
init_button(RETRY_FILAMENT_EXTRUDED, _L("Not Extruded Yet,Retry"));
m_button_list[RETRY_FILAMENT_EXTRUDED]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
wxCommandEvent evt(EVT_SECONDARY_CHECK_RETRY, GetId());
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
this->on_hide();
});
init_button(CONTINUE, _L("Finished,Continue"));
m_button_list[CONTINUE]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
wxCommandEvent evt(EVT_SECONDARY_CHECK_CONFIRM, GetId());
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
this->on_hide();
});
init_button(LOAD_VIRTUAL_TRAY, _L("Load Filament "));
m_button_list[LOAD_VIRTUAL_TRAY]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
//TODO
});
init_button(OK_BUTTON, _L("OK "));
m_button_list[OK_BUTTON]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
wxCommandEvent evt(EVT_SECONDARY_CHECK_CONFIRM, GetId());
e.SetEventObject(this);
GetEventHandler()->ProcessEvent(evt);
this->on_hide();
});
}
PrintErrorDialog::~PrintErrorDialog()
{
}
void PrintErrorDialog::on_dpi_changed(const wxRect& suggested_rect)
{
rescale();
}
void PrintErrorDialog::msw_rescale() {
wxGetApp().UpdateFrameDarkUI(this);
Refresh();
}
void PrintErrorDialog::rescale()
{
for(auto used_button:m_used_button)
m_button_list[used_button]->Rescale();
}
ConfirmBeforeSendDialog::ConfirmBeforeSendDialog(wxWindow* parent, wxWindowID id, const wxString& title, enum ButtonStyle btn_style, const wxPoint& pos, const wxSize& size, long style, bool not_show_again_check)
:DPIDialog(parent, id, title, pos, size, style)
{

View File

@ -45,7 +45,6 @@ wxDECLARE_EVENT(EVT_SECONDARY_CHECK_CANCEL, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_RETRY, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_DONE, wxCommandEvent);
wxDECLARE_EVENT(EVT_SECONDARY_CHECK_RESUME, wxCommandEvent);
wxDECLARE_EVENT(EVT_PRINT_ERROR_STOP, wxCommandEvent);
wxDECLARE_EVENT(EVT_UPDATE_NOZZLE, wxCommandEvent);
class ReleaseNoteDialog : public DPIDialog
@ -158,53 +157,6 @@ public:
std::string show_again_config_text = "";
};
class PrintErrorDialog : public DPIFrame
{
private:
wxWindow* event_parent{ nullptr };
public:
enum PrintErrorButton {
RESUME_PRINTING = 2,
RESUME_PRINTING_DEFECTS = 3,
RESUME_PRINTING_PROBELM_SOLVED = 4,
STOP_PRINTING = 5,
FILAMENT_EXTRUDED = 7,
RETRY_FILAMENT_EXTRUDED = 8,
CONTINUE = 9,
LOAD_VIRTUAL_TRAY=10,
OK_BUTTON=11
};
PrintErrorDialog(
wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxString& title = wxEmptyString,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxCLOSE_BOX | wxCAPTION
);
void update_text_image(wxString text, wxString image_url);
void on_show();
void on_hide();
void update_title_style(wxString title, std::vector<int> style, wxWindow* parent = nullptr);
void post_event(wxCommandEvent&& event);
void rescale();
~PrintErrorDialog();
void on_dpi_changed(const wxRect& suggested_rect);
void msw_rescale();
void init_button(PrintErrorButton style, wxString buton_text);
void init_button_list();
void on_webrequest_state(wxWebRequestEvent& evt);
wxWebRequest web_request;
wxStaticBitmap* m_error_prompt_pic_static;
Label* m_staticText_release_note{ nullptr };
wxBoxSizer* m_sizer_main;
wxBoxSizer* m_sizer_button;
wxScrolledWindow* m_vebview_release_note{ nullptr };
std::map<int, Button*> m_button_list;
std::vector<int> m_used_button;
};
struct ConfirmBeforeSendInfo
{

View File

@ -64,6 +64,37 @@ static wxColour PAGE_TITLE_FONT_COL = wxColour(107, 107, 107);
static wxColour GROUP_TITLE_FONT_COL = wxColour(172, 172, 172);
static wxColour TEXT_LIGHT_FONT_COL = wxColour(107, 107, 107);
static std::vector<std::string> message_containing_retry{
"0701 8004",
"0701 8005",
"0701 8006",
"0701 8006",
"0701 8007",
"0700 8012",
"0701 8012",
"0702 8012",
"0703 8012",
"07FF 8003",
"07FF 8004",
"07FF 8005",
"07FF 8006",
"07FF 8007",
"07FF 8010",
"07FF 8011",
"07FF 8012",
"07FF 8013",
"12FF 8007"
};
static std::vector<std::string> message_containing_done{
"07FF 8007",
"12FF 8007"
};
static std::vector<std::string> message_containing_resume{
"0300 8013"
};
static wxImage fail_image;
@ -1669,7 +1700,6 @@ StatusPanel::StatusPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, co
Bind(EVT_FAN_CHANGED, &StatusPanel::on_fan_changed, this);
Bind(EVT_SECONDARY_CHECK_DONE, &StatusPanel::on_print_error_done, this);
Bind(EVT_SECONDARY_CHECK_RESUME, &StatusPanel::on_subtask_pause_resume, this);
Bind(EVT_PRINT_ERROR_STOP, &StatusPanel::on_subtask_abort, this);
m_switch_speed->Connect(wxEVT_LEFT_DOWN, wxCommandEventHandler(StatusPanel::on_switch_speed), NULL, this);
m_calibration_btn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_start_calibration), NULL, this);
@ -2048,21 +2078,39 @@ void StatusPanel::show_recenter_dialog() {
obj->command_go_home();
}
void StatusPanel::show_error_message(MachineObject* obj, wxString msg, std::string print_error_str, wxString image_url, std::vector<int> used_button)
void StatusPanel::show_error_message(MachineObject* obj, wxString msg, std::string print_error_str)
{
if (msg.IsEmpty()) {
error_info_reset();
} else {
m_project_task_panel->show_error_msg(msg);
auto it_retry = std::find(message_containing_retry.begin(), message_containing_retry.end(), print_error_str);
auto it_done = std::find(message_containing_done.begin(), message_containing_done.end(), print_error_str);
auto it_resume = std::find(message_containing_resume.begin(), message_containing_resume.end(), print_error_str);
BOOST_LOG_TRIVIAL(info) << "show print error! error_msg = " << msg;
if (m_print_error_dlg == nullptr) {
m_print_error_dlg = new PrintErrorDialog(this->GetParent(), wxID_ANY, _L("Error"));
m_print_error_dlg = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM);
}
m_print_error_dlg->update_title_style(_L("Error"), used_button,this);
m_print_error_dlg->update_text_image(msg, image_url);
if (it_done != message_containing_done.end() && it_retry != message_containing_retry.end()) {
m_print_error_dlg->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::DONE_AND_RETRY, this);
}
else if (it_done != message_containing_done.end()) {
m_print_error_dlg->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_DONE, this);
}
else if (it_retry != message_containing_retry.end()) {
m_print_error_dlg->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_RETRY, this);
}
else if (it_resume!= message_containing_resume.end()) {
m_print_error_dlg->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_RESUME, this);
}
else {
m_print_error_dlg->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM, this);
}
m_print_error_dlg->update_text(msg);
m_print_error_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, obj](wxCommandEvent& e) {
if (obj) {
obj->command_clean_print_error(obj->subtask_id_, obj->print_error);
@ -2099,15 +2147,13 @@ void StatusPanel::update_error_message()
}
wxString error_msg = wxGetApp().get_hms_query()->query_print_error_msg(obj->print_error);
std::vector<int> used_button;
wxString error_image_url = wxGetApp().get_hms_query()->query_print_error_url_action(obj->print_error,obj->dev_id, used_button);
if (!error_msg.IsEmpty()) {
wxDateTime now = wxDateTime::Now();
wxString show_time = now.Format("%H:%M:%S");
error_msg = wxString::Format("%s\n[%s %s]",
error_msg = wxString::Format("%s[%s %s]",
error_msg,
print_error_str, show_time);
show_error_message(obj, error_msg, print_error_str,error_image_url,used_button);
show_error_message(obj, error_msg, print_error_str);
} else {
BOOST_LOG_TRIVIAL(info) << "show print error! error_msg is empty, print error = " << obj->print_error;
}

View File

@ -460,7 +460,7 @@ protected:
CalibrationDialog* calibration_dlg {nullptr};
AMSMaterialsSetting *m_filament_setting_dlg{nullptr};
PrintErrorDialog* m_print_error_dlg = nullptr;
SecondaryCheckDialog* m_print_error_dlg = nullptr;
SecondaryCheckDialog* abort_dlg = nullptr;
SecondaryCheckDialog* con_load_dlg = nullptr;
SecondaryCheckDialog* ctrl_e_hint_dlg = nullptr;
@ -513,7 +513,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, wxString msg, std::string print_error_str = "",wxString image_url="",std::vector<int> used_button=std::vector<int>());
void show_error_message(MachineObject* obj, wxString msg, std::string print_error_str = "");
void error_info_reset();
void show_recenter_dialog();