1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : SMESH_HypoFilter.cxx
28 #include "SMESH_HypoFilter.hxx"
30 #include "SMESH_Hypothesis.hxx"
31 #include "SMESH_subMesh.hxx"
36 //=======================================================================
37 //function : NamePredicate::Value
39 //=======================================================================
41 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
42 const TopoDS_Shape& /*aShape*/ ) const
44 return ( _name == aHyp->GetName() );
47 //=======================================================================
48 //function : TypePredicate::Value
50 //=======================================================================
52 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
54 return aHyp->GetType();
57 //=======================================================================
58 //function : DimPredicate::Value
60 //=======================================================================
62 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
64 return aHyp->GetDim();
67 //=======================================================================
68 //function : ApplicablePredicate::IsOk
70 //=======================================================================
72 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
73 const TopoDS_Shape& /*aShape*/) const
75 return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
78 //=======================================================================
79 //function : IsAuxiliaryPredicate::IsOk
81 //=======================================================================
83 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
84 const TopoDS_Shape& /*aShape*/) const
86 return aHyp->IsAuxiliary();
89 //=======================================================================
90 //function : ApplicablePredicate::ApplicablePredicate
92 //=======================================================================
94 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
96 _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
99 //=======================================================================
100 //function : InstancePredicate::IsOk
102 //=======================================================================
104 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
105 const TopoDS_Shape& /*aShape*/) const
107 return _hypo == aHyp;
110 //=======================================================================
111 //function : IsAssignedToPredicate::IsOk
113 //=======================================================================
115 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
116 const TopoDS_Shape& aShape) const
118 return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
121 //=======================================================================
122 //function : IsMoreLocalThanPredicate::IsOk
124 //=======================================================================
126 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
127 const TopoDS_Shape& aShape) const
129 return ( aShape.ShapeType() > _shapeType );
132 //=======================================================================
133 //function : SMESH_HypoFilter
135 //=======================================================================
137 SMESH_HypoFilter::SMESH_HypoFilter()
141 //=======================================================================
142 //function : SMESH_HypoFilter
144 //=======================================================================
146 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
148 add( notNagate ? AND : AND_NOT, aPredicate );
151 //=======================================================================
154 //=======================================================================
156 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
158 add( AND, aPredicate );
162 //=======================================================================
165 //=======================================================================
167 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
169 add( AND_NOT, aPredicate );
173 //=======================================================================
176 //=======================================================================
178 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
180 add( OR, aPredicate );
184 //=======================================================================
186 //purpose : Return predicates
187 //=======================================================================
189 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
191 add( OR_NOT, aPredicate );
195 //=======================================================================
198 //=======================================================================
200 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
202 return new InstancePredicate( theHypo );
205 //=======================================================================
208 //=======================================================================
210 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
212 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
215 //=======================================================================
216 //function : IsAuxiliary
218 //=======================================================================
220 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
222 return new IsAuxiliaryPredicate();
226 //=======================================================================
227 //function : IsGlobal
229 //=======================================================================
231 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
233 return new IsAssignedToPredicate( theMainShape );
236 //=======================================================================
237 //function : IsAssignedTo
239 //=======================================================================
241 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
243 return new IsAssignedToPredicate( theShape );
246 //=======================================================================
249 //=======================================================================
251 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
253 return new NamePredicate( theName );
256 //=======================================================================
259 //=======================================================================
261 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
263 return new DimPredicate( EQUAL, theDim );
266 //=======================================================================
267 //function : IsApplicableTo
269 //=======================================================================
271 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
273 return new ApplicablePredicate( theShape );
276 //=======================================================================
277 //function : IsMoreLocalThan
279 //=======================================================================
281 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape)
283 return new IsMoreLocalThanPredicate( theShape );
286 //=======================================================================
289 //=======================================================================
291 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
293 return new TypePredicate( EQUAL, theHypType );
296 //=======================================================================
299 //=======================================================================
301 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
302 const TopoDS_Shape& aShape) const
304 if ( myPredicates.empty() )
307 bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
308 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
309 for ( ; pred != myPredicates.end(); ++pred )
311 bool ok2 = (*pred)->IsOk( aHyp, aShape );
312 switch ( (*pred)->_logical_op ) {
313 case AND: ok = ok && ok2; break;
314 case AND_NOT: ok = ok && !ok2; break;
315 case OR: ok = ok || ok2; break;
316 case OR_NOT: ok = ok || !ok2; break;
323 //=======================================================================
326 //=======================================================================
328 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNagate )
330 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
331 for ( ; pred != myPredicates.end(); ++pred )
333 myPredicates.clear();
335 add( notNagate ? AND : AND_NOT, aPredicate );
340 //=======================================================================
343 //=======================================================================
345 SMESH_HypoFilter::~SMESH_HypoFilter()