Salome HOME
faf67734f17e79ac4a29bef20508df608289d810
[modules/smesh.git] / src / SMESH / SMESH_ProxyMesh.hxx
1 // Copyright (C) 2007-2012  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.
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_MeshElement.hxx"
30 #include "SMESHDS_SubMesh.hxx"
31
32 #include <TopoDS_Shape.hxx>
33
34 #include <map>
35 #include <vector>
36 #include <boost/shared_ptr.hpp>
37
38 class SMDS_MeshNode;
39 class SMESHDS_Mesh;
40 class SMESH_Mesh;
41
42 /*!
43  * \brief Container of mesh faces substituting other faces in the input mesh of 3D algorithm
44  */
45 class SMESH_EXPORT SMESH_ProxyMesh
46 {
47 public:
48
49   typedef boost::shared_ptr<SMESH_ProxyMesh> Ptr;
50
51   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap;
52
53   //--------------------------------------------------------------------------------
54   /*!
55    * \brief Proxy sub-mesh
56    */
57   class SubMesh : public SMESHDS_SubMesh
58   {
59   public:
60
61     const TN2NMap* GetNodeNodeMap() const { return _n2n; }
62     const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* n ) const;
63     virtual void AddElement(const SMDS_MeshElement * e);
64     virtual int NbElements() const;
65     virtual SMDS_ElemIteratorPtr GetElements() const;
66     virtual void Clear();
67     virtual bool Contains(const SMDS_MeshElement * ME) const;
68
69     template< class ITERATOR >
70     void ChangeElements( ITERATOR it, ITERATOR end )
71     {
72       // change SubMesh contents without deleting tmp faces
73       // for which the caller is responsible
74       _elements.clear();
75       while ( it != end ) _elements.push_back( *it++ );
76     }
77     SubMesh(int index=0):SMESHDS_SubMesh(0,index),_n2n(0) {}
78     ~SubMesh() { Clear(); }
79
80   private:
81     std::vector<const SMDS_MeshElement *> _elements;
82     TN2NMap*                              _n2n;
83     friend class SMESH_ProxyMesh;
84   };
85   //--------------------------------------------------------------------------------
86   // Public interface
87
88   SMESH_ProxyMesh();
89   SMESH_ProxyMesh(std::vector<SMESH_ProxyMesh::Ptr>& components);
90   SMESH_ProxyMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; }
91   virtual ~SMESH_ProxyMesh();
92
93   // Returns the submesh of a face; it can be a proxy sub-mesh
94   const SMESHDS_SubMesh* GetSubMesh(const TopoDS_Shape& face) const;
95
96   // Returns the proxy sub-mesh of a face; it can be NULL
97   const SubMesh* GetProxySubMesh(const TopoDS_Shape& face) const;
98
99   // Returns the proxy node of a node; the input node is returned if no proxy exists
100   const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* node ) const;
101
102   // Returns iterator on all faces of the mesh taking into account substitutions
103   // To be used in case of mesh without shape
104   SMDS_ElemIteratorPtr GetFaces() const;
105
106   // Returns iterator on all faces on the face taking into account substitutions
107   SMDS_ElemIteratorPtr GetFaces(const TopoDS_Shape& face) const;
108
109   // Return total nb of faces taking into account substitutions
110   int NbFaces() const;
111
112   bool IsTemporary(const SMDS_MeshElement* elem ) const;
113
114
115
116   const SMESH_Mesh* GetMesh() const { return _mesh; }
117
118   SMESHDS_Mesh* GetMeshDS() const;
119
120   //--------------------------------------------------------------------------------
121   // Interface for descendants
122  protected:
123
124   void setMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; }
125
126   int shapeIndex(const TopoDS_Shape& shape) const;
127
128   // returns a proxy sub-mesh; zero index is for the case of mesh w/o shape
129   SubMesh* findProxySubMesh(int shapeIndex=0) const;
130
131   // returns a proxy sub-mesh; it is created if not yet exists
132   SubMesh* getProxySubMesh(int shapeIndex);
133
134   // returns a proxy sub-mesh; it is created if not yet exists
135   SubMesh* getProxySubMesh(const TopoDS_Shape& shape=TopoDS_Shape());
136
137   // move proxy sub-mesh from other proxy mesh to this, returns true if sub-mesh found
138   bool takeProxySubMesh( const TopoDS_Shape& shape, SMESH_ProxyMesh* proxyMesh );
139
140   // move tmp elements residing the _mesh from other proxy mesh to this
141   void takeTmpElemsInMesh( SMESH_ProxyMesh* proxyMesh );
142
143   // removes tmp faces from the _mesh
144   void removeTmpElement( const SMDS_MeshElement* face );
145
146   // stores tmp element residing the _mesh
147   void storeTmpElement( const SMDS_MeshElement* face );
148
149   // store node-node correspondence
150   void setNode2Node(const SMDS_MeshNode* srcNode,
151                     const SMDS_MeshNode* proxyNode,
152                     const SubMesh*       subMesh);
153
154   // types of elements needed to implement NbFaces() and GetFaces();
155   // if _allowedTypes is empty, only elements from _subMeshes are returned,
156   // else elements of _mesh filtered using allowedTypes are additionally returned
157   std::vector< SMDSAbs_EntityType> _allowedTypes;
158
159  private:
160
161   const SMESH_Mesh*       _mesh;
162
163   // proxy sub-meshes; index in vector == shapeIndex(shape)
164   std::vector< SubMesh* > _subMeshes;
165
166   // tmp elements residing the _mesh, to be deleted at destruction
167   std::set< const SMDS_MeshElement* > _elemsInMesh;
168
169   // Complex submesh used to iterate over elements in other sub-meshes
170   mutable SubMesh _subContainer;
171 };
172
173 #endif