+
+ // iterator on elements of a current type
+ SMDS_ElemIteratorPtr elemIterator;
+ int iElem = 0;
+
+ // Treat POLYGONs
+ // ---------------
+ if ( aElemTypeData->_geomType == ePOLYGONE )
+ {
+ elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYGON );
+ if ( nbPolygonNodes == 0 ) {
+ // Count nb of nodes
+ while ( elemIterator->more() ) {
+ const SMDS_MeshElement* anElem = elemIterator->next();
+ nbPolygonNodes += anElem->NbNodes();
+ if ( ++iElem == aElemTypeData->_nbElems )
+ break;
+ }
+ }
+ else {
+ // Store in med file
+ PPolygoneInfo aPolygoneInfo = myMed->CrPolygoneInfo(aMeshInfo,
+ aElemTypeData->_entity,
+ aElemTypeData->_geomType,
+ aElemTypeData->_nbElems,
+ nbPolygonNodes,
+ theConnMode, theIsElemNum,
+ theIsElemNames);
+ TElemNum & index = *(aPolygoneInfo->myIndex.get());
+ index[0] = 1;
+
+ while ( elemIterator->more() )
+ {
+ const SMDS_MeshElement* anElem = elemIterator->next();
+ // index
+ TInt aNbNodes = anElem->NbNodes();
+ index[ iElem+1 ] = index[ iElem ] + aNbNodes;
+
+ // connectivity
+ TConnSlice aTConnSlice = aPolygoneInfo->GetConnSlice( iElem );
+ for(TInt iNode = 0; iNode < aNbNodes; iNode++) {
+ const SMDS_MeshElement* aNode = anElem->GetNode( iNode );
+#ifdef _EDF_NODE_IDS_
+ aTConnSlice[ iNode ] = aNodeIdMap[aNode->GetID()];
+#else
+ aTConnSlice[ iNode ] = aNode->GetID();
+#endif
+ }
+ // element number
+ aPolygoneInfo->SetElemNum( iElem, anElem->GetID() );
+
+ // family number
+ int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
+ aPolygoneInfo->SetFamNum( iElem, famNum );
+
+ if ( ++iElem == aPolygoneInfo->GetNbElem() )
+ break;
+ }
+ myMed->SetPolygoneInfo(aPolygoneInfo);
+ }
+
+ }
+
+ // Treat POLYEDREs
+ // ----------------
+ else if (aElemTypeData->_geomType == ePOLYEDRE )
+ {
+ elemIterator = myMesh->elementGeomIterator( SMDSGeom_POLYHEDRA );
+
+ if ( nbPolyhedronNodes == 0 ) {
+ // Count nb of nodes
+ while ( elemIterator->more() ) {
+ const SMDS_MeshElement* anElem = elemIterator->next();
+ const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
+ if ( !aPolyedre ) continue;
+ nbPolyhedronNodes += aPolyedre->NbNodes();
+ nbPolyhedronFaces += aPolyedre->NbFaces();
+ if ( ++iElem == aElemTypeData->_nbElems )
+ break;
+ }
+ }
+ else {
+ // Store in med file
+ PPolyedreInfo aPolyhInfo = myMed->CrPolyedreInfo(aMeshInfo,
+ aElemTypeData->_entity,
+ aElemTypeData->_geomType,
+ aElemTypeData->_nbElems,
+ nbPolyhedronFaces+1,
+ nbPolyhedronNodes,
+ theConnMode,
+ theIsElemNum,
+ theIsElemNames);
+ TElemNum & index = *(aPolyhInfo->myIndex.get());
+ TElemNum & faces = *(aPolyhInfo->myFaces.get());
+ TElemNum & conn = *(aPolyhInfo->myConn.get());
+ index[0] = 1;
+ faces[0] = 1;
+
+ TInt iFace = 0, iNode = 0;
+ while ( elemIterator->more() )
+ {
+ const SMDS_MeshElement* anElem = elemIterator->next();
+ const SMDS_VtkVolume *aPolyedre = dynamic_cast<const SMDS_VtkVolume*>(anElem);
+ if ( !aPolyedre ) continue;
+ // index
+ TInt aNbFaces = aPolyedre->NbFaces();
+ index[ iElem+1 ] = index[ iElem ] + aNbFaces;
+
+ // face index
+ for (TInt f = 1; f <= aNbFaces; ++f, ++iFace ) {
+ int aNbFaceNodes = aPolyedre->NbFaceNodes( f );
+ faces[ iFace+1 ] = faces[ iFace ] + aNbFaceNodes;
+ }
+ // connectivity
+ SMDS_ElemIteratorPtr nodeIt = anElem->nodesIterator();
+ while ( nodeIt->more() ) {
+ const SMDS_MeshElement* aNode = nodeIt->next();
+#ifdef _EDF_NODE_IDS_
+ conn[ iNode ] = aNodeIdMap[aNode->GetID()];
+#else
+ conn[ iNode ] = aNode->GetID();
+#endif
+ ++iNode;
+ }
+ // element number
+ aPolyhInfo->SetElemNum( iElem, anElem->GetID() );
+
+ // family number
+ int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
+ aPolyhInfo->SetFamNum( iElem, famNum );
+
+ if ( ++iElem == aPolyhInfo->GetNbElem() )
+ break;
+ }
+ myMed->SetPolyedreInfo(aPolyhInfo);
+ }
+ } // if (aElemTypeData->_geomType == ePOLYEDRE )
+
+ // Treat BALLs
+ // ----------------
+ else if (aElemTypeData->_geomType == eBALL )
+ {
+ // allocate data arrays
+ PBallInfo aBallInfo = myMed->CrBallInfo( aMeshInfo,
+ aElemTypeData->_nbElems );
+
+ // build map of family numbers for this type
+ if ( !isElemFamMapBuilt[ aElemTypeData->_smdsType ])
+ {
+ fillElemFamilyMap( anElemFamMap, aFamilies, aElemTypeData->_smdsType );
+ isElemFamMapBuilt[ aElemTypeData->_smdsType ] = true;
+ }
+
+ elemIterator = myMesh->elementsIterator( SMDSAbs_Ball );
+ while ( elemIterator->more() )
+ {
+ const SMDS_MeshElement* anElem = elemIterator->next();
+ // connectivity
+ const SMDS_MeshElement* aNode = anElem->GetNode( 0 );
+#ifdef _EDF_NODE_IDS_
+ (*aBallInfo->myConn)[ iElem ] = aNodeIdMap[aNode->GetID()];
+#else
+ (*aBallInfo->myConn)[ iElem ] = aNode->GetID();
+#endif
+ // element number
+ aBallInfo->SetElemNum( iElem, anElem->GetID() );
+
+ // diameter
+ aBallInfo->myDiameters[ iElem ] =
+ static_cast<const SMDS_BallElement*>( anElem )->GetDiameter();
+
+ // family number
+ int famNum = getFamilyId( anElemFamMap, anElem, defaultFamilyId );
+ aBallInfo->SetFamNum( iElem, famNum );
+ ++iElem;
+ }
+ // store data in a file
+ myMed->SetBallInfo(aBallInfo);