1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_HypoFilter.hxx
29 #ifndef SMESH_HypoFilter_HeaderFile
30 #define SMESH_HypoFilter_HeaderFile
32 // ===========================
33 // Filter of SMESH_Hypothesis
34 // ===========================
38 #include <TopoDS_Shape.hxx>
40 class SMESH_HypoFilter;
41 class SMESH_Hypothesis;
43 class SMESH_HypoPredicate {
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() {}
51 friend class SMESH_HypoFilter;
54 class SMESH_HypoFilter: public SMESH_HypoPredicate
57 // Create and add predicates.
58 // Added predicates will be destroyed by filter when it dies
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 );
69 static SMESH_HypoPredicate* IsAlgo();
70 static SMESH_HypoPredicate* IsApplicableTo(const TopoDS_Shape& theShape);
71 static SMESH_HypoPredicate* IsAssignedTo(const TopoDS_Shape& theShape);
72 static SMESH_HypoPredicate* Is(const SMESH_Hypothesis* theHypo);
73 static SMESH_HypoPredicate* IsGlobal(const TopoDS_Shape& theMainShape);
74 static SMESH_HypoPredicate* HasName(const std::string & theName);
75 static SMESH_HypoPredicate* HasDim(const int theDim);
76 static SMESH_HypoPredicate* HasType(const int theHypType);
78 bool IsOk (const SMESH_Hypothesis* aHyp,
79 const TopoDS_Shape& aShape) const;
80 // check aHyp or/and aShape it is assigned to
88 std::list<SMESH_HypoPredicate*> myPredicates;
92 enum Logical { AND, AND_NOT, OR, OR_NOT };
93 enum Comparison { EQUAL, NOT_EQUAL, MORE, LESS };
95 SMESH_HypoFilter(const SMESH_HypoFilter& other){}
97 void add( Logical bool_op, SMESH_HypoPredicate* pred )
100 pred->_logical_op = bool_op;
101 myPredicates.push_back( pred );
105 // predicates implementation
107 template <typename TValue>
108 struct templPredicate: public SMESH_HypoPredicate {
111 virtual TValue Value(const SMESH_Hypothesis* aHyp) const = 0;
112 virtual bool IsOk(const SMESH_Hypothesis* aHyp, const TopoDS_Shape& ) const
114 if ( _comp == EQUAL ) return _val == Value( aHyp );
115 else if ( _comp == NOT_EQUAL ) return _val != Value( aHyp );
116 else if ( _comp == MORE ) return _val < Value( aHyp );
117 else return _val > Value( aHyp );
121 struct NamePredicate : public SMESH_HypoPredicate {
123 NamePredicate( std::string name ): _name(name){}
124 bool IsOk(const SMESH_Hypothesis* aHyp,
125 const TopoDS_Shape& aShape) const;
128 struct TypePredicate : public templPredicate< int > {
129 TypePredicate( Comparison comp, int hypType )
130 { _comp = comp; _val = hypType; }
131 int Value( const SMESH_Hypothesis* aHyp ) const;
134 struct DimPredicate : public templPredicate< int > {
135 DimPredicate( Comparison comp, int dim )
136 { _comp = comp; _val = dim; }
137 int Value( const SMESH_Hypothesis* aHyp ) const;
140 struct ApplicablePredicate : public SMESH_HypoPredicate {
142 ApplicablePredicate( const TopoDS_Shape& theShape );
143 bool IsOk(const SMESH_Hypothesis* aHyp,
144 const TopoDS_Shape& aShape) const;
147 struct InstancePredicate : public SMESH_HypoPredicate {
148 const SMESH_Hypothesis* _hypo;
149 InstancePredicate( const SMESH_Hypothesis* hypo ):_hypo(hypo){}
150 bool IsOk(const SMESH_Hypothesis* aHyp,
151 const TopoDS_Shape& aShape) const;
154 struct IsAssignedToPredicate : public SMESH_HypoPredicate {
155 TopoDS_Shape _mainShape;
156 IsAssignedToPredicate( const TopoDS_Shape& mainShape ):_mainShape(mainShape){}
157 bool IsOk(const SMESH_Hypothesis* aHyp,
158 const TopoDS_Shape& aShape) const;