diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a238a5df61..13f2b3f35e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -976,6 +976,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) #endif // 0 }); this->q->Bind(EVT_UA_PRUSACONNECT_PRINTER_DATA_SUCCESS, [this](UserAccountSuccessEvent& evt) { + this->user_account->set_current_printer_data(evt.data); wxGetApp().handle_connect_request_printer_select_inner(evt.data); }); this->q->Bind(EVT_UA_PRUSACONNECT_PRINTER_DATA_FAIL, [this](UserAccountFailEvent& evt) { diff --git a/src/slic3r/GUI/UserAccount.cpp b/src/slic3r/GUI/UserAccount.cpp index a6117e2a50..8102c810f6 100644 --- a/src/slic3r/GUI/UserAccount.cpp +++ b/src/slic3r/GUI/UserAccount.cpp @@ -198,6 +198,24 @@ namespace { } return pt::ptree(); } + + void fill_supported_printer_models_from_json_inner(const pt::ptree& ptree, std::vector& result) { + std::string printer_model = parse_tree_for_param(ptree, "printer_model"); + if (!printer_model.empty()) { + result.emplace_back(printer_model); + } + pt::ptree out = parse_tree_for_subtree(ptree, "supported_printer_models"); + if (out.empty()) { + BOOST_LOG_TRIVIAL(error) << "Failed to find supported_printer_models in printer detail."; + return; + } + for (const auto& sub : out) { + if (printer_model != sub.second.data()) { + result.emplace_back(sub.second.data()); + } + + } + } } bool UserAccount::on_connect_printers_success(const std::string& data, AppConfig* app_config, bool& out_printers_changed) @@ -308,6 +326,36 @@ bool UserAccount::on_connect_uiid_map_success(const std::string& data, AppConfig return on_connect_printers_success(data, app_config, out_printers_changed); } +std::string UserAccount::get_current_printer_uuid_from_connect(const std::string& selected_printer_id) const +{ + if (m_current_printer_data_json_from_connect.empty() || m_current_printer_uuid_from_connect.empty()) { + return {}; + } + + pt::ptree ptree; + try { + std::stringstream ss(m_current_printer_data_json_from_connect); + pt::read_json(ss, ptree); + } + catch (const std::exception& e) { + BOOST_LOG_TRIVIAL(error) << "Could not parse Printer data from Connect. " << e.what(); + return {}; + } + + std::string data_uuid = parse_tree_for_param(ptree, "uuid"); + assert(data_uuid == m_current_printer_uuid_from_connect); + + //std::string model_name = parse_tree_for_param(ptree, "printer_model"); + std::vector compatible_printers; + fill_supported_printer_models_from_json_inner(ptree, compatible_printers); + if (compatible_printers.empty()) { + return {}; + } + + return std::find(compatible_printers.begin(), compatible_printers.end(), selected_printer_id) == compatible_printers.end() ? "" : m_current_printer_uuid_from_connect; +} + + std::string UserAccount::get_nozzle_from_json(const std::string& message) const { std::string out; @@ -358,21 +406,7 @@ void UserAccount::fill_supported_printer_models_from_json(const std::string& jso pt::ptree ptree; pt::read_json(ss, ptree); - std::string printer_model = parse_tree_for_param(ptree, "printer_model"); - if (!printer_model.empty()) { - result.emplace_back(printer_model); - } - pt::ptree out = parse_tree_for_subtree(ptree, "supported_printer_models"); - if (out.empty()) { - BOOST_LOG_TRIVIAL(error) << "Failed to find supported_printer_models in printer detail."; - return; - } - for (const auto& sub : out) { - if (printer_model != sub.second.data()) { - result.emplace_back(sub.second.data()); - } - - } + fill_supported_printer_models_from_json_inner(ptree, result); } catch (const std::exception& e) { BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what(); diff --git a/src/slic3r/GUI/UserAccount.hpp b/src/slic3r/GUI/UserAccount.hpp index a204a05c31..bfcdae5521 100644 --- a/src/slic3r/GUI/UserAccount.hpp +++ b/src/slic3r/GUI/UserAccount.hpp @@ -73,8 +73,9 @@ public: const std::map& get_printer_state_table() const { return printer_state_table; } void set_current_printer_uuid_from_connect(const std::string& uuid) { m_current_printer_uuid_from_connect = uuid; } - std::string get_current_printer_uuid_from_connect() const { return m_current_printer_uuid_from_connect; } + std::string get_current_printer_uuid_from_connect(const std::string& selected_printer_id) const; + void set_current_printer_data(const std::string& data) { m_current_printer_data_json_from_connect = data; } private: void set_username(const std::string& username); @@ -90,6 +91,7 @@ private: std::string m_avatar_extension; std::string m_current_printer_uuid_from_connect; + std::string m_current_printer_data_json_from_connect; const std::map printer_state_table = { {"OFFLINE" , ConnectPrinterState::CONNECT_PRINTER_OFFLINE}, diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 13c8cc1c01..8bfeeadc1e 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -1102,7 +1102,7 @@ void PrinterPickWebViewDialog::request_compatible_printers_FFF() // Sending only first filament type for now. This should change to array of values const std::string filament_type_serialized = selected_filament.config.option("filament_type")->serialize(); const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize(); - const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(); + const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized); const std::string filename = wxGetApp().plater()->get_upload_filename(); const std::string request = GUI::format( "{" @@ -1122,7 +1122,7 @@ void PrinterPickWebViewDialog::request_compatible_printers_SLA() const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize(); const Preset& selected_material = wxGetApp().preset_bundle->sla_materials.get_selected_preset(); const std::string material_type_serialized = selected_material.config.option("material_type")->serialize(); - const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(); + const std::string uuid = wxGetApp().plater()->get_user_account()->get_current_printer_uuid_from_connect(printer_model_serialized); const std::string filename = wxGetApp().plater()->get_upload_filename(); const std::string request = GUI::format( "{"