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