From: yfr Date: Thu, 17 Jun 2004 11:20:15 +0000 (+0000) Subject: DCQ : Merge with Ecole_ete_a6. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5d46b01483b55dcc4a43955443a8a58494e72229;p=modules%2Fyacs.git DCQ : Merge with Ecole_ete_a6. --- diff --git a/src/Event/Makefile.in b/src/Event/Makefile.in new file mode 100644 index 000000000..426af6888 --- /dev/null +++ b/src/Event/Makefile.in @@ -0,0 +1,52 @@ +# SALOME Utils : general SALOME's definitions and tools +# +# 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 +# Author : Marc Tajchman (CEA) +# Module : SALOME +# $Header$ + +top_srcdir=@top_srcdir@ +top_builddir=../.. +srcdir=@srcdir@ +VPATH=.:@srcdir@:@top_srcdir@/idl + + +@COMMENCE@ + +# header files +EXPORT_HEADERS= \ + SALOME_Event.hxx + +EXPORT_PYSCRIPTS = +# Libraries targets + +LIB = libEvent.la +LIB_SRC = SALOME_Event.cxx + +CPPFLAGS+=$(QT_INCLUDES) +LDFLAGS+=$(QT_MT_LIBS) + +@CONCLUDE@ + + diff --git a/src/Event/SALOME_Event.cxx b/src/Event/SALOME_Event.cxx new file mode 100644 index 000000000..dfebd7b02 --- /dev/null +++ b/src/Event/SALOME_Event.cxx @@ -0,0 +1,140 @@ +// KERNEL SALOME_Event : Define event posting mechanism +// +// 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_Event.cxx +// Author : Sergey ANIKIN +// Module : KERNEL +// $Header$ + +#include "SALOME_Event.hxx" + +#include "utilities.h" + +#include +#include +#include + +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif + +//=========================================================== +/*! + * SALOME_Event::SALOME_Event + * Constructor + */ +//=========================================================== +SALOME_Event::SALOME_Event(): + myWait( true ), + myAutoRelease( false ) +{ + if(MYDEBUG) MESSAGE( "SALOME_Event::SALOME_Event(): this = "<operator+=( mySemaphore->total() ); + } + } + if(MYDEBUG) MESSAGE( "SALOME_Event::processed() COMPLETED: this = "<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 = "<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() = "<GetName(); + med_int aNbAttr = aFamilyInfo->GetNbAttr(); + med_int aNbGroup = aFamilyInfo->GetNbGroup(); + BEGMSG("aFamilyName = '"<GetGroupName(iGroup); + MED::PrefixPrinter aPrefixPrinter; + BEGMSG("aGroupName = '"<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 = '"<second; + TFamilyGroup::const_iterator anFamIter = aFamilyGroup.begin(); + for(; anFamIter != aFamilyGroup.end(); anFamIter++){ + const PFamilyInfo& aFamilyInfo = *anFamIter; + MED::PrefixPrinter aPrefixPrinter; + BEGMSG("aFamilyName = '"<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() = "<GetNbComp(); + string aName = aFieldInfo->GetName(); + MED::PrefixPrinter aPrefixPrinter; + if(MYDEBUG) BEGMSG("aFieldName = '"<GetNbGauss(); + MED::PrefixPrinter aPrefixPrinter; + if(MYDEBUG) BEGMSG("aDt = "<GetDt()<<", "<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 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 TFamilyIdSet; + typedef map TFamilyIdByEntity; + TFamilyIdByEntity aFamilyIdByEntity; + + if(theNodeInfo!=0){ + 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 = "<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 = '"<GetName()<< + "' anId = "<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 index 000000000..326da0d5d --- /dev/null +++ b/src/MEDWrapper/MEDA_Algorithm.hxx @@ -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 + +namespace MEDA{ + using namespace std; + using namespace boost; + + + //--------------------------------------------------------------- + typedef set TCellSet; + typedef map TCellGroup; + + TCellGroup GetCellsByEntity(TWrapper& theWrapper, + const PMeshInfo& theMeshInfo, + const MED::TEntityInfo theEntityInfo); + + + //--------------------------------------------------------------- + typedef set TFamilyGroup; + + TFamilyGroup GetFamilies(TWrapper& theWrapper, + const PMeshInfo& theMeshInfo); + + + //--------------------------------------------------------------- + typedef map TFamilyByEntity; + + TFamilyByEntity GetFamiliesByEntity(TWrapper& theWrapper, + const PNodeInfo& theNodeInfo, + const TCellGroup& theCellGroup, + const TFamilyGroup& theFamilyGroup); + + + //--------------------------------------------------------------- + typedef map TGroupInfo; + + TGroupInfo GetFamiliesByGroup(const TFamilyGroup& theGroupInfo); + + + //--------------------------------------------------------------- + typedef set TTimeStampSet; + typedef map TTimeStampGroup; + + TTimeStampGroup GetFieldsByEntity(TWrapper& theWrapper, + const PMeshInfo& theMeshInfo, + const MED::TEntityInfo theEntityInfo); + + + //--------------------------------------------------------------- + typedef map 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 index 000000000..eb10c07b5 --- /dev/null +++ b/src/MEDWrapper/MEDA_Structures.cxx @@ -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 = "<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 = "<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 = "<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 = "<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 index 000000000..674600a00 --- /dev/null +++ b/src/MEDWrapper/MEDA_Structures.hxx @@ -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 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 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 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 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 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 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 PTimeStampVal; + +}; + +#endif diff --git a/src/MEDWrapper/MEDA_Test.cxx b/src/MEDWrapper/MEDA_Test.cxx new file mode 100644 index 000000000..396dd1dc5 --- /dev/null +++ b/src/MEDWrapper/MEDA_Test.cxx @@ -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() = "<GetDim(); + PMeshInfo aMeshInfoW = TWrapper::CrMeshInfo(aMeshInfo); + aName = aMeshInfoW->GetName(); + cout<<"GetMeshInfo - aName = '"<SetGroupName(iGroup,aName); + } + aMedW.SetFamilyInfo(aFamilyInfoW); + } + + MED::TEntityInfo aEntityInfo = aMed.GetEntityInfo(aMeshInfo); + cout<<"GetEntityInfo - aNbEntities = "<first; + cout<<"\tanEntity = "<GetNbElem(); + cout<<"\tGetNodeInfo - aNbNodes = "<GetNodeCoord(iNode,iDim)<<","; + } + cout<<" "; + } + cout<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 = "<GetConnDim(); + for(int iConn = 0; iConn < iConnEnd; iConn++){ + //cout<GetConn(iElem,iConn)<<","; + } + cout<<" "; + } + cout<SetName(aName); + aMedW.SetFieldInfo(aFieldInfoW); + MED::TGeom aTGeom; + med_entite_maillage anEntity; + med_int aNbTimeStamps = aMed.GetNbTimeStamps(aFieldInfo,aEntityInfo,anEntity,aTGeom); + cout<<"anEntity = "<GetUnitDt()<first; + med_int aNbElem = anTGeomIter->second; + cout<<"\t\taGeom = "<GetVal(aGeom,iElem,j,k)<<","; + } + } + cout<<" "; + } + cout<<"\n"; + } + aMedW.SetTimeStamp(aTimeStampValW); + } + } + } + cout<<"OK"< 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"< 1) + ReadMed(argv[1]); + return 0; + }catch(std::exception& exc){ + cout<<"Follow exception was accured :\n"<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 = '"<GetName()<<"'; aDim = "<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 = '"<GetName()<<"'; anId = "<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 index 000000000..e135e214c --- /dev/null +++ b/src/MEDWrapper/MEDA_Wrapper.hxx @@ -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 index 000000000..0afa3b4cc --- /dev/null +++ b/src/MEDWrapper/MED_Common.hxx @@ -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 +#include +#include +#include + +extern "C"{ +#include +} + +#include + +namespace MED{ + using namespace std; + using namespace boost; + + typedef vector TFloatVector; + typedef vector TStringVector; + typedef vector TIntVector; + typedef set TStringSet; + + typedef map TGeom; + typedef map TEntityInfo; + + med_int GetNbConn(med_entite_maillage theMedEntity, + med_geometrie_element theMedType, + med_int theMeshDim); + + struct TNameInfo; + typedef shared_ptr PNameInfo; + + struct TMeshInfo; + typedef shared_ptr PMeshInfo; + + struct TFamilyInfo; + typedef shared_ptr PFamilyInfo; + + struct TElemInfo; + typedef shared_ptr PElemInfo; + + struct TNodeInfo; + typedef shared_ptr PNodeInfo; + + struct TCellInfo; + typedef shared_ptr PCellInfo; + + struct TFieldInfo; + typedef shared_ptr PFieldInfo; + + struct TTimeStampInfo; + typedef shared_ptr PTimeStampInfo; + + struct TTimeStampVal; + typedef shared_ptr PTimeStampVal; + + class TWrapper; + typedef shared_ptr PWrapper; +}; + + +#endif diff --git a/src/MEDWrapper/MED_Structures.cxx b/src/MEDWrapper/MED_Structures.cxx new file mode 100644 index 000000000..6b940e7c6 --- /dev/null +++ b/src/MEDWrapper/MED_Structures.cxx @@ -0,0 +1,382 @@ +// 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" +#include +using namespace std; +using namespace MED; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#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 =="< 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++){ +#if defined __GNUC_2__ + const string& aVal = theCoordNames[anId]; +#else + const string& aVal = theCoordNames.at(anId); +#endif + + SetCoordName(anId,aVal); + } + + for(med_int anId = 0; anId < theMeshInfo->myDim; anId++){ +#if defined __GNUC_2__ + const string& aVal = theCoordUnits[anId]; +#else + const string& aVal = theCoordUnits.at(anId); +#endif + 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 index 000000000..727e83c34 --- /dev/null +++ b/src/MEDWrapper/MED_Structures.hxx @@ -0,0 +1,243 @@ +// 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 + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif + +#if defined __GNUC_2__ +#include +#endif +#include + +#include "MED_Common.hxx" + +namespace MED{ + using namespace std; + using namespace boost; + +//--------------------------------------------------------------- +#if defined __GNUC_2__ + typedef vector TString; +#else + typedef valarray TString; +#endif + + 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 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 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 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 TValue; + typedef map 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 index 000000000..b227bc110 --- /dev/null +++ b/src/MEDWrapper/MED_Test.cxx @@ -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() = "<myDim; + aName = aMeshInfo->GetName(); + cout<<"GetMeshInfo - aName = '"<SetGroupName(iGroup,aName); + } + + aMedW.SetFamilyInfo(*aFamilyInfo); + } + + cout<<"GetEntityInfo - aNbEntities = "<first; + cout<<"\tanEntity = "<myCoord; + for(int iNode = 0; iNode < aNbNodes; iNode++){ + for(int iDim = 0, anId = iNode*aDim; iDim < aDim; iDim++, anId++){ + //cout<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 = "<myNbElem; iElem++){ + int i = iElem*aCellInfo->myConnDim; + for(int iConn = 0; iConn < aCellInfo->myConnDim; iConn++, i++){ + //cout<myConn[i]<<","; + } + //cout<<" "; + } + cout<myMeshInfo = aNewMeshInfo; + aMedW.SetCellInfo(*aCellInfo); + } + } + + } + cout<<"OK"< 1) + ReadMed(argv[1]); + return 0; + }catch(std::exception& exc){ + cout<<"Follow exception was accured :\n"< +#include +#include +#include + + +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__<<"]::"<(theInfo); + ret = MEDmaaCr(myFile.Id(), + &anInfo.myName[0], + anInfo.myDim); + }catch(...){} + if(ret < 0){ + TFileWrapper aFileWrapper(myFile,MED_REMP); + + TMeshInfo& anInfo = const_cast(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(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(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(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(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(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(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(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(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(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(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(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& 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 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 == "<first; + med_int aNbVal = MEDnVal(anId,&aFieldInfo.myName[0],anEntity,aGeom, + aTimeStampInfo.myNumDt,aTimeStampInfo.myNumOrd); + if(aNbVal <= 0) + EXCEPTION(runtime_error,"GetTimeStampInfo - MEDnVal(...) - aNbVal == "< +} +#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 index 000000000..71cbd7cbd --- /dev/null +++ b/src/MEDWrapper/Makefile.in @@ -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/SALOME_PY/SalomePy.cxx b/src/SALOME_PY/SalomePy.cxx index 76e643d9f..017c54647 100644 --- a/src/SALOME_PY/SalomePy.cxx +++ b/src/SALOME_PY/SalomePy.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +using namespace std; #include #include #include @@ -37,7 +38,6 @@ #include "QAD_Application.h" #include "QAD_Desktop.h" #include "VTKViewer_ViewFrame.h" -using namespace std; extern "C" { @@ -125,7 +125,7 @@ void initlibSalomePy() if ((viewId >=0) && (viewId getStudyFrame(viewId)->getRightFrame()->getViewFrame())->getRenderer(); } - if (renderer == NULL) INFOS("No VTK Renderer available !"); + if (renderer == NULL) MESSAGE("No VTK Renderer available !"); //san:T3.13 - move getRenderer() implementation here MESSAGE("---"); diff --git a/src/SALOME_PYQT/Makefile.in b/src/SALOME_PYQT/Makefile.in index 06a168bd7..7c1de51a1 100644 --- a/src/SALOME_PYQT/Makefile.in +++ b/src/SALOME_PYQT/Makefile.in @@ -20,7 +20,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl # SIP C++ Python # SIP defined in make_commence.in -SIP_FLAGS = -t WS_X11 -t Qt_3_0_5 -s ".cc" -c $(CURDIR) $(PYQT_INCLUDES) +SIP_FLAGS = -t WS_X11 -t Qt_3_0_5 -s ".cc" -c $(CURDIR) -I $(PYQT_SIPS) # SIP input file(s) @@ -41,6 +41,7 @@ LIB = libSalomePyQtcmodule.la MOC_SRC = sipSalomePyQtProxySalomePyQt_moc.cxx LIB_SRC += SalomePyQt.cxx SALOME_PYQT_GUI.cxx $(SIP_SRC) $(MOC_SRC) +LIB_MOC = SALOME_PYQT_GUI.h #LIB_MOC += sipSalomePyQtProxySalomePyQt.h @@ -50,7 +51,7 @@ LIB_CLIENT_IDL = SALOME_Exception.idl CPPFLAGS+=$(QT_INCLUDES) $(PYTHON_INCLUDES) $(SIP_INCLUDES) $(OCC_INCLUDES) $(VTK_INCLUDES) $(OGL_INCLUDES) LIBS+= $(PYTHON_LIBS) $(SIP_LIBS) $(PYQT_LIBS) $(VTK_LIBS) $(OGL_LIBS) -LDFLAGS+= -lSalomeGUI +LDFLAGS+= -lSalomeGUI -lqtcmodule # Custom build step: generate C++ wrapping according to $(SIP_FILES) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx index f2a23e6a9..73e33fd05 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.cxx @@ -1,3 +1,4 @@ +using namespace std; //============================================================================= // File : SALOME_PYQT_GUI.cxx // Created : mer jun 4 17:17:20 UTC 2003 @@ -7,17 +8,14 @@ // $Header$ //============================================================================= -#include "SALOME_PYQT_GUI.hxx" +#include "SALOME_PYQT_GUI.h" #include "QAD_Desktop.h" -#include "QAD_MessageBox.h" #include "SALOME_Selection.h" #include "SALOME_InteractiveObject.hxx" #include "SALOMEGUI_QtCatchCorbaException.hxx" #include "utilities.h" -#include "PyInterp_PyQt.h" -//#include #include #include @@ -25,12 +23,9 @@ #include #include -using namespace std; static PyInterp_PyQt *interp = NULL; static map mapInterp; -static PyObject *module; -static string _moduleName; //============================================================================= /*! @@ -39,26 +34,43 @@ static string _moduleName; */ //============================================================================= -static void setWorkSpace() +void SALOME_PYQT_GUI::setWorkSpace() { MESSAGE("setWorkSpace"); - PyObject *res,*pyws; - - interp->enter(); - pyws=sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(), - sipClass_QWorkspace); - res=PyObject_CallMethod(module,"setWorkSpace","O",pyws); + PyLockWrapper aLock = interp->GetLockWrapper(); + + // Try to import qt module. If it's not possible don't go on + PyObjWrapper qtmodule(PyImport_ImportModule("qt")); + if(!qtmodule){ + PyErr_Print(); + return ; + } + + PyObjWrapper pyws(sipMapCppToSelf( QAD_Application::getDesktop()->getMainFrame(), + sipClass_QWorkspace)); + PyObjWrapper res(PyObject_CallMethod(_module,"setWorkSpace","O",pyws.get())); SCRUTE(pyws->ob_refcnt); - Py_DECREF(pyws); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return ; - } - Py_DECREF(res); - interp->quit(); - return ; + if(!res){ + PyErr_Print(); + return ; + } +} + +//============================================================================= +/*! + * Import Python module (from _moduleName) + */ +//============================================================================= +void SALOME_PYQT_GUI::importModule() +{ + PyLockWrapper aLock = interp->GetLockWrapper(); + + _module=PyImport_ImportModule((char*)_moduleName.c_str()); + if(!_module){ + MESSAGE ( " Problem... " ); + PyErr_Print(); + return; + } } //============================================================================= @@ -69,35 +81,47 @@ static void setWorkSpace() */ //============================================================================= -static void initInterp(int StudyID) +void SALOME_PYQT_GUI::initInterp(int StudyID) { - MESSAGE("initInterp"); - if (mapInterp.find(StudyID) != mapInterp.end()) - { - MESSAGE ( " StudyID is found " << StudyID ); - interp = mapInterp[StudyID]; - return; - } - else - { - MESSAGE ( " StudyID is not found " << StudyID ); - interp=new PyInterp_PyQt(); - mapInterp[StudyID] = interp; - } - - interp->enter(); - - module=PyImport_ImportModule((char*)_moduleName.c_str()); - if(module == NULL) - { - INFOS ( " Problem... " ); - PyErr_Print(); - interp->quit(); - return; - } - // PyQt import is OK - interp->quit(); + MESSAGE("SALOME_PYQT_GUI::initInterp"); + if(mapInterp.find(StudyID) != mapInterp.end()){ + MESSAGE ( "SALOME_PYQT_GUI::initInterp StudyID is found " << StudyID ); + interp = mapInterp[StudyID]; + return; + }else{ + MESSAGE ( "SALOME_PYQT_GUI::initInterp StudyID is not found " << StudyID ); + /* + * The creation of Python interpretor must be protected par a C++ Lock because of C threads + */ + ThreadLock aPyLock = GetPyThreadLock("SALOME_PYQT_GUI::initInterp"); + interp=new PyInterp_PyQt(); + mapInterp[StudyID] = interp; + } + // imports Python GUI module and puts it in _module attribute + importModule(); + // calls _module.setWorkspace and passes the SIP object main workspace setWorkSpace(); + +} + +//============================================================================= +/*! + * constructor : only calls SALOMEGUI constructor + */ +//============================================================================= +SALOME_PYQT_GUI::SALOME_PYQT_GUI( const QString& theName, QObject* theParent ) : + SALOMEGUI( theName, theParent ),_module(0) +{ + MESSAGE("SALOME_PYQT_GUI::SALOME_PYQT_GUI"); +} + +//============================================================================= +/*! + * destructor : do nothing + */ +//============================================================================= +SALOME_PYQT_GUI::~SALOME_PYQT_GUI() +{ } //============================================================================= @@ -110,18 +134,13 @@ bool SALOME_PYQT_GUI::OnGUIEvent (int theCommandID, QAD_Desktop* parent) { MESSAGE("SALOME_PYQT_GUI::OnGUIEvent"); - PyObject *res; - - interp->enter(); - res=PyObject_CallMethod(module,"OnGUIEvent","i",theCommandID); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return false; - } - Py_DECREF(res); - interp->quit(); + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(_module,"OnGUIEvent","i",theCommandID)); + if(!res){ + PyErr_Print(); + return false; + } return true; } @@ -163,8 +182,8 @@ bool SALOME_PYQT_GUI::OnMouseMove (QMouseEvent* pe , QAD_Desktop* parent, QAD_StudyFrame* studyFrame) { - // La ligne suivante est commentée sinon multiple traces ... - // MESSAGE("SALOME_PYQT_GUI::OnMouseMouve"); + // Commented out to avoid multiple traces ... + // MESSAGE("SALOME_PYQT_GUI::OnMouseMove"); return true; } @@ -178,23 +197,29 @@ bool SALOME_PYQT_GUI::OnMouseMove (QMouseEvent* pe , bool SALOME_PYQT_GUI::SetSettings (QAD_Desktop* parent, char* moduleName) { MESSAGE("SALOME_PYQT_GUI::SetSettings"); - PyObject *res; int StudyID = QAD_Application::getDesktop()->getActiveStudy()->getStudyId(); SCRUTE ( StudyID ); _moduleName = moduleName + string("GUI"); SCRUTE(_moduleName); + + // initializes one Python interpreter by study and puts it in interp global variable + // imports Python GUI module and puts it in _module attribute + // calls _module.setWorkspace and passes the SIP object main workspace initInterp(StudyID); - interp->enter(); - res=PyObject_CallMethod(module,"setSettings",""); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return false; - } - Py_DECREF(res); - interp->quit(); + PyLockWrapper aLock = interp->GetLockWrapper(); + + _module = PyImport_ImportModule((char*)_moduleName.c_str()); + if(!_module){ + PyErr_Print(); + return false; + } + + PyObjWrapper res(PyObject_CallMethod(_module,"setSettings","")); + if(!res){ + PyErr_Print(); + return false; + } return true; } @@ -218,25 +243,19 @@ bool SALOME_PYQT_GUI::CustomPopup ( QAD_Desktop* parent, MESSAGE ( " theParent : " << theParent.latin1() ); MESSAGE ( " theObject : " << theObject.latin1() ); - PyObject *res,*pypop; - interp->enter(); - pypop=sipMapCppToSelf( popup, - sipClass_QPopupMenu); - - res=PyObject_CallMethod(module,"customPopup","Osss",pypop, - theContext.latin1(), theObject.latin1(), theParent.latin1()); - Py_DECREF(pypop); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return false; - } - - Py_DECREF(res); - interp->quit(); + PyLockWrapper aLock = interp->GetLockWrapper(); + PyObjWrapper pypop(sipMapCppToSelf( popup, sipClass_QPopupMenu)); + PyObjWrapper res(PyObject_CallMethod(_module,"customPopup", + "Osss",pypop.get(), + theContext.latin1(), + theObject.latin1(), + theParent.latin1())); + if(!res){ + PyErr_Print(); + return false; + } return true; } @@ -253,36 +272,37 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, QString & theObject ) { MESSAGE("SALOME_PYQT_GUI::DefinePopup"); - theContext = ""; - theObject = ""; - theParent = ""; + //theContext = ""; + //theObject = ""; + //theParent = ""; - PyObject *res; - interp->enter(); - res=PyObject_CallMethod(module,"definePopup","sss", - theContext.latin1(), theObject.latin1(), theParent.latin1()); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return ; - } + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(_module,"definePopup","sss", + theContext.latin1(), + theObject.latin1(), + theParent.latin1())); + if(!res){ + PyErr_Print(); + return; + } char *co, *ob, *pa; - int parseOk = PyArg_ParseTuple(res, "sss", &co, &ob, &pa); + if(!PyArg_ParseTuple(res, "sss", &co, &ob, &pa)) + { + // It's not a valid tuple. Do nothing. + return; + } - MESSAGE ("parseOk " << parseOk); + MESSAGE ("parseOk "); MESSAGE (" --- " << co << " " << ob << " " << pa); theContext = co; theObject = ob; theParent = pa; - Py_DECREF(res); - interp->quit(); MESSAGE ( " theContext : " << theContext.latin1() ); MESSAGE ( " theParent : " << theParent.latin1() ); MESSAGE ( " theObject : " << theObject.latin1() ); - } //============================================================================= @@ -292,76 +312,64 @@ void SALOME_PYQT_GUI::DefinePopup( QString & theContext, */ //============================================================================= -void SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) +bool SALOME_PYQT_GUI::ActiveStudyChanged( QAD_Desktop* parent ) { - MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged"); - PyObject *res; int StudyID = parent->getActiveApp()->getActiveStudy()->getStudyId(); + MESSAGE("SALOME_PYQT_GUI::ActiveStudyChanged"<enter(); - res=PyObject_CallMethod(module,"activeStudyChanged","i", StudyID ); - if (res == NULL) - { - PyErr_Print(); - interp->quit(); - return ; - } - Py_DECREF(res); - interp->quit(); - return; + PyLockWrapper aLock = interp->GetLockWrapper(); + + PyObjWrapper res(PyObject_CallMethod(_module,"activeStudyChanged","i", StudyID )); + if(!res){ + PyErr_Print(); + return false; + } + return true; } +//============================================================================= +/*! + * no call to python module.BuildPresentation() (not yet ???) + */ +//============================================================================= +void SALOME_PYQT_GUI::BuildPresentation( const Handle(SALOME_InteractiveObject)& theIO ) +{ +} //============================================================================= /*! - * + * no call to python module.SupportedViewType() (not yet ???) */ //============================================================================= +void SALOME_PYQT_GUI::SupportedViewType(int* buffer, int bufferSize) +{ +} +//============================================================================= +/*! + * no call to python module.Deactivate() (not yet ???) + */ +//============================================================================= +void SALOME_PYQT_GUI::Deactivate() +{ +} + + + + +//============================================================================= +/*! + * Component GUI Factory : returns a new GUI obj at each call + */ +//============================================================================= extern "C" { - bool OnGUIEvent(int theCommandID, QAD_Desktop* parent) - { - return SALOME_PYQT_GUI::OnGUIEvent(theCommandID, parent); - } - - bool OnKeyPress(QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return SALOME_PYQT_GUI::OnKeyPress(pe, parent, studyFrame); - } - - bool OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return SALOME_PYQT_GUI::OnMousePress(pe, parent, studyFrame); - } - - bool OnMouseMove(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame) - { - return SALOME_PYQT_GUI::OnMouseMove(pe, parent, studyFrame); - } - - bool SetSettings(QAD_Desktop* parent, char* moduleName) - { - return SALOME_PYQT_GUI::SetSettings(parent, moduleName); - } - - bool customPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, - const QString & theParent, const QString & theObject) - { - return SALOME_PYQT_GUI::CustomPopup( parent, popup, theContext, theParent, theObject ); - } - - void definePopup(QString & theContext, QString & theParent, QString & theObject) - { - SALOME_PYQT_GUI::DefinePopup(theContext, theParent, theObject); - } - - void activeStudyChanged ( QAD_Desktop* parent ) - { - SALOME_PYQT_GUI::ActiveStudyChanged(parent); + Standard_EXPORT SALOMEGUI* GetComponentGUI() { + MESSAGE("SALOME_PYQT_GUI::GetComponentGUI"); + SALOMEGUI* aGUI = new SALOME_PYQT_GUI(""); + return aGUI; } } - diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.h b/src/SALOME_PYQT/SALOME_PYQT_GUI.h new file mode 100644 index 000000000..2e7617d5a --- /dev/null +++ b/src/SALOME_PYQT/SALOME_PYQT_GUI.h @@ -0,0 +1,52 @@ +//============================================================================= +// File : SALOME_PYQT_GUI.hxx +// Created : mer jun 4 17:17:20 UTC 2003 +// Author : Paul RASCLE, EDF +// Project : SALOME +// Copyright : EDF 2003 +// $Header$ +//============================================================================= + +#ifndef _SALOME_PYQT_GUI_HXX_ +#define _SALOME_PYQT_GUI_HXX_ + +#include "QAD_Desktop.h" +#include "PyInterp_PyQt.h" +#include "SALOMEGUI.h" + +class SALOME_PYQT_GUI: public SALOMEGUI +{ + Q_OBJECT; + +private: + // save the current Python module in the attribute _module + PyObjWrapper _module; + // save the current Python module name in the attribute _moduleName + string _moduleName; + +public: + + SALOME_PYQT_GUI( const QString& name = "", QObject* parent = 0 ); + virtual ~SALOME_PYQT_GUI(); + + virtual bool OnGUIEvent (int theCommandID, QAD_Desktop* parent); + virtual bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame); + virtual bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame); + virtual bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame); + virtual bool SetSettings ( QAD_Desktop* parent, char* moduleName ); + virtual bool CustomPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext, + const QString & theParent, const QString & theObject ); + virtual void DefinePopup ( QString & theContext, QString & theParent, QString & theObject ); + virtual bool ActiveStudyChanged( QAD_Desktop* parent); + virtual void BuildPresentation ( const Handle(SALOME_InteractiveObject)& theIO ); + virtual void SupportedViewType (int* buffer, int bufferSize); + virtual void Deactivate (); + void initInterp(int studyId); + void importModule(); + void setWorkSpace(); + +protected: + +}; + +#endif diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx b/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx deleted file mode 100644 index fe0f6ffb5..000000000 --- a/src/SALOME_PYQT/SALOME_PYQT_GUI.hxx +++ /dev/null @@ -1,43 +0,0 @@ -//============================================================================= -// File : SALOME_PYQT_GUI.hxx -// Created : mer jun 4 17:17:20 UTC 2003 -// Author : Paul RASCLE, EDF -// Project : SALOME -// Copyright : EDF 2003 -// $Header$ -//============================================================================= - -#ifndef _SALOME_PYQT_GUI_HXX_ -#define _SALOME_PYQT_GUI_HXX_ - -#include "QAD_Desktop.h" - -class SALOME_PYQT_GUI: public QObject -{ - Q_OBJECT - -private: - -public: - - static bool OnGUIEvent (int theCommandID, QAD_Desktop* parent); - static bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, - QAD_StudyFrame* studyFrame); - static bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, - QAD_StudyFrame* studyFrame); - static bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, - QAD_StudyFrame* studyFrame); - static bool SetSettings (QAD_Desktop* parent, char* moduleName); - static bool CustomPopup (QAD_Desktop* parent, QPopupMenu* popup, - const QString & theContext, - const QString & theParent, - const QString & theObject); - static void DefinePopup (QString & theContext, QString & theParent, - QString & theObject) ; - static void ActiveStudyChanged (QAD_Desktop* parent); - -protected: - -}; - -#endif diff --git a/src/SALOME_PYQT/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt.cxx index d6421eb31..11d2fe9ce 100644 --- a/src/SALOME_PYQT/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt.cxx @@ -5,6 +5,7 @@ // File : SalomePyQt.cxx // Module : SALOME +using namespace std; #include "SalomePyQt.hxx" #include "QAD_Application.h" @@ -14,7 +15,6 @@ #include "QAD_Config.h" #include "QAD_Settings.h" -using namespace std; QWidget* SalomePyQt::getDesktop() { diff --git a/src/SALOME_SWIG/Makefile.in b/src/SALOME_SWIG/Makefile.in index ddd2ccfbd..2a6f6933a 100644 --- a/src/SALOME_SWIG/Makefile.in +++ b/src/SALOME_SWIG/Makefile.in @@ -38,7 +38,7 @@ LIB = libSALOME_Swigcmodule.la LIB_SRC = SWIG_DEF = libSALOME_Swig.i -EXPORT_PYSCRIPTS = libSALOME_Swig.py Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py +EXPORT_PYSCRIPTS = libSALOME_Swig.py Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py test_remove_ref.py EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py diff --git a/src/SALOME_SWIG/batchmode_salome.py b/src/SALOME_SWIG/batchmode_salome.py index 463aff9be..7cf675756 100644 --- a/src/SALOME_SWIG/batchmode_salome.py +++ b/src/SALOME_SWIG/batchmode_salome.py @@ -57,14 +57,30 @@ class SalomeGUI(SALOMEGUI_Swig): #-------------------------------------------------------------------------- def IDToObject(id): + myObj = None mySO = myStudy.FindObjectID(id); - print id - Builder = myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR") - AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR) - myObj = orb.string_to_object(AtIOR.Value()) + if mySO is not None: + ok, anAttr = mySO.FindAttribute("AttributeIOR") + if ok: + AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR) + if AtIOR.Value() != "": + myObj = orb.string_to_object(AtIOR.Value()) return myObj +def ObjectToSObject(obj): + mySO = None + if obj is not None: + ior = orb.object_to_string(obj) + if ior != "": + mySO = myStudy.FindObjectIOR(ior) + return mySO + +def ObjectToID(obj): + mySO = ObjectToSObject(obj) + if mySO: + return mySO.GetID() + return "" + def IDToSObject(id): mySO = myStudy.FindObjectID(id); return mySO @@ -210,8 +226,13 @@ obj = naming_service.Resolve('myStudyManager') myStudyManager = obj._narrow(SALOMEDS.StudyManager) # create new study -myStudy = myStudyManager.NewStudy("Study1") - +aListOfOpenStudies = myStudyManager.GetOpenStudies(); +myStudy = None; +if len(aListOfOpenStudies) == 0 : + myStudy = myStudyManager.NewStudy("Study1") +else: + myStudy = aListOfOpenStudies[0] + myStudyName = myStudy._get_Name() myStudyId = myStudy._get_StudyId() diff --git a/src/SALOME_SWIG/salome.py b/src/SALOME_SWIG/salome.py index 92a99f11f..9d45865db 100644 --- a/src/SALOME_SWIG/salome.py +++ b/src/SALOME_SWIG/salome.py @@ -99,13 +99,30 @@ class SalomeGUI(SALOMEGUI_Swig): #-------------------------------------------------------------------------- def IDToObject(id): + myObj = None mySO = myStudy.FindObjectID(id); - Builder = myStudy.NewBuilder() - anAttr = Builder.FindOrCreateAttribute(mySO, "AttributeIOR") - AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR) - myObj = orb.string_to_object(AtIOR.Value()) + if mySO is not None: + ok, anAttr = mySO.FindAttribute("AttributeIOR") + if ok: + AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR) + if AtIOR.Value() != "": + myObj = orb.string_to_object(AtIOR.Value()) return myObj +def ObjectToSObject(obj): + mySO = None + if obj is not None: + ior = orb.object_to_string(obj) + if ior != "": + mySO = myStudy.FindObjectIOR(ior) + return mySO + +def ObjectToID(obj): + mySO = ObjectToSObject(obj) + if mySO: + return mySO.GetID() + return "" + def IDToSObject(id): mySO = myStudy.FindObjectID(id); return mySO diff --git a/src/SALOME_SWIG/salome_test.py b/src/SALOME_SWIG/salome_test.py index 31b7f308f..2a8196dc0 100644 --- a/src/SALOME_SWIG/salome_test.py +++ b/src/SALOME_SWIG/salome_test.py @@ -59,6 +59,8 @@ print print "============= Test SMESH =============================" print +import StdMeshers + comp = catalog.GetComponent("SMESH") if comp is None: raise RuntimeError,"Component SMESH not found in Module Catalog." @@ -68,11 +70,11 @@ if comp is None: raise RuntimeError,"Component MED not found in Module Catalog." import SMESH -import smeshpy geom = salome.lcc.FindOrLoadComponent("FactoryServer", "GEOM") myBuilder = salome.myStudy.NewBuilder() +smesh = salome.lcc.FindOrLoadComponent("FactoryServer", "SMESH") smeshgui = salome.ImportComponentGUI("SMESH") smeshgui.Init(salome.myStudyId); @@ -113,138 +115,107 @@ name = geompy.SubShapeName( edge._get_Name(), face._get_Name() ) print name idedge=geompy.addToStudyInFather(face,edge,name) -# ---- launch SMESH, init a Mesh with the box -gen=smeshpy.smeshpy() -mesh=gen.Init(idbox) -idmesh = smeshgui.AddNewMesh( salome.orb.object_to_string(mesh) ) -smeshgui.SetName(idmesh, "Meshbox"); -smeshgui.SetShape(idbox, idmesh); +# ---- SMESH # ---- create Hypothesis print "-------------------------- create Hypothesis" print "-------------------------- LocalLength" -hyp1=gen.CreateHypothesis("LocalLength") -hypLen1 = hyp1._narrow(SMESH.SMESH_LocalLength) +hypLen1 = smesh.CreateHypothesis( "LocalLength", "libStdMeshersEngine.so" ) hypLen1.SetLength(100) print hypLen1.GetName() print hypLen1.GetId() print hypLen1.GetLength() -idlength = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypLen1) ); -smeshgui.SetName(idlength, "Local_Length_100"); +smeshgui.SetName(salome.ObjectToID(hypLen1), "Local_Length_100") print "-------------------------- NumberOfSegments" -hyp2=gen.CreateHypothesis("NumberOfSegments") -hypNbSeg1=hyp2._narrow(SMESH.SMESH_NumberOfSegments) +hypNbSeg1= smesh.CreateHypothesis( "NumberOfSegments", "libStdMeshersEngine.so" ) hypNbSeg1.SetNumberOfSegments(7) print hypNbSeg1.GetName() print hypNbSeg1.GetId() print hypNbSeg1.GetNumberOfSegments() -idseg = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypNbSeg1) ); -smeshgui.SetName(idseg, "NumberOfSegments_7"); +smeshgui.SetName(salome.ObjectToID(hypNbSeg1), "NumberOfSegments_7") print "-------------------------- MaxElementArea" -hyp3=gen.CreateHypothesis("MaxElementArea") -hypArea1=hyp3._narrow(SMESH.SMESH_MaxElementArea) +hypArea1 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" ) hypArea1.SetMaxElementArea(2500) print hypArea1.GetName() print hypArea1.GetId() print hypArea1.GetMaxElementArea() -idarea1 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea1) ); -smeshgui.SetName(idarea1, "MaxElementArea_2500"); +smeshgui.SetName(salome.ObjectToID(hypArea1), "MaxElementArea_2500") print "-------------------------- MaxElementArea" -hyp3=gen.CreateHypothesis("MaxElementArea") -hypArea2=hyp3._narrow(SMESH.SMESH_MaxElementArea) +hypArea2 = smesh.CreateHypothesis( "MaxElementArea", "libStdMeshersEngine.so" ) hypArea2.SetMaxElementArea(500) print hypArea2.GetName() print hypArea2.GetId() print hypArea2.GetMaxElementArea() -idarea2 = smeshgui.AddNewHypothesis( salome.orb.object_to_string(hypArea2) ); -smeshgui.SetName(idarea2, "MaxElementArea_500"); +smeshgui.SetName(salome.ObjectToID(hypArea2), "MaxElementArea_500") print "-------------------------- Regular_1D" -alg1=gen.CreateHypothesis("Regular_1D") -algo1=alg1._narrow(SMESH.SMESH_Algo) -listHyp=algo1.GetCompatibleHypothesis() +algoReg = smesh.CreateHypothesis( "Regular_1D", "libStdMeshersEngine.so" ) +listHyp=algoReg.GetCompatibleHypothesis() for hyp in listHyp: print hyp -algoReg=alg1._narrow(SMESH.SMESH_Regular_1D) print algoReg.GetName() print algoReg.GetId() -idreg = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoReg) ); -smeshgui.SetName(idreg, "Regular_1D"); +smeshgui.SetName(salome.ObjectToID(algoReg), "Regular_1D" ) print "-------------------------- MEFISTO_2D" -alg2=gen.CreateHypothesis("MEFISTO_2D") -algo2=alg2._narrow(SMESH.SMESH_Algo) -listHyp=algo2.GetCompatibleHypothesis() +algoMef = smesh.CreateHypothesis( "MEFISTO_2D", "libStdMeshersEngine.so" ) +listHyp=algoMef.GetCompatibleHypothesis() for hyp in listHyp: print hyp -algoMef=alg2._narrow(SMESH.SMESH_MEFISTO_2D) print algoMef.GetName() print algoMef.GetId() -idmef = smeshgui.AddNewAlgorithms( salome.orb.object_to_string(algoMef) ); -smeshgui.SetName(idmef, "MEFISTO_2D"); +smeshgui.SetName(salome.ObjectToID(algoMef), "MEFISTO_2D" ) + +# ---- add hypothesis to box + +print "-------------------------- add hypothesis to box" +box=salome.IDToObject(idbox) +mesh = smesh.CreateMesh(box) + +smeshgui.SetName( salome.ObjectToID(mesh), "MeshBox" ); + +ret=mesh.AddHypothesis(box,algoReg) +print ret +ret=mesh.AddHypothesis(box,algoMef) +print ret + + +ret=mesh.AddHypothesis(box,hypNbSeg1) +print ret +ret=mesh.AddHypothesis(box,hypArea1) +print ret + # ---- add hypothesis to edge print "-------------------------- add hypothesis to edge" edge=salome.IDToObject(idedge) -submesh=mesh.GetElementsOnShape(edge) +submesh=mesh.GetSubMesh(edge, "SubMeshEdge") + ret=mesh.AddHypothesis(edge,algoReg) print ret ret=mesh.AddHypothesis(edge,hypLen1) print ret -idsm1 = smeshgui.AddSubMeshOnShape( idmesh, - idedge, - salome.orb.object_to_string(submesh), - ShapeTypeEdge ) -smeshgui.SetName(idsm1, "SubMeshEdge") -smeshgui.SetAlgorithms( idsm1, idreg ); -smeshgui.SetHypothesis( idsm1, idlength ); - print "-------------------------- add hypothesis to face" face=salome.IDToObject(idface) -submesh=mesh.GetElementsOnShape(face) -ret=mesh.AddHypothesis(face,hypArea2) -print ret - -idsm2 = smeshgui.AddSubMeshOnShape( idmesh, - idface, - salome.orb.object_to_string(submesh), - ShapeTypeFace ) -smeshgui.SetName(idsm2, "SubMeshFace") -smeshgui.SetHypothesis( idsm2, idarea2 ); +submesh = mesh.GetSubMesh(face, "SubMeshFace") -# ---- add hypothesis to box - -print "-------------------------- add hypothesis to box" -box=salome.IDToObject(idbox) -submesh=mesh.GetElementsOnShape(box) -ret=mesh.AddHypothesis(box,algoReg) -print ret -ret=mesh.AddHypothesis(box,hypNbSeg1) -print ret -ret=mesh.AddHypothesis(box,algoMef) -print ret -ret=mesh.AddHypothesis(box,hypArea1) +ret=mesh.AddHypothesis(face,hypArea2) print ret -smeshgui.SetAlgorithms( idmesh, idreg ); -smeshgui.SetHypothesis( idmesh, idseg ); -smeshgui.SetAlgorithms( idmesh, idmef ); -smeshgui.SetHypothesis( idmesh, idarea1 ); - -gen.Compute(mesh, idbox) +smesh.Compute(mesh, box) sg.updateObjBrowser(1); print @@ -273,7 +244,7 @@ if father is None: myBuilder.DefineComponentInstance(father,SuperVision) def addStudy(ior): - dataflow = SuperVision.getGraph(ior) + dataflow = SuperVision.getStreamGraph(ior) name=dataflow.Name() itr = myStudy.NewChildIterator(father) while itr.More(): @@ -309,7 +280,7 @@ print "Load dataflow from the file : " print xmlfile print -myGraph = Graph ( xmlfile ) +myGraph = StreamGraph ( xmlfile ) # This DataFlow is "valid" : no loop, correct links between Nodes etc... print "myGraph.IsValid() = ", myGraph.IsValid() @@ -371,7 +342,7 @@ for node in nodes: print names # Graph creation -GraphInLines = Graph( 'GraphInLines' ) +GraphInLines = StreamGraph( 'GraphInLines' ) GraphInLines.SetName( 'GraphInLines' ) GraphInLines.SetAuthor( '' ) GraphInLines.SetComment( '' ) @@ -460,8 +431,8 @@ import VISU import visu_gui -medFile = "pointe.med" -medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFile +medFileName = "pointe.med" +medFile = os.getenv('KERNEL_ROOT_DIR') + '/examples/' + medFileName print "Load ", medFile studyCurrent = salome.myStudyName @@ -473,10 +444,11 @@ try: if os.access(medFile, os.R_OK) : if not os.access(medFile, os.W_OK) : import random - medFileNew = "/tmp/" + str(random.randint(0,1000000)) + "_" + medfile + medFileNew = "/tmp/" + str(random.randint(0,1000000)) + "_" + medFileName print " -- Copy " + medFile + " to " + medFileNew os.system("cp "+ medFile + " " + medFileNew) medFile = medFileNew + os.system("chmod 755 " + medFile) if os.access(medFile, os.W_OK) : med_comp.readStructFileWithFieldType(medFile,studyCurrent) diff --git a/src/SALOME_SWIG/test_remove_ref.py b/src/SALOME_SWIG/test_remove_ref.py new file mode 100755 index 000000000..7842a0ecd --- /dev/null +++ b/src/SALOME_SWIG/test_remove_ref.py @@ -0,0 +1,49 @@ +# 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 : test_remove_ref.py +# Module : SALOMEDS + +from salome import * + +myBuilder = myStudy.NewBuilder() + + +obj1 = myStudy.FindObjectID("0:1") +if obj1 is None: print "Is null obj1 " +else: print obj1.GetID() + +obj2 = myBuilder.NewObject(obj1) +print "Obj2 ID = "+obj2.GetID() + +myBuilder.Addreference(obj1, obj2) + +(f, obj3) = obj1.ReferencedObject() + +print "Ref obj ID = "+obj3.GetID() + + +myBuilder.RemoveReference(obj1) + +(f, obj4) = obj1.ReferencedObject() + +print "Ref is found ", f + \ No newline at end of file diff --git a/src/SUPERVGraph/SUPERVGraph.cxx b/src/SUPERVGraph/SUPERVGraph.cxx index 70524b061..140853bb9 100644 --- a/src/SUPERVGraph/SUPERVGraph.cxx +++ b/src/SUPERVGraph/SUPERVGraph.cxx @@ -26,9 +26,9 @@ // Module : SALOME // $Header$ +using namespace std; #include "SUPERVGraph.h" #include "SUPERVGraph_ViewFrame.h" -using namespace std; QAD_ViewFrame* SUPERVGraph::createView(QAD_RightFrame* parent) { diff --git a/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx b/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx index 439ffa15a..7a73fff3e 100644 --- a/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx +++ b/src/SUPERVGraph/SUPERVGraph_ViewFrame.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +using namespace std; #include "SUPERVGraph_ViewFrame.h" #include "QAD_Settings.h" @@ -39,7 +40,6 @@ //QT Include #include #include -using namespace std; SUPERVGraph_View::SUPERVGraph_View(QWidget* theParent): QWidget(theParent){ init(theParent); @@ -249,7 +249,7 @@ QColor SUPERVGraph_ViewFrame::backgroundColor() const } -void SUPERVGraph_ViewFrame::SetSelectionMode( int mode ) +void SUPERVGraph_ViewFrame::SetSelectionMode( Selection_Mode mode ) { MESSAGE ( "SUPERVGraph_ViewFrame::SetSelectionMode" ) } diff --git a/src/SUPERVGraph/SUPERVGraph_ViewFrame.h b/src/SUPERVGraph/SUPERVGraph_ViewFrame.h index 8c62cc436..42aeafdf3 100644 --- a/src/SUPERVGraph/SUPERVGraph_ViewFrame.h +++ b/src/SUPERVGraph/SUPERVGraph_ViewFrame.h @@ -34,6 +34,7 @@ #include "QAD_Application.h" #include "SALOME_InteractiveObject.hxx" +#include "SALOME_Selection.h" class QAD_EXPORT SUPERVGraph_View: public QWidget, public QAD_PopupClientServer{ Q_OBJECT; @@ -62,7 +63,7 @@ class QAD_EXPORT SUPERVGraph_ViewFrame : public QAD_ViewFrame { void setBackgroundColor( const QColor& ); QColor backgroundColor() const; - void SetSelectionMode( int mode ); + void SetSelectionMode( Selection_Mode mode ); void onAdjustTrihedron( ); diff --git a/src/Session/Makefile.in b/src/Session/Makefile.in index 36ba65dde..2072c8e84 100644 --- a/src/Session/Makefile.in +++ b/src/Session/Makefile.in @@ -40,8 +40,9 @@ EXPORT_HEADERS= SALOME_Session_i.hxx # Libraries targets LIB = libSalomeSession.la LIB_SRC=\ - SALOME_Session_QThread.cxx \ - SALOME_Session_i.cxx + SALOME_Session_i.cxx \ + Session_ServerThread.cxx \ + Session_ServerLauncher.cxx # Executables targets BIN = SALOME_Session_Server @@ -49,9 +50,9 @@ BIN_SRC = BIN_SERVER_IDL = SALOME_Session.idl BIN_CLIENT_IDL = SALOMEDS.idl SALOMEDS_Attributes.idl SALOME_Component.idl SALOME_Registry.idl SALOME_ModuleCatalog.idl SALOME_Exception.idl -CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) +CPPFLAGS+=$(QT_MT_INCLUDES) $(OCC_INCLUDES) $(PYTHON_INCLUDES) $(HDF5_INCLUDES) CXXFLAGS+=$(OCC_CXXFLAGS) -LDFLAGS+=$(QT_MT_LIBS) -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace +LDFLAGS+=$(QT_MT_LIBS) $(HDF5_LIBS) -lSalomeHDFPersist -lSalomeNS -lSalomeGUI -lSalomeObject -lSalomeLifeCycleCORBA -lqsplitterP -lOpUtil -lPlot2d -lSalomeVTKFilter -lSALOMELocalTrace -lSalomeContainer -lRegistry -lSalomeNotification -lSalomeDS -lTOOLSDS -lSalomeGenericObj -lSalomeCatalog -lEvent @CONCLUDE@ diff --git a/src/Session/SALOME_Session_QThread.cxx b/src/Session/SALOME_Session_QThread.cxx index bdd9910f2..9229ba274 100644 --- a/src/Session/SALOME_Session_QThread.cxx +++ b/src/Session/SALOME_Session_QThread.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +using namespace std; #include #include @@ -42,14 +43,12 @@ // only to use findFile method : perhaps put it in QAD_Tools ??? #include "QAD_ResourceMgr.h" #include -using namespace std; - +#include "Utils_CatchSignals.h" +#include "Utils_CorbaException.hxx" #include #include CORBA_SERVER_HEADER(SALOMEDS) -SALOME_Session_QThread* SALOME_Session_QThread::_singleton = 0; - //============================================================================= /*! SALOME_Session_QThread * constructor @@ -58,7 +57,6 @@ SALOME_Session_QThread* SALOME_Session_QThread::_singleton = 0; SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread() { - INFOS("Creation SALOME_Session_QThread"); _qappl = 0 ; _mw = 0 ; _argc = argc ; @@ -66,18 +64,6 @@ SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread _NS = 0 ; } ; -//============================================================================= -/*! - * - */ -//============================================================================= - - SALOME_Session_QThread* SALOME_Session_QThread::Instance(int argc, char ** argv) -{ - if (_singleton == 0) _singleton = new SALOME_Session_QThread(argc, argv); - return _singleton; - -} //============================================================================= /*! run @@ -85,18 +71,17 @@ SALOME_Session_QThread::SALOME_Session_QThread(int argc, char ** argv) : QThread * Executes the Qt main window of the GUI on a separate thread */ //============================================================================= - void SALOME_Session_QThread::run() { if (_qappl == 0) { _qappl = new QApplication(_argc, _argv ); - INFOS("creation QApplication"); + MESSAGE("creation QApplication"); } QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) ); _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" ); - INFOS("creation SALOMEGUI_Application"); + MESSAGE("creation SALOMEGUI_Application"); if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) ) { @@ -116,26 +101,59 @@ void SALOME_Session_QThread::run() _qappl->setPalette( QAD_Application::getPalette() ); + Utils_CatchSignals aCatch; + aCatch.Activate(); + /* Run 'SALOMEGUI' application */ QAD_Application::run(); - + // T2.12 - catch exceptions thrown on attempts to modified a locked study while (1) { try { - MESSAGE("run(): starting the main event loop") + MESSAGE("run(): starting the main event loop"); _ret = _qappl->exec(); break; } + catch (SALOME::SALOME_Exception& e) { + INFOS("run(): SALOME::SALOME_Exception is caught"); + QApplication::restoreOverrideCursor(); + QAD_MessageBox::error1 ( (QWidget*)QAD_Application::getDesktop(), + QObject::tr("ERR_ERROR"), + QObject::tr("ERR_APP_EXCEPTION")+ QObject::tr(" SALOME::SALOME_Exception is caught") , + QObject::tr("BUT_OK") ); + + } catch(SALOMEDS::StudyBuilder::LockProtection&) { - MESSAGE("run(): An attempt to modify a locked study has not been handled by QAD_Operation") + INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation"); QApplication::restoreOverrideCursor(); QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(), - QObject::tr("WRN_WARNING"), - QObject::tr("WRN_STUDY_LOCKED"), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED"), + QObject::tr("BUT_OK") ); + } + catch (const CORBA::Exception& e) { + CORBA::Any tmp; + tmp<<= e; + CORBA::TypeCode_var tc = tmp.type(); + const char *p = tc->name(); + INFOS ("run(): CORBA exception of the kind : "<createConfigFile(true); diff --git a/src/Session/SALOME_Session_QThread.hxx b/src/Session/SALOME_Session_QThread.hxx index eac1da8d6..9e9941bd7 100644 --- a/src/Session/SALOME_Session_QThread.hxx +++ b/src/Session/SALOME_Session_QThread.hxx @@ -41,7 +41,7 @@ class SALOME_Session_QThread: public QThread { public: - static SALOME_Session_QThread* Instance(int argc, char ** argv); + SALOME_Session_QThread(int argc, char ** argv) ; //! launch the Qt main window of the GUI on a separate thread virtual void run() ; @@ -57,10 +57,6 @@ protected: QApplication *_qappl ; SALOMEGUI_Application* _mw ; - SALOME_Session_QThread(int argc, char ** argv); - -private: - static SALOME_Session_QThread* _singleton; } ; #endif diff --git a/src/Session/SALOME_Session_Server.cxx b/src/Session/SALOME_Session_Server.cxx index 2b00367c2..ff9a6cf3c 100644 --- a/src/Session/SALOME_Session_Server.cxx +++ b/src/Session/SALOME_Session_Server.cxx @@ -33,13 +33,47 @@ #include using namespace std; +#include +#include +#include +#include + +#include "SALOMEGUI_Application.h" +#include "QAD.h" +#include "QAD_MessageBox.h" +#include "QAD_Application.h" +#include "QAD_Settings.h" +#include "QAD_Config.h" +#include "QAD_Tools.h" +#include "QAD_ResourceMgr.h" +#include "Utils_CatchSignals.h" +#include "Utils_SALOME_Exception.hxx" +#include "Utils_CorbaException.hxx" +#include "SALOMEGUI_QtCatchCorbaException.hxx" + + #include #include CORBA_SERVER_HEADER(SALOME_Session) +#include CORBA_SERVER_HEADER(SALOMEDS) #include "utilities.h" #include "SALOME_Session_i.hxx" +#include "Session_ServerLauncher.hxx" + +/*! - read arguments, define list of server to launch with their arguments. + * - wait for naming service + * - create and run a thread for launch of all servers + * + */ + +// ---------------------------------------------------------------------------- + + + +// ---------------------------------------------------------------------------- + //! CORBA server for SALOME Session /*! * SALOME_Session Server launches a SALOME session servant. @@ -54,120 +88,169 @@ using namespace std; int main(int argc, char **argv) { - try { ORB_INIT &init = *SINGLETON_::Instance() ; ASSERT(SINGLETON_::IsAlreadyExisting()) ; - CORBA::ORB_var &orb = init( argc , argv ) ; - - // - long TIMESleep = 250000000; - int NumberOfTries = 40; - int a; - timespec ts_req; - ts_req.tv_nsec=TIMESleep; - ts_req.tv_sec=0; - timespec ts_rem; - ts_rem.tv_nsec=0; - ts_rem.tv_sec=0; - CosNaming::NamingContext_var inc; - PortableServer::POA_var poa; - CORBA::Object_var theObj; - CORBA::Object_var obj; - CORBA::Object_var object; - SALOME_NamingService &naming = *SINGLETON_::Instance() ; - int SESSION=0; - const char * Env = getenv("USE_LOGGER"); - int EnvL =0; - if ((Env!=NULL) && (strlen(Env))) - EnvL=1; - CosNaming::Name name; - name.length(1); - name[0].id=CORBA::string_dup("Logger"); - PortableServer::POAManager_var pman; - for (int i = 1; i<=NumberOfTries; i++){ - if (i!=1) - a=nanosleep(&ts_req,&ts_rem); - try - { - obj = orb->resolve_initial_references("RootPOA"); - if(!CORBA::is_nil(obj)) - poa = PortableServer::POA::_narrow(obj); - if(!CORBA::is_nil(poa)) - pman = poa->the_POAManager(); - if(!CORBA::is_nil(orb)) - theObj = orb->resolve_initial_references("NameService"); - if (!CORBA::is_nil(theObj)) - inc = CosNaming::NamingContext::_narrow(theObj); - } - catch( CORBA::COMM_FAILURE& ) - { - MESSAGE( "Session Server: CORBA::COMM_FAILURE: Unable to contact the Naming Service" ); - } - if(!CORBA::is_nil(inc)) - { - MESSAGE( "Session Server: Naming Service was found" ); - if(EnvL==1) - { - for(int j=1; j<=NumberOfTries; j++) - { - if (j!=1) - a=nanosleep(&ts_req, &ts_rem); - try - { - object = inc->resolve(name); - } - catch(CosNaming::NamingContext::NotFound) - { MESSAGE( "Session Server: Logger Server wasn't found" ); - } - catch(...) - { - MESSAGE( "Session Server: Unknown exception" ); - } - if (!CORBA::is_nil(object)) - { - MESSAGE( "Session Server: Loger Server was found" ); - SESSION=1; - break; - } - } - } - } - if ((SESSION==1)||((EnvL==0)&&(!CORBA::is_nil(inc)))) - break; - } - - // servant - SALOME_Session_i * mySALOME_Session = new SALOME_Session_i(argc, argv, orb, poa) ; - PortableServer::ObjectId_var mySALOME_Sessionid = poa->activate_object(mySALOME_Session) ; - MESSAGE("poa->activate_object(mySALOME_Session)") - - obj = mySALOME_Session->_this() ; - CORBA::String_var sior(orb->object_to_string(obj)) ; - - mySALOME_Session->NSregister(); - - mySALOME_Session->_remove_ref() ; - - //DECOMMENT PortableServer::POAManager_var pman = poa->the_POAManager() ; + int orbArgc = 1; + CORBA::ORB_var &orb = init( orbArgc , argv ) ; + + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj); + + PortableServer::POAManager_var pman = poa->the_POAManager() ; pman->activate() ; - MESSAGE("pman->activate()") + INFOS("pman->activate()"); + + SALOME_NamingService *_NS = new SALOME_NamingService(orb); + + Utils_CatchSignals aCatch; + aCatch.Activate(); - orb->run() ; - orb->destroy() ; + // CORBA Servant Launcher + + QMutex _GUIMutex ; + QWaitCondition _ServerLaunch; + _GUIMutex.lock(); // to block Launch server thread until wait(mutex) + + Session_ServerLauncher* myServerLauncher + = new Session_ServerLauncher(argc, argv, orb, poa, &_GUIMutex, &_ServerLaunch); + myServerLauncher->start(); + + MESSAGE("waiting wakeAll()"); + _ServerLaunch.wait(&_GUIMutex); // to be reseased by Launch server thread when ready: + // atomic operation lock - unlock on mutex + // unlock mutex: serverThread runs, calls _ServerLaunch->wakeAll() + // this thread wakes up, and lock mutex + + INFOS("Session activated, Launch IAPP..."); + + int qappArgc = 1; + QApplication *_qappl = new QApplication(qappArgc, argv ); + INFOS("creation QApplication"); + _GUIMutex.unlock(); + + QAD_ASSERT ( QObject::connect(_qappl, SIGNAL(lastWindowClosed()), _qappl, SLOT(quit()) ) ); + SALOMEGUI_Application* _mw = new SALOMEGUI_Application ( "MDTV-Standard", "HDF", "hdf" ); + INFOS("creation SALOMEGUI_Application"); + + SCRUTE(_NS); + if ( !SALOMEGUI_Application::addToDesktop ( _mw, _NS ) ) + { + QAD_MessageBox::error1 ( 0, + QObject::tr("ERR_ERROR"), + QObject::tr("ERR_APP_INITFAILED"), + QObject::tr("BUT_OK") ); + } + else + { + + QFileInfo prgInfo(argv[0]); + QDir prgDir(prgInfo.dirPath(true)); + QAD_CONFIG->setPrgDir(prgDir); // CWD is program directory + QAD_CONFIG->createConfigFile(false); // Create config file + // ~/.tr(MEN_APPNAME)/tr(MEN_APPNAME).conf if there's none + QAD_CONFIG->readConfigFile(); // Read config file + + _qappl->setPalette( QAD_Application::getPalette() ); + + //Utils_CatchSignals aCatch; + //aCatch.Activate(); + + /* Run 'SALOMEGUI' application */ + QAD_Application::run(); + + // T2.12 - catch exceptions thrown on attempts to modified a locked study + while (1) + { + try + { + MESSAGE("run(): starting the main event loop"); + int _ret = _qappl->exec(); + break; + } + catch (SALOME::SALOME_Exception& e) + { + QtCatchCorbaException(e); + } + catch(SALOMEDS::StudyBuilder::LockProtection&) + { + INFOS("run(): An attempt to modify a locked study has not been handled by QAD_Operation"); + QApplication::restoreOverrideCursor(); + QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(), + QObject::tr("WRN_WARNING"), + QObject::tr("WRN_STUDY_LOCKED"), + QObject::tr("BUT_OK") ); + } + catch (const CORBA::Exception& e) + { + CORBA::Any tmp; + tmp<<= e; + CORBA::TypeCode_var tc = tmp.type(); + const char *p = tc->name(); + INFOS ("run(): CORBA exception of the kind : "<createConfigFile(true); + } + //orb->shutdown(0); + myServerLauncher->KillAll(); + aCatch.Deactivate(); } - catch (CORBA::SystemException&) + catch (SALOME_Exception& e) + { + INFOS("run(): SALOME::SALOME_Exception is caught: "<name(); + INFOS ("run(): CORBA exception of the kind : "<Register(pSession, "/Kernel/Session"); - _IAPPThread->setNamingService(_NS); } catch (ServiceUnreachable&) { @@ -113,7 +114,7 @@ void SALOME_Session_i::NSregister() { INFOS("Caught unknown exception from Naming Service"); } - MESSAGE("NSregister end"); + MESSAGE("Session registered in Naming Service"); } //============================================================================= @@ -125,13 +126,14 @@ void SALOME_Session_i::NSregister() void SALOME_Session_i::GetInterface() { - _GUIMutex.lock() ; // get access to boolean _isGUI - _isGUI = _IAPPThread->running(); - if(!_isGUI){ - _isGUI = TRUE ; - _IAPPThread->start() ; - } - _GUIMutex.unlock() ; // release access to boolean _isGUI + _GUIMutex->lock() ; // get access to boolean _isGUI + //_isGUI = _IAPPThread->running(); + if(!_isGUI) + { + _isGUI = TRUE ; + //_IAPPThread->start() ; + } + _GUIMutex->unlock() ; // release access to boolean _isGUI } //============================================================================= @@ -145,21 +147,6 @@ void SALOME_Session_i::StopSession() qApp->lock(); QAD_Application::getDesktop()->closeDesktop( true ); qApp->unlock(); -/* - _GUIMutex.lock(); // get access to boolean _isGUI - if ((! _isGUI) && (! _runningStudies)) - { - MESSAGE("Ask for Session Kill, OK"); - exit(0); - } - else - { - _GUIMutex.unlock() ; // release access to boolean _isGUI - MESSAGE("Ask for Session Kill, NOK"); - if (_isGUI) throw SALOME::Session::GUIActive(); - if (_runningStudies) throw SALOME::Session::RunningStudies(); - } -*/ } //============================================================================= @@ -173,16 +160,18 @@ SALOME::StatSession SALOME_Session_i::GetStatSession() { // update Session state //qApp->lock(); // rollback bug - _GUIMutex.lock(); - _isGUI = _IAPPThread->running(); + _GUIMutex->lock(); + //_isGUI = _IAPPThread->running(); + _isGUI = 1; _runningStudies = 0; - if (_isGUI) { - qApp->lock(); - if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() ) - _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count(); - qApp->unlock(); - } - _GUIMutex.unlock(); + if (_isGUI) + { + qApp->lock(); + if ( QAD_Application::getDesktop() && QAD_Application::getDesktop()->getActiveApp() ) + _runningStudies = QAD_Application::getDesktop()->getActiveApp()->getStudies().count(); + qApp->unlock(); + } + _GUIMutex->unlock(); //qApp->unlock(); // getting stat info SALOME::StatSession_var myStats = new SALOME::StatSession ; diff --git a/src/Session/SALOME_Session_i.hxx b/src/Session/SALOME_Session_i.hxx index 0d52f118e..438b93f62 100644 --- a/src/Session/SALOME_Session_i.hxx +++ b/src/Session/SALOME_Session_i.hxx @@ -41,8 +41,8 @@ class SALOME_Session_i: public virtual POA_SALOME::Session, public virtual PortableServer::RefCountServantBase { public: - SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa) ; - ~SALOME_Session_i() ; + SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex); + ~SALOME_Session_i(); //! Launch Graphical User Interface void GetInterface(); @@ -62,8 +62,6 @@ public: void ping(){}; protected: - //! A QT Thread for the GUI - SALOME_Session_QThread *_IAPPThread ; //! Naming service interface SALOME_NamingService *_NS; @@ -71,7 +69,7 @@ protected: int _argc ; char **_argv; CORBA::Boolean _isGUI ; - QMutex _GUIMutex ; + QMutex* _GUIMutex ; int _runningStudies ; CORBA::ORB_var _orb; PortableServer::POA_var _poa; diff --git a/src/Session/Session_ServerLauncher.cxx b/src/Session/Session_ServerLauncher.cxx new file mode 100644 index 000000000..4f278190b --- /dev/null +++ b/src/Session/Session_ServerLauncher.cxx @@ -0,0 +1,231 @@ +// SALOME Session : implementation of Session_ServerLauncher.cxx +// +// 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 : Session_ServerLauncher.xx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#include "Session_ServerLauncher.hxx" + +#include "Utils_SALOME_Exception.hxx" +#include "utilities.h" + +//============================================================================= +/*! + * default constructor not for use + */ +//============================================================================= + +Session_ServerLauncher::Session_ServerLauncher() +{ + ASSERT(0); // must not be called +} + +//============================================================================= +/*! + * constructor + */ +//============================================================================= + +Session_ServerLauncher::Session_ServerLauncher(int argc, + char ** argv, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + QMutex *GUIMutex, + QWaitCondition *ServerLaunch) +{ + _argc = argc; + _argv = argv; + _orb = CORBA::ORB::_duplicate(orb); + _root_poa = PortableServer::POA::_duplicate(poa); + _GUIMutex = GUIMutex; + _ServerLaunch = ServerLaunch; +} + +//============================================================================= +/*! + * destructor + */ +//============================================================================= + +Session_ServerLauncher::~Session_ServerLauncher() +{ +} + +//============================================================================= +/*! + * Check args and activate servers + */ +//============================================================================= + +void Session_ServerLauncher::run() +{ + MESSAGE("Session_ServerLauncher::run"); + _GUIMutex->lock(); // lock released by calling thread when ready: wait(mutex) + MESSAGE("Server Launcher thread free to go..."); + _GUIMutex->unlock(); + + CheckArgs(); + ActivateAll(); + + _ServerLaunch->wakeAll(); + _orb->run(); // this thread wait, during omniORB process events +} + +//============================================================================= +/*! + * controls and dispatchs arguments given with command + */ +//============================================================================= + +void Session_ServerLauncher::CheckArgs() +{ + int argState = 0; + ServArg aServArg(0,0,0); + _argCopy.reserve(_argc); + for (int iarg=0; iarg <_argc; iarg++) + { + SCRUTE(iarg); + SCRUTE(_argv[iarg]); + _argCopy.push_back(_argv[iarg]); + switch (argState) + { + case 0: // looking for "--with" + { + if (strcmp(_argv[iarg],"--with")==0) + argState = 1; + break; + } + case 1: // looking for server type + { + for (int i=0; i::iterator itServ; + for (itServ = _argServToLaunch.begin(); itServ !=_argServToLaunch.end(); itServ++) + { + int argc = 2 + (*itServ)._lastArg - (*itServ)._firstArg; + char** argv = new char*[argc+1]; + argv[argc]=0; // for Engines_Container_i constructor... + int servType = (*itServ)._servType; + argv[0]=strdup(Session_ServerThread::_serverTypes[servType]); + if (argc>1) + { + for (int i=0; iInit(); + } + + // Always launch Session Server + + int argc=1; + char** argv = new char*[argc]; + argv[0] = "Session"; + Session_ServerThread* aServerThread + = new Session_ServerThread(argc, argv, _orb,_root_poa,_GUIMutex); + _serverThreads.push_front(aServerThread); + + aServerThread->Init(); +} + +//============================================================================= +/*! + * Destruction des classes serveur dans l'ordre inverse de creation + */ +//============================================================================= + +void Session_ServerLauncher::KillAll() +{ + MESSAGE("Session_ServerLauncher::KillAll()"); + list::reverse_iterator itServ; + for (itServ = _serverThreads.rbegin(); itServ !=_serverThreads.rend(); itServ++) + { + delete (*itServ); + } +} diff --git a/src/Session/Session_ServerLauncher.hxx b/src/Session/Session_ServerLauncher.hxx new file mode 100644 index 000000000..45804e17d --- /dev/null +++ b/src/Session/Session_ServerLauncher.hxx @@ -0,0 +1,87 @@ +// SALOME Session : implementation of Session_ServerLauncher.hxx +// +// 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 : Session_ServerLauncher.hxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#ifndef _SESSION_SERVERLAUNCHER_HXX_ +#define _SESSION_SERVERLAUNCHER_HXX_ + +#include "Session_ServerThread.hxx" + +#include +#include +#include +#include +#include +#include + +using namespace std; + +class ServArg + { + public: + int _servType; + int _firstArg; + int _lastArg; + inline ServArg(int servType=0, int firstArg=0, int lastArg=0); +}; + +inline ServArg::ServArg(int servType, int firstArg, int lastArg): + _servType(servType),_firstArg(firstArg),_lastArg(lastArg) +{} + +class Session_ServerLauncher: public QThread +{ +public: + Session_ServerLauncher(); + Session_ServerLauncher(int argc, + char ** argv, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + QMutex *GUIMutex, + QWaitCondition *ServerLaunch); + virtual ~Session_ServerLauncher(); + void run(); + void KillAll(); + +protected: + void CheckArgs(); + void ActivateAll(); + +private: + int _argc; + char ** _argv; + CORBA::ORB_var _orb; + PortableServer::POA_var _root_poa; + QMutex* _GUIMutex; + QWaitCondition *_ServerLaunch; + list _argServToLaunch; + vector _argCopy; + list _serverThreads; +}; + +#endif + diff --git a/src/Session/Session_ServerThread.cxx b/src/Session/Session_ServerThread.cxx new file mode 100644 index 000000000..e5e4f055c --- /dev/null +++ b/src/Session/Session_ServerThread.cxx @@ -0,0 +1,503 @@ +// SALOME Session : implementation of Session_ServerThread.cxx +// +// 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 : Session_ServerThread.cxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +// #include +// #include CORBA_SERVER_HEADER(SALOME_Session) +// #include CORBA_SERVER_HEADER(SALOMEDS) + +#include "Session_ServerThread.hxx" + +#include "SALOME_Container_i.hxx" +#include "SALOMEDS_StudyManager_i.hxx" +#include "SALOME_ModuleCatalog_impl.hxx" +#include "RegistryService.hxx" +#include "SALOME_Session_i.hxx" + +#include "Utils_ORB_INIT.hxx" +#include "Utils_SINGLETON.hxx" +#include "Utils_SALOME_Exception.hxx" +#include "OpUtil.hxx" +#include "utilities.h" + +#include +#include + +using namespace std; + +const int Session_ServerThread::NB_SRV_TYP = 5; +const char* Session_ServerThread::_serverTypes[NB_SRV_TYP] = {"Container", + "ModuleCatalog", + "Registry", + "SALOMEDS", + "Session"}; + +//============================================================================= +/*! + * Wait until the given server is ready i.e. is name is found in namingService. + * Try 40 times, with 250 ms sleep between each try. + * If Logger is used for traces, it must be ready before this call, because + * SALOME_NamingService client uses SALOME traces. So, Logger readiness must be + * checked in Launch script before execution of WaitForServerReadiness. + */ +//============================================================================= + +void WaitForServerReadiness(SALOME_NamingService* NS, string serverName) +{ + long TIMESleep = 250000000; // 250 ms. + int NumberOfTries = 40; // total wait = 10 s. + int found = 0; + + timespec ts_req; + ts_req.tv_nsec=TIMESleep; + ts_req.tv_sec=0; + timespec ts_rem; + ts_rem.tv_nsec=0; + ts_rem.tv_sec=0; + + for (int itry=0; itry < NumberOfTries; itry++) + { + try + { + if (serverName.length() == 0) + { + string curdir = NS->Current_Directory(); // to wait for naming service + found = 1; + break; // naming service found + } + else + { + CORBA::Object_ptr obj = NS->Resolve(serverName.c_str()); + if (! CORBA::is_nil(obj)) + { + found =1; + break; // server found, no more try to do + } + MESSAGE("Server "<< serverName <<" not yet ready, waiting..."); + int a = nanosleep(&ts_req,&ts_rem); // wait before retry + } + } + catch( ServiceUnreachable& ) + { + MESSAGE("CORBA::COMM_FAILURE: Naming Service not yet ready, waiting..."); + int a = nanosleep(&ts_req,&ts_rem); // wait before retry + } + } + if (!found) + { + INFOS("Server "<< serverName <<" not found, abort..."); + exit(EXIT_FAILURE); + } +} + +//============================================================================= +/*! + * default constructor not for use + */ +//============================================================================= + +Session_ServerThread::Session_ServerThread() +{ + ASSERT(0); // must not be called +} + +//============================================================================= +/*! + * constructor + */ +//============================================================================= + +Session_ServerThread::Session_ServerThread(int argc, + char ** argv, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + QMutex *GUIMutex) +{ + MESSAGE("Session_ServerThread Constructor " << argv[0]); + _argc = argc; + _argv = argv; + _orb = CORBA::ORB::_duplicate(orb); + _root_poa = PortableServer::POA::_duplicate(poa); + _GUIMutex = GUIMutex; + _servType =-1; + _NS = new SALOME_NamingService(_orb); // one instance per server to limit + // multi thread coherence problems +} + +//============================================================================= +/*! + * destructor + */ +//============================================================================= + +Session_ServerThread::~Session_ServerThread() +{ + MESSAGE("~Session_ServerThread "<< _argv[0]); +} + +//============================================================================= +/*! + * run the thread : activate one servant, the servant type is given by + * argument _argv[0] + */ +//============================================================================= + +void Session_ServerThread::Init() +{ + MESSAGE("Session_ServerThread::Init "<< _argv[0]); + + for (int i=0; i<_argc; i++) SCRUTE(_argv[i]); + for (int i=0; iactivate_object (Catalogue_i); + + CORBA::Object_ptr myCata = Catalogue_i->_this(); + _NS->Register(myCata ,"/Kernel/ModulCatalog"); + } + catch(CORBA::SystemException&) + { + INFOS( "Caught CORBA::SystemException." ); + } + catch(CORBA::Exception&) + { + INFOS( "Caught CORBA::Exception." ); + } + catch(omniORB::fatalException& fe) + { + INFOS( "Caught omniORB::fatalException:" ); + INFOS( " file: " << fe.file() ); + INFOS( " line: " << fe.line() ); + INFOS( " mesg: " << fe.errmsg() ); + } + catch(...) + { + INFOS( "Caught unknown exception." ); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +void Session_ServerThread::ActivateSALOMEDS(int argc, + char ** argv) +{ + try + { + INFOS("SALOMEDS thread started"); + // We allocate the objects on the heap. Since these are reference + // counted objects, they will be deleted by the POA when they are no + // longer needed. + + SALOMEDS_StudyManager_i * myStudyManager_i + = new SALOMEDS_StudyManager_i(_orb); + + // Activate the objects. This tells the POA that the objects are + // ready to accept requests. + + PortableServer::ObjectId_var myStudyManager_iid + = _root_poa->activate_object(myStudyManager_i); + myStudyManager_i->register_name("/myStudyManager"); + } + catch(CORBA::SystemException&) + { + INFOS( "Caught CORBA::SystemException." ); + } + catch(CORBA::Exception&) + { + INFOS( "Caught CORBA::Exception." ); + } + catch(omniORB::fatalException& fe) + { + INFOS( "Caught omniORB::fatalException:" ); + INFOS( " file: " << fe.file() ); + INFOS( " line: " << fe.line() ); + INFOS( " mesg: " << fe.errmsg() ); + } + catch(...) + { + INFOS( "Caught unknown exception." ); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +void Session_ServerThread::ActivateRegistry(int argc, + char ** argv) +{ + INFOS("Registry thread started"); + SCRUTE(argc); + if( argc<3 ) + { + INFOS("you must provide the Salome session name when you call SALOME_Registry_Server"); + throw CommException("you must provide the Salome session name when you call SALOME_Registry_Server"); + } + const char *ptrSessionName=0; + + int k=0 ; + for ( k=1 ; k0); + const char *registryName = "Registry"; + Registry::Components_var varComponents; + try + { + RegistryService *ptrRegistry = SINGLETON_::Instance(); + ptrRegistry->SessionName( ptrSessionName ); + varComponents = ptrRegistry->_this(); + // The RegistryService must not already exist. + + try + { + CORBA::Object_var pipo = _NS->Resolve( registryName ); + if (CORBA::is_nil(pipo) ) throw ServiceUnreachable(); + INFOS("RegistryService servant already existing" ); + ASSERT(0); + } + catch( const ServiceUnreachable &ex ) + { + } + catch( const CORBA::Exception &exx ) + { + } + string absoluteName = string("/") + registryName; + _NS->Register( varComponents , absoluteName.c_str() ); + MESSAGE("On attend les requetes des clients"); + } + catch( const SALOME_Exception &ex ) + { + INFOS( "Communication Error : " << ex.what() ); + ASSERT(0); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +void Session_ServerThread::ActivateContainer(int argc, + char ** argv) +{ + try + { + INFOS("Container thread started"); + + // get or create the child POA + + PortableServer::POA_var factory_poa; + try + { + factory_poa = _root_poa->find_POA("factory_poa",0); + // 0 = no activation (already done if exists) + } + catch (PortableServer::POA::AdapterNonExistent&) + { + INFOS("factory_poa does not exists, create..."); + // define policy objects + PortableServer::ImplicitActivationPolicy_var implicitActivation = + _root_poa->create_implicit_activation_policy( + PortableServer::NO_IMPLICIT_ACTIVATION); + // default = NO_IMPLICIT_ACTIVATION + PortableServer::ThreadPolicy_var threadPolicy = + _root_poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL); + // default = ORB_CTRL_MODEL, other choice SINGLE_THREAD_MODEL + + // create policy list + CORBA::PolicyList policyList; + policyList.length(2); + policyList[0] = PortableServer::ImplicitActivationPolicy:: + _duplicate(implicitActivation); + policyList[1] = PortableServer::ThreadPolicy:: + _duplicate(threadPolicy); + + PortableServer::POAManager_var nil_mgr + = PortableServer::POAManager::_nil(); + factory_poa = _root_poa->create_POA("factory_poa", + nil_mgr, + policyList); + //with nil_mgr instead of pman, + //a new POA manager is created with the new POA + + // destroy policy objects + implicitActivation->destroy(); + threadPolicy->destroy(); + + // obtain the factory poa manager + PortableServer::POAManager_var pmanfac = factory_poa->the_POAManager(); + pmanfac->activate(); + MESSAGE("pmanfac->activate()"); + } + + char *containerName = ""; + if (argc >1) + { + containerName = argv[1]; + } + + Engines_Container_i * myContainer + = new Engines_Container_i(_orb, factory_poa, containerName , argc , argv ); + } + catch(CORBA::SystemException&) + { + INFOS("Caught CORBA::SystemException."); + } + catch(PortableServer::POA::WrongPolicy&) + { + INFOS("Caught CORBA::WrongPolicyException."); + } + catch(PortableServer::POA::ServantAlreadyActive&) + { + INFOS("Caught CORBA::ServantAlreadyActiveException"); + } + catch(CORBA::Exception&) + { + INFOS("Caught CORBA::Exception."); + } + catch(...) + { + INFOS("Caught unknown exception."); + } +} + +//============================================================================= +/*! + * + */ +//============================================================================= + +void Session_ServerThread::ActivateSession(int argc, + char ** argv) +{ + try + { + INFOS("Session thread started"); + SALOME_Session_i * mySALOME_Session + = new SALOME_Session_i(argc, argv, _orb, _root_poa, _GUIMutex) ; + PortableServer::ObjectId_var mySALOME_Sessionid + = _root_poa->activate_object(mySALOME_Session); + INFOS("poa->activate_object(mySALOME_Session)"); + + CORBA::Object_var obj = mySALOME_Session->_this(); + CORBA::String_var sior(_orb->object_to_string(obj)); + + mySALOME_Session->NSregister(); + } + catch (CORBA::SystemException&) + { + INFOS("Caught CORBA::SystemException."); + } + catch (CORBA::Exception&) + { + INFOS("Caught CORBA::Exception."); + } + catch (...) + { + INFOS("Caught unknown exception."); + } +} diff --git a/src/Session/Session_ServerThread.hxx b/src/Session/Session_ServerThread.hxx new file mode 100644 index 000000000..3c12b138e --- /dev/null +++ b/src/Session/Session_ServerThread.hxx @@ -0,0 +1,80 @@ +// SALOME Session : implementation of Session_ServerThread.hxx +// +// 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 : Session_ServerThread.hxx +// Author : Paul RASCLE, EDF +// Module : SALOME +// $Header$ + +#ifndef _SESSION_SERVERTHREAD_HXX_ +#define _SESSION_SERVERTHREAD_HXX_ + +#include +#include + +#include "SALOME_NamingService.hxx" +#include + +using namespace std; + +void WaitForServerReadiness(string serverName); + + +class Session_ServerThread +{ +public: + static const int NB_SRV_TYP; + static const char* _serverTypes[]; + + Session_ServerThread(); + Session_ServerThread(int argc, + char ** argv, + CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + QMutex *GUIMutex); + virtual ~Session_ServerThread(); + void Init(); +protected: + void ActivateModuleCatalog(int argc, + char ** argv); + void ActivateSALOMEDS(int argc, + char ** argv); + void ActivateRegistry(int argc, + char ** argv); + void ActivateContainer(int argc, + char ** argv); + void ActivateSession(int argc, + char ** argv); + +private: + int _argc; + char ** _argv; + int _servType; + CORBA::ORB_var _orb; + PortableServer::POA_var _root_poa; + QMutex* _GUIMutex; + SALOME_NamingService *_NS; +}; + +#endif + diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index ae7937d7d..210c42739 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -1,3 +1,4 @@ +using namespace std; // File : SALOMEDS_Tool.cxx // Created : Mon Oct 21 16:24:34 2002 // Author : Sergey RUIN @@ -12,8 +13,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -22,7 +23,6 @@ #include #include #include -using namespace std; #include #include diff --git a/src/TOOLSGUI/ToolsGUI.cxx b/src/TOOLSGUI/ToolsGUI.cxx index 7e98ad7b1..4b2f47089 100644 --- a/src/TOOLSGUI/ToolsGUI.cxx +++ b/src/TOOLSGUI/ToolsGUI.cxx @@ -26,13 +26,13 @@ // Module : SALOME // $Header$ +using namespace std; #include "ToolsGUI.h" #include "ToolsGUI_CatalogGeneratorDlg.h" #include "utilities.h" #include -using namespace std; int ToolsGUI::runCommand(string & arg) { diff --git a/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx b/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx index 9dc3c696a..abe1d147d 100644 --- a/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx +++ b/src/TOOLSGUI/ToolsGUI_CatalogGeneratorDlg.cxx @@ -27,6 +27,7 @@ // Module : SALOME // $Header$ +using namespace std; #include "ToolsGUI_CatalogGeneratorDlg.h" #include "QAD_Application.h" @@ -48,7 +49,6 @@ #include #include #include -using namespace std; #define SPACING_SIZE 6 #define MARGIN_SIZE 11 @@ -123,8 +123,6 @@ ToolsGUI_CatalogGeneratorDlg::ToolsGUI_CatalogGeneratorDlg( QWidget* parent, con myVersionEdit->setMinimumSize( myMinimumSize ); QStringList aList = QStringList::split(QRegExp("\\s+"),tr( "INF_VERSION" )); myVersionEdit->setText(aList.last()); - QDoubleValidator *validator = new QDoubleValidator(myVersionEdit); - myVersionEdit->setValidator(validator); myPngEdit = new QLineEdit(supplGrp , "myCompIcon" ); myPngEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); @@ -396,7 +394,7 @@ void ToolsGUI_CatalogGeneratorDlg::onApply() else { QString command = ""; if ( getenv("KERNEL_ROOT_DIR") ) - command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser " + IDLpath + " -Wbcatalog=" + XmlFile; + command = QString( getenv( "KERNEL_ROOT_DIR" ) ) + "/bin/salome/runIDLparser -K " + IDLpath + " -Wbcatalog=" + XmlFile; else { QAD_MessageBox::error1( this, tr("TOOLS_ERR_ERROR"), diff --git a/src/TestContainer/SALOME_TestComponent_i.cxx b/src/TestContainer/SALOME_TestComponent_i.cxx index 0bb4fa785..cca19c31a 100644 --- a/src/TestContainer/SALOME_TestComponent_i.cxx +++ b/src/TestContainer/SALOME_TestComponent_i.cxx @@ -26,10 +26,12 @@ // Module : SALOME // $Header$ +using namespace std; #include "utilities.h" #include "SALOME_TestComponent_i.hxx" #include -using namespace std; +#include +#include Engines_TestComponent_i::Engines_TestComponent_i(CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, @@ -60,6 +62,32 @@ char* Engines_TestComponent_i::Coucou(CORBA::Long L) return CORBA::string_dup(s); } +void Engines_TestComponent_i::Setenv() +{ + bool overwrite = true; + map::iterator it; + MESSAGE("set environment associated with keys in map _fieldsDict"); + for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++) + { + std::string cle((*it).first); + if ((*it).second.type()->kind() == CORBA::tk_string) + { + const char* value; + (*it).second >>= value; + int ret = setenv(cle.c_str(), value, overwrite); + MESSAGE("--- setenv: "<load_impl("SalomeTestComponent",dirn.c_str()); m1 = Engines::TestComponent::_narrow(obj); - INFOS("recup m1"); + MESSAGE("recup m1"); SCRUTE(m1->instanceName()); - INFOS("Coucou " << m1->Coucou(1L)); + + Engines::FieldsDict_var dico = new Engines::FieldsDict; + dico->length(3); + dico[0].key=CORBA::string_dup("key_0"); + dico[0].value <<="value_0"; + dico[1].key=CORBA::string_dup("key_1"); + dico[1].value <<=(CORBA::UShort)72; + dico[2].key=CORBA::string_dup("key_2"); + dico[2].value <<="value_2"; + m1->setProperties(dico); + + MESSAGE("Coucou " << m1->Coucou(1L)); + + m1->Setenv(); + + Engines::FieldsDict_var dico2 = m1->getProperties(); + for (CORBA::ULong i=0; ilength(); i++) + { + MESSAGE("dico2["< #include #include #include "SALOME_NamingService.hxx" #include "OpUtil.hxx" -using namespace std; int main (int argc, char * argv[]) { - INFOS("It's OK"); + MESSAGE("It's OK"); return 0; } diff --git a/src/Utils/Makefile.in b/src/Utils/Makefile.in index 86ebc70ef..fbbd1527f 100644 --- a/src/Utils/Makefile.in +++ b/src/Utils/Makefile.in @@ -45,7 +45,9 @@ EXPORT_HEADERS= \ Utils_ORB_INIT.hxx \ Utils_Identity.hxx \ Utils_SINGLETON.hxx \ - Utils_DESTRUCTEUR_GENERIQUE.hxx + Utils_DESTRUCTEUR_GENERIQUE.hxx \ + Utils_ExceptHandlers.hxx \ + Utils_CatchSignals.h EXPORT_PYSCRIPTS = Utils_Identity.py SALOME_utilities.py # Libraries targets @@ -55,9 +57,13 @@ LIB_SRC = OpUtil.cxx Utils_Timer.cxx duplicate.cxx \ Utils_CommException.cxx \ Utils_SALOME_Exception.cxx \ Utils_Identity.cxx Utils_ORB_INIT.cxx \ - Utils_DESTRUCTEUR_GENERIQUE.cxx + Utils_DESTRUCTEUR_GENERIQUE.cxx \ + Utils_ExceptHandlers.cxx \ + Utils_CatchSignals.cxx -LDFLAGS+= +LIB_SERVER_IDL = SALOME_Exception.idl + +LDFLAGS+= -lSALOMELocalTrace @CONCLUDE@ diff --git a/src/Utils/Utils_CatchSignals.cxx b/src/Utils/Utils_CatchSignals.cxx new file mode 100644 index 000000000..5ffc4f936 --- /dev/null +++ b/src/Utils/Utils_CatchSignals.cxx @@ -0,0 +1,236 @@ +// 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 + +#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 +#endif + +#ifdef SOLARIS +# include +# include +# include +# include +#endif + +#include +#include + +#ifdef LIN +# include +# include +#else +# ifdef SA_SIGINFO +# ifndef AIX +# include +# endif +# endif +#endif + + +#ifdef IRIX +# include +# include +#endif + +#include +//============================================================================ +//function : Handler +//purpose : univisal handler for signals +//============================================================================ +static void Handler(const int theSig ) +{ + if (myReserve) { + delete myReserve; + myReserve = NULL; + } + char aMessage[1000]; + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif +#if defined __GNUC_2__ + const char* message = "La fonction strsignal n'est pas supportée par gcc2.95.4"; + sprintf (aMessage, "%d signal cautch : %s", theSig, message); +#else + sprintf (aMessage, "%d signal cautch : %s", theSig, strsignal(theSig)); +#endif + + + MESSAGE("Utils_CatchSignal Handler :: " << aMessage ); + if(theCallBack == NULL) { + MESSAGE("Utils_CatchSignal Handler : throw std::runtime_error()"); + 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); + MESSAGE("signal "< +#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_CommException.cxx b/src/Utils/Utils_CommException.cxx index 0dae2c1bf..d4e953d86 100644 --- a/src/Utils/Utils_CommException.cxx +++ b/src/Utils/Utils_CommException.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +using namespace std; # include "Utils_CommException.hxx" CommException::CommException( void ): SALOME_Exception( "CommException" ) diff --git a/src/Utils/Utils_CorbaException.hxx b/src/Utils/Utils_CorbaException.hxx index 8bffa2d18..d785f16d1 100644 --- a/src/Utils/Utils_CorbaException.hxx +++ b/src/Utils/Utils_CorbaException.hxx @@ -45,4 +45,22 @@ throw SALOME::SALOME_Exception(ExDescription); \ } +#include +//Dump the CORBA exception type. +static ostream& operator<<(ostream& os, const CORBA::Exception& e) +{ + CORBA::Any tmp; + tmp<<= e; + CORBA::TypeCode_var tc = tmp.type(); + const char *p = tc->name(); + os<<"CORBA Exception was catch of the kind : "; + if ( *p != '\0' ) { + os<id(); + } + + return os; +} #endif diff --git a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx index 650d8dfe1..50737af05 100644 --- a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx +++ b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.cxx @@ -26,13 +26,13 @@ // Module : SALOME // $Header$ +using namespace std; void Nettoyage( void ) ; # include # include "utilities.h" # include "Utils_DESTRUCTEUR_GENERIQUE.hxx" # include -using namespace std; extern "C" { # include diff --git a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx index 5962e8e99..6cf3432c1 100644 --- a/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx +++ b/src/Utils/Utils_DESTRUCTEUR_GENERIQUE.hxx @@ -29,6 +29,7 @@ # if !defined( __DESTRUCTEUR_GENERIQUE__H__ ) # define __DESTRUCTEUR_GENERIQUE__H__ +# include # include "utilities.h" /*!\class DESTRUCTEUR_GENERIQUE_ @@ -55,16 +56,12 @@ class DESTRUCTEUR_GENERIQUE_ { public : - virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor - static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions - virtual void operator()( void )=0 ;//!< performs the destruction + virtual ~DESTRUCTEUR_GENERIQUE_() {}//!< virtual destructor + static const int Ajout( DESTRUCTEUR_GENERIQUE_ &objet );//!< adds a destruction object to the list of destructions + virtual void operator()( void )=0 ;//!< performs the destruction } ; - - - - /*!\class DESTRUCTEUR_DE_ * * Purpose @@ -87,49 +84,48 @@ public : * destruction to be performed at the end of the process. * */ - template class DESTRUCTEUR_DE_ : public DESTRUCTEUR_GENERIQUE_ { public : + /* Programs the destruction at the end of the process, of the object objet. + This method records in _PtrObjet the address of an object to be destroyed + at the end of the process + */ + DESTRUCTEUR_DE_(TYPE &objet): + _PtrObjet( &objet ) + { + ASSERT(DESTRUCTEUR_GENERIQUE_::Ajout( *this ) >= 0) ; + } + + /* Performs the destruction of the object. + This method really destroys the object pointed by _PtrObjet. + It should be called at the end of the process (i.e. at exit). + */ + virtual void operator()(void){ + typedef PortableServer::ServantBase TServant; + if(_PtrObjet){ + if(TServant* aServant = dynamic_cast(_PtrObjet)){ + MESSAGE("deleting ServantBase's _PtrObjet"); + PortableServer::POA_var aPOA = aServant->_default_POA(); + PortableServer::ObjectId_var anObjectId = aPOA->servant_to_id(aServant); + aPOA->deactivate_object(anObjectId.in()); + aServant->_remove_ref(); + }else{ + MESSAGE("deleting _PtrObjet"); + TYPE* aPtr = static_cast(_PtrObjet); + delete aPtr; + } + _PtrObjet = NULL ; + } + } + + virtual ~DESTRUCTEUR_DE_(){ + ASSERT(!_PtrObjet) ; + } - inline DESTRUCTEUR_DE_( TYPE &objet ); //! programs the destruction at the end of the process, of the object objet - virtual void operator()( void ) ; //!< performs the destruction of the object - virtual ~DESTRUCTEUR_DE_() ; private : - const TYPE *_PtrObjet ; -} ; - - + TYPE *_PtrObjet ; +}; - - -/*! -This method records in _PtrObjet the address of an object to be destroyed at the end of the process -*/ -template DESTRUCTEUR_DE_::DESTRUCTEUR_DE_( TYPE &objet ): _PtrObjet( &objet ) -{ - int k = DESTRUCTEUR_GENERIQUE_::Ajout( *this ) ; - ASSERT(k>=0) ; -} - -template DESTRUCTEUR_DE_::~DESTRUCTEUR_DE_() -{ - ASSERT(_PtrObjet==NULL) ; -} - -/*! -This method really destroys the object pointed by _PtrObjet. It should be called at the end of the process -(i.e. at exit). -*/ -template void DESTRUCTEUR_DE_::operator()( void ) -{ - if ( _PtrObjet ) - { - MESSAGE("deleting _PtrObjet") ; - delete (TYPE*)_PtrObjet ; - _PtrObjet = NULL ; - } -} - # endif /* # if !defined( __SINGLETON__H__ ) */ diff --git a/src/Utils/Utils_ExceptHandlers.cxx b/src/Utils/Utils_ExceptHandlers.cxx new file mode 100644 index 000000000..4037ebd8c --- /dev/null +++ b/src/Utils/Utils_ExceptHandlers.cxx @@ -0,0 +1,21 @@ +// File: Utils_ExceptHandler.cxx +// Created: Mon Mar 15 10:23:41 2004 +// Author: Oksana TCHEBANOVA +// + + +#include +#include "Utils_CorbaException.hxx" +#include "Utils_SALOME_Exception.hxx" +#include +#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 index 000000000..55558245e --- /dev/null +++ b/src/Utils/Utils_ExceptHandlers.hxx @@ -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 +#include + +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/Utils/Utils_ORB_INIT.cxx b/src/Utils/Utils_ORB_INIT.cxx index c91a525e6..5ac639246 100644 --- a/src/Utils/Utils_ORB_INIT.cxx +++ b/src/Utils/Utils_ORB_INIT.cxx @@ -28,6 +28,7 @@ # include "Utils_ORB_INIT.hxx" # include "utilities.h" +using namespace std; ORB_INIT::ORB_INIT( void ): _orb( CORBA::ORB::_nil() ) { @@ -48,24 +49,27 @@ ORB_INIT::~ORB_INIT() CORBA::ORB_var &ORB_INIT::operator() ( int argc , char **argv ) throw( CommException ) { - if ( CORBA::is_nil( _orb ) ) - { - try - { + try { + if ( CORBA::is_nil( _orb ) ) + { + try + { #if OMNIORB_VERSION >= 4 - const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } }; - _orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ; + const char* options[][2] = { { "giopMaxMsgSize", "104857600" }, { 0, 0 } }; + _orb = CORBA::ORB_init( argc , argv , "omniORB4", options) ; #else - _orb = CORBA::ORB_init( argc , argv ) ; - //set GIOP message size equal to 50Mb for transferring brep shapes as - //sequence of bytes using C++ streams - omniORB::MaxMessageSize(100*1024*1024); + _orb = CORBA::ORB_init( argc , argv ) ; + //set GIOP message size equal to 50Mb for transferring brep shapes as + //sequence of bytes using C++ streams + omniORB::MaxMessageSize(100*1024*1024); #endif - } - catch( const CORBA::Exception &ex ) - { - throw CommException( "Unable to create an ORB connexion" ) ; - } - } - return _orb ; + } + catch( const CORBA::Exception &ex ) + { + throw CommException( "Unable to create an ORB connexion" ) ; + } + } + return _orb ; + } catch ( CommException& e) {throw e;} + catch (...) { throw CommException( "ORB_INIT::operator() : Unknown exception was caught" ) ;} } diff --git a/src/Utils/Utils_ORB_INIT.hxx b/src/Utils/Utils_ORB_INIT.hxx index 2bcccf0a7..1a5c822db 100644 --- a/src/Utils/Utils_ORB_INIT.hxx +++ b/src/Utils/Utils_ORB_INIT.hxx @@ -47,7 +47,7 @@ private : public : ORB_INIT( void ); - ~ORB_INIT(); + virtual ~ORB_INIT(); CORBA::ORB_var & operator() ( int argc , char **argv ) throw( CommException ) ; inline CORBA::ORB_var &orb( void ); diff --git a/src/Utils/Utils_SALOME_Exception.cxx b/src/Utils/Utils_SALOME_Exception.cxx index d91ca119f..8f26985a1 100644 --- a/src/Utils/Utils_SALOME_Exception.cxx +++ b/src/Utils/Utils_SALOME_Exception.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +using namespace std; #include #include "Utils_SALOME_Exception.hxx" #include "utilities.h" @@ -33,9 +34,9 @@ extern "C" { #include #include +#include } -#include -using namespace std; + const char* duplicate( const char *const str ) ; @@ -47,7 +48,7 @@ SALOME_Exception::SALOME_Exception( void ): exception() , _text(0) -char *makeText( const char *text, const char *fileName, const unsigned int lineNumber ) +const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber ) { char *newText = 0 ; @@ -88,14 +89,15 @@ SALOME_Exception::~SALOME_Exception() throw () { if ( _text ) { - delete [] _text ; - _text = NULL; + delete [] _text ; + _text = 0 ; } + ASSERT(_text==NULL) ; } -SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text((char*)duplicate(ex._text)) +SALOME_Exception::SALOME_Exception( const SALOME_Exception &ex ): _text(duplicate(ex._text)) { ; } diff --git a/src/Utils/Utils_SALOME_Exception.hxx b/src/Utils/Utils_SALOME_Exception.hxx index a60f61d1c..9202df72e 100644 --- a/src/Utils/Utils_SALOME_Exception.hxx +++ b/src/Utils/Utils_SALOME_Exception.hxx @@ -31,18 +31,19 @@ # include # include + using namespace std; # define LOCALIZED(message) #message , __FILE__ , __LINE__ -class SALOME_Exception : public std::exception +class SALOME_Exception : public exception { private : SALOME_Exception( void ); protected : - char* _text ; // pointeur + const char* _text ; // non constant pointer but read only char variable public : SALOME_Exception( const char *text, const char *fileName=0, const unsigned int lineNumber=0 ); diff --git a/src/Utils/Utils_Timer.cxx b/src/Utils/Utils_Timer.cxx index 82dd013f1..c2748f6ec 100644 --- a/src/Utils/Utils_Timer.cxx +++ b/src/Utils/Utils_Timer.cxx @@ -25,7 +25,7 @@ // Module : SALOME # include "Utils_Timer.hxx" -# include +# include using namespace std; static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone)); diff --git a/src/Utils/utilities.h b/src/Utils/utilities.h index f8b86b71e..1cf18d27a 100644 --- a/src/Utils/utilities.h +++ b/src/Utils/utilities.h @@ -33,6 +33,7 @@ #include #include +#include #include "SALOME_Log.hxx" /* --- INFOS is always defined (without _DEBUG_): to be used for warnings, with release version --- */ @@ -82,7 +83,7 @@ #define HERE {cout< +#include +#include +#include +#include +#include +#include + +using namespace std; + +#ifdef _DEBUG_ +static int MYDEBUG = 1; +#else +static int MYDEBUG = 0; +#endif + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#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 = "<GetNumberOfCells() = "<GetNumberOfCells()); + MESSAGE("Execute - myCellTypes.size() = "<GetNumberOfCells() = "<GetNumberOfCells()); + if(myStoreMapping){ + MESSAGE("Execute - myOut2InId.size() = "< #include +#ifdef _DEBUG_ +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#else +static int MYDEBUG = 0; +static int MYDEBUGWITHFILES = 0; +#endif + +#if defined __GNUC__ + #if __GNUC__ == 2 + #define __GNUC_2__ + #endif +#endif + vtkCxxRevisionMacro(SALOME_GeometryFilter, "$Revision$"); vtkStandardNewMacro(SALOME_GeometryFilter); -SALOME_GeometryFilter::SALOME_GeometryFilter(): myShowInside(0) +SALOME_GeometryFilter::SALOME_GeometryFilter(): + myShowInside(0), + myStoreMapping(0) {} + SALOME_GeometryFilter::~SALOME_GeometryFilter() {} + void SALOME_GeometryFilter::Execute() { vtkDataSet *input= this->GetInput(); @@ -71,6 +89,34 @@ void SALOME_GeometryFilter::Execute() vtkGeometryFilter::Execute(); } + +void SALOME_GeometryFilter::SetStoreMapping(int theStoreMapping){ + myStoreMapping = theStoreMapping; + this->Modified(); +} + + +vtkIdType SALOME_GeometryFilter::GetObjId(int theVtkID){ + if(myVTK2ObjIds.empty() || theVtkID > myVTK2ObjIds.size()) return -1; +#if defined __GNUC_2__ + return myVTK2ObjIds[theVtkID]; +#else + return myVTK2ObjIds.at(theVtkID); +#endif +} + + +SALOME_GeometryFilter::TVectorId SALOME_GeometryFilter::GetVtkId(int theObjID){ + TVectorId aVect; + if(myObj2VTKIds.empty() || theObjID > myObj2VTKIds.size()) return aVect; +#if defined __GNUC_2__ + return myObj2VTKIds[theObjID]; +#else + return myObj2VTKIds.at(theObjID); +#endif +} + + void SALOME_GeometryFilter::UnstructuredGridExecute() { vtkUnstructuredGrid *input= (vtkUnstructuredGrid *)this->GetInput(); @@ -95,7 +141,7 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() vtkIdType newCellId; int faceId, *faceVerts, numFacePts; float *x; - int PixelConvert[4]; + int PixelConvert[4], aNewPts[VTK_CELL_SIZE]; // ghost cell stuff unsigned char updateLevel = (unsigned char)(output->GetUpdateGhostLevel()); unsigned char *cellGhostLevels = 0; @@ -150,14 +196,15 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() outputCD->CopyAllocate(cd,numCells,numCells/2); - Verts = vtkCellArray::New(); - Verts->Allocate(numCells/4+1,numCells); - Lines = vtkCellArray::New(); - Lines->Allocate(numCells/4+1,numCells); - Polys = vtkCellArray::New(); - Polys->Allocate(numCells/4+1,numCells); - Strips = vtkCellArray::New(); - Strips->Allocate(numCells/4+1,numCells); + output->Allocate(numCells/4+1,numCells); + //Verts = vtkCellArray::New(); + //Verts->Allocate(numCells/4+1,numCells); + //Lines = vtkCellArray::New(); + //Lines->Allocate(numCells/4+1,numCells); + //Polys = vtkCellArray::New(); + //Polys->Allocate(numCells/4+1,numCells); + //Strips = vtkCellArray::New(); + //Strips->Allocate(numCells/4+1,numCells); // Loop over the cells determining what's visible if (!allVisible) @@ -195,6 +242,11 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() // Loop over all cells now that visibility is known // (Have to compute visibility first for 3D cell boundarys) int progressInterval = numCells/20 + 1; + if(myStoreMapping){ + myVTK2ObjIds.clear(); myObj2VTKIds.clear(); //apo + myVTK2ObjIds.reserve(numCells); + myObj2VTKIds.resize(numCells); + } for (cellId=0, Connectivity->InitTraversal(); Connectivity->GetNextCell(npts,pts); cellId++) @@ -216,45 +268,62 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() { //special code for nonlinear cells - rarely occurs, so right now it //is slow. - switch (input->GetCellType(cellId)) + vtkIdType aCellType = input->GetCellType(cellId); + switch (aCellType) { case VTK_EMPTY_CELL: break; case VTK_VERTEX: case VTK_POLY_VERTEX: - newCellId = Verts->InsertNextCell(npts,pts); + newCellId = output->InsertNextCell(aCellType,npts,pts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); break; case VTK_LINE: case VTK_POLY_LINE: - newCellId = Lines->InsertNextCell(npts,pts); + newCellId = output->InsertNextCell(VTK_LINE,npts,pts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); break; case VTK_TRIANGLE: case VTK_QUAD: case VTK_POLYGON: - newCellId = Polys->InsertNextCell(npts,pts); + newCellId = output->InsertNextCell(aCellType,npts,pts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); break; case VTK_TRIANGLE_STRIP: - newCellId = Strips->InsertNextCell(npts,pts); + newCellId = output->InsertNextCell(aCellType,npts,pts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); break; case VTK_PIXEL: - newCellId = Polys->InsertNextCell(npts); - for ( i=0; i < npts; i++) - { - Polys->InsertCellPoint(pts[PixelConvert[i]]); - } - outputCD->CopyData(cd,cellId,newCellId); + newCellId = output->InsertNextCell(aCellType,npts,pts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } + outputCD->CopyData(cd,cellId,newCellId); break; - case VTK_TETRA: + case VTK_TETRA: { for (faceId = 0; faceId < 4; faceId++) { faceIds->Reset(); @@ -263,21 +332,26 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); numFacePts = 3; + aCellType = VTK_TRIANGLE; input->GetCellNeighbors(cellId, faceIds, cellIds); if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { - newCellId = Polys->InsertNextCell(numFacePts); for ( i=0; i < numFacePts; i++) { - Polys->InsertCellPoint(pts[faceVerts[i]]); + aNewPts[i] = pts[faceVerts[i]]; } + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); } } break; - - case VTK_VOXEL: + } + case VTK_VOXEL: { for (faceId = 0; faceId < 6; faceId++) { faceIds->Reset(); @@ -287,21 +361,26 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[2]]); faceIds->InsertNextId(pts[faceVerts[3]]); numFacePts = 4; + aCellType = VTK_QUAD; input->GetCellNeighbors(cellId, faceIds, cellIds); if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { - newCellId = Polys->InsertNextCell(numFacePts); for ( i=0; i < numFacePts; i++) { - Polys->InsertCellPoint(pts[faceVerts[PixelConvert[i]]]); + aNewPts[i] = pts[faceVerts[PixelConvert[i]]]; } + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); } } break; - - case VTK_HEXAHEDRON: + } + case VTK_HEXAHEDRON: { for (faceId = 0; faceId < 6; faceId++) { faceIds->Reset(); @@ -311,21 +390,26 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[2]]); faceIds->InsertNextId(pts[faceVerts[3]]); numFacePts = 4; + aCellType = VTK_QUAD; input->GetCellNeighbors(cellId, faceIds, cellIds); if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { - newCellId = Polys->InsertNextCell(numFacePts); for ( i=0; i < numFacePts; i++) { - Polys->InsertCellPoint(pts[faceVerts[i]]); + aNewPts[i] = pts[faceVerts[i]]; } + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); } } break; - - case VTK_WEDGE: + } + case VTK_WEDGE: { for (faceId = 0; faceId < 5; faceId++) { faceIds->Reset(); @@ -334,26 +418,32 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); numFacePts = 3; + aCellType = VTK_TRIANGLE; if (faceVerts[3] >= 0) { faceIds->InsertNextId(pts[faceVerts[3]]); numFacePts = 4; + aCellType = VTK_QUAD; } input->GetCellNeighbors(cellId, faceIds, cellIds); if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { - newCellId = Polys->InsertNextCell(numFacePts); for ( i=0; i < numFacePts; i++) { - Polys->InsertCellPoint(pts[faceVerts[i]]); + aNewPts[i] = pts[faceVerts[i]]; } + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); } } break; - - case VTK_PYRAMID: + } + case VTK_PYRAMID: { for (faceId = 0; faceId < 5; faceId++) { faceIds->Reset(); @@ -362,104 +452,70 @@ void SALOME_GeometryFilter::UnstructuredGridExecute() faceIds->InsertNextId(pts[faceVerts[1]]); faceIds->InsertNextId(pts[faceVerts[2]]); numFacePts = 3; + aCellType = VTK_TRIANGLE; if (faceVerts[3] >= 0) { faceIds->InsertNextId(pts[faceVerts[3]]); numFacePts = 4; + aCellType = VTK_QUAD; } input->GetCellNeighbors(cellId, faceIds, cellIds); if ( cellIds->GetNumberOfIds() <= 0 || myShowInside == 1 || (!allVisible && !cellVis[cellIds->GetId(0)]) ) { - newCellId = Polys->InsertNextCell(numFacePts); for ( i=0; i < numFacePts; i++) { - Polys->InsertCellPoint(pts[faceVerts[i]]); + aNewPts[i] = pts[faceVerts[i]]; } + newCellId = output->InsertNextCell(aCellType,numFacePts,aNewPts); + if(myStoreMapping){ + myVTK2ObjIds.push_back(cellId); //apo + myObj2VTKIds[cellId].push_back(newCellId); + } outputCD->CopyData(cd,cellId,newCellId); } } break; - + } //Quadratic cells case VTK_QUADRATIC_EDGE: case VTK_QUADRATIC_TRIANGLE: case VTK_QUADRATIC_QUAD: case VTK_QUADRATIC_TETRA: case VTK_QUADRATIC_HEXAHEDRON: - { - vtkGenericCell *cell = vtkGenericCell::New(); - input->GetCell(cellId,cell); - vtkIdList *pts = vtkIdList::New(); - vtkPoints *coords = vtkPoints::New(); - vtkIdList *cellIds = vtkIdList::New(); - vtkIdType newCellId; - - if ( cell->GetCellDimension() == 1 ) - { - cell->Triangulate(0,pts,coords); - for (i=0; i < pts->GetNumberOfIds(); i+=2) - { - newCellId = Lines->InsertNextCell(2); - Lines->InsertCellPoint(pts->GetId(i)); - Lines->InsertCellPoint(pts->GetId(i+1)); - outputCD->CopyData(cd,cellId,newCellId); - } - } - else if ( cell->GetCellDimension() == 2 ) - { - cell->Triangulate(0,pts,coords); - for (i=0; i < pts->GetNumberOfIds(); i+=3) - { - newCellId = Lines->InsertNextCell(2); - Polys->InsertCellPoint(pts->GetId(i)); - Polys->InsertCellPoint(pts->GetId(i+1)); - Polys->InsertCellPoint(pts->GetId(i+2)); - outputCD->CopyData(cd,cellId,newCellId); - } - } - else //3D nonlinear cell - { - vtkCell *face; - for (int j=0; j < cell->GetNumberOfFaces(); j++) - { - face = cell->GetFace(j); - input->GetCellNeighbors(cellId, face->PointIds, cellIds); - if ( cellIds->GetNumberOfIds() <= 0) - { - face->Triangulate(0,pts,coords); - for (i=0; i < pts->GetNumberOfIds(); i+=3) - { - newCellId = Lines->InsertNextCell(2); - Polys->InsertCellPoint(pts->GetId(i)); - Polys->InsertCellPoint(pts->GetId(i+1)); - Polys->InsertCellPoint(pts->GetId(i+2)); - outputCD->CopyData(cd,cellId,newCellId); - } - } - } - } //3d cell - cellIds->Delete(); - coords->Delete(); - pts->Delete(); - cell->Delete(); - } + break; //done with quadratic cells } //switch } //if visible } //for all cells + if(MYDEBUG && myStoreMapping){ + for(int i = 0, iEnd = myVTK2ObjIds.size(); i < iEnd; i++){ + cout<SetVerts(Verts); - Verts->Delete(); - output->SetLines(Lines); - Lines->Delete(); - output->SetPolys(Polys); - Polys->Delete(); - output->SetStrips(Strips); - Strips->Delete(); + //output->SetVerts(Verts); + //Verts->Delete(); + //output->SetLines(Lines); + //Lines->Delete(); + //output->SetPolys(Polys); + //Polys->Delete(); + //output->SetStrips(Strips); + //Strips->Delete(); output->Squeeze(); diff --git a/src/VTKFilter/SALOME_GeometryFilter.h b/src/VTKFilter/SALOME_GeometryFilter.h index f6edf6b78..bce9d27d7 100644 --- a/src/VTKFilter/SALOME_GeometryFilter.h +++ b/src/VTKFilter/SALOME_GeometryFilter.h @@ -24,13 +24,14 @@ // File : SALOME_GeometryFilter.h // Author : Michael ZORIN // Module : SALOME -// $Header: /dn05/salome/CVS/SALOME_ROOT/SALOME/src/OBJECT/SALOME_GeometryFilter.h +// $Header$ #ifndef __SALOME_GeometryFilter_h #define __SALOME_GeometryFilter_h #include +#include class SALOME_GeometryFilter : public vtkGeometryFilter { @@ -40,6 +41,13 @@ public: void SetInside(int theShowInside); int GetInside(); + void SetStoreMapping(int theStoreMapping); + int GetStoreMapping(){ return myStoreMapping;} + + typedef std::vector TVectorId; + virtual vtkIdType GetObjId(int theVtkID); + virtual TVectorId GetVtkId(int theObjID); + protected: SALOME_GeometryFilter(); ~SALOME_GeometryFilter(); @@ -48,7 +56,12 @@ protected: void UnstructuredGridExecute(); private: - int myShowInside; + int myShowInside; + + int myStoreMapping; + TVectorId myVTK2ObjIds; + typedef std::vector TVecVectorId; + TVecVectorId myObj2VTKIds; }; #endif diff --git a/src/VTKFilter/SALOME_PassThroughFilter.cxx b/src/VTKFilter/SALOME_PassThroughFilter.cxx index 3557b6259..f1ee7c5e9 100644 --- a/src/VTKFilter/SALOME_PassThroughFilter.cxx +++ b/src/VTKFilter/SALOME_PassThroughFilter.cxx @@ -27,65 +27,31 @@ #include "SALOME_PassThroughFilter.h" -#include "SALOME_GeometryFilter.h" +#include +#include #include -#include #include -#include -#include -#include - -using namespace std; +vtkCxxRevisionMacro(SALOME_PassThroughFilter, "$Revision$"); vtkStandardNewMacro(SALOME_PassThroughFilter); -SALOME_PassThroughFilter::SALOME_PassThroughFilter(){ - this->vtkProcessObject::SetNthInput(0, NULL); - myGeomFilter = SALOME_GeometryFilter::New(); -} - -SALOME_PassThroughFilter::~SALOME_PassThroughFilter(){ - myGeomFilter->Delete(); -} - -void SALOME_PassThroughFilter::Execute(){ +void SALOME_PassThroughFilter::Execute() +{ vtkDataSet *input = static_cast(this->GetInput()); vtkDataSet *output = static_cast(this->GetOutput()); + + // This has to be here because it initialized all field datas. output->CopyStructure( input ); + + // Pass all. (data object's field data is passed by the + // superclass after this method) output->GetPointData()->PassData( input->GetPointData() ); output->GetCellData()->PassData( input->GetCellData() ); -} - -void SALOME_PassThroughFilter::SetInput(vtkDataSet *input){ - myGeomFilter->SetInput(input); - vtkDataSet *oldInput = this->GetInput(); - if(oldInput != NULL) - if(input == NULL || oldInput->GetDataObjectType() != input->GetDataObjectType()){ - vtkWarningMacro("Changing input type. Deleting output"); - this->SetOutput(NULL); - } - if (input != NULL && this->vtkSource::GetOutput(0) == NULL){ - this->vtkSource::SetNthOutput(0, input->NewInstance()); - this->Outputs[0]->ReleaseData(); - this->Outputs[0]->Delete(); - } - this->vtkProcessObject::SetNthInput(0, input); } -vtkPolyData *SALOME_PassThroughFilter::GetPolyDataOutput() { - vtkDataSet *ds = this->GetOutput(); - if(!ds) return NULL; - if(ds->GetDataObjectType() == VTK_POLY_DATA) return (vtkPolyData *)ds; - myGeomFilter->SetInput(this->GetOutput()); - return myGeomFilter->GetOutput(); -} - -void SALOME_PassThroughFilter::SetInside(int theShowInside){ - myGeomFilter->SetInside(theShowInside); - Modified(); -} -int SALOME_PassThroughFilter::GetInside(){ - return myGeomFilter->GetInside(); +void SALOME_PassThroughFilter::PrintSelf(ostream& os, vtkIndent indent) +{ + this->Superclass::PrintSelf(os,indent); } diff --git a/src/VTKFilter/SALOME_PassThroughFilter.h b/src/VTKFilter/SALOME_PassThroughFilter.h index 51e1124e5..bc625a8d3 100644 --- a/src/VTKFilter/SALOME_PassThroughFilter.h +++ b/src/VTKFilter/SALOME_PassThroughFilter.h @@ -31,27 +31,25 @@ #include -class SALOME_GeometryFilter; - -class SALOME_PassThroughFilter : public vtkDataSetToDataSetFilter{ - public: - vtkTypeMacro(SALOME_PassThroughFilter,vtkDataSetToDataSetFilter); +class SALOME_PassThroughFilter : public vtkDataSetToDataSetFilter +{ +public: + vtkTypeRevisionMacro(SALOME_PassThroughFilter,vtkDataSetToDataSetFilter); + void PrintSelf(ostream& os, vtkIndent indent); + + // Description: + // Create a new SALOME_PassThroughFilter. static SALOME_PassThroughFilter *New(); - void SetInput(vtkDataSet *input); - vtkPolyData *GetPolyDataOutput(); - void SetInside(int theShowInside); - int GetInside(); +protected: - protected: - SALOME_PassThroughFilter(); - virtual ~SALOME_PassThroughFilter(); - void Execute(); + SALOME_PassThroughFilter() {}; + virtual ~SALOME_PassThroughFilter() {}; - SALOME_GeometryFilter* myGeomFilter; + void Execute(); - private: +private: SALOME_PassThroughFilter(const SALOME_PassThroughFilter&); // Not implemented. void operator=(const SALOME_PassThroughFilter&); // Not implemented. }; diff --git a/src/VTKFilter/SALOME_TransformFilter.cxx b/src/VTKFilter/SALOME_TransformFilter.cxx index de1459387..a7b1b2bc5 100644 --- a/src/VTKFilter/SALOME_TransformFilter.cxx +++ b/src/VTKFilter/SALOME_TransformFilter.cxx @@ -48,24 +48,22 @@ void SALOME_TransformFilter::Execute(){ vtkPointData *pd=input->GetPointData(), *outPD=output->GetPointData(); vtkCellData *cd=input->GetCellData(), *outCD=output->GetCellData(); output->CopyStructure( input ); - int anIdentity = 0; - if(SALOME_Transform* aTransform = dynamic_cast(this->Transform)) - anIdentity = aTransform->IsIdentity(); - if(!anIdentity && this->Transform != NULL){ + if(Transform){ + bool anIsIdentity = true; + if(SALOME_Transform* aTransform = dynamic_cast(Transform)) + anIsIdentity = aTransform->IsIdentity(); inPts = input->GetPoints(); - if(!inPts){ - vtkErrorMacro(<<"No input data"); - return; + if(!anIsIdentity && inPts){ + numPts = inPts->GetNumberOfPoints(); + numCells = input->GetNumberOfCells(); + newPts = vtkPoints::New(); + newPts->Allocate(numPts); + this->UpdateProgress(.2); + this->Transform->TransformPoints(inPts,newPts); + this->UpdateProgress(.8); + output->SetPoints(newPts); + newPts->Delete(); } - numPts = inPts->GetNumberOfPoints(); - numCells = input->GetNumberOfCells(); - newPts = vtkPoints::New(); - newPts->Allocate(numPts); - this->UpdateProgress(.2); - this->Transform->TransformPoints(inPts,newPts); - this->UpdateProgress(.8); - output->SetPoints(newPts); - newPts->Delete(); } outPD->PassData(pd); outCD->PassData(cd); diff --git a/src/VTKViewer/Makefile.in b/src/VTKViewer/Makefile.in index 0733c58b9..40ca16b52 100644 --- a/src/VTKViewer/Makefile.in +++ b/src/VTKViewer/Makefile.in @@ -38,7 +38,8 @@ VPATH=.:@srcdir@:$(top_builddir)/inc:$(top_builddir)/idl EXPORT_HEADERS= VTKViewer_RenderWindow.h \ VTKViewer_ViewFrame.h \ VTKViewer_RenderWindowInteractor.h \ - VTKViewer_InteractorStyleSALOME.h + VTKViewer_InteractorStyleSALOME.h \ + VTKViewer_Filter.h # Libraries targets LIB = libVTKViewer.la @@ -49,7 +50,10 @@ LIB_SRC= VTKViewer.cxx \ VTKViewer_InteractorStyleSALOME.cxx \ VTKViewer_Trihedron.cxx \ VTKViewer_VectorText.cxx \ - VTKViewer_Utilities.cxx + VTKViewer_RectPicker.cxx \ + VTKViewer_CellRectPicker.cxx \ + VTKViewer_Utilities.cxx \ + VTKViewer_Filter.cxx LIB_MOC = \ VTKViewer.h \ diff --git a/src/VTKViewer/VTKViewer.cxx b/src/VTKViewer/VTKViewer.cxx index a0c60854e..796028060 100644 --- a/src/VTKViewer/VTKViewer.cxx +++ b/src/VTKViewer/VTKViewer.cxx @@ -26,9 +26,9 @@ // Module : SALOME // $Header$ +using namespace std; #include "VTKViewer.h" #include "VTKViewer_ViewFrame.h" -using namespace std; QAD_ViewFrame* VTKViewer::createView(QAD_RightFrame* parent) { diff --git a/src/VTKViewer/VTKViewer_CellRectPicker.cxx b/src/VTKViewer/VTKViewer_CellRectPicker.cxx new file mode 100644 index 000000000..6e05537cd --- /dev/null +++ b/src/VTKViewer/VTKViewer_CellRectPicker.cxx @@ -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 + +#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 = (d1Points->GetNumberOfPoints(); k++) { + p = tcell->Points->GetPoint(k); + vtkPlane::GeneralizedProjectPoint(p, orig, dir, pp); + if (PointInside(pp, aPoints)) { + result = 1; break; + } + } + if (result && d2Delete(); + 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 index 000000000..76b0b8c40 --- /dev/null +++ b/src/VTKViewer/VTKViewer_CellRectPicker.h @@ -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 +#include + +typedef struct { + vtkIdType cellId; + int subId; + float depth; + float p1[3]; + float p2[3]; +} VTKViewer_CellData; + +typedef std::vector VTKViewer_CellDataSet; +typedef std::map 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 index 000000000..8c09a46c4 --- /dev/null +++ b/src/VTKViewer/VTKViewer_Filter.cxx @@ -0,0 +1,57 @@ +// VTKViewer_Filter : Filter for VTK viewer +// +// 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_Filter.cxx +// Author : Sergey LITONIN +// Module : SALOME + +#include "VTKViewer_Filter.h" + +IMPLEMENT_STANDARD_HANDLE(VTKViewer_Filter, MMgt_TShared) +IMPLEMENT_STANDARD_RTTIEXT(VTKViewer_Filter, MMgt_TShared) + +/* + Class : VTKViewer_Filter + Description : Base class of filters of for VTK viewer. Method IsValid + should be redefined in derived classes +*/ + +VTKViewer_Filter::VTKViewer_Filter() +{ + myActor = 0; +} + +VTKViewer_Filter::~VTKViewer_Filter() +{ +} + +bool VTKViewer_Filter::IsValid( SALOME_Actor* theActor, const int theCellId ) +{ + SetActor( theActor ); + return IsValid( theCellId ); +} + +void VTKViewer_Filter::SetActor( SALOME_Actor* theActor ) +{ + myActor = theActor; +} diff --git a/src/VTKViewer/VTKViewer_Filter.h b/src/VTKViewer/VTKViewer_Filter.h new file mode 100755 index 000000000..d9d9831a8 --- /dev/null +++ b/src/VTKViewer/VTKViewer_Filter.h @@ -0,0 +1,64 @@ +// SMESHGUI_Filter : Filter for VTK viewer +// +// 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_Filter.h +// Author : Sergey LITONIN +// Module : SALOME + +#ifndef VTKViewer_Filter_HeaderFile +#define VTKViewer_Filter_HeaderFile + +#include +#include + +class SALOME_Actor; + +DEFINE_STANDARD_HANDLE(VTKViewer_Filter, MMgt_TShared) + +/* + Class : VTKViewer_Filter + Description : Base class of filters of for VTK viewer. Method IsValid + should be redefined in derived classes +*/ + +class VTKViewer_Filter : public MMgt_TShared +{ + +public: + VTKViewer_Filter(); + virtual ~VTKViewer_Filter(); + + bool IsValid( SALOME_Actor*, const int theCellId ); + virtual bool IsValid( const int theCellId ) const = 0; + + virtual void SetActor( SALOME_Actor* ); + +protected: + + SALOME_Actor* myActor; + +public: + DEFINE_STANDARD_RTTI(VTKViewer_Filter) +}; + +#endif diff --git a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx index 329e055ac..d7cbfb5c2 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx +++ b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.cxx @@ -27,9 +27,12 @@ // $Header$ #include "VTKViewer_InteractorStyleSALOME.h" +#include "VTKViewer_RenderWindowInteractor.h" #include "VTKViewer_RenderWindow.h" #include "VTKViewer_Utilities.h" #include "VTKViewer_Trihedron.h" +#include "VTKViewer_RectPicker.h" +#include "VTKViewer_CellRectPicker.h" #include "QAD_Config.h" #include "QAD_Application.h" @@ -52,7 +55,6 @@ #include #include #include -#include #include //VRV: porting on Qt 3.0.5 @@ -60,6 +62,9 @@ #include #endif //VRV: porting on Qt 3.0.5 +#include + +#include "utilities.h" using namespace std; @@ -78,6 +83,12 @@ VTKViewer_InteractorStyleSALOME::VTKViewer_InteractorStyleSALOME() this->RadianToDegree = 180.0 / vtkMath::Pi(); this->ForcedState = VTK_INTERACTOR_STYLE_CAMERA_NONE; loadCursors(); + + myPActor = vtkActor::New(); + myPActor->PickableOff(); + myPActor->GetProperty()->SetColor(0,1,1); + myPActor->GetProperty()->SetLineWidth(5); + myPActor->GetProperty()->SetPointSize(5); } //---------------------------------------------------------------------------- @@ -85,6 +96,15 @@ VTKViewer_InteractorStyleSALOME::~VTKViewer_InteractorStyleSALOME() { } +//---------------------------------------------------------------------------- +void VTKViewer_InteractorStyleSALOME::setPreselectionProp(const double& theRed, const double& theGreen, + const double& theBlue, const int& theWidth) +{ + myPActor->GetProperty()->SetColor(theRed, theGreen, theBlue); + myPActor->GetProperty()->SetLineWidth(theWidth); + myPActor->GetProperty()->SetPointSize(theWidth); +} + //---------------------------------------------------------------------------- void VTKViewer_InteractorStyleSALOME::setTriedron(VTKViewer_Trihedron* theTrihedron){ m_Trihedron = theTrihedron; @@ -515,8 +535,7 @@ void VTKViewer_InteractorStyleSALOME::startFitArea() void VTKViewer_InteractorStyleSALOME::ViewFitAll() { int aTriedronWasVisible = false; if(m_Trihedron){ - aTriedronWasVisible = - m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn; + aTriedronWasVisible = m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn; if(aTriedronWasVisible) m_Trihedron->VisibilityOff(); } @@ -529,6 +548,7 @@ void VTKViewer_InteractorStyleSALOME::ViewFitAll() { } if(aTriedronWasVisible) m_Trihedron->VisibilityOn(); else m_Trihedron->VisibilityOff(); + ::ResetCameraClippingRange(CurrentRenderer); } @@ -723,7 +743,7 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() // VSV: LOD actor activisation // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate()); - int aSelectionMode = aSel->SelectionMode(); + Selection_Mode aSelectionMode = aSel->SelectionMode(); bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly(); switch (State) { @@ -767,16 +787,17 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() if ( rwi->GetPicker()->IsA("vtkCellPicker") ) { vtkCellPicker* picker; if ( (picker = vtkCellPicker::SafeDownCast(rwi->GetPicker())) ) { - MESSAGE ( " CellId : " << picker->GetCellId() ); - if ( picker->GetCellId() >= 0 ) { + int aVtkId = picker->GetCellId(); + // INFOS ( " CellId : " << aVtkId ); + if ( aVtkId >= 0 ) { vtkActor* ac = picker->GetActor(); if ( ac->IsA("SALOME_Actor") ) { SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac ); - MESSAGE ( " NAME Actor : " << SActor->getName() ); + INFOS ( " NAME Actor : " << SActor->getName() << ", CellId : " << aVtkId ); - //Cell selection //////////////////////////////////// NB - if ( aSelectionMode == 3 ) { - if ( SActor->hasIO() ) { + //Cell selection /////////////////////////////// NB + if ( aSelectionMode == CellSelection ) { + if ( SActor->hasIO() && isValid( SActor, aVtkId, aSelectionMode ) ) { Handle(SALOME_InteractiveObject) IO = SActor->getIO(); // Look in the current selection SALOME_ListIteratorOfListIO It(aSel->StoredIObjects()); @@ -789,91 +810,135 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() break; } } - if(IsSelected) { - // This IO is already in the selection - //if(shift) { - bool add = aSel->AddOrRemoveIndex( IO, picker->GetCellId(), myShiftState, false ); - //Sel->RemoveIObject(IO); - //} + + int anObjId = SActor->GetObjId(aVtkId); + std::vector aVtkList; + if (anObjId != -1) { + aVtkList = SActor->GetVtkId(anObjId); + } + + if (IsSelected) { + // This IO is already in the selection + if (aVtkList.size() > 0) + bool add = aSel->AddOrRemoveIndex( IO, aVtkList, myShiftState, false ); + else + bool add = aSel->AddOrRemoveIndex( IO, aVtkId, myShiftState, false ); } else { - if(!myShiftState) { - this->HighlightProp( NULL ); - aSel->ClearIObjects(); - } - bool add = aSel->AddOrRemoveIndex( IO, picker->GetCellId(), myShiftState, false ); - aSel->AddIObject( IO, false ); + if (!myShiftState) { + this->HighlightProp( NULL ); + aSel->ClearIObjects(); + } + if (aVtkList.size() > 0) + bool add = aSel->AddOrRemoveIndex( IO, aVtkList, myShiftState, false ); + else + bool add = aSel->AddOrRemoveIndex( IO, aVtkId, myShiftState, false ); + aSel->AddIObject( IO, false ); } } } - //Edge selection ////////////////////////// NB - else if ( aSelectionMode == 2 ) { - if(SActor->hasIO()){ - Handle(SALOME_InteractiveObject) IO = SActor->getIO(); - float pickPosition[3],pcoords[3],closestPoint[3],weights[3],dist1=1000000.0,dist2=0; - int subId,edgeId=-10,pickedID,result; - pickedID = picker->GetCellId(); - picker->GetPickPosition(pickPosition); - if (vtkDataSet* UGrid = SActor->GetMapper()->GetInput()){ - if (vtkCell* pickedCell = UGrid->GetCell(pickedID)){ - edgeId = -1; - for (int i = 0, iEnd = pickedCell->GetNumberOfEdges(); i < iEnd; i++){ - vtkCell* edge = pickedCell->GetEdge(i); - if(vtkLine* line = vtkLine::SafeDownCast(edge)){ - result = line->EvaluatePosition(pickPosition,closestPoint,subId,pcoords,dist2,weights); - if (dist2 < dist1) { - dist1 = dist2; - edgeId = i; + //Edge, Face, Volume and EdgeOfCell selection ////////////////////////// NB + else if ( aSelectionMode == EdgeSelection || + aSelectionMode == FaceSelection || + aSelectionMode == VolumeSelection || + aSelectionMode == EdgeOfCellSelection ) { + if ( SActor->hasIO() && isValid( SActor, aVtkId, aSelectionMode ) ) { + Handle(SALOME_InteractiveObject) IO = SActor->getIO(); + if (vtkDataSet* UGrid = SActor->GetMapper()->GetInput()) { + if (vtkCell* pickedCell = UGrid->GetCell(aVtkId)) { + bool result = false; + int edgeId = -1; + int anObjId = SActor->GetObjId(aVtkId); + std::vector aVtkList; + if (anObjId > -1) + aVtkList = SActor->GetVtkId(anObjId); + + if (aSelectionMode == EdgeSelection) { + if ( SActor->GetObjDimension( anObjId ) == 1 ) + result = true; + } + else if ( aSelectionMode == FaceSelection ) { + if ( SActor->GetObjDimension( anObjId ) == 2 ) + result = true; + } + else if (aSelectionMode == VolumeSelection) { + if ( SActor->GetObjDimension( anObjId ) == 3 ) + result = true; + } + else { + float pickPosition[3]; + picker->GetPickPosition(pickPosition); + float distMin = 1000000.0, dist = 0; + for (int i = 0, iEnd = pickedCell->GetNumberOfEdges(); i < iEnd; i++){ + vtkCell* edge = pickedCell->GetEdge(i); + if (vtkLine* line = vtkLine::SafeDownCast(edge)){ + float pcoords[3],closestPoint[3],weights[3]; + int subId; + line->EvaluatePosition(pickPosition,closestPoint,subId,pcoords,dist,weights); + if (dist < distMin) { + distMin = dist; + edgeId = i; + } } } + if (edgeId != -1 || pickedCell->GetCellDimension() == 1) + result = true; + INFOS("edgeID transformed = "<GetPicker())) ) { - MESSAGE ( " PointId : " << picker->GetPointId() ); + INFOS ( " PointId : " << picker->GetPointId() ); if ( picker->GetPointId() >= 0 ) { vtkActor* ac = picker->GetActor(); if ( ac->IsA("SALOME_Actor") ) { SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac ); - MESSAGE ( " NAME Actor : " << SActor->getName() ); + INFOS ( " NAME Actor : " << SActor->getName() ); if ( SActor->hasIO() ) { Handle(SALOME_InteractiveObject) IO = SActor->getIO(); -/* if (IO.IsNull()) + /* + if (IO.IsNull()) break; if (aSelActiveCompOnly && - strcmp(aActiveComponent->ComponentDataType(), IO->getComponentDataType()) != 0) { + strcmp(aActiveComponent->ComponentDataType(), + IO->getComponentDataType()) != 0) { break; - }*/ + } + */ // Look in the current selection SALOME_ListIteratorOfListIO It(aSel->StoredIObjects()); Standard_Boolean IsSelected = false; @@ -949,13 +1014,13 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() } } } - rwi->EndPickCallback(); } + rwi->EndPickCallback(); } else { //processing rectangle selection - SALOMEDS::SComponent_var aActiveComponent = SALOMEDS::SComponent:: - _narrow(aActiveStudy->getStudyDocument()-> - FindObject(QAD_Application::getDesktop()->getActiveComponent())); + SALOMEDS::SComponent_var aActiveComponent = + SALOMEDS::SComponent::_narrow(aActiveStudy->getStudyDocument()-> + FindObject(QAD_Application::getDesktop()->getActiveComponent())); if(aSelActiveCompOnly && aActiveComponent->_is_nil()) return; rwi->StartPickCallback(); @@ -966,7 +1031,7 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() } // Compute bounds - vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); + // vtkCamera *cam = this->CurrentRenderer->GetActiveCamera(); QRect rect(myPoint, myOtherPoint); rect = rect.normalize(); int w, h, x, y; @@ -978,7 +1043,7 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() y2 = h - rect.bottom() - 1; switch (aSelectionMode) { - case 1: // Nodes selection + case NodeSelection: // Nodes selection { if (! rwi->GetPicker()->IsA("vtkPointPicker") ) break; vtkPointPicker* aPointPicker = vtkPointPicker::SafeDownCast(rwi->GetPicker()); @@ -999,7 +1064,8 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() if (IO.IsNull()) continue; if (aSelActiveCompOnly && - strcmp(aActiveComponent->ComponentDataType(), IO->getComponentDataType()) != 0) { + strcmp(aActiveComponent->ComponentDataType(), + IO->getComponentDataType()) != 0) { continue; } @@ -1015,6 +1081,8 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() continue; } if (aDataSet) { + + std::vector anIndices; for (int i=0; i < aDataSet->GetNumberOfPoints(); i++) { float* aPoint; aPoint = aDataSet->GetPoint(i); @@ -1024,12 +1092,21 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() aPoint[1], aPoint[2], aDisp); aPointPicker->Pick(aDisp[0], aDisp[1], 0.0, CurrentRenderer); - if ( aPointPicker->GetPointId() >= 0) { // && (!aSel->IsIndexSelected(IO, aPointPicker->GetPointId()))) { - aSel->AddOrRemoveIndex(IO, aPointPicker->GetPointId(), true, false); - aSel->AddIObject(IO, false); - } + + int pid = aPointPicker->GetPointId(); + if ( pid >= 0) { // && (!aSel->IsIndexSelected(IO, aPointPicker->GetPointId()))) { + std::vector::iterator found = + find(anIndices.begin(), anIndices.end(), pid); + if (found == anIndices.end()) + anIndices.push_back(pid); + } } } + if (!anIndices.empty()) { + aSel->AddOrRemoveIndex(IO, anIndices, true, false); + aSel->AddIObject(IO, false); + anIndices.clear(); + } } } } @@ -1037,91 +1114,140 @@ void VTKViewer_InteractorStyleSALOME::onFinishOperation() } } break; - case 2: // edges selection - case 3: // triangles selection + case CellSelection: + case EdgeOfCellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: { - aSel->SetSelectionMode(aSelectionMode,true); - if (!rwi->GetPicker()->IsA("vtkCellPicker") ) break; - vtkCellPicker* aCellPicker = vtkCellPicker::SafeDownCast(rwi->GetPicker()); - vtkActorCollection* aListActors = this->CurrentRenderer->GetActors(); - aListActors->InitTraversal(); + VTKViewer_CellRectPicker* picker = VTKViewer_CellRectPicker::New(); + picker->SetTolerance(0.001); + picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer); + + vtkActorCollection* aListActors = picker->GetActors(); vtkActor* aActor; - for (int k = 0, kEnd = aListActors->GetNumberOfItems(); k < kEnd; k++){ - vtkActor* aActor = aListActors->GetNextActor(); - if (vtkActor* aActor = aListActors->GetNextActor()){ - if (aActor->GetVisibility() == 0) continue; - if(SALOME_Actor* SActor = SALOME_Actor::SafeDownCast(aActor)) { - if(SActor->hasIO()) { - Handle(SALOME_InteractiveObject) IO = SActor->getIO(); - if(IO.IsNull()) continue; - if(aSelActiveCompOnly) { - if(strcmp(aActiveComponent->ComponentDataType(),IO->getComponentDataType()) != 0) - continue; + aListActors->InitTraversal(); + while(aActor = aListActors->GetNextActor()) { + if (aActor->IsA("SALOME_Actor")) { + SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor); + if (aSActor->hasIO()) { + Handle(SALOME_InteractiveObject) aIO = aSActor->getIO(); + // INFOS ( " NAME Object : " << aIO->getName() << " from " << aIO->getComponentDataType() ); + if (aSelActiveCompOnly && + strcmp(aActiveComponent->ComponentDataType(), + aIO->getComponentDataType()) != 0) { + continue; + } + VTKViewer_CellDataSet cellList = picker->GetCellData(aActor); + if ( !cellList.empty() ) { + INFOS ( " NAME Actor : " << aSActor->getName() ); + std::vector anIndexes; + if (aSelectionMode == CellSelection) { + VTKViewer_CellDataSet::iterator it; + for (it = cellList.begin(); it != cellList.end(); ++it) { + int aCellId = (*it).cellId; + if ( !isValid( aSActor, aCellId, aSelectionMode ) ) + continue; + + int aObjId = aSActor->GetObjId(aCellId); + std::vector aVtkList; + if ( aObjId != -1 ) + aVtkList = aSActor->GetVtkId(aObjId); + + if (aVtkList.size() > 0) { + std::vector::iterator it; + for (it = aVtkList.begin(); it != aVtkList.end(); ++it) { + std::vector::iterator found = + find(anIndexes.begin(), anIndexes.end(), *it); + if (found == anIndexes.end()) + anIndexes.push_back(*it); + } + } + else + anIndexes.push_back(aCellId); + } } - if(vtkDataSet* aDataSet = SActor->GetMapper()->GetInput()){ - for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++){ - if(vtkCell* aCell = aDataSet->GetCell(i)){ - if(IsInRect(aCell, x1, y1, x2, y2)){ - float* aBounds = aCell->GetBounds(); - float aCenter[3]; - aCenter[0] =(aBounds[0] + aBounds[1])/2; // Center X - aCenter[1] =(aBounds[2] + aBounds[3])/2; // Center Y - aCenter[2] =(aBounds[4] + aBounds[5])/2; // Center Z - float aDisp[3]; - ComputeWorldToDisplay(aCenter[0],aCenter[1],aCenter[2],aDisp); - aCellPicker->Pick(aDisp[0], aDisp[1], 0.0, CurrentRenderer); - if(aCellPicker->GetCellId() >= 0 && !aSel->IsIndexSelected(IO,aCellPicker->GetCellId())){ - aSel->AddOrRemoveIndex( IO, aCellPicker->GetCellId(), true, false); - aSel->AddIObject( IO, false ); + else { + if ( vtkDataSet* aDataSet = aSActor->GetMapper()->GetInput() ) { + VTKViewer_CellDataSet::iterator it; + for ( it = cellList.begin(); it != cellList.end(); ++it ) { + int aCellId = (*it).cellId; + + if ( !isValid( aSActor, aCellId, aSelectionMode ) ) + continue; + + int aObjId = aSActor->GetObjId(aCellId); + std::vector aVtkList; + if (aObjId != -1) + aVtkList = aSActor->GetVtkId(aObjId); + bool result = false; + if (vtkCell* aCell = aDataSet->GetCell(aCellId)) { + if ( aSelectionMode == EdgeSelection ) { + if ( aSActor->GetObjDimension( aObjId ) == 1 ) + result = true; + } + else if ( aSelectionMode == FaceSelection ) { + if ( aSActor->GetObjDimension( aObjId ) == 2 ) + result = true; + } + else if ( aSelectionMode == VolumeSelection ) { + if ( aSActor->GetObjDimension( aObjId ) == 3 ) + result = true; } } + if ( result ) { + if (aVtkList.size() > 0) { + std::vector::iterator it; + for (it = aVtkList.begin(); it != aVtkList.end(); ++it) { + std::vector::iterator found = + find(anIndexes.begin(), anIndexes.end(), *it); + if (found == anIndexes.end()) + anIndexes.push_back(*it); + } + } + else + anIndexes.push_back(aCellId); + } } } } + aSel->AddOrRemoveIndex(aIO, anIndexes, true, false); + aSel->AddIObject(aIO, false); } } } } } - break; - case 4: // objects selection + break; + case ActorSelection: // objects selection { - vtkActorCollection* aListActors = this->CurrentRenderer->GetActors(); - aListActors->InitTraversal(); + VTKViewer_RectPicker* picker = VTKViewer_RectPicker::New(); + picker->SetTolerance(0.001); + picker->Pick(x1, y1, 0.0, x2, y2, 0.0, this->CurrentRenderer); + + vtkActorCollection* aListActors = picker->GetActors(); vtkActor* aActor; SALOME_ListIO aListIO; - for (int k = 0; k < aListActors->GetNumberOfItems(); k++) { - aActor = aListActors->GetNextActor(); - if (aActor) { - if (aActor->GetVisibility() == 0) - continue; - if ( aActor->IsA("SALOME_Actor") ) { - SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor); - if ( aSActor->hasIO() && IsInRect(aSActor, x1, y1, x2, y2)) { - Handle(SALOME_InteractiveObject) aIO = aSActor->getIO(); - if (aIO.IsNull()) - continue; - if (aSelActiveCompOnly && - strcmp(aActiveComponent->ComponentDataType(), aIO->getComponentDataType()) != 0) { - continue; - } - if (aListIO.IsEmpty()) { - aListIO.Append( aIO ); - } else { - SALOME_ListIteratorOfListIO It(aListIO); - bool isStored = false; - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IOS = It.Value(); - if( aIO->isSame(IOS) ) { - aIO = IOS; //Added by SRN, fix SAL1307 - isStored = true; - break; - } + aListActors->InitTraversal(); + while(aActor = aListActors->GetNextActor()) { + if (aActor->IsA("SALOME_Actor")) { + SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(aActor); + if (aSActor->hasIO()) { + Handle(SALOME_InteractiveObject) aIO = aSActor->getIO(); + bool isStored = false; + if (!aListIO.IsEmpty()) { + SALOME_ListIteratorOfListIO It(aListIO); + for(;It.More();It.Next()) { + Handle(SALOME_InteractiveObject) IOS = It.Value(); + if( aIO->isSame(IOS) ) { + aIO = IOS; //Added by SRN, fix SAL1307 + isStored = true; + break; } - if (!isStored) - aListIO.Append( aIO ); } } + if (!isStored) + aListIO.Append(aIO); } } } @@ -1223,12 +1349,21 @@ void VTKViewer_InteractorStyleSALOME::onOperation(QPoint mousePos) this->LastPos[1] = h - mousePos.y() - 1; } +// called when selection mode changed (!put necessary initialization here!) +void VTKViewer_InteractorStyleSALOME::OnSelectionModeChanged() +{ + myPActor->VisibilityOff(); +} + // called when user moves mouse inside viewer window and there is no active viewer operation // (!put necessary processing here!) void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) { // processing highlighting - QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy(); - SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); + QAD_Study* anActiveStudy = QAD_Application::getDesktop()->getActiveStudy(); + SALOME_Selection* Sel = SALOME_Selection::Selection( anActiveStudy->getSelection() ); + + Selection_Mode aSelectionMode = Sel->SelectionMode(); + myPActor->VisibilityOff(); vtkRenderWindowInteractor *rwi = this->Interactor; int w, h, x, y; @@ -1238,8 +1373,140 @@ void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) { this->FindPokedRenderer(x,y); rwi->StartPickCallback(); rwi->GetPicker()->Pick(x, y, 0.0, this->CurrentRenderer); + + if (rwi->GetPicker()->IsA("vtkCellPicker")) { + vtkCellPicker* picker = vtkCellPicker::SafeDownCast(rwi->GetPicker()); + int aVtkId = picker->GetCellId(); + // INFOS ( " Preselected CellId : " << picker->GetCellId() ); + if ( aVtkId >= 0 ) { + vtkActor* ac = picker->GetActor(); + if ( ac->IsA("SALOME_Actor") ) { + SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac ); + // INFOS ( " NAME Actor : " << SActor->getName() ); + + if (rwi->IsA("VTKViewer_RenderWindowInteractor")) { + VTKViewer_RenderWindowInteractor* aRWI = + VTKViewer_RenderWindowInteractor::SafeDownCast(rwi); + + //Cell selection //////////////////////////////////// NB + if ( aSelectionMode == CellSelection ) + { + if ( SActor->hasIO() && isValid( SActor, aVtkId, CellSelection ) ) + { + int anObjId = SActor->GetObjId(aVtkId); + std::vector aVtkList; + if (anObjId != -1) + aVtkList = SActor->GetVtkId(anObjId); + + if (aVtkList.size() > 0) + aRWI->setCellData(SActor->getIO(), aVtkList, myPActor); + else + aRWI->setCellData(SActor->getIO(), aVtkId, myPActor); + + this->CurrentRenderer->AddActor(myPActor); + myPActor->GetProperty()->SetRepresentationToSurface(); + myPActor->VisibilityOn(); + } + } + + //Edge, Face, Volume and EdgeOfCell selection ////////////////////////// NB + else if ( aSelectionMode == EdgeSelection || + aSelectionMode == FaceSelection || + aSelectionMode == VolumeSelection || + aSelectionMode == EdgeOfCellSelection ) { + if ( SActor->hasIO() && isValid( SActor, aVtkId, aSelectionMode ) ) + { + if (vtkDataSet* UGrid = SActor->GetMapper()->GetInput()) { + if (vtkCell* pickedCell = UGrid->GetCell(aVtkId)) { + bool result = false; + int edgeId = -1; + int anObjId = SActor->GetObjId(aVtkId); + std::vector aVtkList; + if (anObjId > -1) + aVtkList = SActor->GetVtkId(anObjId); + + if ( aSelectionMode == EdgeSelection ) { + if ( SActor->GetObjDimension( anObjId ) == 1 ) + result = true; + } + else if ( aSelectionMode == FaceSelection ) { + if ( SActor->GetObjDimension( anObjId ) == 2 ) + result = true; + } + else if ( aSelectionMode == VolumeSelection ) { + if ( SActor->GetObjDimension( anObjId ) == 3 ) + result = true; + } + else { + float pickPosition[3]; + picker->GetPickPosition(pickPosition); + float distMin = 1000000.0, dist = 0; + for (int i = 0, iEnd = pickedCell->GetNumberOfEdges(); i < iEnd; i++){ + vtkCell* edge = pickedCell->GetEdge(i); + if(vtkLine* line = vtkLine::SafeDownCast(edge)){ + float pcoords[3],closestPoint[3],weights[3]; + int subId; + line->EvaluatePosition(pickPosition,closestPoint,subId,pcoords,dist,weights); + if (dist < distMin) { + distMin = dist; + edgeId = i; + } + } + } + if (edgeId != -1 || pickedCell->GetCellDimension() == 1) + result = true; + // INFOS("edgeID transformed = "<CurrentRenderer->RemoveActor(myPActor); + if (edgeId == -1) { + if (aVtkList.size() > 0) + aRWI->setCellData(SActor->getIO(), aVtkList, myPActor); + else + aRWI->setCellData(SActor->getIO(), aVtkId, myPActor); + } + else + aRWI->setEdgeData(SActor->getIO(), aVtkId, -edgeId-1, myPActor); + + this->CurrentRenderer->AddActor(myPActor); + myPActor->GetProperty()->SetRepresentationToSurface(); + myPActor->VisibilityOn(); + } + } + } + } + } + } + } + } + } + else if (rwi->GetPicker()->IsA("vtkPointPicker")) { + vtkPointPicker* picker = vtkPointPicker::SafeDownCast(rwi->GetPicker()); + // INFOS ( " Preselected PointId : " << picker->GetPointId() ); + if (picker->GetPointId() >= 0) { + vtkActor* ac = picker->GetActor(); + if ( ac->IsA("SALOME_Actor") ) { + SALOME_Actor* SActor = SALOME_Actor::SafeDownCast( ac ); + // INFOS ( " NAME Actor : " << SActor->getName() ); - if ( rwi->GetPicker()->IsA("vtkPicker") ) { + if (rwi->IsA("VTKViewer_RenderWindowInteractor")) { + VTKViewer_RenderWindowInteractor* aRWI = + VTKViewer_RenderWindowInteractor::SafeDownCast(rwi); + + if ( SActor->hasIO() ) { + myPActor->VisibilityOff(); + this->CurrentRenderer->RemoveActor(myPActor); + aRWI->setPointData(SActor->getIO(), picker->GetPointId(), myPActor); + this->CurrentRenderer->AddActor(myPActor); + myPActor->GetProperty()->SetRepresentationToSurface(); + myPActor->VisibilityOn(); + } + } + } + } + } + else if ( rwi->GetPicker()->IsA("vtkPicker") ) { vtkPicker* picker = vtkPicker::SafeDownCast(rwi->GetPicker()); vtkActor* ac = picker->GetActor(); @@ -1282,7 +1549,7 @@ void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) { } ac = theActors->GetNextActor(); } - // MESSAGE ( " NAME PREVIEW " << SActor->getName() ); + // INFOS ( " NAME PREVIEW " << SActor->getName() ); } } } @@ -1301,6 +1568,9 @@ void VTKViewer_InteractorStyleSALOME::onCursorMove(QPoint mousePos) { } } } + rwi->EndPickCallback(); + rwi->Render(); + this->LastPos[0] = x; this->LastPos[1] = y; } @@ -1425,3 +1695,59 @@ bool VTKViewer_InteractorStyleSALOME::IsInRect(float* thePoint, return ((aPnt[0]>left) && (aPnt[0]bottom) && (aPnt[1]GetMapper()->GetInput(); + if ( aUGrid != 0 ) + { + vtkCell* aCell = aUGrid->GetCell( theId ); + if ( aCell != 0 ) + { + int nbPoints = aCell->GetNumberOfPoints(); + if ( nbPoints == 2 ) + return myEdgeFilter.IsNull() || myEdgeFilter->IsValid( theActor, theId ); + else + return myFaceFilter.IsNull() || myFaceFilter->IsValid( theActor, theId ); + + return true; + } + } + return false; + } + else if ( theSelMode == FaceSelection ) + return myFaceFilter.IsNull() || myFaceFilter->IsValid( theActor, theId ); + else if ( theSelMode == EdgeSelection ) + return myEdgeFilter.IsNull() || myEdgeFilter->IsValid( theActor, theId ); + + return true; +} diff --git a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h index 62438e91e..ce55fdfc8 100644 --- a/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h +++ b/src/VTKViewer/VTKViewer_InteractorStyleSALOME.h @@ -33,6 +33,8 @@ #include #include #include "SALOME_Actor.h" +#include "VTKViewer_Filter.h" +#include "SALOME_Selection.h" class VTKViewer_Trihedron; @@ -55,6 +57,8 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl static VTKViewer_InteractorStyleSALOME *New(); void setTriedron(VTKViewer_Trihedron* theTrihedron); + void setPreselectionProp(const double& theRed = 0, const double& theGreen = 1, + const double& theBlue = 1, const int& theWidth = 5); vtkTypeMacro(VTKViewer_InteractorStyleSALOME, vtkObject); void PrintSelf(ostream& os, vtkIndent indent); @@ -68,8 +72,15 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl void OnRightButtonDown(int ctrl, int shift, int x, int y); void OnRightButtonUp (int ctrl, int shift, int x, int y); + void OnSelectionModeChanged(); + void ViewFitAll(); + void SetEdgeFilter( const Handle(VTKViewer_Filter)& ); + void SetFaceFilter( const Handle(VTKViewer_Filter)& ); + void RemoveFaceFilter(); + void RemoveEdgeFilter(); + protected: VTKViewer_InteractorStyleSALOME(); ~VTKViewer_InteractorStyleSALOME(); @@ -93,12 +104,15 @@ class VTKViewer_InteractorStyleSALOME : public QObject, public vtkInteractorStyl const int left, const int top, const int right, const int bottom); + bool isValid( SALOME_Actor* theActor, const int theCellId, const Selection_Mode theSelMode ); + int State; float MotionFactor; float RadianToDegree; // constant: for conv from deg to rad double myScale; SALOME_Actor* preview; + vtkActor* myPActor; public: bool eventFilter(QObject* object, QEvent* event); @@ -123,26 +137,30 @@ protected: void setCursor(const int operation); protected: - QCursor myDefCursor; - QCursor myPanCursor; - QCursor myZoomCursor; - QCursor myRotateCursor; - QCursor mySpinCursor; - QCursor myHandCursor; - QCursor myGlobalPanCursor; - QPoint myPoint; - QPoint myOtherPoint; - bool myCursorState; - bool myShiftState; - int ForcedState; - VTKViewer_Trihedron* m_Trihedron; - - QWidget* myGUIWindow; + QCursor myDefCursor; + QCursor myPanCursor; + QCursor myZoomCursor; + QCursor myRotateCursor; + QCursor mySpinCursor; + QCursor myHandCursor; + QCursor myGlobalPanCursor; + QPoint myPoint; + QPoint myOtherPoint; + bool myCursorState; + bool myShiftState; + int ForcedState; + + VTKViewer_Trihedron* m_Trihedron; + + QWidget* myGUIWindow; + + Handle(VTKViewer_Filter) myEdgeFilter; + Handle(VTKViewer_Filter) myFaceFilter; // members from old version - double DeltaElevation; - double DeltaAzimuth; - int LastPos[2]; + double DeltaElevation; + double DeltaAzimuth; + int LastPos[2]; }; #endif diff --git a/src/VTKViewer/VTKViewer_RectPicker.cxx b/src/VTKViewer/VTKViewer_RectPicker.cxx new file mode 100644 index 000000000..6453097c0 --- /dev/null +++ b/src/VTKViewer/VTKViewer_RectPicker.cxx @@ -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 + +#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 index 000000000..44b7e0705 --- /dev/null +++ b/src/VTKViewer/VTKViewer_RectPicker.h @@ -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 + +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 + + diff --git a/src/VTKViewer/VTKViewer_RenderWindow.cxx b/src/VTKViewer/VTKViewer_RenderWindow.cxx index 6aef5fb7a..46e3dba3f 100644 --- a/src/VTKViewer/VTKViewer_RenderWindow.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindow.cxx @@ -26,6 +26,7 @@ // Module : SALOME // $Header$ +using namespace std; #include "VTKViewer_RenderWindow.h" #include "utilities.h" #include "QAD_Settings.h" @@ -45,7 +46,6 @@ #include #include #include -using namespace std; //#include //#include @@ -194,8 +194,10 @@ void VTKViewer_RenderWindow::onChangeBackgroundColor() QColor selColor = QColorDialog::getColor ( QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)), NULL ); if ( selColor.isValid() ) { theRenderer->SetBackground( selColor.red()/255., selColor.green()/255., selColor.blue()/255. ); + /* VSR : PAL5420 --------------------------------------------------- QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorRed", selColor.red() ); QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorGreen", selColor.green() ); QAD_CONFIG->addSetting( "VTKViewer:BackgroundColorBlue", selColor.blue() ); + VSR : PAL5420 --------------------------------------------------- */ } } diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx index 2e4ce4b96..9658ef5e5 100644 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.cxx @@ -33,7 +33,7 @@ #include "QAD_Application.h" #include "QAD_Desktop.h" -#include "SALOME_Selection.h" +//#include "SALOME_Selection.h" #include "SALOME_Actor.h" #include @@ -147,6 +147,9 @@ void VTKViewer_RenderWindowInteractor::Initialize() { // this->Initialized = 1 ; + myTolNodes = 0.025; + myTolItems = 0.001; + Cell_Actor = vtkActor::New(); Cell_Actor->PickableOff(); Cell_Actor->GetProperty()->SetColor(1,1,0); @@ -175,32 +178,63 @@ void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver } -void VTKViewer_RenderWindowInteractor::SetSelectionMode(int mode) +void VTKViewer_RenderWindowInteractor::SetSelectionMode(Selection_Mode mode) { Cell_Actor->VisibilityOff(); Edge_Actor->VisibilityOff(); Point_Actor->VisibilityOff(); selectionmode = mode; - if ( mode == 1 ) { + if ( mode == NodeSelection ) { vtkPointPicker* thepicker = vtkPointPicker::New(); - // thepicker->SetTolerance(0.001); + thepicker->SetTolerance(myTolNodes); this->SetPicker(thepicker); - } else if ( mode == 2 ) { + } else if ( mode == EdgeOfCellSelection ) { vtkCellPicker* thepicker = vtkCellPicker::New(); - thepicker->SetTolerance(0.001); + thepicker->SetTolerance(myTolItems); this->SetPicker(thepicker); - } else if ( mode == 3 ) { + } else if ( mode == CellSelection || mode == EdgeSelection || + mode == FaceSelection || mode == VolumeSelection ) { vtkCellPicker* thepicker = vtkCellPicker::New(); - thepicker->SetTolerance(0.001); + thepicker->SetTolerance(myTolItems); this->SetPicker(thepicker); - } else if ( mode == 4 ) { + } else if ( mode == ActorSelection ) { vtkPicker* thepicker = vtkPicker::New(); - thepicker->SetTolerance(0.001); + thepicker->SetTolerance(myTolItems); this->SetPicker(thepicker); } + + VTKViewer_InteractorStyleSALOME* Style = 0; + if (this->InteractorStyle->IsA("VTKViewer_InteractorStyleSALOME")) + Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle); + else + return; + Style->OnSelectionModeChanged(); } +void VTKViewer_RenderWindowInteractor::SetSelectionProp(const double& theRed, const double& theGreen, + const double& theBlue, const int& theWidth) +{ + Cell_Actor->GetProperty()->SetColor(theRed, theGreen, theBlue); + Cell_Actor->GetProperty()->SetLineWidth(theWidth); + + Point_Actor->GetProperty()->SetColor(theRed, theGreen, theBlue); + Point_Actor->GetProperty()->SetPointSize(theWidth); +} + +void VTKViewer_RenderWindowInteractor::SetSelectionTolerance(const double& theTolNodes, const double& theTolItems) +{ + myTolNodes = theTolNodes; + myTolItems = theTolItems; + if (this->GetPicker()->IsA("vtkPointPicker")) { + vtkPointPicker* picker = vtkPointPicker::SafeDownCast(this->GetPicker()); + picker->SetTolerance(theTolNodes); + } + else if (this->GetPicker()->IsA("vtkPicker")) { + vtkPicker* picker = vtkPicker::SafeDownCast(this->GetPicker()); + picker->SetTolerance(theTolItems); + } +} void VTKViewer_RenderWindowInteractor::Enable() { // @@ -604,13 +638,31 @@ void VTKViewer_RenderWindowInteractor::DisplayAll() emit RenderWindowModified() ; } +void VTKViewer_RenderWindowInteractor::Erase( SALOME_Actor* SActor, bool update) +{ + SActor->SetVisibility( false ); + + // Erase dependent actors + vtkActorCollection* theChildActors = vtkActorCollection::New(); + SActor->GetChildActors(theChildActors); + + theChildActors->InitTraversal(); + vtkActor *ac = theChildActors->GetNextActor(); + while(!(ac==NULL)) { + ac->SetVisibility( false ); + ac = theChildActors->GetNextActor(); + } + + if (update) + emit RenderWindowModified(); +} + void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObject)& IObject, bool update) { vtkRenderer* aren; for (this->RenderWindow->GetRenderers()->InitTraversal(); (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) { vtkActorCollection* theActors = aren->GetActors(); - vtkActorCollection* theChildActors = vtkActorCollection::New(); theActors->InitTraversal(); vtkActor *ac = theActors->GetNextActor(); while(!(ac==NULL)) { @@ -618,21 +670,12 @@ void VTKViewer_RenderWindowInteractor::Erase(const Handle(SALOME_InteractiveObje SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac ); if ( anActor->hasIO() ) { if ( IObject->isSame( anActor->getIO() ) ) { - anActor->SetVisibility( false ); - anActor->GetChildActors(theChildActors); + Erase(anActor, false); } } } ac = theActors->GetNextActor(); } - - // Erase dependent actors - theChildActors->InitTraversal(); - ac = theChildActors->GetNextActor(); - while(!(ac==NULL)) { - ac->SetVisibility( false ); - ac = theChildActors->GetNextActor(); - } } if (update) emit RenderWindowModified() ; @@ -828,14 +871,14 @@ bool VTKViewer_RenderWindowInteractor::unHighlightAll(){ aRenColl->InitTraversal(); while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){ vtkActorCollection* theActors = aRen->GetActors(); - theActors->InitTraversal(); if(theActors->IsItemPresent(Point_Actor)) aRen->RemoveActor(Point_Actor); if(theActors->IsItemPresent(Edge_Actor)) aRen->RemoveActor(Edge_Actor); if(theActors->IsItemPresent(Cell_Actor)) aRen->RemoveActor(Cell_Actor); - vtkActor *anActor = theActors->GetNextActor(); + + theActors->InitTraversal(); while(vtkActor *anAct = theActors->GetNextActor()) { if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){ if(anActor->hasIO()){ @@ -995,43 +1038,54 @@ bool VTKViewer_RenderWindowInteractor::highlight(const Handle(SALOME_Interactive vtkActor *theActor, bool hilight, bool update ) { if(MapIndex.Extent() == 0) return false; - vtkRenderer* aRen; - this->RenderWindow->GetRenderers()->InitTraversal(); - for (; aRen = this->RenderWindow->GetRenderers()->GetNextItem(); ) { - vtkActorCollection* anActorColl = aRen->GetActors(); - if ( anActorColl->IsItemPresent(theActor) != 0 ) - aRen->RemoveActor(theActor); - anActorColl->InitTraversal(); - vtkActor *ac = NULL; - for(; (ac = anActorColl->GetNextActor()) != NULL; ){ - if(ac->IsA("SALOME_Actor")){ - SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac); - if(anActor->hasIO()){ - if(IObject->isSame(anActor->getIO())){ - if(vtkPolyData* aSourcePolyData = anActor->GetPolyDataInput()){ - vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); - (*theFun)(aSourcePolyData,aMapper,MapIndex); - theActor->SetMapper(aMapper); - aMapper->Delete(); - if(anActorColl->IsItemPresent(theActor) == 0) - aRen->AddActor(theActor); - if(hilight) - theActor->VisibilityOn(); - else - theActor->VisibilityOff(); - break; - } - } - } - } - } + vtkRenderer* aRen = GetRenderer(); + vtkActorCollection* anActorColl = aRen->GetActors(); + if ( anActorColl->IsItemPresent(theActor) != 0 ) + aRen->RemoveActor(theActor); + + if (hilight) { + setActorData(IObject, MapIndex, theFun, theActor); + aRen->AddActor(theActor); + theActor->VisibilityOn(); + } + else { + theActor->VisibilityOff(); } + if(update){ this->RenderWindow->Render(); emit RenderWindowModified() ; } + return false; } + +void VTKViewer_RenderWindowInteractor::setActorData(const Handle(SALOME_InteractiveObject)& IObject, + const TColStd_MapOfInteger& MapIndex, + VTKViewer_RenderWindowInteractor::TCreateMapperFun theFun, + vtkActor* theActor) +{ + vtkActorCollection* anActorColl = GetRenderer()->GetActors(); + anActorColl->InitTraversal(); + vtkActor *ac = NULL; + while ((ac = anActorColl->GetNextActor()) != NULL) { + if (ac->IsA("SALOME_Actor")){ + SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac); + if (anActor->hasIO()) { + if (IObject->isSame(anActor->getIO())) { + if (vtkPolyData* aSourcePolyData = anActor->GetPolyDataInput()) { + vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); + (*theFun)(aSourcePolyData,aMapper,MapIndex); + theActor->SetMapper(aMapper); + aMapper->Delete(); + break; + } + } + } + } + } +} + static void CellCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, const TColStd_MapOfInteger& theMapIndex) @@ -1041,7 +1095,7 @@ static void CellCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* vtkIdList *ptIds = vtkIdList::New(); ptIds->Allocate(theSourcePolyData->GetMaxCellSize()); - vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); + // vtkPolyDataMapper* aMapper = vtkPolyDataMapper::New(); aPolyData->SetPoints(theSourcePolyData->GetPoints()); TColStd_MapIteratorOfMapOfInteger ite(theMapIndex); int aNbOfParts = theSourcePolyData->GetNumberOfCells(); @@ -1068,6 +1122,23 @@ bool VTKViewer_RenderWindowInteractor::highlightCell(const Handle(SALOME_Interac { return highlight(IObject,MapIndex,&CellCreateMapper,Cell_Actor,hilight,update); } + +void VTKViewer_RenderWindowInteractor::setCellData(const Handle(SALOME_InteractiveObject)& IObject, + const int& theIndex, vtkActor* theActor ) +{ + TColStd_MapOfInteger MapIndex; MapIndex.Add(theIndex); + return setActorData(IObject,MapIndex,&CellCreateMapper,theActor); +} + +void VTKViewer_RenderWindowInteractor::setCellData(const Handle(SALOME_InteractiveObject)& IObject, + const std::vector& theIndexes, vtkActor* theActor ) +{ + TColStd_MapOfInteger MapIndex; + std::vector::const_iterator it; + for (it = theIndexes.begin(); it != theIndexes.end(); ++it) + MapIndex.Add(*it); + return setActorData(IObject,MapIndex,&CellCreateMapper,theActor); +} static void PointCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, @@ -1101,6 +1172,14 @@ bool VTKViewer_RenderWindowInteractor::highlightPoint(const Handle(SALOME_Intera { return highlight(IObject,MapIndex,&PointCreateMapper,Point_Actor,hilight,update); } + + +void VTKViewer_RenderWindowInteractor::setPointData(const Handle(SALOME_InteractiveObject)& IObject, + const int& theIndex, vtkActor* theActor ) +{ + TColStd_MapOfInteger MapIndex; MapIndex.Add(theIndex); + return setActorData(IObject,MapIndex,&PointCreateMapper,theActor); +} static void EdgeCreateMapper(vtkPolyData *theSourcePolyData, vtkPolyDataMapper* theMapper, @@ -1160,3 +1239,11 @@ bool VTKViewer_RenderWindowInteractor::highlightEdge( const Handle(SALOME_Intera { return highlight(IObject,MapIndex,&EdgeCreateMapper,Edge_Actor,hilight,update); } + +void VTKViewer_RenderWindowInteractor::setEdgeData(const Handle(SALOME_InteractiveObject)& IObject, + const int& theCellIndex, const int& theEdgeIndex, + vtkActor* theActor ) +{ + TColStd_MapOfInteger MapIndex; MapIndex.Add(theCellIndex); MapIndex.Add(theEdgeIndex); + return setActorData(IObject,MapIndex,&EdgeCreateMapper,theActor); +} diff --git a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h index e5fa40885..3a22e676a 100644 --- a/src/VTKViewer/VTKViewer_RenderWindowInteractor.h +++ b/src/VTKViewer/VTKViewer_RenderWindowInteractor.h @@ -34,6 +34,7 @@ #include "SALOME_InteractiveObject.hxx" #include "SALOME_Actor.h" +#include "SALOME_Selection.h" // QT Includes #include @@ -141,8 +142,20 @@ public: bool isVisible( const Handle(SALOME_InteractiveObject)& IObject); void rename(const Handle(SALOME_InteractiveObject)& IObject, QString newName); - - void SetSelectionMode(int mode); + void SetSelectionMode(Selection_Mode mode); + void SetSelectionProp(const double& theRed = 1, const double& theGreen = 1, + const double& theBlue = 0, const int& theWidth = 5); + void SetSelectionTolerance(const double& theTolNodes = 0.025, const double& theTolCell = 0.001); + + void setCellData(const Handle(SALOME_InteractiveObject)& IObject, + const int& theIndex, vtkActor* theActor ); + void setCellData(const Handle(SALOME_InteractiveObject)& IObject, + const std::vector& theIndexes, vtkActor* theActor ); + void setEdgeData(const Handle(SALOME_InteractiveObject)& IObject, + const int& theCellIndex, const int& theEdgeIndex, + vtkActor* theActor ); //NB + void setPointData(const Handle(SALOME_InteractiveObject)& IObject, + const int& theIndex, vtkActor* theActor ); // Displaymode management int GetDisplayMode(); @@ -167,6 +180,7 @@ public: void Display(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly=true); void Display( SALOME_Actor* SActor, bool immediatly = true ); + void Erase( SALOME_Actor* SActor, bool immediatly = true ); // Transparency void SetTransparency(const Handle(SALOME_InteractiveObject)& IObject,float trans); @@ -196,6 +210,9 @@ public: bool highlight(const Handle(SALOME_InteractiveObject)& IObject, const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun, vtkActor *theActor, bool hilight, bool update ); + void setActorData(const Handle(SALOME_InteractiveObject)& IObject, + const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun, + vtkActor *theActor ); // Timer used during various mouse events to figure // out mouse movements. @@ -205,7 +222,7 @@ public: int displaymode; //NRI: Selection mode - int selectionmode; + Selection_Mode selectionmode; vtkActor* Point_Actor; vtkActor* Edge_Actor; //NB vtkActor* Cell_Actor; @@ -243,6 +260,8 @@ public: private: QWidget* myGUIWindow; + double myTolNodes; + double myTolItems; }; #endif diff --git a/src/VTKViewer/VTKViewer_Trihedron.cxx b/src/VTKViewer/VTKViewer_Trihedron.cxx index be2d18894..9a278d4a6 100644 --- a/src/VTKViewer/VTKViewer_Trihedron.cxx +++ b/src/VTKViewer/VTKViewer_Trihedron.cxx @@ -63,6 +63,7 @@ public: protected: VTKViewer_UnScaledActor(); + ~VTKViewer_UnScaledActor(){} int mySize; }; @@ -82,8 +83,12 @@ void VTKViewer_UnScaledActor::Render(vtkRenderer *theRenderer){ float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1])); vtkDataSet* aDataSet = GetMapper()->GetInput(); float aLength = aDataSet->GetLength(); + float aPrecision = 1.0E-3; + float anOldScale = GetScale()[0]; float aScale = mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1])); - SetScale(aScale); + if(fabs(aScale - anOldScale)/aScale > aPrecision){ + SetScale(aScale); + } } vtkFollower::Render(theRenderer); } @@ -94,6 +99,50 @@ void VTKViewer_UnScaledActor::SetSize(int theSize){ //============================================================================== +class VTKViewer_LineActor: public vtkFollower{ + VTKViewer_LineActor(const VTKViewer_LineActor&); + +public: + vtkTypeMacro(VTKViewer_LineActor,vtkFollower); + static VTKViewer_LineActor *New(); + + void SetLabelActor(VTKViewer_UnScaledActor* theLabelActor); + void SetArrowActor(VTKViewer_UnScaledActor* theLabelActor); + virtual void Render(vtkRenderer *theRenderer); + +protected: + VTKViewer_LineActor(){ + LabelActor = NULL; + ArrowActor = NULL; + } + ~VTKViewer_LineActor(){ + SetLabelActor(NULL); + SetArrowActor(NULL); + } + + VTKViewer_UnScaledActor* LabelActor; + VTKViewer_UnScaledActor* ArrowActor; +}; + +vtkStandardNewMacro(VTKViewer_LineActor); + +vtkCxxSetObjectMacro(VTKViewer_LineActor,LabelActor,VTKViewer_UnScaledActor); +vtkCxxSetObjectMacro(VTKViewer_LineActor,ArrowActor,VTKViewer_UnScaledActor); + +void VTKViewer_LineActor::Render(vtkRenderer *theRenderer){ + if(LabelActor && LabelActor->GetVisibility()){ + LabelActor->Modified(); + LabelActor->Render(theRenderer); + } + if(ArrowActor && ArrowActor->GetVisibility()){ + ArrowActor->Modified(); + ArrowActor->Render(theRenderer); + } + vtkFollower::Render(theRenderer); +} + +//============================================================================== + // The base class for concreate Axis // Its only duty is to give correct initialization and destruction // of its pipe-lines @@ -106,9 +155,10 @@ protected: vtkTypeMacro(VTKViewer_Axis,vtkObject); virtual void AddToRender(vtkRenderer* theRenderer){ + //Order of the calls are important + theRenderer->AddActor(myLineActor); theRenderer->AddActor(myLabelActor); theRenderer->AddActor(myArrowActor); - theRenderer->AddActor(myLineActor); } virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis); @@ -140,7 +190,8 @@ protected: VTKViewer_Trihedron::TVisibility myVisibility; float myDir[3], myRot[3]; - vtkActor *myLineActor; + VTKViewer_LineActor *myLineActor; + //vtkActor *myLineActor; VTKViewer_UnScaledActor *myArrowActor; VTKViewer_UnScaledActor *myLabelActor; @@ -158,7 +209,7 @@ VTKViewer_Axis::VTKViewer_Axis(){ myMapper[0] = vtkPolyDataMapper::New(); myMapper[0]->SetInput(myLineSource->GetOutput()); - myLineActor = vtkActor::New(); + myLineActor = VTKViewer_LineActor::New(); myLineActor->SetMapper(myMapper[0]); myLineActor->PickableOff(); @@ -176,6 +227,8 @@ VTKViewer_Axis::VTKViewer_Axis(){ myArrowActor->SetSize(aArrowActorSize); myArrowActor->PickableOff(); + myLineActor->SetArrowActor(myArrowActor); + // Initialize the Label pipe-line representation myVectorText = VTKViewer_VectorText::New(); @@ -187,6 +240,9 @@ VTKViewer_Axis::VTKViewer_Axis(){ static int aLabelActorSize = 12; myLabelActor->SetSize(aLabelActorSize); myLabelActor->PickableOff(); + //myLabelActor->DebugOn(); + + myLineActor->SetLabelActor(myLabelActor); // Initialise visibility param. myVisibility = VTKViewer_Trihedron::eOn; @@ -379,12 +435,3 @@ int VTKViewer_Trihedron::GetVisibleActorCount(vtkRenderer* theRenderer){ //SetVisibility(aVis); return aCount; } - -void VTKViewer_Trihedron::Render(vtkRenderer* theRenderer){ - for(int i = 0; i < 3; i++) - { - myAxis[i]->GetLabel()->Render(theRenderer); - myAxis[i]->GetArrow()->Render(theRenderer); - } -} - diff --git a/src/VTKViewer/VTKViewer_Trihedron.h b/src/VTKViewer/VTKViewer_Trihedron.h index 056ea158f..d53a602c3 100644 --- a/src/VTKViewer/VTKViewer_Trihedron.h +++ b/src/VTKViewer/VTKViewer_Trihedron.h @@ -58,8 +58,6 @@ class VTKViewer_Trihedron : public vtkObject{ virtual int GetVisibleActorCount(vtkRenderer* theRenderer); - virtual void Render(vtkRenderer *theRenderer); - protected: vtkActorCollection* myPresent; VTKViewer_Axis* myAxis[3]; diff --git a/src/VTKViewer/VTKViewer_Utilities.cxx b/src/VTKViewer/VTKViewer_Utilities.cxx index ce64a1e4c..b8b61997f 100644 --- a/src/VTKViewer/VTKViewer_Utilities.cxx +++ b/src/VTKViewer/VTKViewer_Utilities.cxx @@ -52,7 +52,7 @@ void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint){ if ( theRenderer->GetActiveCamera() != NULL ) theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn); else{ - INFOS("Trying to reset non-existant camera"); + MESSAGE("Trying to reset non-existant camera"); return; } diff --git a/src/VTKViewer/VTKViewer_ViewFrame.cxx b/src/VTKViewer/VTKViewer_ViewFrame.cxx index 4e059ce38..b68158db7 100644 --- a/src/VTKViewer/VTKViewer_ViewFrame.cxx +++ b/src/VTKViewer/VTKViewer_ViewFrame.cxx @@ -30,11 +30,10 @@ #include "VTKViewer_Utilities.h" #include "VTKViewer_Trihedron.h" #include "VTKViewer_RenderWindow.h" -//#include "VTKViewer_InteractorStyleSALOME.h" +#include "VTKViewer_InteractorStyleSALOME.h" #include "SALOME_Transform.h" #include "SALOME_TransformFilter.h" -#include "SALOME_PassThroughFilter.h" #include "SALOME_GeometryFilter.h" #include "QAD_Settings.h" @@ -43,7 +42,6 @@ #include "QAD_Desktop.h" #include "SALOME_Selection.h" #include "SALOME_InteractiveObject.hxx" -#include "VTKViewer_InteractorStyleSALOME.h" #include "utilities.h" @@ -169,10 +167,10 @@ void VTKViewer_ViewFrame::onAdjustTrihedron(){ float aSize = m_Triedron->GetSize(); float aNewSize = aLength*aSizeInPercents/100.0; // if the new trihedron size have sufficient difference, then apply the value - if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE) + if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){ m_Triedron->SetSize(aNewSize); + } } - m_Triedron->Render(m_Renderer); ::ResetCameraClippingRange(m_Renderer); } @@ -351,7 +349,7 @@ QColor VTKViewer_ViewFrame::backgroundColor() const } -void VTKViewer_ViewFrame::SetSelectionMode( int mode ) +void VTKViewer_ViewFrame::SetSelectionMode( Selection_Mode mode ) { m_RWInteractor->SetSelectionMode( mode ); } @@ -372,31 +370,33 @@ void VTKViewer_ViewFrame::highlight( const Handle(SALOME_InteractiveObject)& IOb { QAD_Study* ActiveStudy = QAD_Application::getDesktop()->getActiveStudy(); SALOME_Selection* Sel = SALOME_Selection::Selection( ActiveStudy->getSelection() ); - if ( Sel->SelectionMode() == 4 ) - m_RWInteractor->highlight(IObject, highlight, update); - else if ( Sel->SelectionMode() == 3 ) { - m_RWInteractor->highlight(IObject, highlight, update); + m_RWInteractor->highlight(IObject, highlight, update); + + switch (Sel->SelectionMode()) { + case NodeSelection: if ( Sel->HasIndex( IObject ) ) { TColStd_MapOfInteger MapIndex; Sel->GetIndex( IObject, MapIndex ); - m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update); + m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update); } - } - else if ( Sel->SelectionMode() == 2 ) { - m_RWInteractor->highlight(IObject, highlight, update); + break; + case EdgeOfCellSelection: if ( Sel->HasIndex( IObject ) ) { TColStd_MapOfInteger MapIndex; Sel->GetIndex( IObject, MapIndex ); m_RWInteractor->highlightEdge(IObject, highlight, MapIndex, update); } - } - else if ( Sel->SelectionMode() == 1 ) { - m_RWInteractor->highlight(IObject, highlight, update); + break; + case CellSelection: + case EdgeSelection: + case FaceSelection: + case VolumeSelection: if ( Sel->HasIndex( IObject ) ) { TColStd_MapOfInteger MapIndex; Sel->GetIndex( IObject, MapIndex ); - m_RWInteractor->highlightPoint(IObject, highlight, MapIndex, update); + m_RWInteractor->highlightCell(IObject, highlight, MapIndex, update); } + break; } } @@ -622,5 +622,3 @@ void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool update /*=fa theActor->RemoveFromRender(m_Renderer); if(update) Repaint(); } - - diff --git a/src/VTKViewer/VTKViewer_ViewFrame.h b/src/VTKViewer/VTKViewer_ViewFrame.h index 83fc35ab1..5547699fa 100644 --- a/src/VTKViewer/VTKViewer_ViewFrame.h +++ b/src/VTKViewer/VTKViewer_ViewFrame.h @@ -58,7 +58,7 @@ class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{ void setBackgroundColor( const QColor& ); QColor backgroundColor() const; - void SetSelectionMode( int mode ); + void SetSelectionMode( Selection_Mode mode ); /* popup management */ void setPopupServer( QAD_Application* );