+
+ // Mesh dimension definition
+ TInt aSpaceDimension = 3;
+ TCoordHelperPtr aCoordHelperPtr;
+ {
+ bool anIsXDimension = false;
+ bool anIsYDimension = false;
+ bool anIsZDimension = false;
+ if ( myAutoDimension )
+ {
+ SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
+ double aBounds[6];
+ if(aNodesIter->more()){
+ const SMDS_MeshNode* aNode = aNodesIter->next();
+ aBounds[0] = aBounds[1] = aNode->X();
+ aBounds[2] = aBounds[3] = aNode->Y();
+ aBounds[4] = aBounds[5] = aNode->Z();
+ }
+ while(aNodesIter->more()){
+ const SMDS_MeshNode* aNode = aNodesIter->next();
+ aBounds[0] = min(aBounds[0],aNode->X());
+ aBounds[1] = max(aBounds[1],aNode->X());
+
+ aBounds[2] = min(aBounds[2],aNode->Y());
+ aBounds[3] = max(aBounds[3],aNode->Y());
+
+ aBounds[4] = min(aBounds[4],aNode->Z());
+ aBounds[5] = max(aBounds[5],aNode->Z());
+ }
+
+ double EPS = 1.0E-7;
+ TopoDS_Shape mainShape = myMesh->ShapeToMesh();
+ bool hasShapeToMesh = ( myMesh->SubMeshIndices().size() > 1 );
+ if ( !mainShape.IsNull() && hasShapeToMesh )
+ {
+ // define EPS by max tolerance of the mainShape (IPAL53097)
+ TopExp_Explorer subShape;
+ for ( subShape.Init( mainShape, TopAbs_FACE ); subShape.More(); subShape.Next() ) {
+ EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Face( subShape.Current() )));
+ }
+ for ( subShape.Init( mainShape, TopAbs_EDGE ); subShape.More(); subShape.Next() ) {
+ EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Edge( subShape.Current() )));
+ }
+ for ( subShape.Init( mainShape, TopAbs_VERTEX ); subShape.More(); subShape.Next() ) {
+ EPS = Max( EPS, BRep_Tool::Tolerance( TopoDS::Vertex( subShape.Current() )));
+ }
+ EPS *= 2.;
+ }
+ 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;
+ aSpaceDimension = anIsXDimension + anIsYDimension + anIsZDimension;
+ if ( !aSpaceDimension )
+ aSpaceDimension = 3;
+ // PAL16857(SMESH not conform to the MED convention):
+ if ( aSpaceDimension == 2 && anIsZDimension ) // 2D only if mesh is in XOY plane
+ aSpaceDimension = 3;
+ // PAL18941(a saved study with a mesh belong Z is opened and the mesh is belong X)
+ if ( aSpaceDimension == 1 && !anIsXDimension ) {// 1D only if mesh is along OX
+ if ( anIsYDimension ) {
+ aSpaceDimension = 2;
+ anIsXDimension = true;
+ } else {
+ aSpaceDimension = 3;
+ }
+ }
+ }
+
+ SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator(/*idInceasingOrder=*/true);
+ switch ( aSpaceDimension ) {
+ 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;
+ }
+ }
+ TInt aMeshDimension = 0;
+ if ( myMesh->NbEdges() > 0 )
+ aMeshDimension = 1;
+ if ( myMesh->NbFaces() > 0 )
+ aMeshDimension = 2;
+ if ( myMesh->NbVolumes() > 0 )
+ aMeshDimension = 3;
+
+ MED::PWrapper myMed = CrWrapper(myFile,myMedVersion);
+ PMeshInfo aMeshInfo = myMed->CrMeshInfo(aMeshDimension,aSpaceDimension,aMeshName);
+ //MESSAGE("Add - aMeshName : "<<aMeshName<<"; "<<aMeshInfo->GetName());
+ myMed->SetMeshInfo(aMeshInfo);
+
+ // Storing SMDS groups and sub-meshes as med families
+ //----------------------------------------------------
+ int myNodesDefaultFamilyId = 0;
+ int my0DElementsDefaultFamilyId = 0;
+ int myBallsDefaultFamilyId = 0;
+ int myEdgesDefaultFamilyId = 0;
+ int myFacesDefaultFamilyId = 0;
+ int myVolumesDefaultFamilyId = 0;
+ int nbNodes = myMesh->NbNodes();
+ int nb0DElements = myMesh->Nb0DElements();
+ int nbBalls = myMesh->NbBalls();
+ int nbEdges = myMesh->NbEdges();
+ int nbFaces = myMesh->NbFaces();
+ int nbVolumes = myMesh->NbVolumes();
+ if (myDoGroupOfNodes && nbNodes) myNodesDefaultFamilyId = REST_NODES_FAMILY;
+ if (myDoGroupOfEdges && nbEdges) myEdgesDefaultFamilyId = REST_EDGES_FAMILY;
+ if (myDoGroupOfFaces && nbFaces) myFacesDefaultFamilyId = REST_FACES_FAMILY;
+ if (myDoGroupOfVolumes && nbVolumes) myVolumesDefaultFamilyId = REST_VOLUMES_FAMILY;
+ if (myDoGroupOf0DElems && nb0DElements) my0DElementsDefaultFamilyId = REST_0DELEM_FAMILY;
+ if (myDoGroupOfBalls && nbBalls) myBallsDefaultFamilyId = REST_BALL_FAMILY;
+
+ //MESSAGE("Perform - aFamilyInfo");