From 98a4d622b4bfc9c9b32d2791a2b943117263be01 Mon Sep 17 00:00:00 2001 From: nri Date: Thu, 10 Jul 2003 15:41:21 +0000 Subject: [PATCH] NRI : Merge from V1_2. --- src/VISU_I/VISU_CorbaMedConvertor.cxx | 524 +++++++++++++------------- 1 file changed, 255 insertions(+), 269 deletions(-) diff --git a/src/VISU_I/VISU_CorbaMedConvertor.cxx b/src/VISU_I/VISU_CorbaMedConvertor.cxx index b23363db..1b879710 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.cxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.cxx @@ -32,13 +32,21 @@ extern "C" { typedef map TVisu2MedEntity; static TVisu2MedEntity aVisu2MedEntity; +typedef map TMed2VisuEntity; +static TMed2VisuEntity aMed2VisuEntity; static int INIT = ( aVisu2MedEntity[VISU::CELL_ENTITY] = SALOME_MED::MED_CELL, aVisu2MedEntity[VISU::FACE_ENTITY] = SALOME_MED::MED_FACE, aVisu2MedEntity[VISU::EDGE_ENTITY] = SALOME_MED::MED_EDGE, aVisu2MedEntity[VISU::NODE_ENTITY] = SALOME_MED::MED_NODE, + + aMed2VisuEntity[SALOME_MED::MED_CELL] = VISU::CELL_ENTITY, + aMed2VisuEntity[SALOME_MED::MED_FACE] = VISU::FACE_ENTITY, + aMed2VisuEntity[SALOME_MED::MED_EDGE] = VISU::EDGE_ENTITY, + aMed2VisuEntity[SALOME_MED::MED_NODE] = VISU::NODE_ENTITY, + 1); -*/ + static int CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = { SALOME_MED::MED_POINT1, SALOME_MED::MED_SEG2, @@ -85,26 +93,19 @@ static int NODEGEOM[1] = { SALOME_MED::MED_POINT1, }; -void Entity2Geom(const VISU::TEntity& theEntity, int* theVector, int* theEnd) { +void GetEntity2Geom(const VISU::TEntity& theEntity, int*& theVector, int* theEnd) + throw (std::runtime_error&) +{ switch(theEntity){ case VISU::CELL_ENTITY: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break; case VISU::FACE_ENTITY: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break; case VISU::EDGE_ENTITY: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break; case VISU::NODE_ENTITY: theVector = NODEGEOM; *theEnd = 1; break; + default: + throw std::runtime_error("GetEntity2Geom >> theEntity is uncorrect !!!"); } } -typedef pair TEntity2Geom; -typedef map TEntity2GeomMap; -static TEntity2GeomMap anEntity2GeomMap; -static int INIT = ( - anEntity2GeomMap[SALOME_MED::MED_CELL] = TEntity2Geom(CELLGEOM,MED_NBR_GEOMETRIE_MAILLE), - anEntity2GeomMap[SALOME_MED::MED_FACE] = TEntity2Geom(FACEGEOM,MED_NBR_GEOMETRIE_FACE), - anEntity2GeomMap[SALOME_MED::MED_EDGE] = TEntity2Geom(EDGEGEOM,MED_NBR_GEOMETRIE_ARETE), - anEntity2GeomMap[SALOME_MED::MED_NODE] = TEntity2Geom(NODEGEOM,1), - 1 -); - struct SalomeMed2vtk { SALOME_MED::medGeometryElement medType; char *medName; @@ -136,14 +137,20 @@ static SalomeMed2vtk salome_med2vtk[SALOME_MED::MED_ALL_ELEMENTS] = { }; #undef CORBAMED2VTK -int FindIdMEDType(int medType){ +int GetIdMEDType(int medType){ for(int i = 0; i < SALOME_MED::MED_ALL_ELEMENTS; i++) if(salome_med2vtk[i].medType == medType) return i; return -1; } -void VISU_MedMeshConvertor::SetMedMesh(SALOME_MED::MESH_ptr theMedMesh) { - myMedMesh = SALOME_MED::MESH::_duplicate(theMedMesh); +string GetName(SALOMEDS::SObject_ptr aSObject){ + SALOMEDS::GenericAttribute_var anAttr; + if (aSObject->FindAttribute(anAttr,"AttributeName")) { + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + CORBA::String_var aString = aName->Value(); + return aString.in(); + } + return ""; } VISU_Convertor* VISU_MEDFieldConvertor::Build() throw (std::runtime_error&){ @@ -505,290 +512,269 @@ int VISU_MEDConvertor::LoadMeshOnGroup(VISU::TMesh& theMesh, return (isPointsUpdated || isCellsOnEntityUpdated); } -void VISU_CorbaMedSupportConvertor::SetSupport(SALOME_MED::SUPPORT_ptr theSupport) { - mySupport = SALOME_MED::SUPPORT::_duplicate(theSupport); - if(!mySupport->_is_nil()) - myMedMesh = mySupport->getMesh(); +int VISU_MEDConvertor::LoadFieldOnMesh(VISU::TMesh& theMesh, + VISU::TMeshOnEntity& theMeshOnEntity, + VISU::TField& theField, + VISU::TField::TValForTime& theValForTime) + throw (std::runtime_error&) +{ + //Main part of code + int isPointsUpdated = LoadPoints(theMesh); + int isCellsOnEntityUpdated = LoadCellsOnEntity(theMeshOnEntity); + int isFieldUpdated = LoadField(theMeshOnEntity,theField,theValForTime); + + return (isPointsUpdated || isCellsOnEntityUpdated || isFieldUpdated); } -int ImportPoints(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH) +int VISU_MEDConvertor::LoadPoints(VISU::TMesh& theMesh, const string& theFamilyName) throw (std::runtime_error&) { -/* - if(MYDEBUG) MESSAGE("ImportPoints - beginning"); - theMesh.myDim = theMESH->getMeshDimension(); - int aNbPoints = theMESH->getNumberOfNodes(); - VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord; - aPointsCoord.resize(theMesh.myDim*aNbPoints,0.0); - Engines::double_array_var coord = theMESH->getCoordinates(SALOME_MED::MED_FULL_INTERLACE); - for (int i = 0 ; i < aNbPoints; i++) - for(int j = 0, ij = theMesh.myDim*i; j < theMesh.myDim; j++) - aPointsCoord[ij+j] = coord[ij+j]; + //Check on existing family + VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[VISU::NODE_ENTITY]; + aMeshOnEntity.myEntity = VISU::NODE_ENTITY; + aMeshOnEntity.myMeshName = theMesh.myName; + VISU::TFamily* pFamily = VISU::GetFamily(aMeshOnEntity,theFamilyName); + bool isFamilyPresent = (pFamily != NULL); + VISU::TFamily& aFamily = *pFamily; + //Check on loading already done + bool isPointsLoaded = !theMesh.myPointsCoord.empty(); + if(isPointsLoaded) + if(!isFamilyPresent) return 0; + else if(!aFamily.mySubMesh.empty()) return 0; + VISUMED::TMesh& aMesh2 = myMeshMap2[theMesh.myName]; + SALOME_MED::MESH_var& aMedMesh = aMesh2.myMesh; + VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[VISU::NODE_ENTITY]; if(MYDEBUG) - MESSAGE("ImportPoints - End : theDim = "<getSpaceDimension(); + int iNumElemEnd = aMedMesh->getNumberOfNodes(); + VISU::TMesh::TPointsCoord& aPointsCoord = theMesh.myPointsCoord; + if(MYDEBUG) MESSAGE("LoadPoints - iNumElemEnd = "<> There is no points in the mesh !!!"); + aPointsCoord.resize(theMesh.myDim*iNumElemEnd,0.0); + Engines::double_array_var coord = aMedMesh->getCoordinates(SALOME_MED::MED_FULL_INTERLACE); + if(!isPointsLoaded){ + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + for(int iDim = 0, iNumElem2Dim = iNumElem*theMesh.myDim; iDim < theMesh.myDim; iDim++, iNumElem2Dim++) + aPointsCoord[iNumElem2Dim] = coord[iNumElem2Dim]; + if(MYDEBUG) MESSAGE("LoadPoints - Filling aMeshOnEntity with type NODE_ENTITY"); + VISU::TMeshOnEntity::TConnForCellType& aConnForCellType = aMeshOnEntity.myCellsConn[VTK_VERTEX]; + aConnForCellType.resize(iNumElemEnd); + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) + aConnForCellType[iNumElem] = VISU::TMeshOnEntity::TConnect(1,iNumElem); + } + if(isFamilyPresent){ + if(MYDEBUG) MESSAGE("LoadPoints - Filling aFamily SubMesh"); + VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName]; + SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily; + VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[VTK_VERTEX]; + SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes(); + Engines::long_array_var aCellNumForType = aMedFamily->getNumber(aGeom[0]); + int iNumElemEndTmp = iNumElemEnd; + iNumElemEnd = aCellNumForType->length(); + for (int iNumElem = 0; iNumElem < iNumElemEnd; iNumElem++) { + int tmp = aCellNumForType[iNumElem]-1; + if(0 > tmp || tmp >= iNumElemEndTmp) { + static QString aString; + aString.sprintf("LoadPoints >> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEnd,iNumElem,tmp); + throw std::runtime_error(aString.latin1()); + } + aSubMeshOnCellType.insert(tmp); + } + } return 1; -*/ } -int ImportCells(VISU::TMesh& theMesh, SALOME_MED::MESH_ptr theMESH, - const SALOME_MED::medEntityMesh& theEntity) +int VISU_MEDConvertor::LoadCellsOnEntity(VISU::TMeshOnEntity& theMeshOnEntity, const string& theFamilyName) throw (std::runtime_error&) { -/* - if(MYDEBUG) MESSAGE("ImportCells - theEntity = "<first, iEnd = anEntity2Geom->second; - int *iArray, iEnd; - VISU::TEntity anEntity = MED2VISUEntity(theEntity); - Entity2Geom(anEntity,iArray,&iEnd); - int aNbPoints = theMesh.myPointsCoord.size(); - for (int i = 0; i < iEnd; i++) { - int medId = FindIdMEDType(iArray[i]); - int nbMedNodes = salome_med2vtk[medId].medNbNodes; - int nbVtkNodes = salome_med2vtk[medId].vtkNbNodes; - int aVtkType = salome_med2vtk[medId].vtkType; - SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType; - int jEnd = theMESH->getNumberOfElements(theEntity,aMedType); - if(jEnd > 0){ - VISU::TMeshOnEntity& aMeshOnEntity = theMesh.myMeshOnEntityMap[anEntity]; - Engines::long_array_var conn = - theMESH->getConnectivity(SALOME_MED::MED_FULL_INTERLACE,SALOME_MED::MED_NODAL,theEntity,aMedType); - if(MYDEBUG) MESSAGE("ImportCells - medName = "<> aNbPoints(%d) <= anArray[%d][%d]=%d < 0 !!!",aNbPoints,iNumElem,k,anArray[k]); + throw std::runtime_error(aString.latin1()); + } + aConnForCellType.push_back(anArray); } - for (int k = 0; k < nbVtkNodes; k++) - if(anArray[k] < 0 || aNbPoints <= anArray[k]) - throw std::runtime_error("ImportCells >> anArray[k] < 0 || aNbPoints <= anArray[k]"); + //Workaround for MED Component data structure + int aSize = aConnForCellType.size(); + aMeshOnEntity2.myCellsFirstIndex[aMedType] = VISUMED::TMeshOnEntity::TIndexAndSize(aCounter,aSize); + aCounter += aSize; } - if(MYDEBUG) - MESSAGE("ImportCells - aMeshOnEntity.myCellsConn.size() = "<_is_nil()) - throw std::runtime_error("VISU_MedMeshConvertor::Build >> myMesh->_is_nil()"); - CORBA::String_var aName = myMedMesh->getName(); - myName = aName; - TMesh& aMesh = myMeshMap[myName]; - if(MYDEBUG) MESSAGE("MedInfo - aMeshName = "<first); - ::ImportPoints(aMesh,myMedMesh); - TVisu2MedEntity::const_iterator aVisu2MedEntityIter = aVisu2MedEntity.begin(); - for(; aVisu2MedEntityIter != aVisu2MedEntity.end(); aVisu2MedEntityIter++) - ::ImportCells(aMesh,myMedMesh,aVisu2MedEntityIter->second); - myIsDone = true; - return this; -*/ + //Filling aFamily SubMesh + if(isFamilyPresent){ + VISUMED::TFamily aFamily2 = aMeshOnEntity2.myFamilyMap[aFamily.myName]; + SALOME_MED::FAMILY_var aMedFamily = aFamily2.myFamily; + SALOME_MED::medGeometryElement_array_var aGeom = aMedFamily->getTypes(); + iGeomElemEnd = aGeom->length(); + if(MYDEBUG) MESSAGE("LoadCellsOnEntity - iGeomElemEnd = "<getNumber(aGeomType); + int medId = GetIdMEDType(aGeomType); + int aVtkType = salome_med2vtk[medId].vtkType; + SALOME_MED::medGeometryElement aMedType = salome_med2vtk[medId].medType; + VISU::TFamily::TSubMeshOnCellType& aSubMeshOnCellType = aFamily.mySubMesh[aVtkType]; + med_int iNumElemEndTmp = theMeshOnEntity.myCellsConn[aVtkType].size(); + med_int iNumElemEnd = aCellNumForType->length(); + int aCounter = aMeshOnEntity2.myCellsFirstIndex[aMedType].first; + if(MYDEBUG) + MESSAGE("LoadCellsOnEntity - medName = "<> iNumElemEndTmp(%d) <= aCellNumForType[%d]=%d < 0 !!!",iNumElemEndTmp,iNumElem,tmp); + throw std::runtime_error(aString.latin1()); + } + aSubMeshOnCellType.insert(tmp); + } + } + } + return 1; } template int ImportField(TArray& theArray, + const VISU::TMesh& theMesh, + const VISU::TField& theField, + VISU::TField::TValForTime& theValForTime, const VISU::TMeshOnEntity& theMeshOnEntity, - VISU::TField& theField, - const SALOME_MED::medEntityMesh& theEntity, - const VISU::TField::TTime& theTime) + const VISUMED::TMeshOnEntity& theMeshOnEntity2) { -/* - if(MYDEBUG) MESSAGE("ImportField - IEnd = "<length()<<"; myNbComp = "<_is_nil()) - throw std::runtime_error("VISU_CorbaMedConvertor::Build >> myField->_is_nil()"); - if(VISU_MedMeshConvertor::Build() == NULL) return NULL; - CORBA::String_var aName = myMedField->getName(); - myName = aName; - TMeshMap::const_iterator aMeshIter = myMeshMap.begin(); - const TMesh& aMesh = aMeshIter->second; - int aNbPoints = aMesh.myPointsCoord.size()/aMesh.myDim; - int aNbCells = aMesh.GetCellsDims().first; - aName = myMedField->getName(); - aMeshOnEntity.myEntity = theEntity; - aMeshOnEntity.myMeshName = theMesh.myName; - TField& aField = myFieldMap[aName.in()]; - aField.myMeshName = aMeshIter->first; - SALOME_MED::SUPPORT_var aSupport = myMedField->getSupport(); - SALOME_MED::medEntityMesh anEntity = aSupport->getEntity(); - int aSize; - if(anEntity == SALOME_MED::MED_NODE){ - aSize = aNbPoints; - aField.myTypeConn = POINT_DATA; - if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - POINT_DATA = "<_is_nil()){ - if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - There is FIELDDOUBLE"); Engines::double_array_var anArray = aFieldDouble->getValue(SALOME_MED::MED_FULL_INTERLACE); - ::ImportField(anArray,aMesh,aField,anEntity,aTime); + if(MYDEBUG) MESSAGE("VISU_MEDConvertor::LoadField - There is FIELDDOUBLE = "<length()); + ::ImportField(anArray,aMesh,theField,theValForTime,theMeshOnEntity,aMeshOnEntity2); } - SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(myMedField); + SALOME_MED::FIELDINT_ptr aFieldInt = SALOME_MED::FIELDINT::_narrow(aMEDField); if(!aFieldInt->_is_nil()){ - if(MYDEBUG) MESSAGE("VISU_CorbaMedConvertor::Build - There is FIELDINT"); Engines::long_array_var anArray = aFieldInt->getValue(SALOME_MED::MED_FULL_INTERLACE); - ::ImportField(anArray,aMesh,aField,anEntity,aTime); - } - myIsDone = true; - return this; -*/ -} - -int ImportCellsOfSupport(VISU::TMesh& theMesh, SALOME_MED::SUPPORT_ptr theSUPPORT) - throw (std::runtime_error&) -{ -/* - if(MYDEBUG) MESSAGE("ImportCellsOfSupport - beginning"); - SALOME_MED::medEntityMesh anEntity = theSUPPORT->getEntity(); - med_int nmailles[SALOME_MED::MED_ALL_ELEMENTS]; - if(MYDEBUG) MESSAGE("ImportCellsOfSupport - anEntity = "<isOnAllElements()){ - int jEnd = theMesh.myPointsCoord.size()/theMesh.myDim; - if(MYDEBUG) MESSAGE("ImportCellsOfSupport - isOnAllElements - "<(1,j); - }else{ - SALOME_MED::medGeometryElement_array_var aGeom = theSUPPORT->getTypes(); - Engines::long_array_var aCellNumForType = theSUPPORT->getNumber(aGeom[0]); - int jEnd = aCellNumForType->length(); - aConnForCellType.resize(jEnd); - for (int j = 0; j < jEnd; j++) - aConnForCellType[j] = vector(1,aCellNumForType[j]-1); - } - }else{ - VISU::TMesh aBaseMesh; - SALOME_MED::MESH_var aMedMesh = theSUPPORT->getMesh(); - ::ImportPoints(aBaseMesh,aMedMesh); - ::ImportCells(aBaseMesh,aMedMesh,anEntity); - if(theSUPPORT->isOnAllElements()){ - if(MYDEBUG) MESSAGE("ImportCellsOfSupport - isOnAllElements"); - }else{ - SALOME_MED::medGeometryElement_array_var aGeom = theSUPPORT->getTypes(); - int iEnd = aGeom->length(); - if(MYDEBUG) MESSAGE("ImportCellsOfSupport - aGeom->length() = "<getNumber(aGeom[i]); - int medId = FindIdMEDType(aGeom[i]); - int aVtkType = salome_med2vtk[medId].vtkType; - med_int jEnd = aCellNumForType->length(); - if(MYDEBUG) MESSAGE("ImportCellsOfSupport - medName = "<getMesh()"); - if(mySupport->_is_nil()) - throw std::runtime_error("VISU_CorbaMedConvertor::Build >> mySupport->_is_nil()"); - SALOME_MED::GROUP_var aGroup = SALOME_MED::GROUP::_narrow(mySupport); - int aNbCells = 0; - if(!aGroup->_is_nil()){ - CORBA::String_var aName = aGroup->getName(); - myName = aName; - if(MYDEBUG) MESSAGE("BuildSupport aGroup->getName() = "<getFamilies(); - med_int iEnd = anArray->length(); - TMesh& aMesh = myMeshMap[myName]; - if(MYDEBUG) MESSAGE("BuildSupport - aGroup->getFamilies()->length() = "<> aNbCells == 0"); - if(MYDEBUG) MESSAGE("BuildSupport - aNbCells = "<