Salome HOME
54355: 'Compute' button is absent for 'Number of the double nodes' value in 'Mesh...
[modules/smesh.git] / src / SMESH / SMESH_ProxyMesh.cxx
index 8649c7d3a6438dbb9e5466bdbe17ca2cf45b863a..c8dcec11c7f3cd0bddb77175f8bf3b4fdc6fddd2 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -24,6 +24,8 @@
 
 #include "SMDS_IteratorOnIterators.hxx"
 #include "SMDS_SetIterator.hxx"
+#include "SMESHDS_Mesh.hxx"
+#include "SMESH_Mesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 
 #include <TopTools_ListIteratorOfListOfShape.hxx>
  */
 //================================================================================
 
-SMESH_ProxyMesh::SMESH_ProxyMesh():_mesh(0)
+SMESH_ProxyMesh::SMESH_ProxyMesh():_mesh(0), _subContainer(0)
 {
 }
+//================================================================================
+/*!
+ * \brief Constructor
+ */
+//================================================================================
+
+SMESH_ProxyMesh::SMESH_ProxyMesh(const SMESH_Mesh& mesh)
+  : _mesh( &mesh ),
+    _subContainer( new SubMesh( GetMeshDS() ) )
+{
+}
+
 //================================================================================
 /*!
  * \brief Make a proxy mesh from components. Components become empty
  */
 //================================================================================
 
