Salome HOME
bc84ad4b1cfc8a1e69424b539b91340018290eab
[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 void SetMesh( const SMDS_Mesh* theMesh );
368       virtual bool IsSatisfy( long theElementId );
369       virtual SMDSAbs_ElementType GetType() const;
370
371       void SetTolerance (const double theToler)  { myToler = theToler; }
372       double GetTolerance () const { return myToler; }
373
374     private:
375       double               myToler;
376       TColStd_MapOfInteger myCoincidentIDs;
377       TMeshModifTracer     myMeshModifTracer;
378     };
379     typedef boost::shared_ptr<CoincidentNodes> CoincidentNodesPtr;
380    
381     /*
382       Class       : CoincidentElements
383       Description : Predicate of Coincident Elements
384       Note        : This class is suitable only for visualization of Coincident Elements
385     */
386     class SMESHCONTROLS_EXPORT CoincidentElements: public Predicate {
387     public:
388       CoincidentElements();
389       virtual void SetMesh( const SMDS_Mesh* theMesh );
390       virtual bool IsSatisfy( long theElementId );
391
392     private:
393       const SMDS_Mesh* myMesh;
394     };
395     class SMESHCONTROLS_EXPORT CoincidentElements1D: public CoincidentElements {
396     public:
397       virtual SMDSAbs_ElementType GetType() const;
398     };
399     class SMESHCONTROLS_EXPORT CoincidentElements2D: public CoincidentElements {
400     public:
401       virtual SMDSAbs_ElementType GetType() const;
402     };
403     class SMESHCONTROLS_EXPORT CoincidentElements3D: public CoincidentElements {
404     public:
405       virtual SMDSAbs_ElementType GetType() const;
406     };
407
408     /*
409       Class       : FreeBorders
410       Description : Predicate for free borders
411     */
412     class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
413     public:
414       FreeBorders();
415       virtual void SetMesh( const SMDS_Mesh* theMesh );
416       virtual bool IsSatisfy( long theElementId );
417       virtual SMDSAbs_ElementType GetType() const;
418
419     protected:
420       const SMDS_Mesh* myMesh;
421     };
422    
423
424     /*
425       Class       : BadOrientedVolume
426       Description : Predicate bad oriented volumes
427     */
428     class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
429     public:
430       BadOrientedVolume();
431       virtual void SetMesh( const SMDS_Mesh* theMesh );
432       virtual bool IsSatisfy( long theElementId );
433       virtual SMDSAbs_ElementType GetType() const;
434
435     protected:
436       const SMDS_Mesh* myMesh;
437     };
438
439     /*
440       Class       : ElemEntityType
441       Description : Functor for calculating entity type
442     */
443     class SMESHCONTROLS_EXPORT ElemEntityType: public virtual Predicate{
444       public:
445       ElemEntityType();
446       virtual void         SetMesh( const SMDS_Mesh* theMesh );
447       virtual bool         IsSatisfy( long theElementId );
448       void                 SetType( SMDSAbs_ElementType theType );
449       virtual              SMDSAbs_ElementType GetType() const;
450       void                 SetElemEntityType( SMDSAbs_EntityType theEntityType );
451       SMDSAbs_EntityType   GetElemEntityType() const;
452
453     private:
454       const SMDS_Mesh*     myMesh;
455       SMDSAbs_ElementType  myType;
456       SMDSAbs_EntityType   myEntityType;
457     };
458     typedef boost::shared_ptr<ElemEntityType> ElemEntityTypePtr;
459
460
461     /*
462       BareBorderVolume
463     */
464     class SMESHCONTROLS_EXPORT BareBorderVolume: public Predicate
465     {
466     public:
467       BareBorderVolume():myMesh(0) {}
468       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
469       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
470       virtual bool IsSatisfy( long theElementId );
471     protected:
472       const SMDS_Mesh* myMesh;
473     };
474     typedef boost::shared_ptr<BareBorderVolume> BareBorderVolumePtr;
475
476     /*
477       BareBorderFace
478     */
479     class SMESHCONTROLS_EXPORT BareBorderFace: public Predicate
480     {
481     public:
482       BareBorderFace():myMesh(0) {}
483       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
484       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
485       virtual bool IsSatisfy( long theElementId );
486     protected:
487       const SMDS_Mesh* myMesh;
488       std::vector< const SMDS_MeshNode* > myLinkNodes;
489     };
490     typedef boost::shared_ptr<BareBorderFace> BareBorderFacePtr;
491
492     /*
493       OverConstrainedVolume
494     */
495     class SMESHCONTROLS_EXPORT OverConstrainedVolume: public Predicate
496     {
497     public:
498       OverConstrainedVolume():myMesh(0) {}
499       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
500       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
501       virtual bool IsSatisfy( long theElementId );
502     protected:
503       const SMDS_Mesh* myMesh;
504     };
505     typedef boost::shared_ptr<OverConstrainedVolume> OverConstrainedVolumePtr;
506
507     /*
508       OverConstrainedFace
509     */
510     class SMESHCONTROLS_EXPORT OverConstrainedFace: public Predicate
511     {
512     public:
513       OverConstrainedFace():myMesh(0) {}
514       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
515       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
516       virtual bool IsSatisfy( long theElementId );
517     protected:
518       const SMDS_Mesh* myMesh;
519     };
520     typedef boost::shared_ptr<OverConstrainedFace> OverConstrainedFacePtr;
521
522     /*
523       Class       : FreeEdges
524       Description : Predicate for free Edges
525     */
526     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
527     public:
528       FreeEdges();
529       virtual void SetMesh( const SMDS_Mesh* theMesh );
530       virtual bool IsSatisfy( long theElementId );
531       virtual SMDSAbs_ElementType GetType() const;
532       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
533       typedef long TElemId;
534       struct Border{
535         TElemId myElemId;
536         TElemId myPntId[2];
537         Border(long theElemId, long thePntId1, long thePntId2);
538         bool operator<(const Border& x) const;
539       };
540       typedef std::set<Border> TBorders;
541       void GetBoreders(TBorders& theBorders);
542
543     protected:
544       const SMDS_Mesh* myMesh;
545     };
546     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
547     
548     
549     /*
550       Class       : FreeNodes
551       Description : Predicate for free nodes
552     */
553     class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
554     public:
555       FreeNodes();
556       virtual void SetMesh( const SMDS_Mesh* theMesh );
557       virtual bool IsSatisfy( long theNodeId );
558       virtual SMDSAbs_ElementType GetType() const;
559
560     protected:
561       const SMDS_Mesh* myMesh;
562     };
563     
564
565     /*
566       Class       : RangeOfIds
567       Description : Predicate for Range of Ids.
568                     Range may be specified with two ways.
569                     1. Using AddToRange method
570                     2. With SetRangeStr method. Parameter of this method is a string
571                        like as "1,2,3,50-60,63,67,70-"
572     */
573     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
574     {
575     public:
576                                     RangeOfIds();
577       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
578       virtual bool                  IsSatisfy( long theNodeId );
579       virtual SMDSAbs_ElementType   GetType() const;
580       virtual void                  SetType( SMDSAbs_ElementType theType );
581
582       bool                          AddToRange( long theEntityId );
583       void                          GetRangeStr( TCollection_AsciiString& );
584       bool                          SetRangeStr( const TCollection_AsciiString& );
585
586     protected:
587       const SMDS_Mesh*              myMesh;
588
589       TColStd_SequenceOfInteger     myMin;
590       TColStd_SequenceOfInteger     myMax;
591       TColStd_MapOfInteger          myIds;
592
593       SMDSAbs_ElementType           myType;
594     };
595     
596     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
597    
598     
599     /*
600       Class       : Comparator
601       Description : Base class for comparators
602     */
603     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
604     public:
605       Comparator();
606       virtual ~Comparator();
607       virtual void SetMesh( const SMDS_Mesh* theMesh );
608       virtual void SetMargin(double theValue);
609       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
610       virtual bool IsSatisfy( long theElementId ) = 0;
611       virtual SMDSAbs_ElementType GetType() const;
612       double  GetMargin();
613   
614     protected:
615       double myMargin;
616       NumericalFunctorPtr myFunctor;
617     };
618     typedef boost::shared_ptr<Comparator> ComparatorPtr;
619   
620   
621     /*
622       Class       : LessThan
623       Description : Comparator "<"
624     */
625     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
626     public:
627       virtual bool IsSatisfy( long theElementId );
628     };
629   
630   
631     /*
632       Class       : MoreThan
633       Description : Comparator ">"
634     */
635     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
636     public:
637       virtual bool IsSatisfy( long theElementId );
638     };
639   
640   
641     /*
642       Class       : EqualTo
643       Description : Comparator "="
644     */
645     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
646     public:
647       EqualTo();
648       virtual bool IsSatisfy( long theElementId );
649       virtual void SetTolerance( double theTol );
650       virtual double GetTolerance();
651   
652     private:
653       double myToler;
654     };
655     typedef boost::shared_ptr<EqualTo> EqualToPtr;
656   
657     
658     /*
659       Class       : LogicalNOT
660       Description : Logical NOT predicate
661     */
662     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
663     public:
664       LogicalNOT();
665       virtual ~LogicalNOT();
666       virtual bool IsSatisfy( long theElementId );
667       virtual void SetMesh( const SMDS_Mesh* theMesh );
668       virtual void SetPredicate(PredicatePtr thePred);
669       virtual SMDSAbs_ElementType GetType() const;
670   
671     private:
672       PredicatePtr myPredicate;
673     };
674     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
675     
676   
677     /*
678       Class       : LogicalBinary
679       Description : Base class for binary logical predicate
680     */
681     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
682     public:
683       LogicalBinary();
684       virtual ~LogicalBinary();
685       virtual void SetMesh( const SMDS_Mesh* theMesh );
686       virtual void SetPredicate1(PredicatePtr thePred);
687       virtual void SetPredicate2(PredicatePtr thePred);
688       virtual SMDSAbs_ElementType GetType() const;
689   
690     protected:
691       PredicatePtr myPredicate1;
692       PredicatePtr myPredicate2;
693     };
694     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
695   
696   
697     /*
698       Class       : LogicalAND
699       Description : Logical AND
700     */
701     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
702     public:
703       virtual bool IsSatisfy( long theElementId );
704     };
705   
706   
707     /*
708       Class       : LogicalOR
709       Description : Logical OR
710     */
711     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
712     public:
713       virtual bool IsSatisfy( long theElementId );
714     };
715   
716   
717     /*
718       Class       : ManifoldPart
719       Description : Predicate for manifold part of mesh
720     */
721     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
722     public:
723
724       /* internal class for algorithm uses */
725       class Link
726       {
727       public:
728         Link( SMDS_MeshNode* theNode1,
729               SMDS_MeshNode* theNode2 );
730         ~Link();
731         
732         bool IsEqual( const ManifoldPart::Link& theLink ) const;
733         bool operator<(const ManifoldPart::Link& x) const;
734         
735         SMDS_MeshNode* myNode1;
736         SMDS_MeshNode* myNode2;
737       };
738
739       bool IsEqual( const ManifoldPart::Link& theLink1,
740                     const ManifoldPart::Link& theLink2 );
741       
742       typedef std::set<ManifoldPart::Link>                TMapOfLink;
743       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
744       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
745       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
746       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
747       
748       ManifoldPart();
749       ~ManifoldPart();
750       virtual void SetMesh( const SMDS_Mesh* theMesh );
751       // inoke when all parameters already set
752       virtual bool IsSatisfy( long theElementId );
753       virtual      SMDSAbs_ElementType GetType() const;
754
755       void    SetAngleTolerance( const double theAngToler );
756       double  GetAngleTolerance() const;
757       void    SetIsOnlyManifold( const bool theIsOnly );
758       void    SetStartElem( const long  theStartElemId );
759
760     private:
761       bool    process();
762       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
763                              SMDS_MeshFace*            theStartFace,
764                              TMapOfLink&               theNonManifold,
765                              TColStd_MapOfInteger&     theResFaces );
766       bool    isInPlane( const SMDS_MeshFace* theFace1,
767                           const SMDS_MeshFace* theFace2 );
768       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
769                               TVectorOfLink&         theSeqOfBoundary,
770                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
771                               TMapOfLink&            theNonManifold,
772                               SMDS_MeshFace*         theNextFace ) const;
773
774       void     getFacesByLink( const Link& theLink,
775                                TVectorOfFacePtr& theFaces ) const;
776
777     private:
778       const SMDS_Mesh*      myMesh;
779       TColStd_MapOfInteger  myMapIds;
780       TColStd_MapOfInteger  myMapBadGeomIds;
781       TVectorOfFacePtr      myAllFacePtr;
782       TDataMapFacePtrInt    myAllFacePtrIntDMap;
783       double                myAngToler;
784       bool                  myIsOnlyManifold;
785       long                  myStartElemId;
786
787     };
788     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
789
790     /*
791       Class       : BelongToMeshGroup
792       Description : Verify whether a mesh element is included into a mesh group
793     */
794     class SMESHCONTROLS_EXPORT BelongToMeshGroup : public virtual Predicate
795     {
796     public:
797       BelongToMeshGroup();
798       virtual void SetMesh( const SMDS_Mesh* theMesh );
799       virtual bool IsSatisfy( long theElementId );
800       virtual SMDSAbs_ElementType GetType() const;
801
802       void SetGroup( SMESHDS_GroupBase* g );
803       void SetStoreName( const std::string& sn );
804       const SMESHDS_GroupBase* GetGroup() const { return myGroup; }
805
806     private:
807       SMESHDS_GroupBase* myGroup;
808       std::string        myStoreName;
809     };
810     typedef boost::shared_ptr<BelongToMeshGroup> BelongToMeshGroupPtr;
811
812     /*
813       Class       : ElementsOnSurface
814       Description : Predicate elements that lying on indicated surface
815                     (plane or cylinder)
816     */
817     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
818     public:
819       ElementsOnSurface();
820       ~ElementsOnSurface();
821       virtual void SetMesh( const SMDS_Mesh* theMesh );
822       virtual bool IsSatisfy( long theElementId );
823       virtual      SMDSAbs_ElementType GetType() const;
824
825       void    SetTolerance( const double theToler );
826       double  GetTolerance() const;
827       void    SetSurface( const TopoDS_Shape& theShape,
828                           const SMDSAbs_ElementType theType );
829       void    SetUseBoundaries( bool theUse );
830       bool    GetUseBoundaries() const { return myUseBoundaries; }
831
832     private:
833       void    process();
834       void    process( const SMDS_MeshElement* theElem  );
835       bool    isOnSurface( const SMDS_MeshNode* theNode );
836
837     private:
838       TMeshModifTracer      myMeshModifTracer;
839       TColStd_MapOfInteger  myIds;
840       SMDSAbs_ElementType   myType;
841       TopoDS_Face           mySurf;
842       double                myToler;
843       bool                  myUseBoundaries;
844       GeomAPI_ProjectPointOnSurf myProjector;
845     };
846
847     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
848
849
850     /*
851       Class       : ElementsOnShape
852       Description : Predicate elements that lying on indicated shape
853                     (1D, 2D or 3D)
854     */
855     class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
856     {
857     public:
858       ElementsOnShape();
859       ~ElementsOnShape();
860
861       virtual void SetMesh (const SMDS_Mesh* theMesh);
862       virtual bool IsSatisfy (long theElementId);
863       virtual SMDSAbs_ElementType GetType() const;
864
865       void    SetTolerance (const double theToler);
866       double  GetTolerance() const;
867       void    SetAllNodes (bool theAllNodes);
868       bool    GetAllNodes() const { return myAllNodesFlag; }
869       void    SetShape (const TopoDS_Shape& theShape,
870                         const SMDSAbs_ElementType theType);
871
872     private:
873
874       struct Classifier;
875       struct OctreeClassifier;
876
877       void clearClassifiers();
878       bool getNodeIsOut( const SMDS_MeshNode* n, bool& isOut );
879       void setNodeIsOut( const SMDS_MeshNode* n, bool  isOut );
880
881       std::vector< Classifier* >  myClassifiers, myWorkClassifiers;
882       OctreeClassifier*           myOctree;
883       SMDSAbs_ElementType         myType;
884       TopoDS_Shape                myShape;
885       double                      myToler;
886       bool                        myAllNodesFlag;
887
888       TMeshModifTracer            myMeshModifTracer;
889       std::vector<bool>           myNodeIsChecked;
890       std::vector<bool>           myNodeIsOut;
891     };
892
893     typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
894
895
896     /*
897       Class       : BelongToGeom
898       Description : Predicate for verifying whether entiy belong to
899       specified geometrical support
900     */
901     class SMESHCONTROLS_EXPORT BelongToGeom: public virtual Predicate
902     {
903     public:
904       BelongToGeom();
905
906       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
907       virtual void                    SetGeom( const TopoDS_Shape& theShape );
908
909       virtual bool                    IsSatisfy( long theElementId );
910
911       virtual void                    SetType( SMDSAbs_ElementType theType );
912       virtual                         SMDSAbs_ElementType GetType() const;
913
914       TopoDS_Shape                    GetShape();
915       const SMESHDS_Mesh*             GetMeshDS() const;
916
917       void                            SetTolerance( double );
918       double                          GetTolerance();
919
920     private:
921       virtual void                    init();
922
923       TopoDS_Shape                    myShape;
924       const SMESHDS_Mesh*             myMeshDS;
925       SMDSAbs_ElementType             myType;
926       bool                            myIsSubshape;
927       double                          myTolerance;          // only if myIsSubshape == false
928       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
929     };
930     typedef boost::shared_ptr<BelongToGeom> BelongToGeomPtr;
931
932     /*
933       Class       : LyingOnGeom
934       Description : Predicate for verifying whether entiy lying or partially lying on
935       specified geometrical support
936     */
937     class SMESHCONTROLS_EXPORT LyingOnGeom: public virtual Predicate
938     {
939     public:
940       LyingOnGeom();
941       
942       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
943       virtual void                    SetGeom( const TopoDS_Shape& theShape );
944       
945       virtual bool                    IsSatisfy( long theElementId );
946       
947       virtual void                    SetType( SMDSAbs_ElementType theType );
948       virtual                         SMDSAbs_ElementType GetType() const;
949       
950       TopoDS_Shape                    GetShape();
951       const SMESHDS_Mesh*             GetMeshDS() const;
952
953       void                            SetTolerance( double );
954       double                          GetTolerance();
955       
956       virtual bool                    Contains( const SMESHDS_Mesh*     theMeshDS,
957                                                 const TopoDS_Shape&     theShape,
958                                                 const SMDS_MeshElement* theElem,
959                                                 TopAbs_ShapeEnum        theFindShapeEnum,
960                                                 TopAbs_ShapeEnum        theAvoidShapeEnum = TopAbs_SHAPE );
961     private:
962       virtual void                    init();
963
964       TopoDS_Shape                    myShape;
965       TColStd_MapOfInteger            mySubShapesIDs;
966       const SMESHDS_Mesh*             myMeshDS;
967       SMDSAbs_ElementType             myType;
968       bool                            myIsSubshape;
969       double                          myTolerance;          // only if myIsSubshape == false
970       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
971     };
972     typedef boost::shared_ptr<LyingOnGeom> LyingOnGeomPtr;
973
974     /*
975       Class       : FreeFaces
976       Description : Predicate for free faces
977     */
978     class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
979     public:
980       FreeFaces();
981       virtual void SetMesh( const SMDS_Mesh* theMesh );
982       virtual bool IsSatisfy( long theElementId );
983       virtual SMDSAbs_ElementType GetType() const;
984
985     private:
986       const SMDS_Mesh* myMesh;
987     };
988
989     /*
990       Class       : LinearOrQuadratic
991       Description : Predicate for free faces
992     */
993     class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
994     public:
995       LinearOrQuadratic();
996       virtual void        SetMesh( const SMDS_Mesh* theMesh );
997       virtual bool        IsSatisfy( long theElementId );
998       void                SetType( SMDSAbs_ElementType theType );
999       virtual SMDSAbs_ElementType GetType() const;
1000
1001     private:
1002       const SMDS_Mesh*    myMesh;
1003       SMDSAbs_ElementType myType;
1004     };
1005     typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
1006
1007     /*
1008       Class       : GroupColor
1009       Description : Functor for check color of group to whic mesh element belongs to
1010     */
1011     class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
1012     public:
1013       GroupColor();
1014       virtual void        SetMesh( const SMDS_Mesh* theMesh );
1015       virtual bool        IsSatisfy( long theElementId );
1016       void                SetType( SMDSAbs_ElementType theType );
1017       virtual             SMDSAbs_ElementType GetType() const;
1018       void                SetColorStr( const TCollection_AsciiString& );
1019       void                GetColorStr( TCollection_AsciiString& ) const;
1020       
1021     private:
1022       typedef std::set< long > TIDs;
1023
1024       Quantity_Color      myColor;
1025       SMDSAbs_ElementType myType;
1026       TIDs                myIDs;
1027     };
1028     typedef boost::shared_ptr<GroupColor> GroupColorPtr;
1029
1030     /*
1031       Class       : ElemGeomType
1032       Description : Predicate to check element geometry type
1033     */
1034     class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
1035     public:
1036       ElemGeomType();
1037       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1038       virtual bool         IsSatisfy( long theElementId );
1039       void                 SetType( SMDSAbs_ElementType theType );
1040       virtual              SMDSAbs_ElementType GetType() const;
1041       void                 SetGeomType( SMDSAbs_GeometryType theType );
1042       SMDSAbs_GeometryType GetGeomType() const;
1043
1044     private:
1045       const SMDS_Mesh*     myMesh;
1046       SMDSAbs_ElementType  myType;
1047       SMDSAbs_GeometryType myGeomType;
1048     };
1049     typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
1050
1051     /*
1052       Class       : CoplanarFaces
1053       Description : Predicate to check angle between faces
1054     */
1055     class SMESHCONTROLS_EXPORT CoplanarFaces: public virtual Predicate
1056     {
1057     public:
1058       CoplanarFaces();
1059       void                 SetFace( long theID )                   { myFaceID = theID; }
1060       long                 GetFace() const                         { return myFaceID; }
1061       void                 SetTolerance (const double theToler)    { myToler = theToler; }
1062       double               GetTolerance () const                   { return myToler; }
1063       virtual              SMDSAbs_ElementType GetType() const     { return SMDSAbs_Face; }
1064
1065       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1066       virtual bool         IsSatisfy( long theElementId );
1067
1068     private:
1069       TMeshModifTracer     myMeshModifTracer;
1070       long                 myFaceID;
1071       double               myToler;
1072       TColStd_MapOfInteger myCoplanarIDs;
1073     };
1074     typedef boost::shared_ptr<CoplanarFaces> CoplanarFacesPtr;
1075
1076     /*
1077       Class       : ConnectedElements
1078       Description : Predicate to get elements of one domain
1079     */
1080     class SMESHCONTROLS_EXPORT ConnectedElements: public virtual Predicate
1081     {
1082     public:
1083       ConnectedElements();
1084       void                 SetNode( int nodeID );
1085       void                 SetPoint( double x, double y, double z );
1086       int                  GetNode() const;
1087       std::vector<double>  GetPoint() const;
1088
1089       void                 SetType( SMDSAbs_ElementType theType );
1090       virtual              SMDSAbs_ElementType GetType() const;
1091
1092       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1093       virtual bool         IsSatisfy( long theElementId );
1094
1095       //const std::set<long>& GetDomainIDs() const { return myOkIDs; }
1096
1097     private:
1098       int                 myNodeID;
1099       std::vector<double> myXYZ;
1100       SMDSAbs_ElementType myType;
1101       TMeshModifTracer    myMeshModifTracer;
1102
1103       void                clearOkIDs();
1104       bool                myOkIDsReady;
1105       std::set< int >     myOkIDs; // empty means that there is one domain
1106     };
1107     typedef boost::shared_ptr<ConnectedElements> ConnectedElementsPtr;
1108
1109     /*
1110       FILTER
1111     */
1112     class SMESHCONTROLS_EXPORT Filter {
1113     public:
1114       Filter();
1115       virtual ~Filter();
1116       virtual void SetPredicate(PredicatePtr thePred);
1117
1118       typedef std::vector<long> TIdSequence;
1119
1120       virtual
1121       void
1122       GetElementsId( const SMDS_Mesh* theMesh,
1123                      TIdSequence& theSequence );
1124
1125       static
1126       void
1127       GetElementsId( const SMDS_Mesh* theMesh,
1128                      PredicatePtr thePredicate,
1129                      TIdSequence& theSequence );
1130       
1131     protected:
1132       PredicatePtr myPredicate;
1133     };
1134   };
1135 };
1136
1137
1138 #endif