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