+ double EPS = 1.0E-7;
+ anIsXDimension = (aBounds[1] - aBounds[0]) + abs(aBounds[1]) + abs(aBounds[0]) > EPS;
+ anIsYDimension = (aBounds[3] - aBounds[2]) + abs(aBounds[3]) + abs(aBounds[2]) > EPS;
+ anIsZDimension = (aBounds[5] - aBounds[4]) + abs(aBounds[5]) + abs(aBounds[4]) > EPS;
+ aMeshDimension = anIsXDimension + anIsYDimension + anIsZDimension;
+ if(!aMeshDimension)
+ aMeshDimension = 3;
+ }
+
+ SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
+ switch(aMeshDimension){
+ case 3:
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYZGetCoord,aXYZName));
+ break;
+ case 2:
+ if(anIsXDimension && anIsYDimension)
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXYGetCoord,aXYName));
+ if(anIsYDimension && anIsZDimension)
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYZGetCoord,aYZName));
+ if(anIsXDimension && anIsZDimension)
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXZGetCoord,aXZName));
+ break;
+ case 1:
+ if(anIsXDimension)
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aXGetCoord,aXName));
+ if(anIsYDimension)
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aYGetCoord,aYName));
+ if(anIsZDimension)
+ aCoordHelperPtr.reset(new TCoordHelper(aNodesIter,aZGetCoord,aZName));
+ break;
+ }
+ }
+
+
+ PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aMeshName);
+ MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
+ myMed->SetMeshInfo(aMeshInfo);
+
+ // Storing SMDS groups and sub-meshes
+ //-----------------------------------
+ int myNodesDefaultFamilyId = 0;
+ int myEdgesDefaultFamilyId = 0;
+ int myFacesDefaultFamilyId = 0;
+ int myVolumesDefaultFamilyId = 0;
+ if (myDoGroupOfNodes)
+ myNodesDefaultFamilyId = REST_NODES_FAMILY;
+ if (myDoGroupOfEdges)
+ myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
+ if (myDoGroupOfFaces)
+ myFacesDefaultFamilyId = REST_FACES_FAMILY;
+ if (myDoGroupOfVolumes)
+ myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
+
+ MESSAGE("Perform - aFamilyInfo");
+ map<const SMDS_MeshElement *, int> anElemFamMap;
+ list<DriverMED_FamilyPtr> aFamilies;
+ if (myAllSubMeshes) {
+ aFamilies = DriverMED_Family::MakeFamilies
+ (myMesh->SubMeshes(), myGroups,
+ myDoGroupOfNodes, myDoGroupOfEdges, myDoGroupOfFaces, myDoGroupOfVolumes);
+ } else {
+ aFamilies = DriverMED_Family::MakeFamilies
+ (mySubMeshes, myGroups,
+ myDoGroupOfNodes, myDoGroupOfEdges, myDoGroupOfFaces, myDoGroupOfVolumes);
+ }
+ list<DriverMED_FamilyPtr>::iterator aFamsIter = aFamilies.begin();
+
+ for (; aFamsIter != aFamilies.end(); aFamsIter++)
+ {
+ PFamilyInfo aFamilyInfo = (*aFamsIter)->GetFamilyInfo(myMed,aMeshInfo);
+ myMed->SetFamilyInfo(aFamilyInfo);
+ int aFamId = (*aFamsIter)->GetId();
+
+ const set<const SMDS_MeshElement *>& anElems = (*aFamsIter)->GetElements();
+ set<const SMDS_MeshElement *>::iterator anElemsIter = anElems.begin();
+ for (; anElemsIter != anElems.end(); anElemsIter++)
+ {
+ anElemFamMap[*anElemsIter] = aFamId;
+ }
+// delete (*aFamsIter);
+ }
+
+ // Storing SMDS nodes to the MED file for the MED mesh
+ //----------------------------------------------------
+#ifdef _EDF_NODE_IDS_
+ typedef map<TInt,TInt> TNodeIdMap;
+ TNodeIdMap aNodeIdMap;
+#endif
+ TInt aNbElems = myMesh->NbNodes();
+ MED::TIntVector anElemNums(aNbElems);
+ MED::TIntVector aFamilyNums(aNbElems);
+ MED::TFloatVector aCoordinates(aNbElems*aMeshDimension);
+ for(TInt iNode = 0, aStartId = 0; aCoordHelperPtr->Next(); iNode++, aStartId += aMeshDimension){
+ for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
+ aCoordinates[aStartId+iCoord] = aCoordHelperPtr->GetCoord(iCoord);
+ }
+ int aNodeID = aCoordHelperPtr->GetID();
+ anElemNums[iNode] = aNodeID;
+#ifdef _EDF_NODE_IDS_
+ aNodeIdMap[aNodeID] = iNode+1;
+#endif
+ const SMDS_MeshNode* aNode = aCoordHelperPtr->GetNode();
+ if (anElemFamMap.find(aNode) != anElemFamMap.end())
+ aFamilyNums[iNode] = anElemFamMap[aNode];
+ else
+ aFamilyNums[iNode] = myNodesDefaultFamilyId;
+ }
+
+ MED::TStringVector aCoordNames(aMeshDimension);
+ MED::TStringVector aCoordUnits(aMeshDimension);
+ for(TInt iCoord = 0; iCoord < aMeshDimension; iCoord++){
+ aCoordNames[iCoord] = aCoordHelperPtr->GetName(iCoord);
+ aCoordUnits[iCoord] = aCoordHelperPtr->GetUnit(iCoord);
+ }
+
+ const ERepere SMDS_COORDINATE_SYSTEM = eCART;
+
+ PNodeInfo aNodeInfo = myMed->CrNodeInfo(aMeshInfo,
+ SMDS_COORDINATE_SYSTEM,
+ aCoordinates,
+ aCoordNames,
+ aCoordUnits,
+ aFamilyNums,
+ anElemNums);
+ MESSAGE("Perform - aNodeInfo->GetNbElem() = "<<aNbElems);
+ myMed->SetNodeInfo(aNodeInfo);
+
+
+ // Storing others SMDS elements to the MED file for the MED mesh
+ //--------------------------------------------------------------
+ EEntiteMaillage SMDS_MED_ENTITY = eMAILLE;
+ const EConnectivite SMDS_MED_CONNECTIVITY = eNOD;
+
+ // Storing SMDS Edges
+ if(TInt aNbElems = myMesh->NbEdges()){
+#ifdef _ELEMENTS_BY_DIM_
+ SMDS_MED_ENTITY = eARETE;
+#endif
+ SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
+ TInt aNbConnectivity = MED::GetNbConnectivities(eSEG2);
+ MED::TIntVector anElemNums(aNbElems);
+ MED::TIntVector aFamilyNums(aNbElems);
+ MED::TIntVector aConnectivity(aNbElems*aNbConnectivity);
+
+ for(TInt iElem = 0, iConn = 0; anIter->more(); iElem++, iConn+=aNbConnectivity){
+ const SMDS_MeshEdge* anElem = anIter->next();
+ SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
+ for(TInt iNode = 0; iNode < aNbConnectivity && aNodesIter->more(); iNode++){
+ const SMDS_MeshElement* aNode = aNodesIter->next();
+#ifdef _EDF_NODE_IDS_
+ aConnectivity[iConn+iNode] = aNodeIdMap[aNode->GetID()];
+#else
+ aConnectivity[iConn+iNode] = aNode->GetID();
+#endif