1、完成文件write和read

2、完成json写入文件
3、修改v循环和w循环写入逻辑
feature/struct-menu-20241023
mzh 1 week ago
parent 011318054a
commit 0d8f1d50cd

@ -103,9 +103,7 @@ void CFDStructDataManager::initJson() {
} }
void CFDStructDataManager::updateJson() { void CFDStructDataManager::updateJson() {
qDebug() << "-----------";
m_dom.SetObject(); m_dom.SetObject();
qDebug() << "++++++++++";
m_solverTimeModeManager->saveDataToDom(m_dom); m_solverTimeModeManager->saveDataToDom(m_dom);
m_solverBasicModeManager->saveDataToDom(m_dom); m_solverBasicModeManager->saveDataToDom(m_dom);
@ -131,9 +129,5 @@ void CFDStructDataManager::printJson() {
Writer<StringBuffer> writer(buffer); Writer<StringBuffer> writer(buffer);
m_dom.Accept(writer); m_dom.Accept(writer);
// freopen(caseJSONPath.c_str(), "w", stdout);
// std::cout << buffer.GetString() << std::endl;
// fclose(stdout);
CFDStructMainUtils::write(caseJSONPath, buffer.GetString()); CFDStructMainUtils::write(caseJSONPath, buffer.GetString());
} }

@ -20,8 +20,7 @@ class CFDStructDataSolverMonitorAerodynamicManager;
class CFDStructDataSolverMonitorImpellerManager; class CFDStructDataSolverMonitorImpellerManager;
class CUIConfig; class CUIConfig;
class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManager class CFDSTRUCTDATAMANAGER_EXPORT CFDStructDataManager {
{
public: public:
CFDStructDataManager(); CFDStructDataManager();
static CFDStructDataManager *getInstance(); static CFDStructDataManager *getInstance();
@ -57,12 +56,12 @@ private:
// 监控-叶轮机械性能曲线 // 监控-叶轮机械性能曲线
CFDStructDataSolverMonitorImpellerManager *m_solverMonitorTubomachineryPerformanceManager; CFDStructDataSolverMonitorImpellerManager *m_solverMonitorTubomachineryPerformanceManager;
public: public:
void initJson(); void initJson();
void updateJson(); void updateJson();
rapidjson::Document getJson(); rapidjson::Document getJson();
void printJson(); void printJson();
private: private:
rapidjson::Document m_dom; rapidjson::Document m_dom;
}; };

@ -49,8 +49,15 @@ void CFDStructDataSolverNumericalMethodManager::saveDataToDom(rapidjson::Documen
{"region", 0, "numericMethod", "numMethodParm", "lussor"}); {"region", 0, "numericMethod", "numMethodParm", "lussor"});
jsonAdd(dom, m_multigridLevels, jsonAdd(dom, m_multigridLevels,
{"region", 0, "numericMethod", "numMethodParm", "gridLevelNum"}); {"region", 0, "numericMethod", "numMethodParm", "gridLevelNum"});
jsonAdd(dom, m_cycleType,
// 循环类型如果是v循环的话写入1如果是w循环的话写入2
if (m_cycleType == 0) {
jsonAdd(dom, 1,
{"region", 0, "numericMethod", "numMethodParm", "cycleType"}); {"region", 0, "numericMethod", "numMethodParm", "cycleType"});
} else if (m_cycleType == 1) {
jsonAdd(dom, 2,
{"region", 0, "numericMethod", "numMethodParm", "cycleType"});
}
jsonAdd(dom, m_coarseGridCFL, jsonAdd(dom, m_coarseGridCFL,
{"region", 0, "numericMethod", "numMethodParm", "coarseGridNum"}); {"region", 0, "numericMethod", "numMethodParm", "coarseGridNum"});
jsonAdd(dom, m_fineGridCFL, jsonAdd(dom, m_fineGridCFL,

@ -1,20 +1,42 @@
#include "CFDStructMainUtils.h" #include "CFDStructMainUtils.h"
#include <direct.h> #include <direct.h>
#include <fstream>
#include <iostream> #include <iostream>
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
void CFDStructMainUtils::write(std::string path, std::string text) { void CFDStructMainUtils::write(std::string path, std::string text) {
std::cout << "start write" << endl;
using namespace std; using namespace std;
char drive[_MAX_PATH], dir[_MAX_PATH], filename[_MAX_PATH], ext[_MAX_PATH]; char drive[_MAX_PATH], dir[_MAX_PATH], filename[_MAX_PATH], ext[_MAX_PATH];
_splitpath(path.c_str(), drive, dir, filename, ext); _splitpath(path.c_str(), drive, dir, filename, ext);
_mkdir(dir); _mkdir(dir);
freopen(path.c_str(), "w", stdout);
cout << text << endl; // if (FILE *file = fopen(path.c_str(), "w")) {
fclose(stdout); // 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;
} }

@ -9,7 +9,8 @@ class CFDStructMAINAPI CFDStructMainUtils {
public: public:
static void write(std::string path, std::string text); 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 #endif

@ -25,7 +25,9 @@ CFDStructOperatorsModelSolverProperty::CFDStructOperatorsModelSolverProperty(QOb
connect(btn, &QPushButton::clicked, this, [=]() { connect(btn, &QPushButton::clicked, this, [=]() {
qDebug() << "Save button has clicked"; qDebug() << "Save button has clicked";
CFDStructDataManager::getInstance()->updateJson(); CFDStructDataManager::getInstance()->updateJson();
qDebug() << "finish updateJson";
CFDStructDataManager::getInstance()->printJson(); CFDStructDataManager::getInstance()->printJson();
qDebug() << "finish printJson";
}); });
connect(sigsCenter, &CFDStructSigsCenter::sig_solverModuleProperty, this, [=](SolutionAnalysisModuleProperty sig, QVariant idx) { connect(sigsCenter, &CFDStructSigsCenter::sig_solverModuleProperty, this, [=](SolutionAnalysisModuleProperty sig, QVariant idx) {

Loading…
Cancel
Save