ENH: filament just show bundle machine

Change-Id: If0a35037dc4b08df7cd3aaf88662638a334196e3
(cherry picked from commit 5ebd67880a679c3013fe10b63b509761eab30670)
This commit is contained in:
zorro.zhang 2022-08-10 17:25:53 +08:00 committed by Lane.Wei
parent 6e1e56be18
commit 2ac9267e42
4 changed files with 683 additions and 602 deletions

View file

@ -854,7 +854,7 @@ int GuideFrame::LoadProfile()
//BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", will load config from %1%.") % bbl_bundle_path;
m_ProfileJson = json::parse("{}");
m_ProfileJson["model"] = json::array();
m_ProfileJson["machine"] = json::array();
m_ProfileJson["machine"] = json::object();
m_ProfileJson["filament"] = json::object();
m_ProfileJson["process"] = json::array();
@ -999,27 +999,205 @@ void StringReplace(string &strBase, string strSrc, string strDes)
}
//int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath)
//{
// //wxString strFolder = strFilePath.BeforeLast(boost::filesystem::path::preferred_separator);
// boost::filesystem::path file_path(strFilePath);
// boost::filesystem::path vendor_dir = boost::filesystem::absolute(file_path.parent_path()/ strVendor).make_preferred();
// BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", vendor path %1%.")% vendor_dir.string();
// try {
//
// //wxLogMessage("GUIDE: json_path1 %s", w2s(strFilePath));
//
// std::string contents;
// LoadFile(strFilePath, contents);
// //wxLogMessage("GUIDE: json_path1 content: %s", contents);
// json jLocal=json::parse(contents);
// //wxLogMessage("GUIDE: json_path1 Loaded");
//
// // BBS:models
// json pmodels = jLocal["machine_model_list"];
// int nsize = pmodels.size();
//
// BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% machine models")%nsize;
//
// for (int n = 0; n < nsize; n++) {
// json OneModel = pmodels.at(n);
//
// OneModel["model"] = OneModel["name"];
// OneModel.erase("name");
//
// std::string s1 = OneModel["model"];
// std::string s2 = OneModel["sub_path"];
//
// boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
// std::string sub_file = sub_path.string();
//
// //wxLogMessage("GUIDE: json_path2 %s", w2s(ModelFilePath));
// LoadFile(sub_file, contents);
// //wxLogMessage("GUIDE: json_path2 content: %s", contents);
// json pm=json::parse(contents);
// //wxLogMessage("GUIDE: json_path2 loaded");
//
// OneModel["vendor"] = strVendor;
// std::string NozzleOpt = pm["nozzle_diameter"];
// StringReplace(NozzleOpt, " ", "");
// OneModel["nozzle_diameter"] = NozzleOpt;
// OneModel["materials"] = pm["default_materials"];
//
// //wxString strCoverPath = wxString::Format("%s\\%s\\%s_cover.png", strFolder, strVendor, std::string(s1.mb_str()));
// std::string cover_file = s1+"_cover.png";
// boost::filesystem::path cover_path = boost::filesystem::absolute(vendor_dir / cover_file).make_preferred();
// OneModel["cover"] = cover_path.string();
//
// OneModel["nozzle_selected"] = "";
//
// m_ProfileJson["model"].push_back(OneModel);
// }
//
// // BBS:Machine
// json pmachine = jLocal["machine_list"];
// nsize = pmachine.size();
// BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% machines")%nsize;
// for (int n = 0; n < nsize; n++) {
// json OneMachine = pmachine.at(n);
//
// std::string s1 = OneMachine["name"];
// std::string s2 = OneMachine["sub_path"];
//
// //wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
// boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
// std::string sub_file = sub_path.string();
// LoadFile(sub_file, contents);
// json pm = json::parse(contents);
//
// std::string strInstant = pm["instantiation"];
// if (strInstant.compare("true") == 0) {
// OneMachine["model"] = pm["printer_model"];
//
// m_ProfileJson["machine"].push_back(OneMachine);
// }
// }
//
// // BBS:Filament
// json pFilament = jLocal["filament_list"];
// nsize = pFilament.size();
//
// int nFalse = 0;
// int nModel = 0;
// int nFinish = 0;
// BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% filaments")%nsize;
// for (int n = 0; n < nsize; n++) {
// json OneFF = pFilament.at(n);
//
// std::string s1 = OneFF["name"];
// std::string s2 = OneFF["sub_path"];
//
// if (!m_ProfileJson["filament"].contains(s1))
// {
// //wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
// boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
// std::string sub_file = sub_path.string();
// LoadFile(sub_file, contents);
// json pm = json::parse(contents);
//
// std::string strInstant = pm["instantiation"];
// if (strInstant == "true") {
// std::string sV;
// std::string sT;
//
// int nRet = GetFilamentInfo(sub_file, sV, sT);
// if (nRet != 0) continue;
//
// OneFF["vendor"] = sV;
// OneFF["type"] = sT;
//
// OneFF["models"] = "";
// OneFF["selected"] = 0;
// }
// else
// continue;
//
// } else {
// OneFF = m_ProfileJson["filament"][s1];
// }
//
// std::string vModel = "";
// int nm = m_ProfileJson["model"].size();
// int bFind = 0;
// for (int m = 0; m < nm; m++) {
// std::string strFF = m_ProfileJson["model"][m]["materials"];
// strFF = (boost::format(";%1%;")%strFF).str();
// std::string strTT = (boost::format(";%1%;")%s1).str();
// if (strFF.find(strTT) != std::string::npos) {
// std::string sModel = m_ProfileJson["model"][m]["model"];
//
// vModel = (boost::format("%1%[%2%]")%vModel %sModel).str();
// bFind = 1;
// }
// }
//
// OneFF["models"] = vModel;
//
// m_ProfileJson["filament"][s1] = OneFF;
// }
//
// //process
// json pProcess = jLocal["process_list"];
// nsize = pProcess.size();
// BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% processes")%nsize;
// for (int n = 0; n < nsize; n++) {
// json OneProcess = pProcess.at(n);
//
// std::string s2 = OneProcess["sub_path"];
// //wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
// boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
// std::string sub_file = sub_path.string();
// LoadFile(sub_file, contents);
// json pm = json::parse(contents);
//
// std::string bInstall = pm["instantiation"];
// if (bInstall == "true")
// {
// m_ProfileJson["process"].push_back(OneProcess);
// }
// }
//
// }
// catch(nlohmann::detail::parse_error &err) {
// BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<<strFilePath <<" got a nlohmann::detail::parse_error, reason = " << err.what();
// return -1;
// }
// catch (std::exception &e) {
// // wxMessageBox(e.what(), "", MB_OK);
// //wxLogMessage("GUIDE: LoadFamily Error: %s", e.what());
// BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << strFilePath << " got exception: " << e.what();
// return -1;
// }
//
// return 0;
//}
int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath)
{
//wxString strFolder = strFilePath.BeforeLast(boost::filesystem::path::preferred_separator);
// wxString strFolder = strFilePath.BeforeLast(boost::filesystem::path::preferred_separator);
boost::filesystem::path file_path(strFilePath);
boost::filesystem::path vendor_dir = boost::filesystem::absolute(file_path.parent_path()/ strVendor).make_preferred();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", vendor path %1%.")% vendor_dir.string();
boost::filesystem::path vendor_dir = boost::filesystem::absolute(file_path.parent_path() / strVendor).make_preferred();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", vendor path %1%.") % vendor_dir.string();
try {
//wxLogMessage("GUIDE: json_path1 %s", w2s(strFilePath));
// wxLogMessage("GUIDE: json_path1 %s", w2s(strFilePath));
std::string contents;
LoadFile(strFilePath, contents);
//wxLogMessage("GUIDE: json_path1 content: %s", contents);
json jLocal=json::parse(contents);
//wxLogMessage("GUIDE: json_path1 Loaded");
// wxLogMessage("GUIDE: json_path1 content: %s", contents);
json jLocal = json::parse(contents);
// wxLogMessage("GUIDE: json_path1 Loaded");
// BBS:models
json pmodels = jLocal["machine_model_list"];
int nsize = pmodels.size();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% machine models")%nsize;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% machine models") % nsize;
for (int n = 0; n < nsize; n++) {
json OneModel = pmodels.at(n);
@ -1031,24 +1209,24 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
std::string s2 = OneModel["sub_path"];
boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
std::string sub_file = sub_path.string();
std::string sub_file = sub_path.string();
//wxLogMessage("GUIDE: json_path2 %s", w2s(ModelFilePath));
// wxLogMessage("GUIDE: json_path2 %s", w2s(ModelFilePath));
LoadFile(sub_file, contents);
//wxLogMessage("GUIDE: json_path2 content: %s", contents);
json pm=json::parse(contents);
//wxLogMessage("GUIDE: json_path2 loaded");
// wxLogMessage("GUIDE: json_path2 content: %s", contents);
json pm = json::parse(contents);
// wxLogMessage("GUIDE: json_path2 loaded");
OneModel["vendor"] = strVendor;
OneModel["vendor"] = strVendor;
std::string NozzleOpt = pm["nozzle_diameter"];
StringReplace(NozzleOpt, " ", "");
OneModel["nozzle_diameter"] = NozzleOpt;
OneModel["materials"] = pm["default_materials"];
//wxString strCoverPath = wxString::Format("%s\\%s\\%s_cover.png", strFolder, strVendor, std::string(s1.mb_str()));
std::string cover_file = s1+"_cover.png";
// wxString strCoverPath = wxString::Format("%s\\%s\\%s_cover.png", strFolder, strVendor, std::string(s1.mb_str()));
std::string cover_file = s1 + "_cover.png";
boost::filesystem::path cover_path = boost::filesystem::absolute(vendor_dir / cover_file).make_preferred();
OneModel["cover"] = cover_path.string();
OneModel["cover"] = cover_path.string();
OneModel["nozzle_selected"] = "";
@ -1058,24 +1236,25 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
// BBS:Machine
json pmachine = jLocal["machine_list"];
nsize = pmachine.size();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% machines")%nsize;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% machines") % nsize;
for (int n = 0; n < nsize; n++) {
json OneMachine = pmachine.at(n);
std::string s1 = OneMachine["name"];
std::string s2 = OneMachine["sub_path"];
//wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
// wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
std::string sub_file = sub_path.string();
std::string sub_file = sub_path.string();
LoadFile(sub_file, contents);
json pm = json::parse(contents);
std::string strInstant = pm["instantiation"];
if (strInstant.compare("true") == 0) {
OneMachine["model"] = pm["printer_model"];
OneMachine["nozzle"] = pm["nozzle_diameter"][0];
m_ProfileJson["machine"].push_back(OneMachine);
m_ProfileJson["machine"][s1]=OneMachine;
}
}
@ -1083,21 +1262,20 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
json pFilament = jLocal["filament_list"];
nsize = pFilament.size();
int nFalse = 0;
int nModel = 0;
int nFalse = 0;
int nModel = 0;
int nFinish = 0;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% filaments")%nsize;
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% filaments") % nsize;
for (int n = 0; n < nsize; n++) {
json OneFF = pFilament.at(n);
std::string s1 = OneFF["name"];
std::string s2 = OneFF["sub_path"];
if (!m_ProfileJson["filament"].contains(s1))
{
//wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
if (!m_ProfileJson["filament"].contains(s1)) {
// wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
std::string sub_file = sub_path.string();
std::string sub_file = sub_path.string();
LoadFile(sub_file, contents);
json pm = json::parse(contents);
@ -1110,67 +1288,60 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
if (nRet != 0) continue;
OneFF["vendor"] = sV;
OneFF["type"] = sT;
OneFF["type"] = sT;
OneFF["models"] = "";
OneFF["models"] = "";
json pPrinters = pm["compatible_printers"];
int nPrinter = pPrinters.size();
std::string ModelList = "";
for (int i = 0; i < nPrinter; i++)
{
std::string sP = pPrinters.at(i);
if (m_ProfileJson["machine"].contains(sP))
{
std::string mModel = m_ProfileJson["machine"][sP]["model"];
std::string mNozzle = m_ProfileJson["machine"][sP]["nozzle"];
std::string NewModel = mModel + "++" + mNozzle;
ModelList = (boost::format("%1%[%2%]") % ModelList % NewModel).str();
}
}
OneFF["models"] = ModelList;
OneFF["selected"] = 0;
}
else
m_ProfileJson["filament"][s1] = OneFF;
} else
continue;
} else {
OneFF = m_ProfileJson["filament"][s1];
}
std::string vModel = "";
int nm = m_ProfileJson["model"].size();
int bFind = 0;
for (int m = 0; m < nm; m++) {
std::string strFF = m_ProfileJson["model"][m]["materials"];
strFF = (boost::format(";%1%;")%strFF).str();
std::string strTT = (boost::format(";%1%;")%s1).str();
if (strFF.find(strTT) != std::string::npos) {
std::string sModel = m_ProfileJson["model"][m]["model"];
vModel = (boost::format("%1%[%2%]")%vModel %sModel).str();
bFind = 1;
}
}
OneFF["models"] = vModel;
m_ProfileJson["filament"][s1] = OneFF;
}
//process
// process
json pProcess = jLocal["process_list"];
nsize = pProcess.size();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% processes")%nsize;
nsize = pProcess.size();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got %1% processes") % nsize;
for (int n = 0; n < nsize; n++) {
json OneProcess = pProcess.at(n);
std::string s2 = OneProcess["sub_path"];
//wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
std::string s2 = OneProcess["sub_path"];
// wxString ModelFilePath = wxString::Format("%s\\%s\\%s", strFolder, strVendor, s2);
boost::filesystem::path sub_path = boost::filesystem::absolute(vendor_dir / s2).make_preferred();
std::string sub_file = sub_path.string();
std::string sub_file = sub_path.string();
LoadFile(sub_file, contents);
json pm = json::parse(contents);
std::string bInstall = pm["instantiation"];
if (bInstall == "true")
{
m_ProfileJson["process"].push_back(OneProcess);
}
if (bInstall == "true") { m_ProfileJson["process"].push_back(OneProcess); }
}
}
catch(nlohmann::detail::parse_error &err) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__<< ": parse "<<strFilePath <<" got a nlohmann::detail::parse_error, reason = " << err.what();
} catch (nlohmann::detail::parse_error &err) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << strFilePath << " got a nlohmann::detail::parse_error, reason = " << err.what();
return -1;
}
catch (std::exception &e) {
} catch (std::exception &e) {
// wxMessageBox(e.what(), "", MB_OK);
//wxLogMessage("GUIDE: LoadFamily Error: %s", e.what());
// wxLogMessage("GUIDE: LoadFamily Error: %s", e.what());
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": parse " << strFilePath << " got exception: " << e.what();
return -1;
}
@ -1178,6 +1349,7 @@ int GuideFrame::LoadProfileFamily(std::string strVendor, std::string strFilePath
return 0;
}
void GuideFrame::StrReplace(std::string &strBase, std::string strSrc, std::string strDes)
{
int pos = 0;