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