Procházet zdrojové kódy

1120 修改网格剖分异常处理

caizm před 1 rokem
rodič
revize
69d2ec7fa7

+ 177 - 45
CAE_Solution/src/acis/cmdmainprocess.cpp

@@ -108,6 +108,7 @@ bool cmdMainProcess::CreateProcess_(string pathGeo)
     //iniACIS();
     //1.--read cad surf parameter
     //Get ENTITY_LIST;
+    string msg_str;
     ENTITY_LIST Whole_ents;
     ENTITY_LIST cells;
     ENTITY_LIST ent;
@@ -168,14 +169,24 @@ bool cmdMainProcess::CreateProcess_(string pathGeo)
             }
         }
 
-        exit_on_bad_outcome(api_n_body_unite(ent, false));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_n_body_unite(ent, false));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Whole_ents after unite is : %d\n", ent.count());
         for (int kk = 0; kk < ent.count(); kk++)
         {
             printf("kk%d is %d; ", kk, is_BODY(ent[kk]));
         }
         // Attach cellular topology to non-regular union (necessary for the Spa3dpm::Cell_VolumeElem_Assoc class below to function correctly).
-        exit_on_bad_outcome(api_ct_attach(ent));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_ct_attach(ent));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Whole_ents after attach is : %d\n", ent.count());
         for (int kk = 0; kk < ent.count(); kk++)
         {
@@ -194,6 +205,9 @@ bool cmdMainProcess::CreateProcess_(string pathGeo)
     }
     else {//self create
         Whole_ents = CreateSelfGeo();
+        if(Whole_ents.count()==0){
+            return false;
+        }
     }
     printf("Load Geometry OK!"); //
     printf("Whole_ents is : %d\n", Whole_ents.count());
@@ -343,7 +357,12 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
         }
 
         ENTITY_LIST testEnt=ent;
-        exit_on_bad_outcome(api_n_body_unite(testEnt, false));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_n_body_unite(testEnt, false));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Whole_ents after unite is : %d,then use stitch function\n", testEnt.count());
         //--
         msg_str.clear();
@@ -360,7 +379,12 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
             //	printf("kk%d is %d; ", kk, is_BODY(ent[kk]));
             //}
             //// Attach cellular topology to non-regular union (necessary for the Spa3dpm::Cell_VolumeElem_Assoc class below to function correctly).
-            exit_on_bad_outcome(api_ct_attach(testEnt));
+            msg_str.clear();
+            msg_str=exit_on_bad_outcome(api_ct_attach(testEnt));
+            if(!msg_str.empty()){
+                emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+                return false;
+            }
             printf("Whole_ents after attach is : %d\n", testEnt.count());
             //--
             msg_str.clear();
@@ -397,6 +421,9 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
         }
     }else {//self create
         Whole_ents = CreateSelfGeo();
+        if(Whole_ents.count() == 0){
+            return false;
+        }
     }
     printf("  load geometry ok!"); //
     printf("Whole_ents is : %d\n", Whole_ents.count());
@@ -450,11 +477,11 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     QString dDir=QDir::currentPath();
     printf("path:%s\n",dDir.toLatin1().data());
     //--
-//    msg_str.clear();
-//    msg_str.append("  path:");
-//    msg_str.append(dDir.toLatin1().data());
-//    msg_str.append(".");
-//    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+    //    msg_str.clear();
+    //    msg_str.append("  path:");
+    //    msg_str.append(dDir.toLatin1().data());
+    //    msg_str.append(".");
+    //    emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     ADIParam_.useDefaultParam();
     CRWriteFile* crw = new CRWriteFile();
 
@@ -501,7 +528,9 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
     emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
     if(ADIParam_.style)
     {
-        createVol(ADIParam_.style, cells);
+        if(!createVol(ADIParam_.style, cells)){
+            return false;
+        }
     }
 
 
@@ -569,8 +598,12 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
         emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("path",msg_str));
     }
 
-
-    exit_on_bad_outcome(api_3dpm_save_mesh(surfMesh_, "3dpmSample_surfMesh.mesh"));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_3dpm_save_mesh(surfMesh_, "3dpmSample_surfMesh.mesh"));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     printf("Successfully wrote SurfMesh to .mesh format\n");
     //--
     msg_str.clear();
