Version: 6.3.1

src/SMESH/SMESH_HypoFilter.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 
00023 //  SMESH SMESH : implementaion of SMESH idl descriptions
00024 //  File   : SMESH_HypoFilter.hxx
00025 //  Module : SMESH
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 
00080   bool IsEmpty() const { return myPredicates.empty(); }
00081 
00085   bool IsOk (const SMESH_Hypothesis* aHyp,
00086              const TopoDS_Shape&     aShape) const;
00090   bool IsAny() const { return myPredicates.empty(); }
00091 
00092   ~SMESH_HypoFilter();
00093 
00094 
00095  protected:
00096   // fields
00097 
00098   std::list<SMESH_HypoPredicate*> myPredicates;
00099 
00100   // private methods
00101 
00102   enum Logical { AND, AND_NOT, OR, OR_NOT };
00103   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
00104 
00105   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
00106 
00107   void add( Logical bool_op, SMESH_HypoPredicate* pred )
00108   {
00109     if ( pred ) {
00110       pred->_logical_op = bool_op;
00111       myPredicates.push_back( pred );
00112     }
00113   }
00114 
00115   // predicates implementation
00116 
00117   template <typename TValue>
00118     struct templPredicate: public SMESH_HypoPredicate {
00119       Comparison _comp;
00120       TValue     _val;
00121       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
00122       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
00123       {
00124         if      ( _comp == EQUAL )     return _val == Value( aHyp );
00125         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
00126         else if ( _comp == MORE )      return _val < Value( aHyp );
00127         else                           return _val > Value( aHyp );
00128       }
00129     };
00130 
00131   struct NamePredicate : public SMESH_HypoPredicate {
00132     std::string _name;
00133     NamePredicate( std::string name ): _name(name){}
00134     bool IsOk(const SMESH_Hypothesis* aHyp,
00135               const TopoDS_Shape&     aShape) const;
00136   };
00137   
00138   struct TypePredicate : public templPredicate< int > {
00139     TypePredicate( Comparison comp, int hypType )
00140     { _comp = comp; _val = hypType; }
00141     int Value( const SMESH_Hypothesis* aHyp ) const;
00142   };
00143   
00144   struct DimPredicate : public templPredicate< int > {
00145     DimPredicate( Comparison comp, int dim )
00146     { _comp = comp; _val = dim; }
00147     int Value( const SMESH_Hypothesis* aHyp ) const;
00148   };
00149   
00150   struct ApplicablePredicate : public SMESH_HypoPredicate {
00151     int _shapeType;
00152     ApplicablePredicate( const TopoDS_Shape& theShape );
00153     bool IsOk(const SMESH_Hypothesis* aHyp,
00154               const TopoDS_Shape&     aShape) const;
00155   };
00156         
00157   struct InstancePredicate : public SMESH_HypoPredicate {
00158     const SMESH_Hypothesis* _hypo;
00159     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
00160     bool IsOk(const SMESH_Hypothesis* aHyp,
00161               const TopoDS_Shape&     aShape) const;
00162   };
00163         
00164   struct IsAssignedToPredicate : public SMESH_HypoPredicate {
00165     TopoDS_Shape _mainShape;
00166     IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
00167     bool IsOk(const SMESH_Hypothesis* aHyp,
00168               const TopoDS_Shape&     aShape) const;
00169   };
00170         
00171   struct IsMoreLocalThanPredicate : public SMESH_HypoPredicate {
00172     TopoDS_Shape _shape;
00173     IsMoreLocalThanPredicate( const TopoDS_Shape& shape ):_shape(shape){}
00174     bool IsOk(const SMESH_Hypothesis* aHyp,
00175               const TopoDS_Shape&     aShape) const;
00176   };
00177         
00178   struct IsAuxiliaryPredicate : public SMESH_HypoPredicate {
00179     bool IsOk(const SMESH_Hypothesis* aHyp,
00180               const TopoDS_Shape&     aShape) const;
00181   };
00182         
00183 };
00184 
00185 
00186 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS