SALOME - SMESH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SMESH_HypoFilter.hxx
Go to the documentation of this file.
00001 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 //  This library is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU Lesser General Public
00008 //  License as published by the Free Software Foundation; either
00009 //  version 2.1 of the License.
00010 //
00011 //  This library is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 //  Lesser General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU Lesser General Public
00017 //  License along with this library; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  SMESH SMESH : implementaion of SMESH idl descriptions
00023 //  File   : SMESH_HypoFilter.hxx
00024 //  Module : SMESH
00025 //  $Header$
00026 //
00027 #ifndef SMESH_HypoFilter_HeaderFile
00028 #define SMESH_HypoFilter_HeaderFile
00029 
00030 #include "SMESH_SMESH.hxx"
00031 
00032 // ===========================
00033 // Filter of SMESH_Hypothesis
00034 // ===========================
00035 
00036 #include <list>
00037 #include <string>
00038 #include <TopoDS_Shape.hxx>
00039 
00040 class SMESH_HypoFilter;
00041 class SMESH_Hypothesis;
00042 
00043 class SMESH_EXPORT SMESH_HypoPredicate {
00044  public:
00045   virtual bool IsOk(const SMESH_Hypothesis* aHyp,
00046                     const TopoDS_Shape&     aShape) const = 0;
00047   // check aHyp or/and aShape it is assigned to
00048   virtual ~SMESH_HypoPredicate() {}
00049  private:
00050   int _logical_op;
00051   friend class SMESH_HypoFilter;
00052 };
00053 
00054 class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate
00055 {
00056  public:
00057   // Create and add predicates.
00058   // Added predicates will be destroyed by filter when it dies
00059   SMESH_HypoFilter();
00060   SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
00061   // notNagate==false means !aPredicate->IsOk()
00062   SMESH_HypoFilter & Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
00063   SMESH_HypoFilter & And   ( SMESH_HypoPredicate* aPredicate );
00064   SMESH_HypoFilter & AndNot( SMESH_HypoPredicate* aPredicate );
00065   SMESH_HypoFilter & Or    ( SMESH_HypoPredicate* aPredicate );
00066   SMESH_HypoFilter & OrNot ( SMESH_HypoPredicate* aPredicate );
00067 
00068   // Create predicates
00069   static SMESH_HypoPredicate* IsAlgo();
00070   static SMESH_HypoPredicate* IsAuxiliary();
00071   static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theShape);
00072   static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape);
00073   static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
00074   static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
00075   static SMESH_HypoPredicate* IsMoreLocalThan(const TopoDS_Shape& theShape);
00076   static SMESH_HypoPredicate* HasName(const std::string & theName);
00077   static SMESH_HypoPredicate* HasDim(const int theDim);
00078   static SMESH_HypoPredicate* HasType(const int theHypType);
00079 
00083   bool IsOk (const SMESH_Hypothesis* aHyp,
00084              const TopoDS_Shape&     aShape) const;
00088   bool IsAny() const { return myPredicates.empty(); }
00089 
00090   ~SMESH_HypoFilter();
00091 
00092 
00093  protected:
00094   // fields
00095 
00096   std::list<SMESH_HypoPredicate*> myPredicates;
00097 
00098   // private methods
00099  #ifdef __BORLANDC__
00100  public:
00101  #endif
00102   enum Logical { AND, AND_NOT, OR, OR_NOT };
00103   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
00104  #ifdef __BORLANDC__
00105  protected:
00106  #endif
00107   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
00108 
00109   void add( Logical bool_op, SMESH_HypoPredicate* pred )
00110   {
00111     if ( pred ) {
00112       pred->_logical_op = bool_op;
00113       myPredicates.push_back( pred );
00114     }
00115   }
00116 
00117   // predicates implementation
00118 
00119   template <typename TValue>
00120     struct templPredicate: public SMESH_HypoPredicate {
00121       Comparison _comp;
00122       TValue     _val;
00123       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
00124       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
00125       {
00126         if      ( _comp == EQUAL )     return _val == Value( aHyp );
00127         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
00128         else if ( _comp == MORE )      return _val < Value( aHyp );
00129         else                           return _val > Value( aHyp );
00130       }
00131     };
00132 
00133   struct NamePredicate : public SMESH_HypoPredicate {
00134     std::string _name;
00135     NamePredicate( std::string name ): _name(name){}
00136     bool IsOk(const SMESH_Hypothesis* aHyp,
00137               const TopoDS_Shape&     aShape) const;
00138   };
00139   
00140   struct TypePredicate : public templPredicate< int > {
00141     TypePredicate( Comparison comp, int hypType )
00142     { _comp = comp; _val = hypType; }
00143     int Value( const SMESH_Hypothesis* aHyp ) const;
00144   };
00145   
00146   struct DimPredicate : public templPredicate< int > {
00147     DimPredicate( Comparison comp, int dim )
00148     { _comp = comp; _val = dim; }
00149     int Value( const SMESH_Hypothesis* aHyp ) const;
00150   };
00151   
00152   struct ApplicablePredicate : public SMESH_HypoPredicate {
00153     int _shapeType;
00154     ApplicablePredicate( const TopoDS_Shape& theShape );
00155     bool IsOk(const SMESH_Hypothesis* aHyp,
00156               const TopoDS_Shape&     aShape) const;
00157   };
00158         
00159   struct InstancePredicate : public SMESH_HypoPredicate {
00160     const SMESH_Hypothesis* _hypo;
00161     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
00162     bool IsOk(const SMESH_Hypothesis* aHyp,
00163               const TopoDS_Shape&     aShape) const;
00164   };
00165         
00166   struct IsAssignedToPredicate : public SMESH_HypoPredicate {
00167     TopoDS_Shape _mainShape;
00168     IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
00169     bool IsOk(const SMESH_Hypothesis* aHyp,
00170               const TopoDS_Shape&     aShape) const;
00171   };
00172         
00173   struct IsMoreLocalThanPredicate : public SMESH_HypoPredicate {
00174     TopAbs_ShapeEnum _shapeType;
00175     IsMoreLocalThanPredicate( const TopoDS_Shape& shape ):_shapeType(shape.ShapeType()){}
00176     bool IsOk(const SMESH_Hypothesis* aHyp,
00177               const TopoDS_Shape&     aShape) const;
00178   };
00179         
00180   struct IsAuxiliaryPredicate : public SMESH_HypoPredicate {
00181     bool IsOk(const SMESH_Hypothesis* aHyp,
00182               const TopoDS_Shape&     aShape) const;
00183   };
00184         
00185 };
00186 
00187 
00188 #endif