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