Salome HOME
Merging with branch OCC_development_for_3_2_0b1
[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 #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_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* IsApplicableTo(const TopoDS_Shape& theShape);
73   static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape);
74   static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
75   static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
76   static SMESH_HypoPredicate* HasName(const std::string & theName);
77   static SMESH_HypoPredicate* HasDim(const int theDim);
78   static SMESH_HypoPredicate* HasType(const int theHypType);
79
80   bool IsOk (const SMESH_Hypothesis* aHyp,
81              const TopoDS_Shape&     aShape) const;
82   // check aHyp or/and aShape it is assigned to
83
84   ~SMESH_HypoFilter();
85
86
87  protected:
88   // fields
89
90   std::list<SMESH_HypoPredicate*> myPredicates;
91
92   // private methods
93
94   enum Logical { AND, AND_NOT, OR, OR_NOT };
95   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
96
97   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
98
99   void add( Logical bool_op, SMESH_HypoPredicate* pred )
100   {
101     if ( pred ) {
102       pred->_logical_op = bool_op;
103       myPredicates.push_back( pred );
104     }
105   }
106
107   // predicates implementation
108
109   template <typename TValue>
110     struct templPredicate: public SMESH_HypoPredicate {
111       Comparison _comp;
112       TValue     _val;
113       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
114       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
115       {
116         if      ( _comp == EQUAL )     return _val == Value( aHyp );
117         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
118         else if ( _comp == MORE )      return _val < Value( aHyp );
119         else                           return _val > Value( aHyp );
120       }
121     };
122
123   struct NamePredicate : public SMESH_HypoPredicate {
124     std::string _name;
125     NamePredicate( std::string name ): _name(name){}
126     bool IsOk(const SMESH_Hypothesis* aHyp,
127               const TopoDS_Shape&     aShape) const;
128   };
129   
130   struct TypePredicate : public templPredicate< int > {
131     TypePredicate( Comparison comp, int hypType )
132     { _comp = comp; _val = hypType; }
133     int Value( const SMESH_Hypothesis* aHyp ) const;
134   };
135   
136   struct DimPredicate : public templPredicate< int > {
137     DimPredicate( Comparison comp, int dim )
138     { _comp = comp; _val = dim; }
139     int Value( const SMESH_Hypothesis* aHyp ) const;
140   };
141   
142   struct ApplicablePredicate : public SMESH_HypoPredicate {
143     int _shapeType;
144     ApplicablePredicate( const TopoDS_Shape& theShape );
145     bool IsOk(const SMESH_Hypothesis* aHyp,
146               const TopoDS_Shape&     aShape) const;
147   };
148         
149   struct InstancePredicate : public SMESH_HypoPredicate {
150     const SMESH_Hypothesis* _hypo;
151     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
152     bool IsOk(const SMESH_Hypothesis* aHyp,
153               const TopoDS_Shape&     aShape) const;
154   };
155         
156   struct IsAssignedToPredicate : public SMESH_HypoPredicate {
157     TopoDS_Shape _mainShape;
158     IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
159     bool IsOk(const SMESH_Hypothesis* aHyp,
160               const TopoDS_Shape&     aShape) const;
161   };
162         
163 };
164
165
166 #endif