保存前只删除一次成果目录,避免删掉其他流动段分析数据

feature/nm-para-property-20260615
lvjunjie 3 weeks ago
parent 597f6243c9
commit 5eb9d7a0fa

@ -438,8 +438,10 @@ class NM_DATA_EXPORT nmDataAnalyzeManager : public ZxDataObjectBin
// 保存数值成果到本地 // 保存数值成果到本地
// @param sRstCode 当前成果ID // @param sRstCode 当前成果ID
// @param pSubWndF 当前分析窗体 // @param pSubWndF 当前分析窗体
// @param bClearRoot 是否清空成果目录仅在遍历保存的第一个窗口时传true
// 清理旧窗口残留后续窗口传false避免误删其他窗口数据
// @return 保存成功返回 true否则返回 false // @return 保存成功返回 true否则返回 false
bool saveNmResult(QString sRstCode, iSubWndFitting* pSubWndF); bool saveNmResult(QString sRstCode, iSubWndFitting* pSubWndF, bool bClearRoot = false);
// 加载本地成果到内存中 // 加载本地成果到内存中
// @param sLoadAnalDir 加载的分析目录 // @param sLoadAnalDir 加载的分析目录

@ -3376,7 +3376,7 @@ bool nmDataAnalyzeManager::WriteProjectData(const QString & filePath)
return true; return true;
} }
bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWndF) bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWndF, bool bClearRoot)
{ {
Q_ASSERT(nullptr != pSubWndF); Q_ASSERT(nullptr != pSubWndF);
// 通过窗口层上下文获取保存目录 // 通过窗口层上下文获取保存目录
@ -3387,12 +3387,14 @@ bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWn
return false; return false;
} }
// sDir为当前成果窗口目录 // bClearRoot为true时清空整个成果目录清理已删除窗口的残留数据。
// 保存前先清空成果ID目录下的旧内容避免旧RstWnd目录或残留文件继续被加载 // 仅在遍历保存的第一个窗口传入true后续窗口传false避免误删其他窗口数据。
if(bClearRoot) {
QString sResultRootPath = QFileInfo(sDir).dir().absolutePath(); QString sResultRootPath = QFileInfo(sDir).dir().absolutePath();
if(!clearDirectoryContents(sResultRootPath)) { if(!clearDirectoryContents(sResultRootPath)) {
return false; return false;
} }
}
QString sResultPath = sDir + "/Results"; QString sResultPath = sDir + "/Results";
this->ensureDirectoryExists(sResultPath); this->ensureDirectoryExists(sResultPath);
@ -3403,7 +3405,7 @@ bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWn
QString sWellHistoryDataPath = sDir + "/WellHistory"; QString sWellHistoryDataPath = sDir + "/WellHistory";
this->ensureDirectoryExists(sWellHistoryDataPath); this->ensureDirectoryExists(sWellHistoryDataPath);
QVector<nmDataWellBase*> vecAllWells = nmDataAnalyzeManager::getCurrentInstance()->getWellDataList(); // 获取所有井 QVector<nmDataWellBase*> vecAllWells = this->getWellDataList(); // 获取所有井
// 遍历所有井,保存历史数据 // 遍历所有井,保存历史数据
for(int wellIdx = 0; wellIdx < vecAllWells.size(); ++wellIdx) { for(int wellIdx = 0; wellIdx < vecAllWells.size(); ++wellIdx) {
@ -3452,7 +3454,7 @@ bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWn
// 保存参与计算井的结果数据 // 保存参与计算井的结果数据
QString sWellRstDataPath = sDir + "/WellRst"; QString sWellRstDataPath = sDir + "/WellRst";
this->ensureDirectoryExists(sWellRstDataPath); this->ensureDirectoryExists(sWellRstDataPath);
QVector<QPair<NM_WELL_MODEL, QString>> vecWells = nmDataAnalyzeManager::getCurrentInstance()->getCalculationWells(); QVector<QPair<NM_WELL_MODEL, QString>> vecWells = this->getCalculationWells();
// 遍历每口井,保存里面计算出来的数据 // 遍历每口井,保存里面计算出来的数据
for(int wellIdx = 0; wellIdx < vecWells.size(); ++wellIdx) { for(int wellIdx = 0; wellIdx < vecWells.size(); ++wellIdx) {
@ -3464,7 +3466,7 @@ bool nmDataAnalyzeManager::saveNmResult(QString sRstCode, iSubWndFitting* pSubWn
continue; continue;
} }
nmDataWellBase* pWellData = nmDataAnalyzeManager::getCurrentInstance()->findWellByName(wellName); nmDataWellBase* pWellData = this->findWellByName(wellName);
if(pWellData) { if(pWellData) {
this->saveWellCalRstData(sWellRstDataPath, pWellData); this->saveWellCalRstData(sWellRstDataPath, pWellData);

@ -738,16 +738,37 @@ bool nmSubWndUtils::saveRsts(iSubWnd* pSubWnd, \
return false; return false;
} }
// 根据窗体指针,找到创建的对应的数据管理对象 // 根据窗体指针,找到创建的对应的数据管理对象
nmDataAnalyzeManager*pDataManager = nmDataAnalyzeManager::findManagerByFitting(pSubWndF); nmDataAnalyzeManager* pDataManager = nmDataAnalyzeManager::findManagerByFitting(pSubWndF);
// 如果不存在,则说明当前分析窗体没有做数值解,不需要做保存处理 // 如果不存在,则说明当前分析窗体没有做数值解,不需要做保存处理
if(pDataManager == nullptr) { if(pDataManager == nullptr) {
return false; return false;
} }
// 如果存在,则对当前分析数据进行保存 // 获取当前Tab下所有流动段分析窗口统一遍历保存。
if(!pDataManager->saveNmResult(sRstName, pSubWndF)) { // 无论主窗口对哪个流动段分析窗口调用 saveRsts
return false; // 都会遍历当前Tab下所有有 DataManager 的窗口依次保存,
// 确保多窗口数据全部持久化。第一个窗口保存时清空成果目录,
// 后续窗口不再清空,避免误删其他窗口数据。
ZxMainWindow* pMainWnd1 = const_cast<ZxMainWindow*>(pMainWnd);
ZxTabWidget* pTabWx = pMainWnd1->getCurTabWx();
QVector<iSubWnd*> vecAllFittingWnds = pMainWnd1->getAllSubWndsOf(pTabWx, "3004", false);
bool bFirstSave = true;
foreach(iSubWnd* pSub, vecAllFittingWnds) {
iSubWndFitting* pFit = dynamic_cast<iSubWndFitting*>(pSub);
if(pFit == nullptr) {
continue;
}
nmDataAnalyzeManager* pMgr = nmDataAnalyzeManager::findManagerByFitting(pFit);
if(pMgr == nullptr) {
continue;
}
// 第一个窗口保存时清空成果目录(清理旧窗口残留),后续窗口不再清空
pMgr->saveNmResult(sRstName, pFit, bFirstSave);
bFirstSave = false;
} }
} else if(pSubWnd->getWndID() == "5118") { } else if(pSubWnd->getWndID() == "5118") {
return true; return true;

Loading…
Cancel
Save