From ec36250a0d659f848132377cd4deae8f4e38a8fd Mon Sep 17 00:00:00 2001 From: eap Date: Thu, 23 Jun 2011 12:06:37 +0000 Subject: [PATCH] 0021014: EDF 1583 SMESH: Improvement of the Python Dump for the creation of groups + SMESHDS_GroupOnFilter.cxx --- src/SMESHDS/SMESHDS_GroupOnFilter.cxx | 165 ++++++++++++++++++++++++++ src/SMESHDS/SMESHDS_GroupOnFilter.hxx | 69 +++++++++++ 2 files changed, 234 insertions(+) create mode 100644 src/SMESHDS/SMESHDS_GroupOnFilter.cxx create mode 100644 src/SMESHDS/SMESHDS_GroupOnFilter.hxx diff --git a/src/SMESHDS/SMESHDS_GroupOnFilter.cxx b/src/SMESHDS/SMESHDS_GroupOnFilter.cxx new file mode 100644 index 000000000..8a984c275 --- /dev/null +++ b/src/SMESHDS/SMESHDS_GroupOnFilter.cxx @@ -0,0 +1,165 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// + +// File : SMESHDS_GroupOnFilter.cxx +// Module : SMESH +// +#include "SMESHDS_GroupOnFilter.hxx" + +#include "SMESHDS_Mesh.hxx" +#include "SMDS_SetIterator.hxx" + +using namespace std; + +//============================================================================= +/*! + * Creates a group based on thePredicate + */ +//============================================================================= + +SMESHDS_GroupOnFilter::SMESHDS_GroupOnFilter (const int theID, + const SMESHDS_Mesh* theMesh, + const SMDSAbs_ElementType theType, + const SMESH_PredicatePtr& thePredicate) + : SMESHDS_GroupBase(theID,theMesh,theType), myMeshModifTime(0) +{ + setChanged(); + SetPredicate( thePredicate ); +} + +//================================================================================ +/*! + * \brief Sets a new predicate + */ +//================================================================================ + +void SMESHDS_GroupOnFilter::SetPredicate( const SMESH_PredicatePtr& thePredicate) +{ + myPredicate = thePredicate; + setChanged(); + if ( myPredicate ) + myPredicate->SetMesh( GetMesh() ); +} + +//================================================================================ +/*! + * \brief Returns nb of elements + */ +//================================================================================ + +int SMESHDS_GroupOnFilter::Extent() +{ + update(); + return myElements.size(); +} + +//================================================================================ +/*! + * \brief Checks if the element belongs to the group + */ +//================================================================================ + +bool SMESHDS_GroupOnFilter::Contains (const int theID) +{ + return myPredicate ? myPredicate->IsSatisfy( theID ) : false; +} + +//================================================================================ +/*! + * \brief Checks if the element belongs to the group + */ +//================================================================================ + +bool SMESHDS_GroupOnFilter::Contains (const SMDS_MeshElement* elem) +{ + return myPredicate ? myPredicate->IsSatisfy( elem->GetID() ) : false; +} + +//================================================================================ +/*! + * \brief Return iterator on all elements + */ +//================================================================================ + +SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const +{ + update(); + return SMDS_ElemIteratorPtr + ( new SMDS_ElementVectorIterator( myElements.begin(), myElements.end() )); +} + +//================================================================================ +/*! + * \brief return ID of theIndex-th element + * \param theIndex - index countered from 1 + * \retval int - element ID + */ +//================================================================================ + +int SMESHDS_GroupOnFilter::GetID (const int theIndex) +{ + update(); + if ( theIndex < 1 || theIndex > myElements.size() ) + return -1; + return myElements[ theIndex-1 ]->GetID(); +} + +//================================================================================ +/*! + * \brief Updates myElements if necessary + */ +//================================================================================ + +void SMESHDS_GroupOnFilter::update() const +{ + if ( myMeshModifTime < GetMesh()->GetMTime() ) + { + SMESHDS_GroupOnFilter* me = const_cast( this ); + me->myElements.clear(); + if ( myPredicate ) + { + me->myElements.reserve( GetMesh()->GetMeshInfo().NbElements(GetType())); + SMDS_ElemIteratorPtr elIt = GetMesh()->elementsIterator(GetType()); + while ( elIt->more() ) + { + const SMDS_MeshElement* e = elIt->next(); + if ( myPredicate->IsSatisfy( e->GetID() )) + me->myElements.push_back( e ); + } + me->myElements.resize( myElements.size() ); + } + me->setChanged( false ); + } +} + +//================================================================================ +/*! + * \brief Sets myMeshModifTime according to modification state + */ +//================================================================================ + +void SMESHDS_GroupOnFilter::setChanged(bool changed) +{ + myMeshModifTime = GetMesh()->GetMTime(); + if ( changed && myMeshModifTime != 0 ) + --myMeshModifTime; +} diff --git a/src/SMESHDS/SMESHDS_GroupOnFilter.hxx b/src/SMESHDS/SMESHDS_GroupOnFilter.hxx new file mode 100644 index 000000000..805378704 --- /dev/null +++ b/src/SMESHDS/SMESHDS_GroupOnFilter.hxx @@ -0,0 +1,69 @@ +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SMESHDS_GroupOnFilter.hxx +// Module : SMESH +// +#ifndef _SMESHDS_GroupOnFilter_HeaderFile +#define _SMESHDS_GroupOnFilter_HeaderFile + +#include "SMESH_SMESHDS.hxx" + +#include "SMESHDS_GroupBase.hxx" +#include "SMESH_Controls.hxx" + +/*! + * \brief Groups whose contents is dynamically updated using the filter + */ +class SMESHDS_EXPORT SMESHDS_GroupOnFilter: public SMESHDS_GroupBase +{ + public: + + SMESHDS_GroupOnFilter (const int theID, + const SMESHDS_Mesh* theMesh, + const SMDSAbs_ElementType theType, + const SMESH_PredicatePtr& thePredicate); + + void SetPredicate( const SMESH_PredicatePtr& thePredicate); + + SMESH_PredicatePtr GetPredicate() const { return myPredicate; } + + virtual int Extent(); + + virtual bool Contains (const int theID); + + virtual bool Contains (const SMDS_MeshElement* elem); + + virtual SMDS_ElemIteratorPtr GetElements() const; + + virtual int GetID (const int theIndex); + + private: + + void update() const; + void setChanged(bool changed=true); + + SMESH_PredicatePtr myPredicate; + std::vector< const SMDS_MeshElement*> myElements; + unsigned long myMeshModifTime; // when myElements was filled +}; + +#endif -- 2.39.2