@@ -635,15 +668,23 @@ bool cmdMainProcess::CreateProcess_(string pathGeo, string pathParam)
 * @reviser
 * @date
 */
-void cmdMainProcess::exit_on_bad_outcome(const outcome &o)
+string cmdMainProcess::exit_on_bad_outcome(const outcome &o)
 {
-
-    if (!o.ok())
+    string msg;
+    if (!o.ok()){
         if (const message_list *ml = get_message(o.error_number()))
         {
-            printf("*** ERROR: %s: %s\n", ml->ident, ml->message);
-            exit(1);
+            msg.append("*** ERROR: ");
+            msg.append(ml->ident);
+            msg.append(": ");
+            msg.append(ml->message);
+            msg.append("\n");
         }
+        return msg;
+    }else{
+        msg.clear();
+        return msg;
+    }
 }
 
 /*
@@ -815,7 +856,12 @@ Spa3dpm::Parameters cmdMainProcess::setADIParamTo3dpm(const DPM_ADIParam &p)
 */
 bool cmdMainProcess::Createcadsurf(const ENTITY_LIST &ents, Spa3dpm::CadSurfSession &cadsurf)
 {
-    exit_on_bad_outcome(api_3dpm_create_cadsurf_session(ents, cadsurf));
+    string msg_str;
+    msg_str=exit_on_bad_outcome(api_3dpm_create_cadsurf_session(ents, cadsurf));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     printf("Successfully created cadsurf session\n");
     return true;
 }
@@ -834,14 +880,24 @@ into a surface mesh.
 bool cmdMainProcess::OutPutSurfMesh(Spa3dpm::MgSession &inSession, Spa3dpm::Mesh &outMesh, const Spa3dpm::Parameters *inParams)
 {
     printf("start created 3dpm_compute_mesh\n");
-    exit_on_bad_outcome(api_3dpm_compute_mesh(inSession, outMesh, inParams));
+    string msg_str;
+    msg_str=exit_on_bad_outcome(api_3dpm_compute_mesh(inSession, outMesh, inParams));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     printf("Successfully created surface mesh\n");
 
     if (ADIParam_.bCleanerSection)//open cleaner or not
     {
         printf("start created create_cleaner_session\n");
         Spa3dpm::CleanerSession  cleantetra;
-        exit_on_bad_outcome(api_3dpm_create_cleaner_session(outMesh, cleantetra));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_create_cleaner_session(outMesh, cleantetra));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         Spa3dpm::Parameters cleanerParams;
         //--set cleaner parameter
         if (!ADIParam_.clrParam.folding_angle.isEmpty())
@@ -868,7 +924,12 @@ bool cmdMainProcess::OutPutSurfMesh(Spa3dpm::MgSession &inSession, Spa3dpm::Mesh
         }
 
         printf("Successfully set cleaner session\n");
-        exit_on_bad_outcome(api_3dpm_compute_mesh(cleantetra, outMesh, &cleanerParams));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_compute_mesh(cleantetra, outMesh, &cleanerParams));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created cleaner surface mesh\n");
     }
 
@@ -885,18 +946,28 @@ bool cmdMainProcess::OutPutSurfMesh(Spa3dpm::MgSession &inSession, Spa3dpm::Mesh
 */
 ENTITY_LIST cmdMainProcess::CreateSelfGeo()
 {
-
+    string msg_str;
     ENTITY_LIST ents;
 
     // Create the first solid block
     BODY *block = nullptr;
-    exit_on_bad_outcome(api_solid_block(SPAposition(0, 0, 0), SPAposition(10, 5, 10), block));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_solid_block(SPAposition(0, 0, 0), SPAposition(10, 5, 10), block));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     ents.add(block);
 
     // Create a hanging face inside the first block
     FACE *face = nullptr;
     SPAvector ab = SPAvector(0.0, 0.0, 1.0);
-    exit_on_bad_outcome(api_face_plane(SPAposition(1, 1, 5), 8, 3, &ab, face));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_face_plane(SPAposition(1, 1, 5), 8, 3, &ab, face));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     //exit_on_bad_outcome(api_face_plane(SPAposition(1, 1, 1), 4, 1, &SPAvector(0.0, 0.0, 1.0), face));
     BODY * sheet = nullptr;
     api_sheet_from_ff(1, &face, sheet);
