Back to index

salome-smesh  6.5.0
SMESH_HypoFilter.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 #include <TopTools_MapOfShape.hxx>
00040 
00041 class SMESH_HypoFilter;
00042 class SMESH_Hypothesis;
00043 class SMESH_Mesh;
00044 
00045 class SMESH_EXPORT SMESH_HypoPredicate {
00046  public:
00047   virtual bool IsOk(const SMESH_Hypothesis* aHyp,
00048                     const TopoDS_Shape&     aShape) const = 0;
00049   // check aHyp or/and aShape it is assigned to
00050   virtual ~SMESH_HypoPredicate() {}
00051  private:
00052   int _logical_op;
00053   friend class SMESH_HypoFilter;
00054 };
00055 
00056 class SMESH_EXPORT SMESH_HypoFilter: public SMESH_HypoPredicate
00057 {
00058  public:
00059   // Create and add predicates.
00060   // Added predicates will be destroyed by filter when it dies
00061   SMESH_HypoFilter();
00062   SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
00063   // notNagate==false means !aPredicate->IsOk()
00064   SMESH_HypoFilter & Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
00065   SMESH_HypoFilter & And   ( SMESH_HypoPredicate* aPredicate );
00066   SMESH_HypoFilter & AndNot( SMESH_HypoPredicate* aPredicate );
00067   SMESH_HypoFilter & Or    ( SMESH_HypoPredicate* aPredicate );
00068   SMESH_HypoFilter & OrNot ( SMESH_HypoPredicate* aPredicate );
00069 
00070   // Create predicates
00071   static SMESH_HypoPredicate* IsAlgo();
00072   static SMESH_HypoPredicate* IsAuxiliary();
00073   static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theShape);
00074   static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape);
00075   static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
00076   static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
00077   static SMESH_HypoPredicate* IsMoreLocalThan(const TopoDS_Shape& theShape,
00078                                               const SMESH_Mesh&   theMesh);
00079   static SMESH_HypoPredicate* HasName(const std::string & theName);
00080   static SMESH_HypoPredicate* HasDim(const int theDim);
00081   static SMESH_HypoPredicate* HasType(const int theHypType);
00082 
00083   bool IsEmpty() const { return myPredicates.empty(); }
00084 
00088   bool IsOk (const SMESH_Hypothesis* aHyp,
00089              const TopoDS_Shape&     aShape) const;
00093   bool IsAny() const { return myPredicates.empty(); }
00094 
00095   ~SMESH_HypoFilter();
00096 
00097 
00098  protected:
00099   // fields
00100 
00101   std::list<SMESH_HypoPredicate*> myPredicates;
00102 
00103   // private methods
00104 
00105   enum Logical { AND, AND_NOT, OR, OR_NOT };
00106   enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
00107 
00108   SMESH_HypoFilter(const SMESH_HypoFilter& other){}
00109 
00110   void add( Logical bool_op, SMESH_HypoPredicate* pred )
00111   {
00112     if ( pred ) {
00113       pred->_logical_op = bool_op;
00114       myPredicates.push_back( pred );
00115     }
00116   }
00117 
00118   // predicates implementation
00119 
00120   template <typename TValue>
00121     struct templPredicate: public SMESH_HypoPredicate {
00122       Comparison _comp;
00123       TValue     _val;
00124       virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
00125       virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
00126       {
00127         if      ( _comp == EQUAL )     return _val == Value( aHyp );
00128         else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
00129         else if ( _comp == MORE )      return _val < Value( aHyp );
00130         else                           return _val > Value( aHyp );
00131       }
00132     };
00133 
00134   struct NamePredicate : public SMESH_HypoPredicate {
00135     std::string _name;
00136     NamePredicate( std::string name ): _name(name){}
00137     bool IsOk(const SMESH_Hypothesis* aHyp,
00138               const TopoDS_Shape&     aShape) const;
00139   };
00140   
00141   struct TypePredicate : public templPredicate< int > {
00142     TypePredicate( Comparison comp, int hypType )
00143     { _comp = comp; _val = hypType; }
00144     int Value( const SMESH_Hypothesis* aHyp ) const;
00145   };
00146   
00147   struct DimPredicate : public templPredicate< int > {
00148     DimPredicate( Comparison comp, int dim )
00149     { _comp = comp; _val = dim; }
00150     int Value( const SMESH_Hypothesis* aHyp ) const;
00151   };
00152   
00153   struct ApplicablePredicate : public SMESH_HypoPredicate {
00154     int _shapeType;
00155     ApplicablePredicate( const TopoDS_Shape& theShape );
00156     bool IsOk(const SMESH_Hypothesis* aHyp,
00157               const TopoDS_Shape&     aShape) const;
00158   };
00159         
00160   struct InstancePredicate : public SMESH_HypoPredicate {
00161     const SMESH_Hypothesis* _hypo;
00162     InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
00163     bool IsOk(const SMESH_Hypothesis* aHyp,
00164               const TopoDS_Shape&     aShape) const;
00165   };
00166         
00167   struct IsAssignedToPredicate : public SMESH_HypoPredicate {
00168     TopoDS_Shape _mainShape;
00169     IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
00170     bool IsOk(const SMESH_Hypothesis* aHyp,
00171               const TopoDS_Shape&     aShape) const;
00172   };
00173         
00174   struct IsMoreLocalThanPredicate : public SMESH_HypoPredicate {
00175     TopoDS_Shape        _shape;
00176     const SMESH_Mesh&   _mesh;
00177     TopTools_MapOfShape _preferableShapes;
00178     IsMoreLocalThanPredicate( const TopoDS_Shape& shape,
00179                               const SMESH_Mesh&   mesh )
00180       :_shape(shape),_mesh(mesh) { findPreferable(); }
00181     bool IsOk(const SMESH_Hypothesis* aHyp,
00182               const TopoDS_Shape&     aShape) const;
00183     void findPreferable();
00184   };
00185         
00186   struct IsAuxiliaryPredicate : public SMESH_HypoPredicate {
00187     bool IsOk(const SMESH_Hypothesis* aHyp,
00188               const TopoDS_Shape&     aShape) const;
00189   };
00190         
00191 };
00192 
00193 
00194 #endif