1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 : implementation of SMESH idl descriptions
24 // File : SMESH_HypoFilter.cxx
27 #include "SMESH_HypoFilter.hxx"
29 #include "SMESHDS_Mesh.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_Hypothesis.hxx"
32 #include "SMESH_Mesh.hxx"
33 #include "SMESH_MesherHelper.hxx"
34 #include "SMESH_subMesh.hxx"
36 #include <TopExp_Explorer.hxx>
41 //=======================================================================
42 //function : NamePredicate::Value
44 //=======================================================================
46 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
47 const TopoDS_Shape& /*aShape*/ ) const
49 return ( _name == aHyp->GetName() );
52 //=======================================================================
53 //function : TypePredicate::Value
55 //=======================================================================
57 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
59 return aHyp->GetType();
62 //=======================================================================
63 //function : DimPredicate::Value
65 //=======================================================================
67 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
69 return aHyp->GetDim();
72 //=======================================================================
73 //function : ApplicablePredicate::IsOk
75 //=======================================================================
77 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
78 const TopoDS_Shape& /*aShape*/) const
80 return SMESH_subMesh::IsApplicableHypothesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
83 //=======================================================================
84 //function : IsAuxiliaryPredicate::IsOk
86 //=======================================================================
88 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
89 const TopoDS_Shape& /*aShape*/) const
91 return aHyp->IsAuxiliary();
94 //=======================================================================
95 //function : ApplicablePredicate::ApplicablePredicate
97 //=======================================================================
99 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
101 _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
104 //=======================================================================
105 //function : InstancePredicate::IsOk
107 //=======================================================================
109 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
110 const TopoDS_Shape& /*aShape*/) const
112 return _hypo == aHyp;
115 //=======================================================================
116 //function : IsAssignedToPredicate::IsOk
118 //=======================================================================
120 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
121 const TopoDS_Shape& aShape) const
123 return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
126 //================================================================================
128 * \brief Finds shapes preferable over _shape due to sub-mesh order
130 //================================================================================
132 void SMESH_HypoFilter::IsMoreLocalThanPredicate::findPreferable()
134 const int shapeID = _mesh.GetMeshDS()->ShapeToIndex( _shape );
135 const TListOfListOfInt& listOfShapeIDList = _mesh.GetMeshOrder();
136 TListOfListOfInt::const_iterator listsIt = listOfShapeIDList.begin();
137 for ( ; listsIt != listOfShapeIDList.end(); ++listsIt )
139 const TListOfInt& idList = *listsIt;
140 TListOfInt::const_iterator idIt =
141 std::find( idList.begin(), idList.end(), shapeID );
142 if ( idIt != idList.end() && *idIt != idList.front() )
144 for ( --idIt; true; --idIt )
146 const TopoDS_Shape& shape = _mesh.GetMeshDS()->IndexToShape( *idIt );
147 if ( !shape.IsNull())
148 _preferableShapes.Add( shape );
150 if ( idIt == idList.begin() )
157 //=======================================================================
158 //function : IsMoreLocalThanPredicate::IsOk
160 //=======================================================================
162 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
163 const TopoDS_Shape& aShape) const
165 if ( aShape.IsSame( _mesh.GetShapeToMesh() ) || // aHyp is global
166 aShape.IsSame( _shape ))
169 if ( SMESH_MesherHelper::IsSubShape( aShape, /*mainShape=*/_shape ))
172 if ( aShape.ShapeType() == TopAbs_COMPOUND &&
173 !SMESH_MesherHelper::IsSubShape( _shape, /*mainShape=*/aShape)) // issue 0020963
175 for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
176 if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
177 for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
178 if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
182 if ( _preferableShapes.Contains( aShape ))
183 return true; // issue 21559, Mesh_6
188 //=======================================================================
189 //function : SMESH_HypoFilter
191 //=======================================================================
193 SMESH_HypoFilter::SMESH_HypoFilter()
198 //=======================================================================
199 //function : SMESH_HypoFilter
201 //=======================================================================
203 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate )
206 add( notNegate ? AND : AND_NOT, aPredicate );
209 //=======================================================================
212 //=======================================================================
214 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
216 add( AND, aPredicate );
220 //=======================================================================
223 //=======================================================================
225 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
227 add( AND_NOT, aPredicate );
231 //=======================================================================
234 //=======================================================================
236 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
238 add( OR, aPredicate );
242 //=======================================================================
244 //purpose : Return predicates
245 //=======================================================================
247 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
249 add( OR_NOT, aPredicate );
253 //=======================================================================
256 //=======================================================================
258 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
260 return new InstancePredicate( theHypo );
263 //=======================================================================
266 //=======================================================================
268 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
270 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
273 //=======================================================================
274 //function : IsAuxiliary
276 //=======================================================================
278 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
280 return new IsAuxiliaryPredicate();
284 //=======================================================================
285 //function : IsGlobal
287 //=======================================================================
289 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
291 return new IsAssignedToPredicate( theMainShape );
294 //=======================================================================
295 //function : IsAssignedTo
297 //=======================================================================
299 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
301 return new IsAssignedToPredicate( theShape );
304 //=======================================================================
307 //=======================================================================
309 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
311 return new NamePredicate( theName );
314 //=======================================================================
317 //=======================================================================
319 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
321 return new DimPredicate( EQUAL, theDim );
324 //=======================================================================
325 //function : IsApplicableTo
327 //=======================================================================
329 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
331 return new ApplicablePredicate( theShape );
334 //=======================================================================
335 //function : IsMoreLocalThan
337 //=======================================================================
339 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape,
340 const SMESH_Mesh& theMesh)
342 return new IsMoreLocalThanPredicate( theShape, theMesh );
345 //=======================================================================
348 //=======================================================================
350 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
352 return new TypePredicate( EQUAL, theHypType );
355 //=======================================================================
358 //=======================================================================
360 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
361 const TopoDS_Shape& aShape) const
366 bool ok = ( myPredicates[0]->_logical_op <= AND_NOT );
367 for ( int i = 0; i < myNbPredicates; ++i )
369 bool ok2 = myPredicates[i]->IsOk( aHyp, aShape );
370 switch ( myPredicates[i]->_logical_op ) {
371 case AND: ok = ok && ok2; break;
372 case AND_NOT: ok = ok && !ok2; break;
373 case OR: ok = ok || ok2; break;
374 case OR_NOT: ok = ok || !ok2; break;
381 //=======================================================================
384 //=======================================================================
386 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNegate )
388 SMESH_HypoPredicate** pred = &myPredicates[0];
389 SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
390 for ( ; pred != end; ++pred )
394 add( notNegate ? AND : AND_NOT, aPredicate );
399 //=======================================================================
402 //=======================================================================
404 SMESH_HypoFilter::~SMESH_HypoFilter()
406 SMESH_HypoPredicate** pred = &myPredicates[0];
407 SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
408 for ( ; pred != end; ++pred )