Procházet zdrojové kódy

0629 修改resultimport vtk文件

caizm před 2 roky
rodič
revize
5e4df2c275

+ 77 - 35
CAE_Solution/src/Rabbitmq/rabbitClient/rabbitclient.cpp

@@ -106,65 +106,107 @@ int rabbitClient::recvMsg()
             }
         }
         disconnect_index = 0;
-        //cout<<"str.c_str() =          "<<str.c_str()<<endl;
+        cout<<"msg string =          "<<str<<endl;
         printf("------------recvClient recvMsg-------------------\n");
         if(str!=""){
+
             str.erase(0,1);//删除首尾双引号
             str.erase(str.end()-1);
             std::string t;
             for (int var = 0; var < str.length(); ++var) {
-                if(str[var]=='\\'){
+                if(str[var]=='\\'){//第一次删除"\\"
 
                 }else{
                     t+=str[var];
                 }
             }
-//            cout<<"t="<<t<<endl;
-            cout<<"t.c_str() =      "<<t.c_str()<<endl;
+            cout<<"t(delete \\) =      "<<t<<endl;
             t.erase(0,1);//暂时移除首尾{}
             t.erase(t.end()-1);
-            /******************************/  //去除param数组里面的多余转义字符
+            //-------------去除param数组里面的多余转义字符-------------------//
             int temp1 = t.find_first_of('[');
             int temp2 = t.find_first_of(']');
-            if(-1 != temp1){
+            if(-1 != temp1){//param包含数组
                 string array_first_t;
                 array_first_t = t.substr(0,temp1);
-                string array_middle_t;
-                for(int i = temp1;i<=temp2;i++){
-                    if(t[i] == '"'){
-                        array_middle_t += '\\';
-                    }
-                    array_middle_t+=t[i];
-                }
                 string array_end_t;
                 array_end_t = t.substr(temp2+1);
-                t.clear();
-                t = '{' + array_first_t+array_middle_t+array_end_t+'}';
-            }else{
-            /******************************/
-            int num1 = t.find_first_of('{',0);//去除paramjson里面的多余转义字符
-            int num2 = t.find_first_of('}',0);
-            if(num1!=-1){
-                string first_t;
-                first_t=t.substr(0,num1);
-                string middle_t;
-                for(int i=num1;i<=num2;i++){
-                    if(t[i] == '"'){
-                        middle_t+='\\';
+                int num_temp1 = array_first_t.find_first_of('{');
+                if(num_temp1!=-1){//param非数组,但包含数组  //json数据格式*******{****************[{*****},{*****}]*****}*********
+                    string array_second_t;
+                    string array_third_t;
+                    string array_middle_t;
+                    string temp_str = array_first_t;
+                    array_first_t = array_first_t.substr(0,num_temp1);//*******
+                    array_second_t = temp_str.substr(num_temp1);//{*********
+                    temp_str = array_end_t;
+                    int num_temp2 = array_end_t.find_first_of('}');
+                    array_end_t = array_end_t.substr(num_temp2);//}*******
+                    array_third_t = temp_str.substr(0,num_temp2);//******
+                    temp_str.clear();
+                    for(int i=0;i<array_second_t.size();i++){
+                        if(array_second_t[i]=='"'){
+                            temp_str+='\\';
+                        }
+                        temp_str+=array_second_t[i];
+                    }
+                    array_second_t = temp_str;
+
+                    temp_str.clear();
+                    for(int i=0;i<array_third_t.size();i++){
+                        if(array_third_t[i]=='"'){
+                            temp_str+='\\';
+                        }
+                        temp_str+=array_third_t[i];
+                    }
+                    array_third_t = temp_str;
+
+                    for(int i=temp1;i<=temp2;i++){
+                        if(t[i] =='"'){
+                            array_middle_t+='\\';
+                            array_middle_t+='\\';
+                            array_middle_t+='\\';
+                        }
+                        array_middle_t+=t[i];//[{*******},{******}]
+                    }
+                    t='{'+array_first_t+array_second_t+array_middle_t+array_third_t+array_end_t+'}';
+                }else{//param数组 //json数据格式*************[{******},{*******},{******}]***************
+                    string array_middle_t;
+                    for(int i = temp1;i<=temp2;i++){
+                        if(t[i] == '"'){
+                            array_middle_t += '\\';
+                        }
+                        array_middle_t+=t[i];
                     }
-                    middle_t+=t[i];
+                    t.clear();
+                    t = '{' + array_first_t+array_middle_t+array_end_t+'}';
+                }
+            }else{//param不包含数组  //json数据格式*****************{**********}*****************
+                //-----------去除paramjson里面的多余转义字符--------------------//
+                int num1 = t.find_first_of('{',0);
+                int num2 = t.find_first_of('}',0);
+                if(num1!=-1){
+                    string first_t;
+                    first_t=t.substr(0,num1);
+                    string middle_t;
+                    for(int i=num1;i<=num2;i++){
+                        if(t[i] == '"'){
+                            middle_t+='\\';
+                        }
+                        middle_t+=t[i];
+                    }
+                    string end_t;
+                    end_t = t.substr(num2+1);
+                    t.clear();
+                    t = '{' + first_t + middle_t + end_t + '}';
+                }else{
+                    t = '{' + t + '}';
                 }
-                string end_t;
-                end_t = t.substr(num2+1);
-                t.clear();
-                t = '{' + first_t + middle_t + end_t + '}';
-            }else{
-                t = '{' + t + '}';
-            }
 
             }
+            cout<<"change:  "<<t<<endl;
             emit sendmsg_recvclientToRecvstate(t);//信号*/
-             //0509
+            //0509
             //emit sendmsg_recvclientToRecvstate(tmp);
         }
         QThread::sleep(1);

+ 18 - 8
CAE_Solution/src/threadPool_and_statemachine/dealWith/boostjsonobject.cpp

@@ -73,6 +73,7 @@ boostJsonObject::~boostJsonObject()
  */
 void boostJsonObject::FromJson(std::string msg)
 {
+    cout<<"msg change over = "<<msg<<endl;
     stringstream msgs(msg);
     boost::property_tree::ptree root;
     boost::property_tree::read_json(msgs,root);//boost 方法
@@ -304,9 +305,9 @@ void boostJsonObject::FromParamJson(string param)
         sm_struct->u = root.get<std::string>("u");
         sm_struct->v = root.get<std::string>("v");
         sm_struct->w = root.get<std::string>("w");
-//        sm_struct->x = root.get<double>("x");//未使用xyz
-//        sm_struct->y = root.get<double>("y");
-//        sm_struct->z = root.get<double>("z");
+        //        sm_struct->x = root.get<double>("x");//未使用xyz
+        //        sm_struct->y = root.get<double>("y");
+        //        sm_struct->z = root.get<double>("z");
     }else if(this->action == "StreamDisplaySelect"){
         //do nothing
     }else if(this->action == "StreamDisplayDeleteLast"){
@@ -327,12 +328,21 @@ void boostJsonObject::FromParamJson(string param)
         this->filePath = root.get<std::string>("filePath");
         ci_struct = new contourinimationw_struct();
         ci_struct->displaytype = root.get<std::string>("animationType");
-        boost::property_tree::ptree items = root.get_child("fileNames");
-        boost::property_tree::ptree::iterator pos = items.begin();
-        for(;pos!=items.end();pos++){
-            ci_struct->filenames.push_back(pos->second.get<std::string>("fileName"));
-            ci_struct->steps.push_back(pos->second.get<int>("step"));
+        //重新组建并解析filenames
+        string fileNames = root.get<std::string>("fileNames");
+        fileNames = "{\"fileNames\":"+fileNames+"}";
+        stringstream temp_filenames(fileNames);
+        boost::property_tree::ptree ptfileName,items_arr;
+        boost::property_tree::json_parser::read_json(temp_filenames,ptfileName);
+        boost::property_tree::ptree items = ptfileName.get_child("fileNames");
+        for(boost::property_tree::ptree::iterator it = items.begin();it!=items.end();it++){
+            items_arr = it->second;
+            string name = items_arr.get<string>("filename");
+            ci_struct->filenames.push_back(name);
+            int num = items_arr.get<int>("step");
+            ci_struct->steps.push_back(num);
         }
+
         if(ci_struct->displaytype=="ContourDisplay"){
             cd_struct = new contourDisplay_struct();
             cd_struct->level = root.get<int>("level");

+ 2 - 1
CAE_Solution/src/threadPool_and_statemachine/dealWith/display_struct.h

@@ -91,11 +91,12 @@ public:
     contourinimationw_struct(){
     }
     ~contourinimationw_struct(){
+        steps.clear();
+        filenames.clear();
     }
     string displaytype;
     vector<int> steps;
     vector<string> filenames;
-    string filepath;
     string hideZones;
 };
 

+ 50 - 44
CAE_Solution/src/threadPool_and_statemachine/dealWith/handlepool.cpp

@@ -65,7 +65,6 @@ handlePool::~handlePool()
  */
 void handlePool::getmsg_recvstateTohandlePool(std::string recvmsg)
 {
-    std::cout<<"recvmsg"<<recvmsg<<std::endl;
     boostJsonObject* json_object = new boostJsonObject();
     QVTKRenderer* render_=NULL;
     try{//处理异常
@@ -245,13 +244,6 @@ void handlePool::judgeLoaddata(boostJsonObject *object, QVTKRenderer *render_)
         }
     }
     QString m_filePath = QString::fromStdString(object->filePath);//测试路径
-    //QString m_filePath = "F:\\czm\\vtkfile\\tfg.ugrid";
-    //    if(object->solverConfigid=="b867ebb4a49d4c7a8ce66d6b07b6f333"){
-    //        m_filePath = "F:\\czm\\vtkfile\\f.vtk";
-    //        //m_filePath = "F:\\czm\\vtkfile\\forward.ugrid";
-    //    }
-
-    //QString m_filePath = "C:\\Users\\Administrator\\Desktop\\VTK\\f.vtk";
     QFileInfo fileinfo_(m_filePath);
     if(!fileinfo_.isFile()){
         cout<<"file path is Empty!"<<endl;
@@ -289,9 +281,8 @@ void handlePool::judgeLoaddata(boostJsonObject *object, QVTKRenderer *render_)
 bool handlePool::resultImport(boostJsonObject *object_, QVTKRenderer *renderer_)
 {
     string type_;
-    //object_->ci_struct->filenames.push_back();
+    //object_->fileName = "dynamicResponse-transient36.vtk";//测试
     //object_->fileName = "hcfd_tec_boundary_timestep100.dat";
-    //object_->fileName = "whole_part1.plt,whole_part2.plt";
     size_t found = object_->fileName.find_first_of(',');
     if(found==string::npos){//单个文件
         vector<string> tmp = stringSplit(object_->fileName,'.');
@@ -347,7 +338,7 @@ bool handlePool::resultImport(boostJsonObject *object_, QVTKRenderer *renderer_)
     }
     //object_->filePath = "F:\\czm\\vtkfile";
     //object_->filePath = "C:\\Users\\Administrator\\Desktop\\Postprocess_Binary";//测试路径
-    //object_->filePath = "C:\\Users\\Administrator\\Documents\\WeChat Files\\wxid_18qjhi0tq90d22\\FileStorage\\File\\2023-06";//测试路径
+    //object_->filePath = "C:\\Users\\Administrator\\Documents\\WeChat Files\\wxid_18qjhi0tq90d22\\FileStorage\\File\\2023-05";//测试路径
     QDir dir(QString::fromStdString(object_->filePath));
     if(!dir.exists()){
         return false;
@@ -428,7 +419,6 @@ bool handlePool::resultImport(boostJsonObject *object_, QVTKRenderer *renderer_)
             return false;
         }
     }else if(type_ == "vtkfile"){
-        //object_->fileName = "dynamicResponse-transient36.vtk";//测试
         rsManager = new ResultVTKManager();
         rsManager->Clear();
         rsManager->fileType = "VTK";
@@ -494,7 +484,7 @@ bool handlePool::resultImport(boostJsonObject *object_, QVTKRenderer *renderer_)
     emit sendImg_handlePoolToSendstate(object_->ToJson("importResult_vector",buildResultImport_msg("Vector",rsManager)));//发送矢量结果数据
     emit sendImg_handlePoolToSendstate(object_->ToJson("importResult_solidsurface",buildResultImport_msg("Solidsurface",rsManager)));//发送实体表面结果数据
     emit sendImg_handlePoolToSendstate(object_->ToJson("importResult_stream",buildResultImport_msg("Stream",rsManager)));//发送流线结果数据
-    if(type_!="vtkfile"){
+    if(type_!="vtkfile"){//vtk没有zone就不发
         emit sendImg_handlePoolToSendstate(object_->ToJson("importResult_animation",buildResultImport_msg("animation",rsManager)));//发送动画所需的zonename
     }
     send_picture(object_,renderer_);
@@ -737,12 +727,7 @@ bool handlePool::result_contourinimationdisplay(boostJsonObject *object_, QVTKRe
         }
     }
     for(int i =0;i<object_->ci_struct->filenames.size();i++){
-#ifdef _WIN32
-        string filename = object_->filePath+"\\"+object_->ci_struct->filenames[i];
-#else
-        string filename = object_->filePath+"/"+object_->ci_struct->filenames[i];
-#endif
-        animation_render(filename,object_->ci_struct->steps[i],render_,object_);
+        animation_render(object_->ci_struct->filenames[i],object_->ci_struct->steps[i],render_,object_);
     }
     delete object_;
     object_ = NULL;
@@ -1158,23 +1143,32 @@ vector<string> handlePool::stringSplit(const string& str, char delim) {
 void handlePool::get_init_scalar_range(ResultManager* cmanager)
 {
     if(cmanager->solveTimes_.size()>1)return;
-    double sltime = *(cmanager->solveTimes_.begin());
-    map<double,map<string,vtkVISUnContour*>>::iterator it1 = cmanager->vtkVisZoneMeshMap_.find(sltime);
-    vector<string> temp_scalar = cmanager->GetMeshScalarNameVec();
-    if(cmanager->fileType == "plt_binary"){
+    if(cmanager->fileType!="VTK"){//非vtk文件标量范围
+        double sltime = *(cmanager->solveTimes_.begin());
+        map<double,map<string,vtkVISUnContour*>>::iterator it1 = cmanager->vtkVisZoneMeshMap_.find(sltime);
+        vector<string> temp_scalar = cmanager->GetMeshScalarNameVec();
+        if(cmanager->fileType == "plt_binary"){
+            for(int i =0;i<temp_scalar.size();i++){
+                temp_scalar[i] = removeSpaces(temp_scalar[i]);
+            }
+        }
         for(int i =0;i<temp_scalar.size();i++){
-            temp_scalar[i] = removeSpaces(temp_scalar[i]);
+            set<double> temp;
+            for(map<string,vtkVISUnContour*>::iterator unIt = it1->second.begin();unIt!=it1->second.end();unIt++){
+                double range[2];
+                unIt->second->GetScalarRange(range,(char*)temp_scalar[i].c_str());
+                temp.insert(range[0]);
+                temp.insert(range[1]);
+            }
+            allscalarrange[temp_scalar[i]] = temp;
+        }
+    }else{//vtk文件标量范围
+        for(int i=0;i<cmanager->source->scalarNumber_;i++){
+            set<double> temp;
+            temp.insert(cmanager->source->scalarRange[i][0]);
+            temp.insert(cmanager->source->scalarRange[i][1]);
+            allscalarrange[cmanager->source->scalarName[i]] =temp;
         }
-    }
-    for(int i =0;i<temp_scalar.size();i++){
-        set<double> temp;
-        for(map<string,vtkVISUnContour*>::iterator unIt = it1->second.begin();unIt!=it1->second.end();unIt++){
-            double range[2];
-            unIt->second->GetScalarRange(range,(char*)temp_scalar[i].c_str());
-            temp.insert(range[0]);
-            temp.insert(range[1]);
-        }
-        allscalarrange[temp_scalar[i]] = temp;
     }
 }
 
@@ -1186,8 +1180,15 @@ void handlePool::get_init_scalar_range(ResultManager* cmanager)
  */
 void handlePool::animation_render(string filename,int step,QVTKRenderer* renderer_,boostJsonObject* object_)
 {
-    string type_;
+
     vector<string> tmp = stringSplit(filename,'.');
+#ifdef _WIN32
+    string fname_ = object_->filePath+"\\"+filename;
+#else
+    string fname_ = object_->filePath+"/"+filename;
+#endif
+    string type_;
+
     if(tmp[1]=="vtk"){
         type_ = "vtkfile";
     }else if(tmp[1]=="dat"){
@@ -1197,22 +1198,26 @@ void handlePool::animation_render(string filename,int step,QVTKRenderer* rendere
     }
     vector<string> hidezonenames_tmp;
     if(type_!="vtkfile"){
-
-        if(object_->ci_struct->hideZones.find_first_of(",")==string::npos){
-            hidezonenames_tmp.push_back(object_->ci_struct->hideZones);
-        }else{
-            hidezonenames_tmp=stringSplit(object_->ci_struct->hideZones,',');
+        if(!object_->ci_struct->hideZones.empty()){
+            if(object_->ci_struct->hideZones.find_first_of(",")==string::npos){
+                hidezonenames_tmp.push_back(object_->ci_struct->hideZones);
+            }else{
+                hidezonenames_tmp=stringSplit(object_->ci_struct->hideZones,',');
+            }
         }
     }
 
-    renderer_->widgetFlag = QVTKRenderer::WidgetModel::ResultModel;
+
     ResultManager* rsManager = NULL;
     if(type_ == "one_plt_ascii_file"||type_ == "one_plt_binary_file"){
+        renderer_->widgetFlag = QVTKRenderer::WidgetModel::ResultModel;
         bool flag = true;
         rsManager = new ResultMeshManager();
         rsManager->Clear();
-        bool f =rsManager->LoadData(QString::fromStdString(filename));
-        set_hidezone_animation(hidezonenames_tmp,rsManager);
+        bool f =rsManager->LoadData(QString::fromStdString(fname_));
+        if(!hidezonenames_tmp.empty()){
+            set_hidezone_animation(hidezonenames_tmp,rsManager);
+        }
         if(f){
             rsManager->SetSaveIndex(0);
             if(renderer_){
@@ -1231,11 +1236,12 @@ void handlePool::animation_render(string filename,int step,QVTKRenderer* rendere
             renderer_->ZoomToExtents();
         }
     }else if(type_ == "vtkfile"){
+        renderer_->widgetFlag = QVTKRenderer::WidgetModel::VTKModel;
         rsManager = new ResultVTKManager();
         rsManager->Clear();
         rsManager->fileType = "VTK";
         bool flag = true;
-        bool f = rsManager->LoadData(QString::fromStdString(filename));//加载
+        bool f = rsManager->LoadData(QString::fromStdString(fname_));//加载
         rsManager->uncontourVec_.clear();
         if(f){
             if(renderer_){