1 // Copyright (C) 2007-2012 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 // File : SMESH_Gen_i.cxx
23 // Author : Paul RASCLE, EDF
27 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_CompSolid.hxx>
32 #include <TopoDS_Solid.hxx>
33 #include <TopoDS_Shell.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TCollection_AsciiString.hxx>
56 #define LibHandle HMODULE
57 #define LoadLib( name ) LoadLibrary( name )
58 #define GetProc GetProcAddress
59 #define UnLoadLib( handle ) FreeLibrary( handle );
61 #define LibHandle void*
62 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
64 #define UnLoadLib( handle ) dlclose( handle );
67 #include "SMESH_Gen_i.hxx"
69 #include "SMDS_EdgePosition.hxx"
70 #include "SMDS_FacePosition.hxx"
71 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
72 #include "SMDS_SetIterator.hxx"
73 #include "SMDS_SpacePosition.hxx"
74 #include "SMDS_VertexPosition.hxx"
75 #include "SMESHDS_Document.hxx"
76 #include "SMESHDS_Group.hxx"
77 #include "SMESHDS_GroupOnGeom.hxx"
78 #include "SMESH_Algo_i.hxx"
79 #include "SMESH_File.hxx"
80 #include "SMESH_Group.hxx"
81 #include "SMESH_Group_i.hxx"
82 #include "SMESH_Hypothesis.hxx"
83 #include "SMESH_Hypothesis_i.hxx"
84 #include "SMESH_Mesh.hxx"
85 #include "SMESH_MeshEditor.hxx"
86 #include "SMESH_Mesh_i.hxx"
87 #include "SMESH_PreMeshInfo.hxx"
88 #include "SMESH_PythonDump.hxx"
90 #include CORBA_SERVER_HEADER(SMESH_Group)
91 #include CORBA_SERVER_HEADER(SMESH_Filter)
92 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
94 #include "DriverMED_W_SMESHDS_Mesh.h"
95 #include "DriverMED_R_SMESHDS_Mesh.h"
97 #include "DriverCGNS_Read.hxx"
101 #include <GEOM_Client.hxx>
103 #include <Basics_Utils.hxx>
105 #include <OpUtil.hxx>
106 #include <SALOMEDS_Tool.hxx>
107 #include <SALOME_Container_i.hxx>
108 #include <SALOME_LifeCycleCORBA.hxx>
109 #include <SALOME_NamingService.hxx>
110 #include <Utils_CorbaException.hxx>
111 #include <Utils_ExceptHandlers.hxx>
112 #include <Utils_SINGLETON.hxx>
113 #include <utilities.h>
115 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
116 #include CORBA_CLIENT_HEADER(SALOME_Session)
123 using SMESH::TPythonDump;
126 #define NUM_TMP_FILES 2
129 static int MYDEBUG = 0;
131 static int MYDEBUG = 0;
134 // Static variables definition
135 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
136 CORBA::ORB_var SMESH_Gen_i::myOrb;
137 PortableServer::POA_var SMESH_Gen_i::myPoa;
138 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
139 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
140 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
143 const int nbElemPerDiagonal = 10;
145 //=============================================================================
147 * GetServant [ static ]
149 * Get servant of the CORBA object
151 //=============================================================================
153 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
155 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
158 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
162 INFOS( "GetServant - Unknown exception was caught!!!" );
167 //=============================================================================
169 * SObjectToObject [ static ]
171 * Get CORBA object corresponding to the SALOMEDS::SObject
173 //=============================================================================
175 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
177 SALOMEDS::GenericAttribute_var anAttr;
178 CORBA::Object_var anObj;
179 if ( !theSObject->_is_nil() ) {
181 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
182 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
183 CORBA::String_var aValue = anIOR->Value();
184 if( strcmp( aValue, "" ) != 0 )
185 anObj = GetORB()->string_to_object( aValue );
189 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
195 //=============================================================================
199 * Get SALOME_NamingService object
201 //=============================================================================
203 SALOME_NamingService* SMESH_Gen_i::GetNS()
205 if ( myNS == NULL ) {
206 myNS = SINGLETON_<SALOME_NamingService>::Instance();
207 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
208 myNS->init_orb( GetORB() );
213 //=============================================================================
217 * Get SALOME_LifeCycleCORBA object
219 //=============================================================================
220 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
221 if ( myLCC == NULL ) {
222 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
228 //=============================================================================
230 * GetGeomEngine [ static ]
232 * Get GEOM::GEOM_Gen reference
234 //=============================================================================
235 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
236 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
237 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
238 //CCRT return aGeomEngine._retn();
239 if(CORBA::is_nil(myGeomGen))
241 Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
242 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
247 //=============================================================================
249 * SMESH_Gen_i::SMESH_Gen_i
251 * Default constructor: not for use
253 //=============================================================================
255 SMESH_Gen_i::SMESH_Gen_i()
257 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
260 //=============================================================================
262 * SMESH_Gen_i::SMESH_Gen_i
264 * Standard constructor, used with Container
266 //=============================================================================
268 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
269 PortableServer::POA_ptr poa,
270 PortableServer::ObjectId* contId,
271 const char* instanceName,
272 const char* interfaceName )
273 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
275 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
277 myOrb = CORBA::ORB::_duplicate(orb);
278 myPoa = PortableServer::POA::_duplicate(poa);
281 _id = myPoa->activate_object( _thisObj );
283 myIsEmbeddedMode = false;
284 myShapeReader = NULL; // shape reader
286 myIsHistoricalPythonDump = true;
287 myToForgetMeshDataOnHypModif = false;
289 // set it in standalone mode only
290 //OSD::SetSignal( true );
292 // 0020605: EDF 1190 SMESH: Display performance. 80 seconds for 52000 cells.
293 // find out mode (embedded or standalone) here else
294 // meshes created before calling SMESH_Client::GetSMESHGen(), which calls
295 // SMESH_Gen_i::SetEmbeddedMode(), have wrong IsEmbeddedMode flag
296 if ( SALOME_NamingService* ns = GetNS() )
298 CORBA::Object_var obj = ns->Resolve( "/Kernel/Session" );
299 SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
300 if ( !session->_is_nil() )
302 CORBA::String_var str_host = session->getHostname();
303 CORBA::Long s_pid = session->getPID();
304 string my_host = Kernel_Utils::GetHostname();
306 long my_pid = (long)_getpid();
308 long my_pid = (long) getpid();
310 SetEmbeddedMode( s_pid == my_pid && my_host == str_host.in() );
315 //=============================================================================
317 * SMESH_Gen_i::~SMESH_Gen_i
321 //=============================================================================
323 SMESH_Gen_i::~SMESH_Gen_i()
325 MESSAGE( "SMESH_Gen_i::~SMESH_Gen_i" );
327 // delete hypothesis creators
328 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
329 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
331 delete (*itHyp).second;
333 myHypCreatorMap.clear();
335 // Clear study contexts data
336 map<int, StudyContext*>::iterator it;
337 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
340 myStudyContextMap.clear();
341 // delete shape reader
342 if ( !myShapeReader )
343 delete myShapeReader;
346 //=============================================================================
348 * SMESH_Gen_i::createHypothesis
350 * Create hypothesis of given type
352 //=============================================================================
353 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
354 const char* theLibName)
355 throw (SALOME::SALOME_Exception)
357 /* It's Need to tranlate lib name for WIN32 or X platform */
358 char* aPlatformLibName = 0;
359 if ( theLibName && theLibName[0] != '\0' )
361 int libNameLen = strlen(theLibName);
362 //check for old format "libXXXXXXX.so"
363 if (libNameLen > 7 &&
364 !strncmp( theLibName, "lib", 3 ) &&
365 !strcmp( theLibName+libNameLen-3, ".so" ))
369 aPlatformLibName = new char[libNameLen - 1];
370 aPlatformLibName[0] = '\0';
371 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
372 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
373 aPlatformLibName[libNameLen - 2] = '\0';
375 aPlatformLibName = new char[ libNameLen + 1];
376 aPlatformLibName[0] = '\0';
377 aPlatformLibName = strcat( aPlatformLibName, theLibName );
378 aPlatformLibName[libNameLen] = '\0';
383 //try to use new format
385 aPlatformLibName = new char[ libNameLen + 5 ];
386 aPlatformLibName[0] = '\0';
387 aPlatformLibName = strcat( aPlatformLibName, theLibName );
388 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
390 aPlatformLibName = new char[ libNameLen + 7 ];
391 aPlatformLibName[0] = '\0';
392 aPlatformLibName = strcat( aPlatformLibName, "lib" );
393 aPlatformLibName = strcat( aPlatformLibName, theLibName );
394 aPlatformLibName = strcat( aPlatformLibName, ".so" );
400 Unexpect aCatch(SALOME_SalomeException);
401 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
403 // create a new hypothesis object servant
404 SMESH_Hypothesis_i* myHypothesis_i = 0;
405 SMESH::SMESH_Hypothesis_var hypothesis_i;
409 // check, if creator for this hypothesis type already exists
410 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
412 // load plugin library
413 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
414 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
417 // report any error, if occured
419 const char* anError = dlerror();
420 throw(SALOME_Exception(anError));
422 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
426 // get method, returning hypothesis creator
427 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
428 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
429 GetHypothesisCreator procHandle =
430 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
433 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
434 UnLoadLib(libHandle);
437 // get hypothesis creator
438 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
439 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
442 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
445 // map hypothesis creator to a hypothesis name
446 myHypCreatorMap[string(theHypName)] = aCreator;
449 // create a new hypothesis object, store its ref. in studyContext
450 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
452 myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
453 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
455 catch (SALOME_Exception& S_ex)
457 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
460 if ( aPlatformLibName )
461 delete[] aPlatformLibName;
464 return hypothesis_i._retn();
466 // activate the CORBA servant of hypothesis
467 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
468 int nextId = RegisterObject( hypothesis_i );
469 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
471 return hypothesis_i._retn();
474 //=============================================================================
476 * SMESH_Gen_i::createMesh
478 * Create empty mesh on shape
480 //=============================================================================
481 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
482 throw ( SALOME::SALOME_Exception )
484 Unexpect aCatch(SALOME_SalomeException);
485 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
487 // Get or create the GEOM_Client instance
489 // create a new mesh object servant, store it in a map in study context
490 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
491 // create a new mesh object
492 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
493 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
495 // activate the CORBA servant of Mesh
496 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
497 int nextId = RegisterObject( mesh );
498 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
501 catch (SALOME_Exception& S_ex) {
502 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
504 return SMESH::SMESH_Mesh::_nil();
507 //=============================================================================
509 * SMESH_Gen_i::GetShapeReader
513 //=============================================================================
514 GEOM_Client* SMESH_Gen_i::GetShapeReader()
516 // create shape reader if necessary
517 if ( !myShapeReader )
518 myShapeReader = new GEOM_Client(GetContainerRef());
519 ASSERT( myShapeReader );
520 return myShapeReader;
523 //=============================================================================
525 * SMESH_Gen_i::SetGeomEngine
527 * Set GEOM::GEOM_Gen reference
529 //=============================================================================
530 //GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
531 void SMESH_Gen_i::SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo )
533 //Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
534 //myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
535 myGeomGen=GEOM::GEOM_Gen::_duplicate(geomcompo);
539 //=============================================================================
541 * SMESH_Gen_i::SetEmbeddedMode
545 //=============================================================================
547 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
549 myIsEmbeddedMode = theMode;
550 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
552 if ( !myIsEmbeddedMode ) {
553 //PAL10867: disable signals catching with "noexcepthandler" option
554 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
555 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
560 char* envDisableFPE = getenv("DISABLE_FPE");
561 if (envDisableFPE && atoi(envDisableFPE))
566 OSD::SetSignal( raiseFPE );
568 // else OSD::SetSignal() is called in GUI
572 //=============================================================================
574 * SMESH_Gen_i::IsEmbeddedMode
578 //=============================================================================
580 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
582 return myIsEmbeddedMode;
585 //=============================================================================
587 * SMESH_Gen_i::SetCurrentStudy
591 //=============================================================================
593 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
595 setCurrentStudy( theStudy );
598 void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy,
599 bool theStudyIsBeingClosed)
601 int curStudyId = GetCurrentStudyID();
602 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
603 // create study context, if it doesn't exist and set current study
604 int studyId = GetCurrentStudyID();
605 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
606 myStudyContextMap[ studyId ] = new StudyContext;
609 // myCurrentStudy may be nil
610 if ( !theStudyIsBeingClosed && !CORBA::is_nil( myCurrentStudy ) ) {
611 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
612 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
613 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
615 // NPAL16168, issue 0020210
616 // Let meshes update their data depending on GEOM groups that could change
617 if ( curStudyId != studyId )
619 //SALOMEDS::SComponent_var me = PublishComponent( myCurrentStudy );
620 SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
621 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
622 if ( !me->_is_nil() ) {
623 SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
624 for ( ; anIter->More(); anIter->Next() ) {
625 SALOMEDS::SObject_var so = anIter->Value();
626 CORBA::Object_var ior = SObjectToObject( so );
627 if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
628 mesh->CheckGeomGroupModif();
635 //=============================================================================
637 * SMESH_Gen_i::GetCurrentStudy
641 //=============================================================================
643 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
645 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
646 return SALOMEDS::Study::_duplicate( myCurrentStudy );
649 //=============================================================================
651 * SMESH_Gen_i::GetCurrentStudyContext
653 * Get current study context
655 //=============================================================================
656 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
658 if ( !CORBA::is_nil( myCurrentStudy ) &&
659 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
660 return myStudyContextMap[ myCurrentStudy->StudyId() ];
665 //=============================================================================
667 * SMESH_Gen_i::CreateHypothesis
669 * Create hypothesis/algorothm of given type and publish it in the study
671 //=============================================================================
673 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
674 const char* theLibName )
675 throw ( SALOME::SALOME_Exception )
677 Unexpect aCatch(SALOME_SalomeException);
678 // Create hypothesis/algorithm
679 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
681 // Publish hypothesis/algorithm in the study
682 if ( CanPublishInStudy( hyp ) ) {
683 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
684 if ( !aSO->_is_nil() ) {
685 // Update Python script
686 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
687 << theHypName << "', '" << theLibName << "')";
694 //================================================================================
696 * \brief Return a hypothesis holding parameter values corresponding either to the mesh
697 * existing on the given geometry or to size of the geometry.
698 * \param theHypType - hypothesis type name
699 * \param theLibName - plugin library name
700 * \param theMesh - The mesh of interest
701 * \param theGeom - The shape to get parameter values from
702 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
703 * in a study and used to compute the mesh, or a temporary one created just to pass
706 //================================================================================
708 SMESH::SMESH_Hypothesis_ptr
709 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
710 const char* theLibName,
711 SMESH::SMESH_Mesh_ptr theMesh,
712 GEOM::GEOM_Object_ptr theGeom,
713 CORBA::Boolean byMesh)
714 throw ( SALOME::SALOME_Exception )
716 Unexpect aCatch(SALOME_SalomeException);
717 if ( byMesh && CORBA::is_nil( theMesh ) )
718 return SMESH::SMESH_Hypothesis::_nil();
719 if ( byMesh && CORBA::is_nil( theGeom ) )
720 return SMESH::SMESH_Hypothesis::_nil();
722 // -----------------------------------------------
723 // find hypothesis used to mesh theGeom
724 // -----------------------------------------------
726 // get mesh and shape
727 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
728 TopoDS_Shape shape = GeomObjectToShape( theGeom );
729 if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
730 return SMESH::SMESH_Hypothesis::_nil();
731 ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
733 // create a temporary hypothesis to know its dimention
734 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
735 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
737 return SMESH::SMESH_Hypothesis::_nil();
738 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
741 // look for a hypothesis of theHypType used to mesh the shape
742 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
745 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
746 int nbLocalHyps = aHypList->length();
747 for ( int i = 0; i < nbLocalHyps; i++ )
748 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
749 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
750 // check super shapes
751 TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
752 while ( nbLocalHyps == 0 && itShape.More() ) {
753 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
754 if ( ! CORBA::is_nil( geomObj )) {
755 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
756 nbLocalHyps = aHypList->length();
757 for ( int i = 0; i < nbLocalHyps; i++ )
758 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
759 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
765 // let the temporary hypothesis find out somehow parameter values by mesh
766 if ( hyp->SetParametersByMesh( mesh, shape ))
767 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
772 diagonal = mesh->GetShapeDiagonalSize();
774 diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
775 ::SMESH_Hypothesis::TDefaults dflts;
776 dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
777 dflts._nbSegments = myGen.GetDefaultNbSegments();
778 dflts._shape = &shape;
779 // let the temporary hypothesis initialize it's values
780 if ( hyp->SetParametersByDefaults( dflts, mesh ))
781 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
784 return SMESH::SMESH_Hypothesis::_nil();
787 //=============================================================================
789 * Sets number of segments per diagonal of boundary box of geometry by which
790 * default segment length of appropriate 1D hypotheses is defined
792 //=============================================================================
794 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
795 throw ( SALOME::SALOME_Exception )
797 if ( theNbSegments > 0 )
798 myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
800 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
802 //=============================================================================
804 * \brief Sets default number of segments per edge
806 //=============================================================================
807 void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
808 throw ( SALOME::SALOME_Exception )
810 if ( theNbSegments > 0 )
811 myGen.SetDefaultNbSegments( int(theNbSegments) );
813 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
816 //=============================================================================
820 //=============================================================================
822 void SMESH_Gen_i::SetOption(const char* name, const char* value)
824 if ( name && value && strlen( value ) > 0 )
827 if ( strcmp(name, "historical_python_dump") == 0 )
829 myIsHistoricalPythonDump = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
830 msgToGUI = "preferences/SMESH/historical_python_dump/";
831 msgToGUI += myIsHistoricalPythonDump ? "true" : "false";
833 else if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
835 myToForgetMeshDataOnHypModif = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
836 msgToGUI = "preferences/SMESH/forget_mesh_on_hyp_modif/";
837 msgToGUI += myToForgetMeshDataOnHypModif ? "true" : "false";
840 // update preferences in case if SetOption() is invoked from python console
841 if ( !msgToGUI.empty() )
843 CORBA::Object_var obj = SMESH_Gen_i::GetNS()->Resolve( "/Kernel/Session" );
844 SALOME::Session_var session = SALOME::Session::_narrow( obj );
845 if ( !CORBA::is_nil( session ) )
846 session->emitMessageOneWay(msgToGUI.c_str());
851 //=============================================================================
853 Return an option value
855 //=============================================================================
857 char* SMESH_Gen_i::GetOption(const char* name)
861 if ( strcmp(name, "historical_python_dump") == 0 )
863 return CORBA::string_dup( myIsHistoricalPythonDump ? "true" : "false" );
865 if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
867 return CORBA::string_dup( myToForgetMeshDataOnHypModif ? "true" : "false" );
870 return CORBA::string_dup( "" );
873 //=============================================================================
875 * SMESH_Gen_i::CreateMesh
877 * Create empty mesh on a shape and publish it in the study
879 //=============================================================================
881 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
882 throw ( SALOME::SALOME_Exception )
884 Unexpect aCatch(SALOME_SalomeException);
885 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
887 SMESH::SMESH_Mesh_var mesh = this->createMesh();
889 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
890 ASSERT( meshServant );
891 meshServant->SetShape( theShapeObject );
893 // publish mesh in the study
894 if ( CanPublishInStudy( mesh ) ) {
895 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
896 aStudyBuilder->NewCommand(); // There is a transaction
897 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
898 aStudyBuilder->CommitCommand();
899 if ( !aSO->_is_nil() ) {
900 // Update Python script
901 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
908 //=============================================================================
910 * SMESH_Gen_i::CreateEmptyMesh
914 //=============================================================================
916 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
917 throw ( SALOME::SALOME_Exception )
919 Unexpect aCatch(SALOME_SalomeException);
920 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
922 SMESH::SMESH_Mesh_var mesh = this->createMesh();
924 // publish mesh in the study
925 if ( CanPublishInStudy( mesh ) ) {
926 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
927 aStudyBuilder->NewCommand(); // There is a transaction
928 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
929 aStudyBuilder->CommitCommand();
930 if ( !aSO->_is_nil() ) {
931 // Update Python script
932 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
939 //=============================================================================
941 * SMESH_Gen_i::CreateMeshFromUNV
943 * Create mesh and import data from UNV file
945 //=============================================================================
947 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
948 throw ( SALOME::SALOME_Exception )
950 Unexpect aCatch(SALOME_SalomeException);
951 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
953 SMESH::SMESH_Mesh_var aMesh = createMesh();
955 // publish mesh in the study
956 if ( CanPublishInStudy( aMesh ) ) {
957 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
958 aStudyBuilder->NewCommand(); // There is a transaction
959 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
960 aStudyBuilder->CommitCommand();
961 if ( !aSO->_is_nil() ) {
962 // Update Python script
963 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV(r'" << theFileName << "')";
967 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
969 aServant->ImportUNVFile( theFileName );
971 // Dump creation of groups
972 SMESH::ListOfGroups_var groups = aServant->GetGroups();
974 aServant->GetImpl().GetMeshDS()->Modified();
975 return aMesh._retn();
978 //=============================================================================
980 * SMESH_Gen_i::CreateMeshFromMED
982 * Create mesh and import data from MED file
984 //=============================================================================
986 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileName,
987 SMESH::DriverMED_ReadStatus& theStatus,
988 const char* theCommandNameForPython,
989 const char* theFileNameForPython)
991 // Retrieve mesh names from the file
992 DriverMED_R_SMESHDS_Mesh myReader;
993 myReader.SetFile( theFileName );
994 myReader.SetMeshId( -1 );
995 Driver_Mesh::Status aStatus;
996 list<string> aNames = myReader.GetMeshNames(aStatus);
997 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
998 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1000 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1003 TPythonDump aPythonDump;
1004 aPythonDump << "([";
1006 if (theStatus == SMESH::DRS_OK) {
1007 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1008 aStudyBuilder->NewCommand(); // There is a transaction
1009 aResult->length( aNames.size() );
1012 // Iterate through all meshes and create mesh objects
1013 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
1015 if (i > 0) aPythonDump << ", ";
1018 SMESH::SMESH_Mesh_var mesh = createMesh();
1020 // publish mesh in the study
1021 SALOMEDS::SObject_var aSO;
1022 if ( CanPublishInStudy( mesh ) )
1023 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
1024 if ( !aSO->_is_nil() ) {
1029 aPythonDump << "mesh_" << i;
1032 // Read mesh data (groups are published automatically by ImportMEDFile())
1033 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1034 ASSERT( meshServant );
1035 SMESH::DriverMED_ReadStatus status1 =
1036 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
1037 if (status1 > theStatus)
1038 theStatus = status1;
1040 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
1041 meshServant->GetImpl().GetMeshDS()->Modified();
1043 aStudyBuilder->CommitCommand();
1046 // Update Python script
1047 aPythonDump << "], status) = " << this << "." << theCommandNameForPython << "(r'" << theFileNameForPython << "')";
1049 // Dump creation of groups
1050 for ( int i = 0; i < aResult->length(); ++i )
1051 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1053 return aResult._retn();
1056 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
1057 SMESH::DriverMED_ReadStatus& theStatus)
1058 throw ( SALOME::SALOME_Exception )
1060 Unexpect aCatch(SALOME_SalomeException);
1061 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
1062 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(theFileName, theStatus, "CreateMeshesFromMED", theFileName);
1066 //=============================================================================
1068 * SMESH_Gen_i::CreateMeshFromSAUV
1070 * Create mesh and import data from SAUV file
1072 //=============================================================================
1074 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName,
1075 SMESH::DriverMED_ReadStatus& theStatus)
1076 throw ( SALOME::SALOME_Exception )
1078 Unexpect aCatch(SALOME_SalomeException);
1079 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromSAUV" );
1080 std::string sauvfilename(theFileName);
1081 std::string medfilename(theFileName);
1082 medfilename += ".med";
1085 cmd = "%PYTHONBIN% ";
1090 cmd += "from medutilities import convert ; convert(r'" + sauvfilename + "', 'GIBI', 'MED', 1, r'" + medfilename + "')";
1092 system(cmd.c_str());
1093 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), theStatus, "CreateMeshesFromSAUV", sauvfilename.c_str());
1095 cmd = "%PYTHONBIN% ";
1100 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1102 system(cmd.c_str());
1106 //=============================================================================
1108 * SMESH_Gen_i::CreateMeshFromSTL
1110 * Create mesh and import data from STL file
1112 //=============================================================================
1114 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
1115 throw ( SALOME::SALOME_Exception )
1117 Unexpect aCatch(SALOME_SalomeException);
1118 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
1120 SMESH::SMESH_Mesh_var aMesh = createMesh();
1122 // publish mesh in the study
1123 if ( CanPublishInStudy( aMesh ) ) {
1124 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1125 aStudyBuilder->NewCommand(); // There is a transaction
1126 SALOMEDS::SObject_var aSO = PublishInStudy
1127 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1128 aStudyBuilder->CommitCommand();
1129 if ( !aSO->_is_nil() ) {
1130 // Update Python script
1131 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL(r'" << theFileName << "')";
1135 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1137 aServant->ImportSTLFile( theFileName );
1138 aServant->GetImpl().GetMeshDS()->Modified();
1139 return aMesh._retn();
1142 //================================================================================
1144 * \brief Create meshes and import data from the CGSN file
1146 //================================================================================
1148 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName,
1149 SMESH::DriverMED_ReadStatus& theStatus)
1150 throw ( SALOME::SALOME_Exception )
1152 Unexpect aCatch(SALOME_SalomeException);
1154 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
1157 // Retrieve nb meshes from the file
1158 DriverCGNS_Read myReader;
1159 myReader.SetFile( theFileName );
1160 Driver_Mesh::Status aStatus;
1161 int nbMeshes = myReader.GetNbMeshes(aStatus);
1162 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1164 aResult->length( nbMeshes );
1166 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1169 TPythonDump aPythonDump;
1170 aPythonDump << "([";
1172 if (theStatus == SMESH::DRS_OK)
1174 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1175 aStudyBuilder->NewCommand(); // There is a transaction
1179 // Iterate through all meshes and create mesh objects
1180 for ( ; i < nbMeshes; ++i )
1183 if (i > 0) aPythonDump << ", ";
1186 SMESH::SMESH_Mesh_var mesh = createMesh();
1187 aResult[i] = SMESH::SMESH_Mesh::_duplicate( mesh );
1189 // Read mesh data (groups are published automatically by ImportMEDFile())
1190 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1191 ASSERT( meshServant );
1193 SMESH::DriverMED_ReadStatus status1 =
1194 meshServant->ImportCGNSFile( theFileName, i, meshName );
1195 if (status1 > theStatus)
1196 theStatus = status1;
1198 meshServant->GetImpl().GetMeshDS()->Modified();
1199 // publish mesh in the study
1200 SALOMEDS::SObject_var aSO;
1201 if ( CanPublishInStudy( mesh ) )
1202 aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() );
1205 if ( !aSO->_is_nil() )
1208 aPythonDump << "mesh_" << i;
1210 aStudyBuilder->CommitCommand();
1213 aPythonDump << "], status) = " << this << ".CreateMeshesFromCGNS(r'" << theFileName << "')";
1215 // Dump creation of groups
1216 for ( int i = 0; i < aResult->length(); ++i )
1217 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1219 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
1222 return aResult._retn();
1225 //================================================================================
1227 * \brief Create a mesh and import data from a GMF file
1229 //================================================================================
1231 SMESH::SMESH_Mesh_ptr
1232 SMESH_Gen_i::CreateMeshesFromGMF( const char* theFileName,
1233 SMESH::ComputeError_out theError)
1234 throw ( SALOME::SALOME_Exception )
1236 Unexpect aCatch(SALOME_SalomeException);
1238 SMESH::SMESH_Mesh_var aMesh = createMesh();
1239 string aFileName = basename( theFileName );
1240 // publish mesh in the study
1241 if ( CanPublishInStudy( aMesh ) ) {
1242 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1243 aStudyBuilder->NewCommand(); // There is a transaction
1244 SALOMEDS::SObject_var aSO = PublishInStudy
1245 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1246 aStudyBuilder->CommitCommand();
1247 if ( !aSO->_is_nil() ) {
1248 // Update Python script
1249 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromGMF(r'" << theFileName << "')";
1252 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1254 theError = aServant->ImportGMFFile( theFileName );
1255 aServant->GetImpl().GetMeshDS()->Modified();
1256 return aMesh._retn();
1260 //=============================================================================
1262 * SMESH_Gen_i::IsReadyToCompute
1264 * Returns true if mesh contains enough data to be computed
1266 //=============================================================================
1268 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
1269 GEOM::GEOM_Object_ptr theShapeObject )
1270 throw ( SALOME::SALOME_Exception )
1272 Unexpect aCatch(SALOME_SalomeException);
1273 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
1275 if ( CORBA::is_nil( theShapeObject ) )
1276 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1277 SALOME::BAD_PARAM );
1279 if ( CORBA::is_nil( theMesh ) )
1280 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1281 SALOME::BAD_PARAM );
1285 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1286 ASSERT( meshServant );
1287 if ( meshServant ) {
1288 // get local TopoDS_Shape
1289 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1290 // call implementation
1291 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1292 return myGen.CheckAlgoState( myLocMesh, myLocShape );
1295 catch ( SALOME_Exception& S_ex ) {
1296 INFOS( "catch exception "<< S_ex.what() );
1301 //================================================================================
1303 * \brief Find SObject for an algo
1305 //================================================================================
1307 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
1310 if ( !myCurrentStudy->_is_nil() ) {
1311 // find algo in the study
1312 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
1313 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
1314 if ( !father->_is_nil() ) {
1315 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
1316 for ( ; itBig->More(); itBig->Next() ) {
1317 SALOMEDS::SObject_var gotBranch = itBig->Value();
1318 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1319 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1320 for ( ; algoIt->More(); algoIt->Next() ) {
1321 SALOMEDS::SObject_var algoSO = algoIt->Value();
1322 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1323 if ( !CORBA::is_nil( algoIOR )) {
1324 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1325 if ( impl && impl->GetImpl() == algo )
1326 return algoSO._retn();
1328 } // loop on algo SO's
1331 } // SMESH component iterator
1335 return SALOMEDS::SObject::_nil();
1338 //================================================================================
1340 * \brief Return errors of mesh computation
1342 //================================================================================
1344 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1345 GEOM::GEOM_Object_ptr theSubObject )
1346 throw ( SALOME::SALOME_Exception )
1348 Unexpect aCatch(SALOME_SalomeException);
1349 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1351 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1352 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1354 if ( CORBA::is_nil( theMesh ) )
1355 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1357 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1359 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1362 if(theMesh->HasShapeToMesh())
1363 shape = GeomObjectToShape( theSubObject );
1365 shape = SMESH_Mesh::PseudoShape();
1367 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1369 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1372 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1373 const bool includeSelf = true, complexShapeFirst = true;
1374 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1376 while ( smIt->more() )
1379 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1381 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1382 if ( error && !error->IsOK() && error->myAlgo )
1384 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1385 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1386 errStruct.comment = error->myComment.c_str();
1387 errStruct.subShapeID = sm->GetId();
1388 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->myAlgo );
1389 if ( !algoSO->_is_nil() )
1390 errStruct.algoName = algoSO->GetName();
1392 errStruct.algoName = error->myAlgo->GetName();
1393 errStruct.hasBadMesh = !error->myBadElements.empty();
1396 error_array->length( nbErr );
1399 catch ( SALOME_Exception& S_ex ) {
1400 INFOS( "catch exception "<< S_ex.what() );
1403 return error_array._retn();
1407 //================================================================================
1409 * \brief Return mesh elements preventing computation of a subshape
1411 //================================================================================
1413 SMESH::MeshPreviewStruct*
1414 SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1415 CORBA::Short theSubShapeID )
1416 throw ( SALOME::SALOME_Exception )
1418 Unexpect aCatch(SALOME_SalomeException);
1419 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetBadInputElements()" );
1421 if ( CORBA::is_nil( theMesh ) )
1422 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1424 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1427 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1429 // mesh implementation
1430 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1431 // submesh by subshape id
1432 if ( SMESH_subMesh * sm = mesh.GetSubMeshContaining( theSubShapeID ))
1435 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1436 if ( error && !error->myBadElements.empty())
1438 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1439 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1441 // get nodes of elements and count elements
1442 TNode2LocalIDMap mapNode2LocalID;
1443 list< TNodeLocalID > connectivity;
1444 int i, nbElements = 0, nbConnNodes = 0;
1446 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
1447 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
1448 for ( ; elemIt != elemEnd; ++elemIt, ++nbElements )
1450 SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator();
1451 while ( nIt->more() )
1452 connectivity.push_back
1453 ( mapNode2LocalID.insert( make_pair( nIt->next(), ++nbConnNodes)).first );
1455 // fill node coords and assign local ids to the nodes
1456 int nbNodes = mapNode2LocalID.size();
1457 result->nodesXYZ.length( nbNodes );
1458 TNodeLocalID node2ID = mapNode2LocalID.begin();
1459 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1460 node2ID->second = i;
1461 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1462 result->nodesXYZ[i].x = node->X();
1463 result->nodesXYZ[i].y = node->Y();
1464 result->nodesXYZ[i].z = node->Z();
1466 // fill connectivity
1467 result->elementConnectivities.length( nbConnNodes );
1468 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1469 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1470 result->elementConnectivities[i] = (*connIt)->second;
1472 // fill element types
1473 result->elementTypes.length( nbElements );
1474 for ( i = 0, elemIt = error->myBadElements.begin(); i <nbElements; ++i, ++elemIt )
1476 const SMDS_MeshElement* elem = *elemIt;
1477 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType();
1478 result->elementTypes[i].isPoly = elem->IsPoly();
1479 result->elementTypes[i].nbNodesInElement = elem->NbNodes();
1485 catch ( SALOME_Exception& S_ex ) {
1486 INFOS( "catch exception "<< S_ex.what() );
1489 return result._retn();
1492 //================================================================================
1494 * \brief Returns errors of hypotheses definintion
1495 * \param theMesh - the mesh
1496 * \param theSubObject - the main or sub- shape
1497 * \retval SMESH::algo_error_array* - sequence of errors
1499 //================================================================================
1501 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1502 GEOM::GEOM_Object_ptr theSubObject )
1503 throw ( SALOME::SALOME_Exception )
1505 Unexpect aCatch(SALOME_SalomeException);
1506 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1508 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1509 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1511 if ( CORBA::is_nil( theMesh ) )
1512 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1514 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1516 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1517 ASSERT( meshServant );
1518 if ( meshServant ) {
1519 TopoDS_Shape myLocShape;
1520 if(theMesh->HasShapeToMesh())
1521 myLocShape = GeomObjectToShape( theSubObject );
1523 myLocShape = SMESH_Mesh::PseudoShape();
1525 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1526 list< ::SMESH_Gen::TAlgoStateError > error_list;
1527 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1528 // call ::SMESH_Gen::GetAlgoState()
1529 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1530 error_array->length( error_list.size() );
1532 for ( error = error_list.begin(); error != error_list.end(); ++error )
1534 // fill AlgoStateError structure
1535 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1536 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1537 errStruct.algoDim = error->_algoDim;
1538 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1539 errStruct.algoName = "";
1540 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->_algo );
1541 if ( !algoSO->_is_nil() )
1542 errStruct.algoName = algoSO->GetName();
1546 catch ( SALOME_Exception& S_ex ) {
1547 INFOS( "catch exception "<< S_ex.what() );
1549 return error_array._retn();
1552 //=============================================================================
1554 * SMESH_Gen_i::GetSubShapesId
1556 * Get sub-shapes unique ID's list
1558 //=============================================================================
1560 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1561 const SMESH::object_array& theListOfSubShapeObject )
1562 throw ( SALOME::SALOME_Exception )
1564 Unexpect aCatch(SALOME_SalomeException);
1565 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1567 SMESH::long_array_var shapesId = new SMESH::long_array;
1570 if ( CORBA::is_nil( theMainShapeObject ) )
1571 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1572 SALOME::BAD_PARAM );
1576 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1577 TopTools_IndexedMapOfShape myIndexToShape;
1578 TopExp::MapShapes(myMainShape,myIndexToShape);
1580 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1582 GEOM::GEOM_Object_var aShapeObject
1583 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1584 if ( CORBA::is_nil( aShapeObject ) )
1585 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1586 SALOME::BAD_PARAM );
1588 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1589 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1591 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1592 setId.insert(myIndexToShape.FindIndex(F));
1593 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1595 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1597 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1598 setId.insert(myIndexToShape.FindIndex(E));
1599 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1601 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1603 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1604 setId.insert(myIndexToShape.FindIndex(V));
1605 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1608 shapesId->length(setId.size());
1609 set<int>::iterator iind;
1611 for (iind = setId.begin(); iind != setId.end(); iind++)
1613 if(MYDEBUG) SCRUTE((*iind));
1614 shapesId[i] = (*iind);
1615 if(MYDEBUG) SCRUTE(shapesId[i]);
1619 catch (SALOME_Exception& S_ex)
1621 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1624 return shapesId._retn();
1627 //=============================================================================
1629 * SMESH_Gen_i::Compute
1631 * Compute mesh on a shape
1633 //=============================================================================
1635 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1636 GEOM::GEOM_Object_ptr theShapeObject )
1637 throw ( SALOME::SALOME_Exception )
1640 Unexpect aCatch(SALOME_SalomeException);
1641 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1643 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1644 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1645 SALOME::BAD_PARAM );
1647 if ( CORBA::is_nil( theMesh ) )
1648 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1649 SALOME::BAD_PARAM );
1651 // Update Python script
1652 TPythonDump() << "isDone = " << this << ".Compute( "
1653 << theMesh << ", " << theShapeObject << ")";
1657 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1658 meshServant->Load();
1659 ASSERT( meshServant );
1660 if ( meshServant ) {
1661 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1662 meshServant->CheckGeomGroupModif();
1663 // get local TopoDS_Shape
1664 TopoDS_Shape myLocShape;
1665 if(theMesh->HasShapeToMesh())
1666 myLocShape = GeomObjectToShape( theShapeObject );
1668 myLocShape = SMESH_Mesh::PseudoShape();
1669 // call implementation compute
1670 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1671 #ifdef WITH_SMESH_CANCEL_COMPUTE
1672 myGen.PrepareCompute( myLocMesh, myLocShape);
1674 bool ok = myGen.Compute( myLocMesh, myLocShape);
1675 meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
1676 myLocMesh.GetMeshDS()->Modified();
1680 catch ( std::bad_alloc ) {
1681 INFOS( "Compute(): lack of memory" );
1683 catch ( SALOME_Exception& S_ex ) {
1684 INFOS( "Compute(): catch exception "<< S_ex.what() );
1687 INFOS( "Compute(): unknown exception " );
1692 //=============================================================================
1694 * SMESH_Gen_i::CancelCompute
1696 * Cancel Compute mesh on a shape
1698 //=============================================================================
1700 void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
1701 GEOM::GEOM_Object_ptr theShapeObject )
1703 #ifdef WITH_SMESH_CANCEL_COMPUTE
1704 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1705 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1706 TopoDS_Shape myLocShape;
1707 if(theMesh->HasShapeToMesh())
1708 myLocShape = GeomObjectToShape( theShapeObject );
1710 myLocShape = SMESH_Mesh::PseudoShape();
1711 myGen.CancelCompute( myLocMesh, myLocShape);
1715 //=============================================================================
1717 * SMESH_Gen_i::Precompute
1719 * Compute mesh as preview till indicated dimension on shape
1721 //=============================================================================
1723 SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh,
1724 GEOM::GEOM_Object_ptr theShapeObject,
1725 SMESH::Dimension theDimension,
1726 SMESH::long_array& theShapesId)
1727 throw ( SALOME::SALOME_Exception )
1729 Unexpect aCatch(SALOME_SalomeException);
1730 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Precompute" );
1732 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1733 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1734 SALOME::BAD_PARAM );
1736 if ( CORBA::is_nil( theMesh ) )
1737 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1738 SALOME::BAD_PARAM );
1740 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1743 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1744 meshServant->Load();
1745 ASSERT( meshServant );
1746 if ( meshServant ) {
1747 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1748 meshServant->CheckGeomGroupModif();
1749 // get local TopoDS_Shape
1750 TopoDS_Shape myLocShape;
1751 if(theMesh->HasShapeToMesh())
1752 myLocShape = GeomObjectToShape( theShapeObject );
1754 return result._retn();;
1756 // call implementation compute
1757 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1759 ::MeshDimension aDim = (MeshDimension)theDimension;
1760 if ( myGen.Compute( myLocMesh, myLocShape, false, aDim, &shapeIds ) )
1762 int nbShapeId = shapeIds.size();
1763 theShapesId.length( nbShapeId );
1764 // iterates on shapes and collect mesh entities into mesh preview
1765 TSetOfInt::const_iterator idIt = shapeIds.begin();
1766 TSetOfInt::const_iterator idEnd = shapeIds.end();
1767 std::map< int, int > mapOfShIdNb;
1768 std::set< SMESH_TLink > setOfEdge;
1769 std::list< SMDSAbs_ElementType > listOfElemType;
1770 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1771 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1772 TNode2LocalIDMap mapNode2LocalID;
1773 list< TNodeLocalID > connectivity;
1774 int i, nbConnNodes = 0;
1775 std::set< const SMESH_subMesh* > setOfVSubMesh;
1776 // iterates on shapes
1777 for ( ; idIt != idEnd; idIt++ )
1779 if ( mapOfShIdNb.find( *idIt ) != mapOfShIdNb.end() )
1781 SMESH_subMesh* sm = myLocMesh.GetSubMeshContaining(*idIt);
1782 if ( !sm || !sm->IsMeshComputed() )
1785 const TopoDS_Shape& aSh = sm->GetSubShape();
1786 const int shDim = myGen.GetShapeDim( aSh );
1787 if ( shDim < 1 || shDim > theDimension )
1790 mapOfShIdNb[ *idIt ] = 0;
1791 theShapesId[ mapOfShIdNb.size() - 1 ] = *idIt;
1793 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1794 if ( !smDS ) continue;
1796 if ( theDimension == SMESH::DIM_2D )
1798 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1799 while ( faceIt->more() )
1801 const SMDS_MeshElement* face = faceIt->next();
1802 int aNbNode = face->NbNodes();
1804 aNbNode /= 2; // do not take into account additional middle nodes
1806 SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
1807 for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
1809 SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
1810 if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
1812 listOfElemType.push_back( SMDSAbs_Edge );
1813 connectivity.push_back
1814 ( mapNode2LocalID.insert( make_pair( node1, ++nbConnNodes)).first );
1815 connectivity.push_back
1816 ( mapNode2LocalID.insert( make_pair( node2, ++nbConnNodes)).first );
1822 else if ( theDimension == SMESH::DIM_1D )
1824 SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
1825 while ( nodeIt->more() )
1827 listOfElemType.push_back( SMDSAbs_Node );
1828 connectivity.push_back
1829 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1831 // add corner nodes by first vertex from edge
1832 SMESH_subMeshIteratorPtr edgeSmIt =
1833 sm->getDependsOnIterator(/*includeSelf*/false,
1834 /*complexShapeFirst*/false);
1835 while ( edgeSmIt->more() )
1837 SMESH_subMesh* vertexSM = edgeSmIt->next();
1838 // check that vertex is not already treated
1839 if ( !setOfVSubMesh.insert( vertexSM ).second )
1841 if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
1844 const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
1845 SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
1846 while ( nodeIt->more() )
1848 listOfElemType.push_back( SMDSAbs_Node );
1849 connectivity.push_back
1850 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1856 // fill node coords and assign local ids to the nodes
1857 int nbNodes = mapNode2LocalID.size();
1858 result->nodesXYZ.length( nbNodes );
1859 TNodeLocalID node2ID = mapNode2LocalID.begin();
1860 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1861 node2ID->second = i;
1862 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1863 result->nodesXYZ[i].x = node->X();
1864 result->nodesXYZ[i].y = node->Y();
1865 result->nodesXYZ[i].z = node->Z();
1867 // fill connectivity
1868 result->elementConnectivities.length( nbConnNodes );
1869 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1870 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1871 result->elementConnectivities[i] = (*connIt)->second;
1874 // fill element types
1875 result->elementTypes.length( listOfElemType.size() );
1876 std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
1877 std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
1878 for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
1880 SMDSAbs_ElementType elemType = *typeIt;
1881 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
1882 result->elementTypes[i].isPoly = false;
1883 result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
1886 // correct number of shapes
1887 theShapesId.length( mapOfShIdNb.size() );
1891 catch ( std::bad_alloc ) {
1892 INFOS( "Precompute(): lack of memory" );
1894 catch ( SALOME_Exception& S_ex ) {
1895 INFOS( "Precompute(): catch exception "<< S_ex.what() );
1898 INFOS( "Precompute(): unknown exception " );
1900 return result._retn();
1904 //=============================================================================
1906 * SMESH_Gen_i::Evaluate
1908 * Evaluate mesh on a shape
1910 //=============================================================================
1912 SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
1913 GEOM::GEOM_Object_ptr theShapeObject)
1914 // SMESH::long_array& theNbElems)
1915 throw ( SALOME::SALOME_Exception )
1917 Unexpect aCatch(SALOME_SalomeException);
1918 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
1920 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1921 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1922 SALOME::BAD_PARAM );
1924 if ( CORBA::is_nil( theMesh ) )
1925 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1926 SALOME::BAD_PARAM );
1928 SMESH::long_array_var nbels = new SMESH::long_array;
1929 nbels->length(SMESH::Entity_Last);
1930 int i = SMESH::Entity_Node;
1931 for (; i < SMESH::Entity_Last; i++)
1934 // Update Python script
1935 TPythonDump() << "theNbElems = " << this << ".Evaluate( "
1936 << theMesh << ", " << theShapeObject << ")";
1940 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1941 ASSERT( meshServant );
1942 if ( meshServant ) {
1943 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1944 meshServant->CheckGeomGroupModif();
1945 // get local TopoDS_Shape
1946 TopoDS_Shape myLocShape;
1947 if(theMesh->HasShapeToMesh())
1948 myLocShape = GeomObjectToShape( theShapeObject );
1950 myLocShape = SMESH_Mesh::PseudoShape();
1951 // call implementation compute
1952 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1953 MapShapeNbElems aResMap;
1954 /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
1955 MapShapeNbElemsItr anIt = aResMap.begin();
1956 for(; anIt!=aResMap.end(); anIt++) {
1957 const vector<int>& aVec = (*anIt).second;
1958 for(i = SMESH::Entity_Node; i < aVec.size(); i++) {
1959 int nbElem = aVec[i];
1960 if ( nbElem < 0 ) // algo failed, check that it has reported a message
1962 SMESH_subMesh* sm = anIt->first;
1963 SMESH_ComputeErrorPtr& error = sm->GetComputeError();
1964 const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
1965 if ( (algo && !error.get()) || error->IsOK() )
1966 error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
1970 nbels[i] += aVec[i];
1974 return nbels._retn();
1977 catch ( std::bad_alloc ) {
1978 INFOS( "Evaluate(): lack of memory" );
1980 catch ( SALOME_Exception& S_ex ) {
1981 INFOS( "Evaluate(): catch exception "<< S_ex.what() );
1984 INFOS( "Evaluate(): unknown exception " );
1987 return nbels._retn();
1990 //================================================================================
1992 * \brief Return geometrical object the given element is built on
1993 * \param theMesh - the mesh the element is in
1994 * \param theElementID - the element ID
1995 * \param theGeomName - the name of the result geom object if it is not yet published
1996 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1998 //================================================================================
2000 GEOM::GEOM_Object_ptr
2001 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2002 CORBA::Long theElementID,
2003 const char* theGeomName)
2004 throw ( SALOME::SALOME_Exception )
2006 Unexpect aCatch(SALOME_SalomeException);
2008 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
2009 if ( !geom->_is_nil() ) {
2010 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2011 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2013 // try to find the corresponding SObject
2014 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
2015 if ( SObj->_is_nil() ) // submesh can be not found even if published
2017 // try to find published submesh
2018 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
2019 if ( !geom->IsMainShape() && list->length() == 1 ) {
2020 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2021 SALOMEDS::ChildIterator_var it;
2022 if ( !mainSO->_is_nil() )
2023 it = myCurrentStudy->NewChildIterator( mainSO );
2024 if ( !it->_is_nil() ) {
2025 for ( it->InitEx(true); SObj->_is_nil() && it->More(); it->Next() ) {
2026 GEOM::GEOM_Object_var subGeom =
2027 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
2028 if ( !subGeom->_is_nil() ) {
2029 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2030 if ( subList->length() == 1 && list[0] == subList[0] ) {
2039 if ( SObj->_is_nil() ) // publish a new subshape
2040 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
2042 // return only published geometry
2043 if ( !SObj->_is_nil() )
2044 return geom._retn();
2046 return GEOM::GEOM_Object::_nil();
2049 //================================================================================
2051 * \brief Return geometrical object the given element is built on.
2052 * \param theMesh - the mesh the element is in
2053 * \param theElementID - the element ID
2054 * \retval GEOM::GEOM_Object_ptr - the found geom object
2056 //================================================================================
2058 GEOM::GEOM_Object_ptr
2059 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2060 CORBA::Long theElementID)
2061 throw ( SALOME::SALOME_Exception )
2063 Unexpect aCatch(SALOME_SalomeException);
2064 if ( CORBA::is_nil( theMesh ) )
2065 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
2067 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2068 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2070 // get a core mesh DS
2071 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
2072 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
2074 ::SMESH_Mesh & mesh = meshServant->GetImpl();
2075 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
2076 // find the element in mesh
2077 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
2078 // find a shape id by the element
2079 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
2080 // get a geom object by the shape id
2081 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
2082 if ( geom->_is_nil() ) {
2083 // try to find a published sub-shape
2084 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2085 SALOMEDS::ChildIterator_var it;
2086 if ( !mainSO->_is_nil() )
2087 it = myCurrentStudy->NewChildIterator( mainSO );
2088 if ( !it->_is_nil() ) {
2089 for ( it->InitEx(true); it->More(); it->Next() ) {
2090 GEOM::GEOM_Object_var subGeom =
2091 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
2092 if ( !subGeom->_is_nil() ) {
2093 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2094 if ( subList->length() == 1 && shapeID == subList[0] ) {
2102 if ( geom->_is_nil() ) {
2104 GEOM::GEOM_IShapesOperations_var op =
2105 geomGen->GetIShapesOperations( GetCurrentStudyID() );
2106 if ( !op->_is_nil() )
2107 geom = op->GetSubShape( mainShape, shapeID );
2109 if ( !geom->_is_nil() ) {
2110 GeomObjectToShape( geom ); // let geom client remember the found shape
2111 return geom._retn();
2116 return GEOM::GEOM_Object::_nil();
2119 //================================================================================
2121 * SMESH_Gen_i::Concatenate
2123 * Concatenate the given meshes into one mesh
2125 //================================================================================
2127 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
2128 CORBA::Boolean theUniteIdenticalGroups,
2129 CORBA::Boolean theMergeNodesAndElements,
2130 CORBA::Double theMergeTolerance)
2131 throw ( SALOME::SALOME_Exception )
2133 return ConcatenateCommon(theMeshesArray,
2134 theUniteIdenticalGroups,
2135 theMergeNodesAndElements,
2140 //================================================================================
2142 * SMESH_Gen_i::ConcatenateWithGroups
2144 * Concatenate the given meshes into one mesh
2145 * Create the groups of all elements from initial meshes
2147 //================================================================================
2149 SMESH::SMESH_Mesh_ptr
2150 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
2151 CORBA::Boolean theUniteIdenticalGroups,
2152 CORBA::Boolean theMergeNodesAndElements,
2153 CORBA::Double theMergeTolerance)
2154 throw ( SALOME::SALOME_Exception )
2156 return ConcatenateCommon(theMeshesArray,
2157 theUniteIdenticalGroups,
2158 theMergeNodesAndElements,
2163 //================================================================================
2165 * SMESH_Gen_i::ConcatenateCommon
2167 * Concatenate the given meshes into one mesh
2169 //================================================================================
2171 SMESH::SMESH_Mesh_ptr
2172 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
2173 CORBA::Boolean theUniteIdenticalGroups,
2174 CORBA::Boolean theMergeNodesAndElements,
2175 CORBA::Double theMergeTolerance,
2176 CORBA::Boolean theCommonGroups)
2177 throw ( SALOME::SALOME_Exception )
2179 typedef map<int, int> TIDsMap;
2180 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
2181 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
2182 typedef std::set<SMESHDS_GroupBase*> TGroups;
2184 TPythonDump* pPythonDump = new TPythonDump;
2185 TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
2188 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
2190 SMESHDS_Mesh* aNewMeshDS = 0;
2191 if ( !aNewMesh->_is_nil() ) {
2192 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
2194 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
2195 aNewMeshDS = aLocMesh.GetMeshDS();
2197 TGroupsMap aGroupsMap;
2198 TListOfNewGroups aListOfNewGroups;
2199 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
2200 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
2203 for ( int i = 0; i < theMeshesArray.length(); i++) {
2204 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
2205 if ( !anInitMesh->_is_nil() ) {
2206 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
2208 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
2209 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
2214 // loop on elements of mesh
2215 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
2216 const SMDS_MeshElement* anElem = 0;
2217 const SMDS_MeshElement* aNewElem = 0;
2218 int anElemNbNodes = 0;
2223 int anNbVolumes = 0;
2226 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
2227 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
2228 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
2229 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
2230 SMESH::long_array_var anIDsBalls = new SMESH::long_array();
2232 if( theCommonGroups ) {
2233 anIDsNodes->length( anInitMeshDS->NbNodes() );
2234 anIDsEdges->length( anInitMeshDS->NbEdges() );
2235 anIDsFaces->length( anInitMeshDS->NbFaces() );
2236 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
2237 anIDsBalls->length( anInitMeshDS->NbBalls() );
2240 for ( int j = 0; itElems->more(); j++) {
2241 anElem = itElems->next();
2242 SMDSAbs_ElementType anElemType = anElem->GetType();
2243 anElemNbNodes = anElem->NbNodes();
2244 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
2246 // loop on nodes of element
2247 const SMDS_MeshNode* aNode = 0;
2248 const SMDS_MeshNode* aNewNode = 0;
2249 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
2251 for ( int k = 0; itNodes->more(); k++) {
2252 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
2253 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
2254 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2255 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2256 if( theCommonGroups )
2257 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2260 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
2261 aNodesArray[k] = aNewNode;
2264 // creates a corresponding element on existent nodes in new mesh
2265 switch ( anElem->GetEntityType() ) {
2266 case SMDSEntity_Polyhedra:
2267 if ( const SMDS_VtkVolume* aVolume =
2268 dynamic_cast<const SMDS_VtkVolume*> (anElem))
2270 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
2271 aVolume->GetQuantities());
2272 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2273 if( theCommonGroups )
2274 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2277 case SMDSEntity_Ball:
2278 if ( const SMDS_BallElement* aBall =
2279 dynamic_cast<const SMDS_BallElement*> (anElem))
2281 aNewElem = aNewEditor.AddElement(aNodesArray, SMDSAbs_Ball,
2282 /*isPoly=*/false, /*id=*/0,
2283 aBall->GetDiameter() );
2284 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2285 if( theCommonGroups )
2286 anIDsBalls[aNbBalls++] = aNewElem->GetID();
2291 aNewElem = aNewEditor.AddElement(aNodesArray,
2294 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2295 if( theCommonGroups ) {
2296 if( anElemType == SMDSAbs_Edge )
2297 anIDsEdges[anNbEdges++] = aNewElem->GetID();
2298 else if( anElemType == SMDSAbs_Face )
2299 anIDsFaces[anNbFaces++] = aNewElem->GetID();
2300 else if( anElemType == SMDSAbs_Volume )
2301 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2307 // copy orphan nodes
2308 SMDS_NodeIteratorPtr itNodes = anInitMeshDS->nodesIterator();
2309 while ( itNodes->more() )
2311 const SMDS_MeshNode* aNode = itNodes->next();
2312 if ( aNode->NbInverseElements() == 0 )
2314 const SMDS_MeshNode* aNewNode =
2315 aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2316 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2317 if( theCommonGroups )
2318 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2323 aListOfGroups = anInitImpl->GetGroups();
2324 SMESH::SMESH_GroupBase_ptr aGroup;
2326 // loop on groups of mesh
2327 SMESH::long_array_var anInitIDs = new SMESH::long_array();
2328 SMESH::long_array_var anNewIDs = new SMESH::long_array();
2329 SMESH::SMESH_Group_var aNewGroup;
2331 SMESH::ElementType aGroupType;
2332 CORBA::String_var aGroupName;
2333 if ( theCommonGroups ) {
2334 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::BALL;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
2336 SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
2338 str += aMeshSObj->GetName();
2343 switch(aGroupType) {
2346 anIDsNodes->length(anNbNodes);
2351 anIDsEdges->length(anNbEdges);
2356 anIDsFaces->length(anNbFaces);
2361 anIDsVolumes->length(anNbVolumes);
2362 anLen = anNbVolumes;
2366 anIDsBalls->length(aNbBalls);
2374 aGroupName = str.c_str();
2376 // add a new group in the mesh
2377 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2379 switch(aGroupType) {
2381 aNewGroup->Add( anIDsNodes );
2384 aNewGroup->Add( anIDsEdges );
2387 aNewGroup->Add( anIDsFaces );
2390 aNewGroup->Add( anIDsVolumes );
2393 aNewGroup->Add( anIDsBalls );
2399 aListOfNewGroups.clear();
2400 aListOfNewGroups.push_back(aNewGroup);
2401 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2406 // check that current group name and type don't have identical ones in union mesh
2407 for (int i = 0; i < aListOfGroups->length(); i++) {
2408 aGroup = aListOfGroups[i];
2409 aListOfNewGroups.clear();
2410 aGroupType = aGroup->GetType();
2411 aGroupName = aGroup->GetName();
2413 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
2415 // convert a list of IDs
2416 anInitIDs = aGroup->GetListOfID();
2417 anNewIDs->length(anInitIDs->length());
2418 if ( aGroupType == SMESH::NODE )
2419 for (int j = 0; j < anInitIDs->length(); j++) {
2420 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
2423 for (int j = 0; j < anInitIDs->length(); j++) {
2424 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
2427 // check that current group name and type don't have identical ones in union mesh
2428 if ( anIter == aGroupsMap.end() ) {
2429 // add a new group in the mesh
2430 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2431 // add elements into new group
2432 aNewGroup->Add( anNewIDs );
2434 aListOfNewGroups.push_back(aNewGroup);
2435 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2438 else if ( theUniteIdenticalGroups ) {
2439 // unite identical groups
2440 TListOfNewGroups& aNewGroups = anIter->second;
2441 aNewGroups.front()->Add( anNewIDs );
2445 // rename identical groups
2446 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2447 aNewGroup->Add( anNewIDs );
2449 TListOfNewGroups& aNewGroups = anIter->second;
2450 string aNewGroupName;
2451 if (aNewGroups.size() == 1) {
2452 aNewGroupName = string(aGroupName) + "_1";
2453 aNewGroups.front()->SetName(aNewGroupName.c_str());
2455 char aGroupNum[128];
2456 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
2457 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
2458 aNewGroup->SetName(aNewGroupName.c_str());
2459 aNewGroups.push_back(aNewGroup);
2466 if (theMergeNodesAndElements) {
2468 TIDSortedNodeSet aMeshNodes; // no input nodes
2469 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
2470 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
2471 aNewEditor.MergeNodes( aGroupsOfNodes );
2473 aNewEditor.MergeEqualElements();
2478 // Update Python script
2479 aPythonDump << aNewMesh << " = " << this;
2480 if( !theCommonGroups )
2481 aPythonDump << ".Concatenate(";
2483 aPythonDump << ".ConcatenateWithGroups(";
2485 for ( int i = 0; i < theMeshesArray.length(); i++) {
2486 if (i > 0) aPythonDump << ", ";
2487 aPythonDump << theMeshesArray[i];
2489 aPythonDump << "], ";
2490 aPythonDump << theUniteIdenticalGroups << ", "
2491 << theMergeNodesAndElements << ", "
2492 << TVar( theMergeTolerance ) << ")";
2494 delete pPythonDump; // enable python dump from GetGroups()
2496 // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
2497 if ( !aNewMesh->_is_nil() )
2499 SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
2502 // IPAL21468 Change icon of compound because it need not be computed.
2503 SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
2504 SetPixMap( aMeshSObj, "ICON_SMESH_TREE_MESH" );
2507 aNewMeshDS->Modified();
2508 return aNewMesh._retn();
2511 //================================================================================
2513 * \brief Create a mesh by copying a part of another mesh
2514 * \param meshPart - a part of mesh to copy
2515 * \param toCopyGroups - to create in the new mesh groups
2516 * the copied elements belongs to
2517 * \param toKeepIDs - to preserve IDs of the copied elements or not
2518 * \retval SMESH::SMESH_Mesh_ptr - the new mesh
2520 //================================================================================
2522 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
2523 const char* meshName,
2524 CORBA::Boolean toCopyGroups,
2525 CORBA::Boolean toKeepIDs)
2527 Unexpect aCatch(SALOME_SalomeException);
2529 TPythonDump* pyDump = new TPythonDump; // prevent dump from CreateMesh()
2531 // 1. Get source mesh
2533 if ( CORBA::is_nil( meshPart ))
2534 THROW_SALOME_CORBA_EXCEPTION( "bad IDSource", SALOME::BAD_PARAM );
2536 SMESH::SMESH_Mesh_var srcMesh = meshPart->GetMesh();
2537 SMESH_Mesh_i* srcMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( srcMesh );
2539 THROW_SALOME_CORBA_EXCEPTION( "bad mesh of IDSource", SALOME::BAD_PARAM );
2541 SMESHDS_Mesh* srcMeshDS = srcMesh_i->GetImpl().GetMeshDS();
2543 // 2. Make a new mesh
2545 SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil());
2546 SMESH_Mesh_i* newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( newMesh );
2548 THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR );
2549 SALOMEDS::SObject_var meshSO = ObjectToSObject(myCurrentStudy, newMesh );
2550 if ( !meshSO->_is_nil() )
2552 SetName( meshSO, meshName, "Mesh" );
2553 SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
2555 SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
2556 ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
2558 // 3. Get elements to copy
2560 SMDS_ElemIteratorPtr srcElemIt; SMDS_NodeIteratorPtr srcNodeIt;
2561 TIDSortedElemSet srcElems;
2562 SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes();
2563 if ( SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
2565 srcElemIt = srcMeshDS->elementsIterator();
2566 srcNodeIt = srcMeshDS->nodesIterator();
2570 SMESH::long_array_var ids = meshPart->GetIDs();
2571 if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes
2573 for (int i=0; i < ids->length(); i++)
2574 if ( const SMDS_MeshElement * elem = srcMeshDS->FindNode( ids[i] ))
2575 srcElems.insert( elem );
2579 for (int i=0; i < ids->length(); i++)
2580 if ( const SMDS_MeshElement * elem = srcMeshDS->FindElement( ids[i] ))
2581 srcElems.insert( elem );
2583 if ( srcElems.empty() )
2584 return newMesh._retn();
2586 typedef SMDS_SetIterator< SMDS_pElement, TIDSortedElemSet::const_iterator > ElIter;
2587 srcElemIt = SMDS_ElemIteratorPtr( new ElIter( srcElems.begin(), srcElems.end() ));
2592 typedef map<SMDS_pElement, SMDS_pElement, TIDCompare> TE2EMap;
2593 TE2EMap e2eMapByType[ SMDSAbs_NbElementTypes ];
2594 TE2EMap& n2nMap = e2eMapByType[ SMDSAbs_Node ];
2596 const SMDS_MeshNode *nSrc, *nTgt;
2597 vector< const SMDS_MeshNode* > nodes;
2598 while ( srcElemIt->more() )
2600 const SMDS_MeshElement * elem = srcElemIt->next();
2602 nodes.resize( elem->NbNodes());
2603 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2605 for ( iN = 0; nIt->more(); ++iN )
2607 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2608 nTgt = newMeshDS->FindNode( nSrc->GetID());
2610 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2615 for ( iN = 0; nIt->more(); ++iN )
2617 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2618 TE2EMap::iterator n2n = n2nMap.insert( make_pair( nSrc, SMDS_pNode(0) )).first;
2620 n2n->second = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2621 nodes[ iN ] = (const SMDS_MeshNode*) n2n->second;
2625 if ( elem->GetType() != SMDSAbs_Node )
2627 int ID = toKeepIDs ? elem->GetID() : 0;
2628 const SMDS_MeshElement * newElem;
2629 switch ( elem->GetEntityType() ) {
2630 case SMDSEntity_Polyhedra:
2631 newElem = editor.GetMeshDS()->
2632 AddPolyhedralVolumeWithID( nodes,
2633 static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
2636 case SMDSEntity_Ball:
2637 newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID,
2638 static_cast<const SMDS_BallElement*>(elem)->GetDiameter());
2641 newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID);
2643 if ( toCopyGroups && !toKeepIDs )
2644 e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem ));
2647 } // while ( srcElemIt->more() )
2649 // 4(b). Copy free nodes
2651 if ( srcNodeIt && srcMeshDS->NbNodes() != newMeshDS->NbNodes() )
2653 while ( srcNodeIt->more() )
2655 nSrc = srcNodeIt->next();
2656 if ( nSrc->NbInverseElements() == 0 )
2659 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2661 n2nMap[ nSrc ] = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2668 int nbNewGroups = 0;
2671 SMESH_Mesh::GroupIteratorPtr gIt = srcMesh_i->GetImpl().GetGroups();
2672 while ( gIt->more() )
2674 SMESH_Group* group = gIt->next();
2675 const SMESHDS_GroupBase* groupDS = group->GetGroupDS();
2677 // Check group type. We copy nodal groups containing nodes of copied element
2678 SMDSAbs_ElementType groupType = groupDS->GetType();
2679 if ( groupType != SMDSAbs_Node &&
2680 newMeshDS->GetMeshInfo().NbElements( groupType ) == 0 )
2681 continue; // group type differs from types of meshPart
2683 // Find copied elements in the group
2684 vector< const SMDS_MeshElement* > groupElems;
2685 SMDS_ElemIteratorPtr eIt = groupDS->GetElements();
2688 const SMDS_MeshElement* foundElem;
2689 if ( groupType == SMDSAbs_Node )
2691 while ( eIt->more() )
2692 if (( foundElem = newMeshDS->FindNode( eIt->next()->GetID() )))
2693 groupElems.push_back( foundElem );
2697 while ( eIt->more() )
2698 if (( foundElem = newMeshDS->FindElement( eIt->next()->GetID() )))
2699 groupElems.push_back( foundElem );
2704 TE2EMap & e2eMap = e2eMapByType[ groupDS->GetType() ];
2705 if ( e2eMap.empty() ) continue;
2706 int minID = e2eMap.begin()->first->GetID();
2707 int maxID = e2eMap.rbegin()->first->GetID();
2708 TE2EMap::iterator e2e;
2709 while ( eIt->more() && groupElems.size() < e2eMap.size())
2711 const SMDS_MeshElement* e = eIt->next();
2712 if ( e->GetID() < minID || e->GetID() > maxID ) continue;
2713 if ((e2e = e2eMap.find( e )) != e2eMap.end())
2714 groupElems.push_back( e2e->second );
2718 if ( !groupElems.empty() )
2720 SMESH::SMESH_Group_var newGroupObj =
2721 newMesh->CreateGroup( SMESH::ElementType(groupType), group->GetName() );
2722 if ( SMESH_GroupBase_i* newGroup_i = SMESH::DownCast<SMESH_GroupBase_i*>( newGroupObj))
2724 SMESHDS_GroupBase * newGroupDS = newGroup_i->GetGroupDS();
2725 SMDS_MeshGroup& smdsGroup = ((SMESHDS_Group*)newGroupDS)->SMDSGroup();
2726 for ( unsigned i = 0; i < groupElems.size(); ++i )
2727 smdsGroup.Add( groupElems[i] );
2735 newMeshDS->Modified();
2737 *pyDump << newMesh << " = " << this
2738 << ".CopyMesh( " << meshPart << ", "
2739 << "'" << meshName << "', "
2740 << toCopyGroups << ", "
2741 << toKeepIDs << ")";
2743 delete pyDump; pyDump = 0; // allow dump in GetGroups()
2745 if ( nbNewGroups > 0 ) // dump created groups
2746 SMESH::ListOfGroups_var groups = newMesh->GetGroups();
2748 return newMesh._retn();
2751 //================================================================================
2753 * SMESH_Gen_i::GetMEDVersion
2755 * Get MED version of the file by its name
2757 //================================================================================
2758 CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
2759 SMESH::MED_VERSION& theVersion)
2761 theVersion = SMESH::MED_V2_1;
2762 MED::EVersion aVersion = MED::GetVersionId( theFileName );
2763 switch( aVersion ) {
2764 case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
2765 case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
2766 case MED::eVUnknown : return false;
2771 //================================================================================
2773 * SMESH_Gen_i::GetMeshNames
2775 * Get names of meshes defined in file with the specified name
2777 //================================================================================
2778 SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
2780 SMESH::string_array_var aResult = new SMESH::string_array();
2781 MED::PWrapper aMed = MED::CrWrapper( theFileName );
2783 MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
2785 aResult->length( aNbMeshes );
2786 for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
2787 MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
2788 aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
2791 return aResult._retn();
2794 //=============================================================================
2798 * Save SMESH module's data
2800 //=============================================================================
2801 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
2805 INFOS( "SMESH_Gen_i::Save" );
2807 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
2808 // san -- in case <myCurrentStudy> differs from theComponent's study,
2809 // use that of the component
2810 if ( myCurrentStudy->_is_nil() ||
2811 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2812 SetCurrentStudy( theComponent->GetStudy() );
2814 // Store study contents as a set of python commands
2815 SavePython(myCurrentStudy);
2817 StudyContext* myStudyContext = GetCurrentStudyContext();
2819 // Declare a byte stream
2820 SALOMEDS::TMPFile_var aStreamFile;
2822 // Obtain a temporary dir
2823 TCollection_AsciiString tmpDir =
2824 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2826 // Create a sequence of files processed
2827 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2828 aFileSeq->length( NUM_TMP_FILES );
2830 TCollection_AsciiString aStudyName( "" );
2832 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2834 // Set names of temporary files
2835 TCollection_AsciiString filename =
2836 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
2837 TCollection_AsciiString meshfile =
2838 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
2839 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
2840 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
2841 filename = tmpDir + filename;
2842 meshfile = tmpDir + meshfile;
2845 HDFdataset* aDataset;
2846 HDFgroup* aTopGroup;
2848 HDFgroup* aSubGroup;
2849 HDFgroup* aSubSubGroup;
2850 hdf_size aSize[ 1 ];
2853 //Remove the files if they exist: BugID: 11225
2854 #ifndef WNT /* unix functionality */
2855 TCollection_AsciiString cmd("rm -f \"");
2857 TCollection_AsciiString cmd("del /F \"");
2864 system(cmd.ToCString());
2866 // MED writer to be used by storage process
2867 DriverMED_W_SMESHDS_Mesh myWriter;
2868 myWriter.SetFile( meshfile.ToCString() );
2871 // SetStoreName() to groups before storing hypotheses to let them refer to
2872 // groups using "store name", which is "Group <group_persistent_id>"
2874 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
2875 for ( ; itBig->More(); itBig->Next() ) {
2876 SALOMEDS::SObject_var gotBranch = itBig->Value();
2877 if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
2878 CORBA::Object_var anObject = SObjectToObject( gotBranch );
2879 if ( !CORBA::is_nil( anObject ) ) {
2880 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
2881 if ( !myMesh->_is_nil() ) {
2882 myMesh->Load(); // load from study file if not yet done
2883 TPythonDump pd; // not to dump GetGroups()
2884 SMESH::ListOfGroups_var groups = myMesh->GetGroups();
2885 pd << ""; // to avoid optimizing pd out
2886 for ( int i = 0; i < groups->length(); ++i )
2888 SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
2891 CORBA::String_var objStr = GetORB()->object_to_string( grImpl->_this() );
2892 int anId = myStudyContext->findId( string( objStr.in() ) );
2894 sprintf( grpName, "Group %d", anId );
2895 SMESHDS_GroupBase* aGrpBaseDS = grImpl->GetGroupDS();
2896 aGrpBaseDS->SetStoreName( grpName );
2906 // ---> create HDF file
2907 aFile = new HDFfile( (char*) filename.ToCString() );
2908 aFile->CreateOnDisk();
2910 // --> iterator for top-level objects
2911 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
2912 for ( ; itBig->More(); itBig->Next() ) {
2913 SALOMEDS::SObject_var gotBranch = itBig->Value();
2915 // --> hypotheses root branch (only one for the study)
2916 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
2917 // create hypotheses root HDF group
2918 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2919 aTopGroup->CreateOnDisk();
2921 // iterator for all hypotheses
2922 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
2923 for ( ; it->More(); it->Next() ) {
2924 SALOMEDS::SObject_var mySObject = it->Value();
2925 CORBA::Object_var anObject = SObjectToObject( mySObject );
2926 if ( !CORBA::is_nil( anObject ) ) {
2927 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2928 if ( !myHyp->_is_nil() ) {
2929 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2931 string hypname = string( myHyp->GetName() );
2932 string libname = string( myHyp->GetLibName() );
2934 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
2935 // WNT and ".so" for X-system) must be deleted
2936 int libname_len = libname.length();
2938 if( libname_len > 4 )
2939 libname.resize( libname_len - 4 );
2941 // PAL17753 (Regresion: missing hypothesis in restored study)
2942 // "lib" also should be removed from the beginning
2943 //if( libname_len > 3 )
2944 //libname.resize( libname_len - 3 );
2945 if( libname_len > 6 )
2946 libname = libname.substr( 3, libname_len - 3 - 3 );
2948 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2949 int id = myStudyContext->findId( string( objStr.in() ) );
2950 string hypdata = string( myImpl->SaveTo() );
2952 // for each hypothesis create HDF group basing on its id
2953 char hypGrpName[30];
2954 sprintf( hypGrpName, "Hypothesis %d", id );
2955 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2956 aGroup->CreateOnDisk();
2957 // --> type name of hypothesis
2958 aSize[ 0 ] = hypname.length() + 1;
2959 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
2960 aDataset->CreateOnDisk();
2961 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
2962 aDataset->CloseOnDisk();
2963 // --> server plugin library name of hypothesis
2964 aSize[ 0 ] = libname.length() + 1;
2965 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
2966 aDataset->CreateOnDisk();
2967 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
2968 aDataset->CloseOnDisk();
2969 // --> persistent data of hypothesis
2970 aSize[ 0 ] = hypdata.length() + 1;
2971 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
2972 aDataset->CreateOnDisk();
2973 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
2974 aDataset->CloseOnDisk();
2975 // close hypothesis HDF group
2976 aGroup->CloseOnDisk();
2981 // close hypotheses root HDF group
2982 aTopGroup->CloseOnDisk();
2984 // --> algorithms root branch (only one for the study)
2985 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
2986 // create algorithms root HDF group
2987 aTopGroup = new HDFgroup( "Algorithms", aFile );
2988 aTopGroup->CreateOnDisk();
2990 // iterator for all algorithms
2991 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
2992 for ( ; it->More(); it->Next() ) {
2993 SALOMEDS::SObject_var mySObject = it->Value();
2994 CORBA::Object_var anObject = SObjectToObject( mySObject );
2995 if ( !CORBA::is_nil( anObject ) ) {
2996 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2997 if ( !myHyp->_is_nil() ) {
2998 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3000 string hypname = string( myHyp->GetName() );
3001 string libname = string( myHyp->GetLibName() );
3003 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
3004 // WNT and ".so" for X-system) must be deleted
3005 int libname_len = libname.length();
3007 if( libname_len > 4 )
3008 libname.resize( libname_len - 4 );
3010 // PAL17753 (Regresion: missing hypothesis in restored study)
3011 // "lib" also should be removed from the beginning
3012 //if( libname_len > 3 )
3013 //libname.resize( libname_len - 3 );
3014 if( libname_len > 6 )
3015 libname = libname.substr( 3, libname_len - 3 - 3 );
3017 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3018 int id = myStudyContext->findId( string( objStr.in() ) );
3019 string hypdata = string( myImpl->SaveTo() );
3021 // for each algorithm create HDF group basing on its id
3022 char hypGrpName[30];
3023 sprintf( hypGrpName, "Algorithm %d", id );
3024 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3025 aGroup->CreateOnDisk();
3026 // --> type name of algorithm
3027 aSize[0] = hypname.length() + 1;
3028 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3029 aDataset->CreateOnDisk();
3030 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3031 aDataset->CloseOnDisk();
3032 // --> server plugin library name of hypothesis
3033 aSize[0] = libname.length() + 1;
3034 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3035 aDataset->CreateOnDisk();
3036 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3037 aDataset->CloseOnDisk();
3038 // --> persistent data of algorithm
3039 aSize[0] = hypdata.length() + 1;
3040 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3041 aDataset->CreateOnDisk();
3042 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3043 aDataset->CloseOnDisk();
3044 // close algorithm HDF group
3045 aGroup->CloseOnDisk();
3050 // close algorithms root HDF group
3051 aTopGroup->CloseOnDisk();
3053 // --> mesh objects roots branches
3054 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
3055 CORBA::Object_var anObject = SObjectToObject( gotBranch );
3056 if ( !CORBA::is_nil( anObject ) ) {
3057 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
3058 if ( !myMesh->_is_nil() ) {
3059 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
3061 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3062 int id = myStudyContext->findId( string( objStr.in() ) );
3063 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
3064 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3065 bool hasShape = myLocMesh.HasShapeToMesh();
3067 // for each mesh open the HDF group basing on its id
3068 char meshGrpName[ 30 ];
3069 sprintf( meshGrpName, "Mesh %d", id );
3070 aTopGroup = new HDFgroup( meshGrpName, aFile );
3071 aTopGroup->CreateOnDisk();
3073 // --> put dataset to hdf file which is a flag that mesh has data
3074 string strHasData = "0";
3075 // check if the mesh is not empty
3076 if ( mySMESHDSMesh->NbNodes() > 0 ) {
3077 // write mesh data to med file
3078 myWriter.SetMesh( mySMESHDSMesh );
3079 myWriter.SetMeshId( id );
3082 aSize[ 0 ] = strHasData.length() + 1;
3083 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
3084 aDataset->CreateOnDisk();
3085 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
3086 aDataset->CloseOnDisk();
3089 // for each mesh open the HDF group basing on its auto color parameter
3090 char meshAutoColorName[ 30 ];
3091 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
3093 anAutoColor[0] = myImpl->GetAutoColor();
3095 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
3096 aDataset->CreateOnDisk();
3097 aDataset->WriteOnDisk( anAutoColor );
3098 aDataset->CloseOnDisk();
3100 // issue 0020693. Store _isModified flag
3101 int isModified = myLocMesh.GetIsModified();
3103 aDataset = new HDFdataset( "_isModified", aTopGroup, HDF_INT32, aSize, 1 );
3104 aDataset->CreateOnDisk();
3105 aDataset->WriteOnDisk( &isModified );
3106 aDataset->CloseOnDisk();
3108 // issue 20918. Store Persistent Id of SMESHDS_Mesh
3109 int meshPersistentId = mySMESHDSMesh->GetPersistentId();
3111 aDataset = new HDFdataset( "meshPersistentId", aTopGroup, HDF_INT32, aSize, 1 );
3112 aDataset->CreateOnDisk();
3113 aDataset->WriteOnDisk( &meshPersistentId );
3114 aDataset->CloseOnDisk();
3116 // write reference on a shape if exists
3117 SALOMEDS::SObject_var myRef;
3118 bool shapeRefFound = false;
3119 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
3121 SALOMEDS::SObject_var myShape;
3122 bool ok = myRef->ReferencedObject( myShape );
3124 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
3125 string myRefOnObject = myShape->GetID();
3126 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
3127 aSize[ 0 ] = myRefOnObject.length() + 1;
3128 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
3129 aDataset->CreateOnDisk();
3130 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3131 aDataset->CloseOnDisk();
3136 // write applied hypotheses if exist
3137 SALOMEDS::SObject_var myHypBranch;
3138 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
3139 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
3140 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
3142 if ( found && (shapeRefFound || !hasShape) ) {
3143 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3144 aGroup->CreateOnDisk();
3146 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
3148 for ( ; it->More(); it->Next() ) {
3149 SALOMEDS::SObject_var mySObject = it->Value();
3150 SALOMEDS::SObject_var myRefOnHyp;
3151 bool ok = mySObject->ReferencedObject( myRefOnHyp );
3153 // san - it is impossible to recover applied hypotheses
3154 // using their entries within Load() method,
3155 // for there are no AttributeIORs in the study when Load() is working.
3156 // Hence, it is better to store persistent IDs of hypotheses as references to them
3158 //string myRefOnObject = myRefOnHyp->GetID();
3159 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3160 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3161 int id = myStudyContext->findId( string( objStr.in() ) );
3162 //if ( myRefOnObject.length() > 0 ) {
3163 //aSize[ 0 ] = myRefOnObject.length() + 1;
3164 char hypName[ 30 ], hypId[ 30 ];
3165 sprintf( hypName, "Hyp %d", ++hypNb );
3166 sprintf( hypId, "%d", id );
3167 aSize[ 0 ] = strlen( hypId ) + 1;
3168 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
3169 aDataset->CreateOnDisk();
3170 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3171 aDataset->WriteOnDisk( hypId );
3172 aDataset->CloseOnDisk();
3176 aGroup->CloseOnDisk();
3179 // write applied algorithms if exist
3180 SALOMEDS::SObject_var myAlgoBranch;
3181 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
3182 if ( found && !shapeRefFound && hasShape) { // remove applied algos
3183 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
3185 if ( found && (shapeRefFound || !hasShape)) {
3186 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3187 aGroup->CreateOnDisk();
3189 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
3191 for ( ; it->More(); it->Next() ) {
3192 SALOMEDS::SObject_var mySObject = it->Value();
3193 SALOMEDS::SObject_var myRefOnAlgo;
3194 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
3196 // san - it is impossible to recover applied algorithms
3197 // using their entries within Load() method,
3198 // for there are no AttributeIORs in the study when Load() is working.
3199 // Hence, it is better to store persistent IDs of algorithms as references to them
3201 //string myRefOnObject = myRefOnAlgo->GetID();
3202 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3203 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3204 int id = myStudyContext->findId( string( objStr.in() ) );
3205 //if ( myRefOnObject.length() > 0 ) {
3206 //aSize[ 0 ] = myRefOnObject.length() + 1;
3207 char algoName[ 30 ], algoId[ 30 ];
3208 sprintf( algoName, "Algo %d", ++algoNb );
3209 sprintf( algoId, "%d", id );
3210 aSize[ 0 ] = strlen( algoId ) + 1;
3211 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
3212 aDataset->CreateOnDisk();
3213 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3214 aDataset->WriteOnDisk( algoId );
3215 aDataset->CloseOnDisk();
3219 aGroup->CloseOnDisk();
3222 // --> submesh objects sub-branches
3224 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
3225 SALOMEDS::SObject_var mySubmeshBranch;
3226 found = gotBranch->FindSubObject( i, mySubmeshBranch );
3228 if ( found ) // check if there is shape reference in submeshes
3230 bool hasShapeRef = false;
3231 SALOMEDS::ChildIterator_var itSM =
3232 myCurrentStudy->NewChildIterator( mySubmeshBranch );
3233 for ( ; itSM->More(); itSM->Next() ) {
3234 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
3235 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
3236 mySubRef->ReferencedObject( myShape );
3237 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
3240 { // remove one submesh
3241 if ( shapeRefFound )
3242 { // unassign hypothesis
3243 SMESH::SMESH_subMesh_var mySubMesh =
3244 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
3245 if ( !mySubMesh->_is_nil() ) {
3246 int shapeID = mySubMesh->GetId();
3247 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
3248 const list<const SMESHDS_Hypothesis*>& hypList =
3249 mySMESHDSMesh->GetHypothesis( S );
3250 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
3251 while ( hyp != hypList.end() ) {
3252 int hypID = (*hyp++)->GetID(); // goto next hyp here because
3253 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
3257 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
3259 } // loop on submeshes of a type
3260 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
3261 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
3264 } // end check if there is shape reference in submeshes
3266 char name_meshgroup[ 30 ];
3267 if ( i == GetSubMeshOnVertexTag() )
3268 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3269 else if ( i == GetSubMeshOnEdgeTag() )
3270 strcpy( name_meshgroup, "SubMeshes On Edge" );
3271 else if ( i == GetSubMeshOnWireTag() )
3272 strcpy( name_meshgroup, "SubMeshes On Wire" );
3273 else if ( i == GetSubMeshOnFaceTag() )
3274 strcpy( name_meshgroup, "SubMeshes On Face" );
3275 else if ( i == GetSubMeshOnShellTag() )
3276 strcpy( name_meshgroup, "SubMeshes On Shell" );
3277 else if ( i == GetSubMeshOnSolidTag() )
3278 strcpy( name_meshgroup, "SubMeshes On Solid" );
3279 else if ( i == GetSubMeshOnCompoundTag() )
3280 strcpy( name_meshgroup, "SubMeshes On Compound" );
3282 // for each type of submeshes create container HDF group
3283 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3284 aGroup->CreateOnDisk();
3286 // iterator for all submeshes of given type
3287 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
3288 for ( ; itSM->More(); itSM->Next() ) {
3289 SALOMEDS::SObject_var mySObject = itSM->Value();
3290 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
3291 if ( !CORBA::is_nil( anSubObject ))
3293 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
3294 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
3295 int subid = myStudyContext->findId( string( objStr.in() ) );
3297 // for each mesh open the HDF group basing on its id
3298 char submeshGrpName[ 30 ];
3299 sprintf( submeshGrpName, "SubMesh %d", subid );
3300 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
3301 aSubGroup->CreateOnDisk();
3303 // write reference on a shape, already checked if it exists
3304 SALOMEDS::SObject_var mySubRef, myShape;
3305 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
3306 mySubRef->ReferencedObject( myShape );
3307 string myRefOnObject = myShape->GetID();
3308 if ( myRefOnObject.length() > 0 ) {
3309 aSize[ 0 ] = myRefOnObject.length() + 1;
3310 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
3311 aDataset->CreateOnDisk();
3312 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3313 aDataset->CloseOnDisk();
3316 // write applied hypotheses if exist
3317 SALOMEDS::SObject_var mySubHypBranch;
3318 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
3320 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3321 aSubSubGroup->CreateOnDisk();
3323 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
3325 for ( ; it->More(); it->Next() ) {
3326 SALOMEDS::SObject_var mySubSObject = it->Value();
3327 SALOMEDS::SObject_var myRefOnHyp;
3328 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
3330 //string myRefOnObject = myRefOnHyp->GetID();
3331 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3332 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3333 int id = myStudyContext->findId( string( objStr.in() ) );
3334 //if ( myRefOnObject.length() > 0 ) {
3335 //aSize[ 0 ] = myRefOnObject.length() + 1;
3336 char hypName[ 30 ], hypId[ 30 ];
3337 sprintf( hypName, "Hyp %d", ++hypNb );
3338 sprintf( hypId, "%d", id );
3339 aSize[ 0 ] = strlen( hypId ) + 1;
3340 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
3341 aDataset->CreateOnDisk();
3342 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3343 aDataset->WriteOnDisk( hypId );
3344 aDataset->CloseOnDisk();
3348 aSubSubGroup->CloseOnDisk();
3351 // write applied algorithms if exist
3352 SALOMEDS::SObject_var mySubAlgoBranch;
3353 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
3355 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3356 aSubSubGroup->CreateOnDisk();
3358 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
3360 for ( ; it->More(); it->Next() ) {
3361 SALOMEDS::SObject_var mySubSObject = it->Value();
3362 SALOMEDS::SObject_var myRefOnAlgo;
3363 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
3365 //string myRefOnObject = myRefOnAlgo->GetID();
3366 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3367 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3368 int id = myStudyContext->findId( string( objStr.in() ) );
3369 //if ( myRefOnObject.length() > 0 ) {
3370 //aSize[ 0 ] = myRefOnObject.length() + 1;
3371 char algoName[ 30 ], algoId[ 30 ];
3372 sprintf( algoName, "Algo %d", ++algoNb );
3373 sprintf( algoId, "%d", id );
3374 aSize[ 0 ] = strlen( algoId ) + 1;
3375 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
3376 aDataset->CreateOnDisk();
3377 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3378 aDataset->WriteOnDisk( algoId );
3379 aDataset->CloseOnDisk();
3383 aSubSubGroup->CloseOnDisk();
3385 // close submesh HDF group
3386 aSubGroup->CloseOnDisk();
3389 // close container of submeshes by type HDF group
3390 aGroup->CloseOnDisk();
3393 // All sub-meshes will be stored in MED file
3394 // .. will NOT (PAL 12992)
3395 //if ( shapeRefFound )
3396 //myWriter.AddAllSubMeshes();
3398 // store submesh order if any
3399 const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
3400 if ( theOrderIds.size() ) {
3401 char order_list[ 30 ];
3402 strcpy( order_list, "Mesh Order" );
3403 // count number of submesh ids
3405 TListOfListOfInt::const_iterator idIt = theOrderIds.begin();
3406 for ( ; idIt != theOrderIds.end(); idIt++ )
3407 nbIDs += (*idIt).size();
3408 // number of values = number of IDs +
3409 // number of lists (for separators) - 1
3410 int* smIDs = new int [ nbIDs + theOrderIds.size() - 1 ];
3411 idIt = theOrderIds.begin();
3412 for ( int i = 0; idIt != theOrderIds.end(); idIt++ ) {
3413 const TListOfInt& idList = *idIt;
3414 if (idIt != theOrderIds.begin()) // not first list
3415 smIDs[ i++ ] = -1/* *idList.size()*/; // separator between lists
3416 // dump submesh ids from current list
3417 TListOfInt::const_iterator id_smId = idList.begin();
3418 for( ; id_smId != idList.end(); id_smId++ )
3419 smIDs[ i++ ] = *id_smId;
3422 aSize[ 0 ] = nbIDs + theOrderIds.size() - 1;
3424 aDataset = new HDFdataset( order_list, aTopGroup, HDF_INT32, aSize, 1 );
3425 aDataset->CreateOnDisk();
3426 aDataset->WriteOnDisk( smIDs );
3427 aDataset->CloseOnDisk();
3432 // groups root sub-branch
3433 SALOMEDS::SObject_var myGroupsBranch;
3434 for ( int i = GetNodeGroupsTag(); i <= GetBallElementsGroupsTag(); i++ ) {
3435 found = gotBranch->FindSubObject( i, myGroupsBranch );
3437 char name_group[ 30 ];
3438 if ( i == GetNodeGroupsTag() )
3439 strcpy( name_group, "Groups of Nodes" );
3440 else if ( i == GetEdgeGroupsTag() )
3441 strcpy( name_group, "Groups of Edges" );
3442 else if ( i == GetFaceGroupsTag() )
3443 strcpy( name_group, "Groups of Faces" );
3444 else if ( i == GetVolumeGroupsTag() )
3445 strcpy( name_group, "Groups of Volumes" );
3446 else if ( i == Get0DElementsGroupsTag() )
3447 strcpy( name_group, "Groups of 0D Elements" );
3448 else if ( i == GetBallElementsGroupsTag() )
3449 strcpy( name_group, "Groups of Balls" );
3451 aGroup = new HDFgroup( name_group, aTopGroup );
3452 aGroup->CreateOnDisk();
3454 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
3455 for ( ; it->More(); it->Next() ) {
3456 SALOMEDS::SObject_var mySObject = it->Value();
3457 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
3458 if ( !CORBA::is_nil( aSubObject ) ) {
3459 SMESH_GroupBase_i* myGroupImpl =
3460 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
3463 SMESHDS_GroupBase* aGrpBaseDS = myGroupImpl->GetGroupDS();
3467 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
3468 int anId = myStudyContext->findId( string( objStr.in() ) );
3470 // For each group, create a dataset named "Group <group_persistent_id>"
3471 // and store the group's user name into it
3472 const char* grpName = aGrpBaseDS->GetStoreName();
3473 char* aUserName = myGroupImpl->GetName();
3474 aSize[ 0 ] = strlen( aUserName ) + 1;
3476 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
3477 aDataset->CreateOnDisk();
3478 aDataset->WriteOnDisk( aUserName );
3479 aDataset->CloseOnDisk();
3482 // For each group, create a dataset named "Group <group_persistent_id> Color"
3483 // and store the group's color into it
3484 char grpColorName[ 30 ];
3485 sprintf( grpColorName, "ColorGroup %d", anId );
3486 SALOMEDS::Color aColor = myGroupImpl->GetColor();
3488 anRGB[ 0 ] = aColor.R;
3489 anRGB[ 1 ] = aColor.G;
3490 anRGB[ 2 ] = aColor.B;
3492 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
3493 aDataset->CreateOnDisk();
3494 aDataset->WriteOnDisk( anRGB );
3495 aDataset->CloseOnDisk();
3497 // Pass SMESHDS_Group to MED writer
3498 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
3500 myWriter.AddGroup( aGrpDS );
3502 // write reference on a shape if exists
3503 SMESHDS_GroupOnGeom* aGeomGrp =
3504 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
3506 SALOMEDS::SObject_var mySubRef, myShape;
3507 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
3508 mySubRef->ReferencedObject( myShape ) &&
3509 !CORBA::is_nil( myShape->GetObject() ))
3511 string myRefOnObject = myShape->GetID();
3512 if ( myRefOnObject.length() > 0 ) {
3513 char aRefName[ 30 ];
3514 sprintf( aRefName, "Ref on shape %d", anId);
3515 aSize[ 0 ] = myRefOnObject.length() + 1;
3516 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
3517 aDataset->CreateOnDisk();
3518 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3519 aDataset->CloseOnDisk();
3522 else // shape ref is invalid:
3524 // save a group on geometry as ordinary group
3525 myWriter.AddGroup( aGeomGrp );
3528 else if ( SMESH_GroupOnFilter_i* aFilterGrp_i =
3529 dynamic_cast<SMESH_GroupOnFilter_i*>( myGroupImpl ))
3531 std::string str = aFilterGrp_i->FilterToString();
3532 std::string hdfGrpName = "Filter " + SMESH_Comment(anId);
3533 aSize[ 0 ] = str.length() + 1;
3534 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup, HDF_STRING, aSize, 1);
3535 aDataset->CreateOnDisk();
3536 aDataset->WriteOnDisk( ( char* )( str.c_str() ) );
3537 aDataset->CloseOnDisk();
3541 aGroup->CloseOnDisk();
3545 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
3547 // Flush current mesh information into MED file
3550 // save info on nb of elements
3551 SMESH_PreMeshInfo::SaveToFile( myImpl, id, aFile );
3553 // maybe a shape was deleted in the study
3554 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
3555 TopoDS_Shape nullShape;
3556 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
3559 if ( !mySMESHDSMesh->SubMeshes().empty() )
3563 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3564 aGroup->CreateOnDisk();
3566 // each element belongs to one or none submesh,
3567 // so for each node/element, we store a submesh ID
3569 // Make maps of submesh IDs of elements sorted by element IDs
3570 typedef int TElemID;
3571 typedef int TSubMID;
3572 map< TElemID, TSubMID > eId2smId, nId2smId;
3573 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
3574 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
3575 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
3576 SMDS_NodeIteratorPtr itNode;
3577 SMDS_ElemIteratorPtr itElem;
3578 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3580 TSubMID aSubMeID = itSubM->first;
3581 SMESHDS_SubMesh* aSubMesh = itSubM->second;
3582 if ( aSubMesh->IsComplexSubmesh() )
3583 continue; // submesh containing other submeshs
3585 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
3586 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
3587 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
3589 hint = eId2smId.begin();
3590 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
3591 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
3594 // Care of elements that are not on submeshes
3595 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
3596 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
3597 /* --- stl_map.h says : */
3598 /* A %map relies on unique keys and thus a %pair is only inserted if its */
3599 /* first element (the key) is not already present in the %map. */
3600 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
3602 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
3603 if ( nbElems != eId2smId.size() ) {
3604 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
3605 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
3608 // Store submesh IDs
3609 for ( int isNode = 0; isNode < 2; ++isNode )
3611 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
3612 if ( id2smId.empty() ) continue;
3613 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
3614 // make and fill array of submesh IDs
3615 int* smIDs = new int [ id2smId.size() ];
3616 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
3617 smIDs[ i ] = id_smId->second;
3619 aSize[ 0 ] = id2smId.size();
3620 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3621 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3622 aDataset->CreateOnDisk();
3623 aDataset->WriteOnDisk( smIDs );
3624 aDataset->CloseOnDisk();
3629 aGroup->CloseOnDisk();
3631 // Store node positions on sub-shapes (SMDS_Position):
3632 // ----------------------------------------------------
3634 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3635 aGroup->CreateOnDisk();
3637 // in aGroup, create 5 datasets to contain:
3638 // "Nodes on Edges" - ID of node on edge
3639 // "Edge positions" - U parameter on node on edge
3640 // "Nodes on Faces" - ID of node on face
3641 // "Face U positions" - U parameter of node on face
3642 // "Face V positions" - V parameter of node on face
3644 // Find out nb of nodes on edges and faces
3645 // Collect corresponing sub-meshes
3646 int nbEdgeNodes = 0, nbFaceNodes = 0;
3647 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
3648 // loop on SMESHDS_SubMesh'es
3649 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3651 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
3652 if ( aSubMesh->IsComplexSubmesh() )
3653 continue; // submesh containing other submeshs
3654 int nbNodes = aSubMesh->NbNodes();
3655 if ( nbNodes == 0 ) continue;
3657 int aShapeID = (*itSubM).first;
3658 if ( aShapeID < 1 || aShapeID > mySMESHDSMesh->MaxShapeIndex() )
3660 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
3661 // write only SMDS_FacePosition and SMDS_EdgePosition
3662 switch ( aShapeType ) {
3664 nbFaceNodes += nbNodes;
3665 aFaceSM.push_back( aSubMesh );
3668 nbEdgeNodes += nbNodes;
3669 aEdgeSM.push_back( aSubMesh );
3675 // Treat positions on edges or faces
3676 for ( int onFace = 0; onFace < 2; onFace++ )
3678 // Create arrays to store in datasets
3679 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
3680 if (!nbNodes) continue;
3681 int* aNodeIDs = new int [ nbNodes ];
3682 double* aUPos = new double [ nbNodes ];
3683 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
3686 // loop on sub-meshes
3687 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
3688 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
3689 for ( ; itSM != pListSM->end(); itSM++ )
3691 SMESHDS_SubMesh* aSubMesh = (*itSM);
3693 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
3694 // loop on nodes in aSubMesh
3695 while ( itNode->more() )
3698 const SMDS_MeshNode* node = itNode->next();
3699 aNodeIDs [ iNode ] = node->GetID();
3702 const SMDS_PositionPtr pos = node->GetPosition();
3703 if ( onFace ) { // on FACE
3704 const SMDS_FacePosition* fPos =
3705 dynamic_cast<const SMDS_FacePosition*>( pos );
3707 aUPos[ iNode ] = fPos->GetUParameter();
3708 aVPos[ iNode ] = fPos->GetVParameter();
3715 const SMDS_EdgePosition* ePos =
3716 dynamic_cast<const SMDS_EdgePosition*>( pos );
3718 aUPos[ iNode ] = ePos->GetUParameter();
3724 } // loop on nodes in aSubMesh
3725 } // loop on sub-meshes
3730 aSize[ 0 ] = nbNodes;
3732 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
3733 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3734 aDataset->CreateOnDisk();
3735 aDataset->WriteOnDisk( aNodeIDs );
3736 aDataset->CloseOnDisk();
3739 aDSName = ( onFace ? "Face U positions" : "Edge positions");
3740 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
3741 aDataset->CreateOnDisk();
3742 aDataset->WriteOnDisk( aUPos );
3743 aDataset->CloseOnDisk();
3746 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
3747 aDataset->CreateOnDisk();
3748 aDataset->WriteOnDisk( aVPos );
3749 aDataset->CloseOnDisk();
3754 if ( aVPos ) delete [] aVPos;
3756 } // treat positions on edges or faces
3758 // close "Node Positions" group
3759 aGroup->CloseOnDisk();
3761 } // if ( there are submeshes in SMESHDS_Mesh )
3764 // close mesh HDF group
3765 aTopGroup->CloseOnDisk();
3773 aFile->CloseOnDisk();
3776 // Convert temporary files to stream
3777 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
3779 // Remove temporary files and directory
3781 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3783 INFOS( "SMESH_Gen_i::Save() completed" );
3784 return aStreamFile._retn();
3787 //=============================================================================
3789 * SMESH_Gen_i::SaveASCII
3791 * Save SMESH module's data in ASCII format
3793 //=============================================================================
3795 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
3797 bool isMultiFile ) {
3798 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
3799 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
3800 return aStreamFile._retn();
3802 //after usual saving needs to encipher binary to text string
3803 //Any binary symbol will be represent as "|xx" () hexadecimal format number
3804 int size = aStreamFile.in().length();
3805 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
3806 for ( int i = 0; i < size; i++ )
3807 sprintf( (char*)&(buffer[i*3]), "|%02x", aStreamFile[i] );
3809 buffer[size * 3] = '\0';
3811 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
3813 return anAsciiStreamFile._retn();
3816 //=============================================================================
3818 * SMESH_Gen_i::loadGeomData
3820 * Load GEOM module data
3822 //=============================================================================
3824 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
3826 if ( theCompRoot->_is_nil() )
3829 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
3830 if ( aStudy->_is_nil() )
3833 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3834 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
3837 //=============================================================================
3841 * Load SMESH module's data
3843 //=============================================================================
3845 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
3846 const SALOMEDS::TMPFile& theStream,
3850 INFOS( "SMESH_Gen_i::Load" );
3852 if ( myCurrentStudy->_is_nil() ||
3853 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
3854 SetCurrentStudy( theComponent->GetStudy() );
3856 /* if( !theComponent->_is_nil() )
3858 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
3859 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
3860 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
3863 StudyContext* myStudyContext = GetCurrentStudyContext();
3865 // Get temporary files location
3866 TCollection_AsciiString tmpDir =
3867 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
3869 INFOS( "THE URL++++++++++++++" )
3871 INFOS( "THE TMP PATH+++++++++" );
3874 // Convert the stream into sequence of files to process
3875 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
3878 TCollection_AsciiString aStudyName( "" );
3880 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
3882 // Set names of temporary files
3883 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
3884 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
3888 HDFdataset* aDataset;
3889 HDFgroup* aTopGroup;
3891 HDFgroup* aSubGroup;
3892 HDFgroup* aSubSubGroup;
3895 // ---> open HDF file
3896 aFile = new HDFfile( (char*) filename.ToCString() );
3898 aFile->OpenOnDisk( HDF_RDONLY );
3900 catch ( HDFexception ) {
3901 INFOS( "Load(): " << filename << " not found!" );
3905 TPythonDump pd; // prevent dump during loading
3907 // DriverMED_R_SMESHDS_Mesh myReader;
3908 // myReader.SetFile( meshfile.ToCString() );
3910 // For PAL13473 ("Repetitive mesh") implementation.
3911 // New dependencies between SMESH objects are established:
3912 // now hypotheses can refer to meshes, shapes and other hypotheses.
3913 // To keep data consistent, the following order of data restoration
3915 // 1. Create hypotheses
3916 // 2. Create all meshes
3917 // 3. Load hypotheses' data
3920 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
3921 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
3923 // get total number of top-level groups
3924 int aNbGroups = aFile->nInternalObjects();
3925 if ( aNbGroups > 0 ) {
3926 // --> in first turn we should read&create hypotheses
3927 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
3928 // open hypotheses root HDF group
3929 aTopGroup = new HDFgroup( "Hypotheses", aFile );
3930 aTopGroup->OpenOnDisk();
3932 // get number of hypotheses
3933 int aNbObjects = aTopGroup->nInternalObjects();
3934 for ( int j = 0; j < aNbObjects; j++ ) {
3935 // try to identify hypothesis
3936 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
3937 aTopGroup->InternalObjectIndentify( j, hypGrpName );
3939 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
3940 // open hypothesis group
3941 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3942 aGroup->OpenOnDisk();
3944 // --> get hypothesis id
3945 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
3950 // get number of datasets
3951 int aNbSubObjects = aGroup->nInternalObjects();
3952 for ( int k = 0; k < aNbSubObjects; k++ ) {
3954 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
3955 aGroup->InternalObjectIndentify( k, name_of_subgroup );
3956 // --> get hypothesis name
3957 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
3958 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3959 aDataset->OpenOnDisk();
3960 size = aDataset->GetSize();
3961 char* hypname_str = new char[ size ];
3962 aDataset->ReadFromDisk( hypname_str );
3963 hypname = string( hypname_str );
3964 delete [] hypname_str;
3965 aDataset->CloseOnDisk();
3967 // --> get hypothesis plugin library name
3968 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
3969 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3970 aDataset->OpenOnDisk();
3971 size = aDataset->GetSize();
3972 char* libname_str = new char[ size ];
3973 aDataset->ReadFromDisk( libname_str );
3974 if(MYDEBUG) SCRUTE( libname_str );
3975 libname = string( libname_str );
3976 delete [] libname_str;
3977 aDataset->CloseOnDisk();
3979 // --> get hypothesis data
3980 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
3981 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3982 aDataset->OpenOnDisk();
3983 size = aDataset->GetSize();
3984 char* hypdata_str = new char[ size ];
3985 aDataset->ReadFromDisk( hypdata_str );
3986 hypdata = string( hypdata_str );
3987 delete [] hypdata_str;
3988 aDataset->CloseOnDisk();
3991 // close hypothesis HDF group
3992 aGroup->CloseOnDisk();
3994 // --> restore hypothesis from data
3995 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
3996 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
3997 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
3998 SMESH::SMESH_Hypothesis_var myHyp;
4000 try { // protect persistence mechanism against exceptions
4001 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4004 INFOS( "Exception during hypothesis creation" );
4007 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4009 // myImpl->LoadFrom( hypdata.c_str() );
4010 hypDataList.push_back( make_pair( myImpl, hypdata ));
4011 string iorString = GetORB()->object_to_string( myHyp );
4012 int newId = myStudyContext->findId( iorString );
4013 myStudyContext->mapOldToNew( id, newId );
4016 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4020 // close hypotheses root HDF group
4021 aTopGroup->CloseOnDisk();
4025 // --> then we should read&create algorithms
4026 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
4027 // open algorithms root HDF group
4028 aTopGroup = new HDFgroup( "Algorithms", aFile );
4029 aTopGroup->OpenOnDisk();
4031 // get number of algorithms
4032 int aNbObjects = aTopGroup->nInternalObjects();
4033 for ( int j = 0; j < aNbObjects; j++ ) {
4034 // try to identify algorithm
4035 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
4036 aTopGroup->InternalObjectIndentify( j, hypGrpName );
4038 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
4039 // open algorithm group
4040 aGroup = new HDFgroup( hypGrpName, aTopGroup );
4041 aGroup->OpenOnDisk();
4043 // --> get algorithm id
4044 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
4049 // get number of datasets
4050 int aNbSubObjects = aGroup->nInternalObjects();
4051 for ( int k = 0; k < aNbSubObjects; k++ ) {
4053 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4054 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4055 // --> get algorithm name
4056 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4057 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4058 aDataset->OpenOnDisk();
4059 size = aDataset->GetSize();
4060 char* hypname_str = new char[ size ];
4061 aDataset->ReadFromDisk( hypname_str );
4062 hypname = string( hypname_str );
4063 delete [] hypname_str;
4064 aDataset->CloseOnDisk();
4066 // --> get algorithm plugin library name
4067 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4068 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4069 aDataset->OpenOnDisk();
4070 size = aDataset->GetSize();
4071 char* libname_str = new char[ size ];
4072 aDataset->ReadFromDisk( libname_str );
4073 if(MYDEBUG) SCRUTE( libname_str );
4074 libname = string( libname_str );
4075 delete [] libname_str;
4076 aDataset->CloseOnDisk();
4078 // --> get algorithm data
4079 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4080 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4081 aDataset->OpenOnDisk();
4082 size = aDataset->GetSize();
4083 char* hypdata_str = new char[ size ];
4084 aDataset->ReadFromDisk( hypdata_str );
4085 if(MYDEBUG) SCRUTE( hypdata_str );
4086 hypdata = string( hypdata_str );
4087 delete [] hypdata_str;
4088 aDataset->CloseOnDisk();
4091 // close algorithm HDF group
4092 aGroup->CloseOnDisk();
4094 // --> restore algorithm from data
4095 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4096 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
4097 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4098 SMESH::SMESH_Hypothesis_var myHyp;
4100 try { // protect persistence mechanism against exceptions
4101 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4104 INFOS( "Exception during hypothesis creation" );
4107 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4109 //myImpl->LoadFrom( hypdata.c_str() );
4110 hypDataList.push_back( make_pair( myImpl, hypdata ));
4111 string iorString = GetORB()->object_to_string( myHyp );
4112 int newId = myStudyContext->findId( iorString );
4113 myStudyContext->mapOldToNew( id, newId );
4116 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4120 // close algorithms root HDF group
4121 aTopGroup->CloseOnDisk();
4125 // --> the rest groups should be meshes
4126 for ( int i = 0; i < aNbGroups; i++ ) {
4127 // identify next group
4128 char meshName[ HDF_NAME_MAX_LEN+1 ];
4129 aFile->InternalObjectIndentify( i, meshName );
4131 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
4133 int id = atoi( string( meshName ).substr( 4 ).c_str() );
4137 // open mesh HDF group
4138 aTopGroup = new HDFgroup( meshName, aFile );
4139 aTopGroup->OpenOnDisk();
4141 // get number of child HDF objects
4142 int aNbObjects = aTopGroup->nInternalObjects();
4143 if ( aNbObjects > 0 ) {
4145 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
4146 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
4147 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
4148 if ( !myNewMeshImpl )
4150 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
4152 string iorString = GetORB()->object_to_string( myNewMesh );
4153 int newId = myStudyContext->findId( iorString );
4154 myStudyContext->mapOldToNew( id, newId );
4157 // try to read and set auto color flag
4158 char aMeshAutoColorName[ 30 ];
4159 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
4160 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
4162 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
4163 aDataset->OpenOnDisk();
4164 size = aDataset->GetSize();
4165 int* anAutoColor = new int[ size ];
4166 aDataset->ReadFromDisk( anAutoColor );
4167 aDataset->CloseOnDisk();
4168 myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
4171 // try to read and set reference to shape
4172 GEOM::GEOM_Object_var aShapeObject;
4173 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
4174 // load mesh "Ref on shape" - it's an entry to SObject
4175 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
4176 aDataset->OpenOnDisk();
4177 size = aDataset->GetSize();
4178 char* refFromFile = new char[ size ];
4179 aDataset->ReadFromDisk( refFromFile );
4180 aDataset->CloseOnDisk();
4181 if ( strlen( refFromFile ) > 0 ) {
4182 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4184 // Make sure GEOM data are loaded first
4185 //loadGeomData( shapeSO->GetFatherComponent() );
4187 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4188 if ( !CORBA::is_nil( shapeObject ) ) {
4189 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4190 if ( !aShapeObject->_is_nil() )
4191 myNewMeshImpl->SetShape( aShapeObject );
4196 // issue 20918. Restore Persistent Id of SMESHDS_Mesh
4197 if( aTopGroup->ExistInternalObject( "meshPersistentId" ) )
4199 aDataset = new HDFdataset( "meshPersistentId", aTopGroup );
4200 aDataset->OpenOnDisk();
4201 size = aDataset->GetSize();
4202 int* meshPersistentId = new int[ size ];
4203 aDataset->ReadFromDisk( meshPersistentId );
4204 aDataset->CloseOnDisk();
4205 myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
4211 // As all object that can be referred by hypothesis are created,
4212 // we can restore hypothesis data
4214 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
4215 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4217 SMESH_Hypothesis_i* hyp = hyp_data->first;
4218 string & data = hyp_data->second;
4219 hyp->LoadFrom( data.c_str() );
4222 // Restore the rest mesh data
4224 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
4225 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4227 aTopGroup = meshi_group->second;
4228 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4229 //::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4230 //SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
4232 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
4233 bool hasData = false;
4236 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
4237 int newId = myStudyContext->findId( iorString );
4238 int id = myStudyContext->getOldId( newId );
4240 // try to find mesh data dataset
4241 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
4242 // load mesh "has data" flag
4243 aDataset = new HDFdataset( "Has data", aTopGroup );
4244 aDataset->OpenOnDisk();
4245 size = aDataset->GetSize();
4246 char* strHasData = new char[ size ];
4247 aDataset->ReadFromDisk( strHasData );
4248 aDataset->CloseOnDisk();
4249 if ( strcmp( strHasData, "1") == 0 ) {
4250 // read mesh data from MED file
4251 // myReader.SetMesh( mySMESHDSMesh );
4252 // myReader.SetMeshId( id );
4253 // myReader.Perform();
4258 // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
4259 // nodes and elements are not yet put into sub-meshes)
4260 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4261 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
4262 aGroup->OpenOnDisk();
4263 // get number of applied algorithms
4264 int aNbSubObjects = aGroup->nInternalObjects();
4265 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
4266 for ( int j = 0; j < aNbSubObjects; j++ ) {
4267 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4268 aGroup->InternalObjectIndentify( j, name_dataset );
4269 // check if it is an algorithm
4270 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
4271 aDataset = new HDFdataset( name_dataset, aGroup );
4272 aDataset->OpenOnDisk();
4273 size = aDataset->GetSize();
4274 char* refFromFile = new char[ size ];
4275 aDataset->ReadFromDisk( refFromFile );
4276 aDataset->CloseOnDisk();
4277 // san - it is impossible to recover applied algorithms using their entries within Load() method
4278 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
4279 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4280 int id = atoi( refFromFile );
4281 string anIOR = myStudyContext->getIORbyOldId( id );
4282 if ( !anIOR.empty() ) {
4283 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4284 if ( !CORBA::is_nil( hypObject ) ) {
4285 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4286 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4287 || !myNewMeshImpl->HasShapeToMesh()) )
4288 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4293 aGroup->CloseOnDisk();
4296 // try to get applied hypotheses
4297 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4298 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
4299 aGroup->OpenOnDisk();
4300 // get number of applied hypotheses
4301 int aNbSubObjects = aGroup->nInternalObjects();
4302 for ( int j = 0; j < aNbSubObjects; j++ ) {
4303 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4304 aGroup->InternalObjectIndentify( j, name_dataset );
4305 // check if it is a hypothesis
4306 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4307 aDataset = new HDFdataset( name_dataset, aGroup );
4308 aDataset->OpenOnDisk();
4309 size = aDataset->GetSize();
4310 char* refFromFile = new char[ size ];
4311 aDataset->ReadFromDisk( refFromFile );
4312 aDataset->CloseOnDisk();
4313 // san - it is impossible to recover applied hypotheses using their entries within Load() method
4314 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
4315 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4316 int id = atoi( refFromFile );
4317 string anIOR = myStudyContext->getIORbyOldId( id );
4318 if ( !anIOR.empty() ) {
4319 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4320 if ( !CORBA::is_nil( hypObject ) ) {
4321 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4322 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4323 || !myNewMeshImpl->HasShapeToMesh()) )
4324 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4329 aGroup->CloseOnDisk();
4332 // --> try to find SUB-MESHES containers for each type of submesh
4333 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
4334 char name_meshgroup[ 30 ];
4335 if ( j == GetSubMeshOnVertexTag() )
4336 strcpy( name_meshgroup, "SubMeshes On Vertex" );
4337 else if ( j == GetSubMeshOnEdgeTag() )
4338 strcpy( name_meshgroup, "SubMeshes On Edge" );
4339 else if ( j == GetSubMeshOnWireTag() )
4340 strcpy( name_meshgroup, "SubMeshes On Wire" );
4341 else if ( j == GetSubMeshOnFaceTag() )
4342 strcpy( name_meshgroup, "SubMeshes On Face" );
4343 else if ( j == GetSubMeshOnShellTag() )
4344 strcpy( name_meshgroup, "SubMeshes On Shell" );
4345 else if ( j == GetSubMeshOnSolidTag() )
4346 strcpy( name_meshgroup, "SubMeshes On Solid" );
4347 else if ( j == GetSubMeshOnCompoundTag() )
4348 strcpy( name_meshgroup, "SubMeshes On Compound" );
4350 // try to get submeshes container HDF group
4351 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
4352 // open submeshes containers HDF group
4353 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
4354 aGroup->OpenOnDisk();
4356 // get number of submeshes
4357 int aNbSubMeshes = aGroup->nInternalObjects();
4358 for ( int k = 0; k < aNbSubMeshes; k++ ) {
4360 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
4361 aGroup->InternalObjectIndentify( k, name_submeshgroup );
4362 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
4363 // --> get submesh id
4364 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
4367 // open submesh HDF group
4368 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
4369 aSubGroup->OpenOnDisk();
4371 // try to read and set reference to subshape
4372 GEOM::GEOM_Object_var aSubShapeObject;
4373 SMESH::SMESH_subMesh_var aSubMesh;
4375 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
4376 // load submesh "Ref on shape" - it's an entry to SObject
4377 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
4378 aDataset->OpenOnDisk();
4379 size = aDataset->GetSize();
4380 char* refFromFile = new char[ size ];
4381 aDataset->ReadFromDisk( refFromFile );
4382 aDataset->CloseOnDisk();
4383 if ( strlen( refFromFile ) > 0 ) {
4384 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
4385 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
4386 if ( !CORBA::is_nil( subShapeObject ) ) {
4387 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
4388 if ( !aSubShapeObject->_is_nil() )
4389 aSubMesh = SMESH::SMESH_subMesh::_duplicate
4390 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
4391 if ( aSubMesh->_is_nil() )
4393 string iorSubString = GetORB()->object_to_string( aSubMesh );
4394 int newSubId = myStudyContext->findId( iorSubString );
4395 myStudyContext->mapOldToNew( subid, newSubId );
4400 if ( aSubMesh->_is_nil() )
4403 // try to get applied algorithms
4404 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4405 // open "applied algorithms" HDF group
4406 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
4407 aSubSubGroup->OpenOnDisk();
4408 // get number of applied algorithms
4409 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4410 for ( int l = 0; l < aNbSubObjects; l++ ) {
4411 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4412 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4413 // check if it is an algorithm
4414 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
4415 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4416 aDataset->OpenOnDisk();
4417 size = aDataset->GetSize();
4418 char* refFromFile = new char[ size ];
4419 aDataset->ReadFromDisk( refFromFile );
4420 aDataset->CloseOnDisk();
4422 int id = atoi( refFromFile );
4423 string anIOR = myStudyContext->getIORbyOldId( id );
4424 if ( !anIOR.empty() ) {
4425 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4426 if ( !CORBA::is_nil( hypObject ) ) {
4427 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4428 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4429 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4434 // close "applied algorithms" HDF group
4435 aSubSubGroup->CloseOnDisk();
4438 // try to get applied hypotheses
4439 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4440 // open "applied hypotheses" HDF group
4441 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
4442 aSubSubGroup->OpenOnDisk();
4443 // get number of applied hypotheses
4444 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4445 for ( int l = 0; l < aNbSubObjects; l++ ) {
4446 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4447 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4448 // check if it is a hypothesis
4449 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4450 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4451 aDataset->OpenOnDisk();
4452 size = aDataset->GetSize();
4453 char* refFromFile = new char[ size ];
4454 aDataset->ReadFromDisk( refFromFile );
4455 aDataset->CloseOnDisk();
4457 int id = atoi( refFromFile );
4458 string anIOR = myStudyContext->getIORbyOldId( id );
4459 if ( !anIOR.empty() ) {
4460 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4461 if ( !CORBA::is_nil( hypObject ) ) {
4462 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4463 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4464 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4469 // close "APPLIED HYPOTHESES" hdf group
4470 aSubSubGroup->CloseOnDisk();
4473 // close SUB-MESH hdf group
4474 aSubGroup->CloseOnDisk();
4477 // close SUB-MESHES containers hdf group
4478 aGroup->CloseOnDisk();
4482 // try to get GROUPS
4483 for ( int ii = GetNodeGroupsTag(); ii <= GetBallElementsGroupsTag(); ii++ ) {
4484 char name_group[ 30 ];
4485 if ( ii == GetNodeGroupsTag() )
4486 strcpy( name_group, "Groups of Nodes" );
4487 else if ( ii == GetEdgeGroupsTag() )
4488 strcpy( name_group, "Groups of Edges" );
4489 else if ( ii == GetFaceGroupsTag() )
4490 strcpy( name_group, "Groups of Faces" );
4491 else if ( ii == GetVolumeGroupsTag() )
4492 strcpy( name_group, "Groups of Volumes" );
4493 else if ( ii == Get0DElementsGroupsTag() )
4494 strcpy( name_group, "Groups of 0D Elements" );
4495 else if ( ii == GetBallElementsGroupsTag() )
4496 strcpy( name_group, "Groups of Balls" );
4498 if ( aTopGroup->ExistInternalObject( name_group ) ) {
4499 aGroup = new HDFgroup( name_group, aTopGroup );
4500 aGroup->OpenOnDisk();
4501 // get number of groups
4502 int aNbSubObjects = aGroup->nInternalObjects();
4503 for ( int j = 0; j < aNbSubObjects; j++ ) {
4504 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4505 aGroup->InternalObjectIndentify( j, name_dataset );
4506 // check if it is an group
4507 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
4509 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
4512 aDataset = new HDFdataset( name_dataset, aGroup );
4513 aDataset->OpenOnDisk();
4515 // Retrieve actual group name
4516 size = aDataset->GetSize();
4517 char* nameFromFile = new char[ size ];
4518 aDataset->ReadFromDisk( nameFromFile );
4519 aDataset->CloseOnDisk();
4521 // Try to find a shape reference
4522 TopoDS_Shape aShape;
4523 char aRefName[ 30 ];
4524 sprintf( aRefName, "Ref on shape %d", subid);
4525 if ( aGroup->ExistInternalObject( aRefName ) ) {
4526 // load mesh "Ref on shape" - it's an entry to SObject
4527 aDataset = new HDFdataset( aRefName, aGroup );
4528 aDataset->OpenOnDisk();
4529 size = aDataset->GetSize();
4530 char* refFromFile = new char[ size ];
4531 aDataset->ReadFromDisk( refFromFile );
4532 aDataset->CloseOnDisk();
4533 if ( strlen( refFromFile ) > 0 ) {
4534 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4535 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4536 if ( !CORBA::is_nil( shapeObject ) ) {
4537 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4538 if ( !aShapeObject->_is_nil() )
4539 aShape = GeomObjectToShape( aShapeObject );
4543 // Try to read a filter of SMESH_GroupOnFilter
4544 SMESH::Filter_var filter;
4545 SMESH_PredicatePtr predicate;
4546 std::string hdfGrpName = "Filter " + SMESH_Comment(subid);
4547 if ( aGroup->ExistInternalObject( hdfGrpName.c_str() ))
4549 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup );
4550 aDataset->OpenOnDisk();
4551 size = aDataset->GetSize();
4552 char* persistStr = new char[ size ];
4553 aDataset->ReadFromDisk( persistStr );
4554 aDataset->CloseOnDisk();
4555 if ( strlen( persistStr ) > 0 ) {
4556 filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
4557 predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
4561 // Create group servant
4562 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
4563 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
4564 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) );
4565 // Obtain a SMESHDS_Group object
4566 if ( aNewGroup->_is_nil() )
4569 string iorSubString = GetORB()->object_to_string( aNewGroup );
4570 int newSubId = myStudyContext->findId( iorSubString );
4571 myStudyContext->mapOldToNew( subid, newSubId );
4573 SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
4577 if ( SMESH_GroupOnFilter_i* aFilterGroup =
4578 dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
4579 aFilterGroup->SetFilter( filter );
4581 SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
4582 if ( !aGroupBaseDS )
4585 aGroupBaseDS->SetStoreName( name_dataset );
4588 // Read color of the group
4589 char aGroupColorName[ 30 ];
4590 sprintf( aGroupColorName, "ColorGroup %d", subid);
4591 if ( aGroup->ExistInternalObject( aGroupColorName ) )
4593 aDataset = new HDFdataset( aGroupColorName, aGroup );
4594 aDataset->OpenOnDisk();
4595 size = aDataset->GetSize();
4596 double* anRGB = new double[ size ];
4597 aDataset->ReadFromDisk( anRGB );
4598 aDataset->CloseOnDisk();
4599 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
4600 aGroupBaseDS->SetColor( aColor );
4603 // Fill group with contents from MED file
4604 // SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
4606 // myReader.GetGroup( aGrp );
4609 aGroup->CloseOnDisk();
4613 // instead of reading mesh data, we read only brief information of all
4614 // objects: mesh, groups, sub-meshes (issue 0021208 )
4617 SMESH_PreMeshInfo::LoadFromFile( myNewMeshImpl, id,
4618 meshfile.ToCString(), filename.ToCString(),
4622 // read Sub-Mesh ORDER if any
4623 if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
4624 aDataset = new HDFdataset( "Mesh Order", aTopGroup );
4625 aDataset->OpenOnDisk();
4626 size = aDataset->GetSize();
4627 int* smIDs = new int[ size ];
4628 aDataset->ReadFromDisk( smIDs );
4629 aDataset->CloseOnDisk();
4630 TListOfListOfInt anOrderIds;
4631 anOrderIds.push_back( TListOfInt() );
4632 for ( int i = 0; i < size; i++ )
4633 if ( smIDs[ i ] < 0 ) // is separator
4634 anOrderIds.push_back( TListOfInt() );
4636 anOrderIds.back().push_back(smIDs[ i ]);
4638 myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
4642 // update hyps needing full mesh data restored (issue 20918)
4643 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4645 SMESH_Hypothesis_i* hyp = hyp_data->first;
4646 hyp->UpdateAsMeshesRestored();
4649 // notify algos on completed restoration to set sub-mesh event listeners
4650 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4652 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4653 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4655 TopoDS_Shape myLocShape;
4656 if(myLocMesh.HasShapeToMesh())
4657 myLocShape = myLocMesh.GetShapeToMesh();
4659 myLocShape = SMESH_Mesh::PseudoShape();
4661 myLocMesh.GetSubMesh(myLocShape)->
4662 ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
4667 aTopGroup->CloseOnDisk();
4670 aFile->CloseOnDisk();
4673 // Remove temporary files created from the stream
4676 SMESH_File meshFile( meshfile.ToCString() );
4677 if ( !meshFile ) // no meshfile exists
4679 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
4683 Engines::Container_var container = GetContainerRef();
4684 if ( Engines_Container_i* container_i = SMESH::DownCast<Engines_Container_i*>( container ))
4686 container_i->registerTemporaryFile( filename.ToCString() );
4687 container_i->registerTemporaryFile( meshfile.ToCString() );
4688 container_i->registerTemporaryFile( tmpDir.ToCString() );
4692 pd << ""; // prevent optimizing pd out
4694 INFOS( "SMESH_Gen_i::Load completed" );
4698 //=============================================================================
4700 * SMESH_Gen_i::LoadASCII
4702 * Load SMESH module's data in ASCII format
4704 //=============================================================================
4706 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
4707 const SALOMEDS::TMPFile& theStream,
4709 bool isMultiFile ) {
4710 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
4711 return Load( theComponent, theStream, theURL, isMultiFile );
4713 //before call main ::Load method it's need for decipher text format to
4714 //binary ( "|xx" => x' )
4715 int size = theStream.length();
4716 if ( int((size / 3 )*3) != size ) //error size of buffer
4719 int real_size = int(size / 3);
4721 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
4725 for ( int i = 0; i < real_size; i++ )
4727 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
4728 sscanf( tmp, "%x", &c );
4729 sprintf( (char*)&(buffer[i]), "%c", (char)c );
4732 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
4734 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
4737 //=============================================================================
4739 * SMESH_Gen_i::Close
4741 * Clears study-connected data when it is closed
4743 //=============================================================================
4745 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
4747 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
4749 // set correct current study
4750 SALOMEDS::Study_var study = theComponent->GetStudy();
4751 if ( study->StudyId() != GetCurrentStudyID())
4752 setCurrentStudy( study, /*IsBeingClosed=*/true );
4754 // Clear study contexts data
4755 int studyId = GetCurrentStudyID();
4756 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
4757 delete myStudyContextMap[ studyId ];
4758 myStudyContextMap.erase( studyId );
4761 // delete SMESH_Mesh's
4762 // See bug IPAL19437.
4764 // StudyContextStruct* context = myGen.GetStudyContext( studyId );
4765 // map< int, SMESH_Mesh* >::iterator i_mesh = context->mapMesh.begin();
4766 // for ( ; i_mesh != context->mapMesh.end(); ++i_mesh ) {
4767 // printf( "--------------------------- SMESH_Gen_i::Close, delete aGroup = %p \n", i_mesh->second );
4768 // delete i_mesh->second;
4772 // delete SMESHDS_Mesh's
4773 // it's too long on big meshes
4774 // if ( context->myDocument ) {
4775 // delete context->myDocument;
4776 // context->myDocument = 0;
4779 // remove the tmp files meshes are loaded from
4780 SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
4782 myCurrentStudy = SALOMEDS::Study::_nil();
4786 //=============================================================================
4788 * SMESH_Gen_i::ComponentDataType
4790 * Get component data type
4792 //=============================================================================
4794 char* SMESH_Gen_i::ComponentDataType()
4796 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
4797 return CORBA::string_dup( "SMESH" );
4801 //=============================================================================
4803 * SMESH_Gen_i::IORToLocalPersistentID
4805 * Transform data from transient form to persistent
4807 //=============================================================================
4809 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
4810 const char* IORString,
4811 CORBA::Boolean /*isMultiFile*/,
4812 CORBA::Boolean /*isASCII*/ )
4814 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
4815 StudyContext* myStudyContext = GetCurrentStudyContext();
4817 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
4818 int anId = myStudyContext->findId( IORString );
4820 if(MYDEBUG) MESSAGE( "VSR " << anId )
4822 sprintf( strId, "%d", anId );
4823 return CORBA::string_dup( strId );
4826 return CORBA::string_dup( "" );
4829 //=============================================================================
4831 * SMESH_Gen_i::LocalPersistentIDToIOR
4833 * Transform data from persistent form to transient
4835 //=============================================================================
4837 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
4838 const char* aLocalPersistentID,
4839 CORBA::Boolean /*isMultiFile*/,
4840 CORBA::Boolean /*isASCII*/ )
4842 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
4843 StudyContext* myStudyContext = GetCurrentStudyContext();
4845 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
4846 int anId = atoi( aLocalPersistentID );
4847 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
4849 return CORBA::string_dup( "" );
4852 //=======================================================================
4853 //function : RegisterObject
4855 //=======================================================================
4857 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
4859 StudyContext* myStudyContext = GetCurrentStudyContext();
4860 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4861 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
4862 return myStudyContext->addObject( string( iorString.in() ) );
4867 //================================================================================
4869 * \brief Return id of registered object
4870 * \param theObject - the Object
4871 * \retval int - Object id
4873 //================================================================================
4875 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
4877 StudyContext* myStudyContext = GetCurrentStudyContext();
4878 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4879 string iorString = GetORB()->object_to_string( theObject );
4880 return myStudyContext->findId( iorString );
4885 //=============================================================================
4887 * SMESH_Gen_i::SetName
4889 * Set a new object name
4891 //=============================================================================
4892 void SMESH_Gen_i::SetName(const char* theIOR,
4893 const char* theName)
4895 if ( theIOR && strcmp( theIOR, "" ) ) {
4896 CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
4897 SALOMEDS::SObject_var aSO = ObjectToSObject( myCurrentStudy, anObject );
4898 if ( !aSO->_is_nil() ) {
4899 SetName( aSO, theName );
4904 int SMESH_Gen_i::GetCurrentStudyID()
4906 return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
4909 //=============================================================================
4911 * SMESHEngine_factory
4913 * C factory, accessible with dlsym, after dlopen
4915 //=============================================================================
4919 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
4920 PortableServer::POA_ptr poa,
4921 PortableServer::ObjectId* contId,
4922 const char* instanceName,
4923 const char* interfaceName )
4925 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
4926 if(MYDEBUG) SCRUTE(interfaceName);
4927 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
4928 return aSMESHGen->getId() ;