Salome HOME
Merge from V6_3_BR 06/06/2011
[modules/smesh.git] / src / SMESH / SMESH_HypoFilter.hxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, 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.
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 : implementaion 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
40 class SMESH_HypoFilter;
41 class SMESH_Hypothesis;
42
43 class SMESH_EXPORT 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_EXPORT 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   SMESH_HypoFilter & Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
63   SMESH_HypoFilter & And   ( SMESH_HypoPredicate* aPredicate );
64   SMESH_HypoFilter & AndNot( SMESH_HypoPredicate* aPredicate );
65   SMESH_HypoFilter & Or    ( SMESH_HypoPredicate* aPredicate );
66   SMESH_HypoFilter & OrNot ( SMESH_HypoPredicate* aPredicate );
67
68   // Create predicates
69   static SMESH_HypoPredicate* IsAlgo();
70   static SMESH_HypoPredicate* IsAuxiliary();
71   static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theShape);
72   static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape);
73   static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
74   static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
75   static SMESH_HypoPredicate* IsMoreLocalThan(const TopoDS_Shape& theShape);
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 IsEmpty() const { return myPredicates.empty(); }
81
82   /*!
83    * \brief check aHyp or/and aShape it is assigned to
84    */
85   bool IsOk (const SMESH_Hypothesis* aHyp,
86              const TopoDS_Shape&     aShape) const;
87   /*!
88    * \brief return true if contains no predicates
89    */
90   bool IsAny() const { return myPredicates.empty(); }
91
92   ~SMESH_HypoFilter();
93
94
95  protected:
96   // fields
97
98   std::list<SMESH_HypoPredicate*> myPredicates;
99
100   // private methods
101
102   enum Logical { AND, AND_NOT, OR, OR_NOT };
103   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
104
105   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
106
107   void add( Logical bool_op, SMESH_HypoPredicate* pred )
108   {
109     if ( pred ) {
110       pred->_logical_op = bool_op;
111       myPredicates.push_back( pred );
112     }
113   }
114
115   // predicates implementation
116
117   template <typename TValue>
118     struct templPredicate: public SMESH_HypoPredicate {
119       Comparison _comp;
120       TValue     _val;
121       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
122       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
123       {
124         if      ( _comp == EQUAL )     return _val == Value( aHyp );
125         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
126         else if ( _comp == MORE )      return _val < Value( aHyp );
127         else                           return _val > Value( aHyp );
128       }
129     };
130
131   struct NamePredicate : public SMESH_HypoPredicate {
132     std::string _name;
133     NamePredicate( std::string name ): _name(name){}
134     bool IsOk(const SMESH_Hypothesis* aHyp,
135               const TopoDS_Shape&     aShape) const;
136   };
137   
138   struct TypePredicate : public templPredicate< int > {
139     TypePredicate( Comparison comp, int hypType )
140     { _comp = comp; _val = hypType; }
141     int Value( const SMESH_Hypothesis* aHyp ) const;
142   };
143   
144   struct DimPredicate : public templPredicate< int > {
145     DimPredicate( Comparison comp, int dim )
146     { _comp = comp; _val = dim; }
147     int Value( const SMESH_Hypothesis* aHyp ) const;
148   };
149   
150   struct ApplicablePredicate : public SMESH_HypoPredicate {
151     int _shapeType;
152     ApplicablePredicate( const TopoDS_Shape& theShape );
153     bool IsOk(const SMESH_Hypothesis* aHyp,
154               const TopoDS_Shape&     aShape) const;
155   };
156         
157   struct InstancePredicate : public SMESH_HypoPredicate {
158     const SMESH_Hypothesis* _hypo;
159     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
160     bool IsOk(const SMESH_Hypothesis* aHyp,
161               const TopoDS_Shape&     aShape) const;
162   };
163         
164   struct IsAssignedToPredicate : public SMESH_HypoPredicate {
165     TopoDS_Shape _mainShape;
166     IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
167     bool IsOk(const SMESH_Hypothesis* aHyp,
168               const TopoDS_Shape&     aShape) const;
169   };
170         
171   struct IsMoreLocalThanPredicate : public SMESH_HypoPredicate {
172     TopoDS_Shape _shape;
173     IsMoreLocalThanPredicate( const TopoDS_Shape& shape ):_shape(shape){}
174     bool IsOk(const SMESH_Hypothesis* aHyp,
175               const TopoDS_Shape&     aShape) const;
176   };
177         
178   struct IsAuxiliaryPredicate : public SMESH_HypoPredicate {
179     bool IsOk(const SMESH_Hypothesis* aHyp,
180               const TopoDS_Shape&     aShape) const;
181   };
182         
183 };
184
185
186 #endif