Salome HOME
PAL7933. Create class SMESH_HypoFilter
authoreap <eap@opencascade.com>
Fri, 4 Feb 2005 10:31:55 +0000 (10:31 +0000)
committereap <eap@opencascade.com>
Fri, 4 Feb 2005 10:31:55 +0000 (10:31 +0000)
src/SMESH/Makefile.in
src/SMESH/SMESH_HypoFilter.cxx [new file with mode: 0644]
src/SMESH/SMESH_HypoFilter.hxx [new file with mode: 0644]

index 4189c810764286f729b5e4bccb700e95467612be..e7d15e00a5388540e98a16f9027828d0a908f4a4 100644 (file)
@@ -63,7 +63,8 @@ LIB_SRC = SMESH_Gen.cxx SMESH_Mesh.cxx SMESH_subMesh.cxx \
          SMESH_Group.cxx \
          SMESH_MeshEditor.cxx \
          SMESH_Block.cxx \
-         SMESH_Pattern.cxx
+         SMESH_Pattern.cxx \
+          SMESH_HypoFilter.cxx
 
 LIB_SERVER_IDL = 
 
diff --git a/src/SMESH/SMESH_HypoFilter.cxx b/src/SMESH/SMESH_HypoFilter.cxx
new file mode 100644 (file)
index 0000000..783547b
--- /dev/null
@@ -0,0 +1,290 @@
+//  SMESH SMESH : implementaion of SMESH idl descriptions
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SMESH_HypoFilter.cxx
+//  Module : SMESH
+//  $Header$
+
+#include "SMESH_HypoFilter.hxx"
+
+#include "SMESH_Hypothesis.hxx"
+#include "SMESH_subMesh.hxx"
+
+using namespace std;
+
+
+//=======================================================================
+//function : NamePredicate::Value
+//purpose  : 
+//=======================================================================
+
+bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
+                                            const TopoDS_Shape&     /*aShape*/ ) const
+{
+  return ( _name == aHyp->GetName() );
+}
+
+//=======================================================================
+//function : TypePredicate::Value
+//purpose  : 
+//=======================================================================
+
+int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
+{
+  return aHyp->GetType();
+};
+
+//=======================================================================
+//function : DimPredicate::Value
+//purpose  : 
+//=======================================================================
+
+int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
+{
+  return aHyp->GetDim();
+}
+
+//=======================================================================
+//function : ApplicablePredicate::IsOk
+//purpose  : 
+//=======================================================================
+
+bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
+                                                 const TopoDS_Shape&     /*aShape*/) const
+{
+  return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
+};
+
+//=======================================================================
+//function : ApplicablePredicate::ApplicablePredicate
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoFilter::ApplicablePredicate::ApplicablePredicate( const TopoDS_Shape& theShape )
+{
+  _shapeType = ( theShape.IsNull() ? TopAbs_SHAPE : theShape.ShapeType());
+}
+
+//=======================================================================
+//function : InstancePredicate::IsOk
+//purpose  : 
+//=======================================================================
+
+bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
+                                               const TopoDS_Shape&     /*aShape*/) const
+{
+  return _hypo == aHyp;
+}
+
+//=======================================================================
+//function : IsGlobalPredicate::IsOk
+//purpose  : 
+//=======================================================================
+
+bool SMESH_HypoFilter::IsGlobalPredicate::IsOk(const SMESH_Hypothesis* aHyp,
+                                               const TopoDS_Shape&     aShape) const
+{
+  return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
+}
+
+//=======================================================================
+//function : SMESH_HypoFilter
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoFilter::SMESH_HypoFilter()
+{
+}
+
+//=======================================================================
+//function : SMESH_HypoFilter
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoFilter::SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate )
+{
+  add( notNagate ? AND : AND_NOT, aPredicate );
+}
+
+//=======================================================================
+//function : And
+//purpose  : 
+//=======================================================================
+
+void SMESH_HypoFilter::And( SMESH_HypoPredicate* aPredicate )
+{
+  add( AND, aPredicate );
+}
+
+//=======================================================================
+//function : AndNot
+//purpose  : 
+//=======================================================================
+
+void SMESH_HypoFilter::AndNot( SMESH_HypoPredicate* aPredicate )
+{
+  add( AND_NOT, aPredicate );
+}
+
+//=======================================================================
+//function : Or
+//purpose  : 
+//=======================================================================
+
+void SMESH_HypoFilter::Or( SMESH_HypoPredicate* aPredicate )
+{
+  add( OR, aPredicate );
+}
+
+//=======================================================================
+//function : OrNot
+//purpose  : Return predicates
+//=======================================================================
+
+void SMESH_HypoFilter::OrNot( SMESH_HypoPredicate* aPredicate )
+{
+  add( OR_NOT, aPredicate );
+}
+
+//=======================================================================
+//function : Is
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoPredicate* SMESH_HypoFilter::Is(const SMESH_Hypothesis* theHypo)
+{
+  return new InstancePredicate( theHypo );
+}
+
+//=======================================================================
+//function : IsAlgo
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoPredicate* SMESH_HypoFilter::IsAlgo()
+{
+  return new TypePredicate( MORE, SMESHDS_Hypothesis::PARAM_ALGO );
+}
+
+//=======================================================================
+//function : IsGlobal
+//purpose  : 
+//=======================================================================
+
+ SMESH_HypoPredicate* SMESH_HypoFilter::IsGlobal(const TopoDS_Shape& theMainShape)
+{
+  return new IsGlobalPredicate( theMainShape );
+}
+
+//=======================================================================
+//function : HasName
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoPredicate* SMESH_HypoFilter::HasName(const string & theName)
+{
+  return new NamePredicate( theName );
+}
+
+//=======================================================================
+//function : HasDim
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoPredicate* SMESH_HypoFilter::HasDim(const int theDim)
+{
+  return new DimPredicate( EQUAL, theDim );
+}
+
+//=======================================================================
+//function : IsApplicableTo
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoPredicate* SMESH_HypoFilter::IsApplicableTo(const TopoDS_Shape& theShape)
+{
+  return new ApplicablePredicate( theShape );
+}
+
+//=======================================================================
+//function : HasType
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoPredicate* SMESH_HypoFilter::HasType(const int theHypType)
+{
+  return new TypePredicate( EQUAL, theHypType );
+}
+
+//=======================================================================
+//function : IsOk
+//purpose  : 
+//=======================================================================
+
+bool SMESH_HypoFilter::IsOk (const SMESH_Hypothesis* aHyp,
+                             const TopoDS_Shape&     aShape) const
+{
+  if ( myPredicates.empty() )
+    return true;
+
+  bool ok = ( myPredicates.front()->_logical_op <= AND_NOT );
+  list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
+  for ( ; pred != myPredicates.end(); ++pred )
+  {
+    bool ok2 = (*pred)->IsOk( aHyp, aShape );
+    switch ( (*pred)->_logical_op ) {
+    case AND:     ok = ok && ok2; break;
+    case AND_NOT: ok = ok && !ok2; break;
+    case OR:      ok = ok || ok2; break;
+    case OR_NOT:  ok = ok || !ok2; break;
+    default:;
+    }
+  }
+  return ok;
+}
+
+//=======================================================================
+//function : Init
+//purpose  : 
+//=======================================================================
+
+void SMESH_HypoFilter::Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate )
+{
+  list<SMESH_HypoPredicate*>::const_iterator pred = myPredicates.begin();
+  for ( ; pred != myPredicates.end(); ++pred )
+    delete *pred;
+
+  add( notNagate ? AND : AND_NOT, aPredicate );
+}
+
+
+//=======================================================================
+//function : IsOk
+//purpose  : 
+//=======================================================================
+
+SMESH_HypoFilter::~SMESH_HypoFilter()
+{
+  Init(0);
+}
+
diff --git a/src/SMESH/SMESH_HypoFilter.hxx b/src/SMESH/SMESH_HypoFilter.hxx
new file mode 100644 (file)
index 0000000..673b9fe
--- /dev/null
@@ -0,0 +1,163 @@
+//  SMESH SMESH : implementaion of SMESH idl descriptions
+//
+//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
+// 
+//  This library is free software; you can redistribute it and/or 
+//  modify it under the terms of the GNU Lesser General Public 
+//  License as published by the Free Software Foundation; either 
+//  version 2.1 of the License. 
+// 
+//  This library is distributed in the hope that it will be useful, 
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+//  Lesser General Public License for more details. 
+// 
+//  You should have received a copy of the GNU Lesser General Public 
+//  License along with this library; if not, write to the Free Software 
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
+// 
+//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//
+//
+//
+//  File   : SMESH_HypoFilter.hxx
+//  Module : SMESH
+//  $Header$
+
+
+#ifndef SMESH_HypoFilter_HeaderFile
+#define SMESH_HypoFilter_HeaderFile
+
+// ===========================
+// Filter of SMESH_Hypothesis
+// ===========================
+
+#include <list>
+#include <string>
+
+class SMESH_HypoFilter;
+class SMESH_Hypothesis;
+class TopoDS_Shape;
+
+class SMESH_HypoPredicate {
+ public:
+  virtual bool IsOk(const SMESH_Hypothesis* aHyp,
+                    const TopoDS_Shape&     aShape) const = 0;
+  // check aHyp or/and aShape it is assigned to
+  virtual ~SMESH_HypoPredicate() {}
+ private:
+  int _logical_op;
+  friend class SMESH_HypoFilter;
+};
+
+class SMESH_HypoFilter: public SMESH_HypoPredicate
+{
+ public:
+  // Create and add predicates.
+  // Added predicates will be destroyed by filter when it dies
+  SMESH_HypoFilter();
+  SMESH_HypoFilter( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
+  // notNagate==false means !aPredicate->IsOk()
+  void Init  ( SMESH_HypoPredicate* aPredicate, bool notNagate = true );
+  void And   ( SMESH_HypoPredicate* aPredicate );
+  void AndNot( SMESH_HypoPredicate* aPredicate );
+  void Or    ( SMESH_HypoPredicate* aPredicate );
+  void OrNot ( SMESH_HypoPredicate* aPredicate );
+
+  // Create predicates
+  static SMESH_HypoPredicate* IsAlgo();
+  static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theMainShape);
+  static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
+  static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
+  static SMESH_HypoPredicate* HasName(const std::string & theName);
+  static SMESH_HypoPredicate* HasDim(const int theDim);
+  static SMESH_HypoPredicate* HasType(const int theHypType);
+
+  bool IsOk (const SMESH_Hypothesis* aHyp,
+             const TopoDS_Shape&     aShape) const;
+  // check aHyp or/and aShape it is assigned to
+
+  ~SMESH_HypoFilter();
+
+
+ protected:
+  // fields
+
+  std::list<SMESH_HypoPredicate*> myPredicates;
+
+  // private methods
+
+  enum Logical { AND, AND_NOT, OR, OR_NOT };
+  enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
+
+  SMESH_HypoFilter(const SMESH_HypoFilter& other){}
+
+  void add( Logical bool_op, SMESH_HypoPredicate* pred )
+  {
+    if ( pred ) {
+      pred->_logical_op = bool_op;
+      myPredicates.push_back( pred );
+    }
+  }
+
+  // predicates implementation
+
+  template <typename TValue>
+    struct templPredicate: public SMESH_HypoPredicate {
+      Comparison _comp;
+      TValue     _val;
+      virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
+      virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
+      {
+        if      ( _comp == EQUAL )     return _val == Value( aHyp );
+        else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
+        else if ( _comp == MORE )      return _val < Value( aHyp );
+        else                           return _val > Value( aHyp );
+      }
+    };
+
+  struct NamePredicate : public SMESH_HypoPredicate {
+    std::string _name;
+    NamePredicate( std::string name ): _name(name){}
+    bool IsOk(const SMESH_Hypothesis* aHyp,
+              const TopoDS_Shape&     aShape) const;
+  };
+  
+  struct TypePredicate : public templPredicate< int > {
+    TypePredicate( Comparison comp, int hypType )
+    { _comp = comp; _val = hypType; }
+    int Value( const SMESH_Hypothesis* aHyp ) const;
+  };
+  
+  struct DimPredicate : public templPredicate< int > {
+    DimPredicate( Comparison comp, int dim )
+    { _comp = comp; _val = dim; }
+    int Value( const SMESH_Hypothesis* aHyp ) const;
+  };
+  
+  struct ApplicablePredicate : public SMESH_HypoPredicate {
+    int _shapeType;
+    ApplicablePredicate( const TopoDS_Shape& theShape );
+    bool IsOk(const SMESH_Hypothesis* aHyp,
+              const TopoDS_Shape&     aShape) const;
+  };
+        
+  struct InstancePredicate : public SMESH_HypoPredicate {
+    const SMESH_Hypothesis* _hypo;
+    InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
+    bool IsOk(const SMESH_Hypothesis* aHyp,
+              const TopoDS_Shape&     aShape) const;
+  };
+        
+  struct IsGlobalPredicate : public SMESH_HypoPredicate {
+    const TopoDS_Shape& _mainShape;
+    IsGlobalPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
+    bool IsOk(const SMESH_Hypothesis* aHyp,
+              const TopoDS_Shape&     aShape) const;
+  };
+        
+};
+
+
+#endif