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
27 #include "SMESH_HypoFilter.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_Hypothesis.hxx"
31 #include "SMESH_MesherHelper.hxx"
32 #include "SMESH_subMesh.hxx"
34 #include <TopExp_Explorer.hxx>
39 //=======================================================================
40 //function : NamePredicate::Value
42 //=======================================================================
44 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
45 const TopoDS_Shape& /*aShape*/ ) const
47 return ( _name == aHyp->GetName() );
50 //=======================================================================
51 //function : TypePredicate::Value
53 //=======================================================================
55 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
57 return aHyp->GetType();
60 //=======================================================================
61 //function : DimPredicate::Value
63 //=======================================================================
65 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
67 return aHyp->GetDim();
70 //=======================================================================
71 //function : ApplicablePredicate::IsOk
73 //=======================================================================
75 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
76 const TopoDS_Shape& /*aShape*/) const
78 return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
81 //=======================================================================
82 //function : IsAuxiliaryPredicate::IsOk
84 //=======================================================================
86 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
87 const TopoDS_Shape& /*aShape*/) const
89 return aHyp->IsAuxiliary();
92 //=======================================================================
93 //function : ApplicablePredicate::ApplicablePredicate
95 //=======================================================================
97 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
99 _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
102 //=======================================================================
103 //function : InstancePredicate::IsOk
105 //=======================================================================
107 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
108 const TopoDS_Shape& /*aShape*/) const
110 return _hypo == aHyp;
113 //=======================================================================
114 //function : IsAssignedToPredicate::IsOk
116 //=======================================================================
118 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
119 const TopoDS_Shape& aShape) const
121 return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
124 //=======================================================================
125 //function : IsMoreLocalThanPredicate::IsOk
127 //=======================================================================
129 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
130 const TopoDS_Shape& aShape) const
132 if ( SMESH_MesherHelper::IsSubShape( aShape, /*mainShape=*/_shape ))
135 if ( aShape.ShapeType() == TopAbs_COMPOUND &&
136 !SMESH_MesherHelper::IsSubShape( _shape, /*mainShape=*/aShape)) // issue 0020963
138 for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
139 if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
140 for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
141 if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
147 //=======================================================================
148 //function : SMESH_HypoFilter
150 //=======================================================================
152 SMESH_HypoFilter::SMESH_HypoFilter()
156 //=======================================================================
157 //function : SMESH_HypoFilter
159 //=======================================================================
161 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
163 add( notNagate ? AND : AND_NOT, aPredicate );
166 //=======================================================================
169 //=======================================================================
171 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
173 add( AND, aPredicate );
177 //=======================================================================
180 //=======================================================================
182 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
184 add( AND_NOT, aPredicate );
188 //=======================================================================
191 //=======================================================================
193 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
195 add( OR, aPredicate );
199 //=======================================================================
201 //purpose : Return predicates
202 //=======================================================================
204 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
206 add( OR_NOT, aPredicate );
210 //=======================================================================
213 //=======================================================================
215 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
217 return new InstancePredicate( theHypo );
220 //=======================================================================
223 //=======================================================================
225 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
227 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
230 //=======================================================================
231 //function : IsAuxiliary
233 //=======================================================================
235 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
237 return new IsAuxiliaryPredicate();
241 //=======================================================================
242 //function : IsGlobal
244 //=======================================================================
246 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
248 return new IsAssignedToPredicate( theMainShape );
251 //=======================================================================
252 //function : IsAssignedTo
254 //=======================================================================
256 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
258 return new IsAssignedToPredicate( theShape );
261 //=======================================================================
264 //=======================================================================
266 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
268 return new NamePredicate( theName );
271 //=======================================================================
274 //=======================================================================
276 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
278 return new DimPredicate( EQUAL, theDim );
281 //=======================================================================
282 //function : IsApplicableTo
284 //=======================================================================
286 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
288 return new ApplicablePredicate( theShape );
291 //=======================================================================
292 //function : IsMoreLocalThan
294 //=======================================================================
296 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape)
298 return new IsMoreLocalThanPredicate( theShape );
301 //=======================================================================
304 //=======================================================================
306 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
308 return new TypePredicate( EQUAL, theHypType );
311 //=======================================================================
314 //=======================================================================
316 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
317 const TopoDS_Shape& aShape) const
319 if ( myPredicates.empty() )
322 bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
323 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
324 for ( ; pred != myPredicates.end(); ++pred )
326 bool ok2 = (*pred)->IsOk( aHyp, aShape );
327 switch ( (*pred)->_logical_op ) {
328 case AND: ok = ok && ok2; break;
329 case AND_NOT: ok = ok && !ok2; break;
330 case OR: ok = ok || ok2; break;
331 case OR_NOT: ok = ok || !ok2; break;
338 //=======================================================================
341 //=======================================================================
343 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNagate )
345 list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
346 for ( ; pred != myPredicates.end(); ++pred )
348 myPredicates.clear();
350 add( notNagate ? AND : AND_NOT, aPredicate );
355 //=======================================================================
358 //=======================================================================
360 SMESH_HypoFilter::~SMESH_HypoFilter()