From bdab8a28c9c52fe7154e7feceb54e9c638881ba4 Mon Sep 17 00:00:00 2001 From: Stone Li Date: Wed, 16 Nov 2022 10:15:04 +0800 Subject: [PATCH] ENH: add filament alias to a print warning Change-Id: Ie7a2e0cbdd016c2120c46cde9a92a93baffbe832 Signed-off-by: Stone Li --- src/libslic3r/Print.cpp | 12 +++++++++--- src/libslic3r/PrintBase.hpp | 8 ++++++++ src/slic3r/GUI/Plater.cpp | 27 +++++++++++++++++++++++++++ src/slic3r/GUI/Plater.hpp | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index b7a039cec..ebce88426 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -1098,9 +1098,15 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons* break; } } - - return { format(L("Plate %d: %s does not support filament %s.\n"), this->get_plate_index() + 1, - L(bed_type_name), extruder_id + 1) }; + + StringObjectException except; + except.string = format(L("Plate %d: %s does not support filament %s\n"), this->get_plate_index() + 1, L(bed_type_name), extruder_id + 1); + except.type = STRING_EXCEPT_FILAMENT_NOT_MATCH_BED_TYPE; + except.params.push_back(std::to_string(this->get_plate_index() + 1)); + except.params.push_back(L(bed_type_name)); + except.params.push_back(std::to_string(extruder_id+1)); + except.object = nullptr; + return except; } } } diff --git a/src/libslic3r/PrintBase.hpp b/src/libslic3r/PrintBase.hpp index c6ecf4ebe..d31cb803a 100644 --- a/src/libslic3r/PrintBase.hpp +++ b/src/libslic3r/PrintBase.hpp @@ -16,12 +16,20 @@ namespace Slic3r { +enum StringExceptionType { + STRING_EXCEPT_NOT_DEFINED = 0, + STRING_EXCEPT_FILAMENT_NOT_MATCH_BED_TYPE = 1, + STRING_EXCEPT_COUNT +}; + // BBS: error with object struct StringObjectException { std::string string; ObjectBase const *object = nullptr; std::string opt_key; + StringExceptionType type; // warning type for tips + std::vector params; // warning params for tips }; class CanceledException : public std::exception diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 821c7d091..6be48c5d8 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4103,6 +4103,8 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool Polygons polygons; std::vector> height_polygons; StringObjectException err = background_process.validate(&warning, &polygons, &height_polygons); + // update string by type + q->post_process_string_object_exception(err); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": validate err=%1%, warning=%2%")%err.string%warning.string; if (err.string.empty()) { @@ -10426,6 +10428,8 @@ void Plater::validate_current_plate(bool& model_fits, bool& validate_error) Polygons polygons; std::vector> height_polygons; StringObjectException err = p->background_process.validate(&warning, &polygons, &height_polygons); + // update string by type + post_process_string_object_exception(err); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": validate err=%1%, warning=%2%, model_fits %3%")%err.string%warning.string %model_fits; if (err.string.empty()) { @@ -10754,6 +10758,29 @@ bool Plater::show_publish_dialog(bool show) return p->show_publish_dlg(show); } +void Plater::post_process_string_object_exception(StringObjectException &err) +{ + if (err.type == StringExceptionType::STRING_EXCEPT_FILAMENT_NOT_MATCH_BED_TYPE) { + try { + int extruder_id = atoi(err.params[2].c_str()) - 1; + if (extruder_id < wxGetApp().preset_bundle->filament_presets.size()) { + std::string filament_name = wxGetApp().preset_bundle->filament_presets[extruder_id]; + for (auto filament : wxGetApp().preset_bundle->filaments) { + if (filament.name == filament_name) { + filament_name = filament.alias; + break; + } + } + err.string = format(L("Plate %d: %s does not support filament %s (%s).\n"), err.params[0], err.params[1], err.params[2], filament_name); + } + } catch (...) { + ; + } + } + + return; +} + #if ENABLE_ENVIRONMENT_MAP void Plater::init_environment_texture() { diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index d4f156aa3..d20f21476 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -22,6 +22,7 @@ #include "Jobs/PrintJob.hpp" #include "Jobs/SendJob.hpp" #include "libslic3r/Model.hpp" +#include "libslic3r/PrintBase.hpp" #define FILAMENT_SYSTEM_COLORS_NUM 16 @@ -504,6 +505,8 @@ public: void show_object_info(); //BBS bool show_publish_dialog(bool show = true); + //BBS: post process string object exception strings by warning types + void post_process_string_object_exception(StringObjectException &err); #if ENABLE_ENVIRONMENT_MAP void init_environment_texture();