Version: 9.16.0
SMESH_HypoFilter.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 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, or (at your option) any later version.
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// SMESH SMESH : implementation of SMESH idl descriptions
24// File : SMESH_HypoFilter.hxx
25// Module : SMESH
26//
27#ifndef SMESH_HypoFilter_HeaderFile
28#define SMESH_HypoFilter_HeaderFile
29
30#include "SMESH_SMESH.hxx"
31
32// ===========================
33// Filter of SMESH_Hypothesis
34// ===========================
35
36#include <list>
37#include <string>
38#include <TopoDS_Shape.hxx>
39#include <TopTools_MapOfShape.hxx>
40
43class SMESH_Mesh;
44
46 public:
47 virtual bool IsOk(const SMESH_Hypothesis* aHyp,
48 const TopoDS_Shape& aShape) const = 0;
49 // check aHyp or/and aShape it is assigned to
51 private:
53 friend class SMESH_HypoFilter;
54};
55
57{
58 public:
59 // Create and add predicates.
60 // Added predicates will be destroyed by filter when it dies
62 explicit SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNegate = true );
63 // notNegate==false means !aPredicate->IsOk()
64 SMESH_HypoFilter & Init ( SMESH_HypoPredicate* aPredicate, bool notNegate = true );
65 SMESH_HypoFilter & And ( SMESH_HypoPredicate* aPredicate );
66 SMESH_HypoFilter & AndNot( SMESH_HypoPredicate* aPredicate );
67 SMESH_HypoFilter & Or ( SMESH_HypoPredicate* aPredicate );
68 SMESH_HypoFilter & OrNot ( SMESH_HypoPredicate* aPredicate );
69
70 // Create predicates
71 static SMESH_HypoPredicate* IsAlgo();
72 static SMESH_HypoPredicate* IsAuxiliary();
73 static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theShape);
74 static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape);
75 static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
76 static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
77 static SMESH_HypoPredicate* IsMoreLocalThan(const TopoDS_Shape& theShape,
78 const SMESH_Mesh& theMesh);
79 static SMESH_HypoPredicate* HasName(const std::string & theName);
80 static SMESH_HypoPredicate* HasDim(const int theDim);
81 static SMESH_HypoPredicate* HasType(const int theHypType);
82
83 bool IsEmpty() const { return myNbPredicates == 0; }
84
88 bool IsOk (const SMESH_Hypothesis* aHyp,
89 const TopoDS_Shape& aShape) const;
93 bool IsAny() const { return myNbPredicates > 0; }
94
96
97
98 protected:
99 // fields
100
101 //std::list<SMESH_HypoPredicate*> myPredicates;
102 SMESH_HypoPredicate* myPredicates[100];
104
105 // private methods
106
107 enum Logical { AND, AND_NOT, OR, OR_NOT };
108 enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
109
111
112 void add( Logical bool_op, SMESH_HypoPredicate* pred )
113 {
114 if ( pred ) {
115 pred->_logical_op = bool_op;
116 myPredicates[ myNbPredicates++ ] = pred;
117 }
118 }
119
120 // predicates implementation
121
122 template <typename TValue>
126 virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
127 virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
128 {
129 if ( _comp == EQUAL ) return _val == Value( aHyp );
130 else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
131 else if ( _comp == MORE ) return _val < Value( aHyp );
132 else return _val > Value( aHyp );
133 }
134 };
135
137 std::string _name;
138 NamePredicate( std::string name ): _name(name){}
139 bool IsOk(const SMESH_Hypothesis* aHyp,
140 const TopoDS_Shape& aShape) const;
141 };
142
143 struct TypePredicate : public templPredicate< int > {
144 TypePredicate( Comparison comp, int hypType )
145 { _comp = comp; _val = hypType; }
146 int Value( const SMESH_Hypothesis* aHyp ) const;
147 };
148
149 struct DimPredicate : public templPredicate< int > {
150 DimPredicate( Comparison comp, int dim )
151 { _comp = comp; _val = dim; }
152 int Value( const SMESH_Hypothesis* aHyp ) const;
153 };
154
157 ApplicablePredicate( const TopoDS_Shape& theShape );
158 bool IsOk(const SMESH_Hypothesis* aHyp,
159 const TopoDS_Shape& aShape) const;
160 };
161
164 InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
165 bool IsOk(const SMESH_Hypothesis* aHyp,
166 const TopoDS_Shape& aShape) const;
167 };
168
170 TopoDS_Shape _mainShape;
171 IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
172 bool IsOk(const SMESH_Hypothesis* aHyp,
173 const TopoDS_Shape& aShape) const;
174 };
175
177 TopoDS_Shape _shape;
179 TopTools_MapOfShape _preferableShapes;
180 IsMoreLocalThanPredicate( const TopoDS_Shape& shape,
181 const SMESH_Mesh& mesh )
182 :_shape(shape),_mesh(mesh) { findPreferable(); }
183 bool IsOk(const SMESH_Hypothesis* aHyp,
184 const TopoDS_Shape& aShape) const;
185 void findPreferable();
186 };
187
189 bool IsOk(const SMESH_Hypothesis* aHyp,
190 const TopoDS_Shape& aShape) const;
191 };
192
193};
194
195
196#endif
#define SMESH_EXPORT
Definition: SMESH_SMESH.hxx:37
Definition: SMESH_HypoFilter.hxx:57
Comparison
Definition: SMESH_HypoFilter.hxx:108
bool IsAny() const
return true if contains no predicates
Definition: SMESH_HypoFilter.hxx:93
SMESH_HypoFilter(const SMESH_HypoFilter &)
Definition: SMESH_HypoFilter.hxx:110
void add(Logical bool_op, SMESH_HypoPredicate *pred)
Definition: SMESH_HypoFilter.hxx:112
Logical
Definition: SMESH_HypoFilter.hxx:107
@ AND
Definition: SMESH_HypoFilter.hxx:107
bool IsEmpty() const
Definition: SMESH_HypoFilter.hxx:83
int myNbPredicates
Definition: SMESH_HypoFilter.hxx:103
Definition: SMESH_HypoFilter.hxx:45
virtual ~SMESH_HypoPredicate()
Definition: SMESH_HypoFilter.hxx:50
int _logical_op
Definition: SMESH_HypoFilter.hxx:52
virtual bool IsOk(const SMESH_Hypothesis *aHyp, const TopoDS_Shape &aShape) const =0
Definition: SMESH_Hypothesis.hxx:48
Definition: SMESH_Mesh.hxx:80
TFloatVector TValue
Definition: MED_Structures.hxx:757
Definition: SMESH_HypoFilter.hxx:155
int _shapeType
Definition: SMESH_HypoFilter.hxx:156
Definition: SMESH_HypoFilter.hxx:149
DimPredicate(Comparison comp, int dim)
Definition: SMESH_HypoFilter.hxx:150
Definition: SMESH_HypoFilter.hxx:162
InstancePredicate(const SMESH_Hypothesis *hypo)
Definition: SMESH_HypoFilter.hxx:164
const SMESH_Hypothesis * _hypo
Definition: SMESH_HypoFilter.hxx:163
Definition: SMESH_HypoFilter.hxx:169
IsAssignedToPredicate(const TopoDS_Shape &mainShape)
Definition: SMESH_HypoFilter.hxx:171
TopoDS_Shape _mainShape
Definition: SMESH_HypoFilter.hxx:170
Definition: SMESH_HypoFilter.hxx:188
Definition: SMESH_HypoFilter.hxx:176
TopTools_MapOfShape _preferableShapes
Definition: SMESH_HypoFilter.hxx:179
const SMESH_Mesh & _mesh
Definition: SMESH_HypoFilter.hxx:178
TopoDS_Shape _shape
Definition: SMESH_HypoFilter.hxx:177
IsMoreLocalThanPredicate(const TopoDS_Shape &shape, const SMESH_Mesh &mesh)
Definition: SMESH_HypoFilter.hxx:180
Definition: SMESH_HypoFilter.hxx:136
NamePredicate(std::string name)
Definition: SMESH_HypoFilter.hxx:138
std::string _name
Definition: SMESH_HypoFilter.hxx:137
Definition: SMESH_HypoFilter.hxx:143
TypePredicate(Comparison comp, int hypType)
Definition: SMESH_HypoFilter.hxx:144
Definition: SMESH_HypoFilter.hxx:123
virtual TValue Value(const SMESH_Hypothesis *aHyp) const =0
virtual bool IsOk(const SMESH_Hypothesis *aHyp, const TopoDS_Shape &) const
Definition: SMESH_HypoFilter.hxx:127
TValue _val
Definition: SMESH_HypoFilter.hxx:125
Comparison _comp
Definition: SMESH_HypoFilter.hxx:124