Salome HOME
Update of CheckDone
[modules/smesh.git] / src / SMDS / SMDS_ElementHolder.hxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SMDS_ElementHolder.hxx
23 //  Module : SMESH
24 //
25 #ifndef _SMDS_ElementHolder_HeaderFile
26 #define _SMDS_ElementHolder_HeaderFile
27
28 #include "SMESH_SMDS.hxx"
29
30 #include "SMDS_ElemIterator.hxx"
31
32 #include <smIdType.hxx>
33 #include <vtkType.h>
34
35 #include <vector>
36 #include <set>
37
38 class SMDS_Mesh;
39 class SMDS_MeshElement;
40
41 //------------------------------------------------------------------------------------
42 /*!
43  * \brief Base class of object holding SMDS_MeshElement pointers.
44  *        Registering such an object in SMDS_Mesh assures that the
45  *        pointers remain valid after compacting the mesh
46  */
47 class SMDS_EXPORT SMDS_ElementHolder
48 {
49  public:
50
51   //! register self in the mesh
52   SMDS_ElementHolder( const SMDS_Mesh* mesh );
53
54   //! un-register self from the mesh
55   virtual ~SMDS_ElementHolder();
56
57
58  protected:
59
60   //!< the descendant object return its elements just before the mesh compacting
61   virtual SMDS_ElemIteratorPtr getElements() = 0;
62
63   //!< the descendant object temporary remove its elements
64   virtual void tmpClear() = 0;
65
66   //!< the descendant object re-add its elements after the mesh compacting
67   virtual void add( const SMDS_MeshElement* element ) = 0;
68
69   //!< the descendant squeeze its element storage after re-adding elements
70   virtual void compact() = 0;
71
72   //!< allow the descendant treat its elements before mesh clearing
73   virtual void clear() {}
74
75   SMDS_Mesh* myMesh;
76
77
78  private: // methods called by SMDS_Mesh
79
80   friend class SMDS_Mesh;
81
82   //! store vtkIDs of elements
83   void beforeCompacting();
84
85   //! restore pointers to elements
86   void restoreElements( const std::vector<smIdType>& idNodessOldToNew,
87                         const std::vector<smIdType>& idCellsOldToNew );
88
89
90   std::vector<const SMDS_MeshElement*>      myExternalElems; //!< elements not contained in the mesh
91   std::vector< vtkIdType >                  myVtkIDs;        //!< vtk IDs of elements
92   std::vector< bool >                       myIsNode;
93   std::set< SMDS_ElementHolder* >::iterator myPtrInMesh;
94 };
95
96 #endif