mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-31 21:52:02 +08:00
Check selected profile in connect by compatible printers vector.
Select printer in plater based on compatible printers vector, if given.
This commit is contained in:
parent
60b4789eed
commit
4358382db7
@ -3680,7 +3680,15 @@ void GUI_App::handle_connect_request_printer_pick(std::string msg)
|
|||||||
// return to plater
|
// return to plater
|
||||||
this->mainframe->select_tab(size_t(0));
|
this->mainframe->select_tab(size_t(0));
|
||||||
// parse message
|
// parse message
|
||||||
std::string model_name = plater()->get_user_account()->get_model_from_json(msg);
|
std::vector<std::string> 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);
|
std::string nozzle = plater()->get_user_account()->get_nozzle_from_json(msg);
|
||||||
assert(!model_name.empty());
|
assert(!model_name.empty());
|
||||||
if (model_name.empty())
|
if (model_name.empty())
|
||||||
|
@ -5862,29 +5862,75 @@ void Plater::connect_gcode()
|
|||||||
}
|
}
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Message from Printer pick webview: " << dialog_msg;
|
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<std::string> 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_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");
|
std::string connect_filament = p->user_account->get_keyword_from_json(dialog_msg, "filament_type");
|
||||||
assert(!connect_printer_model.empty());
|
std::vector<const Preset*> compatible_printer_presets;
|
||||||
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
|
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_printer_preset = &preset_bundle->printers.get_selected_preset();
|
||||||
const Preset* selected_filament_preset = &preset_bundle->filaments.get_selected_preset();
|
const Preset* selected_filament_preset = &preset_bundle->filaments.get_selected_preset();
|
||||||
const std::string selected_nozzle_serialized = dynamic_cast<const ConfigOptionFloats*>(selected_printer_preset->config.option("nozzle_diameter"))->serialize();
|
const std::string selected_nozzle_serialized = dynamic_cast<const ConfigOptionFloats*>(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 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)) {
|
bool is_first = compatible_printer_presets.front()->name == selected_printer_preset->name;
|
||||||
wxString line1 = _L("The printer profile you've selected for upload is not fully compatible with profiles selected for slicing.");
|
bool found = false;
|
||||||
wxString line2 = GUI::format_wxstr(_L("PrusaSlicer Profile: %1%, filament: %3%"), selected_printer_preset->name, selected_nozzle_serialized, selected_filament_serialized);
|
for (const Preset* connect_preset : compatible_printer_presets) {
|
||||||
wxString line3 = GUI::format_wxstr(_L("Selected Printer: %1%, filament: %3%"), connect_printer_preset->name, connect_nozzle, connect_filament);
|
if (!connect_preset) {
|
||||||
wxString line4 =_L("Choose YES to continue upload, choose NO to switch selected printer in PrusaSlicer.");
|
continue;
|
||||||
wxString message = GUI::format_wxstr("%1%\n\n%2%\n%3%\n\n%4%", line1, line2, line3, line4);
|
}
|
||||||
|
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);
|
MessageDialog msg_dialog(this, message, _L("Do you wish to upload?"), wxYES_NO);
|
||||||
auto modal_res = msg_dialog.ShowModal();
|
auto modal_res = msg_dialog.ShowModal();
|
||||||
if (modal_res == wxID_NO) {
|
if (modal_res != wxID_YES) {
|
||||||
// if selected (in connect) preset is not visible, make it visible and selected
|
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) {
|
if (!connect_printer_preset->is_visible) {
|
||||||
size_t preset_id = preset_bundle->printers.get_preset_idx_by_name(connect_printer_preset->name);
|
size_t preset_id = preset_bundle->printers.get_preset_idx_by_name(connect_printer_preset->name);
|
||||||
assert(preset_id != size_t(-1));
|
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));
|
p->notification_manager->push_notification(NotificationType::PrusaConnectPrinters, NotificationManager::NotificationLevel::ImportantNotificationLevel, format(_u8L("Changed Printer to %1%."), connect_printer_preset->name));
|
||||||
select_view_3D("3D");
|
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 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");
|
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."));
|
show_error(this, _L("Failed to select a printer. Missing data (uuid and team id) for chosen printer."));
|
||||||
return;
|
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<PrintHostType>(htPrusaConnectNew));
|
ph_printer.config.set_key_value("host_type", new ConfigOptionEnum<PrintHostType>(htPrusaConnectNew));
|
||||||
// use existing structures to pass data
|
// use existing structures to pass data
|
||||||
ph_printer.config.opt_string("printhost_apikey") = team_id;
|
ph_printer.config.opt_string("printhost_apikey") = team_id;
|
||||||
|
@ -179,6 +179,21 @@ namespace {
|
|||||||
}
|
}
|
||||||
return {};
|
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)
|
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;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UserAccount::fill_compatible_printers_from_json(const std::string& json, std::vector<std::string>& 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
|
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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}} // namespace slic3r::GUI
|
}} // namespace slic3r::GUI
|
@ -71,6 +71,7 @@ public:
|
|||||||
std::string get_nozzle_from_json(const std::string& message) const;
|
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_apikey_from_json(const std::string& message) const;
|
||||||
std::string get_keyword_from_json(const std::string& json, const std::string& keyword) 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<std::string>& result) const;
|
||||||
|
|
||||||
const std::map<std::string, ConnectPrinterState>& get_printer_state_table() const { return printer_state_table; }
|
const std::map<std::string, ConnectPrinterState>& get_printer_state_table() const { return printer_state_table; }
|
||||||
|
|
||||||
@ -101,14 +102,14 @@ private:
|
|||||||
{"3.1.0", "XL" },
|
{"3.1.0", "XL" },
|
||||||
{"5.1.0", "SL1" },
|
{"5.1.0", "SL1" },
|
||||||
// ysFIXME : needs to add Connect ids for next printers
|
// ysFIXME : needs to add Connect ids for next printers
|
||||||
{"0.0.0", "MK4IS" },
|
/*{"0.0.0", "MK4IS" },
|
||||||
{"0.0.0", "MK3SMMU2S" },
|
{"0.0.0", "MK3SMMU2S" },
|
||||||
{"0.0.0", "MK3MMU2" },
|
{"0.0.0", "MK3MMU2" },
|
||||||
{"0.0.0", "MK2.5SMMU2S" },
|
{"0.0.0", "MK2.5SMMU2S" },
|
||||||
{"0.0.0", "MK2.5MMU2" },
|
{"0.0.0", "MK2.5MMU2" },
|
||||||
{"0.0.0", "MK2S" },
|
{"0.0.0", "MK2S" },
|
||||||
{"0.0.0", "MK2SMM" },
|
{"0.0.0", "MK2SMM" },
|
||||||
{"0.0.0", "SL1S" },
|
{"0.0.0", "SL1S" },*/
|
||||||
};
|
};
|
||||||
/* TODO:
|
/* TODO:
|
||||||
4 1 0 iXL
|
4 1 0 iXL
|
||||||
|
@ -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_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);
|
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(
|
const std::string request = GUI::format(
|
||||||
"{"
|
"{"
|
||||||
"\"material\": \"%1%\", "
|
"\"material\": \"%1%\", "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user