From 82a1a38c3063c884995b71faf5e500b0d38a09a3 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Mon, 17 Oct 2022 21:33:57 +0800 Subject: [PATCH] NEW: add slice warning msg to slice_info Change-Id: I145a14b7ab6f4aff2158ca0f86191e57b7efa643 --- src/libslic3r/Format/bbs_3mf.cpp | 44 ++++++++++++++++++++++++++++++++ src/libslic3r/Format/bbs_3mf.hpp | 2 ++ src/slic3r/GUI/PartPlate.cpp | 2 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/Format/bbs_3mf.cpp b/src/libslic3r/Format/bbs_3mf.cpp index f996f85240..724d1ec6e5 100644 --- a/src/libslic3r/Format/bbs_3mf.cpp +++ b/src/libslic3r/Format/bbs_3mf.cpp @@ -175,6 +175,8 @@ static constexpr const char* BUILD_TAG = "build"; static constexpr const char* ITEM_TAG = "item"; static constexpr const char* METADATA_TAG = "metadata"; static constexpr const char* FILAMENT_TAG = "filament"; +static constexpr const char* SLICE_WARNING_TAG = "warning"; +static constexpr const char* WARNING_MSG_TAG = "msg"; static constexpr const char *FILAMENT_ID_TAG = "id"; static constexpr const char* FILAMENT_TYPE_TAG = "type"; static constexpr const char *FILAMENT_COLOR_TAG = "color"; @@ -460,6 +462,14 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) info.used_g = used_filament_g; slice_filaments_info.push_back(info); } + + /* only for test + GCodeProcessorResult::SliceWarnings sw; + sw.msg = BED_TEMP_TOO_HIGH_THAN_FILAMENT; + sw.level = 1; + result->warnings.push_back(sw); + */ + warnings = result->warnings; } @@ -843,6 +853,9 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) bool _handle_start_config_filament(const char** attributes, unsigned int num_attributes); bool _handle_end_config_filament(); + bool _handle_start_config_warning(const char** attributes, unsigned int num_attributes); + bool _handle_end_config_warning(); + //BBS: add plater config parse functions bool _handle_start_config_plater(const char** attributes, unsigned int num_attributes); bool _handle_end_config_plater(); @@ -1510,6 +1523,7 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) plate_data_list[it->first-1]->gcode_weight = it->second->gcode_weight; plate_data_list[it->first-1]->toolpath_outside = it->second->toolpath_outside; plate_data_list[it->first-1]->slice_filaments_info = it->second->slice_filaments_info; + plate_data_list[it->first-1]->warnings = it->second->warnings; plate_data_list[it->first-1]->thumbnail_file = (m_load_restore || it->second->thumbnail_file.empty()) ? it->second->thumbnail_file : m_backup_path + "/" + it->second->thumbnail_file; plate_data_list[it->first-1]->pattern_file = (m_load_restore || it->second->pattern_file.empty()) ? it->second->pattern_file : m_backup_path + "/" + it->second->pattern_file; plate_data_list[it->first-1]->pattern_bbox_file = (m_load_restore || it->second->pattern_bbox_file.empty()) ? it->second->pattern_bbox_file : m_backup_path + "/" + it->second->pattern_bbox_file; @@ -2355,6 +2369,8 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) res = _handle_start_config_plater_instance(attributes, num_attributes); else if (::strcmp(FILAMENT_TAG, name) == 0) res = _handle_start_config_filament(attributes, num_attributes); + else if (::strcmp(SLICE_WARNING_TAG, name) == 0) + res = _handle_start_config_warning(attributes, num_attributes); else if (::strcmp(ASSEMBLE_TAG, name) == 0) res = _handle_start_assemble(attributes, num_attributes); else if (::strcmp(ASSEMBLE_ITEM_TAG, name) == 0) @@ -3205,6 +3221,30 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) return true; } + bool _BBS_3MF_Importer::_handle_start_config_warning(const char** attributes, unsigned int num_attributes) + { + if (m_curr_plater) { + std::string msg = bbs_get_attribute_value_string(attributes, num_attributes, WARNING_MSG_TAG); + std::string lvl_str = bbs_get_attribute_value_string(attributes, num_attributes, "level"); + GCodeProcessorResult::SliceWarnings sw; + sw.msg = msg; + try { + sw.level = atoi(lvl_str.c_str()); + } + catch(...) { + }; + + m_curr_plater->warnings.push_back(sw); + } + return true; + } + + bool _BBS_3MF_Importer::_handle_end_config_warning() + { + // do nothing + return true; + } + bool _BBS_3MF_Importer::_handle_start_config_plater(const char** attributes, unsigned int num_attributes) { if (!m_parsing_slice_info) { @@ -5639,6 +5679,10 @@ void PlateData::parse_filament_info(GCodeProcessorResult *result) << FILAMENT_USED_M_TAG << "=\"" << it->used_m << "\" " << FILAMENT_USED_G_TAG << "=\"" << it->used_g << "\" />\n"; } + + for (auto it = plate_data->warnings.begin(); it != plate_data->warnings.end(); it++) { + stream << " <" << SLICE_WARNING_TAG << " " << "msg=\"" << it->msg << "\" " << "level=\"" << std::to_string(it->level) << "\" />\n"; + } stream << " \n"; } } diff --git a/src/libslic3r/Format/bbs_3mf.hpp b/src/libslic3r/Format/bbs_3mf.hpp index 2feb1c6472..f8bb926512 100644 --- a/src/libslic3r/Format/bbs_3mf.hpp +++ b/src/libslic3r/Format/bbs_3mf.hpp @@ -70,6 +70,8 @@ struct PlateData bool is_sliced_valid = false; bool toolpath_outside {false}; + std::vector warnings; + std::string get_gcode_prediction_str() { return gcode_prediction; } diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index 0f250fbbb8..a3295aa421 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -4106,7 +4106,7 @@ int PartPlateList::load_from_3mf_structure(PlateDataPtrs& plate_data_list) ps.total_used_filament *= 1000; //koef gcode_result->toolpath_outside = plate_data_list[i]->toolpath_outside; m_plate_list[index]->slice_filaments_info = plate_data_list[i]->slice_filaments_info; - + gcode_result->warnings = plate_data_list[i]->warnings; if (!plate_data_list[i]->thumbnail_file.empty()) { if (boost::filesystem::exists(plate_data_list[i]->thumbnail_file)) { m_plate_list[index]->load_thumbnail_data(plate_data_list[i]->thumbnail_file);