Эх сурвалжийг харах

1116 新增结果文件夹和回复保存结果文件路径

caizm 1 жил өмнө
parent
commit
14eabc0160

+ 51 - 7
CAE_Solution/src/acis/cmdmainprocess.cpp

@@ -511,23 +511,66 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     msg_str.append("6. Save the surface mesh to .mesh (optional)");
     emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     string strName = get_uuid();
-    string appPath = get_file_path(object->da_struct->geoPath);
+    string dirPath = get_file_path(object->da_struct->geoPath);
+    QDir dir1("/cephfs/mesh_results");
+    if(!dir1.exists())
+    {
+        dir1.mkdir("/cephfs/mesh_results");
+    }
+    string appPath("/cephfs/mesh_results");
+    appPath.append("/");
+    appPath.append(dirPath);
+    QDir dir2(QString::fromStdString(appPath));
+    if(!dir2.exists())
+    {
+        dir2.mkdir(QString::fromStdString(appPath));
+    }
     if (ADIParam_.strResultFormat == ".ugrid")
     {
         strName = strName+".ugrid";
-        crw->WirteUgridFoamFile(surfMesh_,(appPath+strName).c_str());
+        msg_str.clear();
+        if(true==crw->WirteUgridFoamFile(surfMesh_,(appPath+"/"+strName).c_str())){
+            msg_str.append("result file save path=");
+            msg_str.append((appPath+"/"+strName).c_str());
+        }else{
+            msg_str.append("result file save failed!");
+        }
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     }
     else if (ADIParam_.strResultFormat == ".vtk") {
         strName = strName+".vtk";
-        crw->WirteVtkFoamFile(surfMesh_,(appPath + strName).c_str());
+        msg_str.clear();
+        if(true==crw->WirteVtkFoamFile(surfMesh_,(appPath+"/"+strName).c_str()))
+        {
+            msg_str.append("result file save path=");
+            msg_str.append((appPath+"/"+strName).c_str());
+        }else{
+            msg_str.append("result file save failed!");
+        }
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     }
     else if (ADIParam_.strResultFormat == ".bdf") {
         strName = strName+".bdf";
-        crw->WirteBDFFoamFile(surfMesh_,(appPath + strName).c_str());
+        msg_str.clear();
+        if(true==crw->WirteBDFFoamFile(surfMesh_,(appPath+"/"+strName).c_str())){
+            msg_str.append("result file save path=");
+            msg_str.append((appPath+"/"+strName).c_str());
+        }else{
+            msg_str.append("result file save failed!");
+        }
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     }
     else if (ADIParam_.strResultFormat == ".neu") {
         strName = strName+".neu";
-        crw->WriteNeuFoamFile(surfMesh_,(appPath + strName).c_str());
+        msg_str.clear();
+        if(true==crw->WriteNeuFoamFile(surfMesh_,(appPath+"/"+strName).c_str()))
+        {
+            msg_str.append("result file save path=");
+            msg_str.append((appPath+"/"+strName).c_str());
+        }else{
+            msg_str.append("result file save failed!");
+        }
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     }
 
 
@@ -615,8 +658,9 @@ void cmdMainProcess::exit_on_bad_outcome(const outcome &o)
 string cmdMainProcess::get_file_path(string &path)
 {
     int num = path.find_last_of('/');
-    path = path.substr(0,num+1);
-    return path;
+    path = path.substr(0,num);
+    int num2 = path.find_last_of('/');
+    return path.substr(num2,num-num2+1);
 }
 
 /*

+ 15 - 15
CAE_Solution/src/acis/rwritefile.cpp

@@ -32,12 +32,12 @@ CRWriteFile::~CRWriteFile()
 * @reviser
 * @date
 */
-void CRWriteFile::WriteNeuFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
+bool CRWriteFile::WriteNeuFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
 {
     QFile file(fileName);
     if (!file.open(QIODevice::WriteOnly))
     {
-        return;
+        return false;
     }
 
     QTextStream os(&file);
@@ -131,7 +131,7 @@ void CRWriteFile::WriteNeuFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
     }
     os << endl;
     file.close();
-    return;
+    return true;
 }
 /*
 * @brief Write vtk fomate File
@@ -143,12 +143,12 @@ void CRWriteFile::WriteNeuFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
 * @reviser
 * @date
 */
-void CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
+bool CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
 {
     QFile file(QString::fromUtf8(fileName));
     if (!file.open(QIODevice::WriteOnly))
     {
-        return;
+        return false;
     }
 
     QTextStream os(&file);
@@ -254,7 +254,7 @@ void CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
     }
     os << endl;
     file.close();
-    return;
+    return true;
 }
 /*
 * @brief Write bdf fomate File
@@ -266,12 +266,12 @@ void CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
 * @reviser
 * @date
 */
