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 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
113 CORBA::ORB_var SMESH_Gen_i::myOrb;
114 PortableServer::POA_var SMESH_Gen_i::myPoa;
115 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
116 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
117 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
119 //=============================================================================
121 * GetServant [ static ]
123 * Get servant of the CORBA object
125 //=============================================================================
127 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
129 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
132 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
136 INFOS( "GetServant - Unknown exception was caught!!!" );
141 //=============================================================================
143 * SObjectToObject [ static ]
145 * Get CORBA object corresponding to the SALOMEDS::SObject
147 //=============================================================================
149 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
151 SALOMEDS::GenericAttribute_var anAttr;
152 CORBA::Object_var anObj;
153 if ( !theSObject->_is_nil() ) {
155 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
156 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
157 CORBA::String_var aValue = anIOR->Value();
158 if( strcmp( aValue, "" ) != 0 )
159 anObj = GetORB()->string_to_object( aValue );
163 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
169 //=============================================================================
173 * Get SALOME_NamingService object
175 //=============================================================================
177 SALOME_NamingService* SMESH_Gen_i::GetNS()
179 if ( myNS == NULL ) {
180 myNS = SINGLETON_<SALOME_NamingService>::Instance();
181 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
182 myNS->init_orb( GetORB() );
187 //=============================================================================
191 * Get SALOME_LifeCycleCORBA object
193 //=============================================================================
194 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
195 if ( myLCC == NULL ) {
196 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
202 //=============================================================================
204 * GetGeomEngine [ static ]
206 * Get GEOM::GEOM_Gen reference
208 //=============================================================================
209 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
210 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
211 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
212 //CCRT return aGeomEngine._retn();
213 if(CORBA::is_nil(myGeomGen))
215 Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
216 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
221 //=============================================================================
223 * SMESH_Gen_i::SMESH_Gen_i
225 * Default constructor: not for use
227 //=============================================================================
229 SMESH_Gen_i::SMESH_Gen_i()
231 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
234 //=============================================================================
236 * SMESH_Gen_i::SMESH_Gen_i
238 * Standard constructor, used with Container
240 //=============================================================================
242 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
243 PortableServer::POA_ptr poa,
244 PortableServer::ObjectId* contId,
245 const char* instanceName,
246 const char* interfaceName )
247 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
249 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
251 myOrb = CORBA::ORB::_duplicate(orb);
252 myPoa = PortableServer::POA::_duplicate(poa);
255 _id = myPoa->activate_object( _thisObj );
257 myIsEmbeddedMode = false;
258 myShapeReader = NULL; // shape reader
261 // set it in standalone mode only
262 //OSD::SetSignal( true );
265 //=============================================================================
267 * SMESH_Gen_i::~SMESH_Gen_i
271 //=============================================================================
273 SMESH_Gen_i::~SMESH_Gen_i()
275 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
277 // delete hypothesis creators
278 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
279 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
281 delete (*itHyp).second;
283 myHypCreatorMap.clear();
285 // Clear study contexts data
286 map<int, StudyContext*>::iterator it;
287 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
290 myStudyContextMap.clear();
291 // delete shape reader
292 if ( !myShapeReader )
293 delete myShapeReader;
296 //=============================================================================
298 * SMESH_Gen_i::createHypothesis
300 * Create hypothesis of given type
302 //=============================================================================
303 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
304 const char* theLibName)
305 throw (SALOME::SALOME_Exception)
307 Unexpect aCatch(SALOME_SalomeException);
308 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName);
310 // create a new hypothesis object servant
311 SMESH_Hypothesis_i* myHypothesis_i = 0;
312 SMESH::SMESH_Hypothesis_var hypothesis_i;
316 // check, if creator for this hypothesis type already exists
317 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
319 // load plugin library
320 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
321 void* libHandle = dlopen (theLibName, RTLD_LAZY);
324 // report any error, if occured
325 const char* anError = dlerror();
326 throw(SALOME_Exception(anError));
329 // get method, returning hypothesis creator
330 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
331 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
332 GetHypothesisCreator procHandle =
333 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
336 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
340 // get hypothesis creator
341 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
342 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
345 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
348 // map hypothesis creator to a hypothesis name
349 myHypCreatorMap[string(theHypName)] = aCreator;
352 // create a new hypothesis object, store its ref. in studyContext
353 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
355 myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen);
356 // _CS_gbo Explicit activation (no longer made in the constructor).
357 myHypothesis_i->Activate();
358 myHypothesis_i->SetLibName(theLibName); // for persistency assurance
360 catch (SALOME_Exception& S_ex)
362 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
366 return hypothesis_i._retn();
368 // activate the CORBA servant of hypothesis
369 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
370 int nextId = RegisterObject( hypothesis_i );
371 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
373 return hypothesis_i._retn();
376 //=============================================================================
378 * SMESH_Gen_i::createMesh
380 * Create empty mesh on shape
382 //=============================================================================
383 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
384 throw ( SALOME::SALOME_Exception )
386 Unexpect aCatch(SALOME_SalomeException);
387 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
389 // Get or create the GEOM_Client instance
391 // create a new mesh object servant, store it in a map in study context
392 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
393 // create a new mesh object
394 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
396 // activate the CORBA servant of Mesh
397 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
398 int nextId = RegisterObject( mesh );
399 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
402 catch (SALOME_Exception& S_ex) {
403 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
405 return SMESH::SMESH_Mesh::_nil();
408 //=============================================================================
410 * SMESH_Gen_i::GetShapeReader
414 //=============================================================================
415 GEOM_Client* SMESH_Gen_i::GetShapeReader()
417 // create shape reader if necessary
418 if ( !myShapeReader )
419 myShapeReader = new GEOM_Client(GetContainerRef());
420 ASSERT( myShapeReader );
421 return myShapeReader;
424 //=============================================================================
426 * SMESH_Gen_i::SetGeomEngine
428 * Set GEOM::GEOM_Gen reference
430 //=============================================================================
431 GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
433 Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
434 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
438 //=============================================================================
440 * SMESH_Gen_i::SetEmbeddedMode
444 //=============================================================================
446 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
448 myIsEmbeddedMode = theMode;
450 if ( !myIsEmbeddedMode ) {
451 //PAL10867: disable signals catching with "noexcepthandler" option
452 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
453 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
458 char* envDisableFPE = getenv("DISABLE_FPE");
459 if (envDisableFPE && atoi(envDisableFPE))
464 OSD::SetSignal( raiseFPE );
466 // else OSD::SetSignal() is called in GUI
470 //=============================================================================
472 * SMESH_Gen_i::IsEmbeddedMode
476 //=============================================================================
478 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
480 return myIsEmbeddedMode;
483 //=============================================================================
485 * SMESH_Gen_i::SetCurrentStudy
489 //=============================================================================
491 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
494 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
495 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
496 // create study context, if it doesn't exist and set current study
497 int studyId = GetCurrentStudyID();
498 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
499 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
500 myStudyContextMap[ studyId ] = new StudyContext;
503 // myCurrentStudy may be nil
504 if ( !CORBA::is_nil( myCurrentStudy ) ) {
505 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
506 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
507 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
509 // set current study for geom engine
510 //if ( !CORBA::is_nil( GetGeomEngine() ) )
511 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
515 //=============================================================================
517 * SMESH_Gen_i::GetCurrentStudy
521 //=============================================================================
523 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
525 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
526 return SALOMEDS::Study::_duplicate( myCurrentStudy );
529 //=============================================================================
531 * SMESH_Gen_i::GetCurrentStudyContext
533 * Get current study context
535 //=============================================================================
536 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
538 if ( !CORBA::is_nil( myCurrentStudy ) &&
539 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
540 return myStudyContextMap[ myCurrentStudy->StudyId() ];
545 //=============================================================================
547 * SMESH_Gen_i::CreateHypothesis
549 * Create hypothesis/algorothm of given type and publish it in the study
551 //=============================================================================
553 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
554 const char* theLibName )
555 throw ( SALOME::SALOME_Exception )
557 Unexpect aCatch(SALOME_SalomeException);
558 // Create hypothesis/algorithm
559 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
561 // Publish hypothesis/algorithm in the study
562 if ( CanPublishInStudy( hyp ) ) {
563 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
564 if ( !aSO->_is_nil() ) {
565 // Update Python script
566 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
567 << theHypName << "', '" << theLibName << "')";
574 //================================================================================
576 * \brief Return hypothesis of given type holding parameter values of the existing mesh
577 * \param theHypType - hypothesis type name
578 * \param theLibName - plugin library name
579 * \param theMesh - The mesh of interest
580 * \param theGeom - The shape to get parameter values from
581 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
582 * in a study and used to compute the mesh, or a temporary one created just to pass
585 //================================================================================
587 SMESH::SMESH_Hypothesis_ptr
588 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
589 const char* theLibName,
590 SMESH::SMESH_Mesh_ptr theMesh,
591 GEOM::GEOM_Object_ptr theGeom)
592 throw ( SALOME::SALOME_Exception )
594 Unexpect aCatch(SALOME_SalomeException);
595 if ( CORBA::is_nil( theMesh ) )
596 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
597 if ( CORBA::is_nil( theGeom ) )
598 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
600 // -----------------------------------------------
601 // find hypothesis used to mesh theGeom
602 // -----------------------------------------------
604 // get mesh and shape
605 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
606 TopoDS_Shape shape = GeomObjectToShape( theGeom );
607 if ( !meshServant || shape.IsNull() )
608 return SMESH::SMESH_Hypothesis::_nil();
609 ::SMESH_Mesh& mesh = meshServant->GetImpl();
611 if ( mesh.NbNodes() == 0 ) // empty mesh
612 return SMESH::SMESH_Hypothesis::_nil();
614 // create a temporary hypothesis to know its dimention
615 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
616 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
618 return SMESH::SMESH_Hypothesis::_nil();
619 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
621 // look for a hypothesis of theHypType used to mesh the shape
622 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
625 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
626 int nbLocalHyps = aHypList->length();
627 for ( int i = 0; i < nbLocalHyps; i++ )
628 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
629 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
630 // check super shapes
631 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
632 while ( nbLocalHyps == 0 && itShape.More() ) {
633 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
634 if ( ! CORBA::is_nil( geomObj )) {
635 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
636 nbLocalHyps = aHypList->length();
637 for ( int i = 0; i < nbLocalHyps; i++ )
638 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
639 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
645 // let the temporary hypothesis find out some how parameter values
646 if ( hyp->SetParametersByMesh( &mesh, shape ))
647 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
649 return SMESH::SMESH_Hypothesis::_nil();
652 //=============================================================================
654 * SMESH_Gen_i::CreateMesh
656 * Create empty mesh on a shape and publish it in the study
658 //=============================================================================
660 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
661 throw ( SALOME::SALOME_Exception )
663 Unexpect aCatch(SALOME_SalomeException);
664 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
666 SMESH::SMESH_Mesh_var mesh = this->createMesh();
668 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
669 ASSERT( meshServant );
670 meshServant->SetShape( theShapeObject );
672 // publish mesh in the study
673 if ( CanPublishInStudy( mesh ) ) {
674 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
675 aStudyBuilder->NewCommand(); // There is a transaction
676 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
677 aStudyBuilder->CommitCommand();
678 if ( !aSO->_is_nil() ) {
679 // Update Python script
680 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
687 //=============================================================================
689 * SMESH_Gen_i::CreateEmptyMesh
693 //=============================================================================
695 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
696 throw ( SALOME::SALOME_Exception )
698 Unexpect aCatch(SALOME_SalomeException);
699 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
701 SMESH::SMESH_Mesh_var mesh = this->createMesh();
703 // publish mesh in the study
704 if ( CanPublishInStudy( mesh ) ) {
705 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
706 aStudyBuilder->NewCommand(); // There is a transaction
707 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
708 aStudyBuilder->CommitCommand();
709 if ( !aSO->_is_nil() ) {
710 // Update Python script
711 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
718 //=============================================================================
720 * SMESH_Gen_i::CreateMeshFromUNV
722 * Create mesh and import data from UNV file
724 //=============================================================================
726 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
727 throw ( SALOME::SALOME_Exception )
729 Unexpect aCatch(SALOME_SalomeException);
730 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
732 SMESH::SMESH_Mesh_var aMesh = createMesh();
734 // publish mesh in the study
735 if ( CanPublishInStudy( aMesh ) ) {
736 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
737 aStudyBuilder->NewCommand(); // There is a transaction
738 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
739 aStudyBuilder->CommitCommand();
740 if ( !aSO->_is_nil() ) {
741 // Update Python script
742 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
746 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
748 aServant->ImportUNVFile( theFileName );
750 // Dump creation of groups
751 aServant->GetGroups();
753 return aMesh._retn();
756 //=============================================================================
758 * SMESH_Gen_i::CreateMeshFromMED
760 * Create mesh and import data from MED file
762 //=============================================================================
764 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
765 SMESH::DriverMED_ReadStatus& theStatus)
766 throw ( SALOME::SALOME_Exception )
768 Unexpect aCatch(SALOME_SalomeException);
769 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
771 // Retrieve mesh names from the file
772 DriverMED_R_SMESHDS_Mesh myReader;
773 myReader.SetFile( theFileName );
774 myReader.SetMeshId( -1 );
775 Driver_Mesh::Status aStatus;
776 list<string> aNames = myReader.GetMeshNames(aStatus);
777 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
778 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
780 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
783 TPythonDump aPythonDump;
785 //TCollection_AsciiString aStr ("([");
787 if (theStatus == SMESH::DRS_OK) {
788 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
789 aStudyBuilder->NewCommand(); // There is a transaction
790 aResult->length( aNames.size() );
793 // Iterate through all meshes and create mesh objects
794 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
796 //if (i > 0) aStr += ", ";
797 if (i > 0) aPythonDump << ", ";
800 SMESH::SMESH_Mesh_var mesh = createMesh();
802 // publish mesh in the study
803 SALOMEDS::SObject_var aSO;
804 if ( CanPublishInStudy( mesh ) )
805 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
806 if ( !aSO->_is_nil() ) {
809 //aStr += aSO->GetID();
812 aPythonDump << "mesh_" << i;
814 // aStr += TCollection_AsciiString(i);
817 // Read mesh data (groups are published automatically by ImportMEDFile())
818 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
819 ASSERT( meshServant );
820 SMESH::DriverMED_ReadStatus status1 =
821 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
822 if (status1 > theStatus)
825 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
827 aStudyBuilder->CommitCommand();
830 // Update Python script
831 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
833 // Dump creation of groups
834 for ( int i = 0; i < aResult->length(); ++i )
835 aResult[ i ]->GetGroups();
837 return aResult._retn();
840 //=============================================================================
842 * SMESH_Gen_i::CreateMeshFromSTL
844 * Create mesh and import data from STL file
846 //=============================================================================
848 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
849 throw ( SALOME::SALOME_Exception )
851 Unexpect aCatch(SALOME_SalomeException);
852 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
854 SMESH::SMESH_Mesh_var aMesh = createMesh();
856 // publish mesh in the study
857 if ( CanPublishInStudy( aMesh ) ) {
858 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
859 aStudyBuilder->NewCommand(); // There is a transaction
860 SALOMEDS::SObject_var aSO = PublishInStudy
861 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
862 aStudyBuilder->CommitCommand();
863 if ( !aSO->_is_nil() ) {
864 // Update Python script
865 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
869 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
871 aServant->ImportSTLFile( theFileName );
872 return aMesh._retn();
875 //=============================================================================
877 * SMESH_Gen_i::IsReadyToCompute
879 * Returns true if mesh contains enough data to be computed
881 //=============================================================================
883 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
884 GEOM::GEOM_Object_ptr theShapeObject )
885 throw ( SALOME::SALOME_Exception )
887 Unexpect aCatch(SALOME_SalomeException);
888 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
890 if ( CORBA::is_nil( theShapeObject ) )
891 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
894 if ( CORBA::is_nil( theMesh ) )
895 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
900 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
901 ASSERT( meshServant );
903 // get local TopoDS_Shape
904 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
905 // call implementation
906 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
907 return myGen.CheckAlgoState( myLocMesh, myLocShape );
910 catch ( SALOME_Exception& S_ex ) {
911 INFOS( "catch exception "<< S_ex.what() );
916 //================================================================================
918 * \brief Find SObject for an algo
920 //================================================================================
922 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
925 if ( !myCurrentStudy->_is_nil() ) {
926 // find algo in the study
927 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
928 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
929 if ( !father->_is_nil() ) {
930 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
931 for ( ; itBig->More(); itBig->Next() ) {
932 SALOMEDS::SObject_var gotBranch = itBig->Value();
933 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
934 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
935 for ( ; algoIt->More(); algoIt->Next() ) {
936 SALOMEDS::SObject_var algoSO = algoIt->Value();
937 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
938 if ( !CORBA::is_nil( algoIOR )) {
939 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
940 if ( impl && impl->GetImpl() == algo )
941 return algoSO._retn();
943 } // loop on algo SO's
946 } // SMESH component iterator
950 return SALOMEDS::SObject::_nil();
953 //================================================================================
955 * \brief Return errors of mesh computation
957 //================================================================================
959 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
960 GEOM::GEOM_Object_ptr theSubObject )
961 throw ( SALOME::SALOME_Exception )
963 Unexpect aCatch(SALOME_SalomeException);
964 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
966 if ( CORBA::is_nil( theSubObject ) )
967 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
969 if ( CORBA::is_nil( theMesh ) )
970 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
972 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
974 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
976 TopoDS_Shape shape = GeomObjectToShape( theSubObject );
977 ::SMESH_Mesh& mesh = meshServant->GetImpl();
979 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
982 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
983 const bool includeSelf = true, complexShapeFirst = true;
984 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
986 while ( smIt->more() )
989 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
991 SMESH_ComputeErrorPtr error = sm->GetComputeError();
992 if ( error && !error->IsOK() && error->myAlgo )
994 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
995 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
996 errStruct.comment = error->myComment.c_str();
997 errStruct.subShapeID = sm->GetId();
998 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->myAlgo );
999 if ( !algoSO->_is_nil() )
1000 errStruct.algoName = algoSO->GetName();
1002 errStruct.algoName = error->myAlgo->GetName();
1005 error_array->length( nbErr );
1008 catch ( SALOME_Exception& S_ex ) {
1009 INFOS( "catch exception "<< S_ex.what() );
1012 return error_array._retn();
1015 //================================================================================
1017 * \brief Returns errors of hypotheses definintion
1018 * \param theMesh - the mesh
1019 * \param theSubObject - the main or sub- shape
1020 * \retval SMESH::algo_error_array* - sequence of errors
1022 //================================================================================
1024 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1025 GEOM::GEOM_Object_ptr theSubObject )
1026 throw ( SALOME::SALOME_Exception )
1028 Unexpect aCatch(SALOME_SalomeException);
1029 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1031 if ( CORBA::is_nil( theSubObject ) )
1032 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1034 if ( CORBA::is_nil( theMesh ) )
1035 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1037 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1039 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1040 ASSERT( meshServant );
1041 if ( meshServant ) {
1042 TopoDS_Shape myLocShape = GeomObjectToShape( theSubObject );
1043 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1044 list< ::SMESH_Gen::TAlgoStateError > error_list;
1045 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1046 // call ::SMESH_Gen::GetAlgoState()
1047 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1048 error_array->length( error_list.size() );
1050 for ( error = error_list.begin(); error != error_list.end(); ++error )
1052 // fill AlgoStateError structure
1053 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1054 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1055 errStruct.algoDim = error->_algoDim;
1056 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1057 errStruct.algoName = "";
1058 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->_algo );
1059 if ( !algoSO->_is_nil() )
1060 errStruct.algoName = algoSO->GetName();
1064 catch ( SALOME_Exception& S_ex ) {
1065 INFOS( "catch exception "<< S_ex.what() );
1067 return error_array._retn();
1070 //=============================================================================
1072 * SMESH_Gen_i::GetSubShapesId
1074 * Get sub-shapes unique ID's list
1076 //=============================================================================
1078 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1079 const SMESH::object_array& theListOfSubShapeObject )
1080 throw ( SALOME::SALOME_Exception )
1082 Unexpect aCatch(SALOME_SalomeException);
1083 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1085 SMESH::long_array_var shapesId = new SMESH::long_array;
1088 if ( CORBA::is_nil( theMainShapeObject ) )
1089 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1090 SALOME::BAD_PARAM );
1094 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1095 TopTools_IndexedMapOfShape myIndexToShape;
1096 TopExp::MapShapes(myMainShape,myIndexToShape);
1098 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1100 GEOM::GEOM_Object_var aShapeObject
1101 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1102 if ( CORBA::is_nil( aShapeObject ) )
1103 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1104 SALOME::BAD_PARAM );
1106 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1107 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1109 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1110 setId.insert(myIndexToShape.FindIndex(F));
1111 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1113 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1115 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1116 setId.insert(myIndexToShape.FindIndex(E));
1117 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1119 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1121 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1122 setId.insert(myIndexToShape.FindIndex(V));
1123 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1126 shapesId->length(setId.size());
1127 set<int>::iterator iind;
1129 for (iind = setId.begin(); iind != setId.end(); iind++)
1131 if(MYDEBUG) SCRUTE((*iind));
1132 shapesId[i] = (*iind);
1133 if(MYDEBUG) SCRUTE(shapesId[i]);
1137 catch (SALOME_Exception& S_ex)
1139 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1142 return shapesId._retn();
1145 //=============================================================================
1147 * SMESH_Gen_i::Compute
1149 * Compute mesh on a shape
1151 //=============================================================================
1153 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1154 GEOM::GEOM_Object_ptr theShapeObject )
1155 throw ( SALOME::SALOME_Exception )
1157 Unexpect aCatch(SALOME_SalomeException);
1158 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1160 if ( CORBA::is_nil( theShapeObject ) )
1161 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1162 SALOME::BAD_PARAM );
1164 if ( CORBA::is_nil( theMesh ) )
1165 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1166 SALOME::BAD_PARAM );
1168 // Update Python script
1169 TPythonDump() << "isDone = " << this << ".Compute( "
1170 << theMesh << ", " << theShapeObject << ")";
1171 TPythonDump() << "if not isDone: print 'Mesh', " << theMesh << ", ': computation failed'";
1175 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1176 ASSERT( meshServant );
1177 if ( meshServant ) {
1178 // get local TopoDS_Shape
1179 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1180 // call implementation compute
1181 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1182 return myGen.Compute( myLocMesh, myLocShape);
1185 catch ( std::bad_alloc ) {
1186 INFOS( "Compute(): lack of memory" );
1188 catch ( SALOME_Exception& S_ex ) {
1189 INFOS( "Compute(): catch exception "<< S_ex.what() );
1192 INFOS( "Compute(): unknown exception " );
1197 //================================================================================
1199 * \brief Return geometrical object the given element is built on
1200 * \param theMesh - the mesh the element is in
1201 * \param theElementID - the element ID
1202 * \param theGeomName - the name of the result geom object if it is not yet published
1203 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1205 //================================================================================
1207 GEOM::GEOM_Object_ptr
1208 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1209 CORBA::Long theElementID,
1210 const char* theGeomName)
1211 throw ( SALOME::SALOME_Exception )
1213 Unexpect aCatch(SALOME_SalomeException);
1215 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
1216 if ( !geom->_is_nil() ) {
1217 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1218 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1220 // try to find the corresponding SObject
1221 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1222 if ( SObj->_is_nil() ) // submesh can be not found even if published
1224 // try to find published submesh
1225 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
1226 if ( !geom->IsMainShape() && list->length() == 1 ) {
1227 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1228 SALOMEDS::ChildIterator_var it;
1229 if ( !mainSO->_is_nil() )
1230 it = myCurrentStudy->NewChildIterator( mainSO );
1231 if ( !it->_is_nil() ) {
1232 for ( it->InitEx(true); SObj->_is_nil() && it->More(); it->Next() ) {
1233 GEOM::GEOM_Object_var subGeom =
1234 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1235 if ( !subGeom->_is_nil() ) {
1236 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1237 if ( subList->length() == 1 && list[0] == subList[0] ) {
1246 if ( SObj->_is_nil() ) // publish a new subshape
1247 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1249 // return only published geometry
1250 if ( !SObj->_is_nil() )
1251 return geom._retn();
1253 return GEOM::GEOM_Object::_nil();
1256 //================================================================================
1258 * \brief Return geometrical object the given element is built on.
1259 * \param theMesh - the mesh the element is in
1260 * \param theElementID - the element ID
1261 * \retval GEOM::GEOM_Object_ptr - the found geom object
1263 //================================================================================
1265 GEOM::GEOM_Object_ptr
1266 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1267 CORBA::Long theElementID)
1268 throw ( SALOME::SALOME_Exception )
1270 Unexpect aCatch(SALOME_SalomeException);
1271 if ( CORBA::is_nil( theMesh ) )
1272 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1274 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1275 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1277 // get a core mesh DS
1278 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1279 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1281 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1282 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1283 // find the element in mesh
1284 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) )
1285 // find a shape id by the element
1286 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1287 // get a geom object by the shape id
1288 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1289 if ( geom->_is_nil() ) {
1290 GEOM::GEOM_IShapesOperations_var op =
1291 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1292 if ( !op->_is_nil() )
1293 geom = op->GetSubShape( mainShape, shapeID );
1295 if ( !geom->_is_nil() ) {
1296 GeomObjectToShape( geom ); // let geom client remember the found shape
1297 return geom._retn();
1301 return GEOM::GEOM_Object::_nil();
1304 //================================================================================
1306 * SMESH_Gen_i::Concatenate
1308 * Concatenate the given meshes into one mesh
1310 //================================================================================
1312 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
1313 CORBA::Boolean theUniteIdenticalGroups,
1314 CORBA::Boolean theMergeNodesAndElements,
1315 CORBA::Double theMergeTolerance)
1316 throw ( SALOME::SALOME_Exception )
1318 typedef map<int, int> TIDsMap;
1319 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
1320 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
1321 typedef std::set<SMESHDS_GroupBase*> TGroups;
1323 TPythonDump aPythonDump; // prevent dump of called methods
1326 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
1328 if ( !aNewMesh->_is_nil() ) {
1329 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
1331 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
1332 SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
1334 TGroupsMap aGroupsMap;
1335 TListOfNewGroups aListOfNewGroups;
1336 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
1337 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
1340 for ( int i = 0; i < theMeshesArray.length(); i++) {
1341 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
1342 if ( !anInitMesh->_is_nil() ) {
1343 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
1345 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
1346 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
1351 // loop on elements of mesh
1352 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
1353 const SMDS_MeshElement* anElem = 0;
1354 const SMDS_MeshElement* aNewElem = 0;
1355 int anElemNbNodes = 0;
1357 for ( int j = 0; itElems->more(); j++) {
1358 anElem = itElems->next();
1359 SMDSAbs_ElementType anElemType = anElem->GetType();
1360 anElemNbNodes = anElem->NbNodes();
1361 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
1363 // loop on nodes of element
1364 const SMDS_MeshNode* aNode = 0;
1365 const SMDS_MeshNode* aNewNode = 0;
1366 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
1368 for ( int k = 0; itNodes->more(); k++) {
1369 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
1370 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
1371 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
1372 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
1375 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
1376 aNodesArray[k] = aNewNode;
1379 // creates a corresponding element on existent nodes in new mesh
1380 if ( anElem->IsPoly() && anElemType == SMDSAbs_Volume )
1382 const SMDS_PolyhedralVolumeOfNodes* aVolume =
1383 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
1385 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
1386 aVolume->GetQuanities());
1387 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1392 aNewElem = aNewEditor.AddElement(aNodesArray,
1395 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1399 aListOfGroups = anInitImpl->GetGroups();
1400 SMESH::SMESH_GroupBase_ptr aGroup;
1402 // loop on groups of mesh
1403 SMESH::long_array_var anInitIDs = new SMESH::long_array();
1404 SMESH::long_array_var anNewIDs = new SMESH::long_array();
1405 SMESH::SMESH_Group_var aNewGroup;
1406 for (int i = 0; i < aListOfGroups->length(); i++) {
1407 aGroup = aListOfGroups[i];
1408 aListOfNewGroups.clear();
1409 SMESH::ElementType aGroupType = aGroup->GetType();
1410 CORBA::String_var aGroupName = aGroup->GetName();
1412 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
1414 // convert a list of IDs
1415 anInitIDs = aGroup->GetListOfID();
1416 anNewIDs->length(anInitIDs->length());
1417 if ( aGroupType == SMESH::NODE )
1418 for (int j = 0; j < anInitIDs->length(); j++) {
1419 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
1422 for (int j = 0; j < anInitIDs->length(); j++) {
1423 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
1426 // check that current group name and type don't have identical ones in union mesh
1427 if ( anIter == aGroupsMap.end() ) {
1428 // add a new group in the mesh
1429 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1430 // add elements into new group
1431 aNewGroup->Add( anNewIDs );
1433 aListOfNewGroups.push_back(aNewGroup);
1434 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
1437 else if ( theUniteIdenticalGroups ) {
1438 // unite identical groups
1439 TListOfNewGroups& aNewGroups = anIter->second;
1440 aNewGroups.front()->Add( anNewIDs );
1444 // rename identical groups
1445 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1446 aNewGroup->Add( anNewIDs );
1448 TListOfNewGroups& aNewGroups = anIter->second;
1449 string aNewGroupName;
1450 if (aNewGroups.size() == 1) {
1451 aNewGroupName = string(aGroupName) + "_1";
1452 aNewGroups.front()->SetName(aNewGroupName.c_str());
1454 char aGroupNum[128];
1455 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
1456 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
1457 aNewGroup->SetName(aNewGroupName.c_str());
1458 aNewGroups.push_back(aNewGroup);
1465 if (theMergeNodesAndElements) {
1467 set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
1468 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
1469 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
1470 aNewEditor.MergeNodes( aGroupsOfNodes );
1472 aNewEditor.MergeEqualElements();
1477 // Update Python script
1478 aPythonDump << aNewMesh << " = " << this << ".Concatenate(";
1480 for ( int i = 0; i < theMeshesArray.length(); i++) {
1481 if (i > 0) aPythonDump << ", ";
1482 aPythonDump << theMeshesArray[i];
1484 aPythonDump << "], ";
1485 aPythonDump << theUniteIdenticalGroups << ", "
1486 << theMergeNodesAndElements << ", "
1487 << theMergeTolerance << ")";
1489 return aNewMesh._retn();
1492 //=============================================================================
1496 * Save SMESH module's data
1498 //=============================================================================
1499 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1503 INFOS( "SMESH_Gen_i::Save" );
1505 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1506 // san -- in case <myCurrentStudy> differs from theComponent's study,
1507 // use that of the component
1508 if ( myCurrentStudy->_is_nil() ||
1509 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1510 SetCurrentStudy( theComponent->GetStudy() );
1512 // Store study contents as a set of python commands
1513 SavePython(myCurrentStudy);
1515 StudyContext* myStudyContext = GetCurrentStudyContext();
1517 // Declare a byte stream
1518 SALOMEDS::TMPFile_var aStreamFile;
1520 // Obtain a temporary dir
1521 TCollection_AsciiString tmpDir =
1522 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1524 // Create a sequence of files processed
1525 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1526 aFileSeq->length( NUM_TMP_FILES );
1528 TCollection_AsciiString aStudyName( "" );
1530 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1532 // Set names of temporary files
1533 TCollection_AsciiString filename =
1534 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1535 TCollection_AsciiString meshfile =
1536 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1537 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1538 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1539 filename = tmpDir + filename;
1540 meshfile = tmpDir + meshfile;
1543 HDFdataset* aDataset;
1544 HDFgroup* aTopGroup;
1546 HDFgroup* aSubGroup;
1547 HDFgroup* aSubSubGroup;
1548 hdf_size aSize[ 1 ];
1551 //Remove the files if they exist: BugID: 11225
1552 TCollection_AsciiString cmd("rm -f \"");
1557 system(cmd.ToCString());
1559 // MED writer to be used by storage process
1560 DriverMED_W_SMESHDS_Mesh myWriter;
1561 myWriter.SetFile( meshfile.ToCString() );
1564 // ---> create HDF file
1565 aFile = new HDFfile( filename.ToCString() );
1566 aFile->CreateOnDisk();
1568 // --> iterator for top-level objects
1569 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1570 for ( ; itBig->More(); itBig->Next() ) {
1571 SALOMEDS::SObject_var gotBranch = itBig->Value();
1573 // --> hypotheses root branch (only one for the study)
1574 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1575 // create hypotheses root HDF group
1576 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1577 aTopGroup->CreateOnDisk();
1579 // iterator for all hypotheses
1580 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1581 for ( ; it->More(); it->Next() ) {
1582 SALOMEDS::SObject_var mySObject = it->Value();
1583 CORBA::Object_var anObject = SObjectToObject( mySObject );
1584 if ( !CORBA::is_nil( anObject ) ) {
1585 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1586 if ( !myHyp->_is_nil() ) {
1587 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1589 string hypname = string( myHyp->GetName() );
1590 string libname = string( myHyp->GetLibName() );
1591 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1592 string hypdata = string( myImpl->SaveTo() );
1594 // for each hypothesis create HDF group basing on its id
1595 char hypGrpName[30];
1596 sprintf( hypGrpName, "Hypothesis %d", id );
1597 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1598 aGroup->CreateOnDisk();
1599 // --> type name of hypothesis
1600 aSize[ 0 ] = hypname.length() + 1;
1601 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1602 aDataset->CreateOnDisk();
1603 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1604 aDataset->CloseOnDisk();
1605 // --> server plugin library name of hypothesis
1606 aSize[ 0 ] = libname.length() + 1;
1607 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1608 aDataset->CreateOnDisk();
1609 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1610 aDataset->CloseOnDisk();
1611 // --> persistent data of hypothesis
1612 aSize[ 0 ] = hypdata.length() + 1;
1613 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1614 aDataset->CreateOnDisk();
1615 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1616 aDataset->CloseOnDisk();
1617 // close hypothesis HDF group
1618 aGroup->CloseOnDisk();
1623 // close hypotheses root HDF group
1624 aTopGroup->CloseOnDisk();
1626 // --> algorithms root branch (only one for the study)
1627 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1628 // create algorithms root HDF group
1629 aTopGroup = new HDFgroup( "Algorithms", aFile );
1630 aTopGroup->CreateOnDisk();
1632 // iterator for all algorithms
1633 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1634 for ( ; it->More(); it->Next() ) {
1635 SALOMEDS::SObject_var mySObject = it->Value();
1636 CORBA::Object_var anObject = SObjectToObject( mySObject );
1637 if ( !CORBA::is_nil( anObject ) ) {
1638 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1639 if ( !myHyp->_is_nil() ) {
1640 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1642 string hypname = string( myHyp->GetName() );
1643 string libname = string( myHyp->GetLibName() );
1644 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1645 string hypdata = string( myImpl->SaveTo() );
1647 // for each algorithm create HDF group basing on its id
1648 char hypGrpName[30];
1649 sprintf( hypGrpName, "Algorithm %d", id );
1650 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1651 aGroup->CreateOnDisk();
1652 // --> type name of algorithm
1653 aSize[0] = hypname.length() + 1;
1654 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1655 aDataset->CreateOnDisk();
1656 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1657 aDataset->CloseOnDisk();
1658 // --> server plugin library name of hypothesis
1659 aSize[0] = libname.length() + 1;
1660 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1661 aDataset->CreateOnDisk();
1662 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1663 aDataset->CloseOnDisk();
1664 // --> persistent data of algorithm
1665 aSize[0] = hypdata.length() + 1;
1666 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1667 aDataset->CreateOnDisk();
1668 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1669 aDataset->CloseOnDisk();
1670 // close algorithm HDF group
1671 aGroup->CloseOnDisk();
1676 // close algorithms root HDF group
1677 aTopGroup->CloseOnDisk();
1679 // --> mesh objects roots branches
1680 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1681 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1682 if ( !CORBA::is_nil( anObject ) ) {
1683 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1684 if ( !myMesh->_is_nil() ) {
1685 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1687 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1688 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1689 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1691 // for each mesh open the HDF group basing on its id
1692 char meshGrpName[ 30 ];
1693 sprintf( meshGrpName, "Mesh %d", id );
1694 aTopGroup = new HDFgroup( meshGrpName, aFile );
1695 aTopGroup->CreateOnDisk();
1697 // --> put dataset to hdf file which is a flag that mesh has data
1698 string strHasData = "0";
1699 // check if the mesh is not empty
1700 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1701 // write mesh data to med file
1702 myWriter.SetMesh( mySMESHDSMesh );
1703 myWriter.SetMeshId( id );
1706 aSize[ 0 ] = strHasData.length() + 1;
1707 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1708 aDataset->CreateOnDisk();
1709 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1710 aDataset->CloseOnDisk();
1712 // write reference on a shape if exists
1713 SALOMEDS::SObject_var myRef;
1714 bool shapeRefFound = false;
1715 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1717 SALOMEDS::SObject_var myShape;
1718 bool ok = myRef->ReferencedObject( myShape );
1720 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1721 string myRefOnObject = myShape->GetID();
1722 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1723 aSize[ 0 ] = myRefOnObject.length() + 1;
1724 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1725 aDataset->CreateOnDisk();
1726 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1727 aDataset->CloseOnDisk();
1732 // write applied hypotheses if exist
1733 SALOMEDS::SObject_var myHypBranch;
1734 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1735 if ( found && !shapeRefFound ) { // remove applied hyps
1736 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1738 if ( found && shapeRefFound ) {
1739 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1740 aGroup->CreateOnDisk();
1742 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1744 for ( ; it->More(); it->Next() ) {
1745 SALOMEDS::SObject_var mySObject = it->Value();
1746 SALOMEDS::SObject_var myRefOnHyp;
1747 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1749 // san - it is impossible to recover applied hypotheses
1750 // using their entries within Load() method,
1751 // for there are no AttributeIORs in the study when Load() is working.
1752 // Hence, it is better to store persistent IDs of hypotheses as references to them
1754 //string myRefOnObject = myRefOnHyp->GetID();
1755 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1756 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1757 //if ( myRefOnObject.length() > 0 ) {
1758 //aSize[ 0 ] = myRefOnObject.length() + 1;
1759 char hypName[ 30 ], hypId[ 30 ];
1760 sprintf( hypName, "Hyp %d", ++hypNb );
1761 sprintf( hypId, "%d", id );
1762 aSize[ 0 ] = strlen( hypId ) + 1;
1763 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1764 aDataset->CreateOnDisk();
1765 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1766 aDataset->WriteOnDisk( hypId );
1767 aDataset->CloseOnDisk();
1771 aGroup->CloseOnDisk();
1774 // write applied algorithms if exist
1775 SALOMEDS::SObject_var myAlgoBranch;
1776 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1777 if ( found && !shapeRefFound ) { // remove applied algos
1778 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1780 if ( found && shapeRefFound ) {
1781 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1782 aGroup->CreateOnDisk();
1784 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1786 for ( ; it->More(); it->Next() ) {
1787 SALOMEDS::SObject_var mySObject = it->Value();
1788 SALOMEDS::SObject_var myRefOnAlgo;
1789 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1791 // san - it is impossible to recover applied algorithms
1792 // using their entries within Load() method,
1793 // for there are no AttributeIORs in the study when Load() is working.
1794 // Hence, it is better to store persistent IDs of algorithms as references to them
1796 //string myRefOnObject = myRefOnAlgo->GetID();
1797 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1798 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1799 //if ( myRefOnObject.length() > 0 ) {
1800 //aSize[ 0 ] = myRefOnObject.length() + 1;
1801 char algoName[ 30 ], algoId[ 30 ];
1802 sprintf( algoName, "Algo %d", ++algoNb );
1803 sprintf( algoId, "%d", id );
1804 aSize[ 0 ] = strlen( algoId ) + 1;
1805 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1806 aDataset->CreateOnDisk();
1807 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1808 aDataset->WriteOnDisk( algoId );
1809 aDataset->CloseOnDisk();
1813 aGroup->CloseOnDisk();
1816 // --> submesh objects sub-branches
1818 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1819 SALOMEDS::SObject_var mySubmeshBranch;
1820 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1822 if ( found ) // check if there is shape reference in submeshes
1824 bool hasShapeRef = false;
1825 SALOMEDS::ChildIterator_var itSM =
1826 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1827 for ( ; itSM->More(); itSM->Next() ) {
1828 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1829 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1830 mySubRef->ReferencedObject( myShape );
1831 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1834 { // remove one submesh
1835 if ( shapeRefFound )
1836 { // unassign hypothesis
1837 SMESH::SMESH_subMesh_var mySubMesh =
1838 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1839 if ( !mySubMesh->_is_nil() ) {
1840 int shapeID = mySubMesh->GetId();
1841 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1842 const list<const SMESHDS_Hypothesis*>& hypList =
1843 mySMESHDSMesh->GetHypothesis( S );
1844 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1845 while ( hyp != hypList.end() ) {
1846 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1847 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
1851 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
1853 } // loop on submeshes of a type
1854 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
1855 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
1858 } // end check if there is shape reference in submeshes
1860 char name_meshgroup[ 30 ];
1861 if ( i == GetSubMeshOnVertexTag() )
1862 strcpy( name_meshgroup, "SubMeshes On Vertex" );
1863 else if ( i == GetSubMeshOnEdgeTag() )
1864 strcpy( name_meshgroup, "SubMeshes On Edge" );
1865 else if ( i == GetSubMeshOnWireTag() )
1866 strcpy( name_meshgroup, "SubMeshes On Wire" );
1867 else if ( i == GetSubMeshOnFaceTag() )
1868 strcpy( name_meshgroup, "SubMeshes On Face" );
1869 else if ( i == GetSubMeshOnShellTag() )
1870 strcpy( name_meshgroup, "SubMeshes On Shell" );
1871 else if ( i == GetSubMeshOnSolidTag() )
1872 strcpy( name_meshgroup, "SubMeshes On Solid" );
1873 else if ( i == GetSubMeshOnCompoundTag() )
1874 strcpy( name_meshgroup, "SubMeshes On Compound" );
1876 // for each type of submeshes create container HDF group
1877 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
1878 aGroup->CreateOnDisk();
1880 // iterator for all submeshes of given type
1881 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
1882 for ( ; itSM->More(); itSM->Next() ) {
1883 SALOMEDS::SObject_var mySObject = itSM->Value();
1884 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
1885 if ( !CORBA::is_nil( anSubObject ))
1887 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
1888 int subid = myStudyContext->findId( string( GetORB()->object_to_string( anSubObject ) ) );
1890 // for each mesh open the HDF group basing on its id
1891 char submeshGrpName[ 30 ];
1892 sprintf( submeshGrpName, "SubMesh %d", subid );
1893 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
1894 aSubGroup->CreateOnDisk();
1896 // write reference on a shape, already checked if it exists
1897 SALOMEDS::SObject_var mySubRef, myShape;
1898 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1899 mySubRef->ReferencedObject( myShape );
1900 string myRefOnObject = myShape->GetID();
1901 if ( myRefOnObject.length() > 0 ) {
1902 aSize[ 0 ] = myRefOnObject.length() + 1;
1903 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
1904 aDataset->CreateOnDisk();
1905 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1906 aDataset->CloseOnDisk();
1909 // write applied hypotheses if exist
1910 SALOMEDS::SObject_var mySubHypBranch;
1911 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
1913 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
1914 aSubSubGroup->CreateOnDisk();
1916 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
1918 for ( ; it->More(); it->Next() ) {
1919 SALOMEDS::SObject_var mySubSObject = it->Value();
1920 SALOMEDS::SObject_var myRefOnHyp;
1921 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
1923 //string myRefOnObject = myRefOnHyp->GetID();
1924 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1925 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1926 //if ( myRefOnObject.length() > 0 ) {
1927 //aSize[ 0 ] = myRefOnObject.length() + 1;
1928 char hypName[ 30 ], hypId[ 30 ];
1929 sprintf( hypName, "Hyp %d", ++hypNb );
1930 sprintf( hypId, "%d", id );
1931 aSize[ 0 ] = strlen( hypId ) + 1;
1932 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
1933 aDataset->CreateOnDisk();
1934 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1935 aDataset->WriteOnDisk( hypId );
1936 aDataset->CloseOnDisk();
1940 aSubSubGroup->CloseOnDisk();
1943 // write applied algorithms if exist
1944 SALOMEDS::SObject_var mySubAlgoBranch;
1945 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
1947 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
1948 aSubSubGroup->CreateOnDisk();
1950 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
1952 for ( ; it->More(); it->Next() ) {
1953 SALOMEDS::SObject_var mySubSObject = it->Value();
1954 SALOMEDS::SObject_var myRefOnAlgo;
1955 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
1957 //string myRefOnObject = myRefOnAlgo->GetID();
1958 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1959 int id = myStudyContext->findId( string( GetORB()->object_to_string( anObject ) ) );
1960 //if ( myRefOnObject.length() > 0 ) {
1961 //aSize[ 0 ] = myRefOnObject.length() + 1;
1962 char algoName[ 30 ], algoId[ 30 ];
1963 sprintf( algoName, "Algo %d", ++algoNb );
1964 sprintf( algoId, "%d", id );
1965 aSize[ 0 ] = strlen( algoId ) + 1;
1966 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
1967 aDataset->CreateOnDisk();
1968 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1969 aDataset->WriteOnDisk( algoId );
1970 aDataset->CloseOnDisk();
1974 aSubSubGroup->CloseOnDisk();
1976 // close submesh HDF group
1977 aSubGroup->CloseOnDisk();
1980 // close container of submeshes by type HDF group
1981 aGroup->CloseOnDisk();
1984 // All sub-meshes will be stored in MED file
1985 // .. will NOT (PAL 12992)
1986 //if ( shapeRefFound )
1987 //myWriter.AddAllSubMeshes();
1989 // groups root sub-branch
1990 SALOMEDS::SObject_var myGroupsBranch;
1991 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
1992 found = gotBranch->FindSubObject( i, myGroupsBranch );
1994 char name_group[ 30 ];
1995 if ( i == GetNodeGroupsTag() )
1996 strcpy( name_group, "Groups of Nodes" );
1997 else if ( i == GetEdgeGroupsTag() )
1998 strcpy( name_group, "Groups of Edges" );
1999 else if ( i == GetFaceGroupsTag() )
2000 strcpy( name_group, "Groups of Faces" );
2001 else if ( i == GetVolumeGroupsTag() )
2002 strcpy( name_group, "Groups of Volumes" );
2004 aGroup = new HDFgroup( name_group, aTopGroup );
2005 aGroup->CreateOnDisk();
2007 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
2008 for ( ; it->More(); it->Next() ) {
2009 SALOMEDS::SObject_var mySObject = it->Value();
2010 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
2011 if ( !CORBA::is_nil( aSubObject ) ) {
2012 SMESH_GroupBase_i* myGroupImpl =
2013 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
2017 int anId = myStudyContext->findId( string( GetORB()->object_to_string( aSubObject ) ) );
2019 // For each group, create a dataset named "Group <group_persistent_id>"
2020 // and store the group's user name into it
2022 sprintf( grpName, "Group %d", anId );
2023 char* aUserName = myGroupImpl->GetName();
2024 aSize[ 0 ] = strlen( aUserName ) + 1;
2026 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
2027 aDataset->CreateOnDisk();
2028 aDataset->WriteOnDisk( aUserName );
2029 aDataset->CloseOnDisk();
2031 // Store the group contents into MED file
2032 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
2034 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
2035 << grpName << " to MED file" );
2036 SMESHDS_GroupBase* aGrpBaseDS =
2037 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
2038 aGrpBaseDS->SetStoreName( grpName );
2040 // Pass SMESHDS_Group to MED writer
2041 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
2043 myWriter.AddGroup( aGrpDS );
2045 // write reference on a shape if exists
2046 SMESHDS_GroupOnGeom* aGeomGrp =
2047 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
2049 SALOMEDS::SObject_var mySubRef, myShape;
2050 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
2051 mySubRef->ReferencedObject( myShape ) &&
2052 !CORBA::is_nil( myShape->GetObject() ))
2054 string myRefOnObject = myShape->GetID();
2055 if ( myRefOnObject.length() > 0 ) {
2056 char aRefName[ 30 ];
2057 sprintf( aRefName, "Ref on shape %d", anId);
2058 aSize[ 0 ] = myRefOnObject.length() + 1;
2059 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
2060 aDataset->CreateOnDisk();
2061 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2062 aDataset->CloseOnDisk();
2065 else // shape ref is invalid:
2067 // save a group on geometry as ordinary group
2068 myWriter.AddGroup( aGeomGrp );
2074 aGroup->CloseOnDisk();
2078 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
2080 // Flush current mesh information into MED file
2083 // maybe a shape was deleted in the study
2084 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() ) {
2085 TopoDS_Shape nullShape;
2086 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
2089 if ( !mySMESHDSMesh->SubMeshes().empty() )
2093 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2094 aGroup->CreateOnDisk();
2096 // each element belongs to one or none submesh,
2097 // so for each node/element, we store a submesh ID
2099 // Make maps of submesh IDs of elements sorted by element IDs
2100 typedef int TElemID;
2101 typedef int TSubMID;
2102 map< TElemID, TSubMID > eId2smId, nId2smId;
2103 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
2104 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
2105 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
2106 SMDS_NodeIteratorPtr itNode;
2107 SMDS_ElemIteratorPtr itElem;
2108 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2110 TSubMID aSubMeID = itSubM->first;
2111 SMESHDS_SubMesh* aSubMesh = itSubM->second;
2112 if ( aSubMesh->IsComplexSubmesh() )
2113 continue; // submesh containing other submeshs
2115 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
2116 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
2117 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
2119 hint = eId2smId.begin();
2120 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
2121 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
2124 // Care of elements that are not on submeshes
2125 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
2126 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
2127 /* --- stl_map.h says : */
2128 /* A %map relies on unique keys and thus a %pair is only inserted if its */
2129 /* first element (the key) is not already present in the %map. */
2130 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
2132 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
2133 if ( nbElems != eId2smId.size() ) {
2134 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
2135 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
2138 // Store submesh IDs
2139 for ( int isNode = 0; isNode < 2; ++isNode )
2141 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
2142 if ( id2smId.empty() ) continue;
2143 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
2144 // make and fill array of submesh IDs
2145 int* smIDs = new int [ id2smId.size() ];
2146 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
2147 smIDs[ i ] = id_smId->second;
2149 aSize[ 0 ] = id2smId.size();
2150 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2151 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2152 aDataset->CreateOnDisk();
2153 aDataset->WriteOnDisk( smIDs );
2154 aDataset->CloseOnDisk();
2159 // Store node positions on sub-shapes (SMDS_Position):
2160 // ----------------------------------------------------
2162 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2163 aGroup->CreateOnDisk();
2165 // in aGroup, create 5 datasets to contain:
2166 // "Nodes on Edges" - ID of node on edge
2167 // "Edge positions" - U parameter on node on edge
2168 // "Nodes on Faces" - ID of node on face
2169 // "Face U positions" - U parameter of node on face
2170 // "Face V positions" - V parameter of node on face
2172 // Find out nb of nodes on edges and faces
2173 // Collect corresponing sub-meshes
2174 int nbEdgeNodes = 0, nbFaceNodes = 0;
2175 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
2176 // loop on SMESHDS_SubMesh'es
2177 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2179 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
2180 if ( aSubMesh->IsComplexSubmesh() )
2181 continue; // submesh containing other submeshs
2182 int nbNodes = aSubMesh->NbNodes();
2183 if ( nbNodes == 0 ) continue;
2185 int aShapeID = (*itSubM).first;
2186 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
2187 // write only SMDS_FacePosition and SMDS_EdgePosition
2188 switch ( aShapeType ) {
2190 nbFaceNodes += nbNodes;
2191 aFaceSM.push_back( aSubMesh );
2194 nbEdgeNodes += nbNodes;
2195 aEdgeSM.push_back( aSubMesh );
2201 // Treat positions on edges or faces
2202 for ( int onFace = 0; onFace < 2; onFace++ )
2204 // Create arrays to store in datasets
2205 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
2206 if (!nbNodes) continue;
2207 int* aNodeIDs = new int [ nbNodes ];
2208 double* aUPos = new double [ nbNodes ];
2209 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
2212 // loop on sub-meshes
2213 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
2214 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
2215 for ( ; itSM != pListSM->end(); itSM++ )
2217 SMESHDS_SubMesh* aSubMesh = (*itSM);
2219 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
2220 // loop on nodes in aSubMesh
2221 while ( itNode->more() )
2224 const SMDS_MeshNode* node = itNode->next();
2225 aNodeIDs [ iNode ] = node->GetID();
2228 const SMDS_PositionPtr pos = node->GetPosition();
2229 if ( onFace ) { // on FACE
2230 const SMDS_FacePosition* fPos =
2231 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
2233 aUPos[ iNode ] = fPos->GetUParameter();
2234 aVPos[ iNode ] = fPos->GetVParameter();
2241 const SMDS_EdgePosition* ePos =
2242 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
2244 aUPos[ iNode ] = ePos->GetUParameter();
2250 } // loop on nodes in aSubMesh
2251 } // loop on sub-meshes
2256 aSize[ 0 ] = nbNodes;
2258 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
2259 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2260 aDataset->CreateOnDisk();
2261 aDataset->WriteOnDisk( aNodeIDs );
2262 aDataset->CloseOnDisk();
2265 aDSName = ( onFace ? "Face U positions" : "Edge positions");
2266 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
2267 aDataset->CreateOnDisk();
2268 aDataset->WriteOnDisk( aUPos );
2269 aDataset->CloseOnDisk();
2272 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
2273 aDataset->CreateOnDisk();
2274 aDataset->WriteOnDisk( aVPos );
2275 aDataset->CloseOnDisk();
2280 if ( aVPos ) delete [] aVPos;
2282 } // treat positions on edges or faces
2284 // close "Node Positions" group
2285 aGroup->CloseOnDisk();
2287 } // if ( there are submeshes in SMESHDS_Mesh )
2290 // close mesh HDF group
2291 aTopGroup->CloseOnDisk();
2299 aFile->CloseOnDisk();
2302 // Convert temporary files to stream
2303 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
2305 // Remove temporary files and directory
2307 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2309 INFOS( "SMESH_Gen_i::Save() completed" );
2310 return aStreamFile._retn();
2313 //=============================================================================
2315 * SMESH_Gen_i::SaveASCII
2317 * Save SMESH module's data in ASCII format (not implemented yet)
2319 //=============================================================================
2321 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2323 bool isMultiFile ) {
2324 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2325 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2326 return aStreamFile._retn();
2329 //=============================================================================
2331 * SMESH_Gen_i::loadGeomData
2333 * Load GEOM module data
2335 //=============================================================================
2337 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2339 if ( theCompRoot->_is_nil() )
2342 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2343 if ( aStudy->_is_nil() )
2346 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2347 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2349 //=============================================================================
2351 * \brief Creates SMDS_Position according to shape type
2353 //=============================================================================
2355 class PositionCreator {
2357 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
2358 return (this->*myFuncTable[ type ])();
2361 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
2362 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
2363 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
2364 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
2367 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
2368 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
2369 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
2370 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
2371 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
2372 vector<FmakePos> myFuncTable;
2375 //=============================================================================
2379 * Load SMESH module's data
2381 //=============================================================================
2383 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2384 const SALOMEDS::TMPFile& theStream,
2388 INFOS( "SMESH_Gen_i::Load" );
2390 if ( myCurrentStudy->_is_nil() ||
2391 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2392 SetCurrentStudy( theComponent->GetStudy() );
2394 /* if( !theComponent->_is_nil() )
2396 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2397 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2398 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2401 StudyContext* myStudyContext = GetCurrentStudyContext();
2403 // Get temporary files location
2404 TCollection_AsciiString tmpDir =
2405 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2407 // Convert the stream into sequence of files to process
2408 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2411 TCollection_AsciiString aStudyName( "" );
2413 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2415 // Set names of temporary files
2416 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2417 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2421 HDFdataset* aDataset;
2422 HDFgroup* aTopGroup;
2424 HDFgroup* aSubGroup;
2425 HDFgroup* aSubSubGroup;
2428 // ---> open HDF file
2429 aFile = new HDFfile( filename.ToCString() );
2431 aFile->OpenOnDisk( HDF_RDONLY );
2433 catch ( HDFexception ) {
2434 INFOS( "Load(): " << filename << " not found!" );
2438 DriverMED_R_SMESHDS_Mesh myReader;
2439 myReader.SetFile( meshfile.ToCString() );
2441 // For PAL13473 ("Repetitive mesh") implementation.
2442 // New dependencies between SMESH objects are established:
2443 // now hypotheses can refer to meshes, shapes and other hypotheses.
2444 // To keep data consistent, the following order of data restoration
2446 // 1. Create hypotheses
2447 // 2. Create all meshes
2448 // 3. Load hypotheses' data
2451 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
2452 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
2454 // get total number of top-level groups
2455 int aNbGroups = aFile->nInternalObjects();
2456 if ( aNbGroups > 0 ) {
2457 // --> in first turn we should read&create hypotheses
2458 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2459 // open hypotheses root HDF group
2460 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2461 aTopGroup->OpenOnDisk();
2463 // get number of hypotheses
2464 int aNbObjects = aTopGroup->nInternalObjects();
2465 for ( int j = 0; j < aNbObjects; j++ ) {
2466 // try to identify hypothesis
2467 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2468 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2470 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2471 // open hypothesis group
2472 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2473 aGroup->OpenOnDisk();
2475 // --> get hypothesis id
2476 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2481 // get number of datasets
2482 int aNbSubObjects = aGroup->nInternalObjects();
2483 for ( int k = 0; k < aNbSubObjects; k++ ) {
2485 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2486 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2487 // --> get hypothesis name
2488 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2489 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2490 aDataset->OpenOnDisk();
2491 size = aDataset->GetSize();
2492 char* hypname_str = new char[ size ];
2493 aDataset->ReadFromDisk( hypname_str );
2494 hypname = string( hypname_str );
2495 delete [] hypname_str;
2496 aDataset->CloseOnDisk();
2498 // --> get hypothesis plugin library name
2499 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2500 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2501 aDataset->OpenOnDisk();
2502 size = aDataset->GetSize();
2503 char* libname_str = new char[ size ];
2504 aDataset->ReadFromDisk( libname_str );
2505 if(MYDEBUG) SCRUTE( libname_str );
2506 libname = string( libname_str );
2507 delete [] libname_str;
2508 aDataset->CloseOnDisk();
2510 // --> get hypothesis data
2511 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2512 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2513 aDataset->OpenOnDisk();
2514 size = aDataset->GetSize();
2515 char* hypdata_str = new char[ size ];
2516 aDataset->ReadFromDisk( hypdata_str );
2517 hypdata = string( hypdata_str );
2518 delete [] hypdata_str;
2519 aDataset->CloseOnDisk();
2522 // close hypothesis HDF group
2523 aGroup->CloseOnDisk();
2525 // --> restore hypothesis from data
2526 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2527 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2528 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2529 SMESH::SMESH_Hypothesis_var myHyp;
2531 try { // protect persistence mechanism against exceptions
2532 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2535 INFOS( "Exception during hypothesis creation" );
2538 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2540 // myImpl->LoadFrom( hypdata.c_str() );
2541 hypDataList.push_back( make_pair( myImpl, hypdata ));
2542 string iorString = GetORB()->object_to_string( myHyp );
2543 int newId = myStudyContext->findId( iorString );
2544 myStudyContext->mapOldToNew( id, newId );
2547 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2551 // close hypotheses root HDF group
2552 aTopGroup->CloseOnDisk();
2555 // --> then we should read&create algorithms
2556 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2557 // open algorithms root HDF group
2558 aTopGroup = new HDFgroup( "Algorithms", aFile );
2559 aTopGroup->OpenOnDisk();
2561 // get number of algorithms
2562 int aNbObjects = aTopGroup->nInternalObjects();
2563 for ( int j = 0; j < aNbObjects; j++ ) {
2564 // try to identify algorithm
2565 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2566 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2568 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2569 // open algorithm group
2570 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2571 aGroup->OpenOnDisk();
2573 // --> get algorithm id
2574 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2579 // get number of datasets
2580 int aNbSubObjects = aGroup->nInternalObjects();
2581 for ( int k = 0; k < aNbSubObjects; k++ ) {
2583 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2584 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2585 // --> get algorithm name
2586 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2587 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2588 aDataset->OpenOnDisk();
2589 size = aDataset->GetSize();
2590 char* hypname_str = new char[ size ];
2591 aDataset->ReadFromDisk( hypname_str );
2592 hypname = string( hypname_str );
2593 delete [] hypname_str;
2594 aDataset->CloseOnDisk();
2596 // --> get algorithm plugin library name
2597 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2598 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2599 aDataset->OpenOnDisk();
2600 size = aDataset->GetSize();
2601 char* libname_str = new char[ size ];
2602 aDataset->ReadFromDisk( libname_str );
2603 if(MYDEBUG) SCRUTE( libname_str );
2604 libname = string( libname_str );
2605 delete [] libname_str;
2606 aDataset->CloseOnDisk();
2608 // --> get algorithm data
2609 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2610 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2611 aDataset->OpenOnDisk();
2612 size = aDataset->GetSize();
2613 char* hypdata_str = new char[ size ];
2614 aDataset->ReadFromDisk( hypdata_str );
2615 if(MYDEBUG) SCRUTE( hypdata_str );
2616 hypdata = string( hypdata_str );
2617 delete [] hypdata_str;
2618 aDataset->CloseOnDisk();
2621 // close algorithm HDF group
2622 aGroup->CloseOnDisk();
2624 // --> restore algorithm from data
2625 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2626 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2627 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2628 SMESH::SMESH_Hypothesis_var myHyp;
2630 try { // protect persistence mechanism against exceptions
2631 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2634 INFOS( "Exception during hypothesis creation" );
2637 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2639 //myImpl->LoadFrom( hypdata.c_str() );
2640 hypDataList.push_back( make_pair( myImpl, hypdata ));
2641 string iorString = GetORB()->object_to_string( myHyp );
2642 int newId = myStudyContext->findId( iorString );
2643 myStudyContext->mapOldToNew( id, newId );
2646 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2650 // close algorithms root HDF group
2651 aTopGroup->CloseOnDisk();
2654 // --> the rest groups should be meshes
2655 for ( int i = 0; i < aNbGroups; i++ ) {
2656 // identify next group
2657 char meshName[ HDF_NAME_MAX_LEN+1 ];
2658 aFile->InternalObjectIndentify( i, meshName );
2660 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2662 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2666 // open mesh HDF group
2667 aTopGroup = new HDFgroup( meshName, aFile );
2668 aTopGroup->OpenOnDisk();
2670 // get number of child HDF objects
2671 int aNbObjects = aTopGroup->nInternalObjects();
2672 if ( aNbObjects > 0 ) {
2674 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2675 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2676 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2677 if ( !myNewMeshImpl )
2679 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
2681 string iorString = GetORB()->object_to_string( myNewMesh );
2682 int newId = myStudyContext->findId( iorString );
2683 myStudyContext->mapOldToNew( id, newId );
2685 // try to read and set reference to shape
2686 GEOM::GEOM_Object_var aShapeObject;
2687 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2688 // load mesh "Ref on shape" - it's an entry to SObject
2689 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2690 aDataset->OpenOnDisk();
2691 size = aDataset->GetSize();
2692 char* refFromFile = new char[ size ];
2693 aDataset->ReadFromDisk( refFromFile );
2694 aDataset->CloseOnDisk();
2695 if ( strlen( refFromFile ) > 0 ) {
2696 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2698 // Make sure GEOM data are loaded first
2699 //loadGeomData( shapeSO->GetFatherComponent() );
2701 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2702 if ( !CORBA::is_nil( shapeObject ) ) {
2703 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2704 if ( !aShapeObject->_is_nil() )
2705 myNewMeshImpl->SetShape( aShapeObject );
2714 // As all object that can be referred by hypothesis are created,
2715 // we can restore hypothesis data
2717 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
2718 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
2720 SMESH_Hypothesis_i* hyp = hyp_data->first;
2721 string & data = hyp_data->second;
2722 hyp->LoadFrom( data.c_str() );
2725 // Restore the rest mesh data
2727 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
2728 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
2730 aTopGroup = meshi_group->second;
2731 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
2732 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2733 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2735 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
2736 bool hasData = false;
2739 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
2740 int newId = myStudyContext->findId( iorString );
2741 int id = myStudyContext->getOldId( newId );
2743 // try to find mesh data dataset
2744 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2745 // load mesh "has data" flag
2746 aDataset = new HDFdataset( "Has data", aTopGroup );
2747 aDataset->OpenOnDisk();
2748 size = aDataset->GetSize();
2749 char* strHasData = new char[ size ];
2750 aDataset->ReadFromDisk( strHasData );
2751 aDataset->CloseOnDisk();
2752 if ( strcmp( strHasData, "1") == 0 ) {
2753 // read mesh data from MED file
2754 myReader.SetMesh( mySMESHDSMesh );
2755 myReader.SetMeshId( id );
2761 // try to get applied algorithms
2762 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2763 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2764 aGroup->OpenOnDisk();
2765 // get number of applied algorithms
2766 int aNbSubObjects = aGroup->nInternalObjects();
2767 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2768 for ( int j = 0; j < aNbSubObjects; j++ ) {
2769 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2770 aGroup->InternalObjectIndentify( j, name_dataset );
2771 // check if it is an algorithm
2772 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2773 aDataset = new HDFdataset( name_dataset, aGroup );
2774 aDataset->OpenOnDisk();
2775 size = aDataset->GetSize();
2776 char* refFromFile = new char[ size ];
2777 aDataset->ReadFromDisk( refFromFile );
2778 aDataset->CloseOnDisk();
2780 // san - it is impossible to recover applied algorithms using their entries within Load() method
2782 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2783 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2784 int id = atoi( refFromFile );
2785 string anIOR = myStudyContext->getIORbyOldId( id );
2786 if ( !anIOR.empty() ) {
2787 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2788 if ( !CORBA::is_nil( hypObject ) ) {
2789 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2790 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2791 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2796 aGroup->CloseOnDisk();
2799 // try to get applied hypotheses
2800 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2801 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2802 aGroup->OpenOnDisk();
2803 // get number of applied hypotheses
2804 int aNbSubObjects = aGroup->nInternalObjects();
2805 for ( int j = 0; j < aNbSubObjects; j++ ) {
2806 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2807 aGroup->InternalObjectIndentify( j, name_dataset );
2808 // check if it is a hypothesis
2809 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2810 aDataset = new HDFdataset( name_dataset, aGroup );
2811 aDataset->OpenOnDisk();
2812 size = aDataset->GetSize();
2813 char* refFromFile = new char[ size ];
2814 aDataset->ReadFromDisk( refFromFile );
2815 aDataset->CloseOnDisk();
2817 // san - it is impossible to recover applied hypotheses using their entries within Load() method
2819 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2820 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2821 int id = atoi( refFromFile );
2822 string anIOR = myStudyContext->getIORbyOldId( id );
2823 if ( !anIOR.empty() ) {
2824 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2825 if ( !CORBA::is_nil( hypObject ) ) {
2826 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2827 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2828 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
2833 aGroup->CloseOnDisk();
2836 // --> try to find submeshes containers for each type of submesh
2837 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
2838 char name_meshgroup[ 30 ];
2839 if ( j == GetSubMeshOnVertexTag() )
2840 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2841 else if ( j == GetSubMeshOnEdgeTag() )
2842 strcpy( name_meshgroup, "SubMeshes On Edge" );
2843 else if ( j == GetSubMeshOnWireTag() )
2844 strcpy( name_meshgroup, "SubMeshes On Wire" );
2845 else if ( j == GetSubMeshOnFaceTag() )
2846 strcpy( name_meshgroup, "SubMeshes On Face" );
2847 else if ( j == GetSubMeshOnShellTag() )
2848 strcpy( name_meshgroup, "SubMeshes On Shell" );
2849 else if ( j == GetSubMeshOnSolidTag() )
2850 strcpy( name_meshgroup, "SubMeshes On Solid" );
2851 else if ( j == GetSubMeshOnCompoundTag() )
2852 strcpy( name_meshgroup, "SubMeshes On Compound" );
2854 // try to get submeshes container HDF group
2855 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
2856 // open submeshes containers HDF group
2857 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2858 aGroup->OpenOnDisk();
2860 // get number of submeshes
2861 int aNbSubMeshes = aGroup->nInternalObjects();
2862 for ( int k = 0; k < aNbSubMeshes; k++ ) {
2864 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
2865 aGroup->InternalObjectIndentify( k, name_submeshgroup );
2866 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
2867 // --> get submesh id
2868 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
2871 // open submesh HDF group
2872 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
2873 aSubGroup->OpenOnDisk();
2875 // try to read and set reference to subshape
2876 GEOM::GEOM_Object_var aSubShapeObject;
2877 SMESH::SMESH_subMesh_var aSubMesh;
2879 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
2880 // load submesh "Ref on shape" - it's an entry to SObject
2881 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
2882 aDataset->OpenOnDisk();
2883 size = aDataset->GetSize();
2884 char* refFromFile = new char[ size ];
2885 aDataset->ReadFromDisk( refFromFile );
2886 aDataset->CloseOnDisk();
2887 if ( strlen( refFromFile ) > 0 ) {
2888 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
2889 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
2890 if ( !CORBA::is_nil( subShapeObject ) ) {
2891 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
2892 if ( !aSubShapeObject->_is_nil() )
2893 aSubMesh = SMESH::SMESH_subMesh::_duplicate
2894 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
2895 if ( aSubMesh->_is_nil() )
2897 string iorSubString = GetORB()->object_to_string( aSubMesh );
2898 int newSubId = myStudyContext->findId( iorSubString );
2899 myStudyContext->mapOldToNew( subid, newSubId );
2904 if ( aSubMesh->_is_nil() )
2907 // VSR: Get submesh data from MED convertor
2908 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
2909 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
2910 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
2911 // subid << " for subshape # " << anInternalSubmeshId);
2912 // SMESHDS_SubMesh* aSubMeshDS =
2913 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
2914 // if ( !aSubMeshDS ) {
2915 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
2916 // anInternalSubmeshId << " in current mesh!");
2919 // myReader.GetSubMesh( aSubMeshDS, subid );
2922 // try to get applied algorithms
2923 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2924 // open "applied algorithms" HDF group
2925 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2926 aSubSubGroup->OpenOnDisk();
2927 // get number of applied algorithms
2928 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2929 for ( int l = 0; l < aNbSubObjects; l++ ) {
2930 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2931 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2932 // check if it is an algorithm
2933 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2934 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2935 aDataset->OpenOnDisk();
2936 size = aDataset->GetSize();
2937 char* refFromFile = new char[ size ];
2938 aDataset->ReadFromDisk( refFromFile );
2939 aDataset->CloseOnDisk();
2941 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2942 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2943 int id = atoi( refFromFile );
2944 string anIOR = myStudyContext->getIORbyOldId( id );
2945 if ( !anIOR.empty() ) {
2946 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2947 if ( !CORBA::is_nil( hypObject ) ) {
2948 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2949 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2950 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2955 // close "applied algorithms" HDF group
2956 aSubSubGroup->CloseOnDisk();
2959 // try to get applied hypotheses
2960 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
2961 // open "applied hypotheses" HDF group
2962 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2963 aSubSubGroup->OpenOnDisk();
2964 // get number of applied hypotheses
2965 int aNbSubObjects = aSubSubGroup->nInternalObjects();
2966 for ( int l = 0; l < aNbSubObjects; l++ ) {
2967 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2968 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
2969 // check if it is a hypothesis
2970 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
2971 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
2972 aDataset->OpenOnDisk();
2973 size = aDataset->GetSize();
2974 char* refFromFile = new char[ size ];
2975 aDataset->ReadFromDisk( refFromFile );
2976 aDataset->CloseOnDisk();
2978 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2979 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2980 int id = atoi( refFromFile );
2981 string anIOR = myStudyContext->getIORbyOldId( id );
2982 if ( !anIOR.empty() ) {
2983 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2984 if ( !CORBA::is_nil( hypObject ) ) {
2985 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2986 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
2987 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
2992 // close "applied hypotheses" HDF group
2993 aSubSubGroup->CloseOnDisk();
2996 // close submesh HDF group
2997 aSubGroup->CloseOnDisk();
3000 // close submeshes containers HDF group
3001 aGroup->CloseOnDisk();
3007 // Read sub-meshes from MED
3008 // -------------------------
3009 if(MYDEBUG) MESSAGE("Create all sub-meshes");
3010 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
3011 if ( submeshesInFamilies )
3013 // old way working before fix of PAL 12992
3014 myReader.CreateAllSubMeshes();
3019 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3020 aGroup->OpenOnDisk();
3022 int maxID = mySMESHDSMesh->MaxShapeIndex();
3023 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
3024 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
3026 PositionCreator aPositionCreator;
3028 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
3029 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
3030 for ( int isNode = 0; isNode < 2; ++isNode )
3032 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3033 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
3035 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
3036 aDataset->OpenOnDisk();
3037 // read submesh IDs for all elements sorted by ID
3038 int nbElems = aDataset->GetSize();
3039 int* smIDs = new int [ nbElems ];
3040 aDataset->ReadFromDisk( smIDs );
3041 aDataset->CloseOnDisk();
3043 // get elements sorted by ID
3044 TIDSortedElemSet elemSet;
3046 while ( nIt->more() ) elemSet.insert( nIt->next() );
3048 while ( eIt->more() ) elemSet.insert( eIt->next() );
3049 ASSERT( elemSet.size() == nbElems );
3051 // add elements to submeshes
3052 TIDSortedElemSet::iterator iE = elemSet.begin();
3053 for ( int i = 0; i < nbElems; ++i, ++iE )
3055 int smID = smIDs[ i ];
3056 if ( smID == 0 ) continue;
3057 ASSERT( smID <= maxID );
3058 const SMDS_MeshElement* elem = *iE;
3059 // get or create submesh
3060 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
3062 sm = mySMESHDSMesh->NewSubMesh( smID );
3063 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
3067 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
3068 pos->SetShapeId( smID );
3069 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
3070 node->SetPosition( pos );
3071 sm->AddNode( node );
3073 sm->AddElement( elem );
3079 } // end reading submeshes
3081 // Read node positions on sub-shapes (SMDS_Position)
3083 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
3085 // There are 5 datasets to read:
3086 // "Nodes on Edges" - ID of node on edge
3087 // "Edge positions" - U parameter on node on edge
3088 // "Nodes on Faces" - ID of node on face
3089 // "Face U positions" - U parameter of node on face
3090 // "Face V positions" - V parameter of node on face
3091 char* aEid_DSName = "Nodes on Edges";
3092 char* aEu_DSName = "Edge positions";
3093 char* aFu_DSName = "Face U positions";
3094 //char* aFid_DSName = "Nodes on Faces";
3095 //char* aFv_DSName = "Face V positions";
3098 int nbEids = 0, nbFids = 0;
3099 int *aEids = 0, *aFids = 0;
3100 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
3103 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3104 aGroup->OpenOnDisk();
3106 // loop on 5 data sets
3107 int aNbObjects = aGroup->nInternalObjects();
3108 for ( int i = 0; i < aNbObjects; i++ )
3111 char aDSName[ HDF_NAME_MAX_LEN+1 ];
3112 aGroup->InternalObjectIndentify( i, aDSName );
3114 aDataset = new HDFdataset( aDSName, aGroup );
3115 aDataset->OpenOnDisk();
3116 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
3118 double* pos = new double [ aDataset->GetSize() ];
3119 aDataset->ReadFromDisk( pos );
3121 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
3123 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
3130 int aSize = aDataset->GetSize();
3132 // for reading files, created from 18.07.2005 till 10.10.2005
3133 if (aDataset->GetType() == HDF_STRING)
3134 aSize /= sizeof(int);
3136 int* ids = new int [aSize];
3137 aDataset->ReadFromDisk( ids );
3138 // on face or nodes?
3139 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
3148 aDataset->CloseOnDisk();
3149 } // loop on 5 datasets
3151 // Set node positions on edges or faces
3152 for ( int onFace = 0; onFace < 2; onFace++ )
3154 int nbNodes = ( onFace ? nbFids : nbEids );
3155 if ( nbNodes == 0 ) continue;
3156 int* aNodeIDs = ( onFace ? aFids : aEids );
3157 double* aUPos = ( onFace ? aFupos : aEpos );
3158 double* aVPos = ( onFace ? aFvpos : 0 );
3160 for ( int iNode = 0; iNode < nbNodes; iNode++ )
3162 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
3164 SMDS_PositionPtr aPos = node->GetPosition();
3167 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
3168 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
3169 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
3170 fPos->SetUParameter( aUPos[ iNode ]);
3171 fPos->SetVParameter( aVPos[ iNode ]);
3174 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
3175 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
3176 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
3177 fPos->SetUParameter( aUPos[ iNode ]);
3181 if ( aEids ) delete [] aEids;
3182 if ( aFids ) delete [] aFids;
3183 if ( aEpos ) delete [] aEpos;
3184 if ( aFupos ) delete [] aFupos;
3185 if ( aFvpos ) delete [] aFvpos;
3187 aGroup->CloseOnDisk();
3189 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
3192 // Recompute State (as computed sub-meshes are restored from MED)
3193 if ( !aShapeObject->_is_nil() ) {
3194 MESSAGE("Compute State Engine ...");
3195 TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject );
3196 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
3197 (SMESH_subMesh::SUBMESH_RESTORED);
3198 MESSAGE("Compute State Engine finished");
3201 // try to get groups
3202 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
3203 char name_group[ 30 ];
3204 if ( ii == GetNodeGroupsTag() )
3205 strcpy( name_group, "Groups of Nodes" );
3206 else if ( ii == GetEdgeGroupsTag() )
3207 strcpy( name_group, "Groups of Edges" );
3208 else if ( ii == GetFaceGroupsTag() )
3209 strcpy( name_group, "Groups of Faces" );
3210 else if ( ii == GetVolumeGroupsTag() )
3211 strcpy( name_group, "Groups of Volumes" );
3213 if ( aTopGroup->ExistInternalObject( name_group ) ) {
3214 aGroup = new HDFgroup( name_group, aTopGroup );
3215 aGroup->OpenOnDisk();
3216 // get number of groups
3217 int aNbSubObjects = aGroup->nInternalObjects();
3218 for ( int j = 0; j < aNbSubObjects; j++ ) {
3219 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3220 aGroup->InternalObjectIndentify( j, name_dataset );
3221 // check if it is an group
3222 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
3224 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
3227 aDataset = new HDFdataset( name_dataset, aGroup );
3228 aDataset->OpenOnDisk();
3230 // Retrieve actual group name
3231 size = aDataset->GetSize();
3232 char* nameFromFile = new char[ size ];
3233 aDataset->ReadFromDisk( nameFromFile );
3234 aDataset->CloseOnDisk();
3236 // Try to find a shape reference
3237 TopoDS_Shape aShape;
3238 char aRefName[ 30 ];
3239 sprintf( aRefName, "Ref on shape %d", subid);
3240 if ( aGroup->ExistInternalObject( aRefName ) ) {
3241 // load mesh "Ref on shape" - it's an entry to SObject
3242 aDataset = new HDFdataset( aRefName, aGroup );
3243 aDataset->OpenOnDisk();
3244 size = aDataset->GetSize();
3245 char* refFromFile = new char[ size ];
3246 aDataset->ReadFromDisk( refFromFile );
3247 aDataset->CloseOnDisk();
3248 if ( strlen( refFromFile ) > 0 ) {
3249 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3250 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3251 if ( !CORBA::is_nil( shapeObject ) ) {
3252 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3253 if ( !aShapeObject->_is_nil() )
3254 aShape = GeomObjectToShape( aShapeObject );
3258 // Create group servant
3259 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
3260 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
3261 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
3262 // Obtain a SMESHDS_Group object
3263 if ( aNewGroup->_is_nil() )
3266 string iorSubString = GetORB()->object_to_string( aNewGroup );
3267 int newSubId = myStudyContext->findId( iorSubString );
3268 myStudyContext->mapOldToNew( subid, newSubId );
3270 SMESH_GroupBase_i* aGroupImpl =
3271 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
3275 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
3279 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
3280 aGroupBaseDS->SetStoreName( name_dataset );
3282 // Fill group with contents from MED file
3283 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
3285 myReader.GetGroup( aGrp );
3288 aGroup->CloseOnDisk();
3293 aTopGroup->CloseOnDisk();
3296 aFile->CloseOnDisk();
3299 // Remove temporary files created from the stream
3301 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3303 INFOS( "SMESH_Gen_i::Load completed" );
3307 //=============================================================================
3309 * SMESH_Gen_i::LoadASCII
3311 * Load SMESH module's data in ASCII format (not implemented yet)
3313 //=============================================================================
3315 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
3316 const SALOMEDS::TMPFile& theStream,
3318 bool isMultiFile ) {
3319 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
3320 return Load( theComponent, theStream, theURL, isMultiFile );
3323 //=============================================================================
3325 * SMESH_Gen_i::Close
3327 * Clears study-connected data when it is closed
3329 //=============================================================================
3331 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
3333 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
3335 // Clear study contexts data
3336 int studyId = GetCurrentStudyID();
3337 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
3338 delete myStudyContextMap[ studyId ];
3339 myStudyContextMap.erase( studyId );
3344 //=============================================================================
3346 * SMESH_Gen_i::ComponentDataType
3348 * Get component data type
3350 //=============================================================================
3352 char* SMESH_Gen_i::ComponentDataType()
3354 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
3355 return CORBA::string_dup( "SMESH" );
3359 //=============================================================================
3361 * SMESH_Gen_i::IORToLocalPersistentID
3363 * Transform data from transient form to persistent
3365 //=============================================================================
3367 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
3368 const char* IORString,
3369 CORBA::Boolean /*isMultiFile*/,
3370 CORBA::Boolean /*isASCII*/ )
3372 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
3373 StudyContext* myStudyContext = GetCurrentStudyContext();
3375 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
3376 int anId = myStudyContext->findId( IORString );
3378 if(MYDEBUG) MESSAGE( "VSR " << anId )
3380 sprintf( strId, "%d", anId );
3381 return CORBA::string_dup( strId );
3384 return CORBA::string_dup( "" );
3387 //=============================================================================
3389 * SMESH_Gen_i::LocalPersistentIDToIOR
3391 * Transform data from persistent form to transient
3393 //=============================================================================
3395 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
3396 const char* aLocalPersistentID,
3397 CORBA::Boolean /*isMultiFile*/,
3398 CORBA::Boolean /*isASCII*/ )
3400 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
3401 StudyContext* myStudyContext = GetCurrentStudyContext();
3403 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
3404 int anId = atoi( aLocalPersistentID );
3405 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
3407 return CORBA::string_dup( "" );
3410 //=======================================================================
3411 //function : RegisterObject
3413 //=======================================================================
3415 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
3417 StudyContext* myStudyContext = GetCurrentStudyContext();
3418 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3419 string iorString = GetORB()->object_to_string( theObject );
3420 return myStudyContext->addObject( iorString );
3425 //================================================================================
3427 * \brief Return id of registered object
3428 * \param theObject - the Object
3429 * \retval int - Object id
3431 //================================================================================
3433 int SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
3435 StudyContext* myStudyContext = GetCurrentStudyContext();
3436 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3437 string iorString = GetORB()->object_to_string( theObject );
3438 return myStudyContext->findId( iorString );
3443 //=============================================================================
3445 * SMESHEngine_factory
3447 * C factory, accessible with dlsym, after dlopen
3449 //=============================================================================
3453 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3454 PortableServer::POA_ptr poa,
3455 PortableServer::ObjectId* contId,
3456 const char* instanceName,
3457 const char* interfaceName )
3459 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3460 if(MYDEBUG) SCRUTE(interfaceName);
3461 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3462 return aSMESHGen->getId() ;