Salome HOME
activateModule/deactivateModule functions are made "bool".
[modules/smesh.git] / src / SMESH / SMESH_HypoFilter.hxx
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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_HypoFilter.hxx
25 //  Module : SMESH
26 //  $Header$
27
28
29 #ifndef SMESH_HypoFilter_HeaderFile
30 #define SMESH_HypoFilter_HeaderFile
31
32 // ===========================
33 // Filter of SMESH_Hypothesis
34 // ===========================
35
36 #include <list>
37 #include <string>
38
39 class SMESH_HypoFilter;
40 class SMESH_Hypothesis;
41 class TopoDS_Shape;
42
43 class SMESH_HypoPredicate {
44  public:
45   virtual bool IsOk(const SMESH_Hypothesis* aHyp,
46                     const TopoDS_Shape&     aShape) const = 0;
47   // check aHyp or/and aShape it is assigned to
48   virtual ~SMESH_HypoPredicate() {}
49  private:
50   int _logical_op;
51   friend class SMESH_HypoFilter;
52 };
53
54 class SMESH_HypoFilter: public SMESH_HypoPredicate
55 {
56  public:
57   // Create and add predicates.
58   // Added predicates will be destroyed by filter when it dies
59   SMESH_HypoFilter();
60   SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
61   // notNagate==false means !aPredicate->IsOk()
62   void Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
63   void And   ( SMESH_HypoPredicate* aPredicate );
64   void AndNot( SMESH_HypoPredicate* aPredicate );
65   void Or    ( SMESH_HypoPredicate* aPredicate );
66   void OrNot ( SMESH_HypoPredicate* aPredicate );
67
68   // Create predicates
69   static SMESH_HypoPredicate* IsAlgo();
70   static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theMainShape);
71   static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
72   static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
73   static SMESH_HypoPredicate* HasName(const std::string & theName);
74   static SMESH_HypoPredicate* HasDim(const int theDim);
75   static SMESH_HypoPredicate* HasType(const int theHypType);
76
77   bool IsOk (const SMESH_Hypothesis* aHyp,
78              const TopoDS_Shape&     aShape) const;
79   // check aHyp or/and aShape it is assigned to
80
81   ~SMESH_HypoFilter();
82
83
84  protected:
85   // fields
86
87   std::list<SMESH_HypoPredicate*> myPredicates;
88
89   // private methods
90
91   enum Logical { AND, AND_NOT, OR, OR_NOT };
92   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
93
94   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
95
96   void add( Logical bool_op, SMESH_HypoPredicate* pred )
97   {
98     if ( pred ) {
99       pred->_logical_op = bool_op;
100       myPredicates.push_back( pred );
101     }
102   }
103
104   // predicates implementation
105
106   template <typename TValue>
107     struct templPredicate: public SMESH_HypoPredicate {
108       Comparison _comp;
109       TValue     _val;
110       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
111       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
112       {
113         if      ( _comp == EQUAL )     return _val == Value( aHyp );
114         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
115         else if ( _comp == MORE )      return _val < Value( aHyp );
116         else                           return _val > Value( aHyp );
117       }
118     };
119
120   struct NamePredicate : public SMESH_HypoPredicate {
121     std::string _name;
122     NamePredicate( std::string name ): _name(name){}
123     bool IsOk(const SMESH_Hypothesis* aHyp,
124               const TopoDS_Shape&     aShape) const;
125   };
126   
127   struct TypePredicate : public templPredicate< int > {
128     TypePredicate( Comparison comp, int hypType )
129     { _comp = comp; _val = hypType; }
130     int Value( const SMESH_Hypothesis* aHyp ) const;
131   };
132   
133   struct DimPredicate : public templPredicate< int > {
134     DimPredicate( Comparison comp, int dim )
135     { _comp = comp; _val = dim; }
136     int Value( const SMESH_Hypothesis* aHyp ) const;
137   };
138   
139   struct ApplicablePredicate : public SMESH_HypoPredicate {
140     int _shapeType;
141     ApplicablePredicate( const TopoDS_Shape& theShape );
142     bool IsOk(const SMESH_Hypothesis* aHyp,
143               const TopoDS_Shape&     aShape) const;
144   };
145         
146   struct InstancePredicate : public SMESH_HypoPredicate {
147     const SMESH_Hypothesis* _hypo;
148     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
149     bool IsOk(const SMESH_Hypothesis* aHyp,
150               const TopoDS_Shape&     aShape) const;
151   };
152         
153   struct IsGlobalPredicate : public SMESH_HypoPredicate {
154     const TopoDS_Shape& _mainShape;
155     IsGlobalPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
156     bool IsOk(const SMESH_Hypothesis* aHyp,
157               const TopoDS_Shape&     aShape) const;
158   };
159         
160 };
161
162
163 #endif