-void CRWriteFile::WirteBDFFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
+bool CRWriteFile::WirteBDFFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
 {
     QFile file(fileName);
     if (!file.open(QIODevice::WriteOnly|QIODevice::Text))
     {
-        return;
+        return false;
     }
 
     QTextStream os(&file);
@@ -406,7 +406,7 @@ void CRWriteFile::WirteBDFFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
 
     os << endl;
     file.close();
-    return;
+    return true;
 }
 /*
 * @brief Write vtk fomate File
@@ -418,12 +418,12 @@ void CRWriteFile::WirteBDFFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
 * @reviser
 * @date
 */
-void CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileName, int style)
+bool CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileName, int style)
 {
     QFile file(fileName);
     if (!file.open(QIODevice::WriteOnly))
     {
-        return;
+        return false;
     }
 
     QTextStream os(&file);
@@ -510,7 +510,7 @@ void CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
         break;
     }
     file.close();
-    return;
+    return true;
 }
 /*
 * @brief Write ugrid fomate File
@@ -522,12 +522,12 @@ void CRWriteFile::WirteVtkFoamFile(const Spa3dpm::Mesh &sub, const char *fileNam
 * @reviser
 * @date
 */
-void CRWriteFile::WirteUgridFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
+bool CRWriteFile::WirteUgridFoamFile(const Spa3dpm::Mesh &sub, const char *fileName)
 {
     QFile file(fileName);
     if (!file.open(QIODevice::WriteOnly))
     {
-        return;
+        return false;
     }
 
     QTextStream os(&file);
@@ -606,7 +606,7 @@ void CRWriteFile::WirteUgridFoamFile(const Spa3dpm::Mesh &sub, const char *fileN
     }
     os << endl;
     file.close();
-    return;
+    return true;
 }
 /*
 * @brief Read Xml File

+ 5 - 5
CAE_Solution/src/acis/rwritefile.h

@@ -20,11 +20,11 @@ public:
     private:
         static CRWriteFile* instance;
     public:
-        void WriteNeuFoamFile(const Spa3dpm::Mesh &sub, const char *fileName);
-        void WirteBDFFoamFile(const Spa3dpm::Mesh & sub, const char * fileName);
-        void WirteVtkFoamFile(const Spa3dpm::Mesh & sub, const char * fileName, int style);
-        void WirteUgridFoamFile(const Spa3dpm::Mesh & sub, const char * fileName);
-        void WirteVtkFoamFile(const Spa3dpm::Mesh & sub, const char * fileName);
+        bool WriteNeuFoamFile(const Spa3dpm::Mesh &sub, const char *fileName);
+        bool WirteBDFFoamFile(const Spa3dpm::Mesh & sub, const char * fileName);
+        bool WirteVtkFoamFile(const Spa3dpm::Mesh & sub, const char * fileName, int style);
+        bool WirteUgridFoamFile(const Spa3dpm::Mesh & sub, const char * fileName);
+        bool WirteVtkFoamFile(const Spa3dpm::Mesh & sub, const char * fileName);
         bool ReadXmlParamFile(DPM_ADIParam &ADIParam, const char*fileName);
         bool ReadXmlParam(DPM_ADIParam &ADIParam,boostJsonObject* object);
 };

+ 73 - 0
CAE_Solution/tests/qprocess_test/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 9 - 0
CAE_Solution/tests/qprocess_test/qprocess_test.pro

@@ -0,0 +1,9 @@
+QT += testlib
+QT -= gui
+
+CONFIG += qt console warn_on depend_includepath testcase
+CONFIG -= app_bundle
+
+TEMPLATE = app
+
+SOURCES +=  tst_qprocess_test.cpp

+ 53 - 0
CAE_Solution/tests/qprocess_test/tst_qprocess_test.cpp

@@ -0,0 +1,53 @@
+#include <QtTest>
+#include <QProcess>
+
+// add necessary includes here
+
+class qprocess_test : public QObject
+{
+    Q_OBJECT
+
+public:
+    qprocess_test();
+    ~qprocess_test();
+
+private slots:
+    void test_case1();
+
+};
+
+qprocess_test::qprocess_test()
+{
+}
+
+qprocess_test::~qprocess_test()
+{
+
+}
+/****************
+ * 运行:右键函数名,选择 "Run Test Under Cursor"即可
+ * 测试:1、windows下启动进程,执行终端命令
+ *      2、linux下启动进程,执行sudo相关命令
+ * 结果:成功
+ * *****************/
+void qprocess_test::test_case1()
+{
+#ifdef WIN32
+    QProcess cmd;
+    cmd.start("cmd");
+    cmd.waitForStarted();
+    cmd.write("mkdir /cmd_test\n");
+    cmd.close();
+#else
+    QProcess cmd;
+    cmd.start("bash");
+    cmd.waitForStarted();
+    cmd.write("echo qydl1/ | sudo -S touch /home/roo/test.txt\n");
+    cmd.waitForFinished();
+    cmd.close();
+#endif
+}
+
+QTEST_APPLESS_MAIN(qprocess_test)
+
+#include "tst_qprocess_test.moc"

+ 2 - 1
CAE_Solution/tests/tests.pro

@@ -10,6 +10,7 @@ SUBDIRS += \
     jsonToQt_Test \
     axes_test \
     vtkcamera_test \
-    loadvtkfile
+    loadvtkfile \
+    qprocess_test