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