Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / Controls / SMESH_Controls.hxx
1 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
3 // 
4 //  This library is free software; you can redistribute it and/or 
5 //  modify it under the terms of the GNU Lesser General Public 
6 //  License as published by the Free Software Foundation; either 
7 //  version 2.1 of the License. 
8 // 
9 //  This library is distributed in the hope that it will be useful, 
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 //  Lesser General Public License for more details. 
13 // 
14 //  You should have received a copy of the GNU Lesser General Public 
15 //  License along with this library; if not, write to the Free Software 
16 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
17 // 
18 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
19
20 #ifndef _SMESH_CONTROLS_HXX_
21 #define _SMESH_CONTROLS_HXX_
22
23 #include <map>
24 #include <vector>
25 #include <boost/shared_ptr.hpp>
26 #include "SMDSAbs_ElementType.hxx"
27
28 class SMDS_Mesh;
29 class gp_Pnt;
30 class gp_XYZ;
31 class TColgp_SequenceOfXYZ;
32
33 namespace SMESH{
34   namespace Controls{
35     class Functor{
36     public:
37       ~Functor(){}
38       virtual void SetMesh( SMDS_Mesh* theMesh ) = 0;
39     };
40     typedef boost::shared_ptr<Functor> FunctorPtr;
41
42     class NumericalFunctor: public virtual Functor{
43     public:
44       NumericalFunctor();
45       virtual void SetMesh( SMDS_Mesh* theMesh );
46       virtual double GetValue( long theElementId ) = 0;
47       virtual SMDSAbs_ElementType GetType() const = 0;
48       
49     protected:
50       bool getPoints( const int theId, 
51                       TColgp_SequenceOfXYZ& theRes ) const;
52     protected:
53       SMDS_Mesh* myMesh;
54     };
55     typedef boost::shared_ptr<NumericalFunctor> NumericalFunctorPtr;
56   
57   
58     /*
59       Class       : SMESH_MinimumAngle
60       Description : Functor for calculation of minimum angle
61     */
62     class MinimumAngle: public virtual NumericalFunctor{
63     public:
64       virtual double GetValue( long theElementId );
65       virtual SMDSAbs_ElementType GetType() const;
66     };
67   
68   
69     /*
70       Class       : AspectRatio
71       Description : Functor for calculating aspect ratio
72     */
73     class AspectRatio: public virtual NumericalFunctor{
74     public:
75       virtual double GetValue( long theElementId );
76       virtual SMDSAbs_ElementType GetType() const;
77     };
78   
79   
80     /*
81       Class       : Warping
82       Description : Functor for calculating warping
83     */
84     class Warping: public virtual NumericalFunctor{
85     public:
86       virtual double GetValue( long theElementId );
87       virtual SMDSAbs_ElementType GetType() const;
88       
89     private:
90       double ComputeA( const gp_XYZ&, const gp_XYZ&, 
91                        const gp_XYZ&, const gp_XYZ& ) const;
92     };
93   
94   
95     /*
96       Class       : Taper
97       Description : Functor for calculating taper
98     */
99     class Taper: public virtual NumericalFunctor{
100     public:
101       virtual double GetValue( long theElementId );
102       virtual SMDSAbs_ElementType GetType() const;
103     };
104     
105   
106     /*
107       Class       : Skew
108       Description : Functor for calculating skew in degrees
109     */
110     class Skew: public virtual NumericalFunctor{
111     public:
112       virtual double GetValue( long theElementId );
113       virtual SMDSAbs_ElementType GetType() const;
114     };
115   
116     
117     /*
118       Class       : Area
119       Description : Functor for calculating area
120     */
121     class Area: public virtual NumericalFunctor{
122     public:
123       virtual double GetValue( long theElementId );
124       virtual SMDSAbs_ElementType GetType() const;
125     };
126   
127   
128     /*
129       Class       : Length
130       Description : Functor for calculating length of edge
131     */
132     class Length: public virtual NumericalFunctor{
133     public:
134       virtual double GetValue( long theElementId );
135       virtual SMDSAbs_ElementType GetType() const;
136     };
137   
138   
139     /*
140       Class       : MultiConnection
141       Description : Functor for calculating number of faces conneted to the edge
142     */
143     class MultiConnection: public virtual NumericalFunctor{
144     public:
145       virtual double GetValue( long theElementId );
146       virtual SMDSAbs_ElementType GetType() const;
147     };
148     
149   
150     /*
151       PREDICATES
152     */
153     /*
154       Class       : Predicate
155       Description : Base class for all predicates
156     */
157     class Predicate: public virtual Functor{
158     public:
159       virtual bool IsSatisfy( long theElementId ) = 0;
160       virtual SMDSAbs_ElementType GetType() const = 0;
161     };
162     typedef boost::shared_ptr<Predicate> PredicatePtr;
163     
164   
165   
166     /*
167       Class       : FreeBorders
168       Description : Predicate for free borders
169     */
170     class FreeBorders: public virtual Predicate{
171     public:
172       FreeBorders();
173       virtual void SetMesh( SMDS_Mesh* theMesh );
174       virtual bool IsSatisfy( long theElementId );
175       virtual SMDSAbs_ElementType GetType() const;
176             
177     protected:
178       SMDS_Mesh* myMesh;
179     };
180    
181
182     /*
183       Class       : FreeEdges
184       Description : Predicate for free Edges
185     */
186     class FreeEdges: public virtual Predicate{
187     public:
188       FreeEdges();
189       virtual void SetMesh( SMDS_Mesh* theMesh );
190       virtual bool IsSatisfy( long theElementId );
191       virtual SMDSAbs_ElementType GetType() const;
192       struct Border{
193         long PntId[2];
194         Border(long thePntId1, long thePntId2);
195       };
196       typedef long TElemId;
197       typedef std::map<TElemId,Border> Borders;
198       void GetBoreders(Borders& theBorders);
199       
200     protected:
201       SMDS_Mesh* myMesh;
202     };
203     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
204    
205     
206     /*
207       Class       : Comparator
208       Description : Base class for comparators
209     */
210     class Comparator: public virtual Predicate{
211     public:
212       Comparator();
213       virtual ~Comparator();
214       virtual void SetMesh( SMDS_Mesh* theMesh );
215       virtual void SetMargin(double theValue);
216       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
217       virtual bool IsSatisfy( long theElementId ) = 0;
218       virtual SMDSAbs_ElementType GetType() const;
219   
220     protected:
221       double myMargin;
222       NumericalFunctorPtr myFunctor;
223     };
224     typedef boost::shared_ptr<Comparator> ComparatorPtr;
225   
226   
227     /*
228       Class       : LessThan
229       Description : Comparator "<"
230     */
231     class LessThan: public virtual Comparator{
232     public:
233       virtual bool IsSatisfy( long theElementId );
234     };
235   
236   
237     /*
238       Class       : MoreThan
239       Description : Comparator ">"
240     */
241     class MoreThan: public virtual Comparator{
242     public:
243       virtual bool IsSatisfy( long theElementId );
244     };
245   
246   
247     /*
248       Class       : EqualTo
249       Description : Comparator "="
250     */
251     class EqualTo: public virtual Comparator{
252     public:
253       EqualTo();
254       virtual bool IsSatisfy( long theElementId );
255       virtual void SetTolerance( double theTol );
256   
257     private:
258       double myToler;
259     };
260     typedef boost::shared_ptr<EqualTo> EqualToPtr;
261   
262     
263     /*
264       Class       : LogicalNOT
265       Description : Logical NOT predicate
266     */
267     class LogicalNOT: public virtual Predicate{
268     public:
269       LogicalNOT();
270       virtual ~LogicalNOT();
271       virtual bool IsSatisfy( long theElementId );
272       virtual void SetMesh( SMDS_Mesh* theMesh );
273       virtual void SetPredicate(PredicatePtr thePred);
274       virtual SMDSAbs_ElementType GetType() const;
275   
276     private:
277       PredicatePtr myPredicate;
278     };
279     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
280     
281   
282     /*
283       Class       : LogicalBinary
284       Description : Base class for binary logical predicate
285     */
286     class LogicalBinary: public virtual Predicate{
287     public:
288       LogicalBinary();
289       virtual ~LogicalBinary();
290       virtual void SetMesh( SMDS_Mesh* theMesh );
291       virtual void SetPredicate1(PredicatePtr thePred);
292       virtual void SetPredicate2(PredicatePtr thePred);
293       virtual SMDSAbs_ElementType GetType() const;
294   
295     protected:
296       PredicatePtr myPredicate1;
297       PredicatePtr myPredicate2;
298     };
299     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
300   
301   
302     /*
303       Class       : LogicalAND
304       Description : Logical AND
305     */
306     class LogicalAND: public virtual LogicalBinary{
307     public:
308       virtual bool IsSatisfy( long theElementId );
309     };
310   
311   
312     /*
313       Class       : LogicalOR
314       Description : Logical OR
315     */
316     class LogicalOR: public virtual LogicalBinary{
317     public:
318       virtual bool IsSatisfy( long theElementId );
319     };
320   
321   
322     /*
323       FILTER
324     */
325     class Filter{
326     public:
327       Filter();
328       virtual ~Filter();
329       virtual void SetPredicate(PredicatePtr thePred);
330       typedef std::vector<long> TIdSequence;
331       virtual TIdSequence GetElementsId( SMDS_Mesh* theMesh );
332   
333     protected:
334       PredicatePtr myPredicate;
335     };
336   };  
337 };
338
339
340 #endif