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