diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 5cf38043a0..3957325f65 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3973,7 +3973,7 @@ bool GUI_App::select_filament_preset(const Preset* preset, size_t extruder_index assert(preset->is_visible); return preset_bundle->extruders_filaments[extruder_index].select_filament(preset->name); } -void GUI_App::search_and_select_filaments(const std::string& material, size_t extruder_index, std::string& out_message) +void GUI_App::search_and_select_filaments(const std::string& material, bool avoid_abrasive, size_t extruder_index, std::string& out_message) { const Preset* preset = preset_bundle->extruders_filaments[extruder_index].get_selected_preset(); // selected is ok @@ -3987,6 +3987,7 @@ void GUI_App::search_and_select_filaments(const std::string& material, size_t ex && filament.preset->is_visible && (!filament.preset->vendor || !filament.preset->vendor->templates_profile) && filament.preset->config.has("filament_type") + && (!avoid_abrasive || filament.preset->config.opt_bool("filament_abrasive") == false) && filament.preset->config.option("filament_type")->serialize() == material && filament.preset->name.compare(0, 9, "Prusament") == 0 && select_filament_preset(filament.preset, extruder_index) @@ -4005,6 +4006,7 @@ void GUI_App::search_and_select_filaments(const std::string& material, size_t ex && filament.preset->is_visible && (!filament.preset->vendor || !filament.preset->vendor->templates_profile) && filament.preset->config.has("filament_type") + && (!avoid_abrasive || filament.preset->config.opt_bool("filament_abrasive") == false) && filament.preset->config.option("filament_type")->serialize() == material && select_filament_preset(filament.preset, extruder_index) ) @@ -4022,6 +4024,7 @@ void GUI_App::search_and_select_filaments(const std::string& material, size_t ex && !filament.preset->is_default && (!filament.preset->vendor || !filament.preset->vendor->templates_profile) && filament.preset->config.has("filament_type") + && (!avoid_abrasive || filament.preset->config.opt_bool("filament_abrasive") == false) && filament.preset->config.option("filament_type")->serialize() == material && filament.preset->name.compare(0, 9, "Prusament") == 0 && select_filament_preset(filament.preset, extruder_index)) @@ -4037,7 +4040,8 @@ void GUI_App::select_filament_from_connect(const std::string& msg) { // parse message std::vector materials; - UserAccountUtils::fill_material_from_json(msg, materials); + std::vector avoid_abrasive; + UserAccountUtils::fill_material_from_json(msg, materials, avoid_abrasive); if (materials.empty()) { BOOST_LOG_TRIVIAL(error) << "Failed to select filament from Connect. No material data."; return; @@ -4053,7 +4057,7 @@ void GUI_App::select_filament_from_connect(const std::string& msg) } std::string notification_text; for (size_t i = 0; i < extruder_count; i++) { - search_and_select_filaments(materials[i], i, notification_text); + search_and_select_filaments(materials[i], avoid_abrasive.size() > i ? avoid_abrasive[i] : false, i, notification_text); } // When all filaments are selected/intalled, diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 6d7008f0dd..e915576943 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -416,7 +416,7 @@ public: // return true if preset vas invisible and we have to installed it to make it selectable bool select_printer_preset(const Preset* printer_preset); bool select_filament_preset(const Preset* filament_preset, size_t extruder_index); - void search_and_select_filaments(const std::string& material, size_t extruder_index, std::string& out_message); + void search_and_select_filaments(const std::string& material, bool avoid_abrasive, size_t extruder_index, std::string& out_message); void handle_script_message(std::string msg) {} void request_model_download(std::string import_json) {} void download_project(std::string project_id) {} diff --git a/src/slic3r/GUI/UserAccountUtils.cpp b/src/slic3r/GUI/UserAccountUtils.cpp index fb67f01c59..c82a9731e6 100644 --- a/src/slic3r/GUI/UserAccountUtils.cpp +++ b/src/slic3r/GUI/UserAccountUtils.cpp @@ -110,44 +110,9 @@ std::string json_var_to_opt_string(const std::string& json_var) return "0"; return json_var; } -} -void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map>& result) +void fill_config_options_from_json_inner(boost::property_tree::ptree& ptree, std::map>& result, const std::map& parameters) { - assert(!ptree.empty()); - /* - "slot": { - "active": 3, - "slots": { - "1": { - "material": "PETG", - "temp": 32.0, - "fan_hotend": 0.0, - "fan_print": 0.0, - "nozzle_diameter": 3.2, // float - "high_flow": true, // boolean - "high_temperature": false, // boolean - "hardened": true, // boolean - }, - "3": { - "material": "ASA", - "temp": 35.0, - "fan_hotend": 0.0, - "fan_print": 0.0, - "nozzle_diameter": 3.2, // float - "high_flow": true, // boolean - "high_temperature": false, // boolean - "hardened": true, // boolean - }, - } - } - */ - const std::map parameters = { - // first name from connect, second config option - {"nozzle_diameter","nozzle_diameter"}, - {"high_flow","nozzle_high_flow"}, - //{"",""} - }; pt::ptree slots = parse_tree_for_subtree(parse_tree_for_subtree(ptree, "slot"), "slots"); for (const auto &subtree : slots) { size_t slot_id; @@ -180,8 +145,48 @@ void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map< } } } +} -void fill_material_from_json(const std::string& json, std::vector& result) +void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map>& result) +{ + assert(!ptree.empty()); + /* + "slot": { + "active": 3, + "slots": { + "1": { + "material": "PETG", + "temp": 32.0, + "fan_hotend": 0.0, + "fan_print": 0.0, + "nozzle_diameter": 3.2, // float + "high_flow": true, // boolean + "high_temperature": false, // boolean + "hardened": true, // boolean + }, + "3": { + "material": "ASA", + "temp": 35.0, + "fan_hotend": 0.0, + "fan_print": 0.0, + "nozzle_diameter": 3.2, // float + "high_flow": true, // boolean + "high_temperature": false, // boolean + "hardened": true, // boolean + }, + } + } + */ + const std::map parameters = { + // first name from connect, second config option + {"nozzle_diameter","nozzle_diameter"}, + {"high_flow","nozzle_high_flow"}, + //{"",""} + }; + fill_config_options_from_json_inner(ptree, result, parameters); +} + +void fill_material_from_json(const std::string& json, std::vector& material_result, std::vector& avoid_abrasive_result) { pt::ptree ptree; json_to_ptree(ptree, json); @@ -242,7 +247,8 @@ void fill_material_from_json(const std::string& json, std::vector& if (!filament_subtree.empty()) { std::string material = parse_tree_for_param(filament_subtree, "material"); if (!material.empty()) { - result.emplace_back(std::move(material)); + material_result.emplace_back(std::move(material)); + avoid_abrasive_result.emplace_back(true); } } return; @@ -250,6 +256,7 @@ void fill_material_from_json(const std::string& json, std::vector& // search "slot" subtree for all "material"s // this parses "slots" with respect to numbers of slots and adds empty string to missing numbers // if only filled should be used. Use: parse_tree_for_param_vector(slot_subtree, "material", result); + /* pt::ptree slots = parse_tree_for_subtree(slot_subtree, "slots"); assert(!slots.empty()); for (const auto &subtree : slots) { @@ -265,6 +272,25 @@ void fill_material_from_json(const std::string& json, std::vector& result.emplace_back(); result[slot_id - 1] = val; } + */ + const std::map parameters = { + // first name from connect, second config option + {"material","material"}, + {"hardened","hardened"}, + //{"",""} + }; + std::map> result_map; + fill_config_options_from_json_inner(ptree, result_map, parameters); + if (result_map.find("material") != result_map.end()) { + for (const std::string& val : result_map["material"]) { + material_result.emplace_back(val); + } + } + if (result_map.find("hardened") != result_map.end()) { + for (const std::string& val : result_map["hardened"]) { + avoid_abrasive_result.emplace_back(val == "false" ? 1 : 0); + } + } } std::string get_print_data_from_json(const std::string& json, const std::string& keyword) { diff --git a/src/slic3r/GUI/UserAccountUtils.hpp b/src/slic3r/GUI/UserAccountUtils.hpp index e45b385cf5..d470a93900 100644 --- a/src/slic3r/GUI/UserAccountUtils.hpp +++ b/src/slic3r/GUI/UserAccountUtils.hpp @@ -18,7 +18,7 @@ void fill_supported_printer_models_from_json(boost::property_tree::ptree& ptree, void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map>& result); // Since fill_material_from_json is called only from one place where ptree doesnt need to be shared, it is not always read from json. -void fill_material_from_json(const std::string& json, std::vector& result); +void fill_material_from_json(const std::string& json, std::vector& material_result, std::vector& avoid_abrasive_result); std::string get_print_data_from_json(const std::string &json, const std::string &keyword);