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_Gen.hxx"
31 #include "SMESH_Hypothesis.hxx"
32 #include "SMESH_MesherHelper.hxx"
33 #include "SMESH_subMesh.hxx"
35 #include <TopExp_Explorer.hxx>
40 //=======================================================================
41 //function : NamePredicate::Value
43 //=======================================================================
45 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
46 const TopoDS_Shape& /*aShape*/ ) const
48 return ( _name == aHyp->GetName() );
51 //=======================================================================
52 //function : TypePredicate::Value
54 //=======================================================================
56 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
58 return aHyp->GetType();
61 //=======================================================================
62 //function : DimPredicate::Value
64 //=======================================================================
66 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
68 return aHyp->GetDim();
71 //=======================================================================
72 //function : ApplicablePredicate::IsOk
74 //=======================================================================
76 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
77 const TopoDS_Shape& /*aShape*/) const
79 return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
82 //=======================================================================
83 //function : IsAuxiliaryPredicate::IsOk
85 //=======================================================================
87 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
88 const TopoDS_Shape& /*aShape*/) const
90 return aHyp->IsAuxiliary();
93 //=======================================================================
94 //function : ApplicablePredicate::ApplicablePredicate
96 //=======================================================================
98 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
100 _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
103 //=======================================================================
104 //function : InstancePredicate::IsOk
106 //=======================================================================
108 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
109 const TopoDS_Shape& /*aShape*/) const
111 return _hypo == aHyp;
114 //=======================================================================
115 //function : IsAssignedToPredicate::IsOk
117 //=======================================================================
119 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
120 const TopoDS_Shape& aShape) const
122 return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
125 //=======================================================================
126 //function : IsMoreLocalThanPredicate::IsOk
128 //=======================================================================
130 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
131 const TopoDS_Shape& aShape) const
133 if ( SMESH_MesherHelper::IsSubShape( aShape, /*mainShape=*/_shape ))
136 if ( aShape.ShapeType() == TopAbs_COMPOUND &&
137 !SMESH_MesherHelper::IsSubShape( _shape, /*mainShape=*/aShape)) // issue 0020963
139 for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
140 if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
141 for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
142 if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
148 //=======================================================================
149 //function : SMESH_HypoFilter
151 //=======================================================================
153 SMESH_HypoFilter::SMESH_HypoFilter()
157 //=======================================================================
158 //function : SMESH_HypoFilter
160 //=======================================================================
162 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
164 add( notNagate ? AND : AND_NOT, aPredicate );
167 //=======================================================================
170 //=======================================================================
172 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
174 add( AND, aPredicate );
178 //=======================================================================
181 //=======================================================================
183 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
185 add( AND_NOT, aPredicate );
189 //=======================================================================
192 //=======================================================================
194 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
196 add( OR, aPredicate );
200 //=======================================================================
202 //purpose : Return predicates
203 //=======================================================================
205 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
207 add( OR_NOT, aPredicate );
211 //=======================================================================
214 //=======================================================================
216 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
218 return new InstancePredicate( theHypo );
221 //=======================================================================
224 //=======================================================================
226 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
228 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
231 //=======================================================================
232 //function : IsAuxiliary
234 //=======================================================================
236 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
238 return new IsAuxiliaryPredicate();
242 //=======================================================================
243 //function : IsGlobal
245 //=======================================================================
247 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
249 return new IsAssignedToPredicate( theMainShape );
252 //=======================================================================
253 //function : IsAssignedTo
255 //=======================================================================
257 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
259 return new IsAssignedToPredicate( theShape );
262 //=======================================================================
265 //=======================================================================
267 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
269 return new NamePredicate( theName );
272 //=======================================================================
275 //=======================================================================
277 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
279 return new DimPredicate( EQUAL, theDim );
282 //=======================================================================
283 //function : IsApplicableTo
285 //=======================================================================
287 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
289 return new ApplicablePredicate( theShape );
292 //=======================================================================
293 //function : IsMoreLocalThan
295 //=======================================================================
297 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape)
299 return new IsMoreLocalThanPredicate( theShape );
302 //=======================================================================
305 //=======================================================================
307 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
309 return new TypePredicate( EQUAL, theHypType );
312 //=======================================================================
315 //=======================================================================
317 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
318 const TopoDS_Shape& aShape) const
320 if ( myPredicates.empty() )
323 bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
324 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
325 for ( ; pred != myPredicates.end(); ++pred )
327 bool ok2 = (*pred)->IsOk( aHyp, aShape );
328 switch ( (*pred)->_logical_op ) {
329 case AND: ok = ok && ok2; break;
330 case AND_NOT: ok = ok && !ok2; break;
331 case OR: ok = ok || ok2; break;
332 case OR_NOT: ok = ok || !ok2; break;
339 //=======================================================================
342 //=======================================================================
344 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNagate )
346 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
347 for ( ; pred != myPredicates.end(); ++pred )
349 myPredicates.clear();
351 add( notNagate ? AND : AND_NOT, aPredicate );
356 //=======================================================================
359 //=======================================================================
361 SMESH_HypoFilter::~SMESH_HypoFilter()