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