Printer_model reading when uploading to Connect.

This commit is contained in:
David Kocik 2024-04-23 16:06:13 +02:00
parent 403a3ec095
commit 5e48e0a5a6
4 changed files with 12 additions and 27 deletions

View File

@ -3683,7 +3683,7 @@ bool GUI_App::select_printer_from_connect(const std::string& msg)
std::string model_name = plater()->get_user_account()->get_keyword_from_json(msg, "printer_model");
if (model_name.empty()) {
std::vector<std::string> compatible_printers;
plater()->get_user_account()->fill_compatible_printers_from_json(msg, compatible_printers);
plater()->get_user_account()->fill_supported_printer_models_from_json(msg, compatible_printers);
if (!compatible_printers.empty()) {
model_name = compatible_printers.front();
}

View File

@ -5874,7 +5874,7 @@ void Plater::connect_gcode()
PresetBundle* preset_bundle = wxGetApp().preset_bundle;
// Connect data
std::vector<std::string> compatible_printers;
p->user_account->fill_compatible_printers_from_json_old(dialog_msg, compatible_printers);
p->user_account->fill_supported_printer_models_from_json(dialog_msg, compatible_printers);
std::string connect_nozzle = p->user_account->get_nozzle_from_json(dialog_msg);
std::vector<std::string> connect_materials;

View File

@ -365,41 +365,27 @@ 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<std::string>& result) const
void UserAccount::fill_supported_printer_models_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);
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 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();
}
}
void UserAccount::fill_compatible_printers_from_json_old(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());
if (printer_model != sub.second.data()) {
result.emplace_back(sub.second.data());
}
}
}
catch (const std::exception& e) {

View File

@ -68,8 +68,7 @@ public:
std::string get_model_from_json(const std::string& message) const;
std::string get_nozzle_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<std::string>& result) const;
void fill_compatible_printers_from_json_old(const std::string& json, std::vector<std::string>& result) const;
void fill_supported_printer_models_from_json(const std::string& json, std::vector<std::string>& result) const;
void fill_material_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; }