Select filament from connect.

This commit is contained in:
David Kocik 2024-04-17 15:51:02 +02:00
parent 7b9d9a33a4
commit 8ee04288fb
5 changed files with 134 additions and 27 deletions

View File

@ -3652,8 +3652,8 @@ void GUI_App::open_wifi_config_dialog(bool forced, const wxString& drive_path/*
} }
m_wifi_config_dialog_shown = false; m_wifi_config_dialog_shown = false;
} }
// Returns true if preset had to be installed.
bool GUI_App::select_printer_from_connect(const Preset* preset) bool GUI_App::select_printer_preset(const Preset* preset)
{ {
assert(preset); assert(preset);
@ -3677,11 +3677,8 @@ bool GUI_App::select_printer_from_connect(const Preset* preset)
return is_installed; return is_installed;
} }
void GUI_App::handle_connect_request_printer_pick(std::string msg) bool GUI_App::select_printer_from_connect(const std::string& msg)
{ {
BOOST_LOG_TRIVIAL(error) << "Handling web request: " << msg;
// return to plater
this->mainframe->select_tab(size_t(0));
// parse message // parse message
std::vector<std::string> compatible_printers; std::vector<std::string> compatible_printers;
plater()->get_user_account()->fill_compatible_printers_from_json(msg, compatible_printers); plater()->get_user_account()->fill_compatible_printers_from_json(msg, compatible_printers);
@ -3689,24 +3686,116 @@ void GUI_App::handle_connect_request_printer_pick(std::string msg)
if (compatible_printers.empty()) { if (compatible_printers.empty()) {
// TODO: This should go away when compatible printers gives right information. // TODO: This should go away when compatible printers gives right information.
model_name = plater()->get_user_account()->get_model_from_json(msg); model_name = plater()->get_user_account()->get_model_from_json(msg);
} else { }
else {
model_name = compatible_printers.front(); 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())
return; return false;
// select printer // select printer
const Preset* preset = preset_bundle->printers.find_system_preset_by_model_and_variant(model_name, nozzle); const Preset* printer_preset = preset_bundle->printers.find_system_preset_by_model_and_variant(model_name, nozzle);
bool is_installed = preset && select_printer_from_connect(preset); bool is_installed = printer_preset && select_printer_preset(printer_preset);
// notification // notification
std::string out = preset ? std::string out = printer_preset ?
(is_installed ? GUI::format(_L("Installed and Select Printer:\n%1%"), preset->name) : (is_installed ? GUI::format(_L("Installed and Selected Printer:\n%1%"), printer_preset->name) :
GUI::format(_L("Select Printer:\n%1%"), preset->name) ): GUI::format(_L("Selected Printer:\n%1%"), printer_preset->name)) :
GUI::format(_L("Printer not found:\n%1%"), model_name); GUI::format(_L("Printer not found:\n%1%"), model_name);
this->plater()->get_notification_manager()->close_notification_of_type(NotificationType::UserAccountID); this->plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectPrinterFromConnect);
this->plater()->get_notification_manager()->push_notification(NotificationType::UserAccountID, NotificationManager::NotificationLevel::ImportantNotificationLevel, out); this->plater()->get_notification_manager()->push_notification(NotificationType::SelectPrinterFromConnect, NotificationManager::NotificationLevel::ImportantNotificationLevel, out);
return printer_preset;
}
bool GUI_App::select_filament_preset(const Preset* preset)
{
assert(preset && preset->is_compatible);
if (!preset->is_visible) {
size_t preset_id = preset_bundle->filaments.get_preset_idx_by_name(preset->name);
assert(preset_id != size_t(-1));
preset_bundle->filaments.select_preset(preset_id);
}
return get_tab(Preset::Type::TYPE_FILAMENT)->select_preset(preset->name);
}
void GUI_App::select_filament_from_connect(const std::string& msg)
{
// parse message
std::string desired_type;
desired_type = plater()->get_user_account()->get_keyword_from_json(msg, "material");
if (desired_type.empty()) {
return;
}
// test if currently selected is same type
std::string selected_type = preset_bundle->filaments.get_selected_preset().config.option("filament_type")->serialize();
if (selected_type == desired_type) {
return;
}
// find first filament with suitable type
for (const auto& filament_preset : preset_bundle->filaments) {
if (filament_preset.is_visible
&& !filament_preset.vendor->templates_profile
&& filament_preset.is_compatible
&& filament_preset.config.option("filament_type")->serialize() == desired_type
&& select_filament_preset(&filament_preset))
{
std::string out = GUI::format(_L("Selected Filament:\n%1%"), filament_preset.name);
plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectFilamentFromConnect);
plater()->get_notification_manager()->push_notification(NotificationType::SelectFilamentFromConnect, NotificationManager::NotificationLevel::ImportantNotificationLevel, out);
return;
}
}
// find profile to install
// first try finding Prusament
for (const auto& filament_preset : preset_bundle->filaments) {
if (!filament_preset.vendor->templates_profile
&& filament_preset.is_compatible
&& filament_preset.config.option("filament_type")->serialize() == desired_type
&& filament_preset.name.compare(0, 9, "Prusament") == 0
&& select_filament_preset(&filament_preset))
{
std::string out = GUI::format(_L("Installed and Selected Filament:\n%1%"), filament_preset.name);
plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectFilamentFromConnect);
plater()->get_notification_manager()->push_notification(NotificationType::SelectFilamentFromConnect, NotificationManager::NotificationLevel::ImportantNotificationLevel, out);
return;
}
}
// then just any compatible
for (const auto& filament_preset : preset_bundle->filaments) {
if (!filament_preset.vendor->templates_profile
&& filament_preset.is_compatible
&& filament_preset.config.option("filament_type")->serialize() == desired_type
&& select_filament_preset(&filament_preset))
{
std::string out = GUI::format(_L("Installed and Selected Filament:\n%1%"), filament_preset.name);
plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectFilamentFromConnect);
plater()->get_notification_manager()->push_notification(NotificationType::SelectFilamentFromConnect, NotificationManager::NotificationLevel::ImportantNotificationLevel, out);
return;
}
}
// no filamet found
std::string out = GUI::format(_L("Failed to find and select filament type:\n%1%"), desired_type);
plater()->get_notification_manager()->close_notification_of_type(NotificationType::SelectFilamentFromConnect);
plater()->get_notification_manager()->push_notification(NotificationType::SelectFilamentFromConnect, NotificationManager::NotificationLevel::ImportantNotificationLevel, out);
}
void GUI_App::handle_connect_request_printer_pick(const std::string& msg)
{
BOOST_LOG_TRIVIAL(debug) << "Handling web request: " << msg;
// return to plater
this->mainframe->select_tab(size_t(0));
if (!select_printer_from_connect(msg)) {
// If printer was not selected, do not select filament.
return;
}
if (Preset::printer_technology(preset_bundle->printers.get_selected_preset().config) != ptFFF) {
return;
}
select_filament_from_connect(msg);
} }
void GUI_App::show_printer_webview_tab() void GUI_App::show_printer_webview_tab()

View File

@ -411,10 +411,13 @@ public:
void request_user_login(int online_login) {} void request_user_login(int online_login) {}
void request_user_logout() {} void request_user_logout() {}
int request_user_unbind(std::string dev_id) { return 0; } int request_user_unbind(std::string dev_id) { return 0; }
void handle_connect_request_printer_pick(std::string cmd); bool select_printer_from_connect(const std::string& cmd);
void select_filament_from_connect(const std::string& cmd);
void handle_connect_request_printer_pick(const std::string& cmd);
void show_printer_webview_tab(); void show_printer_webview_tab();
// return true if preset vas invisible and we have to installed it to make it selectable // return true if preset vas invisible and we have to installed it to make it selectable
bool select_printer_from_connect(const Preset* printer_preset); bool select_printer_preset(const Preset* printer_preset);
bool select_filament_preset(const Preset* filament_preset);
void handle_script_message(std::string msg) {} void handle_script_message(std::string msg) {}
void request_model_download(std::string import_json) {} void request_model_download(std::string import_json) {}
void download_project(std::string project_id) {} void download_project(std::string project_id) {}

View File

@ -131,6 +131,9 @@ enum class NotificationType
WifiConfigFileDetected, WifiConfigFileDetected,
// Info abouty successful login or logout // Info abouty successful login or logout
UserAccountID, UserAccountID,
// When in Connect tab "set as current" is selected and selected presets in plater changes
SelectPrinterFromConnect,
SelectFilamentFromConnect,
// Debug notification for connect communication // Debug notification for connect communication
PrusaConnectPrinters, PrusaConnectPrinters,
}; };

View File

@ -5863,7 +5863,7 @@ void Plater::connect_gcode()
std::vector<std::string> compatible_printers; std::vector<std::string> compatible_printers;
p->user_account->fill_compatible_printers_from_json(dialog_msg, 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_type = p->user_account->get_keyword_from_json(dialog_msg, "material");
std::vector<const Preset*> compatible_printer_presets; std::vector<const Preset*> compatible_printer_presets;
for (const std::string& cp : compatible_printers) { 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)); compatible_printer_presets.emplace_back(preset_bundle->printers.find_system_preset_by_model_and_variant(cp, connect_nozzle));
@ -5872,7 +5872,7 @@ void Plater::connect_gcode()
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_type_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();
bool is_first = compatible_printer_presets.front()->name == selected_printer_preset->name; bool is_first = compatible_printer_presets.front()->name == selected_printer_preset->name;
@ -5886,9 +5886,9 @@ void Plater::connect_gcode()
break; break;
} }
} }
// // Dialog to select action
if (!found) { if (!found) {
wxString line1 = _L("The printer profile you've selected for upload is not compatible with profiles selected for slicing."); wxString line1 = _L("The printer 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 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 line3 = _L("Known profiles compatible with printer selected for upload:");
wxString printers_line; wxString printers_line;
@ -5906,7 +5906,7 @@ void Plater::connect_gcode()
return; return;
} }
} else if (!is_first) { } 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 line1 = _L("The printer 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 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 line3 = _L("Known profiles compatible with printer selected for upload:");
wxString printers_line; wxString printers_line;
@ -5924,6 +5924,19 @@ void Plater::connect_gcode()
return; return;
} }
} }
if (selected_filament_type_serialized != connect_filament_type) {
wxString line1 = _L("The printer you've selected has different filament type than filament profile selected for slicing.");
wxString line2 = GUI::format_wxstr(_L("PrusaConnect Filament Type: %1%"), connect_filament_type);
wxString line3 = GUI::format_wxstr(_L("PrusaSlicer Filament Type: %1%"), selected_filament_type_serialized);
wxString line4 = _L("Do you still wish to upload?");
wxString message = GUI::format_wxstr("%1%\n\n%2%\n%3%\n\n%4%", line1, line2, line3, 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 // Commented code with selecting printers in plater
/* /*
// if selected (in connect) preset is not visible, make it visible and selected // if selected (in connect) preset is not visible, make it visible and selected

View File

@ -157,11 +157,10 @@ namespace {
for (const auto& section : tree) { for (const auto& section : tree) {
if (section.first == param) { if (section.first == param) {
return section.second.data(); return section.second.data();
} else { }
if (std::string res = parse_tree_for_param(section.second, param); !res.empty()) if (std::string res = parse_tree_for_param(section.second, param); !res.empty()) {
return res; return res;
} }
} }
return {}; return {};
} }