Salome HOME
3d55ccf3a8ffe0d567efb6bf6d4ca936d375557b
[modules/smesh.git] / src / Controls / SMESH_ControlsDef.hxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef _SMESH_CONTROLSDEF_HXX_
24 #define _SMESH_CONTROLSDEF_HXX_
25
26 #include <set>
27 #include <map>
28 #include <vector>
29
30 #include <boost/shared_ptr.hpp>
31
32 #include <gp_XYZ.hxx>
33 #include <GeomAPI_ProjectPointOnSurf.hxx>
34 #include <GeomAPI_ProjectPointOnCurve.hxx>
35 #include <TColStd_SequenceOfInteger.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37 #include <TCollection_AsciiString.hxx>
38 #include <TopAbs.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <BRepClass3d_SolidClassifier.hxx>
42 #include <Quantity_Color.hxx>
43
44 #include "SMDSAbs_ElementType.hxx"
45 #include "SMDS_MeshNode.hxx"
46
47 #include "SMESH_Controls.hxx"
48
49 #ifdef WNT
50  #if defined SMESHCONTROLS_EXPORTS || defined SMESHControls_EXPORTS
51   #define SMESHCONTROLS_EXPORT __declspec( dllexport )
52  #else
53   #define SMESHCONTROLS_EXPORT __declspec( dllimport )
54  #endif
55 #else
56  #define SMESHCONTROLS_EXPORT
57 #endif
58
59 class SMDS_MeshElement;
60 class SMDS_MeshFace;
61 class SMDS_MeshNode;
62 class SMDS_Mesh;
63
64 class SMESHDS_Mesh;
65 class SMESHDS_SubMesh;
66
67 class gp_Pnt;
68
69 namespace SMESH{
70   namespace Controls{
71
72     class SMESHCONTROLS_EXPORT TSequenceOfXYZ
73     {
74       typedef std::vector<gp_XYZ>::size_type size_type;
75
76     public:
77       TSequenceOfXYZ();
78
79       TSequenceOfXYZ(size_type n);
80
81       TSequenceOfXYZ(size_type n, const gp_XYZ& t);
82
83       TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
84
85       template <class InputIterator>
86       TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
87
88       ~TSequenceOfXYZ();
89
90       TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
91
92       gp_XYZ& operator()(size_type n);
93
94       const gp_XYZ& operator()(size_type n) const;
95
96       void clear();
97
98       void reserve(size_type n);
99
100       void push_back(const gp_XYZ& v);
101
102       size_type size() const;
103
104     private:
105       std::vector<gp_XYZ> myArray;
106     };
107
108     /*
109       Class       : Functor
110       Description : Root of all Functors
111     */
112     class SMESHCONTROLS_EXPORT Functor
113     {
114     public:
115       ~Functor(){}
116       virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
117       virtual SMDSAbs_ElementType GetType() const = 0;
118     };
119
120     /*
121       Class       : NumericalFunctor
122       Description : Root of all Functors returning numeric value
123     */
124     class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
125     public:
126       NumericalFunctor();
127       virtual void SetMesh( const SMDS_Mesh* theMesh );
128       virtual double GetValue( long theElementId );
129       virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
130       void GetHistogram(int                  nbIntervals,
131                         std::vector<int>&    nbEvents,
132                         std::vector<double>& funValues);
133       virtual SMDSAbs_ElementType GetType() const = 0;
134       virtual double GetBadRate( double Value, int nbNodes ) const = 0;
135       long  GetPrecision() const;
136       void  SetPrecision( const long thePrecision );
137       
138       bool GetPoints(const int theId,
139                      TSequenceOfXYZ& theRes) const;
140       static bool GetPoints(const SMDS_MeshElement* theElem,
141                             TSequenceOfXYZ& theRes);
142     protected:
143       const SMDS_Mesh* myMesh;
144       const SMDS_MeshElement* myCurrElement;
145       long       myPrecision;
146     };
147
148
149     /*
150       Class       : Volume
151       Description : Functor calculating volume of 3D mesh element
152     */
153     class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
154     public:
155       virtual double GetValue( long theElementId );
156       //virtual double GetValue( const TSequenceOfXYZ& thePoints );
157       virtual double GetBadRate( double Value, int nbNodes ) const;
158       virtual SMDSAbs_ElementType GetType() const;
159     };
160   
161   
162     /*
163       Class       : MaxElementLength2D
164       Description : Functor calculating maximum length of 2D element
165     */
166     class SMESHCONTROLS_EXPORT MaxElementLength2D: public virtual NumericalFunctor{
167     public:
168       virtual double GetValue( long theElementId );
169       virtual double GetBadRate( double Value, int nbNodes ) const;
170       virtual SMDSAbs_ElementType GetType() const;
171     };
172   
173   
174     /*
175       Class       : MaxElementLength3D
176       Description : Functor calculating maximum length of 3D element
177     */
178     class SMESHCONTROLS_EXPORT MaxElementLength3D: public virtual NumericalFunctor{
179     public:
180       virtual double GetValue( long theElementId );
181       virtual double GetBadRate( double Value, int nbNodes ) const;
182       virtual SMDSAbs_ElementType GetType() const;
183     };
184   
185   
186     /*
187       Class       : SMESH_MinimumAngle
188       Description : Functor for calculation of minimum angle
189     */
190     class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
191     public:
192       virtual double GetValue( const TSequenceOfXYZ& thePoints );
193       virtual double GetBadRate( double Value, int nbNodes ) const;
194       virtual SMDSAbs_ElementType GetType() const;
195     };
196   
197   
198     /*
199       Class       : AspectRatio
200       Description : Functor for calculating aspect ratio
201     */
202     class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
203     public:
204       virtual double GetValue( const TSequenceOfXYZ& thePoints );
205       virtual double GetBadRate( double Value, int nbNodes ) const;
206       virtual SMDSAbs_ElementType GetType() const;
207     };
208   
209   
210     /*
211       Class       : AspectRatio3D
212       Description : Functor for calculating aspect ratio of 3D elems.
213     */
214     class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
215     public:
216       virtual double GetValue( const TSequenceOfXYZ& thePoints );
217       virtual double GetBadRate( double Value, int nbNodes ) const;
218       virtual SMDSAbs_ElementType GetType() const;
219     };
220   
221   
222     /*
223       Class       : Warping
224       Description : Functor for calculating warping
225     */
226     class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
227     public:
228       virtual double GetValue( const TSequenceOfXYZ& thePoints );
229       virtual double GetBadRate( double Value, int nbNodes ) const;
230       virtual SMDSAbs_ElementType GetType() const;
231       
232     private:
233       double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
234     };
235   
236   
237     /*
238       Class       : Taper
239       Description : Functor for calculating taper
240     */
241     class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
242     public:
243       virtual double GetValue( const TSequenceOfXYZ& thePoints );
244       virtual double GetBadRate( double Value, int nbNodes ) const;
245       virtual SMDSAbs_ElementType GetType() const;
246     };
247
248
249     /*
250       Class       : Skew
251       Description : Functor for calculating skew in degrees
252     */
253     class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
254     public:
255       virtual double GetValue( const TSequenceOfXYZ& thePoints );
256       virtual double GetBadRate( double Value, int nbNodes ) const;
257       virtual SMDSAbs_ElementType GetType() const;
258     };
259
260
261     /*
262       Class       : Area
263       Description : Functor for calculating area
264     */
265     class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
266     public:
267       virtual double GetValue( const TSequenceOfXYZ& thePoints );
268       virtual double GetBadRate( double Value, int nbNodes ) const;
269       virtual SMDSAbs_ElementType GetType() const;
270     };
271   
272   
273     /*
274       Class       : Length
275       Description : Functor for calculating length of edge
276     */
277     class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
278     public:
279       virtual double GetValue( const TSequenceOfXYZ& thePoints );
280       virtual double GetBadRate( double Value, int nbNodes ) const;
281       virtual SMDSAbs_ElementType GetType() const;
282     };
283
284     /*
285       Class       : Length2D
286       Description : Functor for calculating length of edge
287     */
288     class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
289     public:
290       virtual double GetValue( long theElementId );
291       virtual double GetBadRate( double Value, int nbNodes ) const;
292       virtual SMDSAbs_ElementType GetType() const;
293       struct Value{
294         double myLength;
295         long myPntId[2];
296         Value(double theLength, long thePntId1, long thePntId2);
297         bool operator<(const Value& x) const;
298       };
299       typedef std::set<Value> TValues;
300       void GetValues(TValues& theValues);
301     };
302     typedef boost::shared_ptr<Length2D> Length2DPtr;
303
304     /*
305       Class       : MultiConnection
306       Description : Functor for calculating number of faces conneted to the edge
307     */
308     class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
309     public:
310       virtual double GetValue( long theElementId );
311       virtual double GetValue( const TSequenceOfXYZ& thePoints );
312       virtual double GetBadRate( double Value, int nbNodes ) const;
313       virtual SMDSAbs_ElementType GetType() const;
314     };
315     
316     /*
317       Class       : MultiConnection2D
318       Description : Functor for calculating number of faces conneted to the edge
319     */
320     class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
321     public:
322       virtual double GetValue( long theElementId );
323       virtual double GetValue( const TSequenceOfXYZ& thePoints );
324       virtual double GetBadRate( double Value, int nbNodes ) const;
325       virtual SMDSAbs_ElementType GetType() const;
326       struct Value{
327         long myPntId[2];
328         Value(long thePntId1, long thePntId2);
329         bool operator<(const Value& x) const;
330       };
331       typedef std::map<Value,int> MValues;
332
333       void GetValues(MValues& theValues);
334     };
335     typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
336     /*
337       PREDICATES
338     */
339     /*
340       Class       : Predicate
341       Description : Base class for all predicates
342     */
343     class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
344     public:
345       virtual bool IsSatisfy( long theElementId ) = 0;
346       virtual SMDSAbs_ElementType GetType() const = 0;
347     };
348   
349   
350     /*
351       Class       : FreeBorders
352       Description : Predicate for free borders
353     */
354     class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
355     public:
356       FreeBorders();
357       virtual void SetMesh( const SMDS_Mesh* theMesh );
358       virtual bool IsSatisfy( long theElementId );
359       virtual SMDSAbs_ElementType GetType() const;
360
361     protected:
362       const SMDS_Mesh* myMesh;
363     };
364    
365
366     /*
367       Class       : BadOrientedVolume
368       Description : Predicate bad oriented volumes
369     */
370     class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
371     public:
372       BadOrientedVolume();
373       virtual void SetMesh( const SMDS_Mesh* theMesh );
374       virtual bool IsSatisfy( long theElementId );
375       virtual SMDSAbs_ElementType GetType() const;
376
377     protected:
378       const SMDS_Mesh* myMesh;
379     };
380
381     /*
382       BareBorderVolume
383     */
384     class SMESHCONTROLS_EXPORT BareBorderVolume: public Predicate
385     {
386     public:
387       BareBorderVolume():myMesh(0) {}
388       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
389       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
390       virtual bool IsSatisfy( long theElementId );
391     protected:
392       const SMDS_Mesh* myMesh;
393     };
394     typedef boost::shared_ptr<BareBorderVolume> BareBorderVolumePtr;
395
396     /*
397       BareBorderFace
398     */
399     class SMESHCONTROLS_EXPORT BareBorderFace: public Predicate
400     {
401     public:
402       BareBorderFace():myMesh(0) {}
403       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
404       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
405       virtual bool IsSatisfy( long theElementId );
406     protected:
407       const SMDS_Mesh* myMesh;
408       std::vector< const SMDS_MeshNode* > myLinkNodes;
409     };
410     typedef boost::shared_ptr<BareBorderFace> BareBorderFacePtr;
411
412     /*
413       Class       : FreeEdges
414       Description : Predicate for free Edges
415     */
416     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
417     public:
418       FreeEdges();
419       virtual void SetMesh( const SMDS_Mesh* theMesh );
420       virtual bool IsSatisfy( long theElementId );
421       virtual SMDSAbs_ElementType GetType() const;
422       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
423       typedef long TElemId;
424       struct Border{
425         TElemId myElemId;
426         TElemId myPntId[2];
427         Border(long theElemId, long thePntId1, long thePntId2);
428         bool operator<(const Border& x) const;
429       };
430       typedef std::set<Border> TBorders;
431       void GetBoreders(TBorders& theBorders);
432
433     protected:
434       const SMDS_Mesh* myMesh;
435     };
436     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
437     
438     
439     /*
440       Class       : FreeNodes
441       Description : Predicate for free nodes
442     */
443     class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
444     public:
445       FreeNodes();
446       virtual void SetMesh( const SMDS_Mesh* theMesh );
447       virtual bool IsSatisfy( long theNodeId );
448       virtual SMDSAbs_ElementType GetType() const;
449
450     protected:
451       const SMDS_Mesh* myMesh;
452     };
453     
454
455     /*
456       Class       : RangeOfIds
457       Description : Predicate for Range of Ids.
458                     Range may be specified with two ways.
459                     1. Using AddToRange method
460                     2. With SetRangeStr method. Parameter of this method is a string
461                        like as "1,2,3,50-60,63,67,70-"
462     */
463     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
464     {
465     public:
466                                     RangeOfIds();
467       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
468       virtual bool                  IsSatisfy( long theNodeId );
469       virtual SMDSAbs_ElementType   GetType() const;
470       virtual void                  SetType( SMDSAbs_ElementType theType );
471
472       bool                          AddToRange( long theEntityId );
473       void                          GetRangeStr( TCollection_AsciiString& );
474       bool                          SetRangeStr( const TCollection_AsciiString& );
475
476     protected:
477       const SMDS_Mesh*              myMesh;
478
479       TColStd_SequenceOfInteger     myMin;
480       TColStd_SequenceOfInteger     myMax;
481       TColStd_MapOfInteger          myIds;
482
483       SMDSAbs_ElementType           myType;
484     };
485     
486     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
487    
488     
489     /*
490       Class       : Comparator
491       Description : Base class for comparators
492     */
493     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
494     public:
495       Comparator();
496       virtual ~Comparator();
497       virtual void SetMesh( const SMDS_Mesh* theMesh );
498       virtual void SetMargin(double theValue);
499       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
500       virtual bool IsSatisfy( long theElementId ) = 0;
501       virtual SMDSAbs_ElementType GetType() const;
502       double  GetMargin();
503   
504     protected:
505       double myMargin;
506       NumericalFunctorPtr myFunctor;
507     };
508     typedef boost::shared_ptr<Comparator> ComparatorPtr;
509   
510   
511     /*
512       Class       : LessThan
513       Description : Comparator "<"
514     */
515     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
516     public:
517       virtual bool IsSatisfy( long theElementId );
518     };
519   
520   
521     /*
522       Class       : MoreThan
523       Description : Comparator ">"
524     */
525     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
526     public:
527       virtual bool IsSatisfy( long theElementId );
528     };
529   
530   
531     /*
532       Class       : EqualTo
533       Description : Comparator "="
534     */
535     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
536     public:
537       EqualTo();
538       virtual bool IsSatisfy( long theElementId );
539       virtual void SetTolerance( double theTol );
540       virtual double GetTolerance();
541   
542     private:
543       double myToler;
544     };
545     typedef boost::shared_ptr<EqualTo> EqualToPtr;
546   
547     
548     /*
549       Class       : LogicalNOT
550       Description : Logical NOT predicate
551     */
552     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
553     public:
554       LogicalNOT();
555       virtual ~LogicalNOT();
556       virtual bool IsSatisfy( long theElementId );
557       virtual void SetMesh( const SMDS_Mesh* theMesh );
558       virtual void SetPredicate(PredicatePtr thePred);
559       virtual SMDSAbs_ElementType GetType() const;
560   
561     private:
562       PredicatePtr myPredicate;
563     };
564     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
565     
566   
567     /*
568       Class       : LogicalBinary
569       Description : Base class for binary logical predicate
570     */
571     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
572     public:
573       LogicalBinary();
574       virtual ~LogicalBinary();
575       virtual void SetMesh( const SMDS_Mesh* theMesh );
576       virtual void SetPredicate1(PredicatePtr thePred);
577       virtual void SetPredicate2(PredicatePtr thePred);
578       virtual SMDSAbs_ElementType GetType() const;
579   
580     protected:
581       PredicatePtr myPredicate1;
582       PredicatePtr myPredicate2;
583     };
584     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
585   
586   
587     /*
588       Class       : LogicalAND
589       Description : Logical AND
590     */
591     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
592     public:
593       virtual bool IsSatisfy( long theElementId );
594     };
595   
596   
597     /*
598       Class       : LogicalOR
599       Description : Logical OR
600     */
601     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
602     public:
603       virtual bool IsSatisfy( long theElementId );
604     };
605   
606   
607     /*
608       Class       : ManifoldPart
609       Description : Predicate for manifold part of mesh
610     */
611     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
612     public:
613
614       /* internal class for algorithm uses */
615       class Link
616       {
617       public:
618         Link( SMDS_MeshNode* theNode1,
619               SMDS_MeshNode* theNode2 );
620         ~Link();
621         
622         bool IsEqual( const ManifoldPart::Link& theLink ) const;
623         bool operator<(const ManifoldPart::Link& x) const;
624         
625         SMDS_MeshNode* myNode1;
626         SMDS_MeshNode* myNode2;
627       };
628
629       bool IsEqual( const ManifoldPart::Link& theLink1,
630                     const ManifoldPart::Link& theLink2 );
631       
632       typedef std::set<ManifoldPart::Link>                TMapOfLink;
633       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
634       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
635       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
636       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
637       
638       ManifoldPart();
639       ~ManifoldPart();
640       virtual void SetMesh( const SMDS_Mesh* theMesh );
641       // inoke when all parameters already set
642       virtual bool IsSatisfy( long theElementId );
643       virtual      SMDSAbs_ElementType GetType() const;
644
645       void    SetAngleTolerance( const double theAngToler );
646       double  GetAngleTolerance() const;
647       void    SetIsOnlyManifold( const bool theIsOnly );
648       void    SetStartElem( const long  theStartElemId );
649
650     private:
651       bool    process();
652       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
653                              SMDS_MeshFace*            theStartFace,
654                              TMapOfLink&               theNonManifold,
655                              TColStd_MapOfInteger&     theResFaces );
656       bool    isInPlane( const SMDS_MeshFace* theFace1,
657                           const SMDS_MeshFace* theFace2 );
658       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
659                               TVectorOfLink&         theSeqOfBoundary,
660                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
661                               TMapOfLink&            theNonManifold,
662                               SMDS_MeshFace*         theNextFace ) const;
663
664      void     getFacesByLink( const Link& theLink,
665                               TVectorOfFacePtr& theFaces ) const;
666
667     private:
668       const SMDS_Mesh*      myMesh;
669       TColStd_MapOfInteger  myMapIds;
670       TColStd_MapOfInteger  myMapBadGeomIds;
671       TVectorOfFacePtr      myAllFacePtr;
672       TDataMapFacePtrInt    myAllFacePtrIntDMap;
673       double                myAngToler;
674       bool                  myIsOnlyManifold;
675       long                  myStartElemId;
676
677     };
678     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
679
680
681     /*
682       Class       : ElementsOnSurface
683       Description : Predicate elements that lying on indicated surface
684                     (plane or cylinder)
685     */
686     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
687     public:
688       ElementsOnSurface();
689       ~ElementsOnSurface();
690       virtual void SetMesh( const SMDS_Mesh* theMesh );
691       virtual bool IsSatisfy( long theElementId );
692       virtual      SMDSAbs_ElementType GetType() const;
693
694       void    SetTolerance( const double theToler );
695       double  GetTolerance() const;
696       void    SetSurface( const TopoDS_Shape& theShape,
697                           const SMDSAbs_ElementType theType );
698       void    SetUseBoundaries( bool theUse );
699       bool    GetUseBoundaries() const { return myUseBoundaries; }
700
701     private:
702       void    process();
703       void    process( const SMDS_MeshElement* theElem  );
704       bool    isOnSurface( const SMDS_MeshNode* theNode );
705
706     private:
707       const SMDS_Mesh*      myMesh;
708       TColStd_MapOfInteger  myIds;
709       SMDSAbs_ElementType   myType;
710       //Handle(Geom_Surface)  mySurf;
711       TopoDS_Face           mySurf;
712       double                myToler;
713       bool                  myUseBoundaries;
714       GeomAPI_ProjectPointOnSurf myProjector;
715     };
716
717     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
718
719
720     /*
721       Class       : ElementsOnShape
722       Description : Predicate elements that lying on indicated shape
723                     (1D, 2D or 3D)
724     */
725     class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
726     {
727     public:
728       ElementsOnShape();
729       ~ElementsOnShape();
730
731       virtual void SetMesh (const SMDS_Mesh* theMesh);
732       virtual bool IsSatisfy (long theElementId);
733       virtual SMDSAbs_ElementType GetType() const;
734
735       void    SetTolerance (const double theToler);
736       double  GetTolerance() const;
737       void    SetAllNodes (bool theAllNodes);
738       bool    GetAllNodes() const { return myAllNodesFlag; }
739       void    SetShape (const TopoDS_Shape& theShape,
740                         const SMDSAbs_ElementType theType);
741
742     private:
743       void    addShape (const TopoDS_Shape& theShape);
744       void    process();
745       void    process (const SMDS_MeshElement* theElem);
746
747     private:
748       const SMDS_Mesh*      myMesh;
749       TColStd_MapOfInteger  myIds;
750       SMDSAbs_ElementType   myType;
751       TopoDS_Shape          myShape;
752       double                myToler;
753       bool                  myAllNodesFlag;
754
755       TopTools_MapOfShape         myShapesMap;
756       TopAbs_ShapeEnum            myCurShapeType; // type of current sub-shape
757       BRepClass3d_SolidClassifier myCurSC;        // current SOLID
758       GeomAPI_ProjectPointOnSurf  myCurProjFace;  // current FACE
759       TopoDS_Face                 myCurFace;      // current FACE
760       GeomAPI_ProjectPointOnCurve myCurProjEdge;  // current EDGE
761       gp_Pnt                      myCurPnt;       // current VERTEX
762     };
763
764     typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
765
766
767     /*
768       Class       : FreeFaces
769       Description : Predicate for free faces
770     */
771     class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
772     public:
773       FreeFaces();
774       virtual void SetMesh( const SMDS_Mesh* theMesh );
775       virtual bool IsSatisfy( long theElementId );
776       virtual SMDSAbs_ElementType GetType() const;
777
778     private:
779       const SMDS_Mesh* myMesh;
780     };
781
782     /*
783       Class       : LinearOrQuadratic
784       Description : Predicate for free faces
785     */
786     class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
787     public:
788       LinearOrQuadratic();
789       virtual void        SetMesh( const SMDS_Mesh* theMesh );
790       virtual bool        IsSatisfy( long theElementId );
791       void                SetType( SMDSAbs_ElementType theType );
792       virtual SMDSAbs_ElementType GetType() const;
793
794     private:
795       const SMDS_Mesh*    myMesh;
796       SMDSAbs_ElementType myType;
797     };
798     typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
799
800     /*
801       Class       : GroupColor
802       Description : Functor for check color of group to whic mesh element belongs to
803     */
804     class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
805     public:
806       GroupColor();
807       virtual void        SetMesh( const SMDS_Mesh* theMesh );
808       virtual bool        IsSatisfy( long theElementId );
809       void                SetType( SMDSAbs_ElementType theType );
810       virtual             SMDSAbs_ElementType GetType() const;
811       void                SetColorStr( const TCollection_AsciiString& );
812       void                GetColorStr( TCollection_AsciiString& ) const;
813       
814     private:
815       typedef std::set< long > TIDs;
816
817       Quantity_Color      myColor;
818       SMDSAbs_ElementType myType;
819       TIDs                myIDs;
820     };
821     typedef boost::shared_ptr<GroupColor> GroupColorPtr;
822
823     /*
824       Class       : ElemGeomType
825       Description : Predicate to check element geometry type
826     */
827     class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
828     public:
829       ElemGeomType();
830       virtual void        SetMesh( const SMDS_Mesh* theMesh );
831       virtual bool        IsSatisfy( long theElementId );
832       void                SetType( SMDSAbs_ElementType theType );
833       virtual             SMDSAbs_ElementType GetType() const;
834       void                SetGeomType( SMDSAbs_GeometryType theType );
835       virtual SMDSAbs_GeometryType GetGeomType() const;
836
837     private:
838       const SMDS_Mesh*     myMesh;
839       SMDSAbs_ElementType  myType;
840       SMDSAbs_GeometryType myGeomType;
841     };
842     typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
843
844     /*
845       FILTER
846     */
847     class SMESHCONTROLS_EXPORT Filter{
848     public:
849       Filter();
850       virtual ~Filter();
851       virtual void SetPredicate(PredicatePtr thePred);
852
853       typedef std::vector<long> TIdSequence;
854
855       virtual
856       void
857       GetElementsId( const SMDS_Mesh* theMesh,
858                      TIdSequence& theSequence );
859
860       static
861       void
862       GetElementsId( const SMDS_Mesh* theMesh,
863                      PredicatePtr thePredicate,
864                      TIdSequence& theSequence );
865       
866     protected:
867       PredicatePtr myPredicate;
868     };
869   };
870 };
871
872
873 #endif