mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-23 14:44:19 -06:00
Allow each vendor's filament profile inherit from OrcaFilamentLibrary and many many fixes...
This commit is contained in:
parent
206c6228a5
commit
d1bc4e1e9f
67 changed files with 350 additions and 2716 deletions
|
@ -580,13 +580,6 @@ void GuideFrame::OnError(wxWebViewEvent &evt)
|
|||
|
||||
void GuideFrame::OnScriptResponseMessage(wxCommandEvent &WXUNUSED(evt))
|
||||
{
|
||||
// if (!m_response_js.empty())
|
||||
//{
|
||||
// RunScript(m_response_js);
|
||||
//}
|
||||
|
||||
// RunScript("This is a message to Web!");
|
||||
// RunScript("postMessage(\"AABBCCDD\");");
|
||||
}
|
||||
|
||||
bool GuideFrame::IsFirstUse()
|
||||
|
@ -602,24 +595,6 @@ bool GuideFrame::IsFirstUse()
|
|||
return true;
|
||||
}
|
||||
|
||||
/*int GuideFrame::CopyDir(const boost::filesystem::path &from_dir, const boost::filesystem::path &to_dir)
|
||||
{
|
||||
if (!boost::filesystem::is_directory(from_dir)) return -1;
|
||||
// i assume to_dir.parent surely exists
|
||||
if (!boost::filesystem::is_directory(to_dir)) boost::filesystem::create_directory(to_dir);
|
||||
for (auto &dir_entry : boost::filesystem::directory_iterator(from_dir)) {
|
||||
if (!boost::filesystem::is_directory(dir_entry.path())) {
|
||||
std::string em;
|
||||
CopyFileResult cfr = copy_file(dir_entry.path().string(), (to_dir / dir_entry.path().filename()).string(), em, false);
|
||||
if (cfr != SUCCESS) { BOOST_LOG_TRIVIAL(error) << "Error when copying files from " << from_dir << " to " << to_dir << ": " << em; }
|
||||
} else {
|
||||
CopyDir(dir_entry.path(), to_dir / dir_entry.path().filename());
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
int GuideFrame::SaveProfile()
|
||||
{
|
||||
// SoftFever: don't collect info
|
||||
|
@ -637,77 +612,6 @@ int GuideFrame::SaveProfile()
|
|||
|
||||
m_MainPtr->app_config->save();
|
||||
|
||||
//Load BBS Conf
|
||||
/*wxString strConfPath = wxGetApp().app_config->config_path();
|
||||
json jCfg;
|
||||
std::ifstream(w2s(strConfPath)) >> jCfg;
|
||||
|
||||
//model
|
||||
jCfg["models"] = json::array();
|
||||
int nM = m_ProfileJson["model"].size();
|
||||
int nModelChoose = 0;
|
||||
for (int m = 0; m < nM; m++)
|
||||
{
|
||||
json amodel = m_ProfileJson["model"][m];
|
||||
|
||||
amodel["nozzle_diameter"] = amodel["nozzle_selected"];
|
||||
amodel.erase("nozzle_selected");
|
||||
amodel.erase("preview");
|
||||
amodel.erase("sub_path");
|
||||
amodel.erase("cover");
|
||||
amodel.erase("materials");
|
||||
|
||||
std::string ss = amodel["nozzle_diameter"];
|
||||
if (ss.compare("") != 0) {
|
||||
nModelChoose++;
|
||||
jCfg["models"].push_back(amodel);
|
||||
}
|
||||
}
|
||||
if (nModelChoose == 0)
|
||||
jCfg.erase("models");
|
||||
|
||||
if (nModelChoose > 0) {
|
||||
// filament
|
||||
jCfg["filaments"] = json::array();
|
||||
for (auto it = m_ProfileJson["filament"].begin(); it != m_ProfileJson["filament"].end(); ++it) {
|
||||
if (it.value()["selected"] == 1) { jCfg["filaments"].push_back(it.key()); }
|
||||
}
|
||||
|
||||
// Preset
|
||||
jCfg["presets"]["filaments"] = json::array();
|
||||
jCfg["presets"]["filaments"].push_back(jCfg["filaments"][0]);
|
||||
|
||||
std::string PresetMachine = m_ProfileJson["machine"][0]["name"];
|
||||
jCfg["presets"]["machine"] = PresetMachine;
|
||||
|
||||
int nTotal = m_ProfileJson["process"].size();
|
||||
int nSet = nTotal / 2;
|
||||
if (nSet > 0) nSet--;
|
||||
|
||||
std::string sMode = m_ProfileJson["process"][nSet]["name"];
|
||||
jCfg["presets"]["process"] = sMode;
|
||||
|
||||
} else {
|
||||
jCfg["presets"]["filaments"] = json::array();
|
||||
jCfg["presets"]["filaments"].push_back("Default Filament");
|
||||
|
||||
jCfg["presets"]["machine"] = "Default Printer";
|
||||
|
||||
jCfg["presets"]["process"] = "Default Setting";
|
||||
}
|
||||
|
||||
std::string sOut = jCfg.dump(4, ' ', false);
|
||||
|
||||
std::ofstream output_file(w2s(strConfPath));
|
||||
output_file << sOut;
|
||||
output_file.close();
|
||||
|
||||
//Copy Profiles
|
||||
if (bbl_bundle_rsrc)
|
||||
{
|
||||
CopyDir(rsrc_vendor_dir,vendor_dir);
|
||||
}*/
|
||||
|
||||
std::string strAll = m_ProfileJson.dump(-1, ' ', false, json::error_handler_t::ignore);
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "before save to app_config: "<< std::endl<<strAll;
|
||||
|
@ -1029,6 +933,8 @@ int GuideFrame::GetFilamentInfo( std::string VendorDirectory, json & pFilaList,
|
|||
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);
|
||||
boost::filesystem::path inherits_path(w2s(strNewFile));
|
||||
if (!boost::filesystem::exists(inherits_path))
|
||||
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))
|
||||
|
@ -1096,8 +1002,10 @@ int GuideFrame::LoadProfile()
|
|||
auto filament_library_name = boost::filesystem::path(PresetBundle::ORCA_FILAMENT_LIBRARY).replace_extension(".json");
|
||||
if (boost::filesystem::exists(vendor_dir / filament_library_name)) {
|
||||
LoadProfileFamily(PresetBundle::ORCA_FILAMENT_LIBRARY, (vendor_dir / filament_library_name).string());
|
||||
m_OrcaFilaLibPath = (vendor_dir / PresetBundle::ORCA_FILAMENT_LIBRARY).string();
|
||||
} else {
|
||||
LoadProfileFamily(PresetBundle::ORCA_FILAMENT_LIBRARY, (rsrc_vendor_dir / filament_library_name).string());
|
||||
m_OrcaFilaLibPath = (rsrc_vendor_dir / PresetBundle::ORCA_FILAMENT_LIBRARY).string();
|
||||
}
|
||||
loaded_vendors.insert(PresetBundle::ORCA_FILAMENT_LIBRARY);
|
||||
|
||||
|
@ -1129,6 +1037,7 @@ int GuideFrame::LoadProfile()
|
|||
continue;
|
||||
|
||||
LoadProfileFamily(w2s(strVendor), iter->path().string());
|
||||
loaded_vendors.insert(w2s(strVendor));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1228,185 +1137,6 @@ 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue