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