mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-02 04:50:37 +08:00
avoid abrasive filament on non harden nozzle when selecting printer from connect.
This commit is contained in:
parent
b492368f26
commit
02c63a56b8
@ -3973,7 +3973,7 @@ bool GUI_App::select_filament_preset(const Preset* preset, size_t extruder_index
|
|||||||
assert(preset->is_visible);
|
assert(preset->is_visible);
|
||||||
return preset_bundle->extruders_filaments[extruder_index].select_filament(preset->name);
|
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();
|
const Preset* preset = preset_bundle->extruders_filaments[extruder_index].get_selected_preset();
|
||||||
// selected is ok
|
// 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->is_visible
|
||||||
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
||||||
&& filament.preset->config.has("filament_type")
|
&& 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->config.option("filament_type")->serialize() == material
|
||||||
&& filament.preset->name.compare(0, 9, "Prusament") == 0
|
&& filament.preset->name.compare(0, 9, "Prusament") == 0
|
||||||
&& select_filament_preset(filament.preset, extruder_index)
|
&& 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->is_visible
|
||||||
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
||||||
&& filament.preset->config.has("filament_type")
|
&& 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->config.option("filament_type")->serialize() == material
|
||||||
&& select_filament_preset(filament.preset, extruder_index)
|
&& 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->is_default
|
||||||
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
&& (!filament.preset->vendor || !filament.preset->vendor->templates_profile)
|
||||||
&& filament.preset->config.has("filament_type")
|
&& 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->config.option("filament_type")->serialize() == material
|
||||||
&& filament.preset->name.compare(0, 9, "Prusament") == 0
|
&& filament.preset->name.compare(0, 9, "Prusament") == 0
|
||||||
&& select_filament_preset(filament.preset, extruder_index))
|
&& select_filament_preset(filament.preset, extruder_index))
|
||||||
@ -4037,7 +4040,8 @@ void GUI_App::select_filament_from_connect(const std::string& msg)
|
|||||||
{
|
{
|
||||||
// parse message
|
// parse message
|
||||||
std::vector<std::string> materials;
|
std::vector<std::string> materials;
|
||||||
UserAccountUtils::fill_material_from_json(msg, materials);
|
std::vector<bool> avoid_abrasive;
|
||||||
|
UserAccountUtils::fill_material_from_json(msg, materials, avoid_abrasive);
|
||||||
if (materials.empty()) {
|
if (materials.empty()) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "Failed to select filament from Connect. No material data.";
|
BOOST_LOG_TRIVIAL(error) << "Failed to select filament from Connect. No material data.";
|
||||||
return;
|
return;
|
||||||
@ -4053,7 +4057,7 @@ void GUI_App::select_filament_from_connect(const std::string& msg)
|
|||||||
}
|
}
|
||||||
std::string notification_text;
|
std::string notification_text;
|
||||||
for (size_t i = 0; i < extruder_count; i++) {
|
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,
|
// When all filaments are selected/intalled,
|
||||||
|
@ -416,7 +416,7 @@ public:
|
|||||||
// 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_preset(const Preset* printer_preset);
|
bool select_printer_preset(const Preset* printer_preset);
|
||||||
bool select_filament_preset(const Preset* filament_preset, size_t extruder_index);
|
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 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) {}
|
||||||
|
@ -110,6 +110,41 @@ std::string json_var_to_opt_string(const std::string& json_var)
|
|||||||
return "0";
|
return "0";
|
||||||
return json_var;
|
return json_var;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fill_config_options_from_json_inner(boost::property_tree::ptree& ptree, std::map<std::string, std::vector<std::string>>& result, const std::map<std::string, std::string>& parameters)
|
||||||
|
{
|
||||||
|
pt::ptree slots = parse_tree_for_subtree(parse_tree_for_subtree(ptree, "slot"), "slots");
|
||||||
|
for (const auto &subtree : slots) {
|
||||||
|
size_t slot_id;
|
||||||
|
try {
|
||||||
|
slot_id = boost::lexical_cast<size_t>(subtree.first);
|
||||||
|
} catch (const boost::bad_lexical_cast&) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (const auto &item : subtree.second) {
|
||||||
|
if (parameters.find(item.first) == parameters.end()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::string config_name = parameters.at(item.first);
|
||||||
|
// resolve value
|
||||||
|
std::string val;
|
||||||
|
if (item.second.size() > 0) {
|
||||||
|
for (const auto &subitem : item.second) {
|
||||||
|
if (!val.empty()) {
|
||||||
|
val += ",";
|
||||||
|
}
|
||||||
|
val += json_var_to_opt_string(subitem.second.data());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val = json_var_to_opt_string(item.second.data());
|
||||||
|
}
|
||||||
|
// insert value
|
||||||
|
while (result[config_name].size() < slot_id)
|
||||||
|
result[config_name].emplace_back();
|
||||||
|
result[config_name][slot_id - 1] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map<std::string, std::vector<std::string>>& result)
|
void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map<std::string, std::vector<std::string>>& result)
|
||||||
@ -148,40 +183,10 @@ void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map<
|
|||||||
{"high_flow","nozzle_high_flow"},
|
{"high_flow","nozzle_high_flow"},
|
||||||
//{"",""}
|
//{"",""}
|
||||||
};
|
};
|
||||||
pt::ptree slots = parse_tree_for_subtree(parse_tree_for_subtree(ptree, "slot"), "slots");
|
fill_config_options_from_json_inner(ptree, result, parameters);
|
||||||
for (const auto &subtree : slots) {
|
|
||||||
size_t slot_id;
|
|
||||||
try {
|
|
||||||
slot_id = boost::lexical_cast<size_t>(subtree.first);
|
|
||||||
} catch (const boost::bad_lexical_cast&) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
for (const auto &item : subtree.second) {
|
|
||||||
if (parameters.find(item.first) == parameters.end()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::string config_name = parameters.at(item.first);
|
|
||||||
// resolve value
|
|
||||||
std::string val;
|
|
||||||
if (item.second.size() > 0) {
|
|
||||||
for (const auto &subitem : item.second) {
|
|
||||||
if (!val.empty()) {
|
|
||||||
val += ",";
|
|
||||||
}
|
|
||||||
val += json_var_to_opt_string(subitem.second.data());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val = json_var_to_opt_string(item.second.data());
|
|
||||||
}
|
|
||||||
// insert value
|
|
||||||
while (result[config_name].size() < slot_id)
|
|
||||||
result[config_name].emplace_back();
|
|
||||||
result[config_name][slot_id - 1] = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill_material_from_json(const std::string& json, std::vector<std::string>& result)
|
void fill_material_from_json(const std::string& json, std::vector<std::string>& material_result, std::vector<bool>& avoid_abrasive_result)
|
||||||
{
|
{
|
||||||
pt::ptree ptree;
|
pt::ptree ptree;
|
||||||
json_to_ptree(ptree, json);
|
json_to_ptree(ptree, json);
|
||||||
@ -242,7 +247,8 @@ void fill_material_from_json(const std::string& json, std::vector<std::string>&
|
|||||||
if (!filament_subtree.empty()) {
|
if (!filament_subtree.empty()) {
|
||||||
std::string material = parse_tree_for_param(filament_subtree, "material");
|
std::string material = parse_tree_for_param(filament_subtree, "material");
|
||||||
if (!material.empty()) {
|
if (!material.empty()) {
|
||||||
result.emplace_back(std::move(material));
|
material_result.emplace_back(std::move(material));
|
||||||
|
avoid_abrasive_result.emplace_back(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -250,6 +256,7 @@ void fill_material_from_json(const std::string& json, std::vector<std::string>&
|
|||||||
// search "slot" subtree for all "material"s
|
// search "slot" subtree for all "material"s
|
||||||
// this parses "slots" with respect to numbers of slots and adds empty string to missing numbers
|
// 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);
|
// 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");
|
pt::ptree slots = parse_tree_for_subtree(slot_subtree, "slots");
|
||||||
assert(!slots.empty());
|
assert(!slots.empty());
|
||||||
for (const auto &subtree : slots) {
|
for (const auto &subtree : slots) {
|
||||||
@ -265,6 +272,25 @@ void fill_material_from_json(const std::string& json, std::vector<std::string>&
|
|||||||
result.emplace_back();
|
result.emplace_back();
|
||||||
result[slot_id - 1] = val;
|
result[slot_id - 1] = val;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
const std::map<std::string, std::string> parameters = {
|
||||||
|
// first name from connect, second config option
|
||||||
|
{"material","material"},
|
||||||
|
{"hardened","hardened"},
|
||||||
|
//{"",""}
|
||||||
|
};
|
||||||
|
std::map<std::string, std::vector<std::string>> 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) {
|
std::string get_print_data_from_json(const std::string& json, const std::string& keyword) {
|
||||||
|
@ -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<std::string,std::vector<std::string>>& result);
|
void fill_config_options_from_json(boost::property_tree::ptree& ptree, std::map<std::string,std::vector<std::string>>& 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.
|
// 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<std::string>& result);
|
void fill_material_from_json(const std::string& json, std::vector<std::string>& material_result, std::vector<bool>& avoid_abrasive_result);
|
||||||
|
|
||||||
std::string get_print_data_from_json(const std::string &json, const std::string &keyword);
|
std::string get_print_data_from_json(const std::string &json, const std::string &keyword);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user