diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index f990eb0cf3..115eba8351 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3680,7 +3680,15 @@ void GUI_App::handle_connect_request_printer_pick(std::string msg) // return to plater this->mainframe->select_tab(size_t(0)); // parse message - std::string model_name = plater()->get_user_account()->get_model_from_json(msg); + std::vector compatible_printers; + plater()->get_user_account()->fill_compatible_printers_from_json(msg, compatible_printers); + std::string model_name; + if (compatible_printers.empty()) { + // TODO: This should go away when compatible printers gives right information. + model_name = plater()->get_user_account()->get_model_from_json(msg); + } else { + model_name = compatible_printers.front(); + } std::string nozzle = plater()->get_user_account()->get_nozzle_from_json(msg); assert(!model_name.empty()); if (model_name.empty()) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7820ef2eba..cd446795b3 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5862,29 +5862,75 @@ void Plater::connect_gcode() } BOOST_LOG_TRIVIAL(debug) << "Message from Printer pick webview: " << dialog_msg; - std::string connect_printer_model = p->user_account->get_model_from_json(dialog_msg); + PresetBundle* preset_bundle = wxGetApp().preset_bundle; + // Connect data + std::vector compatible_printers; + p->user_account->fill_compatible_printers_from_json(dialog_msg, compatible_printers); std::string connect_nozzle = p->user_account->get_nozzle_from_json(dialog_msg); std::string connect_filament = p->user_account->get_keyword_from_json(dialog_msg, "filament_type"); - assert(!connect_printer_model.empty()); - PresetBundle* preset_bundle = wxGetApp().preset_bundle; + std::vector compatible_printer_presets; + for (const std::string& cp : compatible_printers) { + compatible_printer_presets.emplace_back(preset_bundle->printers.find_system_preset_by_model_and_variant(cp, connect_nozzle)); + } + // Selected profiles const Preset* selected_printer_preset = &preset_bundle->printers.get_selected_preset(); const Preset* selected_filament_preset = &preset_bundle->filaments.get_selected_preset(); const std::string selected_nozzle_serialized = dynamic_cast(selected_printer_preset->config.option("nozzle_diameter"))->serialize(); - const std::string selected_filament_serialized = selected_filament_preset ->config.option("filament_type")->serialize(); + const std::string selected_filament_serialized = selected_filament_preset->config.option("filament_type")->serialize(); const std::string selected_printer_model_serialized = selected_printer_preset->config.option("printer_model")->serialize(); - - const Preset* connect_printer_preset = preset_bundle->printers.find_system_preset_by_model_and_variant(connect_printer_model, connect_nozzle); - if (connect_printer_model != selected_printer_model_serialized || (!connect_nozzle.empty() && connect_nozzle != selected_nozzle_serialized) || (!connect_filament.empty() && connect_filament != selected_filament_serialized)) { - wxString line1 = _L("The printer profile you've selected for upload is not fully compatible with profiles selected for slicing."); - wxString line2 = GUI::format_wxstr(_L("PrusaSlicer Profile: %1%, filament: %3%"), selected_printer_preset->name, selected_nozzle_serialized, selected_filament_serialized); - wxString line3 = GUI::format_wxstr(_L("Selected Printer: %1%, filament: %3%"), connect_printer_preset->name, connect_nozzle, connect_filament); - wxString line4 =_L("Choose YES to continue upload, choose NO to switch selected printer in PrusaSlicer."); - wxString message = GUI::format_wxstr("%1%\n\n%2%\n%3%\n\n%4%", line1, line2, line3, line4); + bool is_first = compatible_printer_presets.front()->name == selected_printer_preset->name; + bool found = false; + for (const Preset* connect_preset : compatible_printer_presets) { + if (!connect_preset) { + continue; + } + if (selected_printer_preset->name == connect_preset->name) { + found = true; + break; + } + } + // + if (!found) { + wxString line1 = _L("The printer profile you've selected for upload is not compatible with profiles selected for slicing."); + wxString line2 = GUI::format_wxstr(_L("PrusaSlicer Profile:\n%1%"), selected_printer_preset->name); + wxString line3 = _L("Known profiles compatible with printer selected for upload:"); + wxString printers_line; + for (const Preset* connect_preset : compatible_printer_presets) { + if (!connect_preset) { + continue; + } + printers_line += GUI::format_wxstr(_L("\n%1%"), connect_preset->name); + } + wxString line4 = _L("Do you still wish to upload?"); + wxString message = GUI::format_wxstr("%1%\n\n%2%\n\n%3%%4%\n\n%5%", line1, line2, line3, printers_line,line4); MessageDialog msg_dialog(this, message, _L("Do you wish to upload?"), wxYES_NO); auto modal_res = msg_dialog.ShowModal(); - if (modal_res == wxID_NO) { - // if selected (in connect) preset is not visible, make it visible and selected + if (modal_res != wxID_YES) { + return; + } + } else if (!is_first) { + wxString line1 = _L("The printer profile you've selected for upload might not be compatible with profiles selected for slicing."); + wxString line2 = GUI::format_wxstr(_L("PrusaSlicer Profile:\n%1%"), selected_printer_preset->name); + wxString line3 = _L("Known profiles compatible with printer selected for upload:"); + wxString printers_line; + for (const Preset* connect_preset : compatible_printer_presets) { + if (!connect_preset) { + continue; + } + printers_line += GUI::format_wxstr(_L("\n%1%"), connect_preset->name); + } + wxString line4 = _L("Do you still wish to upload?"); + wxString message = GUI::format_wxstr("%1%\n\n%2%\n\n%3%%4%\n\n%5%", line1, line2, line3, printers_line, line4); + MessageDialog msg_dialog(this, message, _L("Do you wish to upload?"), wxYES_NO); + auto modal_res = msg_dialog.ShowModal(); + if (modal_res != wxID_YES) { + return; + } + } + // Commented code with selecting printers in plater + /* + // if selected (in connect) preset is not visible, make it visible and selected if (!connect_printer_preset->is_visible) { size_t preset_id = preset_bundle->printers.get_preset_idx_by_name(connect_printer_preset->name); assert(preset_id != size_t(-1)); @@ -5904,13 +5950,7 @@ void Plater::connect_gcode() p->notification_manager->push_notification(NotificationType::PrusaConnectPrinters, NotificationManager::NotificationLevel::ImportantNotificationLevel, format(_u8L("Changed Printer to %1%."), connect_printer_preset->name)); select_view_3D("3D"); } - // TODO: select filament - return; - } else if (modal_res != wxID_YES) { - // exit dialog without selecting yes / no - return; - } - } + */ const std::string connect_state = p->user_account->get_keyword_from_json(dialog_msg, "connect_state"); const std::string printer_state = p->user_account->get_keyword_from_json(dialog_msg, "printer_state"); @@ -5929,7 +5969,7 @@ void Plater::connect_gcode() show_error(this, _L("Failed to select a printer. Missing data (uuid and team id) for chosen printer.")); return; } - PhysicalPrinter ph_printer("connect_temp_printer", wxGetApp().preset_bundle->physical_printers.default_config(), *connect_printer_preset); + PhysicalPrinter ph_printer("connect_temp_printer", wxGetApp().preset_bundle->physical_printers.default_config(), /**connect_printer_preset*/*selected_printer_preset); ph_printer.config.set_key_value("host_type", new ConfigOptionEnum(htPrusaConnectNew)); // use existing structures to pass data ph_printer.config.opt_string("printhost_apikey") = team_id; diff --git a/src/slic3r/GUI/UserAccount.cpp b/src/slic3r/GUI/UserAccount.cpp index bf53192ba1..7304c22ec4 100644 --- a/src/slic3r/GUI/UserAccount.cpp +++ b/src/slic3r/GUI/UserAccount.cpp @@ -179,6 +179,21 @@ namespace { } return {}; } + + pt::ptree parse_tree_for_subtree(const pt::ptree& tree, const std::string& param) + { + for (const auto& section : tree) { + if (section.first == param) { + return section.second; + } + else { + if (pt::ptree res = parse_tree_for_subtree(section.second, param); !res.empty()) + return res; + } + + } + return pt::ptree(); + } } bool UserAccount::on_connect_printers_success(const std::string& data, AppConfig* app_config, bool& out_printers_changed) @@ -316,6 +331,29 @@ std::string UserAccount::get_keyword_from_json(const std::string& json, const st } return out; } + +void UserAccount::fill_compatible_printers_from_json(const std::string& json, std::vector& result) const +{ + try { + std::stringstream ss(json); + pt::ptree ptree; + pt::read_json(ss, ptree); + + pt::ptree out = parse_tree_for_subtree(ptree, "printer_type_compatible"); + if (out.empty()) { + BOOST_LOG_TRIVIAL(error) << "Failed to find compatible_printer_type in printer detail."; + return; + } + for (const auto& sub : out) { + result.emplace_back(sub.second.data()); + } + } + catch (const std::exception& e) { + BOOST_LOG_TRIVIAL(error) << "Could not parse prusaconnect message. " << e.what(); + } +} + + std::string UserAccount::get_printer_type_from_name(const std::string& printer_name) const { @@ -328,4 +366,5 @@ std::string UserAccount::get_printer_type_from_name(const std::string& printer_n return {}; } + }} // namespace slic3r::GUI \ No newline at end of file diff --git a/src/slic3r/GUI/UserAccount.hpp b/src/slic3r/GUI/UserAccount.hpp index ba8262ac94..91edd207f9 100644 --- a/src/slic3r/GUI/UserAccount.hpp +++ b/src/slic3r/GUI/UserAccount.hpp @@ -71,6 +71,7 @@ public: std::string get_nozzle_from_json(const std::string& message) const; //std::string get_apikey_from_json(const std::string& message) const; std::string get_keyword_from_json(const std::string& json, const std::string& keyword) const; + void fill_compatible_printers_from_json(const std::string& json, std::vector& result) const; const std::map& get_printer_state_table() const { return printer_state_table; } @@ -101,14 +102,14 @@ private: {"3.1.0", "XL" }, {"5.1.0", "SL1" }, // ysFIXME : needs to add Connect ids for next printers - {"0.0.0", "MK4IS" }, + /*{"0.0.0", "MK4IS" }, {"0.0.0", "MK3SMMU2S" }, {"0.0.0", "MK3MMU2" }, {"0.0.0", "MK2.5SMMU2S" }, {"0.0.0", "MK2.5MMU2" }, {"0.0.0", "MK2S" }, {"0.0.0", "MK2SMM" }, - {"0.0.0", "SL1S" }, + {"0.0.0", "SL1S" },*/ }; /* TODO: 4 1 0 iXL diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index 2111350252..bd692406ee 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -695,7 +695,7 @@ void PrinterPickWebViewDialog::request_compatible_printers() const std::string printer_model_serialized = selected_printer.config.option("printer_model")->serialize(); const std::string printer_type = wxGetApp().plater()->get_user_account()->get_printer_type_from_name(printer_model_serialized); - assert(!filament_type_serialized.empty() && !nozzle_diameter_serialized.empty() && !printer_type.empty()); + // assert(!filament_type_serialized.empty() && !nozzle_diameter_serialized.empty() && !printer_type.empty()); const std::string request = GUI::format( "{" "\"material\": \"%1%\", "