1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Gen_i.cxx
25 // Author : Paul RASCLE, EDF
30 #include <TopExp_Explorer.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <TopoDS_CompSolid.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopTools_MapOfShape.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
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"
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_Filter)
81 #include "DriverMED_W_SMESHDS_Mesh.h"
82 #include "DriverMED_R_SMESHDS_Mesh.h"
84 #include "SALOMEDS_Tool.hxx"
85 #include "SALOME_NamingService.hxx"
86 #include "SALOME_LifeCycleCORBA.hxx"
87 #include "Utils_SINGLETON.hxx"
90 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
92 #include "GEOM_Client.hxx"
93 #include "Utils_ExceptHandlers.hxx"
98 using SMESH::TPythonDump;
100 #define NUM_TMP_FILES 2
103 static int MYDEBUG = 1;
105 static int MYDEBUG = 0;
108 // Static variables definition
109 CORBA::ORB_var SMESH_Gen_i::myOrb;
110 PortableServer::POA_var SMESH_Gen_i::myPoa;
111 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
112 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
113 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
115 //=============================================================================
117 * GetServant [ static ]
119 * Get servant of the CORBA object
121 //=============================================================================
123 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
125 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
128 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
132 INFOS( "GetServant - Unknown exception was caught!!!" );
137 //=============================================================================
139 * SObjectToObject [ static ]
141 * Get CORBA object corresponding to the SALOMEDS::SObject
143 //=============================================================================
145 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
147 SALOMEDS::GenericAttribute_var anAttr;
148 CORBA::Object_var anObj;
149 if ( !theSObject->_is_nil() ) {
151 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
152 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
153 CORBA::String_var aValue = anIOR->Value();
154 if( strcmp( aValue, "" ) != 0 )
155 anObj = GetORB()->string_to_object( aValue );
159 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
165 //=============================================================================
169 * Get SALOME_NamingService object
171 //=============================================================================
173 SALOME_NamingService* SMESH_Gen_i::GetNS()
175 if ( myNS == NULL ) {
176 myNS = SINGLETON_<SALOME_NamingService>::Instance();
177 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
178 myNS->init_orb( GetORB() );
183 //=============================================================================
187 * Get SALOME_LifeCycleCORBA object
189 //=============================================================================
190 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
191 if ( myLCC == NULL ) {
192 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
198 //=============================================================================
200 * GetGeomEngine [ static ]
202 * Get GEOM::GEOM_Gen reference
204 //=============================================================================
205 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
206 GEOM::GEOM_Gen_var aGeomEngine =
207 GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
208 return aGeomEngine._retn();
211 //=============================================================================
213 * SMESH_Gen_i::SMESH_Gen_i
215 * Default constructor: not for use
217 //=============================================================================
219 SMESH_Gen_i::SMESH_Gen_i()
221 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
224 //=============================================================================
226 * SMESH_Gen_i::SMESH_Gen_i
228 * Standard constructor, used with Container
230 //=============================================================================
232 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
233 PortableServer::POA_ptr poa,
234 PortableServer::ObjectId* contId,
235 const char* instanceName,
236 const char* interfaceName )
237 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
239 INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
241 myOrb = CORBA::ORB::_duplicate(orb);
242 myPoa = PortableServer::POA::_duplicate(poa);
245 _id = myPoa->activate_object( _thisObj );
247 myIsEmbeddedMode = false;
248 myShapeReader = NULL; // shape reader
251 OSD::SetSignal( true );
254 //=============================================================================
256 * SMESH_Gen_i::~SMESH_Gen_i
260 //=============================================================================
262 SMESH_Gen_i::~SMESH_Gen_i()
264 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
266 // delete hypothesis creators
267 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
268 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
270 delete (*itHyp).second;
272 myHypCreatorMap.clear();
274 // Clear study contexts data
275 map<int, StudyContext*>::iterator it;
276 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
279 myStudyContextMap.clear();
280 // delete shape reader
281 if ( !myShapeReader )
282 delete myShapeReader;
285 //=============================================================================
287 * SMESH_Gen_i::createHypothesis
289 * Create hypothesis of given type
291 //=============================================================================
292 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
293 const char* theLibName)
294 throw (SALOME::SALOME_Exception)
296 Unexpect aCatch(SALOME_SalomeException);
297 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
299 // create a new hypothesis object servant
300 SMESH_Hypothesis_i* myHypothesis_i = 0;
301 SMESH::SMESH_Hypothesis_var hypothesis_i;
305 // check, if creator for this hypothesis type already exists
306 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
308 // load plugin library
309 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
310 void* libHandle = dlopen (theLibName, RTLD_LAZY);
313 // report any error, if occured
314 const char* anError = dlerror();
315 throw(SALOME_Exception(anError));
318 // get method, returning hypothesis creator
319 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
320 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
321 GetHypothesisCreator procHandle =
322 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
325 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
329 // get hypothesis creator
330 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
331 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
334 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
337 // map hypothesis creator to a hypothesis name
338 myHypCreatorMap[string(theHypName)] = aCreator;
341 // create a new hypothesis object, store its ref. in studyContext
342 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
344 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
345 // _CS_gbo Explicit activation (no longer made in the constructor).
346 myHypothesis_i->Activate();
347 myHypothesis_i->SetLibName(theLibName); // for persistency assurance
349 catch (SALOME_Exception& S_ex)
351 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
355 return hypothesis_i._retn();
357 // activate the CORBA servant of hypothesis
358 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
359 int nextId = RegisterObject( hypothesis_i );
360 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
362 return hypothesis_i._retn();
365 //=============================================================================
367 * SMESH_Gen_i::createMesh
369 * Create empty mesh on shape
371 //=============================================================================
372 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
373 throw ( SALOME::SALOME_Exception )
375 Unexpect aCatch(SALOME_SalomeException);
376 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
378 // Get or create the GEOM_Client instance
380 // create a new mesh object servant, store it in a map in study context
381 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
382 // create a new mesh object
383 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
385 // activate the CORBA servant of Mesh
386 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
387 int nextId = RegisterObject( mesh );
388 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
391 catch (SALOME_Exception& S_ex) {
392 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
394 return SMESH::SMESH_Mesh::_nil();
397 //=============================================================================
399 * SMESH_Gen_i::GetShapeReader
403 //=============================================================================
404 GEOM_Client* SMESH_Gen_i::GetShapeReader()
406 // create shape reader if necessary
407 if ( !myShapeReader )
408 myShapeReader = new GEOM_Client(GetContainerRef());
409 ASSERT( myShapeReader );
410 return myShapeReader;
413 //=============================================================================
415 * SMESH_Gen_i::SetEmbeddedMode
419 //=============================================================================
421 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
423 myIsEmbeddedMode = theMode;
426 //=============================================================================
428 * SMESH_Gen_i::IsEmbeddedMode
432 //=============================================================================
434 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
436 return myIsEmbeddedMode;
439 //=============================================================================
441 * SMESH_Gen_i::SetCurrentStudy
445 //=============================================================================
447 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
450 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
451 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
452 // create study context, if it doesn't exist and set current study
453 int studyId = GetCurrentStudyID();
454 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
455 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
456 myStudyContextMap[ studyId ] = new StudyContext;
459 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
460 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
461 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
463 // set current study for geom engine
464 //if ( !CORBA::is_nil( GetGeomEngine() ) )
465 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
468 //=============================================================================
470 * SMESH_Gen_i::GetCurrentStudy
474 //=============================================================================
476 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
478 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
479 return SALOMEDS::Study::_duplicate( myCurrentStudy );
482 //=============================================================================
484 * SMESH_Gen_i::GetCurrentStudyContext
486 * Get current study context
488 //=============================================================================
489 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
491 if ( !CORBA::is_nil( myCurrentStudy ) &&
492 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
493 return myStudyContextMap[ myCurrentStudy->StudyId() ];
498 //=============================================================================
500 * SMESH_Gen_i::CreateHypothesis
502 * Create hypothesis/algorothm of given type and publish it in the study
504 //=============================================================================
506 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
507 const char* theLibName )
508 throw ( SALOME::SALOME_Exception )
510 Unexpect aCatch(SALOME_SalomeException);
511 // Create hypothesis/algorithm
512 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
514 // Publish hypothesis/algorithm in the study
515 if ( CanPublishInStudy( hyp ) ) {
516 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
517 if ( !aSO->_is_nil() ) {
518 // Update Python script
519 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
520 << theHypName << "', '" << theLibName << "')";
527 //================================================================================
529 * \brief Return hypothesis of given type holding parameter values of the existing mesh
530 * \param theHypType - hypothesis type name
531 * \param theLibName - plugin library name
532 * \param theMesh - The mesh of interest
533 * \param theGeom - The shape to get parameter values from
534 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
535 * in a study and used to compute the mesh, or a temporary one created just to pass
538 //================================================================================
540 SMESH::SMESH_Hypothesis_ptr
541 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
542 const char* theLibName,
543 SMESH::SMESH_Mesh_ptr theMesh,
544 GEOM::GEOM_Object_ptr theGeom)
545 throw ( SALOME::SALOME_Exception )
547 Unexpect aCatch(SALOME_SalomeException);
548 if ( CORBA::is_nil( theMesh ) )
549 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
550 if ( CORBA::is_nil( theGeom ) )
551 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
553 // -----------------------------------------------
554 // find hypothesis used to mesh theGeom
555 // -----------------------------------------------
557 // get mesh and shape
558 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
559 TopoDS_Shape shape = GeomObjectToShape( theGeom );
560 if ( !meshServant || shape.IsNull() )
561 return SMESH::SMESH_Hypothesis::_nil();
562 ::SMESH_Mesh& mesh = meshServant->GetImpl();
564 if ( mesh.NbNodes() == 0 ) // empty mesh
565 return SMESH::SMESH_Hypothesis::_nil();
567 // create a temporary hypothesis to know its dimention
568 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
569 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
571 return SMESH::SMESH_Hypothesis::_nil();
572 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
574 // look for a hypothesis of theHypType used to mesh the shape
575 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
578 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
579 int nbLocalHyps = aHypList->length();
580 for ( int i = 0; i < nbLocalHyps; i++ )
581 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
582 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
583 // check super shapes
584 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
585 while ( nbLocalHyps == 0 && itShape.More() ) {
586 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
587 if ( ! CORBA::is_nil( geomObj )) {
588 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
589 nbLocalHyps = aHypList->length();
590 for ( int i = 0; i < nbLocalHyps; i++ )
591 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
592 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
598 // let the temporary hypothesis find out some how parameter values
599 if ( hyp->SetParametersByMesh( &mesh, shape ))
600 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
602 return SMESH::SMESH_Hypothesis::_nil();
605 //=============================================================================
607 * SMESH_Gen_i::CreateMesh
609 * Create empty mesh on a shape and publish it in the study
611 //=============================================================================
613 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
614 throw ( SALOME::SALOME_Exception )
616 Unexpect aCatch(SALOME_SalomeException);
617 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
619 SMESH::SMESH_Mesh_var mesh = this->createMesh();
621 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
622 ASSERT( meshServant );
623 meshServant->SetShape( theShapeObject );
625 // publish mesh in the study
626 if ( CanPublishInStudy( mesh ) ) {
627 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
628 aStudyBuilder->NewCommand(); // There is a transaction
629 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
630 aStudyBuilder->CommitCommand();
631 if ( !aSO->_is_nil() ) {
632 // Update Python script
633 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
640 //=============================================================================
642 * SMESH_Gen_i::CreateEmptyMesh
646 //=============================================================================
648 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
649 throw ( SALOME::SALOME_Exception )
651 Unexpect aCatch(SALOME_SalomeException);
652 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
654 SMESH::SMESH_Mesh_var mesh = this->createMesh();
656 // publish mesh in the study
657 if ( CanPublishInStudy( mesh ) ) {
658 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
659 aStudyBuilder->NewCommand(); // There is a transaction
660 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
661 aStudyBuilder->CommitCommand();
662 if ( !aSO->_is_nil() ) {
663 // Update Python script
664 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
671 //=============================================================================
673 * SMESH_Gen_i::CreateMeshFromUNV
675 * Create mesh and import data from UNV file
677 //=============================================================================
679 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
680 throw ( SALOME::SALOME_Exception )
682 Unexpect aCatch(SALOME_SalomeException);
683 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
685 SMESH::SMESH_Mesh_var aMesh = createMesh();
687 // publish mesh in the study
688 if ( CanPublishInStudy( aMesh ) ) {
689 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
690 aStudyBuilder->NewCommand(); // There is a transaction
691 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
692 aStudyBuilder->CommitCommand();
693 if ( !aSO->_is_nil() ) {
694 // Update Python script
695 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
699 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
701 aServant->ImportUNVFile( theFileName );
703 // Dump creation of groups
704 aServant->GetGroups();
706 return aMesh._retn();
709 //=============================================================================
711 * SMESH_Gen_i::CreateMeshFromMED
713 * Create mesh and import data from MED file
715 //=============================================================================
717 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
718 SMESH::DriverMED_ReadStatus& theStatus)
719 throw ( SALOME::SALOME_Exception )
721 Unexpect aCatch(SALOME_SalomeException);
722 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
724 // Retrieve mesh names from the file
725 DriverMED_R_SMESHDS_Mesh myReader;
726 myReader.SetFile( theFileName );
727 myReader.SetMeshId( -1 );
728 Driver_Mesh::Status aStatus;
729 list<string> aNames = myReader.GetMeshNames(aStatus);
730 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
731 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
733 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
736 TPythonDump aPythonDump;
738 //TCollection_AsciiString aStr ("([");
740 if (theStatus == SMESH::DRS_OK) {
741 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
742 aStudyBuilder->NewCommand(); // There is a transaction
743 aResult->length( aNames.size() );
746 // Iterate through all meshes and create mesh objects
747 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
749 //if (i > 0) aStr += ", ";
750 if (i > 0) aPythonDump << ", ";
753 SMESH::SMESH_Mesh_var mesh = createMesh();
755 // publish mesh in the study
756 SALOMEDS::SObject_var aSO;
757 if ( CanPublishInStudy( mesh ) )
758 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
759 if ( !aSO->_is_nil() ) {
762 //aStr += aSO->GetID();
765 aPythonDump << "mesh_" << i;
767 // aStr += TCollection_AsciiString(i);
770 // Read mesh data (groups are published automatically by ImportMEDFile())
771 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
772 ASSERT( meshServant );
773 SMESH::DriverMED_ReadStatus status1 =
774 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
775 if (status1 > theStatus)
778 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
780 aStudyBuilder->CommitCommand();
783 // Update Python script
784 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
786 // Dump creation of groups
787 for ( int i = 0; i < aResult->length(); ++i )
788 aResult[ i ]->GetGroups();
790 return aResult._retn();
793 //=============================================================================
795 * SMESH_Gen_i::CreateMeshFromSTL
797 * Create mesh and import data from STL file
799 //=============================================================================
801 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
802 throw ( SALOME::SALOME_Exception )
804 Unexpect aCatch(SALOME_SalomeException);
805 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
807 SMESH::SMESH_Mesh_var aMesh = createMesh();
809 // publish mesh in the study
810 if ( CanPublishInStudy( aMesh ) ) {
811 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
812 aStudyBuilder->NewCommand(); // There is a transaction
813 SALOMEDS::SObject_var aSO = PublishInStudy
814 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
815 aStudyBuilder->CommitCommand();
816 if ( !aSO->_is_nil() ) {
817 // Update Python script
818 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
822 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
824 aServant->ImportSTLFile( theFileName );
825 return aMesh._retn();
828 //=============================================================================
830 * SMESH_Gen_i::IsReadyToCompute
832 * Returns true if mesh contains enough data to be computed
834 //=============================================================================
836 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
837 GEOM::GEOM_Object_ptr theShapeObject )
838 throw ( SALOME::SALOME_Exception )
840 Unexpect aCatch(SALOME_SalomeException);
841 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
843 if ( CORBA::is_nil( theShapeObject ) )
844 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
847 if ( CORBA::is_nil( theMesh ) )
848 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
853 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
854 ASSERT( meshServant );
856 // get local TopoDS_Shape
857 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
858 // call implementation
859 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
860 return myGen.CheckAlgoState( myLocMesh, myLocShape );
863 catch ( SALOME_Exception& S_ex ) {
864 INFOS( "catch exception "<< S_ex.what() );
869 //================================================================================
871 * \brief Returns errors of hypotheses definintion
872 * \param theMesh - the mesh
873 * \param theSubObject - the main or sub- shape
874 * \retval SMESH::algo_error_array* - sequence of errors
876 //================================================================================
878 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
879 GEOM::GEOM_Object_ptr theSubObject )
880 throw ( SALOME::SALOME_Exception )
882 Unexpect aCatch(SALOME_SalomeException);
883 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
885 if ( CORBA::is_nil( theSubObject ) )
886 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
888 if ( CORBA::is_nil( theMesh ) )
889 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
891 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
893 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
894 ASSERT( meshServant );
896 TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
897 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
898 list< ::SMESH_Gen::TAlgoStateError > error_list;
899 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
900 // call ::SMESH_Gen::GetAlgoState()
901 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
902 error_array->length( error_list.size() );
904 for ( error = error_list.begin(); error != error_list.end(); ++error )
907 SMESH::AlgoStateErrorName errName;
908 switch ( error->_name ) {
909 case ::SMESH_Gen::MISSING_ALGO: errName = SMESH::MISSING_ALGO; break;
910 case ::SMESH_Gen::MISSING_HYPO: errName = SMESH::MISSING_HYPO; break;
911 case ::SMESH_Gen::NOT_CONFORM_MESH: errName = SMESH::NOT_CONFORM_MESH; break;
913 THROW_SALOME_CORBA_EXCEPTION( "bad error name",SALOME::BAD_PARAM );
916 CORBA::String_var algoName;
917 if ( error->_algo ) {
918 if ( !myCurrentStudy->_is_nil() ) {
919 // find algo in the study
920 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
921 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
922 if ( !father->_is_nil() ) {
923 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
924 for ( ; itBig->More(); itBig->Next() ) {
925 SALOMEDS::SObject_var gotBranch = itBig->Value();
926 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
927 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
928 for ( ; algoIt->More(); algoIt->Next() ) {
929 SALOMEDS::SObject_var algoSO = algoIt->Value();
930 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
931 if ( !CORBA::is_nil( algoIOR )) {
932 SMESH_Hypothesis_i* myImpl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
933 if ( myImpl && myImpl->GetImpl() == error->_algo ) {
934 algoName = algoSO->GetName();
938 } // loop on algo SO's
941 } // SMESH component iterator
944 if ( algoName.in() == 0 )
945 // use algo type name
946 algoName = CORBA::string_dup( error->_algo->GetName() );
948 // fill AlgoStateError structure
949 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
950 errStruct.name = errName;
951 errStruct.algoName = algoName;
952 errStruct.algoDim = error->_algoDim;
953 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
957 catch ( SALOME_Exception& S_ex ) {
958 INFOS( "catch exception "<< S_ex.what() );
960 return error_array._retn();
963 //=============================================================================
965 * SMESH_Gen_i::GetSubShapesId
967 * Get sub-shapes unique ID's list
969 //=============================================================================
971 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
972 const SMESH::object_array& theListOfSubShapeObject )
973 throw ( SALOME::SALOME_Exception )
975 Unexpect aCatch(SALOME_SalomeException);
976 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
978 SMESH::long_array_var shapesId = new SMESH::long_array;
981 if ( CORBA::is_nil( theMainShapeObject ) )
982 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
987 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
988 TopTools_IndexedMapOfShape myIndexToShape;
989 TopExp::MapShapes(myMainShape,myIndexToShape);
991 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
993 GEOM::GEOM_Object_var aShapeObject
994 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
995 if ( CORBA::is_nil( aShapeObject ) )
996 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
999 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1000 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1002 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1003 setId.insert(myIndexToShape.FindIndex(F));
1004 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1006 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1008 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1009 setId.insert(myIndexToShape.FindIndex(E));
1010 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1012 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1014 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1015 setId.insert(myIndexToShape.FindIndex(V));
1016 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1019 shapesId->length(setId.size());
1020 set<int>::iterator iind;
1022 for (iind = setId.begin(); iind != setId.end(); iind++)
1024 if(MYDEBUG) SCRUTE((*iind));
1025 shapesId[i] = (*iind);
1026 if(MYDEBUG) SCRUTE(shapesId[i]);
1030 catch (SALOME_Exception& S_ex)
1032 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1035 return shapesId._retn();
1038 //=============================================================================
1040 * SMESH_Gen_i::Compute
1042 * Compute mesh on a shape
1044 //=============================================================================
1046 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1047 GEOM::GEOM_Object_ptr theShapeObject )
1048 throw ( SALOME::SALOME_Exception )
1050 Unexpect aCatch(SALOME_SalomeException);
1051 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1053 if ( CORBA::is_nil( theShapeObject ) )
1054 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1055 SALOME::BAD_PARAM );
1057 if ( CORBA::is_nil( theMesh ) )
1058 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1059 SALOME::BAD_PARAM );
1061 // Update Python script
1062 TPythonDump() << "isDone = " << this << ".Compute( "
1063 << theMesh << ", " << theShapeObject << ")";
1064 TPythonDump() << "if not isDone: print 'Mesh " << theMesh << " : computation failed'";
1068 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1069 ASSERT( meshServant );
1070 if ( meshServant ) {
1071 // get local TopoDS_Shape
1072 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1073 // call implementation compute
1074 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1075 return myGen.Compute( myLocMesh, myLocShape);
1078 catch ( SALOME_Exception& S_ex ) {
1079 INFOS( "Compute(): catch exception "<< S_ex.what() );
1082 INFOS( "Compute(): unknown exception " );
1087 //================================================================================
1089 * \brief Return geometrical object the given element is built on
1090 * \param theMesh - the mesh the element is in
1091 * \param theElementID - the element ID
1092 * \param theGeomName - the name of the result geom object if it is not yet published
1093 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1095 //================================================================================
1097 GEOM::GEOM_Object_ptr
1098 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1099 CORBA::Long theElementID,
1100 const char* theGeomName)
1101 throw ( SALOME::SALOME_Exception )
1103 Unexpect aCatch(SALOME_SalomeException);
1104 if ( CORBA::is_nil( theMesh ) )
1105 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1107 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1108 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1110 // get a core mesh DS
1111 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1112 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1114 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1115 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1116 // find the element in mesh
1117 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
1118 // find a shape id by the element
1119 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1120 // get a geom object by the shape id
1121 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1122 if ( geom->_is_nil() ) {
1123 GEOM::GEOM_IShapesOperations_var op =
1124 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1125 if ( !op->_is_nil() )
1126 geom = op->GetSubShape( mainShape, shapeID );
1128 if ( !geom->_is_nil() ) {
1129 // try to find the corresponding SObject
1130 GeomObjectToShape( geom ); // geom client remembers the found shape
1131 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1132 if ( SObj->_is_nil() )
1133 // publish a new subshape
1134 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1135 // return only published geometry
1136 if ( !SObj->_is_nil() )
1137 return geom._retn();
1141 return GEOM::GEOM_Object::_nil();
1144 //=============================================================================
1148 * Save SMESH module's data
1150 //=============================================================================
1151 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1155 INFOS( "SMESH_Gen_i::Save" );
1157 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1158 // san -- in case <myCurrentStudy> differs from theComponent's study,
1159 // use that of the component
1160 if ( myCurrentStudy->_is_nil() ||
1161 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1162 SetCurrentStudy( theComponent->GetStudy() );
1164 // Store study contents as a set of python commands
1165 SavePython(myCurrentStudy);
1167 StudyContext* myStudyContext = GetCurrentStudyContext();
1169 // Declare a byte stream
1170 SALOMEDS::TMPFile_var aStreamFile;
1172 // Obtain a temporary dir
1173 TCollection_AsciiString tmpDir =
1174 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1176 // Create a sequence of files processed
1177 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1178 aFileSeq->length( NUM_TMP_FILES );
1180 TCollection_AsciiString aStudyName( "" );
1182 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1184 // Set names of temporary files
1185 TCollection_AsciiString filename =
1186 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1187 TCollection_AsciiString meshfile =
1188 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1189 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1190 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1191 filename = tmpDir + filename;
1192 meshfile = tmpDir + meshfile;
1195 HDFdataset* aDataset;
1196 HDFgroup* aTopGroup;
1198 HDFgroup* aSubGroup;
1199 HDFgroup* aSubSubGroup;
1200 hdf_size aSize[ 1 ];
1203 //Remove the files if they exist: BugID: 11225
1204 TCollection_AsciiString cmd("rm -f \"");
1209 system(cmd.ToCString());
1211 // MED writer to be used by storage process
1212 DriverMED_W_SMESHDS_Mesh myWriter;
1213 myWriter.SetFile( meshfile.ToCString() );
1216 // ---> create HDF file
1217 aFile = new HDFfile( filename.ToCString() );
1218 aFile->CreateOnDisk();
1220 // --> iterator for top-level objects
1221 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1222 for ( ; itBig->More(); itBig->Next() ) {
1223 SALOMEDS::SObject_var gotBranch = itBig->Value();
1225 // --> hypotheses root branch (only one for the study)
1226 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1227 // create hypotheses root HDF group
1228 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1229 aTopGroup->CreateOnDisk();
1231 // iterator for all hypotheses
1232 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1233 for ( ; it->More(); it->Next() ) {
1234 SALOMEDS::SObject_var mySObject = it->Value();
1235 CORBA::Object_var anObject = SObjectToObject( mySObject );
1236 if ( !CORBA::is_nil( anObject ) ) {
1237 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1238 if ( !myHyp->_is_nil() ) {
1239 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1241 string hypname = string( myHyp->GetName() );
1242 string libname = string( myHyp->GetLibName() );
1243 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1244 string hypdata = string( myImpl->SaveTo() );
1246 // for each hypothesis create HDF group basing on its id
1247 char hypGrpName[30];
1248 sprintf( hypGrpName, "Hypothesis %d", id );
1249 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1250 aGroup->CreateOnDisk();
1251 // --> type name of hypothesis
1252 aSize[ 0 ] = hypname.length() + 1;
1253 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1254 aDataset->CreateOnDisk();
1255 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1256 aDataset->CloseOnDisk();
1257 // --> server plugin library name of hypothesis
1258 aSize[ 0 ] = libname.length() + 1;
1259 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1260 aDataset->CreateOnDisk();
1261 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1262 aDataset->CloseOnDisk();
1263 // --> persistent data of hypothesis
1264 aSize[ 0 ] = hypdata.length() + 1;
1265 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1266 aDataset->CreateOnDisk();
1267 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1268 aDataset->CloseOnDisk();
1269 // close hypothesis HDF group
1270 aGroup->CloseOnDisk();
1275 // close hypotheses root HDF group
1276 aTopGroup->CloseOnDisk();
1278 // --> algorithms root branch (only one for the study)
1279 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1280 // create algorithms root HDF group
1281 aTopGroup = new HDFgroup( "Algorithms", aFile );
1282 aTopGroup->CreateOnDisk();
1284 // iterator for all algorithms
1285 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1286 for ( ; it->More(); it->Next() ) {
1287 SALOMEDS::SObject_var mySObject = it->Value();
1288 CORBA::Object_var anObject = SObjectToObject( mySObject );
1289 if ( !CORBA::is_nil( anObject ) ) {
1290 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1291 if ( !myHyp->_is_nil() ) {
1292 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1294 string hypname = string( myHyp->GetName() );
1295 string libname = string( myHyp->GetLibName() );
1296 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1297 string hypdata = string( myImpl->SaveTo() );
1299 // for each algorithm create HDF group basing on its id
1300 char hypGrpName[30];
1301 sprintf( hypGrpName, "Algorithm %d", id );
1302 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1303 aGroup->CreateOnDisk();
1304 // --> type name of algorithm
1305 aSize[0] = hypname.length() + 1;
1306 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1307 aDataset->CreateOnDisk();
1308 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1309 aDataset->CloseOnDisk();
1310 // --> server plugin library name of hypothesis
1311 aSize[0] = libname.length() + 1;
1312 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1313 aDataset->CreateOnDisk();
1314 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1315 aDataset->CloseOnDisk();
1316 // --> persistent data of algorithm
1317 aSize[0] = hypdata.length() + 1;
1318 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1319 aDataset->CreateOnDisk();
1320 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1321 aDataset->CloseOnDisk();
1322 // close algorithm HDF group
1323 aGroup->CloseOnDisk();
1328 // close algorithms root HDF group
1329 aTopGroup->CloseOnDisk();
1331 // --> mesh objects roots branches
1332 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1333 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1334 if ( !CORBA::is_nil( anObject ) ) {
1335 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1336 if ( !myMesh->_is_nil() ) {
1337 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1339 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1340 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1341 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1343 // for each mesh open the HDF group basing on its id
1344 char meshGrpName[ 30 ];
1345 sprintf( meshGrpName, "Mesh %d", id );
1346 aTopGroup = new HDFgroup( meshGrpName, aFile );
1347 aTopGroup->CreateOnDisk();
1349 // --> put dataset to hdf file which is a flag that mesh has data
1350 string strHasData = "0";
1351 // check if the mesh is not empty
1352 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1353 // write mesh data to med file
1354 myWriter.SetMesh( mySMESHDSMesh );
1355 myWriter.SetMeshId( id );
1358 aSize[ 0 ] = strHasData.length() + 1;
1359 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1360 aDataset->CreateOnDisk();
1361 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1362 aDataset->CloseOnDisk();
1364 // write reference on a shape if exists
1365 SALOMEDS::SObject_var myRef;
1366 bool shapeRefFound = false;
1367 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1369 SALOMEDS::SObject_var myShape;
1370 bool ok = myRef->ReferencedObject( myShape );
1372 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1373 string myRefOnObject = myShape->GetID();
1374 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1375 aSize[ 0 ] = myRefOnObject.length() + 1;
1376 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1377 aDataset->CreateOnDisk();
1378 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1379 aDataset->CloseOnDisk();
1384 // write applied hypotheses if exist
1385 SALOMEDS::SObject_var myHypBranch;
1386 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1387 if ( found && !shapeRefFound ) { // remove applied hyps
1388 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1390 if ( found && shapeRefFound ) {
1391 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1392 aGroup->CreateOnDisk();
1394 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1396 for ( ; it->More(); it->Next() ) {
1397 SALOMEDS::SObject_var mySObject = it->Value();
1398 SALOMEDS::SObject_var myRefOnHyp;
1399 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1401 // san - it is impossible to recover applied hypotheses
1402 // using their entries within Load() method,
1403 // for there are no AttributeIORs in the study when Load() is working.
1404 // Hence, it is better to store persistent IDs of hypotheses as references to them
1406 //string myRefOnObject = myRefOnHyp->GetID();
1407 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1408 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1409 //if ( myRefOnObject.length() > 0 ) {
1410 //aSize[ 0 ] = myRefOnObject.length() + 1;
1411 char hypName[ 30 ], hypId[ 30 ];
1412 sprintf( hypName, "Hyp %d", ++hypNb );
1413 sprintf( hypId, "%d", id );
1414 aSize[ 0 ] = strlen( hypId ) + 1;
1415 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1416 aDataset->CreateOnDisk();
1417 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1418 aDataset->WriteOnDisk( hypId );
1419 aDataset->CloseOnDisk();
1423 aGroup->CloseOnDisk();
1426 // write applied algorithms if exist
1427 SALOMEDS::SObject_var myAlgoBranch;
1428 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1429 if ( found && !shapeRefFound ) { // remove applied algos
1430 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1432 if ( found && shapeRefFound ) {
1433 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1434 aGroup->CreateOnDisk();
1436 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1438 for ( ; it->More(); it->Next() ) {
1439 SALOMEDS::SObject_var mySObject = it->Value();
1440 SALOMEDS::SObject_var myRefOnAlgo;
1441 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1443 // san - it is impossible to recover applied algorithms
1444 // using their entries within Load() method,
1445 // for there are no AttributeIORs in the study when Load() is working.
1446 // Hence, it is better to store persistent IDs of algorithms as references to them
1448 //string myRefOnObject = myRefOnAlgo->GetID();
1449 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1450 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1451 //if ( myRefOnObject.length() > 0 ) {
1452 //aSize[ 0 ] = myRefOnObject.length() + 1;
1453 char algoName[ 30 ], algoId[ 30 ];
1454 sprintf( algoName, "Algo %d", ++algoNb );
1455 sprintf( algoId, "%d", id );
1456 aSize[ 0 ] = strlen( algoId ) + 1;
1457 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1458 aDataset->CreateOnDisk();
1459 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1460 aDataset->WriteOnDisk( algoId );
1461 aDataset->CloseOnDisk();
1465 aGroup->CloseOnDisk();
1468 // --> submesh objects sub-branches
1470 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1471 SALOMEDS::SObject_var mySubmeshBranch;
1472 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1474 if ( found ) // check if there is shape reference in submeshes
1476 bool hasShapeRef = false;
1477 SALOMEDS::ChildIterator_var itSM =
1478 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1479 for ( ; itSM->More(); itSM->Next() ) {
1480 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1481 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1482 mySubRef->ReferencedObject( myShape );
1483 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1486 { // remove one submesh
1487 if ( shapeRefFound )
1488 { // unassign hypothesis
1489 SMESH::SMESH_subMesh_var mySubMesh =
1490 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1491 if ( !mySubMesh->_is_nil() ) {
1492 int shapeID = mySubMesh->GetId();
1493 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1494 const list<const SMESHDS_Hypothesis*>& hypList =
1495 mySMESHDSMesh->GetHypothesis( S );
1496 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1497 while ( hyp != hypList.end() ) {
1498 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1499 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1503 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1505 } // loop on submeshes of a type
1506 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1507 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1510 } // end check if there is shape reference in submeshes
1512 char name_meshgroup[ 30 ];
1513 if ( i == GetSubMeshOnVertexTag() )
1514 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1515 else if ( i == GetSubMeshOnEdgeTag() )
1516 strcpy( name_meshgroup, "SubMeshes On Edge" );
1517 else if ( i == GetSubMeshOnWireTag() )
1518 strcpy( name_meshgroup, "SubMeshes On Wire" );
1519 else if ( i == GetSubMeshOnFaceTag() )
1520 strcpy( name_meshgroup, "SubMeshes On Face" );
1521 else if ( i == GetSubMeshOnShellTag() )
1522 strcpy( name_meshgroup, "SubMeshes On Shell" );
1523 else if ( i == GetSubMeshOnSolidTag() )
1524 strcpy( name_meshgroup, "SubMeshes On Solid" );
1525 else if ( i == GetSubMeshOnCompoundTag() )
1526 strcpy( name_meshgroup, "SubMeshes On Compound" );
1528 // for each type of submeshes create container HDF group
1529 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1530 aGroup->CreateOnDisk();
1532 // iterator for all submeshes of given type
1533 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1534 for ( ; itSM->More(); itSM->Next() ) {
1535 SALOMEDS::SObject_var mySObject = itSM->Value();
1536 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1537 if ( !CORBA::is_nil( anSubObject ))
1539 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1540 int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) );
1542 // for each mesh open the HDF group basing on its id
1543 char submeshGrpName[ 30 ];
1544 sprintf( submeshGrpName, "SubMesh %d", subid );
1545 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1546 aSubGroup->CreateOnDisk();
1548 // write reference on a shape, already checked if it exists
1549 SALOMEDS::SObject_var mySubRef, myShape;
1550 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1551 mySubRef->ReferencedObject( myShape );
1552 string myRefOnObject = myShape->GetID();
1553 if ( myRefOnObject.length() > 0 ) {
1554 aSize[ 0 ] = myRefOnObject.length() + 1;
1555 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1556 aDataset->CreateOnDisk();
1557 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1558 aDataset->CloseOnDisk();
1561 // write applied hypotheses if exist
1562 SALOMEDS::SObject_var mySubHypBranch;
1563 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1565 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1566 aSubSubGroup->CreateOnDisk();
1568 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1570 for ( ; it->More(); it->Next() ) {
1571 SALOMEDS::SObject_var mySubSObject = it->Value();
1572 SALOMEDS::SObject_var myRefOnHyp;
1573 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1575 //string myRefOnObject = myRefOnHyp->GetID();
1576 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1577 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1578 //if ( myRefOnObject.length() > 0 ) {
1579 //aSize[ 0 ] = myRefOnObject.length() + 1;
1580 char hypName[ 30 ], hypId[ 30 ];
1581 sprintf( hypName, "Hyp %d", ++hypNb );
1582 sprintf( hypId, "%d", id );
1583 aSize[ 0 ] = strlen( hypId ) + 1;
1584 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1585 aDataset->CreateOnDisk();
1586 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1587 aDataset->WriteOnDisk( hypId );
1588 aDataset->CloseOnDisk();
1592 aSubSubGroup->CloseOnDisk();
1595 // write applied algorithms if exist
1596 SALOMEDS::SObject_var mySubAlgoBranch;
1597 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1599 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1600 aSubSubGroup->CreateOnDisk();
1602 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1604 for ( ; it->More(); it->Next() ) {
1605 SALOMEDS::SObject_var mySubSObject = it->Value();
1606 SALOMEDS::SObject_var myRefOnAlgo;
1607 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1609 //string myRefOnObject = myRefOnAlgo->GetID();
1610 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1611 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1612 //if ( myRefOnObject.length() > 0 ) {
1613 //aSize[ 0 ] = myRefOnObject.length() + 1;
1614 char algoName[ 30 ], algoId[ 30 ];
1615 sprintf( algoName, "Algo %d", ++algoNb );
1616 sprintf( algoId, "%d", id );
1617 aSize[ 0 ] = strlen( algoId ) + 1;
1618 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1619 aDataset->CreateOnDisk();
1620 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1621 aDataset->WriteOnDisk( algoId );
1622 aDataset->CloseOnDisk();
1626 aSubSubGroup->CloseOnDisk();
1628 // close submesh HDF group
1629 aSubGroup->CloseOnDisk();
1632 // close container of submeshes by type HDF group
1633 aGroup->CloseOnDisk();
1636 // All sub-meshes will be stored in MED file
1637 if ( shapeRefFound )
1638 myWriter.AddAllSubMeshes();
1640 // groups root sub-branch
1641 SALOMEDS::SObject_var myGroupsBranch;
1642 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1643 found = gotBranch->FindSubObject( i, myGroupsBranch );
1645 char name_group[ 30 ];
1646 if ( i == GetNodeGroupsTag() )
1647 strcpy( name_group, "Groups of Nodes" );
1648 else if ( i == GetEdgeGroupsTag() )
1649 strcpy( name_group, "Groups of Edges" );
1650 else if ( i == GetFaceGroupsTag() )
1651 strcpy( name_group, "Groups of Faces" );
1652 else if ( i == GetVolumeGroupsTag() )
1653 strcpy( name_group, "Groups of Volumes" );
1655 aGroup = new HDFgroup( name_group, aTopGroup );
1656 aGroup->CreateOnDisk();
1658 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
1659 for ( ; it->More(); it->Next() ) {
1660 SALOMEDS::SObject_var mySObject = it->Value();
1661 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
1662 if ( !CORBA::is_nil( aSubObject ) ) {
1663 SMESH_GroupBase_i* myGroupImpl =
1664 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
1668 int anId = myStudyContext->findId( string( GetORB()->object_to_string( aSubObject ) ) );
1670 // For each group, create a dataset named "Group <group_persistent_id>"
1671 // and store the group's user name into it
1673 sprintf( grpName, "Group %d", anId );
1674 char* aUserName = myGroupImpl->GetName();
1675 aSize[ 0 ] = strlen( aUserName ) + 1;
1677 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
1678 aDataset->CreateOnDisk();
1679 aDataset->WriteOnDisk( aUserName );
1680 aDataset->CloseOnDisk();
1682 // Store the group contents into MED file
1683 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
1685 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
1686 << grpName << " to MED file" );
1687 SMESHDS_GroupBase* aGrpBaseDS =
1688 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
1689 aGrpBaseDS->SetStoreName( grpName );
1691 // Pass SMESHDS_Group to MED writer
1692 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
1694 myWriter.AddGroup( aGrpDS );
1696 // write reference on a shape if exists
1697 SMESHDS_GroupOnGeom* aGeomGrp =
1698 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
1700 SALOMEDS::SObject_var mySubRef, myShape;
1701 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
1702 mySubRef->ReferencedObject( myShape ) &&
1703 !CORBA::is_nil( myShape->GetObject() ))
1705 string myRefOnObject = myShape->GetID();
1706 if ( myRefOnObject.length() > 0 ) {
1707 char aRefName[ 30 ];
1708 sprintf( aRefName, "Ref on shape %d", anId);
1709 aSize[ 0 ] = myRefOnObject.length() + 1;
1710 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
1711 aDataset->CreateOnDisk();
1712 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1713 aDataset->CloseOnDisk();
1716 else // shape ref is invalid:
1718 // save a group on geometry as ordinary group
1719 myWriter.AddGroup( aGeomGrp );
1725 aGroup->CloseOnDisk();
1729 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
1731 // Flush current mesh information into MED file
1734 // maybe a shape was deleted in the study
1735 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
1736 TopoDS_Shape nullShape;
1737 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
1740 // Store node positions on sub-shapes (SMDS_Position):
1742 if ( !mySMESHDSMesh->SubMeshes().empty() )
1744 aGroup = new HDFgroup( "Node Positions", aTopGroup );
1745 aGroup->CreateOnDisk();
1747 // in aGroup, create 5 datasets to contain:
1748 // "Nodes on Edges" - ID of node on edge
1749 // "Edge positions" - U parameter on node on edge
1750 // "Nodes on Faces" - ID of node on face
1751 // "Face U positions" - U parameter of node on face
1752 // "Face V positions" - V parameter of node on face
1754 // Find out nb of nodes on edges and faces
1755 // Collect corresponing sub-meshes
1756 int nbEdgeNodes = 0, nbFaceNodes = 0;
1757 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
1758 // loop on SMESHDS_SubMesh'es
1759 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
1760 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
1761 for ( ; itSubM != aSubMeshes.end() ; itSubM++ )
1763 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
1764 if ( aSubMesh->IsComplexSubmesh() )
1765 continue; // submesh containing other submeshs
1766 int nbNodes = aSubMesh->NbNodes();
1767 if ( nbNodes == 0 ) continue;
1769 int aShapeID = (*itSubM).first;
1770 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
1771 // write only SMDS_FacePosition and SMDS_EdgePosition
1772 switch ( aShapeType ) {
1774 nbFaceNodes += nbNodes;
1775 aFaceSM.push_back( aSubMesh );
1778 nbEdgeNodes += nbNodes;
1779 aEdgeSM.push_back( aSubMesh );
1785 // Treat positions on edges or faces
1786 for ( int onFace = 0; onFace < 2; onFace++ )
1788 // Create arrays to store in datasets
1789 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
1790 if (!nbNodes) continue;
1791 int* aNodeIDs = new int [ nbNodes ];
1792 double* aUPos = new double [ nbNodes ];
1793 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
1796 // loop on sub-meshes
1797 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
1798 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
1799 for ( ; itSM != pListSM->end(); itSM++ )
1801 SMESHDS_SubMesh* aSubMesh = (*itSM);
1802 if ( aSubMesh->IsComplexSubmesh() )
1803 continue; // submesh containing other submeshs
1805 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
1806 // loop on nodes in aSubMesh
1807 while ( itNode->more() )
1810 const SMDS_MeshNode* node = itNode->next();
1811 aNodeIDs [ iNode ] = node->GetID();
1814 const SMDS_PositionPtr pos = node->GetPosition();
1815 if ( onFace ) { // on FACE
1816 const SMDS_FacePosition* fPos =
1817 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
1819 aUPos[ iNode ] = fPos->GetUParameter();
1820 aVPos[ iNode ] = fPos->GetVParameter();
1827 const SMDS_EdgePosition* ePos =
1828 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
1830 aUPos[ iNode ] = ePos->GetUParameter();
1836 } // loop on nodes in aSubMesh
1837 } // loop on sub-meshes
1842 aSize[ 0 ] = nbNodes;
1844 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
1845 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
1846 aDataset->CreateOnDisk();
1847 aDataset->WriteOnDisk( aNodeIDs );
1848 aDataset->CloseOnDisk();
1851 aDSName = ( onFace ? "Face U positions" : "Edge positions");
1852 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
1853 aDataset->CreateOnDisk();
1854 aDataset->WriteOnDisk( aUPos );
1855 aDataset->CloseOnDisk();
1858 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
1859 aDataset->CreateOnDisk();
1860 aDataset->WriteOnDisk( aVPos );
1861 aDataset->CloseOnDisk();
1866 if ( aVPos ) delete [] aVPos;
1868 } // treat positions on edges or faces
1870 // close "Node Positions" group
1871 aGroup->CloseOnDisk();
1873 } // if ( there are submeshes in SMESHDS_Mesh )
1876 // close mesh HDF group
1877 aTopGroup->CloseOnDisk();
1885 aFile->CloseOnDisk();
1888 // Convert temporary files to stream
1889 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
1891 // Remove temporary files and directory
1893 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
1895 INFOS( "SMESH_Gen_i::Save() completed" );
1896 return aStreamFile._retn();
1899 //=============================================================================
1901 * SMESH_Gen_i::SaveASCII
1903 * Save SMESH module's data in ASCII format (not implemented yet)
1905 //=============================================================================
1907 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
1909 bool isMultiFile ) {
1910 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
1911 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
1912 return aStreamFile._retn();
1915 //=============================================================================
1917 * SMESH_Gen_i::loadGeomData
1919 * Load GEOM module data
1921 //=============================================================================
1923 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
1925 if ( theCompRoot->_is_nil() )
1928 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
1929 if ( aStudy->_is_nil() )
1932 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
1933 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
1936 //=============================================================================
1940 * Load SMESH module's data
1942 //=============================================================================
1944 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
1945 const SALOMEDS::TMPFile& theStream,
1949 INFOS( "SMESH_Gen_i::Load" );
1951 if ( myCurrentStudy->_is_nil() ||
1952 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1953 SetCurrentStudy( theComponent->GetStudy() );
1955 /* if( !theComponent->_is_nil() )
1957 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
1958 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
1959 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
1962 StudyContext* myStudyContext = GetCurrentStudyContext();
1964 // Get temporary files location
1965 TCollection_AsciiString tmpDir =
1966 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1968 // Convert the stream into sequence of files to process
1969 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
1972 TCollection_AsciiString aStudyName( "" );
1974 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1976 // Set names of temporary files
1977 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
1978 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
1982 HDFdataset* aDataset;
1983 HDFgroup* aTopGroup;
1985 HDFgroup* aSubGroup;
1986 HDFgroup* aSubSubGroup;
1989 // ---> open HDF file
1990 aFile = new HDFfile( filename.ToCString() );
1992 aFile->OpenOnDisk( HDF_RDONLY );
1994 catch ( HDFexception ) {
1995 INFOS( "Load(): " << filename << " not found!" );
1999 DriverMED_R_SMESHDS_Mesh myReader;
2000 myReader.SetFile( meshfile.ToCString() );
2002 // get total number of top-level groups
2003 int aNbGroups = aFile->nInternalObjects();
2004 if ( aNbGroups > 0 ) {
2005 // --> in first turn we should read&create hypotheses
2006 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2007 // open hypotheses root HDF group
2008 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2009 aTopGroup->OpenOnDisk();
2011 // get number of hypotheses
2012 int aNbObjects = aTopGroup->nInternalObjects();
2013 for ( int j = 0; j < aNbObjects; j++ ) {
2014 // try to identify hypothesis
2015 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2016 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2018 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2019 // open hypothesis group
2020 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2021 aGroup->OpenOnDisk();
2023 // --> get hypothesis id
2024 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2029 // get number of datasets
2030 int aNbSubObjects = aGroup->nInternalObjects();
2031 for ( int k = 0; k < aNbSubObjects; k++ ) {
2033 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2034 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2035 // --> get hypothesis name
2036 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2037 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2038 aDataset->OpenOnDisk();
2039 size = aDataset->GetSize();
2040 char* hypname_str = new char[ size ];
2041 aDataset->ReadFromDisk( hypname_str );
2042 hypname = string( hypname_str );
2043 delete [] hypname_str;
2044 aDataset->CloseOnDisk();
2046 // --> get hypothesis plugin library name
2047 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2048 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2049 aDataset->OpenOnDisk();
2050 size = aDataset->GetSize();
2051 char* libname_str = new char[ size ];
2052 aDataset->ReadFromDisk( libname_str );
2053 if(MYDEBUG) SCRUTE( libname_str );
2054 libname = string( libname_str );
2055 delete [] libname_str;
2056 aDataset->CloseOnDisk();
2058 // --> get hypothesis data
2059 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2060 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2061 aDataset->OpenOnDisk();
2062 size = aDataset->GetSize();
2063 char* hypdata_str = new char[ size ];
2064 aDataset->ReadFromDisk( hypdata_str );
2065 hypdata = string( hypdata_str );
2066 delete [] hypdata_str;
2067 aDataset->CloseOnDisk();
2070 // close hypothesis HDF group
2071 aGroup->CloseOnDisk();
2073 // --> restore hypothesis from data
2074 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2075 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2076 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2077 SMESH::SMESH_Hypothesis_var myHyp;
2079 try { // protect persistence mechanism against exceptions
2080 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2083 INFOS( "Exception during hypothesis creation" );
2086 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2088 myImpl->LoadFrom( hypdata.c_str() );
2089 string iorString = GetORB()->object_to_string( myHyp );
2090 int newId = myStudyContext->findId( iorString );
2091 myStudyContext->mapOldToNew( id, newId );
2094 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2098 // close hypotheses root HDF group
2099 aTopGroup->CloseOnDisk();
2102 // --> then we should read&create algorithms
2103 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2104 // open algorithms root HDF group
2105 aTopGroup = new HDFgroup( "Algorithms", aFile );
2106 aTopGroup->OpenOnDisk();
2108 // get number of algorithms
2109 int aNbObjects = aTopGroup->nInternalObjects();
2110 for ( int j = 0; j < aNbObjects; j++ ) {
2111 // try to identify algorithm
2112 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2113 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2115 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2116 // open algorithm group
2117 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2118 aGroup->OpenOnDisk();
2120 // --> get algorithm id
2121 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2126 // get number of datasets
2127 int aNbSubObjects = aGroup->nInternalObjects();
2128 for ( int k = 0; k < aNbSubObjects; k++ ) {
2130 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2131 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2132 // --> get algorithm name
2133 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2134 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2135 aDataset->OpenOnDisk();
2136 size = aDataset->GetSize();
2137 char* hypname_str = new char[ size ];
2138 aDataset->ReadFromDisk( hypname_str );
2139 hypname = string( hypname_str );
2140 delete [] hypname_str;
2141 aDataset->CloseOnDisk();
2143 // --> get algorithm plugin library name
2144 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2145 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2146 aDataset->OpenOnDisk();
2147 size = aDataset->GetSize();
2148 char* libname_str = new char[ size ];
2149 aDataset->ReadFromDisk( libname_str );
2150 if(MYDEBUG) SCRUTE( libname_str );
2151 libname = string( libname_str );
2152 delete [] libname_str;
2153 aDataset->CloseOnDisk();
2155 // --> get algorithm data
2156 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2157 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2158 aDataset->OpenOnDisk();
2159 size = aDataset->GetSize();
2160 char* hypdata_str = new char[ size ];
2161 aDataset->ReadFromDisk( hypdata_str );
2162 if(MYDEBUG) SCRUTE( hypdata_str );
2163 hypdata = string( hypdata_str );
2164 delete [] hypdata_str;
2165 aDataset->CloseOnDisk();
2168 // close algorithm HDF group
2169 aGroup->CloseOnDisk();
2171 // --> restore algorithm from data
2172 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2173 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2174 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2175 SMESH::SMESH_Hypothesis_var myHyp;
2177 try { // protect persistence mechanism against exceptions
2178 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2181 INFOS( "Exception during hypothesis creation" );
2184 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2186 myImpl->LoadFrom( hypdata.c_str() );
2187 string iorString = GetORB()->object_to_string( myHyp );
2188 int newId = myStudyContext->findId( iorString );
2189 myStudyContext->mapOldToNew( id, newId );
2192 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2196 // close algorithms root HDF group
2197 aTopGroup->CloseOnDisk();
2200 // --> the rest groups should be meshes
2201 for ( int i = 0; i < aNbGroups; i++ ) {
2202 // identify next group
2203 char meshName[ HDF_NAME_MAX_LEN+1 ];
2204 aFile->InternalObjectIndentify( i, meshName );
2206 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2208 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2212 bool hasData = false;
2214 // open mesh HDF group
2215 aTopGroup = new HDFgroup( meshName, aFile );
2216 aTopGroup->OpenOnDisk();
2218 // get number of child HDF objects
2219 int aNbObjects = aTopGroup->nInternalObjects();
2220 if ( aNbObjects > 0 ) {
2222 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2223 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2224 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2225 if ( !myNewMeshImpl )
2227 string iorString = GetORB()->object_to_string( myNewMesh );
2228 int newId = myStudyContext->findId( iorString );
2229 myStudyContext->mapOldToNew( id, newId );
2231 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2232 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2234 // try to find mesh data dataset
2235 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2236 // load mesh "has data" flag
2237 aDataset = new HDFdataset( "Has data", aTopGroup );
2238 aDataset->OpenOnDisk();
2239 size = aDataset->GetSize();
2240 char* strHasData = new char[ size ];
2241 aDataset->ReadFromDisk( strHasData );
2242 aDataset->CloseOnDisk();
2243 if ( strcmp( strHasData, "1") == 0 ) {
2244 // read mesh data from MED file
2245 myReader.SetMesh( mySMESHDSMesh );
2246 myReader.SetMeshId( id );
2252 // try to read and set reference to shape
2253 GEOM::GEOM_Object_var aShapeObject;
2254 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2255 // load mesh "Ref on shape" - it's an entry to SObject
2256 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2257 aDataset->OpenOnDisk();
2258 size = aDataset->GetSize();
2259 char* refFromFile = new char[ size ];
2260 aDataset->ReadFromDisk( refFromFile );
2261 aDataset->CloseOnDisk();
2262 if ( strlen( refFromFile ) > 0 ) {
2263 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2265 // Make sure GEOM data are loaded first
2266 //loadGeomData( shapeSO->GetFatherComponent() );
2268 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2269 if ( !CORBA::is_nil( shapeObject ) ) {
2270 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2271 if ( !aShapeObject->_is_nil() )
2272 myNewMeshImpl->SetShape( aShapeObject );
2277 // try to get applied algorithms
2278 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2279 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2280 aGroup->OpenOnDisk();
2281 // get number of applied algorithms
2282 int aNbSubObjects = aGroup->nInternalObjects();
2283 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2284 for ( int j = 0; j < aNbSubObjects; j++ ) {
2285 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2286 aGroup->InternalObjectIndentify( j, name_dataset );
2287 // check if it is an algorithm
2288 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2289 aDataset = new HDFdataset( name_dataset, aGroup );
2290 aDataset->OpenOnDisk();
2291 size = aDataset->GetSize();
2292 char* refFromFile = new char[ size ];
2293 aDataset->ReadFromDisk( refFromFile );
2294 aDataset->CloseOnDisk();
2296 // san - it is impossible to recover applied algorithms using their entries within Load() method
2298 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2299 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2300 int id = atoi( refFromFile );
2301 string anIOR = myStudyContext->getIORbyOldId( id );
2302 if ( !anIOR.empty() ) {
2303 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2304 if ( !CORBA::is_nil( hypObject ) ) {
2305 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2306 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2307 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2312 aGroup->CloseOnDisk();
2315 // try to get applied hypotheses
2316 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2317 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2318 aGroup->OpenOnDisk();
2319 // get number of applied hypotheses
2320 int aNbSubObjects = aGroup->nInternalObjects();
2321 for ( int j = 0; j < aNbSubObjects; j++ ) {
2322 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2323 aGroup->InternalObjectIndentify( j, name_dataset );
2324 // check if it is a hypothesis
2325 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2326 aDataset = new HDFdataset( name_dataset, aGroup );
2327 aDataset->OpenOnDisk();
2328 size = aDataset->GetSize();
2329 char* refFromFile = new char[ size ];
2330 aDataset->ReadFromDisk( refFromFile );
2331 aDataset->CloseOnDisk();
2333 // san - it is impossible to recover applied hypotheses using their entries within Load() method
2335 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2336 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2337 int id = atoi( refFromFile );
2338 string anIOR = myStudyContext->getIORbyOldId( id );
2339 if ( !anIOR.empty() ) {
2340 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2341 if ( !CORBA::is_nil( hypObject ) ) {
2342 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2343 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2344 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2349 aGroup->CloseOnDisk();
2352 // --> try to find submeshes containers for each type of submesh
2353 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
2354 char name_meshgroup[ 30 ];
2355 if ( j == GetSubMeshOnVertexTag() )
2356 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2357 else if ( j == GetSubMeshOnEdgeTag() )
2358 strcpy( name_meshgroup, "SubMeshes On Edge" );
2359 else if ( j == GetSubMeshOnWireTag() )
2360 strcpy( name_meshgroup, "SubMeshes On Wire" );
2361 else if ( j == GetSubMeshOnFaceTag() )
2362 strcpy( name_meshgroup, "SubMeshes On Face" );
2363 else if ( j == GetSubMeshOnShellTag() )
2364 strcpy( name_meshgroup, "SubMeshes On Shell" );
2365 else if ( j == GetSubMeshOnSolidTag() )
2366 strcpy( name_meshgroup, "SubMeshes On Solid" );
2367 else if ( j == GetSubMeshOnCompoundTag() )
2368 strcpy( name_meshgroup, "SubMeshes On Compound" );
2370 // try to get submeshes container HDF group
2371 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
2372 // open submeshes containers HDF group
2373 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2374 aGroup->OpenOnDisk();
2376 // get number of submeshes
2377 int aNbSubMeshes = aGroup->nInternalObjects();
2378 for ( int k = 0; k < aNbSubMeshes; k++ ) {
2380 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
2381 aGroup->InternalObjectIndentify( k, name_submeshgroup );
2382 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
2383 // --> get submesh id
2384 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
2387 // open submesh HDF group
2388 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
2389 aSubGroup->OpenOnDisk();
2391 // try to read and set reference to subshape
2392 GEOM::GEOM_Object_var aSubShapeObject;
2393 SMESH::SMESH_subMesh_var aSubMesh;
2395 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2396 // load submesh "Ref on shape" - it's an entry to SObject
2397 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2398 aDataset->OpenOnDisk();
2399 size = aDataset->GetSize();
2400 char* refFromFile = new char[ size ];
2401 aDataset->ReadFromDisk( refFromFile );
2402 aDataset->CloseOnDisk();
2403 if ( strlen( refFromFile ) > 0 ) {
2404 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2405 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2406 if ( !CORBA::is_nil( subShapeObject ) ) {
2407 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2408 if ( !aSubShapeObject->_is_nil() )
2409 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2410 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2411 if ( aSubMesh->_is_nil() )
2413 string iorSubString = GetORB()->object_to_string( aSubMesh );
2414 int newSubId = myStudyContext->findId( iorSubString );
2415 myStudyContext->mapOldToNew( subid, newSubId );
2420 if ( aSubMesh->_is_nil() )
2423 // VSR: Get submesh data from MED convertor
2424 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2425 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2426 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2427 // subid << " for subshape # " << anInternalSubmeshId);
2428 // SMESHDS_SubMesh* aSubMeshDS =
2429 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2430 // if ( !aSubMeshDS ) {
2431 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2432 // anInternalSubmeshId << " in current mesh!");
2435 // myReader.GetSubMesh( aSubMeshDS, subid );
2438 // try to get applied algorithms
2439 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2440 // open "applied algorithms" HDF group
2441 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2442 aSubSubGroup->OpenOnDisk();
2443 // get number of applied algorithms
2444 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2445 for ( int l = 0; l < aNbSubObjects; l++ ) {
2446 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2447 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2448 // check if it is an algorithm
2449 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2450 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2451 aDataset->OpenOnDisk();
2452 size = aDataset->GetSize();
2453 char* refFromFile = new char[ size ];
2454 aDataset->ReadFromDisk( refFromFile );
2455 aDataset->CloseOnDisk();
2457 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2458 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2459 int id = atoi( refFromFile );
2460 string anIOR = myStudyContext->getIORbyOldId( id );
2461 if ( !anIOR.empty() ) {
2462 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2463 if ( !CORBA::is_nil( hypObject ) ) {
2464 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2465 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2466 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2471 // close "applied algorithms" HDF group
2472 aSubSubGroup->CloseOnDisk();
2475 // try to get applied hypotheses
2476 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2477 // open "applied hypotheses" HDF group
2478 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2479 aSubSubGroup->OpenOnDisk();
2480 // get number of applied hypotheses
2481 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2482 for ( int l = 0; l < aNbSubObjects; l++ ) {
2483 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2484 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2485 // check if it is a hypothesis
2486 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2487 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2488 aDataset->OpenOnDisk();
2489 size = aDataset->GetSize();
2490 char* refFromFile = new char[ size ];
2491 aDataset->ReadFromDisk( refFromFile );
2492 aDataset->CloseOnDisk();
2494 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2495 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2496 int id = atoi( refFromFile );
2497 string anIOR = myStudyContext->getIORbyOldId( id );
2498 if ( !anIOR.empty() ) {
2499 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2500 if ( !CORBA::is_nil( hypObject ) ) {
2501 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2502 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2503 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2508 // close "applied hypotheses" HDF group
2509 aSubSubGroup->CloseOnDisk();
2512 // close submesh HDF group
2513 aSubGroup->CloseOnDisk();
2516 // close submeshes containers HDF group
2517 aGroup->CloseOnDisk();
2522 // Read sub-meshes from MED
2523 if(MYDEBUG) MESSAGE("Create all sub-meshes");
2524 myReader.CreateAllSubMeshes();
2527 // Read node positions on sub-shapes (SMDS_Position)
2529 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
2531 // There are 5 datasets to read:
2532 // "Nodes on Edges" - ID of node on edge
2533 // "Edge positions" - U parameter on node on edge
2534 // "Nodes on Faces" - ID of node on face
2535 // "Face U positions" - U parameter of node on face
2536 // "Face V positions" - V parameter of node on face
2537 char* aEid_DSName = "Nodes on Edges";
2538 char* aEu_DSName = "Edge positions";
2539 char* aFu_DSName = "Face U positions";
2540 //char* aFid_DSName = "Nodes on Faces";
2541 //char* aFv_DSName = "Face V positions";
2544 int nbEids = 0, nbFids = 0;
2545 int *aEids = 0, *aFids = 0;
2546 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
2549 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2550 aGroup->OpenOnDisk();
2552 // loop on 5 data sets
2553 int aNbObjects = aGroup->nInternalObjects();
2554 for ( int i = 0; i < aNbObjects; i++ )
2557 char aDSName[ HDF_NAME_MAX_LEN+1 ];
2558 aGroup->InternalObjectIndentify( i, aDSName );
2560 aDataset = new HDFdataset( aDSName, aGroup );
2561 aDataset->OpenOnDisk();
2562 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
2564 double* pos = new double [ aDataset->GetSize() ];
2565 aDataset->ReadFromDisk( pos );
2567 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
2569 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
2576 int aSize = aDataset->GetSize();
2578 // for reading files, created from 18.07.2005 till 10.10.2005
2579 if (aDataset->GetType() == HDF_STRING)
2580 aSize /= sizeof(int);
2582 int* ids = new int [aSize];
2583 aDataset->ReadFromDisk( ids );
2584 // on face or nodes?
2585 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
2594 } // loop on 5 datasets
2596 // Set node positions on edges or faces
2597 for ( int onFace = 0; onFace < 2; onFace++ )
2599 int nbNodes = ( onFace ? nbFids : nbEids );
2600 if ( nbNodes == 0 ) continue;
2601 int* aNodeIDs = ( onFace ? aFids : aEids );
2602 double* aUPos = ( onFace ? aFupos : aEpos );
2603 double* aVPos = ( onFace ? aFvpos : 0 );
2605 for ( int iNode = 0; iNode < nbNodes; iNode++ )
2607 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
2609 SMDS_PositionPtr aPos = node->GetPosition();
2612 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
2613 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
2614 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
2615 fPos->SetUParameter( aUPos[ iNode ]);
2616 fPos->SetVParameter( aVPos[ iNode ]);
2619 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
2620 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
2621 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
2622 fPos->SetUParameter( aUPos[ iNode ]);
2626 if ( aEids ) delete [] aEids;
2627 if ( aFids ) delete [] aFids;
2628 if ( aEpos ) delete [] aEpos;
2629 if ( aFupos ) delete [] aFupos;
2630 if ( aFvpos ) delete [] aFvpos;
2632 aGroup->CloseOnDisk();
2634 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
2637 // Recompute State (as computed sub-meshes are restored from MED)
2638 if ( !aShapeObject->_is_nil() ) {
2639 MESSAGE("Compute State Engine ...");
2640 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
2641 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
2642 (SMESH_subMesh::SUBMESH_RESTORED);
2643 MESSAGE("Compute State Engine finished");
2646 // try to get groups
2647 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
2648 char name_group[ 30 ];
2649 if ( ii == GetNodeGroupsTag() )
2650 strcpy( name_group, "Groups of Nodes" );
2651 else if ( ii == GetEdgeGroupsTag() )
2652 strcpy( name_group, "Groups of Edges" );
2653 else if ( ii == GetFaceGroupsTag() )
2654 strcpy( name_group, "Groups of Faces" );
2655 else if ( ii == GetVolumeGroupsTag() )
2656 strcpy( name_group, "Groups of Volumes" );
2658 if ( aTopGroup->ExistInternalObject( name_group ) ) {
2659 aGroup = new HDFgroup( name_group, aTopGroup );
2660 aGroup->OpenOnDisk();
2661 // get number of groups
2662 int aNbSubObjects = aGroup->nInternalObjects();
2663 for ( int j = 0; j < aNbSubObjects; j++ ) {
2664 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2665 aGroup->InternalObjectIndentify( j, name_dataset );
2666 // check if it is an group
2667 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
2669 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
2672 aDataset = new HDFdataset( name_dataset, aGroup );
2673 aDataset->OpenOnDisk();
2675 // Retrieve actual group name
2676 size = aDataset->GetSize();
2677 char* nameFromFile = new char[ size ];
2678 aDataset->ReadFromDisk( nameFromFile );
2679 aDataset->CloseOnDisk();
2681 // Try to find a shape reference
2682 TopoDS_Shape aShape;
2683 char aRefName[ 30 ];
2684 sprintf( aRefName, "Ref on shape %d", subid);
2685 if ( aGroup->ExistInternalObject( aRefName ) ) {
2686 // load mesh "Ref on shape" - it's an entry to SObject
2687 aDataset = new HDFdataset( aRefName, aGroup );
2688 aDataset->OpenOnDisk();
2689 size = aDataset->GetSize();
2690 char* refFromFile = new char[ size ];
2691 aDataset->ReadFromDisk( refFromFile );
2692 aDataset->CloseOnDisk();
2693 if ( strlen( refFromFile ) > 0 ) {
2694 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2695 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2696 if ( !CORBA::is_nil( shapeObject ) ) {
2697 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2698 if ( !aShapeObject->_is_nil() )
2699 aShape = GeomObjectToShape( aShapeObject );
2703 // Create group servant
2704 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
2705 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
2706 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
2707 // Obtain a SMESHDS_Group object
2708 if ( aNewGroup->_is_nil() )
2711 string iorSubString = GetORB()->object_to_string( aNewGroup );
2712 int newSubId = myStudyContext->findId( iorSubString );
2713 myStudyContext->mapOldToNew( subid, newSubId );
2715 SMESH_GroupBase_i* aGroupImpl =
2716 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
2720 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
2724 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
2725 aGroupBaseDS->SetStoreName( name_dataset );
2727 // Fill group with contents from MED file
2728 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
2730 myReader.GetGroup( aGrp );
2733 aGroup->CloseOnDisk();
2738 aTopGroup->CloseOnDisk();
2743 aFile->CloseOnDisk();
2746 // Remove temporary files created from the stream
2748 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2750 INFOS( "SMESH_Gen_i::Load completed" );
2754 //=============================================================================
2756 * SMESH_Gen_i::LoadASCII
2758 * Load SMESH module's data in ASCII format (not implemented yet)
2760 //=============================================================================
2762 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
2763 const SALOMEDS::TMPFile& theStream,
2765 bool isMultiFile ) {
2766 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
2767 return Load( theComponent, theStream, theURL, isMultiFile );
2770 //=============================================================================
2772 * SMESH_Gen_i::Close
2774 * Clears study-connected data when it is closed
2776 //=============================================================================
2778 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
2780 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
2782 // Clear study contexts data
2783 int studyId = GetCurrentStudyID();
2784 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
2785 delete myStudyContextMap[ studyId ];
2786 myStudyContextMap.erase( studyId );
2791 //=============================================================================
2793 * SMESH_Gen_i::ComponentDataType
2795 * Get component data type
2797 //=============================================================================
2799 char* SMESH_Gen_i::ComponentDataType()
2801 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
2802 return CORBA::string_dup( "SMESH" );
2806 //=============================================================================
2808 * SMESH_Gen_i::IORToLocalPersistentID
2810 * Transform data from transient form to persistent
2812 //=============================================================================
2814 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
2815 const char* IORString,
2816 CORBA::Boolean /*isMultiFile*/,
2817 CORBA::Boolean /*isASCII*/ )
2819 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
2820 StudyContext* myStudyContext = GetCurrentStudyContext();
2822 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
2823 int anId = myStudyContext->findId( IORString );
2825 if(MYDEBUG) MESSAGE( "VSR " << anId )
2827 sprintf( strId, "%d", anId );
2828 return CORBA::string_dup( strId );
2831 return CORBA::string_dup( "" );
2834 //=============================================================================
2836 * SMESH_Gen_i::LocalPersistentIDToIOR
2838 * Transform data from persistent form to transient
2840 //=============================================================================
2842 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
2843 const char* aLocalPersistentID,
2844 CORBA::Boolean /*isMultiFile*/,
2845 CORBA::Boolean /*isASCII*/ )
2847 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
2848 StudyContext* myStudyContext = GetCurrentStudyContext();
2850 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
2851 int anId = atoi( aLocalPersistentID );
2852 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
2854 return CORBA::string_dup( "" );
2857 //=======================================================================
2858 //function : RegisterObject
2860 //=======================================================================
2862 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
2864 StudyContext* myStudyContext = GetCurrentStudyContext();
2865 if ( myStudyContext && !CORBA::is_nil( theObject )) {
2866 string iorString = GetORB()->object_to_string( theObject );
2867 return myStudyContext->addObject( iorString );
2872 //=============================================================================
2874 * SMESHEngine_factory
2876 * C factory, accessible with dlsym, after dlopen
2878 //=============================================================================
2882 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
2883 PortableServer::POA_ptr poa,
2884 PortableServer::ObjectId* contId,
2885 const char* instanceName,
2886 const char* interfaceName )
2888 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
2889 if(MYDEBUG) SCRUTE(interfaceName);
2890 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
2891 return aSMESHGen->getId() ;