Salome HOME
23566: EDF 17146 - Problem with viscous layer
[modules/smesh.git] / src / Controls / SMESH_ControlsDef.hxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 "SMESH_Controls.hxx"
27
28 #include "SMESH_TypeDefs.hxx"
29
30 #include <Bnd_B3d.hxx>
31 #include <GeomAPI_ProjectPointOnCurve.hxx>
32 #include <GeomAPI_ProjectPointOnSurf.hxx>
33 #include <Quantity_Color.hxx>
34 #include <TColStd_MapOfInteger.hxx>
35 #include <TColStd_SequenceOfInteger.hxx>
36 #include <TCollection_AsciiString.hxx>
37 #include <TopAbs.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <gp_XYZ.hxx>
40
41 #include <set>
42 #include <map>
43 #include <vector>
44
45 #include <boost/shared_ptr.hpp>
46
47 class SMDS_MeshElement;
48 class SMDS_MeshFace;
49 class SMDS_MeshNode;
50 class SMDS_Mesh;
51
52 class SMESHDS_Mesh;
53 class SMESHDS_SubMesh;
54 class SMESHDS_GroupBase;
55
56 class BRepClass3d_SolidClassifier;
57 class ShapeAnalysis_Surface;
58 class gp_Pln;
59 class gp_Pnt;
60
61 namespace SMESH{
62   namespace Controls{
63
64     class SMESHCONTROLS_EXPORT TSequenceOfXYZ
65     {
66       typedef std::vector<gp_XYZ>::size_type size_type;
67
68     public:
69       TSequenceOfXYZ();
70
71       explicit TSequenceOfXYZ(size_type n);
72
73       TSequenceOfXYZ(size_type n, const gp_XYZ& t);
74
75       TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ);
76
77       template <class InputIterator>
78       TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd);
79
80       ~TSequenceOfXYZ();
81
82       TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ);
83
84       gp_XYZ& operator()(size_type n);
85
86       const gp_XYZ& operator()(size_type n) const;
87
88       void clear();
89
90       void reserve(size_type n);
91
92       void push_back(const gp_XYZ& v);
93
94       size_type size() const;
95
96
97       void setElement(const SMDS_MeshElement* e) { myElem = e; }
98
99       const SMDS_MeshElement* getElement() const { return myElem; }
100
101       SMDSAbs_EntityType getElementEntity() const;
102
103     private:
104       std::vector<gp_XYZ>     myArray;
105       const SMDS_MeshElement* myElem;
106     };
107
108     /*!
109      * \brief Class used to detect mesh modification: IsMeshModified() returns
110      * true if a mesh has changed since last calling IsMeshModified()
111      */
112     class SMESHCONTROLS_EXPORT TMeshModifTracer
113     {
114       unsigned long    myMeshModifTime;
115       const SMDS_Mesh* myMesh;
116     public:
117       TMeshModifTracer();
118       void SetMesh( const SMDS_Mesh* theMesh );
119       const SMDS_Mesh* GetMesh() const { return myMesh; }
120       bool IsMeshModified();
121     };
122
123     /*
124       Class       : NumericalFunctor
125       Description : Root of all Functors returning numeric value
126     */
127     class SMESHCONTROLS_EXPORT NumericalFunctor: public virtual Functor{
128     public:
129       NumericalFunctor();
130       virtual void SetMesh( const SMDS_Mesh* theMesh );
131       virtual double GetValue( long theElementId );
132       virtual double GetValue(const TSequenceOfXYZ& thePoints) { return -1.0;};
133       void GetHistogram(int                     nbIntervals,
134                         std::vector<int>&       nbEvents,
135                         std::vector<double>&    funValues,
136                         const std::vector<int>& elements,
137                         const double*           minmax=0,
138                         const bool              isLogarithmic = false);
139       virtual SMDSAbs_ElementType GetType() const = 0;
140       virtual double GetBadRate( double Value, int nbNodes ) const = 0;
141       long  GetPrecision() const;
142       void  SetPrecision( const long thePrecision );
143       double Round( const double & value );
144       
145       bool GetPoints(const int theId, TSequenceOfXYZ& theRes) const;
146       static bool GetPoints(const SMDS_MeshElement* theElem, TSequenceOfXYZ& theRes);
147     protected:
148       const SMDS_Mesh*        myMesh;
149       const SMDS_MeshElement* myCurrElement;
150       long                    myPrecision;
151       double                  myPrecisionValue;
152     };
153
154
155     /*
156       Class       : Volume
157       Description : Functor calculating volume of 3D mesh element
158     */
159     class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
160     public:
161       virtual double GetValue( long theElementId );
162       //virtual double GetValue( const TSequenceOfXYZ& thePoints );
163       virtual double GetBadRate( double Value, int nbNodes ) const;
164       virtual SMDSAbs_ElementType GetType() const;
165     };
166   
167   
168     /*
169       Class       : MaxElementLength2D
170       Description : Functor calculating maximum length of 2D element
171     */
172     class SMESHCONTROLS_EXPORT MaxElementLength2D: public virtual NumericalFunctor{
173     public:
174       virtual double GetValue( long theElementId );
175       virtual double GetValue( const TSequenceOfXYZ& P );
176       virtual double GetBadRate( double Value, int nbNodes ) const;
177       virtual SMDSAbs_ElementType GetType() const;
178     };
179   
180   
181     /*
182       Class       : MaxElementLength3D
183       Description : Functor calculating maximum length of 3D element
184     */
185     class SMESHCONTROLS_EXPORT MaxElementLength3D: public virtual NumericalFunctor{
186     public:
187       virtual double GetValue( long theElementId );
188       virtual double GetBadRate( double Value, int nbNodes ) const;
189       virtual SMDSAbs_ElementType GetType() const;
190     };
191   
192   
193     /*
194       Class       : SMESH_MinimumAngle
195       Description : Functor for calculation of minimum angle
196     */
197     class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
198     public:
199       virtual double GetValue( const TSequenceOfXYZ& thePoints );
200       virtual double GetBadRate( double Value, int nbNodes ) const;
201       virtual SMDSAbs_ElementType GetType() const;
202     };
203   
204   
205     /*
206       Class       : AspectRatio
207       Description : Functor for calculating aspect ratio
208     */
209     class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
210     public:
211       virtual double GetValue( long theElementId );
212       virtual double GetValue( const TSequenceOfXYZ& thePoints );
213       virtual double GetBadRate( double Value, int nbNodes ) const;
214       virtual SMDSAbs_ElementType GetType() const;
215     };
216   
217   
218     /*
219       Class       : AspectRatio3D
220       Description : Functor for calculating aspect ratio of 3D elems.
221     */
222     class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
223     public:
224       virtual double GetValue( long theElementId );
225       virtual double GetValue( const TSequenceOfXYZ& thePoints );
226       virtual double GetBadRate( double Value, int nbNodes ) const;
227       virtual SMDSAbs_ElementType GetType() const;
228     };
229   
230   
231     /*
232       Class       : Warping
233       Description : Functor for calculating warping
234     */
235     class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
236     public:
237       virtual double GetValue( const TSequenceOfXYZ& thePoints );
238       virtual double GetBadRate( double Value, int nbNodes ) const;
239       virtual SMDSAbs_ElementType GetType() const;
240       
241     private:
242       double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
243     };
244   
245   
246     /*
247       Class       : Taper
248       Description : Functor for calculating taper
249     */
250     class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
251     public:
252       virtual double GetValue( const TSequenceOfXYZ& thePoints );
253       virtual double GetBadRate( double Value, int nbNodes ) const;
254       virtual SMDSAbs_ElementType GetType() const;
255     };
256
257     /*
258       Class       : Skew
259       Description : Functor for calculating skew in degrees
260     */
261     class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
262     public:
263       virtual double GetValue( const TSequenceOfXYZ& thePoints );
264       virtual double GetBadRate( double Value, int nbNodes ) const;
265       virtual SMDSAbs_ElementType GetType() const;
266     };
267
268
269     /*
270       Class       : Area
271       Description : Functor for calculating area
272     */
273     class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
274     public:
275       virtual double GetValue( const TSequenceOfXYZ& thePoints );
276       virtual double GetBadRate( double Value, int nbNodes ) const;
277       virtual SMDSAbs_ElementType GetType() const;
278     };
279   
280   
281     /*
282       Class       : Length
283       Description : Functor for calculating length of edge
284     */
285     class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
286     public:
287       virtual double GetValue( const TSequenceOfXYZ& thePoints );
288       virtual double GetBadRate( double Value, int nbNodes ) const;
289       virtual SMDSAbs_ElementType GetType() const;
290     };
291
292     /*
293       Class       : Length2D
294       Description : Functor for calculating minimal length of edge
295     */
296     class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
297     public:
298       virtual double GetValue( const TSequenceOfXYZ& thePoints );
299       virtual double GetBadRate( double Value, int nbNodes ) const;
300       virtual SMDSAbs_ElementType GetType() const;
301       struct Value{
302         double myLength;
303         long myPntId[2];
304         Value(double theLength, long thePntId1, long thePntId2);
305         bool operator<(const Value& x) const;
306       };
307       typedef std::set<Value> TValues;
308       void GetValues(TValues& theValues);
309     };
310     typedef boost::shared_ptr<Length2D> Length2DPtr;
311
312     /*
313       Class       : Deflection2D
314       Description : Functor for calculating distance between a face and geometry
315     */
316     class SMESHCONTROLS_EXPORT Deflection2D: public virtual NumericalFunctor{
317     public:
318       virtual void   SetMesh( const SMDS_Mesh* theMesh );
319       virtual double GetValue( const TSequenceOfXYZ& thePoints );
320       virtual double GetBadRate( double Value, int nbNodes ) const;
321       virtual SMDSAbs_ElementType GetType() const;
322     private:
323       Handle(ShapeAnalysis_Surface) mySurface;
324       int                           myShapeIndex;
325       boost::shared_ptr<gp_Pln>     myPlane;
326     };
327
328     /*
329       Class       : MultiConnection
330       Description : Functor for calculating number of faces connected to the edge
331     */
332     class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
333     public:
334       virtual double GetValue( long theElementId );
335       virtual double GetValue( const TSequenceOfXYZ& thePoints );
336       virtual double GetBadRate( double Value, int nbNodes ) const;
337       virtual SMDSAbs_ElementType GetType() const;
338     };
339     
340     /*
341       Class       : MultiConnection2D
342       Description : Functor for calculating number of faces connected to the edge
343     */
344     class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
345     public:
346       virtual double GetValue( long theElementId );
347       virtual double GetValue( const TSequenceOfXYZ& thePoints );
348       virtual double GetBadRate( double Value, int nbNodes ) const;
349       virtual SMDSAbs_ElementType GetType() const;
350       struct Value{
351         long myPntId[2];
352         Value(long thePntId1, long thePntId2);
353         bool operator<(const Value& x) const;
354       };
355       typedef std::map<Value,int> MValues;
356
357       void GetValues(MValues& theValues);
358     };
359     typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
360
361     /*
362       Class       : BallDiameter
363       Description : Functor returning diameter of a ball element
364     */
365     class SMESHCONTROLS_EXPORT BallDiameter: public virtual NumericalFunctor{
366     public:
367       virtual double GetValue( long theElementId );
368       virtual double GetBadRate( double Value, int nbNodes ) const;
369       virtual SMDSAbs_ElementType GetType() const;
370     };
371     
372     /*
373       Class       : NodeConnectivityNumber
374       Description : Functor returning number of elements connected to a node
375     */
376     class SMESHCONTROLS_EXPORT NodeConnectivityNumber: public virtual NumericalFunctor{
377     public:
378       virtual double GetValue( long theNodeId );
379       virtual double GetBadRate( double Value, int nbNodes ) const;
380       virtual SMDSAbs_ElementType GetType() const;
381     };
382
383
384     /*
385       PREDICATES
386     */
387     /*
388       Class       : CoincidentNodes
389       Description : Predicate of Coincident Nodes
390       Note        : This class is suitable only for visualization of Coincident Nodes
391     */
392     class SMESHCONTROLS_EXPORT CoincidentNodes: public Predicate {
393     public:
394       CoincidentNodes();
395       //virtual Predicate* clone() const { return new CoincidentNodes( *this ); }
396       virtual void SetMesh( const SMDS_Mesh* theMesh );
397       virtual bool IsSatisfy( long theElementId );
398       virtual SMDSAbs_ElementType GetType() const;
399
400       void SetTolerance (const double theToler)  { myToler = theToler; }
401       double GetTolerance () const { return myToler; }
402
403     private:
404       double               myToler;
405       TColStd_MapOfInteger myCoincidentIDs;
406       TMeshModifTracer     myMeshModifTracer;
407     };
408     typedef boost::shared_ptr<CoincidentNodes> CoincidentNodesPtr;
409    
410     /*
411       Class       : CoincidentElements
412       Description : Predicate of Coincident Elements
413       Note        : This class is suitable only for visualization of Coincident Elements
414     */
415     class SMESHCONTROLS_EXPORT CoincidentElements: public Predicate {
416     public:
417       CoincidentElements();
418       virtual void SetMesh( const SMDS_Mesh* theMesh );
419       virtual bool IsSatisfy( long theElementId );
420
421     private:
422       const SMDS_Mesh* myMesh;
423     };
424     class SMESHCONTROLS_EXPORT CoincidentElements1D: public CoincidentElements {
425     public:
426       virtual SMDSAbs_ElementType GetType() const;
427       //virtual Predicate* clone() const { return new CoincidentElements1D( *this ); }
428     };
429     class SMESHCONTROLS_EXPORT CoincidentElements2D: public CoincidentElements {
430     public:
431       virtual SMDSAbs_ElementType GetType() const;
432       //virtual Predicate* clone() const { return new CoincidentElements2D( *this ); }
433     };
434     class SMESHCONTROLS_EXPORT CoincidentElements3D: public CoincidentElements {
435     public:
436       virtual SMDSAbs_ElementType GetType() const;
437       //virtual Predicate* clone() const { return new CoincidentElements3D( *this ); }
438     };
439
440     /*
441       Class       : FreeBorders
442       Description : Predicate for free borders
443     */
444     class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
445     public:
446       FreeBorders();
447       //virtual Predicate* clone() const { return new FreeBorders( *this ); }
448       virtual void SetMesh( const SMDS_Mesh* theMesh );
449       virtual bool IsSatisfy( long theElementId );
450       virtual SMDSAbs_ElementType GetType() const;
451
452     protected:
453       const SMDS_Mesh* myMesh;
454     };
455    
456
457     /*
458       Class       : BadOrientedVolume
459       Description : Predicate bad oriented volumes
460     */
461     class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
462     public:
463       BadOrientedVolume();
464       //virtual Predicate* clone() const { return new BadOrientedVolume( *this ); }
465       virtual void SetMesh( const SMDS_Mesh* theMesh );
466       virtual bool IsSatisfy( long theElementId );
467       virtual SMDSAbs_ElementType GetType() const;
468
469     protected:
470       const SMDS_Mesh* myMesh;
471     };
472
473     /*
474       Class       : ElemEntityType
475       Description : Functor for calculating entity type
476     */
477     class SMESHCONTROLS_EXPORT ElemEntityType: public virtual Predicate{
478       public:
479       ElemEntityType();
480       //virtual Predicate*   clone() const { return new ElemEntityType( *this ); }
481       virtual void         SetMesh( const SMDS_Mesh* theMesh );
482       virtual bool         IsSatisfy( long theElementId );
483       void                 SetType( SMDSAbs_ElementType theType );
484       virtual              SMDSAbs_ElementType GetType() const;
485       void                 SetElemEntityType( SMDSAbs_EntityType theEntityType );
486       SMDSAbs_EntityType   GetElemEntityType() const;
487
488     private:
489       const SMDS_Mesh*     myMesh;
490       SMDSAbs_ElementType  myType;
491       SMDSAbs_EntityType   myEntityType;
492     };
493     typedef boost::shared_ptr<ElemEntityType> ElemEntityTypePtr;
494
495
496     /*
497       BareBorderVolume
498     */
499     class SMESHCONTROLS_EXPORT BareBorderVolume: public Predicate
500     {
501     public:
502       BareBorderVolume():myMesh(0) {}
503       virtual Predicate* clone() const { return new BareBorderVolume( *this ); }
504       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
505       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
506       virtual bool IsSatisfy( long theElementId );
507     protected:
508       const SMDS_Mesh* myMesh;
509     };
510     typedef boost::shared_ptr<BareBorderVolume> BareBorderVolumePtr;
511
512     /*
513       BareBorderFace
514     */
515     class SMESHCONTROLS_EXPORT BareBorderFace: public Predicate
516     {
517     public:
518       BareBorderFace():myMesh(0) {}
519       //virtual Predicate* clone() const { return new BareBorderFace( *this ); }
520       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
521       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
522       virtual bool IsSatisfy( long theElementId );
523     protected:
524       const SMDS_Mesh* myMesh;
525       std::vector< const SMDS_MeshNode* > myLinkNodes;
526     };
527     typedef boost::shared_ptr<BareBorderFace> BareBorderFacePtr;
528
529     /*
530       OverConstrainedVolume
531     */
532     class SMESHCONTROLS_EXPORT OverConstrainedVolume: public Predicate
533     {
534     public:
535       OverConstrainedVolume():myMesh(0) {}
536       virtual Predicate* clone() const { return new OverConstrainedVolume( *this ); }
537       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
538       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
539       virtual bool IsSatisfy( long theElementId );
540     protected:
541       const SMDS_Mesh* myMesh;
542     };
543     typedef boost::shared_ptr<OverConstrainedVolume> OverConstrainedVolumePtr;
544
545     /*
546       OverConstrainedFace
547     */
548     class SMESHCONTROLS_EXPORT OverConstrainedFace: public Predicate
549     {
550     public:
551       OverConstrainedFace():myMesh(0) {}
552       //virtual Predicate* clone() const { return new OverConstrainedFace( *this ); }
553       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
554       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
555       virtual bool IsSatisfy( long theElementId );
556     protected:
557       const SMDS_Mesh* myMesh;
558     };
559     typedef boost::shared_ptr<OverConstrainedFace> OverConstrainedFacePtr;
560
561     /*
562       Class       : FreeEdges
563       Description : Predicate for free Edges
564     */
565     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
566     public:
567       FreeEdges();
568       //virtual Predicate* clone() const { return new FreeEdges( *this ); }
569       virtual void SetMesh( const SMDS_Mesh* theMesh );
570       virtual bool IsSatisfy( long theElementId );
571       virtual SMDSAbs_ElementType GetType() const;
572       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
573       typedef long TElemId;
574       struct Border{
575         TElemId myElemId;
576         TElemId myPntId[2];
577         Border(long theElemId, long thePntId1, long thePntId2);
578         bool operator<(const Border& x) const;
579       };
580       typedef std::set<Border> TBorders;
581       void GetBoreders(TBorders& theBorders);
582
583     protected:
584       const SMDS_Mesh* myMesh;
585     };
586     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
587     
588     
589     /*
590       Class       : FreeNodes
591       Description : Predicate for free nodes
592     */
593     class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
594     public:
595       FreeNodes();
596       //virtual Predicate* clone() const { return new FreeNodes( *this ); }
597       virtual void SetMesh( const SMDS_Mesh* theMesh );
598       virtual bool IsSatisfy( long theNodeId );
599       virtual SMDSAbs_ElementType GetType() const;
600
601     protected:
602       const SMDS_Mesh* myMesh;
603     };
604     
605
606     /*
607       Class       : RangeOfIds
608       Description : Predicate for Range of Ids.
609                     Range may be specified with two ways.
610                     1. Using AddToRange method
611                     2. With SetRangeStr method. Parameter of this method is a string
612                        like as "1,2,3,50-60,63,67,70-"
613     */
614     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
615     {
616     public:
617       RangeOfIds();
618       //virtual Predicate*            clone() const { return new RangeOfIds( *this ); }
619       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
620       virtual bool                  IsSatisfy( long theNodeId );
621       virtual SMDSAbs_ElementType   GetType() const;
622       virtual void                  SetType( SMDSAbs_ElementType theType );
623
624       bool                          AddToRange( long theEntityId );
625       void                          GetRangeStr( TCollection_AsciiString& );
626       bool                          SetRangeStr( const TCollection_AsciiString& );
627
628     protected:
629       const SMDS_Mesh*              myMesh;
630
631       TColStd_SequenceOfInteger     myMin;
632       TColStd_SequenceOfInteger     myMax;
633       TColStd_MapOfInteger          myIds;
634
635       SMDSAbs_ElementType           myType;
636     };
637     
638     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
639    
640     
641     /*
642       Class       : Comparator
643       Description : Base class for comparators
644     */
645     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
646     public:
647       Comparator();
648       virtual ~Comparator();
649       virtual void SetMesh( const SMDS_Mesh* theMesh );
650       virtual void SetMargin(double theValue);
651       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
652       virtual bool IsSatisfy( long theElementId ) = 0;
653       virtual SMDSAbs_ElementType GetType() const;
654       double  GetMargin();
655   
656     protected:
657       double myMargin;
658       NumericalFunctorPtr myFunctor;
659     };
660     typedef boost::shared_ptr<Comparator> ComparatorPtr;
661   
662   
663     /*
664       Class       : LessThan
665       Description : Comparator "<"
666     */
667     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
668     public:
669       virtual bool IsSatisfy( long theElementId );
670       //virtual Predicate* clone() const { return new LessThan( *this ); }
671     };
672   
673   
674     /*
675       Class       : MoreThan
676       Description : Comparator ">"
677     */
678     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
679     public:
680       virtual bool IsSatisfy( long theElementId );
681       //virtual Predicate* clone() const { return new MoreThan( *this ); }
682     };
683   
684   
685     /*
686       Class       : EqualTo
687       Description : Comparator "="
688     */
689     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
690     public:
691       EqualTo();
692       //virtual Predicate* clone() const { return new EqualTo( *this ); }
693       virtual bool IsSatisfy( long theElementId );
694       virtual void SetTolerance( double theTol );
695       virtual double GetTolerance();
696   
697     private:
698       double myToler;
699     };
700     typedef boost::shared_ptr<EqualTo> EqualToPtr;
701   
702     
703     /*
704       Class       : LogicalNOT
705       Description : Logical NOT predicate
706     */
707     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
708     public:
709       LogicalNOT();
710       //virtual Predicate* clone() const { return new LogicalNOT( *this ); }
711       virtual ~LogicalNOT();
712       virtual bool IsSatisfy( long theElementId );
713       virtual void SetMesh( const SMDS_Mesh* theMesh );
714       virtual void SetPredicate(PredicatePtr thePred);
715       virtual SMDSAbs_ElementType GetType() const;
716   
717     private:
718       PredicatePtr myPredicate;
719     };
720     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
721     
722   
723     /*
724       Class       : LogicalBinary
725       Description : Base class for binary logical predicate
726     */
727     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
728     public:
729       LogicalBinary();
730       virtual ~LogicalBinary();
731       virtual void SetMesh( const SMDS_Mesh* theMesh );
732       virtual void SetPredicate1(PredicatePtr thePred);
733       virtual void SetPredicate2(PredicatePtr thePred);
734       virtual SMDSAbs_ElementType GetType() const;
735   
736     protected:
737       PredicatePtr myPredicate1;
738       PredicatePtr myPredicate2;
739     };
740     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
741   
742   
743     /*
744       Class       : LogicalAND
745       Description : Logical AND
746     */
747     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
748     public:
749       virtual bool IsSatisfy( long theElementId );
750       //virtual Predicate* clone() const { return new LogicalAND( *this ); }
751     };
752   
753   
754     /*
755       Class       : LogicalOR
756       Description : Logical OR
757     */
758     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
759     public:
760       virtual bool IsSatisfy( long theElementId );
761       //virtual Predicate* clone() const { return new LogicalOR( *this ); }
762     };
763   
764   
765     /*
766       Class       : ManifoldPart
767       Description : Predicate for manifold part of mesh
768     */
769     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
770     public:
771
772       /* internal class for algorithm uses */
773       class Link
774       {
775       public:
776         Link( SMDS_MeshNode* theNode1,
777               SMDS_MeshNode* theNode2 );
778         ~Link();
779         
780         bool IsEqual( const ManifoldPart::Link& theLink ) const;
781         bool operator<(const ManifoldPart::Link& x) const;
782         
783         SMDS_MeshNode* myNode1;
784         SMDS_MeshNode* myNode2;
785       };
786
787       bool IsEqual( const ManifoldPart::Link& theLink1,
788                     const ManifoldPart::Link& theLink2 );
789       
790       typedef std::set<ManifoldPart::Link>                TMapOfLink;
791       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
792       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
793       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
794       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
795       
796       ManifoldPart();
797       ~ManifoldPart();
798       //virtual Predicate* clone() const { return new ManifoldPart( *this ); }
799       virtual void SetMesh( const SMDS_Mesh* theMesh );
800       // inoke when all parameters already set
801       virtual bool IsSatisfy( long theElementId );
802       virtual      SMDSAbs_ElementType GetType() const;
803
804       void    SetAngleTolerance( const double theAngToler );
805       double  GetAngleTolerance() const;
806       void    SetIsOnlyManifold( const bool theIsOnly );
807       void    SetStartElem( const long  theStartElemId );
808
809     private:
810       bool    process();
811       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
812                              SMDS_MeshFace*            theStartFace,
813                              TMapOfLink&               theNonManifold,
814                              TColStd_MapOfInteger&     theResFaces );
815       bool    isInPlane( const SMDS_MeshFace* theFace1,
816                           const SMDS_MeshFace* theFace2 );
817       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
818                               TVectorOfLink&         theSeqOfBoundary,
819                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
820                               TMapOfLink&            theNonManifold,
821                               SMDS_MeshFace*         theNextFace ) const;
822
823       void     getFacesByLink( const Link& theLink,
824                                TVectorOfFacePtr& theFaces ) const;
825
826     private:
827       const SMDS_Mesh*      myMesh;
828       TColStd_MapOfInteger  myMapIds;
829       TColStd_MapOfInteger  myMapBadGeomIds;
830       TVectorOfFacePtr      myAllFacePtr;
831       TDataMapFacePtrInt    myAllFacePtrIntDMap;
832       double                myAngToler;
833       bool                  myIsOnlyManifold;
834       long                  myStartElemId;
835
836     };
837     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
838
839     /*
840       Class       : BelongToMeshGroup
841       Description : Verify whether a mesh element is included into a mesh group
842     */
843     class SMESHCONTROLS_EXPORT BelongToMeshGroup : public virtual Predicate
844     {
845     public:
846       BelongToMeshGroup();
847       //virtual Predicate* clone() const { return new BelongToMeshGroup( *this ); }
848       virtual void SetMesh( const SMDS_Mesh* theMesh );
849       virtual bool IsSatisfy( long theElementId );
850       virtual SMDSAbs_ElementType GetType() const;
851
852       void SetGroup( SMESHDS_GroupBase* g );
853       void SetStoreName( const std::string& sn );
854       const SMESHDS_GroupBase* GetGroup() const { return myGroup; }
855
856     private:
857       SMESHDS_GroupBase* myGroup;
858       std::string        myStoreName;
859     };
860     typedef boost::shared_ptr<BelongToMeshGroup> BelongToMeshGroupPtr;
861
862     /*
863       Class       : ElementsOnSurface
864       Description : Predicate elements that lying on indicated surface
865                     (plane or cylinder)
866     */
867     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
868     public:
869       ElementsOnSurface();
870       ~ElementsOnSurface();
871       //virtual Predicate* clone() const { return new ElementsOnSurface( *this ); }
872       virtual void SetMesh( const SMDS_Mesh* theMesh );
873       virtual bool IsSatisfy( long theElementId );
874       virtual      SMDSAbs_ElementType GetType() const;
875
876       void    SetTolerance( const double theToler );
877       double  GetTolerance() const;
878       void    SetSurface( const TopoDS_Shape& theShape,
879                           const SMDSAbs_ElementType theType );
880       void    SetUseBoundaries( bool theUse );
881       bool    GetUseBoundaries() const { return myUseBoundaries; }
882
883     private:
884       void    process();
885       void    process( const SMDS_MeshElement* theElem  );
886       bool    isOnSurface( const SMDS_MeshNode* theNode );
887
888     private:
889       TMeshModifTracer      myMeshModifTracer;
890       TColStd_MapOfInteger  myIds;
891       SMDSAbs_ElementType   myType;
892       TopoDS_Face           mySurf;
893       double                myToler;
894       bool                  myUseBoundaries;
895       GeomAPI_ProjectPointOnSurf myProjector;
896     };
897
898     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
899
900
901     /*
902       Class       : ElementsOnShape
903       Description : Predicate elements that lying on indicated shape
904                     (1D, 2D or 3D)
905     */
906     class SMESHCONTROLS_EXPORT ElementsOnShape : public Predicate
907     {
908     public:
909       ElementsOnShape();
910       ~ElementsOnShape();
911
912       virtual Predicate* clone() const;
913       virtual void SetMesh (const SMDS_Mesh* theMesh);
914       virtual bool IsSatisfy (long theElementId);
915       virtual SMDSAbs_ElementType GetType() const;
916
917       void    SetTolerance (const double theToler);
918       double  GetTolerance() const;
919       void    SetAllNodes (bool theAllNodes);
920       bool    GetAllNodes() const { return myAllNodesFlag; }
921       void    SetShape (const TopoDS_Shape& theShape,
922                         const SMDSAbs_ElementType theType);
923       bool    IsSatisfy (const SMDS_MeshElement* elem);
924       bool    IsSatisfy (const SMDS_MeshNode* node, TopoDS_Shape* okShape=0);
925
926     private:
927
928       struct Classifier;
929       struct OctreeClassifier;
930
931       void clearClassifiers();
932       bool getNodeIsOut( const SMDS_MeshNode* n, bool& isOut );
933       void setNodeIsOut( const SMDS_MeshNode* n, bool  isOut );
934
935       std::vector< Classifier >  myClassifiers;
936       std::vector< Classifier* > myWorkClassifiers;
937       OctreeClassifier*          myOctree;
938       SMDSAbs_ElementType        myType;
939       TopoDS_Shape               myShape;
940       double                     myToler;
941       bool                       myAllNodesFlag;
942
943       TMeshModifTracer           myMeshModifTracer;
944       std::vector<bool>          myNodeIsChecked;
945       std::vector<bool>          myNodeIsOut;
946     };
947
948     typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
949
950
951     /*
952       Class       : BelongToGeom
953       Description : Predicate for verifying whether entiy belong to
954       specified geometrical support
955     */
956     class SMESHCONTROLS_EXPORT BelongToGeom: public virtual Predicate
957     {
958     public:
959       BelongToGeom();
960       virtual Predicate* clone() const;
961
962       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
963       virtual void                    SetGeom( const TopoDS_Shape& theShape );
964
965       virtual bool                    IsSatisfy( long theElementId );
966
967       virtual void                    SetType( SMDSAbs_ElementType theType );
968       virtual                         SMDSAbs_ElementType GetType() const;
969
970       TopoDS_Shape                    GetShape();
971       const SMESHDS_Mesh*             GetMeshDS() const;
972
973       void                            SetTolerance( double );
974       double                          GetTolerance();
975
976     private:
977       virtual void                    init();
978
979       TopoDS_Shape                    myShape;
980       TColStd_MapOfInteger            mySubShapesIDs;
981       const SMESHDS_Mesh*             myMeshDS;
982       SMDSAbs_ElementType             myType;
983       bool                            myIsSubshape;
984       double                          myTolerance;          // only if myIsSubshape == false
985       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
986     };
987     typedef boost::shared_ptr<BelongToGeom> BelongToGeomPtr;
988
989     /*
990       Class       : LyingOnGeom
991       Description : Predicate for verifying whether entiy lying or partially lying on
992       specified geometrical support
993     */
994     class SMESHCONTROLS_EXPORT LyingOnGeom: public virtual Predicate
995     {
996     public:
997       LyingOnGeom();
998       virtual Predicate* clone() const;
999       
1000       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
1001       virtual void                    SetGeom( const TopoDS_Shape& theShape );
1002       
1003       virtual bool                    IsSatisfy( long theElementId );
1004       
1005       virtual void                    SetType( SMDSAbs_ElementType theType );
1006       virtual                         SMDSAbs_ElementType GetType() const;
1007       
1008       TopoDS_Shape                    GetShape();
1009       const SMESHDS_Mesh*             GetMeshDS() const;
1010
1011       void                            SetTolerance( double );
1012       double                          GetTolerance();
1013       
1014    private:
1015       virtual void                    init();
1016
1017       TopoDS_Shape                    myShape;
1018       TColStd_MapOfInteger            mySubShapesIDs;
1019       const SMESHDS_Mesh*             myMeshDS;
1020       SMDSAbs_ElementType             myType;
1021       bool                            myIsSubshape;
1022       double                          myTolerance;          // only if myIsSubshape == false
1023       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
1024     };
1025     typedef boost::shared_ptr<LyingOnGeom> LyingOnGeomPtr;
1026
1027     /*
1028       Class       : FreeFaces
1029       Description : Predicate for free faces
1030     */
1031     class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
1032     public:
1033       FreeFaces();
1034       //virtual Predicate* clone() const { return new FreeFaces( *this ); }
1035       virtual void SetMesh( const SMDS_Mesh* theMesh );
1036       virtual bool IsSatisfy( long theElementId );
1037       virtual SMDSAbs_ElementType GetType() const;
1038
1039     private:
1040       const SMDS_Mesh* myMesh;
1041     };
1042
1043     /*
1044       Class       : LinearOrQuadratic
1045       Description : Predicate for free faces
1046     */
1047     class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
1048     public:
1049       LinearOrQuadratic();
1050       //virtual Predicate*  clone() const { return new LinearOrQuadratic( *this ); }
1051       virtual void        SetMesh( const SMDS_Mesh* theMesh );
1052       virtual bool        IsSatisfy( long theElementId );
1053       void                SetType( SMDSAbs_ElementType theType );
1054       virtual SMDSAbs_ElementType GetType() const;
1055
1056     private:
1057       const SMDS_Mesh*    myMesh;
1058       SMDSAbs_ElementType myType;
1059     };
1060     typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
1061
1062     /*
1063       Class       : GroupColor
1064       Description : Functor for check color of group to which mesh element belongs to
1065     */
1066     class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
1067     public:
1068       GroupColor();
1069       //virtual Predicate*  clone() const { return new GroupColor( *this ); }
1070       virtual void        SetMesh( const SMDS_Mesh* theMesh );
1071       virtual bool        IsSatisfy( long theElementId );
1072       void                SetType( SMDSAbs_ElementType theType );
1073       virtual             SMDSAbs_ElementType GetType() const;
1074       void                SetColorStr( const TCollection_AsciiString& );
1075       void                GetColorStr( TCollection_AsciiString& ) const;
1076       
1077     private:
1078       typedef std::set< long > TIDs;
1079
1080       Quantity_Color      myColor;
1081       SMDSAbs_ElementType myType;
1082       TIDs                myIDs;
1083     };
1084     typedef boost::shared_ptr<GroupColor> GroupColorPtr;
1085
1086     /*
1087       Class       : ElemGeomType
1088       Description : Predicate to check element geometry type
1089     */
1090     class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
1091     public:
1092       ElemGeomType();
1093       //virtual Predicate*   clone() const { return new ElemGeomType( *this ); }
1094       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1095       virtual bool         IsSatisfy( long theElementId );
1096       void                 SetType( SMDSAbs_ElementType theType );
1097       virtual              SMDSAbs_ElementType GetType() const;
1098       void                 SetGeomType( SMDSAbs_GeometryType theType );
1099       SMDSAbs_GeometryType GetGeomType() const;
1100
1101     private:
1102       const SMDS_Mesh*     myMesh;
1103       SMDSAbs_ElementType  myType;
1104       SMDSAbs_GeometryType myGeomType;
1105     };
1106     typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
1107
1108     /*
1109       Class       : CoplanarFaces
1110       Description : Predicate to check angle between faces
1111     */
1112     class SMESHCONTROLS_EXPORT CoplanarFaces: public virtual Predicate
1113     {
1114     public:
1115       CoplanarFaces();
1116       //virtual Predicate*   clone() const { return new CoplanarFaces( *this ); }
1117       void                 SetFace( long theID )                   { myFaceID = theID; }
1118       long                 GetFace() const                         { return myFaceID; }
1119       void                 SetTolerance (const double theToler)    { myToler = theToler; }
1120       double               GetTolerance () const                   { return myToler; }
1121       virtual              SMDSAbs_ElementType GetType() const     { return SMDSAbs_Face; }
1122
1123       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1124       virtual bool         IsSatisfy( long theElementId );
1125
1126     private:
1127       TMeshModifTracer     myMeshModifTracer;
1128       long                 myFaceID;
1129       double               myToler;
1130       TColStd_MapOfInteger myCoplanarIDs;
1131     };
1132     typedef boost::shared_ptr<CoplanarFaces> CoplanarFacesPtr;
1133
1134     /*
1135       Class       : ConnectedElements
1136       Description : Predicate to get elements of one domain
1137     */
1138     class SMESHCONTROLS_EXPORT ConnectedElements: public virtual Predicate
1139     {
1140     public:
1141       ConnectedElements();
1142       //virtual Predicate*   clone() const { return new ConnectedElements( *this ); }
1143       void                 SetNode( int nodeID );
1144       void                 SetPoint( double x, double y, double z );
1145       int                  GetNode() const;
1146       std::vector<double>  GetPoint() const;
1147
1148       void                 SetType( SMDSAbs_ElementType theType );
1149       virtual              SMDSAbs_ElementType GetType() const;
1150
1151       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1152       virtual bool         IsSatisfy( long theElementId );
1153
1154       //const std::set<long>& GetDomainIDs() const { return myOkIDs; }
1155
1156     private:
1157       int                 myNodeID;
1158       std::vector<double> myXYZ;
1159       SMDSAbs_ElementType myType;
1160       TMeshModifTracer    myMeshModifTracer;
1161
1162       void                clearOkIDs();
1163       bool                myOkIDsReady;
1164       std::set< int >     myOkIDs; // empty means that there is one domain
1165     };
1166     typedef boost::shared_ptr<ConnectedElements> ConnectedElementsPtr;
1167
1168     /*
1169       FILTER
1170     */
1171     class SMESHCONTROLS_EXPORT Filter {
1172     public:
1173       Filter();
1174       virtual ~Filter();
1175       virtual void SetPredicate(PredicatePtr thePred);
1176
1177       typedef std::vector<long> TIdSequence;
1178
1179       virtual
1180       void
1181       GetElementsId( const SMDS_Mesh* theMesh,
1182                      TIdSequence& theSequence );
1183
1184       static
1185       void
1186       GetElementsId( const SMDS_Mesh* theMesh,
1187                      PredicatePtr thePredicate,
1188                      TIdSequence& theSequence );
1189       
1190     protected:
1191       PredicatePtr myPredicate;
1192     };
1193   };
1194 };
1195
1196
1197 #endif