Salome HOME
Update of CheckDone
[modules/smesh.git] / src / DriverMED / DriverMED_R_SMESHDS_Mesh.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH DriverMED : driver to read and write 'med' files
24 //  File   : DriverMED_R_SMESHDS_Mesh.cxx
25 //  Module : SMESH
26
27 #include "DriverMED_R_SMESHDS_Mesh.h"
28
29 #include "DriverMED_Family.h"
30 #include "SMESHDS_Group.hxx"
31 #include "SMESHDS_Mesh.hxx"
32 #include "SMESH_Comment.hxx"
33
34 #include "MED_CoordUtils.hxx"
35 #include "MED_Factory.hxx"
36 #include "MED_Utilities.hxx"
37
38 #include <NCollection_Map.hxx>
39 #include <smIdType.hxx>
40
41 #include "utilities.h"
42
43 //#include <stdlib.h>
44
45 #define _EDF_NODE_IDS_
46
47 using namespace MED;
48 using namespace std;
49
50 typedef std::map<int, DriverMED_FamilyPtr> TID2FamilyMap;
51
52 namespace DriverMED
53 {
54   bool buildMeshGrille(const MED::PWrapper&  theWrapper,
55                        const MED::PMeshInfo& theMeshInfo,
56                        SMESHDS_Mesh*         theMesh,
57                        const TID2FamilyMap&  myFamilies);
58   /*!
59    * \brief Ensure aFamily has a required ID
60    * \param aFamily - a family to check
61    * \param anID - an ID aFamily should have
62    * \param myFamilies - a map of the family ID to the Family
63    * \retval bool  - true if successful
64    */
65   bool checkFamilyID(DriverMED_FamilyPtr & aFamily,
66                      int                   anID,
67                      const TID2FamilyMap&  myFamilies);
68
69
70   const SMDS_MeshNode* FindNode(const SMDS_Mesh* theMesh, TInt theId)
71   {
72     const SMDS_MeshNode* aNode = theMesh->FindNode(theId);
73     if(aNode) return aNode;
74     EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<<theId);
75   }
76
77 }
78
79 //================================================================================
80 /*!
81  * \brief Stores a mesh name
82  */
83 //================================================================================
84
85 void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName)
86 {
87   myMeshName = theMeshName;
88 }
89
90 //================================================================================
91 /*!
92  * \brief Reads a med file
93  */
94 //================================================================================
95
96 Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform()
97 {
98   using namespace DriverMED;
99
100   Status aResult = DRS_FAIL;
101   bool isDescConn = false; // Mantis issue 0020483
102 #ifndef _DEXCEPT_
103   try {
104 #endif
105     myFamilies.clear();
106     MESSAGE("Perform - myFile : "<<myFile);
107     PWrapper aMed = CrWrapperR(myFile);
108
109     aResult = DRS_EMPTY;
110     TInt aNbMeshes = aMed->GetNbMeshes();
111     for (int iMesh = 0; iMesh < aNbMeshes; iMesh++)
112     {
113       // Reading the MED mesh
114       //---------------------
115       PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
116
117       string aMeshName;
118       if (myMeshId != -1) aMeshName = SMESH_Comment( myMeshId );
119       else                aMeshName = myMeshName;
120
121       MESSAGE("Perform - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
122       if ( aMeshName != aMeshInfo->GetName() ) continue;
123       aResult = DRS_OK;
124
125       // Reading MED families to the temporary structure
126       //------------------------------------------------
127       TErr anErr;
128       TInt aNbFams = aMed->GetNbFamilies(aMeshInfo);
129       MESSAGE("Read " << aNbFams << " families");
130       for (TInt iFam = 0; iFam < aNbFams; iFam++)
131       {
132         PFamilyInfo aFamilyInfo = aMed->GetPFamilyInfo(aMeshInfo,iFam+1,&anErr);
133         if(anErr >= 0){
134           TInt aFamId = aFamilyInfo->GetId();
135           MESSAGE("Family " << aFamId << " :");
136
137           DriverMED_FamilyPtr aFamily (new DriverMED_Family);
138
139           TInt aNbGrp = aFamilyInfo->GetNbGroup();
140           MESSAGE("belong to " << aNbGrp << " groups");
141           bool isAttrOk = false;
142           if(aFamilyInfo->GetNbAttr() == aNbGrp)
143             isAttrOk = true;
144           for (TInt iGr = 0; iGr < aNbGrp; iGr++)
145           {
146             string aGroupName = aFamilyInfo->GetGroupName(iGr);
147             if ( isAttrOk ) {
148               TInt anAttrVal = aFamilyInfo->GetAttrVal(iGr);
149               aFamily->SetGroupAttributVal(anAttrVal);
150             }
151             MESSAGE(aGroupName);
152             if ( strncmp( aGroupName.c_str(), NIG_GROUP_PREFIX, strlen(NIG_GROUP_PREFIX) ) != 0 )
153               aFamily->AddGroupName( fixUTF8( aGroupName ));
154           }
155           aFamily->SetId( aFamId );
156           myFamilies[aFamId] = aFamily;
157         }
158       }
159
160       if (aMeshInfo->GetType() == MED::eSTRUCTURE)
161       {
162         /*bool aRes = */DriverMED::buildMeshGrille(aMed,aMeshInfo,myMesh,myFamilies);
163         continue;
164       }
165
166       // Reading MED nodes to the corresponding SMDS structure
167       //------------------------------------------------------
168       PNodeInfo aNodeInfo = aMed->GetPNodeInfo(aMeshInfo);
169       if (!aNodeInfo) {
170         aResult = addMessage("No nodes", /*isFatal=*/true );
171         continue;
172       }
173       aMeshInfo->myDim=aMeshInfo->mySpaceDim;// ignore meshdim in MEDFile because it can be false
174       PCoordHelper aCoordHelper = GetCoordHelper(aNodeInfo);
175
176       EBooleen anIsNodeNum = aNodeInfo->IsElemNum();
177       TInt aNbElems = aNodeInfo->GetNbElem();
178       MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems<<"; anIsNodeNum = "<<anIsNodeNum);
179       DriverMED_FamilyPtr aFamily;
180       for ( TInt iElem = 0; iElem < aNbElems; iElem++ )
181       {
182         TCCoordSlice aCoordSlice = aNodeInfo->GetCoordSlice(iElem);
183         double aCoords[3] = {0.0, 0.0, 0.0};
184         for(TInt iDim = 0; iDim < 3; iDim++)
185           aCoords[iDim] = aCoordHelper->GetCoord(aCoordSlice,iDim);
186         const SMDS_MeshNode* aNode;
187         if ( anIsNodeNum ) {
188           aNode = myMesh->AddNodeWithID
189             (aCoords[0],aCoords[1],aCoords[2],aNodeInfo->GetElemNum(iElem));
190         }
191         else {
192           aNode = myMesh->AddNodeWithID
193             (aCoords[0],aCoords[1],aCoords[2], iElem+1);
194         }
195
196         // Save reference to this node from its family
197         TInt aFamNum = aNodeInfo->GetFamNum(iElem);
198         if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
199         {
200           aFamily->AddElement(aNode);
201           aFamily->SetType(SMDSAbs_Node);
202         }
203       }
204
205       // Are there any MED cells in descending connectivity
206       // Mantis issue 0020483
207       //---------------------------------------------------
208       NCollection_Map<EEntiteMaillage> aDescendingEntitiesMap;
209       if (!isDescConn) {
210         MED::TEntityInfo aEntityInfoDesc = aMed->GetEntityInfo(aMeshInfo, eDESC);
211         MED::TEntityInfo::iterator anEntityIterDesc = aEntityInfoDesc.begin();
212         //for (; anEntityIterDesc != aEntityInfoDesc.end() && !isDescConn; anEntityIterDesc++) {
213         for (; anEntityIterDesc != aEntityInfoDesc.end(); anEntityIterDesc++) {
214           const EEntiteMaillage& anEntity = anEntityIterDesc->first;
215           aDescendingEntitiesMap.Add(anEntity);
216           //if (anEntity != eNOEUD) isDescConn = true;
217         }
218       }
219
220       // Reading pre information about all MED cells
221       //--------------------------------------------
222       typedef MED::TVector<smIdType> TNodeIds;
223       bool takeNumbers = true;  // initially we trust the numbers from file
224       MED::TEntityInfo aEntityInfo = aMed->GetEntityInfo(aMeshInfo, eNOD);
225       MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
226
227       for (; anEntityIter != aEntityInfo.end(); anEntityIter++)
228       {
229         const EEntiteMaillage& anEntity = anEntityIter->first;
230         aDescendingEntitiesMap.Remove(anEntity); // Mantis issue 0020483
231         if (anEntity == eNOEUD) continue;
232
233         // Reading MED cells to the corresponding SMDS structure
234         //------------------------------------------------------
235         const MED::TGeom2Size& aGeom2Size = anEntityIter->second;
236         MED::TGeom2Size::const_iterator aGeom2SizeIter = aGeom2Size.begin();
237         for ( ; aGeom2SizeIter != aGeom2Size.end(); aGeom2SizeIter++)
238         {
239           const EGeometrieElement& aGeom = aGeom2SizeIter->first;
240
241           if ( anEntity == eSTRUCT_ELEMENT ) // MED_BALL (issue 0021459)
242           {
243             PBallInfo aBallInfo = aMed->GetPBallInfo(aMeshInfo);
244             TInt      aNbBalls  = aBallInfo->GetNbElem();
245
246             EBooleen anIsElemNum = takeNumbers ? aBallInfo->IsElemNum() : eFAUX;
247             if ( anIsElemNum && aBallInfo->myElemNum->empty() )
248               anIsElemNum = eFAUX;
249
250             // get supporting nodes
251             TNodeIds aNodeIds;
252 #ifdef _EDF_NODE_IDS_
253             if(anIsNodeNum) {
254               aNodeIds.resize( aNbBalls );
255               for(TInt iBall = 0; iBall < aNbBalls && anIsNodeNum; iBall++)
256               {
257                 aNodeIds[iBall] = aNodeInfo->GetElemNum( (*aBallInfo->myConn)[ iBall ]-1 );
258                 anIsNodeNum = myMesh->FindNode( aNodeIds[iBall] ) ? eVRAI : eFAUX;
259               }
260             }
261 #endif
262             if ( !anIsNodeNum )
263               aNodeIds.assign( aBallInfo->myConn->begin(), aBallInfo->myConn->end());
264
265             // allocate array of diameters
266             vtkIdType maxID = FromSmIdType<vtkIdType>(myMesh->MaxElementID() + aNbBalls);
267             if ( anIsElemNum && !aBallInfo->myElemNum->empty() )
268               maxID = *std::max_element( aBallInfo->myElemNum->begin(),
269                                          aBallInfo->myElemNum->end() );
270             myMesh->GetGrid()->AllocateDiameters( maxID ); // performance optimization
271
272             // create balls
273             SMDS_MeshElement* anElement;
274             DriverMED_FamilyPtr aFamily;
275             for ( TInt iBall = 0; iBall < aNbBalls; iBall++)
276             {
277               anElement = 0;
278               if ( anIsElemNum ) {
279                 if (!(anElement = myMesh->AddBallWithID( aNodeIds[iBall],
280                                                          aBallInfo->myDiameters[iBall],
281                                                          aBallInfo->GetElemNum(iBall))))
282                   anIsElemNum = eFAUX;
283               }
284               if ( !anElement )
285                 myMesh->AddBall( myMesh->FindNode( aNodeIds[iBall]),
286                                  aBallInfo->myDiameters[iBall] );
287
288               // Save reference to this element from its family
289               TInt aFamNum = aBallInfo->GetFamNum(iBall);
290               if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
291               {
292                 aFamily->AddElement(anElement);
293                 aFamily->SetType( SMDSAbs_Ball );
294               }
295             }
296
297             if ( !anIsElemNum &&
298                  ( takeNumbers && aBallInfo->IsElemNum() && !aBallInfo->myElemNum->empty() ))
299               if ( aResult < DRS_WARN_RENUMBER )
300                 aResult = DRS_WARN_RENUMBER;
301
302             continue;
303           } // MED_BALL
304
305           switch(aGeom) {
306           // case ePOINT1: ## PAL16410
307           //     break;
308           case ePOLYGONE:
309           case ePOLYGON2:
310           {
311             PPolygoneInfo aPolygoneInfo = aMed->GetPPolygoneInfo(aMeshInfo,anEntity,aGeom);
312             EBooleen anIsElemNum = takeNumbers ? aPolygoneInfo->IsElemNum() : eFAUX;
313
314             typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolyWithID)
315               (const std::vector<smIdType> & nodes_ids, const smIdType ID);
316             typedef SMDS_MeshFace* (SMESHDS_Mesh::* FAddPolygon)
317               (const std::vector<const SMDS_MeshNode*> & nodes);
318
319             FAddPolyWithID addPolyWithID = & SMESHDS_Mesh::AddPolygonalFaceWithID;
320             FAddPolygon       addPolygon = & SMESHDS_Mesh::AddPolygonalFace;
321             if ( aGeom == ePOLYGON2 ) {
322               addPolyWithID = & SMESHDS_Mesh::AddQuadPolygonalFaceWithID;
323               addPolygon    = & SMESHDS_Mesh::AddQuadPolygonalFace;
324             }
325             TNodeIds aNodeIds;
326             vector<const SMDS_MeshNode*> aNodes;
327             const TInt aNbElem = aPolygoneInfo->GetNbElem();
328             for ( TInt iElem = 0; iElem < aNbElem; iElem++ )
329             {
330               MED::TCConnSlice aConnSlice = aPolygoneInfo->GetConnSlice(iElem);
331               TInt aNbConn = aPolygoneInfo->GetNbConn(iElem);
332               aNodeIds.resize( aNbConn );
333 #ifdef _EDF_NODE_IDS_
334               if(anIsNodeNum)
335                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
336                   aNodeIds[iConn] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
337               else
338                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
339                   aNodeIds[iConn] = aConnSlice[iConn];
340 #else
341               for(TInt iConn = 0; iConn < aNbConn; iConn++)
342                 aNodeIds[iConn] = aConnSlice[iConn];
343 #endif
344               bool isRenum = false;
345               SMDS_MeshElement* anElement = NULL;
346               TInt aFamNum = aPolygoneInfo->GetFamNum(iElem);
347 #ifndef _DEXCEPT_
348               try {
349 #endif
350                 if ( anIsElemNum ) {
351                   TInt anElemId = aPolygoneInfo->GetElemNum( iElem );
352                   anElement = (myMesh->*addPolyWithID)( aNodeIds, ToSmIdType(anElemId) );
353                 }
354                 if ( !anElement ) {
355                   aNodes.resize( aNbConn );
356                   for ( TInt iConn = 0; iConn < aNbConn; iConn++ )
357                     aNodes[iConn] = FindNode( myMesh, aNodeIds[iConn] );
358                   anElement = (myMesh->*addPolygon)( aNodes );
359                   isRenum = anIsElemNum;
360                 }
361 #ifndef _DEXCEPT_
362               } catch(const std::exception& exc) {
363                 aResult = addMessage( exc.what(), /*isFatal=*/true );
364               } catch (...) {
365                 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
366               }
367 #endif
368               if ( !anElement ) {
369                 aResult = DRS_WARN_SKIP_ELEM;
370               }
371               else {
372                 if ( isRenum ) {
373                   anIsElemNum = eFAUX;
374                   takeNumbers = false;
375                   if(aResult < DRS_WARN_RENUMBER)
376                     aResult = DRS_WARN_RENUMBER;
377                 }
378                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
379                 {
380                   // Save reference to this element from its family
381                   aFamily->AddElement(anElement);
382                   aFamily->SetType(anElement->GetType());
383                 }
384               }
385             }
386             break;
387           }
388           case ePOLYEDRE: {
389             PPolyedreInfo aPolyedreInfo = aMed->GetPPolyedreInfo(aMeshInfo,anEntity,aGeom);
390             EBooleen anIsElemNum = takeNumbers ? aPolyedreInfo->IsElemNum() : eFAUX;
391
392             TInt aNbElem = aPolyedreInfo->GetNbElem();
393             for(TInt iElem = 0; iElem < aNbElem; iElem++){
394               MED::TCConnSliceArr aConnSliceArr = aPolyedreInfo->GetConnSliceArr(iElem);
395               TInt aNbFaces = aConnSliceArr.size();
396               typedef MED::TVector<int> TQuantities;
397               TQuantities aQuantities(aNbFaces);
398               TInt aNbNodes = aPolyedreInfo->GetNbNodes(iElem);
399               TNodeIds aNodeIds(aNbNodes);
400               for(TInt iFace = 0, iNode = 0; iFace < aNbFaces; iFace++){
401                 MED::TCConnSlice aConnSlice = aConnSliceArr[iFace];
402                 TInt aNbConn = aConnSlice.size();
403                 aQuantities[iFace] = aNbConn;
404 #ifdef _EDF_NODE_IDS_
405                 if(anIsNodeNum)
406                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
407                   {
408                     aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iConn] - 1);
409                     iNode++;
410                   }
411                 else
412                   for(TInt iConn = 0; iConn < aNbConn; iConn++)
413                   {
414                     aNodeIds[iNode++] = aConnSlice[iConn];
415                   }
416 #else
417                 for(TInt iConn = 0; iConn < aNbConn; iConn++)
418                 {
419                   aNodeIds[iNode++] = aConnSlice[iConn];
420                 }
421 #endif          
422               }
423
424               bool isRenum = false;
425               SMDS_MeshElement* anElement = NULL;
426               TInt aFamNum = aPolyedreInfo->GetFamNum(iElem);
427                 
428 #ifndef _DEXCEPT_
429               try{
430 #endif
431                 if(anIsElemNum){
432                   TInt anElemId = aPolyedreInfo->GetElemNum(iElem);
433                   anElement = myMesh->AddPolyhedralVolumeWithID(aNodeIds,aQuantities,ToSmIdType(anElemId));
434                 }
435                 if(!anElement){
436                   vector<const SMDS_MeshNode*> aNodes(aNbNodes);
437                   for(TInt iConn = 0; iConn < aNbNodes; iConn++)
438                     aNodes[iConn] = FindNode(myMesh,aNodeIds[iConn]);
439                   anElement = myMesh->AddPolyhedralVolume(aNodes,aQuantities);
440                   isRenum = anIsElemNum;
441                 }
442 #ifndef _DEXCEPT_
443               }catch(const std::exception& exc){
444                 aResult = DRS_FAIL;
445               }catch(...){
446                 aResult = DRS_FAIL;
447               }
448 #endif          
449               if(!anElement){
450                 aResult = DRS_WARN_SKIP_ELEM;
451               }else{
452                 if(isRenum){
453                   anIsElemNum = eFAUX;
454                   takeNumbers = false;
455                   if (aResult < DRS_WARN_RENUMBER)
456                     aResult = DRS_WARN_RENUMBER;
457                 }
458                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
459                   // Save reference to this element from its family
460                   aFamily->AddElement(anElement);
461                   aFamily->SetType(anElement->GetType());
462                 }
463               }
464             }
465             break;
466           }
467           default: {
468             PCellInfo aCellInfo = aMed->GetPCellInfo(aMeshInfo,anEntity,aGeom);
469             EBooleen anIsElemNum = takeNumbers ? aCellInfo->IsElemNum() : eFAUX;
470             TInt aNbElems = aCellInfo->GetNbElem();
471             MESSAGE("Perform - anEntity = "<<anEntity<<"; anIsElemNum = "<<anIsElemNum);
472             MESSAGE("Perform - aGeom = "<<aGeom<<"; aNbElems = "<<aNbElems);
473
474             TInt aNbNodes = -1;
475             switch(aGeom){
476             case eSEG2:    aNbNodes = 2;  break;
477             case eSEG3:    aNbNodes = 3;  break;
478             case eTRIA3:   aNbNodes = 3;  break;
479             case eTRIA6:   aNbNodes = 6;  break;
480             case eTRIA7:   aNbNodes = 7;  break;
481             case eQUAD4:   aNbNodes = 4;  break;
482             case eQUAD8:   aNbNodes = 8;  break;
483             case eQUAD9:   aNbNodes = 9;  break;
484             case eTETRA4:  aNbNodes = 4;  break;
485             case eTETRA10: aNbNodes = 10; break;
486             case ePYRA5:   aNbNodes = 5;  break;
487             case ePYRA13:  aNbNodes = 13; break;
488             case ePENTA6:  aNbNodes = 6;  break;
489             case ePENTA15: aNbNodes = 15; break;
490             case ePENTA18: aNbNodes = 18; break;
491             case eHEXA8:   aNbNodes = 8;  break;
492             case eHEXA20:  aNbNodes = 20; break;
493             case eHEXA27:  aNbNodes = 27; break;
494             case eOCTA12:  aNbNodes = 12; break;
495             case ePOINT1:  aNbNodes = 1;  break;
496             default:;
497             }
498             vector<TInt> aNodeIds(aNbNodes);
499             for ( TInt iElem = 0; iElem < aNbElems; iElem++ )
500             {
501               bool anIsValidConnect = false;
502               TCConnSlice aConnSlice = aCellInfo->GetConnSlice(iElem);
503 #ifndef _DEXCEPT_
504               try{
505 #endif
506 #ifdef _EDF_NODE_IDS_
507                 if(anIsNodeNum)
508                   for(int iNode = 0; iNode < aNbNodes; iNode++)
509                     aNodeIds[iNode] = aNodeInfo->GetElemNum(aConnSlice[iNode] - 1);
510                 else
511                   for(int iNode = 0; iNode < aNbNodes; iNode++)
512                     aNodeIds[iNode] = aConnSlice[iNode];
513 #else
514                 for(int iNode = 0; iNode < aNbNodes; iNode++)
515                   aNodeIds[iNode] = aConnSlice[iNode];
516 #endif
517                 anIsValidConnect = true;
518 #ifndef _DEXCEPT_
519               }catch(const std::exception& exc){
520                 INFOS("Following exception was caught:\n\t"<<exc.what());
521                 aResult = addMessage( exc.what(), /*isFatal=*/true );
522               }catch(...){
523                 INFOS("Unknown exception was caught !!!");
524                 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
525               }
526 #endif          
527               if(!anIsValidConnect)
528                 continue;
529
530               bool isRenum = false;
531               const SMDS_MeshElement* anElement = NULL;
532               TInt aFamNum = aCellInfo->GetFamNum(iElem);
533 #ifndef _DEXCEPT_
534               try{
535 #endif
536                 //MESSAGE("Try to create element # " << iElem << " with id = "
537                 //        << aCellInfo->GetElemNum(iElem));
538                 switch(aGeom) {
539                 case ePOINT1:
540                   //anElement = FindNode(myMesh,aNodeIds[0]);
541                   if(anIsElemNum)
542                     anElement = myMesh->Add0DElementWithID
543                       (aNodeIds[0], aCellInfo->GetElemNum(iElem));
544                   if (!anElement) {
545                     anElement = myMesh->Add0DElement(FindNode(myMesh,aNodeIds[0]));
546                     isRenum = anIsElemNum;
547                   }
548                   break;
549                 case eSEG2:
550                   if(anIsElemNum)
551                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
552                                                       aNodeIds[1],
553                                                       aCellInfo->GetElemNum(iElem));
554                   if (!anElement) {
555                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
556                                                 FindNode(myMesh,aNodeIds[1]));
557                     isRenum = anIsElemNum;
558                   }
559                   break;
560                 case eSEG3:
561                   if(anIsElemNum)
562                     anElement = myMesh->AddEdgeWithID(aNodeIds[0],
563                                                       aNodeIds[1],
564                                                       aNodeIds[2],
565                                                       aCellInfo->GetElemNum(iElem));
566                   if (!anElement) {
567                     anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]),
568                                                 FindNode(myMesh,aNodeIds[1]),
569                                                 FindNode(myMesh,aNodeIds[2]));
570                     isRenum = anIsElemNum;
571                   }
572                   break;
573                 case eTRIA3:
574                   aNbNodes = 3;
575                   if(anIsElemNum)
576                     anElement = myMesh->AddFaceWithID(aNodeIds[0],
577                                                       aNodeIds[1],
578                                                       aNodeIds[2],
579                                                       aCellInfo->GetElemNum(iElem));
580                   if (!anElement) {
581                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
582                                                 FindNode(myMesh,aNodeIds[1]),
583                                                 FindNode(myMesh,aNodeIds[2]));
584                     isRenum = anIsElemNum;
585                   }
586                   break;
587                 case eTRIA6:
588                   aNbNodes = 6;
589                   if(anIsElemNum)
590                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
591                                                       aNodeIds[2], aNodeIds[3],
592                                                       aNodeIds[4], aNodeIds[5],
593                                                       aCellInfo->GetElemNum(iElem));
594                   if (!anElement) {
595                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
596                                                 FindNode(myMesh,aNodeIds[1]),
597                                                 FindNode(myMesh,aNodeIds[2]),
598                                                 FindNode(myMesh,aNodeIds[3]),
599                                                 FindNode(myMesh,aNodeIds[4]),
600                                                 FindNode(myMesh,aNodeIds[5]));
601                     isRenum = anIsElemNum;
602                   }
603                   break;
604                 case eTRIA7:
605                   aNbNodes = 7;
606                   if(anIsElemNum)
607                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
608                                                       aNodeIds[2], aNodeIds[3],
609                                                       aNodeIds[4], aNodeIds[5], aNodeIds[6],
610                                                       aCellInfo->GetElemNum(iElem));
611                   if (!anElement) {
612                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
613                                                 FindNode(myMesh,aNodeIds[1]),
614                                                 FindNode(myMesh,aNodeIds[2]),
615                                                 FindNode(myMesh,aNodeIds[3]),
616                                                 FindNode(myMesh,aNodeIds[4]),
617                                                 FindNode(myMesh,aNodeIds[5]),
618                                                 FindNode(myMesh,aNodeIds[6]));
619                     isRenum = anIsElemNum;
620                   }
621                   break;
622                 case eQUAD4:
623                   aNbNodes = 4;
624                   if(anIsElemNum)
625                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
626                                                       aNodeIds[2], aNodeIds[3],
627                                                       aCellInfo->GetElemNum(iElem));
628                   if (!anElement) {
629                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
630                                                 FindNode(myMesh,aNodeIds[1]),
631                                                 FindNode(myMesh,aNodeIds[2]),
632                                                 FindNode(myMesh,aNodeIds[3]));
633                     isRenum = anIsElemNum;
634                   }
635                   break;
636                 case eQUAD8:
637                   aNbNodes = 8;
638                   if(anIsElemNum)
639                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
640                                                       aNodeIds[2], aNodeIds[3],
641                                                       aNodeIds[4], aNodeIds[5],
642                                                       aNodeIds[6], aNodeIds[7],
643                                                       aCellInfo->GetElemNum(iElem));
644                   if (!anElement) {
645                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
646                                                 FindNode(myMesh,aNodeIds[1]),
647                                                 FindNode(myMesh,aNodeIds[2]),
648                                                 FindNode(myMesh,aNodeIds[3]),
649                                                 FindNode(myMesh,aNodeIds[4]),
650                                                 FindNode(myMesh,aNodeIds[5]),
651                                                 FindNode(myMesh,aNodeIds[6]),
652                                                 FindNode(myMesh,aNodeIds[7]));
653                     isRenum = anIsElemNum;
654                   }
655                   break;
656                 case eQUAD9:
657                   aNbNodes = 9;
658                   if(anIsElemNum)
659                     anElement = myMesh->AddFaceWithID(aNodeIds[0], aNodeIds[1],
660                                                       aNodeIds[2], aNodeIds[3],
661                                                       aNodeIds[4], aNodeIds[5],
662                                                       aNodeIds[6], aNodeIds[7], aNodeIds[8],
663                                                       aCellInfo->GetElemNum(iElem));
664                   if (!anElement) {
665                     anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]),
666                                                 FindNode(myMesh,aNodeIds[1]),
667                                                 FindNode(myMesh,aNodeIds[2]),
668                                                 FindNode(myMesh,aNodeIds[3]),
669                                                 FindNode(myMesh,aNodeIds[4]),
670                                                 FindNode(myMesh,aNodeIds[5]),
671                                                 FindNode(myMesh,aNodeIds[6]),
672                                                 FindNode(myMesh,aNodeIds[7]),
673                                                 FindNode(myMesh,aNodeIds[8]));
674                     isRenum = anIsElemNum;
675                   }
676                   break;
677                 case eTETRA4:
678                   aNbNodes = 4;
679                   if(anIsElemNum)
680                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
681                                                         aNodeIds[2], aNodeIds[3],
682                                                         aCellInfo->GetElemNum(iElem));
683                   if (!anElement) {
684                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
685                                                   FindNode(myMesh,aNodeIds[1]),
686                                                   FindNode(myMesh,aNodeIds[2]),
687                                                   FindNode(myMesh,aNodeIds[3]));
688                     isRenum = anIsElemNum;
689                   }
690                   break;
691                 case eTETRA10:
692                   aNbNodes = 10;
693                   if(anIsElemNum)
694                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
695                                                         aNodeIds[2], aNodeIds[3],
696                                                         aNodeIds[4], aNodeIds[5],
697                                                         aNodeIds[6], aNodeIds[7],
698                                                         aNodeIds[8], aNodeIds[9],
699                                                         aCellInfo->GetElemNum(iElem));
700                   if (!anElement) {
701                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
702                                                   FindNode(myMesh,aNodeIds[1]),
703                                                   FindNode(myMesh,aNodeIds[2]),
704                                                   FindNode(myMesh,aNodeIds[3]),
705                                                   FindNode(myMesh,aNodeIds[4]),
706                                                   FindNode(myMesh,aNodeIds[5]),
707                                                   FindNode(myMesh,aNodeIds[6]),
708                                                   FindNode(myMesh,aNodeIds[7]),
709                                                   FindNode(myMesh,aNodeIds[8]),
710                                                   FindNode(myMesh,aNodeIds[9]));
711                     isRenum = anIsElemNum;
712                   }
713                   break;
714                 case ePYRA5:
715                   aNbNodes = 5;
716                   if(anIsElemNum)
717                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
718                                                         aNodeIds[2], aNodeIds[3],
719                                                         aNodeIds[4],
720                                                         aCellInfo->GetElemNum(iElem));
721                   if (!anElement) {
722                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
723                                                   FindNode(myMesh,aNodeIds[1]),
724                                                   FindNode(myMesh,aNodeIds[2]),
725                                                   FindNode(myMesh,aNodeIds[3]),
726                                                   FindNode(myMesh,aNodeIds[4]));
727                     isRenum = anIsElemNum;
728                   }
729                   break;
730                 case ePYRA13:
731                   aNbNodes = 13;
732                   if(anIsElemNum)
733                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
734                                                         aNodeIds[2], aNodeIds[3],
735                                                         aNodeIds[4], aNodeIds[5],
736                                                         aNodeIds[6], aNodeIds[7],
737                                                         aNodeIds[8], aNodeIds[9],
738                                                         aNodeIds[10], aNodeIds[11],
739                                                         aNodeIds[12],
740                                                         aCellInfo->GetElemNum(iElem));
741                   if (!anElement) {
742                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
743                                                   FindNode(myMesh,aNodeIds[1]),
744                                                   FindNode(myMesh,aNodeIds[2]),
745                                                   FindNode(myMesh,aNodeIds[3]),
746                                                   FindNode(myMesh,aNodeIds[4]),
747                                                   FindNode(myMesh,aNodeIds[5]),
748                                                   FindNode(myMesh,aNodeIds[6]),
749                                                   FindNode(myMesh,aNodeIds[7]),
750                                                   FindNode(myMesh,aNodeIds[8]),
751                                                   FindNode(myMesh,aNodeIds[9]),
752                                                   FindNode(myMesh,aNodeIds[10]),
753                                                   FindNode(myMesh,aNodeIds[11]),
754                                                   FindNode(myMesh,aNodeIds[12]));
755                     isRenum = anIsElemNum;
756                   }
757                   break;
758                 case ePENTA6:
759                   aNbNodes = 6;
760                   if(anIsElemNum)
761                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
762                                                         aNodeIds[1],
763                                                         aNodeIds[2],
764                                                         aNodeIds[3],
765                                                         aNodeIds[4],
766                                                         aNodeIds[5],
767                                                         aCellInfo->GetElemNum(iElem));
768                   if (!anElement) {
769                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
770                                                   FindNode(myMesh,aNodeIds[1]),
771                                                   FindNode(myMesh,aNodeIds[2]),
772                                                   FindNode(myMesh,aNodeIds[3]),
773                                                   FindNode(myMesh,aNodeIds[4]),
774                                                   FindNode(myMesh,aNodeIds[5]));
775                     isRenum = anIsElemNum;
776                   }
777                   break;
778                 case ePENTA15:
779                   aNbNodes = 15;
780                   if(anIsElemNum)
781                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
782                                                         aNodeIds[2], aNodeIds[3],
783                                                         aNodeIds[4], aNodeIds[5],
784                                                         aNodeIds[6], aNodeIds[7],
785                                                         aNodeIds[8], aNodeIds[9],
786                                                         aNodeIds[10], aNodeIds[11],
787                                                         aNodeIds[12], aNodeIds[13],
788                                                         aNodeIds[14],
789                                                         aCellInfo->GetElemNum(iElem));
790                   if (!anElement) {
791                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
792                                                   FindNode(myMesh,aNodeIds[1]),
793                                                   FindNode(myMesh,aNodeIds[2]),
794                                                   FindNode(myMesh,aNodeIds[3]),
795                                                   FindNode(myMesh,aNodeIds[4]),
796                                                   FindNode(myMesh,aNodeIds[5]),
797                                                   FindNode(myMesh,aNodeIds[6]),
798                                                   FindNode(myMesh,aNodeIds[7]),
799                                                   FindNode(myMesh,aNodeIds[8]),
800                                                   FindNode(myMesh,aNodeIds[9]),
801                                                   FindNode(myMesh,aNodeIds[10]),
802                                                   FindNode(myMesh,aNodeIds[11]),
803                                                   FindNode(myMesh,aNodeIds[12]),
804                                                   FindNode(myMesh,aNodeIds[13]),
805                                                   FindNode(myMesh,aNodeIds[14]));
806                     isRenum = anIsElemNum;
807                   }
808                   break;
809                 case ePENTA18:
810                   aNbNodes = 18;
811                   if(anIsElemNum)
812                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
813                                                         aNodeIds[2], aNodeIds[3],
814                                                         aNodeIds[4], aNodeIds[5],
815                                                         aNodeIds[6], aNodeIds[7],
816                                                         aNodeIds[8], aNodeIds[9],
817                                                         aNodeIds[10], aNodeIds[11],
818                                                         aNodeIds[12], aNodeIds[13],
819                                                         aNodeIds[14], aNodeIds[15],
820                                                         aNodeIds[16], aNodeIds[17],
821                                                         aCellInfo->GetElemNum(iElem));
822                   if (!anElement) {
823                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
824                                                   FindNode(myMesh,aNodeIds[1]),
825                                                   FindNode(myMesh,aNodeIds[2]),
826                                                   FindNode(myMesh,aNodeIds[3]),
827                                                   FindNode(myMesh,aNodeIds[4]),
828                                                   FindNode(myMesh,aNodeIds[5]),
829                                                   FindNode(myMesh,aNodeIds[6]),
830                                                   FindNode(myMesh,aNodeIds[7]),
831                                                   FindNode(myMesh,aNodeIds[8]),
832                                                   FindNode(myMesh,aNodeIds[9]),
833                                                   FindNode(myMesh,aNodeIds[10]),
834                                                   FindNode(myMesh,aNodeIds[11]),
835                                                   FindNode(myMesh,aNodeIds[12]),
836                                                   FindNode(myMesh,aNodeIds[13]),
837                                                   FindNode(myMesh,aNodeIds[14]),
838                                                   FindNode(myMesh,aNodeIds[15]),
839                                                   FindNode(myMesh,aNodeIds[16]),
840                                                   FindNode(myMesh,aNodeIds[17]));
841                     isRenum = anIsElemNum;
842                   }
843                   break;
844                 case eHEXA8:
845                   aNbNodes = 8;
846                   if(anIsElemNum)
847                     anElement = myMesh->AddVolumeWithID(aNodeIds[0],
848                                                         aNodeIds[1],
849                                                         aNodeIds[2],
850                                                         aNodeIds[3],
851                                                         aNodeIds[4],
852                                                         aNodeIds[5],
853                                                         aNodeIds[6],
854                                                         aNodeIds[7],
855                                                         aCellInfo->GetElemNum(iElem));
856                   if (!anElement) {
857                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
858                                                   FindNode(myMesh,aNodeIds[1]),
859                                                   FindNode(myMesh,aNodeIds[2]),
860                                                   FindNode(myMesh,aNodeIds[3]),
861                                                   FindNode(myMesh,aNodeIds[4]),
862                                                   FindNode(myMesh,aNodeIds[5]),
863                                                   FindNode(myMesh,aNodeIds[6]),
864                                                   FindNode(myMesh,aNodeIds[7]));
865                     isRenum = anIsElemNum;
866                   }
867                   break;
868
869                 case eHEXA20:
870                   aNbNodes = 20;
871                   if(anIsElemNum)
872                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
873                                                         aNodeIds[2], aNodeIds[3],
874                                                         aNodeIds[4], aNodeIds[5],
875                                                         aNodeIds[6], aNodeIds[7],
876                                                         aNodeIds[8], aNodeIds[9],
877                                                         aNodeIds[10], aNodeIds[11],
878                                                         aNodeIds[12], aNodeIds[13],
879                                                         aNodeIds[14], aNodeIds[15],
880                                                         aNodeIds[16], aNodeIds[17],
881                                                         aNodeIds[18], aNodeIds[19],
882                                                         aCellInfo->GetElemNum(iElem));
883                   if (!anElement) {
884                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
885                                                   FindNode(myMesh,aNodeIds[1]),
886                                                   FindNode(myMesh,aNodeIds[2]),
887                                                   FindNode(myMesh,aNodeIds[3]),
888                                                   FindNode(myMesh,aNodeIds[4]),
889                                                   FindNode(myMesh,aNodeIds[5]),
890                                                   FindNode(myMesh,aNodeIds[6]),
891                                                   FindNode(myMesh,aNodeIds[7]),
892                                                   FindNode(myMesh,aNodeIds[8]),
893                                                   FindNode(myMesh,aNodeIds[9]),
894                                                   FindNode(myMesh,aNodeIds[10]),
895                                                   FindNode(myMesh,aNodeIds[11]),
896                                                   FindNode(myMesh,aNodeIds[12]),
897                                                   FindNode(myMesh,aNodeIds[13]),
898                                                   FindNode(myMesh,aNodeIds[14]),
899                                                   FindNode(myMesh,aNodeIds[15]),
900                                                   FindNode(myMesh,aNodeIds[16]),
901                                                   FindNode(myMesh,aNodeIds[17]),
902                                                   FindNode(myMesh,aNodeIds[18]),
903                                                   FindNode(myMesh,aNodeIds[19]));
904                     isRenum = anIsElemNum;
905                   }
906                   break;
907
908                 case eHEXA27:
909                   aNbNodes = 27;
910                   if(anIsElemNum)
911                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
912                                                         aNodeIds[2], aNodeIds[3],
913                                                         aNodeIds[4], aNodeIds[5],
914                                                         aNodeIds[6], aNodeIds[7],
915                                                         aNodeIds[8], aNodeIds[9],
916                                                         aNodeIds[10], aNodeIds[11],
917                                                         aNodeIds[12], aNodeIds[13],
918                                                         aNodeIds[14], aNodeIds[15],
919                                                         aNodeIds[16], aNodeIds[17],
920                                                         aNodeIds[18], aNodeIds[19],
921                                                         aNodeIds[20], aNodeIds[21],
922                                                         aNodeIds[22], aNodeIds[23],
923                                                         aNodeIds[24], aNodeIds[25],
924                                                         aNodeIds[26],
925                                                         aCellInfo->GetElemNum(iElem));
926                   if (!anElement) {
927                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
928                                                   FindNode(myMesh,aNodeIds[1]),
929                                                   FindNode(myMesh,aNodeIds[2]),
930                                                   FindNode(myMesh,aNodeIds[3]),
931                                                   FindNode(myMesh,aNodeIds[4]),
932                                                   FindNode(myMesh,aNodeIds[5]),
933                                                   FindNode(myMesh,aNodeIds[6]),
934                                                   FindNode(myMesh,aNodeIds[7]),
935                                                   FindNode(myMesh,aNodeIds[8]),
936                                                   FindNode(myMesh,aNodeIds[9]),
937                                                   FindNode(myMesh,aNodeIds[10]),
938                                                   FindNode(myMesh,aNodeIds[11]),
939                                                   FindNode(myMesh,aNodeIds[12]),
940                                                   FindNode(myMesh,aNodeIds[13]),
941                                                   FindNode(myMesh,aNodeIds[14]),
942                                                   FindNode(myMesh,aNodeIds[15]),
943                                                   FindNode(myMesh,aNodeIds[16]),
944                                                   FindNode(myMesh,aNodeIds[17]),
945                                                   FindNode(myMesh,aNodeIds[18]),
946                                                   FindNode(myMesh,aNodeIds[19]),
947                                                   FindNode(myMesh,aNodeIds[20]),
948                                                   FindNode(myMesh,aNodeIds[21]),
949                                                   FindNode(myMesh,aNodeIds[22]),
950                                                   FindNode(myMesh,aNodeIds[23]),
951                                                   FindNode(myMesh,aNodeIds[24]),
952                                                   FindNode(myMesh,aNodeIds[25]),
953                                                   FindNode(myMesh,aNodeIds[26]));
954                     isRenum = anIsElemNum;
955                   }
956                   break;
957
958                 case eOCTA12:
959                   aNbNodes = 12;
960                   if(anIsElemNum)
961                     anElement = myMesh->AddVolumeWithID(aNodeIds[0], aNodeIds[1],
962                                                         aNodeIds[2], aNodeIds[3],
963                                                         aNodeIds[4], aNodeIds[5],
964                                                         aNodeIds[6], aNodeIds[7],
965                                                         aNodeIds[8], aNodeIds[9],
966                                                         aNodeIds[10], aNodeIds[11],
967                                                         aCellInfo->GetElemNum(iElem));
968                   if (!anElement) {
969                     anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]),
970                                                   FindNode(myMesh,aNodeIds[1]),
971                                                   FindNode(myMesh,aNodeIds[2]),
972                                                   FindNode(myMesh,aNodeIds[3]),
973                                                   FindNode(myMesh,aNodeIds[4]),
974                                                   FindNode(myMesh,aNodeIds[5]),
975                                                   FindNode(myMesh,aNodeIds[6]),
976                                                   FindNode(myMesh,aNodeIds[7]),
977                                                   FindNode(myMesh,aNodeIds[8]),
978                                                   FindNode(myMesh,aNodeIds[9]),
979                                                   FindNode(myMesh,aNodeIds[10]),
980                                                   FindNode(myMesh,aNodeIds[11]));
981                     isRenum = anIsElemNum;
982                   }
983                   break;
984
985                 default:;
986
987                 } // switch(aGeom)
988
989 #ifndef _DEXCEPT_
990               } catch(const std::exception& exc) {
991                 INFOS("The following exception was caught:\n\t"<<exc.what());
992                 aResult = addMessage( exc.what(), /*isFatal=*/true );
993               } catch(...) {
994                 INFOS("Unknown exception was caught !!!");
995                 aResult = addMessage( "Unknown exception", /*isFatal=*/true );
996               }
997 #endif
998               if (!anElement) {
999                 aResult = DRS_WARN_SKIP_ELEM;
1000               }
1001               else {
1002                 if (isRenum) {
1003                   anIsElemNum = eFAUX;
1004                   takeNumbers = false;
1005                   if (aResult < DRS_WARN_RENUMBER)
1006                     aResult = DRS_WARN_RENUMBER;
1007                 }
1008                 if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )) {
1009                   // Save reference to this element from its family
1010                   aFamily->AddElement(anElement);
1011                   aFamily->SetType(anElement->GetType());
1012                 }
1013               }
1014             } // loop on aNbElems
1015           }} // switch(aGeom)
1016         } // loop on aGeom2Size
1017       } // loop on aEntityInfo
1018
1019       if (aDescendingEntitiesMap.Extent()) isDescConn = true; // Mantis issue 0020483
1020
1021     } // for(int iMesh = 0; iMesh < aNbMeshes; iMesh++)
1022 #ifndef _DEXCEPT_
1023   }
1024   catch(const std::exception& exc)
1025   {
1026     INFOS("The following exception was caught:\n\t"<<exc.what());
1027     aResult = addMessage( exc.what(), /*isFatal=*/true );
1028   }
1029   catch(...)
1030   {
1031     INFOS("Unknown exception was caught !!!");
1032     aResult = addMessage( "Unknown exception", /*isFatal=*/true );
1033   }
1034 #endif
1035
1036   // Mantis issue 0020483
1037   if (aResult == DRS_OK && isDescConn) {
1038     INFOS("There are some elements in descending connectivity in med file. They were not read !!!");
1039     aResult = DRS_WARN_DESCENDING;
1040   }
1041
1042   MESSAGE("Perform - aResult status = "<<aResult);
1043   return aResult;
1044 }
1045
1046 list<string> DriverMED_R_SMESHDS_Mesh::GetMeshNames(Status& theStatus)
1047 {
1048   list<string> aMeshNames;
1049
1050   try {
1051     MESSAGE("GetMeshNames - myFile : " << myFile);
1052     theStatus = DRS_OK;
1053     PWrapper aMed = CrWrapperR(myFile);
1054
1055     if (TInt aNbMeshes = aMed->GetNbMeshes()) {
1056       for (int iMesh = 0; iMesh < aNbMeshes; iMesh++) {
1057         // Reading the MED mesh
1058         //---------------------
1059         PMeshInfo aMeshInfo = aMed->GetPMeshInfo(iMesh+1);
1060         aMeshNames.push_back(aMeshInfo->GetName());
1061       }
1062     }
1063   } catch(const std::exception& exc) {
1064     INFOS("Following exception was caught:\n\t"<<exc.what());
1065     theStatus = DRS_FAIL;
1066   } catch(...) {
1067     INFOS("Unknown exception was caught !!!");
1068     theStatus = DRS_FAIL;
1069   }
1070
1071   return aMeshNames;
1072 }
1073
1074 list<TNameAndType> DriverMED_R_SMESHDS_Mesh::GetGroupNamesAndTypes()
1075 {
1076   list<TNameAndType> aResult;
1077   set<TNameAndType> aResGroupNames;
1078
1079   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1080   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1081   {
1082     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1083     const MED::TStringSet& aGroupNames = aFamily->GetGroupNames();
1084     set<string>::const_iterator aGrNamesIter = aGroupNames.begin();
1085     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1086     {
1087       const ElemTypeSet& types = aFamily->GetTypes();
1088       ElemTypeSet::const_iterator type = types.begin();
1089       for ( ; type != types.end(); ++type )
1090       {
1091         TNameAndType aNameAndType = make_pair( *aGrNamesIter, *type );
1092         if ( aResGroupNames.insert( aNameAndType ).second ) {
1093           aResult.push_back( aNameAndType );
1094         }
1095       }
1096     }
1097   }
1098
1099   return aResult;
1100 }
1101
1102 void DriverMED_R_SMESHDS_Mesh::GetGroup(SMESHDS_Group* theGroup)
1103 {
1104   TFamilyVec * famVecPtr;
1105
1106   if ( myGroups2FamiliesMap.IsEmpty() ) // PAL23514
1107   {
1108     TFamilyVec famVector( 1 );
1109     map<int, DriverMED_FamilyPtr>::iterator famIter = myFamilies.begin();
1110     for ( ; famIter != myFamilies.end(); famIter++ )
1111     {
1112       DriverMED_FamilyPtr    family = famIter->second;
1113       const MED::TStringSet& groups = family->GetGroupNames();
1114       famVector[ 0 ] = family;
1115       MED::TStringSet::const_iterator grpIter = groups.begin();
1116       for ( ; grpIter != groups.end(); ++grpIter )
1117       {
1118         TCollection_AsciiString groupName = grpIter->c_str();
1119         if (( famVecPtr = myGroups2FamiliesMap.ChangeSeek( groupName )))
1120           famVecPtr->push_back( family );
1121         else
1122           myGroups2FamiliesMap.Bind( groupName, famVector );
1123       }
1124     }
1125   }
1126
1127   const char* aGroupName = theGroup->GetStoreName();
1128   MESSAGE("Get Group " << aGroupName);
1129
1130   if (( famVecPtr = myGroups2FamiliesMap.ChangeSeek( aGroupName )))
1131   {
1132     size_t groupSize = 0;
1133     for ( size_t i = 0; i < famVecPtr->size(); ++i )
1134     {
1135       DriverMED_FamilyPtr aFamily = (*famVecPtr)[i];
1136       groupSize += aFamily->NbElements( theGroup->GetType() );
1137     }
1138     theGroup->SMDSGroup().Reserve( groupSize );
1139
1140     for ( size_t i = 0; i < famVecPtr->size(); ++i )
1141     {
1142       DriverMED_FamilyPtr aFamily = (*famVecPtr)[i];
1143       if ( aFamily->GetTypes().count( theGroup->GetType() ))
1144       {
1145         const ElementsSet&           anElements = aFamily->GetElements();
1146         ElementsSet::const_iterator anElemsIter = anElements.begin();
1147         for (; anElemsIter != anElements.end(); anElemsIter++)
1148         {
1149           const SMDS_MeshElement * element = *anElemsIter;
1150           if ( element->GetType() == theGroup->GetType() ) // Issue 0020576
1151             theGroup->SMDSGroup().Add(element);
1152         }
1153         int aGroupAttrVal = aFamily->GetGroupAttributVal();
1154         if( aGroupAttrVal != 0 )
1155           theGroup->SetColorGroup(aGroupAttrVal);
1156       }
1157     }
1158   }
1159 }
1160
1161 void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh,
1162                                            const int theId)
1163 {
1164   char submeshGrpName[ 30 ];
1165   sprintf( submeshGrpName, "SubMesh %d", theId );
1166   string aName (submeshGrpName);
1167   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1168   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1169   {
1170     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1171     if (aFamily->MemberOf(aName))
1172     {
1173       const ElementsSet&           anElements = aFamily->GetElements();
1174       ElementsSet::const_iterator anElemsIter = anElements.begin();
1175       if (aFamily->GetType() == SMDSAbs_Node)
1176       {
1177         for (; anElemsIter != anElements.end(); anElemsIter++)
1178         {
1179           const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>(*anElemsIter);
1180           theSubMesh->AddNode(node);
1181         }
1182       }
1183       else
1184       {
1185         for (; anElemsIter != anElements.end(); anElemsIter++)
1186         {
1187           theSubMesh->AddElement(*anElemsIter);
1188         }
1189       }
1190     }
1191   }
1192 }
1193
1194 void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes ()
1195 {
1196   map<int, DriverMED_FamilyPtr>::iterator aFamsIter = myFamilies.begin();
1197   for (; aFamsIter != myFamilies.end(); aFamsIter++)
1198   {
1199     DriverMED_FamilyPtr aFamily = (*aFamsIter).second;
1200     MED::TStringSet aGroupNames = aFamily->GetGroupNames();
1201     set<string>::iterator aGrNamesIter = aGroupNames.begin();
1202     for (; aGrNamesIter != aGroupNames.end(); aGrNamesIter++)
1203     {
1204       string aName = *aGrNamesIter;
1205       // Check, if this is a Group or SubMesh name
1206       if (aName.substr(0, 7) == string("SubMesh"))
1207       {
1208         int Id = atoi(string(aName).substr(7).c_str());
1209         const ElementsSet&           anElements = aFamily->GetElements();
1210         ElementsSet::const_iterator anElemsIter = anElements.begin();
1211         if (aFamily->GetType() == SMDSAbs_Node)
1212         {
1213           for (; anElemsIter != anElements.end(); anElemsIter++)
1214           {
1215             const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( *anElemsIter );
1216             // find out a shape type
1217             TopoDS_Shape aShape = myMesh->IndexToShape( Id );
1218             int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() );
1219             switch ( aShapeType ) {
1220             case TopAbs_FACE:
1221               myMesh->SetNodeOnFace(node, Id); break;
1222             case TopAbs_EDGE:
1223               myMesh->SetNodeOnEdge(node, Id); break;
1224             case TopAbs_VERTEX:
1225               myMesh->SetNodeOnVertex(node, Id); break;
1226             default:
1227               myMesh->SetNodeInVolume(node, Id);
1228             }
1229           }
1230         }
1231         else
1232         {
1233           for (; anElemsIter != anElements.end(); anElemsIter++)
1234           {
1235             myMesh->SetMeshElementOnShape(*anElemsIter, Id);
1236           }
1237         }
1238       }
1239     }
1240   }
1241 }
1242 /*!
1243  * \brief Ensure aFamily to have required ID
1244  * \param aFamily - a family to check and update
1245  * \param anID - an ID aFamily should have
1246  * \retval bool  - true if successful
1247  */
1248 bool DriverMED::checkFamilyID(DriverMED_FamilyPtr & aFamily,
1249                               int                   anID,
1250                               const TID2FamilyMap&  myFamilies)
1251 {
1252   if ( !aFamily || aFamily->GetId() != anID ) {
1253     map<int, DriverMED_FamilyPtr>::const_iterator i_fam = myFamilies.find(anID);
1254     if ( i_fam == myFamilies.end() )
1255       return false;
1256     aFamily = i_fam->second;
1257   }
1258   return ( aFamily->GetId() == anID );
1259 }
1260
1261 /*!
1262  * \brief Reading the structured mesh and convert to non structured
1263  *        (by filling of smesh structure for non structured mesh)
1264  * \param theWrapper  - PWrapper const pointer
1265  * \param theMeshInfo - PMeshInfo const pointer
1266  * \param myFamilies  - a map of the family ID to the Family
1267  * \return TRUE, if successfully. Else FALSE
1268  */
1269 bool DriverMED::buildMeshGrille(const MED::PWrapper&  theWrapper,
1270                                 const MED::PMeshInfo& theMeshInfo,
1271                                 SMESHDS_Mesh*         myMesh,
1272                                 const TID2FamilyMap&  myFamilies)
1273 {
1274   bool res = true;
1275
1276   MED::PGrilleInfo aGrilleInfo = theWrapper->GetPGrilleInfo(theMeshInfo);
1277   MED::TInt aNbNodes = aGrilleInfo->GetNbNodes();
1278   MED::TInt aNbCells = aGrilleInfo->GetNbCells();
1279   MED::TInt aMeshDim = theMeshInfo->GetDim();
1280   DriverMED_FamilyPtr aFamily;
1281   for(MED::TInt iNode=0;iNode < aNbNodes; iNode++){
1282     double aCoords[3] = {0.0, 0.0, 0.0};
1283     const SMDS_MeshNode* aNode;
1284     MED::TNodeCoord aMEDNodeCoord = aGrilleInfo->GetCoord(iNode);
1285     for(MED::TInt iDim=0;iDim<aMeshDim;iDim++)
1286       aCoords[(int)iDim] = aMEDNodeCoord[(int)iDim];
1287     aNode = myMesh->AddNodeWithID(aCoords[0],aCoords[1],aCoords[2],iNode+1);
1288     if (!aNode) {
1289       EXCEPTION(runtime_error,"buildMeshGrille Error. Node not created! "<<(int)iNode);
1290     }
1291
1292     if((aGrilleInfo->myFamNumNode).size() > 0){
1293       TInt aFamNum = aGrilleInfo->GetFamNumNode(iNode);
1294       if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies ))
1295         {
1296           aFamily->AddElement(aNode);
1297           aFamily->SetType(SMDSAbs_Node);
1298         }
1299     }
1300     
1301   }
1302
1303   SMDS_MeshElement* anElement = NULL;
1304   MED::TIntVector aNodeIds;
1305   for(MED::TInt iCell=0;iCell < aNbCells; iCell++){
1306     aNodeIds = aGrilleInfo->GetConn(iCell);
1307     switch(aGrilleInfo->GetGeom()){
1308     case MED::eSEG2:
1309       if(aNodeIds.size() != 2){
1310         res = false;
1311         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 2!="<<aNodeIds.size());
1312       }
1313       anElement = myMesh->AddEdgeWithID(aNodeIds[0]+1,
1314                                         aNodeIds[1]+1,
1315                                         iCell+1);
1316       break;
1317     case MED::eQUAD4:
1318       if(aNodeIds.size() != 4){
1319         res = false;
1320         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 4!="<<aNodeIds.size());
1321       }
1322       anElement = myMesh->AddFaceWithID(aNodeIds[0]+1,
1323                                         aNodeIds[2]+1,
1324                                         aNodeIds[3]+1,
1325                                         aNodeIds[1]+1,
1326                                         iCell+1);
1327       break;
1328     case MED::eHEXA8:
1329       if(aNodeIds.size() != 8){
1330         res = false;
1331         EXCEPTION(runtime_error,"buildMeshGrille Error. Incorrect size of ids 8!="<<aNodeIds.size());
1332       }
1333       anElement = myMesh->AddVolumeWithID(aNodeIds[0]+1,
1334                                           aNodeIds[2]+1,
1335                                           aNodeIds[3]+1,
1336                                           aNodeIds[1]+1,
1337                                           aNodeIds[4]+1,
1338                                           aNodeIds[6]+1,
1339                                           aNodeIds[7]+1,
1340                                           aNodeIds[5]+1,
1341                                           iCell+1);
1342       break;
1343     default:
1344       break;
1345     }
1346     if (!anElement) {
1347       EXCEPTION(runtime_error,"buildMeshGrille Error. Element not created! "<<iCell);
1348     }
1349     if((aGrilleInfo->myFamNum).size() > 0){
1350       TInt aFamNum = aGrilleInfo->GetFamNum(iCell);
1351       if ( DriverMED::checkFamilyID ( aFamily, aFamNum, myFamilies )){
1352         aFamily->AddElement(anElement);
1353         aFamily->SetType(anElement->GetType());
1354       }
1355     }
1356   }
1357
1358   return res;
1359 }