#include <valarray>
#include <vtkCellType.h>
+#include <boost/tuple/tuple.hpp>
+
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
return Build(aTimeStampIterator);
}
+namespace{
+
+ using namespace boost;
+
+ struct TSObjectByName{
+ std::string myName;
+ typedef tuple<SALOMEDS::SObject_var> 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<SALOME_MED::MESH_var,SALOMEDS::SObject_var> 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>
+ 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 = "<<aNbMeshes);
+
SALOMEDS::Study_var aStudy = mySObject->GetStudy();
- SALOMEDS::ChildIterator_var aMeshIterator = aStudy->NewChildIterator(aMeshSObj);
- for(; aMeshIterator->More(); aMeshIterator->Next()){
- aMeshSObj = aMeshIterator->Value();
- if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aMeshSObj = '"<<GetSObjectName(aMeshSObj)<<"'");
- CORBA::Object_var aMedMesh = VISU::SObjectToObject(aMeshSObj);
- if(CORBA::is_nil(aMedMesh)) continue;
- SALOME_MED::MESH_var aMEDMesh = SALOME_MED::MESH::_narrow(aMedMesh);
- if(aMEDMesh->_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 = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
- SALOMEDS::ChildIterator_var aSupportIterator = aStudy->NewChildIterator(aMeshSObj);
- 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 = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
- int aNbCells, aCellsSize;
- //Check, if there is any data on the support?
- if(aVEntity == VISU::NODE_ENTITY){
- aMesh.myNbPoints = aMeshOnSupport->getNumberOfNodes();
- aNbCells = aMesh.myNbPoints;
- aCellsSize = 2*aMesh.myNbPoints;
- }else{
- GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
+ SALOMEDS::SObject_var aMedCompSObj = mySObject->GetFather();
+
+ bool anIsSuccess = false;
+ TSObjectByName::TRet aSObjectByNameRet =
+ Find(aMedCompSObj,aStudy,TSObjectByName("MEDMESH"),anIsSuccess);
+ if(anIsSuccess){
+ SALOMEDS::SObject_var aMeshesSObj = boost::get<0>(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 = "<<aMeshName<<"; myDim = "<<aMesh.myDim);
+
+ anIsSuccess = false;
+ std::ostringstream aStream;
+ aStream<<"MEDSUPPORTS_OF_"<<aMeshName.in();
+ std::string aSupportsName(aStream.str());
+ TSObjectByName::TRet aSObjectByNameRet =
+ Find(aMeshesSObj,aStudy,TSObjectByName(aSupportsName.c_str()),anIsSuccess);
+ if(!anIsSuccess)
+ continue;
+
+ SALOMEDS::SObject_var aSupportsSObj = boost::get<0>(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 = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
+ int aNbCells, aCellsSize;
+ //Check, if there is any data on the support?
+ if(aVEntity == VISU::NODE_ENTITY){
+ aMesh.myNbPoints = aMeshOnSupport->getNumberOfNodes();
+ aNbCells = aMesh.myNbPoints;
+ aCellsSize = 2*aMesh.myNbPoints;
+ }else
+ GetCellsSize(aNbCells,aCellsSize,aMeshOnSupport,aVEntity);
+
+ if(aNbCells > 0){
+ VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[aVEntity];
+ aMeshOnEntity.myMeshName = aMeshName.in();
+ aMeshOnEntity.myEntity = aVEntity;
+ aMeshOnEntity.myNbCells = aNbCells;
+ aMeshOnEntity.myCellsSize = aCellsSize;
+
+ VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[aVEntity];
+ aMeshOnEntity2.mySupport = aMEDSupport;
+ }
+ continue;
}
- if(aNbCells == 0) continue;
- VISU::TMeshOnEntity& aMeshOnEntity = aMesh.myMeshOnEntityMap[aVEntity];
- aMeshOnEntity.myMeshName = aMeshName.in();
- aMeshOnEntity.myEntity = aVEntity;
- aMeshOnEntity.myNbCells = aNbCells;
- aMeshOnEntity.myCellsSize = aCellsSize;
- VISUMED::TMeshOnEntity& aMeshOnEntity2 = aMesh2.myMeshOnEntityMap[aVEntity];
- aMeshOnEntity2.mySupport = aMEDSupport;
- }else{
SALOME_MED::FAMILY_var aMEDFamily = SALOME_MED::FAMILY::_narrow(aMedSupport);
if(!aMEDFamily->_is_nil()) {
int aNbCells, aCellsSize;
VISUMED::TFamily& aFamily2 = aMeshOnEntity2.myFamilyMap[aSupportName.in()];
aFamily2.myFamily = aMEDFamily;
}
+ continue;
}
+
SALOME_MED::GROUP_var aMEDGroup = SALOME_MED::GROUP::_narrow(aMedSupport);
- if(!aMEDGroup->_is_nil()) {
+ if(!aMEDGroup->_is_nil()){
if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aGroup = '"<<aSupportName<<"' aVEntity = "<<aVEntity);
VISUMED::TGroupMap& aGroupMap2 = aMesh2.myGroupMap;
VISUMED::TGroup& aGroup2 = aGroupMap2[aSupportName.in()];
VISU::TBindGroups& aBindGroups = aFamily.myGroups;
aBindGroups.insert(aSupportName.in());
}
- }
- }
- }
- //Correction of TMesh.TGroupMap
- const VISU::TMeshOnEntityMap& aMeshOnEntityMap = aMesh.myMeshOnEntityMap;
- if(aMeshOnEntityMap.empty()) continue;
- VISU::TGroupMap& aGroupMap = aMesh.myGroupMap;
- VISU::TMeshOnEntityMap::const_iterator aMeshOnEntityMapIter = aMeshOnEntityMap.begin();
- for(; aMeshOnEntityMapIter != aMeshOnEntityMap.end(); aMeshOnEntityMapIter++){
- const VISU::TMeshOnEntity& aMeshOnEntity = aMeshOnEntityMapIter->second;
- const VISU::TFamilyMap& aFamilyMap = aMeshOnEntity.myFamilyMap;
- if(aFamilyMap.empty()) continue;
- VISU::TFamilyMap::const_iterator aFamilyMapIter = aFamilyMap.begin();
- for(; aFamilyMapIter != aFamilyMap.end(); aFamilyMapIter++){
- const VISU::TFamily& aFamily = aFamilyMapIter->second;
- const VISU::TBindGroups& aBindGroups = aFamily.myGroups;
- if(aBindGroups.empty()) continue;
- VISU::TBindGroups::const_iterator aBindGroupsIter = aBindGroups.begin();
- for(; aBindGroupsIter != aBindGroups.end(); aBindGroupsIter++){
- const string& aGroupName = *aBindGroupsIter;
- VISU::TGroup& aGroup = aGroupMap[aGroupName];
- aGroup.myName = aGroupName;
- aGroup.myMeshName = aMesh.myName;
- aGroup.myNbCells += aFamily.myNbCells;
- aGroup.myCellsSize += aFamily.myCellsSize;
- VISU::TFamilyAndEntity aFamilyAndEntity(aFamily.myName,aFamily.myEntity);
- aGroup.myFamilyAndEntitySet.insert(aFamilyAndEntity);
+ continue;
}
}
}
}
- SALOMEDS::SObject_var aFieldSObj;
- if(aMedCompSObj->FindSubObject(aTag+2,aFieldSObj)){
+
+ anIsSuccess = false;
+ aSObjectByNameRet = Find(aMedCompSObj,aStudy,TSObjectByName("MEDFIELD"),anIsSuccess);
+ if(anIsSuccess){
+ SALOMEDS::SObject_var aFieldsSObj = boost::get<0>(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 = '"<<GetSObjectName(aFieldSObj)<<"'");
SALOMEDS::ChildIterator_var aTimeStampIterator = aStudy->NewChildIterator(aFieldSObj);
for(int iTimeStamp = 1; aTimeStampIterator->More(); aTimeStampIterator->Next(), iTimeStamp++){
SALOMEDS::SObject_var aTimeStampSObj = aTimeStampIterator->Value();
if(MYDEBUG) MESSAGE("VISU_MEDConvertor::Build - aTimeStampSObj = '"<<GetSObjectName(aTimeStampSObj)<<"'");
CORBA::Object_var aMedField = VISU::SObjectToObject(aTimeStampSObj);
- if(CORBA::is_nil(aMedField)) continue;
+ if(CORBA::is_nil(aMedField))
+ continue;
+
SALOME_MED::FIELD_var aMEDField = SALOME_MED::FIELD::_narrow(aMedField);
- if(aMEDField->_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()];