1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Gen_i.cxx
24 // Author : Paul RASCLE, EDF
28 #include <TopExp_Explorer.hxx>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_CompSolid.hxx>
33 #include <TopoDS_Solid.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Wire.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TCollection_AsciiString.hxx>
49 #include "Utils_CorbaException.hxx"
51 #include "utilities.h"
62 #define LibHandle HMODULE
63 #define LoadLib( name ) LoadLibrary( name )
64 #define GetProc GetProcAddress
65 #define UnLoadLib( handle ) FreeLibrary( handle );
67 #define LibHandle void*
68 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
70 #define UnLoadLib( handle ) dlclose( handle );
75 #include "SMESH_Gen_i.hxx"
76 #include "SMESH_Mesh_i.hxx"
77 #include "SMESH_Hypothesis_i.hxx"
78 #include "SMESH_Algo_i.hxx"
79 #include "SMESH_Group_i.hxx"
80 #include "SMESH_PythonDump.hxx"
82 #include "SMESHDS_Document.hxx"
83 #include "SMESHDS_Group.hxx"
84 #include "SMESHDS_GroupOnGeom.hxx"
85 #include "SMESH_Mesh.hxx"
86 #include "SMESH_Hypothesis.hxx"
87 #include "SMESH_Group.hxx"
88 #include "SMESH_MeshEditor.hxx"
90 #include "SMDS_EdgePosition.hxx"
91 #include "SMDS_FacePosition.hxx"
92 #include "SMDS_VertexPosition.hxx"
93 #include "SMDS_SpacePosition.hxx"
94 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
96 #include CORBA_SERVER_HEADER(SMESH_Group)
97 #include CORBA_SERVER_HEADER(SMESH_Filter)
98 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
100 #include "DriverMED_W_SMESHDS_Mesh.h"
101 #include "DriverMED_R_SMESHDS_Mesh.h"
103 #include "SALOMEDS_Tool.hxx"
104 #include "SALOME_NamingService.hxx"
105 #include "SALOME_LifeCycleCORBA.hxx"
106 #include "Utils_SINGLETON.hxx"
107 #include "OpUtil.hxx"
109 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
111 #include "GEOM_Client.hxx"
112 #include "Utils_ExceptHandlers.hxx"
117 using SMESH::TPythonDump;
119 #define NUM_TMP_FILES 2
122 static int MYDEBUG = 0;
124 static int MYDEBUG = 0;
127 // Static variables definition
128 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
129 CORBA::ORB_var SMESH_Gen_i::myOrb;
130 PortableServer::POA_var SMESH_Gen_i::myPoa;
131 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
132 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
133 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
136 const int nbElemPerDiagonal = 10;
138 //=============================================================================
140 * GetServant [ static ]
142 * Get servant of the CORBA object
144 //=============================================================================
146 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
148 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
151 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
155 INFOS( "GetServant - Unknown exception was caught!!!" );
160 //=============================================================================
162 * SObjectToObject [ static ]
164 * Get CORBA object corresponding to the SALOMEDS::SObject
166 //=============================================================================
168 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
170 SALOMEDS::GenericAttribute_var anAttr;
171 CORBA::Object_var anObj;
172 if ( !theSObject->_is_nil() ) {
174 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
175 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
176 CORBA::String_var aValue = anIOR->Value();
177 if( strcmp( aValue, "" ) != 0 )
178 anObj = GetORB()->string_to_object( aValue );
182 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
188 //=============================================================================
192 * Get SALOME_NamingService object
194 //=============================================================================
196 SALOME_NamingService* SMESH_Gen_i::GetNS()
198 if ( myNS == NULL ) {
199 myNS = SINGLETON_<SALOME_NamingService>::Instance();
200 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
201 myNS->init_orb( GetORB() );
206 //=============================================================================
210 * Get SALOME_LifeCycleCORBA object
212 //=============================================================================
213 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
214 if ( myLCC == NULL ) {
215 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
221 //=============================================================================
223 * GetGeomEngine [ static ]
225 * Get GEOM::GEOM_Gen reference
227 //=============================================================================
228 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
229 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
230 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
231 //CCRT return aGeomEngine._retn();
232 if(CORBA::is_nil(myGeomGen))
234 Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
235 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
240 //=============================================================================
242 * SMESH_Gen_i::SMESH_Gen_i
244 * Default constructor: not for use
246 //=============================================================================
248 SMESH_Gen_i::SMESH_Gen_i()
250 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
253 //=============================================================================
255 * SMESH_Gen_i::SMESH_Gen_i
257 * Standard constructor, used with Container
259 //=============================================================================
261 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
262 PortableServer::POA_ptr poa,
263 PortableServer::ObjectId* contId,
264 const char* instanceName,
265 const char* interfaceName )
266 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
268 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
270 myOrb = CORBA::ORB::_duplicate(orb);
271 myPoa = PortableServer::POA::_duplicate(poa);
274 _id = myPoa->activate_object( _thisObj );
276 myIsEmbeddedMode = false;
277 myShapeReader = NULL; // shape reader
280 // set it in standalone mode only
281 //OSD::SetSignal( true );
284 //=============================================================================
286 * SMESH_Gen_i::~SMESH_Gen_i
290 //=============================================================================
292 SMESH_Gen_i::~SMESH_Gen_i()
294 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
296 // delete hypothesis creators
297 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
298 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
300 delete (*itHyp).second;
302 myHypCreatorMap.clear();
304 // Clear study contexts data
305 map<int, StudyContext*>::iterator it;
306 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
309 myStudyContextMap.clear();
310 // delete shape reader
311 if ( !myShapeReader )
312 delete myShapeReader;
315 //=============================================================================
317 * SMESH_Gen_i::createHypothesis
319 * Create hypothesis of given type
321 //=============================================================================
322 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
323 const char* theLibName)
324 throw (SALOME::SALOME_Exception)
326 /* It's Need to tranlate lib name for WIN32 or X platform */
327 char* aPlatformLibName = 0;
328 if ( theLibName && theLibName[0] != '\0' )
330 int libNameLen = strlen(theLibName);
331 //check for old format "libXXXXXXX.so"
332 if (libNameLen > 7 &&
333 !strncmp( theLibName, "lib", 3 ) &&
334 !strcmp( theLibName+libNameLen-3, ".so" ))
338 aPlatformLibName = new char[libNameLen - 1];
339 aPlatformLibName[0] = '\0';
340 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
341 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
342 aPlatformLibName[libNameLen - 2] = '\0';
344 aPlatformLibName = new char[ libNameLen + 1];
345 aPlatformLibName[0] = '\0';
346 aPlatformLibName = strcat( aPlatformLibName, theLibName );
347 aPlatformLibName[libNameLen] = '\0';
352 //try to use new format
354 aPlatformLibName = new char[ libNameLen + 5 ];
355 aPlatformLibName[0] = '\0';
356 aPlatformLibName = strcat( aPlatformLibName, theLibName );
357 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
359 aPlatformLibName = new char[ libNameLen + 7 ];
360 aPlatformLibName[0] = '\0';
361 aPlatformLibName = strcat( aPlatformLibName, "lib" );
362 aPlatformLibName = strcat( aPlatformLibName, theLibName );
363 aPlatformLibName = strcat( aPlatformLibName, ".so" );
369 Unexpect aCatch(SALOME_SalomeException);
370 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
372 // create a new hypothesis object servant
373 SMESH_Hypothesis_i* myHypothesis_i = 0;
374 SMESH::SMESH_Hypothesis_var hypothesis_i;
378 // check, if creator for this hypothesis type already exists
379 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
381 // load plugin library
382 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
383 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
386 // report any error, if occured
388 const char* anError = dlerror();
389 throw(SALOME_Exception(anError));
391 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
395 // get method, returning hypothesis creator
396 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
397 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
398 GetHypothesisCreator procHandle =
399 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
402 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
403 UnLoadLib(libHandle);
406 // get hypothesis creator
407 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
408 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
411 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
414 // map hypothesis creator to a hypothesis name
415 myHypCreatorMap[string(theHypName)] = aCreator;
418 // create a new hypothesis object, store its ref. in studyContext
419 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
421 myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
422 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
424 catch (SALOME_Exception& S_ex)
426 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
429 if ( aPlatformLibName )
430 delete[] aPlatformLibName;
433 return hypothesis_i._retn();
435 // activate the CORBA servant of hypothesis
436 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
437 int nextId = RegisterObject( hypothesis_i );
438 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
440 return hypothesis_i._retn();
443 //=============================================================================
445 * SMESH_Gen_i::createMesh
447 * Create empty mesh on shape
449 //=============================================================================
450 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
451 throw ( SALOME::SALOME_Exception )
453 Unexpect aCatch(SALOME_SalomeException);
454 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
456 // Get or create the GEOM_Client instance
458 // create a new mesh object servant, store it in a map in study context
459 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
460 // create a new mesh object
461 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
463 // activate the CORBA servant of Mesh
464 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
465 int nextId = RegisterObject( mesh );
466 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
469 catch (SALOME_Exception& S_ex) {
470 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
472 return SMESH::SMESH_Mesh::_nil();
475 //=============================================================================
477 * SMESH_Gen_i::GetShapeReader
481 //=============================================================================
482 GEOM_Client* SMESH_Gen_i::GetShapeReader()
484 // create shape reader if necessary
485 if ( !myShapeReader )
486 myShapeReader = new GEOM_Client(GetContainerRef());
487 ASSERT( myShapeReader );
488 return myShapeReader;
491 //=============================================================================
493 * SMESH_Gen_i::SetGeomEngine
495 * Set GEOM::GEOM_Gen reference
497 //=============================================================================
498 //GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
499 void SMESH_Gen_i::SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo )
501 //Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
502 //myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
503 myGeomGen=GEOM::GEOM_Gen::_duplicate(geomcompo);
507 //=============================================================================
509 * SMESH_Gen_i::SetEmbeddedMode
513 //=============================================================================
515 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
517 myIsEmbeddedMode = theMode;
519 if ( !myIsEmbeddedMode ) {
520 //PAL10867: disable signals catching with "noexcepthandler" option
521 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
522 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
527 char* envDisableFPE = getenv("DISABLE_FPE");
528 if (envDisableFPE && atoi(envDisableFPE))
533 OSD::SetSignal( raiseFPE );
535 // else OSD::SetSignal() is called in GUI
539 //=============================================================================
541 * SMESH_Gen_i::IsEmbeddedMode
545 //=============================================================================
547 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
549 return myIsEmbeddedMode;
552 //=============================================================================
554 * SMESH_Gen_i::SetCurrentStudy
558 //=============================================================================
560 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
562 int curStudyId = GetCurrentStudyID();
563 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
564 // create study context, if it doesn't exist and set current study
565 int studyId = GetCurrentStudyID();
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 // NPAL16168, issue 0020210
577 // Let meshes update their data depending on GEOM groups that could change
578 if ( curStudyId != studyId )
580 //SALOMEDS::SComponent_var me = PublishComponent( myCurrentStudy );
581 SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
582 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
583 if ( !me->_is_nil() ) {
584 SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
585 for ( ; anIter->More(); anIter->Next() ) {
586 SALOMEDS::SObject_var so = anIter->Value();
587 CORBA::Object_var ior = SObjectToObject( so );
588 if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
589 mesh->CheckGeomGroupModif();
596 //=============================================================================
598 * SMESH_Gen_i::GetCurrentStudy
602 //=============================================================================
604 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
606 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
607 return SALOMEDS::Study::_duplicate( myCurrentStudy );
610 //=============================================================================
612 * SMESH_Gen_i::GetCurrentStudyContext
614 * Get current study context
616 //=============================================================================
617 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
619 if ( !CORBA::is_nil( myCurrentStudy ) &&
620 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
621 return myStudyContextMap[ myCurrentStudy->StudyId() ];
626 //=============================================================================
628 * SMESH_Gen_i::CreateHypothesis
630 * Create hypothesis/algorothm of given type and publish it in the study
632 //=============================================================================
634 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
635 const char* theLibName )
636 throw ( SALOME::SALOME_Exception )
638 Unexpect aCatch(SALOME_SalomeException);
639 // Create hypothesis/algorithm
640 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
642 // Publish hypothesis/algorithm in the study
643 if ( CanPublishInStudy( hyp ) ) {
644 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
645 if ( !aSO->_is_nil() ) {
646 // Update Python script
647 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
648 << theHypName << "', '" << theLibName << "')";
655 //================================================================================
657 * \brief Return a hypothesis holding parameter values corresponding either to the mesh
658 * existing on the given geometry or to size of the geometry.
659 * \param theHypType - hypothesis type name
660 * \param theLibName - plugin library name
661 * \param theMesh - The mesh of interest
662 * \param theGeom - The shape to get parameter values from
663 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
664 * in a study and used to compute the mesh, or a temporary one created just to pass
667 //================================================================================
669 SMESH::SMESH_Hypothesis_ptr
670 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
671 const char* theLibName,
672 SMESH::SMESH_Mesh_ptr theMesh,
673 GEOM::GEOM_Object_ptr theGeom,
674 CORBA::Boolean byMesh)
675 throw ( SALOME::SALOME_Exception )
677 Unexpect aCatch(SALOME_SalomeException);
678 if ( byMesh && CORBA::is_nil( theMesh ) )
679 return SMESH::SMESH_Hypothesis::_nil();
680 if ( byMesh && CORBA::is_nil( theGeom ) )
681 return SMESH::SMESH_Hypothesis::_nil();
683 // -----------------------------------------------
684 // find hypothesis used to mesh theGeom
685 // -----------------------------------------------
687 // get mesh and shape
688 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
689 TopoDS_Shape shape = GeomObjectToShape( theGeom );
690 if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
691 return SMESH::SMESH_Hypothesis::_nil();
692 ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
694 // create a temporary hypothesis to know its dimention
695 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
696 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
698 return SMESH::SMESH_Hypothesis::_nil();
699 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
702 // look for a hypothesis of theHypType used to mesh the shape
703 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
706 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
707 int nbLocalHyps = aHypList->length();
708 for ( int i = 0; i < nbLocalHyps; i++ )
709 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
710 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
711 // check super shapes
712 TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
713 while ( nbLocalHyps == 0 && itShape.More() ) {
714 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
715 if ( ! CORBA::is_nil( geomObj )) {
716 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
717 nbLocalHyps = aHypList->length();
718 for ( int i = 0; i < nbLocalHyps; i++ )
719 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
720 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
726 // let the temporary hypothesis find out some how parameter values by mesh
727 if ( hyp->SetParametersByMesh( mesh, shape ))
728 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
733 diagonal = mesh->GetShapeDiagonalSize();
735 diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
736 ::SMESH_Hypothesis::TDefaults dflts;
737 dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
738 dflts._nbSegments = myGen.GetDefaultNbSegments();
739 // let the temporary hypothesis initialize it's values
740 if ( hyp->SetParametersByDefaults( dflts, mesh ))
741 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
744 return SMESH::SMESH_Hypothesis::_nil();
747 //=============================================================================
749 * Sets number of segments per diagonal of boundary box of geometry by which
750 * default segment length of appropriate 1D hypotheses is defined
752 //=============================================================================
754 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
755 throw ( SALOME::SALOME_Exception )
757 if ( theNbSegments > 0 )
758 myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
760 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
762 //=============================================================================
764 * \brief Sets default number of segments per edge
766 //=============================================================================
767 void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
768 throw ( SALOME::SALOME_Exception )
771 myGen.SetDefaultNbSegments( int(theNbSegments) );
773 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
776 //=============================================================================
778 * SMESH_Gen_i::CreateMesh
780 * Create empty mesh on a shape and publish it in the study
782 //=============================================================================
784 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
785 throw ( SALOME::SALOME_Exception )
787 Unexpect aCatch(SALOME_SalomeException);
788 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
790 SMESH::SMESH_Mesh_var mesh = this->createMesh();
792 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
793 ASSERT( meshServant );
794 meshServant->SetShape( theShapeObject );
796 // publish mesh in the study
797 if ( CanPublishInStudy( mesh ) ) {
798 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
799 aStudyBuilder->NewCommand(); // There is a transaction
800 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
801 aStudyBuilder->CommitCommand();
802 if ( !aSO->_is_nil() ) {
803 // Update Python script
804 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
811 //=============================================================================
813 * SMESH_Gen_i::CreateEmptyMesh
817 //=============================================================================
819 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
820 throw ( SALOME::SALOME_Exception )
822 Unexpect aCatch(SALOME_SalomeException);
823 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
825 SMESH::SMESH_Mesh_var mesh = this->createMesh();
827 // publish mesh in the study
828 if ( CanPublishInStudy( mesh ) ) {
829 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
830 aStudyBuilder->NewCommand(); // There is a transaction
831 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
832 aStudyBuilder->CommitCommand();
833 if ( !aSO->_is_nil() ) {
834 // Update Python script
835 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
842 //=============================================================================
844 * SMESH_Gen_i::CreateMeshFromUNV
846 * Create mesh and import data from UNV file
848 //=============================================================================
850 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
851 throw ( SALOME::SALOME_Exception )
853 Unexpect aCatch(SALOME_SalomeException);
854 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
856 SMESH::SMESH_Mesh_var aMesh = createMesh();
858 // publish mesh in the study
859 if ( CanPublishInStudy( aMesh ) ) {
860 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
861 aStudyBuilder->NewCommand(); // There is a transaction
862 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
863 aStudyBuilder->CommitCommand();
864 if ( !aSO->_is_nil() ) {
865 // Update Python script
866 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
870 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
872 aServant->ImportUNVFile( theFileName );
874 // Dump creation of groups
875 aServant->GetGroups();
877 return aMesh._retn();
880 //=============================================================================
882 * SMESH_Gen_i::CreateMeshFromMED
884 * Create mesh and import data from MED file
886 //=============================================================================
888 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
889 SMESH::DriverMED_ReadStatus& theStatus)
890 throw ( SALOME::SALOME_Exception )
892 Unexpect aCatch(SALOME_SalomeException);
893 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
895 // Retrieve mesh names from the file
896 DriverMED_R_SMESHDS_Mesh myReader;
897 myReader.SetFile( theFileName );
898 myReader.SetMeshId( -1 );
899 Driver_Mesh::Status aStatus;
900 list<string> aNames = myReader.GetMeshNames(aStatus);
901 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
902 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
904 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
907 TPythonDump aPythonDump;
909 //TCollection_AsciiString aStr ("([");
911 if (theStatus == SMESH::DRS_OK) {
912 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
913 aStudyBuilder->NewCommand(); // There is a transaction
914 aResult->length( aNames.size() );
917 // Iterate through all meshes and create mesh objects
918 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
920 //if (i > 0) aStr += ", ";
921 if (i > 0) aPythonDump << ", ";
924 SMESH::SMESH_Mesh_var mesh = createMesh();
926 // publish mesh in the study
927 SALOMEDS::SObject_var aSO;
928 if ( CanPublishInStudy( mesh ) )
929 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
930 if ( !aSO->_is_nil() ) {
933 //aStr += aSO->GetID();
936 aPythonDump << "mesh_" << i;
938 // aStr += TCollection_AsciiString(i);
941 // Read mesh data (groups are published automatically by ImportMEDFile())
942 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
943 ASSERT( meshServant );
944 SMESH::DriverMED_ReadStatus status1 =
945 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
946 if (status1 > theStatus)
949 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
951 aStudyBuilder->CommitCommand();
954 // Update Python script
955 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
957 // Dump creation of groups
958 for ( int i = 0; i < aResult->length(); ++i )
959 aResult[ i ]->GetGroups();
961 return aResult._retn();
964 //=============================================================================
966 * SMESH_Gen_i::CreateMeshFromSTL
968 * Create mesh and import data from STL file
970 //=============================================================================
972 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
973 throw ( SALOME::SALOME_Exception )
975 Unexpect aCatch(SALOME_SalomeException);
976 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
978 SMESH::SMESH_Mesh_var aMesh = createMesh();
980 // publish mesh in the study
981 if ( CanPublishInStudy( aMesh ) ) {
982 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
983 aStudyBuilder->NewCommand(); // There is a transaction
984 SALOMEDS::SObject_var aSO = PublishInStudy
985 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
986 aStudyBuilder->CommitCommand();
987 if ( !aSO->_is_nil() ) {
988 // Update Python script
989 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
993 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
995 aServant->ImportSTLFile( theFileName );
996 return aMesh._retn();
999 //=============================================================================
1001 * SMESH_Gen_i::IsReadyToCompute
1003 * Returns true if mesh contains enough data to be computed
1005 //=============================================================================
1007 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
1008 GEOM::GEOM_Object_ptr theShapeObject )
1009 throw ( SALOME::SALOME_Exception )
1011 Unexpect aCatch(SALOME_SalomeException);
1012 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
1014 if ( CORBA::is_nil( theShapeObject ) )
1015 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1016 SALOME::BAD_PARAM );
1018 if ( CORBA::is_nil( theMesh ) )
1019 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1020 SALOME::BAD_PARAM );
1024 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1025 ASSERT( meshServant );
1026 if ( meshServant ) {
1027 // get local TopoDS_Shape
1028 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1029 // call implementation
1030 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1031 return myGen.CheckAlgoState( myLocMesh, myLocShape );
1034 catch ( SALOME_Exception& S_ex ) {
1035 INFOS( "catch exception "<< S_ex.what() );
1040 //================================================================================
1042 * \brief Find SObject for an algo
1044 //================================================================================
1046 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
1049 if ( !myCurrentStudy->_is_nil() ) {
1050 // find algo in the study
1051 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
1052 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
1053 if ( !father->_is_nil() ) {
1054 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
1055 for ( ; itBig->More(); itBig->Next() ) {
1056 SALOMEDS::SObject_var gotBranch = itBig->Value();
1057 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1058 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1059 for ( ; algoIt->More(); algoIt->Next() ) {
1060 SALOMEDS::SObject_var algoSO = algoIt->Value();
1061 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1062 if ( !CORBA::is_nil( algoIOR )) {
1063 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1064 if ( impl && impl->GetImpl() == algo )
1065 return algoSO._retn();
1067 } // loop on algo SO's
1070 } // SMESH component iterator
1074 return SALOMEDS::SObject::_nil();
1077 //================================================================================
1079 * \brief Return errors of mesh computation
1081 //================================================================================
1083 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1084 GEOM::GEOM_Object_ptr theSubObject )
1085 throw ( SALOME::SALOME_Exception )
1087 Unexpect aCatch(SALOME_SalomeException);
1088 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1090 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1091 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1093 if ( CORBA::is_nil( theMesh ) )
1094 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1096 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1098 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1101 if(theMesh->HasShapeToMesh())
1102 shape = GeomObjectToShape( theSubObject );
1104 shape = SMESH_Mesh::PseudoShape();
1106 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1108 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1111 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1112 const bool includeSelf = true, complexShapeFirst = true;
1113 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1115 while ( smIt->more() )
1118 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1120 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1121 if ( error && !error->IsOK() && error->myAlgo )
1123 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1124 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1125 errStruct.comment = error->myComment.c_str();
1126 errStruct.subShapeID = sm->GetId();
1127 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->myAlgo );
1128 if ( !algoSO->_is_nil() )
1129 errStruct.algoName = algoSO->GetName();
1131 errStruct.algoName = error->myAlgo->GetName();
1132 errStruct.hasBadMesh = !error->myBadElements.empty();
1135 error_array->length( nbErr );
1138 catch ( SALOME_Exception& S_ex ) {
1139 INFOS( "catch exception "<< S_ex.what() );
1142 return error_array._retn();
1146 //================================================================================
1148 * \brief Return mesh elements preventing computation of a subshape
1150 //================================================================================
1152 SMESH::MeshPreviewStruct*
1153 SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1154 CORBA::Short theSubShapeID )
1155 throw ( SALOME::SALOME_Exception )
1157 Unexpect aCatch(SALOME_SalomeException);
1158 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetBadInputElements()" );
1160 if ( CORBA::is_nil( theMesh ) )
1161 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1163 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1166 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1168 // mesh implementation
1169 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1170 // submesh by subshape id
1171 if ( SMESH_subMesh * sm = mesh.GetSubMeshContaining( theSubShapeID ))
1174 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1175 if ( error && !error->myBadElements.empty())
1177 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1178 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1180 // get nodes of elements and count elements
1181 TNode2LocalIDMap mapNode2LocalID;
1182 list< TNodeLocalID > connectivity;
1183 int i, nbElements = 0, nbConnNodes = 0;
1185 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
1186 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
1187 for ( ; elemIt != elemEnd; ++elemIt, ++nbElements )
1189 SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator();
1190 while ( nIt->more() )
1191 connectivity.push_back
1192 ( mapNode2LocalID.insert( make_pair( nIt->next(), ++nbConnNodes)).first );
1194 // fill node coords and assign local ids to the nodes
1195 int nbNodes = mapNode2LocalID.size();
1196 result->nodesXYZ.length( nbNodes );
1197 TNodeLocalID node2ID = mapNode2LocalID.begin();
1198 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1199 node2ID->second = i;
1200 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1201 result->nodesXYZ[i].x = node->X();
1202 result->nodesXYZ[i].y = node->Y();
1203 result->nodesXYZ[i].z = node->Z();
1205 // fill connectivity
1206 result->elementConnectivities.length( nbConnNodes );
1207 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1208 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1209 result->elementConnectivities[i] = (*connIt)->second;
1211 // fill element types
1212 result->elementTypes.length( nbElements );
1213 for ( i = 0, elemIt = error->myBadElements.begin(); i <nbElements; ++i, ++elemIt )
1215 const SMDS_MeshElement* elem = *elemIt;
1216 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType();
1217 result->elementTypes[i].isPoly = elem->IsPoly();
1218 result->elementTypes[i].nbNodesInElement = elem->NbNodes();
1224 catch ( SALOME_Exception& S_ex ) {
1225 INFOS( "catch exception "<< S_ex.what() );
1228 return result._retn();
1231 //================================================================================
1233 * \brief Returns errors of hypotheses definintion
1234 * \param theMesh - the mesh
1235 * \param theSubObject - the main or sub- shape
1236 * \retval SMESH::algo_error_array* - sequence of errors
1238 //================================================================================
1240 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1241 GEOM::GEOM_Object_ptr theSubObject )
1242 throw ( SALOME::SALOME_Exception )
1244 Unexpect aCatch(SALOME_SalomeException);
1245 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1247 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1248 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1250 if ( CORBA::is_nil( theMesh ) )
1251 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1253 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1255 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1256 ASSERT( meshServant );
1257 if ( meshServant ) {
1258 TopoDS_Shape myLocShape;
1259 if(theMesh->HasShapeToMesh())
1260 myLocShape = GeomObjectToShape( theSubObject );
1262 myLocShape = SMESH_Mesh::PseudoShape();
1264 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1265 list< ::SMESH_Gen::TAlgoStateError > error_list;
1266 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1267 // call ::SMESH_Gen::GetAlgoState()
1268 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1269 error_array->length( error_list.size() );
1271 for ( error = error_list.begin(); error != error_list.end(); ++error )
1273 // fill AlgoStateError structure
1274 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1275 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1276 errStruct.algoDim = error->_algoDim;
1277 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1278 errStruct.algoName = "";
1279 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->_algo );
1280 if ( !algoSO->_is_nil() )
1281 errStruct.algoName = algoSO->GetName();
1285 catch ( SALOME_Exception& S_ex ) {
1286 INFOS( "catch exception "<< S_ex.what() );
1288 return error_array._retn();
1291 //=============================================================================
1293 * SMESH_Gen_i::GetSubShapesId
1295 * Get sub-shapes unique ID's list
1297 //=============================================================================
1299 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1300 const SMESH::object_array& theListOfSubShapeObject )
1301 throw ( SALOME::SALOME_Exception )
1303 Unexpect aCatch(SALOME_SalomeException);
1304 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1306 SMESH::long_array_var shapesId = new SMESH::long_array;
1309 if ( CORBA::is_nil( theMainShapeObject ) )
1310 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1311 SALOME::BAD_PARAM );
1315 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1316 TopTools_IndexedMapOfShape myIndexToShape;
1317 TopExp::MapShapes(myMainShape,myIndexToShape);
1319 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1321 GEOM::GEOM_Object_var aShapeObject
1322 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1323 if ( CORBA::is_nil( aShapeObject ) )
1324 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1325 SALOME::BAD_PARAM );
1327 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1328 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1330 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1331 setId.insert(myIndexToShape.FindIndex(F));
1332 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1334 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1336 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1337 setId.insert(myIndexToShape.FindIndex(E));
1338 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1340 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1342 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1343 setId.insert(myIndexToShape.FindIndex(V));
1344 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1347 shapesId->length(setId.size());
1348 set<int>::iterator iind;
1350 for (iind = setId.begin(); iind != setId.end(); iind++)
1352 if(MYDEBUG) SCRUTE((*iind));
1353 shapesId[i] = (*iind);
1354 if(MYDEBUG) SCRUTE(shapesId[i]);
1358 catch (SALOME_Exception& S_ex)
1360 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1363 return shapesId._retn();
1366 //=============================================================================
1368 * SMESH_Gen_i::Compute
1370 * Compute mesh on a shape
1372 //=============================================================================
1374 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1375 GEOM::GEOM_Object_ptr theShapeObject )
1376 throw ( SALOME::SALOME_Exception )
1378 Unexpect aCatch(SALOME_SalomeException);
1379 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1381 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1382 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1383 SALOME::BAD_PARAM );
1385 if ( CORBA::is_nil( theMesh ) )
1386 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1387 SALOME::BAD_PARAM );
1389 // Update Python script
1390 TPythonDump() << "isDone = " << this << ".Compute( "
1391 << theMesh << ", " << theShapeObject << ")";
1395 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1396 ASSERT( meshServant );
1397 if ( meshServant ) {
1398 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1399 meshServant->CheckGeomGroupModif();
1400 // get local TopoDS_Shape
1401 TopoDS_Shape myLocShape;
1402 if(theMesh->HasShapeToMesh())
1403 myLocShape = GeomObjectToShape( theShapeObject );
1405 myLocShape = SMESH_Mesh::PseudoShape();
1406 // call implementation compute
1407 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1408 return myGen.Compute( myLocMesh, myLocShape);
1411 catch ( std::bad_alloc ) {
1412 INFOS( "Compute(): lack of memory" );
1414 catch ( SALOME_Exception& S_ex ) {
1415 INFOS( "Compute(): catch exception "<< S_ex.what() );
1418 INFOS( "Compute(): unknown exception " );
1423 //=============================================================================
1425 * SMESH_Gen_i::Precompute
1427 * Compute mesh as preview till indicated dimension on shape
1429 //=============================================================================
1431 SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh,
1432 GEOM::GEOM_Object_ptr theShapeObject,
1433 SMESH::Dimension theDimension,
1434 SMESH::long_array& theShapesId)
1435 throw ( SALOME::SALOME_Exception )
1437 Unexpect aCatch(SALOME_SalomeException);
1438 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Precompute" );
1440 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1441 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1442 SALOME::BAD_PARAM );
1444 if ( CORBA::is_nil( theMesh ) )
1445 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1446 SALOME::BAD_PARAM );
1448 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1451 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1452 ASSERT( meshServant );
1453 if ( meshServant ) {
1454 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1455 meshServant->CheckGeomGroupModif();
1456 // get local TopoDS_Shape
1457 TopoDS_Shape myLocShape;
1458 if(theMesh->HasShapeToMesh())
1459 myLocShape = GeomObjectToShape( theShapeObject );
1461 return result._retn();;
1463 // call implementation compute
1464 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1466 ::MeshDimension aDim = (MeshDimension)theDimension;
1467 if ( myGen.Compute( myLocMesh, myLocShape, false, aDim, &shapeIds ) )
1469 int nbShapeId = shapeIds.size();
1470 theShapesId.length( nbShapeId );
1471 // iterates on shapes and collect mesh entities into mesh preview
1472 TSetOfInt::const_iterator idIt = shapeIds.begin();
1473 TSetOfInt::const_iterator idEnd = shapeIds.end();
1474 std::map< int, int > mapOfShIdNb;
1475 std::set< SMESH_TLink > setOfEdge;
1476 std::list< SMDSAbs_ElementType > listOfElemType;
1477 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1478 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1479 TNode2LocalIDMap mapNode2LocalID;
1480 list< TNodeLocalID > connectivity;
1481 int i, nbConnNodes = 0;
1482 std::set< const SMESH_subMesh* > setOfVSubMesh;
1483 // iterates on shapes
1484 for ( ; idIt != idEnd; idIt++ )
1486 if ( mapOfShIdNb.find( *idIt ) != mapOfShIdNb.end() )
1488 SMESH_subMesh* sm = myLocMesh.GetSubMeshContaining(*idIt);
1489 if ( !sm || !sm->IsMeshComputed() )
1492 const TopoDS_Shape& aSh = sm->GetSubShape();
1493 const int shDim = myGen.GetShapeDim( aSh );
1494 if ( shDim < 1 || shDim > theDimension )
1497 mapOfShIdNb[ *idIt ] = 0;
1498 theShapesId[ mapOfShIdNb.size() - 1 ] = *idIt;
1500 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1501 if ( !smDS ) continue;
1503 if ( theDimension == SMESH::DIM_2D )
1505 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1506 while ( faceIt->more() )
1508 const SMDS_MeshElement* face = faceIt->next();
1509 int aNbNode = face->NbNodes();
1511 aNbNode /= 2; // do not take into account additional middle nodes
1513 SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
1514 for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
1516 SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
1517 if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
1519 listOfElemType.push_back( SMDSAbs_Edge );
1520 connectivity.push_back
1521 ( mapNode2LocalID.insert( make_pair( node1, ++nbConnNodes)).first );
1522 connectivity.push_back
1523 ( mapNode2LocalID.insert( make_pair( node2, ++nbConnNodes)).first );
1529 else if ( theDimension == SMESH::DIM_1D )
1531 SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
1532 while ( nodeIt->more() )
1534 listOfElemType.push_back( SMDSAbs_Node );
1535 connectivity.push_back
1536 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1538 // add corner nodes by first vertex from edge
1539 SMESH_subMeshIteratorPtr edgeSmIt =
1540 sm->getDependsOnIterator(/*includeSelf*/false,
1541 /*complexShapeFirst*/false);
1542 while ( edgeSmIt->more() )
1544 SMESH_subMesh* vertexSM = edgeSmIt->next();
1545 // check that vertex is not already treated
1546 if ( !setOfVSubMesh.insert( vertexSM ).second )
1548 if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
1551 const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
1552 SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
1553 while ( nodeIt->more() )
1555 listOfElemType.push_back( SMDSAbs_Node );
1556 connectivity.push_back
1557 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1563 // fill node coords and assign local ids to the nodes
1564 int nbNodes = mapNode2LocalID.size();
1565 result->nodesXYZ.length( nbNodes );
1566 TNodeLocalID node2ID = mapNode2LocalID.begin();
1567 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1568 node2ID->second = i;
1569 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1570 result->nodesXYZ[i].x = node->X();
1571 result->nodesXYZ[i].y = node->Y();
1572 result->nodesXYZ[i].z = node->Z();
1574 // fill connectivity
1575 result->elementConnectivities.length( nbConnNodes );
1576 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1577 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1578 result->elementConnectivities[i] = (*connIt)->second;
1581 // fill element types
1582 result->elementTypes.length( listOfElemType.size() );
1583 std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
1584 std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
1585 for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
1587 SMDSAbs_ElementType elemType = *typeIt;
1588 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
1589 result->elementTypes[i].isPoly = false;
1590 result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
1593 // correct number of shapes
1594 theShapesId.length( mapOfShIdNb.size() );
1598 catch ( std::bad_alloc ) {
1599 INFOS( "Precompute(): lack of memory" );
1601 catch ( SALOME_Exception& S_ex ) {
1602 INFOS( "Precompute(): catch exception "<< S_ex.what() );
1605 INFOS( "Precompute(): unknown exception " );
1607 return result._retn();
1611 //=============================================================================
1613 * SMESH_Gen_i::Evaluate
1615 * Evaluate mesh on a shape
1617 //=============================================================================
1619 SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
1620 GEOM::GEOM_Object_ptr theShapeObject)
1621 // SMESH::long_array& theNbElems)
1622 throw ( SALOME::SALOME_Exception )
1624 Unexpect aCatch(SALOME_SalomeException);
1625 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
1627 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1628 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1629 SALOME::BAD_PARAM );
1631 if ( CORBA::is_nil( theMesh ) )
1632 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1633 SALOME::BAD_PARAM );
1635 SMESH::long_array_var nbels = new SMESH::long_array;
1636 nbels->length(SMESH::Entity_Last);
1637 int i = SMESH::Entity_Node;
1638 for (; i < SMESH::Entity_Last; i++)
1641 // Update Python script
1642 TPythonDump() << "theNbElems = " << this << ".Evaluate( "
1643 << theMesh << ", " << theShapeObject << ")";
1647 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1648 ASSERT( meshServant );
1649 if ( meshServant ) {
1650 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1651 meshServant->CheckGeomGroupModif();
1652 // get local TopoDS_Shape
1653 TopoDS_Shape myLocShape;
1654 if(theMesh->HasShapeToMesh())
1655 myLocShape = GeomObjectToShape( theShapeObject );
1657 myLocShape = SMESH_Mesh::PseudoShape();
1658 // call implementation compute
1659 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1660 MapShapeNbElems aResMap;
1661 /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
1662 MapShapeNbElemsItr anIt = aResMap.begin();
1663 for(; anIt!=aResMap.end(); anIt++) {
1664 const vector<int>& aVec = (*anIt).second;
1665 for(i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++) {
1666 nbels[i] += aVec[i];
1672 return nbels._retn();
1675 catch ( std::bad_alloc ) {
1676 INFOS( "Evaluate(): lack of memory" );
1678 catch ( SALOME_Exception& S_ex ) {
1679 INFOS( "Evaluate(): catch exception "<< S_ex.what() );
1682 INFOS( "Evaluate(): unknown exception " );
1685 return nbels._retn();
1688 //================================================================================
1690 * \brief Return geometrical object the given element is built on
1691 * \param theMesh - the mesh the element is in
1692 * \param theElementID - the element ID
1693 * \param theGeomName - the name of the result geom object if it is not yet published
1694 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1696 //================================================================================
1698 GEOM::GEOM_Object_ptr
1699 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1700 CORBA::Long theElementID,
1701 const char* theGeomName)
1702 throw ( SALOME::SALOME_Exception )
1704 Unexpect aCatch(SALOME_SalomeException);
1706 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
1707 if ( !geom->_is_nil() ) {
1708 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1709 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1711 // try to find the corresponding SObject
1712 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1713 if ( SObj->_is_nil() ) // submesh can be not found even if published
1715 // try to find published submesh
1716 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
1717 if ( !geom->IsMainShape() && list->length() == 1 ) {
1718 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1719 SALOMEDS::ChildIterator_var it;
1720 if ( !mainSO->_is_nil() )
1721 it = myCurrentStudy->NewChildIterator( mainSO );
1722 if ( !it->_is_nil() ) {
1723 for ( it->InitEx(true); SObj->_is_nil() && it->More(); it->Next() ) {
1724 GEOM::GEOM_Object_var subGeom =
1725 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1726 if ( !subGeom->_is_nil() ) {
1727 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1728 if ( subList->length() == 1 && list[0] == subList[0] ) {
1737 if ( SObj->_is_nil() ) // publish a new subshape
1738 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1740 // return only published geometry
1741 if ( !SObj->_is_nil() )
1742 return geom._retn();
1744 return GEOM::GEOM_Object::_nil();
1747 //================================================================================
1749 * \brief Return geometrical object the given element is built on.
1750 * \param theMesh - the mesh the element is in
1751 * \param theElementID - the element ID
1752 * \retval GEOM::GEOM_Object_ptr - the found geom object
1754 //================================================================================
1756 GEOM::GEOM_Object_ptr
1757 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1758 CORBA::Long theElementID)
1759 throw ( SALOME::SALOME_Exception )
1761 Unexpect aCatch(SALOME_SalomeException);
1762 if ( CORBA::is_nil( theMesh ) )
1763 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1765 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1766 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1768 // get a core mesh DS
1769 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1770 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1772 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1773 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1774 // find the element in mesh
1775 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
1776 // find a shape id by the element
1777 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1778 // get a geom object by the shape id
1779 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1780 if ( geom->_is_nil() ) {
1781 // try to find a published sub-shape
1782 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1783 SALOMEDS::ChildIterator_var it;
1784 if ( !mainSO->_is_nil() )
1785 it = myCurrentStudy->NewChildIterator( mainSO );
1786 if ( !it->_is_nil() ) {
1787 for ( it->InitEx(true); it->More(); it->Next() ) {
1788 GEOM::GEOM_Object_var subGeom =
1789 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1790 if ( !subGeom->_is_nil() ) {
1791 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1792 if ( subList->length() == 1 && shapeID == subList[0] ) {
1800 if ( geom->_is_nil() ) {
1802 GEOM::GEOM_IShapesOperations_var op =
1803 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1804 if ( !op->_is_nil() )
1805 geom = op->GetSubShape( mainShape, shapeID );
1807 if ( !geom->_is_nil() ) {
1808 GeomObjectToShape( geom ); // let geom client remember the found shape
1809 return geom._retn();
1814 return GEOM::GEOM_Object::_nil();
1817 //================================================================================
1819 * SMESH_Gen_i::Concatenate
1821 * Concatenate the given meshes into one mesh
1823 //================================================================================
1825 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
1826 CORBA::Boolean theUniteIdenticalGroups,
1827 CORBA::Boolean theMergeNodesAndElements,
1828 CORBA::Double theMergeTolerance)
1829 throw ( SALOME::SALOME_Exception )
1831 return ConcatenateCommon(theMeshesArray,
1832 theUniteIdenticalGroups,
1833 theMergeNodesAndElements,
1838 //================================================================================
1840 * SMESH_Gen_i::ConcatenateWithGroups
1842 * Concatenate the given meshes into one mesh
1843 * Create the groups of all elements from initial meshes
1845 //================================================================================
1847 SMESH::SMESH_Mesh_ptr
1848 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
1849 CORBA::Boolean theUniteIdenticalGroups,
1850 CORBA::Boolean theMergeNodesAndElements,
1851 CORBA::Double theMergeTolerance)
1852 throw ( SALOME::SALOME_Exception )
1854 return ConcatenateCommon(theMeshesArray,
1855 theUniteIdenticalGroups,
1856 theMergeNodesAndElements,
1861 //================================================================================
1863 * SMESH_Gen_i::ConcatenateCommon
1865 * Concatenate the given meshes into one mesh
1867 //================================================================================
1869 SMESH::SMESH_Mesh_ptr
1870 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
1871 CORBA::Boolean theUniteIdenticalGroups,
1872 CORBA::Boolean theMergeNodesAndElements,
1873 CORBA::Double theMergeTolerance,
1874 CORBA::Boolean theCommonGroups)
1875 throw ( SALOME::SALOME_Exception )
1877 typedef map<int, int> TIDsMap;
1878 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
1879 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
1880 typedef std::set<SMESHDS_GroupBase*> TGroups;
1882 TPythonDump aPythonDump; // prevent dump of called methods
1885 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
1887 if ( !aNewMesh->_is_nil() ) {
1888 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
1890 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
1891 SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
1893 TGroupsMap aGroupsMap;
1894 TListOfNewGroups aListOfNewGroups;
1895 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
1896 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
1899 for ( int i = 0; i < theMeshesArray.length(); i++) {
1900 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
1901 if ( !anInitMesh->_is_nil() ) {
1902 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
1904 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
1905 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
1910 // loop on elements of mesh
1911 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
1912 const SMDS_MeshElement* anElem = 0;
1913 const SMDS_MeshElement* aNewElem = 0;
1914 int anElemNbNodes = 0;
1919 int anNbVolumes = 0;
1921 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
1922 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
1923 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
1924 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
1926 if( theCommonGroups ) {
1927 anIDsNodes->length( anInitMeshDS->NbNodes() );
1928 anIDsEdges->length( anInitMeshDS->NbEdges() );
1929 anIDsFaces->length( anInitMeshDS->NbFaces() );
1930 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
1933 for ( int j = 0; itElems->more(); j++) {
1934 anElem = itElems->next();
1935 SMDSAbs_ElementType anElemType = anElem->GetType();
1936 anElemNbNodes = anElem->NbNodes();
1937 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
1939 // loop on nodes of element
1940 const SMDS_MeshNode* aNode = 0;
1941 const SMDS_MeshNode* aNewNode = 0;
1942 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
1944 for ( int k = 0; itNodes->more(); k++) {
1945 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
1946 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
1947 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
1948 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
1949 if( theCommonGroups )
1950 anIDsNodes[anNbNodes++] = aNewNode->GetID();
1953 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
1954 aNodesArray[k] = aNewNode;
1957 // creates a corresponding element on existent nodes in new mesh
1958 if ( anElem->IsPoly() && anElemType == SMDSAbs_Volume )
1960 const SMDS_PolyhedralVolumeOfNodes* aVolume =
1961 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
1963 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
1964 aVolume->GetQuanities());
1965 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1966 if( theCommonGroups )
1967 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
1972 aNewElem = aNewEditor.AddElement(aNodesArray,
1975 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
1976 if( theCommonGroups ) {
1977 if( anElemType == SMDSAbs_Edge )
1978 anIDsEdges[anNbEdges++] = aNewElem->GetID();
1979 else if( anElemType == SMDSAbs_Face )
1980 anIDsFaces[anNbFaces++] = aNewElem->GetID();
1981 else if( anElemType == SMDSAbs_Volume )
1982 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
1987 aListOfGroups = anInitImpl->GetGroups();
1988 SMESH::SMESH_GroupBase_ptr aGroup;
1990 // loop on groups of mesh
1991 SMESH::long_array_var anInitIDs = new SMESH::long_array();
1992 SMESH::long_array_var anNewIDs = new SMESH::long_array();
1993 SMESH::SMESH_Group_var aNewGroup;
1995 SMESH::ElementType aGroupType;
1996 CORBA::String_var aGroupName;
1997 if ( theCommonGroups ) {
1998 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::VOLUME;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
2000 SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
2002 str += aMeshSObj->GetName();
2007 switch(aGroupType) {
2010 anIDsNodes->length(anNbNodes);
2015 anIDsEdges->length(anNbEdges);
2020 anIDsFaces->length(anNbFaces);
2025 anIDsVolumes->length(anNbVolumes);
2026 anLen = anNbVolumes;
2033 aGroupName = str.c_str();
2035 // add a new group in the mesh
2036 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2038 switch(aGroupType) {
2040 aNewGroup->Add( anIDsNodes );
2043 aNewGroup->Add( anIDsEdges );
2046 aNewGroup->Add( anIDsFaces );
2049 aNewGroup->Add( anIDsVolumes );
2055 aListOfNewGroups.clear();
2056 aListOfNewGroups.push_back(aNewGroup);
2057 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2062 // check that current group name and type don't have identical ones in union mesh
2063 for (int i = 0; i < aListOfGroups->length(); i++) {
2064 aGroup = aListOfGroups[i];
2065 aListOfNewGroups.clear();
2066 aGroupType = aGroup->GetType();
2067 aGroupName = aGroup->GetName();
2069 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
2071 // convert a list of IDs
2072 anInitIDs = aGroup->GetListOfID();
2073 anNewIDs->length(anInitIDs->length());
2074 if ( aGroupType == SMESH::NODE )
2075 for (int j = 0; j < anInitIDs->length(); j++) {
2076 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
2079 for (int j = 0; j < anInitIDs->length(); j++) {
2080 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
2083 // check that current group name and type don't have identical ones in union mesh
2084 if ( anIter == aGroupsMap.end() ) {
2085 // add a new group in the mesh
2086 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2087 // add elements into new group
2088 aNewGroup->Add( anNewIDs );
2090 aListOfNewGroups.push_back(aNewGroup);
2091 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2094 else if ( theUniteIdenticalGroups ) {
2095 // unite identical groups
2096 TListOfNewGroups& aNewGroups = anIter->second;
2097 aNewGroups.front()->Add( anNewIDs );
2101 // rename identical groups
2102 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2103 aNewGroup->Add( anNewIDs );
2105 TListOfNewGroups& aNewGroups = anIter->second;
2106 string aNewGroupName;
2107 if (aNewGroups.size() == 1) {
2108 aNewGroupName = string(aGroupName) + "_1";
2109 aNewGroups.front()->SetName(aNewGroupName.c_str());
2111 char aGroupNum[128];
2112 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
2113 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
2114 aNewGroup->SetName(aNewGroupName.c_str());
2115 aNewGroups.push_back(aNewGroup);
2122 if (theMergeNodesAndElements) {
2124 set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
2125 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
2126 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
2127 aNewEditor.MergeNodes( aGroupsOfNodes );
2129 aNewEditor.MergeEqualElements();
2134 // Update Python script
2135 aPythonDump << aNewMesh << " = " << this;
2136 if( !theCommonGroups )
2137 aPythonDump << ".Concatenate(";
2139 aPythonDump << ".ConcatenateWithGroups(";
2141 for ( int i = 0; i < theMeshesArray.length(); i++) {
2142 if (i > 0) aPythonDump << ", ";
2143 aPythonDump << theMeshesArray[i];
2145 aPythonDump << "], ";
2146 aPythonDump << theUniteIdenticalGroups << ", "
2147 << theMergeNodesAndElements << ", "
2148 << theMergeTolerance << ")";
2150 return aNewMesh._retn();
2153 //=============================================================================
2157 * Save SMESH module's data
2159 //=============================================================================
2160 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
2164 INFOS( "SMESH_Gen_i::Save" );
2166 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
2167 // san -- in case <myCurrentStudy> differs from theComponent's study,
2168 // use that of the component
2169 if ( myCurrentStudy->_is_nil() ||
2170 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2171 SetCurrentStudy( theComponent->GetStudy() );
2173 // Store study contents as a set of python commands
2174 SavePython(myCurrentStudy);
2176 StudyContext* myStudyContext = GetCurrentStudyContext();
2178 // Declare a byte stream
2179 SALOMEDS::TMPFile_var aStreamFile;
2181 // Obtain a temporary dir
2182 TCollection_AsciiString tmpDir =
2183 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2185 // Create a sequence of files processed
2186 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2187 aFileSeq->length( NUM_TMP_FILES );
2189 TCollection_AsciiString aStudyName( "" );
2191 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2193 // Set names of temporary files
2194 TCollection_AsciiString filename =
2195 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
2196 TCollection_AsciiString meshfile =
2197 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
2198 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
2199 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
2200 filename = tmpDir + filename;
2201 meshfile = tmpDir + meshfile;
2204 HDFdataset* aDataset;
2205 HDFgroup* aTopGroup;
2207 HDFgroup* aSubGroup;
2208 HDFgroup* aSubSubGroup;
2209 hdf_size aSize[ 1 ];
2212 //Remove the files if they exist: BugID: 11225
2213 #ifndef WNT /* unix functionality */
2214 TCollection_AsciiString cmd("rm -f \"");
2216 TCollection_AsciiString cmd("del /F \"");
2223 system(cmd.ToCString());
2225 // MED writer to be used by storage process
2226 DriverMED_W_SMESHDS_Mesh myWriter;
2227 myWriter.SetFile( meshfile.ToCString() );
2230 // ---> create HDF file
2231 aFile = new HDFfile( (char*) filename.ToCString() );
2232 aFile->CreateOnDisk();
2234 // --> iterator for top-level objects
2235 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
2236 for ( ; itBig->More(); itBig->Next() ) {
2237 SALOMEDS::SObject_var gotBranch = itBig->Value();
2239 // --> hypotheses root branch (only one for the study)
2240 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
2241 // create hypotheses root HDF group
2242 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2243 aTopGroup->CreateOnDisk();
2245 // iterator for all hypotheses
2246 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
2247 for ( ; it->More(); it->Next() ) {
2248 SALOMEDS::SObject_var mySObject = it->Value();
2249 CORBA::Object_var anObject = SObjectToObject( mySObject );
2250 if ( !CORBA::is_nil( anObject ) ) {
2251 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2252 if ( !myHyp->_is_nil() ) {
2253 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2255 string hypname = string( myHyp->GetName() );
2256 string libname = string( myHyp->GetLibName() );
2258 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
2259 // WNT and ".so" for X-system) must be deleted
2260 int libname_len = libname.length();
2262 if( libname_len > 4 )
2263 libname.resize( libname_len - 4 );
2265 // PAL17753 (Regresion: missing hypothesis in restored study)
2266 // "lib" also should be removed from the beginning
2267 //if( libname_len > 3 )
2268 //libname.resize( libname_len - 3 );
2269 if( libname_len > 6 )
2270 libname = libname.substr( 3, libname_len - 3 - 3 );
2272 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2273 int id = myStudyContext->findId( string( objStr.in() ) );
2274 string hypdata = string( myImpl->SaveTo() );
2276 // for each hypothesis create HDF group basing on its id
2277 char hypGrpName[30];
2278 sprintf( hypGrpName, "Hypothesis %d", id );
2279 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2280 aGroup->CreateOnDisk();
2281 // --> type name of hypothesis
2282 aSize[ 0 ] = hypname.length() + 1;
2283 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
2284 aDataset->CreateOnDisk();
2285 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
2286 aDataset->CloseOnDisk();
2287 // --> server plugin library name of hypothesis
2288 aSize[ 0 ] = libname.length() + 1;
2289 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
2290 aDataset->CreateOnDisk();
2291 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
2292 aDataset->CloseOnDisk();
2293 // --> persistent data of hypothesis
2294 aSize[ 0 ] = hypdata.length() + 1;
2295 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
2296 aDataset->CreateOnDisk();
2297 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
2298 aDataset->CloseOnDisk();
2299 // close hypothesis HDF group
2300 aGroup->CloseOnDisk();
2305 // close hypotheses root HDF group
2306 aTopGroup->CloseOnDisk();
2308 // --> algorithms root branch (only one for the study)
2309 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
2310 // create algorithms root HDF group
2311 aTopGroup = new HDFgroup( "Algorithms", aFile );
2312 aTopGroup->CreateOnDisk();
2314 // iterator for all algorithms
2315 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
2316 for ( ; it->More(); it->Next() ) {
2317 SALOMEDS::SObject_var mySObject = it->Value();
2318 CORBA::Object_var anObject = SObjectToObject( mySObject );
2319 if ( !CORBA::is_nil( anObject ) ) {
2320 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2321 if ( !myHyp->_is_nil() ) {
2322 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2324 string hypname = string( myHyp->GetName() );
2325 string libname = string( myHyp->GetLibName() );
2327 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
2328 // WNT and ".so" for X-system) must be deleted
2329 int libname_len = libname.length();
2331 if( libname_len > 4 )
2332 libname.resize( libname_len - 4 );
2334 // PAL17753 (Regresion: missing hypothesis in restored study)
2335 // "lib" also should be removed from the beginning
2336 //if( libname_len > 3 )
2337 //libname.resize( libname_len - 3 );
2338 if( libname_len > 6 )
2339 libname = libname.substr( 3, libname_len - 3 - 3 );
2341 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2342 int id = myStudyContext->findId( string( objStr.in() ) );
2343 string hypdata = string( myImpl->SaveTo() );
2345 // for each algorithm create HDF group basing on its id
2346 char hypGrpName[30];
2347 sprintf( hypGrpName, "Algorithm %d", id );
2348 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2349 aGroup->CreateOnDisk();
2350 // --> type name of algorithm
2351 aSize[0] = hypname.length() + 1;
2352 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
2353 aDataset->CreateOnDisk();
2354 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
2355 aDataset->CloseOnDisk();
2356 // --> server plugin library name of hypothesis
2357 aSize[0] = libname.length() + 1;
2358 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
2359 aDataset->CreateOnDisk();
2360 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
2361 aDataset->CloseOnDisk();
2362 // --> persistent data of algorithm
2363 aSize[0] = hypdata.length() + 1;
2364 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
2365 aDataset->CreateOnDisk();
2366 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
2367 aDataset->CloseOnDisk();
2368 // close algorithm HDF group
2369 aGroup->CloseOnDisk();
2374 // close algorithms root HDF group
2375 aTopGroup->CloseOnDisk();
2377 // --> mesh objects roots branches
2378 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
2379 CORBA::Object_var anObject = SObjectToObject( gotBranch );
2380 if ( !CORBA::is_nil( anObject ) ) {
2381 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
2382 if ( !myMesh->_is_nil() ) {
2383 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
2385 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2386 int id = myStudyContext->findId( string( objStr.in() ) );
2387 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
2388 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2389 bool hasShape = myLocMesh.HasShapeToMesh();
2391 // for each mesh open the HDF group basing on its id
2392 char meshGrpName[ 30 ];
2393 sprintf( meshGrpName, "Mesh %d", id );
2394 aTopGroup = new HDFgroup( meshGrpName, aFile );
2395 aTopGroup->CreateOnDisk();
2397 // --> put dataset to hdf file which is a flag that mesh has data
2398 string strHasData = "0";
2399 // check if the mesh is not empty
2400 if ( mySMESHDSMesh->NbNodes() > 0 ) {
2401 // write mesh data to med file
2402 myWriter.SetMesh( mySMESHDSMesh );
2403 myWriter.SetMeshId( id );
2406 aSize[ 0 ] = strHasData.length() + 1;
2407 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
2408 aDataset->CreateOnDisk();
2409 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
2410 aDataset->CloseOnDisk();
2413 // for each mesh open the HDF group basing on its auto color parameter
2414 char meshAutoColorName[ 30 ];
2415 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
2417 anAutoColor[0] = myImpl->GetAutoColor();
2419 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
2420 aDataset->CreateOnDisk();
2421 aDataset->WriteOnDisk( anAutoColor );
2422 aDataset->CloseOnDisk();
2424 // write reference on a shape if exists
2425 SALOMEDS::SObject_var myRef;
2426 bool shapeRefFound = false;
2427 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
2429 SALOMEDS::SObject_var myShape;
2430 bool ok = myRef->ReferencedObject( myShape );
2432 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
2433 string myRefOnObject = myShape->GetID();
2434 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
2435 aSize[ 0 ] = myRefOnObject.length() + 1;
2436 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
2437 aDataset->CreateOnDisk();
2438 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2439 aDataset->CloseOnDisk();
2444 // write applied hypotheses if exist
2445 SALOMEDS::SObject_var myHypBranch;
2446 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
2447 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
2448 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
2450 if ( found && (shapeRefFound || !hasShape) ) {
2451 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2452 aGroup->CreateOnDisk();
2454 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
2456 for ( ; it->More(); it->Next() ) {
2457 SALOMEDS::SObject_var mySObject = it->Value();
2458 SALOMEDS::SObject_var myRefOnHyp;
2459 bool ok = mySObject->ReferencedObject( myRefOnHyp );
2461 // san - it is impossible to recover applied hypotheses
2462 // using their entries within Load() method,
2463 // for there are no AttributeIORs in the study when Load() is working.
2464 // Hence, it is better to store persistent IDs of hypotheses as references to them
2466 //string myRefOnObject = myRefOnHyp->GetID();
2467 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2468 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2469 int id = myStudyContext->findId( string( objStr.in() ) );
2470 //if ( myRefOnObject.length() > 0 ) {
2471 //aSize[ 0 ] = myRefOnObject.length() + 1;
2472 char hypName[ 30 ], hypId[ 30 ];
2473 sprintf( hypName, "Hyp %d", ++hypNb );
2474 sprintf( hypId, "%d", id );
2475 aSize[ 0 ] = strlen( hypId ) + 1;
2476 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
2477 aDataset->CreateOnDisk();
2478 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2479 aDataset->WriteOnDisk( hypId );
2480 aDataset->CloseOnDisk();
2484 aGroup->CloseOnDisk();
2487 // write applied algorithms if exist
2488 SALOMEDS::SObject_var myAlgoBranch;
2489 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
2490 if ( found && !shapeRefFound && hasShape) { // remove applied algos
2491 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
2493 if ( found && (shapeRefFound || !hasShape)) {
2494 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2495 aGroup->CreateOnDisk();
2497 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
2499 for ( ; it->More(); it->Next() ) {
2500 SALOMEDS::SObject_var mySObject = it->Value();
2501 SALOMEDS::SObject_var myRefOnAlgo;
2502 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
2504 // san - it is impossible to recover applied algorithms
2505 // using their entries within Load() method,
2506 // for there are no AttributeIORs in the study when Load() is working.
2507 // Hence, it is better to store persistent IDs of algorithms as references to them
2509 //string myRefOnObject = myRefOnAlgo->GetID();
2510 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2511 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2512 int id = myStudyContext->findId( string( objStr.in() ) );
2513 //if ( myRefOnObject.length() > 0 ) {
2514 //aSize[ 0 ] = myRefOnObject.length() + 1;
2515 char algoName[ 30 ], algoId[ 30 ];
2516 sprintf( algoName, "Algo %d", ++algoNb );
2517 sprintf( algoId, "%d", id );
2518 aSize[ 0 ] = strlen( algoId ) + 1;
2519 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
2520 aDataset->CreateOnDisk();
2521 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2522 aDataset->WriteOnDisk( algoId );
2523 aDataset->CloseOnDisk();
2527 aGroup->CloseOnDisk();
2530 // --> submesh objects sub-branches
2532 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
2533 SALOMEDS::SObject_var mySubmeshBranch;
2534 found = gotBranch->FindSubObject( i, mySubmeshBranch );
2536 if ( found ) // check if there is shape reference in submeshes
2538 bool hasShapeRef = false;
2539 SALOMEDS::ChildIterator_var itSM =
2540 myCurrentStudy->NewChildIterator( mySubmeshBranch );
2541 for ( ; itSM->More(); itSM->Next() ) {
2542 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
2543 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2544 mySubRef->ReferencedObject( myShape );
2545 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
2548 { // remove one submesh
2549 if ( shapeRefFound )
2550 { // unassign hypothesis
2551 SMESH::SMESH_subMesh_var mySubMesh =
2552 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
2553 if ( !mySubMesh->_is_nil() ) {
2554 int shapeID = mySubMesh->GetId();
2555 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
2556 const list<const SMESHDS_Hypothesis*>& hypList =
2557 mySMESHDSMesh->GetHypothesis( S );
2558 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
2559 while ( hyp != hypList.end() ) {
2560 int hypID = (*hyp++)->GetID(); // goto next hyp here because
2561 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
2565 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
2567 } // loop on submeshes of a type
2568 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
2569 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
2572 } // end check if there is shape reference in submeshes
2574 char name_meshgroup[ 30 ];
2575 if ( i == GetSubMeshOnVertexTag() )
2576 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2577 else if ( i == GetSubMeshOnEdgeTag() )
2578 strcpy( name_meshgroup, "SubMeshes On Edge" );
2579 else if ( i == GetSubMeshOnWireTag() )
2580 strcpy( name_meshgroup, "SubMeshes On Wire" );
2581 else if ( i == GetSubMeshOnFaceTag() )
2582 strcpy( name_meshgroup, "SubMeshes On Face" );
2583 else if ( i == GetSubMeshOnShellTag() )
2584 strcpy( name_meshgroup, "SubMeshes On Shell" );
2585 else if ( i == GetSubMeshOnSolidTag() )
2586 strcpy( name_meshgroup, "SubMeshes On Solid" );
2587 else if ( i == GetSubMeshOnCompoundTag() )
2588 strcpy( name_meshgroup, "SubMeshes On Compound" );
2590 // for each type of submeshes create container HDF group
2591 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2592 aGroup->CreateOnDisk();
2594 // iterator for all submeshes of given type
2595 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
2596 for ( ; itSM->More(); itSM->Next() ) {
2597 SALOMEDS::SObject_var mySObject = itSM->Value();
2598 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
2599 if ( !CORBA::is_nil( anSubObject ))
2601 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
2602 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
2603 int subid = myStudyContext->findId( string( objStr.in() ) );
2605 // for each mesh open the HDF group basing on its id
2606 char submeshGrpName[ 30 ];
2607 sprintf( submeshGrpName, "SubMesh %d", subid );
2608 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
2609 aSubGroup->CreateOnDisk();
2611 // write reference on a shape, already checked if it exists
2612 SALOMEDS::SObject_var mySubRef, myShape;
2613 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2614 mySubRef->ReferencedObject( myShape );
2615 string myRefOnObject = myShape->GetID();
2616 if ( myRefOnObject.length() > 0 ) {
2617 aSize[ 0 ] = myRefOnObject.length() + 1;
2618 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
2619 aDataset->CreateOnDisk();
2620 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2621 aDataset->CloseOnDisk();
2624 // write applied hypotheses if exist
2625 SALOMEDS::SObject_var mySubHypBranch;
2626 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
2628 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2629 aSubSubGroup->CreateOnDisk();
2631 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
2633 for ( ; it->More(); it->Next() ) {
2634 SALOMEDS::SObject_var mySubSObject = it->Value();
2635 SALOMEDS::SObject_var myRefOnHyp;
2636 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
2638 //string myRefOnObject = myRefOnHyp->GetID();
2639 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2640 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2641 int id = myStudyContext->findId( string( objStr.in() ) );
2642 //if ( myRefOnObject.length() > 0 ) {
2643 //aSize[ 0 ] = myRefOnObject.length() + 1;
2644 char hypName[ 30 ], hypId[ 30 ];
2645 sprintf( hypName, "Hyp %d", ++hypNb );
2646 sprintf( hypId, "%d", id );
2647 aSize[ 0 ] = strlen( hypId ) + 1;
2648 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
2649 aDataset->CreateOnDisk();
2650 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2651 aDataset->WriteOnDisk( hypId );
2652 aDataset->CloseOnDisk();
2656 aSubSubGroup->CloseOnDisk();
2659 // write applied algorithms if exist
2660 SALOMEDS::SObject_var mySubAlgoBranch;
2661 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
2663 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2664 aSubSubGroup->CreateOnDisk();
2666 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
2668 for ( ; it->More(); it->Next() ) {
2669 SALOMEDS::SObject_var mySubSObject = it->Value();
2670 SALOMEDS::SObject_var myRefOnAlgo;
2671 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
2673 //string myRefOnObject = myRefOnAlgo->GetID();
2674 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2675 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2676 int id = myStudyContext->findId( string( objStr.in() ) );
2677 //if ( myRefOnObject.length() > 0 ) {
2678 //aSize[ 0 ] = myRefOnObject.length() + 1;
2679 char algoName[ 30 ], algoId[ 30 ];
2680 sprintf( algoName, "Algo %d", ++algoNb );
2681 sprintf( algoId, "%d", id );
2682 aSize[ 0 ] = strlen( algoId ) + 1;
2683 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
2684 aDataset->CreateOnDisk();
2685 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2686 aDataset->WriteOnDisk( algoId );
2687 aDataset->CloseOnDisk();
2691 aSubSubGroup->CloseOnDisk();
2693 // close submesh HDF group
2694 aSubGroup->CloseOnDisk();
2697 // close container of submeshes by type HDF group
2698 aGroup->CloseOnDisk();
2701 // All sub-meshes will be stored in MED file
2702 // .. will NOT (PAL 12992)
2703 //if ( shapeRefFound )
2704 //myWriter.AddAllSubMeshes();
2706 // groups root sub-branch
2707 SALOMEDS::SObject_var myGroupsBranch;
2708 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
2709 found = gotBranch->FindSubObject( i, myGroupsBranch );
2711 char name_group[ 30 ];
2712 if ( i == GetNodeGroupsTag() )
2713 strcpy( name_group, "Groups of Nodes" );
2714 else if ( i == GetEdgeGroupsTag() )
2715 strcpy( name_group, "Groups of Edges" );
2716 else if ( i == GetFaceGroupsTag() )
2717 strcpy( name_group, "Groups of Faces" );
2718 else if ( i == GetVolumeGroupsTag() )
2719 strcpy( name_group, "Groups of Volumes" );
2721 aGroup = new HDFgroup( name_group, aTopGroup );
2722 aGroup->CreateOnDisk();
2724 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
2725 for ( ; it->More(); it->Next() ) {
2726 SALOMEDS::SObject_var mySObject = it->Value();
2727 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
2728 if ( !CORBA::is_nil( aSubObject ) ) {
2729 SMESH_GroupBase_i* myGroupImpl =
2730 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
2734 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
2735 int anId = myStudyContext->findId( string( objStr.in() ) );
2737 // For each group, create a dataset named "Group <group_persistent_id>"
2738 // and store the group's user name into it
2740 sprintf( grpName, "Group %d", anId );
2741 char* aUserName = myGroupImpl->GetName();
2742 aSize[ 0 ] = strlen( aUserName ) + 1;
2744 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
2745 aDataset->CreateOnDisk();
2746 aDataset->WriteOnDisk( aUserName );
2747 aDataset->CloseOnDisk();
2750 // For each group, create a dataset named "Group <group_persistent_id> Color"
2751 // and store the group's color into it
2752 char grpColorName[ 30 ];
2753 sprintf( grpColorName, "ColorGroup %d", anId );
2754 SALOMEDS::Color aColor = myGroupImpl->GetColor();
2756 anRGB[ 0 ] = aColor.R;
2757 anRGB[ 1 ] = aColor.G;
2758 anRGB[ 2 ] = aColor.B;
2760 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
2761 aDataset->CreateOnDisk();
2762 aDataset->WriteOnDisk( anRGB );
2763 aDataset->CloseOnDisk();
2765 // Store the group contents into MED file
2766 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
2768 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
2769 << grpName << " to MED file" );
2770 SMESHDS_GroupBase* aGrpBaseDS =
2771 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
2772 aGrpBaseDS->SetStoreName( grpName );
2774 // Pass SMESHDS_Group to MED writer
2775 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
2777 myWriter.AddGroup( aGrpDS );
2779 // write reference on a shape if exists
2780 SMESHDS_GroupOnGeom* aGeomGrp =
2781 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
2783 SALOMEDS::SObject_var mySubRef, myShape;
2784 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
2785 mySubRef->ReferencedObject( myShape ) &&
2786 !CORBA::is_nil( myShape->GetObject() ))
2788 string myRefOnObject = myShape->GetID();
2789 if ( myRefOnObject.length() > 0 ) {
2790 char aRefName[ 30 ];
2791 sprintf( aRefName, "Ref on shape %d", anId);
2792 aSize[ 0 ] = myRefOnObject.length() + 1;
2793 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
2794 aDataset->CreateOnDisk();
2795 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2796 aDataset->CloseOnDisk();
2799 else // shape ref is invalid:
2801 // save a group on geometry as ordinary group
2802 myWriter.AddGroup( aGeomGrp );
2808 aGroup->CloseOnDisk();
2812 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
2814 // Flush current mesh information into MED file
2817 // maybe a shape was deleted in the study
2818 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
2819 TopoDS_Shape nullShape;
2820 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
2823 if ( !mySMESHDSMesh->SubMeshes().empty() )
2827 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2828 aGroup->CreateOnDisk();
2830 // each element belongs to one or none submesh,
2831 // so for each node/element, we store a submesh ID
2833 // Make maps of submesh IDs of elements sorted by element IDs
2834 typedef int TElemID;
2835 typedef int TSubMID;
2836 map< TElemID, TSubMID > eId2smId, nId2smId;
2837 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
2838 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
2839 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
2840 SMDS_NodeIteratorPtr itNode;
2841 SMDS_ElemIteratorPtr itElem;
2842 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2844 TSubMID aSubMeID = itSubM->first;
2845 SMESHDS_SubMesh* aSubMesh = itSubM->second;
2846 if ( aSubMesh->IsComplexSubmesh() )
2847 continue; // submesh containing other submeshs
2849 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
2850 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
2851 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
2853 hint = eId2smId.begin();
2854 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
2855 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
2858 // Care of elements that are not on submeshes
2859 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
2860 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
2861 /* --- stl_map.h says : */
2862 /* A %map relies on unique keys and thus a %pair is only inserted if its */
2863 /* first element (the key) is not already present in the %map. */
2864 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
2866 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
2867 if ( nbElems != eId2smId.size() ) {
2868 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
2869 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
2872 // Store submesh IDs
2873 for ( int isNode = 0; isNode < 2; ++isNode )
2875 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
2876 if ( id2smId.empty() ) continue;
2877 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
2878 // make and fill array of submesh IDs
2879 int* smIDs = new int [ id2smId.size() ];
2880 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
2881 smIDs[ i ] = id_smId->second;
2883 aSize[ 0 ] = id2smId.size();
2884 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
2885 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2886 aDataset->CreateOnDisk();
2887 aDataset->WriteOnDisk( smIDs );
2888 aDataset->CloseOnDisk();
2893 // Store node positions on sub-shapes (SMDS_Position):
2894 // ----------------------------------------------------
2896 aGroup = new HDFgroup( "Node Positions", aTopGroup );
2897 aGroup->CreateOnDisk();
2899 // in aGroup, create 5 datasets to contain:
2900 // "Nodes on Edges" - ID of node on edge
2901 // "Edge positions" - U parameter on node on edge
2902 // "Nodes on Faces" - ID of node on face
2903 // "Face U positions" - U parameter of node on face
2904 // "Face V positions" - V parameter of node on face
2906 // Find out nb of nodes on edges and faces
2907 // Collect corresponing sub-meshes
2908 int nbEdgeNodes = 0, nbFaceNodes = 0;
2909 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
2910 // loop on SMESHDS_SubMesh'es
2911 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2913 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
2914 if ( aSubMesh->IsComplexSubmesh() )
2915 continue; // submesh containing other submeshs
2916 int nbNodes = aSubMesh->NbNodes();
2917 if ( nbNodes == 0 ) continue;
2919 int aShapeID = (*itSubM).first;
2920 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
2921 // write only SMDS_FacePosition and SMDS_EdgePosition
2922 switch ( aShapeType ) {
2924 nbFaceNodes += nbNodes;
2925 aFaceSM.push_back( aSubMesh );
2928 nbEdgeNodes += nbNodes;
2929 aEdgeSM.push_back( aSubMesh );
2935 // Treat positions on edges or faces
2936 for ( int onFace = 0; onFace < 2; onFace++ )
2938 // Create arrays to store in datasets
2939 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
2940 if (!nbNodes) continue;
2941 int* aNodeIDs = new int [ nbNodes ];
2942 double* aUPos = new double [ nbNodes ];
2943 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
2946 // loop on sub-meshes
2947 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
2948 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
2949 for ( ; itSM != pListSM->end(); itSM++ )
2951 SMESHDS_SubMesh* aSubMesh = (*itSM);
2953 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
2954 // loop on nodes in aSubMesh
2955 while ( itNode->more() )
2958 const SMDS_MeshNode* node = itNode->next();
2959 aNodeIDs [ iNode ] = node->GetID();
2962 const SMDS_PositionPtr pos = node->GetPosition();
2963 if ( onFace ) { // on FACE
2964 const SMDS_FacePosition* fPos =
2965 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
2967 aUPos[ iNode ] = fPos->GetUParameter();
2968 aVPos[ iNode ] = fPos->GetVParameter();
2975 const SMDS_EdgePosition* ePos =
2976 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
2978 aUPos[ iNode ] = ePos->GetUParameter();
2984 } // loop on nodes in aSubMesh
2985 } // loop on sub-meshes
2990 aSize[ 0 ] = nbNodes;
2992 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
2993 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
2994 aDataset->CreateOnDisk();
2995 aDataset->WriteOnDisk( aNodeIDs );
2996 aDataset->CloseOnDisk();
2999 aDSName = ( onFace ? "Face U positions" : "Edge positions");
3000 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
3001 aDataset->CreateOnDisk();
3002 aDataset->WriteOnDisk( aUPos );
3003 aDataset->CloseOnDisk();
3006 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
3007 aDataset->CreateOnDisk();
3008 aDataset->WriteOnDisk( aVPos );
3009 aDataset->CloseOnDisk();
3014 if ( aVPos ) delete [] aVPos;
3016 } // treat positions on edges or faces
3018 // close "Node Positions" group
3019 aGroup->CloseOnDisk();
3021 } // if ( there are submeshes in SMESHDS_Mesh )
3024 // close mesh HDF group
3025 aTopGroup->CloseOnDisk();
3033 aFile->CloseOnDisk();
3036 // Convert temporary files to stream
3037 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
3039 // Remove temporary files and directory
3041 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3043 INFOS( "SMESH_Gen_i::Save() completed" );
3044 return aStreamFile._retn();
3047 //=============================================================================
3049 * SMESH_Gen_i::SaveASCII
3051 * Save SMESH module's data in ASCII format
3053 //=============================================================================
3055 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
3057 bool isMultiFile ) {
3058 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
3059 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
3060 return aStreamFile._retn();
3062 //after usual saving needs to encipher binary to text string
3063 //Any binary symbol will be represent as "|xx" () hexadecimal format number
3064 int size = aStreamFile.in().length();
3065 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
3066 for ( int i = 0; i < size; i++ )
3067 sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
3069 buffer[size * 3] = '\0';
3071 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
3073 return anAsciiStreamFile._retn();
3076 //=============================================================================
3078 * SMESH_Gen_i::loadGeomData
3080 * Load GEOM module data
3082 //=============================================================================
3084 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
3086 if ( theCompRoot->_is_nil() )
3089 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
3090 if ( aStudy->_is_nil() )
3093 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3094 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
3096 //=============================================================================
3098 * \brief Creates SMDS_Position according to shape type
3100 //=============================================================================
3102 class PositionCreator {
3104 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
3105 return (this->*myFuncTable[ type ])();
3108 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
3109 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
3110 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
3111 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
3114 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
3115 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
3116 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
3117 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
3118 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
3119 vector<FmakePos> myFuncTable;
3122 //=============================================================================
3126 * Load SMESH module's data
3128 //=============================================================================
3130 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
3131 const SALOMEDS::TMPFile& theStream,
3135 INFOS( "SMESH_Gen_i::Load" );
3137 if ( myCurrentStudy->_is_nil() ||
3138 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
3139 SetCurrentStudy( theComponent->GetStudy() );
3141 /* if( !theComponent->_is_nil() )
3143 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
3144 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
3145 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
3148 StudyContext* myStudyContext = GetCurrentStudyContext();
3150 // Get temporary files location
3151 TCollection_AsciiString tmpDir =
3152 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
3154 INFOS( "THE URL++++++++++++++" )
3156 INFOS( "THE TMP PATH+++++++++" );
3159 // Convert the stream into sequence of files to process
3160 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
3163 TCollection_AsciiString aStudyName( "" );
3165 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
3167 // Set names of temporary files
3168 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
3169 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
3173 HDFdataset* aDataset;
3174 HDFgroup* aTopGroup;
3176 HDFgroup* aSubGroup;
3177 HDFgroup* aSubSubGroup;
3180 // ---> open HDF file
3181 aFile = new HDFfile( (char*) filename.ToCString() );
3183 aFile->OpenOnDisk( HDF_RDONLY );
3185 catch ( HDFexception ) {
3186 INFOS( "Load(): " << filename << " not found!" );
3190 DriverMED_R_SMESHDS_Mesh myReader;
3191 myReader.SetFile( meshfile.ToCString() );
3193 // For PAL13473 ("Repetitive mesh") implementation.
3194 // New dependencies between SMESH objects are established:
3195 // now hypotheses can refer to meshes, shapes and other hypotheses.
3196 // To keep data consistent, the following order of data restoration
3198 // 1. Create hypotheses
3199 // 2. Create all meshes
3200 // 3. Load hypotheses' data
3203 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
3204 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
3206 // get total number of top-level groups
3207 int aNbGroups = aFile->nInternalObjects();
3208 if ( aNbGroups > 0 ) {
3209 // --> in first turn we should read&create hypotheses
3210 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
3211 // open hypotheses root HDF group
3212 aTopGroup = new HDFgroup( "Hypotheses", aFile );
3213 aTopGroup->OpenOnDisk();
3215 // get number of hypotheses
3216 int aNbObjects = aTopGroup->nInternalObjects();
3217 for ( int j = 0; j < aNbObjects; j++ ) {
3218 // try to identify hypothesis
3219 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
3220 aTopGroup->InternalObjectIndentify( j, hypGrpName );
3222 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
3223 // open hypothesis group
3224 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3225 aGroup->OpenOnDisk();
3227 // --> get hypothesis id
3228 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
3233 // get number of datasets
3234 int aNbSubObjects = aGroup->nInternalObjects();
3235 for ( int k = 0; k < aNbSubObjects; k++ ) {
3237 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
3238 aGroup->InternalObjectIndentify( k, name_of_subgroup );
3239 // --> get hypothesis name
3240 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
3241 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3242 aDataset->OpenOnDisk();
3243 size = aDataset->GetSize();
3244 char* hypname_str = new char[ size ];
3245 aDataset->ReadFromDisk( hypname_str );
3246 hypname = string( hypname_str );
3247 delete [] hypname_str;
3248 aDataset->CloseOnDisk();
3250 // --> get hypothesis plugin library name
3251 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
3252 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3253 aDataset->OpenOnDisk();
3254 size = aDataset->GetSize();
3255 char* libname_str = new char[ size ];
3256 aDataset->ReadFromDisk( libname_str );
3257 if(MYDEBUG) SCRUTE( libname_str );
3258 libname = string( libname_str );
3259 delete [] libname_str;
3260 aDataset->CloseOnDisk();
3262 // --> get hypothesis data
3263 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
3264 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3265 aDataset->OpenOnDisk();
3266 size = aDataset->GetSize();
3267 char* hypdata_str = new char[ size ];
3268 aDataset->ReadFromDisk( hypdata_str );
3269 hypdata = string( hypdata_str );
3270 delete [] hypdata_str;
3271 aDataset->CloseOnDisk();
3274 // close hypothesis HDF group
3275 aGroup->CloseOnDisk();
3277 // --> restore hypothesis from data
3278 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
3279 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
3280 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
3281 SMESH::SMESH_Hypothesis_var myHyp;
3283 try { // protect persistence mechanism against exceptions
3284 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
3287 INFOS( "Exception during hypothesis creation" );
3290 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3292 // myImpl->LoadFrom( hypdata.c_str() );
3293 hypDataList.push_back( make_pair( myImpl, hypdata ));
3294 string iorString = GetORB()->object_to_string( myHyp );
3295 int newId = myStudyContext->findId( iorString );
3296 myStudyContext->mapOldToNew( id, newId );
3299 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
3303 // close hypotheses root HDF group
3304 aTopGroup->CloseOnDisk();
3308 // --> then we should read&create algorithms
3309 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
3310 // open algorithms root HDF group
3311 aTopGroup = new HDFgroup( "Algorithms", aFile );
3312 aTopGroup->OpenOnDisk();
3314 // get number of algorithms
3315 int aNbObjects = aTopGroup->nInternalObjects();
3316 for ( int j = 0; j < aNbObjects; j++ ) {
3317 // try to identify algorithm
3318 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
3319 aTopGroup->InternalObjectIndentify( j, hypGrpName );
3321 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
3322 // open algorithm group
3323 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3324 aGroup->OpenOnDisk();
3326 // --> get algorithm id
3327 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
3332 // get number of datasets
3333 int aNbSubObjects = aGroup->nInternalObjects();
3334 for ( int k = 0; k < aNbSubObjects; k++ ) {
3336 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
3337 aGroup->InternalObjectIndentify( k, name_of_subgroup );
3338 // --> get algorithm name
3339 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
3340 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3341 aDataset->OpenOnDisk();
3342 size = aDataset->GetSize();
3343 char* hypname_str = new char[ size ];
3344 aDataset->ReadFromDisk( hypname_str );
3345 hypname = string( hypname_str );
3346 delete [] hypname_str;
3347 aDataset->CloseOnDisk();
3349 // --> get algorithm plugin library name
3350 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
3351 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3352 aDataset->OpenOnDisk();
3353 size = aDataset->GetSize();
3354 char* libname_str = new char[ size ];
3355 aDataset->ReadFromDisk( libname_str );
3356 if(MYDEBUG) SCRUTE( libname_str );
3357 libname = string( libname_str );
3358 delete [] libname_str;
3359 aDataset->CloseOnDisk();
3361 // --> get algorithm data
3362 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
3363 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3364 aDataset->OpenOnDisk();
3365 size = aDataset->GetSize();
3366 char* hypdata_str = new char[ size ];
3367 aDataset->ReadFromDisk( hypdata_str );
3368 if(MYDEBUG) SCRUTE( hypdata_str );
3369 hypdata = string( hypdata_str );
3370 delete [] hypdata_str;
3371 aDataset->CloseOnDisk();
3374 // close algorithm HDF group
3375 aGroup->CloseOnDisk();
3377 // --> restore algorithm from data
3378 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
3379 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
3380 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
3381 SMESH::SMESH_Hypothesis_var myHyp;
3383 try { // protect persistence mechanism against exceptions
3384 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
3387 INFOS( "Exception during hypothesis creation" );
3390 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3392 //myImpl->LoadFrom( hypdata.c_str() );
3393 hypDataList.push_back( make_pair( myImpl, hypdata ));
3394 string iorString = GetORB()->object_to_string( myHyp );
3395 int newId = myStudyContext->findId( iorString );
3396 myStudyContext->mapOldToNew( id, newId );
3399 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
3403 // close algorithms root HDF group
3404 aTopGroup->CloseOnDisk();
3408 // --> the rest groups should be meshes
3409 for ( int i = 0; i < aNbGroups; i++ ) {
3410 // identify next group
3411 char meshName[ HDF_NAME_MAX_LEN+1 ];
3412 aFile->InternalObjectIndentify( i, meshName );
3414 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
3416 int id = atoi( string( meshName ).substr( 4 ).c_str() );
3420 // open mesh HDF group
3421 aTopGroup = new HDFgroup( meshName, aFile );
3422 aTopGroup->OpenOnDisk();
3424 // get number of child HDF objects
3425 int aNbObjects = aTopGroup->nInternalObjects();
3426 if ( aNbObjects > 0 ) {
3428 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
3429 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
3430 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
3431 if ( !myNewMeshImpl )
3433 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
3435 string iorString = GetORB()->object_to_string( myNewMesh );
3436 int newId = myStudyContext->findId( iorString );
3437 myStudyContext->mapOldToNew( id, newId );
3440 // try to read and set auto color flag
3441 char aMeshAutoColorName[ 30 ];
3442 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
3443 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
3445 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
3446 aDataset->OpenOnDisk();
3447 size = aDataset->GetSize();
3448 int* anAutoColor = new int[ size ];
3449 aDataset->ReadFromDisk( anAutoColor );
3450 aDataset->CloseOnDisk();
3451 myNewMeshImpl->SetAutoColor( (bool)anAutoColor[0] );
3454 // try to read and set reference to shape
3455 GEOM::GEOM_Object_var aShapeObject;
3456 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
3457 // load mesh "Ref on shape" - it's an entry to SObject
3458 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
3459 aDataset->OpenOnDisk();
3460 size = aDataset->GetSize();
3461 char* refFromFile = new char[ size ];
3462 aDataset->ReadFromDisk( refFromFile );
3463 aDataset->CloseOnDisk();
3464 if ( strlen( refFromFile ) > 0 ) {
3465 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3467 // Make sure GEOM data are loaded first
3468 //loadGeomData( shapeSO->GetFatherComponent() );
3470 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3471 if ( !CORBA::is_nil( shapeObject ) ) {
3472 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3473 if ( !aShapeObject->_is_nil() )
3474 myNewMeshImpl->SetShape( aShapeObject );
3483 // As all object that can be referred by hypothesis are created,
3484 // we can restore hypothesis data
3486 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
3487 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
3489 SMESH_Hypothesis_i* hyp = hyp_data->first;
3490 string & data = hyp_data->second;
3491 hyp->LoadFrom( data.c_str() );
3494 // Restore the rest mesh data
3496 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
3497 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
3499 aTopGroup = meshi_group->second;
3500 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
3501 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
3502 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3504 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
3505 bool hasData = false;
3508 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
3509 int newId = myStudyContext->findId( iorString );
3510 int id = myStudyContext->getOldId( newId );
3512 // try to find mesh data dataset
3513 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
3514 // load mesh "has data" flag
3515 aDataset = new HDFdataset( "Has data", aTopGroup );
3516 aDataset->OpenOnDisk();
3517 size = aDataset->GetSize();
3518 char* strHasData = new char[ size ];
3519 aDataset->ReadFromDisk( strHasData );
3520 aDataset->CloseOnDisk();
3521 if ( strcmp( strHasData, "1") == 0 ) {
3522 // read mesh data from MED file
3523 myReader.SetMesh( mySMESHDSMesh );
3524 myReader.SetMeshId( id );
3530 // try to get applied algorithms
3531 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3532 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3533 aGroup->OpenOnDisk();
3534 // get number of applied algorithms
3535 int aNbSubObjects = aGroup->nInternalObjects();
3536 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
3537 for ( int j = 0; j < aNbSubObjects; j++ ) {
3538 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3539 aGroup->InternalObjectIndentify( j, name_dataset );
3540 // check if it is an algorithm
3541 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3542 aDataset = new HDFdataset( name_dataset, aGroup );
3543 aDataset->OpenOnDisk();
3544 size = aDataset->GetSize();
3545 char* refFromFile = new char[ size ];
3546 aDataset->ReadFromDisk( refFromFile );
3547 aDataset->CloseOnDisk();
3549 // san - it is impossible to recover applied algorithms using their entries within Load() method
3551 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3552 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3553 int id = atoi( refFromFile );
3554 string anIOR = myStudyContext->getIORbyOldId( id );
3555 if ( !anIOR.empty() ) {
3556 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3557 if ( !CORBA::is_nil( hypObject ) ) {
3558 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3559 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3560 || !myNewMeshImpl->HasShapeToMesh()) )
3561 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3566 aGroup->CloseOnDisk();
3569 // try to get applied hypotheses
3570 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3571 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3572 aGroup->OpenOnDisk();
3573 // get number of applied hypotheses
3574 int aNbSubObjects = aGroup->nInternalObjects();
3575 for ( int j = 0; j < aNbSubObjects; j++ ) {
3576 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3577 aGroup->InternalObjectIndentify( j, name_dataset );
3578 // check if it is a hypothesis
3579 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3580 aDataset = new HDFdataset( name_dataset, aGroup );
3581 aDataset->OpenOnDisk();
3582 size = aDataset->GetSize();
3583 char* refFromFile = new char[ size ];
3584 aDataset->ReadFromDisk( refFromFile );
3585 aDataset->CloseOnDisk();
3587 // san - it is impossible to recover applied hypotheses using their entries within Load() method
3589 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3590 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3591 int id = atoi( refFromFile );
3592 string anIOR = myStudyContext->getIORbyOldId( id );
3593 if ( !anIOR.empty() ) {
3594 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3595 if ( !CORBA::is_nil( hypObject ) ) {
3596 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3597 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3598 || !myNewMeshImpl->HasShapeToMesh()) )
3599 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3604 aGroup->CloseOnDisk();
3607 // --> try to find submeshes containers for each type of submesh
3608 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
3609 char name_meshgroup[ 30 ];
3610 if ( j == GetSubMeshOnVertexTag() )
3611 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3612 else if ( j == GetSubMeshOnEdgeTag() )
3613 strcpy( name_meshgroup, "SubMeshes On Edge" );
3614 else if ( j == GetSubMeshOnWireTag() )
3615 strcpy( name_meshgroup, "SubMeshes On Wire" );
3616 else if ( j == GetSubMeshOnFaceTag() )
3617 strcpy( name_meshgroup, "SubMeshes On Face" );
3618 else if ( j == GetSubMeshOnShellTag() )
3619 strcpy( name_meshgroup, "SubMeshes On Shell" );
3620 else if ( j == GetSubMeshOnSolidTag() )
3621 strcpy( name_meshgroup, "SubMeshes On Solid" );
3622 else if ( j == GetSubMeshOnCompoundTag() )
3623 strcpy( name_meshgroup, "SubMeshes On Compound" );
3625 // try to get submeshes container HDF group
3626 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
3627 // open submeshes containers HDF group
3628 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3629 aGroup->OpenOnDisk();
3631 // get number of submeshes
3632 int aNbSubMeshes = aGroup->nInternalObjects();
3633 for ( int k = 0; k < aNbSubMeshes; k++ ) {
3635 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
3636 aGroup->InternalObjectIndentify( k, name_submeshgroup );
3637 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
3638 // --> get submesh id
3639 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
3642 // open submesh HDF group
3643 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
3644 aSubGroup->OpenOnDisk();
3646 // try to read and set reference to subshape
3647 GEOM::GEOM_Object_var aSubShapeObject;
3648 SMESH::SMESH_subMesh_var aSubMesh;
3650 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
3651 // load submesh "Ref on shape" - it's an entry to SObject
3652 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
3653 aDataset->OpenOnDisk();
3654 size = aDataset->GetSize();
3655 char* refFromFile = new char[ size ];
3656 aDataset->ReadFromDisk( refFromFile );
3657 aDataset->CloseOnDisk();
3658 if ( strlen( refFromFile ) > 0 ) {
3659 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
3660 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
3661 if ( !CORBA::is_nil( subShapeObject ) ) {
3662 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
3663 if ( !aSubShapeObject->_is_nil() )
3664 aSubMesh = SMESH::SMESH_subMesh::_duplicate
3665 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
3666 if ( aSubMesh->_is_nil() )
3668 string iorSubString = GetORB()->object_to_string( aSubMesh );
3669 int newSubId = myStudyContext->findId( iorSubString );
3670 myStudyContext->mapOldToNew( subid, newSubId );
3675 if ( aSubMesh->_is_nil() )
3678 // VSR: Get submesh data from MED convertor
3679 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
3680 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
3681 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
3682 // subid << " for subshape # " << anInternalSubmeshId);
3683 // SMESHDS_SubMesh* aSubMeshDS =
3684 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
3685 // if ( !aSubMeshDS ) {
3686 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
3687 // anInternalSubmeshId << " in current mesh!");
3690 // myReader.GetSubMesh( aSubMeshDS, subid );
3693 // try to get applied algorithms
3694 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3695 // open "applied algorithms" HDF group
3696 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3697 aSubSubGroup->OpenOnDisk();
3698 // get number of applied algorithms
3699 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3700 for ( int l = 0; l < aNbSubObjects; l++ ) {
3701 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3702 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3703 // check if it is an algorithm
3704 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3705 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3706 aDataset->OpenOnDisk();
3707 size = aDataset->GetSize();
3708 char* refFromFile = new char[ size ];
3709 aDataset->ReadFromDisk( refFromFile );
3710 aDataset->CloseOnDisk();
3712 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3713 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3714 int id = atoi( refFromFile );
3715 string anIOR = myStudyContext->getIORbyOldId( id );
3716 if ( !anIOR.empty() ) {
3717 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3718 if ( !CORBA::is_nil( hypObject ) ) {
3719 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3720 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3721 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3726 // close "applied algorithms" HDF group
3727 aSubSubGroup->CloseOnDisk();
3730 // try to get applied hypotheses
3731 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3732 // open "applied hypotheses" HDF group
3733 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3734 aSubSubGroup->OpenOnDisk();
3735 // get number of applied hypotheses
3736 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3737 for ( int l = 0; l < aNbSubObjects; l++ ) {
3738 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3739 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3740 // check if it is a hypothesis
3741 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3742 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3743 aDataset->OpenOnDisk();
3744 size = aDataset->GetSize();
3745 char* refFromFile = new char[ size ];
3746 aDataset->ReadFromDisk( refFromFile );
3747 aDataset->CloseOnDisk();
3749 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3750 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3751 int id = atoi( refFromFile );
3752 string anIOR = myStudyContext->getIORbyOldId( id );
3753 if ( !anIOR.empty() ) {
3754 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3755 if ( !CORBA::is_nil( hypObject ) ) {
3756 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3757 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3758 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3763 // close "applied hypotheses" HDF group
3764 aSubSubGroup->CloseOnDisk();
3767 // close submesh HDF group
3768 aSubGroup->CloseOnDisk();
3771 // close submeshes containers HDF group
3772 aGroup->CloseOnDisk();
3778 // Read sub-meshes from MED
3779 // -------------------------
3780 if(MYDEBUG) MESSAGE("Create all sub-meshes");
3781 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
3782 if ( submeshesInFamilies )
3784 // old way working before fix of PAL 12992
3785 myReader.CreateAllSubMeshes();
3790 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3791 aGroup->OpenOnDisk();
3793 int maxID = mySMESHDSMesh->MaxShapeIndex();
3794 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
3795 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
3797 PositionCreator aPositionCreator;
3799 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
3800 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
3801 for ( int isNode = 0; isNode < 2; ++isNode )
3803 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3804 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
3806 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
3807 aDataset->OpenOnDisk();
3808 // read submesh IDs for all elements sorted by ID
3809 int nbElems = aDataset->GetSize();
3810 int* smIDs = new int [ nbElems ];
3811 aDataset->ReadFromDisk( smIDs );
3812 aDataset->CloseOnDisk();
3814 // get elements sorted by ID
3815 TIDSortedElemSet elemSet;
3817 while ( nIt->more() ) elemSet.insert( nIt->next() );
3819 while ( eIt->more() ) elemSet.insert( eIt->next() );
3820 //ASSERT( elemSet.size() == nbElems ); -- issue 20182
3821 // -- Most probably a bad study was saved when there were
3822 // not fixed bugs in SMDS_MeshInfo
3823 if ( elemSet.size() < nbElems ) {
3825 cout << "SMESH_Gen_i::Load(), warning: Node position data is invalid" << endl;
3827 nbElems = elemSet.size();
3829 // add elements to submeshes
3830 TIDSortedElemSet::iterator iE = elemSet.begin();
3831 for ( int i = 0; i < nbElems; ++i, ++iE )
3833 int smID = smIDs[ i ];
3834 if ( smID == 0 ) continue;
3835 const SMDS_MeshElement* elem = *iE;
3836 if( smID > maxID ) {
3837 // corresponding subshape no longer exists: maybe geom group has been edited
3838 if ( myNewMeshImpl->HasShapeToMesh() )
3839 mySMESHDSMesh->RemoveElement( elem );
3842 // get or create submesh
3843 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
3845 sm = mySMESHDSMesh->NewSubMesh( smID );
3846 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
3850 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
3851 pos->SetShapeId( smID );
3852 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
3853 node->SetPosition( pos );
3854 sm->AddNode( node );
3856 sm->AddElement( elem );
3862 } // end reading submeshes
3864 // Read node positions on sub-shapes (SMDS_Position)
3866 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
3868 // There are 5 datasets to read:
3869 // "Nodes on Edges" - ID of node on edge
3870 // "Edge positions" - U parameter on node on edge
3871 // "Nodes on Faces" - ID of node on face
3872 // "Face U positions" - U parameter of node on face
3873 // "Face V positions" - V parameter of node on face
3874 const char* aEid_DSName = "Nodes on Edges";
3875 const char* aEu_DSName = "Edge positions";
3876 const char* aFu_DSName = "Face U positions";
3877 //char* aFid_DSName = "Nodes on Faces";
3878 //char* aFv_DSName = "Face V positions";
3881 int nbEids = 0, nbFids = 0;
3882 int *aEids = 0, *aFids = 0;
3883 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
3886 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3887 aGroup->OpenOnDisk();
3889 // loop on 5 data sets
3890 int aNbObjects = aGroup->nInternalObjects();
3891 for ( int i = 0; i < aNbObjects; i++ )
3894 char aDSName[ HDF_NAME_MAX_LEN+1 ];
3895 aGroup->InternalObjectIndentify( i, aDSName );
3897 aDataset = new HDFdataset( aDSName, aGroup );
3898 aDataset->OpenOnDisk();
3899 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
3901 double* pos = new double [ aDataset->GetSize() ];
3902 aDataset->ReadFromDisk( pos );
3904 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
3906 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
3913 int aSize = aDataset->GetSize();
3915 // for reading files, created from 18.07.2005 till 10.10.2005
3916 if (aDataset->GetType() == HDF_STRING)
3917 aSize /= sizeof(int);
3919 int* ids = new int [aSize];
3920 aDataset->ReadFromDisk( ids );
3921 // on face or nodes?
3922 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
3931 aDataset->CloseOnDisk();
3932 } // loop on 5 datasets
3934 // Set node positions on edges or faces
3935 for ( int onFace = 0; onFace < 2; onFace++ )
3937 int nbNodes = ( onFace ? nbFids : nbEids );
3938 if ( nbNodes == 0 ) continue;
3939 int* aNodeIDs = ( onFace ? aFids : aEids );
3940 double* aUPos = ( onFace ? aFupos : aEpos );
3941 double* aVPos = ( onFace ? aFvpos : 0 );
3943 for ( int iNode = 0; iNode < nbNodes; iNode++ )
3945 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
3946 if ( !node ) continue; // maybe removed while Loading() if geometry changed
3947 SMDS_PositionPtr aPos = node->GetPosition();
3950 // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );-- issue 20182
3951 // -- Most probably a bad study was saved when there were
3952 // not fixed bugs in SMDS_MeshInfo
3953 if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
3954 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
3955 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
3956 fPos->SetUParameter( aUPos[ iNode ]);
3957 fPos->SetVParameter( aVPos[ iNode ]);
3961 // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
3962 if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
3963 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
3964 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
3965 fPos->SetUParameter( aUPos[ iNode ]);
3970 if ( aEids ) delete [] aEids;
3971 if ( aFids ) delete [] aFids;
3972 if ( aEpos ) delete [] aEpos;
3973 if ( aFupos ) delete [] aFupos;
3974 if ( aFvpos ) delete [] aFvpos;
3976 aGroup->CloseOnDisk();
3978 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
3981 // Recompute State (as computed sub-meshes are restored from MED)
3982 if ( !aShapeObject->_is_nil() || !myNewMeshImpl->HasShapeToMesh()) {
3983 MESSAGE("Compute State Engine ...");
3984 TopoDS_Shape myLocShape;
3985 if(myNewMeshImpl->HasShapeToMesh())
3986 myLocShape = GeomObjectToShape( aShapeObject );
3988 myLocShape = SMESH_Mesh::PseudoShape();
3990 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
3991 (SMESH_subMesh::SUBMESH_RESTORED);
3992 MESSAGE("Compute State Engine finished");
3995 // try to get groups
3996 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
3997 char name_group[ 30 ];
3998 if ( ii == GetNodeGroupsTag() )
3999 strcpy( name_group, "Groups of Nodes" );
4000 else if ( ii == GetEdgeGroupsTag() )
4001 strcpy( name_group, "Groups of Edges" );
4002 else if ( ii == GetFaceGroupsTag() )
4003 strcpy( name_group, "Groups of Faces" );
4004 else if ( ii == GetVolumeGroupsTag() )
4005 strcpy( name_group, "Groups of Volumes" );
4007 if ( aTopGroup->ExistInternalObject( name_group ) ) {
4008 aGroup = new HDFgroup( name_group, aTopGroup );
4009 aGroup->OpenOnDisk();
4010 // get number of groups
4011 int aNbSubObjects = aGroup->nInternalObjects();
4012 for ( int j = 0; j < aNbSubObjects; j++ ) {
4013 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4014 aGroup->InternalObjectIndentify( j, name_dataset );
4015 // check if it is an group
4016 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
4018 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
4021 aDataset = new HDFdataset( name_dataset, aGroup );
4022 aDataset->OpenOnDisk();
4024 // Retrieve actual group name
4025 size = aDataset->GetSize();
4026 char* nameFromFile = new char[ size ];
4027 aDataset->ReadFromDisk( nameFromFile );
4028 aDataset->CloseOnDisk();
4030 // Try to find a shape reference
4031 TopoDS_Shape aShape;
4032 char aRefName[ 30 ];
4033 sprintf( aRefName, "Ref on shape %d", subid);
4034 if ( aGroup->ExistInternalObject( aRefName ) ) {
4035 // load mesh "Ref on shape" - it's an entry to SObject
4036 aDataset = new HDFdataset( aRefName, aGroup );
4037 aDataset->OpenOnDisk();
4038 size = aDataset->GetSize();
4039 char* refFromFile = new char[ size ];
4040 aDataset->ReadFromDisk( refFromFile );
4041 aDataset->CloseOnDisk();
4042 if ( strlen( refFromFile ) > 0 ) {
4043 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4044 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4045 if ( !CORBA::is_nil( shapeObject ) ) {
4046 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4047 if ( !aShapeObject->_is_nil() )
4048 aShape = GeomObjectToShape( aShapeObject );
4052 // Create group servant
4053 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
4054 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
4055 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
4056 // Obtain a SMESHDS_Group object
4057 if ( aNewGroup->_is_nil() )
4060 string iorSubString = GetORB()->object_to_string( aNewGroup );
4061 int newSubId = myStudyContext->findId( iorSubString );
4062 myStudyContext->mapOldToNew( subid, newSubId );
4064 SMESH_GroupBase_i* aGroupImpl =
4065 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
4069 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
4073 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
4074 aGroupBaseDS->SetStoreName( name_dataset );
4077 // Read color of the group
4078 char aGroupColorName[ 30 ];
4079 sprintf( aGroupColorName, "ColorGroup %d", subid);
4080 if ( aGroup->ExistInternalObject( aGroupColorName ) )
4082 aDataset = new HDFdataset( aGroupColorName, aGroup );
4083 aDataset->OpenOnDisk();
4084 size = aDataset->GetSize();
4085 double* anRGB = new double[ size ];
4086 aDataset->ReadFromDisk( anRGB );
4087 aDataset->CloseOnDisk();
4088 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
4089 aGroupBaseDS->SetColor( aColor );
4092 // Fill group with contents from MED file
4093 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
4095 myReader.GetGroup( aGrp );
4098 aGroup->CloseOnDisk();
4104 aTopGroup->CloseOnDisk();
4107 aFile->CloseOnDisk();
4110 // Remove temporary files created from the stream
4112 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
4114 INFOS( "SMESH_Gen_i::Load completed" );
4118 //=============================================================================
4120 * SMESH_Gen_i::LoadASCII
4122 * Load SMESH module's data in ASCII format
4124 //=============================================================================
4126 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
4127 const SALOMEDS::TMPFile& theStream,
4129 bool isMultiFile ) {
4130 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
4131 return Load( theComponent, theStream, theURL, isMultiFile );
4133 //before call main ::Load method it's need for decipher text format to
4134 //binary ( "|xx" => x' )
4135 int size = theStream.length();
4136 if ( int((size / 3 )*3) != size ) //error size of buffer
4139 int real_size = int(size / 3);
4141 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
4145 for ( int i = 0; i < real_size; i++ )
4147 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
4148 sscanf( tmp, "%x", &c );
4149 sprintf( (char*)&(buffer[i]), "%c", (char)c );
4152 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
4154 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
4157 //=============================================================================
4159 * SMESH_Gen_i::Close
4161 * Clears study-connected data when it is closed
4163 //=============================================================================
4165 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
4167 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
4169 // set correct current study
4170 if (theComponent->GetStudy()->StudyId() != GetCurrentStudyID())
4171 SetCurrentStudy(theComponent->GetStudy());
4173 // Clear study contexts data
4174 int studyId = GetCurrentStudyID();
4175 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
4176 delete myStudyContextMap[ studyId ];
4177 myStudyContextMap.erase( studyId );
4180 // delete SMESH_Mesh's
4181 // See bug IPAL19437.
4183 // StudyContextStruct* context = myGen.GetStudyContext( studyId );
4184 // map< int, SMESH_Mesh* >::iterator i_mesh = context->mapMesh.begin();
4185 // for ( ; i_mesh != context->mapMesh.end(); ++i_mesh ) {
4186 // printf( "--------------------------- SMESH_Gen_i::Close, delete aGroup = %p \n", i_mesh->second );
4187 // delete i_mesh->second;
4191 // delete SMESHDS_Mesh's
4192 // it's too long on big meshes
4193 // if ( context->myDocument ) {
4194 // delete context->myDocument;
4195 // context->myDocument = 0;
4201 //=============================================================================
4203 * SMESH_Gen_i::ComponentDataType
4205 * Get component data type
4207 //=============================================================================
4209 char* SMESH_Gen_i::ComponentDataType()
4211 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
4212 return CORBA::string_dup( "SMESH" );
4216 //=============================================================================
4218 * SMESH_Gen_i::IORToLocalPersistentID
4220 * Transform data from transient form to persistent
4222 //=============================================================================
4224 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
4225 const char* IORString,
4226 CORBA::Boolean /*isMultiFile*/,
4227 CORBA::Boolean /*isASCII*/ )
4229 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
4230 StudyContext* myStudyContext = GetCurrentStudyContext();
4232 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
4233 int anId = myStudyContext->findId( IORString );
4235 if(MYDEBUG) MESSAGE( "VSR " << anId )
4237 sprintf( strId, "%d", anId );
4238 return CORBA::string_dup( strId );
4241 return CORBA::string_dup( "" );
4244 //=============================================================================
4246 * SMESH_Gen_i::LocalPersistentIDToIOR
4248 * Transform data from persistent form to transient
4250 //=============================================================================
4252 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
4253 const char* aLocalPersistentID,
4254 CORBA::Boolean /*isMultiFile*/,
4255 CORBA::Boolean /*isASCII*/ )
4257 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
4258 StudyContext* myStudyContext = GetCurrentStudyContext();
4260 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
4261 int anId = atoi( aLocalPersistentID );
4262 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
4264 return CORBA::string_dup( "" );
4267 //=======================================================================
4268 //function : RegisterObject
4270 //=======================================================================
4272 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
4274 StudyContext* myStudyContext = GetCurrentStudyContext();
4275 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4276 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
4277 return myStudyContext->addObject( string( iorString.in() ) );
4282 //================================================================================
4284 * \brief Return id of registered object
4285 * \param theObject - the Object
4286 * \retval int - Object id
4288 //================================================================================
4290 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
4292 StudyContext* myStudyContext = GetCurrentStudyContext();
4293 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4294 string iorString = GetORB()->object_to_string( theObject );
4295 return myStudyContext->findId( iorString );
4300 //=============================================================================
4302 * SMESH_Gen_i::SetName
4304 * Set a new object name
4306 //=============================================================================
4307 void SMESH_Gen_i::SetName(const char* theIOR,
4308 const char* theName)
4310 if ( theIOR && strcmp( theIOR, "" ) ) {
4311 CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
4312 SALOMEDS::SObject_var aSO = ObjectToSObject( myCurrentStudy, anObject );
4313 if ( !aSO->_is_nil() ) {
4314 SetName( aSO, theName );
4319 //=============================================================================
4321 * SMESHEngine_factory
4323 * C factory, accessible with dlsym, after dlopen
4325 //=============================================================================
4329 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
4330 PortableServer::POA_ptr poa,
4331 PortableServer::ObjectId* contId,
4332 const char* instanceName,
4333 const char* interfaceName )
4335 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
4336 if(MYDEBUG) SCRUTE(interfaceName);
4337 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
4338 return aSMESHGen->getId() ;