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