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