mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 16:35:52 +08:00
Compatible printer check when sending uuid to connect.
This commit is contained in:
parent
535ecf7b34
commit
1264f57f84
@ -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) {
|
||||
|
@ -198,6 +198,24 @@ namespace {
|
||||
}
|
||||
return pt::ptree();
|
||||
}
|
||||
|
||||
void fill_supported_printer_models_from_json_inner(const pt::ptree& ptree, std::vector<std::string>& 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<std::string> 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();
|
||||
|
@ -73,8 +73,9 @@ public:
|
||||
const std::map<std::string, ConnectPrinterState>& 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<std::string, ConnectPrinterState> printer_state_table = {
|
||||
{"OFFLINE" , ConnectPrinterState::CONNECT_PRINTER_OFFLINE},
|
||||
|
@ -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(
|
||||
"{"
|
||||
|
Loading…
x
Reference in New Issue
Block a user