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), myPredicateTic(0)
46 SetPredicate( thePredicate );
49 //================================================================================
51 * \brief Sets a new predicate
53 //================================================================================
55 void SMESHDS_GroupOnFilter::SetPredicate( const SMESH_PredicatePtr& thePredicate)
57 myPredicate = thePredicate;
61 myPredicate->SetMesh( GetMesh() );
64 //================================================================================
66 * \brief Returns nb of elements
68 //================================================================================
70 int SMESHDS_GroupOnFilter::Extent() const
73 return myElements.size();
76 //================================================================================
78 * \brief Checks if the element belongs to the group
80 //================================================================================
82 bool SMESHDS_GroupOnFilter::Contains (const int theID)
84 return myPredicate ? myPredicate->IsSatisfy( theID ) : false;
87 //================================================================================
89 * \brief Checks if the element belongs to the group
91 //================================================================================
93 bool SMESHDS_GroupOnFilter::Contains (const SMDS_MeshElement* elem)
95 return myPredicate ? myPredicate->IsSatisfy( elem->GetID() ) : false;
98 //================================================================================
100 * \brief Return iterator on all elements
102 //================================================================================
104 SMDS_ElemIteratorPtr SMESHDS_GroupOnFilter::GetElements() const
107 return SMDS_ElemIteratorPtr
108 ( new SMDS_ElementVectorIterator( myElements.begin(), myElements.end() ));
111 //================================================================================
113 * \brief return ID of theIndex-th element
114 * \param theIndex - index countered from 1
115 * \retval int - element ID
117 //================================================================================
119 int SMESHDS_GroupOnFilter::GetID (const int theIndex)
122 if ( theIndex < 1 || theIndex > myElements.size() )
124 return myElements[ theIndex-1 ]->GetID();
127 //================================================================================
129 * \brief Return a value allowing to find out if a group has changed or not
131 //================================================================================
133 int SMESHDS_GroupOnFilter::GetTic() const
135 return GetMesh()->GetMTime() * myPredicateTic;
138 //================================================================================
140 * \brief Updates myElements if necessary
142 //================================================================================
144 void SMESHDS_GroupOnFilter::update() const
146 if ( myMeshModifTime < GetMesh()->GetMTime() )
148 SMESHDS_GroupOnFilter* me = const_cast<SMESHDS_GroupOnFilter*>( this );
149 me->myElements.clear();
152 me->myElements.reserve( GetMesh()->GetMeshInfo().NbElements(GetType()));
153 SMDS_ElemIteratorPtr elIt = GetMesh()->elementsIterator(GetType());
154 while ( elIt->more() )
156 const SMDS_MeshElement* e = elIt->next();
157 if ( myPredicate->IsSatisfy( e->GetID() ))
158 me->myElements.push_back( e );
160 me->myElements.resize( myElements.size() );
162 me->setChanged( false );
166 //================================================================================
168 * \brief Sets myMeshModifTime according to modification state
170 //================================================================================
172 void SMESHDS_GroupOnFilter::setChanged(bool changed)
174 myMeshModifTime = GetMesh()->GetMTime();
175 if ( changed && myMeshModifTime != 0 )