Salome HOME
Merge branch 'V9_12_BR'
[modules/smesh.git] / src / Controls / SMESH_ControlsDef.hxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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       Class       : ScaledJacobian
410       Description : Functor returning the ScaledJacobian as implemeted in VTK for volumetric elements
411     */
412     class SMESHCONTROLS_EXPORT ScaledJacobian: public virtual NumericalFunctor{
413     public:
414       virtual double GetValue( long theNodeId );
415       virtual double GetBadRate( double Value, int nbNodes ) const;
416       virtual SMDSAbs_ElementType GetType() const;
417     };
418
419
420     /*
421       PREDICATES
422     */
423     /*
424       Class       : CoincidentNodes
425       Description : Predicate of Coincident Nodes
426       Note        : This class is suitable only for visualization of Coincident Nodes
427     */
428     class SMESHCONTROLS_EXPORT CoincidentNodes: public Predicate {
429     public:
430       CoincidentNodes();
431       //virtual Predicate* clone() const { return new CoincidentNodes( *this ); }
432       virtual void SetMesh( const SMDS_Mesh* theMesh );
433       virtual bool IsSatisfy( long theElementId );
434       virtual SMDSAbs_ElementType GetType() const;
435
436       void SetTolerance (const double theToler);
437       double GetTolerance () const { return myToler; }
438
439     private:
440       double           myToler;
441       TIDsMap          myCoincidentIDs;
442       TMeshModifTracer myMeshModifTracer;
443     };
444     typedef boost::shared_ptr<CoincidentNodes> CoincidentNodesPtr;
445    
446     /*
447       Class       : CoincidentElements
448       Description : Predicate of Coincident Elements
449       Note        : This class is suitable only for visualization of Coincident Elements
450     */
451     class SMESHCONTROLS_EXPORT CoincidentElements: public Predicate {
452     public:
453       CoincidentElements();
454       virtual void SetMesh( const SMDS_Mesh* theMesh );
455       virtual bool IsSatisfy( long theElementId );
456
457     private:
458       const SMDS_Mesh* myMesh;
459     };
460     class SMESHCONTROLS_EXPORT CoincidentElements1D: public CoincidentElements {
461     public:
462       virtual SMDSAbs_ElementType GetType() const;
463       //virtual Predicate* clone() const { return new CoincidentElements1D( *this ); }
464     };
465     class SMESHCONTROLS_EXPORT CoincidentElements2D: public CoincidentElements {
466     public:
467       virtual SMDSAbs_ElementType GetType() const;
468       //virtual Predicate* clone() const { return new CoincidentElements2D( *this ); }
469     };
470     class SMESHCONTROLS_EXPORT CoincidentElements3D: public CoincidentElements {
471     public:
472       virtual SMDSAbs_ElementType GetType() const;
473       //virtual Predicate* clone() const { return new CoincidentElements3D( *this ); }
474     };
475
476     /*
477       Class       : FreeBorders
478       Description : Predicate for free borders
479     */
480     class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
481     public:
482       FreeBorders();
483       //virtual Predicate* clone() const { return new FreeBorders( *this ); }
484       virtual void SetMesh( const SMDS_Mesh* theMesh );
485       virtual bool IsSatisfy( long theElementId );
486       virtual SMDSAbs_ElementType GetType() const;
487
488     protected:
489       const SMDS_Mesh* myMesh;
490     };
491    
492
493     /*
494       Class       : BadOrientedVolume
495       Description : Predicate bad oriented volumes
496     */
497     class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
498     public:
499       BadOrientedVolume();
500       //virtual Predicate* clone() const { return new BadOrientedVolume( *this ); }
501       virtual void SetMesh( const SMDS_Mesh* theMesh );
502       virtual bool IsSatisfy( long theElementId );
503       virtual SMDSAbs_ElementType GetType() const;
504
505     protected:
506       const SMDS_Mesh* myMesh;
507     };
508
509     /*
510       Class       : ElemEntityType
511       Description : Functor for calculating entity type
512     */
513     class SMESHCONTROLS_EXPORT ElemEntityType: public virtual Predicate{
514       public:
515       ElemEntityType();
516       //virtual Predicate*   clone() const { return new ElemEntityType( *this ); }
517       virtual void         SetMesh( const SMDS_Mesh* theMesh );
518       virtual bool         IsSatisfy( long theElementId );
519       void                 SetType( SMDSAbs_ElementType theType );
520       virtual              SMDSAbs_ElementType GetType() const;
521       void                 SetElemEntityType( SMDSAbs_EntityType theEntityType );
522       SMDSAbs_EntityType   GetElemEntityType() const;
523
524     private:
525       const SMDS_Mesh*     myMesh;
526       SMDSAbs_ElementType  myType;
527       SMDSAbs_EntityType   myEntityType;
528     };
529     typedef boost::shared_ptr<ElemEntityType> ElemEntityTypePtr;
530
531
532     /*
533       BareBorderVolume
534     */
535     class SMESHCONTROLS_EXPORT BareBorderVolume: public Predicate
536     {
537     public:
538       BareBorderVolume():myMesh(0) {}
539       virtual Predicate* clone() const { return new BareBorderVolume( *this ); }
540       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
541       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
542       virtual bool IsSatisfy( long theElementId );
543     protected:
544       const SMDS_Mesh* myMesh;
545     };
546     typedef boost::shared_ptr<BareBorderVolume> BareBorderVolumePtr;
547
548     /*
549       BareBorderFace
550     */
551     class SMESHCONTROLS_EXPORT BareBorderFace: public Predicate
552     {
553     public:
554       BareBorderFace():myMesh(0) {}
555       //virtual Predicate* clone() const { return new BareBorderFace( *this ); }
556       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
557       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
558       virtual bool IsSatisfy( long theElementId );
559     protected:
560       const SMDS_Mesh* myMesh;
561       std::vector< const SMDS_MeshNode* > myLinkNodes;
562     };
563     typedef boost::shared_ptr<BareBorderFace> BareBorderFacePtr;
564
565     /*
566       OverConstrainedVolume
567     */
568     class SMESHCONTROLS_EXPORT OverConstrainedVolume: public Predicate
569     {
570     public:
571       OverConstrainedVolume():myMesh(0) {}
572       virtual Predicate* clone() const { return new OverConstrainedVolume( *this ); }
573       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
574       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Volume; }
575       virtual bool IsSatisfy( long theElementId );
576     protected:
577       const SMDS_Mesh* myMesh;
578     };
579     typedef boost::shared_ptr<OverConstrainedVolume> OverConstrainedVolumePtr;
580
581     /*
582       OverConstrainedFace
583     */
584     class SMESHCONTROLS_EXPORT OverConstrainedFace: public Predicate
585     {
586     public:
587       OverConstrainedFace():myMesh(0) {}
588       //virtual Predicate* clone() const { return new OverConstrainedFace( *this ); }
589       virtual void SetMesh( const SMDS_Mesh* theMesh ) { myMesh = theMesh; }
590       virtual SMDSAbs_ElementType GetType() const      { return SMDSAbs_Face; }
591       virtual bool IsSatisfy( long theElementId );
592     protected:
593       const SMDS_Mesh* myMesh;
594     };
595     typedef boost::shared_ptr<OverConstrainedFace> OverConstrainedFacePtr;
596
597     /*
598       Class       : FreeEdges
599       Description : Predicate for free Edges
600     */
601     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
602     public:
603       FreeEdges();
604       //virtual Predicate* clone() const { return new FreeEdges( *this ); }
605       virtual void SetMesh( const SMDS_Mesh* theMesh );
606       virtual bool IsSatisfy( long theElementId );
607       virtual SMDSAbs_ElementType GetType() const;
608       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const ::smIdType theFaceId  );
609       typedef long TElemId;
610       struct Border{
611         TElemId myElemId;
612         TElemId myPntId[2];
613         Border(long theElemId, long thePntId1, long thePntId2);
614         bool operator<(const Border& x) const;
615       };
616       typedef std::set<Border> TBorders;
617       void GetBoreders(TBorders& theBorders);
618
619     protected:
620       const SMDS_Mesh* myMesh;
621     };
622     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
623     
624     
625     /*
626       Class       : FreeNodes
627       Description : Predicate for free nodes
628     */
629     class SMESHCONTROLS_EXPORT FreeNodes: public virtual Predicate{
630     public:
631       FreeNodes();
632       //virtual Predicate* clone() const { return new FreeNodes( *this ); }
633       virtual void SetMesh( const SMDS_Mesh* theMesh );
634       virtual bool IsSatisfy( long theNodeId );
635       virtual SMDSAbs_ElementType GetType() const;
636
637     protected:
638       const SMDS_Mesh* myMesh;
639     };
640     
641
642     /*
643       Class       : RangeOfIds
644       Description : Predicate for Range of Ids.
645                     Range may be specified with two ways.
646                     1. Using AddToRange method
647                     2. With SetRangeStr method. Parameter of this method is a string
648                        like as "1,2,3,50-60,63,67,70-"
649     */
650     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
651     {
652     public:
653       RangeOfIds();
654       //virtual Predicate*            clone() const { return new RangeOfIds( *this ); }
655       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
656       virtual bool                  IsSatisfy( long theNodeId );
657       virtual SMDSAbs_ElementType   GetType() const;
658       virtual void                  SetType( SMDSAbs_ElementType theType );
659
660       bool                          AddToRange( long theEntityId );
661       void                          GetRangeStr( TCollection_AsciiString& );
662       bool                          SetRangeStr( const TCollection_AsciiString& );
663
664     protected:
665       const SMDS_Mesh*              myMesh;
666
667       std::vector< ::smIdType >       myMin;
668       std::vector< ::smIdType >       myMax;
669       TIDsMap                       myIds;
670
671       SMDSAbs_ElementType           myType;
672     };
673     
674     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
675    
676     
677     /*
678       Class       : Comparator
679       Description : Base class for comparators
680     */
681     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
682     public:
683       Comparator();
684       virtual ~Comparator();
685       virtual void SetMesh( const SMDS_Mesh* theMesh );
686       virtual void SetMargin(double theValue);
687       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
688       virtual bool IsSatisfy( long theElementId ) = 0;
689       virtual SMDSAbs_ElementType GetType() const;
690       double  GetMargin();
691   
692     protected:
693       double myMargin;
694       NumericalFunctorPtr myFunctor;
695     };
696     typedef boost::shared_ptr<Comparator> ComparatorPtr;
697   
698   
699     /*
700       Class       : LessThan
701       Description : Comparator "<"
702     */
703     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
704     public:
705       virtual bool IsSatisfy( long theElementId );
706       //virtual Predicate* clone() const { return new LessThan( *this ); }
707     };
708   
709   
710     /*
711       Class       : MoreThan
712       Description : Comparator ">"
713     */
714     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
715     public:
716       virtual bool IsSatisfy( long theElementId );
717       //virtual Predicate* clone() const { return new MoreThan( *this ); }
718     };
719   
720   
721     /*
722       Class       : EqualTo
723       Description : Comparator "="
724     */
725     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
726     public:
727       EqualTo();
728       //virtual Predicate* clone() const { return new EqualTo( *this ); }
729       virtual bool IsSatisfy( long theElementId );
730       virtual void SetTolerance( double theTol );
731       virtual double GetTolerance();
732   
733     private:
734       double myToler;
735     };
736     typedef boost::shared_ptr<EqualTo> EqualToPtr;
737   
738     
739     /*
740       Class       : LogicalNOT
741       Description : Logical NOT predicate
742     */
743     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
744     public:
745       LogicalNOT();
746       //virtual Predicate* clone() const { return new LogicalNOT( *this ); }
747       virtual ~LogicalNOT();
748       virtual bool IsSatisfy( long theElementId );
749       virtual void SetMesh( const SMDS_Mesh* theMesh );
750       virtual void SetPredicate(PredicatePtr thePred);
751       virtual SMDSAbs_ElementType GetType() const;
752   
753     private:
754       PredicatePtr myPredicate;
755     };
756     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
757     
758   
759     /*
760       Class       : LogicalBinary
761       Description : Base class for binary logical predicate
762     */
763     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
764     public:
765       LogicalBinary();
766       virtual ~LogicalBinary();
767       virtual void SetMesh( const SMDS_Mesh* theMesh );
768       virtual void SetPredicate1(PredicatePtr thePred);
769       virtual void SetPredicate2(PredicatePtr thePred);
770       virtual SMDSAbs_ElementType GetType() const;
771   
772     protected:
773       PredicatePtr myPredicate1;
774       PredicatePtr myPredicate2;
775     };
776     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
777   
778   
779     /*
780       Class       : LogicalAND
781       Description : Logical AND
782     */
783     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
784     public:
785       virtual bool IsSatisfy( long theElementId );
786       //virtual Predicate* clone() const { return new LogicalAND( *this ); }
787     };
788   
789   
790     /*
791       Class       : LogicalOR
792       Description : Logical OR
793     */
794     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
795     public:
796       virtual bool IsSatisfy( long theElementId );
797       //virtual Predicate* clone() const { return new LogicalOR( *this ); }
798     };
799   
800   
801     /*
802       Class       : ManifoldPart
803       Description : Predicate for manifold part of mesh
804     */
805     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
806     public:
807
808       /* internal class for algorithm uses */
809       class Link
810       {
811       public:
812         Link( SMDS_MeshNode* theNode1,
813               SMDS_MeshNode* theNode2 );
814         ~Link();
815         
816         bool IsEqual( const ManifoldPart::Link& theLink ) const;
817         bool operator<(const ManifoldPart::Link& x) const;
818         
819         SMDS_MeshNode* myNode1;
820         SMDS_MeshNode* myNode2;
821       };
822
823       bool IsEqual( const ManifoldPart::Link& theLink1,
824                     const ManifoldPart::Link& theLink2 );
825       
826       typedef std::set<ManifoldPart::Link>                TMapOfLink;
827       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
828       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
829       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
830       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
831       
832       ManifoldPart();
833       ~ManifoldPart();
834       //virtual Predicate* clone() const { return new ManifoldPart( *this ); }
835       virtual void SetMesh( const SMDS_Mesh* theMesh );
836       // invoke when all parameters already set
837       virtual bool IsSatisfy( long theElementId );
838       virtual      SMDSAbs_ElementType GetType() const;
839
840       void    SetAngleTolerance( const double theAngToler );
841       double  GetAngleTolerance() const;
842       void    SetIsOnlyManifold( const bool theIsOnly );
843       void    SetStartElem( const long  theStartElemId );
844
845     private:
846       bool    process();
847       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
848                              SMDS_MeshFace*            theStartFace,
849                              TMapOfLink&               theNonManifold,
850                              TIDsMap&                  theResFaces );
851       bool    isInPlane( const SMDS_MeshFace* theFace1,
852                           const SMDS_MeshFace* theFace2 );
853       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
854                               TVectorOfLink&         theSeqOfBoundary,
855                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
856                               TMapOfLink&            theNonManifold,
857                               SMDS_MeshFace*         theNextFace ) const;
858
859       void     getFacesByLink( const Link& theLink,
860                                TVectorOfFacePtr& theFaces ) const;
861
862     private:
863       const SMDS_Mesh*      myMesh;
864       TIDsMap               myMapIds;
865       TIDsMap               myMapBadGeomIds;
866       TVectorOfFacePtr      myAllFacePtr;
867       TDataMapFacePtrInt    myAllFacePtrIntDMap;
868       double                myAngToler;
869       bool                  myIsOnlyManifold;
870       long                  myStartElemId;
871
872     };
873     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
874
875     /*
876       Class       : BelongToMeshGroup
877       Description : Verify whether a mesh element is included into a mesh group
878     */
879     class SMESHCONTROLS_EXPORT BelongToMeshGroup : public virtual Predicate
880     {
881     public:
882       BelongToMeshGroup();
883       //virtual Predicate* clone() const { return new BelongToMeshGroup( *this ); }
884       virtual void SetMesh( const SMDS_Mesh* theMesh );
885       virtual bool IsSatisfy( long theElementId );
886       virtual SMDSAbs_ElementType GetType() const;
887
888       void SetGroup( SMESHDS_GroupBase* g );
889       void SetStoreName( const std::string& sn );
890       const SMESHDS_GroupBase* GetGroup() const { return myGroup; }
891
892     private:
893       SMESHDS_GroupBase* myGroup;
894       std::string        myStoreName;
895     };
896     typedef boost::shared_ptr<BelongToMeshGroup> BelongToMeshGroupPtr;
897
898     /*
899       Class       : ElementsOnSurface
900       Description : Predicate elements that lying on indicated surface
901                     (plane or cylinder)
902     */
903     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
904     public:
905       ElementsOnSurface();
906       ~ElementsOnSurface();
907       //virtual Predicate* clone() const { return new ElementsOnSurface( *this ); }
908       virtual void SetMesh( const SMDS_Mesh* theMesh );
909       virtual bool IsSatisfy( long theElementId );
910       virtual      SMDSAbs_ElementType GetType() const;
911
912       void    SetTolerance( const double theToler );
913       double  GetTolerance() const;
914       void    SetSurface( const TopoDS_Shape& theShape,
915                           const SMDSAbs_ElementType theType );
916       void    SetUseBoundaries( bool theUse );
917       bool    GetUseBoundaries() const { return myUseBoundaries; }
918
919     private:
920       void    process();
921       void    process( const SMDS_MeshElement* theElem  );
922       bool    isOnSurface( const SMDS_MeshNode* theNode );
923
924     private:
925       TMeshModifTracer      myMeshModifTracer;
926       TIDsMap               myIds;
927       SMDSAbs_ElementType   myType;
928       TopoDS_Face           mySurf;
929       double                myToler;
930       bool                  myUseBoundaries;
931       GeomAPI_ProjectPointOnSurf myProjector;
932     };
933
934     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
935
936
937     /*
938       Class       : ElementsOnShape
939       Description : Predicate elements that lying on indicated shape
940                     (1D, 2D or 3D)
941     */
942     class SMESHCONTROLS_EXPORT ElementsOnShape : public Predicate
943     {
944     public:
945       ElementsOnShape();
946       ~ElementsOnShape();
947
948       virtual Predicate* clone() const;
949       virtual void SetMesh (const SMDS_Mesh* theMesh);
950       virtual bool IsSatisfy (long theElementId);
951       virtual SMDSAbs_ElementType GetType() const;
952
953       void    SetTolerance (const double theToler);
954       double  GetTolerance() const;
955       void    SetAllNodes (bool theAllNodes);
956       bool    GetAllNodes() const { return myAllNodesFlag; }
957       void    SetShape (const TopoDS_Shape& theShape,
958                         const SMDSAbs_ElementType theType);
959       bool    IsSatisfy (const SMDS_MeshElement* elem);
960       bool    IsSatisfy (const SMDS_MeshNode* node, TopoDS_Shape* okShape=0);
961       void    GetParams( double & u, double & v ) const { u = myU; v = myV; }
962
963     private:
964
965       struct Classifier;
966       struct OctreeClassifier;
967
968       void clearClassifiers();
969       bool getNodeIsOut( const SMDS_MeshNode* n, bool& isOut );
970       void setNodeIsOut( const SMDS_MeshNode* n, bool  isOut );
971
972       std::vector< Classifier >  myClassifiers;
973       std::vector< Classifier* > myWorkClassifiers;
974       OctreeClassifier*          myOctree;
975       SMDSAbs_ElementType        myType;
976       TopoDS_Shape               myShape;
977       double                     myToler;
978       double                     myU, myV; // result of node projection on EDGE or FACE
979       bool                       myAllNodesFlag;
980
981       TMeshModifTracer           myMeshModifTracer;
982       std::vector<bool>          myNodeIsChecked;
983       std::vector<bool>          myNodeIsOut;
984     };
985
986     typedef boost::shared_ptr<ElementsOnShape> ElementsOnShapePtr;
987
988
989     /*
990       Class       : BelongToGeom
991       Description : Predicate for verifying whether entiy belong to
992       specified geometrical support
993     */
994     class SMESHCONTROLS_EXPORT BelongToGeom: public virtual Predicate
995     {
996     public:
997       BelongToGeom();
998       virtual Predicate* clone() const;
999
1000       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
1001       virtual void                    SetGeom( const TopoDS_Shape& theShape );
1002
1003       virtual bool                    IsSatisfy( long theElementId );
1004
1005       virtual void                    SetType( SMDSAbs_ElementType theType );
1006       virtual                         SMDSAbs_ElementType GetType() const;
1007
1008       TopoDS_Shape                    GetShape();
1009       const SMESHDS_Mesh*             GetMeshDS() const;
1010
1011       void                            SetTolerance( double );
1012       double                          GetTolerance();
1013
1014     private:
1015       virtual void                    init();
1016
1017       TopoDS_Shape                    myShape;
1018       TColStd_MapOfInteger            mySubShapesIDs;
1019       const SMESHDS_Mesh*             myMeshDS;
1020       SMDSAbs_ElementType             myType;
1021       bool                            myIsSubshape;
1022       double                          myTolerance;          // only if myIsSubshape == false
1023       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
1024     };
1025     typedef boost::shared_ptr<BelongToGeom> BelongToGeomPtr;
1026
1027     /*
1028       Class       : LyingOnGeom
1029       Description : Predicate for verifying whether entiy lying or partially lying on
1030       specified geometrical support
1031     */
1032     class SMESHCONTROLS_EXPORT LyingOnGeom: public virtual Predicate
1033     {
1034     public:
1035       LyingOnGeom();
1036       virtual Predicate* clone() const;
1037       
1038       virtual void                    SetMesh( const SMDS_Mesh* theMesh );
1039       virtual void                    SetGeom( const TopoDS_Shape& theShape );
1040       
1041       virtual bool                    IsSatisfy( long theElementId );
1042       
1043       virtual void                    SetType( SMDSAbs_ElementType theType );
1044       virtual                         SMDSAbs_ElementType GetType() const;
1045       
1046       TopoDS_Shape                    GetShape();
1047       const SMESHDS_Mesh*             GetMeshDS() const;
1048
1049       void                            SetTolerance( double );
1050       double                          GetTolerance();
1051       
1052    private:
1053       virtual void                    init();
1054
1055       TopoDS_Shape                    myShape;
1056       TColStd_MapOfInteger            mySubShapesIDs;
1057       const SMESHDS_Mesh*             myMeshDS;
1058       SMDSAbs_ElementType             myType;
1059       bool                            myIsSubshape;
1060       double                          myTolerance;          // only if myIsSubshape == false
1061       Controls::ElementsOnShapePtr    myElementsOnShapePtr; // only if myIsSubshape == false
1062     };
1063     typedef boost::shared_ptr<LyingOnGeom> LyingOnGeomPtr;
1064
1065     /*
1066       Class       : FreeFaces
1067       Description : Predicate for free faces
1068     */
1069     class SMESHCONTROLS_EXPORT FreeFaces: public virtual Predicate{
1070     public:
1071       FreeFaces();
1072       //virtual Predicate* clone() const { return new FreeFaces( *this ); }
1073       virtual void SetMesh( const SMDS_Mesh* theMesh );
1074       virtual bool IsSatisfy( long theElementId );
1075       virtual SMDSAbs_ElementType GetType() const;
1076
1077     private:
1078       const SMDS_Mesh* myMesh;
1079     };
1080
1081     /*
1082       Class       : LinearOrQuadratic
1083       Description : Predicate for free faces
1084     */
1085     class SMESHCONTROLS_EXPORT LinearOrQuadratic: public virtual Predicate{
1086     public:
1087       LinearOrQuadratic();
1088       //virtual Predicate*  clone() const { return new LinearOrQuadratic( *this ); }
1089       virtual void        SetMesh( const SMDS_Mesh* theMesh );
1090       virtual bool        IsSatisfy( long theElementId );
1091       void                SetType( SMDSAbs_ElementType theType );
1092       virtual SMDSAbs_ElementType GetType() const;
1093
1094     private:
1095       const SMDS_Mesh*    myMesh;
1096       SMDSAbs_ElementType myType;
1097     };
1098     typedef boost::shared_ptr<LinearOrQuadratic> LinearOrQuadraticPtr;
1099
1100     /*
1101       Class       : GroupColor
1102       Description : Functor for check color of group to which mesh element belongs to
1103     */
1104     class SMESHCONTROLS_EXPORT GroupColor: public virtual Predicate{
1105     public:
1106       GroupColor();
1107       //virtual Predicate*  clone() const { return new GroupColor( *this ); }
1108       virtual void        SetMesh( const SMDS_Mesh* theMesh );
1109       virtual bool        IsSatisfy( long theElementId );
1110       void                SetType( SMDSAbs_ElementType theType );
1111       virtual             SMDSAbs_ElementType GetType() const;
1112       void                SetColorStr( const TCollection_AsciiString& );
1113       void                GetColorStr( TCollection_AsciiString& ) const;
1114       
1115     private:
1116       typedef std::set< long > TIDs;
1117
1118       Quantity_Color      myColor;
1119       SMDSAbs_ElementType myType;
1120       TIDs                myIDs;
1121     };
1122     typedef boost::shared_ptr<GroupColor> GroupColorPtr;
1123
1124     /*
1125       Class       : ElemGeomType
1126       Description : Predicate to check element geometry type
1127     */
1128     class SMESHCONTROLS_EXPORT ElemGeomType: public virtual Predicate{
1129     public:
1130       ElemGeomType();
1131       //virtual Predicate*   clone() const { return new ElemGeomType( *this ); }
1132       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1133       virtual bool         IsSatisfy( long theElementId );
1134       void                 SetType( SMDSAbs_ElementType theType );
1135       virtual              SMDSAbs_ElementType GetType() const;
1136       void                 SetGeomType( SMDSAbs_GeometryType theType );
1137       SMDSAbs_GeometryType GetGeomType() const;
1138
1139     private:
1140       const SMDS_Mesh*     myMesh;
1141       SMDSAbs_ElementType  myType;
1142       SMDSAbs_GeometryType myGeomType;
1143     };
1144     typedef boost::shared_ptr<ElemGeomType> ElemGeomTypePtr;
1145
1146     /*
1147       Class       : CoplanarFaces
1148       Description : Predicate to check angle between faces
1149     */
1150     class SMESHCONTROLS_EXPORT CoplanarFaces: public virtual Predicate
1151     {
1152     public:
1153       CoplanarFaces();
1154       //virtual Predicate*   clone() const { return new CoplanarFaces( *this ); }
1155       void                 SetFace( long theID )                   { myFaceID = theID; }
1156       long                 GetFace() const                         { return myFaceID; }
1157       void                 SetTolerance (const double theToler)    { myToler = theToler; }
1158       double               GetTolerance () const                   { return myToler; }
1159       virtual              SMDSAbs_ElementType GetType() const     { return SMDSAbs_Face; }
1160
1161       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1162       virtual bool         IsSatisfy( long theElementId );
1163
1164     private:
1165       TMeshModifTracer     myMeshModifTracer;
1166       long                 myFaceID;
1167       double               myToler;
1168       TIDsMap              myCoplanarIDs;
1169     };
1170     typedef boost::shared_ptr<CoplanarFaces> CoplanarFacesPtr;
1171
1172     /*
1173       Class       : ConnectedElements
1174       Description : Predicate to get elements of one domain
1175     */
1176     class SMESHCONTROLS_EXPORT ConnectedElements: public virtual Predicate
1177     {
1178     public:
1179       ConnectedElements();
1180       //virtual Predicate*   clone() const { return new ConnectedElements( *this ); }
1181       void                 SetNode( ::smIdType nodeID );
1182       void                 SetPoint( double x, double y, double z );
1183       ::smIdType           GetNode() const;
1184       std::vector<double>  GetPoint() const;
1185
1186       void                 SetType( SMDSAbs_ElementType theType );
1187       virtual              SMDSAbs_ElementType GetType() const;
1188
1189       virtual void         SetMesh( const SMDS_Mesh* theMesh );
1190       virtual bool         IsSatisfy( long theElementId );
1191
1192       //const std::set<long>& GetDomainIDs() const { return myOkIDs; }
1193
1194     private:
1195       ::smIdType            myNodeID;
1196       std::vector<double>   myXYZ;
1197       SMDSAbs_ElementType   myType;
1198       TMeshModifTracer      myMeshModifTracer;
1199
1200       void                  clearOkIDs();
1201       bool                  myOkIDsReady;
1202       std::set<::smIdType>  myOkIDs; // empty means that there is one domain
1203     };
1204     typedef boost::shared_ptr<ConnectedElements> ConnectedElementsPtr;
1205
1206     /*
1207       FILTER
1208     */
1209     class SMESHCONTROLS_EXPORT Filter {
1210     public:
1211       Filter();
1212       virtual ~Filter();
1213       virtual void SetPredicate(PredicatePtr thePred);
1214
1215       typedef std::vector<long> TIdSequence;
1216
1217       virtual
1218       void
1219       GetElementsId( const SMDS_Mesh*     theMesh,
1220                      TIdSequence&         theSequence,
1221                      SMDS_ElemIteratorPtr theElements=0);
1222
1223       static
1224       void
1225       GetElementsId( const SMDS_Mesh*     theMesh,
1226                      PredicatePtr         thePredicate,
1227                      TIdSequence&         theSequence,
1228                      SMDS_ElemIteratorPtr theElements=0 );
1229       
1230     protected:
1231       PredicatePtr myPredicate;
1232     };
1233   }
1234 }
1235
1236
1237 #endif