Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[modules/smesh.git] / src / SMESH / SMESH_HypoFilter.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESH_HypoFilter.cxx
25 //  Module : SMESH
26 //  $Header$
27
28 #include "SMESH_HypoFilter.hxx"
29
30 #include "SMESH_Hypothesis.hxx"
31 #include "SMESH_subMesh.hxx"
32
33 using namespace std;
34
35
36 //=======================================================================
37 //function : NamePredicate::Value
38 //purpose  : 
39 //=======================================================================
40
41 bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
42                                             const TopoDS_Shape&     /*aShape*/ ) const
43 {
44   return ( _name == aHyp->GetName() );
45 }
46
47 //=======================================================================
48 //function : TypePredicate::Value
49 //purpose  : 
50 //=======================================================================
51
52 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
53 {
54   return aHyp->GetType();
55 };
56
57 //=======================================================================
58 //function : DimPredicate::Value
59 //purpose  : 
60 //=======================================================================
61
62 int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
63 {
64   return aHyp->GetDim();
65 }
66
67 //=======================================================================
68 //function : ApplicablePredicate::IsOk
69 //purpose  : 
70 //=======================================================================
71
72 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
73                                                  const TopoDS_Shape&     /*aShape*/) const
74 {
75   return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
76 };
77
78 //=======================================================================
79 //function : IsAuxiliaryPredicate::IsOk
80 //purpose  : 
81 //=======================================================================
82
83 bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
84                                                   const TopoDS_Shape&     /*aShape*/) const
85 {
86   return aHyp->IsAuxiliary();
87 };
88
89 //=======================================================================
90 //function : ApplicablePredicate::ApplicablePredicate
91 //purpose  : 
92 //=======================================================================
93
94 SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
95 {
96   _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
97 }
98
99 //=======================================================================
100 //function : InstancePredicate::IsOk
101 //purpose  : 
102 //=======================================================================
103
104 bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
105                                                const TopoDS_Shape&     /*aShape*/) const
106 {
107   return _hypo == aHyp;
108 }
109
110 //=======================================================================
111 //function : IsAssignedToPredicate::IsOk
112 //purpose  : 
113 //=======================================================================
114
115 bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
116                                                const TopoDS_Shape&     aShape) const
117 {
118   return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
119 }
120
121 //=======================================================================
122 //function : SMESH_HypoFilter
123 //purpose  : 
124 //=======================================================================
125
126 SMESH_HypoFilter::SMESH_HypoFilter()
127 {
128 }
129
130 //=======================================================================
131 //function : SMESH_HypoFilter
132 //purpose  : 
133 //=======================================================================
134
135 SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
136 {
137   add( notNagate ? AND : AND_NOT, aPredicate );
138 }
139
140 //=======================================================================
141 //function : And
142 //purpose  : 
143 //=======================================================================
144
145 SMESH_HypoFilter & SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
146 {
147   add( AND, aPredicate );
148   return *this;
149 }
150
151 //=======================================================================
152 //function : AndNot
153 //purpose  : 
154 //=======================================================================
155
156 SMESH_HypoFilter & SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
157 {
158   add( AND_NOT, aPredicate );
159   return *this;
160 }
161
162 //=======================================================================
163 //function : Or
164 //purpose  : 
165 //=======================================================================
166
167 SMESH_HypoFilter & SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
168 {
169   add( OR, aPredicate );
170   return *this;
171 }
172
173 //=======================================================================
174 //function : OrNot
175 //purpose  : Return predicates
176 //=======================================================================
177
178 SMESH_HypoFilter & SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
179 {
180   add( OR_NOT, aPredicate );
181   return *this;
182 }
183
184 //=======================================================================
185 //function : Is
186 //purpose  : 
187 //=======================================================================
188
189 SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
190 {
191   return new InstancePredicate( theHypo );
192 }
193
194 //=======================================================================
195 //function : IsAlgo
196 //purpose  : 
197 //=======================================================================
198
199 SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
200 {
201   return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
202 }
203
204 //=======================================================================
205 //function : IsAuxiliary
206 //purpose  : 
207 //=======================================================================
208
209 SMESH_HypoPredicate* SMESH_HypoFilter::IsAuxiliary()
210 {
211   return new IsAuxiliaryPredicate();
212 }
213
214
215 //=======================================================================
216 //function : IsGlobal
217 //purpose  : 
218 //=======================================================================
219
220  SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
221 {
222   return new IsAssignedToPredicate( theMainShape );
223 }
224
225 //=======================================================================
226 //function : IsAssignedTo
227 //purpose  : 
228 //=======================================================================
229
230  SMESH_HypoPredicate* SMESH_HypoFilter::IsAssignedTo(const TopoDS_Shape& theShape)
231 {
232   return new IsAssignedToPredicate( theShape );
233 }
234
235 //=======================================================================
236 //function : HasName
237 //purpose  : 
238 //=======================================================================
239
240 SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
241 {
242   return new NamePredicate( theName );
243 }
244
245 //=======================================================================
246 //function : HasDim
247 //purpose  : 
248 //=======================================================================
249
250 SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
251 {
252   return new DimPredicate( EQUAL, theDim );
253 }
254
255 //=======================================================================
256 //function : IsApplicableTo
257 //purpose  : 
258 //=======================================================================
259
260 SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
261 {
262   return new ApplicablePredicate( theShape );
263 }
264
265 //=======================================================================
266 //function : HasType
267 //purpose  : 
268 //=======================================================================
269
270 SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
271 {
272   return new TypePredicate( EQUAL, theHypType );
273 }
274
275 //=======================================================================
276 //function : IsOk
277 //purpose  : 
278 //=======================================================================
279
280 bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
281                              const TopoDS_Shape&     aShape) const
282 {
283   if ( myPredicates.empty() )
284     return true;
285
286   bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
287   list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
288   for ( ; pred != myPredicates.end(); ++pred )
289   {
290     bool ok2 = (*pred)->IsOk( aHyp, aShape );
291     switch ( (*pred)->_logical_op ) {
292     case AND:     ok = ok && ok2; break;
293     case AND_NOT: ok = ok && !ok2; break;
294     case OR:      ok = ok || ok2; break;
295     case OR_NOT:  ok = ok || !ok2; break;
296     default:;
297     }
298   }
299   return ok;
300 }
301
302 //=======================================================================
303 //function : Init
304 //purpose  : 
305 //=======================================================================
306
307 SMESH_HypoFilter & SMESH_HypoFilter::Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate )
308 {
309   list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
310   for ( ; pred != myPredicates.end(); ++pred )
311     delete *pred;
312   myPredicates.clear();
313
314   add( notNagate ? AND : AND_NOT, aPredicate );
315   return *this;
316 }
317
318
319 //=======================================================================
320 //function : IsOk
321 //purpose  : 
322 //=======================================================================
323
324 SMESH_HypoFilter::~SMESH_HypoFilter()
325 {
326   Init(0);
327 }
328