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"
95 #include CORBA_SERVER_HEADER(SMESH_Group)
96 #include CORBA_SERVER_HEADER(SMESH_Filter)
98 #include "DriverMED_W_SMESHDS_Mesh.h"
99 #include "DriverMED_R_SMESHDS_Mesh.h"
101 #include "SALOMEDS_Tool.hxx"
102 #include "SALOME_NamingService.hxx"
103 #include "SALOME_LifeCycleCORBA.hxx"
104 #include "Utils_SINGLETON.hxx"
105 #include "OpUtil.hxx"
107 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
109 #include "GEOM_Client.hxx"
110 #include "Utils_ExceptHandlers.hxx"
115 using SMESH::TPythonDump;
117 #define NUM_TMP_FILES 2
120 static int MYDEBUG = 1;
122 static int MYDEBUG = 0;
125 // Static variables definition
126 CORBA::ORB_var SMESH_Gen_i::myOrb;
127 PortableServer::POA_var SMESH_Gen_i::myPoa;
128 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
129 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
130 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
132 //=============================================================================
134 * GetServant [ static ]
136 * Get servant of the CORBA object
138 //=============================================================================
140 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
142 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
145 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
149 INFOS( "GetServant - Unknown exception was caught!!!" );
154 //=============================================================================
156 * SObjectToObject [ static ]
158 * Get CORBA object corresponding to the SALOMEDS::SObject
160 //=============================================================================
162 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
164 SALOMEDS::GenericAttribute_var anAttr;
165 CORBA::Object_var anObj;
166 if ( !theSObject->_is_nil() ) {
168 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
169 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
170 CORBA::String_var aValue = anIOR->Value();
171 if( strcmp( aValue, "" ) != 0 )
172 anObj = GetORB()->string_to_object( aValue );
176 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
182 //=============================================================================
186 * Get SALOME_NamingService object
188 //=============================================================================
190 SALOME_NamingService* SMESH_Gen_i::GetNS()
192 if ( myNS == NULL ) {
193 myNS = SINGLETON_<SALOME_NamingService>::Instance();
194 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
195 myNS->init_orb( GetORB() );
200 //=============================================================================
204 * Get SALOME_LifeCycleCORBA object
206 //=============================================================================
207 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
208 if ( myLCC == NULL ) {
209 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
215 //=============================================================================
217 * GetGeomEngine [ static ]
219 * Get GEOM::GEOM_Gen reference
221 //=============================================================================
222 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
223 GEOM::GEOM_Gen_var aGeomEngine =
224 GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
225 return aGeomEngine._retn();
228 //=============================================================================
230 * SMESH_Gen_i::SMESH_Gen_i
232 * Default constructor: not for use
234 //=============================================================================
236 SMESH_Gen_i::SMESH_Gen_i()
238 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
241 //=============================================================================
243 * SMESH_Gen_i::SMESH_Gen_i
245 * Standard constructor, used with Container
247 //=============================================================================
249 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
250 PortableServer::POA_ptr poa,
251 PortableServer::ObjectId* contId,
252 const char* instanceName,
253 const char* interfaceName )
254 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
256 INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
258 myOrb = CORBA::ORB::_duplicate(orb);
259 myPoa = PortableServer::POA::_duplicate(poa);
262 _id = myPoa->activate_object( _thisObj );
264 myIsEmbeddedMode = false;
265 myShapeReader = NULL; // shape reader
268 // set it in standalone mode only
269 //OSD::SetSignal( true );
272 //=============================================================================
274 * SMESH_Gen_i::~SMESH_Gen_i
278 //=============================================================================
280 SMESH_Gen_i::~SMESH_Gen_i()
282 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
284 // delete hypothesis creators
285 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
286 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
288 delete (*itHyp).second;
290 myHypCreatorMap.clear();
292 // Clear study contexts data
293 map<int, StudyContext*>::iterator it;
294 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
297 myStudyContextMap.clear();
298 // delete shape reader
299 if ( !myShapeReader )
300 delete myShapeReader;
303 //=============================================================================
305 * SMESH_Gen_i::createHypothesis
307 * Create hypothesis of given type
309 //=============================================================================
310 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
311 const char* theLibName)
312 throw (SALOME::SALOME_Exception)
314 /* It's Need to tranlate lib name for WIN32 or X platform */
315 char* aPlatformLibName = 0;
316 if ( theLibName && theLibName[0] != '\0' )
319 aPlatformLibName = new char[ strlen(theLibName) + 5 ];
320 aPlatformLibName[0] = '\0';
321 aPlatformLibName = strcat( aPlatformLibName, theLibName );
322 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
324 aPlatformLibName = new char[ strlen(theLibName) + 7 ];
325 aPlatformLibName[0] = '\0';
326 aPlatformLibName = strcat( aPlatformLibName, "lib" );
327 aPlatformLibName = strcat( aPlatformLibName, theLibName );
328 aPlatformLibName = strcat( aPlatformLibName, ".so" );
334 Unexpect aCatch(SALOME_SalomeException);
335 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
337 // create a new hypothesis object servant
338 SMESH_Hypothesis_i* myHypothesis_i = 0;
339 SMESH::SMESH_Hypothesis_var hypothesis_i;
343 // check, if creator for this hypothesis type already exists
344 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
346 // load plugin library
347 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
348 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
351 // report any error, if occured
353 const char* anError = dlerror();
354 throw(SALOME_Exception(anError));
356 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
360 // get method, returning hypothesis creator
361 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
362 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
363 GetHypothesisCreator procHandle =
364 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
367 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
368 UnLoadLib(libHandle);
371 // get hypothesis creator
372 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
373 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
376 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
379 // map hypothesis creator to a hypothesis name
380 myHypCreatorMap[string(theHypName)] = aCreator;
383 // create a new hypothesis object, store its ref. in studyContext
384 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
386 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
387 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
389 catch (SALOME_Exception& S_ex)
391 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
394 if ( aPlatformLibName )
395 delete[] aPlatformLibName;
398 return hypothesis_i._retn();
400 // activate the CORBA servant of hypothesis
401 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
402 int nextId = RegisterObject( hypothesis_i );
403 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
405 return hypothesis_i._retn();
408 //=============================================================================
410 * SMESH_Gen_i::createMesh
412 * Create empty mesh on shape
414 //=============================================================================
415 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
416 throw ( SALOME::SALOME_Exception )
418 Unexpect aCatch(SALOME_SalomeException);
419 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
421 // Get or create the GEOM_Client instance
423 // create a new mesh object servant, store it in a map in study context
424 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
425 // create a new mesh object
426 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
428 // activate the CORBA servant of Mesh
429 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
430 int nextId = RegisterObject( mesh );
431 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
434 catch (SALOME_Exception& S_ex) {
435 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
437 return SMESH::SMESH_Mesh::_nil();
440 //=============================================================================
442 * SMESH_Gen_i::GetShapeReader
446 //=============================================================================
447 GEOM_Client* SMESH_Gen_i::GetShapeReader()
449 // create shape reader if necessary
450 if ( !myShapeReader )
451 myShapeReader = new GEOM_Client(GetContainerRef());
452 ASSERT( myShapeReader );
453 return myShapeReader;
456 //=============================================================================
458 * SMESH_Gen_i::SetEmbeddedMode
462 //=============================================================================
464 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
466 myIsEmbeddedMode = theMode;
468 if ( !myIsEmbeddedMode ) {
472 char* envDisableFPE = getenv("DISABLE_FPE");
473 if (envDisableFPE && atoi(envDisableFPE))
478 OSD::SetSignal( raiseFPE );
480 // else OSD::SetSignal() is called in GUI
483 //=============================================================================
485 * SMESH_Gen_i::IsEmbeddedMode
489 //=============================================================================
491 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
493 return myIsEmbeddedMode;
496 //=============================================================================
498 * SMESH_Gen_i::SetCurrentStudy
502 //=============================================================================
504 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
507 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
508 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
509 // create study context, if it doesn't exist and set current study
510 int studyId = GetCurrentStudyID();
511 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
512 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
513 myStudyContextMap[ studyId ] = new StudyContext;
516 // myCurrentStudy may be nil
517 if ( !CORBA::is_nil( myCurrentStudy ) ) {
518 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
519 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
520 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
522 // set current study for geom engine
523 //if ( !CORBA::is_nil( GetGeomEngine() ) )
524 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
528 //=============================================================================
530 * SMESH_Gen_i::GetCurrentStudy
534 //=============================================================================
536 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
538 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
539 return SALOMEDS::Study::_duplicate( myCurrentStudy );
542 //=============================================================================
544 * SMESH_Gen_i::GetCurrentStudyContext
546 * Get current study context
548 //=============================================================================
549 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
551 if ( !CORBA::is_nil( myCurrentStudy ) &&
552 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
553 return myStudyContextMap[ myCurrentStudy->StudyId() ];
558 //=============================================================================
560 * SMESH_Gen_i::CreateHypothesis
562 * Create hypothesis/algorothm of given type and publish it in the study
564 //=============================================================================
566 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
567 const char* theLibName )
568 throw ( SALOME::SALOME_Exception )
570 Unexpect aCatch(SALOME_SalomeException);
571 // Create hypothesis/algorithm
572 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
574 // Publish hypothesis/algorithm in the study
575 if ( CanPublishInStudy( hyp ) ) {
576 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
577 if ( !aSO->_is_nil() ) {
578 // Update Python script
579 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
580 << theHypName << "', '" << theLibName << "')";
587 //================================================================================
589 * \brief Return hypothesis of given type holding parameter values of the existing mesh
590 * \param theHypType - hypothesis type name
591 * \param theLibName - plugin library name
592 * \param theMesh - The mesh of interest
593 * \param theGeom - The shape to get parameter values from
594 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
595 * in a study and used to compute the mesh, or a temporary one created just to pass
598 //================================================================================
600 SMESH::SMESH_Hypothesis_ptr
601 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
602 const char* theLibName,
603 SMESH::SMESH_Mesh_ptr theMesh,
604 GEOM::GEOM_Object_ptr theGeom)
605 throw ( SALOME::SALOME_Exception )
607 Unexpect aCatch(SALOME_SalomeException);
608 if ( CORBA::is_nil( theMesh ) )
609 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
610 if ( CORBA::is_nil( theGeom ) )
611 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
613 // -----------------------------------------------
614 // find hypothesis used to mesh theGeom
615 // -----------------------------------------------
617 // get mesh and shape
618 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
619 TopoDS_Shape shape = GeomObjectToShape( theGeom );
620 if ( !meshServant || shape.IsNull() )
621 return SMESH::SMESH_Hypothesis::_nil();
622 ::SMESH_Mesh& mesh = meshServant->GetImpl();
624 if ( mesh.NbNodes() == 0 ) // empty mesh
625 return SMESH::SMESH_Hypothesis::_nil();
627 // create a temporary hypothesis to know its dimention
628 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
629 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
631 return SMESH::SMESH_Hypothesis::_nil();
632 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
634 // look for a hypothesis of theHypType used to mesh the shape
635 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
638 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
639 int nbLocalHyps = aHypList->length();
640 for ( int i = 0; i < nbLocalHyps; i++ )
641 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
642 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
643 // check super shapes
644 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
645 while ( nbLocalHyps == 0 && itShape.More() ) {
646 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
647 if ( ! CORBA::is_nil( geomObj )) {
648 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
649 nbLocalHyps = aHypList->length();
650 for ( int i = 0; i < nbLocalHyps; i++ )
651 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
652 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
658 // let the temporary hypothesis find out some how parameter values
659 if ( hyp->SetParametersByMesh( &mesh, shape ))
660 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
662 return SMESH::SMESH_Hypothesis::_nil();
665 //=============================================================================
667 * SMESH_Gen_i::CreateMesh
669 * Create empty mesh on a shape and publish it in the study
671 //=============================================================================
673 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
674 throw ( SALOME::SALOME_Exception )
676 Unexpect aCatch(SALOME_SalomeException);
677 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
679 SMESH::SMESH_Mesh_var mesh = this->createMesh();
681 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
682 ASSERT( meshServant );
683 meshServant->SetShape( theShapeObject );
685 // publish mesh in the study
686 if ( CanPublishInStudy( mesh ) ) {
687 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
688 aStudyBuilder->NewCommand(); // There is a transaction
689 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
690 aStudyBuilder->CommitCommand();
691 if ( !aSO->_is_nil() ) {
692 // Update Python script
693 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
700 //=============================================================================
702 * SMESH_Gen_i::CreateEmptyMesh
706 //=============================================================================
708 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
709 throw ( SALOME::SALOME_Exception )
711 Unexpect aCatch(SALOME_SalomeException);
712 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
714 SMESH::SMESH_Mesh_var mesh = this->createMesh();
716 // publish mesh in the study
717 if ( CanPublishInStudy( mesh ) ) {
718 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
719 aStudyBuilder->NewCommand(); // There is a transaction
720 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
721 aStudyBuilder->CommitCommand();
722 if ( !aSO->_is_nil() ) {
723 // Update Python script
724 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
731 //=============================================================================
733 * SMESH_Gen_i::CreateMeshFromUNV
735 * Create mesh and import data from UNV file
737 //=============================================================================
739 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
740 throw ( SALOME::SALOME_Exception )
742 Unexpect aCatch(SALOME_SalomeException);
743 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
745 SMESH::SMESH_Mesh_var aMesh = createMesh();
747 // publish mesh in the study
748 if ( CanPublishInStudy( aMesh ) ) {
749 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
750 aStudyBuilder->NewCommand(); // There is a transaction
751 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
752 aStudyBuilder->CommitCommand();
753 if ( !aSO->_is_nil() ) {
754 // Update Python script
755 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
759 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
761 aServant->ImportUNVFile( theFileName );
763 // Dump creation of groups
764 aServant->GetGroups();
766 return aMesh._retn();
769 //=============================================================================
771 * SMESH_Gen_i::CreateMeshFromMED
773 * Create mesh and import data from MED file
775 //=============================================================================
777 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
778 SMESH::DriverMED_ReadStatus& theStatus)
779 throw ( SALOME::SALOME_Exception )
781 Unexpect aCatch(SALOME_SalomeException);
782 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
784 // Retrieve mesh names from the file
785 DriverMED_R_SMESHDS_Mesh myReader;
786 myReader.SetFile( theFileName );
787 myReader.SetMeshId( -1 );
788 Driver_Mesh::Status aStatus;
789 list<string> aNames = myReader.GetMeshNames(aStatus);
790 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
791 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
793 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
796 TPythonDump aPythonDump;
798 //TCollection_AsciiString aStr ("([");
800 if (theStatus == SMESH::DRS_OK) {
801 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
802 aStudyBuilder->NewCommand(); // There is a transaction
803 aResult->length( aNames.size() );
806 // Iterate through all meshes and create mesh objects
807 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
809 //if (i > 0) aStr += ", ";
810 if (i > 0) aPythonDump << ", ";
813 SMESH::SMESH_Mesh_var mesh = createMesh();
815 // publish mesh in the study
816 SALOMEDS::SObject_var aSO;
817 if ( CanPublishInStudy( mesh ) )
818 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
819 if ( !aSO->_is_nil() ) {
822 //aStr += aSO->GetID();
825 aPythonDump << "mesh_" << i;
827 // aStr += TCollection_AsciiString(i);
830 // Read mesh data (groups are published automatically by ImportMEDFile())
831 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
832 ASSERT( meshServant );
833 SMESH::DriverMED_ReadStatus status1 =
834 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
835 if (status1 > theStatus)
838 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
840 aStudyBuilder->CommitCommand();
843 // Update Python script
844 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
846 // Dump creation of groups
847 for ( int i = 0; i < aResult->length(); ++i )
848 aResult[ i ]->GetGroups();
850 return aResult._retn();
853 //=============================================================================
855 * SMESH_Gen_i::CreateMeshFromSTL
857 * Create mesh and import data from STL file
859 //=============================================================================
861 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
862 throw ( SALOME::SALOME_Exception )
864 Unexpect aCatch(SALOME_SalomeException);
865 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
867 SMESH::SMESH_Mesh_var aMesh = createMesh();
869 // publish mesh in the study
870 if ( CanPublishInStudy( aMesh ) ) {
871 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
872 aStudyBuilder->NewCommand(); // There is a transaction
873 SALOMEDS::SObject_var aSO = PublishInStudy
874 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
875 aStudyBuilder->CommitCommand();
876 if ( !aSO->_is_nil() ) {
877 // Update Python script
878 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
882 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
884 aServant->ImportSTLFile( theFileName );
885 return aMesh._retn();
888 //=============================================================================
890 * SMESH_Gen_i::IsReadyToCompute
892 * Returns true if mesh contains enough data to be computed
894 //=============================================================================
896 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
897 GEOM::GEOM_Object_ptr theShapeObject )
898 throw ( SALOME::SALOME_Exception )
900 Unexpect aCatch(SALOME_SalomeException);
901 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
903 if ( CORBA::is_nil( theShapeObject ) )
904 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
907 if ( CORBA::is_nil( theMesh ) )
908 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
913 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
914 ASSERT( meshServant );
916 // get local TopoDS_Shape
917 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
918 // call implementation
919 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
920 return myGen.CheckAlgoState( myLocMesh, myLocShape );
923 catch ( SALOME_Exception& S_ex ) {
924 INFOS( "catch exception "<< S_ex.what() );
929 //================================================================================
931 * \brief Returns errors of hypotheses definintion
932 * \param theMesh - the mesh
933 * \param theSubObject - the main or sub- shape
934 * \retval SMESH::algo_error_array* - sequence of errors
936 //================================================================================
938 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
939 GEOM::GEOM_Object_ptr theSubObject )
940 throw ( SALOME::SALOME_Exception )
942 Unexpect aCatch(SALOME_SalomeException);
943 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
945 if ( CORBA::is_nil( theSubObject ) )
946 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
948 if ( CORBA::is_nil( theMesh ) )
949 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
951 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
953 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
954 ASSERT( meshServant );
956 TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
957 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
958 list< ::SMESH_Gen::TAlgoStateError > error_list;
959 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
960 // call ::SMESH_Gen::GetAlgoState()
961 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
962 error_array->length( error_list.size() );
964 for ( error = error_list.begin(); error != error_list.end(); ++error )
967 SMESH::AlgoStateErrorName errName;
968 switch ( error->_name ) {
969 case ::SMESH_Gen::MISSING_ALGO: errName = SMESH::MISSING_ALGO; break;
970 case ::SMESH_Gen::MISSING_HYPO: errName = SMESH::MISSING_HYPO; break;
971 case ::SMESH_Gen::NOT_CONFORM_MESH: errName = SMESH::NOT_CONFORM_MESH; break;
973 THROW_SALOME_CORBA_EXCEPTION( "bad error name",SALOME::BAD_PARAM );
976 CORBA::String_var algoName;
977 if ( error->_algo ) {
978 if ( !myCurrentStudy->_is_nil() ) {
979 // find algo in the study
980 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
981 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
982 if ( !father->_is_nil() ) {
983 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
984 for ( ; itBig->More(); itBig->Next() ) {
985 SALOMEDS::SObject_var gotBranch = itBig->Value();
986 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
987 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
988 for ( ; algoIt->More(); algoIt->Next() ) {
989 SALOMEDS::SObject_var algoSO = algoIt->Value();
990 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
991 if ( !CORBA::is_nil( algoIOR )) {
992 SMESH_Hypothesis_i* myImpl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
993 if ( myImpl && myImpl->GetImpl() == error->_algo ) {
994 algoName = algoSO->GetName();
998 } // loop on algo SO's
1001 } // SMESH component iterator
1004 if ( algoName.in() == 0 )
1005 // use algo type name
1006 algoName = CORBA::string_dup( error->_algo->GetName() );
1008 // fill AlgoStateError structure
1009 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1010 errStruct.name = errName;
1011 errStruct.algoName = algoName;
1012 errStruct.algoDim = error->_algoDim;
1013 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1017 catch ( SALOME_Exception& S_ex ) {
1018 INFOS( "catch exception "<< S_ex.what() );
1020 return error_array._retn();
1023 //=============================================================================
1025 * SMESH_Gen_i::GetSubShapesId
1027 * Get sub-shapes unique ID's list
1029 //=============================================================================
1031 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1032 const SMESH::object_array& theListOfSubShapeObject )
1033 throw ( SALOME::SALOME_Exception )
1035 Unexpect aCatch(SALOME_SalomeException);
1036 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1038 SMESH::long_array_var shapesId = new SMESH::long_array;
1041 if ( CORBA::is_nil( theMainShapeObject ) )
1042 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1043 SALOME::BAD_PARAM );
1047 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1048 TopTools_IndexedMapOfShape myIndexToShape;
1049 TopExp::MapShapes(myMainShape,myIndexToShape);
1051 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1053 GEOM::GEOM_Object_var aShapeObject
1054 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1055 if ( CORBA::is_nil( aShapeObject ) )
1056 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1057 SALOME::BAD_PARAM );
1059 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1060 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1062 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1063 setId.insert(myIndexToShape.FindIndex(F));
1064 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1066 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1068 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1069 setId.insert(myIndexToShape.FindIndex(E));
1070 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1072 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1074 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1075 setId.insert(myIndexToShape.FindIndex(V));
1076 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1079 shapesId->length(setId.size());
1080 set<int>::iterator iind;
1082 for (iind = setId.begin(); iind != setId.end(); iind++)
1084 if(MYDEBUG) SCRUTE((*iind));
1085 shapesId[i] = (*iind);
1086 if(MYDEBUG) SCRUTE(shapesId[i]);
1090 catch (SALOME_Exception& S_ex)
1092 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1095 return shapesId._retn();
1098 //=============================================================================
1100 * SMESH_Gen_i::Compute
1102 * Compute mesh on a shape
1104 //=============================================================================
1106 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1107 GEOM::GEOM_Object_ptr theShapeObject )
1108 throw ( SALOME::SALOME_Exception )
1110 Unexpect aCatch(SALOME_SalomeException);
1111 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1113 if ( CORBA::is_nil( theShapeObject ) )
1114 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1115 SALOME::BAD_PARAM );
1117 if ( CORBA::is_nil( theMesh ) )
1118 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1119 SALOME::BAD_PARAM );
1121 // Update Python script
1122 TPythonDump() << "isDone = " << this << ".Compute( "
1123 << theMesh << ", " << theShapeObject << ")";
1124 TPythonDump() << "if not isDone: print 'Mesh " << theMesh << " : computation failed'";
1128 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1129 ASSERT( meshServant );
1130 if ( meshServant ) {
1131 // get local TopoDS_Shape
1132 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1133 // call implementation compute
1134 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1135 return myGen.Compute( myLocMesh, myLocShape);
1138 catch ( SALOME_Exception& S_ex ) {
1139 INFOS( "Compute(): catch exception "<< S_ex.what() );
1142 INFOS( "Compute(): unknown exception " );
1147 //================================================================================
1149 * \brief Return geometrical object the given element is built on
1150 * \param theMesh - the mesh the element is in
1151 * \param theElementID - the element ID
1152 * \param theGeomName - the name of the result geom object if it is not yet published
1153 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1155 //================================================================================
1157 GEOM::GEOM_Object_ptr
1158 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1159 CORBA::Long theElementID,
1160 const char* theGeomName)
1161 throw ( SALOME::SALOME_Exception )
1163 Unexpect aCatch(SALOME_SalomeException);
1164 if ( CORBA::is_nil( theMesh ) )
1165 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1167 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1168 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1170 // get a core mesh DS
1171 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1172 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1174 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1175 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1176 // find the element in mesh
1177 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
1178 // find a shape id by the element
1179 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1180 // get a geom object by the shape id
1181 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1182 if ( geom->_is_nil() ) {
1183 GEOM::GEOM_IShapesOperations_var op =
1184 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1185 if ( !op->_is_nil() )
1186 geom = op->GetSubShape( mainShape, shapeID );
1188 if ( !geom->_is_nil() ) {
1189 // try to find the corresponding SObject
1190 GeomObjectToShape( geom ); // geom client remembers the found shape
1191 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1192 if ( SObj->_is_nil() )
1193 // publish a new subshape
1194 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1195 // return only published geometry
1196 if ( !SObj->_is_nil() )
1197 return geom._retn();
1201 return GEOM::GEOM_Object::_nil();
1204 //=============================================================================
1208 * Save SMESH module's data
1210 //=============================================================================
1211 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1215 INFOS( "SMESH_Gen_i::Save" );
1217 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1218 // san -- in case <myCurrentStudy> differs from theComponent's study,
1219 // use that of the component
1220 if ( myCurrentStudy->_is_nil() ||
1221 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1222 SetCurrentStudy( theComponent->GetStudy() );
1224 // Store study contents as a set of python commands
1225 SavePython(myCurrentStudy);
1227 StudyContext* myStudyContext = GetCurrentStudyContext();
1229 // Declare a byte stream
1230 SALOMEDS::TMPFile_var aStreamFile;
1232 // Obtain a temporary dir
1233 TCollection_AsciiString tmpDir =
1234 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1236 // Create a sequence of files processed
1237 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1238 aFileSeq->length( NUM_TMP_FILES );
1240 TCollection_AsciiString aStudyName( "" );
1242 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1244 // Set names of temporary files
1245 TCollection_AsciiString filename =
1246 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1247 TCollection_AsciiString meshfile =
1248 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1249 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1250 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1251 filename = tmpDir + filename;
1252 meshfile = tmpDir + meshfile;
1255 HDFdataset* aDataset;
1256 HDFgroup* aTopGroup;
1258 HDFgroup* aSubGroup;
1259 HDFgroup* aSubSubGroup;
1260 hdf_size aSize[ 1 ];
1263 //Remove the files if they exist: BugID: 11225
1264 #ifndef WNT /* unix functionality */
1265 TCollection_AsciiString cmd("rm -f \"");
1267 TCollection_AsciiString cmd("del /F \"");
1274 system(cmd.ToCString());
1276 // MED writer to be used by storage process
1277 DriverMED_W_SMESHDS_Mesh myWriter;
1278 myWriter.SetFile( meshfile.ToCString() );
1281 // ---> create HDF file
1282 aFile = new HDFfile( filename.ToCString() );
1283 aFile->CreateOnDisk();
1285 // --> iterator for top-level objects
1286 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1287 for ( ; itBig->More(); itBig->Next() ) {
1288 SALOMEDS::SObject_var gotBranch = itBig->Value();
1290 // --> hypotheses root branch (only one for the study)
1291 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1292 // create hypotheses root HDF group
1293 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1294 aTopGroup->CreateOnDisk();
1296 // iterator for all hypotheses
1297 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1298 for ( ; it->More(); it->Next() ) {
1299 SALOMEDS::SObject_var mySObject = it->Value();
1300 CORBA::Object_var anObject = SObjectToObject( mySObject );
1301 if ( !CORBA::is_nil( anObject ) ) {
1302 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1303 if ( !myHyp->_is_nil() ) {
1304 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1306 string hypname = string( myHyp->GetName() );
1307 string libname = string( myHyp->GetLibName() );
1309 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1310 // WNT and ".so" for X-system) must be deleted
1311 int libname_len = libname.length();
1313 if( libname_len > 4 )
1314 libname.resize( libname_len - 4 );
1316 if( libname_len > 3 )
1317 libname.resize( libname_len - 3 );
1319 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1320 int id = myStudyContext->findId( string( objStr.in() ) );
1321 string hypdata = string( myImpl->SaveTo() );
1323 // for each hypothesis create HDF group basing on its id
1324 char hypGrpName[30];
1325 sprintf( hypGrpName, "Hypothesis %d", id );
1326 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1327 aGroup->CreateOnDisk();
1328 // --> type name of hypothesis
1329 aSize[ 0 ] = hypname.length() + 1;
1330 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1331 aDataset->CreateOnDisk();
1332 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1333 aDataset->CloseOnDisk();
1334 // --> server plugin library name of hypothesis
1335 aSize[ 0 ] = libname.length() + 1;
1336 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1337 aDataset->CreateOnDisk();
1338 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1339 aDataset->CloseOnDisk();
1340 // --> persistent data of hypothesis
1341 aSize[ 0 ] = hypdata.length() + 1;
1342 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1343 aDataset->CreateOnDisk();
1344 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1345 aDataset->CloseOnDisk();
1346 // close hypothesis HDF group
1347 aGroup->CloseOnDisk();
1352 // close hypotheses root HDF group
1353 aTopGroup->CloseOnDisk();
1355 // --> algorithms root branch (only one for the study)
1356 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1357 // create algorithms root HDF group
1358 aTopGroup = new HDFgroup( "Algorithms", aFile );
1359 aTopGroup->CreateOnDisk();
1361 // iterator for all algorithms
1362 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1363 for ( ; it->More(); it->Next() ) {
1364 SALOMEDS::SObject_var mySObject = it->Value();
1365 CORBA::Object_var anObject = SObjectToObject( mySObject );
1366 if ( !CORBA::is_nil( anObject ) ) {
1367 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1368 if ( !myHyp->_is_nil() ) {
1369 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1371 string hypname = string( myHyp->GetName() );
1372 string libname = string( myHyp->GetLibName() );
1374 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1375 // WNT and ".so" for X-system) must be deleted
1376 int libname_len = libname.length();
1378 if( libname_len > 4 )
1379 libname.resize( libname_len - 4 );
1381 if( libname_len > 3 )
1382 libname.resize( libname_len - 3 );
1384 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1385 int id = myStudyContext->findId( string( objStr.in() ) );
1386 string hypdata = string( myImpl->SaveTo() );
1388 // for each algorithm create HDF group basing on its id
1389 char hypGrpName[30];
1390 sprintf( hypGrpName, "Algorithm %d", id );
1391 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1392 aGroup->CreateOnDisk();
1393 // --> type name of algorithm
1394 aSize[0] = hypname.length() + 1;
1395 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1396 aDataset->CreateOnDisk();
1397 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1398 aDataset->CloseOnDisk();
1399 // --> server plugin library name of hypothesis
1400 aSize[0] = libname.length() + 1;
1401 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1402 aDataset->CreateOnDisk();
1403 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1404 aDataset->CloseOnDisk();
1405 // --> persistent data of algorithm
1406 aSize[0] = hypdata.length() + 1;
1407 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1408 aDataset->CreateOnDisk();
1409 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1410 aDataset->CloseOnDisk();
1411 // close algorithm HDF group
1412 aGroup->CloseOnDisk();
1417 // close algorithms root HDF group
1418 aTopGroup->CloseOnDisk();
1420 // --> mesh objects roots branches
1421 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1422 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1423 if ( !CORBA::is_nil( anObject ) ) {
1424 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1425 if ( !myMesh->_is_nil() ) {
1426 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1428 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1429 int id = myStudyContext->findId( string( objStr.in() ) );
1430 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1431 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1433 // for each mesh open the HDF group basing on its id
1434 char meshGrpName[ 30 ];
1435 sprintf( meshGrpName, "Mesh %d", id );
1436 aTopGroup = new HDFgroup( meshGrpName, aFile );
1437 aTopGroup->CreateOnDisk();
1439 // --> put dataset to hdf file which is a flag that mesh has data
1440 string strHasData = "0";
1441 // check if the mesh is not empty
1442 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1443 // write mesh data to med file
1444 myWriter.SetMesh( mySMESHDSMesh );
1445 myWriter.SetMeshId( id );
1448 aSize[ 0 ] = strHasData.length() + 1;
1449 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1450 aDataset->CreateOnDisk();
1451 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1452 aDataset->CloseOnDisk();
1454 // write reference on a shape if exists
1455 SALOMEDS::SObject_var myRef;
1456 bool shapeRefFound = false;
1457 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1459 SALOMEDS::SObject_var myShape;
1460 bool ok = myRef->ReferencedObject( myShape );
1462 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1463 string myRefOnObject = myShape->GetID();
1464 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1465 aSize[ 0 ] = myRefOnObject.length() + 1;
1466 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1467 aDataset->CreateOnDisk();
1468 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1469 aDataset->CloseOnDisk();
1474 // write applied hypotheses if exist
1475 SALOMEDS::SObject_var myHypBranch;
1476 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1477 if ( found && !shapeRefFound ) { // remove applied hyps
1478 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1480 if ( found && shapeRefFound ) {
1481 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1482 aGroup->CreateOnDisk();
1484 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1486 for ( ; it->More(); it->Next() ) {
1487 SALOMEDS::SObject_var mySObject = it->Value();
1488 SALOMEDS::SObject_var myRefOnHyp;
1489 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1491 // san - it is impossible to recover applied hypotheses
1492 // using their entries within Load() method,
1493 // for there are no AttributeIORs in the study when Load() is working.
1494 // Hence, it is better to store persistent IDs of hypotheses as references to them
1496 //string myRefOnObject = myRefOnHyp->GetID();
1497 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1498 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1499 int id = myStudyContext->findId( string( objStr.in() ) );
1500 //if ( myRefOnObject.length() > 0 ) {
1501 //aSize[ 0 ] = myRefOnObject.length() + 1;
1502 char hypName[ 30 ], hypId[ 30 ];
1503 sprintf( hypName, "Hyp %d", ++hypNb );
1504 sprintf( hypId, "%d", id );
1505 aSize[ 0 ] = strlen( hypId ) + 1;
1506 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1507 aDataset->CreateOnDisk();
1508 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1509 aDataset->WriteOnDisk( hypId );
1510 aDataset->CloseOnDisk();
1514 aGroup->CloseOnDisk();
1517 // write applied algorithms if exist
1518 SALOMEDS::SObject_var myAlgoBranch;
1519 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1520 if ( found && !shapeRefFound ) { // remove applied algos
1521 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1523 if ( found && shapeRefFound ) {
1524 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1525 aGroup->CreateOnDisk();
1527 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1529 for ( ; it->More(); it->Next() ) {
1530 SALOMEDS::SObject_var mySObject = it->Value();
1531 SALOMEDS::SObject_var myRefOnAlgo;
1532 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1534 // san - it is impossible to recover applied algorithms
1535 // using their entries within Load() method,
1536 // for there are no AttributeIORs in the study when Load() is working.
1537 // Hence, it is better to store persistent IDs of algorithms as references to them
1539 //string myRefOnObject = myRefOnAlgo->GetID();
1540 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1541 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1542 int id = myStudyContext->findId( string( objStr.in() ) );
1543 //if ( myRefOnObject.length() > 0 ) {
1544 //aSize[ 0 ] = myRefOnObject.length() + 1;
1545 char algoName[ 30 ], algoId[ 30 ];
1546 sprintf( algoName, "Algo %d", ++algoNb );
1547 sprintf( algoId, "%d", id );
1548 aSize[ 0 ] = strlen( algoId ) + 1;
1549 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1550 aDataset->CreateOnDisk();
1551 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1552 aDataset->WriteOnDisk( algoId );
1553 aDataset->CloseOnDisk();
1557 aGroup->CloseOnDisk();
1560 // --> submesh objects sub-branches
1562 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1563 SALOMEDS::SObject_var mySubmeshBranch;
1564 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1566 if ( found ) // check if there is shape reference in submeshes
1568 bool hasShapeRef = false;
1569 SALOMEDS::ChildIterator_var itSM =
1570 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1571 for ( ; itSM->More(); itSM->Next() ) {
1572 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1573 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1574 mySubRef->ReferencedObject( myShape );
1575 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1578 { // remove one submesh
1579 if ( shapeRefFound )
1580 { // unassign hypothesis
1581 SMESH::SMESH_subMesh_var mySubMesh =
1582 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1583 if ( !mySubMesh->_is_nil() ) {
1584 int shapeID = mySubMesh->GetId();
1585 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1586 const list<const SMESHDS_Hypothesis*>& hypList =
1587 mySMESHDSMesh->GetHypothesis( S );
1588 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1589 while ( hyp != hypList.end() ) {
1590 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1591 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1595 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1597 } // loop on submeshes of a type
1598 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1599 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1602 } // end check if there is shape reference in submeshes
1604 char name_meshgroup[ 30 ];
1605 if ( i == GetSubMeshOnVertexTag() )
1606 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1607 else if ( i == GetSubMeshOnEdgeTag() )
1608 strcpy( name_meshgroup, "SubMeshes On Edge" );
1609 else if ( i == GetSubMeshOnWireTag() )
1610 strcpy( name_meshgroup, "SubMeshes On Wire" );
1611 else if ( i == GetSubMeshOnFaceTag() )
1612 strcpy( name_meshgroup, "SubMeshes On Face" );
1613 else if ( i == GetSubMeshOnShellTag() )
1614 strcpy( name_meshgroup, "SubMeshes On Shell" );
1615 else if ( i == GetSubMeshOnSolidTag() )
1616 strcpy( name_meshgroup, "SubMeshes On Solid" );
1617 else if ( i == GetSubMeshOnCompoundTag() )
1618 strcpy( name_meshgroup, "SubMeshes On Compound" );
1620 // for each type of submeshes create container HDF group
1621 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1622 aGroup->CreateOnDisk();
1624 // iterator for all submeshes of given type
1625 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1626 for ( ; itSM->More(); itSM->Next() ) {
1627 SALOMEDS::SObject_var mySObject = itSM->Value();
1628 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1629 if ( !CORBA::is_nil( anSubObject ))
1631 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1632 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
1633 int subid = myStudyContext->findId( string( objStr.in() ) );
1635 // for each mesh open the HDF group basing on its id
1636 char submeshGrpName[ 30 ];
1637 sprintf( submeshGrpName, "SubMesh %d", subid );
1638 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1639 aSubGroup->CreateOnDisk();
1641 // write reference on a shape, already checked if it exists
1642 SALOMEDS::SObject_var mySubRef, myShape;
1643 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1644 mySubRef->ReferencedObject( myShape );
1645 string myRefOnObject = myShape->GetID();
1646 if ( myRefOnObject.length() > 0 ) {
1647 aSize[ 0 ] = myRefOnObject.length() + 1;
1648 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1649 aDataset->CreateOnDisk();
1650 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1651 aDataset->CloseOnDisk();
1654 // write applied hypotheses if exist
1655 SALOMEDS::SObject_var mySubHypBranch;
1656 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1658 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1659 aSubSubGroup->CreateOnDisk();
1661 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1663 for ( ; it->More(); it->Next() ) {
1664 SALOMEDS::SObject_var mySubSObject = it->Value();
1665 SALOMEDS::SObject_var myRefOnHyp;
1666 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1668 //string myRefOnObject = myRefOnHyp->GetID();
1669 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1670 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1671 int id = myStudyContext->findId( string( objStr.in() ) );
1672 //if ( myRefOnObject.length() > 0 ) {
1673 //aSize[ 0 ] = myRefOnObject.length() + 1;
1674 char hypName[ 30 ], hypId[ 30 ];
1675 sprintf( hypName, "Hyp %d", ++hypNb );
1676 sprintf( hypId, "%d", id );
1677 aSize[ 0 ] = strlen( hypId ) + 1;
1678 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1679 aDataset->CreateOnDisk();
1680 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1681 aDataset->WriteOnDisk( hypId );
1682 aDataset->CloseOnDisk();
1686 aSubSubGroup->CloseOnDisk();
1689 // write applied algorithms if exist
1690 SALOMEDS::SObject_var mySubAlgoBranch;
1691 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1693 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1694 aSubSubGroup->CreateOnDisk();
1696 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1698 for ( ; it->More(); it->Next() ) {
1699 SALOMEDS::SObject_var mySubSObject = it->Value();
1700 SALOMEDS::SObject_var myRefOnAlgo;
1701 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1703 //string myRefOnObject = myRefOnAlgo->GetID();
1704 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1705 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1706 int id = myStudyContext->findId( string( objStr.in() ) );
1707 //if ( myRefOnObject.length() > 0 ) {
1708 //aSize[ 0 ] = myRefOnObject.length() + 1;
1709 char algoName[ 30 ], algoId[ 30 ];
1710 sprintf( algoName, "Algo %d", ++algoNb );
1711 sprintf( algoId, "%d", id );
1712 aSize[ 0 ] = strlen( algoId ) + 1;
1713 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1714 aDataset->CreateOnDisk();
1715 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1716 aDataset->WriteOnDisk( algoId );
1717 aDataset->CloseOnDisk();
1721 aSubSubGroup->CloseOnDisk();
1723 // close submesh HDF group
1724 aSubGroup->CloseOnDisk();
1727 // close container of submeshes by type HDF group
1728 aGroup->CloseOnDisk();
1731 // All sub-meshes will be stored in MED file
1732 if ( shapeRefFound )
1733 myWriter.AddAllSubMeshes();
1735 // groups root sub-branch
1736 SALOMEDS::SObject_var myGroupsBranch;
1737 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1738 found = gotBranch->FindSubObject( i, myGroupsBranch );
1740 char name_group[ 30 ];
1741 if ( i == GetNodeGroupsTag() )
1742 strcpy( name_group, "Groups of Nodes" );
1743 else if ( i == GetEdgeGroupsTag() )
1744 strcpy( name_group, "Groups of Edges" );
1745 else if ( i == GetFaceGroupsTag() )
1746 strcpy( name_group, "Groups of Faces" );
1747 else if ( i == GetVolumeGroupsTag() )
1748 strcpy( name_group, "Groups of Volumes" );
1750 aGroup = new HDFgroup( name_group, aTopGroup );
1751 aGroup->CreateOnDisk();
1753 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
1754 for ( ; it->More(); it->Next() ) {
1755 SALOMEDS::SObject_var mySObject = it->Value();
1756 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
1757 if ( !CORBA::is_nil( aSubObject ) ) {
1758 SMESH_GroupBase_i* myGroupImpl =
1759 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
1763 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
1764 int anId = myStudyContext->findId( string( objStr.in() ) );
1766 // For each group, create a dataset named "Group <group_persistent_id>"
1767 // and store the group's user name into it
1769 sprintf( grpName, "Group %d", anId );
1770 char* aUserName = myGroupImpl->GetName();
1771 aSize[ 0 ] = strlen( aUserName ) + 1;
1773 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
1774 aDataset->CreateOnDisk();
1775 aDataset->WriteOnDisk( aUserName );
1776 aDataset->CloseOnDisk();
1778 // Store the group contents into MED file
1779 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
1781 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
1782 << grpName << " to MED file" );
1783 SMESHDS_GroupBase* aGrpBaseDS =
1784 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
1785 aGrpBaseDS->SetStoreName( grpName );
1787 // Pass SMESHDS_Group to MED writer
1788 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
1790 myWriter.AddGroup( aGrpDS );
1792 // write reference on a shape if exists
1793 SMESHDS_GroupOnGeom* aGeomGrp =
1794 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
1796 SALOMEDS::SObject_var mySubRef, myShape;
1797 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
1798 mySubRef->ReferencedObject( myShape ) &&
1799 !CORBA::is_nil( myShape->GetObject() ))
1801 string myRefOnObject = myShape->GetID();
1802 if ( myRefOnObject.length() > 0 ) {
1803 char aRefName[ 30 ];
1804 sprintf( aRefName, "Ref on shape %d", anId);
1805 aSize[ 0 ] = myRefOnObject.length() + 1;
1806 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
1807 aDataset->CreateOnDisk();
1808 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1809 aDataset->CloseOnDisk();
1812 else // shape ref is invalid:
1814 // save a group on geometry as ordinary group
1815 myWriter.AddGroup( aGeomGrp );
1821 aGroup->CloseOnDisk();
1825 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
1827 // Flush current mesh information into MED file
1830 // maybe a shape was deleted in the study
1831 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
1832 TopoDS_Shape nullShape;
1833 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
1836 // Store node positions on sub-shapes (SMDS_Position):
1838 if ( !mySMESHDSMesh->SubMeshes().empty() )
1840 aGroup = new HDFgroup( "Node Positions", aTopGroup );
1841 aGroup->CreateOnDisk();
1843 // in aGroup, create 5 datasets to contain:
1844 // "Nodes on Edges" - ID of node on edge
1845 // "Edge positions" - U parameter on node on edge
1846 // "Nodes on Faces" - ID of node on face
1847 // "Face U positions" - U parameter of node on face
1848 // "Face V positions" - V parameter of node on face
1850 // Find out nb of nodes on edges and faces
1851 // Collect corresponing sub-meshes
1852 int nbEdgeNodes = 0, nbFaceNodes = 0;
1853 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
1854 // loop on SMESHDS_SubMesh'es
1855 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
1856 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
1857 for ( ; itSubM != aSubMeshes.end() ; itSubM++ )
1859 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
1860 if ( aSubMesh->IsComplexSubmesh() )
1861 continue; // submesh containing other submeshs
1862 int nbNodes = aSubMesh->NbNodes();
1863 if ( nbNodes == 0 ) continue;
1865 int aShapeID = (*itSubM).first;
1866 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
1867 // write only SMDS_FacePosition and SMDS_EdgePosition
1868 switch ( aShapeType ) {
1870 nbFaceNodes += nbNodes;
1871 aFaceSM.push_back( aSubMesh );
1874 nbEdgeNodes += nbNodes;
1875 aEdgeSM.push_back( aSubMesh );
1881 // Treat positions on edges or faces
1882 for ( int onFace = 0; onFace < 2; onFace++ )
1884 // Create arrays to store in datasets
1885 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
1886 if (!nbNodes) continue;
1887 int* aNodeIDs = new int [ nbNodes ];
1888 double* aUPos = new double [ nbNodes ];
1889 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
1892 // loop on sub-meshes
1893 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
1894 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
1895 for ( ; itSM != pListSM->end(); itSM++ )
1897 SMESHDS_SubMesh* aSubMesh = (*itSM);
1898 if ( aSubMesh->IsComplexSubmesh() )
1899 continue; // submesh containing other submeshs
1901 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
1902 // loop on nodes in aSubMesh
1903 while ( itNode->more() )
1906 const SMDS_MeshNode* node = itNode->next();
1907 aNodeIDs [ iNode ] = node->GetID();
1910 const SMDS_PositionPtr pos = node->GetPosition();
1911 if ( onFace ) { // on FACE
1912 const SMDS_FacePosition* fPos =
1913 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
1915 aUPos[ iNode ] = fPos->GetUParameter();
1916 aVPos[ iNode ] = fPos->GetVParameter();
1923 const SMDS_EdgePosition* ePos =
1924 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
1926 aUPos[ iNode ] = ePos->GetUParameter();
1932 } // loop on nodes in aSubMesh
1933 } // loop on sub-meshes
1938 aSize[ 0 ] = nbNodes;
1940 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
1941 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
1942 aDataset->CreateOnDisk();
1943 aDataset->WriteOnDisk( aNodeIDs );
1944 aDataset->CloseOnDisk();
1947 aDSName = ( onFace ? "Face U positions" : "Edge positions");
1948 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
1949 aDataset->CreateOnDisk();
1950 aDataset->WriteOnDisk( aUPos );
1951 aDataset->CloseOnDisk();
1954 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
1955 aDataset->CreateOnDisk();
1956 aDataset->WriteOnDisk( aVPos );
1957 aDataset->CloseOnDisk();
1962 if ( aVPos ) delete [] aVPos;
1964 } // treat positions on edges or faces
1966 // close "Node Positions" group
1967 aGroup->CloseOnDisk();
1969 } // if ( there are submeshes in SMESHDS_Mesh )
1972 // close mesh HDF group
1973 aTopGroup->CloseOnDisk();
1981 aFile->CloseOnDisk();
1984 // Convert temporary files to stream
1985 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
1987 // Remove temporary files and directory
1989 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
1991 INFOS( "SMESH_Gen_i::Save() completed" );
1992 return aStreamFile._retn();
1995 //=============================================================================
1997 * SMESH_Gen_i::SaveASCII
1999 * Save SMESH module's data in ASCII format
2001 //=============================================================================
2003 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2005 bool isMultiFile ) {
2006 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2007 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2009 //after usual saving needs to encipher binary to text string
2010 //Any binary symbol will be represent as "|xx" () hexadecimal format number
2011 int size = aStreamFile.in().length();
2012 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
2013 for ( int i = 0; i < size; i++ )
2014 sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
2016 buffer[size * 3] = '\0';
2018 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
2020 return anAsciiStreamFile._retn();
2023 //=============================================================================
2025 * SMESH_Gen_i::loadGeomData
2027 * Load GEOM module data
2029 //=============================================================================
2031 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2033 if ( theCompRoot->_is_nil() )
2036 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2037 if ( aStudy->_is_nil() )
2040 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2041 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2044 //=============================================================================
2048 * Load SMESH module's data
2050 //=============================================================================
2052 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2053 const SALOMEDS::TMPFile& theStream,
2057 INFOS( "SMESH_Gen_i::Load" );
2059 if ( myCurrentStudy->_is_nil() ||
2060 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2061 SetCurrentStudy( theComponent->GetStudy() );
2063 /* if( !theComponent->_is_nil() )
2065 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2066 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2067 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2070 StudyContext* myStudyContext = GetCurrentStudyContext();
2072 // Get temporary files location
2073 TCollection_AsciiString tmpDir =
2074 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2076 // Convert the stream into sequence of files to process
2077 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2080 TCollection_AsciiString aStudyName( "" );
2082 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2084 // Set names of temporary files
2085 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2086 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2090 HDFdataset* aDataset;
2091 HDFgroup* aTopGroup;
2093 HDFgroup* aSubGroup;
2094 HDFgroup* aSubSubGroup;
2097 // ---> open HDF file
2098 aFile = new HDFfile( filename.ToCString() );
2100 aFile->OpenOnDisk( HDF_RDONLY );
2102 catch ( HDFexception ) {
2103 INFOS( "Load(): " << filename << " not found!" );
2107 DriverMED_R_SMESHDS_Mesh myReader;
2108 myReader.SetFile( meshfile.ToCString() );
2110 // get total number of top-level groups
2111 int aNbGroups = aFile->nInternalObjects();
2112 if ( aNbGroups > 0 ) {
2113 // --> in first turn we should read&create hypotheses
2114 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2115 // open hypotheses root HDF group
2116 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2117 aTopGroup->OpenOnDisk();
2119 // get number of hypotheses
2120 int aNbObjects = aTopGroup->nInternalObjects();
2121 for ( int j = 0; j < aNbObjects; j++ ) {
2122 // try to identify hypothesis
2123 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2124 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2126 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2127 // open hypothesis group
2128 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2129 aGroup->OpenOnDisk();
2131 // --> get hypothesis id
2132 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2137 // get number of datasets
2138 int aNbSubObjects = aGroup->nInternalObjects();
2139 for ( int k = 0; k < aNbSubObjects; k++ ) {
2141 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2142 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2143 // --> get hypothesis name
2144 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2145 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2146 aDataset->OpenOnDisk();
2147 size = aDataset->GetSize();
2148 char* hypname_str = new char[ size ];
2149 aDataset->ReadFromDisk( hypname_str );
2150 hypname = string( hypname_str );
2151 delete [] hypname_str;
2152 aDataset->CloseOnDisk();
2154 // --> get hypothesis plugin library name
2155 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2156 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2157 aDataset->OpenOnDisk();
2158 size = aDataset->GetSize();
2159 char* libname_str = new char[ size ];
2160 aDataset->ReadFromDisk( libname_str );
2161 if(MYDEBUG) SCRUTE( libname_str );
2162 libname = string( libname_str );
2163 delete [] libname_str;
2164 aDataset->CloseOnDisk();
2166 // --> get hypothesis data
2167 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2168 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2169 aDataset->OpenOnDisk();
2170 size = aDataset->GetSize();
2171 char* hypdata_str = new char[ size ];
2172 aDataset->ReadFromDisk( hypdata_str );
2173 hypdata = string( hypdata_str );
2174 delete [] hypdata_str;
2175 aDataset->CloseOnDisk();
2178 // close hypothesis HDF group
2179 aGroup->CloseOnDisk();
2181 // --> restore hypothesis from data
2182 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2183 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2184 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2185 SMESH::SMESH_Hypothesis_var myHyp;
2187 try { // protect persistence mechanism against exceptions
2188 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2191 INFOS( "Exception during hypothesis creation" );
2194 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2196 myImpl->LoadFrom( hypdata.c_str() );
2197 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
2198 int newId = myStudyContext->findId( string( iorString.in() ) );
2199 myStudyContext->mapOldToNew( id, newId );
2202 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2206 // close hypotheses root HDF group
2207 aTopGroup->CloseOnDisk();
2210 // --> then we should read&create algorithms
2211 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2212 // open algorithms root HDF group
2213 aTopGroup = new HDFgroup( "Algorithms", aFile );
2214 aTopGroup->OpenOnDisk();
2216 // get number of algorithms
2217 int aNbObjects = aTopGroup->nInternalObjects();
2218 for ( int j = 0; j < aNbObjects; j++ ) {
2219 // try to identify algorithm
2220 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2221 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2223 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2224 // open algorithm group
2225 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2226 aGroup->OpenOnDisk();
2228 // --> get algorithm id
2229 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2234 // get number of datasets
2235 int aNbSubObjects = aGroup->nInternalObjects();
2236 for ( int k = 0; k < aNbSubObjects; k++ ) {
2238 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2239 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2240 // --> get algorithm name
2241 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2242 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2243 aDataset->OpenOnDisk();
2244 size = aDataset->GetSize();
2245 char* hypname_str = new char[ size ];
2246 aDataset->ReadFromDisk( hypname_str );
2247 hypname = string( hypname_str );
2248 delete [] hypname_str;
2249 aDataset->CloseOnDisk();
2251 // --> get algorithm plugin library name
2252 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2253 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2254 aDataset->OpenOnDisk();
2255 size = aDataset->GetSize();
2256 char* libname_str = new char[ size ];
2257 aDataset->ReadFromDisk( libname_str );
2258 if(MYDEBUG) SCRUTE( libname_str );
2259 libname = string( libname_str );
2260 delete [] libname_str;
2261 aDataset->CloseOnDisk();
2263 // --> get algorithm data
2264 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2265 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2266 aDataset->OpenOnDisk();
2267 size = aDataset->GetSize();
2268 char* hypdata_str = new char[ size ];
2269 aDataset->ReadFromDisk( hypdata_str );
2270 if(MYDEBUG) SCRUTE( hypdata_str );
2271 hypdata = string( hypdata_str );
2272 delete [] hypdata_str;
2273 aDataset->CloseOnDisk();
2276 // close algorithm HDF group
2277 aGroup->CloseOnDisk();
2279 // --> restore algorithm from data
2280 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2281 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2282 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2283 SMESH::SMESH_Hypothesis_var myHyp;
2285 try { // protect persistence mechanism against exceptions
2286 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2289 INFOS( "Exception during hypothesis creation" );
2292 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2294 myImpl->LoadFrom( hypdata.c_str() );
2295 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
2296 int newId = myStudyContext->findId( string( iorString.in() ) );
2297 myStudyContext->mapOldToNew( id, newId );
2300 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2304 // close algorithms root HDF group
2305 aTopGroup->CloseOnDisk();
2308 // --> the rest groups should be meshes
2309 for ( int i = 0; i < aNbGroups; i++ ) {
2310 // identify next group
2311 char meshName[ HDF_NAME_MAX_LEN+1 ];
2312 aFile->InternalObjectIndentify( i, meshName );
2314 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2316 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2320 bool hasData = false;
2322 // open mesh HDF group
2323 aTopGroup = new HDFgroup( meshName, aFile );
2324 aTopGroup->OpenOnDisk();
2326 // get number of child HDF objects
2327 int aNbObjects = aTopGroup->nInternalObjects();
2328 if ( aNbObjects > 0 ) {
2330 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2331 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2332 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2333 if ( !myNewMeshImpl )
2335 CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh );
2336 int newId = myStudyContext->findId( string( iorString.in() ) );
2337 myStudyContext->mapOldToNew( id, newId );
2339 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2340 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2342 // try to find mesh data dataset
2343 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2344 // load mesh "has data" flag
2345 aDataset = new HDFdataset( "Has data", aTopGroup );
2346 aDataset->OpenOnDisk();
2347 size = aDataset->GetSize();
2348 char* strHasData = new char[ size ];
2349 aDataset->ReadFromDisk( strHasData );
2350 aDataset->CloseOnDisk();
2351 if ( strcmp( strHasData, "1") == 0 ) {
2352 // read mesh data from MED file
2353 myReader.SetMesh( mySMESHDSMesh );
2354 myReader.SetMeshId( id );
2360 // try to read and set reference to shape
2361 GEOM::GEOM_Object_var aShapeObject;
2362 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2363 // load mesh "Ref on shape" - it's an entry to SObject
2364 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2365 aDataset->OpenOnDisk();
2366 size = aDataset->GetSize();
2367 char* refFromFile = new char[ size ];
2368 aDataset->ReadFromDisk( refFromFile );
2369 aDataset->CloseOnDisk();
2370 if ( strlen( refFromFile ) > 0 ) {
2371 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2373 // Make sure GEOM data are loaded first
2374 //loadGeomData( shapeSO->GetFatherComponent() );
2376 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2377 if ( !CORBA::is_nil( shapeObject ) ) {
2378 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2379 if ( !aShapeObject->_is_nil() )
2380 myNewMeshImpl->SetShape( aShapeObject );
2385 // try to get applied algorithms
2386 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2387 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2388 aGroup->OpenOnDisk();
2389 // get number of applied algorithms
2390 int aNbSubObjects = aGroup->nInternalObjects();
2391 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2392 for ( int j = 0; j < aNbSubObjects; j++ ) {
2393 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2394 aGroup->InternalObjectIndentify( j, name_dataset );
2395 // check if it is an algorithm
2396 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2397 aDataset = new HDFdataset( name_dataset, aGroup );
2398 aDataset->OpenOnDisk();
2399 size = aDataset->GetSize();
2400 char* refFromFile = new char[ size ];
2401 aDataset->ReadFromDisk( refFromFile );
2402 aDataset->CloseOnDisk();
2404 // san - it is impossible to recover applied algorithms using their entries within Load() method
2406 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2407 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2408 int id = atoi( refFromFile );
2409 string anIOR = myStudyContext->getIORbyOldId( id );
2410 if ( !anIOR.empty() ) {
2411 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2412 if ( !CORBA::is_nil( hypObject ) ) {
2413 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2414 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2415 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2420 aGroup->CloseOnDisk();
2423 // try to get applied hypotheses
2424 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2425 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2426 aGroup->OpenOnDisk();
2427 // get number of applied hypotheses
2428 int aNbSubObjects = aGroup->nInternalObjects();
2429 for ( int j = 0; j < aNbSubObjects; j++ ) {
2430 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2431 aGroup->InternalObjectIndentify( j, name_dataset );
2432 // check if it is a hypothesis
2433 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2434 aDataset = new HDFdataset( name_dataset, aGroup );
2435 aDataset->OpenOnDisk();
2436 size = aDataset->GetSize();
2437 char* refFromFile = new char[ size ];
2438 aDataset->ReadFromDisk( refFromFile );
2439 aDataset->CloseOnDisk();
2441 // san - it is impossible to recover applied hypotheses using their entries within Load() method
2443 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2444 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2445 int id = atoi( refFromFile );
2446 string anIOR = myStudyContext->getIORbyOldId( id );
2447 if ( !anIOR.empty() ) {
2448 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2449 if ( !CORBA::is_nil( hypObject ) ) {
2450 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2451 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2452 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2457 aGroup->CloseOnDisk();
2460 // --> try to find submeshes containers for each type of submesh
2461 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
2462 char name_meshgroup[ 30 ];
2463 if ( j == GetSubMeshOnVertexTag() )
2464 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2465 else if ( j == GetSubMeshOnEdgeTag() )
2466 strcpy( name_meshgroup, "SubMeshes On Edge" );
2467 else if ( j == GetSubMeshOnWireTag() )
2468 strcpy( name_meshgroup, "SubMeshes On Wire" );
2469 else if ( j == GetSubMeshOnFaceTag() )
2470 strcpy( name_meshgroup, "SubMeshes On Face" );
2471 else if ( j == GetSubMeshOnShellTag() )
2472 strcpy( name_meshgroup, "SubMeshes On Shell" );
2473 else if ( j == GetSubMeshOnSolidTag() )
2474 strcpy( name_meshgroup, "SubMeshes On Solid" );
2475 else if ( j == GetSubMeshOnCompoundTag() )
2476 strcpy( name_meshgroup, "SubMeshes On Compound" );
2478 // try to get submeshes container HDF group
2479 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
2480 // open submeshes containers HDF group
2481 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2482 aGroup->OpenOnDisk();
2484 // get number of submeshes
2485 int aNbSubMeshes = aGroup->nInternalObjects();
2486 for ( int k = 0; k < aNbSubMeshes; k++ ) {
2488 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
2489 aGroup->InternalObjectIndentify( k, name_submeshgroup );
2490 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
2491 // --> get submesh id
2492 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
2495 // open submesh HDF group
2496 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
2497 aSubGroup->OpenOnDisk();
2499 // try to read and set reference to subshape
2500 GEOM::GEOM_Object_var aSubShapeObject;
2501 SMESH::SMESH_subMesh_var aSubMesh;
2503 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2504 // load submesh "Ref on shape" - it's an entry to SObject
2505 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2506 aDataset->OpenOnDisk();
2507 size = aDataset->GetSize();
2508 char* refFromFile = new char[ size ];
2509 aDataset->ReadFromDisk( refFromFile );
2510 aDataset->CloseOnDisk();
2511 if ( strlen( refFromFile ) > 0 ) {
2512 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2513 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2514 if ( !CORBA::is_nil( subShapeObject ) ) {
2515 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2516 if ( !aSubShapeObject->_is_nil() )
2517 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2518 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2519 if ( aSubMesh->_is_nil() )
2521 CORBA::String_var iorSubString = GetORB()->object_to_string( aSubMesh );
2522 int newSubId = myStudyContext->findId( string( iorSubString.in() ) );
2523 myStudyContext->mapOldToNew( subid, newSubId );
2528 if ( aSubMesh->_is_nil() )
2531 // VSR: Get submesh data from MED convertor
2532 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2533 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2534 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2535 // subid << " for subshape # " << anInternalSubmeshId);
2536 // SMESHDS_SubMesh* aSubMeshDS =
2537 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2538 // if ( !aSubMeshDS ) {
2539 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2540 // anInternalSubmeshId << " in current mesh!");
2543 // myReader.GetSubMesh( aSubMeshDS, subid );
2546 // try to get applied algorithms
2547 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2548 // open "applied algorithms" HDF group
2549 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2550 aSubSubGroup->OpenOnDisk();
2551 // get number of applied algorithms
2552 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2553 for ( int l = 0; l < aNbSubObjects; l++ ) {
2554 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2555 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2556 // check if it is an algorithm
2557 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2558 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2559 aDataset->OpenOnDisk();
2560 size = aDataset->GetSize();
2561 char* refFromFile = new char[ size ];
2562 aDataset->ReadFromDisk( refFromFile );
2563 aDataset->CloseOnDisk();
2565 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2566 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2567 int id = atoi( refFromFile );
2568 string anIOR = myStudyContext->getIORbyOldId( id );
2569 if ( !anIOR.empty() ) {
2570 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2571 if ( !CORBA::is_nil( hypObject ) ) {
2572 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2573 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2574 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2579 // close "applied algorithms" HDF group
2580 aSubSubGroup->CloseOnDisk();
2583 // try to get applied hypotheses
2584 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2585 // open "applied hypotheses" HDF group
2586 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2587 aSubSubGroup->OpenOnDisk();
2588 // get number of applied hypotheses
2589 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2590 for ( int l = 0; l < aNbSubObjects; l++ ) {
2591 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2592 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2593 // check if it is a hypothesis
2594 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2595 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2596 aDataset->OpenOnDisk();
2597 size = aDataset->GetSize();
2598 char* refFromFile = new char[ size ];
2599 aDataset->ReadFromDisk( refFromFile );
2600 aDataset->CloseOnDisk();
2602 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2603 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2604 int id = atoi( refFromFile );
2605 string anIOR = myStudyContext->getIORbyOldId( id );
2606 if ( !anIOR.empty() ) {
2607 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2608 if ( !CORBA::is_nil( hypObject ) ) {
2609 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2610 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2611 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2616 // close "applied hypotheses" HDF group
2617 aSubSubGroup->CloseOnDisk();
2620 // close submesh HDF group
2621 aSubGroup->CloseOnDisk();
2624 // close submeshes containers HDF group
2625 aGroup->CloseOnDisk();
2630 // Read sub-meshes from MED
2631 if(MYDEBUG) MESSAGE("Create all sub-meshes");
2632 myReader.CreateAllSubMeshes();
2635 // Read node positions on sub-shapes (SMDS_Position)
2637 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
2639 // There are 5 datasets to read:
2640 // "Nodes on Edges" - ID of node on edge
2641 // "Edge positions" - U parameter on node on edge
2642 // "Nodes on Faces" - ID of node on face
2643 // "Face U positions" - U parameter of node on face
2644 // "Face V positions" - V parameter of node on face
2645 char* aEid_DSName = "Nodes on Edges";
2646 char* aEu_DSName = "Edge positions";
2647 char* aFu_DSName = "Face U positions";
2648 //char* aFid_DSName = "Nodes on Faces";
2649 //char* aFv_DSName = "Face V positions";
2652 int nbEids = 0, nbFids = 0;
2653 int *aEids = 0, *aFids = 0;
2654 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
2657 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2658 aGroup->OpenOnDisk();
2660 // loop on 5 data sets
2661 int aNbObjects = aGroup->nInternalObjects();
2662 for ( int i = 0; i < aNbObjects; i++ )
2665 char aDSName[ HDF_NAME_MAX_LEN+1 ];
2666 aGroup->InternalObjectIndentify( i, aDSName );
2668 aDataset = new HDFdataset( aDSName, aGroup );
2669 aDataset->OpenOnDisk();
2670 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
2672 double* pos = new double [ aDataset->GetSize() ];
2673 aDataset->ReadFromDisk( pos );
2675 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
2677 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
2684 int aSize = aDataset->GetSize();
2686 // for reading files, created from 18.07.2005 till 10.10.2005
2687 if (aDataset->GetType() == HDF_STRING)
2688 aSize /= sizeof(int);
2690 int* ids = new int [aSize];
2691 aDataset->ReadFromDisk( ids );
2692 // on face or nodes?
2693 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
2702 } // loop on 5 datasets
2704 // Set node positions on edges or faces
2705 for ( int onFace = 0; onFace < 2; onFace++ )
2707 int nbNodes = ( onFace ? nbFids : nbEids );
2708 if ( nbNodes == 0 ) continue;
2709 int* aNodeIDs = ( onFace ? aFids : aEids );
2710 double* aUPos = ( onFace ? aFupos : aEpos );
2711 double* aVPos = ( onFace ? aFvpos : 0 );
2713 for ( int iNode = 0; iNode < nbNodes; iNode++ )
2715 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
2717 SMDS_PositionPtr aPos = node->GetPosition();
2720 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
2721 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
2722 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
2723 fPos->SetUParameter( aUPos[ iNode ]);
2724 fPos->SetVParameter( aVPos[ iNode ]);
2727 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
2728 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
2729 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
2730 fPos->SetUParameter( aUPos[ iNode ]);
2734 if ( aEids ) delete [] aEids;
2735 if ( aFids ) delete [] aFids;
2736 if ( aEpos ) delete [] aEpos;
2737 if ( aFupos ) delete [] aFupos;
2738 if ( aFvpos ) delete [] aFvpos;
2740 aGroup->CloseOnDisk();
2742 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
2745 // Recompute State (as computed sub-meshes are restored from MED)
2746 if ( !aShapeObject->_is_nil() ) {
2747 MESSAGE("Compute State Engine ...");
2748 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
2749 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
2750 (SMESH_subMesh::SUBMESH_RESTORED);
2751 MESSAGE("Compute State Engine finished");
2754 // try to get groups
2755 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
2756 char name_group[ 30 ];
2757 if ( ii == GetNodeGroupsTag() )
2758 strcpy( name_group, "Groups of Nodes" );
2759 else if ( ii == GetEdgeGroupsTag() )
2760 strcpy( name_group, "Groups of Edges" );
2761 else if ( ii == GetFaceGroupsTag() )
2762 strcpy( name_group, "Groups of Faces" );
2763 else if ( ii == GetVolumeGroupsTag() )
2764 strcpy( name_group, "Groups of Volumes" );
2766 if ( aTopGroup->ExistInternalObject( name_group ) ) {
2767 aGroup = new HDFgroup( name_group, aTopGroup );
2768 aGroup->OpenOnDisk();
2769 // get number of groups
2770 int aNbSubObjects = aGroup->nInternalObjects();
2771 for ( int j = 0; j < aNbSubObjects; j++ ) {
2772 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2773 aGroup->InternalObjectIndentify( j, name_dataset );
2774 // check if it is an group
2775 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
2777 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
2780 aDataset = new HDFdataset( name_dataset, aGroup );
2781 aDataset->OpenOnDisk();
2783 // Retrieve actual group name
2784 size = aDataset->GetSize();
2785 char* nameFromFile = new char[ size ];
2786 aDataset->ReadFromDisk( nameFromFile );
2787 aDataset->CloseOnDisk();
2789 // Try to find a shape reference
2790 TopoDS_Shape aShape;
2791 char aRefName[ 30 ];
2792 sprintf( aRefName, "Ref on shape %d", subid);
2793 if ( aGroup->ExistInternalObject( aRefName ) ) {
2794 // load mesh "Ref on shape" - it's an entry to SObject
2795 aDataset = new HDFdataset( aRefName, aGroup );
2796 aDataset->OpenOnDisk();
2797 size = aDataset->GetSize();
2798 char* refFromFile = new char[ size ];
2799 aDataset->ReadFromDisk( refFromFile );
2800 aDataset->CloseOnDisk();
2801 if ( strlen( refFromFile ) > 0 ) {
2802 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2803 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2804 if ( !CORBA::is_nil( shapeObject ) ) {
2805 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2806 if ( !aShapeObject->_is_nil() )
2807 aShape = GeomObjectToShape( aShapeObject );
2811 // Create group servant
2812 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
2813 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
2814 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
2815 // Obtain a SMESHDS_Group object
2816 if ( aNewGroup->_is_nil() )
2819 CORBA::String_var iorSubString = GetORB()->object_to_string( aNewGroup );
2820 int newSubId = myStudyContext->findId( string( iorSubString.in() ) );
2821 myStudyContext->mapOldToNew( subid, newSubId );
2823 SMESH_GroupBase_i* aGroupImpl =
2824 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
2828 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
2832 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
2833 aGroupBaseDS->SetStoreName( name_dataset );
2835 // Fill group with contents from MED file
2836 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
2838 myReader.GetGroup( aGrp );
2841 aGroup->CloseOnDisk();
2846 aTopGroup->CloseOnDisk();
2851 aFile->CloseOnDisk();
2854 // Remove temporary files created from the stream
2856 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2858 INFOS( "SMESH_Gen_i::Load completed" );
2862 //=============================================================================
2864 * SMESH_Gen_i::LoadASCII
2866 * Load SMESH module's data in ASCII format
2868 //=============================================================================
2870 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
2871 const SALOMEDS::TMPFile& theStream,
2873 bool isMultiFile ) {
2874 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
2876 //before call main ::Load method it's need for decipher text format to
2877 //binary ( "|xx" => x' )
2878 int size = theStream.length();
2879 if ( int((size / 3 )*3) != size ) //error size of buffer
2882 int real_size = int(size / 3);
2884 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
2888 for ( int i = 0; i < real_size; i++ )
2890 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
2891 sscanf( tmp, "%x", &c );
2892 sprintf( (char*)&(buffer[i]), "%c", (char)c );
2895 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
2897 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
2900 //=============================================================================
2902 * SMESH_Gen_i::Close
2904 * Clears study-connected data when it is closed
2906 //=============================================================================
2908 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
2910 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
2912 // Clear study contexts data
2913 int studyId = GetCurrentStudyID();
2914 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
2915 delete myStudyContextMap[ studyId ];
2916 myStudyContextMap.erase( studyId );
2921 //=============================================================================
2923 * SMESH_Gen_i::ComponentDataType
2925 * Get component data type
2927 //=============================================================================
2929 char* SMESH_Gen_i::ComponentDataType()
2931 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
2932 return CORBA::string_dup( "SMESH" );
2936 //=============================================================================
2938 * SMESH_Gen_i::IORToLocalPersistentID
2940 * Transform data from transient form to persistent
2942 //=============================================================================
2944 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
2945 const char* IORString,
2946 CORBA::Boolean /*isMultiFile*/,
2947 CORBA::Boolean /*isASCII*/ )
2949 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
2950 StudyContext* myStudyContext = GetCurrentStudyContext();
2952 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
2953 int anId = myStudyContext->findId( IORString );
2955 if(MYDEBUG) MESSAGE( "VSR " << anId )
2957 sprintf( strId, "%d", anId );
2958 return CORBA::string_dup( strId );
2961 return CORBA::string_dup( "" );
2964 //=============================================================================
2966 * SMESH_Gen_i::LocalPersistentIDToIOR
2968 * Transform data from persistent form to transient
2970 //=============================================================================
2972 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
2973 const char* aLocalPersistentID,
2974 CORBA::Boolean /*isMultiFile*/,
2975 CORBA::Boolean /*isASCII*/ )
2977 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
2978 StudyContext* myStudyContext = GetCurrentStudyContext();
2980 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
2981 int anId = atoi( aLocalPersistentID );
2982 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
2984 return CORBA::string_dup( "" );
2987 //=======================================================================
2988 //function : RegisterObject
2990 //=======================================================================
2992 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
2994 StudyContext* myStudyContext = GetCurrentStudyContext();
2995 if ( myStudyContext && !CORBA::is_nil( theObject )) {
2996 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
2997 return myStudyContext->addObject( string( iorString.in() ) );
3002 //=============================================================================
3004 * SMESHEngine_factory
3006 * C factory, accessible with dlsym, after dlopen
3008 //=============================================================================
3012 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3013 PortableServer::POA_ptr poa,
3014 PortableServer::ObjectId* contId,
3015 const char* instanceName,
3016 const char* interfaceName )
3018 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3019 if(MYDEBUG) SCRUTE(interfaceName);
3020 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3021 return aSMESHGen->getId() ;