Fix missing filament profiles in Filament Selection dialog (#14398)

* Resolve preset type based on nozle diameter if printer_variant is empty

* Fix incorectly resolving plastic type (PLA, ABS, etc.)

* Revert default print-variant handling as it can be not only nozzle diameter

---------

Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
ExPikaPaka
2026-06-26 12:37:33 +02:00
committed by GitHub
parent a1a9a0ce2b
commit df95a30a0f

View File

@@ -1037,50 +1037,48 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList,
//GetStardardFilePath(filepath); //GetStardardFilePath(filepath);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " GetFilamentInfo:VendorDirectory - " << VendorDirectory << ", Filepath - "<<filepath; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " GetFilamentInfo:VendorDirectory - " << VendorDirectory << ", Filepath - "<<filepath;
// Resolve this file's own vendor/type into LOCAL variables, independent of
// whatever the caller already accumulated. The cache entry for `filepath`
// must reflect only this file's own inherits chain — passing the caller's
// in/out sVendor/sType down would poison a shared base file's cache with the
// type of whichever descendant happened to traverse it first (e.g. an ABS
// preset reaching fdm_filament_common before a PLA one, making every PLA that
// later reuses the cached base resolve to "ABS"). Merge into the caller's
// out-params only at the end, filling empties.
std::string vendor;
std::string type;
int status = 0;
const auto cache_it = filament_info_cache.find(filepath); const auto cache_it = filament_info_cache.find(filepath);
if (cache_it != filament_info_cache.end()) { if (cache_it != filament_info_cache.end()) {
if (sVendor.empty()) { vendor = cache_it->second.vendor;
sVendor = cache_it->second.vendor; type = cache_it->second.type;
} status = cache_it->second.status;
if (sType.empty()) { } else {
sType = cache_it->second.type;
}
return cache_it->second.status;
}
try { try {
std::string contents; std::string contents;
LoadFile(filepath, contents); LoadFile(filepath, contents);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Json Contents: " << contents; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": Json Contents: " << contents;
json jLocal = json::parse(contents); json jLocal = json::parse(contents);
if (sVendor == "") {
if (jLocal.contains("filament_vendor")) if (jLocal.contains("filament_vendor"))
sVendor = jLocal["filament_vendor"][0]; vendor = jLocal["filament_vendor"][0];
else { else
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains filament_vendor"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains filament_vendor";
}
}
if (sType == "") {
if (jLocal.contains("filament_type")) if (jLocal.contains("filament_type"))
sType = jLocal["filament_type"][0]; type = jLocal["filament_type"][0];
else { else
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains filament_type"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains filament_type";
}
}
if (sVendor == "" || sType == "") if (vendor == "" || type == "") {
{
if (jLocal.contains("inherits")) { if (jLocal.contains("inherits")) {
std::string FName = jLocal["inherits"]; std::string FName = jLocal["inherits"];
if (!pFilaList.contains(FName)) { if (!pFilaList.contains(FName)) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "pFilaList - Not Contains inherits filaments: " << FName; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "pFilaList - Not Contains inherits filaments: " << FName;
filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; status = -1;
return -1; } else {
}
std::string FPath = pFilaList[FName]["sub_path"]; std::string FPath = pFilaList[FName]["sub_path"];
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Before Format Inherits Path: VendorDirectory - " << VendorDirectory << ", sub_path - " << FPath; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Before Format Inherits Path: VendorDirectory - " << VendorDirectory << ", sub_path - " << FPath;
wxString strNewFile = wxString::Format("%s%c%s", wxString(VendorDirectory.c_str(), wxConvUTF8), boost::filesystem::path::preferred_separator, FPath); wxString strNewFile = wxString::Format("%s%c%s", wxString(VendorDirectory.c_str(), wxConvUTF8), boost::filesystem::path::preferred_separator, FPath);
@@ -1088,49 +1086,45 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList,
if (!boost::filesystem::exists(inherits_path)) if (!boost::filesystem::exists(inherits_path))
inherits_path = (boost::filesystem::path(m_OrcaFilaLibPath) / boost::filesystem::path(FPath)).make_preferred(); inherits_path = (boost::filesystem::path(m_OrcaFilaLibPath) / boost::filesystem::path(FPath)).make_preferred();
//boost::filesystem::path nf(strNewFile.c_str());
if (boost::filesystem::exists(inherits_path)) { if (boost::filesystem::exists(inherits_path)) {
const int ret = GetFilamentInfo(VendorDirectory,pFilaList, inherits_path.string(), sVendor, sType); // Recurse with this file's own (vendor, type) as the chain accumulator.
filament_info_cache[filepath] = CachedFilamentInfo{ret, sVendor, sType}; status = GetFilamentInfo(VendorDirectory, pFilaList, inherits_path.string(), vendor, type);
return ret;
} else { } else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " inherits File Not Exist: " << inherits_path; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " inherits File Not Exist: " << inherits_path;
filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; status = -1;
return -1; }
} }
} else { } else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains inherits"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << filepath << " - Not Contains inherits";
if (sType == "") { if (type == "") {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "sType is Empty"; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "sType is Empty";
filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; status = -1;
return -1; } else {
} if (vendor == "")
else vendor = "Generic";
sVendor = "Generic"; status = 0;
filament_info_cache[filepath] = CachedFilamentInfo{0, sVendor, sType};
return 0;
} }
} }
else { } else {
filament_info_cache[filepath] = CachedFilamentInfo{0, sVendor, sType}; status = 0;
return 0;
} }
} }
catch (nlohmann::detail::parse_error &err) { catch (nlohmann::detail::parse_error &err) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << filepath << " got a nlohmann::detail::parse_error, reason = " << err.what(); BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << filepath << " got a nlohmann::detail::parse_error, reason = " << err.what();
filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; status = -1;
return -1;
} }
catch (std::exception &e) catch (std::exception &e) {
{
// wxLogMessage("GUIDE: load_profile_error %s ", e.what());
// wxMessageBox(e.what(), "", MB_OK);
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << filepath << " got exception: " << e.what(); BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << filepath << " got exception: " << e.what();
filament_info_cache[filepath] = CachedFilamentInfo{-1, sVendor, sType}; status = -1;
return -1;
} }
return 0; filament_info_cache[filepath] = CachedFilamentInfo{status, vendor, type};
}
// Merge this file's resolved values into the caller's out-params (fill empties only).
if (sVendor.empty()) sVendor = vendor;
if (sType.empty()) sType = type;
return status;
} }
int GuideFrame::LoadProfileData() int GuideFrame::LoadProfileData()