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