Salome HOME
Merging with WPdev
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #include "SMESH_SMESH.hxx"
33
34 // ===========================
35 // Filter of SMESH_Hypothesis
36 // ===========================
37
38 #include <list>
39 #include <string>
40 #include <TopoDS_Shape.hxx>
41
42 class SMESH_HypoFilter;
43 class SMESH_Hypothesis;
44
45 class SMESH_EXPORT SMESH_HypoPredicate {
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
50   virtual ~SMESH_HypoPredicate() {}
51  private:
52   int _logical_op;
53   friend class SMESH_HypoFilter;
54 };
55
56 class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate
57 {
58  public:
59   // Create and add predicates.
60   // Added predicates will be destroyed by filter when it dies
61   SMESH_HypoFilter();
62   SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
63   // notNagate==false means !aPredicate->IsOk()
64   SMESH_HypoFilter & Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate = 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* HasName(const std::string & theName);
78   static SMESH_HypoPredicate* HasDim(const int theDim);
79   static SMESH_HypoPredicate* HasType(const int theHypType);
80
81   bool IsOk (const SMESH_Hypothesis* aHyp,
82              const TopoDS_Shape&     aShape) const;
83   // check aHyp or/and aShape it is assigned to
84
85   ~SMESH_HypoFilter();
86
87
88  protected:
89   // fields
90
91   std::list<SMESH_HypoPredicate*> myPredicates;
92
93   // private methods
94
95   enum Logical { AND, AND_NOT, OR, OR_NOT };
96   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
97
98   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
99
100   void add( Logical bool_op, SMESH_HypoPredicate* pred )
101   {
102     if ( pred ) {
103       pred->_logical_op = bool_op;
104       myPredicates.push_back( pred );
105     }
106   }
107
108   // predicates implementation
109
110   template <typename TValue>
111     struct templPredicate: public SMESH_HypoPredicate {
112       Comparison _comp;
113       TValue     _val;
114       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
115       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
116       {
117         if      ( _comp == EQUAL )     return _val == Value( aHyp );
118         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
119         else if ( _comp == MORE )      return _val < Value( aHyp );
120         else                           return _val > Value( aHyp );
121       }
122     };
123
124   struct NamePredicate : public SMESH_HypoPredicate {
125     std::string _name;
126     NamePredicate( std::string name ): _name(name){}
127     bool IsOk(const SMESH_Hypothesis* aHyp,
128               const TopoDS_Shape&     aShape) const;
129   };
130   
131   struct TypePredicate : public templPredicate< int > {
132     TypePredicate( Comparison comp, int hypType )
133     { _comp = comp; _val = hypType; }
134     int Value( const SMESH_Hypothesis* aHyp ) const;
135   };
136   
137   struct DimPredicate : public templPredicate< int > {
138     DimPredicate( Comparison comp, int dim )
139     { _comp = comp; _val = dim; }
140     int Value( const SMESH_Hypothesis* aHyp ) const;
141   };
142   
143   struct ApplicablePredicate : public SMESH_HypoPredicate {
144     int _shapeType;
145     ApplicablePredicate( const TopoDS_Shape& theShape );
146     bool IsOk(const SMESH_Hypothesis* aHyp,
147               const TopoDS_Shape&     aShape) const;
148   };
149         
150   struct InstancePredicate : public SMESH_HypoPredicate {
151     const SMESH_Hypothesis* _hypo;
152     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
153     bool IsOk(const SMESH_Hypothesis* aHyp,
154               const TopoDS_Shape&     aShape) const;
155   };
156         
157   struct IsAssignedToPredicate : public SMESH_HypoPredicate {
158     TopoDS_Shape _mainShape;
159     IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
160     bool IsOk(const SMESH_Hypothesis* aHyp,
161               const TopoDS_Shape&     aShape) const;
162   };
163         
164   struct IsAuxiliaryPredicate : public SMESH_HypoPredicate {
165     bool IsOk(const SMESH_Hypothesis* aHyp,
166               const TopoDS_Shape&     aShape) const;
167   };
168         
169 };
170
171
172 #endif