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