X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FDriverMED%2FDriverMED_R_SMESHDS_Mesh.cxx;h=513454316ef57da8f9328384f0d6a4469eae7aad;hb=refs%2Ftags%2FV2_1_0b1;hp=c37f1e60adddd7e446dc350fafc35d799db410ed;hpb=c3bf92bd87b770fd81631a3853f7f5bb1ac6a4e8;p=modules%2Fsmesh.git diff --git a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx index c37f1e60a..513454316 100644 --- a/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx +++ b/src/DriverMED/DriverMED_R_SMESHDS_Mesh.cxx @@ -26,6 +26,7 @@ #include "DriverMED_R_SMESHDS_Mesh.h" #include "DriverMED_R_SMDS_Mesh.h" +#include "SMESHDS_Mesh.hxx" #include "utilities.h" #include "DriverMED_Family.h" @@ -37,101 +38,108 @@ #include -DriverMED_R_SMESHDS_Mesh::DriverMED_R_SMESHDS_Mesh() - : - myMesh (NULL), - myFile (""), - myFileId (-1), - myMeshId (-1) -{ -} - -DriverMED_R_SMESHDS_Mesh::~DriverMED_R_SMESHDS_Mesh() -{ -// map::iterator aFamsIter = myFamilies.begin(); -// for (; aFamsIter != myFamilies.end(); aFamsIter++) -// { -// delete (*aFamsIter).second; -// } -} - -void DriverMED_R_SMESHDS_Mesh::SetMesh(SMDS_Mesh * aMesh) -{ - myMesh = aMesh; -} - -void DriverMED_R_SMESHDS_Mesh::SetFile(string aFile) -{ - myFile = aFile; -} - -void DriverMED_R_SMESHDS_Mesh::SetFileId(med_idt aFileId) -{ - myFileId = aFileId; -} - -void DriverMED_R_SMESHDS_Mesh::SetMeshId(int aMeshId) -{ - myMeshId = aMeshId; -} +#define _EDF_NODE_IDS_ void DriverMED_R_SMESHDS_Mesh::SetMeshName(string theMeshName) { myMeshName = theMeshName; } -void DriverMED_R_SMESHDS_Mesh::Read() -{ - - string myClass = string("SMDS_Mesh"); - string myExtension = string("MED"); - - DriverMED_R_SMDS_Mesh *myReader = new DriverMED_R_SMDS_Mesh; - - myReader->SetMesh(myMesh); - myReader->SetMeshId(myMeshId); - myReader->SetFile(myFile); - myReader->SetFileId(-1); - - myReader->Read(); +static const SMDS_MeshNode* +FindNode(const SMDS_Mesh* theMesh, med_int theId){ + const SMDS_MeshNode* aNode = theMesh->FindNode(theId); + if(aNode) return aNode; + EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<SetMesh(myMesh); - myReader->SetMeshId(myMeshId); +enum ECoordName{eX, eY, eZ, eNone}; +typedef med_float (*TGetCoord)(MEDA::PNodeInfo&, med_int); - SCRUTE(myFileId); - myReader->SetFileId(myFileId); +template +med_float GetCoord(MEDA::PNodeInfo& thePNodeInfo, med_int theElemId){ + return thePNodeInfo->GetNodeCoord(theElemId,TheCoordId); +} - myReader->Read(); +template<> +med_float GetCoord(MEDA::PNodeInfo& thePNodeInfo, med_int theElemId){ + return 0.0; } -static const SMDS_MeshNode* -FindNode(const SMDS_Mesh* theMesh, med_int theId){ - const SMDS_MeshNode* aNode = theMesh->FindNode(theId); - if(aNode) return aNode; - EXCEPTION(runtime_error,"SMDS_Mesh::FindNode - cannot find a SMDS_MeshNode for ID = "<, + &GetCoord, + &GetCoord +}; + + +static TGetCoord aXYGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord +}; + +static TGetCoord aYZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord +}; + +static TGetCoord aXZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord +}; + + +static TGetCoord aXGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord +}; + +static TGetCoord aYGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord +}; + +static TGetCoord aZGetCoord[3] = { + &GetCoord, + &GetCoord, + &GetCoord +}; + + +class TCoordHelper{ + MEDA::PNodeInfo myPNodeInfo; + TGetCoord* myGetCoord; +public: + TCoordHelper(const MEDA::PNodeInfo& thePNodeInfo, + TGetCoord* theGetCoord): + myPNodeInfo(thePNodeInfo), + myGetCoord(theGetCoord) + {} + virtual ~TCoordHelper(){} + med_float GetCoord(med_int theElemId, med_int theCoodId){ + return (*myGetCoord[theCoodId])(myPNodeInfo,theElemId); + } +}; +typedef boost::shared_ptr TCoordHelperPtr; -DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() +Driver_Mesh::Status DriverMED_R_SMESHDS_Mesh::Perform() { - ReadStatus result = DRS_FAIL; + Status aResult = DRS_FAIL; try{ using namespace MEDA; myFamilies.clear(); - MESSAGE("ReadMySelf - myFile : "<GetName()); + MESSAGE("Perform - aMeshName : "<GetName()); if(aMeshName != aMeshInfo->GetName()) continue; - result = DRS_OK; + aResult = DRS_OK; med_int aMeshDim = aMeshInfo->GetDim(); // Reading MED families to the temporary structure @@ -159,7 +167,6 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() med_int aFamId = aFamilyInfo->GetId(); MESSAGE("Family " << aFamId << " :"); -//if (aFamId >= FIRST_VALID_FAMILY) { DriverMED_FamilyPtr aFamily (new DriverMED_Family); med_int aNbGrp = aFamilyInfo->GetNbGroup(); @@ -169,21 +176,56 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() MESSAGE(aGroupName); aFamily->AddGroupName(aGroupName); } -// aFamily->SetId(aFamId); myFamilies[aFamId] = aFamily; -// } } // Reading MED nodes to the corresponding SMDS structure //------------------------------------------------------ PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo); + + TCoordHelperPtr aCoordHelperPtr; + { + med_int aMeshDimension = aMeshInfo->GetDim(); + bool anIsDimPresent[3] = {false, false, false}; + for(med_int iDim = 0; iDim < aMeshDimension; iDim++){ + string aDimName = aNodeInfo->GetCoordName(iDim); + if(aDimName == "x" || aDimName == "X") + anIsDimPresent[eX] = true; + else if(aDimName == "y" || aDimName == "Y") + anIsDimPresent[eY] = true; + else if(aDimName == "z" || aDimName == "Z") + anIsDimPresent[eZ] = true; + } + switch(aMeshDimension){ + case 3: + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYZGetCoord)); + break; + case 2: + if(anIsDimPresent[eY] && anIsDimPresent[eZ]) + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYZGetCoord)); + else if(anIsDimPresent[eX] && anIsDimPresent[eZ]) + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXZGetCoord)); + else + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXYGetCoord)); + break; + case 1: + if(anIsDimPresent[eY]) + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aYGetCoord)); + else if(anIsDimPresent[eZ]) + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aZGetCoord)); + else + aCoordHelperPtr.reset(new TCoordHelper(aNodeInfo,aXGetCoord)); + break; + } + } + med_booleen anIsNodeNum = aNodeInfo->IsElemNum(); med_int aNbElems = aNodeInfo->GetNbElem(); - MESSAGE("ReadMySelf - aNodeInfo->GetNbElem() = "<GetNbElem() = "<GetConn(iElem,i); + } +#endif bool isRenum = false; SMDS_MeshElement* anElement = NULL; @@ -283,12 +324,12 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() case MED_SEG2: case MED_SEG3: if(anIsElemNum) - anElement = myMesh->AddEdgeWithID(aNodeIds.at(0), - aNodeIds.at(1), + anElement = myMesh->AddEdgeWithID(aNodeIds[0], + aNodeIds[1], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1))); + anElement = myMesh->AddEdge(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1])); isRenum = anIsElemNum; } break; @@ -296,14 +337,14 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() case MED_TRIA6: aNbNodes = 3; if(anIsElemNum) - anElement = myMesh->AddFaceWithID(aNodeIds.at(0), - aNodeIds.at(1), - aNodeIds.at(2), + anElement = myMesh->AddFaceWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1)), - FindNode(myMesh,aNodeIds.at(2))); + anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2])); isRenum = anIsElemNum; } break; @@ -312,16 +353,16 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() aNbNodes = 4; // There is some differnce between SMDS and MED if(anIsElemNum) - anElement = myMesh->AddFaceWithID(aNodeIds.at(0), - aNodeIds.at(1), - aNodeIds.at(2), - aNodeIds.at(3), + anElement = myMesh->AddFaceWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1)), - FindNode(myMesh,aNodeIds.at(2)), - FindNode(myMesh,aNodeIds.at(3))); + anElement = myMesh->AddFace(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3])); isRenum = anIsElemNum; } break; @@ -329,16 +370,16 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() case MED_TETRA10: aNbNodes = 4; if(anIsElemNum) - anElement = myMesh->AddVolumeWithID(aNodeIds.at(0), - aNodeIds.at(1), - aNodeIds.at(2), - aNodeIds.at(3), + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1)), - FindNode(myMesh,aNodeIds.at(2)), - FindNode(myMesh,aNodeIds.at(3))); + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3])); isRenum = anIsElemNum; } break; @@ -347,18 +388,18 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() aNbNodes = 5; // There is some differnce between SMDS and MED if(anIsElemNum) - anElement = myMesh->AddVolumeWithID(aNodeIds.at(0), - aNodeIds.at(1), - aNodeIds.at(2), - aNodeIds.at(3), - aNodeIds.at(4), + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1)), - FindNode(myMesh,aNodeIds.at(2)), - FindNode(myMesh,aNodeIds.at(3)), - FindNode(myMesh,aNodeIds.at(4))); + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4])); isRenum = anIsElemNum; } break; @@ -366,20 +407,20 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() case MED_PENTA15: aNbNodes = 6; if(anIsElemNum) - anElement = myMesh->AddVolumeWithID(aNodeIds.at(0), - aNodeIds.at(1), - aNodeIds.at(2), - aNodeIds.at(3), - aNodeIds.at(4), - aNodeIds.at(5), + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aNodeIds[5], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1)), - FindNode(myMesh,aNodeIds.at(2)), - FindNode(myMesh,aNodeIds.at(3)), - FindNode(myMesh,aNodeIds.at(4)), - FindNode(myMesh,aNodeIds.at(5))); + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4]), + FindNode(myMesh,aNodeIds[5])); isRenum = anIsElemNum; } break; @@ -387,45 +428,45 @@ DriverMED_R_SMESHDS_Mesh::ReadStatus DriverMED_R_SMESHDS_Mesh::ReadMySelf() case MED_HEXA20: aNbNodes = 8; if(anIsElemNum) - anElement = myMesh->AddVolumeWithID(aNodeIds.at(0), - aNodeIds.at(1), - aNodeIds.at(2), - aNodeIds.at(3), - aNodeIds.at(4), - aNodeIds.at(5), - aNodeIds.at(6), - aNodeIds.at(7), + anElement = myMesh->AddVolumeWithID(aNodeIds[0], + aNodeIds[1], + aNodeIds[2], + aNodeIds[3], + aNodeIds[4], + aNodeIds[5], + aNodeIds[6], + aNodeIds[7], aCellInfo->GetElemNum(iElem)); if (!anElement) { - anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds.at(0)), - FindNode(myMesh,aNodeIds.at(1)), - FindNode(myMesh,aNodeIds.at(2)), - FindNode(myMesh,aNodeIds.at(3)), - FindNode(myMesh,aNodeIds.at(4)), - FindNode(myMesh,aNodeIds.at(5)), - FindNode(myMesh,aNodeIds.at(6)), - FindNode(myMesh,aNodeIds.at(7))); + anElement = myMesh->AddVolume(FindNode(myMesh,aNodeIds[0]), + FindNode(myMesh,aNodeIds[1]), + FindNode(myMesh,aNodeIds[2]), + FindNode(myMesh,aNodeIds[3]), + FindNode(myMesh,aNodeIds[4]), + FindNode(myMesh,aNodeIds[5]), + FindNode(myMesh,aNodeIds[6]), + FindNode(myMesh,aNodeIds[7])); isRenum = anIsElemNum; } break; } }catch(const std::exception& exc){ //INFOS("Follow exception was cought:\n\t"< DriverMED_R_SMESHDS_Mesh::GetMeshNames() } }catch(const std::exception& exc){ INFOS("Follow exception was cought:\n\t"<& anElements = aFamily->GetElements(); set::iterator anElemsIter = anElements.begin(); + const SMDS_MeshElement * element = 0; for (; anElemsIter != anElements.end(); anElemsIter++) { - theGroup->SMDS_MeshGroup::Add(*anElemsIter); + element = *anElemsIter; + theGroup->SMDSGroup().Add(element); } + if ( element ) + theGroup->SetType( element->GetType() ); } } } @@ -560,10 +608,6 @@ void DriverMED_R_SMESHDS_Mesh::GetSubMesh (SMESHDS_SubMesh* theSubMesh, void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes () { - SMESHDS_Mesh* aSMESHDSMesh = dynamic_cast(myMesh); - if (!aSMESHDSMesh) { - EXCEPTION(runtime_error,"Can not cast SMDS_Mesh to SMESHDS_Mesh"); - } map::iterator aFamsIter = myFamilies.begin(); for (; aFamsIter != myFamilies.end(); aFamsIter++) { @@ -583,18 +627,28 @@ void DriverMED_R_SMESHDS_Mesh::CreateAllSubMeshes () { for (; anElemsIter != anElements.end(); anElemsIter++) { - const SMDS_MeshNode* node = static_cast(*anElemsIter); - aSMESHDSMesh->SetNodeInVolume(node, Id); -// aSMESHDSMesh->SetNodeOnFace(node, Id); -// aSMESHDSMesh->SetNodeOnEdge(node, Id); -// aSMESHDSMesh->SetNodeOnVertex(node, Id); + SMDS_MeshNode* node = const_cast + ( static_cast( *anElemsIter )); + // find out a shape type + TopoDS_Shape aShape = myMesh->IndexToShape( Id ); + int aShapeType = ( aShape.IsNull() ? -1 : aShape.ShapeType() ); + switch ( aShapeType ) { + case TopAbs_FACE: + myMesh->SetNodeOnFace(node, Id); break; + case TopAbs_EDGE: + myMesh->SetNodeOnEdge(node, Id); break; + case TopAbs_VERTEX: + myMesh->SetNodeOnVertex(node, Id); break; + default: + myMesh->SetNodeInVolume(node, Id); + } } } else { for (; anElemsIter != anElements.end(); anElemsIter++) { - aSMESHDSMesh->SetMeshElementOnShape(*anElemsIter, Id); + myMesh->SetMeshElementOnShape(*anElemsIter, Id); } } }