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