1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESHDS_GroupOnFilter.cxx
26 #include "SMESHDS_GroupOnFilter.hxx"
28 #include "SMESHDS_Mesh.hxx"
29 #include "SMDS_SetIterator.hxx"
33 //=============================================================================
35 * Creates a group based on thePredicate
37 //=============================================================================
39 SMESHDS_GroupOnFilter::SMESHDS_GroupOnFilter (const int theID,
40 const SMESHDS_Mesh* theMesh,
41 const SMDSAbs_ElementType theType,
42 const SMESH_PredicatePtr& thePredicate)
43 : SMESHDS_GroupBase(theID,theMesh,theType), myMeshModifTime(0)
46 SetPredicate( thePredicate );
49 //================================================================================
51 * \brief Sets a new predicate
53 //================================================================================
55 void SMESHDS_GroupOnFilter::SetPredicate( const SMESH_PredicatePtr& thePredicate)
57 myPredicate = thePredicate;
60 myPredicate->SetMesh( GetMesh() );
63 //================================================================================
65 * \brief Returns nb of elements
67 //================================================================================
69 int SMESHDS_GroupOnFilter::Extent() const
72 return myElements.size();
75 //================================================================================
77 * \brief Checks if the element belongs to the group
79 //================================================================================
81 bool SMESHDS_GroupOnFilter::Contains (const int theID)
83 return myPredicate ? myPredicate->IsSatisfy( theID ) : false;
86 //================================================================================
88 * \brief Checks if the element belongs to the group
90 //================================================================================
92 bool SMESHDS_GroupOnFilter::Contains (const SMDS_MeshElement* elem)
94 return myPredicate ? myPredicate->IsSatisfy( elem->GetID() ) : false;
97 //================================================================================
99 * \brief Return iterator on all elements
101 //================================================================================
103 SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const
106 return SMDS_ElemIteratorPtr
107 ( new SMDS_ElementVectorIterator( myElements.begin(), myElements.end() ));
110 //================================================================================
112 * \brief return ID of theIndex-th element
113 * \param theIndex - index countered from 1
114 * \retval int - element ID
116 //================================================================================
118 int SMESHDS_GroupOnFilter::GetID (const int theIndex)
121 if ( theIndex < 1 || theIndex > myElements.size() )
123 return myElements[ theIndex-1 ]->GetID();
126 //================================================================================
128 * \brief Updates myElements if necessary
130 //================================================================================
132 void SMESHDS_GroupOnFilter::update() const
134 if ( myMeshModifTime < GetMesh()->GetMTime() )
136 SMESHDS_GroupOnFilter* me = const_cast<SMESHDS_GroupOnFilter*>( this );
137 me->myElements.clear();
140 me->myElements.reserve( GetMesh()->GetMeshInfo().NbElements(GetType()));
141 SMDS_ElemIteratorPtr elIt = GetMesh()->elementsIterator(GetType());
142 while ( elIt->more() )
144 const SMDS_MeshElement* e = elIt->next();
145 if ( myPredicate->IsSatisfy( e->GetID() ))
146 me->myElements.push_back( e );
148 me->myElements.resize( myElements.size() );
150 me->setChanged( false );
154 //================================================================================
156 * \brief Sets myMeshModifTime according to modification state
158 //================================================================================
160 void SMESHDS_GroupOnFilter::setChanged(bool changed)
162 myMeshModifTime = GetMesh()->GetMTime();
163 if ( changed && myMeshModifTime != 0 )