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