Salome HOME
915bd9f4bf1126485f452b2c1d839fec2453fe9e
[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     /*
383       Class       : FreeEdges
384       Description : Predicate for free Edges
385     */
386     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
387     public:
388       FreeEdges();
389       virtual void SetMesh( const SMDS_Mesh* theMesh );
390       virtual bool IsSatisfy( long theElementId );
391       virtual SMDSAbs_ElementType GetType() const;
392       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
393       typedef long TElemId;
394       struct Border{
395         TElemId myElemId;
396         TElemId myPntId[2];
397         Border(long theElemId, long thePntId1, long thePntId2);
398         bool operator<(const Border& x) const;
399       };
400       typedef std::set<Border> TBorders;
401       void GetBoreders(TBorders& theBorders);
402       
403     protected:
404       const SMDS_Mesh* myMesh;
405     };
406     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
407     
408     
409     /*
410       Class       : FreeNodes
411       Description : Predicate for free nodes
412     */
413     class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
414     public:
415       FreeNodes();
416       virtual void SetMesh( const SMDS_Mesh* theMesh );
417       virtual bool IsSatisfy( long theNodeId );
418       virtual SMDSAbs_ElementType GetType() const;
419
420     protected:
421       const SMDS_Mesh* myMesh;
422     };
423     
424
425     /*
426       Class       : RangeOfIds
427       Description : Predicate for Range of Ids.
428                     Range may be specified with two ways.
429                     1. Using AddToRange method
430                     2. With SetRangeStr method. Parameter of this method is a string
431                        like as "1,2,3,50-60,63,67,70-"
432     */
433     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
434     {
435     public:
436                                     RangeOfIds();
437       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
438       virtual bool                  IsSatisfy( long theNodeId );
439       virtual SMDSAbs_ElementType   GetType() const;
440       virtual void                  SetType( SMDSAbs_ElementType theType );
441
442       bool                          AddToRange( long theEntityId );
443       void                          GetRangeStr( TCollection_AsciiString& );
444       bool                          SetRangeStr( const TCollection_AsciiString& );
445
446     protected:
447       const SMDS_Mesh*              myMesh;
448
449       TColStd_SequenceOfInteger     myMin;
450       TColStd_SequenceOfInteger     myMax;
451       TColStd_MapOfInteger          myIds;
452
453       SMDSAbs_ElementType           myType;
454     };
455     
456     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
457    
458     
459     /*
460       Class       : Comparator
461       Description : Base class for comparators
462     */
463     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
464     public:
465       Comparator();
466       virtual ~Comparator();
467       virtual void SetMesh( const SMDS_Mesh* theMesh );
468       virtual void SetMargin(double theValue);
469       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
470       virtual bool IsSatisfy( long theElementId ) = 0;
471       virtual SMDSAbs_ElementType GetType() const;
472       double  GetMargin();
473   
474     protected:
475       double myMargin;
476       NumericalFunctorPtr myFunctor;
477     };
478     typedef boost::shared_ptr<Comparator> ComparatorPtr;
479   
480   
481     /*
482       Class       : LessThan
483       Description : Comparator "<"
484     */
485     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
486     public:
487       virtual bool IsSatisfy( long theElementId );
488     };
489   
490   
491     /*
492       Class       : MoreThan
493       Description : Comparator ">"
494     */
495     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
496     public:
497       virtual bool IsSatisfy( long theElementId );
498     };
499   
500   
501     /*
502       Class       : EqualTo
503       Description : Comparator "="
504     */
505     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
506     public:
507       EqualTo();
508       virtual bool IsSatisfy( long theElementId );
509       virtual void SetTolerance( double theTol );
510       virtual double GetTolerance();
511   
512     private:
513       double myToler;
514     };
515     typedef boost::shared_ptr<EqualTo> EqualToPtr;
516   
517     
518     /*
519       Class       : LogicalNOT
520       Description : Logical NOT predicate
521     */
522     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
523     public:
524       LogicalNOT();
525       virtual ~LogicalNOT();
526       virtual bool IsSatisfy( long theElementId );
527       virtual void SetMesh( const SMDS_Mesh* theMesh );
528       virtual void SetPredicate(PredicatePtr thePred);
529       virtual SMDSAbs_ElementType GetType() const;
530   
531     private:
532       PredicatePtr myPredicate;
533     };
534     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
535     
536   
537     /*
538       Class       : LogicalBinary
539       Description : Base class for binary logical predicate
540     */
541     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
542     public:
543       LogicalBinary();
544       virtual ~LogicalBinary();
545       virtual void SetMesh( const SMDS_Mesh* theMesh );
546       virtual void SetPredicate1(PredicatePtr thePred);
547       virtual void SetPredicate2(PredicatePtr thePred);
548       virtual SMDSAbs_ElementType GetType() const;
549   
550     protected:
551       PredicatePtr myPredicate1;
552       PredicatePtr myPredicate2;
553     };
554     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
555   
556   
557     /*
558       Class       : LogicalAND
559       Description : Logical AND
560     */
561     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
562     public:
563       virtual bool IsSatisfy( long theElementId );
564     };
565   
566   
567     /*
568       Class       : LogicalOR
569       Description : Logical OR
570     */
571     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
572     public:
573       virtual bool IsSatisfy( long theElementId );
574     };
575   
576   
577     /*
578       Class       : ManifoldPart
579       Description : Predicate for manifold part of mesh
580     */
581     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
582     public:
583
584       /* internal class for algorithm uses */
585       class Link
586       {
587       public:
588         Link( SMDS_MeshNode* theNode1,
589               SMDS_MeshNode* theNode2 );
590         ~Link();
591         
592         bool IsEqual( const ManifoldPart::Link& theLink ) const;
593         bool operator<(const ManifoldPart::Link& x) const;
594         
595         SMDS_MeshNode* myNode1;
596         SMDS_MeshNode* myNode2;
597       };
598
599       bool IsEqual( const ManifoldPart::Link& theLink1,
600                     const ManifoldPart::Link& theLink2 );
601       
602       typedef std::set<ManifoldPart::Link>                TMapOfLink;
603       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
604       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
605       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
606       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
607       
608       ManifoldPart();
609       ~ManifoldPart();
610       virtual void SetMesh( const SMDS_Mesh* theMesh );
611       // inoke when all parameters already set
612       virtual bool IsSatisfy( long theElementId );
613       virtual      SMDSAbs_ElementType GetType() const;
614
615       void    SetAngleTolerance( const double theAngToler );
616       double  GetAngleTolerance() const;
617       void    SetIsOnlyManifold( const bool theIsOnly );
618       void    SetStartElem( const long  theStartElemId );
619
620     private:
621       bool    process();
622       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
623                              SMDS_MeshFace*            theStartFace,
624                              TMapOfLink&               theNonManifold,
625                              TColStd_MapOfInteger&     theResFaces );
626       bool    isInPlane( const SMDS_MeshFace* theFace1,
627                           const SMDS_MeshFace* theFace2 );
628       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
629                               TVectorOfLink&         theSeqOfBoundary,
630                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
631                               TMapOfLink&            theNonManifold,
632                               SMDS_MeshFace*         theNextFace ) const;
633
634      void     getFacesByLink( const Link& theLink,
635                               TVectorOfFacePtr& theFaces ) const;
636
637     private:
638       const SMDS_Mesh*      myMesh;
639       TColStd_MapOfInteger  myMapIds;
640       TColStd_MapOfInteger  myMapBadGeomIds;
641       TVectorOfFacePtr      myAllFacePtr;
642       TDataMapFacePtrInt    myAllFacePtrIntDMap;
643       double                myAngToler;
644       bool                  myIsOnlyManifold;
645       long                  myStartElemId;
646
647     };
648     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
649
650
651     /*
652       Class       : ElementsOnSurface
653       Description : Predicate elements that lying on indicated surface
654                     (plane or cylinder)
655     */
656     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
657     public:
658       ElementsOnSurface();
659       ~ElementsOnSurface();
660       virtual void SetMesh( const SMDS_Mesh* theMesh );
661       virtual bool IsSatisfy( long theElementId );
662       virtual      SMDSAbs_ElementType GetType() const;
663
664       void    SetTolerance( const double theToler );
665       double  GetTolerance() const;
666       void    SetSurface( const TopoDS_Shape& theShape,
667                           const SMDSAbs_ElementType theType );
668       void    SetUseBoundaries( bool theUse );
669       bool    GetUseBoundaries() const { return myUseBoundaries; }
670
671     private:
672       void    process();
673       void    process( const SMDS_MeshElement* theElem  );
674       bool    isOnSurface( const SMDS_MeshNode* theNode );
675
676     private:
677       const SMDS_Mesh*      myMesh;
678       TColStd_MapOfInteger  myIds;
679       SMDSAbs_ElementType   myType;
680       //Handle(Geom_Surface)  mySurf;
681       TopoDS_Face           mySurf;
682       double                myToler;
683       bool                  myUseBoundaries;
684       GeomAPI_ProjectPointOnSurf myProjector;
685     };
686
687     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
688
689
690     /*
691       Class       : ElementsOnShape
692       Description : Predicate elements that lying on indicated shape
693                     (1D, 2D or 3D)
694     */
695     class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
696     {
697     public:
698       ElementsOnShape();
699       ~ElementsOnShape();
700
701       virtual void SetMesh (const SMDS_Mesh* theMesh);
702       virtual bool IsSatisfy (long theElementId);
703       virtual SMDSAbs_ElementType GetType() const;
704
705       void    SetTolerance (const double theToler);
706       double  GetTolerance() const;
707       void    SetAllNodes (bool theAllNodes);
708       bool    GetAllNodes() const { return myAllNodesFlag; }
709       void    SetShape (const TopoDS_Shape& theShape,
710                         const SMDSAbs_ElementType theType);
711
712     private:
713       void    addShape (const TopoDS_Shape& theShape);
714       void    process();
715       void    process (const SMDS_MeshElement* theElem);
716
717     private:
718       const SMDS_Mesh*      myMesh;
719       TColStd_MapOfInteger  myIds;
720       SMDSAbs_ElementType   myType;
721       TopoDS_Shape          myShape;
722       double                myToler;
723       bool                  myAllNodesFlag;
724
725       TopTools_MapOfShape         myShapesMap;
726       TopAbs_ShapeEnum            myCurShapeType; // type of current sub-shape
727       BRepClass3d_SolidClassifier myCurSC;        // current SOLID
728       GeomAPI_ProjectPointOnSurf  myCurProjFace;  // current FACE
729       TopoDS_Face                 myCurFace;      // current FACE
730       GeomAPI_ProjectPointOnCurve myCurProjEdge;  // current EDGE
731       gp_Pnt                      myCurPnt;       // current VERTEX
732     };
733
734     typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
735
736
737     /*
738       Class       : FreeFaces
739       Description : Predicate for free faces
740     */
741     class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
742     public:
743       FreeFaces();
744       virtual void SetMesh( const SMDS_Mesh* theMesh );
745       virtual bool IsSatisfy( long theElementId );
746       virtual SMDSAbs_ElementType GetType() const;
747
748     private:
749       const SMDS_Mesh* myMesh;
750     };
751
752     /*
753       Class       : LinearOrQuadratic
754       Description : Predicate for free faces
755     */
756     class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
757     public:
758       LinearOrQuadratic();
759       virtual void        SetMesh( const SMDS_Mesh* theMesh );
760       virtual bool        IsSatisfy( long theElementId );
761       void                SetType( SMDSAbs_ElementType theType );
762       virtual SMDSAbs_ElementType GetType() const;
763
764     private:
765       const SMDS_Mesh*    myMesh;
766       SMDSAbs_ElementType myType;
767     };
768     typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
769
770     /*
771       Class       : GroupColor
772       Description : Functor for check color of group to whic mesh element belongs to
773     */
774     class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
775     public:
776       GroupColor();
777       virtual void        SetMesh( const SMDS_Mesh* theMesh );
778       virtual bool        IsSatisfy( long theElementId );
779       void                SetType( SMDSAbs_ElementType theType );
780       virtual             SMDSAbs_ElementType GetType() const;
781       void                SetColorStr( const TCollection_AsciiString& );
782       void                GetColorStr( TCollection_AsciiString& ) const;
783       
784     private:
785       typedef std::set< long > TIDs;
786
787       Quantity_Color      myColor;
788       SMDSAbs_ElementType myType;
789       TIDs                myIDs;
790     };
791     typedef boost::shared_ptr<GroupColor> GroupColorPtr;
792
793     /*
794       Class       : ElemGeomType
795       Description : Predicate to check element geometry type
796     */
797     class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
798     public:
799       ElemGeomType();
800       virtual void         SetMesh( const SMDS_Mesh* theMesh );
801       virtual bool         IsSatisfy( long theElementId );
802       void                 SetType( SMDSAbs_ElementType theType );
803       virtual              SMDSAbs_ElementType GetType() const;
804       void                 SetGeomType( SMDSAbs_GeometryType theType );
805       virtual SMDSAbs_GeometryType GetGeomType() const;
806
807     private:
808       const SMDS_Mesh*     myMesh;
809       SMDSAbs_ElementType  myType;
810       SMDSAbs_GeometryType myGeomType;
811     };
812     typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
813
814     /*
815       Class       : CoplanarFaces
816       Description : Predicate to check angle between faces
817     */
818     class SMESHCONTROLS_EXPORT CoplanarFaces: public virtual Predicate
819     {
820     public:
821       CoplanarFaces();
822       void                 SetFace( long theID )                   { myFaceID = theID; }
823       long                 GetFace() const                         { return myFaceID; }
824       void                 SetTolerance (const double theToler)    { myToler = theToler; }
825       double               GetTolerance () const                   { return myToler; }
826       virtual void         SetMesh( const SMDS_Mesh* theMesh )     { myMesh = theMesh; }
827       virtual              SMDSAbs_ElementType GetType() const     { return SMDSAbs_Face; }
828
829       virtual bool         IsSatisfy( long theElementId );
830
831     private:
832       const SMDS_Mesh*     myMesh;
833       long                 myFaceID;
834       double               myToler;
835       std::set< long >     myCoplanarIDs;
836     };
837     typedef boost::shared_ptr<CoplanarFaces> CoplanarFacesPtr;
838
839     /*
840       FILTER
841     */
842     class SMESHCONTROLS_EXPORT Filter{
843     public:
844       Filter();
845       virtual ~Filter();
846       virtual void SetPredicate(PredicatePtr thePred);
847
848       typedef std::vector<long> TIdSequence;
849
850       virtual
851       void
852       GetElementsId( const SMDS_Mesh* theMesh,
853                      TIdSequence& theSequence );
854
855       static
856       void
857       GetElementsId( const SMDS_Mesh* theMesh,
858                      PredicatePtr thePredicate,
859                      TIdSequence& theSequence );
860       
861     protected:
862       PredicatePtr myPredicate;
863     };
864   };
865 };
866
867
868 #endif