-SMESH_ProxyMesh::SMESH_ProxyMesh(vector<SMESH_ProxyMesh::Ptr>& components):
+SMESH_ProxyMesh::SMESH_ProxyMesh(std::vector<SMESH_ProxyMesh::Ptr>& components):
   _mesh(0)
 {
   if ( components.empty() ) return;
@@ -57,7 +71,7 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(vector<SMESH_ProxyMesh::Ptr>& components):
 
     takeTmpElemsInMesh( m );
 
-    if ( !_mesh ) _mesh = m->_mesh;
+    if ( !_mesh && m->_mesh ) setMesh( *( m->_mesh ));
     if ( _allowedTypes.empty() ) _allowedTypes = m->_allowedTypes;
 
     if ( _subMeshes.size() < m->_subMeshes.size() )
@@ -68,8 +82,8 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(vector<SMESH_ProxyMesh::Ptr>& components):
       if ( _subMeshes[j] )
       {
         // unite 2 sub-meshes
-        set< const SMDS_MeshElement * > elems( _subMeshes[j]->_elements.begin(),
-                                               _subMeshes[j]->_elements.end());
+        std::set< const SMDS_MeshElement * > elems( _subMeshes[j]->_elements.begin(),
+                                                    _subMeshes[j]->_elements.end());
         elems.insert( m->_subMeshes[j]->_elements.begin(),
                       m->_subMeshes[j]->_elements.end());
         _subMeshes[j]->_elements.assign( elems.begin(), elems.end() );
@@ -93,22 +107,37 @@ SMESH_ProxyMesh::SMESH_ProxyMesh(vector<SMESH_ProxyMesh::Ptr>& components):
 
 //================================================================================
 /*!
- * \brief Destructor deletes proxy submeshes and tmp elemens
+ * \brief Destructor deletes proxy submeshes and tmp elements
  */
 //================================================================================
 
 SMESH_ProxyMesh::~SMESH_ProxyMesh()
 {
-  for ( unsigned i = 0; i < _subMeshes.size(); ++i )
+  delete _subContainer;
+
+  for ( size_t i = 0; i < _subMeshes.size(); ++i )
     delete _subMeshes[i];
   _subMeshes.clear();
 
-  set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.begin();
+  std::set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.begin();
   for ( ; i != _elemsInMesh.end(); ++i )
     GetMeshDS()->RemoveFreeElement( *i, 0 );
   _elemsInMesh.clear();
 }
 
+//================================================================================
+/*!
+ * \brief Set mesh
+ */
+//================================================================================
+
+void SMESH_ProxyMesh::setMesh(const SMESH_Mesh& mesh)
+{
+  _mesh = &mesh;
+  if ( _mesh )
+    _subContainer = new SubMesh( GetMeshDS() );
+}
+
 //================================================================================
 /*!
  * \brief Returns index of a shape
@@ -120,6 +149,19 @@ int SMESH_ProxyMesh::shapeIndex(const TopoDS_Shape& shape) const
   return ( shape.IsNull() || !_mesh->HasShapeToMesh() ? 0 : GetMeshDS()->ShapeToIndex(shape));
 }
 
+//================================================================================
+/*!
+ * \brief Create a SubMesh
+ *  \param [ino] index - shape index
+ *  \return SubMesh* - new SubMesh
+ */
+//================================================================================
+
+SMESH_ProxyMesh::SubMesh* SMESH_ProxyMesh::newSubmesh(int index) const
+{
+  return new SubMesh( GetMeshDS(),index );
+}
+
 //================================================================================
 /*!
  * \brief Returns the submesh of a shape; it can be a proxy sub-mesh
@@ -130,7 +172,7 @@ const SMESHDS_SubMesh* SMESH_ProxyMesh::GetSubMesh(const TopoDS_Shape& shape) co
 {
   const SMESHDS_SubMesh* sm = 0;
 
-  int i = shapeIndex(shape);
+  size_t i = shapeIndex(shape);
   if ( i < _subMeshes.size() )
     sm = _subMeshes[i];
   if ( !sm )
@@ -148,7 +190,7 @@ const SMESHDS_SubMesh* SMESH_ProxyMesh::GetSubMesh(const TopoDS_Shape& shape) co
 const SMESH_ProxyMesh::SubMesh*
 SMESH_ProxyMesh::GetProxySubMesh(const TopoDS_Shape& shape) const
 {
-  int i = shapeIndex(shape);
+  size_t i = shapeIndex(shape);
   return i < _subMeshes.size() ? _subMeshes[i] : 0;
 }
 
@@ -203,12 +245,12 @@ namespace
 
   class TFilteringIterator : public SMDS_ElemIterator
   {
-    SMDS_ElemIteratorPtr        _iter;
-    const SMDS_MeshElement *    _curElem;
-    vector< SMDSAbs_EntityType> _okTypes;
+    SMDS_ElemIteratorPtr             _iter;
+    const SMDS_MeshElement *         _curElem;
+    std::vector< SMDSAbs_EntityType> _okTypes;
   public:
-    TFilteringIterator( const vector< SMDSAbs_EntityType>& okTypes,
-                        const SMDS_ElemIteratorPtr&        elemIterator)
+    TFilteringIterator( const std::vector< SMDSAbs_EntityType>& okTypes,
+                        const SMDS_ElemIteratorPtr&             elemIterator)
       :_iter(elemIterator), _curElem(0), _okTypes(okTypes)
     {
       next();
@@ -243,15 +285,15 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces(const TopoDS_Shape& shape) const
   if ( !_mesh->HasShapeToMesh() )
     return SMDS_ElemIteratorPtr();
 
-  _subContainer.RemoveAllSubmeshes();
+  _subContainer->RemoveAllSubmeshes();
 
   TopTools_IndexedMapOfShape FF;
   TopExp::MapShapes( shape, TopAbs_FACE, FF );
   for ( int i = 1; i <= FF.Extent(); ++i )
     if ( const SMESHDS_SubMesh* sm = GetSubMesh( FF(i)))
-      _subContainer.AddSubMesh( sm );
+      _subContainer->AddSubMesh( sm );
 
-  return _subContainer.SMESHDS_SubMesh::GetElements();
+  return _subContainer->SMESHDS_SubMesh::GetElements();
 }
 
 //================================================================================
@@ -266,27 +308,27 @@ SMDS_ElemIteratorPtr SMESH_ProxyMesh::GetFaces() const
   if ( _mesh->HasShapeToMesh() )
     return SMDS_ElemIteratorPtr();
 
-  _subContainer.RemoveAllSubmeshes();
+  _subContainer->RemoveAllSubmeshes();
   for ( unsigned i = 0; i < _subMeshes.size(); ++i )
     if ( _subMeshes[i] )
-      _subContainer.AddSubMesh( _subMeshes[i] );
+      _subContainer->AddSubMesh( _subMeshes[i] );
 
-  if ( _subContainer.NbSubMeshes() == 0 ) // no elements substituted
+  if ( _subContainer->NbSubMeshes() == 0 ) // no elements substituted
     return GetMeshDS()->elementsIterator(SMDSAbs_Face);
 
   // if _allowedTypes is empty, only elements from _subMeshes are returned,...
-  SMDS_ElemIteratorPtr proxyIter = _subContainer.SMESHDS_SubMesh::GetElements();
+  SMDS_ElemIteratorPtr proxyIter = _subContainer->SMESHDS_SubMesh::GetElements();
   if ( _allowedTypes.empty() || NbFaces() == _mesh->NbFaces() )
     return proxyIter;
 
   // ... else elements filtered using allowedTypes are additionally returned
   SMDS_ElemIteratorPtr facesIter = GetMeshDS()->elementsIterator(SMDSAbs_Face);
   SMDS_ElemIteratorPtr filterIter( new TFilteringIterator( _allowedTypes, facesIter ));
-  vector< SMDS_ElemIteratorPtr > iters(2);
+  std::vector< SMDS_ElemIteratorPtr > iters(2);
   iters[0] = proxyIter;
   iters[1] = filterIter;
     
-  typedef vector< SMDS_ElemIteratorPtr > TElemIterVector;
+  typedef std::vector< SMDS_ElemIteratorPtr >                                 TElemIterVector;
   typedef SMDS_IteratorOnIterators<const SMDS_MeshElement *, TElemIterVector> TItersIter;
   return SMDS_ElemIteratorPtr( new TItersIter( iters ));
 }
@@ -431,7 +473,7 @@ void SMESH_ProxyMesh::removeTmpElement( const SMDS_MeshElement* elem )
 {
   if ( elem && elem->GetID() > 0 )
   {
-    set< const SMDS_MeshElement* >::iterator i =  _elemsInMesh.find( elem );
+    std::set< const SMDS_MeshElement* >::iterator i = _elemsInMesh.find( elem );
     if ( i != _elemsInMesh.end() )
     {
       GetMeshDS()->RemoveFreeElement( elem, 0 );
@@ -468,7 +510,7 @@ void SMESH_ProxyMesh::setNode2Node(const SMDS_MeshNode* srcNode,
   SubMesh* sm = const_cast<SubMesh*>( subMesh );
   if ( !subMesh->_n2n )
     sm->_n2n = new TN2NMap;
-  sm->_n2n->insert( make_pair( srcNode, proxyNode ));
+  sm->_n2n->insert( std::make_pair( srcNode, proxyNode ));
 }
 
 //================================================================================
@@ -482,6 +524,18 @@ bool SMESH_ProxyMesh::IsTemporary(const SMDS_MeshElement* elem ) const
   return ( elem->GetID() < 1 ) || _elemsInMesh.count( elem );
 }
 
+//================================================================================
+/*!
+ * \brief SubMesh Constructor
+ */
+//================================================================================
+
+SMESH_ProxyMesh::SubMesh::SubMesh( const SMDS_Mesh* mesh, int index )
+  : SMESHDS_SubMesh( static_cast<const SMESHDS_Mesh*>( mesh ), index ),
+    _n2n(0)
+{
+}
+
 //================================================================================
 /*!
  * \brief Return a proxy node or an input node