Salome HOME
Fix MA construction
[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 <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       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       Class       : BelongToMeshGroup
784       Description : Verify whether a mesh element is included into a mesh group
785     */
786     class SMESHCONTROLS_EXPORT BelongToMeshGroup : public virtual Predicate
787     {
788     public:
789       BelongToMeshGroup();
790       virtual void SetMesh( const SMDS_Mesh* theMesh );
791       virtual bool IsSatisfy( long theElementId );
792       virtual SMDSAbs_ElementType GetType() const;
793
794       void SetGroup( SMESHDS_GroupBase* g );
795       void SetStoreName( const std::string& sn );
796       const SMESHDS_GroupBase* GetGroup() const { return myGroup; }
797
798     private:
799       SMESHDS_GroupBase* myGroup;
800       std::string        myStoreName;
801     };
802     typedef boost::shared_ptr<BelongToMeshGroup> BelongToMeshGroupPtr;
803
804     /*
805       Class       : ElementsOnSurface
806       Description : Predicate elements that lying on indicated surface
807                     (plane or cylinder)
808     */
809     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
810     public:
811       ElementsOnSurface();
812       ~ElementsOnSurface();
813       virtual void SetMesh( const SMDS_Mesh* theMesh );
814       virtual bool IsSatisfy( long theElementId );
815       virtual      SMDSAbs_ElementType GetType() const;
816
817       void    SetTolerance( const double theToler );
818       double  GetTolerance() const;
819       void    SetSurface( const TopoDS_Shape& theShape,
820                           const SMDSAbs_ElementType theType );
821       void    SetUseBoundaries( bool theUse );
822       bool    GetUseBoundaries() const { return myUseBoundaries; }
823
824     private:
825       void    process();
826       void    process( const SMDS_MeshElement* theElem  );
827       bool    isOnSurface( const SMDS_MeshNode* theNode );
828
829     private:
830       TMeshModifTracer      myMeshModifTracer;
831       TColStd_MapOfInteger  myIds;
832       SMDSAbs_ElementType   myType;
833       TopoDS_Face           mySurf;
834       double                myToler;
835       bool                  myUseBoundaries;
836       GeomAPI_ProjectPointOnSurf myProjector;
837     };
838
839     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
840
841
842     /*
843       Class       : ElementsOnShape
844       Description : Predicate elements that lying on indicated shape
845                     (1D, 2D or 3D)
846     */
847     class SMESHCONTROLS_EXPORT ElementsOnShape : public virtual Predicate
848     {
849     public:
850       ElementsOnShape();
851       ~ElementsOnShape();
852
853       virtual void SetMesh (const SMDS_Mesh* theMesh);
854       virtual bool IsSatisfy (long theElementId);
855       virtual SMDSAbs_ElementType GetType() const;
856
857       void    SetTolerance (const double theToler);
858       double  GetTolerance() const;
859       void    SetAllNodes (bool theAllNodes);
860       bool    GetAllNodes() const { return myAllNodesFlag; }
861       void    SetShape (const TopoDS_Shape& theShape,
862                         const SMDSAbs_ElementType theType);
863
864     private:
865
866       struct TClassifier
867       {
868         TClassifier(const TopoDS_Shape& s, double tol) { Init(s,tol); }
869         void Init(const TopoDS_Shape& s, double tol);
870         bool IsOut(const gp_Pnt& p);
871         TopAbs_ShapeEnum ShapeType() const;
872       private:
873         bool isOutOfSolid (const gp_Pnt& p);
874         bool isOutOfBox   (const gp_Pnt& p);
875         bool isOutOfFace  (const gp_Pnt& p);
876         bool isOutOfEdge  (const gp_Pnt& p);
877         bool isOutOfVertex(const gp_Pnt& p);
878         bool isBox        (const TopoDS_Shape& s);
879
880         bool (TClassifier::* myIsOutFun)(const gp_Pnt& p);
881         BRepClass3d_SolidClassifier mySolidClfr;
882         Bnd_B3d                     myBox;
883         GeomAPI_ProjectPointOnSurf  myProjFace;
884         GeomAPI_ProjectPointOnCurve myProjEdge;
885         gp_Pnt                      myVertexXYZ;
886         TopoDS_Shape                myShape;
887         double                      myTol;
888       };
889       void clearClassifiers();
890       bool getNodeIsOut( const SMDS_MeshNode* n, bool& isOut );
891       void setNodeIsOut( const SMDS_MeshNode* n, bool  isOut );
892
893       std::vector< TClassifier* > myClassifiers;
894       SMDSAbs_ElementType         myType;
895       TopoDS_Shape                myShape;
896       double                      myToler;
897       bool                        myAllNodesFlag;
898
899       TMeshModifTracer            myMeshModifTracer;
900       std::vector<bool>           myNodeIsChecked;
901       std::vector<bool>           myNodeIsOut;
902     };
903
904     typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
905
906
907     /*
908       Class       : BelongToGeom
909       Description : Predicate for verifying whether entiy belong to
910       specified geometrical support
911     */
912     class SMESHCONTROLS_EXPORT BelongToGeom: public virtual Predicate
913     {
914     public:
915       BelongToGeom();
916
917       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
918       virtual void                    SetGeom( const TopoDS_Shape& theShape );
919
920       virtual bool                    IsSatisfy( long theElementId );
921
922       virtual void                    SetType( SMDSAbs_ElementType theType );
923       virtual                         SMDSAbs_ElementType GetType() const;
924
925       TopoDS_Shape                    GetShape();
926       const SMESHDS_Mesh*             GetMeshDS() const;
927
928       void                            SetTolerance( double );
929       double                          GetTolerance();
930
931     private:
932       virtual void                    init();
933
934       TopoDS_Shape                    myShape;
935       const SMESHDS_Mesh*             myMeshDS;
936       SMDSAbs_ElementType             myType;
937       bool                            myIsSubshape;
938       double                          myTolerance;          // only if myIsSubshape == false
939       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
940     };
941     typedef boost::shared_ptr<BelongToGeom> BelongToGeomPtr;
942
943     /*
944       Class       : LyingOnGeom
945       Description : Predicate for verifying whether entiy lying or partially lying on
946       specified geometrical support
947     */
948     class SMESHCONTROLS_EXPORT LyingOnGeom: public virtual Predicate
949     {
950     public:
951       LyingOnGeom();
952       
953       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
954       virtual void                    SetGeom( const TopoDS_Shape& theShape );
955       
956       virtual bool                    IsSatisfy( long theElementId );
957       
958       virtual void                    SetType( SMDSAbs_ElementType theType );
959       virtual                         SMDSAbs_ElementType GetType() const;
960       
961       TopoDS_Shape                    GetShape();
962       const SMESHDS_Mesh*             GetMeshDS() const;
963
964       void                            SetTolerance( double );
965       double                          GetTolerance();
966       
967       virtual bool                    Contains( const SMESHDS_Mesh*     theMeshDS,
968                                                 const TopoDS_Shape&     theShape,
969                                                 const SMDS_MeshElement* theElem,
970                                                 TopAbs_ShapeEnum        theFindShapeEnum,
971                                                 TopAbs_ShapeEnum        theAvoidShapeEnum = TopAbs_SHAPE );
972     private:
973       virtual void                    init();
974
975       TopoDS_Shape                    myShape;
976       TColStd_MapOfInteger            mySubShapesIDs;
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