ENH: Support Child Folder of Filaments in Profiles

Change-Id: Id89281d76efe42e7e8c407cce337fee1485e2cf0
(cherry picked from commit 634159a3ce43f3aaf9223b412e993d3355cb1682)
This commit is contained in:
zorro.zhang 2022-10-20 15:25:12 +08:00 committed by Lane.Wei
parent 047e5c2e90
commit e4fa6d8652
2 changed files with 21 additions and 14 deletions

View file

@ -859,7 +859,7 @@ bool GuideFrame::run()
} }
} }
int GuideFrame::GetFilamentInfo(std::string filepath, std::string &sVendor, std::string &sType) int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList, std::string filepath, std::string &sVendor, std::string &sType)
{ {
//GetStardardFilePath(filepath); //GetStardardFilePath(filepath);
@ -881,21 +881,18 @@ int GuideFrame::GetFilamentInfo(std::string filepath, std::string &sVendor, std:
if (sVendor == "" || sType == "") if (sVendor == "" || sType == "")
{ {
if (jLocal.contains("inherits")) { if (jLocal.contains("inherits")) {
boost::filesystem::path sf(filepath.c_str());
filepath = sf.string();
std::string strFile = filepath;
//wxString strFolder = strFile.BeforeLast(boost::filesystem::path::preferred_separator);
boost::filesystem::path file_path(filepath);
std::string FName = jLocal["inherits"]; std::string FName = jLocal["inherits"];
FName += ".json";
//wxString strNewFile = wxString::Format("%s%c%s.json", strFolder.mb_str(), boost::filesystem::path::preferred_separator, FName.c_str()); if (!pFilaList.contains(FName))
boost::filesystem::path inherits_path = boost::filesystem::absolute(file_path.parent_path() / FName).make_preferred(); return -1;
std::string FPath = pFilaList[FName]["sub_path"];
wxString strNewFile = wxString::Format("%s%c%s", VendorDirectory, boost::filesystem::path::preferred_separator, FPath);
boost::filesystem::path inherits_path = boost::filesystem::absolute(w2s(strNewFile)).make_preferred();
//boost::filesystem::path nf(strNewFile.c_str()); //boost::filesystem::path nf(strNewFile.c_str());
if (boost::filesystem::exists(inherits_path)) if (boost::filesystem::exists(inherits_path))
return GetFilamentInfo(inherits_path.string(), sVendor, sType); return GetFilamentInfo(VendorDirectory,pFilaList, inherits_path.string(), sVendor, sType);
else else
return -1; return -1;
} else { } else {
@ -1379,8 +1376,18 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
// BBS:Filament // BBS:Filament
json pFilament = jLocal["filament_list"]; json pFilament = jLocal["filament_list"];
json tFilaList = json::object();
nsize = pFilament.size(); nsize = pFilament.size();
for (int n = 0; n < nsize; n++) {
json OneFF = pFilament.at(n);
std::string s1 = OneFF["name"];
std::string s2 = OneFF["sub_path"];
tFilaList[s1] = OneFF;
}
int nFalse = 0; int nFalse = 0;
int nModel = 0; int nModel = 0;
int nFinish = 0; int nFinish = 0;
@ -1403,7 +1410,7 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
std::string sV; std::string sV;
std::string sT; std::string sT;
int nRet = GetFilamentInfo(sub_file, sV, sT); int nRet = GetFilamentInfo(vendor_dir.string(),tFilaList, sub_file, sV, sT);
if (nRet != 0) continue; if (nRet != 0) continue;
OneFF["vendor"] = sV; OneFF["vendor"] = sV;

View file

@ -76,7 +76,7 @@ public:
int LoadProfile(); int LoadProfile();
int LoadProfileFamily(std::string strVendor, std::string strFilePath); int LoadProfileFamily(std::string strVendor, std::string strFilePath);
int SaveProfile(); int SaveProfile();
int GetFilamentInfo(std::string filepath, std::string &sVendor, std::string &sType); int GetFilamentInfo( std::string VendorDirectory,json & pFilaList, std::string filepath, std::string &sVendor, std::string &sType);
bool apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater, bool& apply_keeped_changes); bool apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater, bool& apply_keeped_changes);