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