Salome HOME
Correct python dump for the SHAPERSTUDY part of the script
[modules/smesh.git] / src / SMESH_I / SMESH_PreMeshInfo.cxx
1 // Copyright (C) 2007-2019  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.cxx
23 // Created   : Fri Feb 10 17:36:39 2012
24 // Author    : Edward AGAPOV (eap)
25 //
26
27 #include "SMESH_PreMeshInfo.hxx"
28
29 #include "DriverMED.hxx"
30 #include "DriverMED_R_SMESHDS_Mesh.h"
31 #include "MED_Factory.hxx"
32 #include "SMDS_EdgePosition.hxx"
33 #include "SMDS_FacePosition.hxx"
34 #include "SMDS_SpacePosition.hxx"
35 #include "SMDS_VertexPosition.hxx"
36 #include "SMESHDS_Group.hxx"
37 #include "SMESHDS_GroupOnFilter.hxx"
38 #include "SMESHDS_Mesh.hxx"
39 #include "SMESH_Gen_i.hxx"
40 #include "SMESH_Group_i.hxx"
41 #include "SMESH_Mesh_i.hxx"
42 #include "SMESH_subMesh_i.hxx"
43
44 #include <HDFarray.hxx>
45 #include <HDFdataset.hxx>
46 #include <HDFfile.hxx>
47 #include <HDFgroup.hxx>
48 #include <SALOMEDS_Tool.hxx>
49 #include <SALOMEDS_wrap.hxx>
50
51 #include <TopoDS_Iterator.hxx>
52 #include <TopoDS_Shape.hxx>
53
54 #include "SMESH_TryCatch.hxx"
55
56 #include CORBA_SERVER_HEADER(SALOME_Session)
57
58 using namespace std;
59
60 #define MYDEBUGOUT(msg) //std::cout << msg << std::endl;
61
62 namespace
63 {
64   enum {  GroupOnFilter_OutOfDate = -777 };
65
66   // count not yet loaded meshes
67   static int theMeshCounter = 0;
68
69   //================================================================================
70   /*!
71    * \brief Counts not fully loaded meshes
72    */
73   //================================================================================
74
75   void meshInfoLoaded( SMESH_Mesh_i* mesh )
76   {
77     theMeshCounter++;
78   }
79   //================================================================================
80   /*!
81    * \brief Removes temporary files if none of meshes needs them
82    */
83   //================================================================================
84
85   void filesNoMoreNeeded(SMESH_Mesh_i* mesh,
86                          std::string   medFile,
87                          std::string   hdfFile)
88   {
89     if ( --theMeshCounter == 0 )
90     {
91       std::string tmpDir = SALOMEDS_Tool::GetDirFromPath( hdfFile );
92
93       SALOMEDS_Tool::ListOfFiles aFiles;
94       aFiles.reserve(2);
95       medFile = SALOMEDS_Tool::GetNameFromPath( medFile ) + ".med";
96       hdfFile = SALOMEDS_Tool::GetNameFromPath( hdfFile ) + ".hdf";
97       aFiles.push_back(medFile.c_str());
98       aFiles.push_back(hdfFile.c_str());
99
100       SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.c_str(), aFiles, true );
101     }
102   }
103
104   //=============================================================================
105   /*!
106    * \brief Class sending signals on start and finish of loading
107    */
108   //=============================================================================
109
110   class SignalToGUI
111   {
112     std::string         _messagePrefix;
113     SALOME::Session_var _session;
114   public:
115     SignalToGUI( SMESH_Mesh_i* mesh )
116     {
117       SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
118
119       SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( mesh->_this() );
120       CORBA::Object_var        obj = gen->GetNS()->Resolve( "/Kernel/Session" );
121       _session = SALOME::Session::_narrow( obj );
122       if ( !meshSO->_is_nil() && !_session->_is_nil() )
123       {
124         CORBA::String_var meshEntry = meshSO->GetID();
125         _messagePrefix = "SMESH/mesh_loading/";
126         _messagePrefix += meshEntry.in();
127
128         std::string msgToGUI = _messagePrefix + "/";
129         msgToGUI += SMESH_Comment( mesh->NbNodes() );
130         msgToGUI += "/";
131         msgToGUI += SMESH_Comment( mesh->NbElements() );
132
133         _session->emitMessageOneWay( msgToGUI.c_str());
134       }
135     }
136     void sendStop()
137     {
138       if ( !_messagePrefix.empty() )
139       {
140         std::string msgToGUI = _messagePrefix + "/stop";
141         _session->emitMessageOneWay( msgToGUI.c_str());
142         _messagePrefix.clear();
143       }
144     }
145     ~SignalToGUI() { sendStop(); }
146   };
147
148   //=============================================================================
149   /*!
150    * \brief Creates SMDS_Position according to shape type
151    */
152   //=============================================================================
153
154   class PositionCreator {
155   public:
156     SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
157       return (this->*myFuncTable[ type ])();
158     }
159     PositionCreator() {
160       myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
161       myFuncTable[ TopAbs_SOLID  ] = & PositionCreator::volumePosition;
162       myFuncTable[ TopAbs_FACE   ] = & PositionCreator::facePosition;
163       myFuncTable[ TopAbs_EDGE   ] = & PositionCreator::edgePosition;
164       myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
165     }
166   private:
167     SMDS_PositionPtr edgePosition()    const { return SMDS_PositionPtr( new SMDS_EdgePosition  ); }
168     SMDS_PositionPtr facePosition()    const { return SMDS_PositionPtr( new SMDS_FacePosition  ); }
169     SMDS_PositionPtr volumePosition()  const { return SMDS_PositionPtr( new SMDS_SpacePosition ); }
170     SMDS_PositionPtr vertexPosition()  const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
171     SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition();  }
172     typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
173     std::vector<FmakePos> myFuncTable;
174   };
175
176   //================================================================================
177   /*!
178    * \brief Returns ids of simple shapes composing a complex one
179    */
180   //================================================================================
181
182   std::vector<int> getSimpleSubMeshIds( SMESHDS_Mesh* meshDS, int shapeId )
183   {
184     std::vector<int> ids;
185
186     std::list<TopoDS_Shape> shapeQueue( 1, meshDS->IndexToShape( shapeId ));
187     std::list<TopoDS_Shape>::iterator shape = shapeQueue.begin();
188     for ( ; shape != shapeQueue.end(); ++shape )
189     {
190       if ( shape->IsNull() ) continue;
191       if ( shape->ShapeType() == TopAbs_COMPOUND ||
192            shape->ShapeType() == TopAbs_COMPSOLID )
193       {
194         for ( TopoDS_Iterator it( *shape ); it.More(); it.Next() )
195           shapeQueue.push_back( it.Value() );
196       }
197       else
198       {
199         ids.push_back( meshDS->ShapeToIndex( *shape ));
200       }
201     }
202     return ids;
203   }
204
205   //================================================================================
206   /*!
207    * \brief Return EEntiteMaillage by EGeometrieElement
208    */
209   //================================================================================
210
211   MED::EEntiteMaillage entityByGeom(const MED::EGeometrieElement geom )
212   {
213     return geom == MED::eBALL ? MED::eSTRUCT_ELEMENT : MED::eMAILLE;
214   }
215
216   //================================================================================
217   /*!
218    * \brief Return a map< EGeometrieElement, SMDSAbs_EntityType >
219    */
220   //================================================================================
221
222   typedef std::map< MED::EGeometrieElement, SMDSAbs_EntityType > Tmed2smeshElemTypeMap;
223   const Tmed2smeshElemTypeMap& med2smeshElemTypeMap()
224   {
225     static Tmed2smeshElemTypeMap med2smeshTypes;
226     if ( med2smeshTypes.empty() )
227     {
228       for  ( int iG = 0; iG < SMDSEntity_Last; ++iG )
229       {
230         SMDSAbs_EntityType    smdsType = (SMDSAbs_EntityType) iG;
231         MED::EGeometrieElement medType =
232           (MED::EGeometrieElement) DriverMED::GetMedGeoType( smdsType );
233         med2smeshTypes.insert( std::make_pair( medType, smdsType ));
234       }
235     }
236     return med2smeshTypes;
237   }
238
239   //================================================================================
240   /*!
241    * \brief Writes meshInfo into a HDF file
242    */
243   //================================================================================
244
245   void meshInfo2hdf( SMESH::long_array_var meshInfo,
246                      const std::string&    name,
247                      HDFgroup*             hdfGroup)
248   {
249     // we use med identification of element (MED::EGeometrieElement) types
250     // but not enum SMDSAbs_EntityType because values of SMDSAbs_EntityType may
251     // change at insertion of new items in the middle.
252     //const vector<MED::EGeometrieElement>& medTypes = mesh2medElemType();
253
254     std::vector<int> data;
255
256     for ( size_t i = 0; i < meshInfo->length(); ++i )
257       if ( meshInfo[i] > 0 || meshInfo[i] == GroupOnFilter_OutOfDate )
258       {
259         data.push_back( DriverMED::GetMedGeoType( SMDSAbs_EntityType( i ))); //medTypes[ i ] );
260         data.push_back( meshInfo[ i ] );
261       }
262
263     if ( !data.empty() )
264     {
265       hdf_size datasetSize[] = { data.size() };
266       HDFarray* anArray = new HDFarray(0, HDF_INT32, 1, datasetSize);
267       anArray->CreateOnDisk();
268       datasetSize[0] = 1;
269       HDFdataset* dataset = new HDFdataset( name.c_str(), hdfGroup, HDF_ARRAY, datasetSize, 1 );
270       dataset->SetArrayId(anArray->GetId());
271       dataset->CreateOnDisk();
272       dataset->WriteOnDisk( & data[0]  );
273       dataset->CloseOnDisk();
274       anArray->CloseOnDisk();
275     }
276   }
277 }
278
279 //================================================================================
280 /*!
281  * \brief Reads meshInfo from a HDF file
282  */
283 //================================================================================
284
285 void SMESH_PreMeshInfo::hdf2meshInfo( const std::string&              name,
286                                       HDFgroup*                       hdfGroup,
287                                       const TColStd_MapOfAsciiString& allHdfNames)
288 {
289   //if ( hdfGroup->ExistInternalObject( name.c_str()) ) PAL23514
290   if ( allHdfNames.Contains( name.c_str() ))
291   {
292     HDFdataset* dataset = new HDFdataset( name.c_str(), hdfGroup );
293     dataset->OpenOnDisk();
294
295     // // hdf_size datasetSize[ 1 ];
296     // // HDFarray *array = new HDFarray(dataset);
297     // // array->GetDim( datasetSize );
298     // int size = dataset->GetSize();
299
300     std::vector<int> info( SMDSEntity_Last * 2, 0 );
301     dataset->ReadFromDisk( &info[0] );
302     dataset->CloseOnDisk();
303
304     const Tmed2smeshElemTypeMap& med2smesh = med2smeshElemTypeMap();
305     Tmed2smeshElemTypeMap::const_iterator me2sme, me2smeEnd = med2smesh.end();
306     for ( size_t i = 0; i < info.size(); )
307     {
308       int medType = info[i++];
309       int nbElems = info[i++];
310       if ( !nbElems ) break;
311       me2sme = med2smesh.find( (MED::EGeometrieElement) medType );
312       if ( me2sme != me2smeEnd )
313         setNb( me2sme->second, nbElems );
314     }
315   }
316   _isInfoOk = true;
317
318   if ( NbNodes() == GroupOnFilter_OutOfDate ) // case of !SMESHDS_GroupOnFilter::IsUpToDate()
319   {
320     _isInfoOk = false;
321     setNb( SMDSEntity_Node, 0 );
322   }
323 }
324
325 //================================================================================
326 /*!
327  * \brief Constructor callable by SMESH_PreMeshInfo only
328  */
329 //================================================================================
330
331 SMESH_PreMeshInfo::SMESH_PreMeshInfo(SMESH_Mesh_i*      mesh,
332                                      const int          meshID,
333                                      const std::string& medFile,
334                                      const std::string& hdfFile)
335   : _medFileName( medFile ),
336     _hdfFileName( hdfFile ),
337     _toRemoveFiles( false ),
338     _meshID( meshID ),
339     _mesh( mesh ),
340     _isInfoOk( false ),
341     _elemCounter( 0 )
342 {
343 }
344
345 //================================================================================
346 /*!
347  * \brief Release temporary files
348  */
349 //================================================================================
350
351 SMESH_PreMeshInfo::~SMESH_PreMeshInfo()
352 {
353   if ( _toRemoveFiles ) // it can be true only for SMESH_PreMeshInfo of the mesh
354     filesNoMoreNeeded( _mesh, _medFileName, _hdfFileName );
355
356   _toRemoveFiles = false;
357 }
358
359 //================================================================================
360 /*!
361  * \brief fills SMESH_PreMeshInfo field of all objects of mesh
362  */
363 //================================================================================
364
365 void SMESH_PreMeshInfo::LoadFromFile( SMESH_Mesh_i*      mesh,
366                                       const int          meshID,
367                                       const std::string& medFile,
368                                       const std::string& hdfFile,
369                                       const bool         toRemoveFiles)
370 {
371   SMESH_TRY;
372
373   SMESH_PreMeshInfo* meshPreInfo = new SMESH_PreMeshInfo( mesh,meshID,medFile,hdfFile );
374   mesh->changePreMeshInfo() = meshPreInfo;
375
376   meshPreInfo->_toRemoveFiles = toRemoveFiles;
377   if ( toRemoveFiles )
378     meshInfoLoaded( mesh );
379
380   if ( meshPreInfo->readPreInfoFromHDF() )
381     // all SMESH_PreMeshInfo's are stored in HDF file (written after
382     // implementing SMESH_PreMeshInfo)
383     return;
384
385   // try to read SMESH_PreMeshInfo from med file (as study is older than SMESH_PreMeshInfo)
386   if ( meshPreInfo->readMeshInfo() )
387   {
388     meshPreInfo->readGroupInfo();
389     meshPreInfo->readSubMeshInfo();
390   }
391   else
392   {
393     meshPreInfo->FullLoadFromFile();
394   }
395   SMESH_CATCH( SMESH::doNothing );
396 }
397
398 //================================================================================
399 /*!
400  * \brief Tries to read all SMESH_PreMeshInfo from a HDF file
401  *  \retval bool - true if succeeded
402  *
403  * This method is symmetrical to SaveToFile()
404  */
405 //================================================================================
406
407 bool SMESH_PreMeshInfo::readPreInfoFromHDF()
408 {
409   HDFfile* aFile = new HDFfile( (char*) _hdfFileName.c_str() );
410   aFile->OpenOnDisk( HDF_RDONLY );
411
412   SMESH_Comment hdfGroupName("SMESH_PreMeshInfo"); hdfGroupName << _meshID;
413   const bool infoAvailable = aFile->ExistInternalObject( hdfGroupName );
414   if ( infoAvailable )
415   {
416     HDFgroup* infoHdfGroup = new HDFgroup( hdfGroupName, aFile );
417     infoHdfGroup->OpenOnDisk();
418
419     // PAL23514: get all names from the HDFgroup to avoid iteration on its contents
420     // within aGroup->ExistInternalObject( name )
421     TColStd_MapOfAsciiString mapOfNames;
422     {
423       std::vector< std::string > subNames;
424       infoHdfGroup->GetAllObjects( subNames );
425       for ( size_t iN = 0; iN < subNames.size(); ++iN )
426         mapOfNames.Add( subNames[ iN ].c_str() );
427     }
428
429     _mesh->changePreMeshInfo()->hdf2meshInfo( "Mesh", infoHdfGroup, mapOfNames );
430
431     // read SMESH_PreMeshInfo of groups
432     map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i2group = _mesh->_mapGroups.begin();
433     for ( ; i2group != _mesh->_mapGroups.end(); ++i2group )
434     {
435       if ( SMESH_GroupBase_i* group_i =
436            SMESH::DownCast<SMESH_GroupBase_i*>( i2group->second ))
437       {
438         group_i->changePreMeshInfo() = newInstance();
439         if ( SMESHDS_GroupBase* group = group_i->GetGroupDS() )
440         {
441           const std::string name = group->GetStoreName();
442           group_i->changePreMeshInfo()->hdf2meshInfo( name, infoHdfGroup, mapOfNames );
443         }
444       }
445     }
446
447     // read SMESH_PreMeshInfo of sub-meshes
448     map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = _mesh->_mapSubMeshIor.begin();
449     for ( ; id2sm != _mesh->_mapSubMeshIor.end(); ++id2sm )
450     {
451       if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
452       {
453         sm->changePreMeshInfo() = newInstance();
454         sm->changePreMeshInfo()->hdf2meshInfo( SMESH_Comment( sm->GetId()),
455                                                infoHdfGroup,
456                                                mapOfNames );
457       }
458     }
459     infoHdfGroup->CloseOnDisk();
460   }
461
462   aFile->CloseOnDisk();
463   delete aFile;
464
465   return infoAvailable;
466 }
467
468 //================================================================================
469 /*!
470  * \brief Reads mesh info of mesh from the med file
471  */
472 //================================================================================
473
474 bool SMESH_PreMeshInfo::readMeshInfo()
475 {
476   _isInfoOk = true;
477
478   MED::PWrapper aMed = MED::CrWrapperR(_medFileName);
479   MED::PMeshInfo medMeshInfo = aMed->CrMeshInfo(3,3,SMESH_Comment( _meshID ));
480
481   // read nb nodes
482   int nbNodes = std::max( 0, aMed->GetNbNodes( medMeshInfo ));
483   if ( nbNodes > 0 )
484   {
485     setNb( SMDSEntity_Node, nbNodes);
486
487     // read nb of elements
488     Tmed2smeshElemTypeMap::const_iterator me2sme    = med2smeshElemTypeMap().begin();
489     Tmed2smeshElemTypeMap::const_iterator me2smeEnd = med2smeshElemTypeMap().end();
490     for ( ; me2sme != me2smeEnd; ++me2sme )
491     {
492       int nbElems = aMed->GetNbCells( medMeshInfo, entityByGeom(me2sme->first), me2sme->first );
493       if ( nbElems > 0 )
494         setNb( me2sme->second, nbElems );
495     }
496   }
497   return true;
498 }
499
500 //================================================================================
501 /*!
502  * \brief Reads info of groups from the med file
503  */
504 //================================================================================
505
506 void SMESH_PreMeshInfo::readGroupInfo()
507 {
508   if ( _mesh->_mapGroups.empty() ) return;
509
510   // make SMESH_PreMeshInfo of groups
511   map< std::string, SMESH_PreMeshInfo* > name2GroupInfo;
512   map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i2group = _mesh->_mapGroups.begin();
513   for ( ; i2group != _mesh->_mapGroups.end(); ++i2group )
514   {
515     if ( SMESH_GroupBase_i* group_i =
516          SMESH::DownCast<SMESH_GroupBase_i*>( i2group->second ))
517     {
518       SMESH_PreMeshInfo* info = newInstance();
519       group_i->changePreMeshInfo() = info;
520       if ( SMESHDS_Group* group = dynamic_cast< SMESHDS_Group* >( group_i->GetGroupDS() ))
521       {
522         std::string name = group->GetStoreName();
523         name2GroupInfo.insert( std::make_pair( name, info ));
524         info->_isInfoOk = true;
525       }
526     }
527   }
528
529   map< int, vector< SMESH_PreMeshInfo* > > famId2grInfo;
530
531   MED::PWrapper aMed = MED::CrWrapperR(_medFileName);
532   MED::PMeshInfo medMeshInfo = aMed->CrMeshInfo(3,3,SMESH_Comment( _meshID ));
533
534   // read families to fill in famId2grInfo
535   int nbFams = aMed->GetNbFamilies( medMeshInfo );
536   if ( nbFams <= 1 ) return; // zero family is always present
537   for ( int iF = 0; iF <= nbFams; ++iF )
538   {
539     int nbGroups = aMed->GetNbFamGroup( iF, medMeshInfo );
540     if ( nbGroups < 1 ) continue;
541     MED::PFamilyInfo medFamInfo = aMed->CrFamilyInfo( medMeshInfo, nbGroups, nbGroups );
542     aMed->GetFamilyInfo( iF, medFamInfo ); // read groups of a family
543     vector< SMESH_PreMeshInfo* >& grInfoVec = famId2grInfo[ medFamInfo->GetId() ];
544     for ( int iG = 0; iG < nbGroups; ++iG )
545     {
546       const std::string grName = medFamInfo->GetGroupName( iG );
547       map< std::string, SMESH_PreMeshInfo* >::iterator n2i = name2GroupInfo.find( grName );
548       if ( n2i != name2GroupInfo.end() )
549         grInfoVec.push_back( n2i->second );
550     }
551   }
552
553   // read family numbers of elements
554   Tmed2smeshElemTypeMap::const_iterator me2sme    = med2smeshElemTypeMap().begin();
555   Tmed2smeshElemTypeMap::const_iterator me2smeEnd = med2smeshElemTypeMap().end();
556   MED::PElemInfo medElemInfo = aMed->CrElemInfo( medMeshInfo, 0 );
557   MED::TIntVector& famNums = medElemInfo->myFamNum;
558   for ( ; me2sme != me2smeEnd; ++me2sme ) // loop on elem types
559   {
560     famNums.resize( NbEntities( me2sme->second ));
561     if ( famNums.empty() ) continue;
562     aMed->GetFamilies( medElemInfo, famNums.size(), entityByGeom(me2sme->first), me2sme->first );
563     // distribute elements of a type among groups
564     map< int, vector< SMESH_PreMeshInfo* > >::iterator f2infos = famId2grInfo.begin();
565     for ( size_t i = 0; i < famNums.size(); ++i )
566     {
567       if ( famNums[i] != f2infos->first )
568       {
569         f2infos = famId2grInfo.find( famNums[i] );
570         if ( f2infos == famId2grInfo.end() )
571           f2infos = famId2grInfo.insert
572             ( std::make_pair( famNums[i], vector< SMESH_PreMeshInfo*>())).first;
573       }
574       vector< SMESH_PreMeshInfo* >& infoVec = f2infos->second ;
575       for ( size_t j = 0; j < infoVec.size(); ++j )
576         infoVec[j]->_elemCounter++;
577     }
578     // pass _elemCounter to a real elem type
579     map< std::string, SMESH_PreMeshInfo* >::iterator n2i = name2GroupInfo.begin();
580     for ( ; n2i != name2GroupInfo.end(); ++n2i )
581     {
582       SMESH_PreMeshInfo* info = n2i->second;
583       info->setNb( me2sme->second, info->_elemCounter );
584       info->_elemCounter = 0;
585     }
586   }
587 }
588
589 //================================================================================
590 /*!
591  * \brief Reads info of sub-meshes from hdf file of old study
592  */
593 //================================================================================
594
595 void SMESH_PreMeshInfo::readSubMeshInfo()
596 {
597   if ( _mesh->_mapSubMeshIor.empty() ) return;
598
599   // create SMESH_PreMeshInfo of sub-meshes
600   map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = _mesh->_mapSubMeshIor.begin();
601   for ( ; id2sm != _mesh->_mapSubMeshIor.end(); ++id2sm )
602   {
603     if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
604     {
605       sm->changePreMeshInfo() = newInstance();
606       sm->changePreMeshInfo()->_isInfoOk = true;
607     }
608   }
609
610   // try to read 
611   HDFfile* aFile = new HDFfile( (char*) _hdfFileName.c_str() );
612   aFile->OpenOnDisk( HDF_RDONLY );
613
614   char meshGrpName[ 30 ];
615   sprintf( meshGrpName, "Mesh %d", _meshID );
616   if ( aFile->ExistInternalObject( meshGrpName ) )
617   {
618     HDFgroup* aTopGroup = new HDFgroup( meshGrpName, aFile );
619     aTopGroup->OpenOnDisk();
620     if ( aTopGroup->ExistInternalObject( "Submeshes" ))
621     {
622       HDFgroup* aGroup = new HDFgroup( "Submeshes", aTopGroup );
623       aGroup->OpenOnDisk();
624
625       SMESHDS_Mesh* meshDS = _mesh->GetImpl().GetMeshDS();
626       int maxSmId = Max( meshDS->MaxSubMeshIndex(), meshDS->MaxShapeIndex() );
627
628       for ( int isNode = 0; isNode < 2; ++isNode )
629       {
630         std::string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
631         if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
632         {
633           // read sub-mesh id of all nodes or elems
634           HDFdataset* aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
635           aDataset->OpenOnDisk();
636           int nbElems = aDataset->GetSize();
637           int* smIDs = new int [ nbElems ];
638           aDataset->ReadFromDisk( smIDs );
639           aDataset->CloseOnDisk();
640           // count nb elems in each sub-mesh
641           vector<int> nbBySubmeshId( maxSmId + 1, 0 );
642           for ( int i = 0; i < nbElems; ++i )
643           {
644             const int smID = smIDs[ i ];
645             if ( smID < (int) nbBySubmeshId.size() )
646               nbBySubmeshId[ smID ]++;
647           }
648           delete [] smIDs;
649
650           // store nb elems in SMESH_PreMeshInfo of sub-meshes
651           map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = _mesh->_mapSubMeshIor.begin();
652           for ( ; id2sm != _mesh->_mapSubMeshIor.end(); ++id2sm )
653           {
654             if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
655             {
656               SMESH_PreMeshInfo* & info = sm->changePreMeshInfo();
657
658               vector<int> smIds = getSimpleSubMeshIds( meshDS, id2sm->first );
659               for ( size_t i = 0; i < smIds.size(); ++i )
660                 info->_elemCounter += nbBySubmeshId[ smIds[i] ];
661
662               SMDSAbs_EntityType elemType;
663               if ( isNode )
664               {
665                 elemType = SMDSEntity_Node;
666               }
667               else
668               {
669                 bool koElemType = false;
670                 const TopoDS_Shape& shape = meshDS->IndexToShape( smIds[0] );
671                 elemType = getElemType( shape.ShapeType(), info->_elemCounter, koElemType );
672                 info->_isInfoOk = !koElemType;
673               }
674               info->setNb( elemType, info->_elemCounter );
675             }
676           }
677         } // if ( aGroup->ExistInternalObject( aDSName ))
678       } // for ( int isNode = 0; isNode < 2; ++isNode )
679
680       aGroup->CloseOnDisk();
681     } // if ( aTopGroup->ExistInternalObject( "Submeshes" ))
682
683     aTopGroup->CloseOnDisk();
684   } // if ( aFile->ExistInternalObject( meshGrpName ) )
685
686   aFile->CloseOnDisk();
687   delete aFile;
688 }
689
690 //================================================================================
691 /*!
692  * \brief Return type of element for sub-mesh on a shape of given type
693  */
694 //================================================================================
695
696 SMDSAbs_EntityType SMESH_PreMeshInfo::getElemType( const TopAbs_ShapeEnum shapeType,
697                                                    const int              nbElemsInSubMesh,
698                                                    bool&                  isKoType) const
699 {
700   isKoType = false;
701   int type, typeEnd;
702   SMESH_PreMeshInfo* meshInfo = _mesh->changePreMeshInfo();
703
704   switch ( shapeType )
705   {
706   case TopAbs_SOLID:
707     type = SMDSEntity_Tetra;
708     typeEnd = SMDSEntity_Last;
709     isKoType = ( meshInfo->NbVolumes() != nbElemsInSubMesh );
710     break;
711   case TopAbs_FACE:
712   case TopAbs_SHELL:  
713     type = SMDSEntity_Triangle;
714     typeEnd = SMDSEntity_Tetra;
715     isKoType = ( meshInfo->NbFaces() != nbElemsInSubMesh );
716     break;
717   case TopAbs_WIRE:
718   case TopAbs_EDGE:   return SMDSEntity_Edge;
719   case TopAbs_VERTEX: return SMDSEntity_0D;
720   default:            return SMDSEntity_Last;
721   }
722
723   if ( !isKoType )
724   {
725     for ( int t = type; t < typeEnd; ++t )
726       if ( nbElemsInSubMesh == meshInfo->NbEntities( SMDSAbs_EntityType( t )))
727         return SMDSAbs_EntityType( t );
728   }
729   isKoType = true;
730   return SMDSAbs_EntityType( type );
731 }
732
733 //================================================================================
734 /*!
735  * \brief Saves SMESH_PreMeshInfo to the study file
736  */
737 //================================================================================
738
739 void SMESH_PreMeshInfo::SaveToFile( SMESH_Mesh_i* mesh,
740                                     const int     meshID,
741                                     HDFfile*      hdfFile)
742 {
743   // create a HDF group for SMESH_PreMeshInfo of this mesh
744   SMESH_Comment hdfGroupName("SMESH_PreMeshInfo"); hdfGroupName << meshID;
745   HDFgroup* infoHdfGroup = new HDFgroup( hdfGroupName, hdfFile );
746   infoHdfGroup->CreateOnDisk();
747
748   SMESH_TRY;
749
750   // info of mesh
751   meshInfo2hdf( mesh->GetMeshInfo(), "Mesh", infoHdfGroup );
752   
753   // info of groups
754   SMESH_PreMeshInfo incompleteInfo( 0,0,"","");
755   incompleteInfo.setNb( SMDSEntity_Node, GroupOnFilter_OutOfDate );
756   SMESHDS_Mesh* meshDS = mesh->GetImpl().GetMeshDS();
757
758   map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i2group = mesh->_mapGroups.begin();
759   for ( ; i2group != mesh->_mapGroups.end(); ++i2group )
760   {
761     if ( SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>( i2group->second ))
762     {
763       SMESHDS_GroupBase * group = group_i->GetGroupDS();
764       if ( SMESHDS_GroupOnFilter* gof = dynamic_cast<SMESHDS_GroupOnFilter*>(group))
765       {
766         // prevent too long storage time due to applying filter to many elements
767         if ( !gof->IsUpToDate() && meshDS->GetMeshInfo().NbElements( gof->GetType() ) > 1e5 )
768         {
769           meshInfo2hdf( incompleteInfo.GetMeshInfo(),
770                         group->GetStoreName(),
771                         infoHdfGroup);
772           continue;
773         }
774       }
775       meshInfo2hdf( group_i->GetMeshInfo(), group->GetStoreName(), infoHdfGroup);
776     }
777   }
778
779   // info of sub-meshes
780   map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = mesh->_mapSubMeshIor.begin();
781   for ( ; id2sm != mesh->_mapSubMeshIor.end(); ++id2sm )
782   {
783     if ( SMESH_subMesh_i* sm = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
784     {
785       meshInfo2hdf( sm->GetMeshInfo(),
786                     SMESH_Comment( sm->GetId() ),
787                     infoHdfGroup);
788     }
789   }
790
791   SMESH_CATCH( SMESH::doNothing );
792
793   infoHdfGroup->CloseOnDisk();
794 }
795
796 //================================================================================
797 /*!
798  * \brief Reads all data and remove all SMESH_PreMeshInfo fields from objects
799  */
800 //================================================================================
801
802 void SMESH_PreMeshInfo::FullLoadFromFile() const
803 {
804   SignalToGUI signalOnLoading( _mesh );
805
806   SMESH_PreMeshInfo* meshInfo = _mesh->changePreMeshInfo();
807   _mesh->changePreMeshInfo() = NULL; // to allow GUI accessing to real info
808
809   ::SMESH_Mesh&   mesh = _mesh->GetImpl();
810   SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
811
812   SMESH_TRY;
813
814   MYDEBUGOUT( "BEG FullLoadFromFile() " << _meshID );
815
816   // load mesh
817   DriverMED_R_SMESHDS_Mesh myReader;
818   myReader.SetFile( _medFileName.c_str() );
819   myReader.SetMesh( meshDS );
820   myReader.SetMeshId( _meshID );
821   myReader.Perform();
822
823   // load groups
824   const set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
825   set<SMESHDS_GroupBase*>::const_iterator groupIt = groups.begin();
826   for ( ; groupIt != groups.end(); ++groupIt )
827     if ( SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( *groupIt ))
828       myReader.GetGroup( aGrp );
829
830   // load sub-meshes
831   readSubMeshes( &myReader );
832
833   SMESH_CATCH( SMESH::doNothing );
834
835   _mesh->changePreMeshInfo() = meshInfo;
836
837   ForgetAllData();
838
839   signalOnLoading.sendStop();
840
841   meshDS->Modified();
842
843   // load dependent meshes referring/referred via hypotheses
844   SMESH_subMesh* mainSub = mesh.GetSubMesh( mesh.GetShapeToMesh() );
845   mainSub->ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED); // #16648 
846   mainSub->ComputeStateEngine (SMESH_subMesh::SUBMESH_LOADED);
847
848   MYDEBUGOUT( "END FullLoadFromFile()" );
849 }
850
851 //================================================================================
852 /*!
853  * \brief Reads full data of sub-meshes
854  */
855 //================================================================================
856
857 void SMESH_PreMeshInfo::readSubMeshes(DriverMED_R_SMESHDS_Mesh* reader) const
858 {
859   HDFfile* aFile = new HDFfile( (char*) _hdfFileName.c_str() );
860   aFile->OpenOnDisk( HDF_RDONLY );
861
862   char meshGrpName[ 30 ];
863   sprintf( meshGrpName, "Mesh %d", _meshID );
864   if ( aFile->ExistInternalObject( meshGrpName ) )
865   {
866     HDFgroup* aTopGroup = new HDFgroup( meshGrpName, aFile );
867     aTopGroup->OpenOnDisk();
868
869     SMESHDS_Mesh* meshDS = _mesh->GetImpl().GetMeshDS();
870
871     // issue 0020693. Restore _isModified flag
872     if ( aTopGroup->ExistInternalObject( "_isModified" ))
873     {
874       HDFdataset* aDataset = new HDFdataset( "_isModified", aTopGroup );
875       aDataset->OpenOnDisk();
876       hdf_size size = aDataset->GetSize();
877       int* isModified = new int[ size ];
878       aDataset->ReadFromDisk( isModified );
879       aDataset->CloseOnDisk();
880       _mesh->GetImpl().SetIsModified( bool(*isModified));
881       delete [] isModified;
882     }
883
884     bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
885     if ( submeshesInFamilies ) // from MED
886     {
887       // old way working before fix of PAL 12992
888       reader->CreateAllSubMeshes();
889     }
890     else
891     {
892       // open a group
893       HDFgroup* aGroup = new HDFgroup( "Submeshes", aTopGroup );
894       aGroup->OpenOnDisk();
895
896       int maxID = Max( meshDS->MaxSubMeshIndex(), meshDS->MaxShapeIndex() );
897       vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
898       vector< TopAbs_ShapeEnum  > smType   ( maxID + 1, TopAbs_SHAPE );
899
900       PositionCreator aPositionCreator;
901
902       SMDS_NodeIteratorPtr nIt = meshDS->nodesIterator();
903       SMDS_ElemIteratorPtr eIt = meshDS->elementsIterator();
904       for ( int isNode = 0; isNode < 2; ++isNode )
905       {
906         std::string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
907         if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
908         {
909           HDFdataset* aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
910           aDataset->OpenOnDisk();
911           // read submesh IDs for all elements sorted by ID
912           size_t nbElems = aDataset->GetSize();
913           int* smIDs = new int [ nbElems ];
914           aDataset->ReadFromDisk( smIDs );
915           aDataset->CloseOnDisk();
916
917           // get elements sorted by ID
918           TIDSortedElemSet elemSet;
919           if ( isNode )
920             while ( nIt->more() ) elemSet.insert( elemSet.end(), nIt->next() );
921           else
922             while ( eIt->more() ) elemSet.insert( elemSet.end(), eIt->next() );
923           //ASSERT( elemSet.size() == nbElems ); -- issue 20182
924           // -- Most probably a bad study was saved when there were
925           // not fixed bugs in SMDS_MeshInfo
926           if ( elemSet.size() < nbElems ) {
927 #ifdef _DEBUG_
928             cout << "SMESH_Gen_i::Load(), warning: Node position data is invalid" << endl;
929 #endif
930             nbElems = elemSet.size();
931           }
932           // add elements to sub-meshes
933           TIDSortedElemSet::iterator iE = elemSet.begin();
934           for ( size_t i = 0; i < nbElems; ++i, ++iE )
935           {
936             int smID = smIDs[ i ];
937             if ( smID == 0 ) continue;
938             const SMDS_MeshElement* elem = *iE;
939             if ( smID > maxID ) {
940               // corresponding subshape no longer exists: maybe geom group has been edited
941               if ( _mesh->GetImpl().HasShapeToMesh() )
942                 meshDS->RemoveElement( elem );
943               continue;
944             }
945             // get or create submesh
946             SMESHDS_SubMesh* & sm = subMeshes[ smID ];
947             if ( ! sm ) {
948               sm = meshDS->NewSubMesh( smID );
949               smType[ smID ] = meshDS->IndexToShape( smID ).ShapeType();
950             }
951             // add
952             if ( isNode ) {
953               SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
954               SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
955               node->SetPosition( pos, sm->GetID() );
956               sm->AddNode( node );
957             } else {
958               sm->AddElement( elem );
959             }
960           }
961           delete [] smIDs;
962         }
963       }
964     } // end reading submeshes
965
966     // Read node positions on sub-shapes (SMDS_Position)
967
968     if ( aTopGroup->ExistInternalObject( "Node Positions" ))
969     {
970       // There are 5 datasets to read:
971       // "Nodes on Edges" - ID of node on edge
972       // "Edge positions" - U parameter on node on edge
973       // "Nodes on Faces" - ID of node on face
974       // "Face U positions" - U parameter of node on face
975       // "Face V positions" - V parameter of node on face
976       const char* aEid_DSName = "Nodes on Edges";
977       const char* aEu_DSName  = "Edge positions";
978       const char* aFu_DSName  = "Face U positions";
979       //char* aFid_DSName = "Nodes on Faces";
980       //char* aFv_DSName  = "Face V positions";
981
982       // data to retrieve
983       int nbEids = 0, nbFids = 0;
984       int *aEids = 0, *aFids  = 0;
985       double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
986
987       // open a group
988       HDFgroup* aGroup = new HDFgroup( "Node Positions", aTopGroup );
989       aGroup->OpenOnDisk();
990
991       // loop on 5 data sets
992       int aNbObjects = aGroup->nInternalObjects();
993       for ( int i = 0; i < aNbObjects; i++ )
994       {
995         // identify dataset
996         char aDSName[ HDF_NAME_MAX_LEN+1 ];
997         aGroup->InternalObjectIndentify( i, aDSName );
998         // read data
999         HDFdataset* aDataset = new HDFdataset( aDSName, aGroup );
1000         aDataset->OpenOnDisk();
1001         if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
1002         {
1003           double* pos = new double [ aDataset->GetSize() ];
1004           aDataset->ReadFromDisk( pos );
1005           // which one?
1006           if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
1007             aEpos = pos;
1008           else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
1009             aFupos = pos;
1010           else
1011             aFvpos = pos;
1012         }
1013         else // NODE IDS
1014         {
1015           int aSize = aDataset->GetSize();
1016
1017           // for reading files, created from 18.07.2005 till 10.10.2005
1018           if (aDataset->GetType() == HDF_STRING)
1019             aSize /= sizeof(int);
1020
1021           int* ids = new int [aSize];
1022           aDataset->ReadFromDisk( ids );
1023           // on face or nodes?
1024           if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
1025             aEids = ids;
1026             nbEids = aSize;
1027           }
1028           else {
1029             aFids = ids;
1030             nbFids = aSize;
1031           }
1032         }
1033         aDataset->CloseOnDisk();
1034       } // loop on 5 datasets
1035
1036       // Set node positions on edges or faces
1037       for ( int onFace = 0; onFace < 2; onFace++ )
1038       {
1039         int nbNodes = ( onFace ? nbFids : nbEids );
1040         if ( nbNodes == 0 ) continue;
1041         int* aNodeIDs = ( onFace ? aFids : aEids );
1042         double* aUPos = ( onFace ? aFupos : aEpos );
1043         double* aVPos = ( onFace ? aFvpos : 0 );
1044         // loop on node IDs
1045         for ( int iNode = 0; iNode < nbNodes; iNode++ )
1046         {
1047           const SMDS_MeshNode* node = meshDS->FindNode( aNodeIDs[ iNode ]);
1048           if ( !node ) continue; // maybe removed while Loading() if geometry changed
1049           SMDS_PositionPtr aPos = node->GetPosition();
1050           ASSERT( aPos );
1051           if ( onFace ) {
1052             // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );-- issue 20182
1053             // -- Most probably a bad study was saved when there were
1054             // not fixed bugs in SMDS_MeshInfo
1055             if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
1056               SMDS_FacePositionPtr fPos = aPos;
1057               fPos->SetUParameter( aUPos[ iNode ]);
1058               fPos->SetVParameter( aVPos[ iNode ]);
1059             }
1060           }
1061           else {
1062             // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
1063             if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
1064               SMDS_EdgePositionPtr ePos = aPos;
1065               ePos->SetUParameter( aUPos[ iNode ]);
1066             }
1067           }
1068         }
1069       }
1070       if ( aEids ) delete [] aEids;
1071       if ( aFids ) delete [] aFids;
1072       if ( aEpos ) delete [] aEpos;
1073       if ( aFupos ) delete [] aFupos;
1074       if ( aFvpos ) delete [] aFvpos;
1075
1076       aGroup->CloseOnDisk();
1077
1078     } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
1079
1080     aTopGroup->CloseOnDisk();
1081   } // if ( aFile->ExistInternalObject( meshGrpName ) )
1082   
1083   aFile->CloseOnDisk();
1084   delete aFile;
1085 }
1086
1087 //================================================================================
1088 /*!
1089  * \brief Remove all SMESH_PreMeshInfo fields from objects w/o data loading
1090  */
1091 //================================================================================
1092
1093 void SMESH_PreMeshInfo::ForgetAllData() const
1094 {
1095   SMESH_TRY;
1096
1097   if ( _mesh->changePreMeshInfo() != this )
1098     return _mesh->changePreMeshInfo()->ForgetAllData();
1099
1100   // remove SMESH_PreMeshInfo from groups
1101   map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i2group = _mesh->_mapGroups.begin();
1102   for ( ; i2group != _mesh->_mapGroups.end(); ++i2group )
1103   {
1104     if ( SMESH_GroupBase_i* group_i =
1105          SMESH::DownCast<SMESH_GroupBase_i*>( i2group->second ))
1106     {
1107       SMESH_PreMeshInfo* & info = group_i->changePreMeshInfo();
1108       delete info;
1109       info = NULL;
1110     }
1111   }
1112   // remove SMESH_PreMeshInfo from sub-meshes
1113   map<int, SMESH::SMESH_subMesh_ptr>::iterator id2sm = _mesh->_mapSubMeshIor.begin();
1114   for ( ; id2sm != _mesh->_mapSubMeshIor.end(); ++id2sm )
1115   {
1116     if ( SMESH_subMesh_i* sm_i = SMESH::DownCast<SMESH_subMesh_i*>( id2sm->second ))
1117     {
1118       SMESH_PreMeshInfo* & info = sm_i->changePreMeshInfo();
1119       delete info;
1120       info = NULL;
1121     }
1122   }
1123   // remove SMESH_PreMeshInfo from the mesh
1124   _mesh->changePreMeshInfo() = NULL;
1125   delete this;
1126
1127   SMESH_CATCH( SMESH::doNothing );
1128
1129
1130   // Finalize loading
1131
1132   // SMESH_TRY;
1133
1134   // ::SMESH_Mesh& mesh = _mesh->GetImpl();
1135
1136   // // update hyps needing full mesh data restored (issue 20918)
1137   // // map<int, SMESH::SMESH_Hypothesis_ptr>::iterator id2hyp= _mesh->_mapHypo.begin();
1138   // // for ( ; id2hyp != _mesh->_mapHypo.end(); ++id2hyp )
1139   // //   if ( SMESH_Hypothesis_i* hyp = SMESH::DownCast<SMESH_Hypothesis_i*>( id2hyp->second ))
1140   // //     hyp->UpdateAsMeshesRestored();
1141
1142
1143   // SMESH_CATCH( SMESH::doNothing );
1144 }
1145
1146 //================================================================================
1147 /*!
1148  * \brief remove all SMESH_PreMeshInfo fields from mesh and its child objects w/o data loading
1149  */
1150 //================================================================================
1151
1152 void SMESH_PreMeshInfo::ForgetAllData( SMESH_Mesh_i* mesh )
1153 {
1154   if ( mesh && mesh->changePreMeshInfo() )
1155     mesh->changePreMeshInfo()->ForgetAllData();
1156 }
1157
1158 //================================================================================
1159 /*!
1160  * \brief Calls either FullLoadFromFile() or ForgetAllData() depending on preferences
1161  */
1162 //================================================================================
1163
1164 void SMESH_PreMeshInfo::ForgetOrLoad() const
1165 {
1166   if ( SMESH_Gen_i::GetSMESHGen()->ToForgetMeshDataOnHypModif() &&
1167        _mesh->HasShapeToMesh())
1168     ForgetAllData();
1169   else
1170     FullLoadFromFile();
1171 }
1172
1173 //================================================================================
1174 /*!
1175  * \brief Method of SMESH_IDSource interface
1176  */
1177 //================================================================================
1178
1179 SMESH::array_of_ElementType* SMESH_PreMeshInfo::GetTypes() const
1180 {
1181   SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
1182
1183   types->length( 4 );
1184   int nbTypes = 0;
1185   if (NbEdges())      types[nbTypes++] = SMESH::EDGE;
1186   if (NbFaces())      types[nbTypes++] = SMESH::FACE;
1187   if (NbVolumes())    types[nbTypes++] = SMESH::VOLUME;
1188   if (Nb0DElements()) types[nbTypes++] = SMESH::ELEM0D;
1189   if (NbBalls())      types[nbTypes++] = SMESH::BALL;
1190   types->length( nbTypes );
1191
1192   return types._retn();
1193 }
1194
1195 //================================================================================
1196 /*!
1197  * \brief Method of SMESH_IDSource interface returning nb elements by element type
1198  */
1199 //================================================================================
1200
1201 SMESH::long_array* SMESH_PreMeshInfo::GetMeshInfo() const
1202 {
1203   SMESH::long_array_var aRes = new SMESH::long_array();
1204   aRes->length(SMESH::Entity_Last);
1205   for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
1206     aRes[i] = 0;
1207
1208   for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
1209     aRes[i] = NbEntities((SMDSAbs_EntityType)i);
1210   return aRes._retn();
1211 }
1212
1213 //================================================================================
1214 /*!
1215  * Returns false if GetMeshInfo() returns incorrect information that may
1216  * happen if mesh data is not yet fully loaded from the file of study.
1217  */
1218 //================================================================================
1219
1220 bool SMESH_PreMeshInfo::IsMeshInfoCorrect() const
1221 {
1222   return _isInfoOk;
1223 }
1224
1225 //================================================================================
1226 /*!
1227  * \brief TEMPORARY method to remove study files on closing study;
1228  * RIGHT WAY: study files are remove automatically when meshes are destroyed
1229  */
1230 //================================================================================
1231
1232 void SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD(SALOMEDS::SComponent_ptr smeshComp)
1233 {
1234   if ( theMeshCounter > 0 )
1235   {
1236     SALOMEDS::ChildIterator_wrap itBig = SMESH_Gen_i::getStudyServant()->NewChildIterator( smeshComp );
1237     for ( ; itBig->More(); itBig->Next() ) {
1238       SALOMEDS::SObject_wrap gotBranch = itBig->Value();
1239       CORBA::Object_var       anObject = SMESH_Gen_i::SObjectToObject( gotBranch );
1240       if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( anObject ))
1241       {
1242         if ( mesh->changePreMeshInfo() )
1243         {
1244           mesh->changePreMeshInfo()->ForgetAllData();
1245         }
1246       }
1247     }
1248   }
1249 }