1 // Copyright (C) 2007-2008 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
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : SMESH_HypoFilter.cxx
27 #include "SMESH_HypoFilter.hxx"
29 #include "SMESH_Hypothesis.hxx"
30 #include "SMESH_subMesh.hxx"
35 //=======================================================================
36 //function : NamePredicate::Value
38 //=======================================================================
40 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
41 const TopoDS_Shape& /*aShape*/ ) const
43 return ( _name == aHyp->GetName() );
46 //=======================================================================
47 //function : TypePredicate::Value
49 //=======================================================================
51 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
53 return aHyp->GetType();
56 //=======================================================================
57 //function : DimPredicate::Value
59 //=======================================================================
61 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
63 return aHyp->GetDim();
66 //=======================================================================
67 //function : ApplicablePredicate::IsOk
69 //=======================================================================
71 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
72 const TopoDS_Shape& /*aShape*/) const
74 return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
77 //=======================================================================
78 //function : IsAuxiliaryPredicate::IsOk
80 //=======================================================================
82 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
83 const TopoDS_Shape& /*aShape*/) const
85 return aHyp->IsAuxiliary();
88 //=======================================================================
89 //function : ApplicablePredicate::ApplicablePredicate
91 //=======================================================================
93 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
95 _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
98 //=======================================================================
99 //function : InstancePredicate::IsOk
101 //=======================================================================
103 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
104 const TopoDS_Shape& /*aShape*/) const
106 return _hypo == aHyp;
109 //=======================================================================
110 //function : IsAssignedToPredicate::IsOk
112 //=======================================================================
114 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
115 const TopoDS_Shape& aShape) const
117 return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
120 //=======================================================================
121 //function : IsMoreLocalThanPredicate::IsOk
123 //=======================================================================
125 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
126 const TopoDS_Shape& aShape) const
128 return ( aShape.ShapeType() > _shapeType );
131 //=======================================================================
132 //function : SMESH_HypoFilter
134 //=======================================================================
136 SMESH_HypoFilter::SMESH_HypoFilter()
140 //=======================================================================
141 //function : SMESH_HypoFilter
143 //=======================================================================
145 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
147 add( notNagate ? AND : AND_NOT, aPredicate );
150 //=======================================================================
153 //=======================================================================
155 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
157 add( AND, aPredicate );
161 //=======================================================================
164 //=======================================================================
166 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
168 add( AND_NOT, aPredicate );
172 //=======================================================================
175 //=======================================================================
177 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
179 add( OR, aPredicate );
183 //=======================================================================
185 //purpose : Return predicates
186 //=======================================================================
188 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
190 add( OR_NOT, aPredicate );
194 //=======================================================================
197 //=======================================================================
199 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
201 return new InstancePredicate( theHypo );
204 //=======================================================================
207 //=======================================================================
209 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
211 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
214 //=======================================================================
215 //function : IsAuxiliary
217 //=======================================================================
219 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
221 return new IsAuxiliaryPredicate();
225 //=======================================================================
226 //function : IsGlobal
228 //=======================================================================
230 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
232 return new IsAssignedToPredicate( theMainShape );
235 //=======================================================================
236 //function : IsAssignedTo
238 //=======================================================================
240 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
242 return new IsAssignedToPredicate( theShape );
245 //=======================================================================
248 //=======================================================================
250 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
252 return new NamePredicate( theName );
255 //=======================================================================
258 //=======================================================================
260 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
262 return new DimPredicate( EQUAL, theDim );
265 //=======================================================================
266 //function : IsApplicableTo
268 //=======================================================================
270 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
272 return new ApplicablePredicate( theShape );
275 //=======================================================================
276 //function : IsMoreLocalThan
278 //=======================================================================
280 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape)
282 return new IsMoreLocalThanPredicate( theShape );
285 //=======================================================================
288 //=======================================================================
290 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
292 return new TypePredicate( EQUAL, theHypType );
295 //=======================================================================
298 //=======================================================================
300 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
301 const TopoDS_Shape& aShape) const
303 if ( myPredicates.empty() )
306 bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
307 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
308 for ( ; pred != myPredicates.end(); ++pred )
310 bool ok2 = (*pred)->IsOk( aHyp, aShape );
311 switch ( (*pred)->_logical_op ) {
312 case AND: ok = ok && ok2; break;
313 case AND_NOT: ok = ok && !ok2; break;
314 case OR: ok = ok || ok2; break;
315 case OR_NOT: ok = ok || !ok2; break;
322 //=======================================================================
325 //=======================================================================
327 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNagate )
329 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
330 for ( ; pred != myPredicates.end(); ++pred )
332 myPredicates.clear();
334 add( notNagate ? AND : AND_NOT, aPredicate );
339 //=======================================================================
342 //=======================================================================
344 SMESH_HypoFilter::~SMESH_HypoFilter()