From 232516edc798a92981328ea053eebf2b6b6882f7 Mon Sep 17 00:00:00 2001 From: apo Date: Wed, 12 Jan 2005 10:31:11 +0000 Subject: [PATCH] [Bug PAL7252] DEVELOPMENT: Porting to MED2.2 Adjusting to new data-tree of MED module --- src/VISU_I/VISU_CorbaMedConvertor.cxx | 275 +++++++++++++++++--------- 1 file changed, 184 insertions(+), 91 deletions(-) diff --git a/src/VISU_I/VISU_CorbaMedConvertor.cxx b/src/VISU_I/VISU_CorbaMedConvertor.cxx index 99336d9f..d3bd9f89 100644 --- a/src/VISU_I/VISU_CorbaMedConvertor.cxx +++ b/src/VISU_I/VISU_CorbaMedConvertor.cxx @@ -33,12 +33,14 @@ #include #include +#include + using namespace std; #define USER_INTERLACE MED_FULL_INTERLACE #ifdef _DEBUG_ -static int MYDEBUG = 0; +static int MYDEBUG = 0 #else static int MYDEBUG = 0; #endif @@ -367,66 +369,166 @@ VISU_MEDConvertor::Build() return Build(aTimeStampIterator); } +namespace{ + + using namespace boost; + + struct TSObjectByName{ + std::string myName; + typedef tuple TRet; + + TSObjectByName(const std::string& theName): + myName(theName) + {} + + TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess) + { + SALOMEDS::GenericAttribute_var anAttr; + if(theSObj->FindAttribute(anAttr,"AttributeName")){ + SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); + CORBA::String_var aValue = aName->Value(); + theIsSuccess = (myName == aValue.in()); + if(theIsSuccess) + return TRet(SALOMEDS::SObject::_duplicate(theSObj)); + } + return TRet(); + } + + }; + + struct TMeshByName{ + std::string myName; + typedef tuple TRet; + + TMeshByName(const std::string& theName): + myName(theName) + {} + + TRet operator()(SALOMEDS::SObject_ptr theSObj, bool& theIsSuccess) + { + CORBA::Object_var anObj = VISU::SObjectToObject(theSObj); + if(!CORBA::is_nil(anObj)){ + SALOME_MED::MESH_var aMesh = SALOME_MED::MESH::_narrow(anObj); + if(!CORBA::is_nil(aMesh)){ + CORBA::String_var aName = aMesh->getName(); + theIsSuccess = (myName == aName.in()); + if(theIsSuccess) + return TRet(aMesh,SALOMEDS::SObject::_duplicate(theSObj)); + } + } + return TRet(); + } + }; + + template + typename TFun::TRet + Find(SALOMEDS::SObject_ptr theStartSObj, + SALOMEDS::Study_ptr theStudy, + TFun theFun, + bool& theIsSuccess, + bool theIsAllLevels = true) + { + SALOMEDS::ChildIterator_var anIter = theStudy->NewChildIterator(theStartSObj); + anIter->InitEx(theIsAllLevels); + for(; anIter->More(); anIter->Next()){ + SALOMEDS::SObject_var aSObj = anIter->Value(); + typename TFun::TRet aRet = theFun(aSObj,theIsSuccess); + if(theIsSuccess) + return aRet; + } + return typename TFun::TRet(); + } + +} VISU_Convertor* VISU_MEDConvertor::Build(SALOME_MED::MED_ptr theMED) { - if(theMED->_is_nil()) return NULL; - CORBA::Short aTag = mySObject->Tag(); - SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather(); - SALOMEDS::SObject_var aMeshSObj; - if(!aMedCompSObj->FindSubObject(aTag+1,aMeshSObj)) - throw std::runtime_error("VISU_MEDConvertor::Build >> Cann't find MEDMESH label !!!"); - if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDMESH found."); + if(CORBA::is_nil(theMED)) + return NULL; + + CORBA::Long aNbMeshes = theMED->getNumberOfMeshes(); + SALOME_MED::string_array_var aMeshNames = theMED->getMeshNames(); + if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aNbMeshes = "<GetStudy(); - SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj); - for(; aMeshIterator->More(); aMeshIterator->Next()){ - aMeshSObj = aMeshIterator->Value(); - if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<_is_nil()) continue; - CORBA::String_var aMeshName = aMEDMesh->getName(); - VISU::TMesh &aMesh = myMeshMap[aMeshName.in()]; - aMesh.myDim = aMEDMesh->getSpaceDimension(); - aMesh.myName = aMeshName.in(); - aMesh.myPointsDim.resize(aMesh.myDim); - VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()]; - aMesh2.myMesh = aMEDMesh; - if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<(aSObjectByNameRet); + for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){ + anIsSuccess = false; + CORBA::String_var aMeshName = aMeshNames[iMesh]; + TMeshByName::TRet aMeshByNameRet = + Find(aMeshesSObj,aStudy,TMeshByName(aMeshName.in()),anIsSuccess); + if(!anIsSuccess) + continue; + + VISU::TMesh &aMesh = myMeshMap[aMeshName.in()]; + SALOME_MED::MESH_var aMEDMesh = boost::get<0>(aMeshByNameRet); + aMesh.myDim = aMEDMesh->getSpaceDimension(); + aMesh.myName = aMeshName.in(); + aMesh.myPointsDim.resize(aMesh.myDim); + VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()]; + aMesh2.myMesh = aMEDMesh; + + if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshName = "<(aSObjectByNameRet); + SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aSupportsSObj); + aSupportIterator->InitEx(true); + for(; aSupportIterator->More(); aSupportIterator->Next()){ + SALOMEDS::SObject_var aSupportSObj = aSupportIterator->Value(); + + CORBA::Object_var aMedSupport = VISU::SObjectToObject(aSupportSObj); + if(CORBA::is_nil(aMedSupport)) + continue; + + SALOME_MED::SUPPORT_var aMEDSupport = SALOME_MED::SUPPORT::_narrow(aMedSupport); + if(aMEDSupport->_is_nil()) + continue; + + SALOME_MED::MESH_var aMeshOnSupport = aMEDSupport->getMesh(); + SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity(); + VISU::TEntity aVEntity = MEDEntityToVTK(aMEntity); + CORBA::String_var aSupportName = aMEDSupport->getName(); + + if(aMEDSupport->isOnAllElements()){ + if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - Support isOnAllElements = '"<(aSObjectByNameRet); if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - MEDFIELD found."); - SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldSObj); + SALOMEDS::ChildIterator_var aFieldIterator = aStudy->NewChildIterator(aFieldsSObj); for(int iField = 0; aFieldIterator->More(); aFieldIterator->Next(), iField++){ - aFieldSObj = aFieldIterator->Value(); + SALOMEDS::SObject_var aFieldSObj = aFieldIterator->Value(); if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aFieldName = '"<NewChildIterator(aFieldSObj); for(int iTimeStamp = 1; aTimeStampIterator->More(); aTimeStampIterator->Next(), iTimeStamp++){ SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value(); if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<_is_nil()) continue; + if(aMEDField->_is_nil()) + continue; + SALOME_MED::SUPPORT_var aMEDSupport = aMEDField->getSupport(); - if(aMEDSupport->_is_nil()) continue; + if(aMEDSupport->_is_nil()) + continue; + SALOME_MED::medEntityMesh aMEntity = aMEDSupport->getEntity(); VISU::TEntity anEntity = MEDEntityToVTK(aMEntity); SALOME_MED::MESH_var aMEDMesh = aMEDSupport->getMesh(); - if(aMEDMesh->_is_nil()) continue; + if(aMEDMesh->_is_nil()) + continue; + CORBA::String_var aMeshName = aMEDMesh->getName(); CORBA::String_var aFieldName = aMEDField->getName(); - VISU::TMesh &aMesh = myMeshMap[aMeshName.in()]; + VISU::TMeshMap::iterator aMeshMapIter = myMeshMap.find(aMeshName.in()); + if(aMeshMapIter == myMeshMap.end()) + continue; + + VISU::TMesh &aMesh = aMeshMapIter->second; aMesh.myDim = aMEDMesh->getSpaceDimension(); aMesh.myName = aMeshName.in(); VISUMED::TMesh &aMesh2 = myMeshMap2[aMeshName.in()]; -- 2.39.2