diff --git a/resources/info/filament_info.json b/resources/info/filament_info.json new file mode 100644 index 000000000..673e1a89a --- /dev/null +++ b/resources/info/filament_info.json @@ -0,0 +1,27 @@ +{ + "version": "1.0.0.1", + "high_temp_filament": [ + "ABS", + "ASA", + "PC", + "PA", + "PA-CF", + "PA6-CF", + "PET-CF", + "PPS", + "PPS-CF", + "PPA-CF", + "PPA-GF" + ], + "low_temp_filament": [ + "PLA", + "TPU", + "PLA-CF", + "PLA-AERO", + "PVA" + ], + "high_low_compatible_filament":[ + "HIPS", + "PETG" + ] +} \ No newline at end of file diff --git a/resources/info/nozzle_info.json b/resources/info/nozzle_info.json new file mode 100644 index 000000000..e5e6631c0 --- /dev/null +++ b/resources/info/nozzle_info.json @@ -0,0 +1,9 @@ +{ + "version": "1.0.0.1", + "nozzle_hrc": { + "hardened_steel": 55, + "stainless_steel": 20, + "brass": 2, + "undefine": 0 + } +} \ No newline at end of file diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index b84e9aacf..9ef2f1dc3 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -64,12 +64,6 @@ const std::vector GCodeProcessor::Reserved_Tags = { const std::string GCodeProcessor::Flush_Start_Tag = " FLUSH_START"; const std::string GCodeProcessor::Flush_End_Tag = " FLUSH_END"; -const std::map GCodeProcessor::Nozzle_Type_To_HRC={ - {NozzleType::ntStainlessSteel,20}, - {NozzleType::ntHardenedSteel,55}, - {NozzleType::ntBrass,2}, - {NozzleType::ntUndefine,0} -}; const float GCodeProcessor::Wipe_Width = 0.05f; const float GCodeProcessor::Wipe_Height = 0.05f; @@ -4315,7 +4309,7 @@ void GCodeProcessor::update_slice_warnings() warning.params.clear(); warning.level=1; - int nozzle_hrc = Nozzle_Type_To_HRC.find(m_result.nozzle_type)->second; + int nozzle_hrc = Print::get_hrc_by_nozzle_type(m_result.nozzle_type); if (nozzle_hrc!=0) { for (size_t i = 0; i < used_extruders.size(); i++) { int HRC=0; diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index 300276739..e8245129a 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -240,7 +240,6 @@ namespace Slic3r { static const std::vector Reserved_Tags; static const std::string Flush_Start_Tag; static const std::string Flush_End_Tag; - static const std::mapNozzle_Type_To_HRC; public: enum class ETags : unsigned char { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 3aecb5d2f..5a622cf74 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -899,30 +899,15 @@ static StringObjectException layered_print_cleareance_valid(const Print &print, bool Print::check_multi_filaments_compatibility(const std::vector& filament_types) { - static std::map filament_is_high_temp{ - {"PLA", false}, - {"PLA-CF", false}, - //{"PETG", true}, - {"ABS", true}, - {"TPU", false}, - {"PA", true}, - {"PA-CF", true}, - {"PET-CF", true}, - {"PC", true}, - {"ASA", true}, - {"HIPS", true} - }; - bool has_high_temperature_filament = false; bool has_low_temperature_filament = false; - for (const auto& type : filament_types) - if (filament_is_high_temp.find(type) != filament_is_high_temp.end()) { - if (filament_is_high_temp[type]) - has_high_temperature_filament = true; - else - has_low_temperature_filament = true; - } + for (const auto& type : filament_types) { + if (get_filament_temp_type(type) ==FilamentTempType::HighTemp) + has_high_temperature_filament = true; + else if (get_filament_temp_type(type) == FilamentTempType::LowTemp) + has_low_temperature_filament = true; + } if (has_high_temperature_filament && has_low_temperature_filament) return false; @@ -2087,6 +2072,76 @@ Vec2d Print::translate_to_print_space(const Point& point) const { return Vec2d(unscaled(point.x()) - m_origin(0), unscaled(point.y()) - m_origin(1)); } +FilamentTempType Print::get_filament_temp_type(const std::string& filament_type) +{ + const static std::string HighTempFilamentStr = "high_temp_filament"; + const static std::string LowTempFilamentStr = "low_temp_filament"; + const static std::string HighLowCompatibleFilamentStr = "high_low_compatible_filament"; + static std::unordered_map>filament_temp_type_map; + + if (filament_temp_type_map.empty()) { + fs::path file_path = fs::path(resources_dir()) / "info" / "filament_info.json"; + std::ifstream in(file_path.string()); + json j; + try{ + j = json::parse(in); + in.close(); + auto&&high_temp_filament_arr =j[HighTempFilamentStr].get < std::vector>(); + filament_temp_type_map[HighTempFilamentStr] = std::unordered_set(high_temp_filament_arr.begin(), high_temp_filament_arr.end()); + auto&& low_temp_filament_arr = j[LowTempFilamentStr].get < std::vector>(); + filament_temp_type_map[LowTempFilamentStr] = std::unordered_set(low_temp_filament_arr.begin(), low_temp_filament_arr.end()); + auto&& high_low_compatible_filament_arr = j[HighLowCompatibleFilamentStr].get < std::vector>(); + filament_temp_type_map[HighLowCompatibleFilamentStr] = std::unordered_set(high_low_compatible_filament_arr.begin(), high_low_compatible_filament_arr.end()); + } + catch (const json::parse_error& err){ + in.close(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << file_path.string() << " got a nlohmann::detail::parse_error, reason = " << err.what(); + filament_temp_type_map[HighTempFilamentStr] = {"ABS","ASA","PC","PA","PA-CF","PA6-CF","PET-CF","PPS","PPS-CF","PPA-GF","PPA-CF"}; + filament_temp_type_map[LowTempFilamentStr] = {"PLA","TPU","PLA-CF","PLA-AERO","PVA"}; + filament_temp_type_map[HighLowCompatibleFilamentStr] = { "HIPS","PETG" }; + } + } + + if (filament_temp_type_map[HighLowCompatibleFilamentStr].find(filament_type) != filament_temp_type_map[HighLowCompatibleFilamentStr].end()) + return HighLowCompatible; + if (filament_temp_type_map[HighTempFilamentStr].find(filament_type) != filament_temp_type_map[HighTempFilamentStr].end()) + return HighTemp; + if (filament_temp_type_map[LowTempFilamentStr].find(filament_type) != filament_temp_type_map[LowTempFilamentStr].end()) + return LowTemp; + return Undefine; +} + +int Print::get_hrc_by_nozzle_type(const NozzleType&type) +{ + static std::mapnozzle_type_to_hrc; + if (nozzle_type_to_hrc.empty()) { + fs::path file_path = fs::path(resources_dir()) / "info" / "nozzle_info.json"; + std::ifstream in(file_path.string()); + json j; + try { + j = json::parse(in); + in.close(); + for (const auto& elem : j["nozzle_hrc"].items()) + nozzle_type_to_hrc[elem.key()] = elem.value(); + } + catch (const json::parse_error& err) { + in.close(); + BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << file_path.string() << " got a nlohmann::detail::parse_error, reason = " << err.what(); + nozzle_type_to_hrc = { + {"hardened_steel",55}, + {"stainless_steel",20}, + {"brass",2}, + {"undefine",0} + }; + } + } + auto iter = nozzle_type_to_hrc.find(NozzleTypeEumnToStr[type]); + if (iter != nozzle_type_to_hrc.end()) + return iter->second; + //0 represents undefine + return 0; +} + void Print::finalize_first_layer_convex_hull() { append(m_first_layer_convex_hull.points, m_skirt_convex_hull); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 5a98909be..d84830726 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -672,6 +672,12 @@ class ConstPrintRegionPtrsAdaptor : public ConstVectorOfPtrsAdaptor }; */ +enum FilamentTempType { + HighTemp=0, + LowTemp, + HighLowCompatible, + Undefine +}; // The complete print tray with possibly multiple objects. class Print : public PrintBaseWithState { @@ -819,7 +825,8 @@ public: Vec2d translate_to_print_space(const Vec2d& point) const; // scaled point Vec2d translate_to_print_space(const Point& point) const; - + static FilamentTempType get_filament_temp_type(const std::string& filament_type); + static int get_hrc_by_nozzle_type(const NozzleType& type); static bool check_multi_filaments_compatibility(const std::vector& filament_types); protected: diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 74da46ce9..a97f2bbfb 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -210,6 +210,13 @@ enum NozzleType { ntCount }; +static std::unordered_mapNozzleTypeEumnToStr = { + {NozzleType::ntUndefine, "undefine"}, + {NozzleType::ntHardenedSteel, "hardened_steel"}, + {NozzleType::ntStainlessSteel, "stainless_steel"}, + {NozzleType::ntBrass, "brass"} +}; + // BBS enum PrinterStructure { psUndefine=0,