Salome HOME
Fix bug 0020138: EDF SMESH : Impossible to create (n)D mesh after creating (n+1)D...
[modules/smesh.git] / src / Controls / SMESH_ControlsDef.hxx
1 //  Copyright (C) 2007-2008  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.
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 #ifndef _SMESH_CONTROLSDEF_HXX_
23 #define _SMESH_CONTROLSDEF_HXX_
24
25 #include <set>
26 #include <map>
27 #include <vector>
28 #include <boost/shared_ptr.hpp>
29 #include <gp_XYZ.hxx>
30 //#include <Geom_Surface.hxx>
31 #include <GeomAPI_ProjectPointOnSurf.hxx>
32 #include <TColStd_SequenceOfInteger.hxx>
33 #include <TColStd_MapOfInteger.hxx>
34 #include <TCollection_AsciiString.hxx>
35 #include <TopoDS_Face.hxx>
36
37 #include "SMDSAbs_ElementType.hxx"
38 #include "SMDS_MeshNode.hxx"
39
40 #include "SMESH_Controls.hxx"
41
42 #ifdef WNT
43  #if defined SMESHCONTROLS_EXPORTS
44   #define SMESHCONTROLS_EXPORT __declspec( dllexport )
45  #else
46   #define SMESHCONTROLS_EXPORT __declspec( dllimport )
47  #endif
48 #else
49  #define SMESHCONTROLS_EXPORT
50 #endif
51
52 class SMDS_MeshElement;
53 class SMDS_MeshFace;
54 class SMDS_MeshNode;
55 class SMDS_Mesh;
56
57 class SMESHDS_Mesh;
58 class SMESHDS_SubMesh;
59
60 class gp_Pnt;
61 //class TopoDS_Shape;
62
63 namespace SMESH{
64   namespace Controls{
65
66     class SMESHCONTROLS_EXPORT TSequenceOfXYZ: public std::vector<gp_XYZ>
67     {
68     public:
69       typedef std::vector<gp_XYZ> TSuperClass;
70       TSequenceOfXYZ()
71       {}
72
73       TSequenceOfXYZ(size_type n):
74         TSuperClass(n)
75       {}
76
77       TSequenceOfXYZ(size_type n, const value_type& t):
78         TSuperClass(n,t)
79       {}
80
81       TSequenceOfXYZ(const TSequenceOfXYZ& theSequenceOfXYZ):
82         TSuperClass(theSequenceOfXYZ)
83       {}
84
85       template <class InputIterator>
86       TSequenceOfXYZ(InputIterator theBegin, InputIterator theEnd):
87         TSuperClass(theBegin,theEnd)
88       {}
89
90       TSequenceOfXYZ& operator=(const TSequenceOfXYZ& theSequenceOfXYZ){
91         TSuperClass::operator=(theSequenceOfXYZ);
92         return *this;
93       }
94
95       reference operator()(size_type n){
96         return TSuperClass::operator[](n-1);
97       }
98
99       const_reference operator()(size_type n) const{
100         return TSuperClass::operator[](n-1);
101       }
102
103     private:
104       reference operator[](size_type n);
105
106       const_reference operator[](size_type n) const;
107     };
108
109     /*
110       Class       : Functor
111       Description : Root of all Functors
112     */
113     class SMESHCONTROLS_EXPORT Functor
114     {
115     public:
116       ~Functor(){}
117       virtual void SetMesh( const SMDS_Mesh* theMesh ) = 0;
118       virtual SMDSAbs_ElementType GetType() const = 0;
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       virtual SMDSAbs_ElementType GetType() const = 0;
132       virtual double GetBadRate( double Value, int nbNodes ) const = 0;
133       long  GetPrecision() const;
134       void  SetPrecision( const long thePrecision );
135       
136       bool GetPoints(const int theId, 
137                      TSequenceOfXYZ& theRes) const;
138       static bool GetPoints(const SMDS_MeshElement* theElem, 
139                             TSequenceOfXYZ& theRes);
140     protected:
141       const SMDS_Mesh* myMesh;
142       const SMDS_MeshElement* myCurrElement;
143       long       myPrecision;
144     };
145   
146   
147     /*
148       Class       : Volume
149       Description : Functor calculating volume of 3D mesh element
150     */
151     class SMESHCONTROLS_EXPORT Volume: public virtual NumericalFunctor{
152     public:
153       virtual double GetValue( long theElementId );
154       //virtual double GetValue( const TSequenceOfXYZ& thePoints );
155       virtual double GetBadRate( double Value, int nbNodes ) const;
156       virtual SMDSAbs_ElementType GetType() const;
157     };
158   
159   
160     /*
161       Class       : SMESH_MinimumAngle
162       Description : Functor for calculation of minimum angle
163     */
164     class SMESHCONTROLS_EXPORT MinimumAngle: public virtual NumericalFunctor{
165     public:
166       virtual double GetValue( const TSequenceOfXYZ& thePoints );
167       virtual double GetBadRate( double Value, int nbNodes ) const;
168       virtual SMDSAbs_ElementType GetType() const;
169     };
170   
171   
172     /*
173       Class       : AspectRatio
174       Description : Functor for calculating aspect ratio
175     */
176     class SMESHCONTROLS_EXPORT AspectRatio: public virtual NumericalFunctor{
177     public:
178       virtual double GetValue( const TSequenceOfXYZ& thePoints );
179       virtual double GetBadRate( double Value, int nbNodes ) const;
180       virtual SMDSAbs_ElementType GetType() const;
181     };
182   
183   
184     /*
185       Class       : AspectRatio3D
186       Description : Functor for calculating aspect ratio of 3D elems.
187     */
188     class SMESHCONTROLS_EXPORT AspectRatio3D: public virtual NumericalFunctor{
189     public:
190       virtual double GetValue( const TSequenceOfXYZ& thePoints );
191       virtual double GetBadRate( double Value, int nbNodes ) const;
192       virtual SMDSAbs_ElementType GetType() const;
193     };
194   
195   
196     /*
197       Class       : Warping
198       Description : Functor for calculating warping
199     */
200     class SMESHCONTROLS_EXPORT Warping: public virtual NumericalFunctor{
201     public:
202       virtual double GetValue( const TSequenceOfXYZ& thePoints );
203       virtual double GetBadRate( double Value, int nbNodes ) const;
204       virtual SMDSAbs_ElementType GetType() const;
205       
206     private:
207       double ComputeA( const gp_XYZ&, const gp_XYZ&, const gp_XYZ&, const gp_XYZ& ) const;
208     };
209   
210   
211     /*
212       Class       : Taper
213       Description : Functor for calculating taper
214     */
215     class SMESHCONTROLS_EXPORT Taper: public virtual NumericalFunctor{
216     public:
217       virtual double GetValue( const TSequenceOfXYZ& thePoints );
218       virtual double GetBadRate( double Value, int nbNodes ) const;
219       virtual SMDSAbs_ElementType GetType() const;
220     };
221     
222   
223     /*
224       Class       : Skew
225       Description : Functor for calculating skew in degrees
226     */
227     class SMESHCONTROLS_EXPORT Skew: public virtual NumericalFunctor{
228     public:
229       virtual double GetValue( const TSequenceOfXYZ& thePoints );
230       virtual double GetBadRate( double Value, int nbNodes ) const;
231       virtual SMDSAbs_ElementType GetType() const;
232     };
233   
234     
235     /*
236       Class       : Area
237       Description : Functor for calculating area
238     */
239     class SMESHCONTROLS_EXPORT Area: public virtual NumericalFunctor{
240     public:
241       virtual double GetValue( const TSequenceOfXYZ& thePoints );
242       virtual double GetBadRate( double Value, int nbNodes ) const;
243       virtual SMDSAbs_ElementType GetType() const;
244     };
245   
246   
247     /*
248       Class       : Length
249       Description : Functor for calculating length of edge
250     */
251     class SMESHCONTROLS_EXPORT Length: public virtual NumericalFunctor{
252     public:
253       virtual double GetValue( const TSequenceOfXYZ& thePoints );
254       virtual double GetBadRate( double Value, int nbNodes ) const;
255       virtual SMDSAbs_ElementType GetType() const;
256     };
257   
258     /*
259       Class       : Length2D
260       Description : Functor for calculating length of edge
261     */
262     class SMESHCONTROLS_EXPORT Length2D: public virtual NumericalFunctor{
263     public:
264       virtual double GetValue( long theElementId );
265       virtual double GetBadRate( double Value, int nbNodes ) const;
266       virtual SMDSAbs_ElementType GetType() const;
267       struct Value{
268         double myLength;
269         long myPntId[2];
270         Value(double theLength, long thePntId1, long thePntId2);
271         bool operator<(const Value& x) const;
272       };
273       typedef std::set<Value> TValues;
274       void GetValues(TValues& theValues);
275       
276     };
277     typedef boost::shared_ptr<Length2D> Length2DPtr;
278
279     /*
280       Class       : MultiConnection
281       Description : Functor for calculating number of faces conneted to the edge
282     */
283     class SMESHCONTROLS_EXPORT MultiConnection: public virtual NumericalFunctor{
284     public:
285       virtual double GetValue( long theElementId );
286       virtual double GetValue( const TSequenceOfXYZ& thePoints );
287       virtual double GetBadRate( double Value, int nbNodes ) const;
288       virtual SMDSAbs_ElementType GetType() const;
289     };
290     
291     /*
292       Class       : MultiConnection2D
293       Description : Functor for calculating number of faces conneted to the edge
294     */
295     class SMESHCONTROLS_EXPORT MultiConnection2D: public virtual NumericalFunctor{
296     public:
297       virtual double GetValue( long theElementId );
298       virtual double GetValue( const TSequenceOfXYZ& thePoints );
299       virtual double GetBadRate( double Value, int nbNodes ) const;
300       virtual SMDSAbs_ElementType GetType() const;
301       struct Value{
302         long myPntId[2];
303         Value(long thePntId1, long thePntId2);
304         bool operator<(const Value& x) const;
305       };
306       typedef std::map<Value,int> MValues;
307
308       void GetValues(MValues& theValues);
309     };
310     typedef boost::shared_ptr<MultiConnection2D> MultiConnection2DPtr;
311     /*
312       PREDICATES
313     */
314     /*
315       Class       : Predicate
316       Description : Base class for all predicates
317     */
318     class SMESHCONTROLS_EXPORT Predicate: public virtual Functor{
319     public:
320       virtual bool IsSatisfy( long theElementId ) = 0;
321       virtual SMDSAbs_ElementType GetType() const = 0;
322     };
323     
324   
325   
326     /*
327       Class       : FreeBorders
328       Description : Predicate for free borders
329     */
330     class SMESHCONTROLS_EXPORT FreeBorders: public virtual Predicate{
331     public:
332       FreeBorders();
333       virtual void SetMesh( const SMDS_Mesh* theMesh );
334       virtual bool IsSatisfy( long theElementId );
335       virtual SMDSAbs_ElementType GetType() const;
336             
337     protected:
338       const SMDS_Mesh* myMesh;
339     };
340    
341
342     /*
343       Class       : BadOrientedVolume
344       Description : Predicate bad oriented volumes
345     */
346     class SMESHCONTROLS_EXPORT BadOrientedVolume: public virtual Predicate{
347     public:
348       BadOrientedVolume();
349       virtual void SetMesh( const SMDS_Mesh* theMesh );
350       virtual bool IsSatisfy( long theElementId );
351       virtual SMDSAbs_ElementType GetType() const;
352             
353     protected:
354       const SMDS_Mesh* myMesh;
355     };
356    
357
358     /*
359       Class       : FreeEdges
360       Description : Predicate for free Edges
361     */
362     class SMESHCONTROLS_EXPORT FreeEdges: public virtual Predicate{
363     public:
364       FreeEdges();
365       virtual void SetMesh( const SMDS_Mesh* theMesh );
366       virtual bool IsSatisfy( long theElementId );
367       virtual SMDSAbs_ElementType GetType() const;
368       static bool IsFreeEdge( const SMDS_MeshNode** theNodes, const int theFaceId  );
369       typedef long TElemId;
370       struct Border{
371         TElemId myElemId;
372         TElemId myPntId[2];
373         Border(long theElemId, long thePntId1, long thePntId2);
374         bool operator<(const Border& x) const;
375       };
376       typedef std::set<Border> TBorders;
377       void GetBoreders(TBorders& theBorders);
378       
379     protected:
380       const SMDS_Mesh* myMesh;
381     };
382     typedef boost::shared_ptr<FreeEdges> FreeEdgesPtr;
383
384
385     /*
386       Class       : RangeOfIds
387       Description : Predicate for Range of Ids.
388                     Range may be specified with two ways.
389                     1. Using AddToRange method
390                     2. With SetRangeStr method. Parameter of this method is a string
391                        like as "1,2,3,50-60,63,67,70-"
392     */
393     class SMESHCONTROLS_EXPORT RangeOfIds: public virtual Predicate
394     {
395     public:
396                                     RangeOfIds();
397       virtual void                  SetMesh( const SMDS_Mesh* theMesh );
398       virtual bool                  IsSatisfy( long theNodeId );
399       virtual SMDSAbs_ElementType   GetType() const;
400       virtual void                  SetType( SMDSAbs_ElementType theType );
401
402       bool                          AddToRange( long theEntityId );
403       void                          GetRangeStr( TCollection_AsciiString& );
404       bool                          SetRangeStr( const TCollection_AsciiString& );
405
406     protected:
407       const SMDS_Mesh*              myMesh;
408
409       TColStd_SequenceOfInteger     myMin;
410       TColStd_SequenceOfInteger     myMax;
411       TColStd_MapOfInteger          myIds;
412
413       SMDSAbs_ElementType           myType;
414     };
415     
416     typedef boost::shared_ptr<RangeOfIds> RangeOfIdsPtr;
417    
418     
419     /*
420       Class       : Comparator
421       Description : Base class for comparators
422     */
423     class SMESHCONTROLS_EXPORT Comparator: public virtual Predicate{
424     public:
425       Comparator();
426       virtual ~Comparator();
427       virtual void SetMesh( const SMDS_Mesh* theMesh );
428       virtual void SetMargin(double theValue);
429       virtual void SetNumFunctor(NumericalFunctorPtr theFunct);
430       virtual bool IsSatisfy( long theElementId ) = 0;
431       virtual SMDSAbs_ElementType GetType() const;
432       double  GetMargin();
433   
434     protected:
435       double myMargin;
436       NumericalFunctorPtr myFunctor;
437     };
438     typedef boost::shared_ptr<Comparator> ComparatorPtr;
439   
440   
441     /*
442       Class       : LessThan
443       Description : Comparator "<"
444     */
445     class SMESHCONTROLS_EXPORT LessThan: public virtual Comparator{
446     public:
447       virtual bool IsSatisfy( long theElementId );
448     };
449   
450   
451     /*
452       Class       : MoreThan
453       Description : Comparator ">"
454     */
455     class SMESHCONTROLS_EXPORT MoreThan: public virtual Comparator{
456     public:
457       virtual bool IsSatisfy( long theElementId );
458     };
459   
460   
461     /*
462       Class       : EqualTo
463       Description : Comparator "="
464     */
465     class SMESHCONTROLS_EXPORT EqualTo: public virtual Comparator{
466     public:
467       EqualTo();
468       virtual bool IsSatisfy( long theElementId );
469       virtual void SetTolerance( double theTol );
470       virtual double GetTolerance();
471   
472     private:
473       double myToler;
474     };
475     typedef boost::shared_ptr<EqualTo> EqualToPtr;
476   
477     
478     /*
479       Class       : LogicalNOT
480       Description : Logical NOT predicate
481     */
482     class SMESHCONTROLS_EXPORT LogicalNOT: public virtual Predicate{
483     public:
484       LogicalNOT();
485       virtual ~LogicalNOT();
486       virtual bool IsSatisfy( long theElementId );
487       virtual void SetMesh( const SMDS_Mesh* theMesh );
488       virtual void SetPredicate(PredicatePtr thePred);
489       virtual SMDSAbs_ElementType GetType() const;
490   
491     private:
492       PredicatePtr myPredicate;
493     };
494     typedef boost::shared_ptr<LogicalNOT> LogicalNOTPtr;
495     
496   
497     /*
498       Class       : LogicalBinary
499       Description : Base class for binary logical predicate
500     */
501     class SMESHCONTROLS_EXPORT LogicalBinary: public virtual Predicate{
502     public:
503       LogicalBinary();
504       virtual ~LogicalBinary();
505       virtual void SetMesh( const SMDS_Mesh* theMesh );
506       virtual void SetPredicate1(PredicatePtr thePred);
507       virtual void SetPredicate2(PredicatePtr thePred);
508       virtual SMDSAbs_ElementType GetType() const;
509   
510     protected:
511       PredicatePtr myPredicate1;
512       PredicatePtr myPredicate2;
513     };
514     typedef boost::shared_ptr<LogicalBinary> LogicalBinaryPtr;
515   
516   
517     /*
518       Class       : LogicalAND
519       Description : Logical AND
520     */
521     class SMESHCONTROLS_EXPORT LogicalAND: public virtual LogicalBinary{
522     public:
523       virtual bool IsSatisfy( long theElementId );
524     };
525   
526   
527     /*
528       Class       : LogicalOR
529       Description : Logical OR
530     */
531     class SMESHCONTROLS_EXPORT LogicalOR: public virtual LogicalBinary{
532     public:
533       virtual bool IsSatisfy( long theElementId );
534     };
535   
536   
537     /*
538       Class       : ManifoldPart
539       Description : Predicate for manifold part of mesh
540     */
541     class SMESHCONTROLS_EXPORT ManifoldPart: public virtual Predicate{
542     public:
543
544       /* internal class for algorithm uses */
545       class Link
546       {
547       public:
548         Link( SMDS_MeshNode* theNode1,
549               SMDS_MeshNode* theNode2 );
550         ~Link();
551         
552         bool IsEqual( const ManifoldPart::Link& theLink ) const;
553         bool operator<(const ManifoldPart::Link& x) const;
554         
555         SMDS_MeshNode* myNode1;
556         SMDS_MeshNode* myNode2;
557       };
558
559       bool IsEqual( const ManifoldPart::Link& theLink1,
560                     const ManifoldPart::Link& theLink2 );
561       
562       typedef std::set<ManifoldPart::Link>                TMapOfLink;
563       typedef std::vector<SMDS_MeshFace*>                 TVectorOfFacePtr;
564       typedef std::vector<ManifoldPart::Link>             TVectorOfLink;
565       typedef std::map<SMDS_MeshFace*,int>                TDataMapFacePtrInt;
566       typedef std::map<ManifoldPart::Link,SMDS_MeshFace*> TDataMapOfLinkFacePtr;
567       
568       ManifoldPart();
569       ~ManifoldPart();
570       virtual void SetMesh( const SMDS_Mesh* theMesh );
571       // inoke when all parameters already set
572       virtual bool IsSatisfy( long theElementId );
573       virtual      SMDSAbs_ElementType GetType() const;
574
575       void    SetAngleTolerance( const double theAngToler );
576       double  GetAngleTolerance() const;
577       void    SetIsOnlyManifold( const bool theIsOnly );
578       void    SetStartElem( const long  theStartElemId );
579
580     private:
581       bool    process();
582       bool    findConnected( const TDataMapFacePtrInt& theAllFacePtrInt,
583                              SMDS_MeshFace*            theStartFace,
584                              TMapOfLink&               theNonManifold,
585                              TColStd_MapOfInteger&     theResFaces );
586       bool    isInPlane( const SMDS_MeshFace* theFace1,
587                           const SMDS_MeshFace* theFace2 );
588       void    expandBoundary( TMapOfLink&            theMapOfBoundary,
589                               TVectorOfLink&         theSeqOfBoundary,
590                               TDataMapOfLinkFacePtr& theDMapLinkFacePtr,
591                               TMapOfLink&            theNonManifold,
592                               SMDS_MeshFace*         theNextFace ) const;
593
594      void     getFacesByLink( const Link& theLink,
595                               TVectorOfFacePtr& theFaces ) const;
596
597     private:
598       const SMDS_Mesh*      myMesh;
599       TColStd_MapOfInteger  myMapIds;
600       TColStd_MapOfInteger  myMapBadGeomIds;
601       TVectorOfFacePtr      myAllFacePtr;
602       TDataMapFacePtrInt    myAllFacePtrIntDMap;
603       double                myAngToler;
604       bool                  myIsOnlyManifold;
605       long                  myStartElemId;
606
607     };
608     typedef boost::shared_ptr<ManifoldPart> ManifoldPartPtr;
609                          
610
611     /*
612       Class       : ElementsOnSurface
613       Description : Predicate elements that lying on indicated surface
614                     (plane or cylinder)
615     */
616     class SMESHCONTROLS_EXPORT ElementsOnSurface : public virtual Predicate {
617     public:
618       ElementsOnSurface();
619       ~ElementsOnSurface();
620       virtual void SetMesh( const SMDS_Mesh* theMesh );
621       virtual bool IsSatisfy( long theElementId );
622       virtual      SMDSAbs_ElementType GetType() const;
623
624       void    SetTolerance( const double theToler );
625       double  GetTolerance() const;
626       void    SetSurface( const TopoDS_Shape& theShape,
627                           const SMDSAbs_ElementType theType );
628       void    SetUseBoundaries( bool theUse );
629       bool    GetUseBoundaries() const { return myUseBoundaries; }
630
631     private:
632       void    process();
633       void    process( const SMDS_MeshElement* theElem  );
634       bool    isOnSurface( const SMDS_MeshNode* theNode );
635
636     private:
637       const SMDS_Mesh*      myMesh;
638       TColStd_MapOfInteger  myIds;
639       SMDSAbs_ElementType   myType;
640       //Handle(Geom_Surface)  mySurf;
641       TopoDS_Face           mySurf;
642       double                myToler;
643       bool                  myUseBoundaries;
644       GeomAPI_ProjectPointOnSurf myProjector;
645     };
646     
647     typedef boost::shared_ptr<ElementsOnSurface> ElementsOnSurfacePtr;
648       
649
650     /*
651       FILTER
652     */
653     class SMESHCONTROLS_EXPORT Filter{
654     public:
655       Filter();
656       virtual ~Filter();
657       virtual void SetPredicate(PredicatePtr thePred);
658
659       typedef std::vector<long> TIdSequence;
660
661       virtual 
662       void
663       GetElementsId( const SMDS_Mesh* theMesh,
664                      TIdSequence& theSequence );
665
666       static
667       void
668       GetElementsId( const SMDS_Mesh* theMesh, 
669                      PredicatePtr thePredicate,
670                      TIdSequence& theSequence );
671       
672     protected:
673       PredicatePtr myPredicate;
674     };
675   };  
676 };
677
678
679 #endif