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 && !strncmp( theLibName, "lib", 3 ) && !strcmp( theLibName+libNameLen-3, ".so" ) )
334 aPlatformLibName = new char[libNameLen - 1];
335 aPlatformLibName[0] = '\0';
336 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
337 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
338 aPlatformLibName[libNameLen - 2] = '\0';
340 aPlatformLibName = new char[ libNameLen + 1];
341 aPlatformLibName[0] = '\0';
342 aPlatformLibName = strcat( aPlatformLibName, theLibName );
343 aPlatformLibName[libNameLen] = '\0';
349 //try to use new format
351 aPlatformLibName = new char[ libNameLen + 5 ];
352 aPlatformLibName[0] = '\0';
353 aPlatformLibName = strcat( aPlatformLibName, theLibName );
354 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
356 aPlatformLibName = new char[ libNameLen + 7 ];
357 aPlatformLibName[0] = '\0';
358 aPlatformLibName = strcat( aPlatformLibName, "lib" );
359 aPlatformLibName = strcat( aPlatformLibName, theLibName );
360 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 typedef map<int, int> TIDsMap;
1423 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
1424 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
1425 typedef std::set<SMESHDS_GroupBase*> TGroups;
1427 TPythonDump aPythonDump; // prevent dump of called methods
1430 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
1432 if ( !aNewMesh->_is_nil() ) {
1433 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
1435 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
1436 SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
1438 TGroupsMap aGroupsMap;
1439 TListOfNewGroups aListOfNewGroups;
1440 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
1441 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
1444 for ( int i = 0; i < theMeshesArray.length(); i++) {
1445 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
1446 if ( !anInitMesh->_is_nil() ) {
1447 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
1449 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
1450 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
1455 // loop on elements of mesh
1456 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
1457 const SMDS_MeshElement* anElem = 0;
1458 const SMDS_MeshElement* aNewElem = 0;
1459 int anElemNbNodes = 0;
1461 for ( int j = 0; itElems->more(); j++) {
1462 anElem = itElems->next();
1463 SMDSAbs_ElementType anElemType = anElem->GetType();
1464 anElemNbNodes = anElem->NbNodes();
1465 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
1467 // loop on nodes of element
1468 const SMDS_MeshNode* aNode = 0;
1469 const SMDS_MeshNode* aNewNode = 0;
1470 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
1472 for ( int k = 0; itNodes->more(); k++) {
1473 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
1474 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
1475 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
1476 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
1479 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
1480 aNodesArray[k] = aNewNode;
1483 // creates a corresponding element on existent nodes in new mesh
1484 if ( anElem->IsPoly() && anElemType == SMDSAbs_Volume )
1486 const SMDS_PolyhedralVolumeOfNodes* aVolume =
1487 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
1489 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
1490 aVolume->GetQuanities());
1491 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1496 aNewElem = aNewEditor.AddElement(aNodesArray,
1499 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1503 aListOfGroups = anInitImpl->GetGroups();
1504 SMESH::SMESH_GroupBase_ptr aGroup;
1506 // loop on groups of mesh
1507 SMESH::long_array_var anInitIDs = new SMESH::long_array();
1508 SMESH::long_array_var anNewIDs = new SMESH::long_array();
1509 SMESH::SMESH_Group_var aNewGroup;
1510 for (int i = 0; i < aListOfGroups->length(); i++) {
1511 aGroup = aListOfGroups[i];
1512 aListOfNewGroups.clear();
1513 SMESH::ElementType aGroupType = aGroup->GetType();
1514 CORBA::String_var aGroupName = aGroup->GetName();
1516 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
1518 // convert a list of IDs
1519 anInitIDs = aGroup->GetListOfID();
1520 anNewIDs->length(anInitIDs->length());
1521 if ( aGroupType == SMESH::NODE )
1522 for (int j = 0; j < anInitIDs->length(); j++) {
1523 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
1526 for (int j = 0; j < anInitIDs->length(); j++) {
1527 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
1530 // check that current group name and type don't have identical ones in union mesh
1531 if ( anIter == aGroupsMap.end() ) {
1532 // add a new group in the mesh
1533 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1534 // add elements into new group
1535 aNewGroup->Add( anNewIDs );
1537 aListOfNewGroups.push_back(aNewGroup);
1538 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
1541 else if ( theUniteIdenticalGroups ) {
1542 // unite identical groups
1543 TListOfNewGroups& aNewGroups = anIter->second;
1544 aNewGroups.front()->Add( anNewIDs );
1548 // rename identical groups
1549 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
1550 aNewGroup->Add( anNewIDs );
1552 TListOfNewGroups& aNewGroups = anIter->second;
1553 string aNewGroupName;
1554 if (aNewGroups.size() == 1) {
1555 aNewGroupName = string(aGroupName) + "_1";
1556 aNewGroups.front()->SetName(aNewGroupName.c_str());
1558 char aGroupNum[128];
1559 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
1560 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
1561 aNewGroup->SetName(aNewGroupName.c_str());
1562 aNewGroups.push_back(aNewGroup);
1569 if (theMergeNodesAndElements) {
1571 set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
1572 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
1573 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
1574 aNewEditor.MergeNodes( aGroupsOfNodes );
1576 aNewEditor.MergeEqualElements();
1581 // Update Python script
1582 aPythonDump << aNewMesh << " = " << this << ".Concatenate(";
1584 for ( int i = 0; i < theMeshesArray.length(); i++) {
1585 if (i > 0) aPythonDump << ", ";
1586 aPythonDump << theMeshesArray[i];
1588 aPythonDump << "], ";
1589 aPythonDump << theUniteIdenticalGroups << ", "
1590 << theMergeNodesAndElements << ", "
1591 << theMergeTolerance << ")";
1593 return aNewMesh._retn();
1596 //=============================================================================
1600 * Save SMESH module's data
1602 //=============================================================================
1603 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
1607 INFOS( "SMESH_Gen_i::Save" );
1609 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
1610 // san -- in case <myCurrentStudy> differs from theComponent's study,
1611 // use that of the component
1612 if ( myCurrentStudy->_is_nil() ||
1613 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
1614 SetCurrentStudy( theComponent->GetStudy() );
1616 // Store study contents as a set of python commands
1617 SavePython(myCurrentStudy);
1619 StudyContext* myStudyContext = GetCurrentStudyContext();
1621 // Declare a byte stream
1622 SALOMEDS::TMPFile_var aStreamFile;
1624 // Obtain a temporary dir
1625 TCollection_AsciiString tmpDir =
1626 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
1628 // Create a sequence of files processed
1629 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
1630 aFileSeq->length( NUM_TMP_FILES );
1632 TCollection_AsciiString aStudyName( "" );
1634 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
1636 // Set names of temporary files
1637 TCollection_AsciiString filename =
1638 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
1639 TCollection_AsciiString meshfile =
1640 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
1641 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
1642 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
1643 filename = tmpDir + filename;
1644 meshfile = tmpDir + meshfile;
1647 HDFdataset* aDataset;
1648 HDFgroup* aTopGroup;
1650 HDFgroup* aSubGroup;
1651 HDFgroup* aSubSubGroup;
1652 hdf_size aSize[ 1 ];
1655 //Remove the files if they exist: BugID: 11225
1656 #ifndef WNT /* unix functionality */
1657 TCollection_AsciiString cmd("rm -f \"");
1659 TCollection_AsciiString cmd("del /F \"");
1666 system(cmd.ToCString());
1668 // MED writer to be used by storage process
1669 DriverMED_W_SMESHDS_Mesh myWriter;
1670 myWriter.SetFile( meshfile.ToCString() );
1673 // ---> create HDF file
1674 aFile = new HDFfile( filename.ToCString() );
1675 aFile->CreateOnDisk();
1677 // --> iterator for top-level objects
1678 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
1679 for ( ; itBig->More(); itBig->Next() ) {
1680 SALOMEDS::SObject_var gotBranch = itBig->Value();
1682 // --> hypotheses root branch (only one for the study)
1683 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
1684 // create hypotheses root HDF group
1685 aTopGroup = new HDFgroup( "Hypotheses", aFile );
1686 aTopGroup->CreateOnDisk();
1688 // iterator for all hypotheses
1689 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1690 for ( ; it->More(); it->Next() ) {
1691 SALOMEDS::SObject_var mySObject = it->Value();
1692 CORBA::Object_var anObject = SObjectToObject( mySObject );
1693 if ( !CORBA::is_nil( anObject ) ) {
1694 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1695 if ( !myHyp->_is_nil() ) {
1696 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1698 string hypname = string( myHyp->GetName() );
1699 string libname = string( myHyp->GetLibName() );
1701 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1702 // WNT and ".so" for X-system) must be deleted
1703 int libname_len = libname.length();
1705 if( libname_len > 4 )
1706 libname.resize( libname_len - 4 );
1708 if( libname_len > 3 )
1709 libname.resize( libname_len - 3 );
1711 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1712 int id = myStudyContext->findId( string( objStr.in() ) );
1713 string hypdata = string( myImpl->SaveTo() );
1715 // for each hypothesis create HDF group basing on its id
1716 char hypGrpName[30];
1717 sprintf( hypGrpName, "Hypothesis %d", id );
1718 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1719 aGroup->CreateOnDisk();
1720 // --> type name of hypothesis
1721 aSize[ 0 ] = hypname.length() + 1;
1722 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1723 aDataset->CreateOnDisk();
1724 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1725 aDataset->CloseOnDisk();
1726 // --> server plugin library name of hypothesis
1727 aSize[ 0 ] = libname.length() + 1;
1728 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1729 aDataset->CreateOnDisk();
1730 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1731 aDataset->CloseOnDisk();
1732 // --> persistent data of hypothesis
1733 aSize[ 0 ] = hypdata.length() + 1;
1734 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1735 aDataset->CreateOnDisk();
1736 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1737 aDataset->CloseOnDisk();
1738 // close hypothesis HDF group
1739 aGroup->CloseOnDisk();
1744 // close hypotheses root HDF group
1745 aTopGroup->CloseOnDisk();
1747 // --> algorithms root branch (only one for the study)
1748 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1749 // create algorithms root HDF group
1750 aTopGroup = new HDFgroup( "Algorithms", aFile );
1751 aTopGroup->CreateOnDisk();
1753 // iterator for all algorithms
1754 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
1755 for ( ; it->More(); it->Next() ) {
1756 SALOMEDS::SObject_var mySObject = it->Value();
1757 CORBA::Object_var anObject = SObjectToObject( mySObject );
1758 if ( !CORBA::is_nil( anObject ) ) {
1759 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
1760 if ( !myHyp->_is_nil() ) {
1761 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
1763 string hypname = string( myHyp->GetName() );
1764 string libname = string( myHyp->GetLibName() );
1766 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
1767 // WNT and ".so" for X-system) must be deleted
1768 int libname_len = libname.length();
1770 if( libname_len > 4 )
1771 libname.resize( libname_len - 4 );
1773 if( libname_len > 3 )
1774 libname.resize( libname_len - 3 );
1776 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1777 int id = myStudyContext->findId( string( objStr.in() ) );
1778 string hypdata = string( myImpl->SaveTo() );
1780 // for each algorithm create HDF group basing on its id
1781 char hypGrpName[30];
1782 sprintf( hypGrpName, "Algorithm %d", id );
1783 aGroup = new HDFgroup( hypGrpName, aTopGroup );
1784 aGroup->CreateOnDisk();
1785 // --> type name of algorithm
1786 aSize[0] = hypname.length() + 1;
1787 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
1788 aDataset->CreateOnDisk();
1789 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
1790 aDataset->CloseOnDisk();
1791 // --> server plugin library name of hypothesis
1792 aSize[0] = libname.length() + 1;
1793 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
1794 aDataset->CreateOnDisk();
1795 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
1796 aDataset->CloseOnDisk();
1797 // --> persistent data of algorithm
1798 aSize[0] = hypdata.length() + 1;
1799 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
1800 aDataset->CreateOnDisk();
1801 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
1802 aDataset->CloseOnDisk();
1803 // close algorithm HDF group
1804 aGroup->CloseOnDisk();
1809 // close algorithms root HDF group
1810 aTopGroup->CloseOnDisk();
1812 // --> mesh objects roots branches
1813 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
1814 CORBA::Object_var anObject = SObjectToObject( gotBranch );
1815 if ( !CORBA::is_nil( anObject ) ) {
1816 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
1817 if ( !myMesh->_is_nil() ) {
1818 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
1820 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1821 int id = myStudyContext->findId( string( objStr.in() ) );
1822 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
1823 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
1824 bool hasShape = myLocMesh.HasShapeToMesh();
1826 // for each mesh open the HDF group basing on its id
1827 char meshGrpName[ 30 ];
1828 sprintf( meshGrpName, "Mesh %d", id );
1829 aTopGroup = new HDFgroup( meshGrpName, aFile );
1830 aTopGroup->CreateOnDisk();
1832 // --> put dataset to hdf file which is a flag that mesh has data
1833 string strHasData = "0";
1834 // check if the mesh is not empty
1835 if ( mySMESHDSMesh->NbNodes() > 0 ) {
1836 // write mesh data to med file
1837 myWriter.SetMesh( mySMESHDSMesh );
1838 myWriter.SetMeshId( id );
1841 aSize[ 0 ] = strHasData.length() + 1;
1842 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
1843 aDataset->CreateOnDisk();
1844 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
1845 aDataset->CloseOnDisk();
1848 // for each mesh open the HDF group basing on its auto color parameter
1849 char meshAutoColorName[ 30 ];
1850 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
1852 anAutoColor[0] = myImpl->GetAutoColor();
1854 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
1855 aDataset->CreateOnDisk();
1856 aDataset->WriteOnDisk( anAutoColor );
1857 aDataset->CloseOnDisk();
1859 // write reference on a shape if exists
1860 SALOMEDS::SObject_var myRef;
1861 bool shapeRefFound = false;
1862 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
1864 SALOMEDS::SObject_var myShape;
1865 bool ok = myRef->ReferencedObject( myShape );
1867 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
1868 string myRefOnObject = myShape->GetID();
1869 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
1870 aSize[ 0 ] = myRefOnObject.length() + 1;
1871 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
1872 aDataset->CreateOnDisk();
1873 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1874 aDataset->CloseOnDisk();
1879 // write applied hypotheses if exist
1880 SALOMEDS::SObject_var myHypBranch;
1881 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
1882 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
1883 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
1885 if ( found && (shapeRefFound || !hasShape) ) {
1886 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
1887 aGroup->CreateOnDisk();
1889 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
1891 for ( ; it->More(); it->Next() ) {
1892 SALOMEDS::SObject_var mySObject = it->Value();
1893 SALOMEDS::SObject_var myRefOnHyp;
1894 bool ok = mySObject->ReferencedObject( myRefOnHyp );
1896 // san - it is impossible to recover applied hypotheses
1897 // using their entries within Load() method,
1898 // for there are no AttributeIORs in the study when Load() is working.
1899 // Hence, it is better to store persistent IDs of hypotheses as references to them
1901 //string myRefOnObject = myRefOnHyp->GetID();
1902 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
1903 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1904 int id = myStudyContext->findId( string( objStr.in() ) );
1905 //if ( myRefOnObject.length() > 0 ) {
1906 //aSize[ 0 ] = myRefOnObject.length() + 1;
1907 char hypName[ 30 ], hypId[ 30 ];
1908 sprintf( hypName, "Hyp %d", ++hypNb );
1909 sprintf( hypId, "%d", id );
1910 aSize[ 0 ] = strlen( hypId ) + 1;
1911 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
1912 aDataset->CreateOnDisk();
1913 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1914 aDataset->WriteOnDisk( hypId );
1915 aDataset->CloseOnDisk();
1919 aGroup->CloseOnDisk();
1922 // write applied algorithms if exist
1923 SALOMEDS::SObject_var myAlgoBranch;
1924 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
1925 if ( found && !shapeRefFound && hasShape) { // remove applied algos
1926 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
1928 if ( found && (shapeRefFound || !hasShape)) {
1929 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
1930 aGroup->CreateOnDisk();
1932 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
1934 for ( ; it->More(); it->Next() ) {
1935 SALOMEDS::SObject_var mySObject = it->Value();
1936 SALOMEDS::SObject_var myRefOnAlgo;
1937 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
1939 // san - it is impossible to recover applied algorithms
1940 // using their entries within Load() method,
1941 // for there are no AttributeIORs in the study when Load() is working.
1942 // Hence, it is better to store persistent IDs of algorithms as references to them
1944 //string myRefOnObject = myRefOnAlgo->GetID();
1945 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
1946 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
1947 int id = myStudyContext->findId( string( objStr.in() ) );
1948 //if ( myRefOnObject.length() > 0 ) {
1949 //aSize[ 0 ] = myRefOnObject.length() + 1;
1950 char algoName[ 30 ], algoId[ 30 ];
1951 sprintf( algoName, "Algo %d", ++algoNb );
1952 sprintf( algoId, "%d", id );
1953 aSize[ 0 ] = strlen( algoId ) + 1;
1954 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
1955 aDataset->CreateOnDisk();
1956 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
1957 aDataset->WriteOnDisk( algoId );
1958 aDataset->CloseOnDisk();
1962 aGroup->CloseOnDisk();
1965 // --> submesh objects sub-branches
1967 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
1968 SALOMEDS::SObject_var mySubmeshBranch;
1969 found = gotBranch->FindSubObject( i, mySubmeshBranch );
1971 if ( found ) // check if there is shape reference in submeshes
1973 bool hasShapeRef = false;
1974 SALOMEDS::ChildIterator_var itSM =
1975 myCurrentStudy->NewChildIterator( mySubmeshBranch );
1976 for ( ; itSM->More(); itSM->Next() ) {
1977 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
1978 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
1979 mySubRef->ReferencedObject( myShape );
1980 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
1983 { // remove one submesh
1984 if ( shapeRefFound )
1985 { // unassign hypothesis
1986 SMESH::SMESH_subMesh_var mySubMesh =
1987 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
1988 if ( !mySubMesh->_is_nil() ) {
1989 int shapeID = mySubMesh->GetId();
1990 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
1991 const list<const SMESHDS_Hypothesis*>& hypList =
1992 mySMESHDSMesh->GetHypothesis( S );
1993 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
1994 while ( hyp != hypList.end() ) {
1995 int hypID = (*hyp++)->GetID(); // goto next hyp here because
1996 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
2000 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
2002 } // loop on submeshes of a type
2003 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
2004 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
2007 } // end check if there is shape reference in submeshes
2009 char name_meshgroup[ 30 ];
2010 if ( i == GetSubMeshOnVertexTag() )
2011 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2012 else if ( i == GetSubMeshOnEdgeTag() )
2013 strcpy( name_meshgroup, "SubMeshes On Edge" );
2014 else if ( i == GetSubMeshOnWireTag() )
2015 strcpy( name_meshgroup, "SubMeshes On Wire" );
2016 else if ( i == GetSubMeshOnFaceTag() )
2017 strcpy( name_meshgroup, "SubMeshes On Face" );
2018 else if ( i == GetSubMeshOnShellTag() )
2019 strcpy( name_meshgroup, "SubMeshes On Shell" );
2020 else if ( i == GetSubMeshOnSolidTag() )
2021 strcpy( name_meshgroup, "SubMeshes On Solid" );
2022 else if ( i == GetSubMeshOnCompoundTag() )
2023 strcpy( name_meshgroup, "SubMeshes On Compound" );
2025 // for each type of submeshes create container HDF group
2026 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2027 aGroup->CreateOnDisk();
2029 // iterator for all submeshes of given type
2030 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
2031 for ( ; itSM->More(); itSM->Next() ) {
2032 SALOMEDS::SObject_var mySObject = itSM->Value();
2033 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
2034 if ( !CORBA::is_nil( anSubObject ))
2036 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
2037 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
2038 int subid = myStudyContext->findId( string( objStr.in() ) );
2040 // for each mesh open the HDF group basing on its id
2041 char submeshGrpName[ 30 ];
2042 sprintf( submeshGrpName, "SubMesh %d", subid );
2043 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
2044 aSubGroup->CreateOnDisk();
2046 // write reference on a shape, already checked if it exists
2047 SALOMEDS::SObject_var mySubRef, myShape;
2048 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2049 mySubRef->ReferencedObject( myShape );
2050 string myRefOnObject = myShape->GetID();
2051 if ( myRefOnObject.length() > 0 ) {
2052 aSize[ 0 ] = myRefOnObject.length() + 1;
2053 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
2054 aDataset->CreateOnDisk();
2055 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2056 aDataset->CloseOnDisk();
2059 // write applied hypotheses if exist
2060 SALOMEDS::SObject_var mySubHypBranch;
2061 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
2063 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2064 aSubSubGroup->CreateOnDisk();
2066 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
2068 for ( ; it->More(); it->Next() ) {
2069 SALOMEDS::SObject_var mySubSObject = it->Value();
2070 SALOMEDS::SObject_var myRefOnHyp;
2071 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
2073 //string myRefOnObject = myRefOnHyp->GetID();
2074 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2075 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2076 int id = myStudyContext->findId( string( objStr.in() ) );
2077 //if ( myRefOnObject.length() > 0 ) {
2078 //aSize[ 0 ] = myRefOnObject.length() + 1;
2079 char hypName[ 30 ], hypId[ 30 ];
2080 sprintf( hypName, "Hyp %d", ++hypNb );
2081 sprintf( hypId, "%d", id );
2082 aSize[ 0 ] = strlen( hypId ) + 1;
2083 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
2084 aDataset->CreateOnDisk();
2085 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2086 aDataset->WriteOnDisk( hypId );
2087 aDataset->CloseOnDisk();
2091 aSubSubGroup->CloseOnDisk();
2094 // write applied algorithms if exist
2095 SALOMEDS::SObject_var mySubAlgoBranch;
2096 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
2098 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2099 aSubSubGroup->CreateOnDisk();
2101 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
2103 for ( ; it->More(); it->Next() ) {
2104 SALOMEDS::SObject_var mySubSObject = it->Value();
2105 SALOMEDS::SObject_var myRefOnAlgo;
2106 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
2108 //string myRefOnObject = myRefOnAlgo->GetID();
2109 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2110 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2111 int id = myStudyContext->findId( string( objStr.in() ) );
2112 //if ( myRefOnObject.length() > 0 ) {
2113 //aSize[ 0 ] = myRefOnObject.length() + 1;
2114 char algoName[ 30 ], algoId[ 30 ];
2115 sprintf( algoName, "Algo %d", ++algoNb );
2116 sprintf( algoId, "%d", id );
2117 aSize[ 0 ] = strlen( algoId ) + 1;
2118 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
2119 aDataset->CreateOnDisk();
2120 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2121 aDataset->WriteOnDisk( algoId );
2122 aDataset->CloseOnDisk();
2126 aSubSubGroup->CloseOnDisk();
2128 // close submesh HDF group
2129 aSubGroup->CloseOnDisk();
2132 // close container of submeshes by type HDF group
2133 aGroup->CloseOnDisk();
2136 // All sub-meshes will be stored in MED file
2137 // .. will NOT (PAL 12992)
2138 //if ( shapeRefFound )
2139 //myWriter.AddAllSubMeshes();
2141 // groups root sub-branch
2142 SALOMEDS::SObject_var myGroupsBranch;
2143 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
2144 found = gotBranch->FindSubObject( i, myGroupsBranch );
2146 char name_group[ 30 ];
2147 if ( i == GetNodeGroupsTag() )
2148 strcpy( name_group, "Groups of Nodes" );
2149 else if ( i == GetEdgeGroupsTag() )
2150 strcpy( name_group, "Groups of Edges" );
2151 else if ( i == GetFaceGroupsTag() )
2152 strcpy( name_group, "Groups of Faces" );
2153 else if ( i == GetVolumeGroupsTag() )
2154 strcpy( name_group, "Groups of Volumes" );
2156 aGroup = new HDFgroup( name_group, aTopGroup );
2157 aGroup->CreateOnDisk();
2159 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
2160 for ( ; it->More(); it->Next() ) {
2161 SALOMEDS::SObject_var mySObject = it->Value();
2162 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
2163 if ( !CORBA::is_nil( aSubObject ) ) {
2164 SMESH_GroupBase_i* myGroupImpl =
2165 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
2169 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
2170 int anId = myStudyContext->findId( string( objStr.in() ) );
2172 // For each group, create a dataset named "Group <group_persistent_id>"
2173 // and store the group's user name into it
2175 sprintf( grpName, "Group %d", anId );
2176 char* aUserName = myGroupImpl->GetName();
2177 aSize[ 0 ] = strlen( aUserName ) + 1;
2179 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
2180 aDataset->CreateOnDisk();
2181 aDataset->WriteOnDisk( aUserName );
2182 aDataset->CloseOnDisk();
2185 // For each group, create a dataset named "Group <group_persistent_id> Color"
2186 // and store the group's color into it
2187 char grpColorName[ 30 ];
2188 sprintf( grpColorName, "ColorGroup %d", anId );
2189 SALOMEDS::Color aColor = myGroupImpl->GetColor();
2191 anRGB[ 0 ] = aColor.R;
2192 anRGB[ 1 ] = aColor.G;
2193 anRGB[ 2 ] = aColor.B;
2195 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
2196 aDataset->CreateOnDisk();
2197 aDataset->WriteOnDisk( anRGB );
2198 aDataset->CloseOnDisk();
2200 // Store the group contents into MED file
2201 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
2203 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
2204 << grpName << " to MED file" );
2205 SMESHDS_GroupBase* aGrpBaseDS =
2206 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
2207 aGrpBaseDS->SetStoreName( grpName );
2209 // Pass SMESHDS_Group to MED writer
2210 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
2212 myWriter.AddGroup( aGrpDS );
2214 // write reference on a shape if exists
2215 SMESHDS_GroupOnGeom* aGeomGrp =
2216 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
2218 SALOMEDS::SObject_var mySubRef, myShape;
2219 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
2220 mySubRef->ReferencedObject( myShape ) &&
2221 !CORBA::is_nil( myShape->GetObject() ))
2223 string myRefOnObject = myShape->GetID();
2224 if ( myRefOnObject.length() > 0 ) {
2225 char aRefName[ 30 ];
2226 sprintf( aRefName, "Ref on shape %d", anId);
2227 aSize[ 0 ] = myRefOnObject.length() + 1;
2228 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
2229 aDataset->CreateOnDisk();
2230 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2231 aDataset->CloseOnDisk();
2234 else // shape ref is invalid:
2236 // save a group on geometry as ordinary group
2237 myWriter.AddGroup( aGeomGrp );
2243 aGroup->CloseOnDisk();
2247 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
2249 // Flush current mesh information into MED file
2252 // maybe a shape was deleted in the study
2253 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
2254 TopoDS_Shape nullShape;
2255 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
2258 if ( !mySMESHDSMesh->SubMeshes().empty() )
2262 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2263 aGroup->CreateOnDisk();
2265 // each element belongs to one or none submesh,
2266 // so for each node/element, we store a submesh ID
2268 // Make maps of submesh IDs of elements sorted by element IDs
2269 typedef int TElemID;
2270 typedef int TSubMID;
2271 map< TElemID, TSubMID > eId2smId, nId2smId;
2272 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
2273 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
2274 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
2275 SMDS_NodeIteratorPtr itNode;
2276 SMDS_ElemIteratorPtr itElem;
2277 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2279 TSubMID aSubMeID = itSubM->first;
2280 SMESHDS_SubMesh* aSubMesh = itSubM->second;
2281 if ( aSubMesh->IsComplexSubmesh() )
2282 continue; // submesh containing other submeshs
2284 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
2285 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
2286 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
2288 hint = eId2smId.begin();
2289 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
2290 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
2293 // Care of elements that are not on submeshes
2294 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
2295 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
2296 /* --- stl_map.h says : */
2297 /* A %map relies on unique keys and thus a %pair is only inserted if its */
2298 /* first element (the key) is not already present in the %map. */
2299 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
2301 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
2302 if ( nbElems != eId2smId.size() ) {
2303 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
2304 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
2307 // Store submesh IDs
2308 for ( int isNode = 0; isNode < 2; ++isNode )
2310 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
2311 if ( id2smId.empty() ) continue;
2312 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
2313 // make and fill array of submesh IDs
2314 int* smIDs = new int [ id2smId.size() ];
2315 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
2316 smIDs[ i ] = id_smId->second;
2318 aSize[ 0 ] = id2smId.size();
2319 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2320 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2321 aDataset->CreateOnDisk();
2322 aDataset->WriteOnDisk( smIDs );
2323 aDataset->CloseOnDisk();
2328 // Store node positions on sub-shapes (SMDS_Position):
2329 // ----------------------------------------------------
2331 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2332 aGroup->CreateOnDisk();
2334 // in aGroup, create 5 datasets to contain:
2335 // "Nodes on Edges" - ID of node on edge
2336 // "Edge positions" - U parameter on node on edge
2337 // "Nodes on Faces" - ID of node on face
2338 // "Face U positions" - U parameter of node on face
2339 // "Face V positions" - V parameter of node on face
2341 // Find out nb of nodes on edges and faces
2342 // Collect corresponing sub-meshes
2343 int nbEdgeNodes = 0, nbFaceNodes = 0;
2344 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
2345 // loop on SMESHDS_SubMesh'es
2346 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2348 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
2349 if ( aSubMesh->IsComplexSubmesh() )
2350 continue; // submesh containing other submeshs
2351 int nbNodes = aSubMesh->NbNodes();
2352 if ( nbNodes == 0 ) continue;
2354 int aShapeID = (*itSubM).first;
2355 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
2356 // write only SMDS_FacePosition and SMDS_EdgePosition
2357 switch ( aShapeType ) {
2359 nbFaceNodes += nbNodes;
2360 aFaceSM.push_back( aSubMesh );
2363 nbEdgeNodes += nbNodes;
2364 aEdgeSM.push_back( aSubMesh );
2370 // Treat positions on edges or faces
2371 for ( int onFace = 0; onFace < 2; onFace++ )
2373 // Create arrays to store in datasets
2374 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
2375 if (!nbNodes) continue;
2376 int* aNodeIDs = new int [ nbNodes ];
2377 double* aUPos = new double [ nbNodes ];
2378 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
2381 // loop on sub-meshes
2382 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
2383 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
2384 for ( ; itSM != pListSM->end(); itSM++ )
2386 SMESHDS_SubMesh* aSubMesh = (*itSM);
2388 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
2389 // loop on nodes in aSubMesh
2390 while ( itNode->more() )
2393 const SMDS_MeshNode* node = itNode->next();
2394 aNodeIDs [ iNode ] = node->GetID();
2397 const SMDS_PositionPtr pos = node->GetPosition();
2398 if ( onFace ) { // on FACE
2399 const SMDS_FacePosition* fPos =
2400 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
2402 aUPos[ iNode ] = fPos->GetUParameter();
2403 aVPos[ iNode ] = fPos->GetVParameter();
2410 const SMDS_EdgePosition* ePos =
2411 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
2413 aUPos[ iNode ] = ePos->GetUParameter();
2419 } // loop on nodes in aSubMesh
2420 } // loop on sub-meshes
2425 aSize[ 0 ] = nbNodes;
2427 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
2428 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2429 aDataset->CreateOnDisk();
2430 aDataset->WriteOnDisk( aNodeIDs );
2431 aDataset->CloseOnDisk();
2434 aDSName = ( onFace ? "Face U positions" : "Edge positions");
2435 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
2436 aDataset->CreateOnDisk();
2437 aDataset->WriteOnDisk( aUPos );
2438 aDataset->CloseOnDisk();
2441 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
2442 aDataset->CreateOnDisk();
2443 aDataset->WriteOnDisk( aVPos );
2444 aDataset->CloseOnDisk();
2449 if ( aVPos ) delete [] aVPos;
2451 } // treat positions on edges or faces
2453 // close "Node Positions" group
2454 aGroup->CloseOnDisk();
2456 } // if ( there are submeshes in SMESHDS_Mesh )
2459 // close mesh HDF group
2460 aTopGroup->CloseOnDisk();
2468 aFile->CloseOnDisk();
2471 // Convert temporary files to stream
2472 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
2474 // Remove temporary files and directory
2476 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
2478 INFOS( "SMESH_Gen_i::Save() completed" );
2479 return aStreamFile._retn();
2482 //=============================================================================
2484 * SMESH_Gen_i::SaveASCII
2486 * Save SMESH module's data in ASCII format
2488 //=============================================================================
2490 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
2492 bool isMultiFile ) {
2493 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
2494 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
2495 return aStreamFile._retn();
2497 //after usual saving needs to encipher binary to text string
2498 //Any binary symbol will be represent as "|xx" () hexadecimal format number
2499 int size = aStreamFile.in().length();
2500 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
2501 for ( int i = 0; i < size; i++ )
2502 sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
2504 buffer[size * 3] = '\0';
2506 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
2508 return anAsciiStreamFile._retn();
2511 //=============================================================================
2513 * SMESH_Gen_i::loadGeomData
2515 * Load GEOM module data
2517 //=============================================================================
2519 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
2521 if ( theCompRoot->_is_nil() )
2524 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
2525 if ( aStudy->_is_nil() )
2528 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
2529 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
2531 //=============================================================================
2533 * \brief Creates SMDS_Position according to shape type
2535 //=============================================================================
2537 class PositionCreator {
2539 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
2540 return (this->*myFuncTable[ type ])();
2543 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
2544 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
2545 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
2546 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
2549 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
2550 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
2551 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
2552 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
2553 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
2554 vector<FmakePos> myFuncTable;
2557 //=============================================================================
2561 * Load SMESH module's data
2563 //=============================================================================
2565 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
2566 const SALOMEDS::TMPFile& theStream,
2570 INFOS( "SMESH_Gen_i::Load" );
2572 if ( myCurrentStudy->_is_nil() ||
2573 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2574 SetCurrentStudy( theComponent->GetStudy() );
2576 /* if( !theComponent->_is_nil() )
2578 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
2579 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
2580 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
2583 StudyContext* myStudyContext = GetCurrentStudyContext();
2585 // Get temporary files location
2586 TCollection_AsciiString tmpDir =
2587 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2589 INFOS( "THE URL++++++++++++++" )
2591 INFOS( "THE TMP PATH+++++++++" );
2594 // Convert the stream into sequence of files to process
2595 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
2598 TCollection_AsciiString aStudyName( "" );
2600 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2602 // Set names of temporary files
2603 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
2604 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
2608 HDFdataset* aDataset;
2609 HDFgroup* aTopGroup;
2611 HDFgroup* aSubGroup;
2612 HDFgroup* aSubSubGroup;
2615 // ---> open HDF file
2616 aFile = new HDFfile( filename.ToCString() );
2618 aFile->OpenOnDisk( HDF_RDONLY );
2620 catch ( HDFexception ) {
2621 INFOS( "Load(): " << filename << " not found!" );
2625 DriverMED_R_SMESHDS_Mesh myReader;
2626 myReader.SetFile( meshfile.ToCString() );
2628 // For PAL13473 ("Repetitive mesh") implementation.
2629 // New dependencies between SMESH objects are established:
2630 // now hypotheses can refer to meshes, shapes and other hypotheses.
2631 // To keep data consistent, the following order of data restoration
2633 // 1. Create hypotheses
2634 // 2. Create all meshes
2635 // 3. Load hypotheses' data
2638 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
2639 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
2641 // get total number of top-level groups
2642 int aNbGroups = aFile->nInternalObjects();
2643 if ( aNbGroups > 0 ) {
2644 // --> in first turn we should read&create hypotheses
2645 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
2646 // open hypotheses root HDF group
2647 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2648 aTopGroup->OpenOnDisk();
2650 // get number of hypotheses
2651 int aNbObjects = aTopGroup->nInternalObjects();
2652 for ( int j = 0; j < aNbObjects; j++ ) {
2653 // try to identify hypothesis
2654 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2655 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2657 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
2658 // open hypothesis group
2659 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2660 aGroup->OpenOnDisk();
2662 // --> get hypothesis id
2663 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
2668 // get number of datasets
2669 int aNbSubObjects = aGroup->nInternalObjects();
2670 for ( int k = 0; k < aNbSubObjects; k++ ) {
2672 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2673 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2674 // --> get hypothesis name
2675 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2676 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2677 aDataset->OpenOnDisk();
2678 size = aDataset->GetSize();
2679 char* hypname_str = new char[ size ];
2680 aDataset->ReadFromDisk( hypname_str );
2681 hypname = string( hypname_str );
2682 delete [] hypname_str;
2683 aDataset->CloseOnDisk();
2685 // --> get hypothesis plugin library name
2686 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2687 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2688 aDataset->OpenOnDisk();
2689 size = aDataset->GetSize();
2690 char* libname_str = new char[ size ];
2691 aDataset->ReadFromDisk( libname_str );
2692 if(MYDEBUG) SCRUTE( libname_str );
2693 libname = string( libname_str );
2694 delete [] libname_str;
2695 aDataset->CloseOnDisk();
2697 // --> get hypothesis data
2698 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2699 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2700 aDataset->OpenOnDisk();
2701 size = aDataset->GetSize();
2702 char* hypdata_str = new char[ size ];
2703 aDataset->ReadFromDisk( hypdata_str );
2704 hypdata = string( hypdata_str );
2705 delete [] hypdata_str;
2706 aDataset->CloseOnDisk();
2709 // close hypothesis HDF group
2710 aGroup->CloseOnDisk();
2712 // --> restore hypothesis from data
2713 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2714 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
2715 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2716 SMESH::SMESH_Hypothesis_var myHyp;
2718 try { // protect persistence mechanism against exceptions
2719 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2722 INFOS( "Exception during hypothesis creation" );
2725 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2727 // myImpl->LoadFrom( hypdata.c_str() );
2728 hypDataList.push_back( make_pair( myImpl, hypdata ));
2729 string iorString = GetORB()->object_to_string( myHyp );
2730 int newId = myStudyContext->findId( iorString );
2731 myStudyContext->mapOldToNew( id, newId );
2734 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2738 // close hypotheses root HDF group
2739 aTopGroup->CloseOnDisk();
2743 // --> then we should read&create algorithms
2744 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
2745 // open algorithms root HDF group
2746 aTopGroup = new HDFgroup( "Algorithms", aFile );
2747 aTopGroup->OpenOnDisk();
2749 // get number of algorithms
2750 int aNbObjects = aTopGroup->nInternalObjects();
2751 for ( int j = 0; j < aNbObjects; j++ ) {
2752 // try to identify algorithm
2753 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
2754 aTopGroup->InternalObjectIndentify( j, hypGrpName );
2756 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
2757 // open algorithm group
2758 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2759 aGroup->OpenOnDisk();
2761 // --> get algorithm id
2762 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
2767 // get number of datasets
2768 int aNbSubObjects = aGroup->nInternalObjects();
2769 for ( int k = 0; k < aNbSubObjects; k++ ) {
2771 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
2772 aGroup->InternalObjectIndentify( k, name_of_subgroup );
2773 // --> get algorithm name
2774 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
2775 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2776 aDataset->OpenOnDisk();
2777 size = aDataset->GetSize();
2778 char* hypname_str = new char[ size ];
2779 aDataset->ReadFromDisk( hypname_str );
2780 hypname = string( hypname_str );
2781 delete [] hypname_str;
2782 aDataset->CloseOnDisk();
2784 // --> get algorithm plugin library name
2785 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
2786 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2787 aDataset->OpenOnDisk();
2788 size = aDataset->GetSize();
2789 char* libname_str = new char[ size ];
2790 aDataset->ReadFromDisk( libname_str );
2791 if(MYDEBUG) SCRUTE( libname_str );
2792 libname = string( libname_str );
2793 delete [] libname_str;
2794 aDataset->CloseOnDisk();
2796 // --> get algorithm data
2797 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
2798 aDataset = new HDFdataset( name_of_subgroup, aGroup );
2799 aDataset->OpenOnDisk();
2800 size = aDataset->GetSize();
2801 char* hypdata_str = new char[ size ];
2802 aDataset->ReadFromDisk( hypdata_str );
2803 if(MYDEBUG) SCRUTE( hypdata_str );
2804 hypdata = string( hypdata_str );
2805 delete [] hypdata_str;
2806 aDataset->CloseOnDisk();
2809 // close algorithm HDF group
2810 aGroup->CloseOnDisk();
2812 // --> restore algorithm from data
2813 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
2814 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
2815 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
2816 SMESH::SMESH_Hypothesis_var myHyp;
2818 try { // protect persistence mechanism against exceptions
2819 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
2822 INFOS( "Exception during hypothesis creation" );
2825 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2827 //myImpl->LoadFrom( hypdata.c_str() );
2828 hypDataList.push_back( make_pair( myImpl, hypdata ));
2829 string iorString = GetORB()->object_to_string( myHyp );
2830 int newId = myStudyContext->findId( iorString );
2831 myStudyContext->mapOldToNew( id, newId );
2834 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
2838 // close algorithms root HDF group
2839 aTopGroup->CloseOnDisk();
2843 // --> the rest groups should be meshes
2844 for ( int i = 0; i < aNbGroups; i++ ) {
2845 // identify next group
2846 char meshName[ HDF_NAME_MAX_LEN+1 ];
2847 aFile->InternalObjectIndentify( i, meshName );
2849 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
2851 int id = atoi( string( meshName ).substr( 4 ).c_str() );
2855 // open mesh HDF group
2856 aTopGroup = new HDFgroup( meshName, aFile );
2857 aTopGroup->OpenOnDisk();
2859 // get number of child HDF objects
2860 int aNbObjects = aTopGroup->nInternalObjects();
2861 if ( aNbObjects > 0 ) {
2863 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
2864 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
2865 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
2866 if ( !myNewMeshImpl )
2868 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
2870 string iorString = GetORB()->object_to_string( myNewMesh );
2871 int newId = myStudyContext->findId( iorString );
2872 myStudyContext->mapOldToNew( id, newId );
2875 // try to read and set auto color flag
2876 char aMeshAutoColorName[ 30 ];
2877 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
2878 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
2880 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
2881 aDataset->OpenOnDisk();
2882 size = aDataset->GetSize();
2883 int* anAutoColor = new int[ size ];
2884 aDataset->ReadFromDisk( anAutoColor );
2885 aDataset->CloseOnDisk();
2886 myNewMeshImpl->SetAutoColor( (bool)anAutoColor[0] );
2889 // try to read and set reference to shape
2890 GEOM::GEOM_Object_var aShapeObject;
2891 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
2892 // load mesh "Ref on shape" - it's an entry to SObject
2893 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
2894 aDataset->OpenOnDisk();
2895 size = aDataset->GetSize();
2896 char* refFromFile = new char[ size ];
2897 aDataset->ReadFromDisk( refFromFile );
2898 aDataset->CloseOnDisk();
2899 if ( strlen( refFromFile ) > 0 ) {
2900 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
2902 // Make sure GEOM data are loaded first
2903 //loadGeomData( shapeSO->GetFatherComponent() );
2905 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
2906 if ( !CORBA::is_nil( shapeObject ) ) {
2907 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
2908 if ( !aShapeObject->_is_nil() )
2909 myNewMeshImpl->SetShape( aShapeObject );
2918 // As all object that can be referred by hypothesis are created,
2919 // we can restore hypothesis data
2921 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
2922 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
2924 SMESH_Hypothesis_i* hyp = hyp_data->first;
2925 string & data = hyp_data->second;
2926 hyp->LoadFrom( data.c_str() );
2929 // Restore the rest mesh data
2931 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
2932 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
2934 aTopGroup = meshi_group->second;
2935 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
2936 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
2937 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2939 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
2940 bool hasData = false;
2943 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
2944 int newId = myStudyContext->findId( iorString );
2945 int id = myStudyContext->getOldId( newId );
2947 // try to find mesh data dataset
2948 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
2949 // load mesh "has data" flag
2950 aDataset = new HDFdataset( "Has data", aTopGroup );
2951 aDataset->OpenOnDisk();
2952 size = aDataset->GetSize();
2953 char* strHasData = new char[ size ];
2954 aDataset->ReadFromDisk( strHasData );
2955 aDataset->CloseOnDisk();
2956 if ( strcmp( strHasData, "1") == 0 ) {
2957 // read mesh data from MED file
2958 myReader.SetMesh( mySMESHDSMesh );
2959 myReader.SetMeshId( id );
2965 // try to get applied algorithms
2966 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
2967 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2968 aGroup->OpenOnDisk();
2969 // get number of applied algorithms
2970 int aNbSubObjects = aGroup->nInternalObjects();
2971 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
2972 for ( int j = 0; j < aNbSubObjects; j++ ) {
2973 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
2974 aGroup->InternalObjectIndentify( j, name_dataset );
2975 // check if it is an algorithm
2976 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
2977 aDataset = new HDFdataset( name_dataset, aGroup );
2978 aDataset->OpenOnDisk();
2979 size = aDataset->GetSize();
2980 char* refFromFile = new char[ size ];
2981 aDataset->ReadFromDisk( refFromFile );
2982 aDataset->CloseOnDisk();
2984 // san - it is impossible to recover applied algorithms using their entries within Load() method
2986 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
2987 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
2988 int id = atoi( refFromFile );
2989 string anIOR = myStudyContext->getIORbyOldId( id );
2990 if ( !anIOR.empty() ) {
2991 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
2992 if ( !CORBA::is_nil( hypObject ) ) {
2993 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
2994 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
2995 || !myNewMeshImpl->HasShapeToMesh()) )
2996 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3001 aGroup->CloseOnDisk();
3004 // try to get applied hypotheses
3005 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3006 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3007 aGroup->OpenOnDisk();
3008 // get number of applied hypotheses
3009 int aNbSubObjects = aGroup->nInternalObjects();
3010 for ( int j = 0; j < aNbSubObjects; j++ ) {
3011 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3012 aGroup->InternalObjectIndentify( j, name_dataset );
3013 // check if it is a hypothesis
3014 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3015 aDataset = new HDFdataset( name_dataset, aGroup );
3016 aDataset->OpenOnDisk();
3017 size = aDataset->GetSize();
3018 char* refFromFile = new char[ size ];
3019 aDataset->ReadFromDisk( refFromFile );
3020 aDataset->CloseOnDisk();
3022 // san - it is impossible to recover applied hypotheses using their entries within Load() method
3024 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3025 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3026 int id = atoi( refFromFile );
3027 string anIOR = myStudyContext->getIORbyOldId( id );
3028 if ( !anIOR.empty() ) {
3029 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3030 if ( !CORBA::is_nil( hypObject ) ) {
3031 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3032 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3033 || !myNewMeshImpl->HasShapeToMesh()) )
3034 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3039 aGroup->CloseOnDisk();
3042 // --> try to find submeshes containers for each type of submesh
3043 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
3044 char name_meshgroup[ 30 ];
3045 if ( j == GetSubMeshOnVertexTag() )
3046 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3047 else if ( j == GetSubMeshOnEdgeTag() )
3048 strcpy( name_meshgroup, "SubMeshes On Edge" );
3049 else if ( j == GetSubMeshOnWireTag() )
3050 strcpy( name_meshgroup, "SubMeshes On Wire" );
3051 else if ( j == GetSubMeshOnFaceTag() )
3052 strcpy( name_meshgroup, "SubMeshes On Face" );
3053 else if ( j == GetSubMeshOnShellTag() )
3054 strcpy( name_meshgroup, "SubMeshes On Shell" );
3055 else if ( j == GetSubMeshOnSolidTag() )
3056 strcpy( name_meshgroup, "SubMeshes On Solid" );
3057 else if ( j == GetSubMeshOnCompoundTag() )
3058 strcpy( name_meshgroup, "SubMeshes On Compound" );
3060 // try to get submeshes container HDF group
3061 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
3062 // open submeshes containers HDF group
3063 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3064 aGroup->OpenOnDisk();
3066 // get number of submeshes
3067 int aNbSubMeshes = aGroup->nInternalObjects();
3068 for ( int k = 0; k < aNbSubMeshes; k++ ) {
3070 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
3071 aGroup->InternalObjectIndentify( k, name_submeshgroup );
3072 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
3073 // --> get submesh id
3074 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
3077 // open submesh HDF group
3078 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
3079 aSubGroup->OpenOnDisk();
3081 // try to read and set reference to subshape
3082 GEOM::GEOM_Object_var aSubShapeObject;
3083 SMESH::SMESH_subMesh_var aSubMesh;
3085 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
3086 // load submesh "Ref on shape" - it's an entry to SObject
3087 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
3088 aDataset->OpenOnDisk();
3089 size = aDataset->GetSize();
3090 char* refFromFile = new char[ size ];
3091 aDataset->ReadFromDisk( refFromFile );
3092 aDataset->CloseOnDisk();
3093 if ( strlen( refFromFile ) > 0 ) {
3094 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
3095 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
3096 if ( !CORBA::is_nil( subShapeObject ) ) {
3097 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
3098 if ( !aSubShapeObject->_is_nil() )
3099 aSubMesh = SMESH::SMESH_subMesh::_duplicate
3100 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
3101 if ( aSubMesh->_is_nil() )
3103 string iorSubString = GetORB()->object_to_string( aSubMesh );
3104 int newSubId = myStudyContext->findId( iorSubString );
3105 myStudyContext->mapOldToNew( subid, newSubId );
3110 if ( aSubMesh->_is_nil() )
3113 // VSR: Get submesh data from MED convertor
3114 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
3115 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
3116 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
3117 // subid << " for subshape # " << anInternalSubmeshId);
3118 // SMESHDS_SubMesh* aSubMeshDS =
3119 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
3120 // if ( !aSubMeshDS ) {
3121 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
3122 // anInternalSubmeshId << " in current mesh!");
3125 // myReader.GetSubMesh( aSubMeshDS, subid );
3128 // try to get applied algorithms
3129 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3130 // open "applied algorithms" HDF group
3131 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3132 aSubSubGroup->OpenOnDisk();
3133 // get number of applied algorithms
3134 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3135 for ( int l = 0; l < aNbSubObjects; l++ ) {
3136 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3137 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3138 // check if it is an algorithm
3139 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3140 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3141 aDataset->OpenOnDisk();
3142 size = aDataset->GetSize();
3143 char* refFromFile = new char[ size ];
3144 aDataset->ReadFromDisk( refFromFile );
3145 aDataset->CloseOnDisk();
3147 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3148 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3149 int id = atoi( refFromFile );
3150 string anIOR = myStudyContext->getIORbyOldId( id );
3151 if ( !anIOR.empty() ) {
3152 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3153 if ( !CORBA::is_nil( hypObject ) ) {
3154 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3155 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3156 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3161 // close "applied algorithms" HDF group
3162 aSubSubGroup->CloseOnDisk();
3165 // try to get applied hypotheses
3166 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3167 // open "applied hypotheses" HDF group
3168 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3169 aSubSubGroup->OpenOnDisk();
3170 // get number of applied hypotheses
3171 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3172 for ( int l = 0; l < aNbSubObjects; l++ ) {
3173 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3174 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3175 // check if it is a hypothesis
3176 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3177 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3178 aDataset->OpenOnDisk();
3179 size = aDataset->GetSize();
3180 char* refFromFile = new char[ size ];
3181 aDataset->ReadFromDisk( refFromFile );
3182 aDataset->CloseOnDisk();
3184 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3185 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3186 int id = atoi( refFromFile );
3187 string anIOR = myStudyContext->getIORbyOldId( id );
3188 if ( !anIOR.empty() ) {
3189 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3190 if ( !CORBA::is_nil( hypObject ) ) {
3191 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3192 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3193 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3198 // close "applied hypotheses" HDF group
3199 aSubSubGroup->CloseOnDisk();
3202 // close submesh HDF group
3203 aSubGroup->CloseOnDisk();
3206 // close submeshes containers HDF group
3207 aGroup->CloseOnDisk();
3213 // Read sub-meshes from MED
3214 // -------------------------
3215 if(MYDEBUG) MESSAGE("Create all sub-meshes");
3216 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
3217 if ( submeshesInFamilies )
3219 // old way working before fix of PAL 12992
3220 myReader.CreateAllSubMeshes();
3225 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3226 aGroup->OpenOnDisk();
3228 int maxID = mySMESHDSMesh->MaxShapeIndex();
3229 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
3230 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
3232 PositionCreator aPositionCreator;
3234 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
3235 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
3236 for ( int isNode = 0; isNode < 2; ++isNode )
3238 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3239 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
3241 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
3242 aDataset->OpenOnDisk();
3243 // read submesh IDs for all elements sorted by ID
3244 int nbElems = aDataset->GetSize();
3245 int* smIDs = new int [ nbElems ];
3246 aDataset->ReadFromDisk( smIDs );
3247 aDataset->CloseOnDisk();
3249 // get elements sorted by ID
3250 TIDSortedElemSet elemSet;
3252 while ( nIt->more() ) elemSet.insert( nIt->next() );
3254 while ( eIt->more() ) elemSet.insert( eIt->next() );
3255 ASSERT( elemSet.size() == nbElems );
3257 // add elements to submeshes
3258 TIDSortedElemSet::iterator iE = elemSet.begin();
3259 for ( int i = 0; i < nbElems; ++i, ++iE )
3261 int smID = smIDs[ i ];
3262 if ( smID == 0 ) continue;
3263 ASSERT( smID <= maxID );
3264 const SMDS_MeshElement* elem = *iE;
3265 // get or create submesh
3266 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
3268 sm = mySMESHDSMesh->NewSubMesh( smID );
3269 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
3273 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
3274 pos->SetShapeId( smID );
3275 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
3276 node->SetPosition( pos );
3277 sm->AddNode( node );
3279 sm->AddElement( elem );
3285 } // end reading submeshes
3287 // Read node positions on sub-shapes (SMDS_Position)
3289 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
3291 // There are 5 datasets to read:
3292 // "Nodes on Edges" - ID of node on edge
3293 // "Edge positions" - U parameter on node on edge
3294 // "Nodes on Faces" - ID of node on face
3295 // "Face U positions" - U parameter of node on face
3296 // "Face V positions" - V parameter of node on face
3297 char* aEid_DSName = "Nodes on Edges";
3298 char* aEu_DSName = "Edge positions";
3299 char* aFu_DSName = "Face U positions";
3300 //char* aFid_DSName = "Nodes on Faces";
3301 //char* aFv_DSName = "Face V positions";
3304 int nbEids = 0, nbFids = 0;
3305 int *aEids = 0, *aFids = 0;
3306 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
3309 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3310 aGroup->OpenOnDisk();
3312 // loop on 5 data sets
3313 int aNbObjects = aGroup->nInternalObjects();
3314 for ( int i = 0; i < aNbObjects; i++ )
3317 char aDSName[ HDF_NAME_MAX_LEN+1 ];
3318 aGroup->InternalObjectIndentify( i, aDSName );
3320 aDataset = new HDFdataset( aDSName, aGroup );
3321 aDataset->OpenOnDisk();
3322 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
3324 double* pos = new double [ aDataset->GetSize() ];
3325 aDataset->ReadFromDisk( pos );
3327 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
3329 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
3336 int aSize = aDataset->GetSize();
3338 // for reading files, created from 18.07.2005 till 10.10.2005
3339 if (aDataset->GetType() == HDF_STRING)
3340 aSize /= sizeof(int);
3342 int* ids = new int [aSize];
3343 aDataset->ReadFromDisk( ids );
3344 // on face or nodes?
3345 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
3354 aDataset->CloseOnDisk();
3355 } // loop on 5 datasets
3357 // Set node positions on edges or faces
3358 for ( int onFace = 0; onFace < 2; onFace++ )
3360 int nbNodes = ( onFace ? nbFids : nbEids );
3361 if ( nbNodes == 0 ) continue;
3362 int* aNodeIDs = ( onFace ? aFids : aEids );
3363 double* aUPos = ( onFace ? aFupos : aEpos );
3364 double* aVPos = ( onFace ? aFvpos : 0 );
3366 for ( int iNode = 0; iNode < nbNodes; iNode++ )
3368 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
3370 SMDS_PositionPtr aPos = node->GetPosition();
3373 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );
3374 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
3375 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
3376 fPos->SetUParameter( aUPos[ iNode ]);
3377 fPos->SetVParameter( aVPos[ iNode ]);
3380 ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );
3381 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
3382 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
3383 fPos->SetUParameter( aUPos[ iNode ]);
3387 if ( aEids ) delete [] aEids;
3388 if ( aFids ) delete [] aFids;
3389 if ( aEpos ) delete [] aEpos;
3390 if ( aFupos ) delete [] aFupos;
3391 if ( aFvpos ) delete [] aFvpos;
3393 aGroup->CloseOnDisk();
3395 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
3398 // Recompute State (as computed sub-meshes are restored from MED)
3399 if ( !aShapeObject->_is_nil() || !myNewMeshImpl->HasShapeToMesh()) {
3400 MESSAGE("Compute State Engine ...");
3401 TopoDS_Shape myLocShape;
3402 if(myNewMeshImpl->HasShapeToMesh())
3403 myLocShape = GeomObjectToShape( aShapeObject );
3405 myLocShape = SMESH_Mesh::PseudoShape();
3407 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
3408 (SMESH_subMesh::SUBMESH_RESTORED);
3409 MESSAGE("Compute State Engine finished");
3412 // try to get groups
3413 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
3414 char name_group[ 30 ];
3415 if ( ii == GetNodeGroupsTag() )
3416 strcpy( name_group, "Groups of Nodes" );
3417 else if ( ii == GetEdgeGroupsTag() )
3418 strcpy( name_group, "Groups of Edges" );
3419 else if ( ii == GetFaceGroupsTag() )
3420 strcpy( name_group, "Groups of Faces" );
3421 else if ( ii == GetVolumeGroupsTag() )
3422 strcpy( name_group, "Groups of Volumes" );
3424 if ( aTopGroup->ExistInternalObject( name_group ) ) {
3425 aGroup = new HDFgroup( name_group, aTopGroup );
3426 aGroup->OpenOnDisk();
3427 // get number of groups
3428 int aNbSubObjects = aGroup->nInternalObjects();
3429 for ( int j = 0; j < aNbSubObjects; j++ ) {
3430 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3431 aGroup->InternalObjectIndentify( j, name_dataset );
3432 // check if it is an group
3433 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
3435 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
3438 aDataset = new HDFdataset( name_dataset, aGroup );
3439 aDataset->OpenOnDisk();
3441 // Retrieve actual group name
3442 size = aDataset->GetSize();
3443 char* nameFromFile = new char[ size ];
3444 aDataset->ReadFromDisk( nameFromFile );
3445 aDataset->CloseOnDisk();
3447 // Try to find a shape reference
3448 TopoDS_Shape aShape;
3449 char aRefName[ 30 ];
3450 sprintf( aRefName, "Ref on shape %d", subid);
3451 if ( aGroup->ExistInternalObject( aRefName ) ) {
3452 // load mesh "Ref on shape" - it's an entry to SObject
3453 aDataset = new HDFdataset( aRefName, aGroup );
3454 aDataset->OpenOnDisk();
3455 size = aDataset->GetSize();
3456 char* refFromFile = new char[ size ];
3457 aDataset->ReadFromDisk( refFromFile );
3458 aDataset->CloseOnDisk();
3459 if ( strlen( refFromFile ) > 0 ) {
3460 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3461 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3462 if ( !CORBA::is_nil( shapeObject ) ) {
3463 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3464 if ( !aShapeObject->_is_nil() )
3465 aShape = GeomObjectToShape( aShapeObject );
3469 // Create group servant
3470 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
3471 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
3472 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
3473 // Obtain a SMESHDS_Group object
3474 if ( aNewGroup->_is_nil() )
3477 string iorSubString = GetORB()->object_to_string( aNewGroup );
3478 int newSubId = myStudyContext->findId( iorSubString );
3479 myStudyContext->mapOldToNew( subid, newSubId );
3481 SMESH_GroupBase_i* aGroupImpl =
3482 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
3486 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
3490 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
3491 aGroupBaseDS->SetStoreName( name_dataset );
3494 // Read color of the group
3495 char aGroupColorName[ 30 ];
3496 sprintf( aGroupColorName, "ColorGroup %d", subid);
3497 if ( aGroup->ExistInternalObject( aGroupColorName ) )
3499 aDataset = new HDFdataset( aGroupColorName, aGroup );
3500 aDataset->OpenOnDisk();
3501 size = aDataset->GetSize();
3502 double* anRGB = new double[ size ];
3503 aDataset->ReadFromDisk( anRGB );
3504 aDataset->CloseOnDisk();
3505 SALOMEDS::Color aColor;
3506 aColor.R = anRGB[0];
3507 aColor.G = anRGB[1];
3508 aColor.B = anRGB[2];
3509 aGroupBaseDS->SetColor( aColor );
3512 // Fill group with contents from MED file
3513 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
3515 myReader.GetGroup( aGrp );
3518 aGroup->CloseOnDisk();
3524 aTopGroup->CloseOnDisk();
3527 aFile->CloseOnDisk();
3530 // Remove temporary files created from the stream
3532 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3534 INFOS( "SMESH_Gen_i::Load completed" );
3538 //=============================================================================
3540 * SMESH_Gen_i::LoadASCII
3542 * Load SMESH module's data in ASCII format
3544 //=============================================================================
3546 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
3547 const SALOMEDS::TMPFile& theStream,
3549 bool isMultiFile ) {
3550 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
3551 return Load( theComponent, theStream, theURL, isMultiFile );
3553 //before call main ::Load method it's need for decipher text format to
3554 //binary ( "|xx" => x' )
3555 int size = theStream.length();
3556 if ( int((size / 3 )*3) != size ) //error size of buffer
3559 int real_size = int(size / 3);
3561 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
3565 for ( int i = 0; i < real_size; i++ )
3567 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
3568 sscanf( tmp, "%x", &c );
3569 sprintf( (char*)&(buffer[i]), "%c", (char)c );
3572 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
3574 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
3577 //=============================================================================
3579 * SMESH_Gen_i::Close
3581 * Clears study-connected data when it is closed
3583 //=============================================================================
3585 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
3587 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
3589 // Clear study contexts data
3590 int studyId = GetCurrentStudyID();
3591 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
3592 delete myStudyContextMap[ studyId ];
3593 myStudyContextMap.erase( studyId );
3596 // delete SMESH_Mesh's
3597 StudyContextStruct* context = myGen.GetStudyContext( studyId );
3598 map< int, SMESH_Mesh* >::iterator i_mesh = context->mapMesh.begin();
3599 for ( ; i_mesh != context->mapMesh.end(); ++i_mesh )
3600 delete i_mesh->second;
3601 // delete SMESHDS_Mesh's
3602 // it's too long on big meshes
3603 // if ( context->myDocument ) {
3604 // delete context->myDocument;
3605 // context->myDocument = 0;
3611 //=============================================================================
3613 * SMESH_Gen_i::ComponentDataType
3615 * Get component data type
3617 //=============================================================================
3619 char* SMESH_Gen_i::ComponentDataType()
3621 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
3622 return CORBA::string_dup( "SMESH" );
3626 //=============================================================================
3628 * SMESH_Gen_i::IORToLocalPersistentID
3630 * Transform data from transient form to persistent
3632 //=============================================================================
3634 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
3635 const char* IORString,
3636 CORBA::Boolean /*isMultiFile*/,
3637 CORBA::Boolean /*isASCII*/ )
3639 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
3640 StudyContext* myStudyContext = GetCurrentStudyContext();
3642 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
3643 int anId = myStudyContext->findId( IORString );
3645 if(MYDEBUG) MESSAGE( "VSR " << anId )
3647 sprintf( strId, "%d", anId );
3648 return CORBA::string_dup( strId );
3651 return CORBA::string_dup( "" );
3654 //=============================================================================
3656 * SMESH_Gen_i::LocalPersistentIDToIOR
3658 * Transform data from persistent form to transient
3660 //=============================================================================
3662 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
3663 const char* aLocalPersistentID,
3664 CORBA::Boolean /*isMultiFile*/,
3665 CORBA::Boolean /*isASCII*/ )
3667 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
3668 StudyContext* myStudyContext = GetCurrentStudyContext();
3670 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
3671 int anId = atoi( aLocalPersistentID );
3672 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
3674 return CORBA::string_dup( "" );
3677 //=======================================================================
3678 //function : RegisterObject
3680 //=======================================================================
3682 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
3684 StudyContext* myStudyContext = GetCurrentStudyContext();
3685 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3686 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
3687 return myStudyContext->addObject( string( iorString.in() ) );
3692 //================================================================================
3694 * \brief Return id of registered object
3695 * \param theObject - the Object
3696 * \retval int - Object id
3698 //================================================================================
3700 int SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
3702 StudyContext* myStudyContext = GetCurrentStudyContext();
3703 if ( myStudyContext && !CORBA::is_nil( theObject )) {
3704 string iorString = GetORB()->object_to_string( theObject );
3705 return myStudyContext->findId( iorString );
3710 //=============================================================================
3712 * SMESHEngine_factory
3714 * C factory, accessible with dlsym, after dlopen
3716 //=============================================================================
3720 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
3721 PortableServer::POA_ptr poa,
3722 PortableServer::ObjectId* contId,
3723 const char* instanceName,
3724 const char* interfaceName )
3726 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
3727 if(MYDEBUG) SCRUTE(interfaceName);
3728 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
3729 return aSMESHGen->getId() ;