1 // Copyright (C) 2007-2010 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 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_HypoFilter.cxx
28 #include "SMESH_HypoFilter.hxx"
30 #include "SMESH_Hypothesis.hxx"
31 #include "SMESH_subMesh.hxx"
33 #include <TopExp_Explorer.hxx>
38 //=======================================================================
39 //function : NamePredicate::Value
41 //=======================================================================
43 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
44 const TopoDS_Shape& /*aShape*/ ) const
46 return ( _name == aHyp->GetName() );
49 //=======================================================================
50 //function : TypePredicate::Value
52 //=======================================================================
54 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
56 return aHyp->GetType();
59 //=======================================================================
60 //function : DimPredicate::Value
62 //=======================================================================
64 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
66 return aHyp->GetDim();
69 //=======================================================================
70 //function : ApplicablePredicate::IsOk
72 //=======================================================================
74 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
75 const TopoDS_Shape& /*aShape*/) const
77 return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
80 //=======================================================================
81 //function : IsAuxiliaryPredicate::IsOk
83 //=======================================================================
85 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
86 const TopoDS_Shape& /*aShape*/) const
88 return aHyp->IsAuxiliary();
91 //=======================================================================
92 //function : ApplicablePredicate::ApplicablePredicate
94 //=======================================================================
96 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
98 _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
101 //=======================================================================
102 //function : InstancePredicate::IsOk
104 //=======================================================================
106 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
107 const TopoDS_Shape& /*aShape*/) const
109 return _hypo == aHyp;
112 //=======================================================================
113 //function : IsAssignedToPredicate::IsOk
115 //=======================================================================
117 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
118 const TopoDS_Shape& aShape) const
120 return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
123 //=======================================================================
124 //function : IsMoreLocalThanPredicate::IsOk
126 //=======================================================================
128 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
129 const TopoDS_Shape& aShape) const
132 // if aShape is COMPOUND (i.e. most probably a GEOM group) then
133 // it is more local if it contains shapes of less dimension than _shapeType
134 if ( aShape.ShapeType() == TopAbs_COMPOUND )
135 for ( int moreLocalType = _shapeType+1; moreLocalType < int(TopAbs_SHAPE); ++moreLocalType )
136 if ( TopExp_Explorer( aShape, TopAbs_ShapeEnum(moreLocalType)).More())
138 return ( aShape.ShapeType() > _shapeType );
141 //=======================================================================
142 //function : SMESH_HypoFilter
144 //=======================================================================
146 SMESH_HypoFilter::SMESH_HypoFilter()
150 //=======================================================================
151 //function : SMESH_HypoFilter
153 //=======================================================================
155 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
157 add( notNagate ? AND : AND_NOT, aPredicate );
160 //=======================================================================
163 //=======================================================================
165 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
167 add( AND, aPredicate );
171 //=======================================================================
174 //=======================================================================
176 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
178 add( AND_NOT, aPredicate );
182 //=======================================================================
185 //=======================================================================
187 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
189 add( OR, aPredicate );
193 //=======================================================================
195 //purpose : Return predicates
196 //=======================================================================
198 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
200 add( OR_NOT, aPredicate );
204 //=======================================================================
207 //=======================================================================
209 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
211 return new InstancePredicate( theHypo );
214 //=======================================================================
217 //=======================================================================
219 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
221 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
224 //=======================================================================
225 //function : IsAuxiliary
227 //=======================================================================
229 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
231 return new IsAuxiliaryPredicate();
235 //=======================================================================
236 //function : IsGlobal
238 //=======================================================================
240 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
242 return new IsAssignedToPredicate( theMainShape );
245 //=======================================================================
246 //function : IsAssignedTo
248 //=======================================================================
250 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
252 return new IsAssignedToPredicate( theShape );
255 //=======================================================================
258 //=======================================================================
260 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
262 return new NamePredicate( theName );
265 //=======================================================================
268 //=======================================================================
270 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
272 return new DimPredicate( EQUAL, theDim );
275 //=======================================================================
276 //function : IsApplicableTo
278 //=======================================================================
280 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
282 return new ApplicablePredicate( theShape );
285 //=======================================================================
286 //function : IsMoreLocalThan
288 //=======================================================================
290 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape)
292 return new IsMoreLocalThanPredicate( theShape );
295 //=======================================================================
298 //=======================================================================
300 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
302 return new TypePredicate( EQUAL, theHypType );
305 //=======================================================================
308 //=======================================================================
310 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
311 const TopoDS_Shape& aShape) const
313 if ( myPredicates.empty() )
316 bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
317 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
318 for ( ; pred != myPredicates.end(); ++pred )
320 bool ok2 = (*pred)->IsOk( aHyp, aShape );
321 switch ( (*pred)->_logical_op ) {
322 case AND: ok = ok && ok2; break;
323 case AND_NOT: ok = ok && !ok2; break;
324 case OR: ok = ok || ok2; break;
325 case OR_NOT: ok = ok || !ok2; break;
332 //=======================================================================
335 //=======================================================================
337 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNagate )
339 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
340 for ( ; pred != myPredicates.end(); ++pred )
342 myPredicates.clear();
344 add( notNagate ? AND : AND_NOT, aPredicate );
349 //=======================================================================
352 //=======================================================================
354 SMESH_HypoFilter::~SMESH_HypoFilter()