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"
64 #define LibHandle HMODULE
65 #define LoadLib( name ) LoadLibrary( name )
66 #define GetProc GetProcAddress
67 #define UnLoadLib( handle ) FreeLibrary( handle );
69 #define LibHandle void*
70 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
72 #define UnLoadLib( handle ) dlclose( handle );
77 #include "SMESH_Gen_i.hxx"
78 #include "SMESH_Mesh_i.hxx"
79 #include "SMESH_Hypothesis_i.hxx"
80 #include "SMESH_Algo_i.hxx"
81 #include "SMESH_Group_i.hxx"
82 #include "SMESH_PythonDump.hxx"
84 #include "SMESHDS_Document.hxx"
85 #include "SMESHDS_Group.hxx"
86 #include "SMESHDS_GroupOnGeom.hxx"
87 #include "SMESH_Mesh.hxx"
88 #include "SMESH_Hypothesis.hxx"
89 #include "SMESH_Group.hxx"
90 #include "SMESH_MeshEditor.hxx"
92 #include "SMDS_EdgePosition.hxx"
93 #include "SMDS_FacePosition.hxx"
94 #include "SMDS_VertexPosition.hxx"
95 #include "SMDS_SpacePosition.hxx"
96 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
98 #include CORBA_SERVER_HEADER(SMESH_Group)
99 #include CORBA_SERVER_HEADER(SMESH_Filter)
101 #include "DriverMED_W_SMESHDS_Mesh.h"
102 #include "DriverMED_R_SMESHDS_Mesh.h"
104 #include "SALOMEDS_Tool.hxx"
105 #include "SALOME_NamingService.hxx"
106 #include "SALOME_LifeCycleCORBA.hxx"
107 #include "Utils_SINGLETON.hxx"
108 #include "OpUtil.hxx"
110 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
112 #include "GEOM_Client.hxx"
113 #include "Utils_ExceptHandlers.hxx"
118 using SMESH::TPythonDump;
120 #define NUM_TMP_FILES 2
123 static int MYDEBUG = 0;
125 static int MYDEBUG = 0;
128 // Static variables definition
129 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
130 CORBA::ORB_var SMESH_Gen_i::myOrb;
131 PortableServer::POA_var SMESH_Gen_i::myPoa;
132 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
133 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
134 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
136 //=============================================================================
138 * GetServant [ static ]
140 * Get servant of the CORBA object
142 //=============================================================================
144 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
146 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
149 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
153 INFOS( "GetServant - Unknown exception was caught!!!" );
158 //=============================================================================
160 * SObjectToObject [ static ]
162 * Get CORBA object corresponding to the SALOMEDS::SObject
164 //=============================================================================
166 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
168 SALOMEDS::GenericAttribute_var anAttr;
169 CORBA::Object_var anObj;
170 if ( !theSObject->_is_nil() ) {
172 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
173 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
174 CORBA::String_var aValue = anIOR->Value();
175 if( strcmp( aValue, "" ) != 0 )
176 anObj = GetORB()->string_to_object( aValue );
180 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
186 //=============================================================================
190 * Get SALOME_NamingService object
192 //=============================================================================
194 SALOME_NamingService* SMESH_Gen_i::GetNS()
196 if ( myNS == NULL ) {
197 myNS = SINGLETON_<SALOME_NamingService>::Instance();
198 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
199 myNS->init_orb( GetORB() );
204 //=============================================================================
208 * Get SALOME_LifeCycleCORBA object
210 //=============================================================================
211 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
212 if ( myLCC == NULL ) {
213 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
219 //=============================================================================
221 * GetGeomEngine [ static ]
223 * Get GEOM::GEOM_Gen reference
225 //=============================================================================
226 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
227 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
228 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
229 //CCRT return aGeomEngine._retn();
230 if(CORBA::is_nil(myGeomGen))
232 Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
233 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
238 //=============================================================================
240 * SMESH_Gen_i::SMESH_Gen_i
242 * Default constructor: not for use
244 //=============================================================================
246 SMESH_Gen_i::SMESH_Gen_i()
248 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
251 //=============================================================================
253 * SMESH_Gen_i::SMESH_Gen_i
255 * Standard constructor, used with Container
257 //=============================================================================
259 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
260 PortableServer::POA_ptr poa,
261 PortableServer::ObjectId* contId,
262 const char* instanceName,
263 const char* interfaceName )
264 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
266 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
268 myOrb = CORBA::ORB::_duplicate(orb);
269 myPoa = PortableServer::POA::_duplicate(poa);
272 _id = myPoa->activate_object( _thisObj );
274 myIsEmbeddedMode = false;
275 myShapeReader = NULL; // shape reader
278 // set it in standalone mode only
279 //OSD::SetSignal( true );
282 //=============================================================================
284 * SMESH_Gen_i::~SMESH_Gen_i
288 //=============================================================================
290 SMESH_Gen_i::~SMESH_Gen_i()
292 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
294 // delete hypothesis creators
295 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
296 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
298 delete (*itHyp).second;
300 myHypCreatorMap.clear();
302 // Clear study contexts data
303 map<int, StudyContext*>::iterator it;
304 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
307 myStudyContextMap.clear();
308 // delete shape reader
309 if ( !myShapeReader )
310 delete myShapeReader;
313 //=============================================================================
315 * SMESH_Gen_i::createHypothesis
317 * Create hypothesis of given type
319 //=============================================================================
320 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
321 const char* theLibName)
322 throw (SALOME::SALOME_Exception)
324 /* It's Need to tranlate lib name for WIN32 or X platform */
325 char* aPlatformLibName = 0;
326 if ( theLibName && theLibName[0] != '\0' )
328 int libNameLen = strlen(theLibName);
329 //check for old format "libXXXXXXX.so"
330 if (libNameLen > 7 &&
331 !strncmp( theLibName, "lib", 3 ) &&
332 !strcmp( theLibName+libNameLen-3, ".so" ))
336 aPlatformLibName = new char[libNameLen - 1];
337 aPlatformLibName[0] = '\0';
338 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
339 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
340 aPlatformLibName[libNameLen - 2] = '\0';
342 aPlatformLibName = new char[ libNameLen + 1];
343 aPlatformLibName[0] = '\0';
344 aPlatformLibName = strcat( aPlatformLibName, theLibName );
345 aPlatformLibName[libNameLen] = '\0';
350 //try to use new format
352 aPlatformLibName = new char[ libNameLen + 5 ];
353 aPlatformLibName[0] = '\0';
354 aPlatformLibName = strcat( aPlatformLibName, theLibName );
355 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
357 aPlatformLibName = new char[ libNameLen + 7 ];
358 aPlatformLibName[0] = '\0';
359 aPlatformLibName = strcat( aPlatformLibName, "lib" );
360 aPlatformLibName = strcat( aPlatformLibName, theLibName );
361 aPlatformLibName = strcat( aPlatformLibName, ".so" );
367 Unexpect aCatch(SALOME_SalomeException);
368 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
370 // create a new hypothesis object servant
371 SMESH_Hypothesis_i* myHypothesis_i = 0;
372 SMESH::SMESH_Hypothesis_var hypothesis_i;
376 // check, if creator for this hypothesis type already exists
377 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
379 // load plugin library
380 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
381 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
384 // report any error, if occured
386 const char* anError = dlerror();
387 throw(SALOME_Exception(anError));
389 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
393 // get method, returning hypothesis creator
394 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
395 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
396 GetHypothesisCreator procHandle =
397 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
400 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
401 UnLoadLib(libHandle);
404 // get hypothesis creator
405 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
406 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
409 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
412 // map hypothesis creator to a hypothesis name
413 myHypCreatorMap[string(theHypName)] = aCreator;
416 // create a new hypothesis object, store its ref. in studyContext
417 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
419 myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
420 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
422 catch (SALOME_Exception& S_ex)
424 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
427 if ( aPlatformLibName )
428 delete[] aPlatformLibName;
431 return hypothesis_i._retn();
433 // activate the CORBA servant of hypothesis
434 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
435 int nextId = RegisterObject( hypothesis_i );
436 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
438 return hypothesis_i._retn();
441 //=============================================================================
443 * SMESH_Gen_i::createMesh
445 * Create empty mesh on shape
447 //=============================================================================
448 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
449 throw ( SALOME::SALOME_Exception )
451 Unexpect aCatch(SALOME_SalomeException);
452 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
454 // Get or create the GEOM_Client instance
456 // create a new mesh object servant, store it in a map in study context
457 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
458 // create a new mesh object
459 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
461 // activate the CORBA servant of Mesh
462 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
463 int nextId = RegisterObject( mesh );
464 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
467 catch (SALOME_Exception& S_ex) {
468 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
470 return SMESH::SMESH_Mesh::_nil();
473 //=============================================================================
475 * SMESH_Gen_i::GetShapeReader
479 //=============================================================================
480 GEOM_Client* SMESH_Gen_i::GetShapeReader()
482 // create shape reader if necessary
483 if ( !myShapeReader )
484 myShapeReader = new GEOM_Client(GetContainerRef());
485 ASSERT( myShapeReader );
486 return myShapeReader;
489 //=============================================================================
491 * SMESH_Gen_i::SetGeomEngine
493 * Set GEOM::GEOM_Gen reference
495 //=============================================================================
496 //GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
497 void SMESH_Gen_i::SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo )
499 //Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
500 //myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
501 myGeomGen=GEOM::GEOM_Gen::_duplicate(geomcompo);
505 //=============================================================================
507 * SMESH_Gen_i::SetEmbeddedMode
511 //=============================================================================
513 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
515 myIsEmbeddedMode = theMode;
517 if ( !myIsEmbeddedMode ) {
518 //PAL10867: disable signals catching with "noexcepthandler" option
519 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
520 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
525 char* envDisableFPE = getenv("DISABLE_FPE");
526 if (envDisableFPE && atoi(envDisableFPE))
531 OSD::SetSignal( raiseFPE );
533 // else OSD::SetSignal() is called in GUI
537 //=============================================================================
539 * SMESH_Gen_i::IsEmbeddedMode
543 //=============================================================================
545 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
547 return myIsEmbeddedMode;
550 //=============================================================================
552 * SMESH_Gen_i::SetCurrentStudy
556 //=============================================================================
558 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
561 //MESSAGE( "SMESH_Gen_i::SetCurrentStudy" );
562 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
563 // create study context, if it doesn't exist and set current study
564 int studyId = GetCurrentStudyID();
565 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId );
566 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
567 myStudyContextMap[ studyId ] = new StudyContext;
570 // myCurrentStudy may be nil
571 if ( !CORBA::is_nil( myCurrentStudy ) ) {
572 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
573 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
574 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
576 // set current study for geom engine
577 //if ( !CORBA::is_nil( GetGeomEngine() ) )
578 // GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() );
582 //=============================================================================
584 * SMESH_Gen_i::GetCurrentStudy
588 //=============================================================================
590 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
592 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
593 return SALOMEDS::Study::_duplicate( myCurrentStudy );
596 //=============================================================================
598 * SMESH_Gen_i::GetCurrentStudyContext
600 * Get current study context
602 //=============================================================================
603 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
605 if ( !CORBA::is_nil( myCurrentStudy ) &&
606 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
607 return myStudyContextMap[ myCurrentStudy->StudyId() ];
612 //=============================================================================
614 * SMESH_Gen_i::CreateHypothesis
616 * Create hypothesis/algorothm of given type and publish it in the study
618 //=============================================================================
620 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
621 const char* theLibName )
622 throw ( SALOME::SALOME_Exception )
624 Unexpect aCatch(SALOME_SalomeException);
625 // Create hypothesis/algorithm
626 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
628 // Publish hypothesis/algorithm in the study
629 if ( CanPublishInStudy( hyp ) ) {
630 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
631 if ( !aSO->_is_nil() ) {
632 // Update Python script
633 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
634 << theHypName << "', '" << theLibName << "')";
641 //================================================================================
643 * \brief Return hypothesis of given type holding parameter values of the existing mesh
644 * \param theHypType - hypothesis type name
645 * \param theLibName - plugin library name
646 * \param theMesh - The mesh of interest
647 * \param theGeom - The shape to get parameter values from
648 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
649 * in a study and used to compute the mesh, or a temporary one created just to pass
652 //================================================================================
654 SMESH::SMESH_Hypothesis_ptr
655 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
656 const char* theLibName,
657 SMESH::SMESH_Mesh_ptr theMesh,
658 GEOM::GEOM_Object_ptr theGeom)
659 throw ( SALOME::SALOME_Exception )
661 Unexpect aCatch(SALOME_SalomeException);
662 if ( CORBA::is_nil( theMesh ) )
663 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
664 if ( CORBA::is_nil( theGeom ) )
665 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
667 // -----------------------------------------------
668 // find hypothesis used to mesh theGeom
669 // -----------------------------------------------
671 // get mesh and shape
672 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
673 TopoDS_Shape shape = GeomObjectToShape( theGeom );
674 if ( !meshServant || shape.IsNull() )
675 return SMESH::SMESH_Hypothesis::_nil();
676 ::SMESH_Mesh& mesh = meshServant->GetImpl();
678 if ( mesh.NbNodes() == 0 ) // empty mesh
679 return SMESH::SMESH_Hypothesis::_nil();
681 // create a temporary hypothesis to know its dimention
682 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
683 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
685 return SMESH::SMESH_Hypothesis::_nil();
686 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
688 // look for a hypothesis of theHypType used to mesh the shape
689 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
692 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
693 int nbLocalHyps = aHypList->length();
694 for ( int i = 0; i < nbLocalHyps; i++ )
695 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
696 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
697 // check super shapes
698 TopTools_ListIteratorOfListOfShape itShape( mesh.GetAncestors( shape ));
699 while ( nbLocalHyps == 0 && itShape.More() ) {
700 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
701 if ( ! CORBA::is_nil( geomObj )) {
702 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
703 nbLocalHyps = aHypList->length();
704 for ( int i = 0; i < nbLocalHyps; i++ )
705 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
706 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
712 // let the temporary hypothesis find out some how parameter values
713 if ( hyp->SetParametersByMesh( &mesh, shape ))
714 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
716 return SMESH::SMESH_Hypothesis::_nil();
719 //=============================================================================
721 * SMESH_Gen_i::CreateMesh
723 * Create empty mesh on a shape and publish it in the study
725 //=============================================================================
727 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
728 throw ( SALOME::SALOME_Exception )
730 Unexpect aCatch(SALOME_SalomeException);
731 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
733 SMESH::SMESH_Mesh_var mesh = this->createMesh();
735 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
736 ASSERT( meshServant );
737 meshServant->SetShape( theShapeObject );
739 // publish mesh in the study
740 if ( CanPublishInStudy( mesh ) ) {
741 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
742 aStudyBuilder->NewCommand(); // There is a transaction
743 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
744 aStudyBuilder->CommitCommand();
745 if ( !aSO->_is_nil() ) {
746 // Update Python script
747 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
754 //=============================================================================
756 * SMESH_Gen_i::CreateEmptyMesh
760 //=============================================================================
762 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
763 throw ( SALOME::SALOME_Exception )
765 Unexpect aCatch(SALOME_SalomeException);
766 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
768 SMESH::SMESH_Mesh_var mesh = this->createMesh();
770 // publish mesh in the study
771 if ( CanPublishInStudy( mesh ) ) {
772 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
773 aStudyBuilder->NewCommand(); // There is a transaction
774 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
775 aStudyBuilder->CommitCommand();
776 if ( !aSO->_is_nil() ) {
777 // Update Python script
778 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
785 //=============================================================================
787 * SMESH_Gen_i::CreateMeshFromUNV
789 * Create mesh and import data from UNV file
791 //=============================================================================
793 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
794 throw ( SALOME::SALOME_Exception )
796 Unexpect aCatch(SALOME_SalomeException);
797 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
799 SMESH::SMESH_Mesh_var aMesh = createMesh();
801 // publish mesh in the study
802 if ( CanPublishInStudy( aMesh ) ) {
803 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
804 aStudyBuilder->NewCommand(); // There is a transaction
805 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
806 aStudyBuilder->CommitCommand();
807 if ( !aSO->_is_nil() ) {
808 // Update Python script
809 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
813 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
815 aServant->ImportUNVFile( theFileName );
817 // Dump creation of groups
818 aServant->GetGroups();
820 return aMesh._retn();
823 //=============================================================================
825 * SMESH_Gen_i::CreateMeshFromMED
827 * Create mesh and import data from MED file
829 //=============================================================================
831 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
832 SMESH::DriverMED_ReadStatus& theStatus)
833 throw ( SALOME::SALOME_Exception )
835 Unexpect aCatch(SALOME_SalomeException);
836 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
838 // Retrieve mesh names from the file
839 DriverMED_R_SMESHDS_Mesh myReader;
840 myReader.SetFile( theFileName );
841 myReader.SetMeshId( -1 );
842 Driver_Mesh::Status aStatus;
843 list<string> aNames = myReader.GetMeshNames(aStatus);
844 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
845 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
847 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
850 TPythonDump aPythonDump;
852 //TCollection_AsciiString aStr ("([");
854 if (theStatus == SMESH::DRS_OK) {
855 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
856 aStudyBuilder->NewCommand(); // There is a transaction
857 aResult->length( aNames.size() );
860 // Iterate through all meshes and create mesh objects
861 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
863 //if (i > 0) aStr += ", ";
864 if (i > 0) aPythonDump << ", ";
867 SMESH::SMESH_Mesh_var mesh = createMesh();
869 // publish mesh in the study
870 SALOMEDS::SObject_var aSO;
871 if ( CanPublishInStudy( mesh ) )
872 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
873 if ( !aSO->_is_nil() ) {
876 //aStr += aSO->GetID();
879 aPythonDump << "mesh_" << i;
881 // aStr += TCollection_AsciiString(i);
884 // Read mesh data (groups are published automatically by ImportMEDFile())
885 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
886 ASSERT( meshServant );
887 SMESH::DriverMED_ReadStatus status1 =
888 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
889 if (status1 > theStatus)
892 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
894 aStudyBuilder->CommitCommand();
897 // Update Python script
898 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
900 // Dump creation of groups
901 for ( int i = 0; i < aResult->length(); ++i )
902 aResult[ i ]->GetGroups();
904 return aResult._retn();
907 //=============================================================================
909 * SMESH_Gen_i::CreateMeshFromSTL
911 * Create mesh and import data from STL file
913 //=============================================================================
915 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
916 throw ( SALOME::SALOME_Exception )
918 Unexpect aCatch(SALOME_SalomeException);
919 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
921 SMESH::SMESH_Mesh_var aMesh = createMesh();
923 // publish mesh in the study
924 if ( CanPublishInStudy( aMesh ) ) {
925 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
926 aStudyBuilder->NewCommand(); // There is a transaction
927 SALOMEDS::SObject_var aSO = PublishInStudy
928 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
929 aStudyBuilder->CommitCommand();
930 if ( !aSO->_is_nil() ) {
931 // Update Python script
932 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
936 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
938 aServant->ImportSTLFile( theFileName );
939 return aMesh._retn();
942 //=============================================================================
944 * SMESH_Gen_i::IsReadyToCompute
946 * Returns true if mesh contains enough data to be computed
948 //=============================================================================
950 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
951 GEOM::GEOM_Object_ptr theShapeObject )
952 throw ( SALOME::SALOME_Exception )
954 Unexpect aCatch(SALOME_SalomeException);
955 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
957 if ( CORBA::is_nil( theShapeObject ) )
958 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
961 if ( CORBA::is_nil( theMesh ) )
962 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
967 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
968 ASSERT( meshServant );
970 // get local TopoDS_Shape
971 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
972 // call implementation
973 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
974 return myGen.CheckAlgoState( myLocMesh, myLocShape );
977 catch ( SALOME_Exception& S_ex ) {
978 INFOS( "catch exception "<< S_ex.what() );
983 //================================================================================
985 * \brief Find SObject for an algo
987 //================================================================================
989 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
992 if ( !myCurrentStudy->_is_nil() ) {
993 // find algo in the study
994 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
995 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
996 if ( !father->_is_nil() ) {
997 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
998 for ( ; itBig->More(); itBig->Next() ) {
999 SALOMEDS::SObject_var gotBranch = itBig->Value();
1000 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1001 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1002 for ( ; algoIt->More(); algoIt->Next() ) {
1003 SALOMEDS::SObject_var algoSO = algoIt->Value();
1004 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1005 if ( !CORBA::is_nil( algoIOR )) {
1006 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1007 if ( impl && impl->GetImpl() == algo )
1008 return algoSO._retn();
1010 } // loop on algo SO's
1013 } // SMESH component iterator
1017 return SALOMEDS::SObject::_nil();
1020 //================================================================================
1022 * \brief Return errors of mesh computation
1024 //================================================================================
1026 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1027 GEOM::GEOM_Object_ptr theSubObject )
1028 throw ( SALOME::SALOME_Exception )
1030 Unexpect aCatch(SALOME_SalomeException);
1031 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1033 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1034 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1036 if ( CORBA::is_nil( theMesh ) )
1037 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1039 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1041 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1044 if(theMesh->HasShapeToMesh())
1045 shape = GeomObjectToShape( theSubObject );
1047 shape = SMESH_Mesh::PseudoShape();
1049 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1051 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1054 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1055 const bool includeSelf = true, complexShapeFirst = true;
1056 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1058 while ( smIt->more() )
1061 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1063 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1064 if ( error && !error->IsOK() && error->myAlgo )
1066 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1067 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1068 errStruct.comment = error->myComment.c_str();
1069 errStruct.subShapeID = sm->GetId();
1070 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->myAlgo );
1071 if ( !algoSO->_is_nil() )
1072 errStruct.algoName = algoSO->GetName();
1074 errStruct.algoName = error->myAlgo->GetName();
1077 error_array->length( nbErr );
1080 catch ( SALOME_Exception& S_ex ) {
1081 INFOS( "catch exception "<< S_ex.what() );
1084 return error_array._retn();
1087 //================================================================================
1089 * \brief Returns errors of hypotheses definintion
1090 * \param theMesh - the mesh
1091 * \param theSubObject - the main or sub- shape
1092 * \retval SMESH::algo_error_array* - sequence of errors
1094 //================================================================================
1096 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1097 GEOM::GEOM_Object_ptr theSubObject )
1098 throw ( SALOME::SALOME_Exception )
1100 Unexpect aCatch(SALOME_SalomeException);
1101 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1103 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1104 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1106 if ( CORBA::is_nil( theMesh ) )
1107 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1109 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1111 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1112 ASSERT( meshServant );
1113 if ( meshServant ) {
1114 TopoDS_Shape myLocShape;
1115 if(theMesh->HasShapeToMesh())
1116 myLocShape = GeomObjectToShape( theSubObject );
1118 myLocShape = SMESH_Mesh::PseudoShape();
1120 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1121 list< ::SMESH_Gen::TAlgoStateError > error_list;
1122 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1123 // call ::SMESH_Gen::GetAlgoState()
1124 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1125 error_array->length( error_list.size() );
1127 for ( error = error_list.begin(); error != error_list.end(); ++error )
1129 // fill AlgoStateError structure
1130 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1131 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1132 errStruct.algoDim = error->_algoDim;
1133 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1134 errStruct.algoName = "";
1135 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->_algo );
1136 if ( !algoSO->_is_nil() )
1137 errStruct.algoName = algoSO->GetName();
1141 catch ( SALOME_Exception& S_ex ) {
1142 INFOS( "catch exception "<< S_ex.what() );
1144 return error_array._retn();
1147 //=============================================================================
1149 * SMESH_Gen_i::GetSubShapesId
1151 * Get sub-shapes unique ID's list
1153 //=============================================================================
1155 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1156 const SMESH::object_array& theListOfSubShapeObject )
1157 throw ( SALOME::SALOME_Exception )
1159 Unexpect aCatch(SALOME_SalomeException);
1160 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1162 SMESH::long_array_var shapesId = new SMESH::long_array;
1165 if ( CORBA::is_nil( theMainShapeObject ) )
1166 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1167 SALOME::BAD_PARAM );
1171 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1172 TopTools_IndexedMapOfShape myIndexToShape;
1173 TopExp::MapShapes(myMainShape,myIndexToShape);
1175 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1177 GEOM::GEOM_Object_var aShapeObject
1178 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1179 if ( CORBA::is_nil( aShapeObject ) )
1180 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1181 SALOME::BAD_PARAM );
1183 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1184 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1186 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1187 setId.insert(myIndexToShape.FindIndex(F));
1188 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1190 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1192 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1193 setId.insert(myIndexToShape.FindIndex(E));
1194 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1196 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1198 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1199 setId.insert(myIndexToShape.FindIndex(V));
1200 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1203 shapesId->length(setId.size());
1204 set<int>::iterator iind;
1206 for (iind = setId.begin(); iind != setId.end(); iind++)
1208 if(MYDEBUG) SCRUTE((*iind));
1209 shapesId[i] = (*iind);
1210 if(MYDEBUG) SCRUTE(shapesId[i]);
1214 catch (SALOME_Exception& S_ex)
1216 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1219 return shapesId._retn();
1222 //=============================================================================
1224 * SMESH_Gen_i::Compute
1226 * Compute mesh on a shape
1228 //=============================================================================
1230 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1231 GEOM::GEOM_Object_ptr theShapeObject )
1232 throw ( SALOME::SALOME_Exception )
1234 Unexpect aCatch(SALOME_SalomeException);
1235 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1237 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1238 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1239 SALOME::BAD_PARAM );
1241 if ( CORBA::is_nil( theMesh ) )
1242 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1243 SALOME::BAD_PARAM );
1245 // Update Python script
1246 TPythonDump() << "isDone = " << this << ".Compute( "
1247 << theMesh << ", " << theShapeObject << ")";
1251 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1252 ASSERT( meshServant );
1253 if ( meshServant ) {
1254 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1255 meshServant->CheckGeomGroupModif();
1256 // get local TopoDS_Shape
1257 TopoDS_Shape myLocShape;
1258 if(theMesh->HasShapeToMesh())
1259 myLocShape = GeomObjectToShape( theShapeObject );
1261 myLocShape = SMESH_Mesh::PseudoShape();
1262 // call implementation compute
1263 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1264 return myGen.Compute( myLocMesh, myLocShape);
1267 catch ( std::bad_alloc ) {
1268 INFOS( "Compute(): lack of memory" );
1270 catch ( SALOME_Exception& S_ex ) {
1271 INFOS( "Compute(): catch exception "<< S_ex.what() );
1274 INFOS( "Compute(): unknown exception " );
1279 //================================================================================
1281 * \brief Return geometrical object the given element is built on
1282 * \param theMesh - the mesh the element is in
1283 * \param theElementID - the element ID
1284 * \param theGeomName - the name of the result geom object if it is not yet published
1285 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1287 //================================================================================
1289 GEOM::GEOM_Object_ptr
1290 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1291 CORBA::Long theElementID,
1292 const char* theGeomName)
1293 throw ( SALOME::SALOME_Exception )
1295 Unexpect aCatch(SALOME_SalomeException);
1297 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
1298 if ( !geom->_is_nil() ) {
1299 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1300 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1302 // try to find the corresponding SObject
1303 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1304 if ( SObj->_is_nil() ) // submesh can be not found even if published
1306 // try to find published submesh
1307 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
1308 if ( !geom->IsMainShape() && list->length() == 1 ) {
1309 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1310 SALOMEDS::ChildIterator_var it;
1311 if ( !mainSO->_is_nil() )
1312 it = myCurrentStudy->NewChildIterator( mainSO );
1313 if ( !it->_is_nil() ) {
1314 for ( it->InitEx(true); SObj->_is_nil() && it->More(); it->Next() ) {
1315 GEOM::GEOM_Object_var subGeom =
1316 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1317 if ( !subGeom->_is_nil() ) {
1318 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1319 if ( subList->length() == 1 && list[0] == subList[0] ) {
1328 if ( SObj->_is_nil() ) // publish a new subshape
1329 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1331 // return only published geometry
1332 if ( !SObj->_is_nil() )
1333 return geom._retn();
1335 return GEOM::GEOM_Object::_nil();
1338 //================================================================================
1340 * \brief Return geometrical object the given element is built on.
1341 * \param theMesh - the mesh the element is in
1342 * \param theElementID - the element ID
1343 * \retval GEOM::GEOM_Object_ptr - the found geom object
1345 //================================================================================
1347 GEOM::GEOM_Object_ptr
1348 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1349 CORBA::Long theElementID)
1350 throw ( SALOME::SALOME_Exception )
1352 Unexpect aCatch(SALOME_SalomeException);
1353 if ( CORBA::is_nil( theMesh ) )
1354 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1356 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1357 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1359 // get a core mesh DS
1360 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1361 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1363 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1364 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1365 // find the element in mesh
1366 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
1367 // find a shape id by the element
1368 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1369 // get a geom object by the shape id
1370 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1371 if ( geom->_is_nil() ) {
1372 // try to find a published sub-shape
1373 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1374 SALOMEDS::ChildIterator_var it;
1375 if ( !mainSO->_is_nil() )
1376 it = myCurrentStudy->NewChildIterator( mainSO );
1377 if ( !it->_is_nil() ) {
1378 for ( it->InitEx(true); it->More(); it->Next() ) {
1379 GEOM::GEOM_Object_var subGeom =
1380 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1381 if ( !subGeom->_is_nil() ) {
1382 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1383 if ( subList->length() == 1 && shapeID == subList[0] ) {
1391 if ( geom->_is_nil() ) {
1393 GEOM::GEOM_IShapesOperations_var op =
1394 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1395 if ( !op->_is_nil() )
1396 geom = op->GetSubShape( mainShape, shapeID );
1398 if ( !geom->_is_nil() ) {
1399 GeomObjectToShape( geom ); // let geom client remember the found shape
1400 return geom._retn();
1405 return GEOM::GEOM_Object::_nil();
1408 //================================================================================
1410 * SMESH_Gen_i::Concatenate
1412 * Concatenate the given meshes into one mesh
1414 //================================================================================
1416 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
1417 CORBA::Boolean theUniteIdenticalGroups,
1418 CORBA::Boolean theMergeNodesAndElements,
1419 CORBA::Double theMergeTolerance)
1420 throw ( SALOME::SALOME_Exception )
1422 return ConcatenateCommon(theMeshesArray,
1423 theUniteIdenticalGroups,
1424 theMergeNodesAndElements,
1429 //================================================================================
1431 * SMESH_Gen_i::ConcatenateWithGroups
1433 * Concatenate the given meshes into one mesh
1434 * Create the groups of all elements from initial meshes
1436 //================================================================================
1438 SMESH::SMESH_Mesh_ptr
1439 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
1440 CORBA::Boolean theUniteIdenticalGroups,
1441 CORBA::Boolean theMergeNodesAndElements,
1442 CORBA::Double theMergeTolerance)
1443 throw ( SALOME::SALOME_Exception )
1445 return ConcatenateCommon(theMeshesArray,
1446 theUniteIdenticalGroups,
1447 theMergeNodesAndElements,
1452 //================================================================================
1454 * SMESH_Gen_i::ConcatenateCommon
1456 * Concatenate the given meshes into one mesh
1458 //================================================================================
1460 SMESH::SMESH_Mesh_ptr
1461 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
1462 CORBA::Boolean theUniteIdenticalGroups,
1463 CORBA::Boolean theMergeNodesAndElements,
1464 CORBA::Double theMergeTolerance,
1465 CORBA::Boolean theCommonGroups)
1466 throw ( SALOME::SALOME_Exception )
1468 typedef map<int, int> TIDsMap;
1469 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
1470 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
1471 typedef std::set<SMESHDS_GroupBase*> TGroups;
1473 TPythonDump aPythonDump; // prevent dump of called methods
1476 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
1478 if ( !aNewMesh->_is_nil() ) {
1479 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
1481 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
1482 SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
1484 TGroupsMap aGroupsMap;
1485 TListOfNewGroups aListOfNewGroups;
1486 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
1487 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
1490 for ( int i = 0; i < theMeshesArray.length(); i++) {
1491 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
1492 if ( !anInitMesh->_is_nil() ) {
1493 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
1495 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
1496 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
1501 // loop on elements of mesh
1502 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
1503 const SMDS_MeshElement* anElem = 0;
1504 const SMDS_MeshElement* aNewElem = 0;
1505 int anElemNbNodes = 0;
1510 int anNbVolumes = 0;
1512 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
1513 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
1514 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
1515 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
1517 if( theCommonGroups ) {
1518 anIDsNodes->length( anInitMeshDS->NbNodes() );
1519 anIDsEdges->length( anInitMeshDS->NbEdges() );
1520 anIDsFaces->length( anInitMeshDS->NbFaces() );
1521 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
1524 for ( int j = 0; itElems->more(); j++) {
1525 anElem = itElems->next();
1526 SMDSAbs_ElementType anElemType = anElem->GetType();
1527 anElemNbNodes = anElem->NbNodes();
1528 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
1530 // loop on nodes of element
1531 const SMDS_MeshNode* aNode = 0;
1532 const SMDS_MeshNode* aNewNode = 0;
1533 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
1535 for ( int k = 0; itNodes->more(); k++) {
1536 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
1537 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
1538 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
1539 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
1540 if( theCommonGroups )
1541 anIDsNodes[anNbNodes++] = aNewNode->GetID();
1544 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
1545 aNodesArray[k] = aNewNode;
1548 // creates a corresponding element on existent nodes in new mesh
1549 if ( anElem->IsPoly() && anElemType == SMDSAbs_Volume )
1551 const SMDS_PolyhedralVolumeOfNodes* aVolume =
1552 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
1554 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
1555 aVolume->GetQuanities());
1556 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1557 if( theCommonGroups )
1558 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
1563 aNewElem = aNewEditor.AddElement(aNodesArray,
1566 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1567 if( theCommonGroups ) {
1568 if( anElemType == SMDSAbs_Edge )
1569 anIDsEdges[anNbEdges++] = aNewElem->GetID();
1570 else if( anElemType == SMDSAbs_Face )
1571 anIDsFaces[anNbFaces++] = aNewElem->GetID();
1572 else if( anElemType == SMDSAbs_Volume )
1573 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
1578 aListOfGroups = anInitImpl->GetGroups();
1579 SMESH::SMESH_GroupBase_ptr aGroup;
1581 // loop on groups of mesh
1582 SMESH::long_array_var anInitIDs = new SMESH::long_array();
1583 SMESH::long_array_var anNewIDs = new SMESH::long_array();
1584 SMESH::SMESH_Group_var aNewGroup;
1586 SMESH::ElementType aGroupType;
1587 CORBA::String_var aGroupName;
1588 if ( theCommonGroups ) {
1589 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::VOLUME;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
1591 SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
1593 str += aMeshSObj->GetName();
1598 switch(aGroupType) {
1601 anIDsNodes->length(anNbNodes);
1606 anIDsEdges->length(anNbEdges);
1611 anIDsFaces->length(anNbFaces);
1616 anIDsVolumes->length(anNbVolumes);
1617 anLen = anNbVolumes;
1624 aGroupName = str.c_str();
1626 // add a new group in the mesh
1627 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1629 switch(aGroupType) {
1631 aNewGroup->Add( anIDsNodes );
1634 aNewGroup->Add( anIDsEdges );
1637 aNewGroup->Add( anIDsFaces );
1640 aNewGroup->Add( anIDsVolumes );
1646 aListOfNewGroups.clear();
1647 aListOfNewGroups.push_back(aNewGroup);
1648 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
1653 // check that current group name and type don't have identical ones in union mesh
1654 for (int i = 0; i < aListOfGroups->length(); i++) {
1655 aGroup = aListOfGroups[i];
1656 aListOfNewGroups.clear();
1657 aGroupType = aGroup->GetType();
1658 aGroupName = aGroup->GetName();
1660 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
1662 // convert a list of IDs
1663 anInitIDs = aGroup->GetListOfID();
1664 anNewIDs->length(anInitIDs->length());
1665 if ( aGroupType == SMESH::NODE )
1666 for (int j = 0; j < anInitIDs->length(); j++) {
1667 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
1670 for (int j = 0; j < anInitIDs->length(); j++) {
1671 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
1674 // check that current group name and type don't have identical ones in union mesh
1675 if ( anIter == aGroupsMap.end() ) {
1676 // add a new group in the mesh
1677 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1678 // add elements into new group
1679 aNewGroup->Add( anNewIDs );
1681 aListOfNewGroups.push_back(aNewGroup);
1682 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
1685 else if ( theUniteIdenticalGroups ) {
1686 // unite identical groups
1687 TListOfNewGroups& aNewGroups = anIter->second;
1688 aNewGroups.front()->Add( anNewIDs );
1692 // rename identical groups
1693 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1694 aNewGroup->Add( anNewIDs );
1696 TListOfNewGroups& aNewGroups = anIter->second;
1697 string aNewGroupName;
1698 if (aNewGroups.size() == 1) {
1699 aNewGroupName = string(aGroupName) + "_1";
1700 aNewGroups.front()->SetName(aNewGroupName.c_str());
1702 char aGroupNum[128];
1703 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
1704 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
1705 aNewGroup->SetName(aNewGroupName.c_str());
1706 aNewGroups.push_back(aNewGroup);
1713 if (theMergeNodesAndElements) {
1715 set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
1716 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
1717 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
1718 aNewEditor.MergeNodes( aGroupsOfNodes );
1720 aNewEditor.MergeEqualElements();
1725 // Update Python script
1726 aPythonDump << aNewMesh << " = " << this;
1727 if( !theCommonGroups )
1728 aPythonDump << ".Concatenate(";
1730 aPythonDump << ".ConcatenateWithGroups(";
1732 for ( int i = 0; i < theMeshesArray.length(); i++) {
1733 if (i > 0) aPythonDump << ", ";
1734 aPythonDump << theMeshesArray[i];
1736 aPythonDump << "], ";
1737 aPythonDump << theUniteIdenticalGroups << ", "
1738 << theMergeNodesAndElements << ", "
1739 << theMergeTolerance << ")";
1741 return aNewMesh._retn();
1744 //=============================================================================
1748 * Save SMESH module's data
1750 //=============================================================================
1751 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1755 INFOS( "SMESH_Gen_i::Save" );
1757 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1758 // san -- in case <myCurrentStudy> differs from theComponent's study,
1759 // use that of the component
1760 if ( myCurrentStudy->_is_nil() ||
1761 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1762 SetCurrentStudy( theComponent->GetStudy() );
1764 // Store study contents as a set of python commands
1765 SavePython(myCurrentStudy);
1767 StudyContext* myStudyContext = GetCurrentStudyContext();
1769 // Declare a byte stream
1770 SALOMEDS::TMPFile_var aStreamFile;
1772 // Obtain a temporary dir
1773 TCollection_AsciiString tmpDir =
1774 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1776 // Create a sequence of files processed
1777 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1778 aFileSeq->length( NUM_TMP_FILES );
1780 TCollection_AsciiString aStudyName( "" );
1782 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1784 // Set names of temporary files
1785 TCollection_AsciiString filename =
1786 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1787 TCollection_AsciiString meshfile =
1788 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1789 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1790 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1791 filename = tmpDir + filename;
1792 meshfile = tmpDir + meshfile;
1795 HDFdataset* aDataset;
1796 HDFgroup* aTopGroup;
1798 HDFgroup* aSubGroup;
1799 HDFgroup* aSubSubGroup;
1800 hdf_size aSize[ 1 ];
1803 //Remove the files if they exist: BugID: 11225
1804 #ifndef WNT /* unix functionality */
1805 TCollection_AsciiString cmd("rm -f \"");
1807 TCollection_AsciiString cmd("del /F \"");
1814 system(cmd.ToCString());
1816 // MED writer to be used by storage process
1817 DriverMED_W_SMESHDS_Mesh myWriter;
1818 myWriter.SetFile( meshfile.ToCString() );
1821 // ---> create HDF file
1822 aFile = new HDFfile( filename.ToCString() );
1823 aFile->CreateOnDisk();
1825 // --> iterator for top-level objects
1826 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1827 for ( ; itBig->More(); itBig->Next() ) {
1828 SALOMEDS::SObject_var gotBranch = itBig->Value();
1830 // --> hypotheses root branch (only one for the study)
1831 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1832 // create hypotheses root HDF group
1833 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1834 aTopGroup->CreateOnDisk();
1836 // iterator for all hypotheses
1837 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1838 for ( ; it->More(); it->Next() ) {
1839 SALOMEDS::SObject_var mySObject = it->Value();
1840 CORBA::Object_var anObject = SObjectToObject( mySObject );
1841 if ( !CORBA::is_nil( anObject ) ) {
1842 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1843 if ( !myHyp->_is_nil() ) {
1844 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1846 string hypname = string( myHyp->GetName() );
1847 string libname = string( myHyp->GetLibName() );
1849 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1850 // WNT and ".so" for X-system) must be deleted
1851 int libname_len = libname.length();
1853 if( libname_len > 4 )
1854 libname.resize( libname_len - 4 );
1856 // PAL17753 (Regresion: missing hypothesis in restored study)
1857 // "lib" also should be removed from the beginning
1858 //if( libname_len > 3 )
1859 //libname.resize( libname_len - 3 );
1860 if( libname_len > 6 )
1861 libname = libname.substr( 3, libname_len - 3 - 3 );
1863 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1864 int id = myStudyContext->findId( string( objStr.in() ) );
1865 string hypdata = string( myImpl->SaveTo() );
1867 // for each hypothesis create HDF group basing on its id
1868 char hypGrpName[30];
1869 sprintf( hypGrpName, "Hypothesis %d", id );
1870 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1871 aGroup->CreateOnDisk();
1872 // --> type name of hypothesis
1873 aSize[ 0 ] = hypname.length() + 1;
1874 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1875 aDataset->CreateOnDisk();
1876 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1877 aDataset->CloseOnDisk();
1878 // --> server plugin library name of hypothesis
1879 aSize[ 0 ] = libname.length() + 1;
1880 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1881 aDataset->CreateOnDisk();
1882 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1883 aDataset->CloseOnDisk();
1884 // --> persistent data of hypothesis
1885 aSize[ 0 ] = hypdata.length() + 1;
1886 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1887 aDataset->CreateOnDisk();
1888 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1889 aDataset->CloseOnDisk();
1890 // close hypothesis HDF group
1891 aGroup->CloseOnDisk();
1896 // close hypotheses root HDF group
1897 aTopGroup->CloseOnDisk();
1899 // --> algorithms root branch (only one for the study)
1900 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1901 // create algorithms root HDF group
1902 aTopGroup = new HDFgroup( "Algorithms", aFile );
1903 aTopGroup->CreateOnDisk();
1905 // iterator for all algorithms
1906 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1907 for ( ; it->More(); it->Next() ) {
1908 SALOMEDS::SObject_var mySObject = it->Value();
1909 CORBA::Object_var anObject = SObjectToObject( mySObject );
1910 if ( !CORBA::is_nil( anObject ) ) {
1911 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1912 if ( !myHyp->_is_nil() ) {
1913 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1915 string hypname = string( myHyp->GetName() );
1916 string libname = string( myHyp->GetLibName() );
1918 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1919 // WNT and ".so" for X-system) must be deleted
1920 int libname_len = libname.length();
1922 if( libname_len > 4 )
1923 libname.resize( libname_len - 4 );
1925 // PAL17753 (Regresion: missing hypothesis in restored study)
1926 // "lib" also should be removed from the beginning
1927 //if( libname_len > 3 )
1928 //libname.resize( libname_len - 3 );
1929 if( libname_len > 6 )
1930 libname = libname.substr( 3, libname_len - 3 - 3 );
1932 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1933 int id = myStudyContext->findId( string( objStr.in() ) );
1934 string hypdata = string( myImpl->SaveTo() );
1936 // for each algorithm create HDF group basing on its id
1937 char hypGrpName[30];
1938 sprintf( hypGrpName, "Algorithm %d", id );
1939 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1940 aGroup->CreateOnDisk();
1941 // --> type name of algorithm
1942 aSize[0] = hypname.length() + 1;
1943 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1944 aDataset->CreateOnDisk();
1945 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1946 aDataset->CloseOnDisk();
1947 // --> server plugin library name of hypothesis
1948 aSize[0] = libname.length() + 1;
1949 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1950 aDataset->CreateOnDisk();
1951 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1952 aDataset->CloseOnDisk();
1953 // --> persistent data of algorithm
1954 aSize[0] = hypdata.length() + 1;
1955 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1956 aDataset->CreateOnDisk();
1957 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1958 aDataset->CloseOnDisk();
1959 // close algorithm HDF group
1960 aGroup->CloseOnDisk();
1965 // close algorithms root HDF group
1966 aTopGroup->CloseOnDisk();
1968 // --> mesh objects roots branches
1969 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1970 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1971 if ( !CORBA::is_nil( anObject ) ) {
1972 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1973 if ( !myMesh->_is_nil() ) {
1974 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1976 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1977 int id = myStudyContext->findId( string( objStr.in() ) );
1978 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1979 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1980 bool hasShape = myLocMesh.HasShapeToMesh();
1982 // for each mesh open the HDF group basing on its id
1983 char meshGrpName[ 30 ];
1984 sprintf( meshGrpName, "Mesh %d", id );
1985 aTopGroup = new HDFgroup( meshGrpName, aFile );
1986 aTopGroup->CreateOnDisk();
1988 // --> put dataset to hdf file which is a flag that mesh has data
1989 string strHasData = "0";
1990 // check if the mesh is not empty
1991 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1992 // write mesh data to med file
1993 myWriter.SetMesh( mySMESHDSMesh );
1994 myWriter.SetMeshId( id );
1997 aSize[ 0 ] = strHasData.length() + 1;
1998 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1999 aDataset->CreateOnDisk();
2000 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
2001 aDataset->CloseOnDisk();
2004 // for each mesh open the HDF group basing on its auto color parameter
2005 char meshAutoColorName[ 30 ];
2006 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
2008 anAutoColor[0] = myImpl->GetAutoColor();
2010 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
2011 aDataset->CreateOnDisk();
2012 aDataset->WriteOnDisk( anAutoColor );
2013 aDataset->CloseOnDisk();
2015 // write reference on a shape if exists
2016 SALOMEDS::SObject_var myRef;
2017 bool shapeRefFound = false;
2018 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
2020 SALOMEDS::SObject_var myShape;
2021 bool ok = myRef->ReferencedObject( myShape );
2023 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
2024 string myRefOnObject = myShape->GetID();
2025 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
2026 aSize[ 0 ] = myRefOnObject.length() + 1;
2027 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
2028 aDataset->CreateOnDisk();
2029 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2030 aDataset->CloseOnDisk();
2035 // write applied hypotheses if exist
2036 SALOMEDS::SObject_var myHypBranch;
2037 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
2038 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
2039 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
2041 if ( found && (shapeRefFound || !hasShape) ) {
2042 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2043 aGroup->CreateOnDisk();
2045 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
2047 for ( ; it->More(); it->Next() ) {
2048 SALOMEDS::SObject_var mySObject = it->Value();
2049 SALOMEDS::SObject_var myRefOnHyp;
2050 bool ok = mySObject->ReferencedObject( myRefOnHyp );
2052 // san - it is impossible to recover applied hypotheses
2053 // using their entries within Load() method,
2054 // for there are no AttributeIORs in the study when Load() is working.
2055 // Hence, it is better to store persistent IDs of hypotheses as references to them
2057 //string myRefOnObject = myRefOnHyp->GetID();
2058 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2059 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2060 int id = myStudyContext->findId( string( objStr.in() ) );
2061 //if ( myRefOnObject.length() > 0 ) {
2062 //aSize[ 0 ] = myRefOnObject.length() + 1;
2063 char hypName[ 30 ], hypId[ 30 ];
2064 sprintf( hypName, "Hyp %d", ++hypNb );
2065 sprintf( hypId, "%d", id );
2066 aSize[ 0 ] = strlen( hypId ) + 1;
2067 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
2068 aDataset->CreateOnDisk();
2069 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2070 aDataset->WriteOnDisk( hypId );
2071 aDataset->CloseOnDisk();
2075 aGroup->CloseOnDisk();
2078 // write applied algorithms if exist
2079 SALOMEDS::SObject_var myAlgoBranch;
2080 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
2081 if ( found && !shapeRefFound && hasShape) { // remove applied algos
2082 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
2084 if ( found && (shapeRefFound || !hasShape)) {
2085 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2086 aGroup->CreateOnDisk();
2088 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
2090 for ( ; it->More(); it->Next() ) {
2091 SALOMEDS::SObject_var mySObject = it->Value();
2092 SALOMEDS::SObject_var myRefOnAlgo;
2093 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
2095 // san - it is impossible to recover applied algorithms
2096 // using their entries within Load() method,
2097 // for there are no AttributeIORs in the study when Load() is working.
2098 // Hence, it is better to store persistent IDs of algorithms as references to them
2100 //string myRefOnObject = myRefOnAlgo->GetID();
2101 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2102 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2103 int id = myStudyContext->findId( string( objStr.in() ) );
2104 //if ( myRefOnObject.length() > 0 ) {
2105 //aSize[ 0 ] = myRefOnObject.length() + 1;
2106 char algoName[ 30 ], algoId[ 30 ];
2107 sprintf( algoName, "Algo %d", ++algoNb );
2108 sprintf( algoId, "%d", id );
2109 aSize[ 0 ] = strlen( algoId ) + 1;
2110 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
2111 aDataset->CreateOnDisk();
2112 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2113 aDataset->WriteOnDisk( algoId );
2114 aDataset->CloseOnDisk();
2118 aGroup->CloseOnDisk();
2121 // --> submesh objects sub-branches
2123 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
2124 SALOMEDS::SObject_var mySubmeshBranch;
2125 found = gotBranch->FindSubObject( i, mySubmeshBranch );
2127 if ( found ) // check if there is shape reference in submeshes
2129 bool hasShapeRef = false;
2130 SALOMEDS::ChildIterator_var itSM =
2131 myCurrentStudy->NewChildIterator( mySubmeshBranch );
2132 for ( ; itSM->More(); itSM->Next() ) {
2133 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
2134 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2135 mySubRef->ReferencedObject( myShape );
2136 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
2139 { // remove one submesh
2140 if ( shapeRefFound )
2141 { // unassign hypothesis
2142 SMESH::SMESH_subMesh_var mySubMesh =
2143 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
2144 if ( !mySubMesh->_is_nil() ) {
2145 int shapeID = mySubMesh->GetId();
2146 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
2147 const list<const SMESHDS_Hypothesis*>& hypList =
2148 mySMESHDSMesh->GetHypothesis( S );
2149 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
2150 while ( hyp != hypList.end() ) {
2151 int hypID = (*hyp++)->GetID(); // goto next hyp here because
2152 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
2156 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
2158 } // loop on submeshes of a type
2159 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
2160 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
2163 } // end check if there is shape reference in submeshes
2165 char name_meshgroup[ 30 ];
2166 if ( i == GetSubMeshOnVertexTag() )
2167 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2168 else if ( i == GetSubMeshOnEdgeTag() )
2169 strcpy( name_meshgroup, "SubMeshes On Edge" );
2170 else if ( i == GetSubMeshOnWireTag() )
2171 strcpy( name_meshgroup, "SubMeshes On Wire" );
2172 else if ( i == GetSubMeshOnFaceTag() )
2173 strcpy( name_meshgroup, "SubMeshes On Face" );
2174 else if ( i == GetSubMeshOnShellTag() )
2175 strcpy( name_meshgroup, "SubMeshes On Shell" );
2176 else if ( i == GetSubMeshOnSolidTag() )
2177 strcpy( name_meshgroup, "SubMeshes On Solid" );
2178 else if ( i == GetSubMeshOnCompoundTag() )
2179 strcpy( name_meshgroup, "SubMeshes On Compound" );
2181 // for each type of submeshes create container HDF group
2182 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2183 aGroup->CreateOnDisk();
2185 // iterator for all submeshes of given type
2186 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
2187 for ( ; itSM->More(); itSM->Next() ) {
2188 SALOMEDS::SObject_var mySObject = itSM->Value();
2189 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
2190 if ( !CORBA::is_nil( anSubObject ))
2192 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
2193 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
2194 int subid = myStudyContext->findId( string( objStr.in() ) );
2196 // for each mesh open the HDF group basing on its id
2197 char submeshGrpName[ 30 ];
2198 sprintf( submeshGrpName, "SubMesh %d", subid );
2199 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
2200 aSubGroup->CreateOnDisk();
2202 // write reference on a shape, already checked if it exists
2203 SALOMEDS::SObject_var mySubRef, myShape;
2204 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2205 mySubRef->ReferencedObject( myShape );
2206 string myRefOnObject = myShape->GetID();
2207 if ( myRefOnObject.length() > 0 ) {
2208 aSize[ 0 ] = myRefOnObject.length() + 1;
2209 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
2210 aDataset->CreateOnDisk();
2211 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2212 aDataset->CloseOnDisk();
2215 // write applied hypotheses if exist
2216 SALOMEDS::SObject_var mySubHypBranch;
2217 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
2219 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2220 aSubSubGroup->CreateOnDisk();
2222 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
2224 for ( ; it->More(); it->Next() ) {
2225 SALOMEDS::SObject_var mySubSObject = it->Value();
2226 SALOMEDS::SObject_var myRefOnHyp;
2227 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
2229 //string myRefOnObject = myRefOnHyp->GetID();
2230 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2231 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2232 int id = myStudyContext->findId( string( objStr.in() ) );
2233 //if ( myRefOnObject.length() > 0 ) {
2234 //aSize[ 0 ] = myRefOnObject.length() + 1;
2235 char hypName[ 30 ], hypId[ 30 ];
2236 sprintf( hypName, "Hyp %d", ++hypNb );
2237 sprintf( hypId, "%d", id );
2238 aSize[ 0 ] = strlen( hypId ) + 1;
2239 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
2240 aDataset->CreateOnDisk();
2241 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2242 aDataset->WriteOnDisk( hypId );
2243 aDataset->CloseOnDisk();
2247 aSubSubGroup->CloseOnDisk();
2250 // write applied algorithms if exist
2251 SALOMEDS::SObject_var mySubAlgoBranch;
2252 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
2254 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2255 aSubSubGroup->CreateOnDisk();
2257 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
2259 for ( ; it->More(); it->Next() ) {
2260 SALOMEDS::SObject_var mySubSObject = it->Value();
2261 SALOMEDS::SObject_var myRefOnAlgo;
2262 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
2264 //string myRefOnObject = myRefOnAlgo->GetID();
2265 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2266 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2267 int id = myStudyContext->findId( string( objStr.in() ) );
2268 //if ( myRefOnObject.length() > 0 ) {
2269 //aSize[ 0 ] = myRefOnObject.length() + 1;
2270 char algoName[ 30 ], algoId[ 30 ];
2271 sprintf( algoName, "Algo %d", ++algoNb );
2272 sprintf( algoId, "%d", id );
2273 aSize[ 0 ] = strlen( algoId ) + 1;
2274 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
2275 aDataset->CreateOnDisk();
2276 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2277 aDataset->WriteOnDisk( algoId );
2278 aDataset->CloseOnDisk();
2282 aSubSubGroup->CloseOnDisk();
2284 // close submesh HDF group
2285 aSubGroup->CloseOnDisk();
2288 // close container of submeshes by type HDF group
2289 aGroup->CloseOnDisk();
2292 // All sub-meshes will be stored in MED file
2293 // .. will NOT (PAL 12992)
2294 //if ( shapeRefFound )
2295 //myWriter.AddAllSubMeshes();
2297 // groups root sub-branch
2298 SALOMEDS::SObject_var myGroupsBranch;
2299 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
2300 found = gotBranch->FindSubObject( i, myGroupsBranch );
2302 char name_group[ 30 ];
2303 if ( i == GetNodeGroupsTag() )
2304 strcpy( name_group, "Groups of Nodes" );
2305 else if ( i == GetEdgeGroupsTag() )
2306 strcpy( name_group, "Groups of Edges" );
2307 else if ( i == GetFaceGroupsTag() )
2308 strcpy( name_group, "Groups of Faces" );
2309 else if ( i == GetVolumeGroupsTag() )
2310 strcpy( name_group, "Groups of Volumes" );
2312 aGroup = new HDFgroup( name_group, aTopGroup );
2313 aGroup->CreateOnDisk();
2315 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
2316 for ( ; it->More(); it->Next() ) {
2317 SALOMEDS::SObject_var mySObject = it->Value();
2318 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
2319 if ( !CORBA::is_nil( aSubObject ) ) {
2320 SMESH_GroupBase_i* myGroupImpl =
2321 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
2325 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
2326 int anId = myStudyContext->findId( string( objStr.in() ) );
2328 // For each group, create a dataset named "Group <group_persistent_id>"
2329 // and store the group's user name into it
2331 sprintf( grpName, "Group %d", anId );
2332 char* aUserName = myGroupImpl->GetName();
2333 aSize[ 0 ] = strlen( aUserName ) + 1;
2335 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
2336 aDataset->CreateOnDisk();
2337 aDataset->WriteOnDisk( aUserName );
2338 aDataset->CloseOnDisk();
2341 // For each group, create a dataset named "Group <group_persistent_id> Color"
2342 // and store the group's color into it
2343 char grpColorName[ 30 ];
2344 sprintf( grpColorName, "ColorGroup %d", anId );
2345 SALOMEDS::Color aColor = myGroupImpl->GetColor();
2347 anRGB[ 0 ] = aColor.R;
2348 anRGB[ 1 ] = aColor.G;
2349 anRGB[ 2 ] = aColor.B;
2351 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
2352 aDataset->CreateOnDisk();
2353 aDataset->WriteOnDisk( anRGB );
2354 aDataset->CloseOnDisk();
2356 // Store the group contents into MED file
2357 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
2359 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
2360 << grpName << " to MED file" );
2361 SMESHDS_GroupBase* aGrpBaseDS =
2362 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
2363 aGrpBaseDS->SetStoreName( grpName );
2365 // Pass SMESHDS_Group to MED writer
2366 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
2368 myWriter.AddGroup( aGrpDS );
2370 // write reference on a shape if exists
2371 SMESHDS_GroupOnGeom* aGeomGrp =
2372 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
2374 SALOMEDS::SObject_var mySubRef, myShape;
2375 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
2376 mySubRef->ReferencedObject( myShape ) &&
2377 !CORBA::is_nil( myShape->GetObject() ))
2379 string myRefOnObject = myShape->GetID();
2380 if ( myRefOnObject.length() > 0 ) {
2381 char aRefName[ 30 ];
2382 sprintf( aRefName, "Ref on shape %d", anId);
2383 aSize[ 0 ] = myRefOnObject.length() + 1;
2384 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
2385 aDataset->CreateOnDisk();
2386 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2387 aDataset->CloseOnDisk();
2390 else // shape ref is invalid:
2392 // save a group on geometry as ordinary group
2393 myWriter.AddGroup( aGeomGrp );
2399 aGroup->CloseOnDisk();
2403 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
2405 // Flush current mesh information into MED file
2408 // maybe a shape was deleted in the study
2409 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
2410 TopoDS_Shape nullShape;
2411 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
2414 if ( !mySMESHDSMesh->SubMeshes().empty() )
2418 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2419 aGroup->CreateOnDisk();
2421 // each element belongs to one or none submesh,
2422 // so for each node/element, we store a submesh ID
2424 // Make maps of submesh IDs of elements sorted by element IDs
2425 typedef int TElemID;
2426 typedef int TSubMID;
2427 map< TElemID, TSubMID > eId2smId, nId2smId;
2428 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
2429 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
2430 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
2431 SMDS_NodeIteratorPtr itNode;
2432 SMDS_ElemIteratorPtr itElem;
2433 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2435 TSubMID aSubMeID = itSubM->first;
2436 SMESHDS_SubMesh* aSubMesh = itSubM->second;
2437 if ( aSubMesh->IsComplexSubmesh() )
2438 continue; // submesh containing other submeshs
2440 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
2441 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
2442 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
2444 hint = eId2smId.begin();
2445 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
2446 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
2449 // Care of elements that are not on submeshes
2450 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
2451 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
2452 /* --- stl_map.h says : */
2453 /* A %map relies on unique keys and thus a %pair is only inserted if its */
2454 /* first element (the key) is not already present in the %map. */
2455 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
2457 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
2458 if ( nbElems != eId2smId.size() ) {
2459 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
2460 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
2463 // Store submesh IDs
2464 for ( int isNode = 0; isNode < 2; ++isNode )
2466 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
2467 if ( id2smId.empty() ) continue;
2468 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
2469 // make and fill array of submesh IDs
2470 int* smIDs = new int [ id2smId.size() ];
2471 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
2472 smIDs[ i ] = id_smId->second;
2474 aSize[ 0 ] = id2smId.size();
2475 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2476 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2477 aDataset->CreateOnDisk();
2478 aDataset->WriteOnDisk( smIDs );
2479 aDataset->CloseOnDisk();
2484 // Store node positions on sub-shapes (SMDS_Position):
2485 // ----------------------------------------------------
2487 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2488 aGroup->CreateOnDisk();
2490 // in aGroup, create 5 datasets to contain:
2491 // "Nodes on Edges" - ID of node on edge
2492 // "Edge positions" - U parameter on node on edge
2493 // "Nodes on Faces" - ID of node on face
2494 // "Face U positions" - U parameter of node on face
2495 // "Face V positions" - V parameter of node on face
2497 // Find out nb of nodes on edges and faces
2498 // Collect corresponing sub-meshes
2499 int nbEdgeNodes = 0, nbFaceNodes = 0;
2500 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
2501 // loop on SMESHDS_SubMesh'es
2502 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2504 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
2505 if ( aSubMesh->IsComplexSubmesh() )
2506 continue; // submesh containing other submeshs
2507 int nbNodes = aSubMesh->NbNodes();
2508 if ( nbNodes == 0 ) continue;
2510 int aShapeID = (*itSubM).first;
2511 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
2512 // write only SMDS_FacePosition and SMDS_EdgePosition
2513 switch ( aShapeType ) {
2515 nbFaceNodes += nbNodes;
2516 aFaceSM.push_back( aSubMesh );
2519 nbEdgeNodes += nbNodes;
2520 aEdgeSM.push_back( aSubMesh );
2526 // Treat positions on edges or faces
2527 for ( int onFace = 0; onFace < 2; onFace++ )
2529 // Create arrays to store in datasets
2530 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
2531 if (!nbNodes) continue;
2532 int* aNodeIDs = new int [ nbNodes ];
2533 double* aUPos = new double [ nbNodes ];
2534 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
2537 // loop on sub-meshes
2538 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
2539 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
2540 for ( ; itSM != pListSM->end(); itSM++ )
2542 SMESHDS_SubMesh* aSubMesh = (*itSM);
2544 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
2545 // loop on nodes in aSubMesh
2546 while ( itNode->more() )
2549 const SMDS_MeshNode* node = itNode->next();
2550 aNodeIDs [ iNode ] = node->GetID();
2553 const SMDS_PositionPtr pos = node->GetPosition();
2554 if ( onFace ) { // on FACE
2555 const SMDS_FacePosition* fPos =
2556 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
2558 aUPos[ iNode ] = fPos->GetUParameter();
2559 aVPos[ iNode ] = fPos->GetVParameter();
2566 const SMDS_EdgePosition* ePos =
2567 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
2569 aUPos[ iNode ] = ePos->GetUParameter();
2575 } // loop on nodes in aSubMesh
2576 } // loop on sub-meshes
2581 aSize[ 0 ] = nbNodes;
2583 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
2584 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2585 aDataset->CreateOnDisk();
2586 aDataset->WriteOnDisk( aNodeIDs );
2587 aDataset->CloseOnDisk();
2590 aDSName = ( onFace ? "Face U positions" : "Edge positions");
2591 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
2592 aDataset->CreateOnDisk();
2593 aDataset->WriteOnDisk( aUPos );
2594 aDataset->CloseOnDisk();
2597 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
2598 aDataset->CreateOnDisk();
2599 aDataset->WriteOnDisk( aVPos );
2600 aDataset->CloseOnDisk();
2605 if ( aVPos ) delete [] aVPos;
2607 } // treat positions on edges or faces
2609 // close "Node Positions" group
2610 aGroup->CloseOnDisk();
2612 } // if ( there are submeshes in SMESHDS_Mesh )
2615 // close mesh HDF group
2616 aTopGroup->CloseOnDisk();
2624 aFile->CloseOnDisk();
2627 // Convert temporary files to stream
2628 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
2630 // Remove temporary files and directory
2632 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2634 INFOS( "SMESH_Gen_i::Save() completed" );
2635 return aStreamFile._retn();
2638 //=============================================================================
2640 * SMESH_Gen_i::SaveASCII
2642 * Save SMESH module's data in ASCII format
2644 //=============================================================================
2646 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2648 bool isMultiFile ) {
2649 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2650 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2651 return aStreamFile._retn();
2653 //after usual saving needs to encipher binary to text string
2654 //Any binary symbol will be represent as "|xx" () hexadecimal format number
2655 int size = aStreamFile.in().length();
2656 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
2657 for ( int i = 0; i < size; i++ )
2658 sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
2660 buffer[size * 3] = '\0';
2662 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
2664 return anAsciiStreamFile._retn();
2667 //=============================================================================
2669 * SMESH_Gen_i::loadGeomData
2671 * Load GEOM module data
2673 //=============================================================================
2675 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2677 if ( theCompRoot->_is_nil() )
2680 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2681 if ( aStudy->_is_nil() )
2684 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2685 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2687 //=============================================================================
2689 * \brief Creates SMDS_Position according to shape type
2691 //=============================================================================
2693 class PositionCreator {
2695 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
2696 return (this->*myFuncTable[ type ])();
2699 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
2700 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
2701 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
2702 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
2705 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
2706 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
2707 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
2708 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
2709 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
2710 vector<FmakePos> myFuncTable;
2713 //=============================================================================
2717 * Load SMESH module's data
2719 //=============================================================================
2721 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2722 const SALOMEDS::TMPFile& theStream,
2726 INFOS( "SMESH_Gen_i::Load" );
2728 if ( myCurrentStudy->_is_nil() ||
2729 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2730 SetCurrentStudy( theComponent->GetStudy() );
2732 /* if( !theComponent->_is_nil() )
2734 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2735 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2736 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2739 StudyContext* myStudyContext = GetCurrentStudyContext();
2741 // Get temporary files location
2742 TCollection_AsciiString tmpDir =
2743 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2745 INFOS( "THE URL++++++++++++++" )
2747 INFOS( "THE TMP PATH+++++++++" );
2750 // Convert the stream into sequence of files to process
2751 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2754 TCollection_AsciiString aStudyName( "" );
2756 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2758 // Set names of temporary files
2759 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2760 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2764 HDFdataset* aDataset;
2765 HDFgroup* aTopGroup;
2767 HDFgroup* aSubGroup;
2768 HDFgroup* aSubSubGroup;
2771 // ---> open HDF file
2772 aFile = new HDFfile( filename.ToCString() );
2774 aFile->OpenOnDisk( HDF_RDONLY );
2776 catch ( HDFexception ) {
2777 INFOS( "Load(): " << filename << " not found!" );
2781 DriverMED_R_SMESHDS_Mesh myReader;
2782 myReader.SetFile( meshfile.ToCString() );
2784 // For PAL13473 ("Repetitive mesh") implementation.
2785 // New dependencies between SMESH objects are established:
2786 // now hypotheses can refer to meshes, shapes and other hypotheses.
2787 // To keep data consistent, the following order of data restoration
2789 // 1. Create hypotheses
2790 // 2. Create all meshes
2791 // 3. Load hypotheses' data
2794 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
2795 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
2797 // get total number of top-level groups
2798 int aNbGroups = aFile->nInternalObjects();
2799 if ( aNbGroups > 0 ) {
2800 // --> in first turn we should read&create hypotheses
2801 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2802 // open hypotheses root HDF group
2803 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2804 aTopGroup->OpenOnDisk();
2806 // get number of hypotheses
2807 int aNbObjects = aTopGroup->nInternalObjects();
2808 for ( int j = 0; j < aNbObjects; j++ ) {
2809 // try to identify hypothesis
2810 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2811 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2813 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2814 // open hypothesis group
2815 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2816 aGroup->OpenOnDisk();
2818 // --> get hypothesis id
2819 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2824 // get number of datasets
2825 int aNbSubObjects = aGroup->nInternalObjects();
2826 for ( int k = 0; k < aNbSubObjects; k++ ) {
2828 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2829 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2830 // --> get hypothesis name
2831 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2832 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2833 aDataset->OpenOnDisk();
2834 size = aDataset->GetSize();
2835 char* hypname_str = new char[ size ];
2836 aDataset->ReadFromDisk( hypname_str );
2837 hypname = string( hypname_str );
2838 delete [] hypname_str;
2839 aDataset->CloseOnDisk();
2841 // --> get hypothesis plugin library name
2842 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2843 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2844 aDataset->OpenOnDisk();
2845 size = aDataset->GetSize();
2846 char* libname_str = new char[ size ];
2847 aDataset->ReadFromDisk( libname_str );
2848 if(MYDEBUG) SCRUTE( libname_str );
2849 libname = string( libname_str );
2850 delete [] libname_str;
2851 aDataset->CloseOnDisk();
2853 // --> get hypothesis data
2854 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2855 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2856 aDataset->OpenOnDisk();
2857 size = aDataset->GetSize();
2858 char* hypdata_str = new char[ size ];
2859 aDataset->ReadFromDisk( hypdata_str );
2860 hypdata = string( hypdata_str );
2861 delete [] hypdata_str;
2862 aDataset->CloseOnDisk();
2865 // close hypothesis HDF group
2866 aGroup->CloseOnDisk();
2868 // --> restore hypothesis from data
2869 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2870 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2871 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2872 SMESH::SMESH_Hypothesis_var myHyp;
2874 try { // protect persistence mechanism against exceptions
2875 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2878 INFOS( "Exception during hypothesis creation" );
2881 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2883 // myImpl->LoadFrom( hypdata.c_str() );
2884 hypDataList.push_back( make_pair( myImpl, hypdata ));
2885 string iorString = GetORB()->object_to_string( myHyp );
2886 int newId = myStudyContext->findId( iorString );
2887 myStudyContext->mapOldToNew( id, newId );
2890 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2894 // close hypotheses root HDF group
2895 aTopGroup->CloseOnDisk();
2899 // --> then we should read&create algorithms
2900 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2901 // open algorithms root HDF group
2902 aTopGroup = new HDFgroup( "Algorithms", aFile );
2903 aTopGroup->OpenOnDisk();
2905 // get number of algorithms
2906 int aNbObjects = aTopGroup->nInternalObjects();
2907 for ( int j = 0; j < aNbObjects; j++ ) {
2908 // try to identify algorithm
2909 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2910 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2912 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2913 // open algorithm group
2914 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2915 aGroup->OpenOnDisk();
2917 // --> get algorithm id
2918 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2923 // get number of datasets
2924 int aNbSubObjects = aGroup->nInternalObjects();
2925 for ( int k = 0; k < aNbSubObjects; k++ ) {
2927 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2928 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2929 // --> get algorithm name
2930 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2931 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2932 aDataset->OpenOnDisk();
2933 size = aDataset->GetSize();
2934 char* hypname_str = new char[ size ];
2935 aDataset->ReadFromDisk( hypname_str );
2936 hypname = string( hypname_str );
2937 delete [] hypname_str;
2938 aDataset->CloseOnDisk();
2940 // --> get algorithm plugin library name
2941 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2942 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2943 aDataset->OpenOnDisk();
2944 size = aDataset->GetSize();
2945 char* libname_str = new char[ size ];
2946 aDataset->ReadFromDisk( libname_str );
2947 if(MYDEBUG) SCRUTE( libname_str );
2948 libname = string( libname_str );
2949 delete [] libname_str;
2950 aDataset->CloseOnDisk();
2952 // --> get algorithm data
2953 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2954 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2955 aDataset->OpenOnDisk();
2956 size = aDataset->GetSize();
2957 char* hypdata_str = new char[ size ];
2958 aDataset->ReadFromDisk( hypdata_str );
2959 if(MYDEBUG) SCRUTE( hypdata_str );
2960 hypdata = string( hypdata_str );
2961 delete [] hypdata_str;
2962 aDataset->CloseOnDisk();
2965 // close algorithm HDF group
2966 aGroup->CloseOnDisk();
2968 // --> restore algorithm from data
2969 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2970 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2971 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2972 SMESH::SMESH_Hypothesis_var myHyp;
2974 try { // protect persistence mechanism against exceptions
2975 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2978 INFOS( "Exception during hypothesis creation" );
2981 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2983 //myImpl->LoadFrom( hypdata.c_str() );
2984 hypDataList.push_back( make_pair( myImpl, hypdata ));
2985 string iorString = GetORB()->object_to_string( myHyp );
2986 int newId = myStudyContext->findId( iorString );
2987 myStudyContext->mapOldToNew( id, newId );
2990 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2994 // close algorithms root HDF group
2995 aTopGroup->CloseOnDisk();
2999 // --> the rest groups should be meshes
3000 for ( int i = 0; i < aNbGroups; i++ ) {
3001 // identify next group
3002 char meshName[ HDF_NAME_MAX_LEN+1 ];
3003 aFile->InternalObjectIndentify( i, meshName );
3005 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
3007 int id = atoi( string( meshName ).substr( 4 ).c_str() );
3011 // open mesh HDF group
3012 aTopGroup = new HDFgroup( meshName, aFile );
3013 aTopGroup->OpenOnDisk();
3015 // get number of child HDF objects
3016 int aNbObjects = aTopGroup->nInternalObjects();
3017 if ( aNbObjects > 0 ) {
3019 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
3020 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
3021 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
3022 if ( !myNewMeshImpl )
3024 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
3026 string iorString = GetORB()->object_to_string( myNewMesh );
3027 int newId = myStudyContext->findId( iorString );
3028 myStudyContext->mapOldToNew( id, newId );
3031 // try to read and set auto color flag
3032 char aMeshAutoColorName[ 30 ];
3033 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
3034 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
3036 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
3037 aDataset->OpenOnDisk();
3038 size = aDataset->GetSize();
3039 int* anAutoColor = new int[ size ];
3040 aDataset->ReadFromDisk( anAutoColor );
3041 aDataset->CloseOnDisk();
3042 myNewMeshImpl->SetAutoColor( (bool)anAutoColor[0] );
3045 // try to read and set reference to shape
3046 GEOM::GEOM_Object_var aShapeObject;
3047 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
3048 // load mesh "Ref on shape" - it's an entry to SObject
3049 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
3050 aDataset->OpenOnDisk();
3051 size = aDataset->GetSize();
3052 char* refFromFile = new char[ size ];
3053 aDataset->ReadFromDisk( refFromFile );
3054 aDataset->CloseOnDisk();
3055 if ( strlen( refFromFile ) > 0 ) {
3056 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3058 // Make sure GEOM data are loaded first
3059 //loadGeomData( shapeSO->GetFatherComponent() );
3061 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3062 if ( !CORBA::is_nil( shapeObject ) ) {
3063 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3064 if ( !aShapeObject->_is_nil() )
3065 myNewMeshImpl->SetShape( aShapeObject );
3074 // As all object that can be referred by hypothesis are created,
3075 // we can restore hypothesis data
3077 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
3078 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
3080 SMESH_Hypothesis_i* hyp = hyp_data->first;
3081 string & data = hyp_data->second;
3082 hyp->LoadFrom( data.c_str() );
3085 // Restore the rest mesh data
3087 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
3088 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
3090 aTopGroup = meshi_group->second;
3091 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
3092 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
3093 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3095 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
3096 bool hasData = false;
3099 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
3100 int newId = myStudyContext->findId( iorString );
3101 int id = myStudyContext->getOldId( newId );
3103 // try to find mesh data dataset
3104 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
3105 // load mesh "has data" flag
3106 aDataset = new HDFdataset( "Has data", aTopGroup );
3107 aDataset->OpenOnDisk();
3108 size = aDataset->GetSize();
3109 char* strHasData = new char[ size ];
3110 aDataset->ReadFromDisk( strHasData );
3111 aDataset->CloseOnDisk();
3112 if ( strcmp( strHasData, "1") == 0 ) {
3113 // read mesh data from MED file
3114 myReader.SetMesh( mySMESHDSMesh );
3115 myReader.SetMeshId( id );
3121 // try to get applied algorithms
3122 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3123 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3124 aGroup->OpenOnDisk();
3125 // get number of applied algorithms
3126 int aNbSubObjects = aGroup->nInternalObjects();
3127 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
3128 for ( int j = 0; j < aNbSubObjects; j++ ) {
3129 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3130 aGroup->InternalObjectIndentify( j, name_dataset );
3131 // check if it is an algorithm
3132 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3133 aDataset = new HDFdataset( name_dataset, aGroup );
3134 aDataset->OpenOnDisk();
3135 size = aDataset->GetSize();
3136 char* refFromFile = new char[ size ];
3137 aDataset->ReadFromDisk( refFromFile );
3138 aDataset->CloseOnDisk();
3140 // san - it is impossible to recover applied algorithms using their entries within Load() method
3142 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3143 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3144 int id = atoi( refFromFile );
3145 string anIOR = myStudyContext->getIORbyOldId( id );
3146 if ( !anIOR.empty() ) {
3147 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3148 if ( !CORBA::is_nil( hypObject ) ) {
3149 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3150 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3151 || !myNewMeshImpl->HasShapeToMesh()) )
3152 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3157 aGroup->CloseOnDisk();
3160 // try to get applied hypotheses
3161 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3162 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3163 aGroup->OpenOnDisk();
3164 // get number of applied hypotheses
3165 int aNbSubObjects = aGroup->nInternalObjects();
3166 for ( int j = 0; j < aNbSubObjects; j++ ) {
3167 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3168 aGroup->InternalObjectIndentify( j, name_dataset );
3169 // check if it is a hypothesis
3170 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3171 aDataset = new HDFdataset( name_dataset, aGroup );
3172 aDataset->OpenOnDisk();
3173 size = aDataset->GetSize();
3174 char* refFromFile = new char[ size ];
3175 aDataset->ReadFromDisk( refFromFile );
3176 aDataset->CloseOnDisk();
3178 // san - it is impossible to recover applied hypotheses using their entries within Load() method
3180 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3181 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3182 int id = atoi( refFromFile );
3183 string anIOR = myStudyContext->getIORbyOldId( id );
3184 if ( !anIOR.empty() ) {
3185 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3186 if ( !CORBA::is_nil( hypObject ) ) {
3187 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3188 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3189 || !myNewMeshImpl->HasShapeToMesh()) )
3190 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3195 aGroup->CloseOnDisk();
3198 // --> try to find submeshes containers for each type of submesh
3199 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
3200 char name_meshgroup[ 30 ];
3201 if ( j == GetSubMeshOnVertexTag() )
3202 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3203 else if ( j == GetSubMeshOnEdgeTag() )
3204 strcpy( name_meshgroup, "SubMeshes On Edge" );
3205 else if ( j == GetSubMeshOnWireTag() )
3206 strcpy( name_meshgroup, "SubMeshes On Wire" );
3207 else if ( j == GetSubMeshOnFaceTag() )
3208 strcpy( name_meshgroup, "SubMeshes On Face" );
3209 else if ( j == GetSubMeshOnShellTag() )
3210 strcpy( name_meshgroup, "SubMeshes On Shell" );
3211 else if ( j == GetSubMeshOnSolidTag() )
3212 strcpy( name_meshgroup, "SubMeshes On Solid" );
3213 else if ( j == GetSubMeshOnCompoundTag() )
3214 strcpy( name_meshgroup, "SubMeshes On Compound" );
3216 // try to get submeshes container HDF group
3217 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
3218 // open submeshes containers HDF group
3219 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3220 aGroup->OpenOnDisk();
3222 // get number of submeshes
3223 int aNbSubMeshes = aGroup->nInternalObjects();
3224 for ( int k = 0; k < aNbSubMeshes; k++ ) {
3226 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
3227 aGroup->InternalObjectIndentify( k, name_submeshgroup );
3228 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
3229 // --> get submesh id
3230 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
3233 // open submesh HDF group
3234 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
3235 aSubGroup->OpenOnDisk();
3237 // try to read and set reference to subshape
3238 GEOM::GEOM_Object_var aSubShapeObject;
3239 SMESH::SMESH_subMesh_var aSubMesh;
3241 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
3242 // load submesh "Ref on shape" - it's an entry to SObject
3243 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
3244 aDataset->OpenOnDisk();
3245 size = aDataset->GetSize();
3246 char* refFromFile = new char[ size ];
3247 aDataset->ReadFromDisk( refFromFile );
3248 aDataset->CloseOnDisk();
3249 if ( strlen( refFromFile ) > 0 ) {
3250 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
3251 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
3252 if ( !CORBA::is_nil( subShapeObject ) ) {
3253 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
3254 if ( !aSubShapeObject->_is_nil() )
3255 aSubMesh = SMESH::SMESH_subMesh::_duplicate
3256 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
3257 if ( aSubMesh->_is_nil() )
3259 string iorSubString = GetORB()->object_to_string( aSubMesh );
3260 int newSubId = myStudyContext->findId( iorSubString );
3261 myStudyContext->mapOldToNew( subid, newSubId );
3266 if ( aSubMesh->_is_nil() )
3269 // VSR: Get submesh data from MED convertor
3270 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
3271 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
3272 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
3273 // subid << " for subshape # " << anInternalSubmeshId);
3274 // SMESHDS_SubMesh* aSubMeshDS =
3275 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
3276 // if ( !aSubMeshDS ) {
3277 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
3278 // anInternalSubmeshId << " in current mesh!");
3281 // myReader.GetSubMesh( aSubMeshDS, subid );
3284 // try to get applied algorithms
3285 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3286 // open "applied algorithms" HDF group
3287 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3288 aSubSubGroup->OpenOnDisk();
3289 // get number of applied algorithms
3290 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3291 for ( int l = 0; l < aNbSubObjects; l++ ) {
3292 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3293 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3294 // check if it is an algorithm
3295 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3296 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3297 aDataset->OpenOnDisk();
3298 size = aDataset->GetSize();
3299 char* refFromFile = new char[ size ];
3300 aDataset->ReadFromDisk( refFromFile );
3301 aDataset->CloseOnDisk();
3303 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3304 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3305 int id = atoi( refFromFile );
3306 string anIOR = myStudyContext->getIORbyOldId( id );
3307 if ( !anIOR.empty() ) {
3308 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3309 if ( !CORBA::is_nil( hypObject ) ) {
3310 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3311 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3312 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3317 // close "applied algorithms" HDF group
3318 aSubSubGroup->CloseOnDisk();
3321 // try to get applied hypotheses
3322 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3323 // open "applied hypotheses" HDF group
3324 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3325 aSubSubGroup->OpenOnDisk();
3326 // get number of applied hypotheses
3327 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3328 for ( int l = 0; l < aNbSubObjects; l++ ) {
3329 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3330 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3331 // check if it is a hypothesis
3332 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3333 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3334 aDataset->OpenOnDisk();
3335 size = aDataset->GetSize();
3336 char* refFromFile = new char[ size ];
3337 aDataset->ReadFromDisk( refFromFile );
3338 aDataset->CloseOnDisk();
3340 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3341 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3342 int id = atoi( refFromFile );
3343 string anIOR = myStudyContext->getIORbyOldId( id );
3344 if ( !anIOR.empty() ) {
3345 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3346 if ( !CORBA::is_nil( hypObject ) ) {
3347 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3348 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3349 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3354 // close "applied hypotheses" HDF group
3355 aSubSubGroup->CloseOnDisk();
3358 // close submesh HDF group
3359 aSubGroup->CloseOnDisk();
3362 // close submeshes containers HDF group
3363 aGroup->CloseOnDisk();
3369 // Read sub-meshes from MED
3370 // -------------------------
3371 if(MYDEBUG) MESSAGE("Create all sub-meshes");
3372 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
3373 if ( submeshesInFamilies )
3375 // old way working before fix of PAL 12992
3376 myReader.CreateAllSubMeshes();
3381 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3382 aGroup->OpenOnDisk();
3384 int maxID = mySMESHDSMesh->MaxShapeIndex();
3385 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
3386 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
3388 PositionCreator aPositionCreator;
3390 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
3391 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
3392 for ( int isNode = 0; isNode < 2; ++isNode )
3394 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3395 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
3397 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
3398 aDataset->OpenOnDisk();
3399 // read submesh IDs for all elements sorted by ID
3400 int nbElems = aDataset->GetSize();
3401 int* smIDs = new int [ nbElems ];
3402 aDataset->ReadFromDisk( smIDs );
3403 aDataset->CloseOnDisk();
3405 // get elements sorted by ID
3406 TIDSortedElemSet elemSet;
3408 while ( nIt->more() ) elemSet.insert( nIt->next() );
3410 while ( eIt->more() ) elemSet.insert( eIt->next() );
3411 ASSERT( elemSet.size() == nbElems );
3413 // add elements to submeshes
3414 TIDSortedElemSet::iterator iE = elemSet.begin();
3415 for ( int i = 0; i < nbElems; ++i, ++iE )
3417 int smID = smIDs[ i ];
3418 if ( smID == 0 ) continue;
3419 ASSERT( smID <= maxID );
3420 const SMDS_MeshElement* elem = *iE;
3421 // get or create submesh
3422 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
3424 sm = mySMESHDSMesh->NewSubMesh( smID );
3425 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
3429 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
3430 pos->SetShapeId( smID );
3431 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
3432 node->SetPosition( pos );
3433 sm->AddNode( node );
3435 sm->AddElement( elem );
3441 } // end reading submeshes
3443 // Read node positions on sub-shapes (SMDS_Position)
3445 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
3447 // There are 5 datasets to read:
3448 // "Nodes on Edges" - ID of node on edge
3449 // "Edge positions" - U parameter on node on edge
3450 // "Nodes on Faces" - ID of node on face
3451 // "Face U positions" - U parameter of node on face
3452 // "Face V positions" - V parameter of node on face
3453 char* aEid_DSName = "Nodes on Edges";
3454 char* aEu_DSName = "Edge positions";
3455 char* aFu_DSName = "Face U positions";
3456 //char* aFid_DSName = "Nodes on Faces";
3457 //char* aFv_DSName = "Face V positions";
3460 int nbEids = 0, nbFids = 0;
3461 int *aEids = 0, *aFids = 0;
3462 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
3465 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3466 aGroup->OpenOnDisk();
3468 // loop on 5 data sets
3469 int aNbObjects = aGroup->nInternalObjects();
3470 for ( int i = 0; i < aNbObjects; i++ )
3473 char aDSName[ HDF_NAME_MAX_LEN+1 ];
3474 aGroup->InternalObjectIndentify( i, aDSName );
3476 aDataset = new HDFdataset( aDSName, aGroup );
3477 aDataset->OpenOnDisk();
3478 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
3480 double* pos = new double [ aDataset->GetSize() ];
3481 aDataset->ReadFromDisk( pos );
3483 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
3485 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
3492 int aSize = aDataset->GetSize();
3494 // for reading files, created from 18.07.2005 till 10.10.2005
3495 if (aDataset->GetType() == HDF_STRING)
3496 aSize /= sizeof(int);
3498 int* ids = new int [aSize];
3499 aDataset->ReadFromDisk( ids );
3500 // on face or nodes?
3501 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
3510 aDataset->CloseOnDisk();
3511 } // loop on 5 datasets
3513 // Set node positions on edges or faces
3514 for ( int onFace = 0; onFace < 2; onFace++ )
3516 int nbNodes = ( onFace ? nbFids : nbEids );
3517 if ( nbNodes == 0 ) continue;
3518 int* aNodeIDs = ( onFace ? aFids : aEids );
3519 double* aUPos = ( onFace ? aFupos : aEpos );
3520 double* aVPos = ( onFace ? aFvpos : 0 );
3522 for ( int iNode = 0; iNode < nbNodes; iNode++ )
3524 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
3526 SMDS_PositionPtr aPos = node->GetPosition();
3529 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
3530 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
3531 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
3532 fPos->SetUParameter( aUPos[ iNode ]);
3533 fPos->SetVParameter( aVPos[ iNode ]);
3536 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
3537 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
3538 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
3539 fPos->SetUParameter( aUPos[ iNode ]);
3543 if ( aEids ) delete [] aEids;
3544 if ( aFids ) delete [] aFids;
3545 if ( aEpos ) delete [] aEpos;
3546 if ( aFupos ) delete [] aFupos;
3547 if ( aFvpos ) delete [] aFvpos;
3549 aGroup->CloseOnDisk();
3551 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
3554 // Recompute State (as computed sub-meshes are restored from MED)
3555 if ( !aShapeObject->_is_nil() || !myNewMeshImpl->HasShapeToMesh()) {
3556 MESSAGE("Compute State Engine ...");
3557 TopoDS_Shape myLocShape;
3558 if(myNewMeshImpl->HasShapeToMesh())
3559 myLocShape = GeomObjectToShape( aShapeObject );
3561 myLocShape = SMESH_Mesh::PseudoShape();
3563 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
3564 (SMESH_subMesh::SUBMESH_RESTORED);
3565 MESSAGE("Compute State Engine finished");
3568 // try to get groups
3569 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
3570 char name_group[ 30 ];
3571 if ( ii == GetNodeGroupsTag() )
3572 strcpy( name_group, "Groups of Nodes" );
3573 else if ( ii == GetEdgeGroupsTag() )
3574 strcpy( name_group, "Groups of Edges" );
3575 else if ( ii == GetFaceGroupsTag() )
3576 strcpy( name_group, "Groups of Faces" );
3577 else if ( ii == GetVolumeGroupsTag() )
3578 strcpy( name_group, "Groups of Volumes" );
3580 if ( aTopGroup->ExistInternalObject( name_group ) ) {
3581 aGroup = new HDFgroup( name_group, aTopGroup );
3582 aGroup->OpenOnDisk();
3583 // get number of groups
3584 int aNbSubObjects = aGroup->nInternalObjects();
3585 for ( int j = 0; j < aNbSubObjects; j++ ) {
3586 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3587 aGroup->InternalObjectIndentify( j, name_dataset );
3588 // check if it is an group
3589 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
3591 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
3594 aDataset = new HDFdataset( name_dataset, aGroup );
3595 aDataset->OpenOnDisk();
3597 // Retrieve actual group name
3598 size = aDataset->GetSize();
3599 char* nameFromFile = new char[ size ];
3600 aDataset->ReadFromDisk( nameFromFile );
3601 aDataset->CloseOnDisk();
3603 // Try to find a shape reference
3604 TopoDS_Shape aShape;
3605 char aRefName[ 30 ];
3606 sprintf( aRefName, "Ref on shape %d", subid);
3607 if ( aGroup->ExistInternalObject( aRefName ) ) {
3608 // load mesh "Ref on shape" - it's an entry to SObject
3609 aDataset = new HDFdataset( aRefName, aGroup );
3610 aDataset->OpenOnDisk();
3611 size = aDataset->GetSize();
3612 char* refFromFile = new char[ size ];
3613 aDataset->ReadFromDisk( refFromFile );
3614 aDataset->CloseOnDisk();
3615 if ( strlen( refFromFile ) > 0 ) {
3616 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3617 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3618 if ( !CORBA::is_nil( shapeObject ) ) {
3619 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3620 if ( !aShapeObject->_is_nil() )
3621 aShape = GeomObjectToShape( aShapeObject );
3625 // Create group servant
3626 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
3627 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
3628 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
3629 // Obtain a SMESHDS_Group object
3630 if ( aNewGroup->_is_nil() )
3633 string iorSubString = GetORB()->object_to_string( aNewGroup );
3634 int newSubId = myStudyContext->findId( iorSubString );
3635 myStudyContext->mapOldToNew( subid, newSubId );
3637 SMESH_GroupBase_i* aGroupImpl =
3638 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
3642 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
3646 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
3647 aGroupBaseDS->SetStoreName( name_dataset );
3650 // Read color of the group
3651 char aGroupColorName[ 30 ];
3652 sprintf( aGroupColorName, "ColorGroup %d", subid);
3653 if ( aGroup->ExistInternalObject( aGroupColorName ) )
3655 aDataset = new HDFdataset( aGroupColorName, aGroup );
3656 aDataset->OpenOnDisk();
3657 size = aDataset->GetSize();
3658 double* anRGB = new double[ size ];
3659 aDataset->ReadFromDisk( anRGB );
3660 aDataset->CloseOnDisk();
3661 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
3662 aGroupBaseDS->SetColor( aColor );
3665 // Fill group with contents from MED file
3666 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
3668 myReader.GetGroup( aGrp );
3671 aGroup->CloseOnDisk();
3677 aTopGroup->CloseOnDisk();
3680 aFile->CloseOnDisk();
3683 // Remove temporary files created from the stream
3685 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3687 INFOS( "SMESH_Gen_i::Load completed" );
3691 //=============================================================================
3693 * SMESH_Gen_i::LoadASCII
3695 * Load SMESH module's data in ASCII format
3697 //=============================================================================
3699 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
3700 const SALOMEDS::TMPFile& theStream,
3702 bool isMultiFile ) {
3703 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
3704 return Load( theComponent, theStream, theURL, isMultiFile );
3706 //before call main ::Load method it's need for decipher text format to
3707 //binary ( "|xx" => x' )
3708 int size = theStream.length();
3709 if ( int((size / 3 )*3) != size ) //error size of buffer
3712 int real_size = int(size / 3);
3714 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
3718 for ( int i = 0; i < real_size; i++ )
3720 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
3721 sscanf( tmp, "%x", &c );
3722 sprintf( (char*)&(buffer[i]), "%c", (char)c );
3725 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
3727 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
3730 //=============================================================================
3732 * SMESH_Gen_i::Close
3734 * Clears study-connected data when it is closed
3736 //=============================================================================
3738 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
3740 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
3742 // set correct current study
3743 if (theComponent->GetStudy()->StudyId() != GetCurrentStudyID())
3744 SetCurrentStudy(theComponent->GetStudy());
3746 // Clear study contexts data
3747 int studyId = GetCurrentStudyID();
3748 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
3749 delete myStudyContextMap[ studyId ];
3750 myStudyContextMap.erase( studyId );
3753 // delete SMESH_Mesh's
3754 // See bug IPAL19437.
3756 // StudyContextStruct* context = myGen.GetStudyContext( studyId );
3757 // map< int, SMESH_Mesh* >::iterator i_mesh = context->mapMesh.begin();
3758 // for ( ; i_mesh != context->mapMesh.end(); ++i_mesh ) {
3759 // printf( "--------------------------- SMESH_Gen_i::Close, delete aGroup = %p \n", i_mesh->second );
3760 // delete i_mesh->second;
3764 // delete SMESHDS_Mesh's
3765 // it's too long on big meshes
3766 // if ( context->myDocument ) {
3767 // delete context->myDocument;
3768 // context->myDocument = 0;
3774 //=============================================================================
3776 * SMESH_Gen_i::ComponentDataType
3778 * Get component data type
3780 //=============================================================================
3782 char* SMESH_Gen_i::ComponentDataType()
3784 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
3785 return CORBA::string_dup( "SMESH" );
3789 //=============================================================================
3791 * SMESH_Gen_i::IORToLocalPersistentID
3793 * Transform data from transient form to persistent
3795 //=============================================================================
3797 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
3798 const char* IORString,
3799 CORBA::Boolean /*isMultiFile*/,
3800 CORBA::Boolean /*isASCII*/ )
3802 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
3803 StudyContext* myStudyContext = GetCurrentStudyContext();
3805 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
3806 int anId = myStudyContext->findId( IORString );
3808 if(MYDEBUG) MESSAGE( "VSR " << anId )
3810 sprintf( strId, "%d", anId );
3811 return CORBA::string_dup( strId );
3814 return CORBA::string_dup( "" );
3817 //=============================================================================
3819 * SMESH_Gen_i::LocalPersistentIDToIOR
3821 * Transform data from persistent form to transient
3823 //=============================================================================
3825 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
3826 const char* aLocalPersistentID,
3827 CORBA::Boolean /*isMultiFile*/,
3828 CORBA::Boolean /*isASCII*/ )
3830 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
3831 StudyContext* myStudyContext = GetCurrentStudyContext();
3833 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
3834 int anId = atoi( aLocalPersistentID );
3835 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
3837 return CORBA::string_dup( "" );
3840 //=======================================================================
3841 //function : RegisterObject
3843 //=======================================================================
3845 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
3847 StudyContext* myStudyContext = GetCurrentStudyContext();
3848 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3849 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
3850 return myStudyContext->addObject( string( iorString.in() ) );
3855 //================================================================================
3857 * \brief Return id of registered object
3858 * \param theObject - the Object
3859 * \retval int - Object id
3861 //================================================================================
3863 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
3865 StudyContext* myStudyContext = GetCurrentStudyContext();
3866 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3867 string iorString = GetORB()->object_to_string( theObject );
3868 return myStudyContext->findId( iorString );
3873 //=============================================================================
3875 * SMESHEngine_factory
3877 * C factory, accessible with dlsym, after dlopen
3879 //=============================================================================
3883 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3884 PortableServer::POA_ptr poa,
3885 PortableServer::ObjectId* contId,
3886 const char* instanceName,
3887 const char* interfaceName )
3889 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3890 if(MYDEBUG) SCRUTE(interfaceName);
3891 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3892 return aSMESHGen->getId() ;