1 // Copyright (C) 2007-2014 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 : 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 //================================================================================
126 * \brief Finds shapes preferable over _shape due to sub-mesh order
128 //================================================================================
130 void SMESH_HypoFilter::IsMoreLocalThanPredicate::findPreferable()
132 const int shapeID = _mesh.GetMeshDS()->ShapeToIndex( _shape );
133 const TListOfListOfInt& listOfShapeIDList = _mesh.GetMeshOrder();
134 TListOfListOfInt::const_iterator listsIt = listOfShapeIDList.begin();
135 for ( ; listsIt != listOfShapeIDList.end(); ++listsIt )
137 const TListOfInt& idList = *listsIt;
138 TListOfInt::const_iterator idIt =
139 std::find( idList.begin(), idList.end(), shapeID );
140 if ( idIt != idList.end() && *idIt != idList.front() )
142 for ( ; idIt != idList.end(); --idIt )
144 const TopoDS_Shape& shape = _mesh.GetMeshDS()->IndexToShape( *idIt );
145 if ( !shape.IsNull())
146 _preferableShapes.Add( shape );
152 //=======================================================================
153 //function : IsMoreLocalThanPredicate::IsOk
155 //=======================================================================
157 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
158 const TopoDS_Shape& aShape) const
160 if ( aShape.IsSame( _mesh.GetShapeToMesh() ))
161 return false; // aHyp is global
163 if ( SMESH_MesherHelper::IsSubShape( aShape, /*mainShape=*/_shape ))
166 if ( aShape.ShapeType() == TopAbs_COMPOUND &&
167 !SMESH_MesherHelper::IsSubShape( _shape, /*mainShape=*/aShape)) // issue 0020963
169 for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
170 if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
171 for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
172 if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
176 if ( _preferableShapes.Contains( aShape ))
177 return true; // issue 21559, Mesh_6
182 //=======================================================================
183 //function : SMESH_HypoFilter
185 //=======================================================================
187 SMESH_HypoFilter::SMESH_HypoFilter()
192 //=======================================================================
193 //function : SMESH_HypoFilter
195 //=======================================================================
197 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate )
200 add( notNegate ? AND : AND_NOT, aPredicate );
203 //=======================================================================
206 //=======================================================================
208 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
210 add( AND, aPredicate );
214 //=======================================================================
217 //=======================================================================
219 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
221 add( AND_NOT, aPredicate );
225 //=======================================================================
228 //=======================================================================
230 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
232 add( OR, aPredicate );
236 //=======================================================================
238 //purpose : Return predicates
239 //=======================================================================
241 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
243 add( OR_NOT, aPredicate );
247 //=======================================================================
250 //=======================================================================
252 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
254 return new InstancePredicate( theHypo );
257 //=======================================================================
260 //=======================================================================
262 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
264 return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
267 //=======================================================================
268 //function : IsAuxiliary
270 //=======================================================================
272 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
274 return new IsAuxiliaryPredicate();
278 //=======================================================================
279 //function : IsGlobal
281 //=======================================================================
283 SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
285 return new IsAssignedToPredicate( theMainShape );
288 //=======================================================================
289 //function : IsAssignedTo
291 //=======================================================================
293 SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
295 return new IsAssignedToPredicate( theShape );
298 //=======================================================================
301 //=======================================================================
303 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
305 return new NamePredicate( theName );
308 //=======================================================================
311 //=======================================================================
313 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
315 return new DimPredicate( EQUAL, theDim );
318 //=======================================================================
319 //function : IsApplicableTo
321 //=======================================================================
323 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
325 return new ApplicablePredicate( theShape );
328 //=======================================================================
329 //function : IsMoreLocalThan
331 //=======================================================================
333 SMESH_HypoPredicate* SMESH_HypoFilter::IsMoreLocalThan(const TopoDS_Shape& theShape,
334 const SMESH_Mesh& theMesh)
336 return new IsMoreLocalThanPredicate( theShape, theMesh );
339 //=======================================================================
342 //=======================================================================
344 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
346 return new TypePredicate( EQUAL, theHypType );
349 //=======================================================================
352 //=======================================================================
354 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
355 const TopoDS_Shape& aShape) const
360 bool ok = ( myPredicates[0]->_logical_op <= AND_NOT );
361 for ( int i = 0; i < myNbPredicates; ++i )
363 bool ok2 = myPredicates[i]->IsOk( aHyp, aShape );
364 switch ( myPredicates[i]->_logical_op ) {
365 case AND: ok = ok && ok2; break;
366 case AND_NOT: ok = ok && !ok2; break;
367 case OR: ok = ok || ok2; break;
368 case OR_NOT: ok = ok || !ok2; break;
375 //=======================================================================
378 //=======================================================================
380 SMESH_HypoFilter & SMESH_HypoFilter::Init ( SMESH_HypoPredicate* aPredicate, bool notNegate )
382 SMESH_HypoPredicate** pred = &myPredicates[0];
383 SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
384 for ( ; pred != end; ++pred )
388 add( notNegate ? AND : AND_NOT, aPredicate );
393 //=======================================================================
396 //=======================================================================
398 SMESH_HypoFilter::~SMESH_HypoFilter()
400 SMESH_HypoPredicate** pred = &myPredicates[0];
401 SMESH_HypoPredicate** end = &myPredicates[myNbPredicates];
402 for ( ; pred != end; ++pred )