@@ -911,21 +982,40 @@ ENTITY_LIST cmdMainProcess::CreateSelfGeo()
 
     // Create the second solid cube with edge length 10, adjacent to the first block
     BODY *cube = nullptr;
-    exit_on_bad_outcome(api_solid_block(SPAposition(0, 5, 0), SPAposition(10, 15, 10), cube));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_solid_block(SPAposition(0, 5, 0), SPAposition(10, 15, 10), cube));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     ents.add(cube);
 
     // Create a sphere of radius 4 that lies insides the second block
     BODY *sphere = nullptr;
-    exit_on_bad_outcome(api_solid_sphere(SPAposition(5, 10, 5), 4, sphere));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_solid_sphere(SPAposition(5, 10, 5), 4, sphere));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     ents.add(sphere);
 
     printf("Entity Count not unite: %d\n", ents.count());
     // Non-regularized unite of the blocks and the sphere. All faces are kept and used to divide the output body into cells (in Acis) and subdomains (in 3DPM).
-    exit_on_bad_outcome(api_n_body_unite(ents, false));
-
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_n_body_unite(ents, false));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
 
     // Attach cellular topology to non-regular union (necessary for the Spa3dpm::Cell_VolumeElem_Assoc class below to function correctly).
-    exit_on_bad_outcome(api_ct_attach(ents));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_ct_attach(ents));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     //printf("Successfully attached cellular topology to body\n");
     //ENTITY_LIST cells;
     //api_ct_get_all_cells(ents, cells);
@@ -1101,8 +1191,9 @@ void cmdMainProcess::CreateLocalSizeMap()
 * @author QiYan
 * @date 20221202
 */
-void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
+bool cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
 {
+    string msg_str;
     if (istyle==1){//四面体网格
         USE_TETRA = 1;
         USE_HEXA = 0;
@@ -1116,7 +1207,7 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
         USE_TETRA = 0;
         USE_HEXA = 0;
     }else {
-        return;
+        return false;
     }
 
     if (USE_HEXA == 1)
@@ -1162,7 +1253,7 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
         if (ADIParam_.hexaParam.components.isEmpty())
         {
             printf(" hexaParam.components is empty!");
-            return;
+            return false;
         }
         hexaParams.SetParam("components", ADIParam_.hexaParam.components.toLatin1().data()); // all connected components will be meshed
         printf("tags %s\n", ADIParam_.hexaParam.components.toLatin1().data());
@@ -1207,10 +1298,20 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
 
         // Create Hexa session
         Spa3dpm::HexaSession hexa;
-        exit_on_bad_outcome(api_3dpm_create_hexa_session(surfMesh_, hexa));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_create_hexa_session(surfMesh_, hexa));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created hexa session\n");
 
-        exit_on_bad_outcome(api_3dpm_compute_mesh(hexa, volMesh, &hexaParams));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_compute_mesh(hexa, volMesh, &hexaParams));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created volume mesh\n");
 
         printf("Total Hexahedron count: %d\n", volMesh.HexahedronCount());
@@ -1227,7 +1328,12 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
         // Create a tetra session that will convert the MeshGems surface mesh into a MeshGems volume mesh containing tetrahedra only.
 
         Spa3dpm::TetraHpcSession  tetra;
-        exit_on_bad_outcome(api_3dpm_create_tetra_hpc_session(surfMesh_, tetra));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_create_tetra_hpc_session(surfMesh_, tetra));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created tetra session\n");
 
         // Set Tetra Parameters
@@ -1248,7 +1354,12 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
         }
 
 
-        exit_on_bad_outcome(api_3dpm_compute_mesh(tetra, volMesh, &tetParams));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_compute_mesh(tetra, volMesh, &tetParams));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created volume mesh\n");
 
         printf("Total Tetrahedron count: %d\n", volMesh.TetrahedronCount());
