1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESH_ProxyMesh.hxx
21 // Created : Thu Dec 2 10:05:35 2010
22 // Author : Edward AGAPOV (eap)
24 #ifndef __SMESH_ProxyMesh_HXX__
25 #define __SMESH_ProxyMesh_HXX__
27 #include "SMESH_SMESH.hxx"
29 #include "SMESHDS_SubMesh.hxx"
30 #include "SMESH_TypeDefs.hxx"
32 #include <TopoDS_Shape.hxx>
36 #include <boost/shared_ptr.hpp>
39 class SMDS_MeshElement;
44 * \brief Container of xD mesh elements substituting other ones in the
45 * input mesh of an (x+1)D algorithm
47 class SMESH_EXPORT SMESH_ProxyMesh
51 typedef boost::shared_ptr<SMESH_ProxyMesh> Ptr;
53 typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap;
55 //--------------------------------------------------------------------------------
57 * \brief Proxy sub-mesh
59 class SMESH_EXPORT SubMesh : public SMESHDS_SubMesh
63 const TN2NMap* GetNodeNodeMap() const { return _n2n; }
64 const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* n ) const;
65 const UVPtStructVec& GetUVPtStructVec() const { return _uvPtStructVec; }
66 virtual void AddElement(const SMDS_MeshElement * e);
67 virtual int NbElements() const;
68 virtual int NbNodes() const;
69 virtual SMDS_ElemIteratorPtr GetElements(bool reverse=false) const;
70 virtual SMDS_NodeIteratorPtr GetNodes(bool reverse=false) const;
72 virtual bool Contains(const SMDS_MeshElement * ME) const;
74 template< class ITERATOR >
75 void ChangeElements( ITERATOR it, ITERATOR end )
77 // change SubMesh contents without deleting tmp elements
78 // for which the caller is responsible
79 _elements.assign( it, end );
81 SubMesh(int index=0):SMESHDS_SubMesh(0,index),_n2n(0) {}
82 virtual ~SubMesh() { Clear(); }
85 std::vector<const SMDS_MeshElement *> _elements;
87 UVPtStructVec _uvPtStructVec; // for SubMesh of EDGE
88 friend class SMESH_ProxyMesh;
90 //--------------------------------------------------------------------------------
94 SMESH_ProxyMesh(std::vector<SMESH_ProxyMesh::Ptr>& components);
95 SMESH_ProxyMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; }
96 virtual ~SMESH_ProxyMesh();
98 // Returns the submesh of a shape; it can be a proxy sub-mesh
99 const SMESHDS_SubMesh* GetSubMesh(const TopoDS_Shape& shape) const;
101 // Returns the proxy sub-mesh of a shape; it can be NULL
102 const SubMesh* GetProxySubMesh(const TopoDS_Shape& shape) const;
104 // Returns the proxy node of a node; the input node is returned if no proxy exists
105 const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* node ) const;
107 // Returns number of proxy sub-meshes
108 int NbProxySubMeshes() const;
110 // Returns iterator on all faces of the mesh taking into account substitutions.
111 // To be used in case of mesh without shape
112 SMDS_ElemIteratorPtr GetFaces() const;
114 // Returns iterator on all faces on the face taking into account substitutions
115 SMDS_ElemIteratorPtr GetFaces(const TopoDS_Shape& face) const;
117 // Return total nb of faces taking into account substitutions
120 bool IsTemporary(const SMDS_MeshElement* elem ) const;
124 SMESH_Mesh* GetMesh() const { return const_cast<SMESH_Mesh*>( _mesh ); }
126 SMESHDS_Mesh* GetMeshDS() const;
128 //--------------------------------------------------------------------------------
129 // Interface for descendants
132 void setMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; }
134 int shapeIndex(const TopoDS_Shape& shape) const;
136 virtual SubMesh* newSubmesh(int index=0) const { return new SubMesh(index); }
138 // returns a proxy sub-mesh; zero index is for the case of mesh w/o shape
139 SubMesh* findProxySubMesh(int shapeIndex=0) const;
141 // returns a proxy sub-mesh; it is created if not yet exists
142 SubMesh* getProxySubMesh(int shapeIndex);
144 // returns a proxy sub-mesh; it is created if not yet exists
145 SubMesh* getProxySubMesh(const TopoDS_Shape& shape=TopoDS_Shape());
147 // move proxy sub-mesh from other proxy mesh to this, returns true if sub-mesh found
148 bool takeProxySubMesh( const TopoDS_Shape& shape, SMESH_ProxyMesh* proxyMesh );
150 // move tmp elements residing the _mesh from other proxy mesh to this
151 void takeTmpElemsInMesh( SMESH_ProxyMesh* proxyMesh );
153 // removes tmp element from the _mesh
154 void removeTmpElement( const SMDS_MeshElement* elem );
156 // stores tmp element residing the _mesh
157 void storeTmpElement( const SMDS_MeshElement* elem );
159 // store node-node correspondence
160 void setNode2Node(const SMDS_MeshNode* srcNode,
161 const SMDS_MeshNode* proxyNode,
162 const SubMesh* subMesh);
164 // types of elements needed to implement NbFaces() and GetFaces();
165 // if _allowedTypes is empty, only elements from _subMeshes are returned,
166 // else elements of _mesh filtered using allowedTypes are additionally returned
167 std::vector< SMDSAbs_EntityType> _allowedTypes;
171 const SMESH_Mesh* _mesh;
173 // proxy sub-meshes; index in vector == shapeIndex(shape)
174 std::vector< SubMesh* > _subMeshes;
176 // tmp elements residing the _mesh, to be deleted at destruction
177 std::set< const SMDS_MeshElement* > _elemsInMesh;
179 // Complex submesh used to iterate over elements in other sub-meshes
180 mutable SubMesh _subContainer;