1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Gen_i.cxx
25 // Author : Paul RASCLE, EDF
30 #include <TopExp_Explorer.hxx>
32 #include <TopoDS_Iterator.hxx>
33 #include <TopoDS_Compound.hxx>
34 #include <TopoDS_CompSolid.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopoDS_Shell.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Wire.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopTools_MapOfShape.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
44 #include <TopTools_ListOfShape.hxx>
45 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TCollection_AsciiString.hxx>
51 #include "Utils_CorbaException.hxx"
53 #include "utilities.h"
60 #include "SMESH_Gen_i.hxx"
61 #include "SMESH_Mesh_i.hxx"
62 #include "SMESH_Hypothesis_i.hxx"
63 #include "SMESH_Algo_i.hxx"
64 #include "SMESH_Group_i.hxx"
65 #include "SMESH_PythonDump.hxx"
67 #include "SMESHDS_Document.hxx"
68 #include "SMESHDS_Group.hxx"
69 #include "SMESHDS_GroupOnGeom.hxx"
70 #include "SMESH_Mesh.hxx"
71 #include "SMESH_Hypothesis.hxx"
72 #include "SMESH_Group.hxx"
73 #include "SMESH_MeshEditor.hxx"
75 #include "SMDS_EdgePosition.hxx"
76 #include "SMDS_FacePosition.hxx"
77 #include "SMDS_VertexPosition.hxx"
78 #include "SMDS_SpacePosition.hxx"
79 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
81 #include CORBA_SERVER_HEADER(SMESH_Group)
82 #include CORBA_SERVER_HEADER(SMESH_Filter)
84 #include "DriverMED_W_SMESHDS_Mesh.h"
85 #include "DriverMED_R_SMESHDS_Mesh.h"
87 #include "SALOMEDS_Tool.hxx"
88 #include "SALOME_NamingService.hxx"
89 #include "SALOME_LifeCycleCORBA.hxx"
90 #include "Utils_SINGLETON.hxx"
93 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
95 #include "GEOM_Client.hxx"
96 #include "Utils_ExceptHandlers.hxx"
101 using SMESH::TPythonDump;
103 #define NUM_TMP_FILES 2
106 static int MYDEBUG = 0;
108 static int MYDEBUG = 0;
111 // Static variables definition
112 CORBA::ORB_var SMESH_Gen_i::myOrb;
113 PortableServer::POA_var SMESH_Gen_i::myPoa;
114 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
115 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
116 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
118 //=============================================================================
120 * GetServant [ static ]
122 * Get servant of the CORBA object
124 //=============================================================================
126 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
128 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
131 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
135 INFOS( "GetServant - Unknown exception was caught!!!" );
140 //=============================================================================
142 * SObjectToObject [ static ]
144 * Get CORBA object corresponding to the SALOMEDS::SObject
146 //=============================================================================
148 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
150 SALOMEDS::GenericAttribute_var anAttr;
151 CORBA::Object_var anObj;
152 if ( !theSObject->_is_nil() ) {
154 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
155 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
156 CORBA::String_var aValue = anIOR->Value();
157 if( strcmp( aValue, "" ) != 0 )
158 anObj = GetORB()->string_to_object( aValue );
162 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
168 //=============================================================================
172 * Get SALOME_NamingService object
174 //=============================================================================
176 SALOME_NamingService* SMESH_Gen_i::GetNS()
178 if ( myNS == NULL ) {
179 myNS = SINGLETON_<SALOME_NamingService>::Instance();
180 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
181 myNS->init_orb( GetORB() );
186 //=============================================================================
190 * Get SALOME_LifeCycleCORBA object
192 //=============================================================================
193 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
194 if ( myLCC == NULL ) {
195 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
201 //=============================================================================
203 * GetGeomEngine [ static ]
205 * Get GEOM::GEOM_Gen reference
207 //=============================================================================
208 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
209 GEOM::GEOM_Gen_var aGeomEngine =
210 GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
211 return aGeomEngine._retn();
214 //=============================================================================
216 * SMESH_Gen_i::SMESH_Gen_i
218 * Default constructor: not for use
220 //=============================================================================
222 SMESH_Gen_i::SMESH_Gen_i()
224 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
227 //=============================================================================
229 * SMESH_Gen_i::SMESH_Gen_i
231 * Standard constructor, used with Container
233 //=============================================================================
235 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
236 PortableServer::POA_ptr poa,
237 PortableServer::ObjectId* contId,
238 const char* instanceName,
239 const char* interfaceName )
240 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
242 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
244 myOrb = CORBA::ORB::_duplicate(orb);
245 myPoa = PortableServer::POA::_duplicate(poa);
248 _id = myPoa->activate_object( _thisObj );
250 myIsEmbeddedMode = false;
251 myShapeReader = NULL; // shape reader
254 // set it in standalone mode only
255 //OSD::SetSignal( true );
258 //=============================================================================
260 * SMESH_Gen_i::~SMESH_Gen_i
264 //=============================================================================
266 SMESH_Gen_i::~SMESH_Gen_i()
268 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
270 // delete hypothesis creators
271 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
272 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
274 delete (*itHyp).second;
276 myHypCreatorMap.clear();
278 // Clear study contexts data
279 map<int, StudyContext*>::iterator it;
280 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
283 myStudyContextMap.clear();
284 // delete shape reader
285 if ( !myShapeReader )
286 delete myShapeReader;
289 //=============================================================================
291 * SMESH_Gen_i::createHypothesis
293 * Create hypothesis of given type
295 //=============================================================================
296 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
297 const char* theLibName)
298 throw (SALOME::SALOME_Exception)
300 Unexpect aCatch(SALOME_SalomeException);
301 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
303 // create a new hypothesis object servant
304 SMESH_Hypothesis_i* myHypothesis_i = 0;
305 SMESH::SMESH_Hypothesis_var hypothesis_i;
309 // check, if creator for this hypothesis type already exists
310 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
312 // load plugin library
313 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
314 void* libHandle = dlopen (theLibName, RTLD_LAZY);
317 // report any error, if occured
318 const char* anError = dlerror();
319 throw(SALOME_Exception(anError));
322 // get method, returning hypothesis creator
323 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
324 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
325 GetHypothesisCreator procHandle =
326 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
329 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
333 // get hypothesis creator
334 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
335 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
338 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
341 // map hypothesis creator to a hypothesis name
342 myHypCreatorMap[string(theHypName)] = aCreator;
345 // create a new hypothesis object, store its ref. in studyContext
346 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
348 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
349 // _CS_gbo Explicit activation (no longer made in the constructor).
350 myHypothesis_i->Activate();
351 myHypothesis_i->SetLibName(theLibName); // for persistency assurance
353 catch (SALOME_Exception& S_ex)
355 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
359 return hypothesis_i._retn();
361 // activate the CORBA servant of hypothesis
362 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
363 int nextId = RegisterObject( hypothesis_i );
364 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
366 return hypothesis_i._retn();
369 //=============================================================================
371 * SMESH_Gen_i::createMesh
373 * Create empty mesh on shape
375 //=============================================================================
376 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
377 throw ( SALOME::SALOME_Exception )
379 Unexpect aCatch(SALOME_SalomeException);
380 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
382 // Get or create the GEOM_Client instance
384 // create a new mesh object servant, store it in a map in study context
385 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
386 // create a new mesh object
387 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
389 // activate the CORBA servant of Mesh
390 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
391 int nextId = RegisterObject( mesh );
392 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
395 catch (SALOME_Exception& S_ex) {
396 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
398 return SMESH::SMESH_Mesh::_nil();
401 //=============================================================================
403 * SMESH_Gen_i::GetShapeReader
407 //=============================================================================
408 GEOM_Client* SMESH_Gen_i::GetShapeReader()
410 // create shape reader if necessary
411 if ( !myShapeReader )
412 myShapeReader = new GEOM_Client(GetContainerRef());
413 ASSERT( myShapeReader );
414 return myShapeReader;
417 //=============================================================================
419 * SMESH_Gen_i::SetEmbeddedMode
423 //=============================================================================
425 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
427 myIsEmbeddedMode = theMode;
429 if ( !myIsEmbeddedMode ) {
430 //PAL10867: disable signals catching with "noexcepthandler" option
431 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
432 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
437 char* envDisableFPE = getenv("DISABLE_FPE");
438 if (envDisableFPE && atoi(envDisableFPE))
443 OSD::SetSignal( raiseFPE );
445 // else OSD::SetSignal() is called in GUI
449 //=============================================================================
451 * SMESH_Gen_i::IsEmbeddedMode
455 //=============================================================================
457 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
459 return myIsEmbeddedMode;
462 //=============================================================================
464 * SMESH_Gen_i::SetCurrentStudy
468 //=============================================================================
470 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
473 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
474 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
475 // create study context, if it doesn't exist and set current study
476 int studyId = GetCurrentStudyID();
477 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
478 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
479 myStudyContextMap[ studyId ] = new StudyContext;
482 // myCurrentStudy may be nil
483 if ( !CORBA::is_nil( myCurrentStudy ) ) {
484 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
485 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
486 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
488 // set current study for geom engine
489 //if ( !CORBA::is_nil( GetGeomEngine() ) )
490 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
494 //=============================================================================
496 * SMESH_Gen_i::GetCurrentStudy
500 //=============================================================================
502 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
504 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
505 return SALOMEDS::Study::_duplicate( myCurrentStudy );
508 //=============================================================================
510 * SMESH_Gen_i::GetCurrentStudyContext
512 * Get current study context
514 //=============================================================================
515 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
517 if ( !CORBA::is_nil( myCurrentStudy ) &&
518 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
519 return myStudyContextMap[ myCurrentStudy->StudyId() ];
524 //=============================================================================
526 * SMESH_Gen_i::CreateHypothesis
528 * Create hypothesis/algorothm of given type and publish it in the study
530 //=============================================================================
532 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
533 const char* theLibName )
534 throw ( SALOME::SALOME_Exception )
536 Unexpect aCatch(SALOME_SalomeException);
537 // Create hypothesis/algorithm
538 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
540 // Publish hypothesis/algorithm in the study
541 if ( CanPublishInStudy( hyp ) ) {
542 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
543 if ( !aSO->_is_nil() ) {
544 // Update Python script
545 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
546 << theHypName << "', '" << theLibName << "')";
553 //================================================================================
555 * \brief Return hypothesis of given type holding parameter values of the existing mesh
556 * \param theHypType - hypothesis type name
557 * \param theLibName - plugin library name
558 * \param theMesh - The mesh of interest
559 * \param theGeom - The shape to get parameter values from
560 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
561 * in a study and used to compute the mesh, or a temporary one created just to pass
564 //================================================================================
566 SMESH::SMESH_Hypothesis_ptr
567 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
568 const char* theLibName,
569 SMESH::SMESH_Mesh_ptr theMesh,
570 GEOM::GEOM_Object_ptr theGeom)
571 throw ( SALOME::SALOME_Exception )
573 Unexpect aCatch(SALOME_SalomeException);
574 if ( CORBA::is_nil( theMesh ) )
575 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
576 if ( CORBA::is_nil( theGeom ) )
577 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
579 // -----------------------------------------------
580 // find hypothesis used to mesh theGeom
581 // -----------------------------------------------
583 // get mesh and shape
584 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
585 TopoDS_Shape shape = GeomObjectToShape( theGeom );
586 if ( !meshServant || shape.IsNull() )
587 return SMESH::SMESH_Hypothesis::_nil();
588 ::SMESH_Mesh& mesh = meshServant->GetImpl();
590 if ( mesh.NbNodes() == 0 ) // empty mesh
591 return SMESH::SMESH_Hypothesis::_nil();
593 // create a temporary hypothesis to know its dimention
594 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
595 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
597 return SMESH::SMESH_Hypothesis::_nil();
598 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
600 // look for a hypothesis of theHypType used to mesh the shape
601 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
604 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
605 int nbLocalHyps = aHypList->length();
606 for ( int i = 0; i < nbLocalHyps; i++ )
607 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
608 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
609 // check super shapes
610 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
611 while ( nbLocalHyps == 0 && itShape.More() ) {
612 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
613 if ( ! CORBA::is_nil( geomObj )) {
614 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
615 nbLocalHyps = aHypList->length();
616 for ( int i = 0; i < nbLocalHyps; i++ )
617 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
618 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
624 // let the temporary hypothesis find out some how parameter values
625 if ( hyp->SetParametersByMesh( &mesh, shape ))
626 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
628 return SMESH::SMESH_Hypothesis::_nil();
631 //=============================================================================
633 * SMESH_Gen_i::CreateMesh
635 * Create empty mesh on a shape and publish it in the study
637 //=============================================================================
639 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
640 throw ( SALOME::SALOME_Exception )
642 Unexpect aCatch(SALOME_SalomeException);
643 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
645 SMESH::SMESH_Mesh_var mesh = this->createMesh();
647 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
648 ASSERT( meshServant );
649 meshServant->SetShape( theShapeObject );
651 // publish mesh in the study
652 if ( CanPublishInStudy( mesh ) ) {
653 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
654 aStudyBuilder->NewCommand(); // There is a transaction
655 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
656 aStudyBuilder->CommitCommand();
657 if ( !aSO->_is_nil() ) {
658 // Update Python script
659 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
666 //=============================================================================
668 * SMESH_Gen_i::CreateEmptyMesh
672 //=============================================================================
674 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
675 throw ( SALOME::SALOME_Exception )
677 Unexpect aCatch(SALOME_SalomeException);
678 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
680 SMESH::SMESH_Mesh_var mesh = this->createMesh();
682 // publish mesh in the study
683 if ( CanPublishInStudy( mesh ) ) {
684 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
685 aStudyBuilder->NewCommand(); // There is a transaction
686 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
687 aStudyBuilder->CommitCommand();
688 if ( !aSO->_is_nil() ) {
689 // Update Python script
690 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
697 //=============================================================================
699 * SMESH_Gen_i::CreateMeshFromUNV
701 * Create mesh and import data from UNV file
703 //=============================================================================
705 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
706 throw ( SALOME::SALOME_Exception )
708 Unexpect aCatch(SALOME_SalomeException);
709 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
711 SMESH::SMESH_Mesh_var aMesh = createMesh();
713 // publish mesh in the study
714 if ( CanPublishInStudy( aMesh ) ) {
715 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
716 aStudyBuilder->NewCommand(); // There is a transaction
717 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
718 aStudyBuilder->CommitCommand();
719 if ( !aSO->_is_nil() ) {
720 // Update Python script
721 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
725 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
727 aServant->ImportUNVFile( theFileName );
729 // Dump creation of groups
730 aServant->GetGroups();
732 return aMesh._retn();
735 //=============================================================================
737 * SMESH_Gen_i::CreateMeshFromMED
739 * Create mesh and import data from MED file
741 //=============================================================================
743 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
744 SMESH::DriverMED_ReadStatus& theStatus)
745 throw ( SALOME::SALOME_Exception )
747 Unexpect aCatch(SALOME_SalomeException);
748 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
750 // Retrieve mesh names from the file
751 DriverMED_R_SMESHDS_Mesh myReader;
752 myReader.SetFile( theFileName );
753 myReader.SetMeshId( -1 );
754 Driver_Mesh::Status aStatus;
755 list<string> aNames = myReader.GetMeshNames(aStatus);
756 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
757 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
759 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
762 TPythonDump aPythonDump;
764 //TCollection_AsciiString aStr ("([");
766 if (theStatus == SMESH::DRS_OK) {
767 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
768 aStudyBuilder->NewCommand(); // There is a transaction
769 aResult->length( aNames.size() );
772 // Iterate through all meshes and create mesh objects
773 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
775 //if (i > 0) aStr += ", ";
776 if (i > 0) aPythonDump << ", ";
779 SMESH::SMESH_Mesh_var mesh = createMesh();
781 // publish mesh in the study
782 SALOMEDS::SObject_var aSO;
783 if ( CanPublishInStudy( mesh ) )
784 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
785 if ( !aSO->_is_nil() ) {
788 //aStr += aSO->GetID();
791 aPythonDump << "mesh_" << i;
793 // aStr += TCollection_AsciiString(i);
796 // Read mesh data (groups are published automatically by ImportMEDFile())
797 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
798 ASSERT( meshServant );
799 SMESH::DriverMED_ReadStatus status1 =
800 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
801 if (status1 > theStatus)
804 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
806 aStudyBuilder->CommitCommand();
809 // Update Python script
810 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
812 // Dump creation of groups
813 for ( int i = 0; i < aResult->length(); ++i )
814 aResult[ i ]->GetGroups();
816 return aResult._retn();
819 //=============================================================================
821 * SMESH_Gen_i::CreateMeshFromSTL
823 * Create mesh and import data from STL file
825 //=============================================================================
827 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
828 throw ( SALOME::SALOME_Exception )
830 Unexpect aCatch(SALOME_SalomeException);
831 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
833 SMESH::SMESH_Mesh_var aMesh = createMesh();
835 // publish mesh in the study
836 if ( CanPublishInStudy( aMesh ) ) {
837 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
838 aStudyBuilder->NewCommand(); // There is a transaction
839 SALOMEDS::SObject_var aSO = PublishInStudy
840 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
841 aStudyBuilder->CommitCommand();
842 if ( !aSO->_is_nil() ) {
843 // Update Python script
844 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
848 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
850 aServant->ImportSTLFile( theFileName );
851 return aMesh._retn();
854 //=============================================================================
856 * SMESH_Gen_i::IsReadyToCompute
858 * Returns true if mesh contains enough data to be computed
860 //=============================================================================
862 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
863 GEOM::GEOM_Object_ptr theShapeObject )
864 throw ( SALOME::SALOME_Exception )
866 Unexpect aCatch(SALOME_SalomeException);
867 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
869 if ( CORBA::is_nil( theShapeObject ) )
870 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
873 if ( CORBA::is_nil( theMesh ) )
874 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
879 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
880 ASSERT( meshServant );
882 // get local TopoDS_Shape
883 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
884 // call implementation
885 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
886 return myGen.CheckAlgoState( myLocMesh, myLocShape );
889 catch ( SALOME_Exception& S_ex ) {
890 INFOS( "catch exception "<< S_ex.what() );
895 //================================================================================
897 * \brief Returns errors of hypotheses definintion
898 * \param theMesh - the mesh
899 * \param theSubObject - the main or sub- shape
900 * \retval SMESH::algo_error_array* - sequence of errors
902 //================================================================================
904 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
905 GEOM::GEOM_Object_ptr theSubObject )
906 throw ( SALOME::SALOME_Exception )
908 Unexpect aCatch(SALOME_SalomeException);
909 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
911 if ( CORBA::is_nil( theSubObject ) )
912 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
914 if ( CORBA::is_nil( theMesh ) )
915 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
917 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
919 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
920 ASSERT( meshServant );
922 TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
923 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
924 list< ::SMESH_Gen::TAlgoStateError > error_list;
925 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
926 // call ::SMESH_Gen::GetAlgoState()
927 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
928 error_array->length( error_list.size() );
930 for ( error = error_list.begin(); error != error_list.end(); ++error )
933 SMESH::AlgoStateErrorName errName;
934 switch ( error->_name ) {
935 case ::SMESH_Gen::MISSING_ALGO: errName = SMESH::MISSING_ALGO; break;
936 case ::SMESH_Gen::MISSING_HYPO: errName = SMESH::MISSING_HYPO; break;
937 case ::SMESH_Gen::NOT_CONFORM_MESH: errName = SMESH::NOT_CONFORM_MESH; break;
938 case ::SMESH_Gen::BAD_PARAM_VALUE: errName = SMESH::BAD_PARAM_VALUE; break;
940 THROW_SALOME_CORBA_EXCEPTION( "bad error name",SALOME::BAD_PARAM );
943 CORBA::String_var algoName = "";
944 if ( error->_algo ) {
945 if ( !myCurrentStudy->_is_nil() ) {
946 // find algo in the study
947 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
948 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
949 if ( !father->_is_nil() ) {
950 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
951 for ( ; itBig->More(); itBig->Next() ) {
952 SALOMEDS::SObject_var gotBranch = itBig->Value();
953 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
954 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
955 for ( ; algoIt->More(); algoIt->Next() ) {
956 SALOMEDS::SObject_var algoSO = algoIt->Value();
957 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
958 if ( !CORBA::is_nil( algoIOR )) {
959 SMESH_Hypothesis_i* myImpl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
960 if ( myImpl && myImpl->GetImpl() == error->_algo ) {
961 algoName = algoSO->GetName();
965 } // loop on algo SO's
968 } // SMESH component iterator
971 if ( algoName.in() == 0 )
972 // use algo type name
973 algoName = error->_algo->GetName();
975 // fill AlgoStateError structure
976 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
977 errStruct.name = errName;
978 errStruct.algoName = algoName;
979 errStruct.algoDim = error->_algoDim;
980 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
984 catch ( SALOME_Exception& S_ex ) {
985 INFOS( "catch exception "<< S_ex.what() );
987 return error_array._retn();
990 //=============================================================================
992 * SMESH_Gen_i::GetSubShapesId
994 * Get sub-shapes unique ID's list
996 //=============================================================================
998 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
999 const SMESH::object_array& theListOfSubShapeObject )
1000 throw ( SALOME::SALOME_Exception )
1002 Unexpect aCatch(SALOME_SalomeException);
1003 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1005 SMESH::long_array_var shapesId = new SMESH::long_array;
1008 if ( CORBA::is_nil( theMainShapeObject ) )
1009 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1010 SALOME::BAD_PARAM );
1014 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1015 TopTools_IndexedMapOfShape myIndexToShape;
1016 TopExp::MapShapes(myMainShape,myIndexToShape);
1018 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1020 GEOM::GEOM_Object_var aShapeObject
1021 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1022 if ( CORBA::is_nil( aShapeObject ) )
1023 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1024 SALOME::BAD_PARAM );
1026 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1027 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1029 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1030 setId.insert(myIndexToShape.FindIndex(F));
1031 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1033 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1035 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1036 setId.insert(myIndexToShape.FindIndex(E));
1037 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1039 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1041 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1042 setId.insert(myIndexToShape.FindIndex(V));
1043 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1046 shapesId->length(setId.size());
1047 set<int>::iterator iind;
1049 for (iind = setId.begin(); iind != setId.end(); iind++)
1051 if(MYDEBUG) SCRUTE((*iind));
1052 shapesId[i] = (*iind);
1053 if(MYDEBUG) SCRUTE(shapesId[i]);
1057 catch (SALOME_Exception& S_ex)
1059 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1062 return shapesId._retn();
1065 //=============================================================================
1067 * SMESH_Gen_i::Compute
1069 * Compute mesh on a shape
1071 //=============================================================================
1073 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1074 GEOM::GEOM_Object_ptr theShapeObject )
1075 throw ( SALOME::SALOME_Exception )
1077 Unexpect aCatch(SALOME_SalomeException);
1078 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1080 if ( CORBA::is_nil( theShapeObject ) )
1081 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1082 SALOME::BAD_PARAM );
1084 if ( CORBA::is_nil( theMesh ) )
1085 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1086 SALOME::BAD_PARAM );
1088 // Update Python script
1089 TPythonDump() << "isDone = " << this << ".Compute( "
1090 << theMesh << ", " << theShapeObject << ")";
1091 TPythonDump() << "if not isDone: print 'Mesh', " << theMesh << ", ': computation failed'";
1095 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1096 ASSERT( meshServant );
1097 if ( meshServant ) {
1098 // get local TopoDS_Shape
1099 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1100 // call implementation compute
1101 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1102 return myGen.Compute( myLocMesh, myLocShape);
1105 catch ( std::bad_alloc& exc ) {
1106 THROW_SALOME_CORBA_EXCEPTION( "Memory allocation problem",
1107 SALOME::INTERNAL_ERROR );
1109 catch ( SALOME_Exception& S_ex ) {
1110 INFOS( "Compute(): catch exception "<< S_ex.what() );
1113 INFOS( "Compute(): unknown exception " );
1118 //================================================================================
1120 * \brief Return geometrical object the given element is built on
1121 * \param theMesh - the mesh the element is in
1122 * \param theElementID - the element ID
1123 * \param theGeomName - the name of the result geom object if it is not yet published
1124 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1126 //================================================================================
1128 GEOM::GEOM_Object_ptr
1129 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1130 CORBA::Long theElementID,
1131 const char* theGeomName)
1132 throw ( SALOME::SALOME_Exception )
1134 Unexpect aCatch(SALOME_SalomeException);
1136 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
1137 if ( !geom->_is_nil() ) {
1138 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1139 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1141 // try to find the corresponding SObject
1142 GeomObjectToShape( geom ); // geom client remembers the found shape
1143 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1144 if ( SObj->_is_nil() )
1145 // publish a new subshape
1146 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1147 // return only published geometry
1148 if ( !SObj->_is_nil() )
1149 return geom._retn();
1151 return GEOM::GEOM_Object::_nil();
1154 //================================================================================
1156 * SMESH_Gen_i::Concatenate
1158 * Concatenate the given meshes into one mesh
1160 //================================================================================
1162 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
1163 CORBA::Boolean theUniteIdenticalGroups,
1164 CORBA::Boolean theMergeNodesAndElements,
1165 CORBA::Double theMergeTolerance)
1166 throw ( SALOME::SALOME_Exception )
1168 typedef map<int, int> TIDsMap;
1169 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
1170 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
1171 typedef std::set<SMESHDS_GroupBase*> TGroups;
1174 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
1176 // to update Python script
1177 TPythonDump aPythonDump;
1179 if ( !aNewMesh->_is_nil() ) {
1180 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
1182 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
1183 SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
1185 TGroupsMap aGroupsMap;
1186 TListOfNewGroups aListOfNewGroups;
1187 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
1188 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
1191 for ( int i = 0; i < theMeshesArray.length(); i++) {
1192 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
1193 if ( !anInitMesh->_is_nil() ) {
1194 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
1196 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
1197 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
1202 // loop on elements of mesh
1203 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
1204 const SMDS_MeshElement* anElem = 0;
1205 const SMDS_MeshElement* aNewElem = 0;
1206 int anElemNbNodes = 0;
1208 for ( int j = 0; itElems->more(); j++) {
1209 anElem = itElems->next();
1210 SMDSAbs_ElementType anElemType = anElem->GetType();
1211 anElemNbNodes = anElem->NbNodes();
1212 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
1214 // loop on nodes of element
1215 const SMDS_MeshNode* aNode = 0;
1216 const SMDS_MeshNode* aNewNode = 0;
1217 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
1219 for ( int k = 0; itNodes->more(); k++) {
1220 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
1221 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
1222 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
1223 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
1226 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
1227 aNodesArray[k] = aNewNode;
1230 // creates a corresponding element on existent nodes in new mesh
1231 if ( anElem->IsPoly() && anElemType == SMDSAbs_Volume )
1233 const SMDS_PolyhedralVolumeOfNodes* aVolume =
1234 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
1236 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
1237 aVolume->GetQuanities());
1238 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1243 aNewElem = aNewEditor.AddElement(aNodesArray,
1246 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1250 aListOfGroups = anInitImpl->GetGroups();
1251 SMESH::SMESH_GroupBase_ptr aGroup;
1253 // loop on groups of mesh
1254 SMESH::long_array_var anInitIDs = new SMESH::long_array();
1255 SMESH::long_array_var anNewIDs = new SMESH::long_array();
1256 SMESH::SMESH_Group_var aNewGroup;
1257 for (int i = 0; i < aListOfGroups->length(); i++) {
1258 aGroup = aListOfGroups[i];
1259 aListOfNewGroups.clear();
1260 SMESH::ElementType aGroupType = aGroup->GetType();
1261 CORBA::String_var aGroupName = aGroup->GetName();
1263 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
1265 // convert a list of IDs
1266 anInitIDs = aGroup->GetListOfID();
1267 anNewIDs->length(anInitIDs->length());
1268 if ( aGroupType == SMESH::NODE )
1269 for (int j = 0; j < anInitIDs->length(); j++) {
1270 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
1273 for (int j = 0; j < anInitIDs->length(); j++) {
1274 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
1277 // check that current group name and type don't have identical ones in union mesh
1278 if ( anIter == aGroupsMap.end() ) {
1279 // add a new group in the mesh
1280 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1281 // add elements into new group
1282 aNewGroup->Add( anNewIDs );
1284 aListOfNewGroups.push_back(aNewGroup);
1285 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
1288 else if ( theUniteIdenticalGroups ) {
1289 // unite identical groups
1290 TListOfNewGroups& aNewGroups = anIter->second;
1291 aNewGroups.front()->Add( anNewIDs );
1295 // rename identical groups
1296 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1297 aNewGroup->Add( anNewIDs );
1299 TListOfNewGroups& aNewGroups = anIter->second;
1300 string aNewGroupName;
1301 if (aNewGroups.size() == 1) {
1302 aNewGroupName = string(aGroupName) + "_1";
1303 aNewGroups.front()->SetName(aNewGroupName.c_str());
1305 char aGroupNum[128];
1306 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
1307 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
1308 aNewGroup->SetName(aNewGroupName.c_str());
1309 aNewGroups.push_back(aNewGroup);
1316 if (theMergeNodesAndElements) {
1318 set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
1319 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
1320 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
1321 aNewEditor.MergeNodes( aGroupsOfNodes );
1323 aNewEditor.MergeEqualElements();
1328 // Update Python script
1329 RemoveLastFromPythonScript( GetCurrentStudyID() );
1330 aPythonDump << aNewMesh << " = " << this << ".Concatenate(";
1332 for ( int i = 0; i < theMeshesArray.length(); i++) {
1333 if (i > 0) aPythonDump << ", ";
1334 aPythonDump << theMeshesArray[i];
1336 aPythonDump << "], ";
1337 aPythonDump << theUniteIdenticalGroups << ", "
1338 << theMergeNodesAndElements << ", "
1339 << theMergeTolerance << ")";
1341 return aNewMesh._retn();
1344 //================================================================================
1346 * \brief Return geometrical object the given element is built on.
1347 * \param theMesh - the mesh the element is in
1348 * \param theElementID - the element ID
1349 * \retval GEOM::GEOM_Object_ptr - the found geom object
1351 //================================================================================
1353 GEOM::GEOM_Object_ptr
1354 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1355 CORBA::Long theElementID)
1356 throw ( SALOME::SALOME_Exception )
1358 Unexpect aCatch(SALOME_SalomeException);
1359 if ( CORBA::is_nil( theMesh ) )
1360 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1362 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1363 GEOM::GEOM_Gen_var geomGen = GetGeomEngine();
1365 // get a core mesh DS
1366 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1367 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1369 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1370 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1371 // find the element in mesh
1372 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
1373 // find a shape id by the element
1374 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1375 // get a geom object by the shape id
1376 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1377 if ( geom->_is_nil() ) {
1378 GEOM::GEOM_IShapesOperations_var op =
1379 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1380 if ( !op->_is_nil() )
1381 geom = op->GetSubShape( mainShape, shapeID );
1383 if ( !geom->_is_nil() )
1384 return geom._retn();
1387 return GEOM::GEOM_Object::_nil();
1390 //=============================================================================
1394 * Save SMESH module's data
1396 //=============================================================================
1397 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1401 INFOS( "SMESH_Gen_i::Save" );
1403 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1404 // san -- in case <myCurrentStudy> differs from theComponent's study,
1405 // use that of the component
1406 if ( myCurrentStudy->_is_nil() ||
1407 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1408 SetCurrentStudy( theComponent->GetStudy() );
1410 // Store study contents as a set of python commands
1411 SavePython(myCurrentStudy);
1413 StudyContext* myStudyContext = GetCurrentStudyContext();
1415 // Declare a byte stream
1416 SALOMEDS::TMPFile_var aStreamFile;
1418 // Obtain a temporary dir
1419 TCollection_AsciiString tmpDir =
1420 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1422 // Create a sequence of files processed
1423 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1424 aFileSeq->length( NUM_TMP_FILES );
1426 TCollection_AsciiString aStudyName( "" );
1428 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1430 // Set names of temporary files
1431 TCollection_AsciiString filename =
1432 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1433 TCollection_AsciiString meshfile =
1434 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1435 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1436 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1437 filename = tmpDir + filename;
1438 meshfile = tmpDir + meshfile;
1441 HDFdataset* aDataset;
1442 HDFgroup* aTopGroup;
1444 HDFgroup* aSubGroup;
1445 HDFgroup* aSubSubGroup;
1446 hdf_size aSize[ 1 ];
1449 //Remove the files if they exist: BugID: 11225
1450 TCollection_AsciiString cmd("rm -f \"");
1455 system(cmd.ToCString());
1457 // MED writer to be used by storage process
1458 DriverMED_W_SMESHDS_Mesh myWriter;
1459 myWriter.SetFile( meshfile.ToCString() );
1462 // ---> create HDF file
1463 aFile = new HDFfile( filename.ToCString() );
1464 aFile->CreateOnDisk();
1466 // --> iterator for top-level objects
1467 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1468 for ( ; itBig->More(); itBig->Next() ) {
1469 SALOMEDS::SObject_var gotBranch = itBig->Value();
1471 // --> hypotheses root branch (only one for the study)
1472 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1473 // create hypotheses root HDF group
1474 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1475 aTopGroup->CreateOnDisk();
1477 // iterator for all hypotheses
1478 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1479 for ( ; it->More(); it->Next() ) {
1480 SALOMEDS::SObject_var mySObject = it->Value();
1481 CORBA::Object_var anObject = SObjectToObject( mySObject );
1482 if ( !CORBA::is_nil( anObject ) ) {
1483 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1484 if ( !myHyp->_is_nil() ) {
1485 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1487 string hypname = string( myHyp->GetName() );
1488 string libname = string( myHyp->GetLibName() );
1489 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1490 string hypdata = string( myImpl->SaveTo() );
1492 // for each hypothesis create HDF group basing on its id
1493 char hypGrpName[30];
1494 sprintf( hypGrpName, "Hypothesis %d", id );
1495 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1496 aGroup->CreateOnDisk();
1497 // --> type name of hypothesis
1498 aSize[ 0 ] = hypname.length() + 1;
1499 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1500 aDataset->CreateOnDisk();
1501 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1502 aDataset->CloseOnDisk();
1503 // --> server plugin library name of hypothesis
1504 aSize[ 0 ] = libname.length() + 1;
1505 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1506 aDataset->CreateOnDisk();
1507 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1508 aDataset->CloseOnDisk();
1509 // --> persistent data of hypothesis
1510 aSize[ 0 ] = hypdata.length() + 1;
1511 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1512 aDataset->CreateOnDisk();
1513 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1514 aDataset->CloseOnDisk();
1515 // close hypothesis HDF group
1516 aGroup->CloseOnDisk();
1521 // close hypotheses root HDF group
1522 aTopGroup->CloseOnDisk();
1524 // --> algorithms root branch (only one for the study)
1525 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1526 // create algorithms root HDF group
1527 aTopGroup = new HDFgroup( "Algorithms", aFile );
1528 aTopGroup->CreateOnDisk();
1530 // iterator for all algorithms
1531 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1532 for ( ; it->More(); it->Next() ) {
1533 SALOMEDS::SObject_var mySObject = it->Value();
1534 CORBA::Object_var anObject = SObjectToObject( mySObject );
1535 if ( !CORBA::is_nil( anObject ) ) {
1536 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1537 if ( !myHyp->_is_nil() ) {
1538 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1540 string hypname = string( myHyp->GetName() );
1541 string libname = string( myHyp->GetLibName() );
1542 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1543 string hypdata = string( myImpl->SaveTo() );
1545 // for each algorithm create HDF group basing on its id
1546 char hypGrpName[30];
1547 sprintf( hypGrpName, "Algorithm %d", id );
1548 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1549 aGroup->CreateOnDisk();
1550 // --> type name of algorithm
1551 aSize[0] = hypname.length() + 1;
1552 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1553 aDataset->CreateOnDisk();
1554 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1555 aDataset->CloseOnDisk();
1556 // --> server plugin library name of hypothesis
1557 aSize[0] = libname.length() + 1;
1558 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1559 aDataset->CreateOnDisk();
1560 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1561 aDataset->CloseOnDisk();
1562 // --> persistent data of algorithm
1563 aSize[0] = hypdata.length() + 1;
1564 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1565 aDataset->CreateOnDisk();
1566 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1567 aDataset->CloseOnDisk();
1568 // close algorithm HDF group
1569 aGroup->CloseOnDisk();
1574 // close algorithms root HDF group
1575 aTopGroup->CloseOnDisk();
1577 // --> mesh objects roots branches
1578 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1579 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1580 if ( !CORBA::is_nil( anObject ) ) {
1581 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1582 if ( !myMesh->_is_nil() ) {
1583 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1585 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1586 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1587 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1589 // for each mesh open the HDF group basing on its id
1590 char meshGrpName[ 30 ];
1591 sprintf( meshGrpName, "Mesh %d", id );
1592 aTopGroup = new HDFgroup( meshGrpName, aFile );
1593 aTopGroup->CreateOnDisk();
1595 // --> put dataset to hdf file which is a flag that mesh has data
1596 string strHasData = "0";
1597 // check if the mesh is not empty
1598 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1599 // write mesh data to med file
1600 myWriter.SetMesh( mySMESHDSMesh );
1601 myWriter.SetMeshId( id );
1604 aSize[ 0 ] = strHasData.length() + 1;
1605 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1606 aDataset->CreateOnDisk();
1607 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1608 aDataset->CloseOnDisk();
1610 // write reference on a shape if exists
1611 SALOMEDS::SObject_var myRef;
1612 bool shapeRefFound = false;
1613 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1615 SALOMEDS::SObject_var myShape;
1616 bool ok = myRef->ReferencedObject( myShape );
1618 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1619 string myRefOnObject = myShape->GetID();
1620 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1621 aSize[ 0 ] = myRefOnObject.length() + 1;
1622 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1623 aDataset->CreateOnDisk();
1624 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1625 aDataset->CloseOnDisk();
1630 // write applied hypotheses if exist
1631 SALOMEDS::SObject_var myHypBranch;
1632 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1633 if ( found && !shapeRefFound ) { // remove applied hyps
1634 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1636 if ( found && shapeRefFound ) {
1637 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1638 aGroup->CreateOnDisk();
1640 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1642 for ( ; it->More(); it->Next() ) {
1643 SALOMEDS::SObject_var mySObject = it->Value();
1644 SALOMEDS::SObject_var myRefOnHyp;
1645 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1647 // san - it is impossible to recover applied hypotheses
1648 // using their entries within Load() method,
1649 // for there are no AttributeIORs in the study when Load() is working.
1650 // Hence, it is better to store persistent IDs of hypotheses as references to them
1652 //string myRefOnObject = myRefOnHyp->GetID();
1653 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1654 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1655 //if ( myRefOnObject.length() > 0 ) {
1656 //aSize[ 0 ] = myRefOnObject.length() + 1;
1657 char hypName[ 30 ], hypId[ 30 ];
1658 sprintf( hypName, "Hyp %d", ++hypNb );
1659 sprintf( hypId, "%d", id );
1660 aSize[ 0 ] = strlen( hypId ) + 1;
1661 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1662 aDataset->CreateOnDisk();
1663 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1664 aDataset->WriteOnDisk( hypId );
1665 aDataset->CloseOnDisk();
1669 aGroup->CloseOnDisk();
1672 // write applied algorithms if exist
1673 SALOMEDS::SObject_var myAlgoBranch;
1674 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1675 if ( found && !shapeRefFound ) { // remove applied algos
1676 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1678 if ( found && shapeRefFound ) {
1679 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1680 aGroup->CreateOnDisk();
1682 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1684 for ( ; it->More(); it->Next() ) {
1685 SALOMEDS::SObject_var mySObject = it->Value();
1686 SALOMEDS::SObject_var myRefOnAlgo;
1687 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1689 // san - it is impossible to recover applied algorithms
1690 // using their entries within Load() method,
1691 // for there are no AttributeIORs in the study when Load() is working.
1692 // Hence, it is better to store persistent IDs of algorithms as references to them
1694 //string myRefOnObject = myRefOnAlgo->GetID();
1695 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1696 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1697 //if ( myRefOnObject.length() > 0 ) {
1698 //aSize[ 0 ] = myRefOnObject.length() + 1;
1699 char algoName[ 30 ], algoId[ 30 ];
1700 sprintf( algoName, "Algo %d", ++algoNb );
1701 sprintf( algoId, "%d", id );
1702 aSize[ 0 ] = strlen( algoId ) + 1;
1703 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1704 aDataset->CreateOnDisk();
1705 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1706 aDataset->WriteOnDisk( algoId );
1707 aDataset->CloseOnDisk();
1711 aGroup->CloseOnDisk();
1714 // --> submesh objects sub-branches
1716 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1717 SALOMEDS::SObject_var mySubmeshBranch;
1718 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1720 if ( found ) // check if there is shape reference in submeshes
1722 bool hasShapeRef = false;
1723 SALOMEDS::ChildIterator_var itSM =
1724 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1725 for ( ; itSM->More(); itSM->Next() ) {
1726 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1727 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1728 mySubRef->ReferencedObject( myShape );
1729 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1732 { // remove one submesh
1733 if ( shapeRefFound )
1734 { // unassign hypothesis
1735 SMESH::SMESH_subMesh_var mySubMesh =
1736 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1737 if ( !mySubMesh->_is_nil() ) {
1738 int shapeID = mySubMesh->GetId();
1739 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1740 const list<const SMESHDS_Hypothesis*>& hypList =
1741 mySMESHDSMesh->GetHypothesis( S );
1742 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1743 while ( hyp != hypList.end() ) {
1744 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1745 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1749 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1751 } // loop on submeshes of a type
1752 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1753 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1756 } // end check if there is shape reference in submeshes
1758 char name_meshgroup[ 30 ];
1759 if ( i == GetSubMeshOnVertexTag() )
1760 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1761 else if ( i == GetSubMeshOnEdgeTag() )
1762 strcpy( name_meshgroup, "SubMeshes On Edge" );
1763 else if ( i == GetSubMeshOnWireTag() )
1764 strcpy( name_meshgroup, "SubMeshes On Wire" );
1765 else if ( i == GetSubMeshOnFaceTag() )
1766 strcpy( name_meshgroup, "SubMeshes On Face" );
1767 else if ( i == GetSubMeshOnShellTag() )
1768 strcpy( name_meshgroup, "SubMeshes On Shell" );
1769 else if ( i == GetSubMeshOnSolidTag() )
1770 strcpy( name_meshgroup, "SubMeshes On Solid" );
1771 else if ( i == GetSubMeshOnCompoundTag() )
1772 strcpy( name_meshgroup, "SubMeshes On Compound" );
1774 // for each type of submeshes create container HDF group
1775 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1776 aGroup->CreateOnDisk();
1778 // iterator for all submeshes of given type
1779 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1780 for ( ; itSM->More(); itSM->Next() ) {
1781 SALOMEDS::SObject_var mySObject = itSM->Value();
1782 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1783 if ( !CORBA::is_nil( anSubObject ))
1785 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1786 int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) );
1788 // for each mesh open the HDF group basing on its id
1789 char submeshGrpName[ 30 ];
1790 sprintf( submeshGrpName, "SubMesh %d", subid );
1791 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1792 aSubGroup->CreateOnDisk();
1794 // write reference on a shape, already checked if it exists
1795 SALOMEDS::SObject_var mySubRef, myShape;
1796 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1797 mySubRef->ReferencedObject( myShape );
1798 string myRefOnObject = myShape->GetID();
1799 if ( myRefOnObject.length() > 0 ) {
1800 aSize[ 0 ] = myRefOnObject.length() + 1;
1801 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1802 aDataset->CreateOnDisk();
1803 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1804 aDataset->CloseOnDisk();
1807 // write applied hypotheses if exist
1808 SALOMEDS::SObject_var mySubHypBranch;
1809 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1811 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1812 aSubSubGroup->CreateOnDisk();
1814 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1816 for ( ; it->More(); it->Next() ) {
1817 SALOMEDS::SObject_var mySubSObject = it->Value();
1818 SALOMEDS::SObject_var myRefOnHyp;
1819 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1821 //string myRefOnObject = myRefOnHyp->GetID();
1822 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1823 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1824 //if ( myRefOnObject.length() > 0 ) {
1825 //aSize[ 0 ] = myRefOnObject.length() + 1;
1826 char hypName[ 30 ], hypId[ 30 ];
1827 sprintf( hypName, "Hyp %d", ++hypNb );
1828 sprintf( hypId, "%d", id );
1829 aSize[ 0 ] = strlen( hypId ) + 1;
1830 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1831 aDataset->CreateOnDisk();
1832 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1833 aDataset->WriteOnDisk( hypId );
1834 aDataset->CloseOnDisk();
1838 aSubSubGroup->CloseOnDisk();
1841 // write applied algorithms if exist
1842 SALOMEDS::SObject_var mySubAlgoBranch;
1843 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1845 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1846 aSubSubGroup->CreateOnDisk();
1848 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1850 for ( ; it->More(); it->Next() ) {
1851 SALOMEDS::SObject_var mySubSObject = it->Value();
1852 SALOMEDS::SObject_var myRefOnAlgo;
1853 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1855 //string myRefOnObject = myRefOnAlgo->GetID();
1856 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1857 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1858 //if ( myRefOnObject.length() > 0 ) {
1859 //aSize[ 0 ] = myRefOnObject.length() + 1;
1860 char algoName[ 30 ], algoId[ 30 ];
1861 sprintf( algoName, "Algo %d", ++algoNb );
1862 sprintf( algoId, "%d", id );
1863 aSize[ 0 ] = strlen( algoId ) + 1;
1864 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1865 aDataset->CreateOnDisk();
1866 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1867 aDataset->WriteOnDisk( algoId );
1868 aDataset->CloseOnDisk();
1872 aSubSubGroup->CloseOnDisk();
1874 // close submesh HDF group
1875 aSubGroup->CloseOnDisk();
1878 // close container of submeshes by type HDF group
1879 aGroup->CloseOnDisk();
1882 // All sub-meshes will be stored in MED file
1883 // .. will NOT (PAL 12992)
1884 //if ( shapeRefFound )
1885 //myWriter.AddAllSubMeshes();
1887 // groups root sub-branch
1888 SALOMEDS::SObject_var myGroupsBranch;
1889 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1890 found = gotBranch->FindSubObject( i, myGroupsBranch );
1892 char name_group[ 30 ];
1893 if ( i == GetNodeGroupsTag() )
1894 strcpy( name_group, "Groups of Nodes" );
1895 else if ( i == GetEdgeGroupsTag() )
1896 strcpy( name_group, "Groups of Edges" );
1897 else if ( i == GetFaceGroupsTag() )
1898 strcpy( name_group, "Groups of Faces" );
1899 else if ( i == GetVolumeGroupsTag() )
1900 strcpy( name_group, "Groups of Volumes" );
1902 aGroup = new HDFgroup( name_group, aTopGroup );
1903 aGroup->CreateOnDisk();
1905 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
1906 for ( ; it->More(); it->Next() ) {
1907 SALOMEDS::SObject_var mySObject = it->Value();
1908 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
1909 if ( !CORBA::is_nil( aSubObject ) ) {
1910 SMESH_GroupBase_i* myGroupImpl =
1911 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
1915 int anId = myStudyContext->findId( string( GetORB()->object_to_string( aSubObject ) ) );
1917 // For each group, create a dataset named "Group <group_persistent_id>"
1918 // and store the group's user name into it
1920 sprintf( grpName, "Group %d", anId );
1921 char* aUserName = myGroupImpl->GetName();
1922 aSize[ 0 ] = strlen( aUserName ) + 1;
1924 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
1925 aDataset->CreateOnDisk();
1926 aDataset->WriteOnDisk( aUserName );
1927 aDataset->CloseOnDisk();
1929 // Store the group contents into MED file
1930 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
1932 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
1933 << grpName << " to MED file" );
1934 SMESHDS_GroupBase* aGrpBaseDS =
1935 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
1936 aGrpBaseDS->SetStoreName( grpName );
1938 // Pass SMESHDS_Group to MED writer
1939 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
1941 myWriter.AddGroup( aGrpDS );
1943 // write reference on a shape if exists
1944 SMESHDS_GroupOnGeom* aGeomGrp =
1945 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
1947 SALOMEDS::SObject_var mySubRef, myShape;
1948 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
1949 mySubRef->ReferencedObject( myShape ) &&
1950 !CORBA::is_nil( myShape->GetObject() ))
1952 string myRefOnObject = myShape->GetID();
1953 if ( myRefOnObject.length() > 0 ) {
1954 char aRefName[ 30 ];
1955 sprintf( aRefName, "Ref on shape %d", anId);
1956 aSize[ 0 ] = myRefOnObject.length() + 1;
1957 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
1958 aDataset->CreateOnDisk();
1959 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1960 aDataset->CloseOnDisk();
1963 else // shape ref is invalid:
1965 // save a group on geometry as ordinary group
1966 myWriter.AddGroup( aGeomGrp );
1972 aGroup->CloseOnDisk();
1976 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
1978 // Flush current mesh information into MED file
1981 // maybe a shape was deleted in the study
1982 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
1983 TopoDS_Shape nullShape;
1984 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
1987 if ( !mySMESHDSMesh->SubMeshes().empty() )
1991 aGroup = new HDFgroup( "Submeshes", aTopGroup );
1992 aGroup->CreateOnDisk();
1994 // each element belongs to one or none submesh,
1995 // so for each node/element, we store a submesh ID
1997 // Make maps of submesh IDs of elements sorted by element IDs
1998 typedef int TElemID;
1999 typedef int TSubMID;
2000 map< TElemID, TSubMID > eId2smId, nId2smId;
2001 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
2002 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
2003 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
2004 SMDS_NodeIteratorPtr itNode;
2005 SMDS_ElemIteratorPtr itElem;
2006 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2008 TSubMID aSubMeID = itSubM->first;
2009 SMESHDS_SubMesh* aSubMesh = itSubM->second;
2010 if ( aSubMesh->IsComplexSubmesh() )
2011 continue; // submesh containing other submeshs
2013 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
2014 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
2015 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
2017 hint = eId2smId.begin();
2018 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
2019 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
2022 // Care of elements that are not on submeshes
2023 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
2024 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
2025 /* --- stl_map.h says : */
2026 /* A %map relies on unique keys and thus a %pair is only inserted if its */
2027 /* first element (the key) is not already present in the %map. */
2028 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
2030 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
2031 if ( nbElems != eId2smId.size() ) {
2032 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
2033 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
2036 // Store submesh IDs
2037 for ( int isNode = 0; isNode < 2; ++isNode )
2039 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
2040 if ( id2smId.empty() ) continue;
2041 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
2042 // make and fill array of submesh IDs
2043 int* smIDs = new int [ id2smId.size() ];
2044 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
2045 smIDs[ i ] = id_smId->second;
2047 aSize[ 0 ] = id2smId.size();
2048 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2049 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2050 aDataset->CreateOnDisk();
2051 aDataset->WriteOnDisk( smIDs );
2052 aDataset->CloseOnDisk();
2057 // Store node positions on sub-shapes (SMDS_Position):
2058 // ----------------------------------------------------
2060 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2061 aGroup->CreateOnDisk();
2063 // in aGroup, create 5 datasets to contain:
2064 // "Nodes on Edges" - ID of node on edge
2065 // "Edge positions" - U parameter on node on edge
2066 // "Nodes on Faces" - ID of node on face
2067 // "Face U positions" - U parameter of node on face
2068 // "Face V positions" - V parameter of node on face
2070 // Find out nb of nodes on edges and faces
2071 // Collect corresponing sub-meshes
2072 int nbEdgeNodes = 0, nbFaceNodes = 0;
2073 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
2074 // loop on SMESHDS_SubMesh'es
2075 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2077 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
2078 if ( aSubMesh->IsComplexSubmesh() )
2079 continue; // submesh containing other submeshs
2080 int nbNodes = aSubMesh->NbNodes();
2081 if ( nbNodes == 0 ) continue;
2083 int aShapeID = (*itSubM).first;
2084 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
2085 // write only SMDS_FacePosition and SMDS_EdgePosition
2086 switch ( aShapeType ) {
2088 nbFaceNodes += nbNodes;
2089 aFaceSM.push_back( aSubMesh );
2092 nbEdgeNodes += nbNodes;
2093 aEdgeSM.push_back( aSubMesh );
2099 // Treat positions on edges or faces
2100 for ( int onFace = 0; onFace < 2; onFace++ )
2102 // Create arrays to store in datasets
2103 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
2104 if (!nbNodes) continue;
2105 int* aNodeIDs = new int [ nbNodes ];
2106 double* aUPos = new double [ nbNodes ];
2107 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
2110 // loop on sub-meshes
2111 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
2112 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
2113 for ( ; itSM != pListSM->end(); itSM++ )
2115 SMESHDS_SubMesh* aSubMesh = (*itSM);
2117 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
2118 // loop on nodes in aSubMesh
2119 while ( itNode->more() )
2122 const SMDS_MeshNode* node = itNode->next();
2123 aNodeIDs [ iNode ] = node->GetID();
2126 const SMDS_PositionPtr pos = node->GetPosition();
2127 if ( onFace ) { // on FACE
2128 const SMDS_FacePosition* fPos =
2129 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
2131 aUPos[ iNode ] = fPos->GetUParameter();
2132 aVPos[ iNode ] = fPos->GetVParameter();
2139 const SMDS_EdgePosition* ePos =
2140 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
2142 aUPos[ iNode ] = ePos->GetUParameter();
2148 } // loop on nodes in aSubMesh
2149 } // loop on sub-meshes
2154 aSize[ 0 ] = nbNodes;
2156 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
2157 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2158 aDataset->CreateOnDisk();
2159 aDataset->WriteOnDisk( aNodeIDs );
2160 aDataset->CloseOnDisk();
2163 aDSName = ( onFace ? "Face U positions" : "Edge positions");
2164 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
2165 aDataset->CreateOnDisk();
2166 aDataset->WriteOnDisk( aUPos );
2167 aDataset->CloseOnDisk();
2170 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
2171 aDataset->CreateOnDisk();
2172 aDataset->WriteOnDisk( aVPos );
2173 aDataset->CloseOnDisk();
2178 if ( aVPos ) delete [] aVPos;
2180 } // treat positions on edges or faces
2182 // close "Node Positions" group
2183 aGroup->CloseOnDisk();
2185 } // if ( there are submeshes in SMESHDS_Mesh )
2188 // close mesh HDF group
2189 aTopGroup->CloseOnDisk();
2197 aFile->CloseOnDisk();
2200 // Convert temporary files to stream
2201 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
2203 // Remove temporary files and directory
2205 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2207 INFOS( "SMESH_Gen_i::Save() completed" );
2208 return aStreamFile._retn();
2211 //=============================================================================
2213 * SMESH_Gen_i::SaveASCII
2215 * Save SMESH module's data in ASCII format (not implemented yet)
2217 //=============================================================================
2219 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2221 bool isMultiFile ) {
2222 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2223 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2224 return aStreamFile._retn();
2227 //=============================================================================
2229 * SMESH_Gen_i::loadGeomData
2231 * Load GEOM module data
2233 //=============================================================================
2235 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2237 if ( theCompRoot->_is_nil() )
2240 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2241 if ( aStudy->_is_nil() )
2244 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2245 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2247 //=============================================================================
2249 * \brief Creates SMDS_Position according to shape type
2251 //=============================================================================
2253 class PositionCreator {
2255 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
2256 return (this->*myFuncTable[ type ])();
2259 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
2260 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
2261 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
2262 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
2265 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
2266 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
2267 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
2268 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
2269 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
2270 vector<FmakePos> myFuncTable;
2273 //=============================================================================
2277 * Load SMESH module's data
2279 //=============================================================================
2281 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2282 const SALOMEDS::TMPFile& theStream,
2286 INFOS( "SMESH_Gen_i::Load" );
2288 if ( myCurrentStudy->_is_nil() ||
2289 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2290 SetCurrentStudy( theComponent->GetStudy() );
2292 /* if( !theComponent->_is_nil() )
2294 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2295 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2296 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2299 StudyContext* myStudyContext = GetCurrentStudyContext();
2301 // Get temporary files location
2302 TCollection_AsciiString tmpDir =
2303 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2305 // Convert the stream into sequence of files to process
2306 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2309 TCollection_AsciiString aStudyName( "" );
2311 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2313 // Set names of temporary files
2314 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2315 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2319 HDFdataset* aDataset;
2320 HDFgroup* aTopGroup;
2322 HDFgroup* aSubGroup;
2323 HDFgroup* aSubSubGroup;
2326 // ---> open HDF file
2327 aFile = new HDFfile( filename.ToCString() );
2329 aFile->OpenOnDisk( HDF_RDONLY );
2331 catch ( HDFexception ) {
2332 INFOS( "Load(): " << filename << " not found!" );
2336 DriverMED_R_SMESHDS_Mesh myReader;
2337 myReader.SetFile( meshfile.ToCString() );
2339 // For PAL13473 ("Repetitive mesh") implementation.
2340 // New dependencies between SMESH objects are established:
2341 // now hypotheses can refer to meshes, shapes and other hypotheses.
2342 // To keep data consistent, the following order of data restoration
2344 // 1. Create hypotheses
2345 // 2. Create all meshes
2346 // 3. Load hypotheses' data
2349 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
2350 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
2352 // get total number of top-level groups
2353 int aNbGroups = aFile->nInternalObjects();
2354 if ( aNbGroups > 0 ) {
2355 // --> in first turn we should read&create hypotheses
2356 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2357 // open hypotheses root HDF group
2358 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2359 aTopGroup->OpenOnDisk();
2361 // get number of hypotheses
2362 int aNbObjects = aTopGroup->nInternalObjects();
2363 for ( int j = 0; j < aNbObjects; j++ ) {
2364 // try to identify hypothesis
2365 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2366 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2368 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2369 // open hypothesis group
2370 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2371 aGroup->OpenOnDisk();
2373 // --> get hypothesis id
2374 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2379 // get number of datasets
2380 int aNbSubObjects = aGroup->nInternalObjects();
2381 for ( int k = 0; k < aNbSubObjects; k++ ) {
2383 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2384 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2385 // --> get hypothesis name
2386 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2387 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2388 aDataset->OpenOnDisk();
2389 size = aDataset->GetSize();
2390 char* hypname_str = new char[ size ];
2391 aDataset->ReadFromDisk( hypname_str );
2392 hypname = string( hypname_str );
2393 delete [] hypname_str;
2394 aDataset->CloseOnDisk();
2396 // --> get hypothesis plugin library name
2397 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2398 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2399 aDataset->OpenOnDisk();
2400 size = aDataset->GetSize();
2401 char* libname_str = new char[ size ];
2402 aDataset->ReadFromDisk( libname_str );
2403 if(MYDEBUG) SCRUTE( libname_str );
2404 libname = string( libname_str );
2405 delete [] libname_str;
2406 aDataset->CloseOnDisk();
2408 // --> get hypothesis data
2409 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2410 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2411 aDataset->OpenOnDisk();
2412 size = aDataset->GetSize();
2413 char* hypdata_str = new char[ size ];
2414 aDataset->ReadFromDisk( hypdata_str );
2415 hypdata = string( hypdata_str );
2416 delete [] hypdata_str;
2417 aDataset->CloseOnDisk();
2420 // close hypothesis HDF group
2421 aGroup->CloseOnDisk();
2423 // --> restore hypothesis from data
2424 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2425 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2426 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2427 SMESH::SMESH_Hypothesis_var myHyp;
2429 try { // protect persistence mechanism against exceptions
2430 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2433 INFOS( "Exception during hypothesis creation" );
2436 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2438 // myImpl->LoadFrom( hypdata.c_str() );
2439 hypDataList.push_back( make_pair( myImpl, hypdata ));
2440 string iorString = GetORB()->object_to_string( myHyp );
2441 int newId = myStudyContext->findId( iorString );
2442 myStudyContext->mapOldToNew( id, newId );
2445 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2449 // close hypotheses root HDF group
2450 aTopGroup->CloseOnDisk();
2453 // --> then we should read&create algorithms
2454 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2455 // open algorithms root HDF group
2456 aTopGroup = new HDFgroup( "Algorithms", aFile );
2457 aTopGroup->OpenOnDisk();
2459 // get number of algorithms
2460 int aNbObjects = aTopGroup->nInternalObjects();
2461 for ( int j = 0; j < aNbObjects; j++ ) {
2462 // try to identify algorithm
2463 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2464 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2466 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2467 // open algorithm group
2468 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2469 aGroup->OpenOnDisk();
2471 // --> get algorithm id
2472 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2477 // get number of datasets
2478 int aNbSubObjects = aGroup->nInternalObjects();
2479 for ( int k = 0; k < aNbSubObjects; k++ ) {
2481 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2482 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2483 // --> get algorithm name
2484 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2485 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2486 aDataset->OpenOnDisk();
2487 size = aDataset->GetSize();
2488 char* hypname_str = new char[ size ];
2489 aDataset->ReadFromDisk( hypname_str );
2490 hypname = string( hypname_str );
2491 delete [] hypname_str;
2492 aDataset->CloseOnDisk();
2494 // --> get algorithm plugin library name
2495 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2496 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2497 aDataset->OpenOnDisk();
2498 size = aDataset->GetSize();
2499 char* libname_str = new char[ size ];
2500 aDataset->ReadFromDisk( libname_str );
2501 if(MYDEBUG) SCRUTE( libname_str );
2502 libname = string( libname_str );
2503 delete [] libname_str;
2504 aDataset->CloseOnDisk();
2506 // --> get algorithm data
2507 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2508 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2509 aDataset->OpenOnDisk();
2510 size = aDataset->GetSize();
2511 char* hypdata_str = new char[ size ];
2512 aDataset->ReadFromDisk( hypdata_str );
2513 if(MYDEBUG) SCRUTE( hypdata_str );
2514 hypdata = string( hypdata_str );
2515 delete [] hypdata_str;
2516 aDataset->CloseOnDisk();
2519 // close algorithm HDF group
2520 aGroup->CloseOnDisk();
2522 // --> restore algorithm from data
2523 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2524 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2525 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2526 SMESH::SMESH_Hypothesis_var myHyp;
2528 try { // protect persistence mechanism against exceptions
2529 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2532 INFOS( "Exception during hypothesis creation" );
2535 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2537 //myImpl->LoadFrom( hypdata.c_str() );
2538 hypDataList.push_back( make_pair( myImpl, hypdata ));
2539 string iorString = GetORB()->object_to_string( myHyp );
2540 int newId = myStudyContext->findId( iorString );
2541 myStudyContext->mapOldToNew( id, newId );
2544 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2548 // close algorithms root HDF group
2549 aTopGroup->CloseOnDisk();
2552 // --> the rest groups should be meshes
2553 for ( int i = 0; i < aNbGroups; i++ ) {
2554 // identify next group
2555 char meshName[ HDF_NAME_MAX_LEN+1 ];
2556 aFile->InternalObjectIndentify( i, meshName );
2558 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2560 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2564 // open mesh HDF group
2565 aTopGroup = new HDFgroup( meshName, aFile );
2566 aTopGroup->OpenOnDisk();
2568 // get number of child HDF objects
2569 int aNbObjects = aTopGroup->nInternalObjects();
2570 if ( aNbObjects > 0 ) {
2572 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2573 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2574 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2575 if ( !myNewMeshImpl )
2577 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
2579 string iorString = GetORB()->object_to_string( myNewMesh );
2580 int newId = myStudyContext->findId( iorString );
2581 myStudyContext->mapOldToNew( id, newId );
2583 // try to read and set reference to shape
2584 GEOM::GEOM_Object_var aShapeObject;
2585 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2586 // load mesh "Ref on shape" - it's an entry to SObject
2587 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2588 aDataset->OpenOnDisk();
2589 size = aDataset->GetSize();
2590 char* refFromFile = new char[ size ];
2591 aDataset->ReadFromDisk( refFromFile );
2592 aDataset->CloseOnDisk();
2593 if ( strlen( refFromFile ) > 0 ) {
2594 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2596 // Make sure GEOM data are loaded first
2597 //loadGeomData( shapeSO->GetFatherComponent() );
2599 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2600 if ( !CORBA::is_nil( shapeObject ) ) {
2601 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2602 if ( !aShapeObject->_is_nil() )
2603 myNewMeshImpl->SetShape( aShapeObject );
2612 // As all object that can be referred by hypothesis are created,
2613 // we can restore hypothesis data
2615 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
2616 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
2618 SMESH_Hypothesis_i* hyp = hyp_data->first;
2619 string & data = hyp_data->second;
2620 hyp->LoadFrom( data.c_str() );
2623 // Restore the rest mesh data
2625 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
2626 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
2628 aTopGroup = meshi_group->second;
2629 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
2630 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2631 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2633 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
2634 bool hasData = false;
2637 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
2638 int newId = myStudyContext->findId( iorString );
2639 int id = myStudyContext->getOldId( newId );
2641 // try to find mesh data dataset
2642 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2643 // load mesh "has data" flag
2644 aDataset = new HDFdataset( "Has data", aTopGroup );
2645 aDataset->OpenOnDisk();
2646 size = aDataset->GetSize();
2647 char* strHasData = new char[ size ];
2648 aDataset->ReadFromDisk( strHasData );
2649 aDataset->CloseOnDisk();
2650 if ( strcmp( strHasData, "1") == 0 ) {
2651 // read mesh data from MED file
2652 myReader.SetMesh( mySMESHDSMesh );
2653 myReader.SetMeshId( id );
2659 // try to get applied algorithms
2660 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2661 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2662 aGroup->OpenOnDisk();
2663 // get number of applied algorithms
2664 int aNbSubObjects = aGroup->nInternalObjects();
2665 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2666 for ( int j = 0; j < aNbSubObjects; j++ ) {
2667 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2668 aGroup->InternalObjectIndentify( j, name_dataset );
2669 // check if it is an algorithm
2670 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2671 aDataset = new HDFdataset( name_dataset, aGroup );
2672 aDataset->OpenOnDisk();
2673 size = aDataset->GetSize();
2674 char* refFromFile = new char[ size ];
2675 aDataset->ReadFromDisk( refFromFile );
2676 aDataset->CloseOnDisk();
2678 // san - it is impossible to recover applied algorithms using their entries within Load() method
2680 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2681 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2682 int id = atoi( refFromFile );
2683 string anIOR = myStudyContext->getIORbyOldId( id );
2684 if ( !anIOR.empty() ) {
2685 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2686 if ( !CORBA::is_nil( hypObject ) ) {
2687 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2688 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2689 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2694 aGroup->CloseOnDisk();
2697 // try to get applied hypotheses
2698 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2699 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2700 aGroup->OpenOnDisk();
2701 // get number of applied hypotheses
2702 int aNbSubObjects = aGroup->nInternalObjects();
2703 for ( int j = 0; j < aNbSubObjects; j++ ) {
2704 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2705 aGroup->InternalObjectIndentify( j, name_dataset );
2706 // check if it is a hypothesis
2707 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2708 aDataset = new HDFdataset( name_dataset, aGroup );
2709 aDataset->OpenOnDisk();
2710 size = aDataset->GetSize();
2711 char* refFromFile = new char[ size ];
2712 aDataset->ReadFromDisk( refFromFile );
2713 aDataset->CloseOnDisk();
2715 // san - it is impossible to recover applied hypotheses using their entries within Load() method
2717 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2718 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2719 int id = atoi( refFromFile );
2720 string anIOR = myStudyContext->getIORbyOldId( id );
2721 if ( !anIOR.empty() ) {
2722 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2723 if ( !CORBA::is_nil( hypObject ) ) {
2724 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2725 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2726 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2731 aGroup->CloseOnDisk();
2734 // --> try to find submeshes containers for each type of submesh
2735 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
2736 char name_meshgroup[ 30 ];
2737 if ( j == GetSubMeshOnVertexTag() )
2738 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2739 else if ( j == GetSubMeshOnEdgeTag() )
2740 strcpy( name_meshgroup, "SubMeshes On Edge" );
2741 else if ( j == GetSubMeshOnWireTag() )
2742 strcpy( name_meshgroup, "SubMeshes On Wire" );
2743 else if ( j == GetSubMeshOnFaceTag() )
2744 strcpy( name_meshgroup, "SubMeshes On Face" );
2745 else if ( j == GetSubMeshOnShellTag() )
2746 strcpy( name_meshgroup, "SubMeshes On Shell" );
2747 else if ( j == GetSubMeshOnSolidTag() )
2748 strcpy( name_meshgroup, "SubMeshes On Solid" );
2749 else if ( j == GetSubMeshOnCompoundTag() )
2750 strcpy( name_meshgroup, "SubMeshes On Compound" );
2752 // try to get submeshes container HDF group
2753 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
2754 // open submeshes containers HDF group
2755 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2756 aGroup->OpenOnDisk();
2758 // get number of submeshes
2759 int aNbSubMeshes = aGroup->nInternalObjects();
2760 for ( int k = 0; k < aNbSubMeshes; k++ ) {
2762 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
2763 aGroup->InternalObjectIndentify( k, name_submeshgroup );
2764 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
2765 // --> get submesh id
2766 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
2769 // open submesh HDF group
2770 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
2771 aSubGroup->OpenOnDisk();
2773 // try to read and set reference to subshape
2774 GEOM::GEOM_Object_var aSubShapeObject;
2775 SMESH::SMESH_subMesh_var aSubMesh;
2777 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2778 // load submesh "Ref on shape" - it's an entry to SObject
2779 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2780 aDataset->OpenOnDisk();
2781 size = aDataset->GetSize();
2782 char* refFromFile = new char[ size ];
2783 aDataset->ReadFromDisk( refFromFile );
2784 aDataset->CloseOnDisk();
2785 if ( strlen( refFromFile ) > 0 ) {
2786 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2787 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2788 if ( !CORBA::is_nil( subShapeObject ) ) {
2789 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2790 if ( !aSubShapeObject->_is_nil() )
2791 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2792 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2793 if ( aSubMesh->_is_nil() )
2795 string iorSubString = GetORB()->object_to_string( aSubMesh );
2796 int newSubId = myStudyContext->findId( iorSubString );
2797 myStudyContext->mapOldToNew( subid, newSubId );
2802 if ( aSubMesh->_is_nil() )
2805 // VSR: Get submesh data from MED convertor
2806 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2807 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2808 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2809 // subid << " for subshape # " << anInternalSubmeshId);
2810 // SMESHDS_SubMesh* aSubMeshDS =
2811 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2812 // if ( !aSubMeshDS ) {
2813 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2814 // anInternalSubmeshId << " in current mesh!");
2817 // myReader.GetSubMesh( aSubMeshDS, subid );
2820 // try to get applied algorithms
2821 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2822 // open "applied algorithms" HDF group
2823 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2824 aSubSubGroup->OpenOnDisk();
2825 // get number of applied algorithms
2826 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2827 for ( int l = 0; l < aNbSubObjects; l++ ) {
2828 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2829 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2830 // check if it is an algorithm
2831 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2832 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2833 aDataset->OpenOnDisk();
2834 size = aDataset->GetSize();
2835 char* refFromFile = new char[ size ];
2836 aDataset->ReadFromDisk( refFromFile );
2837 aDataset->CloseOnDisk();
2839 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2840 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2841 int id = atoi( refFromFile );
2842 string anIOR = myStudyContext->getIORbyOldId( id );
2843 if ( !anIOR.empty() ) {
2844 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2845 if ( !CORBA::is_nil( hypObject ) ) {
2846 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2847 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2848 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2853 // close "applied algorithms" HDF group
2854 aSubSubGroup->CloseOnDisk();
2857 // try to get applied hypotheses
2858 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2859 // open "applied hypotheses" HDF group
2860 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2861 aSubSubGroup->OpenOnDisk();
2862 // get number of applied hypotheses
2863 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2864 for ( int l = 0; l < aNbSubObjects; l++ ) {
2865 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2866 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2867 // check if it is a hypothesis
2868 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2869 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2870 aDataset->OpenOnDisk();
2871 size = aDataset->GetSize();
2872 char* refFromFile = new char[ size ];
2873 aDataset->ReadFromDisk( refFromFile );
2874 aDataset->CloseOnDisk();
2876 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2877 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2878 int id = atoi( refFromFile );
2879 string anIOR = myStudyContext->getIORbyOldId( id );
2880 if ( !anIOR.empty() ) {
2881 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2882 if ( !CORBA::is_nil( hypObject ) ) {
2883 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2884 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2885 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2890 // close "applied hypotheses" HDF group
2891 aSubSubGroup->CloseOnDisk();
2894 // close submesh HDF group
2895 aSubGroup->CloseOnDisk();
2898 // close submeshes containers HDF group
2899 aGroup->CloseOnDisk();
2905 // Read sub-meshes from MED
2906 // -------------------------
2907 if(MYDEBUG) MESSAGE("Create all sub-meshes");
2908 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
2909 if ( submeshesInFamilies )
2911 // old way working before fix of PAL 12992
2912 myReader.CreateAllSubMeshes();
2917 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2918 aGroup->OpenOnDisk();
2920 int maxID = mySMESHDSMesh->MaxShapeIndex();
2921 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
2922 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
2924 PositionCreator aPositionCreator;
2926 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
2927 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
2928 for ( int isNode = 0; isNode < 2; ++isNode )
2930 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2931 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
2933 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
2934 aDataset->OpenOnDisk();
2935 // read submesh IDs for all elements sorted by ID
2936 int nbElems = aDataset->GetSize();
2937 int* smIDs = new int [ nbElems ];
2938 aDataset->ReadFromDisk( smIDs );
2939 aDataset->CloseOnDisk();
2941 // get elements sorted by ID
2942 TIDSortedElemSet elemSet;
2944 while ( nIt->more() ) elemSet.insert( nIt->next() );
2946 while ( eIt->more() ) elemSet.insert( eIt->next() );
2947 ASSERT( elemSet.size() == nbElems );
2949 // add elements to submeshes
2950 TIDSortedElemSet::iterator iE = elemSet.begin();
2951 for ( int i = 0; i < nbElems; ++i, ++iE )
2953 int smID = smIDs[ i ];
2954 if ( smID == 0 ) continue;
2955 ASSERT( smID <= maxID );
2956 const SMDS_MeshElement* elem = *iE;
2957 // get or create submesh
2958 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
2960 sm = mySMESHDSMesh->NewSubMesh( smID );
2961 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
2965 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
2966 pos->SetShapeId( smID );
2967 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
2968 node->SetPosition( pos );
2969 sm->AddNode( node );
2971 sm->AddElement( elem );
2977 } // end reading submeshes
2979 // Read node positions on sub-shapes (SMDS_Position)
2981 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
2983 // There are 5 datasets to read:
2984 // "Nodes on Edges" - ID of node on edge
2985 // "Edge positions" - U parameter on node on edge
2986 // "Nodes on Faces" - ID of node on face
2987 // "Face U positions" - U parameter of node on face
2988 // "Face V positions" - V parameter of node on face
2989 char* aEid_DSName = "Nodes on Edges";
2990 char* aEu_DSName = "Edge positions";
2991 char* aFu_DSName = "Face U positions";
2992 //char* aFid_DSName = "Nodes on Faces";
2993 //char* aFv_DSName = "Face V positions";
2996 int nbEids = 0, nbFids = 0;
2997 int *aEids = 0, *aFids = 0;
2998 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
3001 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3002 aGroup->OpenOnDisk();
3004 // loop on 5 data sets
3005 int aNbObjects = aGroup->nInternalObjects();
3006 for ( int i = 0; i < aNbObjects; i++ )
3009 char aDSName[ HDF_NAME_MAX_LEN+1 ];
3010 aGroup->InternalObjectIndentify( i, aDSName );
3012 aDataset = new HDFdataset( aDSName, aGroup );
3013 aDataset->OpenOnDisk();
3014 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
3016 double* pos = new double [ aDataset->GetSize() ];
3017 aDataset->ReadFromDisk( pos );
3019 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
3021 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
3028 int aSize = aDataset->GetSize();
3030 // for reading files, created from 18.07.2005 till 10.10.2005
3031 if (aDataset->GetType() == HDF_STRING)
3032 aSize /= sizeof(int);
3034 int* ids = new int [aSize];
3035 aDataset->ReadFromDisk( ids );
3036 // on face or nodes?
3037 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
3046 aDataset->CloseOnDisk();
3047 } // loop on 5 datasets
3049 // Set node positions on edges or faces
3050 for ( int onFace = 0; onFace < 2; onFace++ )
3052 int nbNodes = ( onFace ? nbFids : nbEids );
3053 if ( nbNodes == 0 ) continue;
3054 int* aNodeIDs = ( onFace ? aFids : aEids );
3055 double* aUPos = ( onFace ? aFupos : aEpos );
3056 double* aVPos = ( onFace ? aFvpos : 0 );
3058 for ( int iNode = 0; iNode < nbNodes; iNode++ )
3060 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
3062 SMDS_PositionPtr aPos = node->GetPosition();
3065 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
3066 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
3067 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
3068 fPos->SetUParameter( aUPos[ iNode ]);
3069 fPos->SetVParameter( aVPos[ iNode ]);
3072 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
3073 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
3074 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
3075 fPos->SetUParameter( aUPos[ iNode ]);
3079 if ( aEids ) delete [] aEids;
3080 if ( aFids ) delete [] aFids;
3081 if ( aEpos ) delete [] aEpos;
3082 if ( aFupos ) delete [] aFupos;
3083 if ( aFvpos ) delete [] aFvpos;
3085 aGroup->CloseOnDisk();
3087 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
3090 // Recompute State (as computed sub-meshes are restored from MED)
3091 if ( !aShapeObject->_is_nil() ) {
3092 MESSAGE("Compute State Engine ...");
3093 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
3094 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
3095 (SMESH_subMesh::SUBMESH_RESTORED);
3096 MESSAGE("Compute State Engine finished");
3099 // try to get groups
3100 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
3101 char name_group[ 30 ];
3102 if ( ii == GetNodeGroupsTag() )
3103 strcpy( name_group, "Groups of Nodes" );
3104 else if ( ii == GetEdgeGroupsTag() )
3105 strcpy( name_group, "Groups of Edges" );
3106 else if ( ii == GetFaceGroupsTag() )
3107 strcpy( name_group, "Groups of Faces" );
3108 else if ( ii == GetVolumeGroupsTag() )
3109 strcpy( name_group, "Groups of Volumes" );
3111 if ( aTopGroup->ExistInternalObject( name_group ) ) {
3112 aGroup = new HDFgroup( name_group, aTopGroup );
3113 aGroup->OpenOnDisk();
3114 // get number of groups
3115 int aNbSubObjects = aGroup->nInternalObjects();
3116 for ( int j = 0; j < aNbSubObjects; j++ ) {
3117 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3118 aGroup->InternalObjectIndentify( j, name_dataset );
3119 // check if it is an group
3120 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
3122 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
3125 aDataset = new HDFdataset( name_dataset, aGroup );
3126 aDataset->OpenOnDisk();
3128 // Retrieve actual group name
3129 size = aDataset->GetSize();
3130 char* nameFromFile = new char[ size ];
3131 aDataset->ReadFromDisk( nameFromFile );
3132 aDataset->CloseOnDisk();
3134 // Try to find a shape reference
3135 TopoDS_Shape aShape;
3136 char aRefName[ 30 ];
3137 sprintf( aRefName, "Ref on shape %d", subid);
3138 if ( aGroup->ExistInternalObject( aRefName ) ) {
3139 // load mesh "Ref on shape" - it's an entry to SObject
3140 aDataset = new HDFdataset( aRefName, aGroup );
3141 aDataset->OpenOnDisk();
3142 size = aDataset->GetSize();
3143 char* refFromFile = new char[ size ];
3144 aDataset->ReadFromDisk( refFromFile );
3145 aDataset->CloseOnDisk();
3146 if ( strlen( refFromFile ) > 0 ) {
3147 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3148 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3149 if ( !CORBA::is_nil( shapeObject ) ) {
3150 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3151 if ( !aShapeObject->_is_nil() )
3152 aShape = GeomObjectToShape( aShapeObject );
3156 // Create group servant
3157 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
3158 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
3159 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
3160 // Obtain a SMESHDS_Group object
3161 if ( aNewGroup->_is_nil() )
3164 string iorSubString = GetORB()->object_to_string( aNewGroup );
3165 int newSubId = myStudyContext->findId( iorSubString );
3166 myStudyContext->mapOldToNew( subid, newSubId );
3168 SMESH_GroupBase_i* aGroupImpl =
3169 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
3173 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
3177 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
3178 aGroupBaseDS->SetStoreName( name_dataset );
3180 // Fill group with contents from MED file
3181 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
3183 myReader.GetGroup( aGrp );
3186 aGroup->CloseOnDisk();
3191 aTopGroup->CloseOnDisk();
3194 aFile->CloseOnDisk();
3197 // Remove temporary files created from the stream
3199 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3201 INFOS( "SMESH_Gen_i::Load completed" );
3205 //=============================================================================
3207 * SMESH_Gen_i::LoadASCII
3209 * Load SMESH module's data in ASCII format (not implemented yet)
3211 //=============================================================================
3213 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
3214 const SALOMEDS::TMPFile& theStream,
3216 bool isMultiFile ) {
3217 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
3218 return Load( theComponent, theStream, theURL, isMultiFile );
3221 //=============================================================================
3223 * SMESH_Gen_i::Close
3225 * Clears study-connected data when it is closed
3227 //=============================================================================
3229 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
3231 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
3233 // Clear study contexts data
3234 int studyId = GetCurrentStudyID();
3235 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
3236 delete myStudyContextMap[ studyId ];
3237 myStudyContextMap.erase( studyId );
3242 //=============================================================================
3244 * SMESH_Gen_i::ComponentDataType
3246 * Get component data type
3248 //=============================================================================
3250 char* SMESH_Gen_i::ComponentDataType()
3252 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
3253 return CORBA::string_dup( "SMESH" );
3257 //=============================================================================
3259 * SMESH_Gen_i::IORToLocalPersistentID
3261 * Transform data from transient form to persistent
3263 //=============================================================================
3265 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
3266 const char* IORString,
3267 CORBA::Boolean /*isMultiFile*/,
3268 CORBA::Boolean /*isASCII*/ )
3270 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
3271 StudyContext* myStudyContext = GetCurrentStudyContext();
3273 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
3274 int anId = myStudyContext->findId( IORString );
3276 if(MYDEBUG) MESSAGE( "VSR " << anId )
3278 sprintf( strId, "%d", anId );
3279 return CORBA::string_dup( strId );
3282 return CORBA::string_dup( "" );
3285 //=============================================================================
3287 * SMESH_Gen_i::LocalPersistentIDToIOR
3289 * Transform data from persistent form to transient
3291 //=============================================================================
3293 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
3294 const char* aLocalPersistentID,
3295 CORBA::Boolean /*isMultiFile*/,
3296 CORBA::Boolean /*isASCII*/ )
3298 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
3299 StudyContext* myStudyContext = GetCurrentStudyContext();
3301 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
3302 int anId = atoi( aLocalPersistentID );
3303 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
3305 return CORBA::string_dup( "" );
3308 //=======================================================================
3309 //function : RegisterObject
3311 //=======================================================================
3313 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
3315 StudyContext* myStudyContext = GetCurrentStudyContext();
3316 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3317 string iorString = GetORB()->object_to_string( theObject );
3318 return myStudyContext->addObject( iorString );
3323 //================================================================================
3325 * \brief Return id of registered object
3326 * \param theObject - the Object
3327 * \retval int - Object id
3329 //================================================================================
3331 int SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
3333 StudyContext* myStudyContext = GetCurrentStudyContext();
3334 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3335 string iorString = GetORB()->object_to_string( theObject );
3336 return myStudyContext->findId( iorString );
3341 //=============================================================================
3343 * SMESHEngine_factory
3345 * C factory, accessible with dlsym, after dlopen
3347 //=============================================================================
3351 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3352 PortableServer::POA_ptr poa,
3353 PortableServer::ObjectId* contId,
3354 const char* instanceName,
3355 const char* interfaceName )
3357 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3358 if(MYDEBUG) SCRUTE(interfaceName);
3359 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3360 return aSMESHGen->getId() ;