ENH: use json to store filament & nozzle info
1.Use json to store nozzle hrc 2.Use json to store filament temp type jira: STUDIO-3488 Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I8eb226e26352a41418f4e46d8cda403dc22ecff4 (cherry picked from commit 62a71d5b1947474d3d86be9015551c1007c89702)
This commit is contained in:
parent
9ce3487b20
commit
96abc3209a
7 changed files with 128 additions and 30 deletions
27
resources/info/filament_info.json
Normal file
27
resources/info/filament_info.json
Normal file
|
@ -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"
|
||||
]
|
||||
}
|
9
resources/info/nozzle_info.json
Normal file
9
resources/info/nozzle_info.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"version": "1.0.0.1",
|
||||
"nozzle_hrc": {
|
||||
"hardened_steel": 55,
|
||||
"stainless_steel": 20,
|
||||
"brass": 2,
|
||||
"undefine": 0
|
||||
}
|
||||
}
|
|
@ -64,12 +64,6 @@ const std::vector<std::string> GCodeProcessor::Reserved_Tags = {
|
|||
const std::string GCodeProcessor::Flush_Start_Tag = " FLUSH_START";
|
||||
const std::string GCodeProcessor::Flush_End_Tag = " FLUSH_END";
|
||||
|
||||
const std::map<NozzleType,int> 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;
|
||||
|
|
|
@ -242,7 +242,6 @@ namespace Slic3r {
|
|||
static const std::vector<std::string> Reserved_Tags;
|
||||
static const std::string Flush_Start_Tag;
|
||||
static const std::string Flush_End_Tag;
|
||||
static const std::map<NozzleType, int>Nozzle_Type_To_HRC;
|
||||
public:
|
||||
enum class ETags : unsigned char
|
||||
{
|
||||
|
|
|
@ -899,30 +899,15 @@ static StringObjectException layered_print_cleareance_valid(const Print &print,
|
|||
|
||||
bool Print::check_multi_filaments_compatibility(const std::vector<std::string>& filament_types)
|
||||
{
|
||||
static std::map<std::string, bool> 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;
|
||||
|
@ -2140,6 +2125,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<std::string, std::unordered_set<std::string>>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<std::string>>();
|
||||
filament_temp_type_map[HighTempFilamentStr] = std::unordered_set<std::string>(high_temp_filament_arr.begin(), high_temp_filament_arr.end());
|
||||
auto&& low_temp_filament_arr = j[LowTempFilamentStr].get < std::vector<std::string>>();
|
||||
filament_temp_type_map[LowTempFilamentStr] = std::unordered_set<std::string>(low_temp_filament_arr.begin(), low_temp_filament_arr.end());
|
||||
auto&& high_low_compatible_filament_arr = j[HighLowCompatibleFilamentStr].get < std::vector<std::string>>();
|
||||
filament_temp_type_map[HighLowCompatibleFilamentStr] = std::unordered_set<std::string>(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::map<std::string, int>nozzle_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);
|
||||
|
|
|
@ -672,6 +672,12 @@ class ConstPrintRegionPtrsAdaptor : public ConstVectorOfPtrsAdaptor<PrintRegion>
|
|||
};
|
||||
*/
|
||||
|
||||
enum FilamentTempType {
|
||||
HighTemp=0,
|
||||
LowTemp,
|
||||
HighLowCompatible,
|
||||
Undefine
|
||||
};
|
||||
// The complete print tray with possibly multiple objects.
|
||||
class Print : public PrintBaseWithState<PrintStep, psCount>
|
||||
{
|
||||
|
@ -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<std::string>& filament_types);
|
||||
// similar to check_multi_filaments_compatibility, but the input is int, and may be negative (means unset)
|
||||
static bool is_filaments_compatible(const std::vector<int>& types);
|
||||
|
|
|
@ -210,6 +210,13 @@ enum NozzleType {
|
|||
ntCount
|
||||
};
|
||||
|
||||
static std::unordered_map<NozzleType, std::string>NozzleTypeEumnToStr = {
|
||||
{NozzleType::ntUndefine, "undefine"},
|
||||
{NozzleType::ntHardenedSteel, "hardened_steel"},
|
||||
{NozzleType::ntStainlessSteel, "stainless_steel"},
|
||||
{NozzleType::ntBrass, "brass"}
|
||||
};
|
||||
|
||||
// BBS
|
||||
enum PrinterStructure {
|
||||
psUndefine=0,
|
||||
|
|
Loading…
Reference in a new issue