From 0d8f1d50cde3e10a41f1f2f4ac6fe27fd8531db0 Mon Sep 17 00:00:00 2001 From: mzh Date: Fri, 8 Nov 2024 16:24:15 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=AE=8C=E6=88=90=E6=96=87=E4=BB=B6w?= =?UTF-8?q?rite=E5=92=8Cread=202=E3=80=81=E5=AE=8C=E6=88=90json=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=96=87=E4=BB=B6=203=E3=80=81=E4=BF=AE=E6=94=B9v?= =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E5=92=8Cw=E5=BE=AA=E7=8E=AF=E5=86=99?= =?UTF-8?q?=E5=85=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CFDStructDataManager.cpp | 6 ---- .../CFDStructDataManager.h | 15 +++++----- ...StructDataSolverNumericalMethodManager.cpp | 11 +++++-- .../CFDStructMain/CFDStructMainUtils.cpp | 30 ++++++++++++++++--- CFDStruct/CFDStructMain/CFDStructMainUtils.h | 3 +- .../CFDStructOperatorsModelSolverProperty.cpp | 2 ++ 6 files changed, 46 insertions(+), 21 deletions(-) diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataManager.cpp b/CFDStruct/CFDStructDataManager/CFDStructDataManager.cpp index df54fb8..5f607af 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataManager.cpp +++ b/CFDStruct/CFDStructDataManager/CFDStructDataManager.cpp @@ -103,9 +103,7 @@ void CFDStructDataManager::initJson() { } void CFDStructDataManager::updateJson() { - qDebug() << "-----------"; m_dom.SetObject(); - qDebug() << "++++++++++"; m_solverTimeModeManager->saveDataToDom(m_dom); m_solverBasicModeManager->saveDataToDom(m_dom); @@ -131,9 +129,5 @@ void CFDStructDataManager::printJson() { Writer writer(buffer); m_dom.Accept(writer); - // freopen(caseJSONPath.c_str(), "w", stdout); - // std::cout << buffer.GetString() << std::endl; - // fclose(stdout); - CFDStructMainUtils::write(caseJSONPath, buffer.GetString()); } diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataManager.h b/CFDStruct/CFDStructDataManager/CFDStructDataManager.h index 655f175..ca82325 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataManager.h +++ b/CFDStruct/CFDStructDataManager/CFDStructDataManager.h @@ -20,19 +20,18 @@ class CFDStructDataSolverMonitorAerodynamicManager; class CFDStructDataSolverMonitorImpellerManager; class CUIConfig; -class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManager -{ -public: +class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManager { + public: CFDStructDataManager(); static CFDStructDataManager *getInstance(); // 获取一个action的参数设置配置 CUIConfig *getActionParamUIConfig(SolutionAnalysisModuleProperty sig, QVariant idx); -private: + private: void initDataManagers(); -private: + private: static CFDStructDataManager *m_instance; CFDStructDataSolverTimeModeManager *m_solverTimeModeManager; @@ -57,13 +56,13 @@ private: // 监控-叶轮机械性能曲线 CFDStructDataSolverMonitorImpellerManager *m_solverMonitorTubomachineryPerformanceManager; - -public: + public: void initJson(); void updateJson(); rapidjson::Document getJson(); void printJson(); -private: + + private: rapidjson::Document m_dom; }; diff --git a/CFDStruct/CFDStructDataManager/CFDStructDataSolverNumericalMethodManager.cpp b/CFDStruct/CFDStructDataManager/CFDStructDataSolverNumericalMethodManager.cpp index d2786f7..504c04e 100644 --- a/CFDStruct/CFDStructDataManager/CFDStructDataSolverNumericalMethodManager.cpp +++ b/CFDStruct/CFDStructDataManager/CFDStructDataSolverNumericalMethodManager.cpp @@ -49,8 +49,15 @@ void CFDStructDataSolverNumericalMethodManager::saveDataToDom(rapidjson::Documen {"region", 0, "numericMethod", "numMethodParm", "lussor"}); jsonAdd(dom, m_multigridLevels, {"region", 0, "numericMethod", "numMethodParm", "gridLevelNum"}); - jsonAdd(dom, m_cycleType, - {"region", 0, "numericMethod", "numMethodParm", "cycleType"}); + + // 循环类型,如果是v循环的话写入1;如果是w循环的话写入2 + if (m_cycleType == 0) { + jsonAdd(dom, 1, + {"region", 0, "numericMethod", "numMethodParm", "cycleType"}); + } else if (m_cycleType == 1) { + jsonAdd(dom, 2, + {"region", 0, "numericMethod", "numMethodParm", "cycleType"}); + } jsonAdd(dom, m_coarseGridCFL, {"region", 0, "numericMethod", "numMethodParm", "coarseGridNum"}); jsonAdd(dom, m_fineGridCFL, diff --git a/CFDStruct/CFDStructMain/CFDStructMainUtils.cpp b/CFDStruct/CFDStructMain/CFDStructMainUtils.cpp index da23fe4..06842dd 100644 --- a/CFDStruct/CFDStructMain/CFDStructMainUtils.cpp +++ b/CFDStruct/CFDStructMain/CFDStructMainUtils.cpp @@ -1,20 +1,42 @@ #include "CFDStructMainUtils.h" #include +#include #include #include #include void CFDStructMainUtils::write(std::string path, std::string text) { + std::cout << "start write" << endl; using namespace std; char drive[_MAX_PATH], dir[_MAX_PATH], filename[_MAX_PATH], ext[_MAX_PATH]; _splitpath(path.c_str(), drive, dir, filename, ext); _mkdir(dir); - freopen(path.c_str(), "w", stdout); - cout << text << endl; - fclose(stdout); + + // if (FILE *file = fopen(path.c_str(), "w")) { + // fprintf(file, "%s", text.c_str()); + // fclose(file); + // } + ofstream outfile(path); + outfile << text << endl; + outfile.close(); } -void CFDStructMainUtils::read(std::string path, std::string &text) { +std::string CFDStructMainUtils::read(std::string path) { + using namespace std; + + string res; + + ifstream infile(path); + if (infile.is_open()) { + cout << "openfile" << endl; + char c; + while (infile >> c) + res += c; + infile.close(); + } else { + cout << "cant openfile" << endl; + } + return res; } diff --git a/CFDStruct/CFDStructMain/CFDStructMainUtils.h b/CFDStruct/CFDStructMain/CFDStructMainUtils.h index 74aab35..bcd8fda 100644 --- a/CFDStruct/CFDStructMain/CFDStructMainUtils.h +++ b/CFDStruct/CFDStructMain/CFDStructMainUtils.h @@ -9,7 +9,8 @@ class CFDStructMAINAPI CFDStructMainUtils { public: static void write(std::string path, std::string text); - static void read(std::string path, std::string &text); + public: + static std::string read(std::string path); }; #endif diff --git a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModelSolverProperty.cpp b/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModelSolverProperty.cpp index aaf239a..55c90ab 100644 --- a/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModelSolverProperty.cpp +++ b/CFDStruct/CFDStructOperatorsModel/CFDStructOperatorsModelSolverProperty.cpp @@ -25,7 +25,9 @@ CFDStructOperatorsModelSolverProperty::CFDStructOperatorsModelSolverProperty(QOb connect(btn, &QPushButton::clicked, this, [=]() { qDebug() << "Save button has clicked"; CFDStructDataManager::getInstance()->updateJson(); + qDebug() << "finish updateJson"; CFDStructDataManager::getInstance()->printJson(); + qDebug() << "finish printJson"; }); connect(sigsCenter, &CFDStructSigsCenter::sig_solverModuleProperty, this, [=](SolutionAnalysisModuleProperty sig, QVariant idx) {