]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
SALOME PAL V1_4_1
authorsmh <smh@opencascade.com>
Fri, 2 Apr 2004 13:47:08 +0000 (13:47 +0000)
committersmh <smh@opencascade.com>
Fri, 2 Apr 2004 13:47:08 +0000 (13:47 +0000)
29 files changed:
src/MEDWrapper/MEDA_Algorithm.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Algorithm.hxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Structures.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Structures.hxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Test.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Test1.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Wrapper.cxx [new file with mode: 0644]
src/MEDWrapper/MEDA_Wrapper.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Common.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Structures.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Structures.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Test.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Utilities.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Utilities.hxx [new file with mode: 0644]
src/MEDWrapper/MED_Wrapper.cxx [new file with mode: 0644]
src/MEDWrapper/MED_Wrapper.hxx [new file with mode: 0644]
src/MEDWrapper/Makefile.in [new file with mode: 0644]
src/Utils/Utils_CatchSignals.cxx [new file with mode: 0644]
src/Utils/Utils_CatchSignals.h [new file with mode: 0644]
src/Utils/Utils_ExceptHandlers.cxx [new file with mode: 0644]
src/Utils/Utils_ExceptHandlers.hxx [new file with mode: 0644]
src/VTKFilter/SALOME_ExtractUnstructuredGrid.cxx [new file with mode: 0644]
src/VTKFilter/SALOME_ExtractUnstructuredGrid.h [new file with mode: 0644]
src/VTKViewer/VTKViewer_CellRectPicker.cxx [new file with mode: 0644]
src/VTKViewer/VTKViewer_CellRectPicker.h [new file with mode: 0644]
src/VTKViewer/VTKViewer_Filter.cxx [new file with mode: 0755]
src/VTKViewer/VTKViewer_Filter.h [new file with mode: 0755]
src/VTKViewer/VTKViewer_RectPicker.cxx [new file with mode: 0644]
src/VTKViewer/VTKViewer_RectPicker.h [new file with mode: 0644]

