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