1 // Copyright (C) 2007-2024 CEA, EDF, 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
159 //purpose : Check if aShape is more local than this->_shape
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 // [bos#22320] compound of FACEs is MORE local than compound of SOLIDs
176 TopAbs_ShapeEnum givenType = SMESH_MesherHelper::GetGroupType( _shape );
177 TopAbs_ShapeEnum hypType = SMESH_MesherHelper::GetGroupType( aShape );
178 if ( SMESH_Gen::GetShapeDim( givenType ) > SMESH_Gen::GetShapeDim( hypType ))
180 for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
181 if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
182 for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
183 if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
188 // take forced sub-mesh priority into account
189 if ( _preferableShapes.Contains( aShape ))
190 return true; // issue 21559, Mesh_6
195 //=======================================================================
196 //function : SMESH_HypoFilter
198 //=======================================================================
200 SMESH_HypoFilter::SMESH_HypoFilter()
205 //=======================================================================
206 //function : SMESH_HypoFilter
208 //=======================================================================
210 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate )
213 add( notNegate ? AND : AND_NOT, aPredicate );
216 //=======================================================================
219 //=======================================================================
221 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
223 add( AND, aPredicate );
227 //=======================================================================
230 //=======================================================================
232 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
234 add( AND_NOT, aPredicate );
238 //=======================================================================
241 //=======================================================================
243 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
245 add( OR, aPredicate );
249 //=======================================================================
251 //purpose : Return predicates
252 //=======================================================================
254 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
256 add( OR_NOT, aPredicate );
260 //=======================================================================
263 //=======================================================================
265 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
267 return new InstancePredicate( theHypo );
270 //=======================================================================
273 //=======================================================================
275 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
277 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
280 //=======================================================================
281 //function : IsAuxiliary
283 //=======================================================================
285 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
287 return new IsAuxiliaryPredicate();
291 //=======================================================================
292 //function : IsGlobal
294 //=======================================================================
296 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
298 return new IsAssignedToPredicate( theMainShape );
301 //=======================================================================
302 //function : IsAssignedTo
304 //=======================================================================
306 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
308 return new IsAssignedToPredicate( theShape );
311 //=======================================================================
314 //=======================================================================
316 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
318 return new NamePredicate( theName );
321 //=======================================================================
324 //=======================================================================
326 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
328 return new DimPredicate( EQUAL, theDim );
331 //=======================================================================
332 //function : IsApplicableTo
334 //=======================================================================
336 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
338 return new ApplicablePredicate( theShape );
341 //=======================================================================
342 //function : IsMoreLocalThan
344 //=======================================================================
346 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape,
347 const SMESH_Mesh& theMesh)
349 return new IsMoreLocalThanPredicate( theShape, theMesh );
352 //=======================================================================
355 //=======================================================================
357 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
359 return new TypePredicate( EQUAL, theHypType );
362 //=======================================================================
365 //=======================================================================
367 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
368 const TopoDS_Shape& aShape) const
373 bool ok = ( myPredicates[0]->_logical_op <= AND_NOT );
374 for ( int i = 0; i < myNbPredicates; ++i )
376 bool ok2 = myPredicates[i]->IsOk( aHyp, aShape );
377 switch ( myPredicates[i]->_logical_op ) {
378 case AND: ok = ok && ok2; break;
379 case AND_NOT: ok = ok && !ok2; break;
380 case OR: ok = ok || ok2; break;
381 case OR_NOT: ok = ok || !ok2; break;
388 //=======================================================================
391 //=======================================================================
393 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNegate )
395 SMESH_HypoPredicate** pred = &myPredicates[0];
396 SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
397 for ( ; pred != end; ++pred )
401 add( notNegate ? AND : AND_NOT, aPredicate );
406 //=======================================================================
409 //=======================================================================
411 SMESH_HypoFilter::~SMESH_HypoFilter()
413 SMESH_HypoPredicate** pred = &myPredicates[0];
414 SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
415 for ( ; pred != end; ++pred )