diff --git a/src/MEDWrapper/MEDA_Algorithm.cxx b/src/MEDWrapper/MEDA_Algorithm.cxx
new file mode 100644 (file)
index 0000000..420e50f
--- /dev/null
@@ -0,0 +1,252 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Algorithm.hxx"
+#include "MED_Utilities.hxx"
+using namespace std;
+using namespace MEDA;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+TCellGroup MEDA::GetCellsByEntity(TWrapper& theWrapper, 
+                                 const PMeshInfo& theMeshInfo,
+                                 const MED::TEntityInfo theEntityInfo)
+{
+  if(MYDEBUG) MESSAGE("GetCellsByEntity(...)");
+  TCellGroup aGroup;
+  MED::TEntityInfo::const_iterator anIter = theEntityInfo.begin();
+  for(; anIter != theEntityInfo.end(); anIter++){
+    const med_entite_maillage& anEntity = anIter->first;
+    if(anEntity == MED_NOEUD) continue;
+    const MED::TGeom& aGeom = anIter->second;
+    TCellSet& aCellSet = aGroup[anEntity];
+    MED::TGeom::const_iterator anGeomIter = aGeom.begin();
+    for(; anGeomIter != aGeom.end(); anGeomIter++){
+      const med_geometrie_element& aGeo = anGeomIter->first;
+      PCellInfo aCellInfo = theWrapper.GetCellInfo(theMeshInfo,anEntity,aGeo);
+      aCellSet.insert(aCellInfo);
+      if(MYDEBUG){
+       med_int aNbElem = aCellInfo->GetNbElem();
+       MED::PrefixPrinter aPrefixPrinter;
+       BEGMSG("aGeo = "<<aGeo<<"; aNbElem = "<<aNbElem<<": ");
+       for(int iElem = 0; iElem < aNbElem; iElem++){
+         int iConnEnd = aCellInfo->GetConnDim();
+         for(int iConn = 0; iConn < iConnEnd; iConn++){
+           ADDMSG(aCellInfo->GetConn(iElem,iConn)<<",");
+         }
+         ADDMSG(" ");
+       }
+       ADDMSG("\n");
+      }
+    }
+  }
+  if(MYDEBUG) ADDMSG("\n");
+  return aGroup;
+}
+
+
+//---------------------------------------------------------------
+TFamilyGroup 
+MEDA::GetFamilies(TWrapper& theWrapper,
+                 const PMeshInfo& theMeshInfo)
+{
+  if(MYDEBUG) MESSAGE("GetFamilies(...)");
+  TFamilyGroup aGroup;
+  int aNbFam = theWrapper.GetNbFamilies(theMeshInfo);
+  MED::PrefixPrinter aPrefixPrinter;
+  if(MYDEBUG) BEGMSG("GetNbFamilies() = "<<aNbFam<<"\n");
+  for(int iFam = 0; iFam < aNbFam; iFam++){
+    PFamilyInfo aFamilyInfo = theWrapper.GetFamilyInfo(theMeshInfo,iFam);
+    aGroup.insert(aFamilyInfo);
+    if(MYDEBUG){
+      MED::PrefixPrinter aPrefixPrinter;
+      string aName = aFamilyInfo->GetName();
+      med_int aNbAttr = aFamilyInfo->GetNbAttr();
+      med_int aNbGroup = aFamilyInfo->GetNbGroup();
+      BEGMSG("aFamilyName = '"<<aName<<"'; andId = "<<aFamilyInfo->GetId()<<
+            "; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<"\n");
+      for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+       aName = aFamilyInfo->GetGroupName(iGroup);
+       MED::PrefixPrinter aPrefixPrinter;
+       BEGMSG("aGroupName = '"<<aName<<"'\n");
+      }
+    }
+  }
+  if(MYDEBUG) ADDMSG("\n");
+  return aGroup;
+}
+
+
+TGroupInfo 
+MEDA::GetFamiliesByGroup(const TFamilyGroup& theGroupInfo)
+{
+  if(MYDEBUG) MESSAGE("GetFamiliesByGroup(...)");
+  TGroupInfo aGroup;
+  TFamilyGroup::const_iterator anIter = theGroupInfo.begin();
+  for(; anIter != theGroupInfo.end(); anIter++){
+    const PFamilyInfo& aFamilyInfo = *anIter;
+    int aNbGroup = aFamilyInfo->GetNbGroup();
+    for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+      aGroup[aFamilyInfo->GetGroupName(iGroup)].insert(aFamilyInfo);
+    } 
+  }
+  if(MYDEBUG){
+    TGroupInfo::const_iterator anIter = aGroup.begin();
+    for(; anIter != aGroup.end(); anIter++){
+      string aName = anIter->first;
+      MED::PrefixPrinter aPrefixPrinter;
+      BEGMSG("aGroupName = '"<<aName<<"'\n");
+      const TFamilyGroup& aFamilyGroup = anIter->second;
+      TFamilyGroup::const_iterator anFamIter = aFamilyGroup.begin();
+      for(; anFamIter != aFamilyGroup.end(); anFamIter++){
+       const PFamilyInfo& aFamilyInfo = *anFamIter;
+       MED::PrefixPrinter aPrefixPrinter;
+       BEGMSG("aFamilyName = '"<<aFamilyInfo->GetName()<<"'\n");
+      }
+    }
+    ADDMSG("\n");
+  }
+  return aGroup;
+}
+
+
+//---------------------------------------------------------------
+TTimeStampGroup 
+MEDA::GetFieldsByEntity(TWrapper& theWrapper, 
+                       const PMeshInfo& theMeshInfo,
+                       const MED::TEntityInfo theEntityInfo)
+{
+  if(MYDEBUG) MESSAGE("GetFieldsByEntity(...)");
+  TTimeStampGroup aGroup;
+  med_int aNbFields = theWrapper.GetNbFields(); 
+  MED::PrefixPrinter aPrefixPrinter;
+  if(MYDEBUG) BEGMSG("GetNbFields() = "<<aNbFields<<"\n");
+  for(int iField = 0; iField < aNbFields; iField++){
+    PFieldInfo aFieldInfo = theWrapper.GetFieldInfo(theMeshInfo,iField);
+    med_int aNbComp = aFieldInfo->GetNbComp();
+    string aName = aFieldInfo->GetName();
+    MED::PrefixPrinter aPrefixPrinter;
+    if(MYDEBUG) BEGMSG("aFieldName = '"<<aName<<"'; aNbComp = "<<aNbComp<<"; ");
+    MED::TGeom aGeom;
+    med_entite_maillage anEntity;
+    med_int aNbTimeStamps = theWrapper.GetNbTimeStamps(aFieldInfo,theEntityInfo,anEntity,aGeom);
+    if(MYDEBUG) BEGMSG("anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<"\n");
+    for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
+      PTimeStampInfo aTimeStamp = 
+       theWrapper.GetTimeStampInfo(aFieldInfo,iTimeStamp,anEntity,aGeom);
+      aGroup[aFieldInfo].insert(aTimeStamp);
+      med_int aNbGauss = aTimeStamp->GetNbGauss();
+      MED::PrefixPrinter aPrefixPrinter;
+      if(MYDEBUG) BEGMSG("aDt = "<<aTimeStamp->GetDt()<<", "<<aTimeStamp->GetUnitDt()<<"\n");
+    }
+  }
+  if(MYDEBUG) ADDMSG("\n");
+  return aGroup;
+}
+
+
+TFieldGroup 
+MEDA::GetFieldsByEntity(const TTimeStampGroup& theTimeStampGroup)
+{
+  TFieldGroup aGroup;
+  TTimeStampGroup::const_iterator anIter = theTimeStampGroup.begin();
+  for(; anIter != theTimeStampGroup.end(); anIter++){
+    const PFieldInfo& aFieldInfo = anIter->first;
+    const TTimeStampSet& aTimeStampSet = anIter->second;
+    if(aTimeStampSet.empty()) continue;
+    const PTimeStampInfo& aTimeStampInfo = *aTimeStampSet.begin();
+    aGroup[aTimeStampInfo->GetEntity()].insert(*anIter);
+  }
+  return aGroup;
+}
+
+
+TFamilyByEntity
+MEDA::GetFamiliesByEntity(TWrapper& theWrapper, 
+                         const PNodeInfo& theNodeInfo,
+                         const TCellGroup& theCellGroup,
+                         const TFamilyGroup& theFamilyGroup)
+{
+  if(MYDEBUG) MESSAGE("GetFamiliesByEntity(...)");
+  TFamilyByEntity aFamilyByEntity;
+
+  typedef map<med_int,PFamilyInfo> TFamilyByIdMap;
+  TFamilyByIdMap aFamilyByIdMap;
+  TFamilyGroup::const_iterator anIter = theFamilyGroup.begin();
+  for(; anIter != theFamilyGroup.end(); anIter++){
+    const PFamilyInfo& aFamilyInfo = *anIter;
+    aFamilyByIdMap.insert(TFamilyByIdMap::value_type(aFamilyInfo->GetId(),aFamilyInfo));
+  }
+
+  if(!aFamilyByIdMap.empty()){
+    typedef set<med_int> TFamilyIdSet;
+    typedef map<med_entite_maillage,TFamilyIdSet> TFamilyIdByEntity;
+    TFamilyIdByEntity aFamilyIdByEntity;
+
+    if(theNodeInfo){
+      if(med_int aNbElem = theNodeInfo->GetNbElem()){
+       TFamilyIdSet& aFamilyIdSet = aFamilyIdByEntity[MED_NOEUD];
+       for(med_int i = 0; i < aNbElem; i++){
+         aFamilyIdSet.insert(theNodeInfo->GetFamNum(i));
+       }
+      }
+    }
+    
+    if(!theCellGroup.empty()){
+      TCellGroup::const_iterator anIter = theCellGroup.begin();
+      for(; anIter != theCellGroup.end(); anIter++){
+       const med_entite_maillage& anEntity = anIter->first;
+       TFamilyIdSet& aFamilyIdSet = aFamilyIdByEntity[anEntity];
+       const TCellSet& aCellSet = anIter->second;
+       TCellSet::const_iterator anCellIter = aCellSet.begin();
+       for(; anCellIter != aCellSet.end(); anCellIter++){
+         const PCellInfo& aCellInfo = *anCellIter;
+         if(med_int aNbElem = aCellInfo->GetNbElem()){
+           for(med_int i = 0; i < aNbElem; i++){
+             aFamilyIdSet.insert(aCellInfo->GetFamNum(i));
+           }
+         }
+       }
+      }
+    }
+    
+    if(!aFamilyIdByEntity.empty()){
+      TFamilyIdByEntity::const_iterator anIter = aFamilyIdByEntity.begin();
+      for(; anIter != aFamilyIdByEntity.end(); anIter++){
+       const med_entite_maillage& anEntity = anIter->first;
+       MED::PrefixPrinter aPrefixPrinter;
+       if(MYDEBUG) BEGMSG("anEntity = "<<anEntity<<":\n");
+       const TFamilyIdSet& aFamilyIdSet = anIter->second;
+       TFamilyIdSet::const_iterator anFamilyIdIter = aFamilyIdSet.begin();
+       for(; anFamilyIdIter != aFamilyIdSet.end(); anFamilyIdIter++){
+         const med_int& aFamilyId = *anFamilyIdIter;
+         TFamilyByIdMap::const_iterator 
+           anFamilyByIdMapIter = aFamilyByIdMap.find(aFamilyId);
+         if(anFamilyByIdMapIter != aFamilyByIdMap.end()){
+           const PFamilyInfo& aFamilyInfo = anFamilyByIdMapIter->second;
+           aFamilyByEntity[anEntity].insert(aFamilyInfo);
+           MED::PrefixPrinter aPrefixPrinter;
+           if(MYDEBUG) 
+             BEGMSG("aFamilyName = '"<<aFamilyInfo->GetName()<<
+                    "' anId = "<<aFamilyInfo->GetId()<<"\n");
+         }
+       }
+      }
+    }
+  }    
+  if(MYDEBUG) ADDMSG("\n");
+  return aFamilyByEntity;
+}
+
diff --git a/src/MEDWrapper/MEDA_Algorithm.hxx b/src/MEDWrapper/MEDA_Algorithm.hxx
new file mode 100644 (file)
index 0000000..326da0d
--- /dev/null
@@ -0,0 +1,69 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MEDA_Algorithm_HeaderFile
+#define MEDA_Algorithm_HeaderFile
+
+#include "MEDA_Structures.hxx"
+#include "MEDA_Wrapper.hxx"
+
+#include <set>
+
+namespace MEDA{
+  using namespace std;
+  using namespace boost;
+
+
+  //---------------------------------------------------------------
+  typedef set<PCellInfo> TCellSet;
+  typedef map<med_entite_maillage,TCellSet> TCellGroup;
+
+  TCellGroup GetCellsByEntity(TWrapper& theWrapper, 
+                             const PMeshInfo& theMeshInfo,
+                             const MED::TEntityInfo theEntityInfo);
+
+
+  //---------------------------------------------------------------
+  typedef set<PFamilyInfo> TFamilyGroup;
+
+  TFamilyGroup GetFamilies(TWrapper& theWrapper, 
+                          const PMeshInfo& theMeshInfo);
+
+
+  //---------------------------------------------------------------
+  typedef map<med_entite_maillage,TFamilyGroup> TFamilyByEntity;
+  
+  TFamilyByEntity GetFamiliesByEntity(TWrapper& theWrapper, 
+                                     const PNodeInfo& theNodeInfo, 
+                                     const TCellGroup& theCellGroup,
+                                     const TFamilyGroup& theFamilyGroup);
+
+
+  //---------------------------------------------------------------
+  typedef map<string,TFamilyGroup> TGroupInfo;
+  
+  TGroupInfo GetFamiliesByGroup(const TFamilyGroup& theGroupInfo);
+
+
+  //---------------------------------------------------------------
+  typedef set<PTimeStampInfo> TTimeStampSet;
+  typedef map<PFieldInfo,TTimeStampSet> TTimeStampGroup;
+
+  TTimeStampGroup GetFieldsByEntity(TWrapper& theWrapper, 
+                                   const PMeshInfo& theMeshInfo,
+                                   const MED::TEntityInfo theEntityInfo);
+
+
+  //---------------------------------------------------------------
+  typedef map<med_entite_maillage,TTimeStampGroup> TFieldGroup;
+
+  TFieldGroup GetFieldsByEntity(const TTimeStampGroup& theTimeStampGroup);
+
+};
+
+#endif
diff --git a/src/MEDWrapper/MEDA_Structures.cxx b/src/MEDWrapper/MEDA_Structures.cxx
new file mode 100644 (file)
index 0000000..eb10c07
--- /dev/null
@@ -0,0 +1,333 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Structures.hxx"
+#include "MED_Structures.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MEDA;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+TNameInfo::TNameInfo(const MED::PNameInfo& theInfo): 
+  myInfo(theInfo) 
+{}
+
+string TNameInfo::GetName() const{
+  return myInfo->GetName();
+}
+
+void TNameInfo::SetName(const string& theValue){
+  myInfo->SetName(theValue);
+}
+
+
+//---------------------------------------------------------------
+TMeshInfo::TMeshInfo(const MED::PMeshInfo& theInfo): 
+  TNameInfo(theInfo),
+  myInfo(theInfo)
+{}
+
+med_int TMeshInfo::GetDim() const{
+  return myInfo->myDim;
+}
+
+
+//---------------------------------------------------------------
+TFamilyInfo::TFamilyInfo(const MED::PFamilyInfo& theInfo): 
+  TNameInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_int TFamilyInfo::GetId() const{
+  return myInfo->myId;
+}
+
+void TFamilyInfo::SetId(med_int theId){
+  myInfo->myId = theId;
+}
+
+med_int TFamilyInfo::GetNbGroup() const{
+  return myInfo->myNbGroup;
+}
+
+string TFamilyInfo::GetGroupName(med_int theId) const{
+  return myInfo->GetGroupName(theId);
+}
+
+void TFamilyInfo::SetGroupName(med_int theId, const string& theValue){
+  myInfo->SetGroupName(theId,theValue);
+}
+
+med_int TFamilyInfo::GetNbAttr() const{
+  return myInfo->myNbAttr;
+}
+
+string TFamilyInfo::GetAttrDesc(med_int theId) const{
+  return myInfo->GetAttrDesc(theId);
+}
+
+void TFamilyInfo::SetAttrDesc(med_int theId, const string& theValue){
+  myInfo->SetAttrDesc(theId,theValue);
+}
+
+med_int TFamilyInfo::GetAttrId(med_int theId) const{
+  return myInfo->myAttrId[theId];
+}
+
+void TFamilyInfo::SetAttrId(med_int theId, med_int theVal){
+  myInfo->myAttrId[theId] = theVal;
+}
+
+med_int TFamilyInfo::GetAttrVal(med_int theId) const{
+  return myInfo->myAttrVal[theId];
+}
+
+void TFamilyInfo::SetAttrVal(med_int theId, med_int theVal){
+  myInfo->myAttrVal[theId] = theVal;
+}
+
+
+//---------------------------------------------------------------
+TElemInfo::TElemInfo(const MED::PElemInfo& theInfo): 
+  myInfo(theInfo) 
+{}
+
+med_int TElemInfo::GetNbElem() const{
+  return myInfo->myNbElem;
+}
+
+med_int TElemInfo::GetFamNum(med_int theId) const{
+  return myInfo->myFamNum[theId];
+}
+
+void TElemInfo::SetFamNum(med_int theId, med_int theValue){
+  myInfo->myFamNum[theId] = theValue;
+}
+
+med_booleen TElemInfo::IsElemNum() const{
+  return myInfo->myIsElemNum;
+}
+
+med_int TElemInfo::GetElemNum(med_int theId) const{
+  if(theId < 0 || myInfo->myElemNum.size() < theId)
+    EXCEPTION(runtime_error,"TElemInfo::GetElemNum - myInfo->myElemNum.size() = "<<
+             myInfo->myElemNum.size()<<"; theId = "<<theId<<")");
+  return myInfo->myElemNum[theId];
+}
+
+void TElemInfo::SetElemNum(med_int theId, med_int theValue){
+  if(theId < 0 || myInfo->myElemNum.size() < theId)
+    EXCEPTION(runtime_error,"TElemInfo::SetElemNum - myInfo->myElemNum.size() = "<<
+             myInfo->myElemNum.size()<<"; theId = "<<theId<<")");
+  myInfo->myElemNum[theId] = theValue;
+}
+
+med_booleen TElemInfo::IsElemNames() const{
+  return myInfo->myIsElemNames;
+}
+
+string TElemInfo::GetElemName(med_int theId) const{
+  return myInfo->GetElemName(theId);
+}
+
+void TElemInfo::SetElemName(med_int theId, const string& theValue){
+  myInfo->SetElemName(theId,theValue);
+}
+
+
+//---------------------------------------------------------------
+TNodeInfo::TNodeInfo(const MED::PNodeInfo& theInfo): 
+  TElemInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_repere TNodeInfo::GetSystem() const{
+  return myInfo->mySystem;
+}
+
+void TNodeInfo::GetSystem(med_repere theSystem){
+  myInfo->mySystem = theSystem;
+}
+
+med_float TNodeInfo::GetNodeCoord(med_int theId, med_int theComp) const{
+  return myInfo->myCoord[myInfo->myMeshInfo->myDim*theId + theComp];
+}
+
+void TNodeInfo::SetNodeCoord(med_int theId, med_int theComp, med_float theVal){
+  myInfo->myCoord[myInfo->myMeshInfo->myDim*theId + theComp] = theVal;
+}
+
+string TNodeInfo::GetCoordName(med_int theId) const{
+  return myInfo->GetCoordName(theId);
+}
+
+void TNodeInfo::SetCoordName(med_int theId, const string& theValue){
+  myInfo->SetCoordName(theId,theValue);
+}
+
+string TNodeInfo::GetCoordUnit(med_int theId) const{
+  return myInfo->GetCoordUnit(theId);
+}
+
+void TNodeInfo::SetCoordUnit(med_int theId, const string& theValue){
+  myInfo->SetCoordUnit(theId,theValue);
+}
+
+
+//---------------------------------------------------------------
+TCellInfo::TCellInfo(const MED::PCellInfo& theInfo): 
+  TElemInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_entite_maillage TCellInfo::GetEntity() const{
+  return myInfo->myTEntity;
+}
+
+med_geometrie_element TCellInfo::GetGeom() const{
+  return myInfo->myTGeom;
+}
+
+med_connectivite TCellInfo::GetConn() const{
+  return myInfo->myTConn;
+}
+
+med_int TCellInfo::GetConnDim() const{
+  return myInfo->myConnDim;
+}
+
+med_int TCellInfo::GetConn(med_int theElemId, med_int theConnId) const{
+  med_int anId = myInfo->myConnDim*theElemId + theConnId;
+  if(anId < 0 || myInfo->myConn.size() < anId)
+    EXCEPTION(runtime_error,"TElemInfo::GetConn - myInfo->myConn.size() = "<<
+             myInfo->myConn.size()<<"; anId = "<<anId<<")");
+  return myInfo->myConn[anId];
+}
+void TCellInfo::SetConn(med_int theElemId, med_int theConnId, med_int theVal){
+  med_int anId = myInfo->myConnDim*theElemId + theConnId;
+  if(anId < 0 || myInfo->myConn.size() < anId)
+    EXCEPTION(runtime_error,"TElemInfo::SetConn - myInfo->myConn.size() = "<<
+             myInfo->myConn.size()<<"; anId = "<<anId<<")");
+  myInfo->myConn[myInfo->myConnDim*theElemId + theConnId] = theVal;
+}
+
+
+//---------------------------------------------------------------
+TFieldInfo::TFieldInfo(const MED::PFieldInfo& theInfo): 
+  TNameInfo(theInfo),
+  myInfo(theInfo) 
+{}
+
+med_type_champ TFieldInfo::GetType() const{
+  return myInfo->myType;
+}
+
+med_int TFieldInfo::GetNbComp() const{
+  return myInfo->myNbComp;
+}
+
+string TFieldInfo::GetCompName(med_int theId) const{
+  return myInfo->GetCompName(theId);
+}
+
+void TFieldInfo::SetCompName(med_int theId, const string& theValue){
+  myInfo->SetCompName(theId,theValue);
+}
+
+string TFieldInfo::GetUnitName(med_int theId) const{
+  return myInfo->GetUnitName(theId);
+}
+
+void TFieldInfo::SetUnitName(med_int theId, const string& theValue){
+  myInfo->SetUnitName(theId,theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampInfo::TTimeStampInfo(const MED::PTimeStampInfo& theInfo): 
+  myInfo(theInfo) 
+{}
+
+med_entite_maillage TTimeStampInfo::GetEntity() const{
+  return myInfo->myEntity;
+}
+
+const MED::TGeom& TTimeStampInfo::GetGeom() const{
+  return myInfo->myGeom;
+}
+
+med_int TTimeStampInfo::GetNbGauss() const{
+  return myInfo->myNbGauss;
+}
+
+med_int TTimeStampInfo::GetNumDt() const{
+  return myInfo->myNumDt;
+}
+
+med_int TTimeStampInfo::GetNumOrd() const{
+  return myInfo->myNumOrd;
+}
+
+med_float TTimeStampInfo::GetDt() const{
+  return myInfo->myDt;
+}
+
+string TTimeStampInfo::GetUnitDt() const{
+  return myInfo->GetUnitDt();
+}
+
+void TTimeStampInfo::SetUnitDt(const string& theValue){
+  myInfo->SetUnitDt(theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampVal::TTimeStampVal(const MED::PTimeStampVal& theInfo): 
+  myInfo(theInfo) 
+{}
+
+med_float TTimeStampVal::GetVal(med_geometrie_element theGeom, 
+                               med_int theId, 
+                               med_int theComp, 
+                               med_int theGauss) const
+{
+  med_int aNbComp = myInfo->myTimeStampInfo->myFieldInfo->myNbComp;
+  med_int aNbGauss = myInfo->myTimeStampInfo->myNbGauss;
+  med_int aStep = aNbComp*aNbGauss;
+  return myInfo->myMeshValue[theGeom][theId*aStep + theComp*aNbGauss + theGauss];
+}
+
+void TTimeStampVal::SetVal(med_geometrie_element theGeom,
+                          med_int theId, 
+                          med_int theComp, 
+                          med_float theVal, 
+                          med_int theGauss)
+{
+  med_int aNbComp = myInfo->myTimeStampInfo->myFieldInfo->myNbComp;
+  med_int aNbGauss = myInfo->myTimeStampInfo->myNbGauss;
+  med_int aStep = aNbComp*aNbGauss;
+  myInfo->myMeshValue[theGeom][theId*aStep + theComp*aNbGauss + theGauss] = theVal;
+}
+
+string TTimeStampVal::GetPflName() const{
+  return myInfo->GetPflName();
+}
+
+void TTimeStampVal::SetPflName(const string& theValue){
+  myInfo->SetPflName(theValue);
+}
+
diff --git a/src/MEDWrapper/MEDA_Structures.hxx b/src/MEDWrapper/MEDA_Structures.hxx
new file mode 100644 (file)
index 0000000..674600a
--- /dev/null
@@ -0,0 +1,205 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MEDA_Structures_HeaderFile
+#define MEDA_Structures_HeaderFile
+
+#include "MED_Common.hxx"
+
+namespace MEDA{
+  using namespace std;
+  using namespace boost;
+
+//---------------------------------------------------------------
+  class TNameInfo{
+    friend class TWrapper;
+    TNameInfo();
+  protected:
+    MED::PNameInfo myInfo;
+    TNameInfo(const MED::PNameInfo& theInfo);
+  public:
+    virtual ~TNameInfo() {} 
+
+    string GetName() const;
+    void SetName(const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  class TMeshInfo: public TNameInfo{
+    friend class TWrapper;
+    TMeshInfo();
+  protected:
+    MED::PMeshInfo myInfo;
+    TMeshInfo(const MED::PMeshInfo& theInfo);
+
+  public:
+    med_int GetDim() const;
+  };
+  typedef shared_ptr<TMeshInfo> PMeshInfo;
+
+
+//---------------------------------------------------------------
+  class TFamilyInfo: public TNameInfo{
+    friend class TWrapper;
+    TFamilyInfo();
+  protected:
+    MED::PFamilyInfo myInfo;
+    TFamilyInfo(const MED::PFamilyInfo& theInfo);
+  public:
+    med_int GetId() const;
+    void SetId(med_int theId);
+
+    med_int GetNbGroup() const;
+    string GetGroupName(med_int theId) const;
+    void SetGroupName(med_int theId, const string& theValue);
+
+    med_int GetNbAttr() const;
+    string GetAttrDesc(med_int theId) const;
+    void SetAttrDesc(med_int theId, const string& theValue);
+    
+    med_int GetAttrId(med_int theId) const;
+    void SetAttrId(med_int theId, med_int theVal);
+
+    med_int GetAttrVal(med_int theId) const;
+    void SetAttrVal(med_int theId, med_int theVal);
+  };
+  typedef shared_ptr<TFamilyInfo> PFamilyInfo;
+
+
+//---------------------------------------------------------------
+  class TElemInfo{
+    friend class TWrapper;
+    TElemInfo();
+  protected:
+    MED::PElemInfo myInfo;
+    TElemInfo(const MED::PElemInfo& theInfo);
+  public:
+    virtual ~TElemInfo() {} 
+
+    med_int GetNbElem() const;
+
+    med_int GetFamNum(med_int theId) const;
+    void SetFamNum(med_int theId, med_int theValue);
+
+    med_booleen IsElemNum() const;
+    med_int GetElemNum(med_int theId) const;
+    void SetElemNum(med_int theId, med_int theValue);
+
+    med_booleen IsElemNames() const;
+    string GetElemName(med_int theId) const;
+    void SetElemName(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  class TNodeInfo: public TElemInfo{
+    friend class TWrapper;
+    TNodeInfo();
+  protected:
+    MED::PNodeInfo myInfo;
+    TNodeInfo(const MED::PNodeInfo& theInfo);
+  public:
+    med_repere GetSystem() const;
+    void GetSystem(med_repere theSystem);
+    
+    med_float GetNodeCoord(med_int theId, med_int theComp) const;
+    void SetNodeCoord(med_int theId, med_int theComp, med_float theVal);
+
+    string GetCoordName(med_int theId) const;
+    void SetCoordName(med_int theId, const string& theValue);
+
+    string GetCoordUnit(med_int theId) const;
+    void SetCoordUnit(med_int theId, const string& theValue);
+  };
+  typedef shared_ptr<TNodeInfo> PNodeInfo;
+
+
+//---------------------------------------------------------------
+  class TCellInfo: public TElemInfo{
+    friend class TWrapper;
+    TCellInfo();
+  protected:
+    MED::PCellInfo myInfo;
+    TCellInfo(const MED::PCellInfo& theInfo);
+  public:
+    med_entite_maillage GetEntity() const;
+    med_geometrie_element GetGeom() const;
+    med_connectivite GetConn() const;
+    
+    med_int GetConnDim() const;
+    med_int GetConn(med_int theElemId, med_int theConnId) const;
+    void SetConn(med_int theElemId, med_int theConnId, med_int theVal);
+  };
+  typedef shared_ptr<TCellInfo> PCellInfo;
+
+
+//---------------------------------------------------------------
+  class TFieldInfo: public TNameInfo{
+    friend class TWrapper;
+    TFieldInfo();
+  protected:
+    MED::PFieldInfo myInfo;
+    TFieldInfo(const MED::PFieldInfo& theInfo);
+  public:
+    med_type_champ GetType() const;
+    med_int GetNbComp() const;
+
+    string GetCompName(med_int theId) const;
+    void SetCompName(med_int theId, const string& theValue);
+
+    string GetUnitName(med_int theId) const;
+    void SetUnitName(med_int theId, const string& theValue);
+  };
+  typedef shared_ptr<TFieldInfo> PFieldInfo;
+
+
+//---------------------------------------------------------------
+  class TTimeStampInfo{
+    friend class TWrapper;
+    TTimeStampInfo();
+  protected:
+    MED::PTimeStampInfo myInfo;
+    TTimeStampInfo(const MED::PTimeStampInfo& theInfo);
+  public:
+    med_entite_maillage GetEntity() const;
+    const MED::TGeom& GetGeom() const;
+
+    med_int GetNbGauss() const;
+    med_int GetNumDt() const;
+    med_int GetNumOrd() const;
+
+    med_float GetDt() const;
+
+    string GetUnitDt() const;
+    void SetUnitDt(const string& theValue);
+  };
+  typedef shared_ptr<TTimeStampInfo> PTimeStampInfo;
+  
+
+//---------------------------------------------------------------
+  class TTimeStampVal{
+    friend class TWrapper;
+    TTimeStampVal();
+  protected:
+    MED::PTimeStampVal myInfo;
+    TTimeStampVal(const MED::PTimeStampVal& theInfo);
+  public:
+    med_float GetVal(med_geometrie_element theGeom, med_int theId, 
+                    med_int theComp, med_int theGauss = 0) const;
+    void SetVal(med_geometrie_element theGeom, med_int theId, 
+               med_int theComp, med_float theVal, med_int theGauss = 0);
+    
+    string GetPflName() const;
+    void SetPflName(const string& theValue);
+  };
+  typedef shared_ptr<TTimeStampVal> PTimeStampVal;
+  
+};
+
+#endif
diff --git a/src/MEDWrapper/MEDA_Test.cxx b/src/MEDWrapper/MEDA_Test.cxx
new file mode 100644 (file)
index 0000000..396dd1d
--- /dev/null
@@ -0,0 +1,182 @@
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File:    VISUConvertor.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Structures.hxx"
+#include "MEDA_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+
+#ifdef DEBUG
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+void ReadMed(const char* theFileName){
+  using namespace MEDA;
+  TWrapper aMed(theFileName);
+  string aFileName = theFileName;
+  aFileName += "+";
+  TWrapper aMedW(aFileName);
+
+  int aNbMeshes = aMed.GetNbMeshes();
+  cout<<"GetNbMeshes() = "<<aNbMeshes<<endl;
+
+  string aName;
+  for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+    PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh);
+    int aDim = aMeshInfo->GetDim();
+    PMeshInfo aMeshInfoW = TWrapper::CrMeshInfo(aMeshInfo);
+    aName = aMeshInfoW->GetName();
+    cout<<"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<endl;
+    aName[0] += 1;
+    aMeshInfoW->SetName(aName);
+    aMedW.SetMeshInfo(aMeshInfoW);
+  
+    int aNbFam = aMed.GetNbFamilies(aMeshInfo);
+    cout<<"GetNbFamilies() = "<<aNbFam<<endl;
+    for(int iFam = 0; iFam < aNbFam; iFam++){
+      PFamilyInfo aFamilyInfo = aMed.GetFamilyInfo(aMeshInfo,iFam);
+      PFamilyInfo aFamilyInfoW = TWrapper::CrFamilyInfo(aMeshInfoW,aFamilyInfo);
+      aName = aFamilyInfo->GetName();
+      int aNbAttr = aFamilyInfo->GetNbAttr();
+      int aNbGroup = aFamilyInfo->GetNbGroup();
+      cout<<"\taName = '"<<aName<<"'; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<endl;
+      aName[0] += 1;
+      aFamilyInfoW->SetName(aName);
+      for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+       aName = aFamilyInfo->GetGroupName(iGroup);
+       cout<<"\t\taGroupName = '"<<aName<<"'\n";
+       aName[0] += 1;
+       aFamilyInfoW->SetGroupName(iGroup,aName);
+      }
+      aMedW.SetFamilyInfo(aFamilyInfoW);
+    }
+
+    MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo);
+    cout<<"GetEntityInfo - aNbEntities = "<<aEntityInfo.size()<<endl;
+    MED::TEntityInfo::iterator anEntityIter = aEntityInfo.begin();
+    for(; anEntityIter != aEntityInfo.end(); anEntityIter++){
+      const med_entite_maillage& anEntity = anEntityIter->first;
+      cout<<"\tanEntity = "<<anEntity<<endl;
+      if(anEntity == MED_NOEUD){
+       PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo);
+       PNodeInfo aNodeInfoW = TWrapper::CrNodeInfo(aMeshInfoW,aNodeInfo);
+       int aNbNodes = aNodeInfo->GetNbElem();
+       cout<<"\tGetNodeInfo - aNbNodes = "<<aNbNodes<<": ";
+       for(int iNode = 0; iNode < aNbNodes; iNode++){
+         for(int iDim = 0; iDim < aDim; iDim++){
+           //cout<<aNodeInfo->GetNodeCoord(iNode,iDim)<<",";
+         }
+         cout<<" ";
+       }
+       cout<<endl;
+       aMedW.SetNodeInfo(aNodeInfoW);
+       continue;
+      }
+      const MED::TGeom& aTGeom = anEntityIter->second;
+      MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
+      for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+       const med_geometrie_element& aGeom = anTGeomIter->first;
+       PCellInfo aCellInfo = aMed.GetCellInfo(aMeshInfo,anEntity,aGeom);
+       PCellInfo aCellInfoW = TWrapper::CrCellInfo(aMeshInfoW,aCellInfo);
+       med_int aNbElem = aCellInfo->GetNbElem();
+       cout<<"\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ";
+       for(int iElem = 0; iElem < aNbElem; iElem++){
+         int iConnEnd = aCellInfo->GetConnDim();
+         for(int iConn = 0; iConn < iConnEnd; iConn++){
+           //cout<<aCellInfo->GetConn(iElem,iConn)<<",";
+         }
+         cout<<" ";
+       }
+       cout<<endl;
+       aMedW.SetCellInfo(aCellInfoW);
+      }
+    }
+
+    med_int aNbFields = aMed.GetNbFields(); 
+    cout<<"GetNbFields() = "<<aNbFields<<endl;
+    for(int iField = 0; iField < aNbFields; iField++){
+      PFieldInfo aFieldInfo = aMed.GetFieldInfo(aMeshInfo,iField);
+      PFieldInfo aFieldInfoW = TWrapper::CrFieldInfo(aMeshInfoW,aFieldInfo);
+      med_int aNbComp = aFieldInfo->GetNbComp();
+      aName = aFieldInfo->GetName();
+      cout<<"\taName = '"<<aName<<"'; aNbComp = "<<aNbComp<<"; ";
+      aName[0] += 1;
+      aFieldInfoW->SetName(aName);
+      aMedW.SetFieldInfo(aFieldInfoW);
+      MED::TGeom aTGeom;
+      med_entite_maillage anEntity;
+      med_int aNbTimeStamps = aMed.GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aTGeom);
+      cout<<"anEntity = "<<anEntity<<"; GetNbTimeStamps = "<<aNbTimeStamps<<endl;
+      for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
+       PTimeStampInfo aTimeStamp = aMed.GetTimeStampInfo(aFieldInfo,iTimeStamp,
+                                                         anEntity,aTGeom);
+       PTimeStampInfo aTimeStampW = TWrapper::CrTimeStampInfo(aFieldInfoW,aTimeStamp);
+       med_int aNbGauss = aTimeStamp->GetNbGauss();
+       cout<<"\t\taDt = "<<aTimeStamp->GetDt()<<", "<<aTimeStamp->GetUnitDt()<<endl;
+       PTimeStampVal aTimeStampVal = aMed.GetTimeStampVal(aTimeStamp);
+       PTimeStampVal aTimeStampValW = TWrapper::CrTimeStampVal(aTimeStampW,aTimeStampVal);
+       MED::TGeom::const_iterator anTGeomIter = aTGeom.begin();
+       for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+         const med_geometrie_element& aGeom = anTGeomIter->first;
+         med_int aNbElem = anTGeomIter->second;
+         cout<<"\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ";
+         for(int iElem = 0; iElem < aNbElem; iElem++){
+           for(int j = 0; j < aNbComp; j++){
+             for(int k = 0; k < aNbGauss; k++){
+               //cout<<aTimeStampValW->GetVal(aGeom,iElem,j,k)<<",";
+             }
+           }
+           cout<<" ";
+         }
+         cout<<"\n";
+       }
+       aMedW.SetTimeStamp(aTimeStampValW);
+      }
+    }    
+  }
+  cout<<"OK"<<endl;
+}
+
+
+int main(int argc, char** argv){ 
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  try{
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  }catch(std::exception& exc){
+    cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
+  }catch(...){
+    cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
+  } 
+  return 1;
+}
diff --git a/src/MEDWrapper/MEDA_Test1.cxx b/src/MEDWrapper/MEDA_Test1.cxx
new file mode 100644 (file)
index 0000000..4b0158c
--- /dev/null
@@ -0,0 +1,92 @@
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File:    VISUConvertor.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Algorithm.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MEDA;
+
+#ifdef DEBUG
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+namespace MEDA{
+  using namespace std;
+  using namespace boost;
+  
+  
+};
+
+void ReadMed(const char* theFileName){
+  TWrapper aMed(theFileName);
+  string aFileName = theFileName;
+  aFileName += "+";
+  TWrapper aMedW(aFileName);
+
+  int aNbMeshes = aMed.GetNbMeshes();
+  cout<<"GetNbMeshes() = "<<aNbMeshes<<endl;
+
+  string aName;
+  for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+    PMeshInfo aMeshInfo = aMed.GetMeshInfo(iMesh);
+  
+    PNodeInfo aNodeInfo = aMed.GetNodeInfo(aMeshInfo);
+
+    MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo);
+
+    TCellGroup aCellGroup = GetCellsByEntity(aMed,aMeshInfo,aEntityInfo);
+
+    TFamilyGroup aFamilyGroup = GetFamilies(aMed,aMeshInfo);
+
+    TFamilyByEntity aFamilyByEntity = GetFamiliesByEntity(aMed,aNodeInfo,aCellGroup,aFamilyGroup);
+
+    TGroupInfo aGroupInfo = GetFamiliesByGroup(aFamilyGroup);
+
+    TTimeStampGroup aTimeStampGroup = GetFieldsByEntity(aMed,aMeshInfo,aEntityInfo);
+
+    TFieldGroup aFieldGroup = GetFieldsByEntity(aTimeStampGroup);
+
+  }
+  cout<<"OK"<<endl;
+}
+
+
+int main(int argc, char** argv){ 
+  try{
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  }catch(std::exception& exc){
+    cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
+  }catch(...){
+    cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
+  } 
+  return 1;
+}
diff --git a/src/MEDWrapper/MEDA_Wrapper.cxx b/src/MEDWrapper/MEDA_Wrapper.cxx
new file mode 100644 (file)
index 0000000..f48e7b4
--- /dev/null
@@ -0,0 +1,355 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MEDA_Wrapper.hxx"
+#include "MED_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MEDA;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 0;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+TWrapper::TWrapper(const string& theFileName):
+  myWrapper(new MED::TWrapper(theFileName))
+{}
+
+
+//---------------------------------------------------------------
+PMeshInfo TWrapper::CrMeshInfo(med_int theDim,
+                              const string& theValue)
+{
+  MED::PMeshInfo anInfo(new MED::TMeshInfo(theDim,theValue));
+  return PMeshInfo(new TMeshInfo(anInfo));
+}
+
+PMeshInfo TWrapper::CrMeshInfo(const PMeshInfo& theInfo){
+  MED::PMeshInfo anInfo(new MED::TMeshInfo(*theInfo->myInfo));
+  return PMeshInfo(new TMeshInfo(anInfo));
+}
+
+med_int TWrapper::GetNbMeshes(){
+  return myWrapper->GetNbMeshes();
+}
+
+PMeshInfo TWrapper::GetMeshInfo(med_int theId){
+  PMeshInfo anInfo = CrMeshInfo();
+  myWrapper->GetMeshInfo(theId+1,*anInfo->myInfo);
+  if(MYDEBUG){
+    MESSAGE("GetMeshInfo(...)");
+    MED::PrefixPrinter aPrefixPrinter;
+    BEGMSG("aName = '"<<anInfo->GetName()<<"'; aDim = "<<anInfo->GetDim()<<"\n");
+    ADDMSG("\n");
+  }
+  return anInfo;
+}
+
+void TWrapper::SetMeshInfo(const PMeshInfo& theInfo){
+  myWrapper->SetMeshInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PFamilyInfo TWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo, 
+                                  med_int theNbGroup,
+                                  med_int theNbAttr,
+                                  med_int theId,
+                                  const string& theValue)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PFamilyInfo anInfo(new MED::TFamilyInfo(aMeshInfo,
+                                              theNbGroup,
+                                              theNbAttr,
+                                              theId,
+                                              theValue));
+  return PFamilyInfo(new TFamilyInfo(anInfo));
+}
+
+PFamilyInfo TWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                  const string& theValue,
+                                  med_int theId,
+                                  const MED::TStringSet& theGroupNames, 
+                                  const MED::TStringVector& theAttrDescs, 
+                                  const MED::TIntVector& theAttrIds, 
+                                  const MED::TIntVector& theAttrVals)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PFamilyInfo anInfo(new MED::TFamilyInfo(aMeshInfo,
+                                              theValue,
+                                              theId,
+                                              theGroupNames,
+                                              theAttrDescs,
+                                              theAttrIds,
+                                              theAttrVals));
+  return PFamilyInfo(new TFamilyInfo(anInfo));
+}
+
+PFamilyInfo TWrapper::CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                  const PFamilyInfo& theInfo)
+{
+  MED::PFamilyInfo anInfo(new MED::TFamilyInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PFamilyInfo(new TFamilyInfo(anInfo));
+}
+
+med_int TWrapper::GetNbFamilies(const PMeshInfo& theMeshInfo){
+  return myWrapper->GetNbFamilies(*theMeshInfo->myInfo);
+}
+
+PFamilyInfo TWrapper::GetFamilyInfo(const PMeshInfo& theMeshInfo, med_int theId){
+  med_int aNbAttr = myWrapper->GetNbFamAttr(theId+1,*theMeshInfo->myInfo);
+  med_int aNbGroup = myWrapper->GetNbFamGroup(theId+1,*theMeshInfo->myInfo);
+  PFamilyInfo anInfo = CrFamilyInfo(theMeshInfo,aNbGroup,aNbAttr);
+  myWrapper->GetFamilyInfo(theId+1,*anInfo->myInfo);
+  if(MYDEBUG){
+    MESSAGE("GetFamilyInfo(...)");
+    MED::PrefixPrinter aPrefixPrinter;
+    BEGMSG("aName = '"<<anInfo->GetName()<<"'; anId = "<<anInfo->GetId()<<"\n");
+    ADDMSG("\n");
+  }
+  return anInfo;
+}
+
+void TWrapper::SetFamilyInfo(const PFamilyInfo& theInfo){
+  myWrapper->SetFamilyInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PNodeInfo TWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                              med_int theNbElem,
+                              med_repere theSystem, 
+                              med_booleen theIsElemNum,
+                              med_booleen theIsElemNames)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PNodeInfo anInfo(new MED::TNodeInfo(aMeshInfo,
+                                          theNbElem,
+                                          theSystem,
+                                          theIsElemNum,
+                                          theIsElemNames));
+  return PNodeInfo(new TNodeInfo(anInfo));
+}
+
+PNodeInfo TWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                              med_repere theSystem, 
+                              const MED::TFloatVector& theNodeCoords,
+                              const MED::TStringVector& theCoordNames,
+                              const MED::TStringVector& theCoordUnits,
+                              const MED::TIntVector& theFamilyNums,
+                              const MED::TIntVector& theElemNums,
+                              const MED::TStringVector& theElemNames)
+{
+  const MED::PMeshInfo& aMeshInfo = theMeshInfo->myInfo;
+  MED::PNodeInfo anInfo(new MED::TNodeInfo(aMeshInfo,
+                                          theSystem,
+                                          theNodeCoords,
+                                          theCoordNames,
+                                          theCoordUnits,
+                                          theFamilyNums,
+                                          theElemNums,
+                                          theElemNames));
+  return PNodeInfo(new TNodeInfo(anInfo));
+}
+
+PNodeInfo TWrapper::CrNodeInfo(const PMeshInfo& theMeshInfo,
+                              const PNodeInfo& theInfo)
+{
+  MED::PNodeInfo anInfo(new MED::TNodeInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PNodeInfo(new TNodeInfo(anInfo));
+}
+
+PNodeInfo TWrapper::GetNodeInfo(const PMeshInfo& theMeshInfo){
+  med_int aNbElems = myWrapper->GetNbNodes(*theMeshInfo->myInfo);
+  PNodeInfo anInfo = CrNodeInfo(theMeshInfo,aNbElems);
+  myWrapper->GetNodeInfo(*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetNodeInfo(const PNodeInfo& theInfo){
+  myWrapper->SetNodeInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+MED::TEntityInfo TWrapper::GetEntityInfo(const PMeshInfo& theMeshInfo){
+  return myWrapper->GetEntityInfo(*theMeshInfo->myInfo);
+}
+
+PCellInfo TWrapper::CrCellInfo(const PMeshInfo& theMeshInfo, 
+                              med_int theNbElem,
+                              med_entite_maillage theEntity, 
+                              med_geometrie_element theGeom,
+                              med_connectivite theConn,
+                              med_booleen theIsElemNum,
+                              med_booleen theIsElemNames)
+{
+  MED::PCellInfo anInfo(new MED::TCellInfo(theMeshInfo->myInfo,
+                                          theNbElem,
+                                          theEntity,
+                                          theGeom,
+                                          theConn,
+                                          theIsElemNum,
+                                          theIsElemNames));
+  return PCellInfo(new TCellInfo(anInfo));
+}
+
+PCellInfo TWrapper::CrCellInfo(const PMeshInfo& theMeshInfo, 
+                              med_entite_maillage theEntity, 
+                              med_geometrie_element theGeom,
+                              med_connectivite theConn,
+                              const MED::TIntVector& theConnectivities,
+                              const MED::TIntVector& theFamilyNums,
+                              const MED::TIntVector& theElemNums,
+                              const MED::TStringVector& theElemNames)
+{
+  MED::PCellInfo anInfo(new MED::TCellInfo(theMeshInfo->myInfo,
+                                          theEntity,
+                                          theGeom,
+                                          theConn,
+                                          theConnectivities,
+                                          theFamilyNums,
+                                          theElemNums,
+                                          theElemNames));
+  return PCellInfo(new TCellInfo(anInfo));
+}
+
+PCellInfo TWrapper::CrCellInfo(const PMeshInfo& theMeshInfo,
+                              const PCellInfo& theInfo)
+{
+  MED::PCellInfo anInfo(new MED::TCellInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PCellInfo(new TCellInfo(anInfo));
+}
+
+PCellInfo TWrapper::GetCellInfo(const PMeshInfo& theMeshInfo, 
+                               med_entite_maillage theEntity, 
+                               med_geometrie_element theGeom, 
+                               med_connectivite theConn)
+{
+  med_int aNbElem = myWrapper->GetNbCells(*theMeshInfo->myInfo,theEntity,theGeom,theConn);
+  PCellInfo anInfo = CrCellInfo(theMeshInfo,aNbElem,theEntity,theGeom,theConn);
+  myWrapper->GetCellInfo(*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetCellInfo(const PCellInfo& theInfo){
+  myWrapper->SetCellInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PFieldInfo TWrapper::CrFieldInfo(const PMeshInfo& theMeshInfo, 
+                                med_int theNbComp,
+                                med_type_champ theType,
+                                const string& theValue)
+{
+  MED::PFieldInfo anInfo(new MED::TFieldInfo(theMeshInfo->myInfo,
+                                            theNbComp,
+                                            theType,
+                                            theValue));
+  return PFieldInfo(new TFieldInfo(anInfo));
+}
+
+PFieldInfo TWrapper::CrFieldInfo(const PMeshInfo& theMeshInfo,
+                                const PFieldInfo& theInfo)
+{
+  MED::PFieldInfo anInfo(new MED::TFieldInfo(*theInfo->myInfo));
+  anInfo->myMeshInfo = theMeshInfo->myInfo;
+  return PFieldInfo(new TFieldInfo(anInfo));
+}
+
+med_int TWrapper::GetNbFields(){
+  return myWrapper->GetNbFields();
+}
+
+PFieldInfo TWrapper::GetFieldInfo(const PMeshInfo& theMeshInfo, med_int theId){
+  med_int aNbComp = myWrapper->GetNbComp(theId+1);
+  PFieldInfo anInfo = CrFieldInfo(theMeshInfo,aNbComp);
+  myWrapper->GetFieldInfo(theId+1,*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetFieldInfo(const PFieldInfo& theInfo){
+  myWrapper->SetFieldInfo(*theInfo->myInfo);
+}
+
+
+//---------------------------------------------------------------
+PTimeStampInfo TWrapper::CrTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                                        med_entite_maillage theEntity,
+                                        const MED::TGeom& theGeom)
+{
+  MED::PTimeStampInfo anInfo(new MED::TTimeStampInfo(theFieldInfo->myInfo,
+                                                    theEntity,
+                                                    theGeom));
+  return PTimeStampInfo(new TTimeStampInfo(anInfo));
+}
+
+PTimeStampInfo TWrapper::CrTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                        const PTimeStampInfo& theInfo)
+{
+  MED::PTimeStampInfo anInfo(new MED::TTimeStampInfo(*theInfo->myInfo));
+  anInfo->myFieldInfo = theFieldInfo->myInfo;
+  return PTimeStampInfo(new TTimeStampInfo(anInfo));
+}
+
+med_int TWrapper::GetNbTimeStamps(const PFieldInfo& theFieldInfo, 
+                                 const MED::TEntityInfo& theEntityInfo,
+                                 med_entite_maillage& theEntity,
+                                 MED::TGeom& theGeom)
+{
+  return myWrapper->GetNbTimeStamps(*theFieldInfo->myInfo,
+                                   theEntityInfo,
+                                   theEntity,
+                                   theGeom);
+}
+
+PTimeStampInfo TWrapper::GetTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                         med_int theId,
+                                         med_entite_maillage theEntity,
+                                         const MED::TGeom& theGeom)
+{
+  PTimeStampInfo anInfo = CrTimeStampInfo(theFieldInfo,theEntity,theGeom);
+  myWrapper->GetTimeStampInfo(theId+1,*anInfo->myInfo);
+  return anInfo;
+}
+
+
+//---------------------------------------------------------------
+PTimeStampVal TWrapper::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo)
+{
+  MED::PTimeStampVal anInfo(new MED::TTimeStampVal(theTimeStampInfo->myInfo));
+  return PTimeStampVal(new TTimeStampVal(anInfo));
+}
+
+PTimeStampVal TWrapper::CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
+                                      const PTimeStampVal& theInfo)
+{
+  MED::PTimeStampVal anInfo(new MED::TTimeStampVal(*theInfo->myInfo));
+  anInfo->myTimeStampInfo = theTimeStampInfo->myInfo;
+  return PTimeStampVal(new TTimeStampVal(anInfo));
+}
+
+PTimeStampVal TWrapper::GetTimeStampVal(const PTimeStampInfo& theTimeStampInfo)
+{
+  PTimeStampVal anInfo = CrTimeStampVal(theTimeStampInfo);
+  myWrapper->GetTimeStampVal(*anInfo->myInfo);
+  return anInfo;
+}
+
+void TWrapper::SetTimeStamp(const PTimeStampVal& theTimeStampVal){
+  myWrapper->SetTimeStamp(*theTimeStampVal->myInfo);
+}
diff --git a/src/MEDWrapper/MEDA_Wrapper.hxx b/src/MEDWrapper/MEDA_Wrapper.hxx
new file mode 100644 (file)
index 0000000..e135e21
--- /dev/null
@@ -0,0 +1,161 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MEDA_Wrapper_HeaderFile
+#define MEDA_Wrapper_HeaderFile
+
+#include "MEDA_Structures.hxx"
+
+namespace MEDA{
+  class TWrapper{
+    TWrapper();
+    TWrapper(const TWrapper&);
+  protected:
+    MED::PWrapper myWrapper;
+    
+  public:
+    TWrapper(const string& theFileName);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PMeshInfo CrMeshInfo(med_int theDim = 0,
+                               const string& theValue = "");
+
+    static PMeshInfo CrMeshInfo(const PMeshInfo& theMeshInfo);
+
+    med_int GetNbMeshes();
+
+    PMeshInfo GetMeshInfo(med_int theId);
+
+    void SetMeshInfo(const PMeshInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                   med_int theNbGroup = 0, 
+                                   med_int theNbAttr = 0,
+                                   med_int theId = 0,
+                                   const string& theValue = "");
+
+    static PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                   const string& theValue,
+                                   med_int theId,
+                                   const MED::TStringSet& theGroupNames, 
+                                   const MED::TStringVector& theAttrDescs = MED::TStringVector(), 
+                                   const MED::TIntVector& theAttrIds = MED::TIntVector(), 
+                                   const MED::TIntVector& theAttrVals = MED::TIntVector());
+
+    static PFamilyInfo CrFamilyInfo(const PMeshInfo& theMeshInfo,
+                                   const PFamilyInfo& theInfo);
+
+    med_int GetNbFamilies(const PMeshInfo& theMeshInfo);
+
+    PFamilyInfo GetFamilyInfo(const PMeshInfo& theMeshInfo, med_int theId);
+
+    void SetFamilyInfo(const PFamilyInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                               med_int theNbElem,
+                               med_repere theSystem = MED_CART, 
+                               med_booleen theIsElemNum = MED_VRAI,
+                               med_booleen theIsElemNames = MED_VRAI);
+
+    static PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo, 
+                               med_repere theSystem, 
+                               const MED::TFloatVector& theNodeCoords,
+                               const MED::TStringVector& theCoordNames,
+                               const MED::TStringVector& theCoordUnits,
+                               const MED::TIntVector& theFamilyNums,
+                               const MED::TIntVector& theElemNums,
+                               const MED::TStringVector& theElemNames = MED::TStringVector());
+
+    static PNodeInfo CrNodeInfo(const PMeshInfo& theMeshInfo,
+                               const PNodeInfo& theInfo);
+
+    PNodeInfo GetNodeInfo(const PMeshInfo& theMeshInfo);
+
+    void SetNodeInfo(const PNodeInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    MED::TEntityInfo GetEntityInfo(const PMeshInfo& theMeshInfo);
+
+    static PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo, 
+                               med_int theNbElem,
+                               med_entite_maillage theEntity, 
+                               med_geometrie_element theGeom,
+                               med_connectivite theConn = MED_NOD,
+                               med_booleen theIsElemNum = MED_VRAI,
+                               med_booleen theIsElemNames = MED_VRAI);
+
+    static PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo, 
+                               med_entite_maillage theEntity, 
+                               med_geometrie_element theGeom,
+                               med_connectivite theConn,
+                               const MED::TIntVector& theConnectivities,
+                               const MED::TIntVector& theFamilyNums,
+                               const MED::TIntVector& theElemNums,
+                               const MED::TStringVector& theElemNames = MED::TStringVector());
+
+    static PCellInfo CrCellInfo(const PMeshInfo& theMeshInfo,
+                               const PCellInfo& theInfo);
+
+    PCellInfo GetCellInfo(const PMeshInfo& theMeshInfo, 
+                         med_entite_maillage theEntity, 
+                         med_geometrie_element theGeom, 
+                         med_connectivite theConn = MED_NOD);
+
+    void SetCellInfo(const PCellInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PFieldInfo CrFieldInfo(const PMeshInfo& theMeshInfo, 
+                                 med_int theNbComp = 0,
+                                 med_type_champ theType = MED_REEL64,
+                                 const string& theValue = "");
+
+    static PFieldInfo CrFieldInfo(const PMeshInfo& theMeshInfo,
+                                 const PFieldInfo& theInfo);
+    med_int GetNbFields();
+
+    PFieldInfo GetFieldInfo(const PMeshInfo& theMeshInfo, med_int theId);
+
+    void SetFieldInfo(const PFieldInfo& theInfo);
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PTimeStampInfo CrTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                                         med_entite_maillage theEntity,
+                                         const MED::TGeom& theGeom);
+
+    static PTimeStampInfo CrTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                         const PTimeStampInfo& theInfo);
+
+    med_int GetNbTimeStamps(const PFieldInfo& theFieldInfo, 
+                           const MED::TEntityInfo& theEntityInfo,
+                           med_entite_maillage& theEntity,
+                           MED::TGeom& theGeom);
+
+    PTimeStampInfo GetTimeStampInfo(const PFieldInfo& theFieldInfo,
+                                   med_int theId,
+                                   med_entite_maillage theEntity,
+                                   const MED::TGeom& theGeom);
+
+    
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    static PTimeStampVal CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo);
+
+    static PTimeStampVal CrTimeStampVal(const PTimeStampInfo& theTimeStampInfo,
+                                       const PTimeStampVal& theInfo);
+
+    PTimeStampVal GetTimeStampVal(const PTimeStampInfo& theTimeStampInfo);
+
+    void SetTimeStamp(const PTimeStampVal& theTimeStampVal);
+  };
+
+};
+
+
+#endif
diff --git a/src/MEDWrapper/MED_Common.hxx b/src/MEDWrapper/MED_Common.hxx
new file mode 100644 (file)
index 0000000..0afa3b4
--- /dev/null
@@ -0,0 +1,71 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Common_HeaderFile
+#define MED_Common_HeaderFile
+
+#include <string>
+#include <vector>
+#include <set>
+#include <map>
+
+extern "C"{
+#include <med.h>
+}  
+
+#include <boost/shared_ptr.hpp>
+
+namespace MED{
+  using namespace std;
+  using namespace boost;
+
+  typedef vector<med_float> TFloatVector;
+  typedef vector<string> TStringVector;
+  typedef vector<med_int> TIntVector;
+  typedef set<string> TStringSet;
+
+  typedef map<med_geometrie_element,med_int> TGeom;
+  typedef map<med_entite_maillage,TGeom> TEntityInfo;
+
+  med_int GetNbConn(med_entite_maillage theMedEntity, 
+                   med_geometrie_element theMedType,
+                   med_int theMeshDim);
+
+  struct TNameInfo;
+  typedef shared_ptr<TNameInfo> PNameInfo;
+  
+  struct TMeshInfo;
+  typedef shared_ptr<TMeshInfo> PMeshInfo;
+  
+  struct TFamilyInfo;
+  typedef shared_ptr<TFamilyInfo> PFamilyInfo;
+
+  struct TElemInfo;
+  typedef shared_ptr<TElemInfo> PElemInfo;
+
+  struct TNodeInfo;
+  typedef shared_ptr<TNodeInfo> PNodeInfo;
+
+  struct TCellInfo;
+  typedef shared_ptr<TCellInfo> PCellInfo;
+
+  struct TFieldInfo;
+  typedef shared_ptr<TFieldInfo> PFieldInfo;
+
+  struct TTimeStampInfo;
+  typedef shared_ptr<TTimeStampInfo> PTimeStampInfo;
+  
+  struct TTimeStampVal;
+  typedef shared_ptr<TTimeStampVal> PTimeStampVal;
+
+  class TWrapper;
+  typedef shared_ptr<TWrapper> PWrapper;
+};
+
+
+#endif
diff --git a/src/MEDWrapper/MED_Structures.cxx b/src/MEDWrapper/MED_Structures.cxx
new file mode 100644 (file)
index 0000000..871f471
--- /dev/null
@@ -0,0 +1,368 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MED_Structures.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MED;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+//---------------------------------------------------------------
+string MED::GetString(med_int theId, med_int theStep,
+                     const TString& theString)
+{
+  const char* aPos = &theString[theId*theStep];
+  med_int aSize = min(med_int(strlen(aPos)),theStep);
+  return string(aPos,aSize);
+}
+
+void MED::SetString(med_int theId, med_int theStep,
+                   TString& theString, const string& theValue)
+{
+  med_int aSize = min(med_int(theValue.size()+1),theStep);
+  if(aSize > theStep)
+    EXCEPTION(runtime_error,"SetString(...): aSize =="<<aSize<<"of '"<<theValue<<"' > theStep");
+  strncpy(&theString[theId*theStep],theValue.c_str(),aSize);
+}
+
+med_int MED::GetNbConn(med_entite_maillage theMedEntity, 
+                      med_geometrie_element theMedType,
+                      med_int theMeshDim)
+{
+  med_int anElemDim = theMedType / 100, nsup = 0;
+  if(theMedEntity == MED_MAILLE && anElemDim < theMeshDim) nsup = 1;
+  return nsup + theMedType % 100;
+}
+
+
+//---------------------------------------------------------------
+TNameInfo::TNameInfo(const string& theValue):
+  myName('\0',MED_TAILLE_NOM+1) 
+{
+  if(theValue != "") SetName(theValue);
+}
+
+string TNameInfo::GetName() const { 
+  return GetString(0,MED_TAILLE_NOM,myName);
+}
+
+void TNameInfo::SetName(const string& theValue){
+  SetString(0,MED_TAILLE_NOM,myName,theValue);
+}
+
+
+//---------------------------------------------------------------
+TMeshInfo::TMeshInfo(med_int theDim,
+                    const string& theValue):
+  TNameInfo(theValue),
+  myDim(theDim)
+{}
+
+//---------------------------------------------------------------
+TFamilyInfo::TFamilyInfo(const PMeshInfo& theMeshInfo, 
+                        med_int theNbGroup, 
+                        med_int theNbAttr,
+                        med_int theId,
+                        const string& theValue):
+  TNameInfo(theValue),
+  myMeshInfo(theMeshInfo),
+  myId(theId),
+  myNbGroup(theNbGroup),
+  myGroupNames('\0',theNbGroup*MED_TAILLE_LNOM+1),
+  myNbAttr(theNbAttr), 
+  myAttrId(theNbAttr), 
+  myAttrVal(theNbAttr),
+  myAttrDesc('\0',theNbAttr*MED_TAILLE_DESC+1)
+{}  
+
+TFamilyInfo::TFamilyInfo(const PMeshInfo& theMeshInfo,
+                        const string& theValue,
+                        med_int theId,
+                        const TStringSet& theGroupNames, 
+                        const TStringVector& theAttrDescs, 
+                        const TIntVector& theAttrIds, 
+                        const TIntVector& theAttrVals):
+  TNameInfo(theValue),
+  myMeshInfo(theMeshInfo),
+  myId(theId),
+  myNbGroup(theGroupNames.size()),
+  myGroupNames('\0',theGroupNames.size()*MED_TAILLE_LNOM+1),
+  myNbAttr(theAttrDescs.size()), 
+  myAttrId(theAttrDescs.size()), 
+  myAttrVal(theAttrDescs.size()),
+  myAttrDesc('\0',theAttrDescs.size()*MED_TAILLE_DESC+1)
+{
+  if(myNbGroup){
+    TStringSet::const_iterator anIter = theGroupNames.begin();
+    for(med_int anId = 0; anIter != theGroupNames.end(); anIter++, anId++){
+      const string& aVal = *anIter;
+      SetGroupName(anId,aVal);
+    }
+  }
+  if(myNbAttr){
+    for(med_int anId = 0, anEnd = theAttrDescs.size(); anId < anEnd; anId++){
+      const string& aVal = theAttrDescs[anId];
+      SetAttrDesc(anId,aVal);
+      myAttrId[anId] = theAttrIds[anId];
+      myAttrVal[anId] = theAttrVals[anId];
+    }
+  }
+}  
+
+string TFamilyInfo::GetGroupName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_LNOM,myGroupNames);
+}
+
+void TFamilyInfo::SetGroupName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_LNOM,myGroupNames,theValue);
+}
+
+string TFamilyInfo::GetAttrDesc(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_DESC,myAttrDesc);
+}
+
+void TFamilyInfo::SetAttrDesc(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_DESC,myAttrDesc,theValue);
+}
+
+
+//---------------------------------------------------------------
+TElemInfo::TElemInfo(const PMeshInfo& theMeshInfo, 
+                    med_int theNbElem,
+                    med_booleen theIsElemNum,
+                    med_booleen theIsElemNames):
+  myMeshInfo(theMeshInfo), 
+  myNbElem(theNbElem),
+  myFamNum(theNbElem),
+  myIsElemNum(theIsElemNum), 
+  myElemNum(theIsElemNum == MED_FAUX? 0: theNbElem),
+  myIsElemNames(theIsElemNames),
+  myElemNames('\0',(theIsElemNames == MED_FAUX? 0: theNbElem)*MED_TAILLE_PNOM+1)
+{}
+
+TElemInfo::TElemInfo(const PMeshInfo& theMeshInfo, 
+                    const TIntVector& theFamilyNums,
+                    const TIntVector& theElemNums,
+                    const TStringVector& theElemNames):
+  myMeshInfo(theMeshInfo), 
+  myNbElem(theFamilyNums.size()),
+  myFamNum(theFamilyNums.size()),
+  myIsElemNum(theElemNums.size()? MED_VRAI: MED_FAUX), 
+  myElemNum(theElemNums.size()),
+  myIsElemNames(theElemNames.size()? MED_VRAI: MED_FAUX),
+  myElemNames('\0',theElemNames.size()*MED_TAILLE_PNOM+1)
+{
+  if(myNbElem){
+    for(med_int anId = 0; anId < myNbElem; anId++){
+      myFamNum[anId] = theFamilyNums[anId];
+    }
+    if(myIsElemNum == MED_VRAI){
+      for(med_int anId = 0; anId < myNbElem; anId++){
+       myElemNum[anId] = theElemNums[anId];
+      }
+    }
+    if(myIsElemNames == MED_VRAI){
+      for(med_int anId = 0; anId < myNbElem; anId++){
+       const string& aVal = theElemNames[anId];
+       SetElemName(anId,aVal);
+      }
+    }
+  }
+}
+
+string TElemInfo::GetElemName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myElemNames);
+}
+
+void TElemInfo::SetElemName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myElemNames,theValue);
+}
+
+
+//---------------------------------------------------------------
+TNodeInfo::TNodeInfo(const PMeshInfo& theMeshInfo, 
+                    med_int theNbElem,
+                    med_repere theSystem, 
+                    med_booleen theIsElemNum,
+                    med_booleen theIsElemNames):
+  TElemInfo(theMeshInfo,theNbElem,theIsElemNum,theIsElemNames),
+  myCoord(theNbElem*theMeshInfo->myDim), 
+  mySystem(theSystem), 
+  myCoordNames('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1),
+  myCoordUnits('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1)
+{}
+
+TNodeInfo::TNodeInfo(const PMeshInfo& theMeshInfo, 
+                    med_repere theSystem, 
+                    const TFloatVector& theNodeCoords,
+                    const TStringVector& theCoordNames,
+                    const TStringVector& theCoordUnits,
+                    const TIntVector& theFamilyNums,
+                    const TIntVector& theElemNums,
+                    const TStringVector& theElemNames):
+  TElemInfo(theMeshInfo,theFamilyNums,theElemNums,theElemNames),
+  myCoord(theNodeCoords.size()), 
+  mySystem(theSystem), 
+  myCoordNames('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1),
+  myCoordUnits('\0',theMeshInfo->myDim*MED_TAILLE_PNOM+1)
+{
+  if(myCoord.size() == myNbElem*theMeshInfo->myDim){
+    for(med_int anId = 0, anEnd = myCoord.size(); anId < anEnd; anId++){
+      myCoord[anId] = theNodeCoords[anId];
+    }
+  }else 
+    EXCEPTION(runtime_error,"myCoord.size() != myNbElem*theMeshInfo->myDim");
+
+  for(med_int anId = 0; anId < theMeshInfo->myDim; anId++){
+    const string& aVal = theCoordNames.at(anId);
+    SetCoordName(anId,aVal);
+  }
+
+  for(med_int anId = 0; anId < theMeshInfo->myDim; anId++){
+    const string& aVal = theCoordUnits.at(anId);
+    SetCoordUnit(anId,aVal);
+  }
+}
+
+string TNodeInfo::GetCoordName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myCoordNames);
+}
+
+void TNodeInfo::SetCoordName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myCoordNames,theValue);
+}
+
+string TNodeInfo::GetCoordUnit(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myCoordUnits);
+}
+
+void TNodeInfo::SetCoordUnit(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myCoordUnits,theValue);
+}
+
+
+//---------------------------------------------------------------
+TCellInfo::TCellInfo(const PMeshInfo& theMeshInfo, 
+                    med_int theNbElem,
+                    med_entite_maillage theTEntity, 
+                    med_geometrie_element theTGeom,
+                    med_connectivite theTConn,
+                    med_booleen theIsElemNum,
+                    med_booleen theIsElemNames):
+  TElemInfo(theMeshInfo,theNbElem,theIsElemNum,theIsElemNames),
+  myTEntity(theTEntity), 
+  myTGeom(theTGeom), 
+  myTConn(theTConn),
+  myConnDim(GetNbConn(myTEntity,myTGeom,theMeshInfo->myDim)),
+  myConn(theNbElem*myConnDim)
+{}
+
+TCellInfo::TCellInfo(const PMeshInfo& theMeshInfo, 
+                    med_entite_maillage theTEntity, 
+                    med_geometrie_element theTGeom,
+                    med_connectivite theTConn,
+                    const TIntVector& theConnectivities,
+                    const TIntVector& theFamilyNums,
+                    const TIntVector& theElemNums,
+                    const TStringVector& theElemNames):
+  TElemInfo(theMeshInfo,theFamilyNums,theElemNums,theElemNames),
+  myTEntity(theTEntity), 
+  myTGeom(theTGeom), 
+  myTConn(theTConn),
+  myConnDim(GetNbConn(myTEntity,myTGeom,theMeshInfo->myDim)),
+  myConn(theConnectivities.size())
+{
+  if(myConn.size() == myConnDim*theFamilyNums.size()){
+    for(med_int anId = 0, anEnd = myConn.size(); anId < anEnd; anId++){
+      myConn[anId] = theConnectivities[anId];
+    }
+  }else 
+    EXCEPTION(runtime_error,"myConn.size() == myConnDim*theFamilyNums.size()");
+}
+
+//---------------------------------------------------------------
+TFieldInfo::TFieldInfo(const PMeshInfo& theMeshInfo, 
+                      med_int theNbComp,
+                      med_type_champ theType,
+                      const string& theValue):
+  TNameInfo(theValue),
+  myMeshInfo(theMeshInfo), 
+  myNbComp(theNbComp),
+  myType(theType),
+  myCompNames('\0',theNbComp*MED_TAILLE_PNOM + 1),
+  myUnitNames('\0',theNbComp*MED_TAILLE_PNOM + 1)
+{}
+
+string TFieldInfo::GetCompName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myCompNames);
+}
+
+void TFieldInfo::SetCompName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myCompNames,theValue);
+}
+
+string TFieldInfo::GetUnitName(med_int theId) const { 
+  return GetString(theId,MED_TAILLE_PNOM,myUnitNames);
+}
+
+void TFieldInfo::SetUnitName(med_int theId, const string& theValue){
+  SetString(theId,MED_TAILLE_PNOM,myUnitNames,theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampInfo::TTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                              med_entite_maillage theEntity,
+                              const TGeom& theGeom):
+  myFieldInfo(theFieldInfo), 
+  myEntity(theEntity), 
+  myGeom(theGeom), 
+  myUnitDt('\0',MED_TAILLE_PNOM+1)
+{}
+
+string TTimeStampInfo::GetUnitDt() const { 
+  return GetString(0,MED_TAILLE_PNOM,myUnitDt);
+}
+
+void TTimeStampInfo::SetUnitDt(const string& theValue){
+  SetString(0,MED_TAILLE_PNOM,myUnitDt,theValue);
+}
+
+
+//---------------------------------------------------------------
+TTimeStampVal::TTimeStampVal(const PTimeStampInfo& theTimeStampInfo):
+  myTimeStampInfo(theTimeStampInfo),
+  myPflName('\0',MED_TAILLE_NOM+1)
+{
+  med_int aNbComp = theTimeStampInfo->myFieldInfo->myNbComp;
+  med_int aNbGauss = theTimeStampInfo->myNbGauss;
+  const TGeom& aTGeom = theTimeStampInfo->myGeom;
+  TGeom::const_iterator anIter = aTGeom.begin();
+  for(; anIter != aTGeom.end(); anIter++){
+    const med_geometrie_element& aGeom = anIter->first;
+    med_int aNb = anIter->second*aNbComp*aNbGauss;
+    myMeshValue[aGeom].resize(aNb);
+  }
+}
+
+string TTimeStampVal::GetPflName() const { 
+  return GetString(0,MED_TAILLE_NOM,myPflName);
+}
+
+void TTimeStampVal::SetPflName(const string& theValue){
+  SetString(0,MED_TAILLE_NOM,myPflName,theValue);
+}
+
+
diff --git a/src/MEDWrapper/MED_Structures.hxx b/src/MEDWrapper/MED_Structures.hxx
new file mode 100644 (file)
index 0000000..e58956c
--- /dev/null
@@ -0,0 +1,230 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Structures_HeaderFile
+#define MED_Structures_HeaderFile
+
+#include <valarray>
+
+#include "MED_Common.hxx"
+
+namespace MED{
+  using namespace std;
+  using namespace boost;
+
+//---------------------------------------------------------------
+  typedef valarray<char> TString;
+
+  string GetString(med_int theId, med_int theStep, const TString& theString);
+  void SetString(med_int theId, med_int theStep, TString& theString, 
+                const string& theValue);
+
+
+//---------------------------------------------------------------
+  struct TNameInfo{
+    TNameInfo(const string& theValue = "");
+    virtual ~TNameInfo() {} 
+
+    TString myName;
+    string GetName() const;
+    void SetName(const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  struct TMeshInfo: TNameInfo{
+    TMeshInfo(med_int theDim = 0,
+             const string& theValue = "");
+
+    med_int myDim;
+  };
+  
+
+//---------------------------------------------------------------
+  typedef valarray<med_int> TFamAttr;
+
+  struct TFamilyInfo: TNameInfo{
+    TFamilyInfo(const PMeshInfo& theMeshInfo,
+               med_int theNbGroup = 0, 
+               med_int theNbAttr = 0,
+               med_int theId = 0,
+               const string& theValue = "");
+
+    TFamilyInfo(const PMeshInfo& theMeshInfo,
+               const string& theValue,
+               med_int theId,
+               const TStringSet& theGroupNames, 
+               const TStringVector& theAttrDescs = TStringVector(), 
+               const TIntVector& theAttrIds = TIntVector(), 
+               const TIntVector& theAttrVals = TIntVector());
+
+    PMeshInfo myMeshInfo;
+    med_int myId;
+
+    med_int myNbGroup;
+    TString myGroupNames;
+    string GetGroupName(med_int theId) const;
+    void SetGroupName(med_int theId, const string& theValue);
+
+    med_int myNbAttr;
+    TFamAttr myAttrId;
+    TFamAttr myAttrVal;
+
+    TString myAttrDesc;
+    string GetAttrDesc(med_int theId) const;
+    void SetAttrDesc(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  typedef valarray<med_int> TElemNum;
+
+  struct TElemInfo{
+    TElemInfo(const PMeshInfo& theMeshInfo, 
+             med_int theNbElem,
+             med_booleen theIsElemNum = MED_VRAI,
+             med_booleen theIsElemNames = MED_VRAI);
+    TElemInfo(const PMeshInfo& theMeshInfo, 
+             const TIntVector& theFamilyNums,
+             const TIntVector& theElemNums,
+             const TStringVector& theElemNames = TStringVector());
+    virtual ~TElemInfo() {} 
+
+    PMeshInfo myMeshInfo;
+    med_int myNbElem;
+    
+    TElemNum myFamNum;
+
+    med_booleen myIsElemNum;
+    TElemNum myElemNum;
+
+    med_booleen myIsElemNames;
+    TString myElemNames;
+    string GetElemName(med_int theId) const;
+    void SetElemName(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  typedef valarray<med_float> TNodeCoord;
+
+  struct TNodeInfo: TElemInfo{
+    TNodeInfo(const PMeshInfo& theMeshInfo, 
+             med_int theNbElem,
+             med_repere theSystem = MED_CART, 
+             med_booleen theIsElemNum = MED_VRAI,
+             med_booleen theIsElemNames = MED_VRAI);
+
+    TNodeInfo(const PMeshInfo& theMeshInfo, 
+             med_repere theSystem, 
+             const TFloatVector& theNodeCoords,
+             const TStringVector& theCoordNames,
+             const TStringVector& theCoordUnits,
+             const TIntVector& theFamilyNums,
+             const TIntVector& theElemNums,
+             const TStringVector& theElemNames = TStringVector());
+
+    TNodeCoord myCoord;
+    med_repere mySystem;
+
+    TString myCoordNames;
+    string GetCoordName(med_int theId) const;
+    void SetCoordName(med_int theId, const string& theValue);
+
+    TString myCoordUnits;
+    string GetCoordUnit(med_int theId) const;
+    void SetCoordUnit(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  struct TCellInfo: TElemInfo{
+    TCellInfo(const PMeshInfo& theMeshInfo, 
+             med_int theNbElem,
+             med_entite_maillage theTEntity, 
+             med_geometrie_element theTGeom,
+             med_connectivite theTConn = MED_NOD,
+             med_booleen theIsElemNum = MED_VRAI,
+             med_booleen theIsElemNames = MED_VRAI);
+
+    TCellInfo(const PMeshInfo& theMeshInfo, 
+             med_entite_maillage theTEntity, 
+             med_geometrie_element theTGeom,
+             med_connectivite theTConn,
+             const TIntVector& theConnectivities,
+             const TIntVector& theFamilyNums,
+             const TIntVector& theElemNums,
+             const TStringVector& theElemNames = TStringVector());
+
+    med_entite_maillage myTEntity;
+    med_geometrie_element myTGeom;
+    med_connectivite myTConn;
+
+    med_int myConnDim;
+    TElemNum myConn;
+  };
+
+
+//---------------------------------------------------------------
+  struct TFieldInfo: TNameInfo{
+    TFieldInfo(const PMeshInfo& theMeshInfo, 
+              med_int theNbComp = 0,
+              med_type_champ theType = MED_REEL64,
+              const string& theValue = "");
+    
+    PMeshInfo myMeshInfo;
+    med_type_champ myType;
+    med_int myNbComp;
+    
+    TString myCompNames; 
+    string GetCompName(med_int theId) const;
+    void SetCompName(med_int theId, const string& theValue);
+
+    TString myUnitNames; 
+    string GetUnitName(med_int theId) const;
+    void SetUnitName(med_int theId, const string& theValue);
+  };
+
+
+//---------------------------------------------------------------
+  struct TTimeStampInfo{
+    TTimeStampInfo(const PFieldInfo& theFieldInfo, 
+                  med_entite_maillage theEntity,
+                  const TGeom& theGeom);
+
+    PFieldInfo myFieldInfo;
+    med_entite_maillage myEntity;
+    TGeom myGeom;
+
+    med_int myNbGauss, myNumDt, myNumOrd;
+    med_float myDt;
+
+    TString myUnitDt;
+    string GetUnitDt() const;
+    void SetUnitDt(const string& theValue);
+  };
+  
+
+  typedef valarray<med_float> TValue;
+  typedef map<med_geometrie_element,TValue> TMeshValue;
+//---------------------------------------------------------------
+  struct TTimeStampVal{
+    TTimeStampVal(const PTimeStampInfo& theTimeStampInfo);
+
+    PTimeStampInfo myTimeStampInfo;
+    TMeshValue myMeshValue;
+
+    TString myPflName;
+    string GetPflName() const;
+    void SetPflName(const string& theValue);
+  };
+
+};
+
+
+#endif
diff --git a/src/MEDWrapper/MED_Test.cxx b/src/MEDWrapper/MED_Test.cxx
new file mode 100644 (file)
index 0000000..b227bc1
--- /dev/null
@@ -0,0 +1,186 @@
+//  VISU OBJECT : interactive object for VISU entities implementation
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File:    VISUConvertor.cxx
+//  Author:  Alexey PETROV
+//  Module : VISU
+
+#include "MED_Structures.hxx"
+#include "MED_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+
+#ifdef DEBUG
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+void ReadMed(const char* theFileName){
+  using namespace MED;
+  TWrapper aMed(theFileName);
+  string aFileName = theFileName;
+  aFileName += "-";
+  TWrapper aMedW(aFileName);
+
+  int aNbMeshes = aMed.GetNbMeshes();
+  cout<<"GetNbMeshes() = "<<aNbMeshes<<endl;
+
+  string aName;
+  for(int iMesh = 0; iMesh < aNbMeshes; iMesh++){
+    PMeshInfo aMeshInfo(new TMeshInfo());
+    PMeshInfo aNewMeshInfo(new TMeshInfo());
+    aMed.GetMeshInfo(iMesh+1,*aMeshInfo);
+    int aDim = aMeshInfo->myDim;
+    aName = aMeshInfo->GetName();
+    cout<<"GetMeshInfo - aName = '"<<aName<<"'; aDim = "<<aDim<<endl;
+    *aNewMeshInfo = *aMeshInfo;
+    aName[0] += 1;
+    aNewMeshInfo->SetName(aName);
+    aMedW.SetMeshInfo(*aNewMeshInfo);
+
+    TEntityInfo aEntityInfo = aMed.GetEntityInfo(*aMeshInfo);
+
+    med_int aNbFields = aMed.GetNbFields(); 
+    cout<<"GetNbFields() = "<<aNbFields<<endl;
+    for(int iField = 0; iField < aNbFields; iField++){
+      med_int aNbComp = aMed.GetNbComp(iField+1);
+      PFieldInfo aFieldInfo(new TFieldInfo(aMeshInfo,aNbComp));
+      aMed.GetFieldInfo(iField+1,*aFieldInfo);
+      cout<<"\taName = '"<<aFieldInfo->GetName()<<"'; aNbComp = "<<aNbComp<<"; ";
+      aMedW.SetFieldInfo(*aFieldInfo);
+      med_entite_maillage anEntity;
+      TGeom aTGeom;
+      med_int aNbTimeStamps = aMed.GetNbTimeStamps(*aFieldInfo,aEntityInfo,
+                                                  anEntity,aTGeom);
+      cout<<"GetNbTimeStamps = "<<aNbTimeStamps<<endl;
+      PTimeStampInfo aTimeStampInfo(new TTimeStampInfo(aFieldInfo,anEntity,aTGeom));
+      for(int iTimeStamp = 0; iTimeStamp < aNbTimeStamps; iTimeStamp++){
+       aMed.GetTimeStampInfo(iTimeStamp+1, *aTimeStampInfo);
+
+       TTimeStampVal aTimeStampVal(aTimeStampInfo);
+       aMed.GetTimeStampVal(aTimeStampVal);
+       aMedW.SetTimeStamp(aTimeStampVal);
+
+       TMeshValue& aMeshValue = aTimeStampVal.myMeshValue;
+       TMeshValue::iterator aMeshValueIter = aMeshValue.begin();
+       for(; aMeshValueIter != aMeshValue.end(); aMeshValueIter++){
+         med_geometrie_element aGeom = aMeshValueIter->first;
+         TValue aValue = aMeshValueIter->second;
+         cout<<"\t\taGeom = "<<aGeom<<"; aValue = "<<aValue.size()<<": ";
+         for(int i = 0, iEnd = aValue.size()/aNbComp; i < iEnd; i++){
+           for(int j = 0, ij = i*aNbComp; j < aNbComp; j++, ij++){
+             //cout<<aValue[ij]<<",";
+           }
+           //cout<<" ";
+         }
+         cout<<"\n";
+       }
+      }
+    }
+
+    int aNbFam = aMed.GetNbFamilies(*aMeshInfo);
+    cout<<"GetNbFamilies() = "<<aNbFam<<endl;
+    for(int iFam = 0; iFam < aNbFam; iFam++){
+      int aNbAttr = aMed.GetNbFamAttr(iFam+1,*aMeshInfo);
+      int aNbGroup = aMed.GetNbFamGroup(iFam+1,*aMeshInfo);
+      PFamilyInfo aFamilyInfo(new TFamilyInfo(aMeshInfo,aNbGroup,aNbAttr));
+      aMed.GetFamilyInfo(iFam+1,*aFamilyInfo);
+      aName = aFamilyInfo->GetName();
+      cout<<"\taName = '"<<aName<<"'; aNbAttr = "<<aNbAttr<<"; aNbGroup = "<<aNbGroup<<endl;
+      aName[0] += 1;
+      aFamilyInfo->SetName(aName);
+      aFamilyInfo->myMeshInfo = aNewMeshInfo;
+      aName = aFamilyInfo->GetName();
+      for(int iGroup = 0; iGroup < aNbGroup; iGroup++){
+       aName = aFamilyInfo->GetGroupName(iGroup);
+       cout<<"\t\taGroupName = '"<<aName<<"'\n";
+       aName[0] += 1;
+       aFamilyInfo->SetGroupName(iGroup,aName);
+      }
+
+      aMedW.SetFamilyInfo(*aFamilyInfo);
+    }
+
+    cout<<"GetEntityInfo - aNbEntities = "<<aEntityInfo.size()<<endl;
+    TEntityInfo::iterator anEntityInfoIter = aEntityInfo.begin();
+    for(; anEntityInfoIter != aEntityInfo.end(); anEntityInfoIter++){
+      const med_entite_maillage& anEntity = anEntityInfoIter->first;
+      cout<<"\tanEntity = "<<anEntity<<endl;
+      if(anEntity == MED_NOEUD){
+       int aNbNodes = aMed.GetNbNodes(*aMeshInfo);
+       PNodeInfo aNodeInfo(new TNodeInfo(aMeshInfo,aNbNodes));
+       aMed.GetNodeInfo(*aNodeInfo);
+       cout<<"\tGetNodeInfo - aNbNodes = "<<aNbNodes<<": ";
+       TNodeCoord& aCoord = aNodeInfo->myCoord;
+       for(int iNode = 0; iNode < aNbNodes; iNode++){
+         for(int iDim = 0, anId = iNode*aDim; iDim < aDim; iDim++, anId++){
+           //cout<<aCoord[anId]<<",";
+           aCoord[anId] += 1.0;
+         }
+         //cout<<" ";
+       }
+       cout<<endl;
+       aNodeInfo->myMeshInfo = aNewMeshInfo;
+       aMedW.SetNodeInfo(*aNodeInfo);
+       continue;
+      }
+      TGeom& aTGeom = anEntityInfoIter->second;
+      TGeom::iterator anTGeomIter = aTGeom.begin();
+      for(; anTGeomIter != aTGeom.end(); anTGeomIter++){
+       const med_geometrie_element& aGeom = anTGeomIter->first;
+       med_int& aNbElem = anTGeomIter->second;
+       cout<<"\t\taGeom = "<<aGeom<<"; aNbElem = "<<aNbElem<<": ";
+       PCellInfo aCellInfo(new TCellInfo(aMeshInfo,aNbElem,anEntity,aGeom));
+       aMed.GetCellInfo(*aCellInfo);
+       for(int iElem = 0; iElem < aCellInfo->myNbElem; iElem++){
+         int i = iElem*aCellInfo->myConnDim;
+         for(int iConn = 0; iConn < aCellInfo->myConnDim; iConn++, i++){
+           //cout<<aCellInfo->myConn[i]<<",";
+         }
+         //cout<<" ";
+       }
+       cout<<endl;
+       aCellInfo->myMeshInfo = aNewMeshInfo;
+       aMedW.SetCellInfo(*aCellInfo);
+      }
+    }
+    
+  }
+  cout<<"OK"<<endl;
+}
+
+
+int main(int argc, char** argv){ 
+  try{
+    if(argc > 1)
+      ReadMed(argv[1]);
+    return 0;
+  }catch(std::exception& exc){
+    cout<<"Follow exception was accured :\n"<<exc.what()<<endl;
+  }catch(...){
+    cout<<"Unknown exception was accured in VISU_Convertor_impl"<<endl;
+  } 
+  return 1;
+}
diff --git a/src/MEDWrapper/MED_Utilities.cxx b/src/MEDWrapper/MED_Utilities.cxx
new file mode 100644 (file)
index 0000000..e09d642
--- /dev/null
@@ -0,0 +1,37 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MED_Utilities.hxx"
+
+using namespace std;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+int MED::PrefixPrinter::myCounter = 0;
+
+MED::PrefixPrinter::PrefixPrinter()
+{
+  myCounter++;
+}
+
+MED::PrefixPrinter::~PrefixPrinter()
+{
+  myCounter--;
+}
+
+string MED::PrefixPrinter::GetPrefix()
+{
+  if(myCounter)
+    return string(myCounter*2,' ');
+  return "";
+}
diff --git a/src/MEDWrapper/MED_Utilities.hxx b/src/MEDWrapper/MED_Utilities.hxx
new file mode 100644 (file)
index 0000000..a7cf092
--- /dev/null
@@ -0,0 +1,52 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Utilities_HeaderFile
+#define MED_Utilities_HeaderFile
+
+#include <iostream>    
+#include <sstream>     
+#include <string>
+#include <stdexcept>
+
+
+namespace MED{
+  using namespace std;
+  class PrefixPrinter{
+    static int myCounter;
+  public:
+    PrefixPrinter();
+    ~PrefixPrinter();
+
+    static string GetPrefix();
+  };
+};
+
+
+#ifndef MESSAGE
+
+#define MESSAGE(msg) std::cout<<__FILE__<<"["<<__LINE__<<"]::"<<msg<<endl;
+
+#define BEGMSG(msg) std::cout<<MED::PrefixPrinter::GetPrefix()<<msg
+
+#define ADDMSG(msg) std::cout<<msg
+
+#endif
+
+
+#ifndef EXCEPTION
+
+#define EXCEPTION(TYPE, MSG) {\
+  std::ostringstream aStream;\
+  aStream<<__FILE__<<"["<<__LINE__<<"]::"<<MSG;\
+  throw TYPE(aStream.str());\
+}
+
+#endif
+
+#endif
diff --git a/src/MEDWrapper/MED_Wrapper.cxx b/src/MEDWrapper/MED_Wrapper.cxx
new file mode 100644 (file)
index 0000000..d732fb0
--- /dev/null
@@ -0,0 +1,624 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.cxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#include "MED_Wrapper.hxx"
+#include "MED_Utilities.hxx"
+
+using namespace std;
+using namespace MED;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+
+
+//---------------------------------------------------------------
+static med_geometrie_element NODEGEOM[1] = {MED_POINT1};
+
+static med_geometrie_element EDGEGEOM[MED_NBR_GEOMETRIE_ARETE] = {
+  MED_SEG2, MED_SEG3
+};
+
+static med_geometrie_element FACEGEOM[MED_NBR_GEOMETRIE_FACE] = {
+  MED_TRIA3, MED_QUAD4, MED_TRIA6, MED_QUAD8
+};
+
+static med_geometrie_element  CELLGEOM[MED_NBR_GEOMETRIE_MAILLE] = {
+  MED_POINT1, MED_SEG2, MED_SEG3, MED_TRIA3,
+  MED_QUAD4, MED_TRIA6, MED_QUAD8, MED_TETRA4,
+  MED_PYRA5, MED_PENTA6, MED_HEXA8, MED_TETRA10, 
+  MED_PYRA13, MED_PENTA15, MED_HEXA20
+};
+
+void GetEntity2Geom(med_entite_maillage theEntity, med_geometrie_element*& theVector, int* theEnd){
+  switch(theEntity){
+  case MED_MAILLE: theVector = CELLGEOM; *theEnd = MED_NBR_GEOMETRIE_MAILLE; break;
+  case MED_FACE: theVector = FACEGEOM; *theEnd = MED_NBR_GEOMETRIE_FACE; break;
+  case MED_ARETE: theVector = EDGEGEOM; *theEnd = MED_NBR_GEOMETRIE_ARETE; break;
+  case MED_NOEUD: theVector = NODEGEOM; *theEnd = 1; break;
+  default:
+    EXCEPTION(runtime_error,"GetEntity2Geom - theEntity == "<<theEntity<<" is uncorrect");
+  }
+}
+
+
+//---------------------------------------------------------------
+TFile::TFile(const std::string& theFileName): 
+  myFid(0), 
+  myCount(0),
+  myFileName(strdup(theFileName.c_str()))
+{}
+
+TFile::~TFile(){ 
+  free(myFileName);
+  Close();
+}
+
+
+void TFile::Open(med_mode_acces theMode){
+  if(myCount++ == 0){
+    myFid = MEDouvrir(myFileName,theMode);
+    if(myFid < 0)
+      EXCEPTION(runtime_error,"TFile - MEDouvrir('"<<myFileName<<"',"<<theMode<<")");
+  }
+}
+void TFile::Close(){ 
+  if(--myCount == 0) {
+    MEDfermer(myFid);
+  }
+}
+
+const med_idt& TFile::Id() const { 
+  if(myFid < 0)
+    EXCEPTION(runtime_error,"TFile - GetFid() < 0");
+  return myFid;
+}
+
+
+//---------------------------------------------------------------
+TWrapper::TWrapper(const std::string& theFileName): 
+  myFile(theFileName)
+{}
+
+
+med_int TWrapper::GetNbMeshes(){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  return MEDnMaa(myFile.Id());
+}
+
+
+void TWrapper::GetMeshInfo(med_int theMeshId, TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  med_err ret = MEDmaaInfo(myFile.Id(),
+                          theMeshId,
+                          &theInfo.myName[0],
+                          &theInfo.myDim);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetMeshInfo - MEDmaaInfo(...)");
+}
+
+
+void TWrapper::SetMeshInfo(const TMeshInfo& theInfo){
+  med_err ret = -1;
+  try{
+    TFileWrapper aFileWrapper(myFile,MED_ECRI);
+    
+    TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+    ret = MEDmaaCr(myFile.Id(),
+                  &anInfo.myName[0],
+                  anInfo.myDim);
+  }catch(...){}
+  if(ret < 0){
+    TFileWrapper aFileWrapper(myFile,MED_REMP);
+    
+    TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+    ret = MEDmaaCr(myFile.Id(),
+                  &anInfo.myName[0],
+                  anInfo.myDim);
+  }
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetMeshInfo - MEDmaaCr(...)");
+}
+
+
+med_int TWrapper::GetNbFamilies(const TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+  return MEDnFam(myFile.Id(),
+                &anInfo.myName[0],
+                0,
+                MED_FAMILLE);
+}
+
+
+med_int TWrapper::GetNbFamAttr(med_int theFamId, const TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+  return MEDnFam(myFile.Id(),
+                &anInfo.myName[0],
+                theFamId,
+                MED_ATTR);
+}
+
+
+med_int TWrapper::GetNbFamGroup(med_int theFamId, const TMeshInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& anInfo = const_cast<TMeshInfo&>(theInfo);
+  return MEDnFam(myFile.Id(),
+                &anInfo.myName[0],
+                theFamId,
+                MED_GROUPE);
+}
+
+
+void TWrapper::GetFamilyInfo(med_int theFamId, TFamilyInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
+
+  med_err ret = MEDfamInfo(myFile.Id(),
+                          &aMeshInfo.myName[0],
+                          theFamId,
+                          &theInfo.myName[0],
+                          &theInfo.myId,
+                          &theInfo.myAttrId[0],
+                          &theInfo.myAttrVal[0],
+                          &theInfo.myAttrDesc[0],
+                          &theInfo.myNbAttr,
+                          &theInfo.myGroupNames[0],
+                          &theInfo.myNbGroup);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetFamilyInfo - MEDfamInfo(...)");
+}
+
+
+void TWrapper::SetFamilyInfo(const TFamilyInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+
+  TFamilyInfo& anInfo = const_cast<TFamilyInfo&>(theInfo);
+  TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
+
+  med_err ret = MEDfamCr(myFile.Id(),
+                        &aMeshInfo.myName[0],
+                        &anInfo.myName[0],
+                        anInfo.myId,
+                        &anInfo.myAttrId[0],
+                        &anInfo.myAttrVal[0],
+                        &anInfo.myAttrDesc[0],
+                        anInfo.myNbAttr,
+                        &anInfo.myGroupNames[0],
+                        anInfo.myNbGroup);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetFamilyInfo - MEDfamCr(...)");
+}
+
+
+med_int TWrapper::GetNbNodes(const TMeshInfo& theMeshInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo);
+
+  return MEDnEntMaa(myFile.Id(),
+                   &aMeshInfo.myName[0],
+                   MED_COOR,MED_NOEUD,
+                   med_geometrie_element(0),
+                   med_connectivite(0));
+}
+
+
+void TWrapper::GetNodeInfo(TNodeInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
+
+  med_err ret = MEDnoeudsLire(myFile.Id(),
+                             &aMeshInfo.myName[0],
+                             aMeshInfo.myDim,
+                             &theInfo.myCoord[0],
+                             MED_FULL_INTERLACE,
+                             &theInfo.mySystem,
+                             &theInfo.myCoordNames[0],
+                             &theInfo.myCoordUnits[0],
+                             &theInfo.myElemNames[0],
+                             &theInfo.myIsElemNames,
+                             &theInfo.myElemNum[0],
+                             &theInfo.myIsElemNum,
+                             &theInfo.myFamNum[0],
+                             theInfo.myNbElem);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetNodeInfo - MEDnoeudsLire(...)");
+}
+
+
+void TWrapper::SetNodeInfo(const TNodeInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+
+  TNodeInfo& anInfo = const_cast<TNodeInfo&>(theInfo);
+  TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
+
+  med_err ret = MEDnoeudsEcr(myFile.Id(),
+                            &aMeshInfo.myName[0],
+                            aMeshInfo.myDim,
+                            &anInfo.myCoord[0],
+                            MED_FULL_INTERLACE,
+                            anInfo.mySystem,
+                            &anInfo.myCoordNames[0],
+                            &anInfo.myCoordUnits[0],
+                            &anInfo.myElemNames[0],
+                            anInfo.myIsElemNames,
+                            &anInfo.myElemNum[0],
+                            anInfo.myIsElemNum,
+                            &anInfo.myFamNum[0],
+                            anInfo.myNbElem,
+                            MED_REMP);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetNodeInfo - MEDnoeudsEcr(...)");
+}
+
+
+TEntityInfo TWrapper::GetEntityInfo(const TMeshInfo& theMeshInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TEntityInfo anInfo;
+  if(med_int aNbElem = GetNbNodes(theMeshInfo)){
+    anInfo[MED_NOEUD][MED_POINT1] = aNbElem;
+    med_entite_maillage anEntityVector[3] = {MED_MAILLE, MED_FACE, MED_ARETE};
+    for(med_int iEntity = 0; iEntity < 3; iEntity++){
+      med_int iGeomEnd;
+      med_entite_maillage& anEntity = anEntityVector[iEntity];
+      med_geometrie_element* aGeomVector;
+      GetEntity2Geom(anEntity,aGeomVector,&iGeomEnd);
+      for(med_int iGeom = 0; iGeom < iGeomEnd; iGeom++) {
+       med_geometrie_element& aGeom = aGeomVector[iGeom];
+       if(med_int aNb = GetNbCells(theMeshInfo,anEntity,aGeom)){
+         anInfo[anEntity][aGeom] = aNb;
+       }
+      }
+    }
+  }
+  return anInfo;
+}
+
+
+med_int TWrapper::GetNbCells(const TMeshInfo& theMeshInfo, 
+                            med_entite_maillage theTEntity, 
+                            med_geometrie_element theTGeom, 
+                            med_connectivite theTConn)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = const_cast<TMeshInfo&>(theMeshInfo);
+
+  return MEDnEntMaa(myFile.Id(),
+                   &aMeshInfo.myName[0],
+                   MED_CONN,
+                   theTEntity,
+                   theTGeom,
+                   theTConn); 
+}
+
+
+void TWrapper::GetCellInfo(TCellInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  TMeshInfo& aMeshInfo = *theInfo.myMeshInfo;
+  med_int aNbElem = theInfo.myElemNum.size();
+
+  med_err ret = MEDelementsLire(myFile.Id(),
+                               &aMeshInfo.myName[0],
+                               aMeshInfo.myDim,
+                               &theInfo.myConn[0],
+                               MED_FULL_INTERLACE,
+                               &theInfo.myElemNames[0],
+                               &theInfo.myIsElemNames,
+                               &theInfo.myElemNum[0],
+                               &theInfo.myIsElemNum,
+                               &theInfo.myFamNum[0],
+                               aNbElem,
+                               theInfo.myTEntity,
+                               theInfo.myTGeom,
+                               theInfo.myTConn);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)");
+}
+
+
+void TWrapper::SetCellInfo(const TCellInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+
+  TCellInfo& anInfo = const_cast<TCellInfo&>(theInfo);
+  TMeshInfo& aMeshInfo = *anInfo.myMeshInfo;
+  med_int aNbElem = anInfo.myElemNum.size();
+
+  med_err ret = MEDelementsEcr(myFile.Id(),
+                              &aMeshInfo.myName[0],
+                              aMeshInfo.myDim,
+                              &anInfo.myConn[0],
+                              MED_FULL_INTERLACE,
+                              &anInfo.myElemNames[0],
+                              anInfo.myIsElemNames,
+                              &anInfo.myElemNum[0],
+                              anInfo.myIsElemNum,
+                              &anInfo.myFamNum[0],
+                              anInfo.myNbElem,
+                              anInfo.myTEntity,
+                              anInfo.myTGeom,
+                              anInfo.myTConn,
+                              MED_REMP);
+
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetCellInfo - MEDelementsLire(...)");
+}
+
+
+med_int TWrapper::GetNbFields(){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  return MEDnChamp(myFile.Id(),0);
+}
+
+
+med_int TWrapper::GetNbComp(med_int theFieldId){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  return MEDnChamp(myFile.Id(),theFieldId);
+}
+
+
+void TWrapper::GetFieldInfo(med_int theFieldId, TFieldInfo& theInfo){
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+  
+  med_err ret = MEDchampInfo(myFile.Id(),
+                            theFieldId,
+                            &theInfo.myName[0],
+                            &theInfo.myType,
+                            &theInfo.myCompNames[0],
+                            &theInfo.myUnitNames[0],
+                            theInfo.myNbComp);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetFieldInfo - MEDchampInfo(...)");
+}
+
+
+void TWrapper::SetFieldInfo(const TFieldInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+  
+  TFieldInfo& anInfo = const_cast<TFieldInfo&>(theInfo);
+  med_err ret = MEDchampCr(myFile.Id(),
+                          &anInfo.myName[0],
+                          anInfo.myType,
+                          &anInfo.myCompNames[0],
+                          &anInfo.myUnitNames[0],
+                          anInfo.myNbComp);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"SetFieldInfo - MEDchampEcr(...)");
+}
+
+
+med_int TWrapper::GetNbTimeStamps(const TFieldInfo& theInfo, 
+                                 const TEntityInfo& theEntityInfo,
+                                 med_entite_maillage& theEntity,
+                                 TGeom& theGeom)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+
+  if(theEntityInfo.empty()) 
+    EXCEPTION(runtime_error,"GetNbTimeStamps - There is no any Entity on the Mesh");
+
+  theGeom.clear();
+  med_int aNbTimeStamps = 0;
+  TFieldInfo& anInfo = const_cast<TFieldInfo&>(theInfo);
+  TEntityInfo::const_iterator anIter = theEntityInfo.begin();
+  for(; anIter != theEntityInfo.end(); anIter++){
+    const med_entite_maillage& anEntity = anIter->first;
+    const TGeom& aTGeom = anIter->second;
+    TGeom::const_iterator anGeomIter = aTGeom.begin();
+    for(; anGeomIter != aTGeom.end(); anGeomIter++){
+      const med_geometrie_element& aGeom = anGeomIter->first;
+      aNbTimeStamps = MEDnPasdetemps(myFile.Id(),&anInfo.myName[0],anEntity,aGeom);
+      if(aNbTimeStamps){
+       theEntity = anEntity;
+       theGeom[aGeom] = anGeomIter->second;
+      }
+    }
+    if(aNbTimeStamps) break;
+  }
+  return aNbTimeStamps;
+}
+
+
+void TWrapper::GetTimeStampInfo(med_int theTimeStampId, TTimeStampInfo& theInfo)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+  med_idt anId = myFile.Id();
+
+  TFieldInfo& aFieldInfo = *theInfo.myFieldInfo;
+  TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
+
+  med_entite_maillage anEntity = theInfo.myEntity;
+  TGeom& aTGeom = theInfo.myGeom;
+  if(aTGeom.empty())
+    EXCEPTION(runtime_error,"GetTimeStampInfo - There is no any cell");
+
+  TGeom::iterator anIter = aTGeom.begin();
+  med_geometrie_element aGeom = anIter->first;
+
+  med_err ret = MEDpasdetempsInfo(anId,
+                                 &aFieldInfo.myName[0],
+                                 anEntity,
+                                 aGeom,
+                                 theTimeStampId,
+                                 &aMeshInfo.myName[0],
+                                 &theInfo.myNbGauss,
+                                 &theInfo.myNumDt,
+                                 &theInfo.myUnitDt[0],
+                                 &theInfo.myDt,
+                                 &theInfo.myNumOrd);
+  if(ret < 0)
+    EXCEPTION(runtime_error,"GetTimeStampInfo - MEDpasdetempsInfo(...)");
+
+  static med_int MAX_NB_GAUSS_POINTS = 32;
+  if(theInfo.myNbGauss > MAX_NB_GAUSS_POINTS) 
+    theInfo.myNbGauss = 1;
+}
+
+void TWrapper::SetTimeStamp(const TTimeStampVal& theVal)
+{
+  TFileWrapper aFileWrapper(myFile,MED_ECRI);
+  
+  TTimeStampVal& aVal = const_cast<TTimeStampVal&>(theVal);
+  TTimeStampInfo& aTimeStampInfo = *aVal.myTimeStampInfo;
+  TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo;
+  TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
+  TMeshValue& aMeshValue = aVal.myMeshValue;
+  
+  med_entite_maillage anEntity = aTimeStampInfo.myEntity;
+  TMeshValue::iterator anIter = aMeshValue.begin();
+  for(; anIter != aMeshValue.end(); anIter++){
+    const med_geometrie_element& aGeom = anIter->first;
+    TValue& aValue = aVal.myMeshValue[aGeom];
+    med_int iEnd = aValue.size();
+    med_int aNbVal = iEnd / aFieldInfo.myNbComp;
+    
+    med_err ret;
+    switch(aFieldInfo.myType){
+    case MED_REEL64: {
+      valarray<med_float>& anArray = aValue;
+
+      ret = MEDchampEcr(myFile.Id(),
+                       &aMeshInfo.myName[0],
+                       &aFieldInfo.myName[0],
+                       (unsigned char*)&anArray[0],
+                       MED_FULL_INTERLACE,
+                       aNbVal,
+                       aTimeStampInfo.myNbGauss,
+                       MED_ALL,
+                       &aVal.myPflName[0],
+                       MED_ECRI, 
+                       anEntity,
+                       aGeom,
+                       aTimeStampInfo.myNumDt,
+                       &aTimeStampInfo.myUnitDt[0],
+                       aTimeStampInfo.myDt,
+                       aTimeStampInfo.myNumOrd);
+      break;
+    }
+    case MED_INT32:
+    case MED_INT: {
+      valarray<med_int> anArray(iEnd);
+      for(med_int i = 0; i< iEnd; i++) anArray[i] = med_int(aValue[i]);
+
+      ret = MEDchampEcr(myFile.Id(),
+                       &aMeshInfo.myName[0],
+                       &aFieldInfo.myName[0],
+                       (unsigned char*)&anArray[0],
+                       MED_FULL_INTERLACE,
+                       aNbVal,
+                       aTimeStampInfo.myNbGauss,
+                       MED_ALL,
+                       &aVal.myPflName[0],
+                       MED_ECRI, 
+                       anEntity,
+                       aGeom,
+                       aTimeStampInfo.myNumDt,
+                       &aTimeStampInfo.myUnitDt[0],
+                       aTimeStampInfo.myDt,
+                       aTimeStampInfo.myNumOrd);
+      break;
+    }
+    default: 
+      EXCEPTION(runtime_error,"SetTimeStamp - Type of the field == "<<aFieldInfo.myType<<" is wrong");
+    }
+    if(ret < 0)
+      EXCEPTION(runtime_error,"SetTimeStamp - MEDchampEcr(...)");
+  }
+}
+
+void TWrapper::GetTimeStampVal(TTimeStampVal& theVal)
+{
+  TFileWrapper aFileWrapper(myFile,MED_LECT);
+  med_idt anId = myFile.Id();
+
+  TTimeStampInfo& aTimeStampInfo = *theVal.myTimeStampInfo;
+  TFieldInfo& aFieldInfo = *aTimeStampInfo.myFieldInfo;
+  TMeshInfo& aMeshInfo = *aFieldInfo.myMeshInfo;
+  TMeshValue& aMeshValue = theVal.myMeshValue;
+
+  med_entite_maillage anEntity = aTimeStampInfo.myEntity;
+  TGeom& aTGeom = aTimeStampInfo.myGeom;
+  TGeom::iterator anIter = aTGeom.begin();
+  for(; anIter != aTGeom.end(); anIter++){
+    const med_geometrie_element& aGeom = anIter->first;
+    med_int aNbVal = MEDnVal(anId,&aFieldInfo.myName[0],anEntity,aGeom,
+                            aTimeStampInfo.myNumDt,aTimeStampInfo.myNumOrd);
+    if(aNbVal <= 0)
+      EXCEPTION(runtime_error,"GetTimeStampInfo - MEDnVal(...) - aNbVal == "<<aNbVal<<" <= 0");
+
+    TValue& aValue = theVal.myMeshValue[aGeom];
+    med_int iEnd = aNbVal * aFieldInfo.myNbComp;
+
+    if(iEnd != aValue.size())
+      EXCEPTION(runtime_error,"GetTimeStampInfo - iEnd == "<<iEnd<<" != aValue.size() == "<<aValue.size());
+
+    med_err ret;
+    switch(aFieldInfo.myType){
+    case MED_REEL64: {
+      valarray<med_float> anArray(iEnd);
+      ret = MEDchampLire(myFile.Id(),
+                        &aMeshInfo.myName[0],
+                        &aFieldInfo.myName[0],
+                        (unsigned char*)&anArray[0],
+                        MED_FULL_INTERLACE,
+                        MED_ALL,
+                        &theVal.myPflName[0],
+                        anEntity,
+                        aGeom,
+                        aTimeStampInfo.myNumDt,
+                        aTimeStampInfo.myNumOrd);
+      if(ret >= 0) 
+       for(med_int i = 0; i < iEnd; i++) aValue[i] = anArray[i];
+      break;
+    }
+    case MED_INT32:
+    case MED_INT: {
+      valarray<med_int> anArray(iEnd);
+      ret = MEDchampLire(myFile.Id(),
+                        &aMeshInfo.myName[0],
+                        &aFieldInfo.myName[0],
+                        (unsigned char*)&anArray[0],
+                        MED_FULL_INTERLACE,
+                        MED_ALL,
+                        &theVal.myPflName[0],
+                        anEntity,
+                        aGeom,
+                        aTimeStampInfo.myNumDt,
+                        aTimeStampInfo.myNumOrd);
+      if(ret >= 0) 
+       for(med_int i = 0; i < iEnd; i++) aValue[i] = anArray[i];
+      break;
+    }
+    default:
+      EXCEPTION(runtime_error,"GetValTimeStamp - Type of the field == "<<aFieldInfo.myType<<" is wrong");
+    }
+    if(ret < 0)
+      EXCEPTION(runtime_error,"GetValTimeStamp - MEDchampLire(...)");
+  }
+}
diff --git a/src/MEDWrapper/MED_Wrapper.hxx b/src/MEDWrapper/MED_Wrapper.hxx
new file mode 100644 (file)
index 0000000..efb5c5e
--- /dev/null
@@ -0,0 +1,125 @@
+//  Copyright (C) 2003  CEA/DEN, EDF R&D
+//
+//
+//
+//  File   : VISU_DatConvertor.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef MED_Wrapper_HeaderFile
+#define MED_Wrapper_HeaderFile
+
+extern "C"{
+#include <med.h>
+}  
+#include "MED_Structures.hxx"
+
+
+namespace MED{
+//---------------------------------------------------------------
+  class TFile{
+    TFile();
+    TFile(const TFile&);
+  public:
+    TFile(const string& theFileName);
+    ~TFile();
+    
+    void Open(med_mode_acces theMode);
+    const med_idt& Id() const;
+    void Close();
+
+  protected:
+    char* myFileName;
+    med_idt myFid;
+    int myCount;
+  };
+
+
+//---------------------------------------------------------------
+  class TFileWrapper{
+    TFile& myFile;
+  public:
+    TFileWrapper(TFile& theFile, med_mode_acces theMode): 
+      myFile(theFile)
+    {
+      myFile.Open(theMode);
+    }
+
+    ~TFileWrapper(){
+      myFile.Close();
+    }
+  };
+
+
+//---------------------------------------------------------------
+  class TWrapper{
+    TWrapper();
+    TWrapper(const TWrapper&);
+    
+  public:
+    TWrapper(const string& theFileName);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbMeshes();
+    
+    void GetMeshInfo(med_int theMeshId, TMeshInfo&);
+    void SetMeshInfo(const TMeshInfo& theInfo);
+    
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbFamilies(const TMeshInfo& theMeshInfo);
+    med_int GetNbFamAttr(med_int theFamId, const TMeshInfo& theInfo);
+    med_int GetNbFamGroup(med_int theFamId, const TMeshInfo& theInfo);
+    
+    void GetFamilyInfo(med_int theFamId, TFamilyInfo& theInfo);
+    void SetFamilyInfo(const TFamilyInfo& theInfo);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbNodes(const TMeshInfo& theMeshInfo);
+    
+    void GetNodeInfo(TNodeInfo&);
+    void SetNodeInfo(const TNodeInfo&);
+    
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    TEntityInfo GetEntityInfo(const TMeshInfo& theMeshInfo);
+    
+    med_int GetNbCells(const TMeshInfo& theMeshInfo, 
+                      med_entite_maillage, 
+                      med_geometrie_element, 
+                      med_connectivite theTConn = MED_NOD);
+    
+    void GetCellInfo(TCellInfo& theInfo);
+    void SetCellInfo(const TCellInfo& theInfo);
+    
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbFields();
+    
+    med_int GetNbComp(med_int theFieldId);
+    
+    void GetFieldInfo(med_int theFieldId, TFieldInfo& theInfo);
+    void SetFieldInfo(const TFieldInfo& theInfo);
+
+
+    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    med_int GetNbTimeStamps(const TFieldInfo& theInfo, 
+                           const TEntityInfo& theEntityInfo,
+                           med_entite_maillage& theEntity,
+                           TGeom& theGeom);
+
+    void GetTimeStampInfo(med_int theTimeStampId, TTimeStampInfo&);
+
+    void GetTimeStampVal(TTimeStampVal& theTimeStampVal);
+
+    void SetTimeStamp(const TTimeStampVal& theTimeStampVal);
+
+  protected:
+    TFile myFile;
+  };
+
+};
+
+#endif
diff --git a/src/MEDWrapper/Makefile.in b/src/MEDWrapper/Makefile.in
new file mode 100644 (file)
index 0000000..71cbd7c
--- /dev/null
@@ -0,0 +1,51 @@
+#  VISU OBJECT : interactive object for VISU entities implementation
+#
+#  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+#  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+# 
+#  This library is free software; you can redistribute it and/or 
+#  modify it under the terms of the GNU Lesser General Public 
+#  License as published by the Free Software Foundation; either 
+#  version 2.1 of the License. 
+# 
+#  This library is distributed in the hope that it will be useful, 
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+#  Lesser General Public License for more details. 
+# 
+#  You should have received a copy of the GNU Lesser General Public 
+#  License along with this library; if not, write to the Free Software 
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+# 
+#  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+#
+#
+#
+#  File   : Makefile.in
+#  Module : VISU
+
+top_srcdir=@top_srcdir@
+top_builddir=../..
+srcdir=@srcdir@
+VPATH=.:@srcdir@:@top_srcdir@/idl
+
+
+@COMMENCE@
+
+EXPORT_HEADERS = MED_Common.hxx MED_Utilities.hxx MEDA_Structures.hxx MEDA_Wrapper.hxx MEDA_Algorithm.hxx
+
+# Libraries targets
+
+LIB = libMEDWrapper.la
+LIB_SRC = MED_Structures.cxx MED_Wrapper.cxx MED_Utilities.cxx \
+         MEDA_Structures.cxx MEDA_Wrapper.cxx MEDA_Algorithm.cxx 
+
+# Executables targets
+BIN = MED_Test MEDA_Test MEDA_Test1
+BIN_SRC = 
+
+CPPFLAGS+= $(BOOST_CPPFLAGS)  $(MED2_INCLUDES)
+
+LDFLAGS+= $(MED2_LIBS) $(HDF5_LIBS)
+
+@CONCLUDE@
diff --git a/src/Utils/Utils_CatchSignals.cxx b/src/Utils/Utils_CatchSignals.cxx
new file mode 100644 (file)
index 0000000..8d9b6c4
--- /dev/null
@@ -0,0 +1,230 @@
+//  KERNEL Utils : common utils for KERNEL
+//  Copyright (C) 2003  CEA
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+//
+//
+//
+//  File   : Utils_CatchSignals.cxx
+//  Author : Oksana Tchebanova
+//  Module : KERNEL
+//  $Header:
+
+
+#include "Utils_CatchSignals.h"
+#include "utilities.h"
+
+#include <stdexcept>
+
+#define RESERVE_SIZE 100000
+
+static void* theCallBack = NULL;
+static int *myReserve = NULL;
+using namespace std;
+//=======================================================================
+//function : Utils_CatchSignals
+//purpose  : Constructor
+//=======================================================================
+Utils_CatchSignals::Utils_CatchSignals() 
+     :myIsActivated(false)
+{
+  
+  for(int i = 0; i<SIG_MAX_NUM; i++)
+    mySigStates[i] = NULL;
+
+  theCallBack = NULL; 
+}
+
+#ifndef WNT
+
+//================================ UNIX part ==================================================
+
+
+//==============================
+typedef void (ACT_SIGIO_HANDLER)(void) ;
+
+ACT_SIGIO_HANDLER *ADR_ACT_SIGIO_HANDLER = NULL ;
+
+typedef void (* SIG_PFV) (int);
+
+#ifdef SUN
+# include <floatingpoint.h>
+#endif
+
+#ifdef SOLARIS
+# include <floatingpoint.h>
+# include <sys/machsig.h>
+# include <stdlib.h>
+# include <stdio.h>
+#endif
+
+#include <signal.h>
+#include <sys/signal.h>
+
+#ifdef LIN
+# include <stdlib.h>
+# include <stdio.h>
+#else
+# ifdef SA_SIGINFO 
+#   ifndef AIX
+# include <bits/siginfo.h>
+#    endif
+# endif
+#endif
+
+
+#ifdef IRIX
+# include <sigfpe.h>
+# include <sys/siginfo.h>
+#endif 
+
+#include <unistd.h>
+//============================================================================
+//function : Handler 
+//purpose  : univisal handler for signals
+//============================================================================
+static void Handler(const int theSig )
+{
+  if (myReserve) {
+    delete myReserve; 
+    myReserve = NULL;
+  }
+  char aMessage[1000];
+  sprintf (aMessage, "%d signal cautch : %s", theSig, strsignal(theSig));
+#ifdef _DEBUG_ 
+  MESSAGE("Utils_CatchSignal  Handler :: " << aMessage );
+#endif
+  if(theCallBack == NULL) {
+#ifdef _DEBUG_ 
+    MESSAGE("Utils_CatchSignal  Handler : throw std::runtime_error()");
+#endif
+    throw (std::runtime_error(aMessage));
+  }
+  else ((void (*)())theCallBack)();  
+}
+//=======================================================================
+//function : TryHandlerReset
+//purpose  : Redefine signal handlers. If the handler of the signal is
+//           set as SIG_IGN. That's why the shells often ignore some 
+//           signal when starting child processes. We keep it.
+//=======================================================================
+static SIG_PFV TryHandlerReset( int theSigNum )
+{
+  if (signal(theSigNum, (SIG_PFV) &Handler) == SIG_IGN)
+    {
+      signal(theSigNum, SIG_IGN);  
+#ifdef _DEBUG_
+      MESSAGE("signal "<<theSigNum <<" is kept as ignored");
+#endif
+     return SIG_IGN;
+    } 
+  else return signal(theSigNum, (SIG_PFV) &Handler);
+}
+//=======================================================================
+//function : Activate
+//purpose  : 
+//=======================================================================
+
+void Utils_CatchSignals::Activate() 
+{  
+  if(myIsActivated) return;
+
+  if (myReserve) delete myReserve;
+  myReserve = new int[RESERVE_SIZE];
+
+    
+  mySigStates[0] = TryHandlerReset(SIGHUP);   // ...... floating point exception
+  mySigStates[1] = TryHandlerReset(SIGFPE);   // ...... floating point exception
+  
+  mySigStates[2] = TryHandlerReset(SIGINT);   // ...... interrupt
+  mySigStates[3] = TryHandlerReset(SIGQUIT);  // ...... quit
+  mySigStates[4] = TryHandlerReset(SIGBUS);   // ...... bus error
+  mySigStates[5] = TryHandlerReset(SIGILL);   // ...... illegal instruction
+  mySigStates[6] = TryHandlerReset(SIGTERM);  // ...... termination
+  mySigStates[7] = TryHandlerReset(SIGSEGV);  // ...... segmentation 
+  //mySigStates[8] = TryHandlerReset (SIGABRT); // ...... abort (ANSI).  
+  mySigStates[9] = TryHandlerReset(SIGSTKFLT);// ...... stack fault.  
+
+  myIsActivated = true;
+}
+
+//=======================================================================
+//function : Deactivate
+//purpose  : 
+//=======================================================================
+void Utils_CatchSignals::Deactivate() 
+{
+  if(!myIsActivated) return;
+
+  signal(SIGHUP, (SIG_PFV)mySigStates[0]);   // ...... hangup
+  signal(SIGFPE, (SIG_PFV)mySigStates[1]);   // ...... floating point exception
+  signal(SIGINT, (SIG_PFV)mySigStates[2]);   // ...... interrupt
+  signal(SIGQUIT,(SIG_PFV)mySigStates[3]);   // ...... quit
+  signal(SIGBUS, (SIG_PFV)mySigStates[4]);   // ...... bus error
+  signal(SIGILL, (SIG_PFV)mySigStates[5]);   // ...... illegal instruction
+  signal(SIGTERM,(SIG_PFV)mySigStates[6]);   // ...... illegal instruction
+  signal(SIGSEGV,(SIG_PFV)mySigStates[7]);   // ...... segmentation violation
+  //signal(SIGABRT,(SIG_PFV)mySigStates[8] );  // ...... abort (ANSI).     
+  signal(SIGSTKFLT,(SIG_PFV)mySigStates[9]); // ...... stack fault.  
+
+  myIsActivated = false;
+  delete myReserve;
+  myReserve = NULL;
+}
+#endif // ifndef WNT
+
+//=======================================================================
+//function : SetCallBack
+//purpose  : Sets pointer to (void (*)()
+//=======================================================================
+void Utils_CatchSignals::SetCallBack(const int theAddressHiPart, 
+                                        const int theAddressLowPart) 
+{
+  theCallBack = (void *)((theAddressHiPart << 32 ) + theAddressLowPart); 
+}
+
+//=======================================================================
+//function : UnsetCallBack
+//purpose  : 
+//=======================================================================
+void Utils_CatchSignals::UnsetCallBack()
+{
+  theCallBack = NULL;
+}
+
+//=======================================================================
+//function : Destroy
+//purpose  : 
+//=======================================================================
+void Utils_CatchSignals::Destroy() 
+{
+  if(myIsActivated) Deactivate();
+}
+
+bool Utils_CatchSignals::ReserveMemory()
+{
+  if (!myReserve) myReserve = new int [RESERVE_SIZE];
+  return true;
+}
+
+void Utils_CatchSignals::FreeReserved()
+{
+  if (myReserve) 
+    {delete myReserve ; myReserve = NULL;}
+}
diff --git a/src/Utils/Utils_CatchSignals.h b/src/Utils/Utils_CatchSignals.h
new file mode 100644 (file)
index 0000000..bf45e7b
--- /dev/null
@@ -0,0 +1,60 @@
+//  KERNEL Utils : common utils for KERNEL
+//  Copyright (C) 2003  CEA
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+//
+//
+//
+//  File   : Utils_CatchSignals.h
+//  Author : Oksana Tchebanova
+//  Module : KERNEL
+//  $Header:
+
+#ifndef _UTILS_CATCHSIGNALS_H_
+#define _UTILS_CATCHSIGNALS_H_
+
+#include <stdio.h>
+#define SIG_MAX_NUM 11 
+
+typedef void (* SIG_PFV) (int);
+
+class Utils_CatchSignals {
+
+ public:
+  Utils_CatchSignals();
+  void Destroy() ;
+  ~Utils_CatchSignals()
+    {
+      Destroy();
+    }
+
+  static  void SetCallBack(const int theAddressHiPart,const int theAddressLowPart) ;
+  static  void UnsetCallBack() ;
+  void Activate();
+  void Deactivate() ;
+  bool ReserveMemory();
+  void FreeReserved();
+
+private: 
+
+  SIG_PFV mySigStates[SIG_MAX_NUM];
+  int  myFloatOpWord;
+  bool myIsActivated;
+};
+
+#endif
diff --git a/src/Utils/Utils_ExceptHandlers.cxx b/src/Utils/Utils_ExceptHandlers.cxx
new file mode 100644 (file)
index 0000000..4037ebd
--- /dev/null
@@ -0,0 +1,21 @@
+// File:       Utils_ExceptHandler.cxx
+// Created:    Mon Mar 15 10:23:41 2004
+// Author:     Oksana TCHEBANOVA
+//             <ota@localhost.localdomain>
+
+
+#include <Utils_ExceptHandlers.hxx>
+#include "Utils_CorbaException.hxx"
+#include "Utils_SALOME_Exception.hxx"
+#include <SALOMEconfig.h>
+#include CORBA_SERVER_HEADER(SALOME_Exception)
+
+void SalomeException ()
+{
+  throw SALOME_Exception("Salome Exception");
+}
+
+void SALOME_SalomeException() {
+  THROW_SALOME_CORBA_EXCEPTION("INTERNAL ERROR", SALOME::INTERNAL_ERROR);
+}
+
diff --git a/src/Utils/Utils_ExceptHandlers.hxx b/src/Utils/Utils_ExceptHandlers.hxx
new file mode 100644 (file)
index 0000000..5555824
--- /dev/null
@@ -0,0 +1,75 @@
+//  KERNEL Utils : common utils for KERNEL
+//  Copyright (C) 2003  CEA
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+//
+//
+//
+//  File   : Utils_ExceptHandlers.hxx
+//  Author : Oksana Tchebanova
+//  Module : KERNEL
+//  $Header:
+
+
+#ifndef Utils_ExceptHandlers_HeaderFile
+#define Utils_ExceptHandlers_HeaderFile
+
+#include <stdexcept>
+#include <utilities.h>
+
+typedef void (*PVF)();
+
+class Unexpect { //save / retrieve unexpected exceptions treatment
+  PVF old;
+  public :
+    Unexpect( PVF f ) 
+      { old = set_unexpected(f); }
+  ~Unexpect() { set_unexpected(old); }
+};
+
+class Terminate {//save / retrieve terminate function
+  
+  PVF old;
+  public :
+    Terminate( PVF f ) 
+      { old = set_terminate(f); }
+  ~Terminate() { set_terminate(old); }
+};
+
+#define UNEXPECT_CATCH(FuncName, ExceptionConstructor) \
+void FuncName () {\
+   throw ExceptionConstructor (); \
+}
+//Example of the usage 
+
+// void DTC_NotFound () {
+//   throw (SALOME_DataTypeCatalog::NotFound());
+// }
+// or the same :
+//
+// UNEXPECT_CATCH( DTC_NotFound , SALOME_DataTypeCatalog::NotFound)
+// in the function body :
+// ....
+// Unexpect aCatch(DTC_NotFound) // redefinition of the unexpect exceptions handler
+// ....
+
+
+//Definitions :
+extern void SalomeException();
+extern void SALOME_SalomeException();
+#endif
diff --git a/src/VTKFilter/SALOME_ExtractUnstructuredGrid.cxx b/src/VTKFilter/SALOME_ExtractUnstructuredGrid.cxx
new file mode 100644 (file)
index 0000000..e484dee
--- /dev/null
@@ -0,0 +1,338 @@
+//  VISU CONVERTOR :
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+// File:    VISU_ExtractUnstructuredGrid.cxx
+// Author:  Alexey PETROV
+// Module : VISU
+
+
+#include "SALOME_ExtractUnstructuredGrid.h"
+#include "utilities.h"
+
+#include <vtkUnsignedCharArray.h>
+#include <vtkUnstructuredGrid.h>
+#include <vtkObjectFactory.h>
+#include <vtkCellArray.h>
+#include <vtkIntArray.h>
+#include <vtkIdList.h>
+#include <vtkCell.h>
+
+using namespace std;
+
+#ifdef _DEBUG_
+static int MYDEBUG = 1;
+#else
+static int MYDEBUG = 0;
+#endif
+
+vtkStandardNewMacro(SALOME_ExtractUnstructuredGrid);
+
+
+SALOME_ExtractUnstructuredGrid::SALOME_ExtractUnstructuredGrid():
+  myExtractionMode(eCells), myChangeMode(ePassAll)
+{}
+
+
+SALOME_ExtractUnstructuredGrid::~SALOME_ExtractUnstructuredGrid(){}
+
+
+void SALOME_ExtractUnstructuredGrid::RegisterCell(vtkIdType theCellId){
+  if(0 && MYDEBUG) MESSAGE("RegisterCell - theCellId = "<<theCellId);
+  myCellIds.insert(theCellId);
+  Modified();
+}
+
+
+void SALOME_ExtractUnstructuredGrid::RegisterCellsWithType(vtkIdType theCellType){
+  if(0 && MYDEBUG) MESSAGE("RegisterCellsWithType - theCellType = "<<theCellType);
+  myCellTypes.insert(theCellType);
+  Modified();
+}
+
+
+void SALOME_ExtractUnstructuredGrid::SetStoreMapping(int theStoreMapping){
+  myStoreMapping = theStoreMapping;
+  this->Modified();
+}
+
+vtkIdType SALOME_ExtractUnstructuredGrid::GetOutId(int theOutId) const{
+  if(myCellIds.empty() && myCellTypes.empty()) return theOutId;
+  if(myOut2InId.empty() || theOutId > myOut2InId.size()) return -1;
+  return myOut2InId.at(theOutId);
+}
+
+vtkIdType SALOME_ExtractUnstructuredGrid::GetInId(int theInId) const{
+  if(myCellIds.empty() && myCellTypes.empty()) return theInId;
+  TMapId::const_iterator anIter = myIn2OutId.find(theInId);
+  if(anIter == myIn2OutId.end()) return -1;
+  return anIter->second;
+}
+
+
+inline void InsertCell(vtkUnstructuredGrid *theInput,
+                      vtkCellArray *theConnectivity, 
+                      vtkUnsignedCharArray* theCellTypesArray,
+                      vtkIdType theCellId, 
+                      vtkIdList *theIdList,
+                      bool theStoreMapping,
+                      vtkIdType theOutId, 
+                      SALOME_ExtractUnstructuredGrid::TVectorId& theOut2InId,
+                      SALOME_ExtractUnstructuredGrid::TMapId& theIn2OutId)
+{
+  vtkCell *aCell = theInput->GetCell(theCellId);
+  vtkIdList *aPntIds = aCell->GetPointIds();
+  vtkIdType aNbIds = aPntIds->GetNumberOfIds();
+  theIdList->SetNumberOfIds(aNbIds);
+  for(vtkIdType i = 0; i < aNbIds; i++){
+    theIdList->SetId(i,aPntIds->GetId(i));
+  }
+  theConnectivity->InsertNextCell(theIdList);
+
+  vtkIdType aCellType = aCell->GetCellType();
+  theCellTypesArray->InsertNextValue(aCellType);
+  if(theStoreMapping){
+    theOut2InId.push_back(theCellId);
+    theIn2OutId[theCellId] = theOutId;
+  }
+}
+
+inline void InsertPointCell(vtkCellArray *theConnectivity, 
+                           vtkUnsignedCharArray* theCellTypesArray,
+                           vtkIdType theCellId, 
+                           vtkIdList *theIdList,
+                           bool theStoreMapping,
+                           vtkIdType theOutId, 
+                           SALOME_ExtractUnstructuredGrid::TVectorId& theOut2InId,
+                           SALOME_ExtractUnstructuredGrid::TMapId& theIn2OutId)
+{
+  theIdList->SetId(0,theCellId);
+  theConnectivity->InsertNextCell(theIdList);
+  theCellTypesArray->InsertNextValue(VTK_VERTEX);
+  if(theStoreMapping){
+    theOut2InId.push_back(theCellId);
+    theIn2OutId[theCellId] = theOutId;
+  }
+}
+
+void SALOME_ExtractUnstructuredGrid::Execute(){
+  vtkUnstructuredGrid *anInput = this->GetInput();
+  vtkUnstructuredGrid *anOutput = this->GetOutput();
+  myOut2InId.clear();  myIn2OutId.clear();
+
+  if(MYDEBUG){
+    MESSAGE("Execute - anInput->GetNumberOfCells() = "<<anInput->GetNumberOfCells());
+    MESSAGE("Execute - myCellTypes.size() = "<<myCellTypes.size());
+    MESSAGE("Execute - myCellIds.size() = "<<myCellIds.size());
+    MESSAGE("Execute - myExtractionMode = "<<myExtractionMode);
+    MESSAGE("Execute - myChangeMode = "<<myChangeMode);
+  }
+  if(myExtractionMode == eCells){
+    if(myChangeMode == ePassAll || myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving){
+      if(vtkIdType aNbElems = anInput->GetNumberOfCells()){
+       if(myStoreMapping) myOut2InId.reserve(aNbElems);
+       anOutput->ShallowCopy(anInput);
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         if(myStoreMapping){
+           myOut2InId.push_back(aCellId);
+           myIn2OutId[aCellId] = anOutId;
+         }
+       }
+      }
+    }else{
+      vtkIdList *anIdList = vtkIdList::New();
+      vtkCellArray *aConnectivity = vtkCellArray::New();
+      vtkIdType aNbElems = anInput->GetNumberOfCells();
+      aConnectivity->Allocate(2*aNbElems,0);
+      vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+      aCellTypesArray->SetNumberOfComponents(1);
+      aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
+      if(!myCellIds.empty() && myCellTypes.empty()){
+       if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
+       if(myChangeMode == eAdding){
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           if(myCellIds.find(aCellId) != myCellIds.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }else{
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           if(myCellIds.find(aCellId) == myCellIds.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }else if(myCellIds.empty() && !myCellTypes.empty()){
+       if(myChangeMode == eAdding){
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) != myCellTypes.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }else{
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) == myCellTypes.end()){
+             InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                        myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }else if(!myCellIds.empty() && !myCellTypes.empty()){
+       if(myChangeMode == eAdding){
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) != myCellTypes.end()){
+             if(myCellIds.find(aCellId) != myCellIds.end()){
+               InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             }
+           }
+         }
+       }else{
+         for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+           vtkIdType aType = anInput->GetCellType(aCellId);
+           if(myCellTypes.find(aType) == myCellTypes.end()){
+             if(myCellIds.find(aCellId) == myCellIds.end()){
+               InsertCell(anInput,aConnectivity,aCellTypesArray,aCellId,anIdList,
+                          myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+             }
+           }
+         }
+       }
+      }
+      if(aNbElems = aConnectivity->GetNumberOfCells()){
+       vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+       aCellLocationsArray->SetNumberOfComponents(1);
+       aCellLocationsArray->SetNumberOfTuples(aNbElems);
+       aConnectivity->InitTraversal();
+       for(vtkIdType i = 0, *pts, npts; aConnectivity->GetNextCell(npts,pts); i++){
+         aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
+       }
+       anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
+       anOutput->SetPoints(anInput->GetPoints());
+       aCellLocationsArray->Delete();
+      }
+      aCellTypesArray->Delete();
+      aConnectivity->Delete();
+      anIdList->Delete();
+    }
+  }else{
+    vtkIdList *anIdList = vtkIdList::New();
+    anIdList->SetNumberOfIds(1);
+    vtkCellArray *aConnectivity = vtkCellArray::New();
+    vtkIdType aNbElems = anInput->GetNumberOfPoints();
+    aConnectivity->Allocate(2*aNbElems,0);
+    vtkUnsignedCharArray* aCellTypesArray = vtkUnsignedCharArray::New();
+    aCellTypesArray->SetNumberOfComponents(1);
+    aCellTypesArray->Allocate(aNbElems*aCellTypesArray->GetNumberOfComponents());
+    if(myChangeMode == ePassAll || myCellIds.empty() && myCellTypes.empty() && myChangeMode == eRemoving){
+      if(myStoreMapping) myOut2InId.reserve(aNbElems);
+      for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+       InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                       myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+      }
+    }else if(!myCellIds.empty() && myCellTypes.empty()){
+      if(myStoreMapping) myOut2InId.reserve(myCellIds.size());
+      if(myChangeMode == eAdding){
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         if(myCellIds.find(aCellId) != myCellIds.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }else{
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         if(myCellIds.find(aCellId) == myCellIds.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }
+    }else if(myCellIds.empty() && !myCellTypes.empty()){
+      if(myChangeMode == eAdding){
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) != myCellTypes.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }else{
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) == myCellTypes.end()){
+           InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                           myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+         }
+       }
+      }
+    }else if(!myCellIds.empty() && !myCellTypes.empty()){
+      if(myChangeMode == eAdding){
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) != myCellTypes.end()){
+           if(myCellIds.find(aCellId) != myCellIds.end()){
+             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                             myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }else{
+       for(vtkIdType aCellId = 0, anOutId = 0; aCellId < aNbElems; aCellId++,anOutId++){
+         vtkIdType aType = anInput->GetCellType(aCellId);
+         if(myCellTypes.find(aType) == myCellTypes.end()){
+           if(myCellIds.find(aCellId) == myCellIds.end()){
+             InsertPointCell(aConnectivity,aCellTypesArray,aCellId,anIdList,
+                             myStoreMapping,anOutId,myOut2InId,myIn2OutId);
+           }
+         }
+       }
+      }
+    }
+    if(aNbElems = aConnectivity->GetNumberOfCells()){
+      vtkIntArray* aCellLocationsArray = vtkIntArray::New();
+      aCellLocationsArray->SetNumberOfComponents(1);
+      aCellLocationsArray->SetNumberOfTuples(aNbElems);
+      aConnectivity->InitTraversal();
+      for(vtkIdType i = 0, *pts, npts; aConnectivity->GetNextCell(npts,pts); i++){
+       aCellLocationsArray->SetValue(i,aConnectivity->GetTraversalLocation(npts));
+      }
+      anOutput->SetCells(aCellTypesArray,aCellLocationsArray,aConnectivity);
+      anOutput->SetPoints(anInput->GetPoints());
+      aCellLocationsArray->Delete();
+    }
+    aCellTypesArray->Delete();
+    aConnectivity->Delete();
+    anIdList->Delete();
+  }
+  if(MYDEBUG){
+    MESSAGE("Execute - anOutput->GetNumberOfCells() = "<<anOutput->GetNumberOfCells());
+    if(myStoreMapping){
+      MESSAGE("Execute - myOut2InId.size() = "<<myOut2InId.size());
+      MESSAGE("Execute - myIn2OutId.size() = "<<myIn2OutId.size());
+    }
+  }
+}
diff --git a/src/VTKFilter/SALOME_ExtractUnstructuredGrid.h b/src/VTKFilter/SALOME_ExtractUnstructuredGrid.h
new file mode 100644 (file)
index 0000000..2e91379
--- /dev/null
@@ -0,0 +1,111 @@
+//  VISU CONVERTOR :
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//  File   : SALOME_ExtractUnstructuredGrid.hxx
+//  Author : Alexey PETROV
+//  Module : VISU
+
+#ifndef SALOME_ExtractUnstructuredGrid_HeaderFile
+#define SALOME_ExtractUnstructuredGrid_HeaderFile
+
+#include <vtkUnstructuredGridToUnstructuredGridFilter.h>
+
+#include <set>
+#include <map>
+#include <vector>
+
+class SALOME_ExtractUnstructuredGrid : public vtkUnstructuredGridToUnstructuredGridFilter{
+public:
+  vtkTypeMacro(SALOME_ExtractUnstructuredGrid,vtkUnstructuredGridToUnstructuredGridFilter);
+
+  // Description:
+  // Construct with all types of clipping turned off.
+  static SALOME_ExtractUnstructuredGrid *New();
+
+  enum EExtraction{ eCells, ePoints};
+  void SetModeOfExtraction(EExtraction theExtractionMode){
+    myExtractionMode = theExtractionMode; Modified();
+  }
+  EExtraction GetModeOfExtraction(){ return myExtractionMode;}
+
+  enum EChanging{ ePassAll, eAdding, eRemoving};
+  void SetModeOfChanging(EChanging theChangeMode){
+    myChangeMode = theChangeMode; 
+    Modified();
+  }
+  EChanging GetModeOfChanging(){ return myChangeMode;}
+
+  // Remove the cell from the output
+  void RegisterCell(vtkIdType theCellId);
+  int IsCellsRegistered() { return !myCellIds.empty();}
+  int ClearRegisteredCells() { 
+    myCellIds.clear();
+    Modified();
+  }
+  
+  // Remove every cells with the type from the output
+  void RegisterCellsWithType(vtkIdType theCellType);
+  int IsCellsWithTypeRegistered() { return !myCellTypes.empty();}
+  int ClearRegisteredCellsWithType() { 
+    myCellTypes.clear();
+    Modified();
+  }
+
+  // Do the filter do some real work
+  int IsChanging() { return IsCellsRegistered() || IsCellsWithTypeRegistered();}
+
+  // Do it keep the mapping between input's and output's UnstructuredGrid
+  void SetStoreMapping(int theStoreMapping);
+  int GetStoreMapping(){ return myStoreMapping;}
+
+  vtkIdType GetOutId(int theOutId) const;
+  vtkIdType GetInId(int theInId) const;
+
+  typedef std::vector<vtkIdType> TVectorId;
+  typedef std::map<vtkIdType,vtkIdType> TMapId;
+
+protected:
+  SALOME_ExtractUnstructuredGrid();
+  ~SALOME_ExtractUnstructuredGrid();
+
+  void Execute();
+
+  EExtraction myExtractionMode;
+  
+  EChanging myChangeMode;
+  typedef std::set<vtkIdType> TSetId;
+  TSetId myCellIds;
+  TSetId myCellTypes;
+
+  bool myStoreMapping;
+  TVectorId myOut2InId;
+  TMapId myIn2OutId;
+
+private:
+  SALOME_ExtractUnstructuredGrid(const SALOME_ExtractUnstructuredGrid&);  // Not implemented.
+  void operator=(const SALOME_ExtractUnstructuredGrid&);  // Not implemented.
+};
+
+
+#endif
+
+
diff --git a/src/VTKViewer/VTKViewer_CellRectPicker.cxx b/src/VTKViewer/VTKViewer_CellRectPicker.cxx
new file mode 100644 (file)
index 0000000..6e05537
--- /dev/null
@@ -0,0 +1,433 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_CellRectPicker.cxx
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#include <VTKViewer_CellRectPicker.h>
+
+#include "vtkGenericCell.h"
+#include "vtkAssemblyNode.h"
+#include "vtkAssemblyPath.h"
+#include "vtkObjectFactory.h"
+#include "vtkImageData.h"
+#include "vtkMapper.h"
+#include "vtkVolumeMapper.h"
+#include "vtkMath.h"
+#include "vtkLine.h"
+#include "vtkQuad.h"
+#include "vtkPoints.h"
+#include "vtkPlane.h"
+#include "vtkActor.h"
+
+using namespace std;
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(VTKViewer_CellRectPicker);
+//----------------------------------------------------------------------------
+
+VTKViewer_CellRectPicker::VTKViewer_CellRectPicker()
+{
+  this->Cell = vtkGenericCell::New();
+  this->Quad1 = vtkQuad::New();
+  this->Quad2 = vtkQuad::New();
+}
+
+VTKViewer_CellRectPicker::~VTKViewer_CellRectPicker()
+{
+  this->Cell->Delete();
+  this->Quad1->Delete();
+  this->Quad2->Delete();
+}
+
+void VTKViewer_CellRectPicker::Initialize()
+{
+  ActorData.clear();
+  this->VTKViewer_RectPicker::Initialize();
+}
+
+//----------------------------------------------------------------------------
+float VTKViewer_CellRectPicker::IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                                                vtkAssemblyPath *path, vtkProp3D *prop3D, 
+                                                vtkAbstractMapper3D *m)
+{
+  vtkDataSet *input;
+  vtkMapper *mapper;
+  vtkVolumeMapper *volumeMapper;
+
+  // Get the underlying dataset
+  if ( (mapper=vtkMapper::SafeDownCast(m)) != NULL ) {
+    input = mapper->GetInput();
+  }
+  else if ( (volumeMapper=vtkVolumeMapper::SafeDownCast(m)) != NULL ) {
+    input = volumeMapper->GetInput();
+  }
+  else {
+    return VTK_LARGE_FLOAT;
+  }
+
+  vtkIdType numCells;
+  if ( (numCells = input->GetNumberOfCells()) < 1 ) {
+    return 2.0;
+  }
+
+  int i, k, subId;
+  float bounds[6], center[3], cp1[3], cp2[3];
+  float pcoord[3], weight[4], dist;
+  float t1[2], t2[2], x[3], t;
+
+  for (k = 0; k < 4; k++) {
+    this->Quad1->PointIds->SetId(k, k);
+    this->Quad1->Points->SetPoint(k, p1[k]);
+    this->Quad2->PointIds->SetId(k, k);
+    this->Quad2->Points->SetPoint(k, p2[k]);
+  }
+
+  /*
+  cout << "---> Selection area:"   << endl;
+  for (k = 0; k < 4; k++)
+    cout << "\t(" << p1[k][0] << ", " << p1[k][1] << ", " << p1[k][2] << ")";
+  cout << endl;
+  for (k = 0; k < 4; k++)
+    cout << "\t(" << p2[k][0] << ", " << p2[k][1] << ", " << p2[k][2] << ")";
+  cout << endl;
+  */
+
+  vtkIdType cellId;
+  VTKViewer_CellData cellData;
+  VTKViewer_CellDataSet dataList;
+
+  char inside; int n; float *point;
+  float tMin = VTK_LARGE_FLOAT, xMin[3];
+  for (cellId = 0; cellId < numCells; cellId++) {
+    input->GetCell(cellId, this->Cell);
+
+    this->Cell->GetBounds(bounds);
+    for (i = 0; i < 3; i++)
+      center[i] = (bounds[2*i]+bounds[2*i+1])/2;
+
+    /*
+    if (!VTKViewer_RectPicker::PointInside(center, p1, p2, 0.01))
+      continue;
+    */
+
+    inside = 1;
+    n = this->Cell->Points->GetNumberOfPoints();
+    //cout << "---> Info cell " << cellId << " (" << n << "): " << endl;
+    for (k = 0; k < n; k++) {
+      point = this->Cell->Points->GetPoint(k);
+      //cout << "  P (" << point[0] << ", " << point[1] << ", " << point[2] << ")";
+      if (!VTKViewer_RectPicker::PointInside(point, p1, p2)) {
+       inside = 0; break;
+      }
+    }
+    //cout << endl;
+    if (!inside) continue;
+
+    //cout << "---> Inside cell " << cellId << endl;
+
+    this->Quad1->EvaluatePosition(center, 0, subId, pcoord, dist, weight);
+    t1[0] = pcoord[0]; t1[1] = pcoord[1];
+    this->Quad2->EvaluatePosition(center, 0, subId, pcoord, dist, weight);
+    t2[0] = pcoord[0]; t2[1] = pcoord[1];
+
+    pcoord[0] = (t1[0]+t2[0])/2; pcoord[1] = (t1[1]+t2[1])/2; pcoord[2] = 0;
+
+    this->Quad1->EvaluateLocation(subId, pcoord, cp1, weight);
+    this->Quad2->EvaluateLocation(subId, pcoord, cp2, weight);
+
+    if (this->Cell->IntersectWithLine(cp1, cp2, tol, t, x, pcoord, subId)) {
+      cellData.cellId = cellId;
+      cellData.subId = subId;
+      cellData.depth = t;
+      for (i = 0; i < 3; i++) {
+       cellData.p1[i] = cp1[i];
+       cellData.p2[i] = cp2[i];
+      }
+      /*
+      cout << "---> Include cell " << cellId << ", depth = " << t   << endl;
+      cout << "     P1 = (" << cp1[0] << ", " << cp1[1] << ", " << cp1[2] << ")"  << endl;
+      cout << "     P2 = (" << cp2[0] << ", " << cp2[1] << ", " << cp2[2] << ")"  << endl;
+      */
+      IncludeCell(input, cellData, dataList);
+      if (t < tMin) {
+       tMin = t;
+       for (i = 0; i < 3; i++)
+         xMin[i] = x[i];
+      }
+    }
+  }
+
+  if (!dataList.empty()) {
+    // compare against other actors
+    IncludeActor(prop3D, input, dataList);
+    if (tMin < this->GlobalTMin) {
+      this->MarkPicked(path, prop3D, m, tMin, xMin);
+    }
+  }
+
+  return tMin;
+}
+
+
+//----------------------------------------------------------------------------
+void VTKViewer_CellRectPicker::IncludeCell(vtkDataSet* input, 
+                                          VTKViewer_CellData cellData, 
+                                          VTKViewer_CellDataSet& dataList)
+{
+  vtkGenericCell* cell1 = vtkGenericCell::New();
+  vtkGenericCell* cell2 = vtkGenericCell::New();
+  vtkCell* sub1 = 0;
+  vtkCell* sub2 = 0;
+  
+  input->GetCell(cellData.cellId, cell1);
+  if (cell1->GetNumberOfFaces() > 0)
+    sub1 = cell1->GetFace(cellData.subId);
+
+  int i, result;
+  float p1[3], p2[3], dir[3];
+  char add = 1;
+
+  VTKViewer_CellData curData;
+  VTKViewer_CellDataSet::iterator it;
+  for (it = dataList.begin(); it != dataList.end();) {
+    curData = *it;
+    for (i = 0; i < 3; i++) {
+      p1[i] = (cellData.p1[i]+curData.p1[i])/2;
+      p2[i] = (cellData.p2[i]+curData.p2[i])/2;
+      dir[i] = p2[i] - p1[i];
+    }
+
+    input->GetCell(curData.cellId, cell2);
+    sub2 = 0;
+    if (cell2->GetNumberOfFaces() > 0)
+      sub2 = cell2->GetFace(curData.subId);
+
+    if (sub1) {
+      if (sub2)
+       result = IntersectCells(sub1, cellData.depth, 
+                               sub2, curData.depth, dir);
+      else 
+       result = IntersectCells(sub1, cellData.depth, 
+                               cell2, curData.depth, dir);
+    }
+    else {
+      if (sub2)
+       result = IntersectCells(cell1, cellData.depth, 
+                               sub2, curData.depth, dir);
+      else
+       result = IntersectCells(cell1, cellData.depth, 
+                               cell2, curData.depth, dir);
+    }
+    /*
+    cout << "     Direction = (" << dir[0] << ", " << dir[1] << ", " << dir[2] << ")";
+    cout << "     depth = " << cellData.depth << ", " << curData.depth << ", " << result << endl;
+    */
+    if (result > 0) {
+      if (result == 1) {
+       it = dataList.erase(it);
+       continue;
+      } 
+      else {
+       add = 0;
+       break;
+      }
+    }
+    ++it;
+  }
+  if (add) {
+    //cout << "     add "   << endl;
+    dataList.push_back(cellData);
+  }
+
+  cell1->Delete();
+  cell2->Delete();
+}
+
+//----------------------------------------------------------------------------
+void VTKViewer_CellRectPicker::IncludeActor(vtkProp3D* prop, 
+                                           vtkDataSet* input, 
+                                           VTKViewer_CellDataSet& dataList)
+{
+  vtkGenericCell* cell1 = vtkGenericCell::New();
+  vtkGenericCell* cell2 = vtkGenericCell::New();
+
+  int i, result;
+  float p1[3], p2[3], dir[3];
+  char removed;
+
+  VTKViewer_CellDataSet actorData;
+  VTKViewer_CellData curData, cellData;
+  VTKViewer_CellDataSet::iterator it1, it2;
+  VTKViewer_ActorDataMap::iterator it;
+
+  for (it1 = dataList.begin(); it1 != dataList.end();) {
+    cellData = *it1;
+    input->GetCell(cellData.cellId, cell1);
+    removed = 0;
+
+    for (it = ActorData.begin(); it != ActorData.end(); ++it) {
+      vtkActor* actor = (*it).first;
+      actorData = (*it).second;
+
+      for (it2 = actorData.begin(); it2 != actorData.end();) {
+       curData = *it2;
+       for (i = 0; i < 3; i++) {
+         p1[i] = (cellData.p1[i]+curData.p1[i])/2;
+         p2[i] = (cellData.p2[i]+curData.p2[i])/2;
+         dir[i] = p2[i] - p1[i];
+       }
+
+       input->GetCell(curData.cellId, cell2);
+       result = IntersectCells(cell1, cellData.depth,
+                               cell2, curData.depth, dir);
+       if (result > 0) {
+         if (result == 1) {
+           it2 = actorData.erase(it2);
+           continue;
+         }
+         else {
+           removed = 1;
+           it1 = dataList.erase(it1);
+           break;
+         }
+         break;
+       }
+       ++it2;
+      }
+      if (removed) break;
+    } // by actors
+    if (!removed) ++it1;
+  }
+
+  if (!dataList.empty()) {
+    vtkActor* actor;
+    if ((actor = vtkActor::SafeDownCast(prop)) != NULL)
+      ActorData[actor] = dataList;
+  }
+
+  cell1->Delete();
+  cell2->Delete();
+}
+
+int VTKViewer_CellRectPicker::IntersectCells(vtkCell* c1, float d1, vtkCell* c2, float d2, float dir[3])
+{
+  int i, k;
+  float *orig, cp[3], bounds[6];
+  vtkCell* cell = 0;
+  vtkCell* tcell = 0;
+
+  // define the central point and cell for projection
+  if (fabs(d1-d2) < 1.e-7) return 0;
+
+  if (d1 < d2) {
+    orig = c1->Points->GetPoint(0);
+    cell = c1;
+    tcell = c2;
+    c2->GetBounds(bounds);
+    for (i = 0; i < 3; i++)
+      cp[i] = (bounds[2*i] + bounds[2*i+1])/2;
+  }
+  else if (d1 > d2) {
+    orig = c2->Points->GetPoint(0);
+    cell = c2;
+    tcell = c1;
+    c1->GetBounds(bounds);
+    for (i = 0; i < 3; i++)
+      cp[i] = (bounds[2*i] + bounds[2*i+1])/2;
+  }
+
+  float proj[3];
+  vtkPlane::GeneralizedProjectPoint(cp, orig, dir, proj);
+
+  float *p, pp[3];
+  vtkPoints* aPoints = vtkPoints::New();
+  for (k = 0; k < cell->Points->GetNumberOfPoints(); k++) {
+    p = cell->Points->GetPoint(k);
+    vtkPlane::GeneralizedProjectPoint(p, orig, dir, pp);
+    aPoints->InsertNextPoint(pp[0], pp[1], pp[2]);
+  }
+
+  int result = 0;
+  if (PointInside(proj, aPoints)) {
+    result = (d1<d2) ? 1 : 2;
+  }
+
+  if (result == 0) {
+    // test for boundary cells
+    for (k = 0; k < tcell->Points->GetNumberOfPoints(); k++) {
+      p = tcell->Points->GetPoint(k);
+      vtkPlane::GeneralizedProjectPoint(p, orig, dir, pp);
+      if (PointInside(pp, aPoints)) {
+       result = 1; break;
+      }
+    }
+    if (result && d2<d1) result = 2;
+  }
+
+  aPoints->Delete();
+  return result;
+}
+
+char VTKViewer_CellRectPicker::PointInside(float point[3], vtkPoints* list)
+{
+  int i, k, l, n;
+  float x[3], *a1, *a2, v[3], p[3], q[3];
+
+  n = list->GetNumberOfPoints();
+  if (n < 3) return 0;
+
+  for (k = 0; k < n; k++) {
+    l = k+1; if (l == n) l = 0;
+    a1 = list->GetPoint(k);
+    a2 = list->GetPoint(l);
+
+    // compute vectors
+    for (i = 0; i < 3; i++) {
+      x[i] = point[i] - a1[i];
+      v[i] = a2[i]-a1[i];
+    }
+
+    // check if point coincides with vertex
+    if (x[0]*x[0] + x[1]*x[1] + x[2]*x[2] < 1.e-7) return 0;
+
+    // compute normal
+    vtkMath::Cross(x, v, p);
+
+    // check if point lays on edge
+    if (p[0]*p[0] + p[1]*p[1] + p[2]*p[2] < 1.e-7) return 0;
+
+    // check if normals are in the same direction
+    if (k > 0) {
+      if (vtkMath::Dot(p, q) < 0.0) return 0;
+    }
+
+    // remember normal direction
+    for (i = 0; i < 3; i++) {
+      q[i] = p[i];
+    }
+  }
+
+  return 1;
+}
diff --git a/src/VTKViewer/VTKViewer_CellRectPicker.h b/src/VTKViewer/VTKViewer_CellRectPicker.h
new file mode 100644 (file)
index 0000000..76b0b8c
--- /dev/null
@@ -0,0 +1,94 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_CellRectPicker.h
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#ifndef __VTKViewer_CellRectPicker_h
+#define __VTKViewer_CellRectPicker_h
+
+#include "VTKViewer_RectPicker.h"
+#include <map>
+#include <vector>
+
+typedef struct {
+  vtkIdType cellId;
+  int subId;
+  float depth;
+  float p1[3];
+  float p2[3];
+} VTKViewer_CellData;
+
+typedef std::vector<VTKViewer_CellData> VTKViewer_CellDataSet;
+typedef std::map<vtkActor*, VTKViewer_CellDataSet> VTKViewer_ActorDataMap;
+
+class vtkCell;
+class vtkGenericCell;
+class vtkQuad;
+
+class VTK_EXPORT VTKViewer_CellRectPicker : public VTKViewer_RectPicker
+{
+public:
+  static VTKViewer_CellRectPicker *New();
+  vtkTypeMacro(VTKViewer_CellRectPicker,VTKViewer_RectPicker);
+
+  // Description:
+  // Get the id of the picked cells. 
+  // (Notes: use GetActors() to get picked actors list)
+  VTKViewer_CellDataSet GetCellData(vtkActor* actor) 
+    { return this->ActorData[actor]; }
+
+  // Description:
+  // The method returns a non-zero value if the cells intersect each other 
+  // in the direction dir[3]. Returned value is 1 if the first cell is top of 
+  // the second one according to direction and 2 if the second cell is top.
+  static int IntersectCells(vtkCell* c1, float d1, vtkCell* c2, float d2, float dir[3]);
+
+  // Description:
+  // The method returns a non-zero value if the point is inlide point data set
+  static char PointInside(float point[3], vtkPoints* list);
+
+protected:
+  VTKViewer_CellRectPicker();
+  ~VTKViewer_CellRectPicker();
+
+  VTKViewer_ActorDataMap ActorData;
+
+  virtual float IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                          vtkAssemblyPath *path, vtkProp3D *p, 
+                          vtkAbstractMapper3D *m);
+  void Initialize();
+
+  void IncludeCell(vtkDataSet* input, VTKViewer_CellData cellData, VTKViewer_CellDataSet& dalaList);
+  void IncludeActor(vtkProp3D* prop, vtkDataSet* input, VTKViewer_CellDataSet& dataList);
+
+private:
+  vtkGenericCell *Cell;
+  vtkQuad* Quad1;
+  vtkQuad* Quad2;
+};
+
+#endif
+
+
diff --git a/src/VTKViewer/VTKViewer_Filter.cxx b/src/VTKViewer/VTKViewer_Filter.cxx
new file mode 100755 (executable)
index 0000000..8c09a46
--- /dev/null
@@ -0,0 +1,57 @@
+//  VTKViewer_Filter : Filter for VTK viewer\r
+//\r
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+//  This library is free software; you can redistribute it and/or \r
+//  modify it under the terms of the GNU Lesser General Public \r
+//  License as published by the Free Software Foundation; either \r
+//  version 2.1 of the License. \r
+// \r
+//  This library is distributed in the hope that it will be useful, \r
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
+//  Lesser General Public License for more details. \r
+// \r
+//  You should have received a copy of the GNU Lesser General Public \r
+//  License along with this library; if not, write to the Free Software \r
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
+// \r
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+//  File   : VTKViewer_Filter.cxx\r
+//  Author : Sergey LITONIN\r
+//  Module : SALOME\r
+\r
+#include "VTKViewer_Filter.h"\r
+\r
+IMPLEMENT_STANDARD_HANDLE(VTKViewer_Filter, MMgt_TShared)\r
+IMPLEMENT_STANDARD_RTTIEXT(VTKViewer_Filter, MMgt_TShared)\r
+\r
+/*\r
+  Class       : VTKViewer_Filter\r
+  Description : Base class of filters of for VTK viewer. Method IsValid \r
+                should be redefined in derived classes\r
+*/\r
+\r
+VTKViewer_Filter::VTKViewer_Filter()\r
+{\r
+  myActor = 0;\r
+}\r
+\r
+VTKViewer_Filter::~VTKViewer_Filter()\r
+{\r
+}\r
+\r
+bool VTKViewer_Filter::IsValid( SALOME_Actor* theActor, const int theCellId )\r
+{\r
+  SetActor( theActor );\r
+  return IsValid( theCellId );\r
+}\r
+\r
+void VTKViewer_Filter::SetActor( SALOME_Actor* theActor )\r
+{\r
+  myActor = theActor;\r
+}\r
diff --git a/src/VTKViewer/VTKViewer_Filter.h b/src/VTKViewer/VTKViewer_Filter.h
new file mode 100755 (executable)
index 0000000..d9d9831
--- /dev/null
@@ -0,0 +1,64 @@
+//  SMESHGUI_Filter : Filter for VTK viewer\r
+//\r
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,\r
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS \r
+// \r
+//  This library is free software; you can redistribute it and/or \r
+//  modify it under the terms of the GNU Lesser General Public \r
+//  License as published by the Free Software Foundation; either \r
+//  version 2.1 of the License. \r
+// \r
+//  This library is distributed in the hope that it will be useful, \r
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of \r
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU \r
+//  Lesser General Public License for more details. \r
+// \r
+//  You should have received a copy of the GNU Lesser General Public \r
+//  License along with this library; if not, write to the Free Software \r
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA \r
+// \r
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org \r
+//\r
+//\r
+//\r
+//  File   : VTKViewer_Filter.h\r
+//  Author : Sergey LITONIN\r
+//  Module : SALOME\r
+\r
+#ifndef VTKViewer_Filter_HeaderFile\r
+#define VTKViewer_Filter_HeaderFile\r
+\r
+#include <MMgt_TShared.hxx>\r
+#include <Standard_DefineHandle.hxx>\r
+\r
+class SALOME_Actor;\r
+\r
+DEFINE_STANDARD_HANDLE(VTKViewer_Filter, MMgt_TShared)\r
+\r
+/*\r
+  Class       : VTKViewer_Filter\r
+  Description : Base class of filters of for VTK viewer. Method IsValid \r
+                should be redefined in derived classes\r
+*/\r
+\r
+class VTKViewer_Filter : public MMgt_TShared\r
+{\r
+\r
+public:\r
+                              VTKViewer_Filter();\r
+  virtual                     ~VTKViewer_Filter();\r
+\r
+  bool                        IsValid( SALOME_Actor*, const int theCellId );\r
+  virtual bool                IsValid( const int theCellId ) const = 0;\r
+\r
+  virtual void                SetActor( SALOME_Actor* );\r
+\r
+protected:\r
+\r
+  SALOME_Actor*               myActor;\r
+\r
+public:  \r
+  DEFINE_STANDARD_RTTI(VTKViewer_Filter)\r
+};\r
+\r
+#endif\r
diff --git a/src/VTKViewer/VTKViewer_RectPicker.cxx b/src/VTKViewer/VTKViewer_RectPicker.cxx
new file mode 100644 (file)
index 0000000..6453097
--- /dev/null
@@ -0,0 +1,881 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_RectPicker.cxx
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#include <VTKViewer_RectPicker.h>
+
+#include "vtkActor.h"
+#include "vtkAssemblyNode.h"
+#include "vtkAssemblyPath.h"
+#include "vtkCamera.h"
+#include "vtkCommand.h"
+#include "vtkImageData.h"
+#include "vtkLODProp3D.h"
+#include "vtkMapper.h"
+#include "vtkMath.h"
+#include "vtkObjectFactory.h"
+#include "vtkPoints.h"
+#include "vtkProp3DCollection.h"
+#include "vtkProperty.h"
+#include "vtkRenderWindow.h"
+#include "vtkRenderer.h"
+#include "vtkTransform.h"
+#include "vtkVertex.h"
+#include "vtkVolume.h"
+#include "vtkVolumeMapper.h"
+
+using namespace std;
+
+//----------------------------------------------------------------------------
+vtkStandardNewMacro(VTKViewer_RectPicker);
+//----------------------------------------------------------------------------
+
+VTKViewer_RectPicker::VTKViewer_RectPicker()
+{
+}
+
+//----------------------------------------------------------------------------
+int VTKViewer_RectPicker::Pick(float selectionX1, float selectionY1, float selectionZ1,
+                              float selectionX2, float selectionY2, float selectionZ2,
+                              vtkRenderer *renderer)
+{
+  int k, i;
+  vtkProp *prop;
+  vtkCamera *camera;
+  vtkAbstractMapper3D *mapper = NULL;
+  float p1World[4][4], p2World[4][4], p1Mapper[4][4], p2Mapper[4][4];
+  float c1[3], c2[3];
+  int picked=0;
+  int *winSize;
+  float x, y, t, p;
+  float *viewport;
+  float cameraPos[4], cameraFP[4];
+  float *displayCoords, *worldCoords;
+  float pickPosition[4][3];
+  double *clipRange;
+  float ray[4][3], rayLength[4];
+  int pickable;
+  int LODId;
+  float windowLowerLeft[4], windowUpperRight[4];
+  float bounds[6], tol;
+  float tF, tB;
+  float hitPosition[3];
+  float cameraDOP[3];
+  
+  //  Initialize picking process
+  this->Initialize();
+  this->Renderer = renderer;
+
+  /* Selection point is not defined for the rectangle
+  this->SelectionPoint[0] = 
+  this->SelectionPoint[1] = 
+  this->SelectionPoint[2] = 
+  */
+
+  // Invoke start pick method if defined
+  this->InvokeEvent(vtkCommand::StartPickEvent,NULL);
+
+  if ( renderer == NULL )
+    {
+    vtkErrorMacro(<<"Must specify renderer!");
+    return 0;
+    }
+
+  // Get camera focal point and position. Convert to display (screen) 
+  // coordinates. We need a depth value for z-buffer.
+  //
+  camera = renderer->GetActiveCamera();
+  camera->GetPosition((float *)cameraPos); cameraPos[3] = 1.0;
+  camera->GetFocalPoint((float *)cameraFP); cameraFP[3] = 1.0;
+
+  renderer->SetWorldPoint(cameraFP);
+  renderer->WorldToDisplay();
+  displayCoords = renderer->GetDisplayPoint();
+  selectionZ1 = selectionZ2 = displayCoords[2];
+
+  // Convert the selection rectangle into world coordinates.
+  //
+  renderer->SetDisplayPoint(selectionX1, selectionY1, selectionZ1);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[0][i] = worldCoords[i] / worldCoords[3];
+    }
+
+  renderer->SetDisplayPoint(selectionX1, selectionY2, (selectionZ1+selectionZ2)/2);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[1][i] = worldCoords[i] / worldCoords[3];
+    }
+  
+  renderer->SetDisplayPoint(selectionX2, selectionY2, selectionZ2);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[2][i] = worldCoords[i] / worldCoords[3];
+    }
+
+  renderer->SetDisplayPoint(selectionX2, selectionY1, (selectionZ1+selectionZ2)/2);
+  renderer->DisplayToWorld();
+  worldCoords = renderer->GetWorldPoint();
+  if ( worldCoords[3] == 0.0 )
+    {
+    vtkErrorMacro(<<"Bad homogeneous coordinates");
+    return 0;
+    }
+  for (i=0; i < 3; i++) 
+    {
+    pickPosition[3][i] = worldCoords[i] / worldCoords[3];
+    }
+  
+  //  Compute the ray endpoints.  The ray is along the line running from
+  //  the camera position to the selection point, starting where this line
+  //  intersects the front clipping plane, and terminating where this
+  //  line intersects the back clipping plane.
+  for (k=0; k < 4; k++) {
+    for (i=0; i<3; i++)
+      {
+       ray[k][i] = pickPosition[k][i] - cameraPos[i];
+      }
+  }
+  for (i=0; i<3; i++)
+    {
+      cameraDOP[i] = cameraFP[i] - cameraPos[i];
+    }
+
+  vtkMath::Normalize(cameraDOP);
+
+  for (k=0; k < 4; k++) {
+    if (( rayLength[k] = vtkMath::Dot(cameraDOP,ray[k])) == 0.0 ) 
+      {
+       vtkWarningMacro("Cannot process points");
+       return 0;
+      } 
+  }
+
+  clipRange = camera->GetClippingRange();
+
+  if ( camera->GetParallelProjection() )
+    {
+      for (k=0; k < 4; k++) {
+       tF = clipRange[0] - rayLength[k];
+       tB = clipRange[1] - rayLength[k];
+       for (i=0; i<3; i++) 
+         {
+           p1World[k][i] = pickPosition[k][i] + tF*cameraDOP[i];
+           p2World[k][i] = pickPosition[k][i] + tB*cameraDOP[i];
+         }
+       p1World[k][3] = p2World[k][3] = 1.0;
+      }
+    }
+  else
+    {
+      for (k=0; k < 4; k++) {
+       tF = clipRange[0] / rayLength[k];
+       tB = clipRange[1] / rayLength[k];
+       for (i=0; i<3; i++) 
+         {
+           p1World[k][i] = cameraPos[i] + tF*ray[k][i];
+           p2World[k][i] = cameraPos[i] + tB*ray[k][i];
+         }
+       p1World[k][3] = p2World[k][3] = 1.0;
+      }
+    }
+
+  // Compute the center points of ray rectangle
+  for (i=0; i<3; i++) {
+    c1[i] = c2[i] = 0;
+    for (k=0; k<4; k++) {
+      c1[i] += p1World[k][i];
+      c2[i] += p2World[k][i];
+    }
+    c1[i] = c1[i]/4;
+    c2[i] = c2[i]/4;
+  }
+  
+  // Compute the tolerance in world coordinates.  Do this by
+  // determining the world coordinates of the diagonal points of the
+  // window, computing the width of the window in world coordinates, and 
+  // multiplying by the tolerance.
+  //
+  viewport = renderer->GetViewport();
+  winSize = renderer->GetRenderWindow()->GetSize();
+  x = winSize[0] * viewport[0];
+  y = winSize[1] * viewport[1];
+  renderer->SetDisplayPoint(x, y, selectionZ1);
+  renderer->DisplayToWorld();
+  renderer->GetWorldPoint(windowLowerLeft);
+
+  x = winSize[0] * viewport[2];
+  y = winSize[1] * viewport[3];
+  renderer->SetDisplayPoint(x, y, selectionZ2);
+  renderer->DisplayToWorld();
+  renderer->GetWorldPoint(windowUpperRight);
+
+  for (tol=0.0,i=0; i<3; i++) 
+    {
+    tol += (windowUpperRight[i] - windowLowerLeft[i]) *
+      (windowUpperRight[i] - windowLowerLeft[i]);
+    }
+  
+  tol = sqrt (tol) * this->Tolerance;
+
+  //  Loop over all props.  Transform ray (defined from position of
+  //  camera to selection point) into coordinates of mapper (not
+  //  transformed to actors coordinates!  Reduces overall computation!!!).
+  //  Note that only vtkProp3D's can be picked by vtkPicker.
+  //
+  vtkPropCollection *props;
+  vtkProp *propCandidate;
+  if ( this->PickFromList ) 
+    {
+    props = this->GetPickList();
+    }
+  else 
+    {
+    props = renderer->GetProps();
+    }
+
+  vtkActor *actor;
+  vtkLODProp3D *prop3D;
+  vtkVolume *volume;
+  vtkAssemblyPath *path;
+  vtkProperty *tempProperty;
+  this->Transform->PostMultiply();
+  for ( props->InitTraversal(); (prop=props->GetNextProp()); )
+    {
+    for ( prop->InitPathTraversal(); (path=prop->GetNextPath()); )
+      {
+      pickable = 0;
+      actor = NULL;
+      propCandidate = path->GetLastNode()->GetProp();
+      if ( propCandidate->GetPickable() && propCandidate->GetVisibility() )
+        {
+        pickable = 1;
+        if ( (actor=vtkActor::SafeDownCast(propCandidate)) != NULL )
+          {
+          mapper = actor->GetMapper();
+          if ( actor->GetProperty()->GetOpacity() <= 0.0 )
+            {
+            pickable = 0;
+            }
+          }
+        else if ( (prop3D=vtkLODProp3D::SafeDownCast(propCandidate)) != NULL )
+          {
+          LODId = prop3D->GetPickLODID();
+          mapper = prop3D->GetLODMapper(LODId);
+
+          // if the mapper is a vtkMapper (as opposed to a vtkVolumeMapper), 
+          // then check the transparency to see if the object is pickable
+          if ( vtkMapper::SafeDownCast(mapper) != NULL)
+            {
+            prop3D->GetLODProperty(LODId, &tempProperty);
+            if ( tempProperty->GetOpacity() <= 0.0 )
+              {
+              pickable = 0;
+              }
+            }
+          }
+        else if ( (volume=vtkVolume::SafeDownCast(propCandidate)) != NULL )
+          {
+          mapper = volume->GetMapper();
+          }
+        else
+          {
+          pickable = 0; //only vtkProp3D's (actors and volumes) can be picked
+          }
+        }
+      //  If actor can be picked, get its composite matrix, invert it, and
+      //  use the inverted matrix to transform the ray points into mapper
+      //  coordinates. 
+      if ( pickable  &&  mapper != NULL )
+        {
+        vtkMatrix4x4 *LastMatrix = path->GetLastNode()->GetMatrix();
+        if (LastMatrix == NULL)
+          {
+          vtkErrorMacro (<< "Pick: Null matrix.");
+          return 0;
+          }
+        this->Transform->SetMatrix(LastMatrix);
+        this->Transform->Push();
+        this->Transform->Inverse();
+
+       for (k=0; k < 4; k++) {
+         this->Transform->TransformPoint(p1World[k],p1Mapper[k]);
+         this->Transform->TransformPoint(p2World[k],p2Mapper[k]);
+
+         for (i=0; i<3; i++) 
+           {
+             ray[k][i] = p2Mapper[k][i] - p1Mapper[k][i];
+           }
+       }
+
+        this->Transform->Pop();
+
+        //  Have the ray endpoints in mapper space, now need to compare this
+        //  with the mapper bounds to see whether intersection is possible.
+        //
+        //  Get the bounding box of the modeller.  Note that the tolerance is
+        //  added to the bounding box to make sure things on the edge of the
+        //  bounding box are picked correctly.
+        mapper->GetBounds(bounds);
+        bounds[0] -= tol; bounds[1] += tol; 
+        bounds[2] -= tol; bounds[3] += tol; 
+        bounds[4] -= tol; bounds[5] += tol; 
+        if ( HitBBox(bounds, p1Mapper, ray) ) {
+         t = this->IntersectWithHex(p1Mapper, p2Mapper, tol, path, 
+                                    (vtkProp3D *)propCandidate, mapper);
+         if ( t >= 0.0 && t <= 1.0 /*t < VTK_LARGE_FLOAT*/ ) {
+           picked = 1;
+           this->Prop3Ds->AddItem((vtkProp3D *)prop);
+           this->PickedPositions->InsertNextPoint
+             ((1.0 - t)*c1[0] + t*c2[0],
+              (1.0 - t)*c1[1] + t*c2[1],
+              (1.0 - t)*c1[2] + t*c2[2]);
+           
+           // backwards compatibility: also add to this->Actors
+           if (actor) {
+             this->Actors->AddItem(actor);
+           }
+         }
+       }
+
+        }//if visible and pickable not transparent and has mapper
+      }//for all parts
+    }//for all actors
+  
+  // Invoke end pick method if defined
+  this->InvokeEvent(vtkCommand::EndPickEvent,NULL);
+  
+  return picked;
+}
+
+#define SIDE_LEFT 0
+#define SIDE_RIGHT 1
+#define SIDE_MIDDLE 2
+
+float GetParameterValue(float start, float end, float point)
+{
+  if (start == end) return -VTK_LARGE_FLOAT;
+  return (point-start)/(end-start);
+}
+
+void GetPointCoord(const float start[3], const float end[3], float t, float point[3])
+{
+  int i;
+  for (i = 0; i < 3; i++) {
+    point[i] = start[i] + t*(end[i]-start[i]);
+  }
+}
+
+char GetIntersectionPoint(const float start[3], const float end[3], 
+                         const int& index, const float p, float point[3])
+{
+  float t = GetParameterValue(start[index], end[index], p);
+  char result = 0;
+  if (t >= 0.0 && t <= 1.0) {
+    result = 1;
+    GetPointCoord(start, end, t, point);
+  }
+  return result;
+}
+
+//----------------------------------------------------------------------------
+char VTKViewer_RectPicker::HitBBox (float bounds[6], float origin[4][4], float dir[4][3])
+{
+  int i, j, k, n;
+  float endray[4][3];
+
+  for (k = 0; k < 4; k++) {
+    for (i = 0; i < 3; i++) {
+      endray[k][i] = origin[k][i] + dir[k][i];
+    }
+  }
+
+  // Compute hex bounding box, center point and center direction
+  float hbounds[6], center[3], ray[3];
+  for (i = 0; i < 3; i++) {
+    hbounds[2*i] = hbounds[2*i+1] = origin[0][i];
+    center[i] = ray[i] = 0;
+    for (k = 0; k < 4; k++) {
+      center[i] += origin[k][i];
+      ray[i] += endray[k][i];
+      if (origin[k][i] < hbounds[2*i]) {
+       hbounds[2*i] = origin[k][i];
+      }
+      else if (origin[k][i] > hbounds[2*i+1])
+       hbounds[2*i+1] = origin[k][i];
+      if (endray[k][i] < hbounds[2*i])
+       hbounds[2*i] = endray[k][i];
+      else if (endray[k][i] > hbounds[2*i+1])
+       hbounds[2*i+1] = endray[k][i];
+    }
+    center[i] = center[i]/4;
+    ray[i] = ray[i]/4;
+    ray[i] = ray[i] - center[i];
+  }
+
+  // Check for intersection between bouning boxes
+  for (i = 0; i < 3; i++) {
+    if (bounds[2*i+1] < hbounds[2*i] || bounds[2*i] > hbounds[2*i+1])
+      return 0;
+  }
+
+  // Check if one of the origin point lays inside bbox
+  char inside;
+  for (k = 0; k < 4; k++) {
+    inside = 1;
+    for (i = 0; i < 3; i++) {
+      if (origin[k][i] < bounds[2*i] || origin[k][i] > bounds[2*i+1]) {
+       inside = 0;
+       break;
+      }
+    }
+    if (inside) return 1;
+  }
+
+  // Find the closest coord plane for the center point
+  char side[3];
+  float coordPlane[3];
+  inside = 1;
+  for (i = 0; i < 3; i++) {
+    if (center[i] < bounds[2*i]) {
+      inside = 0;
+      coordPlane[i] = bounds[2*i];
+      side[i] = SIDE_LEFT;
+    }
+    else if (center[i] > bounds[2*i+1]) {
+      inside = 0;
+      coordPlane[i] = bounds[2*i+1];
+      side[i] = SIDE_RIGHT;
+    }
+    else {
+      coordPlane[i] = (ray[i]<0.0) ? bounds[2*i] : bounds[2*i+1];
+      side[i] = SIDE_MIDDLE;
+    }
+  }
+  if (inside) return 1;
+
+  // Calculate parametric distances to the planes and find the max
+  float maxT[3];
+  int whichPlane = 0;
+  char defined = 0;
+  for (i = 0; i < 3; i++) {
+    if (side[i] != SIDE_MIDDLE && ray[i] != 0.0) {
+      maxT[i] = (coordPlane[i]-center[i])/ray[i];
+      defined = 1;
+    }
+    else
+      maxT[i] = -1.0;
+  }
+  for (i = 0; i < 3; i++) {
+    if (maxT[whichPlane] < maxT[i])
+      whichPlane = i;
+  }
+
+  // Check for intersection along the center ray
+  float coord;
+  if (maxT[whichPlane] <= 1.0 && maxT[whichPlane] >= 0.0) {
+    inside = 1;
+    for (i = 0; i < 3; i++) {
+      if (i != whichPlane) {
+       coord = center[i] + maxT[whichPlane]*ray[i];
+       if (coord < bounds[2*i] || coord > bounds[2*i+1])
+         inside = 0;
+      }
+    }
+    if (inside) return 1;
+  }
+
+  // Define the intersection plane
+  if (!defined) {
+    for (i = 0; i < 3; i++) {
+      if (ray[i] != 0.0) {
+       maxT[i] = (coordPlane[i]-center[i])/ray[i];
+      }
+      else 
+       maxT[i] = VTK_LARGE_FLOAT;
+    }
+    for (i = 0; i < 3; i++) {
+      if (maxT[whichPlane] > maxT[i])
+       whichPlane = i;
+    }
+  }
+
+  // Compute the intersection between hex and coord plane
+  float t[4];
+  for (k = 0; k < 4; k++) {
+    if (dir[k][whichPlane] != 0.0) {
+      t[k] = (coordPlane[whichPlane]-origin[k][whichPlane])/dir[k][whichPlane];
+    }
+    else {
+      t[k] = VTK_LARGE_FLOAT;
+    }
+  }
+
+  vtkPoints* aPoints = vtkPoints::New();
+  float p[3], q[3], t1;
+  for (k = 0; k < 4; k++) {
+    n = (k+1)%4; // next point
+    if (t[k] > 1.0) {
+      if (t[n] < 1.0) {
+       // find intersection point
+       t1 = GetParameterValue(endray[k][whichPlane], endray[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(endray[k], endray[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+      if (t[n] < 0.0) {
+       // find second intersection point
+       t1 = GetParameterValue(origin[k][whichPlane], origin[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(origin[k], origin[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+    }
+    else if (t[k] < 0.0) {
+      if (t[n] > 0.0) {
+       // find intersection point
+       t1 = GetParameterValue(origin[k][whichPlane], origin[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(origin[k], origin[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+    }
+    else {
+      // find intersection point
+      GetPointCoord(origin[k], endray[k], t[k], p);
+      aPoints->InsertNextPoint(p[0], p[1], p[2]);
+
+      if (t[n] < 0.0) {
+       // find second intersection point
+       t1 = GetParameterValue(origin[k][whichPlane], origin[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(origin[k], origin[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+      else if (t[n] > 1.0) {
+       // find second intersection point
+       t1 = GetParameterValue(endray[k][whichPlane], endray[n][whichPlane], coordPlane[whichPlane]);
+       if (t1 > 0.0 && t1 < 1.0) {
+         GetPointCoord(endray[k], endray[n], t1, p);
+         aPoints->InsertNextPoint(p[0], p[1], p[2]);
+       }
+      }
+    }
+  }
+  n = aPoints->GetNumberOfPoints();
+  if (n == 0) {
+    aPoints->Delete();
+    return 0;
+  }
+
+  if (n == 1) {
+    aPoints->GetPoint(0, p);
+    inside = 1;
+    for (i = 0; i < 3; i++) {
+      if (i != whichPlane) {
+       if (p[i] < bounds[2*i] || p[i] > bounds[2*i+1]) {
+         inside = 0; break;
+       }
+      }
+    }
+    aPoints->Delete();
+    return inside;
+  }
+
+  // Analize intersection
+  int nearPlane, boundPlane = -1;
+  float boundCoord, boundMin, boundMax;
+  char intersect = 0;
+  for (k = 0; k < n; k++) {
+    aPoints->GetPoint(k, p);
+    j = k+1; if (j == n) j = 0;
+    aPoints->GetPoint(j, q);
+    inside = 1;
+    nearPlane = 0;
+    // if the point is inside bbox
+    for (i = 0; i < 3; i++) {
+      if (i != whichPlane) {
+       if (p[i] < bounds[2*i]) {
+         side[i] = SIDE_LEFT;
+         maxT[i] = GetParameterValue(p[i], q[i], bounds[2*i]);
+         inside = 0; 
+       }
+       else if (p[i] > bounds[2*i+1]) {
+         side[i] = SIDE_RIGHT;
+         maxT[i] = GetParameterValue(p[i], q[i], bounds[2*i+1]);
+         inside = 0; 
+       }
+       else {
+         side[i] = SIDE_MIDDLE;
+         maxT[i] = -1.0;
+       }
+      }
+      else maxT[i] = -1.0;
+      if (maxT[i] > maxT[nearPlane]) nearPlane = i;
+    }
+    if (inside) break;
+    // if segment intersects bbox
+    if (maxT[nearPlane] >= 0.0 && maxT[nearPlane] <= 1.0) {
+      for (i = 0; i < 3; i++) {
+       if (i != whichPlane && i != nearPlane) {
+         coord = p[i] + maxT[nearPlane]*(q[i]-p[i]);
+         if (coord >= bounds[2*i] && coord <= bounds[2*i+1]) {
+           intersect = 1; break;
+         }
+       }
+      }
+      // intersect with boundPlane
+      if (boundPlane == -1) {
+       boundCoord = p[nearPlane] + maxT[nearPlane]*(q[nearPlane]-p[nearPlane]);
+       boundPlane = nearPlane;
+       for (i = 0; i < 3; i++) {
+         if (i != whichPlane && i != boundPlane) {
+           coord = p[i] + maxT[nearPlane]*(q[i]-p[i]);
+           boundMin = boundMax = coord;
+         }
+       }
+      }
+      else {
+       t1 = GetParameterValue(p[boundPlane], q[boundPlane], boundCoord);
+       if (t1 >= 0.0 && t1 <= 1.0) {
+         for (i = 0; i < 3; i++) {
+           if (i != whichPlane && i != boundPlane) {
+             coord = p[i] + t1*(q[i]-p[i]);
+             if (coord < boundMin) boundMin = coord;
+             if (coord > boundMax) boundMax = coord;
+           }
+         }
+       }
+      }
+    }
+    if (intersect) break;
+  }
+  aPoints->Delete();
+  if (inside || intersect) {
+    return 1;
+  }
+
+  inside = 1;
+  for (i = 0; i < 3; i++) {
+    if (i != whichPlane && i != boundPlane) {
+      if (boundMin > bounds[2*i+1] || boundMax < bounds[2*i])
+       inside = 0;
+    }
+  }
+
+  return inside;
+}
+
+//----------------------------------------------------------------------------
+char VTKViewer_RectPicker::PointInside (float p[3], float p1[4][4], float p2[4][4], float tol)
+{
+  int i, j, k;
+  float t, coord[3];
+
+  // Fix one coordinate (x, for example) and 
+  // compute intersection with coordinate plane
+  vtkPoints* aPoints = vtkPoints::New();
+  int mode = 0;
+  for (k = 0; k < 4; k++) {
+    j = k+1; if (j == 4) j = 0;
+    switch (mode) {
+    case 0:
+      if (GetIntersectionPoint(p1[k], p1[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 0;
+      }
+      if (GetIntersectionPoint(p1[k], p2[k], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 1;
+      }
+      if (GetIntersectionPoint(p2[k], p2[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 2;
+      }
+      /*
+      if ((p1[k][0]-p[0])*(p2[k][0]-p[0]) <= 0) {
+       t = GetParameterValue(p1[k][0], p2[k][0], p[0]);
+       if (t >= 0.0 && t <= 1.0) {
+         GetPointCoord(p1[k], p2[k], t, coord);
+         aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       }
+      }
+      */
+      break;
+    case 1:
+      if (GetIntersectionPoint(p1[k], p2[k], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 1;
+      }
+      if (GetIntersectionPoint(p2[k], p2[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 2;
+      }
+      if (GetIntersectionPoint(p1[k], p1[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 0;
+      }
+      /*
+      if ((p1[k][0]-p[0])*(p1[j][0]-p[0]) <= 0) {
+       t = GetParameterValue(p1[k][0], p1[j][0], p[0]);
+       if (t > 0.0 && t < 1.0) {
+         GetPointCoord(p1[k], p1[j], t, coord);
+         aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       }
+      }
+      */
+      break;
+    case 2:
+      if (GetIntersectionPoint(p2[k], p2[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 2;
+      }
+      if (GetIntersectionPoint(p1[k], p2[k], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 1;
+      }
+      if (GetIntersectionPoint(p1[k], p1[j], 0, p[0], coord)) {
+       aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       mode = 0;
+      }
+      /*
+      if ((p2[k][0]-p[0])*(p2[j][0]-p[0]) <= 0) {
+       t = GetParameterValue(p2[k][0], p2[j][0], p[0]);
+       if (t > 0.0 && t < 1.0) {
+         GetPointCoord(p2[k], p2[j], t, coord);
+         aPoints->InsertNextPoint(coord[0], coord[1], coord[2]);
+       }
+      }
+      */
+      break;
+    }
+  }
+  int n = aPoints->GetNumberOfPoints();
+  //cout << "---> Points in X projection " << n << endl;
+  if (n == 0) {
+    aPoints->Delete();
+    return 0;
+  }
+
+  // Fix the second coord and define bounds
+  float zMin = VTK_LARGE_FLOAT, zMax = -VTK_LARGE_FLOAT, z, ncoord[3];
+  char inside = 0;
+  for (k = 0; k < n; k++) {
+    aPoints->GetPoint(k, coord);
+    //cout << "  P" << k << " (" << coord[0] << ", " << coord[1] << ", " << coord[2] << ")";
+    j = k+1; if (j == n) j = 0;
+    if (j == k) {
+      if (p[1] == coord[1] && p[2] == coord[2]) {
+       inside = 1;
+      }
+      break;
+    }
+    aPoints->GetPoint(j, ncoord);
+    t = GetParameterValue(coord[1], ncoord[1], p[1]);
+    if (t >= 0.0 && t <= 1) {
+      z = coord[2] + t*(ncoord[2]-coord[2]);
+      if (z < zMin) zMin = z;
+      if (z > zMax) zMax = z;
+    }
+  }
+  //cout << endl << " Zmin = " << zMin << ", Zmax = " << zMax  << endl;
+  if (!inside) {
+    if (p[2] <= (zMax+tol) && p[2] >= (zMin-tol))
+      inside = 1;
+  }
+  
+  aPoints->Delete();
+  return inside;
+}
+
+//----------------------------------------------------------------------------
+float VTKViewer_RectPicker::IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                                            vtkAssemblyPath *path, vtkProp3D *prop3D, 
+                                            vtkAbstractMapper3D *mapper)
+{
+  int i, k;
+  float *center, p0[3], ray[3], rayFactor, t;
+
+  // Get the data from the modeler
+  //
+  center = mapper->GetCenter();
+
+  if (!PointInside(center, p1, p2)) {
+    return 2.0;
+  }
+
+  //   Determine appropriate info
+  //
+  for (i = 0; i < 3; i++) {
+    p0[i] = ray[i] = 0;
+    for (k = 0; k < 4; k++) {
+      p0[i] += p1[k][i];
+      ray[i] += p2[k][i];
+    }
+    p0[i] = p0[i]/4;
+    ray[i] = ray[i]/4;
+    ray[i] = ray[i] - p0[i];
+  }
+  if (( rayFactor = vtkMath::Dot(ray,ray)) == 0.0 ) {
+    vtkErrorMacro("Cannot process points");
+    return 2.0;
+  }
+
+  // Project the center point onto the ray and determine its parametric value
+  //
+  t = (ray[0]*(center[0]-p0[0]) + ray[1]*(center[1]-p0[1])
+       + ray[2]*(center[2]-p0[2])) / rayFactor;
+
+  if ( t >= 0.0 && t <= 1.0 && t < this->GlobalTMin ) {
+    this->MarkPicked(path, prop3D, mapper, t, center);
+  }
+  return t;
+}
diff --git a/src/VTKViewer/VTKViewer_RectPicker.h b/src/VTKViewer/VTKViewer_RectPicker.h
new file mode 100644 (file)
index 0000000..44b7e07
--- /dev/null
@@ -0,0 +1,84 @@
+//  SALOME VTKViewer : build VTK viewer into Salome desktop
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : VTKViewer_RectPicker.h
+//  Author : Natalia KOPNOVA
+//  Module : SALOME
+
+#ifndef __VTKViewer_RectPicker_h
+#define __VTKViewer_RectPicker_h
+
+#include <vtkPicker.h>
+
+class VTK_EXPORT VTKViewer_RectPicker : public vtkPicker
+{
+public:
+  static VTKViewer_RectPicker *New();
+  vtkTypeMacro(VTKViewer_RectPicker,vtkPicker);
+  
+  // Description:
+  // Perform pick operation with selection rectangle provided. Normally the 
+  // first two values for the selection top-left and right-bottom points are 
+  // x-y pixel coordinate, and the third value is =0. 
+  // Return non-zero if something was successfully picked.
+  virtual int Pick(float selectionX1, float selectionY1, float selectionZ1, 
+                  float selectionX2, float selectionY2, float selectionZ2,
+                   vtkRenderer *renderer);  
+
+  // Description: 
+  // Perform pick operation with selection rectangle provided. Normally the first
+  // two values for the selection top-left and right-bottom points are x-y pixel 
+  // coordinate, and the third value is =0. 
+  // Return non-zero if something was successfully picked.
+  int Pick(float selectionPt1[3], float selectionPt2[3], vtkRenderer *ren)
+    {return this->Pick(selectionPt1[0], selectionPt1[1], selectionPt1[2], 
+                      selectionPt2[0], selectionPt2[1], selectionPt2[2],
+                      ren);};
+
+  // Description:
+  // Bounding box intersection with hexahedron. The method returns a non-zero value 
+  // if the bounding box is hit. Origin[4][4] starts the ray from corner points, 
+  // dir[4][3] is the vector components of the ray in the x-y-z directions. 
+  // (Notes: the intersection ray dir[4][3] is NOT normalized.)
+  static char HitBBox(float bounds[6], float origin[4][4], float dir[4][3]);
+
+  // Description:
+  // Position of point relative to hexahedron. The method returns a non-zero value 
+  // if the point is inside. p1[4][4] is the corner points of top face, 
+  // p2[4][4] is the corner points of bottom face. 
+  static char PointInside(float point[3], float p1[4][4], float p2[4][4], float tol=0);
+
+protected:
+  VTKViewer_RectPicker();
+  ~VTKViewer_RectPicker() {};
+
+  virtual float IntersectWithHex(float p1[4][4], float p2[4][4], float tol, 
+                          vtkAssemblyPath *path, vtkProp3D *p, 
+                          vtkAbstractMapper3D *m);
+
+private:
+};
+
+#endif
+
+