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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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>
45 #include <BRep_Tool.hxx>
46 #include <TCollection_AsciiString.hxx>
48 #include "Utils_CorbaException.hxx"
50 #include "utilities.h"
57 #include "SMESH_Gen_i.hxx"
58 #include "SMESH_Mesh_i.hxx"
59 #include "SMESH_Hypothesis_i.hxx"
60 #include "SMESH_Algo_i.hxx"
61 #include "SMESH_Group_i.hxx"
63 #include "SMESHDS_Document.hxx"
64 #include "SMESHDS_Group.hxx"
65 #include "SMESHDS_GroupOnGeom.hxx"
66 #include "SMESH_Group.hxx"
68 #include "SMDS_EdgePosition.hxx"
69 #include "SMDS_FacePosition.hxx"
71 #include CORBA_SERVER_HEADER(SMESH_Group)
72 #include CORBA_SERVER_HEADER(SMESH_Filter)
74 #include "DriverMED_W_SMESHDS_Mesh.h"
75 #include "DriverMED_R_SMESHDS_Mesh.h"
77 #include "SALOMEDS_Tool.hxx"
78 #include "SALOME_NamingService.hxx"
79 #include "SALOME_LifeCycleCORBA.hxx"
80 #include "Utils_SINGLETON.hxx"
83 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
85 #include "GEOM_Client.hxx"
86 #include "Utils_ExceptHandlers.hxx"
89 #include <boost/filesystem/path.hpp>
93 #define NUM_TMP_FILES 2
96 static int MYDEBUG = 0;
98 static int MYDEBUG = 0;
101 // Static variables definition
102 CORBA::ORB_var SMESH_Gen_i::myOrb;
103 PortableServer::POA_var SMESH_Gen_i::myPoa;
104 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
105 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
106 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
108 //=============================================================================
110 * GetServant [ static ]
112 * Get servant of the CORBA object
114 //=============================================================================
116 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
118 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
121 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
125 INFOS( "GetServant - Unknown exception was caught!!!" );
130 //=============================================================================
132 * SObjectToObject [ static ]
134 * Get CORBA object corresponding to the SALOMEDS::SObject
136 //=============================================================================
138 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
140 SALOMEDS::GenericAttribute_var anAttr;
141 CORBA::Object_var anObj;
142 if ( !theSObject->_is_nil() ) {
144 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
145 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
146 CORBA::String_var aValue = anIOR->Value();
147 if( strcmp( aValue, "" ) != 0 )
148 anObj = GetORB()->string_to_object( aValue );
152 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
158 //=============================================================================
162 * Get SALOME_NamingService object
164 //=============================================================================
166 SALOME_NamingService* SMESH_Gen_i::GetNS()
168 if ( myNS == NULL ) {
169 myNS = SINGLETON_<SALOME_NamingService>::Instance();
170 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
171 myNS->init_orb( GetORB() );
176 //=============================================================================
180 * Get SALOME_LifeCycleCORBA object
182 //=============================================================================
183 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
184 if ( myLCC == NULL ) {
185 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
191 //=============================================================================
193 * GetGeomEngine [ static ]
195 * Get GEOM::GEOM_Gen reference
197 //=============================================================================
198 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
199 GEOM::GEOM_Gen_var aGeomEngine =
200 GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
201 return aGeomEngine._retn();
204 //=============================================================================
206 * SMESH_Gen_i::SMESH_Gen_i
208 * Default constructor: not for use
210 //=============================================================================
212 SMESH_Gen_i::SMESH_Gen_i()
214 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
217 //=============================================================================
219 * SMESH_Gen_i::SMESH_Gen_i
221 * Standard constructor, used with Container
223 //=============================================================================
225 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
226 PortableServer::POA_ptr poa,
227 PortableServer::ObjectId* contId,
228 const char* instanceName,
229 const char* interfaceName )
230 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
232 INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
234 myOrb = CORBA::ORB::_duplicate(orb);
235 myPoa = PortableServer::POA::_duplicate(poa);
238 _id = myPoa->activate_object( _thisObj );
240 myShapeReader = NULL; // shape reader
244 //=============================================================================
246 * SMESH_Gen_i::~SMESH_Gen_i
250 //=============================================================================
252 SMESH_Gen_i::~SMESH_Gen_i()
254 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
256 // delete hypothesis creators
257 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
258 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
260 delete (*itHyp).second;
262 myHypCreatorMap.clear();
264 // Clear study contexts data
265 map<int, StudyContext*>::iterator it;
266 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
269 myStudyContextMap.clear();
270 // delete shape reader
271 if ( !myShapeReader )
272 delete myShapeReader;
275 //=============================================================================
277 * SMESH_Gen_i::createHypothesis
279 * Create hypothesis of given type
281 //=============================================================================
282 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
283 const char* theLibName)
284 throw (SALOME::SALOME_Exception)
286 Unexpect aCatch(SALOME_SalomeException);
287 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
289 // create a new hypothesis object servant
290 SMESH_Hypothesis_i* myHypothesis_i = 0;
291 SMESH::SMESH_Hypothesis_var hypothesis_i;
295 // check, if creator for this hypothesis type already exists
296 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
298 // load plugin library
299 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
300 void* libHandle = dlopen (theLibName, RTLD_LAZY);
303 // report any error, if occured
304 const char* anError = dlerror();
305 throw(SALOME_Exception(anError));
308 // get method, returning hypothesis creator
309 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
310 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
311 GetHypothesisCreator procHandle =
312 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
315 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
319 // get hypothesis creator
320 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
321 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
324 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
327 // map hypothesis creator to a hypothesis name
328 myHypCreatorMap[string(theHypName)] = aCreator;
331 // create a new hypothesis object, store its ref. in studyContext
332 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
334 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
335 // _CS_gbo Explicit activation (no longer made in the constructor).
336 myHypothesis_i->Activate();
337 myHypothesis_i->SetLibName(theLibName); // for persistency assurance
339 catch (SALOME_Exception& S_ex)
341 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
345 return hypothesis_i._retn();
347 // activate the CORBA servant of hypothesis
348 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
349 int nextId = RegisterObject( hypothesis_i );
350 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
352 return hypothesis_i._retn();
355 //=============================================================================
357 * SMESH_Gen_i::createMesh
359 * Create empty mesh on shape
361 //=============================================================================
362 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
363 throw ( SALOME::SALOME_Exception )
365 Unexpect aCatch(SALOME_SalomeException);
366 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
368 // Get or create the GEOM_Client instance
370 // create a new mesh object servant, store it in a map in study context
371 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
372 // create a new mesh object
373 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID() ));
375 // activate the CORBA servant of Mesh
376 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
377 int nextId = RegisterObject( mesh );
378 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
381 catch (SALOME_Exception& S_ex) {
382 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
384 return SMESH::SMESH_Mesh::_nil();
387 //=============================================================================
389 * SMESH_Gen_i::GetShapeReader
393 //=============================================================================
394 GEOM_Client* SMESH_Gen_i::GetShapeReader()
396 // create shape reader if necessary
397 if ( !myShapeReader )
398 myShapeReader = new GEOM_Client(GetContainerRef());
399 ASSERT( myShapeReader );
400 return myShapeReader;
403 //=============================================================================
405 * SMESH_Gen_i::SetCurrentStudy
409 //=============================================================================
411 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
413 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
414 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
415 // create study context, if it doesn't exist and set current study
416 int studyId = GetCurrentStudyID();
417 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
418 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
419 myStudyContextMap[ studyId ] = new StudyContext;
421 // set current study for geom engine
423 if ( !CORBA::is_nil( GetGeomEngine() ) )
424 GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
428 //=============================================================================
430 * SMESH_Gen_i::GetCurrentStudy
434 //=============================================================================
436 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
438 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
439 return SALOMEDS::Study::_duplicate( myCurrentStudy );
442 //=============================================================================
444 * SMESH_Gen_i::GetCurrentStudyContext
446 * Get current study context
448 //=============================================================================
449 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
451 if ( !CORBA::is_nil( myCurrentStudy ) &&
452 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
453 return myStudyContextMap[ myCurrentStudy->StudyId() ];
458 //=============================================================================
460 * SMESH_Gen_i::CreateHypothesis
462 * Create hypothesis/algorothm of given type and publish it in the study
464 //=============================================================================
466 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
467 const char* theLibName )
468 throw ( SALOME::SALOME_Exception )
470 Unexpect aCatch(SALOME_SalomeException);
471 // Create hypothesis/algorithm
472 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
474 // Publish hypothesis/algorithm in the study
475 if ( CanPublishInStudy( hyp ) )
476 PublishHypothesis( myCurrentStudy, hyp );
481 //=============================================================================
483 * SMESH_Gen_i::CreateMesh
485 * Create empty mesh on a shape and publish it in the study
487 //=============================================================================
489 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
490 throw ( SALOME::SALOME_Exception )
492 Unexpect aCatch(SALOME_SalomeException);
493 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
495 SMESH::SMESH_Mesh_var mesh = this->createMesh();
497 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
498 ASSERT( meshServant );
499 meshServant->SetShape( theShapeObject );
500 // publish mesh in the study
501 if ( CanPublishInStudy( mesh ) )
502 PublishMesh( myCurrentStudy, mesh.in() );
506 //=============================================================================
508 * SMESH_Gen_i::CreateMeshFromUNV
510 * Create mesh and import data from UNV file
512 //=============================================================================
514 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
515 throw ( SALOME::SALOME_Exception )
517 Unexpect aCatch(SALOME_SalomeException);
518 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
520 SMESH::SMESH_Mesh_var aMesh = createMesh();
521 string aFileName; // = boost::filesystem::path(theFileName).leaf();
522 // publish mesh in the study
523 if ( CanPublishInStudy( aMesh ) )
524 PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
526 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
528 aServant->ImportUNVFile( theFileName );
529 return aMesh._retn();
532 //=============================================================================
534 * SMESH_Gen_i::CreateMeshFromMED
536 * Create mesh and import data from MED file
538 //=============================================================================
540 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
541 SMESH::DriverMED_ReadStatus& theStatus)
542 throw ( SALOME::SALOME_Exception )
544 Unexpect aCatch(SALOME_SalomeException);
545 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
547 // Retrieve mesh names from the file
548 DriverMED_R_SMESHDS_Mesh myReader;
549 myReader.SetFile( theFileName );
550 myReader.SetMeshId( -1 );
551 Driver_Mesh::Status aStatus;
552 list<string> aNames = myReader.GetMeshNames(aStatus);
553 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
554 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
555 if(theStatus == SMESH::DRS_OK){
556 aResult->length( aNames.size() );
559 // Iterate through all meshes and create mesh objects
560 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
562 SMESH::SMESH_Mesh_var mesh = createMesh();
564 // publish mesh in the study
565 if ( CanPublishInStudy( mesh ) )
566 PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
568 // Read mesh data (groups are published automatically by ImportMEDFile())
569 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
570 ASSERT( meshServant );
571 SMESH::DriverMED_ReadStatus status1 =
572 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
573 if (status1 > theStatus)
576 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
579 return aResult._retn();
582 //=============================================================================
584 * SMESH_Gen_i::CreateMeshFromSTL
586 * Create mesh and import data from STL file
588 //=============================================================================
590 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
591 throw ( SALOME::SALOME_Exception )
593 Unexpect aCatch(SALOME_SalomeException);
594 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
596 SMESH::SMESH_Mesh_var aMesh = createMesh();
597 string aFileName; // = boost::filesystem::path(theFileName).leaf();
598 // publish mesh in the study
599 if ( CanPublishInStudy( aMesh ) )
600 PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
602 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
604 aServant->ImportSTLFile( theFileName );
605 return aMesh._retn();
608 //=============================================================================
610 * SMESH_Gen_i::IsReadyToCompute
612 * Returns true if mesh contains enough data to be computed
614 //=============================================================================
616 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
617 GEOM::GEOM_Object_ptr theShapeObject )
618 throw ( SALOME::SALOME_Exception )
620 Unexpect aCatch(SALOME_SalomeException);
621 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
623 if ( CORBA::is_nil( theShapeObject ) )
624 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
627 if ( CORBA::is_nil( theMesh ) )
628 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
633 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
634 ASSERT( meshServant );
636 // get local TopoDS_Shape
637 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
638 // call implementation
639 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
640 return myGen.CheckAlgoState( myLocMesh, myLocShape );
643 catch ( SALOME_Exception& S_ex ) {
644 INFOS( "catch exception "<< S_ex.what() );
649 //=============================================================================
651 * SMESH_Gen_i::GetSubShapesId
653 * Get sub-shapes unique ID's list
655 //=============================================================================
657 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
658 const SMESH::object_array& theListOfSubShapeObject )
659 throw ( SALOME::SALOME_Exception )
661 Unexpect aCatch(SALOME_SalomeException);
662 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
664 SMESH::long_array_var shapesId = new SMESH::long_array;
667 if ( CORBA::is_nil( theMainShapeObject ) )
668 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
673 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
674 TopTools_IndexedMapOfShape myIndexToShape;
675 TopExp::MapShapes(myMainShape,myIndexToShape);
677 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
679 GEOM::GEOM_Object_var aShapeObject
680 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
681 if ( CORBA::is_nil( aShapeObject ) )
682 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
685 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
686 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
688 const TopoDS_Face& F = TopoDS::Face(exp.Current());
689 setId.insert(myIndexToShape.FindIndex(F));
690 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
692 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
694 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
695 setId.insert(myIndexToShape.FindIndex(E));
696 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
698 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
700 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
701 setId.insert(myIndexToShape.FindIndex(V));
702 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
705 shapesId->length(setId.size());
706 set<int>::iterator iind;
708 for (iind = setId.begin(); iind != setId.end(); iind++)
710 if(MYDEBUG) SCRUTE((*iind));
711 shapesId[i] = (*iind);
712 if(MYDEBUG) SCRUTE(shapesId[i]);
716 catch (SALOME_Exception& S_ex)
718 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
721 return shapesId._retn();
724 //=============================================================================
726 * SMESH_Gen_i::Compute
728 * Compute mesh on a shape
730 //=============================================================================
732 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
733 GEOM::GEOM_Object_ptr theShapeObject )
734 throw ( SALOME::SALOME_Exception )
736 Unexpect aCatch(SALOME_SalomeException);
737 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
739 if ( CORBA::is_nil( theShapeObject ) )
740 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
743 if ( CORBA::is_nil( theMesh ) )
744 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
749 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
750 ASSERT( meshServant );
752 // get local TopoDS_Shape
753 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
754 // call implementation compute
755 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
756 return myGen.Compute( myLocMesh, myLocShape);
759 catch ( SALOME_Exception& S_ex ) {
760 INFOS( "Compute(): catch exception "<< S_ex.what() );
763 INFOS( "Compute(): unknown exception " );
768 //=============================================================================
772 * Save SMESH module's data
774 //=============================================================================
775 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
779 INFOS( "SMESH_Gen_i::Save" );
781 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
782 // san -- in case <myCurrentStudy> differs from theComponent's study,
783 // use that of the component
784 if ( myCurrentStudy->_is_nil() ||
785 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
786 SetCurrentStudy( theComponent->GetStudy() );
788 StudyContext* myStudyContext = GetCurrentStudyContext();
790 // Declare a byte stream
791 SALOMEDS::TMPFile_var aStreamFile;
793 // Obtain a temporary dir
794 TCollection_AsciiString tmpDir =
795 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
797 // Create a sequence of files processed
798 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
799 aFileSeq->length( NUM_TMP_FILES );
801 TCollection_AsciiString aStudyName( "" );
803 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
805 // Set names of temporary files
806 TCollection_AsciiString filename =
807 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
808 TCollection_AsciiString meshfile =
809 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
810 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
811 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
812 filename = tmpDir + filename;
813 meshfile = tmpDir + meshfile;
816 HDFdataset* aDataset;
820 HDFgroup* aSubSubGroup;
823 // MED writer to be used by storage process
824 DriverMED_W_SMESHDS_Mesh myWriter;
825 myWriter.SetFile( meshfile.ToCString() );
828 // ---> create HDF file
829 aFile = new HDFfile( filename.ToCString() );
830 aFile->CreateOnDisk();
832 // --> iterator for top-level objects
833 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
834 for ( ; itBig->More(); itBig->Next() ) {
835 SALOMEDS::SObject_var gotBranch = itBig->Value();
837 // --> hypotheses root branch (only one for the study)
838 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
839 // create hypotheses root HDF group
840 aTopGroup = new HDFgroup( "Hypotheses", aFile );
841 aTopGroup->CreateOnDisk();
843 // iterator for all hypotheses
844 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
845 for ( ; it->More(); it->Next() ) {
846 SALOMEDS::SObject_var mySObject = it->Value();
847 CORBA::Object_var anObject = SObjectToObject( mySObject );
848 if ( !CORBA::is_nil( anObject ) ) {
849 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
850 if ( !myHyp->_is_nil() ) {
851 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
853 string hypname = string( myHyp->GetName() );
854 string libname = string( myHyp->GetLibName() );
855 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
856 string hypdata = string( myImpl->SaveTo() );
858 // for each hypothesis create HDF group basing on its id
860 sprintf( hypGrpName, "Hypothesis %d", id );
861 aGroup = new HDFgroup( hypGrpName, aTopGroup );
862 aGroup->CreateOnDisk();
863 // --> type name of hypothesis
864 aSize[ 0 ] = hypname.length() + 1;
865 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
866 aDataset->CreateOnDisk();
867 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
868 aDataset->CloseOnDisk();
869 // --> server plugin library name of hypothesis
870 aSize[ 0 ] = libname.length() + 1;
871 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
872 aDataset->CreateOnDisk();
873 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
874 aDataset->CloseOnDisk();
875 // --> persistent data of hypothesis
876 aSize[ 0 ] = hypdata.length() + 1;
877 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
878 aDataset->CreateOnDisk();
879 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
880 aDataset->CloseOnDisk();
881 // close hypothesis HDF group
882 aGroup->CloseOnDisk();
887 // close hypotheses root HDF group
888 aTopGroup->CloseOnDisk();
890 // --> algorithms root branch (only one for the study)
891 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
892 // create algorithms root HDF group
893 aTopGroup = new HDFgroup( "Algorithms", aFile );
894 aTopGroup->CreateOnDisk();
896 // iterator for all algorithms
897 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
898 for ( ; it->More(); it->Next() ) {
899 SALOMEDS::SObject_var mySObject = it->Value();
900 CORBA::Object_var anObject = SObjectToObject( mySObject );
901 if ( !CORBA::is_nil( anObject ) ) {
902 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
903 if ( !myHyp->_is_nil() ) {
904 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
906 string hypname = string( myHyp->GetName() );
907 string libname = string( myHyp->GetLibName() );
908 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
909 string hypdata = string( myImpl->SaveTo() );
911 // for each algorithm create HDF group basing on its id
913 sprintf( hypGrpName, "Algorithm %d", id );
914 aGroup = new HDFgroup( hypGrpName, aTopGroup );
915 aGroup->CreateOnDisk();
916 // --> type name of algorithm
917 aSize[0] = hypname.length() + 1;
918 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
919 aDataset->CreateOnDisk();
920 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
921 aDataset->CloseOnDisk();
922 // --> server plugin library name of hypothesis
923 aSize[0] = libname.length() + 1;
924 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
925 aDataset->CreateOnDisk();
926 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
927 aDataset->CloseOnDisk();
928 // --> persistent data of algorithm
929 aSize[0] = hypdata.length() + 1;
930 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
931 aDataset->CreateOnDisk();
932 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
933 aDataset->CloseOnDisk();
934 // close algorithm HDF group
935 aGroup->CloseOnDisk();
940 // close algorithms root HDF group
941 aTopGroup->CloseOnDisk();
943 // --> mesh objects roots branches
944 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
945 CORBA::Object_var anObject = SObjectToObject( gotBranch );
946 if ( !CORBA::is_nil( anObject ) ) {
947 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
948 if ( !myMesh->_is_nil() ) {
949 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
951 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
952 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
953 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
955 // for each mesh open the HDF group basing on its id
956 char meshGrpName[ 30 ];
957 sprintf( meshGrpName, "Mesh %d", id );
958 aTopGroup = new HDFgroup( meshGrpName, aFile );
959 aTopGroup->CreateOnDisk();
961 // --> put dataset to hdf file which is a flag that mesh has data
962 string strHasData = "0";
963 // check if the mesh is not empty
964 if ( mySMESHDSMesh->NbNodes() > 0 ) {
965 // write mesh data to med file
966 myWriter.SetMesh( mySMESHDSMesh );
967 myWriter.SetMeshId( id );
970 aSize[ 0 ] = strHasData.length() + 1;
971 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
972 aDataset->CreateOnDisk();
973 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
974 aDataset->CloseOnDisk();
976 // write reference on a shape if exists
977 SALOMEDS::SObject_var myRef;
978 bool shapeRefFound = false;
979 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
981 SALOMEDS::SObject_var myShape;
982 bool ok = myRef->ReferencedObject( myShape );
984 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
985 string myRefOnObject = myShape->GetID();
986 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
987 aSize[ 0 ] = myRefOnObject.length() + 1;
988 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
989 aDataset->CreateOnDisk();
990 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
991 aDataset->CloseOnDisk();
995 // maybe a shape was deleted in the study
996 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
997 TopoDS_Shape nullShape;
998 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
1001 // write applied hypotheses if exist
1002 SALOMEDS::SObject_var myHypBranch;
1003 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1004 if ( found && !shapeRefFound ) { // remove applied hyps
1005 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1007 if ( found && shapeRefFound ) {
1008 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1009 aGroup->CreateOnDisk();
1011 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1013 for ( ; it->More(); it->Next() ) {
1014 SALOMEDS::SObject_var mySObject = it->Value();
1015 SALOMEDS::SObject_var myRefOnHyp;
1016 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1018 // san - it is impossible to recover applied hypotheses
1019 // using their entries within Load() method,
1020 // for there are no AttributeIORs in the study when Load() is working.
1021 // Hence, it is better to store persistent IDs of hypotheses as references to them
1023 //string myRefOnObject = myRefOnHyp->GetID();
1024 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1025 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1026 //if ( myRefOnObject.length() > 0 ) {
1027 //aSize[ 0 ] = myRefOnObject.length() + 1;
1028 char hypName[ 30 ], hypId[ 30 ];
1029 sprintf( hypName, "Hyp %d", ++hypNb );
1030 sprintf( hypId, "%d", id );
1031 aSize[ 0 ] = strlen( hypId ) + 1;
1032 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1033 aDataset->CreateOnDisk();
1034 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1035 aDataset->WriteOnDisk( hypId );
1036 aDataset->CloseOnDisk();
1040 aGroup->CloseOnDisk();
1043 // write applied algorithms if exist
1044 SALOMEDS::SObject_var myAlgoBranch;
1045 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1046 if ( found && !shapeRefFound ) { // remove applied hyps
1047 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1049 if ( found && shapeRefFound ) {
1050 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1051 aGroup->CreateOnDisk();
1053 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1055 for ( ; it->More(); it->Next() ) {
1056 SALOMEDS::SObject_var mySObject = it->Value();
1057 SALOMEDS::SObject_var myRefOnAlgo;
1058 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1060 // san - it is impossible to recover applied algorithms
1061 // using their entries within Load() method,
1062 // for there are no AttributeIORs in the study when Load() is working.
1063 // Hence, it is better to store persistent IDs of algorithms as references to them
1065 //string myRefOnObject = myRefOnAlgo->GetID();
1066 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1067 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1068 //if ( myRefOnObject.length() > 0 ) {
1069 //aSize[ 0 ] = myRefOnObject.length() + 1;
1070 char algoName[ 30 ], algoId[ 30 ];
1071 sprintf( algoName, "Algo %d", ++algoNb );
1072 sprintf( algoId, "%d", id );
1073 aSize[ 0 ] = strlen( algoId ) + 1;
1074 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1075 aDataset->CreateOnDisk();
1076 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1077 aDataset->WriteOnDisk( algoId );
1078 aDataset->CloseOnDisk();
1082 aGroup->CloseOnDisk();
1085 // --> submesh objects sub-branches
1087 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1088 SALOMEDS::SObject_var mySubmeshBranch;
1089 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1091 if ( found ) // check if there is shape reference in submeshes
1093 bool hasShapeRef = false;
1094 SALOMEDS::ChildIterator_var itSM =
1095 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1096 for ( ; itSM->More(); itSM->Next() ) {
1097 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1098 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1099 mySubRef->ReferencedObject( myShape );
1100 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1103 { // remove one submesh
1104 if ( shapeRefFound )
1105 { // unassign hypothesis
1106 SMESH::SMESH_subMesh_var mySubMesh =
1107 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1108 if ( !mySubMesh->_is_nil() ) {
1109 int shapeID = mySubMesh->GetId();
1110 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1111 const list<const SMESHDS_Hypothesis*>& hypList =
1112 mySMESHDSMesh->GetHypothesis( S );
1113 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1114 while ( hyp != hypList.end() ) {
1115 int hypID = (*hyp++)->GetID(); // goto next here because
1116 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1120 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1122 } // loop on submeshes of a type
1123 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1124 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1127 } // end check if there is shape reference in submeshes
1129 char name_meshgroup[ 30 ];
1130 if ( i == GetSubMeshOnVertexTag() )
1131 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1132 else if ( i == GetSubMeshOnEdgeTag() )
1133 strcpy( name_meshgroup, "SubMeshes On Edge" );
1134 else if ( i == GetSubMeshOnWireTag() )
1135 strcpy( name_meshgroup, "SubMeshes On Wire" );
1136 else if ( i == GetSubMeshOnFaceTag() )
1137 strcpy( name_meshgroup, "SubMeshes On Face" );
1138 else if ( i == GetSubMeshOnShellTag() )
1139 strcpy( name_meshgroup, "SubMeshes On Shell" );
1140 else if ( i == GetSubMeshOnSolidTag() )
1141 strcpy( name_meshgroup, "SubMeshes On Solid" );
1142 else if ( i == GetSubMeshOnCompoundTag() )
1143 strcpy( name_meshgroup, "SubMeshes On Compound" );
1145 // for each type of submeshes create container HDF group
1146 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1147 aGroup->CreateOnDisk();
1149 // iterator for all submeshes of given type
1150 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1151 for ( ; itSM->More(); itSM->Next() ) {
1152 SALOMEDS::SObject_var mySObject = itSM->Value();
1153 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1154 if ( !CORBA::is_nil( anSubObject ))
1156 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1157 int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) );
1159 // for each mesh open the HDF group basing on its id
1160 char submeshGrpName[ 30 ];
1161 sprintf( submeshGrpName, "SubMesh %d", subid );
1162 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1163 aSubGroup->CreateOnDisk();
1165 // write reference on a shape, already checked if it exists
1166 SALOMEDS::SObject_var mySubRef, myShape;
1167 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1168 mySubRef->ReferencedObject( myShape );
1169 string myRefOnObject = myShape->GetID();
1170 if ( myRefOnObject.length() > 0 ) {
1171 aSize[ 0 ] = myRefOnObject.length() + 1;
1172 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1173 aDataset->CreateOnDisk();
1174 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1175 aDataset->CloseOnDisk();
1178 // write applied hypotheses if exist
1179 SALOMEDS::SObject_var mySubHypBranch;
1180 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1182 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1183 aSubSubGroup->CreateOnDisk();
1185 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1187 for ( ; it->More(); it->Next() ) {
1188 SALOMEDS::SObject_var mySubSObject = it->Value();
1189 SALOMEDS::SObject_var myRefOnHyp;
1190 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1192 //string myRefOnObject = myRefOnHyp->GetID();
1193 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1194 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1195 //if ( myRefOnObject.length() > 0 ) {
1196 //aSize[ 0 ] = myRefOnObject.length() + 1;
1197 char hypName[ 30 ], hypId[ 30 ];
1198 sprintf( hypName, "Hyp %d", ++hypNb );
1199 sprintf( hypId, "%d", id );
1200 aSize[ 0 ] = strlen( hypId ) + 1;
1201 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1202 aDataset->CreateOnDisk();
1203 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1204 aDataset->WriteOnDisk( hypId );
1205 aDataset->CloseOnDisk();
1209 aSubSubGroup->CloseOnDisk();
1212 // write applied algorithms if exist
1213 SALOMEDS::SObject_var mySubAlgoBranch;
1214 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1216 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1217 aSubSubGroup->CreateOnDisk();
1219 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1221 for ( ; it->More(); it->Next() ) {
1222 SALOMEDS::SObject_var mySubSObject = it->Value();
1223 SALOMEDS::SObject_var myRefOnAlgo;
1224 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1226 //string myRefOnObject = myRefOnAlgo->GetID();
1227 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1228 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1229 //if ( myRefOnObject.length() > 0 ) {
1230 //aSize[ 0 ] = myRefOnObject.length() + 1;
1231 char algoName[ 30 ], algoId[ 30 ];
1232 sprintf( algoName, "Algo %d", ++algoNb );
1233 sprintf( algoId, "%d", id );
1234 aSize[ 0 ] = strlen( algoId ) + 1;
1235 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1236 aDataset->CreateOnDisk();
1237 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1238 aDataset->WriteOnDisk( algoId );
1239 aDataset->CloseOnDisk();
1243 aSubSubGroup->CloseOnDisk();
1245 // close submesh HDF group
1246 aSubGroup->CloseOnDisk();
1249 // close container of submeshes by type HDF group
1250 aGroup->CloseOnDisk();
1253 // All sub-meshes will be stored in MED file
1254 myWriter.AddAllSubMeshes();
1256 // groups root sub-branch
1257 SALOMEDS::SObject_var myGroupsBranch;
1258 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1259 found = gotBranch->FindSubObject( i, myGroupsBranch );
1261 char name_group[ 30 ];
1262 if ( i == GetNodeGroupsTag() )
1263 strcpy( name_group, "Groups of Nodes" );
1264 else if ( i == GetEdgeGroupsTag() )
1265 strcpy( name_group, "Groups of Edges" );
1266 else if ( i == GetFaceGroupsTag() )
1267 strcpy( name_group, "Groups of Faces" );
1268 else if ( i == GetVolumeGroupsTag() )
1269 strcpy( name_group, "Groups of Volumes" );
1271 aGroup = new HDFgroup( name_group, aTopGroup );
1272 aGroup->CreateOnDisk();
1274 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
1275 for ( ; it->More(); it->Next() ) {
1276 SALOMEDS::SObject_var mySObject = it->Value();
1277 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
1278 if ( !CORBA::is_nil( aSubObject ) ) {
1279 SMESH_GroupBase_i* myGroupImpl =
1280 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
1284 int anId = myStudyContext->findId( string( GetORB()->object_to_string( aSubObject ) ) );
1286 // For each group, create a dataset named "Group <group_persistent_id>"
1287 // and store the group's user name into it
1289 sprintf( grpName, "Group %d", anId );
1290 char* aUserName = myGroupImpl->GetName();
1291 aSize[ 0 ] = strlen( aUserName ) + 1;
1293 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
1294 aDataset->CreateOnDisk();
1295 aDataset->WriteOnDisk( aUserName );
1296 aDataset->CloseOnDisk();
1298 // Store the group contents into MED file
1299 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
1301 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
1302 << grpName << " to MED file" );
1303 SMESHDS_GroupBase* aGrpBaseDS =
1304 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
1305 aGrpBaseDS->SetStoreName( grpName );
1307 // Pass SMESHDS_Group to MED writer
1308 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
1310 myWriter.AddGroup( aGrpDS );
1312 // write reference on a shape if exists
1313 SMESHDS_GroupOnGeom* aGeomGrp =
1314 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
1316 SALOMEDS::SObject_var mySubRef, myShape;
1317 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
1318 mySubRef->ReferencedObject( myShape ) &&
1319 !CORBA::is_nil( myShape->GetObject() ))
1321 string myRefOnObject = myShape->GetID();
1322 if ( myRefOnObject.length() > 0 ) {
1323 char aRefName[ 30 ];
1324 sprintf( aRefName, "Ref on shape %d", anId);
1325 aSize[ 0 ] = myRefOnObject.length() + 1;
1326 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
1327 aDataset->CreateOnDisk();
1328 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1329 aDataset->CloseOnDisk();
1332 else // shape ref is invalid:
1334 // save a group on geometry as ordinary group
1335 myWriter.AddGroup( aGeomGrp );
1341 aGroup->CloseOnDisk();
1345 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
1347 // Flush current mesh information into MED file
1351 // Store node positions on sub-shapes (SMDS_Position):
1353 if ( !mySMESHDSMesh->SubMeshes().empty() )
1355 aGroup = new HDFgroup( "Node Positions", aTopGroup );
1356 aGroup->CreateOnDisk();
1358 // in aGroup, create 5 datasets to contain:
1359 // "Nodes on Edges" - ID of node on edge
1360 // "Edge positions" - U parameter on node on edge
1361 // "Nodes on Faces" - ID of node on face
1362 // "Face U positions" - U parameter of node on face
1363 // "Face V positions" - V parameter of node on face
1365 // Find out nb of nodes on edges and faces
1366 // Collect corresponing sub-meshes
1367 int nbEdgeNodes = 0, nbFaceNodes = 0;
1368 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
1369 // loop on SMESHDS_SubMesh'es
1370 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
1371 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
1372 for ( ; itSubM != aSubMeshes.end() ; itSubM++ )
1374 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
1375 if ( aSubMesh->IsComplexSubmesh() )
1376 continue; // submesh containing other submeshs
1377 int nbNodes = aSubMesh->NbNodes();
1378 if ( nbNodes == 0 ) continue;
1380 int aShapeID = (*itSubM).first;
1381 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
1382 // write only SMDS_FacePosition and SMDS_EdgePosition
1383 switch ( aShapeType ) {
1385 nbFaceNodes += nbNodes;
1386 aFaceSM.push_back( aSubMesh );
1389 nbEdgeNodes += nbNodes;
1390 aEdgeSM.push_back( aSubMesh );
1396 // Treat positions on edges or faces
1397 for ( int onFace = 0; onFace < 2; onFace++ )
1399 // Create arrays to store in datasets
1400 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
1401 if (!nbNodes) continue;
1402 int* aNodeIDs = new int [ nbNodes ];
1403 double* aUPos = new double [ nbNodes ];
1404 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
1407 // loop on sub-meshes
1408 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
1409 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
1410 for ( ; itSM != pListSM->end(); itSM++ )
1412 SMESHDS_SubMesh* aSubMesh = (*itSM);
1413 if ( aSubMesh->IsComplexSubmesh() )
1414 continue; // submesh containing other submeshs
1416 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
1417 // loop on nodes in aSubMesh
1418 while ( itNode->more() )
1421 const SMDS_MeshNode* node = itNode->next();
1422 aNodeIDs [ iNode ] = node->GetID();
1425 const SMDS_PositionPtr pos = node->GetPosition();
1426 if ( onFace ) { // on FACE
1427 const SMDS_FacePosition* fPos =
1428 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
1430 aUPos[ iNode ] = fPos->GetUParameter();
1431 aVPos[ iNode ] = fPos->GetVParameter();
1438 const SMDS_EdgePosition* ePos =
1439 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
1441 aUPos[ iNode ] = ePos->GetUParameter();
1447 } // loop on nodes in aSubMesh
1448 } // loop on sub-meshes
1453 aSize[ 0 ] = nbNodes;
1455 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
1456 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
1457 aDataset->CreateOnDisk();
1458 aDataset->WriteOnDisk( aNodeIDs );
1459 aDataset->CloseOnDisk();
1462 aDSName = ( onFace ? "Face U positions" : "Edge positions");
1463 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
1464 aDataset->CreateOnDisk();
1465 aDataset->WriteOnDisk( aUPos );
1466 aDataset->CloseOnDisk();
1469 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
1470 aDataset->CreateOnDisk();
1471 aDataset->WriteOnDisk( aVPos );
1472 aDataset->CloseOnDisk();
1477 if ( aVPos ) delete [] aVPos;
1479 } // treat positions on edges or faces
1481 // close "Node Positions" group
1482 aGroup->CloseOnDisk();
1484 } // if ( there are submeshes in SMESHDS_Mesh )
1487 // close mesh HDF group
1488 aTopGroup->CloseOnDisk();
1496 aFile->CloseOnDisk();
1499 // Convert temporary files to stream
1500 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
1502 // Remove temporary files and directory
1504 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
1506 INFOS( "SMESH_Gen_i::Save() completed" );
1507 return aStreamFile._retn();
1510 //=============================================================================
1512 * SMESH_Gen_i::SaveASCII
1514 * Save SMESH module's data in ASCII format (not implemented yet)
1516 //=============================================================================
1518 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
1520 bool isMultiFile ) {
1521 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
1522 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
1523 return aStreamFile._retn();
1526 //=============================================================================
1528 * SMESH_Gen_i::loadGeomData
1530 * Load GEOM module data
1532 //=============================================================================
1534 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
1536 if ( theCompRoot->_is_nil() )
1539 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
1540 if ( aStudy->_is_nil() )
1543 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1544 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
1547 //=============================================================================
1551 * Load SMESH module's data
1553 //=============================================================================
1555 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
1556 const SALOMEDS::TMPFile& theStream,
1560 INFOS( "SMESH_Gen_i::Load" );
1562 if ( myCurrentStudy->_is_nil() ||
1563 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1564 SetCurrentStudy( theComponent->GetStudy() );
1566 StudyContext* myStudyContext = GetCurrentStudyContext();
1568 // Get temporary files location
1569 TCollection_AsciiString tmpDir =
1570 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1572 // Convert the stream into sequence of files to process
1573 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
1576 TCollection_AsciiString aStudyName( "" );
1578 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1580 // Set names of temporary files
1581 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
1582 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
1586 HDFdataset* aDataset;
1587 HDFgroup* aTopGroup;
1589 HDFgroup* aSubGroup;
1590 HDFgroup* aSubSubGroup;
1593 // ---> open HDF file
1594 aFile = new HDFfile( filename.ToCString() );
1596 aFile->OpenOnDisk( HDF_RDONLY );
1598 catch ( HDFexception ) {
1599 INFOS( "Load(): " << filename << " not found!" );
1603 DriverMED_R_SMESHDS_Mesh myReader;
1604 myReader.SetFile( meshfile.ToCString() );
1606 // get total number of top-level groups
1607 int aNbGroups = aFile->nInternalObjects();
1608 if ( aNbGroups > 0 ) {
1609 // --> in first turn we should read&create hypotheses
1610 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
1611 // open hypotheses root HDF group
1612 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1613 aTopGroup->OpenOnDisk();
1615 // get number of hypotheses
1616 int aNbObjects = aTopGroup->nInternalObjects();
1617 for ( int j = 0; j < aNbObjects; j++ ) {
1618 // try to identify hypothesis
1619 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
1620 aTopGroup->InternalObjectIndentify( j, hypGrpName );
1622 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
1623 // open hypothesis group
1624 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1625 aGroup->OpenOnDisk();
1627 // --> get hypothesis id
1628 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
1633 // get number of datasets
1634 int aNbSubObjects = aGroup->nInternalObjects();
1635 for ( int k = 0; k < aNbSubObjects; k++ ) {
1637 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
1638 aGroup->InternalObjectIndentify( k, name_of_subgroup );
1639 // --> get hypothesis name
1640 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
1641 aDataset = new HDFdataset( name_of_subgroup, aGroup );
1642 aDataset->OpenOnDisk();
1643 size = aDataset->GetSize();
1644 char* hypname_str = new char[ size ];
1645 aDataset->ReadFromDisk( hypname_str );
1646 hypname = string( hypname_str );
1648 aDataset->CloseOnDisk();
1650 // --> get hypothesis plugin library name
1651 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
1652 aDataset = new HDFdataset( name_of_subgroup, aGroup );
1653 aDataset->OpenOnDisk();
1654 size = aDataset->GetSize();
1655 char* libname_str = new char[ size ];
1656 aDataset->ReadFromDisk( libname_str );
1657 if(MYDEBUG) SCRUTE( libname_str );
1658 libname = string( libname_str );
1660 aDataset->CloseOnDisk();
1662 // --> get hypothesis data
1663 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
1664 aDataset = new HDFdataset( name_of_subgroup, aGroup );
1665 aDataset->OpenOnDisk();
1666 size = aDataset->GetSize();
1667 char* hypdata_str = new char[ size ];
1668 aDataset->ReadFromDisk( hypdata_str );
1669 hypdata = string( hypdata_str );
1671 aDataset->CloseOnDisk();
1674 // close hypothesis HDF group
1675 aGroup->CloseOnDisk();
1677 // --> restore hypothesis from data
1678 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
1679 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
1680 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
1681 SMESH::SMESH_Hypothesis_var myHyp;
1683 try { // protect persistence mechanism against exceptions
1684 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
1687 INFOS( "Exception during hypothesis creation" );
1690 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1692 myImpl->LoadFrom( hypdata.c_str() );
1693 string iorString = GetORB()->object_to_string( myHyp );
1694 int newId = myStudyContext->findId( iorString );
1695 myStudyContext->mapOldToNew( id, newId );
1698 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
1702 // close hypotheses root HDF group
1703 aTopGroup->CloseOnDisk();
1706 // --> then we should read&create algorithms
1707 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
1708 // open algorithms root HDF group
1709 aTopGroup = new HDFgroup( "Algorithms", aFile );
1710 aTopGroup->OpenOnDisk();
1712 // get number of algorithms
1713 int aNbObjects = aTopGroup->nInternalObjects();
1714 for ( int j = 0; j < aNbObjects; j++ ) {
1715 // try to identify algorithm
1716 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
1717 aTopGroup->InternalObjectIndentify( j, hypGrpName );
1719 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
1720 // open algorithm group
1721 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1722 aGroup->OpenOnDisk();
1724 // --> get algorithm id
1725 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
1730 // get number of datasets
1731 int aNbSubObjects = aGroup->nInternalObjects();
1732 for ( int k = 0; k < aNbSubObjects; k++ ) {
1734 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
1735 aGroup->InternalObjectIndentify( k, name_of_subgroup );
1736 // --> get algorithm name
1737 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
1738 aDataset = new HDFdataset( name_of_subgroup, aGroup );
1739 aDataset->OpenOnDisk();
1740 size = aDataset->GetSize();
1741 char* hypname_str = new char[ size ];
1742 aDataset->ReadFromDisk( hypname_str );
1743 hypname = string( hypname_str );
1745 aDataset->CloseOnDisk();
1747 // --> get algorithm plugin library name
1748 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
1749 aDataset = new HDFdataset( name_of_subgroup, aGroup );
1750 aDataset->OpenOnDisk();
1751 size = aDataset->GetSize();
1752 char* libname_str = new char[ size ];
1753 aDataset->ReadFromDisk( libname_str );
1754 if(MYDEBUG) SCRUTE( libname_str );
1755 libname = string( libname_str );
1757 aDataset->CloseOnDisk();
1759 // --> get algorithm data
1760 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
1761 aDataset = new HDFdataset( name_of_subgroup, aGroup );
1762 aDataset->OpenOnDisk();
1763 size = aDataset->GetSize();
1764 char* hypdata_str = new char[ size ];
1765 aDataset->ReadFromDisk( hypdata_str );
1766 if(MYDEBUG) SCRUTE( hypdata_str );
1767 hypdata = string( hypdata_str );
1769 aDataset->CloseOnDisk();
1772 // close algorithm HDF group
1773 aGroup->CloseOnDisk();
1775 // --> restore algorithm from data
1776 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
1777 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
1778 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
1779 SMESH::SMESH_Hypothesis_var myHyp;
1781 try { // protect persistence mechanism against exceptions
1782 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
1785 INFOS( "Exception during hypothesis creation" );
1788 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1790 myImpl->LoadFrom( hypdata.c_str() );
1791 string iorString = GetORB()->object_to_string( myHyp );
1792 int newId = myStudyContext->findId( iorString );
1793 myStudyContext->mapOldToNew( id, newId );
1796 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
1800 // close algorithms root HDF group
1801 aTopGroup->CloseOnDisk();
1804 // --> the rest groups should be meshes
1805 for ( int i = 0; i < aNbGroups; i++ ) {
1806 // identify next group
1807 char meshName[ HDF_NAME_MAX_LEN+1 ];
1808 aFile->InternalObjectIndentify( i, meshName );
1810 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
1812 int id = atoi( string( meshName ).substr( 4 ).c_str() );
1816 bool hasData = false;
1818 // open mesh HDF group
1819 aTopGroup = new HDFgroup( meshName, aFile );
1820 aTopGroup->OpenOnDisk();
1822 // get number of child HDF objects
1823 int aNbObjects = aTopGroup->nInternalObjects();
1824 if ( aNbObjects > 0 ) {
1826 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
1827 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
1828 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
1829 if ( !myNewMeshImpl )
1831 string iorString = GetORB()->object_to_string( myNewMesh );
1832 int newId = myStudyContext->findId( iorString );
1833 myStudyContext->mapOldToNew( id, newId );
1835 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
1836 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1838 // try to find mesh data dataset
1839 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
1840 // load mesh "has data" flag
1841 aDataset = new HDFdataset( "Has data", aTopGroup );
1842 aDataset->OpenOnDisk();
1843 size = aDataset->GetSize();
1844 char* strHasData = new char[ size ];
1845 aDataset->ReadFromDisk( strHasData );
1846 aDataset->CloseOnDisk();
1847 if ( strcmp( strHasData, "1") == 0 ) {
1848 // read mesh data from MED file
1849 myReader.SetMesh( mySMESHDSMesh );
1850 myReader.SetMeshId( id );
1856 // try to read and set reference to shape
1857 GEOM::GEOM_Object_var aShapeObject;
1858 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
1859 // load mesh "Ref on shape" - it's an entry to SObject
1860 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
1861 aDataset->OpenOnDisk();
1862 size = aDataset->GetSize();
1863 char* refFromFile = new char[ size ];
1864 aDataset->ReadFromDisk( refFromFile );
1865 aDataset->CloseOnDisk();
1866 if ( strlen( refFromFile ) > 0 ) {
1867 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
1869 // Make sure GEOM data are loaded first
1870 loadGeomData( shapeSO->GetFatherComponent() );
1872 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
1873 if ( !CORBA::is_nil( shapeObject ) ) {
1874 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
1875 if ( !aShapeObject->_is_nil() )
1876 myNewMeshImpl->SetShape( aShapeObject );
1881 // try to get applied hypotheses
1882 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
1883 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1884 aGroup->OpenOnDisk();
1885 // get number of applied hypotheses
1886 int aNbSubObjects = aGroup->nInternalObjects();
1887 for ( int j = 0; j < aNbSubObjects; j++ ) {
1888 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
1889 aGroup->InternalObjectIndentify( j, name_dataset );
1890 // check if it is a hypothesis
1891 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
1892 aDataset = new HDFdataset( name_dataset, aGroup );
1893 aDataset->OpenOnDisk();
1894 size = aDataset->GetSize();
1895 char* refFromFile = new char[ size ];
1896 aDataset->ReadFromDisk( refFromFile );
1897 aDataset->CloseOnDisk();
1899 // san - it is impossible to recover applied hypotheses using their entries within Load() method
1901 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
1902 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
1903 int id = atoi( refFromFile );
1904 string anIOR = myStudyContext->getIORbyOldId( id );
1905 if ( !anIOR.empty() ) {
1906 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
1907 if ( !CORBA::is_nil( hypObject ) ) {
1908 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
1909 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
1910 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
1915 aGroup->CloseOnDisk();
1918 // try to get applied algorithms
1919 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
1920 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1921 aGroup->OpenOnDisk();
1922 // get number of applied algorithms
1923 int aNbSubObjects = aGroup->nInternalObjects();
1924 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
1925 for ( int j = 0; j < aNbSubObjects; j++ ) {
1926 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
1927 aGroup->InternalObjectIndentify( j, name_dataset );
1928 // check if it is an algorithm
1929 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
1930 aDataset = new HDFdataset( name_dataset, aGroup );
1931 aDataset->OpenOnDisk();
1932 size = aDataset->GetSize();
1933 char* refFromFile = new char[ size ];
1934 aDataset->ReadFromDisk( refFromFile );
1935 aDataset->CloseOnDisk();
1937 // san - it is impossible to recover applied algorithms using their entries within Load() method
1939 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
1940 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
1941 int id = atoi( refFromFile );
1942 string anIOR = myStudyContext->getIORbyOldId( id );
1943 if ( !anIOR.empty() ) {
1944 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
1945 if ( !CORBA::is_nil( hypObject ) ) {
1946 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
1947 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
1948 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
1953 aGroup->CloseOnDisk();
1956 // --> try to find submeshes containers for each type of submesh
1957 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
1958 char name_meshgroup[ 30 ];
1959 if ( j == GetSubMeshOnVertexTag() )
1960 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1961 else if ( j == GetSubMeshOnEdgeTag() )
1962 strcpy( name_meshgroup, "SubMeshes On Edge" );
1963 else if ( j == GetSubMeshOnWireTag() )
1964 strcpy( name_meshgroup, "SubMeshes On Wire" );
1965 else if ( j == GetSubMeshOnFaceTag() )
1966 strcpy( name_meshgroup, "SubMeshes On Face" );
1967 else if ( j == GetSubMeshOnShellTag() )
1968 strcpy( name_meshgroup, "SubMeshes On Shell" );
1969 else if ( j == GetSubMeshOnSolidTag() )
1970 strcpy( name_meshgroup, "SubMeshes On Solid" );
1971 else if ( j == GetSubMeshOnCompoundTag() )
1972 strcpy( name_meshgroup, "SubMeshes On Compound" );
1974 // try to get submeshes container HDF group
1975 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
1976 // open submeshes containers HDF group
1977 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1978 aGroup->OpenOnDisk();
1980 // get number of submeshes
1981 int aNbSubMeshes = aGroup->nInternalObjects();
1982 for ( int k = 0; k < aNbSubMeshes; k++ ) {
1984 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
1985 aGroup->InternalObjectIndentify( k, name_submeshgroup );
1986 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
1987 // --> get submesh id
1988 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
1991 // open submesh HDF group
1992 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
1993 aSubGroup->OpenOnDisk();
1995 // try to read and set reference to subshape
1996 GEOM::GEOM_Object_var aSubShapeObject;
1997 SMESH::SMESH_subMesh_var aSubMesh;
1999 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2000 // load submesh "Ref on shape" - it's an entry to SObject
2001 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2002 aDataset->OpenOnDisk();
2003 size = aDataset->GetSize();
2004 char* refFromFile = new char[ size ];
2005 aDataset->ReadFromDisk( refFromFile );
2006 aDataset->CloseOnDisk();
2007 if ( strlen( refFromFile ) > 0 ) {
2008 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2009 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2010 if ( !CORBA::is_nil( subShapeObject ) ) {
2011 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2012 if ( !aSubShapeObject->_is_nil() )
2013 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2014 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2015 if ( aSubMesh->_is_nil() )
2017 string iorSubString = GetORB()->object_to_string( aSubMesh );
2018 int newSubId = myStudyContext->findId( iorSubString );
2019 myStudyContext->mapOldToNew( subid, newSubId );
2024 if ( aSubMesh->_is_nil() )
2027 // VSR: Get submesh data from MED convertor
2028 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2029 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2030 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2031 // subid << " for subshape # " << anInternalSubmeshId);
2032 // SMESHDS_SubMesh* aSubMeshDS =
2033 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2034 // if ( !aSubMeshDS ) {
2035 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2036 // anInternalSubmeshId << " in current mesh!");
2039 // myReader.GetSubMesh( aSubMeshDS, subid );
2042 // try to get applied hypotheses
2043 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2044 // open "applied hypotheses" HDF group
2045 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2046 aSubSubGroup->OpenOnDisk();
2047 // get number of applied hypotheses
2048 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2049 for ( int l = 0; l < aNbSubObjects; l++ ) {
2050 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2051 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2052 // check if it is a hypothesis
2053 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2054 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2055 aDataset->OpenOnDisk();
2056 size = aDataset->GetSize();
2057 char* refFromFile = new char[ size ];
2058 aDataset->ReadFromDisk( refFromFile );
2059 aDataset->CloseOnDisk();
2061 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2062 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2063 int id = atoi( refFromFile );
2064 string anIOR = myStudyContext->getIORbyOldId( id );
2065 if ( !anIOR.empty() ) {
2066 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2067 if ( !CORBA::is_nil( hypObject ) ) {
2068 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2069 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2070 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2075 // close "applied hypotheses" HDF group
2076 aSubSubGroup->CloseOnDisk();
2079 // try to get applied algorithms
2080 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2081 // open "applied algorithms" HDF group
2082 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2083 aSubSubGroup->OpenOnDisk();
2084 // get number of applied algorithms
2085 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2086 for ( int l = 0; l < aNbSubObjects; l++ ) {
2087 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2088 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2089 // check if it is an algorithm
2090 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2091 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2092 aDataset->OpenOnDisk();
2093 size = aDataset->GetSize();
2094 char* refFromFile = new char[ size ];
2095 aDataset->ReadFromDisk( refFromFile );
2096 aDataset->CloseOnDisk();
2098 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2099 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2100 int id = atoi( refFromFile );
2101 string anIOR = myStudyContext->getIORbyOldId( id );
2102 if ( !anIOR.empty() ) {
2103 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2104 if ( !CORBA::is_nil( hypObject ) ) {
2105 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2106 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2107 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2112 // close "applied algorithms" HDF group
2113 aSubSubGroup->CloseOnDisk();
2116 // close submesh HDF group
2117 aSubGroup->CloseOnDisk();
2120 // close submeshes containers HDF group
2121 aGroup->CloseOnDisk();
2126 // Read sub-meshes from MED
2127 if(MYDEBUG) MESSAGE("JFA - Create all sub-meshes");
2128 myReader.CreateAllSubMeshes();
2131 // Read node positions on sub-shapes (SMDS_Position)
2133 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
2135 // There are 5 datasets to read:
2136 // "Nodes on Edges" - ID of node on edge
2137 // "Edge positions" - U parameter on node on edge
2138 // "Nodes on Faces" - ID of node on face
2139 // "Face U positions" - U parameter of node on face
2140 // "Face V positions" - V parameter of node on face
2141 char* aEid_DSName = "Nodes on Edges";
2142 char* aEu_DSName = "Edge positions";
2143 char* aFu_DSName = "Face U positions";
2144 //char* aFid_DSName = "Nodes on Faces";
2145 //char* aFv_DSName = "Face V positions";
2148 int nbEids = 0, nbFids = 0;
2149 int *aEids = 0, *aFids = 0;
2150 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
2153 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2154 aGroup->OpenOnDisk();
2156 // loop on 5 data sets
2157 int aNbObjects = aGroup->nInternalObjects();
2158 for ( int i = 0; i < aNbObjects; i++ )
2161 char aDSName[ HDF_NAME_MAX_LEN+1 ];
2162 aGroup->InternalObjectIndentify( i, aDSName );
2164 aDataset = new HDFdataset( aDSName, aGroup );
2165 aDataset->OpenOnDisk();
2166 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
2168 double* pos = new double [ aDataset->GetSize() ];
2169 aDataset->ReadFromDisk( pos );
2171 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
2173 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
2180 int* ids = new int [ aDataset->GetSize() ];
2181 aDataset->ReadFromDisk( ids );
2182 // on face or nodes?
2183 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
2185 nbEids = aDataset->GetSize();
2189 nbFids = aDataset->GetSize();
2192 } // loop on 5 datasets
2194 // Set node positions on edges or faces
2195 for ( int onFace = 0; onFace < 2; onFace++ )
2197 int nbNodes = ( onFace ? nbFids : nbEids );
2198 if ( nbNodes == 0 ) continue;
2199 int* aNodeIDs = ( onFace ? aFids : aEids );
2200 double* aUPos = ( onFace ? aFupos : aEpos );
2201 double* aVPos = ( onFace ? aFvpos : 0 );
2203 for ( int iNode = 0; iNode < nbNodes; iNode++ )
2205 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
2207 SMDS_PositionPtr aPos = node->GetPosition();
2210 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
2211 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
2212 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
2213 fPos->SetUParameter( aUPos[ iNode ]);
2214 fPos->SetVParameter( aVPos[ iNode ]);
2217 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
2218 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
2219 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
2220 fPos->SetUParameter( aUPos[ iNode ]);
2224 if ( aEids ) delete [] aEids;
2225 if ( aFids ) delete [] aFids;
2226 if ( aEpos ) delete [] aEpos;
2227 if ( aFupos ) delete [] aFupos;
2228 if ( aFvpos ) delete [] aFvpos;
2230 aGroup->CloseOnDisk();
2232 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
2235 // Recompute State (as computed sub-meshes are restored from MED)
2236 if ( !aShapeObject->_is_nil() ) {
2237 MESSAGE("JFA - Compute State Engine ...");
2238 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
2239 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
2240 (SMESH_subMesh::SUBMESH_RESTORED);
2241 MESSAGE("JFA - Compute State Engine finished");
2244 // try to get groups
2245 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
2246 char name_group[ 30 ];
2247 if ( ii == GetNodeGroupsTag() )
2248 strcpy( name_group, "Groups of Nodes" );
2249 else if ( ii == GetEdgeGroupsTag() )
2250 strcpy( name_group, "Groups of Edges" );
2251 else if ( ii == GetFaceGroupsTag() )
2252 strcpy( name_group, "Groups of Faces" );
2253 else if ( ii == GetVolumeGroupsTag() )
2254 strcpy( name_group, "Groups of Volumes" );
2256 if ( aTopGroup->ExistInternalObject( name_group ) ) {
2257 aGroup = new HDFgroup( name_group, aTopGroup );
2258 aGroup->OpenOnDisk();
2259 // get number of groups
2260 int aNbSubObjects = aGroup->nInternalObjects();
2261 for ( int j = 0; j < aNbSubObjects; j++ ) {
2262 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2263 aGroup->InternalObjectIndentify( j, name_dataset );
2264 // check if it is an group
2265 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
2267 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
2270 aDataset = new HDFdataset( name_dataset, aGroup );
2271 aDataset->OpenOnDisk();
2273 // Retrieve actual group name
2274 size = aDataset->GetSize();
2275 char* nameFromFile = new char[ size ];
2276 aDataset->ReadFromDisk( nameFromFile );
2277 aDataset->CloseOnDisk();
2279 // Try to find a shape reference
2280 TopoDS_Shape aShape;
2281 char aRefName[ 30 ];
2282 sprintf( aRefName, "Ref on shape %d", subid);
2283 if ( aGroup->ExistInternalObject( aRefName ) ) {
2284 // load mesh "Ref on shape" - it's an entry to SObject
2285 aDataset = new HDFdataset( aRefName, aGroup );
2286 aDataset->OpenOnDisk();
2287 size = aDataset->GetSize();
2288 char* refFromFile = new char[ size ];
2289 aDataset->ReadFromDisk( refFromFile );
2290 aDataset->CloseOnDisk();
2291 if ( strlen( refFromFile ) > 0 ) {
2292 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2293 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2294 if ( !CORBA::is_nil( shapeObject ) ) {
2295 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2296 if ( !aShapeObject->_is_nil() )
2297 aShape = GeomObjectToShape( aShapeObject );
2301 // Create group servant
2302 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
2303 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
2304 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
2305 // Obtain a SMESHDS_Group object
2306 if ( aNewGroup->_is_nil() )
2309 string iorSubString = GetORB()->object_to_string( aNewGroup );
2310 int newSubId = myStudyContext->findId( iorSubString );
2311 myStudyContext->mapOldToNew( subid, newSubId );
2313 SMESH_GroupBase_i* aGroupImpl =
2314 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
2318 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
2322 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
2323 aGroupBaseDS->SetStoreName( name_dataset );
2325 // Fill group with contents from MED file
2326 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
2328 myReader.GetGroup( aGrp );
2331 aGroup->CloseOnDisk();
2336 aTopGroup->CloseOnDisk();
2341 aFile->CloseOnDisk();
2344 // Remove temporary files created from the stream
2346 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2348 INFOS( "SMESH_Gen_i::Load completed" );
2352 //=============================================================================
2354 * SMESH_Gen_i::LoadASCII
2356 * Load SMESH module's data in ASCII format (not implemented yet)
2358 //=============================================================================
2360 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
2361 const SALOMEDS::TMPFile& theStream,
2363 bool isMultiFile ) {
2364 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
2365 return Load( theComponent, theStream, theURL, isMultiFile );
2368 //=============================================================================
2370 * SMESH_Gen_i::Close
2372 * Clears study-connected data when it is closed
2374 //=============================================================================
2376 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
2378 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
2380 // Clear study contexts data
2381 int studyId = GetCurrentStudyID();
2382 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
2383 delete myStudyContextMap[ studyId ];
2384 myStudyContextMap.erase( studyId );
2389 //=============================================================================
2391 * SMESH_Gen_i::ComponentDataType
2393 * Get component data type
2395 //=============================================================================
2397 char* SMESH_Gen_i::ComponentDataType()
2399 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
2400 return CORBA::string_dup( "SMESH" );
2404 //=============================================================================
2406 * SMESH_Gen_i::IORToLocalPersistentID
2408 * Transform data from transient form to persistent
2410 //=============================================================================
2412 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
2413 const char* IORString,
2414 CORBA::Boolean /*isMultiFile*/,
2415 CORBA::Boolean /*isASCII*/ )
2417 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
2418 StudyContext* myStudyContext = GetCurrentStudyContext();
2420 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
2421 int anId = myStudyContext->findId( IORString );
2423 if(MYDEBUG) MESSAGE( "VSR " << anId )
2425 sprintf( strId, "%d", anId );
2426 return CORBA::string_dup( strId );
2429 return CORBA::string_dup( "" );
2432 //=============================================================================
2434 * SMESH_Gen_i::LocalPersistentIDToIOR
2436 * Transform data from persistent form to transient
2438 //=============================================================================
2440 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
2441 const char* aLocalPersistentID,
2442 CORBA::Boolean /*isMultiFile*/,
2443 CORBA::Boolean /*isASCII*/ )
2445 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
2446 StudyContext* myStudyContext = GetCurrentStudyContext();
2448 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
2449 int anId = atoi( aLocalPersistentID );
2450 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
2452 return CORBA::string_dup( "" );
2455 //=======================================================================
2456 //function : RegisterObject
2458 //=======================================================================
2460 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
2462 StudyContext* myStudyContext = GetCurrentStudyContext();
2463 if ( myStudyContext && !CORBA::is_nil( theObject )) {
2464 string iorString = GetORB()->object_to_string( theObject );
2465 return myStudyContext->addObject( iorString );
2470 //=============================================================================
2472 * SMESHEngine_factory
2474 * C factory, accessible with dlsym, after dlopen
2476 //=============================================================================
2480 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
2481 PortableServer::POA_ptr poa,
2482 PortableServer::ObjectId* contId,
2483 const char* instanceName,
2484 const char* interfaceName )
2486 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
2487 if(MYDEBUG) SCRUTE(interfaceName);
2488 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
2489 return aSMESHGen->getId() ;