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"
60 #include "SMESH_Gen_i.hxx"
61 #include "SMESH_Mesh_i.hxx"
62 #include "SMESH_Hypothesis_i.hxx"
63 #include "SMESH_Algo_i.hxx"
64 #include "SMESH_Group_i.hxx"
65 #include "SMESH_PythonDump.hxx"
67 #include "SMESHDS_Document.hxx"
68 #include "SMESHDS_Group.hxx"
69 #include "SMESHDS_GroupOnGeom.hxx"
70 #include "SMESH_Mesh.hxx"
71 #include "SMESH_Hypothesis.hxx"
72 #include "SMESH_Group.hxx"
73 #include "SMESH_MeshEditor.hxx"
75 #include "SMDS_EdgePosition.hxx"
76 #include "SMDS_FacePosition.hxx"
77 #include "SMDS_VertexPosition.hxx"
78 #include "SMDS_SpacePosition.hxx"
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_Filter)
83 #include "DriverMED_W_SMESHDS_Mesh.h"
84 #include "DriverMED_R_SMESHDS_Mesh.h"
86 #include "SALOMEDS_Tool.hxx"
87 #include "SALOME_NamingService.hxx"
88 #include "SALOME_LifeCycleCORBA.hxx"
89 #include "Utils_SINGLETON.hxx"
92 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
94 #include "GEOM_Client.hxx"
95 #include "Utils_ExceptHandlers.hxx"
100 using SMESH::TPythonDump;
102 #define NUM_TMP_FILES 2
105 static int MYDEBUG = 1;
107 static int MYDEBUG = 0;
110 // Static variables definition
111 CORBA::ORB_var SMESH_Gen_i::myOrb;
112 PortableServer::POA_var SMESH_Gen_i::myPoa;
113 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
114 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
115 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
117 //=============================================================================
119 * GetServant [ static ]
121 * Get servant of the CORBA object
123 //=============================================================================
125 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
127 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
130 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
134 INFOS( "GetServant - Unknown exception was caught!!!" );
139 //=============================================================================
141 * SObjectToObject [ static ]
143 * Get CORBA object corresponding to the SALOMEDS::SObject
145 //=============================================================================
147 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
149 SALOMEDS::GenericAttribute_var anAttr;
150 CORBA::Object_var anObj;
151 if ( !theSObject->_is_nil() ) {
153 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
154 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
155 CORBA::String_var aValue = anIOR->Value();
156 if( strcmp( aValue, "" ) != 0 )
157 anObj = GetORB()->string_to_object( aValue );
161 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
167 //=============================================================================
171 * Get SALOME_NamingService object
173 //=============================================================================
175 SALOME_NamingService* SMESH_Gen_i::GetNS()
177 if ( myNS == NULL ) {
178 myNS = SINGLETON_<SALOME_NamingService>::Instance();
179 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
180 myNS->init_orb( GetORB() );
185 //=============================================================================
189 * Get SALOME_LifeCycleCORBA object
191 //=============================================================================
192 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
193 if ( myLCC == NULL ) {
194 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
200 //=============================================================================
202 * GetGeomEngine [ static ]
204 * Get GEOM::GEOM_Gen reference
206 //=============================================================================
207 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
208 GEOM::GEOM_Gen_var aGeomEngine =
209 GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
210 return aGeomEngine._retn();
213 //=============================================================================
215 * SMESH_Gen_i::SMESH_Gen_i
217 * Default constructor: not for use
219 //=============================================================================
221 SMESH_Gen_i::SMESH_Gen_i()
223 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
226 //=============================================================================
228 * SMESH_Gen_i::SMESH_Gen_i
230 * Standard constructor, used with Container
232 //=============================================================================
234 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
235 PortableServer::POA_ptr poa,
236 PortableServer::ObjectId* contId,
237 const char* instanceName,
238 const char* interfaceName )
239 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
241 INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
243 myOrb = CORBA::ORB::_duplicate(orb);
244 myPoa = PortableServer::POA::_duplicate(poa);
247 _id = myPoa->activate_object( _thisObj );
249 myIsEmbeddedMode = false;
250 myShapeReader = NULL; // shape reader
253 // set it in standalone mode only
254 //OSD::SetSignal( true );
257 //=============================================================================
259 * SMESH_Gen_i::~SMESH_Gen_i
263 //=============================================================================
265 SMESH_Gen_i::~SMESH_Gen_i()
267 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
269 // delete hypothesis creators
270 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
271 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
273 delete (*itHyp).second;
275 myHypCreatorMap.clear();
277 // Clear study contexts data
278 map<int, StudyContext*>::iterator it;
279 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
282 myStudyContextMap.clear();
283 // delete shape reader
284 if ( !myShapeReader )
285 delete myShapeReader;
288 //=============================================================================
290 * SMESH_Gen_i::createHypothesis
292 * Create hypothesis of given type
294 //=============================================================================
295 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
296 const char* theLibName)
297 throw (SALOME::SALOME_Exception)
299 Unexpect aCatch(SALOME_SalomeException);
300 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
302 // create a new hypothesis object servant
303 SMESH_Hypothesis_i* myHypothesis_i = 0;
304 SMESH::SMESH_Hypothesis_var hypothesis_i;
308 // check, if creator for this hypothesis type already exists
309 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
311 // load plugin library
312 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
313 void* libHandle = dlopen (theLibName, RTLD_LAZY);
316 // report any error, if occured
317 const char* anError = dlerror();
318 throw(SALOME_Exception(anError));
321 // get method, returning hypothesis creator
322 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
323 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
324 GetHypothesisCreator procHandle =
325 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
328 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
332 // get hypothesis creator
333 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
334 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
337 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
340 // map hypothesis creator to a hypothesis name
341 myHypCreatorMap[string(theHypName)] = aCreator;
344 // create a new hypothesis object, store its ref. in studyContext
345 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
347 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
348 // _CS_gbo Explicit activation (no longer made in the constructor).
349 myHypothesis_i->Activate();
350 myHypothesis_i->SetLibName(theLibName); // for persistency assurance
352 catch (SALOME_Exception& S_ex)
354 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
358 return hypothesis_i._retn();
360 // activate the CORBA servant of hypothesis
361 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
362 int nextId = RegisterObject( hypothesis_i );
363 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
365 return hypothesis_i._retn();
368 //=============================================================================
370 * SMESH_Gen_i::createMesh
372 * Create empty mesh on shape
374 //=============================================================================
375 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
376 throw ( SALOME::SALOME_Exception )
378 Unexpect aCatch(SALOME_SalomeException);
379 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
381 // Get or create the GEOM_Client instance
383 // create a new mesh object servant, store it in a map in study context
384 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
385 // create a new mesh object
386 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
388 // activate the CORBA servant of Mesh
389 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
390 int nextId = RegisterObject( mesh );
391 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
394 catch (SALOME_Exception& S_ex) {
395 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
397 return SMESH::SMESH_Mesh::_nil();
400 //=============================================================================
402 * SMESH_Gen_i::GetShapeReader
406 //=============================================================================
407 GEOM_Client* SMESH_Gen_i::GetShapeReader()
409 // create shape reader if necessary
410 if ( !myShapeReader )
411 myShapeReader = new GEOM_Client(GetContainerRef());
412 ASSERT( myShapeReader );
413 return myShapeReader;
416 //=============================================================================
418 * SMESH_Gen_i::SetEmbeddedMode
422 //=============================================================================
424 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
426 myIsEmbeddedMode = theMode;
428 if ( !myIsEmbeddedMode ) {
429 //PAL10867: disable signals catching with "noexcepthandler" option
430 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
431 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
436 char* envDisableFPE = getenv("DISABLE_FPE");
437 if (envDisableFPE && atoi(envDisableFPE))
442 OSD::SetSignal( raiseFPE );
444 // else OSD::SetSignal() is called in GUI
448 //=============================================================================
450 * SMESH_Gen_i::IsEmbeddedMode
454 //=============================================================================
456 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
458 return myIsEmbeddedMode;
461 //=============================================================================
463 * SMESH_Gen_i::SetCurrentStudy
467 //=============================================================================
469 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
472 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
473 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
474 // create study context, if it doesn't exist and set current study
475 int studyId = GetCurrentStudyID();
476 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
477 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
478 myStudyContextMap[ studyId ] = new StudyContext;
481 // myCurrentStudy may be nil
482 if ( !CORBA::is_nil( myCurrentStudy ) ) {
483 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
484 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
485 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
487 // set current study for geom engine
488 //if ( !CORBA::is_nil( GetGeomEngine() ) )
489 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
493 //=============================================================================
495 * SMESH_Gen_i::GetCurrentStudy
499 //=============================================================================
501 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
503 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
504 return SALOMEDS::Study::_duplicate( myCurrentStudy );
507 //=============================================================================
509 * SMESH_Gen_i::GetCurrentStudyContext
511 * Get current study context
513 //=============================================================================
514 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
516 if ( !CORBA::is_nil( myCurrentStudy ) &&
517 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
518 return myStudyContextMap[ myCurrentStudy->StudyId() ];
523 //=============================================================================
525 * SMESH_Gen_i::CreateHypothesis
527 * Create hypothesis/algorothm of given type and publish it in the study
529 //=============================================================================
531 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
532 const char* theLibName )
533 throw ( SALOME::SALOME_Exception )
535 Unexpect aCatch(SALOME_SalomeException);
536 // Create hypothesis/algorithm
537 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
539 // Publish hypothesis/algorithm in the study
540 if ( CanPublishInStudy( hyp ) ) {
541 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
542 if ( !aSO->_is_nil() ) {
543 // Update Python script
544 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
545 << theHypName << "', '" << theLibName << "')";
552 //================================================================================
554 * \brief Return hypothesis of given type holding parameter values of the existing mesh
555 * \param theHypType - hypothesis type name
556 * \param theLibName - plugin library name
557 * \param theMesh - The mesh of interest
558 * \param theGeom - The shape to get parameter values from
559 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
560 * in a study and used to compute the mesh, or a temporary one created just to pass
563 //================================================================================
565 SMESH::SMESH_Hypothesis_ptr
566 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
567 const char* theLibName,
568 SMESH::SMESH_Mesh_ptr theMesh,
569 GEOM::GEOM_Object_ptr theGeom)
570 throw ( SALOME::SALOME_Exception )
572 Unexpect aCatch(SALOME_SalomeException);
573 if ( CORBA::is_nil( theMesh ) )
574 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
575 if ( CORBA::is_nil( theGeom ) )
576 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
578 // -----------------------------------------------
579 // find hypothesis used to mesh theGeom
580 // -----------------------------------------------
582 // get mesh and shape
583 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
584 TopoDS_Shape shape = GeomObjectToShape( theGeom );
585 if ( !meshServant || shape.IsNull() )
586 return SMESH::SMESH_Hypothesis::_nil();
587 ::SMESH_Mesh& mesh = meshServant->GetImpl();
589 if ( mesh.NbNodes() == 0 ) // empty mesh
590 return SMESH::SMESH_Hypothesis::_nil();
592 // create a temporary hypothesis to know its dimention
593 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
594 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
596 return SMESH::SMESH_Hypothesis::_nil();
597 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
599 // look for a hypothesis of theHypType used to mesh the shape
600 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
603 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
604 int nbLocalHyps = aHypList->length();
605 for ( int i = 0; i < nbLocalHyps; i++ )
606 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
607 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
608 // check super shapes
609 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
610 while ( nbLocalHyps == 0 && itShape.More() ) {
611 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
612 if ( ! CORBA::is_nil( geomObj )) {
613 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
614 nbLocalHyps = aHypList->length();
615 for ( int i = 0; i < nbLocalHyps; i++ )
616 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
617 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
623 // let the temporary hypothesis find out some how parameter values
624 if ( hyp->SetParametersByMesh( &mesh, shape ))
625 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
627 return SMESH::SMESH_Hypothesis::_nil();
630 //=============================================================================
632 * SMESH_Gen_i::CreateMesh
634 * Create empty mesh on a shape and publish it in the study
636 //=============================================================================
638 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
639 throw ( SALOME::SALOME_Exception )
641 Unexpect aCatch(SALOME_SalomeException);
642 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
644 SMESH::SMESH_Mesh_var mesh = this->createMesh();
646 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
647 ASSERT( meshServant );
648 meshServant->SetShape( theShapeObject );
650 // publish mesh in the study
651 if ( CanPublishInStudy( mesh ) ) {
652 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
653 aStudyBuilder->NewCommand(); // There is a transaction
654 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
655 aStudyBuilder->CommitCommand();
656 if ( !aSO->_is_nil() ) {
657 // Update Python script
658 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
665 //=============================================================================
667 * SMESH_Gen_i::CreateEmptyMesh
671 //=============================================================================
673 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
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 // publish mesh in the study
682 if ( CanPublishInStudy( mesh ) ) {
683 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
684 aStudyBuilder->NewCommand(); // There is a transaction
685 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
686 aStudyBuilder->CommitCommand();
687 if ( !aSO->_is_nil() ) {
688 // Update Python script
689 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
696 //=============================================================================
698 * SMESH_Gen_i::CreateMeshFromUNV
700 * Create mesh and import data from UNV file
702 //=============================================================================
704 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
705 throw ( SALOME::SALOME_Exception )
707 Unexpect aCatch(SALOME_SalomeException);
708 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
710 SMESH::SMESH_Mesh_var aMesh = createMesh();
712 // publish mesh in the study
713 if ( CanPublishInStudy( aMesh ) ) {
714 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
715 aStudyBuilder->NewCommand(); // There is a transaction
716 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
717 aStudyBuilder->CommitCommand();
718 if ( !aSO->_is_nil() ) {
719 // Update Python script
720 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
724 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
726 aServant->ImportUNVFile( theFileName );
728 // Dump creation of groups
729 aServant->GetGroups();
731 return aMesh._retn();
734 //=============================================================================
736 * SMESH_Gen_i::CreateMeshFromMED
738 * Create mesh and import data from MED file
740 //=============================================================================
742 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
743 SMESH::DriverMED_ReadStatus& theStatus)
744 throw ( SALOME::SALOME_Exception )
746 Unexpect aCatch(SALOME_SalomeException);
747 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
749 // Retrieve mesh names from the file
750 DriverMED_R_SMESHDS_Mesh myReader;
751 myReader.SetFile( theFileName );
752 myReader.SetMeshId( -1 );
753 Driver_Mesh::Status aStatus;
754 list<string> aNames = myReader.GetMeshNames(aStatus);
755 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
756 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
758 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
761 TPythonDump aPythonDump;
763 //TCollection_AsciiString aStr ("([");
765 if (theStatus == SMESH::DRS_OK) {
766 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
767 aStudyBuilder->NewCommand(); // There is a transaction
768 aResult->length( aNames.size() );
771 // Iterate through all meshes and create mesh objects
772 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
774 //if (i > 0) aStr += ", ";
775 if (i > 0) aPythonDump << ", ";
778 SMESH::SMESH_Mesh_var mesh = createMesh();
780 // publish mesh in the study
781 SALOMEDS::SObject_var aSO;
782 if ( CanPublishInStudy( mesh ) )
783 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
784 if ( !aSO->_is_nil() ) {
787 //aStr += aSO->GetID();
790 aPythonDump << "mesh_" << i;
792 // aStr += TCollection_AsciiString(i);
795 // Read mesh data (groups are published automatically by ImportMEDFile())
796 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
797 ASSERT( meshServant );
798 SMESH::DriverMED_ReadStatus status1 =
799 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
800 if (status1 > theStatus)
803 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
805 aStudyBuilder->CommitCommand();
808 // Update Python script
809 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
811 // Dump creation of groups
812 for ( int i = 0; i < aResult->length(); ++i )
813 aResult[ i ]->GetGroups();
815 return aResult._retn();
818 //=============================================================================
820 * SMESH_Gen_i::CreateMeshFromSTL
822 * Create mesh and import data from STL file
824 //=============================================================================
826 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
827 throw ( SALOME::SALOME_Exception )
829 Unexpect aCatch(SALOME_SalomeException);
830 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
832 SMESH::SMESH_Mesh_var aMesh = createMesh();
834 // publish mesh in the study
835 if ( CanPublishInStudy( aMesh ) ) {
836 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
837 aStudyBuilder->NewCommand(); // There is a transaction
838 SALOMEDS::SObject_var aSO = PublishInStudy
839 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
840 aStudyBuilder->CommitCommand();
841 if ( !aSO->_is_nil() ) {
842 // Update Python script
843 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
847 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
849 aServant->ImportSTLFile( theFileName );
850 return aMesh._retn();
853 //=============================================================================
855 * SMESH_Gen_i::IsReadyToCompute
857 * Returns true if mesh contains enough data to be computed
859 //=============================================================================
861 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
862 GEOM::GEOM_Object_ptr theShapeObject )
863 throw ( SALOME::SALOME_Exception )
865 Unexpect aCatch(SALOME_SalomeException);
866 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
868 if ( CORBA::is_nil( theShapeObject ) )
869 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
872 if ( CORBA::is_nil( theMesh ) )
873 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
878 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
879 ASSERT( meshServant );
881 // get local TopoDS_Shape
882 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
883 // call implementation
884 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
885 return myGen.CheckAlgoState( myLocMesh, myLocShape );
888 catch ( SALOME_Exception& S_ex ) {
889 INFOS( "catch exception "<< S_ex.what() );
894 //================================================================================
896 * \brief Returns errors of hypotheses definintion
897 * \param theMesh - the mesh
898 * \param theSubObject - the main or sub- shape
899 * \retval SMESH::algo_error_array* - sequence of errors
901 //================================================================================
903 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
904 GEOM::GEOM_Object_ptr theSubObject )
905 throw ( SALOME::SALOME_Exception )
907 Unexpect aCatch(SALOME_SalomeException);
908 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
910 if ( CORBA::is_nil( theSubObject ) )
911 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
913 if ( CORBA::is_nil( theMesh ) )
914 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
916 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
918 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
919 ASSERT( meshServant );
921 TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
922 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
923 list< ::SMESH_Gen::TAlgoStateError > error_list;
924 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
925 // call ::SMESH_Gen::GetAlgoState()
926 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
927 error_array->length( error_list.size() );
929 for ( error = error_list.begin(); error != error_list.end(); ++error )
932 SMESH::AlgoStateErrorName errName;
933 switch ( error->_name ) {
934 case ::SMESH_Gen::MISSING_ALGO: errName = SMESH::MISSING_ALGO; break;
935 case ::SMESH_Gen::MISSING_HYPO: errName = SMESH::MISSING_HYPO; break;
936 case ::SMESH_Gen::NOT_CONFORM_MESH: errName = SMESH::NOT_CONFORM_MESH; break;
938 THROW_SALOME_CORBA_EXCEPTION( "bad error name",SALOME::BAD_PARAM );
941 CORBA::String_var algoName;
942 if ( error->_algo ) {
943 if ( !myCurrentStudy->_is_nil() ) {
944 // find algo in the study
945 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
946 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
947 if ( !father->_is_nil() ) {
948 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
949 for ( ; itBig->More(); itBig->Next() ) {
950 SALOMEDS::SObject_var gotBranch = itBig->Value();
951 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
952 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
953 for ( ; algoIt->More(); algoIt->Next() ) {
954 SALOMEDS::SObject_var algoSO = algoIt->Value();
955 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
956 if ( !CORBA::is_nil( algoIOR )) {
957 SMESH_Hypothesis_i* myImpl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
958 if ( myImpl && myImpl->GetImpl() == error->_algo ) {
959 algoName = algoSO->GetName();
963 } // loop on algo SO's
966 } // SMESH component iterator
969 if ( algoName.in() == 0 )
970 // use algo type name
971 algoName = CORBA::string_dup( error->_algo->GetName() );
973 // fill AlgoStateError structure
974 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
975 errStruct.name = errName;
976 errStruct.algoName = algoName;
977 errStruct.algoDim = error->_algoDim;
978 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
982 catch ( SALOME_Exception& S_ex ) {
983 INFOS( "catch exception "<< S_ex.what() );
985 return error_array._retn();
988 //=============================================================================
990 * SMESH_Gen_i::GetSubShapesId
992 * Get sub-shapes unique ID's list
994 //=============================================================================
996 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
997 const SMESH::object_array& theListOfSubShapeObject )
998 throw ( SALOME::SALOME_Exception )
1000 Unexpect aCatch(SALOME_SalomeException);
1001 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1003 SMESH::long_array_var shapesId = new SMESH::long_array;
1006 if ( CORBA::is_nil( theMainShapeObject ) )
1007 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1008 SALOME::BAD_PARAM );
1012 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1013 TopTools_IndexedMapOfShape myIndexToShape;
1014 TopExp::MapShapes(myMainShape,myIndexToShape);
1016 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1018 GEOM::GEOM_Object_var aShapeObject
1019 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1020 if ( CORBA::is_nil( aShapeObject ) )
1021 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1022 SALOME::BAD_PARAM );
1024 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1025 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1027 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1028 setId.insert(myIndexToShape.FindIndex(F));
1029 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1031 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1033 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1034 setId.insert(myIndexToShape.FindIndex(E));
1035 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1037 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1039 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1040 setId.insert(myIndexToShape.FindIndex(V));
1041 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1044 shapesId->length(setId.size());
1045 set<int>::iterator iind;
1047 for (iind = setId.begin(); iind != setId.end(); iind++)
1049 if(MYDEBUG) SCRUTE((*iind));
1050 shapesId[i] = (*iind);
1051 if(MYDEBUG) SCRUTE(shapesId[i]);
1055 catch (SALOME_Exception& S_ex)
1057 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1060 return shapesId._retn();
1063 //=============================================================================
1065 * SMESH_Gen_i::Compute
1067 * Compute mesh on a shape
1069 //=============================================================================
1071 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1072 GEOM::GEOM_Object_ptr theShapeObject )
1073 throw ( SALOME::SALOME_Exception )
1075 Unexpect aCatch(SALOME_SalomeException);
1076 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1078 if ( CORBA::is_nil( theShapeObject ) )
1079 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1080 SALOME::BAD_PARAM );
1082 if ( CORBA::is_nil( theMesh ) )
1083 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1084 SALOME::BAD_PARAM );
1086 // Update Python script
1087 TPythonDump() << "isDone = " << this << ".Compute( "
1088 << theMesh << ", " << theShapeObject << ")";
1089 TPythonDump() << "if not isDone: print 'Mesh " << theMesh << " : computation failed'";
1093 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1094 ASSERT( meshServant );
1095 if ( meshServant ) {
1096 // get local TopoDS_Shape
1097 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1098 // call implementation compute
1099 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1100 return myGen.Compute( myLocMesh, myLocShape);
1103 catch ( SALOME_Exception& S_ex ) {
1104 INFOS( "Compute(): catch exception "<< S_ex.what() );
1107 INFOS( "Compute(): unknown exception " );
1112 //================================================================================
1114 * \brief Return geometrical object the given element is built on
1115 * \param theMesh - the mesh the element is in
1116 * \param theElementID - the element ID
1117 * \param theGeomName - the name of the result geom object if it is not yet published
1118 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1120 //================================================================================
1122 GEOM::GEOM_Object_ptr
1123 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1124 CORBA::Long theElementID,
1125 const char* theGeomName)
1126 throw ( SALOME::SALOME_Exception )
1128 Unexpect aCatch(SALOME_SalomeException);
1129 if ( CORBA::is_nil( theMesh ) )
1130 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1132 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1133 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1135 // get a core mesh DS
1136 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1137 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1139 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1140 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1141 // find the element in mesh
1142 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
1143 // find a shape id by the element
1144 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1145 // get a geom object by the shape id
1146 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1147 if ( geom->_is_nil() ) {
1148 GEOM::GEOM_IShapesOperations_var op =
1149 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1150 if ( !op->_is_nil() )
1151 geom = op->GetSubShape( mainShape, shapeID );
1153 if ( !geom->_is_nil() ) {
1154 // try to find the corresponding SObject
1155 GeomObjectToShape( geom ); // geom client remembers the found shape
1156 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1157 if ( SObj->_is_nil() )
1158 // publish a new subshape
1159 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1160 // return only published geometry
1161 if ( !SObj->_is_nil() )
1162 return geom._retn();
1166 return GEOM::GEOM_Object::_nil();
1169 //=============================================================================
1173 * Save SMESH module's data
1175 //=============================================================================
1176 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1180 INFOS( "SMESH_Gen_i::Save" );
1182 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1183 // san -- in case <myCurrentStudy> differs from theComponent's study,
1184 // use that of the component
1185 if ( myCurrentStudy->_is_nil() ||
1186 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1187 SetCurrentStudy( theComponent->GetStudy() );
1189 // Store study contents as a set of python commands
1190 SavePython(myCurrentStudy);
1192 StudyContext* myStudyContext = GetCurrentStudyContext();
1194 // Declare a byte stream
1195 SALOMEDS::TMPFile_var aStreamFile;
1197 // Obtain a temporary dir
1198 TCollection_AsciiString tmpDir =
1199 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1201 // Create a sequence of files processed
1202 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1203 aFileSeq->length( NUM_TMP_FILES );
1205 TCollection_AsciiString aStudyName( "" );
1207 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1209 // Set names of temporary files
1210 TCollection_AsciiString filename =
1211 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1212 TCollection_AsciiString meshfile =
1213 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1214 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1215 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1216 filename = tmpDir + filename;
1217 meshfile = tmpDir + meshfile;
1220 HDFdataset* aDataset;
1221 HDFgroup* aTopGroup;
1223 HDFgroup* aSubGroup;
1224 HDFgroup* aSubSubGroup;
1225 hdf_size aSize[ 1 ];
1228 //Remove the files if they exist: BugID: 11225
1229 TCollection_AsciiString cmd("rm -f \"");
1234 system(cmd.ToCString());
1236 // MED writer to be used by storage process
1237 DriverMED_W_SMESHDS_Mesh myWriter;
1238 myWriter.SetFile( meshfile.ToCString() );
1241 // ---> create HDF file
1242 aFile = new HDFfile( filename.ToCString() );
1243 aFile->CreateOnDisk();
1245 // --> iterator for top-level objects
1246 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1247 for ( ; itBig->More(); itBig->Next() ) {
1248 SALOMEDS::SObject_var gotBranch = itBig->Value();
1250 // --> hypotheses root branch (only one for the study)
1251 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1252 // create hypotheses root HDF group
1253 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1254 aTopGroup->CreateOnDisk();
1256 // iterator for all hypotheses
1257 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1258 for ( ; it->More(); it->Next() ) {
1259 SALOMEDS::SObject_var mySObject = it->Value();
1260 CORBA::Object_var anObject = SObjectToObject( mySObject );
1261 if ( !CORBA::is_nil( anObject ) ) {
1262 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1263 if ( !myHyp->_is_nil() ) {
1264 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1266 string hypname = string( myHyp->GetName() );
1267 string libname = string( myHyp->GetLibName() );
1268 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1269 string hypdata = string( myImpl->SaveTo() );
1271 // for each hypothesis create HDF group basing on its id
1272 char hypGrpName[30];
1273 sprintf( hypGrpName, "Hypothesis %d", id );
1274 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1275 aGroup->CreateOnDisk();
1276 // --> type name of hypothesis
1277 aSize[ 0 ] = hypname.length() + 1;
1278 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1279 aDataset->CreateOnDisk();
1280 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1281 aDataset->CloseOnDisk();
1282 // --> server plugin library name of hypothesis
1283 aSize[ 0 ] = libname.length() + 1;
1284 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1285 aDataset->CreateOnDisk();
1286 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1287 aDataset->CloseOnDisk();
1288 // --> persistent data of hypothesis
1289 aSize[ 0 ] = hypdata.length() + 1;
1290 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1291 aDataset->CreateOnDisk();
1292 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1293 aDataset->CloseOnDisk();
1294 // close hypothesis HDF group
1295 aGroup->CloseOnDisk();
1300 // close hypotheses root HDF group
1301 aTopGroup->CloseOnDisk();
1303 // --> algorithms root branch (only one for the study)
1304 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1305 // create algorithms root HDF group
1306 aTopGroup = new HDFgroup( "Algorithms", aFile );
1307 aTopGroup->CreateOnDisk();
1309 // iterator for all algorithms
1310 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1311 for ( ; it->More(); it->Next() ) {
1312 SALOMEDS::SObject_var mySObject = it->Value();
1313 CORBA::Object_var anObject = SObjectToObject( mySObject );
1314 if ( !CORBA::is_nil( anObject ) ) {
1315 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1316 if ( !myHyp->_is_nil() ) {
1317 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1319 string hypname = string( myHyp->GetName() );
1320 string libname = string( myHyp->GetLibName() );
1321 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1322 string hypdata = string( myImpl->SaveTo() );
1324 // for each algorithm create HDF group basing on its id
1325 char hypGrpName[30];
1326 sprintf( hypGrpName, "Algorithm %d", id );
1327 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1328 aGroup->CreateOnDisk();
1329 // --> type name of algorithm
1330 aSize[0] = hypname.length() + 1;
1331 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1332 aDataset->CreateOnDisk();
1333 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1334 aDataset->CloseOnDisk();
1335 // --> server plugin library name of hypothesis
1336 aSize[0] = libname.length() + 1;
1337 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1338 aDataset->CreateOnDisk();
1339 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1340 aDataset->CloseOnDisk();
1341 // --> persistent data of algorithm
1342 aSize[0] = hypdata.length() + 1;
1343 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1344 aDataset->CreateOnDisk();
1345 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1346 aDataset->CloseOnDisk();
1347 // close algorithm HDF group
1348 aGroup->CloseOnDisk();
1353 // close algorithms root HDF group
1354 aTopGroup->CloseOnDisk();
1356 // --> mesh objects roots branches
1357 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1358 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1359 if ( !CORBA::is_nil( anObject ) ) {
1360 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1361 if ( !myMesh->_is_nil() ) {
1362 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1364 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1365 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1366 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1368 // for each mesh open the HDF group basing on its id
1369 char meshGrpName[ 30 ];
1370 sprintf( meshGrpName, "Mesh %d", id );
1371 aTopGroup = new HDFgroup( meshGrpName, aFile );
1372 aTopGroup->CreateOnDisk();
1374 // --> put dataset to hdf file which is a flag that mesh has data
1375 string strHasData = "0";
1376 // check if the mesh is not empty
1377 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1378 // write mesh data to med file
1379 myWriter.SetMesh( mySMESHDSMesh );
1380 myWriter.SetMeshId( id );
1383 aSize[ 0 ] = strHasData.length() + 1;
1384 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1385 aDataset->CreateOnDisk();
1386 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1387 aDataset->CloseOnDisk();
1389 // write reference on a shape if exists
1390 SALOMEDS::SObject_var myRef;
1391 bool shapeRefFound = false;
1392 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1394 SALOMEDS::SObject_var myShape;
1395 bool ok = myRef->ReferencedObject( myShape );
1397 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1398 string myRefOnObject = myShape->GetID();
1399 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1400 aSize[ 0 ] = myRefOnObject.length() + 1;
1401 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1402 aDataset->CreateOnDisk();
1403 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1404 aDataset->CloseOnDisk();
1409 // write applied hypotheses if exist
1410 SALOMEDS::SObject_var myHypBranch;
1411 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1412 if ( found && !shapeRefFound ) { // remove applied hyps
1413 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1415 if ( found && shapeRefFound ) {
1416 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1417 aGroup->CreateOnDisk();
1419 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1421 for ( ; it->More(); it->Next() ) {
1422 SALOMEDS::SObject_var mySObject = it->Value();
1423 SALOMEDS::SObject_var myRefOnHyp;
1424 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1426 // san - it is impossible to recover applied hypotheses
1427 // using their entries within Load() method,
1428 // for there are no AttributeIORs in the study when Load() is working.
1429 // Hence, it is better to store persistent IDs of hypotheses as references to them
1431 //string myRefOnObject = myRefOnHyp->GetID();
1432 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1433 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1434 //if ( myRefOnObject.length() > 0 ) {
1435 //aSize[ 0 ] = myRefOnObject.length() + 1;
1436 char hypName[ 30 ], hypId[ 30 ];
1437 sprintf( hypName, "Hyp %d", ++hypNb );
1438 sprintf( hypId, "%d", id );
1439 aSize[ 0 ] = strlen( hypId ) + 1;
1440 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1441 aDataset->CreateOnDisk();
1442 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1443 aDataset->WriteOnDisk( hypId );
1444 aDataset->CloseOnDisk();
1448 aGroup->CloseOnDisk();
1451 // write applied algorithms if exist
1452 SALOMEDS::SObject_var myAlgoBranch;
1453 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1454 if ( found && !shapeRefFound ) { // remove applied algos
1455 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1457 if ( found && shapeRefFound ) {
1458 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1459 aGroup->CreateOnDisk();
1461 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1463 for ( ; it->More(); it->Next() ) {
1464 SALOMEDS::SObject_var mySObject = it->Value();
1465 SALOMEDS::SObject_var myRefOnAlgo;
1466 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1468 // san - it is impossible to recover applied algorithms
1469 // using their entries within Load() method,
1470 // for there are no AttributeIORs in the study when Load() is working.
1471 // Hence, it is better to store persistent IDs of algorithms as references to them
1473 //string myRefOnObject = myRefOnAlgo->GetID();
1474 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1475 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1476 //if ( myRefOnObject.length() > 0 ) {
1477 //aSize[ 0 ] = myRefOnObject.length() + 1;
1478 char algoName[ 30 ], algoId[ 30 ];
1479 sprintf( algoName, "Algo %d", ++algoNb );
1480 sprintf( algoId, "%d", id );
1481 aSize[ 0 ] = strlen( algoId ) + 1;
1482 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1483 aDataset->CreateOnDisk();
1484 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1485 aDataset->WriteOnDisk( algoId );
1486 aDataset->CloseOnDisk();
1490 aGroup->CloseOnDisk();
1493 // --> submesh objects sub-branches
1495 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1496 SALOMEDS::SObject_var mySubmeshBranch;
1497 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1499 if ( found ) // check if there is shape reference in submeshes
1501 bool hasShapeRef = false;
1502 SALOMEDS::ChildIterator_var itSM =
1503 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1504 for ( ; itSM->More(); itSM->Next() ) {
1505 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1506 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1507 mySubRef->ReferencedObject( myShape );
1508 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1511 { // remove one submesh
1512 if ( shapeRefFound )
1513 { // unassign hypothesis
1514 SMESH::SMESH_subMesh_var mySubMesh =
1515 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1516 if ( !mySubMesh->_is_nil() ) {
1517 int shapeID = mySubMesh->GetId();
1518 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1519 const list<const SMESHDS_Hypothesis*>& hypList =
1520 mySMESHDSMesh->GetHypothesis( S );
1521 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1522 while ( hyp != hypList.end() ) {
1523 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1524 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1528 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1530 } // loop on submeshes of a type
1531 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1532 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1535 } // end check if there is shape reference in submeshes
1537 char name_meshgroup[ 30 ];
1538 if ( i == GetSubMeshOnVertexTag() )
1539 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1540 else if ( i == GetSubMeshOnEdgeTag() )
1541 strcpy( name_meshgroup, "SubMeshes On Edge" );
1542 else if ( i == GetSubMeshOnWireTag() )
1543 strcpy( name_meshgroup, "SubMeshes On Wire" );
1544 else if ( i == GetSubMeshOnFaceTag() )
1545 strcpy( name_meshgroup, "SubMeshes On Face" );
1546 else if ( i == GetSubMeshOnShellTag() )
1547 strcpy( name_meshgroup, "SubMeshes On Shell" );
1548 else if ( i == GetSubMeshOnSolidTag() )
1549 strcpy( name_meshgroup, "SubMeshes On Solid" );
1550 else if ( i == GetSubMeshOnCompoundTag() )
1551 strcpy( name_meshgroup, "SubMeshes On Compound" );
1553 // for each type of submeshes create container HDF group
1554 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1555 aGroup->CreateOnDisk();
1557 // iterator for all submeshes of given type
1558 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1559 for ( ; itSM->More(); itSM->Next() ) {
1560 SALOMEDS::SObject_var mySObject = itSM->Value();
1561 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1562 if ( !CORBA::is_nil( anSubObject ))
1564 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1565 int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) );
1567 // for each mesh open the HDF group basing on its id
1568 char submeshGrpName[ 30 ];
1569 sprintf( submeshGrpName, "SubMesh %d", subid );
1570 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1571 aSubGroup->CreateOnDisk();
1573 // write reference on a shape, already checked if it exists
1574 SALOMEDS::SObject_var mySubRef, myShape;
1575 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1576 mySubRef->ReferencedObject( myShape );
1577 string myRefOnObject = myShape->GetID();
1578 if ( myRefOnObject.length() > 0 ) {
1579 aSize[ 0 ] = myRefOnObject.length() + 1;
1580 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1581 aDataset->CreateOnDisk();
1582 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1583 aDataset->CloseOnDisk();
1586 // write applied hypotheses if exist
1587 SALOMEDS::SObject_var mySubHypBranch;
1588 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1590 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1591 aSubSubGroup->CreateOnDisk();
1593 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1595 for ( ; it->More(); it->Next() ) {
1596 SALOMEDS::SObject_var mySubSObject = it->Value();
1597 SALOMEDS::SObject_var myRefOnHyp;
1598 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1600 //string myRefOnObject = myRefOnHyp->GetID();
1601 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1602 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1603 //if ( myRefOnObject.length() > 0 ) {
1604 //aSize[ 0 ] = myRefOnObject.length() + 1;
1605 char hypName[ 30 ], hypId[ 30 ];
1606 sprintf( hypName, "Hyp %d", ++hypNb );
1607 sprintf( hypId, "%d", id );
1608 aSize[ 0 ] = strlen( hypId ) + 1;
1609 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1610 aDataset->CreateOnDisk();
1611 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1612 aDataset->WriteOnDisk( hypId );
1613 aDataset->CloseOnDisk();
1617 aSubSubGroup->CloseOnDisk();
1620 // write applied algorithms if exist
1621 SALOMEDS::SObject_var mySubAlgoBranch;
1622 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1624 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1625 aSubSubGroup->CreateOnDisk();
1627 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1629 for ( ; it->More(); it->Next() ) {
1630 SALOMEDS::SObject_var mySubSObject = it->Value();
1631 SALOMEDS::SObject_var myRefOnAlgo;
1632 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1634 //string myRefOnObject = myRefOnAlgo->GetID();
1635 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1636 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1637 //if ( myRefOnObject.length() > 0 ) {
1638 //aSize[ 0 ] = myRefOnObject.length() + 1;
1639 char algoName[ 30 ], algoId[ 30 ];
1640 sprintf( algoName, "Algo %d", ++algoNb );
1641 sprintf( algoId, "%d", id );
1642 aSize[ 0 ] = strlen( algoId ) + 1;
1643 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1644 aDataset->CreateOnDisk();
1645 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1646 aDataset->WriteOnDisk( algoId );
1647 aDataset->CloseOnDisk();
1651 aSubSubGroup->CloseOnDisk();
1653 // close submesh HDF group
1654 aSubGroup->CloseOnDisk();
1657 // close container of submeshes by type HDF group
1658 aGroup->CloseOnDisk();
1661 // All sub-meshes will be stored in MED file
1662 // .. will NOT (PAL 12992)
1663 //if ( shapeRefFound )
1664 //myWriter.AddAllSubMeshes();
1666 // groups root sub-branch
1667 SALOMEDS::SObject_var myGroupsBranch;
1668 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1669 found = gotBranch->FindSubObject( i, myGroupsBranch );
1671 char name_group[ 30 ];
1672 if ( i == GetNodeGroupsTag() )
1673 strcpy( name_group, "Groups of Nodes" );
1674 else if ( i == GetEdgeGroupsTag() )
1675 strcpy( name_group, "Groups of Edges" );
1676 else if ( i == GetFaceGroupsTag() )
1677 strcpy( name_group, "Groups of Faces" );
1678 else if ( i == GetVolumeGroupsTag() )
1679 strcpy( name_group, "Groups of Volumes" );
1681 aGroup = new HDFgroup( name_group, aTopGroup );
1682 aGroup->CreateOnDisk();
1684 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
1685 for ( ; it->More(); it->Next() ) {
1686 SALOMEDS::SObject_var mySObject = it->Value();
1687 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
1688 if ( !CORBA::is_nil( aSubObject ) ) {
1689 SMESH_GroupBase_i* myGroupImpl =
1690 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
1694 int anId = myStudyContext->findId( string( GetORB()->object_to_string( aSubObject ) ) );
1696 // For each group, create a dataset named "Group <group_persistent_id>"
1697 // and store the group's user name into it
1699 sprintf( grpName, "Group %d", anId );
1700 char* aUserName = myGroupImpl->GetName();
1701 aSize[ 0 ] = strlen( aUserName ) + 1;
1703 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
1704 aDataset->CreateOnDisk();
1705 aDataset->WriteOnDisk( aUserName );
1706 aDataset->CloseOnDisk();
1708 // Store the group contents into MED file
1709 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
1711 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
1712 << grpName << " to MED file" );
1713 SMESHDS_GroupBase* aGrpBaseDS =
1714 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
1715 aGrpBaseDS->SetStoreName( grpName );
1717 // Pass SMESHDS_Group to MED writer
1718 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
1720 myWriter.AddGroup( aGrpDS );
1722 // write reference on a shape if exists
1723 SMESHDS_GroupOnGeom* aGeomGrp =
1724 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
1726 SALOMEDS::SObject_var mySubRef, myShape;
1727 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
1728 mySubRef->ReferencedObject( myShape ) &&
1729 !CORBA::is_nil( myShape->GetObject() ))
1731 string myRefOnObject = myShape->GetID();
1732 if ( myRefOnObject.length() > 0 ) {
1733 char aRefName[ 30 ];
1734 sprintf( aRefName, "Ref on shape %d", anId);
1735 aSize[ 0 ] = myRefOnObject.length() + 1;
1736 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
1737 aDataset->CreateOnDisk();
1738 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1739 aDataset->CloseOnDisk();
1742 else // shape ref is invalid:
1744 // save a group on geometry as ordinary group
1745 myWriter.AddGroup( aGeomGrp );
1751 aGroup->CloseOnDisk();
1755 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
1757 // Flush current mesh information into MED file
1760 // maybe a shape was deleted in the study
1761 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
1762 TopoDS_Shape nullShape;
1763 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
1766 if ( !mySMESHDSMesh->SubMeshes().empty() )
1770 aGroup = new HDFgroup( "Submeshes", aTopGroup );
1771 aGroup->CreateOnDisk();
1773 // each element belongs to one or none submesh,
1774 // so for each node/element, we store a submesh ID
1776 // Make maps of submesh IDs of elements sorted by element IDs
1777 typedef int TElemID;
1778 typedef int TSubMID;
1779 map< TElemID, TSubMID > eId2smId, nId2smId;
1780 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
1781 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
1782 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
1783 SMDS_NodeIteratorPtr itNode;
1784 SMDS_ElemIteratorPtr itElem;
1785 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
1787 TSubMID aSubMeID = itSubM->first;
1788 SMESHDS_SubMesh* aSubMesh = itSubM->second;
1789 if ( aSubMesh->IsComplexSubmesh() )
1790 continue; // submesh containing other submeshs
1792 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
1793 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
1794 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
1796 hint = eId2smId.begin();
1797 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
1798 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
1801 // Care of elements that are not on submeshes
1802 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
1803 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
1804 /* --- stl_map.h says : */
1805 /* A %map relies on unique keys and thus a %pair is only inserted if its */
1806 /* first element (the key) is not already present in the %map. */
1807 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
1809 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
1810 if ( nbElems != eId2smId.size() ) {
1811 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
1812 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
1815 // Store submesh IDs
1816 for ( int isNode = 0; isNode < 2; ++isNode )
1818 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
1819 if ( id2smId.empty() ) continue;
1820 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
1821 // make and fill array of submesh IDs
1822 int* smIDs = new int [ id2smId.size() ];
1823 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
1824 smIDs[ i ] = id_smId->second;
1826 aSize[ 0 ] = id2smId.size();
1827 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
1828 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
1829 aDataset->CreateOnDisk();
1830 aDataset->WriteOnDisk( smIDs );
1831 aDataset->CloseOnDisk();
1836 // Store node positions on sub-shapes (SMDS_Position):
1837 // ----------------------------------------------------
1839 aGroup = new HDFgroup( "Node Positions", aTopGroup );
1840 aGroup->CreateOnDisk();
1842 // in aGroup, create 5 datasets to contain:
1843 // "Nodes on Edges" - ID of node on edge
1844 // "Edge positions" - U parameter on node on edge
1845 // "Nodes on Faces" - ID of node on face
1846 // "Face U positions" - U parameter of node on face
1847 // "Face V positions" - V parameter of node on face
1849 // Find out nb of nodes on edges and faces
1850 // Collect corresponing sub-meshes
1851 int nbEdgeNodes = 0, nbFaceNodes = 0;
1852 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
1853 // loop on SMESHDS_SubMesh'es
1854 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
1856 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
1857 if ( aSubMesh->IsComplexSubmesh() )
1858 continue; // submesh containing other submeshs
1859 int nbNodes = aSubMesh->NbNodes();
1860 if ( nbNodes == 0 ) continue;
1862 int aShapeID = (*itSubM).first;
1863 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
1864 // write only SMDS_FacePosition and SMDS_EdgePosition
1865 switch ( aShapeType ) {
1867 nbFaceNodes += nbNodes;
1868 aFaceSM.push_back( aSubMesh );
1871 nbEdgeNodes += nbNodes;
1872 aEdgeSM.push_back( aSubMesh );
1878 // Treat positions on edges or faces
1879 for ( int onFace = 0; onFace < 2; onFace++ )
1881 // Create arrays to store in datasets
1882 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
1883 if (!nbNodes) continue;
1884 int* aNodeIDs = new int [ nbNodes ];
1885 double* aUPos = new double [ nbNodes ];
1886 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
1889 // loop on sub-meshes
1890 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
1891 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
1892 for ( ; itSM != pListSM->end(); itSM++ )
1894 SMESHDS_SubMesh* aSubMesh = (*itSM);
1896 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
1897 // loop on nodes in aSubMesh
1898 while ( itNode->more() )
1901 const SMDS_MeshNode* node = itNode->next();
1902 aNodeIDs [ iNode ] = node->GetID();
1905 const SMDS_PositionPtr pos = node->GetPosition();
1906 if ( onFace ) { // on FACE
1907 const SMDS_FacePosition* fPos =
1908 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
1910 aUPos[ iNode ] = fPos->GetUParameter();
1911 aVPos[ iNode ] = fPos->GetVParameter();
1918 const SMDS_EdgePosition* ePos =
1919 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
1921 aUPos[ iNode ] = ePos->GetUParameter();
1927 } // loop on nodes in aSubMesh
1928 } // loop on sub-meshes
1933 aSize[ 0 ] = nbNodes;
1935 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
1936 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
1937 aDataset->CreateOnDisk();
1938 aDataset->WriteOnDisk( aNodeIDs );
1939 aDataset->CloseOnDisk();
1942 aDSName = ( onFace ? "Face U positions" : "Edge positions");
1943 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
1944 aDataset->CreateOnDisk();
1945 aDataset->WriteOnDisk( aUPos );
1946 aDataset->CloseOnDisk();
1949 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
1950 aDataset->CreateOnDisk();
1951 aDataset->WriteOnDisk( aVPos );
1952 aDataset->CloseOnDisk();
1957 if ( aVPos ) delete [] aVPos;
1959 } // treat positions on edges or faces
1961 // close "Node Positions" group
1962 aGroup->CloseOnDisk();
1964 } // if ( there are submeshes in SMESHDS_Mesh )
1967 // close mesh HDF group
1968 aTopGroup->CloseOnDisk();
1976 aFile->CloseOnDisk();
1979 // Convert temporary files to stream
1980 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
1982 // Remove temporary files and directory
1984 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
1986 INFOS( "SMESH_Gen_i::Save() completed" );
1987 return aStreamFile._retn();
1990 //=============================================================================
1992 * SMESH_Gen_i::SaveASCII
1994 * Save SMESH module's data in ASCII format (not implemented yet)
1996 //=============================================================================
1998 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2000 bool isMultiFile ) {
2001 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2002 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2003 return aStreamFile._retn();
2006 //=============================================================================
2008 * SMESH_Gen_i::loadGeomData
2010 * Load GEOM module data
2012 //=============================================================================
2014 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2016 if ( theCompRoot->_is_nil() )
2019 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2020 if ( aStudy->_is_nil() )
2023 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2024 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2026 //=============================================================================
2028 * \brief Creates SMDS_Position according to shape type
2030 //=============================================================================
2032 class PositionCreator {
2034 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
2035 return (this->*myFuncTable[ type ])();
2038 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
2039 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
2040 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
2041 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
2044 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
2045 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
2046 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
2047 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
2048 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
2049 vector<FmakePos> myFuncTable;
2052 //=============================================================================
2056 * Load SMESH module's data
2058 //=============================================================================
2060 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2061 const SALOMEDS::TMPFile& theStream,
2065 INFOS( "SMESH_Gen_i::Load" );
2067 if ( myCurrentStudy->_is_nil() ||
2068 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2069 SetCurrentStudy( theComponent->GetStudy() );
2071 /* if( !theComponent->_is_nil() )
2073 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2074 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2075 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2078 StudyContext* myStudyContext = GetCurrentStudyContext();
2080 // Get temporary files location
2081 TCollection_AsciiString tmpDir =
2082 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2084 // Convert the stream into sequence of files to process
2085 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2088 TCollection_AsciiString aStudyName( "" );
2090 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2092 // Set names of temporary files
2093 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2094 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2098 HDFdataset* aDataset;
2099 HDFgroup* aTopGroup;
2101 HDFgroup* aSubGroup;
2102 HDFgroup* aSubSubGroup;
2105 // ---> open HDF file
2106 aFile = new HDFfile( filename.ToCString() );
2108 aFile->OpenOnDisk( HDF_RDONLY );
2110 catch ( HDFexception ) {
2111 INFOS( "Load(): " << filename << " not found!" );
2115 DriverMED_R_SMESHDS_Mesh myReader;
2116 myReader.SetFile( meshfile.ToCString() );
2118 // get total number of top-level groups
2119 int aNbGroups = aFile->nInternalObjects();
2120 if ( aNbGroups > 0 ) {
2121 // --> in first turn we should read&create hypotheses
2122 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2123 // open hypotheses root HDF group
2124 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2125 aTopGroup->OpenOnDisk();
2127 // get number of hypotheses
2128 int aNbObjects = aTopGroup->nInternalObjects();
2129 for ( int j = 0; j < aNbObjects; j++ ) {
2130 // try to identify hypothesis
2131 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2132 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2134 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2135 // open hypothesis group
2136 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2137 aGroup->OpenOnDisk();
2139 // --> get hypothesis id
2140 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2145 // get number of datasets
2146 int aNbSubObjects = aGroup->nInternalObjects();
2147 for ( int k = 0; k < aNbSubObjects; k++ ) {
2149 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2150 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2151 // --> get hypothesis name
2152 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2153 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2154 aDataset->OpenOnDisk();
2155 size = aDataset->GetSize();
2156 char* hypname_str = new char[ size ];
2157 aDataset->ReadFromDisk( hypname_str );
2158 hypname = string( hypname_str );
2159 delete [] hypname_str;
2160 aDataset->CloseOnDisk();
2162 // --> get hypothesis plugin library name
2163 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2164 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2165 aDataset->OpenOnDisk();
2166 size = aDataset->GetSize();
2167 char* libname_str = new char[ size ];
2168 aDataset->ReadFromDisk( libname_str );
2169 if(MYDEBUG) SCRUTE( libname_str );
2170 libname = string( libname_str );
2171 delete [] libname_str;
2172 aDataset->CloseOnDisk();
2174 // --> get hypothesis data
2175 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2176 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2177 aDataset->OpenOnDisk();
2178 size = aDataset->GetSize();
2179 char* hypdata_str = new char[ size ];
2180 aDataset->ReadFromDisk( hypdata_str );
2181 hypdata = string( hypdata_str );
2182 delete [] hypdata_str;
2183 aDataset->CloseOnDisk();
2186 // close hypothesis HDF group
2187 aGroup->CloseOnDisk();
2189 // --> restore hypothesis from data
2190 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2191 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2192 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2193 SMESH::SMESH_Hypothesis_var myHyp;
2195 try { // protect persistence mechanism against exceptions
2196 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2199 INFOS( "Exception during hypothesis creation" );
2202 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2204 myImpl->LoadFrom( hypdata.c_str() );
2205 string iorString = GetORB()->object_to_string( myHyp );
2206 int newId = myStudyContext->findId( iorString );
2207 myStudyContext->mapOldToNew( id, newId );
2210 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2214 // close hypotheses root HDF group
2215 aTopGroup->CloseOnDisk();
2218 // --> then we should read&create algorithms
2219 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2220 // open algorithms root HDF group
2221 aTopGroup = new HDFgroup( "Algorithms", aFile );
2222 aTopGroup->OpenOnDisk();
2224 // get number of algorithms
2225 int aNbObjects = aTopGroup->nInternalObjects();
2226 for ( int j = 0; j < aNbObjects; j++ ) {
2227 // try to identify algorithm
2228 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2229 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2231 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2232 // open algorithm group
2233 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2234 aGroup->OpenOnDisk();
2236 // --> get algorithm id
2237 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2242 // get number of datasets
2243 int aNbSubObjects = aGroup->nInternalObjects();
2244 for ( int k = 0; k < aNbSubObjects; k++ ) {
2246 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2247 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2248 // --> get algorithm name
2249 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2250 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2251 aDataset->OpenOnDisk();
2252 size = aDataset->GetSize();
2253 char* hypname_str = new char[ size ];
2254 aDataset->ReadFromDisk( hypname_str );
2255 hypname = string( hypname_str );
2256 delete [] hypname_str;
2257 aDataset->CloseOnDisk();
2259 // --> get algorithm plugin library name
2260 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2261 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2262 aDataset->OpenOnDisk();
2263 size = aDataset->GetSize();
2264 char* libname_str = new char[ size ];
2265 aDataset->ReadFromDisk( libname_str );
2266 if(MYDEBUG) SCRUTE( libname_str );
2267 libname = string( libname_str );
2268 delete [] libname_str;
2269 aDataset->CloseOnDisk();
2271 // --> get algorithm data
2272 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2273 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2274 aDataset->OpenOnDisk();
2275 size = aDataset->GetSize();
2276 char* hypdata_str = new char[ size ];
2277 aDataset->ReadFromDisk( hypdata_str );
2278 if(MYDEBUG) SCRUTE( hypdata_str );
2279 hypdata = string( hypdata_str );
2280 delete [] hypdata_str;
2281 aDataset->CloseOnDisk();
2284 // close algorithm HDF group
2285 aGroup->CloseOnDisk();
2287 // --> restore algorithm from data
2288 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2289 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2290 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2291 SMESH::SMESH_Hypothesis_var myHyp;
2293 try { // protect persistence mechanism against exceptions
2294 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2297 INFOS( "Exception during hypothesis creation" );
2300 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2302 myImpl->LoadFrom( hypdata.c_str() );
2303 string iorString = GetORB()->object_to_string( myHyp );
2304 int newId = myStudyContext->findId( iorString );
2305 myStudyContext->mapOldToNew( id, newId );
2308 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2312 // close algorithms root HDF group
2313 aTopGroup->CloseOnDisk();
2316 // --> the rest groups should be meshes
2317 for ( int i = 0; i < aNbGroups; i++ ) {
2318 // identify next group
2319 char meshName[ HDF_NAME_MAX_LEN+1 ];
2320 aFile->InternalObjectIndentify( i, meshName );
2322 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2324 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2328 bool hasData = false;
2330 // open mesh HDF group
2331 aTopGroup = new HDFgroup( meshName, aFile );
2332 aTopGroup->OpenOnDisk();
2334 // get number of child HDF objects
2335 int aNbObjects = aTopGroup->nInternalObjects();
2336 if ( aNbObjects > 0 ) {
2338 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2339 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2340 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2341 if ( !myNewMeshImpl )
2343 string iorString = GetORB()->object_to_string( myNewMesh );
2344 int newId = myStudyContext->findId( iorString );
2345 myStudyContext->mapOldToNew( id, newId );
2347 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2348 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2350 // try to find mesh data dataset
2351 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2352 // load mesh "has data" flag
2353 aDataset = new HDFdataset( "Has data", aTopGroup );
2354 aDataset->OpenOnDisk();
2355 size = aDataset->GetSize();
2356 char* strHasData = new char[ size ];
2357 aDataset->ReadFromDisk( strHasData );
2358 aDataset->CloseOnDisk();
2359 if ( strcmp( strHasData, "1") == 0 ) {
2360 // read mesh data from MED file
2361 myReader.SetMesh( mySMESHDSMesh );
2362 myReader.SetMeshId( id );
2368 // try to read and set reference to shape
2369 GEOM::GEOM_Object_var aShapeObject;
2370 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2371 // load mesh "Ref on shape" - it's an entry to SObject
2372 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2373 aDataset->OpenOnDisk();
2374 size = aDataset->GetSize();
2375 char* refFromFile = new char[ size ];
2376 aDataset->ReadFromDisk( refFromFile );
2377 aDataset->CloseOnDisk();
2378 if ( strlen( refFromFile ) > 0 ) {
2379 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2381 // Make sure GEOM data are loaded first
2382 //loadGeomData( shapeSO->GetFatherComponent() );
2384 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2385 if ( !CORBA::is_nil( shapeObject ) ) {
2386 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2387 if ( !aShapeObject->_is_nil() )
2388 myNewMeshImpl->SetShape( aShapeObject );
2393 // try to get applied algorithms
2394 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2395 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2396 aGroup->OpenOnDisk();
2397 // get number of applied algorithms
2398 int aNbSubObjects = aGroup->nInternalObjects();
2399 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2400 for ( int j = 0; j < aNbSubObjects; j++ ) {
2401 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2402 aGroup->InternalObjectIndentify( j, name_dataset );
2403 // check if it is an algorithm
2404 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2405 aDataset = new HDFdataset( name_dataset, aGroup );
2406 aDataset->OpenOnDisk();
2407 size = aDataset->GetSize();
2408 char* refFromFile = new char[ size ];
2409 aDataset->ReadFromDisk( refFromFile );
2410 aDataset->CloseOnDisk();
2412 // san - it is impossible to recover applied algorithms using their entries within Load() method
2414 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2415 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2416 int id = atoi( refFromFile );
2417 string anIOR = myStudyContext->getIORbyOldId( id );
2418 if ( !anIOR.empty() ) {
2419 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2420 if ( !CORBA::is_nil( hypObject ) ) {
2421 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2422 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2423 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2428 aGroup->CloseOnDisk();
2431 // try to get applied hypotheses
2432 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2433 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2434 aGroup->OpenOnDisk();
2435 // get number of applied hypotheses
2436 int aNbSubObjects = aGroup->nInternalObjects();
2437 for ( int j = 0; j < aNbSubObjects; j++ ) {
2438 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2439 aGroup->InternalObjectIndentify( j, name_dataset );
2440 // check if it is a hypothesis
2441 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2442 aDataset = new HDFdataset( name_dataset, aGroup );
2443 aDataset->OpenOnDisk();
2444 size = aDataset->GetSize();
2445 char* refFromFile = new char[ size ];
2446 aDataset->ReadFromDisk( refFromFile );
2447 aDataset->CloseOnDisk();
2449 // san - it is impossible to recover applied hypotheses using their entries within Load() method
2451 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2452 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2453 int id = atoi( refFromFile );
2454 string anIOR = myStudyContext->getIORbyOldId( id );
2455 if ( !anIOR.empty() ) {
2456 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2457 if ( !CORBA::is_nil( hypObject ) ) {
2458 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2459 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2460 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2465 aGroup->CloseOnDisk();
2468 // --> try to find submeshes containers for each type of submesh
2469 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
2470 char name_meshgroup[ 30 ];
2471 if ( j == GetSubMeshOnVertexTag() )
2472 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2473 else if ( j == GetSubMeshOnEdgeTag() )
2474 strcpy( name_meshgroup, "SubMeshes On Edge" );
2475 else if ( j == GetSubMeshOnWireTag() )
2476 strcpy( name_meshgroup, "SubMeshes On Wire" );
2477 else if ( j == GetSubMeshOnFaceTag() )
2478 strcpy( name_meshgroup, "SubMeshes On Face" );
2479 else if ( j == GetSubMeshOnShellTag() )
2480 strcpy( name_meshgroup, "SubMeshes On Shell" );
2481 else if ( j == GetSubMeshOnSolidTag() )
2482 strcpy( name_meshgroup, "SubMeshes On Solid" );
2483 else if ( j == GetSubMeshOnCompoundTag() )
2484 strcpy( name_meshgroup, "SubMeshes On Compound" );
2486 // try to get submeshes container HDF group
2487 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
2488 // open submeshes containers HDF group
2489 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2490 aGroup->OpenOnDisk();
2492 // get number of submeshes
2493 int aNbSubMeshes = aGroup->nInternalObjects();
2494 for ( int k = 0; k < aNbSubMeshes; k++ ) {
2496 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
2497 aGroup->InternalObjectIndentify( k, name_submeshgroup );
2498 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
2499 // --> get submesh id
2500 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
2503 // open submesh HDF group
2504 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
2505 aSubGroup->OpenOnDisk();
2507 // try to read and set reference to subshape
2508 GEOM::GEOM_Object_var aSubShapeObject;
2509 SMESH::SMESH_subMesh_var aSubMesh;
2511 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2512 // load submesh "Ref on shape" - it's an entry to SObject
2513 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2514 aDataset->OpenOnDisk();
2515 size = aDataset->GetSize();
2516 char* refFromFile = new char[ size ];
2517 aDataset->ReadFromDisk( refFromFile );
2518 aDataset->CloseOnDisk();
2519 if ( strlen( refFromFile ) > 0 ) {
2520 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2521 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2522 if ( !CORBA::is_nil( subShapeObject ) ) {
2523 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2524 if ( !aSubShapeObject->_is_nil() )
2525 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2526 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2527 if ( aSubMesh->_is_nil() )
2529 string iorSubString = GetORB()->object_to_string( aSubMesh );
2530 int newSubId = myStudyContext->findId( iorSubString );
2531 myStudyContext->mapOldToNew( subid, newSubId );
2536 if ( aSubMesh->_is_nil() )
2539 // VSR: Get submesh data from MED convertor
2540 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2541 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2542 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2543 // subid << " for subshape # " << anInternalSubmeshId);
2544 // SMESHDS_SubMesh* aSubMeshDS =
2545 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2546 // if ( !aSubMeshDS ) {
2547 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2548 // anInternalSubmeshId << " in current mesh!");
2551 // myReader.GetSubMesh( aSubMeshDS, subid );
2554 // try to get applied algorithms
2555 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2556 // open "applied algorithms" HDF group
2557 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2558 aSubSubGroup->OpenOnDisk();
2559 // get number of applied algorithms
2560 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2561 for ( int l = 0; l < aNbSubObjects; l++ ) {
2562 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2563 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2564 // check if it is an algorithm
2565 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2566 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2567 aDataset->OpenOnDisk();
2568 size = aDataset->GetSize();
2569 char* refFromFile = new char[ size ];
2570 aDataset->ReadFromDisk( refFromFile );
2571 aDataset->CloseOnDisk();
2573 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2574 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2575 int id = atoi( refFromFile );
2576 string anIOR = myStudyContext->getIORbyOldId( id );
2577 if ( !anIOR.empty() ) {
2578 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2579 if ( !CORBA::is_nil( hypObject ) ) {
2580 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2581 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2582 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2587 // close "applied algorithms" HDF group
2588 aSubSubGroup->CloseOnDisk();
2591 // try to get applied hypotheses
2592 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2593 // open "applied hypotheses" HDF group
2594 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2595 aSubSubGroup->OpenOnDisk();
2596 // get number of applied hypotheses
2597 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2598 for ( int l = 0; l < aNbSubObjects; l++ ) {
2599 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2600 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2601 // check if it is a hypothesis
2602 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2603 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2604 aDataset->OpenOnDisk();
2605 size = aDataset->GetSize();
2606 char* refFromFile = new char[ size ];
2607 aDataset->ReadFromDisk( refFromFile );
2608 aDataset->CloseOnDisk();
2610 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2611 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2612 int id = atoi( refFromFile );
2613 string anIOR = myStudyContext->getIORbyOldId( id );
2614 if ( !anIOR.empty() ) {
2615 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2616 if ( !CORBA::is_nil( hypObject ) ) {
2617 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2618 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2619 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2624 // close "applied hypotheses" HDF group
2625 aSubSubGroup->CloseOnDisk();
2628 // close submesh HDF group
2629 aSubGroup->CloseOnDisk();
2632 // close submeshes containers HDF group
2633 aGroup->CloseOnDisk();
2639 // Read sub-meshes from MED
2640 // -------------------------
2641 if(MYDEBUG) MESSAGE("Create all sub-meshes");
2642 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
2643 if ( submeshesInFamilies )
2645 // old way working before fix of PAL 12992
2646 myReader.CreateAllSubMeshes();
2651 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2652 aGroup->OpenOnDisk();
2654 int maxID = mySMESHDSMesh->MaxShapeIndex();
2655 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
2656 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
2658 PositionCreator aPositionCreator;
2660 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
2661 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
2662 for ( int isNode = 0; isNode < 2; ++isNode )
2664 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2665 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
2667 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
2668 aDataset->OpenOnDisk();
2669 // read submesh IDs for all elements sorted by ID
2670 int nbElems = aDataset->GetSize();
2671 int* smIDs = new int [ nbElems ];
2672 aDataset->ReadFromDisk( smIDs );
2673 aDataset->CloseOnDisk();
2675 // get elements sorted by ID
2676 ::SMESH_MeshEditor::TIDSortedElemSet elemSet;
2678 while ( nIt->more() ) elemSet.insert( nIt->next() );
2680 while ( eIt->more() ) elemSet.insert( eIt->next() );
2681 ASSERT( elemSet.size() == nbElems );
2683 // add elements to submeshes
2684 ::SMESH_MeshEditor::TIDSortedElemSet::iterator iE = elemSet.begin();
2685 for ( int i = 0; i < nbElems; ++i, ++iE )
2687 int smID = smIDs[ i ];
2688 if ( smID == 0 ) continue;
2689 ASSERT( smID <= maxID );
2690 const SMDS_MeshElement* elem = *iE;
2691 // get or create submesh
2692 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
2694 sm = mySMESHDSMesh->NewSubMesh( smID );
2695 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
2699 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
2700 pos->SetShapeId( smID );
2701 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
2702 node->SetPosition( pos );
2703 sm->AddNode( node );
2705 sm->AddElement( elem );
2711 } // end reading submeshes
2713 // Read node positions on sub-shapes (SMDS_Position)
2715 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
2717 // There are 5 datasets to read:
2718 // "Nodes on Edges" - ID of node on edge
2719 // "Edge positions" - U parameter on node on edge
2720 // "Nodes on Faces" - ID of node on face
2721 // "Face U positions" - U parameter of node on face
2722 // "Face V positions" - V parameter of node on face
2723 char* aEid_DSName = "Nodes on Edges";
2724 char* aEu_DSName = "Edge positions";
2725 char* aFu_DSName = "Face U positions";
2726 //char* aFid_DSName = "Nodes on Faces";
2727 //char* aFv_DSName = "Face V positions";
2730 int nbEids = 0, nbFids = 0;
2731 int *aEids = 0, *aFids = 0;
2732 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
2735 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2736 aGroup->OpenOnDisk();
2738 // loop on 5 data sets
2739 int aNbObjects = aGroup->nInternalObjects();
2740 for ( int i = 0; i < aNbObjects; i++ )
2743 char aDSName[ HDF_NAME_MAX_LEN+1 ];
2744 aGroup->InternalObjectIndentify( i, aDSName );
2746 aDataset = new HDFdataset( aDSName, aGroup );
2747 aDataset->OpenOnDisk();
2748 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
2750 double* pos = new double [ aDataset->GetSize() ];
2751 aDataset->ReadFromDisk( pos );
2753 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
2755 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
2762 int aSize = aDataset->GetSize();
2764 // for reading files, created from 18.07.2005 till 10.10.2005
2765 if (aDataset->GetType() == HDF_STRING)
2766 aSize /= sizeof(int);
2768 int* ids = new int [aSize];
2769 aDataset->ReadFromDisk( ids );
2770 // on face or nodes?
2771 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
2780 aDataset->CloseOnDisk();
2781 } // loop on 5 datasets
2783 // Set node positions on edges or faces
2784 for ( int onFace = 0; onFace < 2; onFace++ )
2786 int nbNodes = ( onFace ? nbFids : nbEids );
2787 if ( nbNodes == 0 ) continue;
2788 int* aNodeIDs = ( onFace ? aFids : aEids );
2789 double* aUPos = ( onFace ? aFupos : aEpos );
2790 double* aVPos = ( onFace ? aFvpos : 0 );
2792 for ( int iNode = 0; iNode < nbNodes; iNode++ )
2794 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
2796 SMDS_PositionPtr aPos = node->GetPosition();
2799 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
2800 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
2801 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
2802 fPos->SetUParameter( aUPos[ iNode ]);
2803 fPos->SetVParameter( aVPos[ iNode ]);
2806 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
2807 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
2808 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
2809 fPos->SetUParameter( aUPos[ iNode ]);
2813 if ( aEids ) delete [] aEids;
2814 if ( aFids ) delete [] aFids;
2815 if ( aEpos ) delete [] aEpos;
2816 if ( aFupos ) delete [] aFupos;
2817 if ( aFvpos ) delete [] aFvpos;
2819 aGroup->CloseOnDisk();
2821 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
2824 // Recompute State (as computed sub-meshes are restored from MED)
2825 if ( !aShapeObject->_is_nil() ) {
2826 MESSAGE("Compute State Engine ...");
2827 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
2828 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
2829 (SMESH_subMesh::SUBMESH_RESTORED);
2830 MESSAGE("Compute State Engine finished");
2833 // try to get groups
2834 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
2835 char name_group[ 30 ];
2836 if ( ii == GetNodeGroupsTag() )
2837 strcpy( name_group, "Groups of Nodes" );
2838 else if ( ii == GetEdgeGroupsTag() )
2839 strcpy( name_group, "Groups of Edges" );
2840 else if ( ii == GetFaceGroupsTag() )
2841 strcpy( name_group, "Groups of Faces" );
2842 else if ( ii == GetVolumeGroupsTag() )
2843 strcpy( name_group, "Groups of Volumes" );
2845 if ( aTopGroup->ExistInternalObject( name_group ) ) {
2846 aGroup = new HDFgroup( name_group, aTopGroup );
2847 aGroup->OpenOnDisk();
2848 // get number of groups
2849 int aNbSubObjects = aGroup->nInternalObjects();
2850 for ( int j = 0; j < aNbSubObjects; j++ ) {
2851 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2852 aGroup->InternalObjectIndentify( j, name_dataset );
2853 // check if it is an group
2854 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
2856 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
2859 aDataset = new HDFdataset( name_dataset, aGroup );
2860 aDataset->OpenOnDisk();
2862 // Retrieve actual group name
2863 size = aDataset->GetSize();
2864 char* nameFromFile = new char[ size ];
2865 aDataset->ReadFromDisk( nameFromFile );
2866 aDataset->CloseOnDisk();
2868 // Try to find a shape reference
2869 TopoDS_Shape aShape;
2870 char aRefName[ 30 ];
2871 sprintf( aRefName, "Ref on shape %d", subid);
2872 if ( aGroup->ExistInternalObject( aRefName ) ) {
2873 // load mesh "Ref on shape" - it's an entry to SObject
2874 aDataset = new HDFdataset( aRefName, aGroup );
2875 aDataset->OpenOnDisk();
2876 size = aDataset->GetSize();
2877 char* refFromFile = new char[ size ];
2878 aDataset->ReadFromDisk( refFromFile );
2879 aDataset->CloseOnDisk();
2880 if ( strlen( refFromFile ) > 0 ) {
2881 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2882 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2883 if ( !CORBA::is_nil( shapeObject ) ) {
2884 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2885 if ( !aShapeObject->_is_nil() )
2886 aShape = GeomObjectToShape( aShapeObject );
2890 // Create group servant
2891 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
2892 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
2893 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
2894 // Obtain a SMESHDS_Group object
2895 if ( aNewGroup->_is_nil() )
2898 string iorSubString = GetORB()->object_to_string( aNewGroup );
2899 int newSubId = myStudyContext->findId( iorSubString );
2900 myStudyContext->mapOldToNew( subid, newSubId );
2902 SMESH_GroupBase_i* aGroupImpl =
2903 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
2907 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
2911 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
2912 aGroupBaseDS->SetStoreName( name_dataset );
2914 // Fill group with contents from MED file
2915 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
2917 myReader.GetGroup( aGrp );
2920 aGroup->CloseOnDisk();
2925 aTopGroup->CloseOnDisk();
2930 aFile->CloseOnDisk();
2933 // Remove temporary files created from the stream
2935 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2937 INFOS( "SMESH_Gen_i::Load completed" );
2941 //=============================================================================
2943 * SMESH_Gen_i::LoadASCII
2945 * Load SMESH module's data in ASCII format (not implemented yet)
2947 //=============================================================================
2949 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
2950 const SALOMEDS::TMPFile& theStream,
2952 bool isMultiFile ) {
2953 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
2954 return Load( theComponent, theStream, theURL, isMultiFile );
2957 //=============================================================================
2959 * SMESH_Gen_i::Close
2961 * Clears study-connected data when it is closed
2963 //=============================================================================
2965 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
2967 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
2969 // Clear study contexts data
2970 int studyId = GetCurrentStudyID();
2971 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
2972 delete myStudyContextMap[ studyId ];
2973 myStudyContextMap.erase( studyId );
2978 //=============================================================================
2980 * SMESH_Gen_i::ComponentDataType
2982 * Get component data type
2984 //=============================================================================
2986 char* SMESH_Gen_i::ComponentDataType()
2988 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
2989 return CORBA::string_dup( "SMESH" );
2993 //=============================================================================
2995 * SMESH_Gen_i::IORToLocalPersistentID
2997 * Transform data from transient form to persistent
2999 //=============================================================================
3001 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
3002 const char* IORString,
3003 CORBA::Boolean /*isMultiFile*/,
3004 CORBA::Boolean /*isASCII*/ )
3006 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
3007 StudyContext* myStudyContext = GetCurrentStudyContext();
3009 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
3010 int anId = myStudyContext->findId( IORString );
3012 if(MYDEBUG) MESSAGE( "VSR " << anId )
3014 sprintf( strId, "%d", anId );
3015 return CORBA::string_dup( strId );
3018 return CORBA::string_dup( "" );
3021 //=============================================================================
3023 * SMESH_Gen_i::LocalPersistentIDToIOR
3025 * Transform data from persistent form to transient
3027 //=============================================================================
3029 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
3030 const char* aLocalPersistentID,
3031 CORBA::Boolean /*isMultiFile*/,
3032 CORBA::Boolean /*isASCII*/ )
3034 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
3035 StudyContext* myStudyContext = GetCurrentStudyContext();
3037 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
3038 int anId = atoi( aLocalPersistentID );
3039 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
3041 return CORBA::string_dup( "" );
3044 //=======================================================================
3045 //function : RegisterObject
3047 //=======================================================================
3049 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
3051 StudyContext* myStudyContext = GetCurrentStudyContext();
3052 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3053 string iorString = GetORB()->object_to_string( theObject );
3054 return myStudyContext->addObject( iorString );
3059 //=============================================================================
3061 * SMESHEngine_factory
3063 * C factory, accessible with dlsym, after dlopen
3065 //=============================================================================
3069 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3070 PortableServer::POA_ptr poa,
3071 PortableServer::ObjectId* contId,
3072 const char* instanceName,
3073 const char* interfaceName )
3075 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3076 if(MYDEBUG) SCRUTE(interfaceName);
3077 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3078 return aSMESHGen->getId() ;