00001 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00018 // 00019 00020 // File : SMESH_ProxyMesh.hxx 00021 // Created : Thu Dec 2 10:05:35 2010 00022 // Author : Edward AGAPOV (eap) 00023 00024 #ifndef __SMESH_ProxyMesh_HXX__ 00025 #define __SMESH_ProxyMesh_HXX__ 00026 00027 #include "SMESH_SMESH.hxx" 00028 00029 #include "SMDS_MeshElement.hxx" 00030 #include "SMESHDS_SubMesh.hxx" 00031 00032 #include <TopoDS_Shape.hxx> 00033 00034 #include <map> 00035 #include <vector> 00036 #include <boost/shared_ptr.hpp> 00037 00038 class SMDS_MeshNode; 00039 class SMESHDS_Mesh; 00040 class SMESH_Mesh; 00041 00045 class SMESH_EXPORT SMESH_ProxyMesh 00046 { 00047 public: 00048 00049 typedef boost::shared_ptr<SMESH_ProxyMesh> Ptr; 00050 00051 typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*, TIDCompare > TN2NMap; 00052 00053 //-------------------------------------------------------------------------------- 00057 class SubMesh : public SMESHDS_SubMesh 00058 { 00059 public: 00060 00061 const TN2NMap* GetNodeNodeMap() const { return _n2n; } 00062 const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* n ) const; 00063 virtual void AddElement(const SMDS_MeshElement * e); 00064 virtual int NbElements() const; 00065 virtual SMDS_ElemIteratorPtr GetElements() const; 00066 virtual void Clear(); 00067 virtual bool Contains(const SMDS_MeshElement * ME) const; 00068 00069 template< class ITERATOR > 00070 void ChangeElements( ITERATOR it, ITERATOR end ) 00071 { 00072 // change SubMesh contents without deleting tmp faces 00073 // for which the caller is responsible 00074 _elements.clear(); 00075 while ( it != end ) _elements.push_back( *it++ ); 00076 } 00077 SubMesh(int index=0):SMESHDS_SubMesh(0,index),_n2n(0) {} 00078 ~SubMesh() { Clear(); } 00079 00080 private: 00081 std::vector<const SMDS_MeshElement *> _elements; 00082 TN2NMap* _n2n; 00083 friend class SMESH_ProxyMesh; 00084 }; 00085 //-------------------------------------------------------------------------------- 00086 // Public interface 00087 00088 SMESH_ProxyMesh(); 00089 SMESH_ProxyMesh(std::vector<SMESH_ProxyMesh::Ptr>& components); 00090 SMESH_ProxyMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; } 00091 virtual ~SMESH_ProxyMesh(); 00092 00093 // Returns the submesh of a face; it can be a proxy sub-mesh 00094 const SMESHDS_SubMesh* GetSubMesh(const TopoDS_Shape& face) const; 00095 00096 // Returns the proxy sub-mesh of a face; it can be NULL 00097 const SubMesh* GetProxySubMesh(const TopoDS_Shape& face) const; 00098 00099 // Returns the proxy node of a node; the input node is returned if no proxy exists 00100 const SMDS_MeshNode* GetProxyNode( const SMDS_MeshNode* node ) const; 00101 00102 // Returns iterator on all faces of the mesh taking into account substitutions 00103 // To be used in case of mesh without shape 00104 SMDS_ElemIteratorPtr GetFaces() const; 00105 00106 // Returns iterator on all faces on the face taking into account substitutions 00107 SMDS_ElemIteratorPtr GetFaces(const TopoDS_Shape& face) const; 00108 00109 // Return total nb of faces taking into account substitutions 00110 int NbFaces() const; 00111 00112 bool IsTemporary(const SMDS_MeshElement* elem ) const; 00113 00114 00115 00116 const SMESH_Mesh* GetMesh() const { return _mesh; } 00117 00118 SMESHDS_Mesh* GetMeshDS() const; 00119 00120 //-------------------------------------------------------------------------------- 00121 // Interface for descendants 00122 protected: 00123 00124 void setMesh(const SMESH_Mesh& mesh) { _mesh = &mesh; } 00125 00126 int shapeIndex(const TopoDS_Shape& shape) const; 00127 00128 // returns a proxy sub-mesh; zero index is for the case of mesh w/o shape 00129 SubMesh* findProxySubMesh(int shapeIndex=0) const; 00130 00131 // returns a proxy sub-mesh; it is created if not yet exists 00132 SubMesh* getProxySubMesh(int shapeIndex); 00133 00134 // returns a proxy sub-mesh; it is created if not yet exists 00135 SubMesh* getProxySubMesh(const TopoDS_Shape& shape=TopoDS_Shape()); 00136 00137 // move proxy sub-mesh from other proxy mesh to this, returns true if sub-mesh found 00138 bool takeProxySubMesh( const TopoDS_Shape& shape, SMESH_ProxyMesh* proxyMesh ); 00139 00140 // move tmp elements residing the _mesh from other proxy mesh to this 00141 void takeTmpElemsInMesh( SMESH_ProxyMesh* proxyMesh ); 00142 00143 // removes tmp faces from the _mesh 00144 void removeTmpElement( const SMDS_MeshElement* face ); 00145 00146 // stores tmp element residing the _mesh 00147 void storeTmpElement( const SMDS_MeshElement* face ); 00148 00149 // store node-node correspondence 00150 void setNode2Node(const SMDS_MeshNode* srcNode, 00151 const SMDS_MeshNode* proxyNode, 00152 const SubMesh* subMesh); 00153 00154 // types of elements needed to implement NbFaces() and GetFaces(); 00155 // if _allowedTypes is empty, only elements from _subMeshes are returned, 00156 // else elements of _mesh filtered using allowedTypes are additionally returned 00157 std::vector< SMDSAbs_EntityType> _allowedTypes; 00158 00159 private: 00160 00161 const SMESH_Mesh* _mesh; 00162 00163 // proxy sub-meshes; index in vector == shapeIndex(shape) 00164 std::vector< SubMesh* > _subMeshes; 00165 00166 // tmp elements residing the _mesh, to be deleted at destruction 00167 std::set< const SMDS_MeshElement* > _elemsInMesh; 00168 00169 // Complex submesh used to iterate over elements in other sub-meshes 00170 mutable SubMesh _subContainer; 00171 }; 00172 00173 #endif