Salome HOME
0023505: Sigsegv with fuse on cylinder and cone
[modules/smesh.git] / src / SMESH_I / SMESH_PreMeshInfo.hxx
1 // Copyright (C) 2007-2016  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      : SMESH_PreMeshInfo.hxx
23 // Created   : Fri Feb 10 13:25:02 2012
24 // Author    : Edward AGAPOV (eap)
25
26
27 #ifndef __SMESH_PreMeshInfo_HXX__
28 #define __SMESH_PreMeshInfo_HXX__
29
30 #include "SMDS_MeshInfo.hxx"
31 #include <SALOMEconfig.h>
32 #include CORBA_SERVER_HEADER(SMESH_Mesh)
33 #include CORBA_SERVER_HEADER(SALOMEDS)
34
35 #include <TopAbs_ShapeEnum.hxx>
36
37 class DriverMED_R_SMESHDS_Mesh;
38 class HDFfile;
39 class HDFgroup;
40 class SMESH_Mesh_i;
41
42 /*!
43  * \brief Class loading and holding information of a mesh object (mesh, group, submesh)
44  *        not yet loaded from HDF file of study.
45  *
46  * Usage scenario:
47  * - SMESH_PreMeshInfo::LoadFromFile() // reads info of all objects
48  * - if ( myPreInfo ) myPreInfo->NbElements() // access to info by objects
49  * - myPreInfo->FullLoadFromFile() // reads all mesh data and resets myPreInfo=NULL
50  */
51
52 class SMESH_PreMeshInfo : public SMDS_MeshInfo
53 {
54 public:
55   // fills SMESH_PreMeshInfo* field of all objects of mesh
56   static void LoadFromFile( SMESH_Mesh_i*      mesh,
57                             const int          meshID,
58                             const std::string& medFile,
59                             const std::string& hdfFile,
60                             const bool         toRemoveFiles);
61
62   // saves SMESH_PreMeshInfo to the study file
63   static void SaveToFile( SMESH_Mesh_i* mesh,
64                           const int     meshID,
65                           HDFfile*      hdfFile);
66
67   // remove all SMESH_PreMeshInfo fields from mesh and its child objects w/o data loading
68   static void ForgetAllData( SMESH_Mesh_i* mesh );
69
70   // reads all data and remove all SMESH_PreMeshInfo fields from objects
71   void FullLoadFromFile() const;
72
73   // remove all SMESH_PreMeshInfo fields from objects w/o data loading
74   void ForgetAllData() const;
75
76   // calls either FullLoadFromFile() or ForgetAllData() depending on preferences;
77   // is called on hypothesis modification
78   void ForgetOrLoad() const;
79
80   // meshods of SMESH_IDSource interface
81   SMESH::array_of_ElementType* GetTypes() const;
82   SMESH::long_array*           GetMeshInfo() const;
83   bool                         IsMeshInfoCorrect() const;
84
85   ~SMESH_PreMeshInfo();
86
87   // TEMPORARY method to remove study files on closing study;
88   // RIGHT WAY: study files are remove automatically when meshes are destroyed
89   static void RemoveStudyFiles_TMP_METHOD(SALOMEDS::SComponent_ptr smeshComp);
90
91 private:
92
93   // creation by LoadFromFile() only
94   SMESH_PreMeshInfo(SMESH_Mesh_i*      mesh,
95                     const int          meshID,
96                     const std::string& medFile,
97                     const std::string& hdfFile);
98
99   SMESH_PreMeshInfo* newInstance()
100   { return new SMESH_PreMeshInfo( _mesh,_meshID,_medFileName,_hdfFileName ); }
101
102   // reading from the new study, for which SaveToFile() was called
103   bool readPreInfoFromHDF();
104   void hdf2meshInfo( const std::string& dataSetName, HDFgroup* infoHdfGroup );
105
106   // reading from the old study, for which SaveToFile() was not called
107   bool readMeshInfo();
108   void readGroupInfo();
109   void readSubMeshInfo();
110   SMDSAbs_EntityType getElemType( const TopAbs_ShapeEnum shapeType,
111                                   const int              nbElemsInSubMesh,
112                                   bool&                  isKoType) const;
113
114   void readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const;
115
116   // general data
117   std::string   _medFileName, _hdfFileName;
118   bool          _toRemoveFiles;
119   int           _meshID;
120   SMESH_Mesh_i* _mesh;
121   bool          _isInfoOk;
122
123   int _elemCounter; /* used as a counter while mesh info reading and
124                        as a signal that mesh info is incorrect after reading
125                      */
126 };
127
128 #endif