Salome HOME
#18963 Minimize compiler warnings
[modules/smesh.git] / src / SMESH / SMESH_ProxyMesh.hxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File      : SMESH_ProxyMesh.hxx
21 // Created   : Thu Dec  2 10:05:35 2010
22 // Author    : Edward AGAPOV (eap)
23
24 #ifndef __SMESH_ProxyMesh_HXX__
25 #define __SMESH_ProxyMesh_HXX__
26
27 #include "SMESH_SMESH.hxx"
28
29 #include "SMDS_ElementHolder.hxx"
30 #include "SMESHDS_SubMesh.hxx"
31 #include "SMESH_TypeDefs.hxx"
32
33 #include <TopoDS_Shape.hxx>
34 #include <NCollection_DataMap.hxx>
35
36 #include <map>
37 #include <vector>
38 #include <boost/shared_ptr.hpp>
39
40 class SMDS_MeshNode;
41 class SMDS_MeshElement;
42 class SMESHDS_Mesh;
43 class SMESH_Mesh;
44
45 /*!
46  * \brief Container of xD mesh elements substituting other ones in the
47  *        input mesh of an (x+1)D algorithm
48  */
49 class SMESH_EXPORT SMESH_ProxyMesh
50 {
51 public:
52
53   typedef boost::shared_ptr<SMESH_ProxyMesh> Ptr;
54
55   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap;
56
57   //--------------------------------------------------------------------------------
58   /*!
59    * \brief Proxy sub-mesh
60    */
61   class SMESH_EXPORT SubMesh : public SMESHDS_SubMesh
62   {
63   public:
64
65     const TN2NMap*       GetNodeNodeMap() const { return _n2n; }
66     const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* n ) const;
67     const UVPtStructVec& GetUVPtStructVec() const { return _uvPtStructVec; }
68     virtual void         AddElement(const SMDS_MeshElement * e);
69     virtual int          NbElements() const;
70     virtual int          NbNodes() const;
71     virtual SMDS_ElemIteratorPtr GetElements() const;
72     virtual SMDS_NodeIteratorPtr GetNodes() const;
73     virtual void         Clear();
74     virtual bool         Contains(const SMDS_MeshElement * ME) const;
75
76     template< class ITERATOR >
77       void ChangeElements( ITERATOR it, ITERATOR end )
78     {
79       // change SubMesh contents without deleting tmp elements
80       // for which the caller is responsible
81       _elements.assign( it, end );
82     }
83     SubMesh(const SMDS_Mesh* mesh, int index=0);
84     virtual ~SubMesh() { Clear(); }
85
86   protected:
87     std::vector<const SMDS_MeshElement *> _elements;
88     TN2NMap*                              _n2n;
89     UVPtStructVec                         _uvPtStructVec; // for SubMesh of EDGE
90     friend class SMESH_ProxyMesh;
91
92   protected: // methods of SMDS_ElementHolder; remove elements before mesh compacting or clearing
93     virtual SMDS_ElemIteratorPtr getElements() { Clear(); return GetElements(); }
94     virtual void tmpClear() {}
95     virtual void add( const SMDS_MeshElement* /*element*/ ) {}
96     virtual void compact() {}
97     virtual void clear() { Clear(); }
98   };
99   //--------------------------------------------------------------------------------
100   // Public interface
101
102   SMESH_ProxyMesh();
103   SMESH_ProxyMesh(std::vector<SMESH_ProxyMesh::Ptr>& components);
104   SMESH_ProxyMesh(const SMESH_Mesh& mesh);
105   virtual ~SMESH_ProxyMesh();
106
107   // Returns a sub-mesh of a shape; it can be a proxy sub-mesh
108   const SMESHDS_SubMesh* GetSubMesh(const TopoDS_Shape& shape) const;
109
110   // Return a sub-mesh by a shape ID; it can be a proxy sub-mesh
111   const SMESHDS_SubMesh* GetSubMesh(const int shapeID) const;
112
113   // Return a proxy sub-mesh of a shape; it can be NULL
114   const SubMesh*         GetProxySubMesh(const TopoDS_Shape& shape) const;
115
116   // Return a proxy node of a node; the input node is returned if no proxy exists
117   const SMDS_MeshNode*   GetProxyNode( const SMDS_MeshNode* node ) const;
118
119   // Return number of proxy sub-meshes
120   int                    NbProxySubMeshes() const;
121
122   // Return iterator on all faces of the mesh taking into account substitutions.
123   // To be used in case of mesh without shape
124   SMDS_ElemIteratorPtr   GetFaces() const;
125
126   // Return iterator on all faces on the face taking into account substitutions
127   SMDS_ElemIteratorPtr   GetFaces(const TopoDS_Shape& face) const;
128
129   // Return total nb of faces taking into account substitutions
130   int                    NbFaces() const;
131
132   bool                   IsTemporary(const SMDS_MeshElement* elem ) const;
133
134   // Return iterator on inverse elements of a node that may be a proxy one
135   SMDS_ElemIteratorPtr   GetInverseElementIterator(const SMDS_MeshNode* node,
136                                                    SMDSAbs_ElementType  type) const;
137
138   // Check if a FACE has prisms on its both sides
139   static bool HasPrismsOnTwoSides( SMESHDS_SubMesh* faceSM );
140
141   SMESH_Mesh*            GetMesh() const { return const_cast<SMESH_Mesh*>( _mesh ); }
142
143   SMESHDS_Mesh*          GetMeshDS() const;
144
145   //--------------------------------------------------------------------------------
146   // Interface for descendants
147  protected:
148
149   void     setMesh(const SMESH_Mesh& mesh);
150
151   int      shapeIndex(const TopoDS_Shape& shape) const;
152
153   virtual SubMesh* newSubmesh(int index=0) const;
154
155   // Return a proxy sub-mesh; zero index is for the case of mesh w/o shape
156   SubMesh* findProxySubMesh(int shapeIndex=0) const;
157
158   // Return a proxy sub-mesh; it is created if not yet exists
159   SubMesh* getProxySubMesh(int shapeIndex);
160
161   // Return a proxy sub-mesh; it is created if not yet exists
162   SubMesh* getProxySubMesh(const TopoDS_Shape& shape=TopoDS_Shape());
163
164   // move proxy sub-mesh from other proxy mesh to this, returns true if sub-mesh found
165   bool     takeProxySubMesh( const TopoDS_Shape& shape, SMESH_ProxyMesh* proxyMesh );
166
167   // move tmp elements residing the _mesh from other proxy mesh to this
168   void     takeTmpElemsInMesh( SMESH_ProxyMesh* proxyMesh );
169
170   // removes tmp element from the _mesh
171   void     removeTmpElement( const SMDS_MeshElement* elem );
172
173   // stores tmp element residing the _mesh
174   void     storeTmpElement( const SMDS_MeshElement* elem );
175
176   // store node-node correspondence
177   void     setNode2Node(const SMDS_MeshNode* srcNode,
178                         const SMDS_MeshNode* proxyNode,
179                         const SubMesh*       subMesh);
180
181   // types of elements needed to implement NbFaces() and GetFaces();
182   // if _allowedTypes is empty, only elements from _subMeshes are returned,
183   // else elements of _mesh filtered using allowedTypes are additionally returned
184   std::vector< SMDSAbs_EntityType> _allowedTypes;
185
186  private:
187
188   const SMESH_Mesh*       _mesh;
189
190   // proxy sub-meshes; index in vector == shapeIndex(shape)
191   std::vector< SubMesh* > _subMeshes;
192
193   // tmp elements residing the _mesh, to be deleted at destruction
194   std::set< const SMDS_MeshElement* > _elemsInMesh;
195
196   // inverse elements of proxy nodes
197   typedef NCollection_DataMap< const SMDS_MeshNode*,
198                                std::vector< const SMDS_MeshElement* >,
199                                SMESH_Hasher                         > TNodeElemVecMap;
200   TNodeElemVecMap  _inverseElements;
201
202   // Complex submesh used to iterate over elements in other sub-meshes
203   mutable SubMesh* _subContainer;
204 };
205
206 #endif