@@ -1262,7 +1373,12 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
         // Create a tetra session that will convert the MeshGems surface mesh into a MeshGems volume mesh containing tetrahedra only.
 
         Spa3dpm::HybridSession Hybird;
-        exit_on_bad_outcome(api_3dpm_create_hybrid_session(surfMesh_, Hybird));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_create_hybrid_session(surfMesh_, Hybird));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created Hybird session\n");
 
         // Set Tetra Parameters
@@ -1289,14 +1405,24 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
         }
 
 
-        exit_on_bad_outcome(api_3dpm_compute_mesh(Hybird, volMesh, &HybirdParams));
+        msg_str.clear();
+        msg_str=exit_on_bad_outcome(api_3dpm_compute_mesh(Hybird, volMesh, &HybirdParams));
+        if(!msg_str.empty()){
+            emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+            return false;
+        }
         printf("Successfully created volume mesh\n");
 
         printf("Total Tetrahedron count: %d\n", volMesh.TetrahedronCount());
     }
     //print_mesh_info(volMesh); // optional
     //Save the volumen mesh to .mesh (optional)
-    exit_on_bad_outcome(api_3dpm_save_mesh(volMesh, "3dpmSample_volMesh.mesh"));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_3dpm_save_mesh(volMesh, "3dpmSample_volMesh.mesh"));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     printf("Successfully wrote VolMesh to .mesh format\n\n");
     //// Extract CAD-Mesh associativity information
     //meshgems_mesh_t *mg_mesh = volMesh.GetMeshgemsMeshPtr();
@@ -1371,20 +1497,26 @@ void cmdMainProcess::createVol(int istyle,ENTITY_LIST &cells)
     }
 
 
-    exit_on_bad_outcome(api_3dpm_save_mesh(surfMesh_, "3dpmSample_surfMesh.mesh"));
+    msg_str.clear();
+    msg_str=exit_on_bad_outcome(api_3dpm_save_mesh(surfMesh_, "3dpmSample_surfMesh.mesh"));
+    if(!msg_str.empty()){
+        emit LogMsg::getInstance()->send_to_sendClient(object->ToJson("log",msg_str));
+        return false;
+    }
     printf("Successfully wrote vol to .mesh format\n");
 
     //-----
     //7.start show for qy --only for self show
-    QProcess *process = new QProcess;
-    process->setWorkingDirectory("F:\\czm\\qt_demo\\build-test_hoops-Desktop_Qt_5_12_0_MSVC2015_64bit-Debug\\debug\\gmsh");
-    QStringList strLName;
-    strLName << QString(appPath + strName);
-    process->start("F:\\czm\\qt_demo\\build-test_hoops-Desktop_Qt_5_12_0_MSVC2015_64bit-Debug\\debug\\gmsh\\win\\gmsh-git-Windows64-sdk\\bin\\gmsh.exe", strLName);
+//    QProcess *process = new QProcess;
+//    process->setWorkingDirectory("F:\\czm\\qt_demo\\build-test_hoops-Desktop_Qt_5_12_0_MSVC2015_64bit-Debug\\debug\\gmsh");
+//    QStringList strLName;
+//    strLName << QString(appPath + strName);
+//    process->start("F:\\czm\\qt_demo\\build-test_hoops-Desktop_Qt_5_12_0_MSVC2015_64bit-Debug\\debug\\gmsh\\win\\gmsh-git-Windows64-sdk\\bin\\gmsh.exe", strLName);
     if(crw!=NULL){
         delete crw;
         crw = NULL;
     }
+    return true;
 }
 
 //-callbacke

+ 2 - 2
CAE_Solution/src/acis/cmdmainprocess.h

@@ -71,10 +71,10 @@ private:
     bool OutPutSurfMesh(Spa3dpm::MgSession &inSession, Spa3dpm::Mesh &outMesh, const Spa3dpm::Parameters *inParams);
     ENTITY_LIST CreateSelfGeo();
     void CreateLocalSizeMap();
-    void createVol(int, ENTITY_LIST &cells);
+    bool createVol(int, ENTITY_LIST &cells);
 
 
-    void exit_on_bad_outcome(const outcome & o);
+    string exit_on_bad_outcome(const outcome & o);
 //    void iniACIS();
 //    void closeACIS();
     //some