1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Gen_i.cxx
25 // Author : Paul RASCLE, EDF
30 #include <TopExp_Explorer.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <TopoDS_CompSolid.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopTools_MapOfShape.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <TopTools_ListOfShape.hxx>
45 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TCollection_AsciiString.hxx>
51 #include "Utils_CorbaException.hxx"
53 #include "utilities.h"
64 #define LibHandle HMODULE
65 #define LoadLib( name ) LoadLibrary( name )
66 #define GetProc GetProcAddress
67 #define UnLoadLib( handle ) FreeLibrary( handle );
69 #define LibHandle void*
70 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
72 #define UnLoadLib( handle ) dlclose( handle );
77 #include "SMESH_Gen_i.hxx"
78 #include "SMESH_Mesh_i.hxx"
79 #include "SMESH_Hypothesis_i.hxx"
80 #include "SMESH_Algo_i.hxx"
81 #include "SMESH_Group_i.hxx"
82 #include "SMESH_PythonDump.hxx"
84 #include "SMESHDS_Document.hxx"
85 #include "SMESHDS_Group.hxx"
86 #include "SMESHDS_GroupOnGeom.hxx"
87 #include "SMESH_Mesh.hxx"
88 #include "SMESH_Hypothesis.hxx"
89 #include "SMESH_Group.hxx"
90 #include "SMESH_MeshEditor.hxx"
92 #include "SMDS_EdgePosition.hxx"
93 #include "SMDS_FacePosition.hxx"
94 #include "SMDS_VertexPosition.hxx"
95 #include "SMDS_SpacePosition.hxx"
97 #include CORBA_SERVER_HEADER(SMESH_Group)
98 #include CORBA_SERVER_HEADER(SMESH_Filter)
100 #include "DriverMED_W_SMESHDS_Mesh.h"
101 #include "DriverMED_R_SMESHDS_Mesh.h"
103 #include "SALOMEDS_Tool.hxx"
104 #include "SALOME_NamingService.hxx"
105 #include "SALOME_LifeCycleCORBA.hxx"
106 #include "Utils_SINGLETON.hxx"
107 #include "OpUtil.hxx"
109 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
111 #include "GEOM_Client.hxx"
112 #include "Utils_ExceptHandlers.hxx"
117 using SMESH::TPythonDump;
119 #define NUM_TMP_FILES 2
122 static int MYDEBUG = 0;
124 static int MYDEBUG = 0;
127 // Static variables definition
128 CORBA::ORB_var SMESH_Gen_i::myOrb;
129 PortableServer::POA_var SMESH_Gen_i::myPoa;
130 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
131 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
132 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
134 //=============================================================================
136 * GetServant [ static ]
138 * Get servant of the CORBA object
140 //=============================================================================
142 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
144 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
147 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
151 INFOS( "GetServant - Unknown exception was caught!!!" );
156 //=============================================================================
158 * SObjectToObject [ static ]
160 * Get CORBA object corresponding to the SALOMEDS::SObject
162 //=============================================================================
164 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
166 SALOMEDS::GenericAttribute_var anAttr;
167 CORBA::Object_var anObj;
168 if ( !theSObject->_is_nil() ) {
170 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
171 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
172 CORBA::String_var aValue = anIOR->Value();
173 if( strcmp( aValue, "" ) != 0 )
174 anObj = GetORB()->string_to_object( aValue );
178 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
184 //=============================================================================
188 * Get SALOME_NamingService object
190 //=============================================================================
192 SALOME_NamingService* SMESH_Gen_i::GetNS()
194 if ( myNS == NULL ) {
195 myNS = SINGLETON_<SALOME_NamingService>::Instance();
196 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
197 myNS->init_orb( GetORB() );
202 //=============================================================================
206 * Get SALOME_LifeCycleCORBA object
208 //=============================================================================
209 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
210 if ( myLCC == NULL ) {
211 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
217 //=============================================================================
219 * GetGeomEngine [ static ]
221 * Get GEOM::GEOM_Gen reference
223 //=============================================================================
224 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
225 GEOM::GEOM_Gen_var aGeomEngine =
226 GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
227 return aGeomEngine._retn();
230 //=============================================================================
232 * SMESH_Gen_i::SMESH_Gen_i
234 * Default constructor: not for use
236 //=============================================================================
238 SMESH_Gen_i::SMESH_Gen_i()
240 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
243 //=============================================================================
245 * SMESH_Gen_i::SMESH_Gen_i
247 * Standard constructor, used with Container
249 //=============================================================================
251 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
252 PortableServer::POA_ptr poa,
253 PortableServer::ObjectId* contId,
254 const char* instanceName,
255 const char* interfaceName )
256 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
258 INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
260 myOrb = CORBA::ORB::_duplicate(orb);
261 myPoa = PortableServer::POA::_duplicate(poa);
264 _id = myPoa->activate_object( _thisObj );
266 myIsEmbeddedMode = false;
267 myShapeReader = NULL; // shape reader
270 // set it in standalone mode only
271 //OSD::SetSignal( true );
274 //=============================================================================
276 * SMESH_Gen_i::~SMESH_Gen_i
280 //=============================================================================
282 SMESH_Gen_i::~SMESH_Gen_i()
284 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
286 // delete hypothesis creators
287 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
288 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
290 delete (*itHyp).second;
292 myHypCreatorMap.clear();
294 // Clear study contexts data
295 map<int, StudyContext*>::iterator it;
296 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
299 myStudyContextMap.clear();
300 // delete shape reader
301 if ( !myShapeReader )
302 delete myShapeReader;
305 //=============================================================================
307 * SMESH_Gen_i::createHypothesis
309 * Create hypothesis of given type
311 //=============================================================================
312 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
313 const char* theLibName)
314 throw (SALOME::SALOME_Exception)
316 /* It's Need to tranlate lib name for WIN32 or X platform */
317 char* aPlatformLibName = 0;
318 if ( theLibName && theLibName[0] != '\0' )
320 int libNameLen = strlen(theLibName);
321 //check for old format "libXXXXXXX.so"
322 if( libNameLen > 7 && !strncmp( theLibName, "lib", 3 ) && !strcmp( theLibName+libNameLen-3, ".so" ) )
326 aPlatformLibName = new char[libNameLen - 1];
327 aPlatformLibName[0] = '\0';
328 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
329 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
330 aPlatformLibName[libNameLen - 2] = '\0';
332 aPlatformLibName = new char[ libNameLen + 1];
333 aPlatformLibName[0] = '\0';
334 aPlatformLibName = strcat( aPlatformLibName, theLibName );
335 aPlatformLibName[libNameLen] = '\0';
341 //try to use new format
343 aPlatformLibName = new char[ libNameLen + 5 ];
344 aPlatformLibName[0] = '\0';
345 aPlatformLibName = strcat( aPlatformLibName, theLibName );
346 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
348 aPlatformLibName = new char[ libNameLen + 7 ];
349 aPlatformLibName[0] = '\0';
350 aPlatformLibName = strcat( aPlatformLibName, "lib" );
351 aPlatformLibName = strcat( aPlatformLibName, theLibName );
352 aPlatformLibName = strcat( aPlatformLibName, ".so" );
359 Unexpect aCatch(SALOME_SalomeException);
360 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
362 // create a new hypothesis object servant
363 SMESH_Hypothesis_i* myHypothesis_i = 0;
364 SMESH::SMESH_Hypothesis_var hypothesis_i;
368 // check, if creator for this hypothesis type already exists
369 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
371 // load plugin library
372 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
373 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
376 // report any error, if occured
378 const char* anError = dlerror();
379 throw(SALOME_Exception(anError));
381 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
385 // get method, returning hypothesis creator
386 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
387 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
388 GetHypothesisCreator procHandle =
389 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
392 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
393 UnLoadLib(libHandle);
396 // get hypothesis creator
397 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
398 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
401 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
404 // map hypothesis creator to a hypothesis name
405 myHypCreatorMap[string(theHypName)] = aCreator;
408 // create a new hypothesis object, store its ref. in studyContext
409 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
411 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
412 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
414 catch (SALOME_Exception& S_ex)
416 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
419 if ( aPlatformLibName )
420 delete[] aPlatformLibName;
423 return hypothesis_i._retn();
425 // activate the CORBA servant of hypothesis
426 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
427 int nextId = RegisterObject( hypothesis_i );
428 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
430 return hypothesis_i._retn();
433 //=============================================================================
435 * SMESH_Gen_i::createMesh
437 * Create empty mesh on shape
439 //=============================================================================
440 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
441 throw ( SALOME::SALOME_Exception )
443 Unexpect aCatch(SALOME_SalomeException);
444 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
446 // Get or create the GEOM_Client instance
448 // create a new mesh object servant, store it in a map in study context
449 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
450 // create a new mesh object
451 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
453 // activate the CORBA servant of Mesh
454 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
455 int nextId = RegisterObject( mesh );
456 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
459 catch (SALOME_Exception& S_ex) {
460 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
462 return SMESH::SMESH_Mesh::_nil();
465 //=============================================================================
467 * SMESH_Gen_i::GetShapeReader
471 //=============================================================================
472 GEOM_Client* SMESH_Gen_i::GetShapeReader()
474 // create shape reader if necessary
475 if ( !myShapeReader )
476 myShapeReader = new GEOM_Client(GetContainerRef());
477 ASSERT( myShapeReader );
478 return myShapeReader;
481 //=============================================================================
483 * SMESH_Gen_i::SetEmbeddedMode
487 //=============================================================================
489 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
491 myIsEmbeddedMode = theMode;
493 if ( !myIsEmbeddedMode ) {
494 //PAL10867: disable signals catching with "noexcepthandler" option
495 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
496 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
501 char* envDisableFPE = getenv("DISABLE_FPE");
502 if (envDisableFPE && atoi(envDisableFPE))
507 OSD::SetSignal( raiseFPE );
509 // else OSD::SetSignal() is called in GUI
513 //=============================================================================
515 * SMESH_Gen_i::IsEmbeddedMode
519 //=============================================================================
521 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
523 return myIsEmbeddedMode;
526 //=============================================================================
528 * SMESH_Gen_i::SetCurrentStudy
532 //=============================================================================
534 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
537 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
538 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
539 // create study context, if it doesn't exist and set current study
540 int studyId = GetCurrentStudyID();
541 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
542 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
543 myStudyContextMap[ studyId ] = new StudyContext;
546 // myCurrentStudy may be nil
547 if ( !CORBA::is_nil( myCurrentStudy ) ) {
548 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
549 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
550 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
552 // set current study for geom engine
553 //if ( !CORBA::is_nil( GetGeomEngine() ) )
554 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
558 //=============================================================================
560 * SMESH_Gen_i::GetCurrentStudy
564 //=============================================================================
566 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
568 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
569 return SALOMEDS::Study::_duplicate( myCurrentStudy );
572 //=============================================================================
574 * SMESH_Gen_i::GetCurrentStudyContext
576 * Get current study context
578 //=============================================================================
579 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
581 if ( !CORBA::is_nil( myCurrentStudy ) &&
582 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
583 return myStudyContextMap[ myCurrentStudy->StudyId() ];
588 //=============================================================================
590 * SMESH_Gen_i::CreateHypothesis
592 * Create hypothesis/algorothm of given type and publish it in the study
594 //=============================================================================
596 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
597 const char* theLibName )
598 throw ( SALOME::SALOME_Exception )
600 Unexpect aCatch(SALOME_SalomeException);
601 // Create hypothesis/algorithm
602 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
604 // Publish hypothesis/algorithm in the study
605 if ( CanPublishInStudy( hyp ) ) {
606 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
607 if ( !aSO->_is_nil() ) {
608 // Update Python script
609 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
610 << theHypName << "', '" << theLibName << "')";
617 //================================================================================
619 * \brief Return hypothesis of given type holding parameter values of the existing mesh
620 * \param theHypType - hypothesis type name
621 * \param theLibName - plugin library name
622 * \param theMesh - The mesh of interest
623 * \param theGeom - The shape to get parameter values from
624 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
625 * in a study and used to compute the mesh, or a temporary one created just to pass
628 //================================================================================
630 SMESH::SMESH_Hypothesis_ptr
631 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
632 const char* theLibName,
633 SMESH::SMESH_Mesh_ptr theMesh,
634 GEOM::GEOM_Object_ptr theGeom)
635 throw ( SALOME::SALOME_Exception )
637 Unexpect aCatch(SALOME_SalomeException);
638 if ( CORBA::is_nil( theMesh ) )
639 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
640 if ( CORBA::is_nil( theGeom ) )
641 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
643 // -----------------------------------------------
644 // find hypothesis used to mesh theGeom
645 // -----------------------------------------------
647 // get mesh and shape
648 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
649 TopoDS_Shape shape = GeomObjectToShape( theGeom );
650 if ( !meshServant || shape.IsNull() )
651 return SMESH::SMESH_Hypothesis::_nil();
652 ::SMESH_Mesh& mesh = meshServant->GetImpl();
654 if ( mesh.NbNodes() == 0 ) // empty mesh
655 return SMESH::SMESH_Hypothesis::_nil();
657 // create a temporary hypothesis to know its dimention
658 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
659 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
661 return SMESH::SMESH_Hypothesis::_nil();
662 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
664 // look for a hypothesis of theHypType used to mesh the shape
665 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
668 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
669 int nbLocalHyps = aHypList->length();
670 for ( int i = 0; i < nbLocalHyps; i++ )
671 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
672 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
673 // check super shapes
674 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
675 while ( nbLocalHyps == 0 && itShape.More() ) {
676 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
677 if ( ! CORBA::is_nil( geomObj )) {
678 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
679 nbLocalHyps = aHypList->length();
680 for ( int i = 0; i < nbLocalHyps; i++ )
681 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
682 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
688 // let the temporary hypothesis find out some how parameter values
689 if ( hyp->SetParametersByMesh( &mesh, shape ))
690 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
692 return SMESH::SMESH_Hypothesis::_nil();
695 //=============================================================================
697 * SMESH_Gen_i::CreateMesh
699 * Create empty mesh on a shape and publish it in the study
701 //=============================================================================
703 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
704 throw ( SALOME::SALOME_Exception )
706 Unexpect aCatch(SALOME_SalomeException);
707 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
709 SMESH::SMESH_Mesh_var mesh = this->createMesh();
711 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
712 ASSERT( meshServant );
713 meshServant->SetShape( theShapeObject );
715 // publish mesh in the study
716 if ( CanPublishInStudy( mesh ) ) {
717 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
718 aStudyBuilder->NewCommand(); // There is a transaction
719 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
720 aStudyBuilder->CommitCommand();
721 if ( !aSO->_is_nil() ) {
722 // Update Python script
723 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
730 //=============================================================================
732 * SMESH_Gen_i::CreateEmptyMesh
736 //=============================================================================
738 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
739 throw ( SALOME::SALOME_Exception )
741 Unexpect aCatch(SALOME_SalomeException);
742 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
744 SMESH::SMESH_Mesh_var mesh = this->createMesh();
746 // publish mesh in the study
747 if ( CanPublishInStudy( mesh ) ) {
748 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
749 aStudyBuilder->NewCommand(); // There is a transaction
750 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
751 aStudyBuilder->CommitCommand();
752 if ( !aSO->_is_nil() ) {
753 // Update Python script
754 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
761 //=============================================================================
763 * SMESH_Gen_i::CreateMeshFromUNV
765 * Create mesh and import data from UNV file
767 //=============================================================================
769 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
770 throw ( SALOME::SALOME_Exception )
772 Unexpect aCatch(SALOME_SalomeException);
773 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
775 SMESH::SMESH_Mesh_var aMesh = createMesh();
777 // publish mesh in the study
778 if ( CanPublishInStudy( aMesh ) ) {
779 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
780 aStudyBuilder->NewCommand(); // There is a transaction
781 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
782 aStudyBuilder->CommitCommand();
783 if ( !aSO->_is_nil() ) {
784 // Update Python script
785 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
789 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
791 aServant->ImportUNVFile( theFileName );
793 // Dump creation of groups
794 aServant->GetGroups();
796 return aMesh._retn();
799 //=============================================================================
801 * SMESH_Gen_i::CreateMeshFromMED
803 * Create mesh and import data from MED file
805 //=============================================================================
807 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
808 SMESH::DriverMED_ReadStatus& theStatus)
809 throw ( SALOME::SALOME_Exception )
811 Unexpect aCatch(SALOME_SalomeException);
812 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
814 // Retrieve mesh names from the file
815 DriverMED_R_SMESHDS_Mesh myReader;
816 myReader.SetFile( theFileName );
817 myReader.SetMeshId( -1 );
818 Driver_Mesh::Status aStatus;
819 list<string> aNames = myReader.GetMeshNames(aStatus);
820 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
821 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
823 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
826 TPythonDump aPythonDump;
828 //TCollection_AsciiString aStr ("([");
830 if (theStatus == SMESH::DRS_OK) {
831 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
832 aStudyBuilder->NewCommand(); // There is a transaction
833 aResult->length( aNames.size() );
836 // Iterate through all meshes and create mesh objects
837 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
839 //if (i > 0) aStr += ", ";
840 if (i > 0) aPythonDump << ", ";
843 SMESH::SMESH_Mesh_var mesh = createMesh();
845 // publish mesh in the study
846 SALOMEDS::SObject_var aSO;
847 if ( CanPublishInStudy( mesh ) )
848 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
849 if ( !aSO->_is_nil() ) {
852 //aStr += aSO->GetID();
855 aPythonDump << "mesh_" << i;
857 // aStr += TCollection_AsciiString(i);
860 // Read mesh data (groups are published automatically by ImportMEDFile())
861 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
862 ASSERT( meshServant );
863 SMESH::DriverMED_ReadStatus status1 =
864 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
865 if (status1 > theStatus)
868 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
870 aStudyBuilder->CommitCommand();
873 // Update Python script
874 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
876 // Dump creation of groups
877 for ( int i = 0; i < aResult->length(); ++i )
878 aResult[ i ]->GetGroups();
880 return aResult._retn();
883 //=============================================================================
885 * SMESH_Gen_i::CreateMeshFromSTL
887 * Create mesh and import data from STL file
889 //=============================================================================
891 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
892 throw ( SALOME::SALOME_Exception )
894 Unexpect aCatch(SALOME_SalomeException);
895 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
897 SMESH::SMESH_Mesh_var aMesh = createMesh();
899 // publish mesh in the study
900 if ( CanPublishInStudy( aMesh ) ) {
901 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
902 aStudyBuilder->NewCommand(); // There is a transaction
903 SALOMEDS::SObject_var aSO = PublishInStudy
904 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
905 aStudyBuilder->CommitCommand();
906 if ( !aSO->_is_nil() ) {
907 // Update Python script
908 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
912 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
914 aServant->ImportSTLFile( theFileName );
915 return aMesh._retn();
918 //=============================================================================
920 * SMESH_Gen_i::IsReadyToCompute
922 * Returns true if mesh contains enough data to be computed
924 //=============================================================================
926 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
927 GEOM::GEOM_Object_ptr theShapeObject )
928 throw ( SALOME::SALOME_Exception )
930 Unexpect aCatch(SALOME_SalomeException);
931 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
933 if ( CORBA::is_nil( theShapeObject ) )
934 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
937 if ( CORBA::is_nil( theMesh ) )
938 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
943 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
944 ASSERT( meshServant );
946 // get local TopoDS_Shape
947 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
948 // call implementation
949 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
950 return myGen.CheckAlgoState( myLocMesh, myLocShape );
953 catch ( SALOME_Exception& S_ex ) {
954 INFOS( "catch exception "<< S_ex.what() );
959 //================================================================================
961 * \brief Returns errors of hypotheses definintion
962 * \param theMesh - the mesh
963 * \param theSubObject - the main or sub- shape
964 * \retval SMESH::algo_error_array* - sequence of errors
966 //================================================================================
968 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
969 GEOM::GEOM_Object_ptr theSubObject )
970 throw ( SALOME::SALOME_Exception )
972 Unexpect aCatch(SALOME_SalomeException);
973 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
975 if ( CORBA::is_nil( theSubObject ) )
976 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
978 if ( CORBA::is_nil( theMesh ) )
979 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
981 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
983 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
984 ASSERT( meshServant );
986 TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
987 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
988 list< ::SMESH_Gen::TAlgoStateError > error_list;
989 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
990 // call ::SMESH_Gen::GetAlgoState()
991 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
992 error_array->length( error_list.size() );
994 for ( error = error_list.begin(); error != error_list.end(); ++error )
997 SMESH::AlgoStateErrorName errName;
998 switch ( error->_name ) {
999 case ::SMESH_Gen::MISSING_ALGO: errName = SMESH::MISSING_ALGO; break;
1000 case ::SMESH_Gen::MISSING_HYPO: errName = SMESH::MISSING_HYPO; break;
1001 case ::SMESH_Gen::NOT_CONFORM_MESH: errName = SMESH::NOT_CONFORM_MESH; break;
1002 case ::SMESH_Gen::BAD_PARAM_VALUE: errName = SMESH::BAD_PARAM_VALUE; break;
1004 THROW_SALOME_CORBA_EXCEPTION( "bad error name",SALOME::BAD_PARAM );
1007 CORBA::String_var algoName;
1008 if ( error->_algo ) {
1009 if ( !myCurrentStudy->_is_nil() ) {
1010 // find algo in the study
1011 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
1012 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
1013 if ( !father->_is_nil() ) {
1014 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
1015 for ( ; itBig->More(); itBig->Next() ) {
1016 SALOMEDS::SObject_var gotBranch = itBig->Value();
1017 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1018 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1019 for ( ; algoIt->More(); algoIt->Next() ) {
1020 SALOMEDS::SObject_var algoSO = algoIt->Value();
1021 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1022 if ( !CORBA::is_nil( algoIOR )) {
1023 SMESH_Hypothesis_i* myImpl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1024 if ( myImpl && myImpl->GetImpl() == error->_algo ) {
1025 algoName = algoSO->GetName();
1029 } // loop on algo SO's
1032 } // SMESH component iterator
1035 if ( algoName.in() == 0 )
1036 // use algo type name
1037 algoName = CORBA::string_dup( error->_algo->GetName() );
1039 // fill AlgoStateError structure
1040 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1041 errStruct.name = errName;
1042 errStruct.algoName = algoName;
1043 errStruct.algoDim = error->_algoDim;
1044 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1048 catch ( SALOME_Exception& S_ex ) {
1049 INFOS( "catch exception "<< S_ex.what() );
1051 return error_array._retn();
1054 //=============================================================================
1056 * SMESH_Gen_i::GetSubShapesId
1058 * Get sub-shapes unique ID's list
1060 //=============================================================================
1062 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1063 const SMESH::object_array& theListOfSubShapeObject )
1064 throw ( SALOME::SALOME_Exception )
1066 Unexpect aCatch(SALOME_SalomeException);
1067 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1069 SMESH::long_array_var shapesId = new SMESH::long_array;
1072 if ( CORBA::is_nil( theMainShapeObject ) )
1073 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1074 SALOME::BAD_PARAM );
1078 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1079 TopTools_IndexedMapOfShape myIndexToShape;
1080 TopExp::MapShapes(myMainShape,myIndexToShape);
1082 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1084 GEOM::GEOM_Object_var aShapeObject
1085 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1086 if ( CORBA::is_nil( aShapeObject ) )
1087 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1088 SALOME::BAD_PARAM );
1090 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1091 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1093 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1094 setId.insert(myIndexToShape.FindIndex(F));
1095 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1097 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1099 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1100 setId.insert(myIndexToShape.FindIndex(E));
1101 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1103 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1105 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1106 setId.insert(myIndexToShape.FindIndex(V));
1107 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1110 shapesId->length(setId.size());
1111 set<int>::iterator iind;
1113 for (iind = setId.begin(); iind != setId.end(); iind++)
1115 if(MYDEBUG) SCRUTE((*iind));
1116 shapesId[i] = (*iind);
1117 if(MYDEBUG) SCRUTE(shapesId[i]);
1121 catch (SALOME_Exception& S_ex)
1123 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1126 return shapesId._retn();
1129 //=============================================================================
1131 * SMESH_Gen_i::Compute
1133 * Compute mesh on a shape
1135 //=============================================================================
1137 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1138 GEOM::GEOM_Object_ptr theShapeObject )
1139 throw ( SALOME::SALOME_Exception )
1141 Unexpect aCatch(SALOME_SalomeException);
1142 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1144 if ( CORBA::is_nil( theShapeObject ) )
1145 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1146 SALOME::BAD_PARAM );
1148 if ( CORBA::is_nil( theMesh ) )
1149 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1150 SALOME::BAD_PARAM );
1152 // Update Python script
1153 TPythonDump() << "isDone = " << this << ".Compute( "
1154 << theMesh << ", " << theShapeObject << ")";
1155 TPythonDump() << "if not isDone: print 'Mesh', " << theMesh << ", ': computation failed'";
1159 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1160 ASSERT( meshServant );
1161 if ( meshServant ) {
1162 // get local TopoDS_Shape
1163 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1164 // call implementation compute
1165 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1166 return myGen.Compute( myLocMesh, myLocShape);
1169 catch ( std::bad_alloc& exc ) {
1170 THROW_SALOME_CORBA_EXCEPTION( "Memory allocation problem",
1171 SALOME::INTERNAL_ERROR );
1173 catch ( SALOME_Exception& S_ex ) {
1174 INFOS( "Compute(): catch exception "<< S_ex.what() );
1177 INFOS( "Compute(): unknown exception " );
1182 //================================================================================
1184 * \brief Return geometrical object the given element is built on
1185 * \param theMesh - the mesh the element is in
1186 * \param theElementID - the element ID
1187 * \param theGeomName - the name of the result geom object if it is not yet published
1188 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1190 //================================================================================
1192 GEOM::GEOM_Object_ptr
1193 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1194 CORBA::Long theElementID,
1195 const char* theGeomName)
1196 throw ( SALOME::SALOME_Exception )
1198 Unexpect aCatch(SALOME_SalomeException);
1200 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
1201 if ( !geom->_is_nil() ) {
1202 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1203 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1205 // try to find the corresponding SObject
1206 GeomObjectToShape( geom ); // geom client remembers the found shape
1207 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1208 if ( SObj->_is_nil() )
1209 // publish a new subshape
1210 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1211 // return only published geometry
1212 if ( !SObj->_is_nil() )
1213 return geom._retn();
1215 return GEOM::GEOM_Object::_nil();
1219 //================================================================================
1221 * \brief Return geometrical object the given element is built on.
1222 * \param theMesh - the mesh the element is in
1223 * \param theElementID - the element ID
1224 * \retval GEOM::GEOM_Object_ptr - the found geom object
1226 //================================================================================
1228 GEOM::GEOM_Object_ptr
1229 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1230 CORBA::Long theElementID)
1231 throw ( SALOME::SALOME_Exception )
1233 Unexpect aCatch(SALOME_SalomeException);
1234 if ( CORBA::is_nil( theMesh ) )
1235 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1237 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1238 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1240 // get a core mesh DS
1241 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1242 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1244 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1245 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1246 // find the element in mesh
1247 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
1248 // find a shape id by the element
1249 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1250 // get a geom object by the shape id
1251 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1252 if ( geom->_is_nil() ) {
1253 GEOM::GEOM_IShapesOperations_var op =
1254 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1255 if ( !op->_is_nil() )
1256 geom = op->GetSubShape( mainShape, shapeID );
1258 if ( !geom->_is_nil() )
1259 return geom._retn();
1262 return GEOM::GEOM_Object::_nil();
1265 //=============================================================================
1269 * Save SMESH module's data
1271 //=============================================================================
1272 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1276 INFOS( "SMESH_Gen_i::Save" );
1278 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1279 // san -- in case <myCurrentStudy> differs from theComponent's study,
1280 // use that of the component
1281 if ( myCurrentStudy->_is_nil() ||
1282 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1283 SetCurrentStudy( theComponent->GetStudy() );
1285 // Store study contents as a set of python commands
1286 SavePython(myCurrentStudy);
1288 StudyContext* myStudyContext = GetCurrentStudyContext();
1290 // Declare a byte stream
1291 SALOMEDS::TMPFile_var aStreamFile;
1293 // Obtain a temporary dir
1294 TCollection_AsciiString tmpDir =
1295 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1297 // Create a sequence of files processed
1298 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1299 aFileSeq->length( NUM_TMP_FILES );
1301 TCollection_AsciiString aStudyName( "" );
1303 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1305 // Set names of temporary files
1306 TCollection_AsciiString filename =
1307 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1308 TCollection_AsciiString meshfile =
1309 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1310 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1311 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1312 filename = tmpDir + filename;
1313 meshfile = tmpDir + meshfile;
1316 HDFdataset* aDataset;
1317 HDFgroup* aTopGroup;
1319 HDFgroup* aSubGroup;
1320 HDFgroup* aSubSubGroup;
1321 hdf_size aSize[ 1 ];
1324 //Remove the files if they exist: BugID: 11225
1325 #ifndef WNT /* unix functionality */
1326 TCollection_AsciiString cmd("rm -f \"");
1328 TCollection_AsciiString cmd("del /F \"");
1335 system(cmd.ToCString());
1337 // MED writer to be used by storage process
1338 DriverMED_W_SMESHDS_Mesh myWriter;
1339 myWriter.SetFile( meshfile.ToCString() );
1342 // ---> create HDF file
1343 aFile = new HDFfile( filename.ToCString() );
1344 aFile->CreateOnDisk();
1346 // --> iterator for top-level objects
1347 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1348 for ( ; itBig->More(); itBig->Next() ) {
1349 SALOMEDS::SObject_var gotBranch = itBig->Value();
1351 // --> hypotheses root branch (only one for the study)
1352 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1353 // create hypotheses root HDF group
1354 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1355 aTopGroup->CreateOnDisk();
1357 // iterator for all hypotheses
1358 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1359 for ( ; it->More(); it->Next() ) {
1360 SALOMEDS::SObject_var mySObject = it->Value();
1361 CORBA::Object_var anObject = SObjectToObject( mySObject );
1362 if ( !CORBA::is_nil( anObject ) ) {
1363 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1364 if ( !myHyp->_is_nil() ) {
1365 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1367 string hypname = string( myHyp->GetName() );
1368 string libname = string( myHyp->GetLibName() );
1370 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1371 // WNT and ".so" for X-system) must be deleted
1372 int libname_len = libname.length();
1374 if( libname_len > 4 )
1375 libname.resize( libname_len - 4 );
1377 if( libname_len > 3 )
1378 libname.resize( libname_len - 3 );
1380 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1381 int id = myStudyContext->findId( string( objStr.in() ) );
1382 string hypdata = string( myImpl->SaveTo() );
1384 // for each hypothesis create HDF group basing on its id
1385 char hypGrpName[30];
1386 sprintf( hypGrpName, "Hypothesis %d", id );
1387 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1388 aGroup->CreateOnDisk();
1389 // --> type name of hypothesis
1390 aSize[ 0 ] = hypname.length() + 1;
1391 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1392 aDataset->CreateOnDisk();
1393 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1394 aDataset->CloseOnDisk();
1395 // --> server plugin library name of hypothesis
1396 aSize[ 0 ] = libname.length() + 1;
1397 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1398 aDataset->CreateOnDisk();
1399 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1400 aDataset->CloseOnDisk();
1401 // --> persistent data of hypothesis
1402 aSize[ 0 ] = hypdata.length() + 1;
1403 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1404 aDataset->CreateOnDisk();
1405 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1406 aDataset->CloseOnDisk();
1407 // close hypothesis HDF group
1408 aGroup->CloseOnDisk();
1413 // close hypotheses root HDF group
1414 aTopGroup->CloseOnDisk();
1416 // --> algorithms root branch (only one for the study)
1417 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1418 // create algorithms root HDF group
1419 aTopGroup = new HDFgroup( "Algorithms", aFile );
1420 aTopGroup->CreateOnDisk();
1422 // iterator for all algorithms
1423 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1424 for ( ; it->More(); it->Next() ) {
1425 SALOMEDS::SObject_var mySObject = it->Value();
1426 CORBA::Object_var anObject = SObjectToObject( mySObject );
1427 if ( !CORBA::is_nil( anObject ) ) {
1428 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1429 if ( !myHyp->_is_nil() ) {
1430 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1432 string hypname = string( myHyp->GetName() );
1433 string libname = string( myHyp->GetLibName() );
1435 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1436 // WNT and ".so" for X-system) must be deleted
1437 int libname_len = libname.length();
1439 if( libname_len > 4 )
1440 libname.resize( libname_len - 4 );
1442 if( libname_len > 3 )
1443 libname.resize( libname_len - 3 );
1445 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1446 int id = myStudyContext->findId( string( objStr.in() ) );
1447 string hypdata = string( myImpl->SaveTo() );
1449 // for each algorithm create HDF group basing on its id
1450 char hypGrpName[30];
1451 sprintf( hypGrpName, "Algorithm %d", id );
1452 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1453 aGroup->CreateOnDisk();
1454 // --> type name of algorithm
1455 aSize[0] = hypname.length() + 1;
1456 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1457 aDataset->CreateOnDisk();
1458 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1459 aDataset->CloseOnDisk();
1460 // --> server plugin library name of hypothesis
1461 aSize[0] = libname.length() + 1;
1462 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1463 aDataset->CreateOnDisk();
1464 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1465 aDataset->CloseOnDisk();
1466 // --> persistent data of algorithm
1467 aSize[0] = hypdata.length() + 1;
1468 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1469 aDataset->CreateOnDisk();
1470 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1471 aDataset->CloseOnDisk();
1472 // close algorithm HDF group
1473 aGroup->CloseOnDisk();
1478 // close algorithms root HDF group
1479 aTopGroup->CloseOnDisk();
1481 // --> mesh objects roots branches
1482 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1483 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1484 if ( !CORBA::is_nil( anObject ) ) {
1485 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1486 if ( !myMesh->_is_nil() ) {
1487 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1489 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1490 int id = myStudyContext->findId( string( objStr.in() ) );
1491 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1492 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1494 // for each mesh open the HDF group basing on its id
1495 char meshGrpName[ 30 ];
1496 sprintf( meshGrpName, "Mesh %d", id );
1497 aTopGroup = new HDFgroup( meshGrpName, aFile );
1498 aTopGroup->CreateOnDisk();
1500 // --> put dataset to hdf file which is a flag that mesh has data
1501 string strHasData = "0";
1502 // check if the mesh is not empty
1503 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1504 // write mesh data to med file
1505 myWriter.SetMesh( mySMESHDSMesh );
1506 myWriter.SetMeshId( id );
1509 aSize[ 0 ] = strHasData.length() + 1;
1510 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1511 aDataset->CreateOnDisk();
1512 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1513 aDataset->CloseOnDisk();
1515 // write reference on a shape if exists
1516 SALOMEDS::SObject_var myRef;
1517 bool shapeRefFound = false;
1518 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1520 SALOMEDS::SObject_var myShape;
1521 bool ok = myRef->ReferencedObject( myShape );
1523 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1524 string myRefOnObject = myShape->GetID();
1525 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1526 aSize[ 0 ] = myRefOnObject.length() + 1;
1527 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1528 aDataset->CreateOnDisk();
1529 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1530 aDataset->CloseOnDisk();
1535 // write applied hypotheses if exist
1536 SALOMEDS::SObject_var myHypBranch;
1537 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1538 if ( found && !shapeRefFound ) { // remove applied hyps
1539 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1541 if ( found && shapeRefFound ) {
1542 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1543 aGroup->CreateOnDisk();
1545 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1547 for ( ; it->More(); it->Next() ) {
1548 SALOMEDS::SObject_var mySObject = it->Value();
1549 SALOMEDS::SObject_var myRefOnHyp;
1550 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1552 // san - it is impossible to recover applied hypotheses
1553 // using their entries within Load() method,
1554 // for there are no AttributeIORs in the study when Load() is working.
1555 // Hence, it is better to store persistent IDs of hypotheses as references to them
1557 //string myRefOnObject = myRefOnHyp->GetID();
1558 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1559 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1560 int id = myStudyContext->findId( string( objStr.in() ) );
1561 //if ( myRefOnObject.length() > 0 ) {
1562 //aSize[ 0 ] = myRefOnObject.length() + 1;
1563 char hypName[ 30 ], hypId[ 30 ];
1564 sprintf( hypName, "Hyp %d", ++hypNb );
1565 sprintf( hypId, "%d", id );
1566 aSize[ 0 ] = strlen( hypId ) + 1;
1567 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1568 aDataset->CreateOnDisk();
1569 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1570 aDataset->WriteOnDisk( hypId );
1571 aDataset->CloseOnDisk();
1575 aGroup->CloseOnDisk();
1578 // write applied algorithms if exist
1579 SALOMEDS::SObject_var myAlgoBranch;
1580 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1581 if ( found && !shapeRefFound ) { // remove applied algos
1582 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1584 if ( found && shapeRefFound ) {
1585 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1586 aGroup->CreateOnDisk();
1588 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1590 for ( ; it->More(); it->Next() ) {
1591 SALOMEDS::SObject_var mySObject = it->Value();
1592 SALOMEDS::SObject_var myRefOnAlgo;
1593 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1595 // san - it is impossible to recover applied algorithms
1596 // using their entries within Load() method,
1597 // for there are no AttributeIORs in the study when Load() is working.
1598 // Hence, it is better to store persistent IDs of algorithms as references to them
1600 //string myRefOnObject = myRefOnAlgo->GetID();
1601 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1602 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1603 int id = myStudyContext->findId( string( objStr.in() ) );
1604 //if ( myRefOnObject.length() > 0 ) {
1605 //aSize[ 0 ] = myRefOnObject.length() + 1;
1606 char algoName[ 30 ], algoId[ 30 ];
1607 sprintf( algoName, "Algo %d", ++algoNb );
1608 sprintf( algoId, "%d", id );
1609 aSize[ 0 ] = strlen( algoId ) + 1;
1610 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1611 aDataset->CreateOnDisk();
1612 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1613 aDataset->WriteOnDisk( algoId );
1614 aDataset->CloseOnDisk();
1618 aGroup->CloseOnDisk();
1621 // --> submesh objects sub-branches
1623 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1624 SALOMEDS::SObject_var mySubmeshBranch;
1625 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1627 if ( found ) // check if there is shape reference in submeshes
1629 bool hasShapeRef = false;
1630 SALOMEDS::ChildIterator_var itSM =
1631 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1632 for ( ; itSM->More(); itSM->Next() ) {
1633 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1634 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1635 mySubRef->ReferencedObject( myShape );
1636 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1639 { // remove one submesh
1640 if ( shapeRefFound )
1641 { // unassign hypothesis
1642 SMESH::SMESH_subMesh_var mySubMesh =
1643 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1644 if ( !mySubMesh->_is_nil() ) {
1645 int shapeID = mySubMesh->GetId();
1646 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1647 const list<const SMESHDS_Hypothesis*>& hypList =
1648 mySMESHDSMesh->GetHypothesis( S );
1649 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1650 while ( hyp != hypList.end() ) {
1651 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1652 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1656 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1658 } // loop on submeshes of a type
1659 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1660 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1663 } // end check if there is shape reference in submeshes
1665 char name_meshgroup[ 30 ];
1666 if ( i == GetSubMeshOnVertexTag() )
1667 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1668 else if ( i == GetSubMeshOnEdgeTag() )
1669 strcpy( name_meshgroup, "SubMeshes On Edge" );
1670 else if ( i == GetSubMeshOnWireTag() )
1671 strcpy( name_meshgroup, "SubMeshes On Wire" );
1672 else if ( i == GetSubMeshOnFaceTag() )
1673 strcpy( name_meshgroup, "SubMeshes On Face" );
1674 else if ( i == GetSubMeshOnShellTag() )
1675 strcpy( name_meshgroup, "SubMeshes On Shell" );
1676 else if ( i == GetSubMeshOnSolidTag() )
1677 strcpy( name_meshgroup, "SubMeshes On Solid" );
1678 else if ( i == GetSubMeshOnCompoundTag() )
1679 strcpy( name_meshgroup, "SubMeshes On Compound" );
1681 // for each type of submeshes create container HDF group
1682 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1683 aGroup->CreateOnDisk();
1685 // iterator for all submeshes of given type
1686 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1687 for ( ; itSM->More(); itSM->Next() ) {
1688 SALOMEDS::SObject_var mySObject = itSM->Value();
1689 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1690 if ( !CORBA::is_nil( anSubObject ))
1692 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1693 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
1694 int subid = myStudyContext->findId( string( objStr.in() ) );
1696 // for each mesh open the HDF group basing on its id
1697 char submeshGrpName[ 30 ];
1698 sprintf( submeshGrpName, "SubMesh %d", subid );
1699 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1700 aSubGroup->CreateOnDisk();
1702 // write reference on a shape, already checked if it exists
1703 SALOMEDS::SObject_var mySubRef, myShape;
1704 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1705 mySubRef->ReferencedObject( myShape );
1706 string myRefOnObject = myShape->GetID();
1707 if ( myRefOnObject.length() > 0 ) {
1708 aSize[ 0 ] = myRefOnObject.length() + 1;
1709 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1710 aDataset->CreateOnDisk();
1711 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1712 aDataset->CloseOnDisk();
1715 // write applied hypotheses if exist
1716 SALOMEDS::SObject_var mySubHypBranch;
1717 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1719 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1720 aSubSubGroup->CreateOnDisk();
1722 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1724 for ( ; it->More(); it->Next() ) {
1725 SALOMEDS::SObject_var mySubSObject = it->Value();
1726 SALOMEDS::SObject_var myRefOnHyp;
1727 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1729 //string myRefOnObject = myRefOnHyp->GetID();
1730 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1731 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1732 int id = myStudyContext->findId( string( objStr.in() ) );
1733 //if ( myRefOnObject.length() > 0 ) {
1734 //aSize[ 0 ] = myRefOnObject.length() + 1;
1735 char hypName[ 30 ], hypId[ 30 ];
1736 sprintf( hypName, "Hyp %d", ++hypNb );
1737 sprintf( hypId, "%d", id );
1738 aSize[ 0 ] = strlen( hypId ) + 1;
1739 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1740 aDataset->CreateOnDisk();
1741 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1742 aDataset->WriteOnDisk( hypId );
1743 aDataset->CloseOnDisk();
1747 aSubSubGroup->CloseOnDisk();
1750 // write applied algorithms if exist
1751 SALOMEDS::SObject_var mySubAlgoBranch;
1752 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1754 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1755 aSubSubGroup->CreateOnDisk();
1757 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1759 for ( ; it->More(); it->Next() ) {
1760 SALOMEDS::SObject_var mySubSObject = it->Value();
1761 SALOMEDS::SObject_var myRefOnAlgo;
1762 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1764 //string myRefOnObject = myRefOnAlgo->GetID();
1765 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1766 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1767 int id = myStudyContext->findId( string( objStr.in() ) );
1768 //if ( myRefOnObject.length() > 0 ) {
1769 //aSize[ 0 ] = myRefOnObject.length() + 1;
1770 char algoName[ 30 ], algoId[ 30 ];
1771 sprintf( algoName, "Algo %d", ++algoNb );
1772 sprintf( algoId, "%d", id );
1773 aSize[ 0 ] = strlen( algoId ) + 1;
1774 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1775 aDataset->CreateOnDisk();
1776 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1777 aDataset->WriteOnDisk( algoId );
1778 aDataset->CloseOnDisk();
1782 aSubSubGroup->CloseOnDisk();
1784 // close submesh HDF group
1785 aSubGroup->CloseOnDisk();
1788 // close container of submeshes by type HDF group
1789 aGroup->CloseOnDisk();
1792 // All sub-meshes will be stored in MED file
1793 // .. will NOT (PAL 12992)
1794 //if ( shapeRefFound )
1795 //myWriter.AddAllSubMeshes();
1797 // groups root sub-branch
1798 SALOMEDS::SObject_var myGroupsBranch;
1799 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1800 found = gotBranch->FindSubObject( i, myGroupsBranch );
1802 char name_group[ 30 ];
1803 if ( i == GetNodeGroupsTag() )
1804 strcpy( name_group, "Groups of Nodes" );
1805 else if ( i == GetEdgeGroupsTag() )
1806 strcpy( name_group, "Groups of Edges" );
1807 else if ( i == GetFaceGroupsTag() )
1808 strcpy( name_group, "Groups of Faces" );
1809 else if ( i == GetVolumeGroupsTag() )
1810 strcpy( name_group, "Groups of Volumes" );
1812 aGroup = new HDFgroup( name_group, aTopGroup );
1813 aGroup->CreateOnDisk();
1815 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
1816 for ( ; it->More(); it->Next() ) {
1817 SALOMEDS::SObject_var mySObject = it->Value();
1818 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
1819 if ( !CORBA::is_nil( aSubObject ) ) {
1820 SMESH_GroupBase_i* myGroupImpl =
1821 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
1825 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
1826 int anId = myStudyContext->findId( string( objStr.in() ) );
1828 // For each group, create a dataset named "Group <group_persistent_id>"
1829 // and store the group's user name into it
1831 sprintf( grpName, "Group %d", anId );
1832 char* aUserName = myGroupImpl->GetName();
1833 aSize[ 0 ] = strlen( aUserName ) + 1;
1835 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
1836 aDataset->CreateOnDisk();
1837 aDataset->WriteOnDisk( aUserName );
1838 aDataset->CloseOnDisk();
1840 // Store the group contents into MED file
1841 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
1843 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
1844 << grpName << " to MED file" );
1845 SMESHDS_GroupBase* aGrpBaseDS =
1846 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
1847 aGrpBaseDS->SetStoreName( grpName );
1849 // Pass SMESHDS_Group to MED writer
1850 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
1852 myWriter.AddGroup( aGrpDS );
1854 // write reference on a shape if exists
1855 SMESHDS_GroupOnGeom* aGeomGrp =
1856 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
1858 SALOMEDS::SObject_var mySubRef, myShape;
1859 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
1860 mySubRef->ReferencedObject( myShape ) &&
1861 !CORBA::is_nil( myShape->GetObject() ))
1863 string myRefOnObject = myShape->GetID();
1864 if ( myRefOnObject.length() > 0 ) {
1865 char aRefName[ 30 ];
1866 sprintf( aRefName, "Ref on shape %d", anId);
1867 aSize[ 0 ] = myRefOnObject.length() + 1;
1868 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
1869 aDataset->CreateOnDisk();
1870 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1871 aDataset->CloseOnDisk();
1874 else // shape ref is invalid:
1876 // save a group on geometry as ordinary group
1877 myWriter.AddGroup( aGeomGrp );
1883 aGroup->CloseOnDisk();
1887 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
1889 // Flush current mesh information into MED file
1892 // maybe a shape was deleted in the study
1893 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
1894 TopoDS_Shape nullShape;
1895 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
1898 if ( !mySMESHDSMesh->SubMeshes().empty() )
1902 aGroup = new HDFgroup( "Submeshes", aTopGroup );
1903 aGroup->CreateOnDisk();
1905 // each element belongs to one or none submesh,
1906 // so for each node/element, we store a submesh ID
1908 // Make maps of submesh IDs of elements sorted by element IDs
1909 typedef int TElemID;
1910 typedef int TSubMID;
1911 map< TElemID, TSubMID > eId2smId, nId2smId;
1912 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
1913 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
1914 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
1915 SMDS_NodeIteratorPtr itNode;
1916 SMDS_ElemIteratorPtr itElem;
1917 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
1919 TSubMID aSubMeID = itSubM->first;
1920 SMESHDS_SubMesh* aSubMesh = itSubM->second;
1921 if ( aSubMesh->IsComplexSubmesh() )
1922 continue; // submesh containing other submeshs
1924 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
1925 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
1926 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
1928 hint = eId2smId.begin();
1929 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
1930 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
1933 // Care of elements that are not on submeshes
1934 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
1935 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
1936 /* --- stl_map.h says : */
1937 /* A %map relies on unique keys and thus a %pair is only inserted if its */
1938 /* first element (the key) is not already present in the %map. */
1939 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
1941 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
1942 if ( nbElems != eId2smId.size() ) {
1943 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
1944 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
1947 // Store submesh IDs
1948 for ( int isNode = 0; isNode < 2; ++isNode )
1950 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
1951 if ( id2smId.empty() ) continue;
1952 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
1953 // make and fill array of submesh IDs
1954 int* smIDs = new int [ id2smId.size() ];
1955 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
1956 smIDs[ i ] = id_smId->second;
1958 aSize[ 0 ] = id2smId.size();
1959 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
1960 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
1961 aDataset->CreateOnDisk();
1962 aDataset->WriteOnDisk( smIDs );
1963 aDataset->CloseOnDisk();
1968 // Store node positions on sub-shapes (SMDS_Position):
1969 // ----------------------------------------------------
1971 aGroup = new HDFgroup( "Node Positions", aTopGroup );
1972 aGroup->CreateOnDisk();
1974 // in aGroup, create 5 datasets to contain:
1975 // "Nodes on Edges" - ID of node on edge
1976 // "Edge positions" - U parameter on node on edge
1977 // "Nodes on Faces" - ID of node on face
1978 // "Face U positions" - U parameter of node on face
1979 // "Face V positions" - V parameter of node on face
1981 // Find out nb of nodes on edges and faces
1982 // Collect corresponing sub-meshes
1983 int nbEdgeNodes = 0, nbFaceNodes = 0;
1984 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
1985 // loop on SMESHDS_SubMesh'es
1986 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
1988 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
1989 if ( aSubMesh->IsComplexSubmesh() )
1990 continue; // submesh containing other submeshs
1991 int nbNodes = aSubMesh->NbNodes();
1992 if ( nbNodes == 0 ) continue;
1994 int aShapeID = (*itSubM).first;
1995 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
1996 // write only SMDS_FacePosition and SMDS_EdgePosition
1997 switch ( aShapeType ) {
1999 nbFaceNodes += nbNodes;
2000 aFaceSM.push_back( aSubMesh );
2003 nbEdgeNodes += nbNodes;
2004 aEdgeSM.push_back( aSubMesh );
2010 // Treat positions on edges or faces
2011 for ( int onFace = 0; onFace < 2; onFace++ )
2013 // Create arrays to store in datasets
2014 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
2015 if (!nbNodes) continue;
2016 int* aNodeIDs = new int [ nbNodes ];
2017 double* aUPos = new double [ nbNodes ];
2018 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
2021 // loop on sub-meshes
2022 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
2023 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
2024 for ( ; itSM != pListSM->end(); itSM++ )
2026 SMESHDS_SubMesh* aSubMesh = (*itSM);
2028 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
2029 // loop on nodes in aSubMesh
2030 while ( itNode->more() )
2033 const SMDS_MeshNode* node = itNode->next();
2034 aNodeIDs [ iNode ] = node->GetID();
2037 const SMDS_PositionPtr pos = node->GetPosition();
2038 if ( onFace ) { // on FACE
2039 const SMDS_FacePosition* fPos =
2040 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
2042 aUPos[ iNode ] = fPos->GetUParameter();
2043 aVPos[ iNode ] = fPos->GetVParameter();
2050 const SMDS_EdgePosition* ePos =
2051 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
2053 aUPos[ iNode ] = ePos->GetUParameter();
2059 } // loop on nodes in aSubMesh
2060 } // loop on sub-meshes
2065 aSize[ 0 ] = nbNodes;
2067 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
2068 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2069 aDataset->CreateOnDisk();
2070 aDataset->WriteOnDisk( aNodeIDs );
2071 aDataset->CloseOnDisk();
2074 aDSName = ( onFace ? "Face U positions" : "Edge positions");
2075 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
2076 aDataset->CreateOnDisk();
2077 aDataset->WriteOnDisk( aUPos );
2078 aDataset->CloseOnDisk();
2081 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
2082 aDataset->CreateOnDisk();
2083 aDataset->WriteOnDisk( aVPos );
2084 aDataset->CloseOnDisk();
2089 if ( aVPos ) delete [] aVPos;
2091 } // treat positions on edges or faces
2093 // close "Node Positions" group
2094 aGroup->CloseOnDisk();
2096 } // if ( there are submeshes in SMESHDS_Mesh )
2099 // close mesh HDF group
2100 aTopGroup->CloseOnDisk();
2108 aFile->CloseOnDisk();
2111 // Convert temporary files to stream
2112 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
2114 // Remove temporary files and directory
2116 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2118 INFOS( "SMESH_Gen_i::Save() completed" );
2119 return aStreamFile._retn();
2122 //=============================================================================
2124 * SMESH_Gen_i::SaveASCII
2126 * Save SMESH module's data in ASCII format
2128 //=============================================================================
2130 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2132 bool isMultiFile ) {
2133 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2134 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2135 return aStreamFile._retn();
2137 //after usual saving needs to encipher binary to text string
2138 //Any binary symbol will be represent as "|xx" () hexadecimal format number
2139 int size = aStreamFile.in().length();
2140 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
2141 for ( int i = 0; i < size; i++ )
2142 sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
2144 buffer[size * 3] = '\0';
2146 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
2148 return anAsciiStreamFile._retn();
2151 //=============================================================================
2153 * SMESH_Gen_i::loadGeomData
2155 * Load GEOM module data
2157 //=============================================================================
2159 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2161 if ( theCompRoot->_is_nil() )
2164 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2165 if ( aStudy->_is_nil() )
2168 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2169 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2171 //=============================================================================
2173 * \brief Creates SMDS_Position according to shape type
2175 //=============================================================================
2177 class PositionCreator {
2179 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
2180 return (this->*myFuncTable[ type ])();
2183 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
2184 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
2185 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
2186 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
2189 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
2190 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
2191 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
2192 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
2193 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
2194 vector<FmakePos> myFuncTable;
2197 //=============================================================================
2201 * Load SMESH module's data
2203 //=============================================================================
2205 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2206 const SALOMEDS::TMPFile& theStream,
2210 INFOS( "SMESH_Gen_i::Load" );
2212 if ( myCurrentStudy->_is_nil() ||
2213 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2214 SetCurrentStudy( theComponent->GetStudy() );
2216 /* if( !theComponent->_is_nil() )
2218 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2219 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2220 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2223 StudyContext* myStudyContext = GetCurrentStudyContext();
2225 // Get temporary files location
2226 TCollection_AsciiString tmpDir =
2227 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2229 INFOS( "THE URL++++++++++++++" )
2231 INFOS( "THE TMP PATH+++++++++" );
2234 // Convert the stream into sequence of files to process
2235 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2238 TCollection_AsciiString aStudyName( "" );
2240 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2242 // Set names of temporary files
2243 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2244 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2248 HDFdataset* aDataset;
2249 HDFgroup* aTopGroup;
2251 HDFgroup* aSubGroup;
2252 HDFgroup* aSubSubGroup;
2255 // ---> open HDF file
2256 aFile = new HDFfile( filename.ToCString() );
2258 aFile->OpenOnDisk( HDF_RDONLY );
2260 catch ( HDFexception ) {
2261 INFOS( "Load(): " << filename << " not found!" );
2265 DriverMED_R_SMESHDS_Mesh myReader;
2266 myReader.SetFile( meshfile.ToCString() );
2268 // For PAL13473 ("Repetitive mesh") implementation.
2269 // New dependencies between SMESH objects are established:
2270 // now hypotheses can refer to meshes, shapes and other hypotheses.
2271 // To keep data consistent, the following order of data restoration
2273 // 1. Create hypotheses
2274 // 2. Create all meshes
2275 // 3. Load hypotheses' data
2278 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
2279 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
2281 // get total number of top-level groups
2282 int aNbGroups = aFile->nInternalObjects();
2283 if ( aNbGroups > 0 ) {
2284 // --> in first turn we should read&create hypotheses
2285 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2286 // open hypotheses root HDF group
2287 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2288 aTopGroup->OpenOnDisk();
2290 // get number of hypotheses
2291 int aNbObjects = aTopGroup->nInternalObjects();
2292 for ( int j = 0; j < aNbObjects; j++ ) {
2293 // try to identify hypothesis
2294 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2295 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2297 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2298 // open hypothesis group
2299 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2300 aGroup->OpenOnDisk();
2302 // --> get hypothesis id
2303 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2308 // get number of datasets
2309 int aNbSubObjects = aGroup->nInternalObjects();
2310 for ( int k = 0; k < aNbSubObjects; k++ ) {
2312 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2313 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2314 // --> get hypothesis name
2315 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2316 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2317 aDataset->OpenOnDisk();
2318 size = aDataset->GetSize();
2319 char* hypname_str = new char[ size ];
2320 aDataset->ReadFromDisk( hypname_str );
2321 hypname = string( hypname_str );
2322 delete [] hypname_str;
2323 aDataset->CloseOnDisk();
2325 // --> get hypothesis plugin library name
2326 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2327 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2328 aDataset->OpenOnDisk();
2329 size = aDataset->GetSize();
2330 char* libname_str = new char[ size ];
2331 aDataset->ReadFromDisk( libname_str );
2332 if(MYDEBUG) SCRUTE( libname_str );
2333 libname = string( libname_str );
2334 delete [] libname_str;
2335 aDataset->CloseOnDisk();
2337 // --> get hypothesis data
2338 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2339 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2340 aDataset->OpenOnDisk();
2341 size = aDataset->GetSize();
2342 char* hypdata_str = new char[ size ];
2343 aDataset->ReadFromDisk( hypdata_str );
2344 hypdata = string( hypdata_str );
2345 delete [] hypdata_str;
2346 aDataset->CloseOnDisk();
2349 // close hypothesis HDF group
2350 aGroup->CloseOnDisk();
2352 // --> restore hypothesis from data
2353 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2354 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2355 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2356 SMESH::SMESH_Hypothesis_var myHyp;
2358 try { // protect persistence mechanism against exceptions
2359 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2362 INFOS( "Exception during hypothesis creation" );
2365 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2367 // myImpl->LoadFrom( hypdata.c_str() );
2368 hypDataList.push_back( make_pair( myImpl, hypdata ));
2369 string iorString = GetORB()->object_to_string( myHyp );
2370 int newId = myStudyContext->findId( iorString );
2371 myStudyContext->mapOldToNew( id, newId );
2374 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2378 // close hypotheses root HDF group
2379 aTopGroup->CloseOnDisk();
2382 // --> then we should read&create algorithms
2383 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2384 // open algorithms root HDF group
2385 aTopGroup = new HDFgroup( "Algorithms", aFile );
2386 aTopGroup->OpenOnDisk();
2388 // get number of algorithms
2389 int aNbObjects = aTopGroup->nInternalObjects();
2390 for ( int j = 0; j < aNbObjects; j++ ) {
2391 // try to identify algorithm
2392 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2393 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2395 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2396 // open algorithm group
2397 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2398 aGroup->OpenOnDisk();
2400 // --> get algorithm id
2401 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2406 // get number of datasets
2407 int aNbSubObjects = aGroup->nInternalObjects();
2408 for ( int k = 0; k < aNbSubObjects; k++ ) {
2410 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2411 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2412 // --> get algorithm name
2413 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2414 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2415 aDataset->OpenOnDisk();
2416 size = aDataset->GetSize();
2417 char* hypname_str = new char[ size ];
2418 aDataset->ReadFromDisk( hypname_str );
2419 hypname = string( hypname_str );
2420 delete [] hypname_str;
2421 aDataset->CloseOnDisk();
2423 // --> get algorithm plugin library name
2424 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2425 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2426 aDataset->OpenOnDisk();
2427 size = aDataset->GetSize();
2428 char* libname_str = new char[ size ];
2429 aDataset->ReadFromDisk( libname_str );
2430 if(MYDEBUG) SCRUTE( libname_str );
2431 libname = string( libname_str );
2432 delete [] libname_str;
2433 aDataset->CloseOnDisk();
2435 // --> get algorithm data
2436 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2437 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2438 aDataset->OpenOnDisk();
2439 size = aDataset->GetSize();
2440 char* hypdata_str = new char[ size ];
2441 aDataset->ReadFromDisk( hypdata_str );
2442 if(MYDEBUG) SCRUTE( hypdata_str );
2443 hypdata = string( hypdata_str );
2444 delete [] hypdata_str;
2445 aDataset->CloseOnDisk();
2448 // close algorithm HDF group
2449 aGroup->CloseOnDisk();
2451 // --> restore algorithm from data
2452 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2453 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2454 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2455 SMESH::SMESH_Hypothesis_var myHyp;
2457 try { // protect persistence mechanism against exceptions
2458 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2461 INFOS( "Exception during hypothesis creation" );
2464 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2466 //myImpl->LoadFrom( hypdata.c_str() );
2467 hypDataList.push_back( make_pair( myImpl, hypdata ));
2468 string iorString = GetORB()->object_to_string( myHyp );
2469 int newId = myStudyContext->findId( iorString );
2470 myStudyContext->mapOldToNew( id, newId );
2473 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2477 // close algorithms root HDF group
2478 aTopGroup->CloseOnDisk();
2481 // --> the rest groups should be meshes
2482 for ( int i = 0; i < aNbGroups; i++ ) {
2483 // identify next group
2484 char meshName[ HDF_NAME_MAX_LEN+1 ];
2485 aFile->InternalObjectIndentify( i, meshName );
2487 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2489 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2493 // open mesh HDF group
2494 aTopGroup = new HDFgroup( meshName, aFile );
2495 aTopGroup->OpenOnDisk();
2497 // get number of child HDF objects
2498 int aNbObjects = aTopGroup->nInternalObjects();
2499 if ( aNbObjects > 0 ) {
2501 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2502 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2503 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2504 if ( !myNewMeshImpl )
2506 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
2508 string iorString = GetORB()->object_to_string( myNewMesh );
2509 int newId = myStudyContext->findId( iorString );
2510 myStudyContext->mapOldToNew( id, newId );
2512 // try to read and set reference to shape
2513 GEOM::GEOM_Object_var aShapeObject;
2514 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2515 // load mesh "Ref on shape" - it's an entry to SObject
2516 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2517 aDataset->OpenOnDisk();
2518 size = aDataset->GetSize();
2519 char* refFromFile = new char[ size ];
2520 aDataset->ReadFromDisk( refFromFile );
2521 aDataset->CloseOnDisk();
2522 if ( strlen( refFromFile ) > 0 ) {
2523 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2525 // Make sure GEOM data are loaded first
2526 //loadGeomData( shapeSO->GetFatherComponent() );
2528 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2529 if ( !CORBA::is_nil( shapeObject ) ) {
2530 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2531 if ( !aShapeObject->_is_nil() )
2532 myNewMeshImpl->SetShape( aShapeObject );
2541 // As all object that can be referred by hypothesis are created,
2542 // we can restore hypothesis data
2544 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
2545 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
2547 SMESH_Hypothesis_i* hyp = hyp_data->first;
2548 string & data = hyp_data->second;
2549 hyp->LoadFrom( data.c_str() );
2552 // Restore the rest mesh data
2554 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
2555 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
2557 aTopGroup = meshi_group->second;
2558 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
2559 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2560 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2562 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
2563 bool hasData = false;
2566 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
2567 int newId = myStudyContext->findId( iorString );
2568 int id = myStudyContext->getOldId( newId );
2570 // try to find mesh data dataset
2571 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2572 // load mesh "has data" flag
2573 aDataset = new HDFdataset( "Has data", aTopGroup );
2574 aDataset->OpenOnDisk();
2575 size = aDataset->GetSize();
2576 char* strHasData = new char[ size ];
2577 aDataset->ReadFromDisk( strHasData );
2578 aDataset->CloseOnDisk();
2579 if ( strcmp( strHasData, "1") == 0 ) {
2580 // read mesh data from MED file
2581 myReader.SetMesh( mySMESHDSMesh );
2582 myReader.SetMeshId( id );
2588 // try to get applied algorithms
2589 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2590 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2591 aGroup->OpenOnDisk();
2592 // get number of applied algorithms
2593 int aNbSubObjects = aGroup->nInternalObjects();
2594 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2595 for ( int j = 0; j < aNbSubObjects; j++ ) {
2596 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2597 aGroup->InternalObjectIndentify( j, name_dataset );
2598 // check if it is an algorithm
2599 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2600 aDataset = new HDFdataset( name_dataset, aGroup );
2601 aDataset->OpenOnDisk();
2602 size = aDataset->GetSize();
2603 char* refFromFile = new char[ size ];
2604 aDataset->ReadFromDisk( refFromFile );
2605 aDataset->CloseOnDisk();
2607 // san - it is impossible to recover applied algorithms using their entries within Load() method
2609 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2610 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2611 int id = atoi( refFromFile );
2612 string anIOR = myStudyContext->getIORbyOldId( id );
2613 if ( !anIOR.empty() ) {
2614 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2615 if ( !CORBA::is_nil( hypObject ) ) {
2616 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2617 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2618 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2623 aGroup->CloseOnDisk();
2626 // try to get applied hypotheses
2627 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2628 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2629 aGroup->OpenOnDisk();
2630 // get number of applied hypotheses
2631 int aNbSubObjects = aGroup->nInternalObjects();
2632 for ( int j = 0; j < aNbSubObjects; j++ ) {
2633 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2634 aGroup->InternalObjectIndentify( j, name_dataset );
2635 // check if it is a hypothesis
2636 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2637 aDataset = new HDFdataset( name_dataset, aGroup );
2638 aDataset->OpenOnDisk();
2639 size = aDataset->GetSize();
2640 char* refFromFile = new char[ size ];
2641 aDataset->ReadFromDisk( refFromFile );
2642 aDataset->CloseOnDisk();
2644 // san - it is impossible to recover applied hypotheses using their entries within Load() method
2646 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2647 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2648 int id = atoi( refFromFile );
2649 string anIOR = myStudyContext->getIORbyOldId( id );
2650 if ( !anIOR.empty() ) {
2651 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2652 if ( !CORBA::is_nil( hypObject ) ) {
2653 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2654 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2655 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2660 aGroup->CloseOnDisk();
2663 // --> try to find submeshes containers for each type of submesh
2664 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
2665 char name_meshgroup[ 30 ];
2666 if ( j == GetSubMeshOnVertexTag() )
2667 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2668 else if ( j == GetSubMeshOnEdgeTag() )
2669 strcpy( name_meshgroup, "SubMeshes On Edge" );
2670 else if ( j == GetSubMeshOnWireTag() )
2671 strcpy( name_meshgroup, "SubMeshes On Wire" );
2672 else if ( j == GetSubMeshOnFaceTag() )
2673 strcpy( name_meshgroup, "SubMeshes On Face" );
2674 else if ( j == GetSubMeshOnShellTag() )
2675 strcpy( name_meshgroup, "SubMeshes On Shell" );
2676 else if ( j == GetSubMeshOnSolidTag() )
2677 strcpy( name_meshgroup, "SubMeshes On Solid" );
2678 else if ( j == GetSubMeshOnCompoundTag() )
2679 strcpy( name_meshgroup, "SubMeshes On Compound" );
2681 // try to get submeshes container HDF group
2682 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
2683 // open submeshes containers HDF group
2684 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2685 aGroup->OpenOnDisk();
2687 // get number of submeshes
2688 int aNbSubMeshes = aGroup->nInternalObjects();
2689 for ( int k = 0; k < aNbSubMeshes; k++ ) {
2691 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
2692 aGroup->InternalObjectIndentify( k, name_submeshgroup );
2693 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
2694 // --> get submesh id
2695 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
2698 // open submesh HDF group
2699 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
2700 aSubGroup->OpenOnDisk();
2702 // try to read and set reference to subshape
2703 GEOM::GEOM_Object_var aSubShapeObject;
2704 SMESH::SMESH_subMesh_var aSubMesh;
2706 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2707 // load submesh "Ref on shape" - it's an entry to SObject
2708 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2709 aDataset->OpenOnDisk();
2710 size = aDataset->GetSize();
2711 char* refFromFile = new char[ size ];
2712 aDataset->ReadFromDisk( refFromFile );
2713 aDataset->CloseOnDisk();
2714 if ( strlen( refFromFile ) > 0 ) {
2715 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2716 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2717 if ( !CORBA::is_nil( subShapeObject ) ) {
2718 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2719 if ( !aSubShapeObject->_is_nil() )
2720 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2721 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2722 if ( aSubMesh->_is_nil() )
2724 string iorSubString = GetORB()->object_to_string( aSubMesh );
2725 int newSubId = myStudyContext->findId( iorSubString );
2726 myStudyContext->mapOldToNew( subid, newSubId );
2731 if ( aSubMesh->_is_nil() )
2734 // VSR: Get submesh data from MED convertor
2735 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2736 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2737 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2738 // subid << " for subshape # " << anInternalSubmeshId);
2739 // SMESHDS_SubMesh* aSubMeshDS =
2740 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2741 // if ( !aSubMeshDS ) {
2742 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2743 // anInternalSubmeshId << " in current mesh!");
2746 // myReader.GetSubMesh( aSubMeshDS, subid );
2749 // try to get applied algorithms
2750 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2751 // open "applied algorithms" HDF group
2752 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2753 aSubSubGroup->OpenOnDisk();
2754 // get number of applied algorithms
2755 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2756 for ( int l = 0; l < aNbSubObjects; l++ ) {
2757 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2758 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2759 // check if it is an algorithm
2760 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2761 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2762 aDataset->OpenOnDisk();
2763 size = aDataset->GetSize();
2764 char* refFromFile = new char[ size ];
2765 aDataset->ReadFromDisk( refFromFile );
2766 aDataset->CloseOnDisk();
2768 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2769 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2770 int id = atoi( refFromFile );
2771 string anIOR = myStudyContext->getIORbyOldId( id );
2772 if ( !anIOR.empty() ) {
2773 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2774 if ( !CORBA::is_nil( hypObject ) ) {
2775 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2776 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2777 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2782 // close "applied algorithms" HDF group
2783 aSubSubGroup->CloseOnDisk();
2786 // try to get applied hypotheses
2787 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2788 // open "applied hypotheses" HDF group
2789 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2790 aSubSubGroup->OpenOnDisk();
2791 // get number of applied hypotheses
2792 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2793 for ( int l = 0; l < aNbSubObjects; l++ ) {
2794 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2795 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2796 // check if it is a hypothesis
2797 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2798 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2799 aDataset->OpenOnDisk();
2800 size = aDataset->GetSize();
2801 char* refFromFile = new char[ size ];
2802 aDataset->ReadFromDisk( refFromFile );
2803 aDataset->CloseOnDisk();
2805 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2806 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2807 int id = atoi( refFromFile );
2808 string anIOR = myStudyContext->getIORbyOldId( id );
2809 if ( !anIOR.empty() ) {
2810 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2811 if ( !CORBA::is_nil( hypObject ) ) {
2812 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2813 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2814 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2819 // close "applied hypotheses" HDF group
2820 aSubSubGroup->CloseOnDisk();
2823 // close submesh HDF group
2824 aSubGroup->CloseOnDisk();
2827 // close submeshes containers HDF group
2828 aGroup->CloseOnDisk();
2834 // Read sub-meshes from MED
2835 // -------------------------
2836 if(MYDEBUG) MESSAGE("Create all sub-meshes");
2837 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
2838 if ( submeshesInFamilies )
2840 // old way working before fix of PAL 12992
2841 myReader.CreateAllSubMeshes();
2846 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2847 aGroup->OpenOnDisk();
2849 int maxID = mySMESHDSMesh->MaxShapeIndex();
2850 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
2851 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
2853 PositionCreator aPositionCreator;
2855 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
2856 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
2857 for ( int isNode = 0; isNode < 2; ++isNode )
2859 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2860 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
2862 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
2863 aDataset->OpenOnDisk();
2864 // read submesh IDs for all elements sorted by ID
2865 int nbElems = aDataset->GetSize();
2866 int* smIDs = new int [ nbElems ];
2867 aDataset->ReadFromDisk( smIDs );
2868 aDataset->CloseOnDisk();
2870 // get elements sorted by ID
2871 ::SMESH_MeshEditor::TIDSortedElemSet elemSet;
2873 while ( nIt->more() ) elemSet.insert( nIt->next() );
2875 while ( eIt->more() ) elemSet.insert( eIt->next() );
2876 ASSERT( elemSet.size() == nbElems );
2878 // add elements to submeshes
2879 ::SMESH_MeshEditor::TIDSortedElemSet::iterator iE = elemSet.begin();
2880 for ( int i = 0; i < nbElems; ++i, ++iE )
2882 int smID = smIDs[ i ];
2883 if ( smID == 0 ) continue;
2884 ASSERT( smID <= maxID );
2885 const SMDS_MeshElement* elem = *iE;
2886 // get or create submesh
2887 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
2889 sm = mySMESHDSMesh->NewSubMesh( smID );
2890 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
2894 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
2895 pos->SetShapeId( smID );
2896 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
2897 node->SetPosition( pos );
2898 sm->AddNode( node );
2900 sm->AddElement( elem );
2906 } // end reading submeshes
2908 // Read node positions on sub-shapes (SMDS_Position)
2910 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
2912 // There are 5 datasets to read:
2913 // "Nodes on Edges" - ID of node on edge
2914 // "Edge positions" - U parameter on node on edge
2915 // "Nodes on Faces" - ID of node on face
2916 // "Face U positions" - U parameter of node on face
2917 // "Face V positions" - V parameter of node on face
2918 char* aEid_DSName = "Nodes on Edges";
2919 char* aEu_DSName = "Edge positions";
2920 char* aFu_DSName = "Face U positions";
2921 //char* aFid_DSName = "Nodes on Faces";
2922 //char* aFv_DSName = "Face V positions";
2925 int nbEids = 0, nbFids = 0;
2926 int *aEids = 0, *aFids = 0;
2927 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
2930 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2931 aGroup->OpenOnDisk();
2933 // loop on 5 data sets
2934 int aNbObjects = aGroup->nInternalObjects();
2935 for ( int i = 0; i < aNbObjects; i++ )
2938 char aDSName[ HDF_NAME_MAX_LEN+1 ];
2939 aGroup->InternalObjectIndentify( i, aDSName );
2941 aDataset = new HDFdataset( aDSName, aGroup );
2942 aDataset->OpenOnDisk();
2943 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
2945 double* pos = new double [ aDataset->GetSize() ];
2946 aDataset->ReadFromDisk( pos );
2948 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
2950 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
2957 int aSize = aDataset->GetSize();
2959 // for reading files, created from 18.07.2005 till 10.10.2005
2960 if (aDataset->GetType() == HDF_STRING)
2961 aSize /= sizeof(int);
2963 int* ids = new int [aSize];
2964 aDataset->ReadFromDisk( ids );
2965 // on face or nodes?
2966 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
2975 aDataset->CloseOnDisk();
2976 } // loop on 5 datasets
2978 // Set node positions on edges or faces
2979 for ( int onFace = 0; onFace < 2; onFace++ )
2981 int nbNodes = ( onFace ? nbFids : nbEids );
2982 if ( nbNodes == 0 ) continue;
2983 int* aNodeIDs = ( onFace ? aFids : aEids );
2984 double* aUPos = ( onFace ? aFupos : aEpos );
2985 double* aVPos = ( onFace ? aFvpos : 0 );
2987 for ( int iNode = 0; iNode < nbNodes; iNode++ )
2989 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
2991 SMDS_PositionPtr aPos = node->GetPosition();
2994 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
2995 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
2996 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
2997 fPos->SetUParameter( aUPos[ iNode ]);
2998 fPos->SetVParameter( aVPos[ iNode ]);
3001 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
3002 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
3003 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
3004 fPos->SetUParameter( aUPos[ iNode ]);
3008 if ( aEids ) delete [] aEids;
3009 if ( aFids ) delete [] aFids;
3010 if ( aEpos ) delete [] aEpos;
3011 if ( aFupos ) delete [] aFupos;
3012 if ( aFvpos ) delete [] aFvpos;
3014 aGroup->CloseOnDisk();
3016 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
3019 // Recompute State (as computed sub-meshes are restored from MED)
3020 if ( !aShapeObject->_is_nil() ) {
3021 MESSAGE("Compute State Engine ...");
3022 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
3023 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
3024 (SMESH_subMesh::SUBMESH_RESTORED);
3025 MESSAGE("Compute State Engine finished");
3028 // try to get groups
3029 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
3030 char name_group[ 30 ];
3031 if ( ii == GetNodeGroupsTag() )
3032 strcpy( name_group, "Groups of Nodes" );
3033 else if ( ii == GetEdgeGroupsTag() )
3034 strcpy( name_group, "Groups of Edges" );
3035 else if ( ii == GetFaceGroupsTag() )
3036 strcpy( name_group, "Groups of Faces" );
3037 else if ( ii == GetVolumeGroupsTag() )
3038 strcpy( name_group, "Groups of Volumes" );
3040 if ( aTopGroup->ExistInternalObject( name_group ) ) {
3041 aGroup = new HDFgroup( name_group, aTopGroup );
3042 aGroup->OpenOnDisk();
3043 // get number of groups
3044 int aNbSubObjects = aGroup->nInternalObjects();
3045 for ( int j = 0; j < aNbSubObjects; j++ ) {
3046 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3047 aGroup->InternalObjectIndentify( j, name_dataset );
3048 // check if it is an group
3049 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
3051 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
3054 aDataset = new HDFdataset( name_dataset, aGroup );
3055 aDataset->OpenOnDisk();
3057 // Retrieve actual group name
3058 size = aDataset->GetSize();
3059 char* nameFromFile = new char[ size ];
3060 aDataset->ReadFromDisk( nameFromFile );
3061 aDataset->CloseOnDisk();
3063 // Try to find a shape reference
3064 TopoDS_Shape aShape;
3065 char aRefName[ 30 ];
3066 sprintf( aRefName, "Ref on shape %d", subid);
3067 if ( aGroup->ExistInternalObject( aRefName ) ) {
3068 // load mesh "Ref on shape" - it's an entry to SObject
3069 aDataset = new HDFdataset( aRefName, aGroup );
3070 aDataset->OpenOnDisk();
3071 size = aDataset->GetSize();
3072 char* refFromFile = new char[ size ];
3073 aDataset->ReadFromDisk( refFromFile );
3074 aDataset->CloseOnDisk();
3075 if ( strlen( refFromFile ) > 0 ) {
3076 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3077 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3078 if ( !CORBA::is_nil( shapeObject ) ) {
3079 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3080 if ( !aShapeObject->_is_nil() )
3081 aShape = GeomObjectToShape( aShapeObject );
3085 // Create group servant
3086 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
3087 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
3088 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
3089 // Obtain a SMESHDS_Group object
3090 if ( aNewGroup->_is_nil() )
3093 string iorSubString = GetORB()->object_to_string( aNewGroup );
3094 int newSubId = myStudyContext->findId( iorSubString );
3095 myStudyContext->mapOldToNew( subid, newSubId );
3097 SMESH_GroupBase_i* aGroupImpl =
3098 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
3102 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
3106 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
3107 aGroupBaseDS->SetStoreName( name_dataset );
3109 // Fill group with contents from MED file
3110 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
3112 myReader.GetGroup( aGrp );
3115 aGroup->CloseOnDisk();
3120 aTopGroup->CloseOnDisk();
3123 aFile->CloseOnDisk();
3126 // Remove temporary files created from the stream
3128 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3130 INFOS( "SMESH_Gen_i::Load completed" );
3134 //=============================================================================
3136 * SMESH_Gen_i::LoadASCII
3138 * Load SMESH module's data in ASCII format
3140 //=============================================================================
3142 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
3143 const SALOMEDS::TMPFile& theStream,
3145 bool isMultiFile ) {
3146 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
3147 return Load( theComponent, theStream, theURL, isMultiFile );
3149 //before call main ::Load method it's need for decipher text format to
3150 //binary ( "|xx" => x' )
3151 int size = theStream.length();
3152 if ( int((size / 3 )*3) != size ) //error size of buffer
3155 int real_size = int(size / 3);
3157 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
3161 for ( int i = 0; i < real_size; i++ )
3163 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
3164 sscanf( tmp, "%x", &c );
3165 sprintf( (char*)&(buffer[i]), "%c", (char)c );
3168 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
3170 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
3173 //=============================================================================
3175 * SMESH_Gen_i::Close
3177 * Clears study-connected data when it is closed
3179 //=============================================================================
3181 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
3183 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
3185 // Clear study contexts data
3186 int studyId = GetCurrentStudyID();
3187 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
3188 delete myStudyContextMap[ studyId ];
3189 myStudyContextMap.erase( studyId );
3194 //=============================================================================
3196 * SMESH_Gen_i::ComponentDataType
3198 * Get component data type
3200 //=============================================================================
3202 char* SMESH_Gen_i::ComponentDataType()
3204 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
3205 return CORBA::string_dup( "SMESH" );
3209 //=============================================================================
3211 * SMESH_Gen_i::IORToLocalPersistentID
3213 * Transform data from transient form to persistent
3215 //=============================================================================
3217 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
3218 const char* IORString,
3219 CORBA::Boolean /*isMultiFile*/,
3220 CORBA::Boolean /*isASCII*/ )
3222 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
3223 StudyContext* myStudyContext = GetCurrentStudyContext();
3225 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
3226 int anId = myStudyContext->findId( IORString );
3228 if(MYDEBUG) MESSAGE( "VSR " << anId )
3230 sprintf( strId, "%d", anId );
3231 return CORBA::string_dup( strId );
3234 return CORBA::string_dup( "" );
3237 //=============================================================================
3239 * SMESH_Gen_i::LocalPersistentIDToIOR
3241 * Transform data from persistent form to transient
3243 //=============================================================================
3245 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
3246 const char* aLocalPersistentID,
3247 CORBA::Boolean /*isMultiFile*/,
3248 CORBA::Boolean /*isASCII*/ )
3250 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
3251 StudyContext* myStudyContext = GetCurrentStudyContext();
3253 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
3254 int anId = atoi( aLocalPersistentID );
3255 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
3257 return CORBA::string_dup( "" );
3260 //=======================================================================
3261 //function : RegisterObject
3263 //=======================================================================
3265 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
3267 StudyContext* myStudyContext = GetCurrentStudyContext();
3268 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3269 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
3270 return myStudyContext->addObject( string( iorString.in() ) );
3275 //================================================================================
3277 * \brief Return id of registered object
3278 * \param theObject - the Object
3279 * \retval int - Object id
3281 //================================================================================
3283 int SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
3285 StudyContext* myStudyContext = GetCurrentStudyContext();
3286 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3287 string iorString = GetORB()->object_to_string( theObject );
3288 return myStudyContext->findId( iorString );
3293 //=============================================================================
3295 * SMESHEngine_factory
3297 * C factory, accessible with dlsym, after dlopen
3299 //=============================================================================
3303 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3304 PortableServer::POA_ptr poa,
3305 PortableServer::ObjectId* contId,
3306 const char* instanceName,
3307 const char* interfaceName )
3309 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3310 if(MYDEBUG) SCRUTE(interfaceName);
3311 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3312 return aSMESHGen->getId() ;