1 // Copyright (C) 2007-2013 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"
68 #include "SMESH_version.h"
70 #include "SMDS_EdgePosition.hxx"
71 #include "SMDS_FacePosition.hxx"
72 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
73 #include "SMDS_SetIterator.hxx"
74 #include "SMDS_SpacePosition.hxx"
75 #include "SMDS_VertexPosition.hxx"
76 #include "SMESHDS_Document.hxx"
77 #include "SMESHDS_Group.hxx"
78 #include "SMESHDS_GroupOnGeom.hxx"
79 #include "SMESH_Algo_i.hxx"
80 #include "SMESH_File.hxx"
81 #include "SMESH_Group.hxx"
82 #include "SMESH_Group_i.hxx"
83 #include "SMESH_Hypothesis.hxx"
84 #include "SMESH_Hypothesis_i.hxx"
85 #include "SMESH_Mesh.hxx"
86 #include "SMESH_MeshEditor.hxx"
87 #include "SMESH_Mesh_i.hxx"
88 #include "SMESH_PreMeshInfo.hxx"
89 #include "SMESH_PythonDump.hxx"
91 #include CORBA_SERVER_HEADER(SMESH_Group)
92 #include CORBA_SERVER_HEADER(SMESH_Filter)
93 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
95 #include "DriverMED_W_SMESHDS_Mesh.h"
96 #include "DriverMED_R_SMESHDS_Mesh.h"
98 #include "DriverCGNS_Read.hxx"
102 #include <GEOM_Client.hxx>
104 #include <Basics_Utils.hxx>
106 #include <OpUtil.hxx>
107 #include <SALOMEDS_Tool.hxx>
108 #include <SALOME_Container_i.hxx>
109 #include <SALOME_LifeCycleCORBA.hxx>
110 #include <SALOME_NamingService.hxx>
111 #include <Utils_CorbaException.hxx>
112 #include <Utils_ExceptHandlers.hxx>
113 #include <Utils_SINGLETON.hxx>
114 #include <utilities.h>
116 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
117 #include CORBA_CLIENT_HEADER(SALOME_Session)
119 // helpers about SALOME::GenericObj
120 #include <SALOMEDS_wrap.hxx>
121 #include <SALOMEDS_Attributes_wrap.hxx>
122 #include <GEOM_wrap.hxx>
130 using SMESH::TPythonDump;
133 #define NUM_TMP_FILES 2
136 static int MYDEBUG = 0;
138 static int MYDEBUG = 0;
141 // Static variables definition
142 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
143 CORBA::ORB_var SMESH_Gen_i::myOrb;
144 PortableServer::POA_var SMESH_Gen_i::myPoa;
145 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
146 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
147 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
150 const int nbElemPerDiagonal = 10;
152 //=============================================================================
154 * GetServant [ static ]
156 * Get servant of the CORBA object
158 //=============================================================================
160 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
162 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
165 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
169 INFOS( "GetServant - Unknown exception was caught!!!" );
174 //=============================================================================
176 * SObjectToObject [ static ]
178 * Get CORBA object corresponding to the SALOMEDS::SObject
180 //=============================================================================
182 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
184 SALOMEDS::GenericAttribute_wrap anAttr;
185 CORBA::Object_var anObj;
186 if ( !theSObject->_is_nil() ) {
188 if( theSObject->FindAttribute( anAttr.inout(), "AttributeIOR" ) ) {
189 SALOMEDS::AttributeIOR_wrap anIOR = anAttr;
190 CORBA::String_var aValue = anIOR->Value();
191 if( strcmp( aValue, "" ) != 0 )
192 anObj = GetORB()->string_to_object( aValue );
196 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
202 //=============================================================================
206 * Get SALOME_NamingService object
208 //=============================================================================
210 SALOME_NamingService* SMESH_Gen_i::GetNS()
212 if ( myNS == NULL ) {
213 myNS = SINGLETON_<SALOME_NamingService>::Instance();
214 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
215 myNS->init_orb( GetORB() );
220 //=============================================================================
224 * Get SALOME_LifeCycleCORBA object
226 //=============================================================================
227 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
228 if ( myLCC == NULL ) {
229 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
235 //=============================================================================
237 * GetGeomEngine [ static ]
239 * Get GEOM::GEOM_Gen reference
241 //=============================================================================
242 GEOM::GEOM_Gen_var SMESH_Gen_i::GetGeomEngine() {
243 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
244 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
245 //CCRT return aGeomEngine._retn();
246 if(CORBA::is_nil(myGeomGen))
248 Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
249 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
254 //=============================================================================
256 * SMESH_Gen_i::SMESH_Gen_i
258 * Default constructor: not for use
260 //=============================================================================
262 SMESH_Gen_i::SMESH_Gen_i()
264 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
267 //=============================================================================
269 * SMESH_Gen_i::SMESH_Gen_i
271 * Standard constructor, used with Container
273 //=============================================================================
275 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
276 PortableServer::POA_ptr poa,
277 PortableServer::ObjectId* contId,
278 const char* instanceName,
279 const char* interfaceName )
280 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
282 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
284 myOrb = CORBA::ORB::_duplicate(orb);
285 myPoa = PortableServer::POA::_duplicate(poa);
288 _id = myPoa->activate_object( _thisObj );
290 myIsEmbeddedMode = false;
291 myShapeReader = NULL; // shape reader
293 myIsHistoricalPythonDump = true;
294 myToForgetMeshDataOnHypModif = false;
296 // set it in standalone mode only
297 //OSD::SetSignal( true );
299 // 0020605: EDF 1190 SMESH: Display performance. 80 seconds for 52000 cells.
300 // find out mode (embedded or standalone) here else
301 // meshes created before calling SMESH_Client::GetSMESHGen(), which calls
302 // SMESH_Gen_i::SetEmbeddedMode(), have wrong IsEmbeddedMode flag
303 if ( SALOME_NamingService* ns = GetNS() )
305 CORBA::Object_var obj = ns->Resolve( "/Kernel/Session" );
306 SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
307 if ( !session->_is_nil() )
309 CORBA::String_var str_host = session->getHostname();
310 CORBA::Long s_pid = session->getPID();
311 string my_host = Kernel_Utils::GetHostname();
313 long my_pid = (long)_getpid();
315 long my_pid = (long) getpid();
317 SetEmbeddedMode( s_pid == my_pid && my_host == str_host.in() );
322 //=============================================================================
324 * SMESH_Gen_i::~SMESH_Gen_i
328 //=============================================================================
330 SMESH_Gen_i::~SMESH_Gen_i()
332 MESSAGE( "SMESH_Gen_i::~SMESH_Gen_i" );
334 // delete hypothesis creators
335 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
336 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
338 delete (*itHyp).second;
340 myHypCreatorMap.clear();
342 // Clear study contexts data
343 map<int, StudyContext*>::iterator it;
344 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
347 myStudyContextMap.clear();
348 // delete shape reader
350 delete myShapeReader;
353 //=============================================================================
355 * SMESH_Gen_i::createHypothesis
357 * Create hypothesis of given type
359 //=============================================================================
360 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
361 const char* theLibName)
362 throw (SALOME::SALOME_Exception)
364 /* It's Need to tranlate lib name for WIN32 or X platform */
365 char* aPlatformLibName = 0;
366 if ( theLibName && theLibName[0] != '\0' )
368 int libNameLen = strlen(theLibName);
369 //check for old format "libXXXXXXX.so"
370 if (libNameLen > 7 &&
371 !strncmp( theLibName, "lib", 3 ) &&
372 !strcmp( theLibName+libNameLen-3, ".so" ))
376 aPlatformLibName = new char[libNameLen - 1];
377 aPlatformLibName[0] = '\0';
378 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
379 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
380 aPlatformLibName[libNameLen - 2] = '\0';
382 aPlatformLibName = new char[ libNameLen + 1];
383 aPlatformLibName[0] = '\0';
384 aPlatformLibName = strcat( aPlatformLibName, theLibName );
385 aPlatformLibName[libNameLen] = '\0';
390 //try to use new format
392 aPlatformLibName = new char[ libNameLen + 5 ];
393 aPlatformLibName[0] = '\0';
394 aPlatformLibName = strcat( aPlatformLibName, theLibName );
395 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
397 aPlatformLibName = new char[ libNameLen + 7 ];
398 aPlatformLibName[0] = '\0';
399 aPlatformLibName = strcat( aPlatformLibName, "lib" );
400 aPlatformLibName = strcat( aPlatformLibName, theLibName );
401 aPlatformLibName = strcat( aPlatformLibName, ".so" );
407 Unexpect aCatch(SALOME_SalomeException);
408 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
410 // create a new hypothesis object servant
411 SMESH_Hypothesis_i* myHypothesis_i = 0;
412 SMESH::SMESH_Hypothesis_var hypothesis_i;
416 // check, if creator for this hypothesis type already exists
417 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
419 // load plugin library
420 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
421 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
424 // report any error, if occured
426 const char* anError = dlerror();
427 throw(SALOME_Exception(anError));
429 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
433 // get method, returning hypothesis creator
434 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
435 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
436 GetHypothesisCreator procHandle =
437 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
440 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
441 UnLoadLib(libHandle);
444 // get hypothesis creator
445 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
446 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
449 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
452 // map hypothesis creator to a hypothesis name
453 myHypCreatorMap[string(theHypName)] = aCreator;
456 // create a new hypothesis object, store its ref. in studyContext
457 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
459 myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
460 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
462 catch (SALOME_Exception& S_ex)
464 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
467 if ( aPlatformLibName )
468 delete[] aPlatformLibName;
471 return hypothesis_i._retn();
473 // activate the CORBA servant of hypothesis
474 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
475 int nextId = RegisterObject( hypothesis_i );
476 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
478 return hypothesis_i._retn();
481 //=============================================================================
483 * SMESH_Gen_i::createMesh
485 * Create empty mesh on shape
487 //=============================================================================
488 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
489 throw ( SALOME::SALOME_Exception )
491 Unexpect aCatch(SALOME_SalomeException);
492 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
494 // Get or create the GEOM_Client instance
496 // create a new mesh object servant, store it in a map in study context
497 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
498 // create a new mesh object
499 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
500 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
502 // activate the CORBA servant of Mesh
503 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
504 int nextId = RegisterObject( mesh );
505 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
508 catch (SALOME_Exception& S_ex) {
509 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
511 return SMESH::SMESH_Mesh::_nil();
514 //=============================================================================
516 * SMESH_Gen_i::GetShapeReader
520 //=============================================================================
521 GEOM_Client* SMESH_Gen_i::GetShapeReader()
523 // create shape reader if necessary
524 if ( !myShapeReader )
525 myShapeReader = new GEOM_Client(GetContainerRef());
526 ASSERT( myShapeReader );
527 return myShapeReader;
530 //=============================================================================
532 * SMESH_Gen_i::SetGeomEngine
534 * Set GEOM::GEOM_Gen reference
536 //=============================================================================
537 //GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
538 void SMESH_Gen_i::SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo )
540 //Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
541 //myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
542 myGeomGen=GEOM::GEOM_Gen::_duplicate(geomcompo);
546 //=============================================================================
548 * SMESH_Gen_i::SetEmbeddedMode
552 //=============================================================================
554 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
556 myIsEmbeddedMode = theMode;
557 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
559 if ( !myIsEmbeddedMode ) {
560 //PAL10867: disable signals catching with "noexcepthandler" option
561 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
562 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
567 char* envDisableFPE = getenv("DISABLE_FPE");
568 if (envDisableFPE && atoi(envDisableFPE))
573 OSD::SetSignal( raiseFPE );
575 // else OSD::SetSignal() is called in GUI
579 //=============================================================================
581 * SMESH_Gen_i::IsEmbeddedMode
585 //=============================================================================
587 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
589 return myIsEmbeddedMode;
592 //=============================================================================
594 * SMESH_Gen_i::SetCurrentStudy
598 //=============================================================================
600 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
602 setCurrentStudy( theStudy );
605 void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy,
606 bool theStudyIsBeingClosed)
608 int curStudyId = GetCurrentStudyID();
609 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
610 // create study context, if it doesn't exist and set current study
611 int studyId = GetCurrentStudyID();
612 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() )
613 myStudyContextMap[ studyId ] = new StudyContext;
615 // myCurrentStudy may be nil
616 if ( !theStudyIsBeingClosed && !CORBA::is_nil( myCurrentStudy ) ) {
617 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
618 SALOMEDS::SComponent_wrap GEOM_var = myCurrentStudy->FindComponent( "GEOM" );
619 if( !GEOM_var->_is_nil() )
620 aStudyBuilder->LoadWith( GEOM_var, GetGeomEngine() );
621 // NPAL16168, issue 0020210
622 // Let meshes update their data depending on GEOM groups that could change
623 if ( curStudyId != studyId )
625 CORBA::String_var compDataType = ComponentDataType();
626 SALOMEDS::SComponent_wrap me = myCurrentStudy->FindComponent( compDataType.in() );
627 if ( !me->_is_nil() ) {
628 SALOMEDS::ChildIterator_wrap anIter = myCurrentStudy->NewChildIterator( me );
629 for ( ; anIter->More(); anIter->Next() ) {
630 SALOMEDS::SObject_wrap so = anIter->Value();
631 CORBA::Object_var ior = SObjectToObject( so );
632 if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
633 mesh->CheckGeomGroupModif();
640 //=============================================================================
642 * SMESH_Gen_i::GetCurrentStudy
646 //=============================================================================
648 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
650 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
651 return SALOMEDS::Study::_duplicate( myCurrentStudy );
654 //=============================================================================
656 * SMESH_Gen_i::GetCurrentStudyContext
658 * Get current study context
660 //=============================================================================
661 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
663 if ( !CORBA::is_nil( myCurrentStudy ) &&
664 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
665 return myStudyContextMap[ myCurrentStudy->StudyId() ];
670 //=============================================================================
672 * SMESH_Gen_i::CreateHypothesis
674 * Create hypothesis/algorothm of given type and publish it in the study
676 //=============================================================================
678 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
679 const char* theLibName )
680 throw ( SALOME::SALOME_Exception )
682 Unexpect aCatch(SALOME_SalomeException);
683 // Create hypothesis/algorithm
684 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
686 // Publish hypothesis/algorithm in the study
687 if ( CanPublishInStudy( hyp ) ) {
688 SALOMEDS::SObject_wrap aSO = PublishHypothesis( myCurrentStudy, hyp );
689 if ( !aSO->_is_nil() ) {
690 // Update Python script
691 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
692 << theHypName << "', '" << theLibName << "')";
699 //================================================================================
701 * \brief Return a hypothesis holding parameter values corresponding either to the mesh
702 * existing on the given geometry or to size of the geometry.
703 * \param theHypType - hypothesis type name
704 * \param theLibName - plugin library name
705 * \param theMesh - The mesh of interest
706 * \param theGeom - The shape to get parameter values from
707 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
708 * in a study and used to compute the mesh, or a temporary one created just to pass
711 //================================================================================
713 SMESH::SMESH_Hypothesis_ptr
714 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
715 const char* theLibName,
716 SMESH::SMESH_Mesh_ptr theMesh,
717 GEOM::GEOM_Object_ptr theGeom,
718 CORBA::Boolean byMesh)
719 throw ( SALOME::SALOME_Exception )
721 Unexpect aCatch(SALOME_SalomeException);
722 if ( byMesh && CORBA::is_nil( theMesh ) )
723 return SMESH::SMESH_Hypothesis::_nil();
724 if ( byMesh && CORBA::is_nil( theGeom ) )
725 return SMESH::SMESH_Hypothesis::_nil();
727 // -----------------------------------------------
728 // find hypothesis used to mesh theGeom
729 // -----------------------------------------------
731 // get mesh and shape
732 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
733 TopoDS_Shape shape = GeomObjectToShape( theGeom );
734 if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
735 return SMESH::SMESH_Hypothesis::_nil();
736 ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
738 // create a temporary hypothesis to know its dimention
739 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
740 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
742 return SMESH::SMESH_Hypothesis::_nil();
743 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
746 // look for a hypothesis of theHypType used to mesh the shape
747 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
750 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
751 int nbLocalHyps = aHypList->length();
752 for ( int i = 0; i < nbLocalHyps; i++ ) {
753 CORBA::String_var hypName = aHypList[i]->GetName();
754 if ( strcmp( theHypType, hypName.in() ) == 0 ) // FOUND local!
755 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
757 // check super shapes
758 TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
759 while ( nbLocalHyps == 0 && itShape.More() ) {
760 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
761 if ( ! CORBA::is_nil( geomObj )) {
762 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
763 nbLocalHyps = aHypList->length();
764 for ( int i = 0; i < nbLocalHyps; i++ )
765 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
766 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
772 // let the temporary hypothesis find out somehow parameter values by mesh
773 if ( hyp->SetParametersByMesh( mesh, shape ))
774 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
779 diagonal = mesh->GetShapeDiagonalSize();
781 diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
782 ::SMESH_Hypothesis::TDefaults dflts;
783 dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
784 dflts._nbSegments = myGen.GetDefaultNbSegments();
785 dflts._shape = &shape;
786 // let the temporary hypothesis initialize it's values
787 if ( hyp->SetParametersByDefaults( dflts, mesh ))
788 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
791 return SMESH::SMESH_Hypothesis::_nil();
794 //=============================================================================
796 * Sets number of segments per diagonal of boundary box of geometry by which
797 * default segment length of appropriate 1D hypotheses is defined
799 //=============================================================================
801 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
802 throw ( SALOME::SALOME_Exception )
804 if ( theNbSegments > 0 )
805 myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
807 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
809 //=============================================================================
811 * \brief Sets default number of segments per edge
813 //=============================================================================
814 void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
815 throw ( SALOME::SALOME_Exception )
817 if ( theNbSegments > 0 )
818 myGen.SetDefaultNbSegments( int(theNbSegments) );
820 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
823 //=============================================================================
827 //=============================================================================
829 void SMESH_Gen_i::SetOption(const char* name, const char* value)
831 if ( name && value && strlen( value ) > 0 )
834 if ( strcmp(name, "historical_python_dump") == 0 )
836 myIsHistoricalPythonDump = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
837 msgToGUI = "preferences/SMESH/historical_python_dump/";
838 msgToGUI += myIsHistoricalPythonDump ? "true" : "false";
840 else if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
842 myToForgetMeshDataOnHypModif = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
843 msgToGUI = "preferences/SMESH/forget_mesh_on_hyp_modif/";
844 msgToGUI += myToForgetMeshDataOnHypModif ? "true" : "false";
847 // update preferences in case if SetOption() is invoked from python console
848 if ( !msgToGUI.empty() )
850 CORBA::Object_var obj = SMESH_Gen_i::GetNS()->Resolve( "/Kernel/Session" );
851 SALOME::Session_var session = SALOME::Session::_narrow( obj );
852 if ( !CORBA::is_nil( session ) )
853 session->emitMessageOneWay(msgToGUI.c_str());
858 //=============================================================================
860 Return an option value
862 //=============================================================================
864 char* SMESH_Gen_i::GetOption(const char* name)
868 if ( strcmp(name, "historical_python_dump") == 0 )
870 return CORBA::string_dup( myIsHistoricalPythonDump ? "true" : "false" );
872 if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
874 return CORBA::string_dup( myToForgetMeshDataOnHypModif ? "true" : "false" );
877 return CORBA::string_dup( "" );
880 //=============================================================================
882 * SMESH_Gen_i::CreateMesh
884 * Create empty mesh on a shape and publish it in the study
886 //=============================================================================
888 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
889 throw ( SALOME::SALOME_Exception )
891 Unexpect aCatch(SALOME_SalomeException);
892 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
894 SMESH::SMESH_Mesh_var mesh = this->createMesh();
896 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
897 ASSERT( meshServant );
898 meshServant->SetShape( theShapeObject );
900 // publish mesh in the study
901 if ( CanPublishInStudy( mesh ) ) {
902 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
903 aStudyBuilder->NewCommand(); // There is a transaction
904 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
905 aStudyBuilder->CommitCommand();
906 if ( !aSO->_is_nil() ) {
907 // Update Python script
908 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
915 //=============================================================================
917 * SMESH_Gen_i::CreateEmptyMesh
921 //=============================================================================
923 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
924 throw ( SALOME::SALOME_Exception )
926 Unexpect aCatch(SALOME_SalomeException);
927 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
929 SMESH::SMESH_Mesh_var mesh = this->createMesh();
931 // publish mesh in the study
932 if ( CanPublishInStudy( mesh ) ) {
933 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
934 aStudyBuilder->NewCommand(); // There is a transaction
935 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
936 aStudyBuilder->CommitCommand();
937 if ( !aSO->_is_nil() ) {
938 // Update Python script
939 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
946 //=============================================================================
948 * SMESH_Gen_i::CreateMeshFromUNV
950 * Create mesh and import data from UNV file
952 //=============================================================================
954 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
955 throw ( SALOME::SALOME_Exception )
957 Unexpect aCatch(SALOME_SalomeException);
958 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
960 SMESH::SMESH_Mesh_var aMesh = createMesh();
962 // publish mesh in the study
963 if ( CanPublishInStudy( aMesh ) ) {
964 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
965 aStudyBuilder->NewCommand(); // There is a transaction
966 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
967 aStudyBuilder->CommitCommand();
968 if ( !aSO->_is_nil() ) {
969 // Update Python script
970 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromUNV(r'" << theFileName << "')";
974 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
976 aServant->ImportUNVFile( theFileName );
978 // Dump creation of groups
979 SMESH::ListOfGroups_var groups = aServant->GetGroups();
981 aServant->GetImpl().GetMeshDS()->Modified();
982 return aMesh._retn();
985 //=============================================================================
987 * SMESH_Gen_i::CreateMeshFromMED
989 * Create mesh and import data from MED file
991 //=============================================================================
993 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileName,
994 SMESH::DriverMED_ReadStatus& theStatus,
995 const char* theCommandNameForPython,
996 const char* theFileNameForPython)
999 char bname[ _MAX_FNAME ];
1000 _splitpath( theFileNameForPython, NULL, NULL, bname, NULL );
1001 string aFileName = bname;
1003 string aFileName = basename( theFileNameForPython );
1005 // Retrieve mesh names from the file
1006 DriverMED_R_SMESHDS_Mesh myReader;
1007 myReader.SetFile( theFileName );
1008 myReader.SetMeshId( -1 );
1009 Driver_Mesh::Status aStatus;
1010 list<string> aNames = myReader.GetMeshNames(aStatus);
1011 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
1012 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1014 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1017 TPythonDump aPythonDump;
1018 aPythonDump << "([";
1020 if (theStatus == SMESH::DRS_OK) {
1021 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1022 aStudyBuilder->NewCommand(); // There is a transaction
1023 aResult->length( aNames.size() );
1026 // Iterate through all meshes and create mesh objects
1027 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
1029 if (i > 0) aPythonDump << ", ";
1032 SMESH::SMESH_Mesh_var mesh = createMesh();
1034 // publish mesh in the study
1035 SALOMEDS::SObject_wrap aSO;
1036 if ( CanPublishInStudy( mesh ) )
1037 // little trick: for MED file theFileName and theFileNameForPython are the same, but they are different for SAUV
1038 // - as names of meshes are stored in MED file, we use them for data publishing
1039 // - as mesh name is not stored in UNV file, we use file name as name of mesh when publishing data
1040 aSO = PublishMesh( myCurrentStudy, mesh.in(), ( theFileName == theFileNameForPython ) ? (*it).c_str() : aFileName.c_str() );
1041 if ( !aSO->_is_nil() ) {
1046 aPythonDump << "mesh_" << i;
1049 // Read mesh data (groups are published automatically by ImportMEDFile())
1050 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1051 ASSERT( meshServant );
1052 SMESH::DriverMED_ReadStatus status1 =
1053 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
1054 if (status1 > theStatus)
1055 theStatus = status1;
1057 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
1058 meshServant->GetImpl().GetMeshDS()->Modified();
1060 aStudyBuilder->CommitCommand();
1063 // Update Python script
1064 aPythonDump << "], status) = " << this << "." << theCommandNameForPython << "(r'" << theFileNameForPython << "')";
1066 // Dump creation of groups
1067 for ( int i = 0; i < aResult->length(); ++i )
1068 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1070 return aResult._retn();
1073 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
1074 SMESH::DriverMED_ReadStatus& theStatus)
1075 throw ( SALOME::SALOME_Exception )
1077 Unexpect aCatch(SALOME_SalomeException);
1078 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
1079 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(theFileName, theStatus, "CreateMeshesFromMED", theFileName);
1083 //=============================================================================
1085 * SMESH_Gen_i::CreateMeshFromSAUV
1087 * Create mesh and import data from SAUV file
1089 //=============================================================================
1091 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName,
1092 SMESH::DriverMED_ReadStatus& theStatus)
1093 throw ( SALOME::SALOME_Exception )
1095 Unexpect aCatch(SALOME_SalomeException);
1096 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromSAUV" );
1097 std::string sauvfilename(theFileName);
1098 std::string medfilename(theFileName);
1099 medfilename += ".med";
1102 cmd = "%PYTHONBIN% ";
1107 cmd += "from medutilities import convert ; convert(r'" + sauvfilename + "', 'GIBI', 'MED', 1, r'" + medfilename + "')";
1109 system(cmd.c_str());
1110 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), theStatus, "CreateMeshesFromSAUV", sauvfilename.c_str());
1112 cmd = "%PYTHONBIN% ";
1117 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1119 system(cmd.c_str());
1123 //=============================================================================
1125 * SMESH_Gen_i::CreateMeshFromSTL
1127 * Create mesh and import data from STL file
1129 //=============================================================================
1131 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
1132 throw ( SALOME::SALOME_Exception )
1134 Unexpect aCatch(SALOME_SalomeException);
1135 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
1137 SMESH::SMESH_Mesh_var aMesh = createMesh();
1140 char bname[ _MAX_FNAME ];
1141 _splitpath( theFileName, NULL, NULL, bname, NULL );
1142 string aFileName = bname;
1144 string aFileName = basename( theFileName );
1146 // publish mesh in the study
1147 if ( CanPublishInStudy( aMesh ) ) {
1148 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1149 aStudyBuilder->NewCommand(); // There is a transaction
1150 SALOMEDS::SObject_wrap aSO = PublishInStudy
1151 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1152 aStudyBuilder->CommitCommand();
1153 if ( !aSO->_is_nil() ) {
1154 // Update Python script
1155 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL(r'" << theFileName << "')";
1159 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1161 aServant->ImportSTLFile( theFileName );
1162 aServant->GetImpl().GetMeshDS()->Modified();
1163 return aMesh._retn();
1166 //================================================================================
1168 * \brief Create meshes and import data from the CGSN file
1170 //================================================================================
1172 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName,
1173 SMESH::DriverMED_ReadStatus& theStatus)
1174 throw ( SALOME::SALOME_Exception )
1176 Unexpect aCatch(SALOME_SalomeException);
1178 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
1181 // Retrieve nb meshes from the file
1182 DriverCGNS_Read myReader;
1183 myReader.SetFile( theFileName );
1184 Driver_Mesh::Status aStatus;
1185 int nbMeshes = myReader.GetNbMeshes(aStatus);
1186 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1188 aResult->length( nbMeshes );
1190 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1193 TPythonDump aPythonDump;
1194 aPythonDump << "([";
1196 if (theStatus == SMESH::DRS_OK)
1198 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1199 aStudyBuilder->NewCommand(); // There is a transaction
1203 // Iterate through all meshes and create mesh objects
1204 for ( ; i < nbMeshes; ++i )
1207 if (i > 0) aPythonDump << ", ";
1210 SMESH::SMESH_Mesh_var mesh = createMesh();
1211 aResult[i] = SMESH::SMESH_Mesh::_duplicate( mesh );
1213 // Read mesh data (groups are published automatically by ImportMEDFile())
1214 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1215 ASSERT( meshServant );
1217 SMESH::DriverMED_ReadStatus status1 =
1218 meshServant->ImportCGNSFile( theFileName, i, meshName );
1219 if (status1 > theStatus)
1220 theStatus = status1;
1222 meshServant->GetImpl().GetMeshDS()->Modified();
1223 // publish mesh in the study
1224 SALOMEDS::SObject_wrap aSO;
1225 if ( CanPublishInStudy( mesh ) )
1226 aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() );
1229 if ( !aSO->_is_nil() ) {
1233 aPythonDump << "mesh_" << i;
1236 aStudyBuilder->CommitCommand();
1239 aPythonDump << "], status) = " << this << ".CreateMeshesFromCGNS(r'" << theFileName << "')";
1241 // Dump creation of groups
1242 for ( int i = 0; i < aResult->length(); ++i )
1243 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1245 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
1248 return aResult._retn();
1251 //================================================================================
1253 * \brief Create a mesh and import data from a GMF file
1255 //================================================================================
1257 SMESH::SMESH_Mesh_ptr
1258 SMESH_Gen_i::CreateMeshesFromGMF( const char* theFileName,
1259 CORBA::Boolean theMakeRequiredGroups,
1260 SMESH::ComputeError_out theError)
1261 throw ( SALOME::SALOME_Exception )
1263 Unexpect aCatch(SALOME_SalomeException);
1265 SMESH::SMESH_Mesh_var aMesh = createMesh();
1267 char bname[ _MAX_FNAME ];
1268 _splitpath( theFileName, NULL, NULL, bname, NULL );
1269 string aFileName = bname;
1271 string aFileName = basename( theFileName );
1273 // publish mesh in the study
1274 if ( CanPublishInStudy( aMesh ) ) {
1275 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1276 aStudyBuilder->NewCommand(); // There is a transaction
1277 SALOMEDS::SObject_wrap aSO = PublishInStudy
1278 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1279 aStudyBuilder->CommitCommand();
1280 if ( !aSO->_is_nil() ) {
1281 // Update Python script
1282 TPythonDump() << "("<< aSO << ", error) = " << this << ".CreateMeshesFromGMF(r'"
1283 << theFileName << "', "
1284 << theMakeRequiredGroups << " )";
1287 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1289 theError = aServant->ImportGMFFile( theFileName, theMakeRequiredGroups );
1290 aServant->GetImpl().GetMeshDS()->Modified();
1291 return aMesh._retn();
1295 //=============================================================================
1297 * SMESH_Gen_i::IsReadyToCompute
1299 * Returns true if mesh contains enough data to be computed
1301 //=============================================================================
1303 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
1304 GEOM::GEOM_Object_ptr theShapeObject )
1305 throw ( SALOME::SALOME_Exception )
1307 Unexpect aCatch(SALOME_SalomeException);
1308 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
1310 if ( CORBA::is_nil( theShapeObject ) )
1311 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1312 SALOME::BAD_PARAM );
1314 if ( CORBA::is_nil( theMesh ) )
1315 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1316 SALOME::BAD_PARAM );
1320 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1321 ASSERT( meshServant );
1322 if ( meshServant ) {
1323 // get local TopoDS_Shape
1324 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1325 // call implementation
1326 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1327 return myGen.CheckAlgoState( myLocMesh, myLocShape );
1330 catch ( SALOME_Exception& S_ex ) {
1331 INFOS( "catch exception "<< S_ex.what() );
1336 //================================================================================
1338 * \brief Find SObject for an algo
1340 //================================================================================
1342 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
1345 if ( !myCurrentStudy->_is_nil() ) {
1346 // find algo in the study
1347 CORBA::String_var compDataType = ComponentDataType();
1348 SALOMEDS::SComponent_wrap father = myCurrentStudy->FindComponent( compDataType.in() );
1349 if ( !father->_is_nil() ) {
1350 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( father );
1351 for ( ; itBig->More(); itBig->Next() ) {
1352 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
1353 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1354 SALOMEDS::ChildIterator_wrap algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1355 for ( ; algoIt->More(); algoIt->Next() ) {
1356 SALOMEDS::SObject_wrap algoSO = algoIt->Value();
1357 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1358 if ( !CORBA::is_nil( algoIOR )) {
1359 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1360 if ( impl && impl->GetImpl() == algo )
1361 return algoSO._retn();
1363 } // loop on algo SO's
1366 } // SMESH component iterator
1370 return SALOMEDS::SObject::_nil();
1373 //================================================================================
1375 * \brief Return errors of mesh computation
1377 //================================================================================
1379 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1380 GEOM::GEOM_Object_ptr theSubObject )
1381 throw ( SALOME::SALOME_Exception )
1383 Unexpect aCatch(SALOME_SalomeException);
1384 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1386 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1387 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1389 if ( CORBA::is_nil( theMesh ) )
1390 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1392 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1394 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1397 if(theMesh->HasShapeToMesh())
1398 shape = GeomObjectToShape( theSubObject );
1400 shape = SMESH_Mesh::PseudoShape();
1402 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1404 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1407 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1408 const bool includeSelf = true, complexShapeFirst = true;
1409 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1411 while ( smIt->more() )
1414 // if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1416 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1417 if ( error && !error->IsOK() && error->myAlgo )
1419 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1420 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1421 errStruct.comment = error->myComment.c_str();
1422 errStruct.subShapeID = sm->GetId();
1423 SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->myAlgo );
1424 if ( !algoSO->_is_nil() ) {
1425 CORBA::String_var algoName = algoSO->GetName();
1426 errStruct.algoName = algoName;
1429 errStruct.algoName = error->myAlgo->GetName();
1431 errStruct.hasBadMesh = !error->myBadElements.empty();
1434 error_array->length( nbErr );
1437 catch ( SALOME_Exception& S_ex ) {
1438 INFOS( "catch exception "<< S_ex.what() );
1441 return error_array._retn();
1445 //================================================================================
1447 * \brief Return mesh elements preventing computation of a subshape
1449 //================================================================================
1451 SMESH::MeshPreviewStruct*
1452 SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1453 CORBA::Short theSubShapeID )
1454 throw ( SALOME::SALOME_Exception )
1456 Unexpect aCatch(SALOME_SalomeException);
1457 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetBadInputElements()" );
1459 if ( CORBA::is_nil( theMesh ) )
1460 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1462 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1465 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1467 // mesh implementation
1468 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1469 // submesh by subshape id
1470 if ( SMESH_subMesh * sm = mesh.GetSubMeshContaining( theSubShapeID ))
1473 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1474 if ( error && !error->myBadElements.empty())
1476 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1477 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1479 // get nodes of elements and count elements
1480 TNode2LocalIDMap mapNode2LocalID;
1481 list< TNodeLocalID > connectivity;
1482 int i, nbElements = 0, nbConnNodes = 0;
1484 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
1485 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
1486 for ( ; elemIt != elemEnd; ++elemIt, ++nbElements )
1488 SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator();
1489 while ( nIt->more() )
1490 connectivity.push_back
1491 ( mapNode2LocalID.insert( make_pair( nIt->next(), ++nbConnNodes)).first );
1493 // fill node coords and assign local ids to the nodes
1494 int nbNodes = mapNode2LocalID.size();
1495 result->nodesXYZ.length( nbNodes );
1496 TNodeLocalID node2ID = mapNode2LocalID.begin();
1497 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1498 node2ID->second = i;
1499 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1500 result->nodesXYZ[i].x = node->X();
1501 result->nodesXYZ[i].y = node->Y();
1502 result->nodesXYZ[i].z = node->Z();
1504 // fill connectivity
1505 result->elementConnectivities.length( nbConnNodes );
1506 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1507 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1508 result->elementConnectivities[i] = (*connIt)->second;
1510 // fill element types
1511 result->elementTypes.length( nbElements );
1512 for ( i = 0, elemIt = error->myBadElements.begin(); i <nbElements; ++i, ++elemIt )
1514 const SMDS_MeshElement* elem = *elemIt;
1515 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType();
1516 result->elementTypes[i].isPoly = elem->IsPoly();
1517 result->elementTypes[i].nbNodesInElement = elem->NbNodes();
1523 catch ( SALOME_Exception& S_ex ) {
1524 INFOS( "catch exception "<< S_ex.what() );
1527 return result._retn();
1530 //================================================================================
1532 * \brief Returns errors of hypotheses definintion
1533 * \param theMesh - the mesh
1534 * \param theSubObject - the main or sub- shape
1535 * \retval SMESH::algo_error_array* - sequence of errors
1537 //================================================================================
1539 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1540 GEOM::GEOM_Object_ptr theSubObject )
1541 throw ( SALOME::SALOME_Exception )
1543 Unexpect aCatch(SALOME_SalomeException);
1544 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1546 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1547 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1549 if ( CORBA::is_nil( theMesh ) )
1550 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1552 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1554 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1555 ASSERT( meshServant );
1556 if ( meshServant ) {
1557 TopoDS_Shape myLocShape;
1558 if(theMesh->HasShapeToMesh())
1559 myLocShape = GeomObjectToShape( theSubObject );
1561 myLocShape = SMESH_Mesh::PseudoShape();
1563 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1564 list< ::SMESH_Gen::TAlgoStateError > error_list;
1565 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1566 // call ::SMESH_Gen::GetAlgoState()
1567 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1568 error_array->length( error_list.size() );
1570 for ( error = error_list.begin(); error != error_list.end(); ++error )
1572 // fill AlgoStateError structure
1573 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1574 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1575 errStruct.algoDim = error->_algoDim;
1576 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1577 errStruct.algoName = "";
1578 SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->_algo );
1579 if ( !algoSO->_is_nil() ) {
1580 CORBA::String_var algoName = algoSO->GetName();
1581 errStruct.algoName = algoName.in();
1586 catch ( SALOME_Exception& S_ex ) {
1587 INFOS( "catch exception "<< S_ex.what() );
1589 return error_array._retn();
1592 //=============================================================================
1594 * SMESH_Gen_i::GetSubShapesId
1596 * Get sub-shapes unique ID's list
1598 //=============================================================================
1600 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1601 const SMESH::object_array& theListOfSubShapeObject )
1602 throw ( SALOME::SALOME_Exception )
1604 Unexpect aCatch(SALOME_SalomeException);
1605 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1607 SMESH::long_array_var shapesId = new SMESH::long_array;
1610 if ( CORBA::is_nil( theMainShapeObject ) )
1611 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1612 SALOME::BAD_PARAM );
1616 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1617 TopTools_IndexedMapOfShape myIndexToShape;
1618 TopExp::MapShapes(myMainShape,myIndexToShape);
1620 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1622 GEOM::GEOM_Object_var aShapeObject
1623 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1624 if ( CORBA::is_nil( aShapeObject ) )
1625 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1626 SALOME::BAD_PARAM );
1628 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1629 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1631 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1632 setId.insert(myIndexToShape.FindIndex(F));
1633 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1635 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1637 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1638 setId.insert(myIndexToShape.FindIndex(E));
1639 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1641 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1643 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1644 setId.insert(myIndexToShape.FindIndex(V));
1645 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1648 shapesId->length(setId.size());
1649 set<int>::iterator iind;
1651 for (iind = setId.begin(); iind != setId.end(); iind++)
1653 if(MYDEBUG) SCRUTE((*iind));
1654 shapesId[i] = (*iind);
1655 if(MYDEBUG) SCRUTE(shapesId[i]);
1659 catch (SALOME_Exception& S_ex)
1661 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1664 return shapesId._retn();
1667 //=============================================================================
1669 * SMESH_Gen_i::Compute
1671 * Compute mesh on a shape
1673 //=============================================================================
1675 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1676 GEOM::GEOM_Object_ptr theShapeObject )
1677 throw ( SALOME::SALOME_Exception )
1680 Unexpect aCatch(SALOME_SalomeException);
1681 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1683 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1684 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1685 SALOME::BAD_PARAM );
1687 if ( CORBA::is_nil( theMesh ) )
1688 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1689 SALOME::BAD_PARAM );
1691 // Update Python script
1692 TPythonDump() << "isDone = " << this << ".Compute( "
1693 << theMesh << ", " << theShapeObject << ")";
1697 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1698 meshServant->Load();
1699 ASSERT( meshServant );
1700 if ( meshServant ) {
1701 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1702 meshServant->CheckGeomGroupModif();
1703 // get local TopoDS_Shape
1704 TopoDS_Shape myLocShape;
1705 if(theMesh->HasShapeToMesh())
1706 myLocShape = GeomObjectToShape( theShapeObject );
1708 myLocShape = SMESH_Mesh::PseudoShape();
1709 // call implementation compute
1710 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1711 #ifdef WITH_SMESH_CANCEL_COMPUTE
1712 myGen.PrepareCompute( myLocMesh, myLocShape);
1714 bool ok = myGen.Compute( myLocMesh, myLocShape);
1715 meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
1716 myLocMesh.GetMeshDS()->Modified();
1720 catch ( std::bad_alloc ) {
1721 INFOS( "Compute(): lack of memory" );
1723 catch ( SALOME_Exception& S_ex ) {
1724 INFOS( "Compute(): catch exception "<< S_ex.what() );
1727 INFOS( "Compute(): unknown exception " );
1732 //=============================================================================
1734 * SMESH_Gen_i::CancelCompute
1736 * Cancel Compute mesh on a shape
1738 //=============================================================================
1740 void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
1741 GEOM::GEOM_Object_ptr theShapeObject )
1743 #ifdef WITH_SMESH_CANCEL_COMPUTE
1744 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1745 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1746 TopoDS_Shape myLocShape;
1747 if(theMesh->HasShapeToMesh())
1748 myLocShape = GeomObjectToShape( theShapeObject );
1750 myLocShape = SMESH_Mesh::PseudoShape();
1751 myGen.CancelCompute( myLocMesh, myLocShape);
1755 //=============================================================================
1757 * SMESH_Gen_i::Precompute
1759 * Compute mesh as preview till indicated dimension on shape
1761 //=============================================================================
1763 SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh,
1764 GEOM::GEOM_Object_ptr theShapeObject,
1765 SMESH::Dimension theDimension,
1766 SMESH::long_array& theShapesId)
1767 throw ( SALOME::SALOME_Exception )
1769 Unexpect aCatch(SALOME_SalomeException);
1770 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Precompute" );
1772 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1773 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1774 SALOME::BAD_PARAM );
1776 if ( CORBA::is_nil( theMesh ) )
1777 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1778 SALOME::BAD_PARAM );
1780 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1783 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1784 meshServant->Load();
1785 ASSERT( meshServant );
1786 if ( meshServant ) {
1787 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1788 meshServant->CheckGeomGroupModif();
1789 // get local TopoDS_Shape
1790 TopoDS_Shape myLocShape;
1791 if(theMesh->HasShapeToMesh())
1792 myLocShape = GeomObjectToShape( theShapeObject );
1794 return result._retn();;
1796 // call implementation compute
1797 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1799 ::MeshDimension aDim = (MeshDimension)theDimension;
1800 if ( myGen.Compute( myLocMesh, myLocShape, false, aDim, &shapeIds ) )
1802 int nbShapeId = shapeIds.size();
1803 theShapesId.length( nbShapeId );
1804 // iterates on shapes and collect mesh entities into mesh preview
1805 TSetOfInt::const_iterator idIt = shapeIds.begin();
1806 TSetOfInt::const_iterator idEnd = shapeIds.end();
1807 std::map< int, int > mapOfShIdNb;
1808 std::set< SMESH_TLink > setOfEdge;
1809 std::list< SMDSAbs_ElementType > listOfElemType;
1810 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1811 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1812 TNode2LocalIDMap mapNode2LocalID;
1813 list< TNodeLocalID > connectivity;
1814 int i, nbConnNodes = 0;
1815 std::set< const SMESH_subMesh* > setOfVSubMesh;
1816 // iterates on shapes
1817 for ( ; idIt != idEnd; idIt++ )
1819 if ( mapOfShIdNb.find( *idIt ) != mapOfShIdNb.end() )
1821 SMESH_subMesh* sm = myLocMesh.GetSubMeshContaining(*idIt);
1822 if ( !sm || !sm->IsMeshComputed() )
1825 const TopoDS_Shape& aSh = sm->GetSubShape();
1826 const int shDim = myGen.GetShapeDim( aSh );
1827 if ( shDim < 1 || shDim > theDimension )
1830 mapOfShIdNb[ *idIt ] = 0;
1831 theShapesId[ mapOfShIdNb.size() - 1 ] = *idIt;
1833 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1834 if ( !smDS ) continue;
1836 if ( theDimension == SMESH::DIM_2D )
1838 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1839 while ( faceIt->more() )
1841 const SMDS_MeshElement* face = faceIt->next();
1842 int aNbNode = face->NbNodes();
1844 aNbNode /= 2; // do not take into account additional middle nodes
1846 SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
1847 for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
1849 SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
1850 if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
1852 listOfElemType.push_back( SMDSAbs_Edge );
1853 connectivity.push_back
1854 ( mapNode2LocalID.insert( make_pair( node1, ++nbConnNodes)).first );
1855 connectivity.push_back
1856 ( mapNode2LocalID.insert( make_pair( node2, ++nbConnNodes)).first );
1862 else if ( theDimension == SMESH::DIM_1D )
1864 SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
1865 while ( nodeIt->more() )
1867 listOfElemType.push_back( SMDSAbs_Node );
1868 connectivity.push_back
1869 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1871 // add corner nodes by first vertex from edge
1872 SMESH_subMeshIteratorPtr edgeSmIt =
1873 sm->getDependsOnIterator(/*includeSelf*/false,
1874 /*complexShapeFirst*/false);
1875 while ( edgeSmIt->more() )
1877 SMESH_subMesh* vertexSM = edgeSmIt->next();
1878 // check that vertex is not already treated
1879 if ( !setOfVSubMesh.insert( vertexSM ).second )
1881 if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
1884 const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
1885 SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
1886 while ( nodeIt->more() )
1888 listOfElemType.push_back( SMDSAbs_Node );
1889 connectivity.push_back
1890 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1896 // fill node coords and assign local ids to the nodes
1897 int nbNodes = mapNode2LocalID.size();
1898 result->nodesXYZ.length( nbNodes );
1899 TNodeLocalID node2ID = mapNode2LocalID.begin();
1900 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1901 node2ID->second = i;
1902 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1903 result->nodesXYZ[i].x = node->X();
1904 result->nodesXYZ[i].y = node->Y();
1905 result->nodesXYZ[i].z = node->Z();
1907 // fill connectivity
1908 result->elementConnectivities.length( nbConnNodes );
1909 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1910 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1911 result->elementConnectivities[i] = (*connIt)->second;
1914 // fill element types
1915 result->elementTypes.length( listOfElemType.size() );
1916 std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
1917 std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
1918 for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
1920 SMDSAbs_ElementType elemType = *typeIt;
1921 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
1922 result->elementTypes[i].isPoly = false;
1923 result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
1926 // correct number of shapes
1927 theShapesId.length( mapOfShIdNb.size() );
1931 catch ( std::bad_alloc ) {
1932 INFOS( "Precompute(): lack of memory" );
1934 catch ( SALOME_Exception& S_ex ) {
1935 INFOS( "Precompute(): catch exception "<< S_ex.what() );
1938 INFOS( "Precompute(): unknown exception " );
1940 return result._retn();
1944 //=============================================================================
1946 * SMESH_Gen_i::Evaluate
1948 * Evaluate mesh on a shape
1950 //=============================================================================
1952 SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
1953 GEOM::GEOM_Object_ptr theShapeObject)
1954 // SMESH::long_array& theNbElems)
1955 throw ( SALOME::SALOME_Exception )
1957 Unexpect aCatch(SALOME_SalomeException);
1958 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
1960 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1961 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1962 SALOME::BAD_PARAM );
1964 if ( CORBA::is_nil( theMesh ) )
1965 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1966 SALOME::BAD_PARAM );
1968 SMESH::long_array_var nbels = new SMESH::long_array;
1969 nbels->length(SMESH::Entity_Last);
1970 int i = SMESH::Entity_Node;
1971 for (; i < SMESH::Entity_Last; i++)
1974 // Update Python script
1975 TPythonDump() << "theNbElems = " << this << ".Evaluate( "
1976 << theMesh << ", " << theShapeObject << ")";
1980 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1981 ASSERT( meshServant );
1982 if ( meshServant ) {
1983 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1984 meshServant->CheckGeomGroupModif();
1985 // get local TopoDS_Shape
1986 TopoDS_Shape myLocShape;
1987 if(theMesh->HasShapeToMesh())
1988 myLocShape = GeomObjectToShape( theShapeObject );
1990 myLocShape = SMESH_Mesh::PseudoShape();
1991 // call implementation compute
1992 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1993 MapShapeNbElems aResMap;
1994 /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
1995 MapShapeNbElemsItr anIt = aResMap.begin();
1996 for(; anIt!=aResMap.end(); anIt++) {
1997 const vector<int>& aVec = (*anIt).second;
1998 for(i = SMESH::Entity_Node; i < aVec.size(); i++) {
1999 int nbElem = aVec[i];
2000 if ( nbElem < 0 ) // algo failed, check that it has reported a message
2002 SMESH_subMesh* sm = anIt->first;
2003 SMESH_ComputeErrorPtr& error = sm->GetComputeError();
2004 const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
2005 if ( (algo && !error.get()) || error->IsOK() )
2006 error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
2010 nbels[i] += aVec[i];
2014 return nbels._retn();
2017 catch ( std::bad_alloc ) {
2018 INFOS( "Evaluate(): lack of memory" );
2020 catch ( SALOME_Exception& S_ex ) {
2021 INFOS( "Evaluate(): catch exception "<< S_ex.what() );
2024 INFOS( "Evaluate(): unknown exception " );
2027 return nbels._retn();
2030 //================================================================================
2032 * \brief Return geometrical object the given element is built on
2033 * \param theMesh - the mesh the element is in
2034 * \param theElementID - the element ID
2035 * \param theGeomName - the name of the result geom object if it is not yet published
2036 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object (no need to UnRegister())
2038 //================================================================================
2040 GEOM::GEOM_Object_ptr
2041 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2042 CORBA::Long theElementID,
2043 const char* theGeomName)
2044 throw ( SALOME::SALOME_Exception )
2046 Unexpect aCatch(SALOME_SalomeException);
2048 GEOM::GEOM_Object_wrap geom = FindGeometryByMeshElement(theMesh, theElementID);
2049 if ( !geom->_is_nil() ) {
2050 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2051 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2053 // try to find the corresponding SObject
2054 SALOMEDS::SObject_wrap SObj = ObjectToSObject( myCurrentStudy, geom.in() );
2055 if ( SObj->_is_nil() ) // submesh can be not found even if published
2057 // try to find published submesh
2058 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
2059 if ( !geom->IsMainShape() && list->length() == 1 ) {
2060 SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2061 SALOMEDS::ChildIterator_wrap it;
2062 if ( !mainSO->_is_nil() ) {
2063 it = myCurrentStudy->NewChildIterator( mainSO );
2065 if ( !it->_is_nil() ) {
2066 for ( it->InitEx(true); it->More(); it->Next() ) {
2067 SALOMEDS::SObject_wrap so = it->Value();
2068 CORBA::Object_var obj = SObjectToObject( so );
2069 GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
2070 if ( !subGeom->_is_nil() ) {
2071 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2072 if ( subList->length() == 1 && list[0] == subList[0] ) {
2082 if ( SObj->_is_nil() ) // publish a new subshape
2083 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
2085 // return only published geometry
2086 if ( !SObj->_is_nil() ) {
2087 //return geom._retn(); -- servant of geom must be UnRegister()ed;
2088 CORBA::Object_var obj = SObjectToObject( SObj );
2089 GEOM::GEOM_Object_var go = GEOM::GEOM_Object::_narrow( obj );
2093 return GEOM::GEOM_Object::_nil();
2096 //================================================================================
2098 * \brief Return geometrical object the given element is built on.
2099 * \param theMesh - the mesh the element is in
2100 * \param theElementID - the element ID
2101 * \retval GEOM::GEOM_Object_ptr - the found or created (UnRegister()!) geom object
2103 //================================================================================
2105 GEOM::GEOM_Object_ptr
2106 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2107 CORBA::Long theElementID)
2108 throw ( SALOME::SALOME_Exception )
2110 Unexpect aCatch(SALOME_SalomeException);
2111 if ( CORBA::is_nil( theMesh ) )
2112 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
2114 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2115 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2117 // get a core mesh DS
2118 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
2119 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
2121 ::SMESH_Mesh & mesh = meshServant->GetImpl();
2122 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
2123 // find the element in mesh
2124 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
2125 // find a shape id by the element
2126 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
2127 // get a geom object by the shape id
2128 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
2129 if ( geom->_is_nil() ) {
2130 // try to find a published sub-shape
2131 SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2132 SALOMEDS::ChildIterator_wrap it;
2133 if ( !mainSO->_is_nil() ) {
2134 it = myCurrentStudy->NewChildIterator( mainSO );
2136 if ( !it->_is_nil() ) {
2137 for ( it->InitEx(true); it->More(); it->Next() ) {
2138 SALOMEDS::SObject_wrap so = it->Value();
2139 CORBA::Object_var obj = SObjectToObject( so );
2140 GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
2141 if ( !subGeom->_is_nil() ) {
2142 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2143 if ( subList->length() == 1 && shapeID == subList[0] ) {
2151 if ( geom->_is_nil() ) {
2153 GEOM::GEOM_IShapesOperations_wrap op =
2154 geomGen->GetIShapesOperations( GetCurrentStudyID() );
2155 if ( !op->_is_nil() )
2156 geom = op->GetSubShape( mainShape, shapeID );
2161 if ( !geom->_is_nil() ) {
2162 GeomObjectToShape( geom ); // let geom client remember the found shape
2163 return geom._retn();
2168 return GEOM::GEOM_Object::_nil();
2171 //================================================================================
2173 * SMESH_Gen_i::Concatenate
2175 * Concatenate the given meshes into one mesh
2177 //================================================================================
2179 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
2180 CORBA::Boolean theUniteIdenticalGroups,
2181 CORBA::Boolean theMergeNodesAndElements,
2182 CORBA::Double theMergeTolerance)
2183 throw ( SALOME::SALOME_Exception )
2185 return ConcatenateCommon(theMeshesArray,
2186 theUniteIdenticalGroups,
2187 theMergeNodesAndElements,
2192 //================================================================================
2194 * SMESH_Gen_i::ConcatenateWithGroups
2196 * Concatenate the given meshes into one mesh
2197 * Create the groups of all elements from initial meshes
2199 //================================================================================
2201 SMESH::SMESH_Mesh_ptr
2202 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
2203 CORBA::Boolean theUniteIdenticalGroups,
2204 CORBA::Boolean theMergeNodesAndElements,
2205 CORBA::Double theMergeTolerance)
2206 throw ( SALOME::SALOME_Exception )
2208 return ConcatenateCommon(theMeshesArray,
2209 theUniteIdenticalGroups,
2210 theMergeNodesAndElements,
2215 //================================================================================
2217 * SMESH_Gen_i::ConcatenateCommon
2219 * Concatenate the given meshes into one mesh
2221 //================================================================================
2223 SMESH::SMESH_Mesh_ptr
2224 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
2225 CORBA::Boolean theUniteIdenticalGroups,
2226 CORBA::Boolean theMergeNodesAndElements,
2227 CORBA::Double theMergeTolerance,
2228 CORBA::Boolean theCommonGroups)
2229 throw ( SALOME::SALOME_Exception )
2231 typedef map<int, int> TIDsMap;
2232 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
2233 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
2234 typedef std::set<SMESHDS_GroupBase*> TGroups;
2236 TPythonDump* pPythonDump = new TPythonDump;
2237 TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
2240 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
2242 SMESHDS_Mesh* aNewMeshDS = 0;
2243 if ( !aNewMesh->_is_nil() ) {
2244 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
2246 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
2247 aNewMeshDS = aLocMesh.GetMeshDS();
2249 TGroupsMap aGroupsMap;
2250 TListOfNewGroups aListOfNewGroups;
2251 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
2252 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
2255 for ( int i = 0; i < theMeshesArray.length(); i++) {
2256 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
2257 if ( !anInitMesh->_is_nil() ) {
2258 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
2260 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
2261 aInitLocMesh.Load();
2262 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
2267 // loop on elements of mesh
2268 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
2269 const SMDS_MeshElement* anElem = 0;
2270 const SMDS_MeshElement* aNewElem = 0;
2271 int anElemNbNodes = 0;
2276 int anNbVolumes = 0;
2279 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
2280 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
2281 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
2282 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
2283 SMESH::long_array_var anIDsBalls = new SMESH::long_array();
2285 if( theCommonGroups ) {
2286 anIDsNodes->length( anInitMeshDS->NbNodes() );
2287 anIDsEdges->length( anInitMeshDS->NbEdges() );
2288 anIDsFaces->length( anInitMeshDS->NbFaces() );
2289 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
2290 anIDsBalls->length( anInitMeshDS->NbBalls() );
2293 for ( int j = 0; itElems->more(); j++) {
2294 anElem = itElems->next();
2295 SMDSAbs_ElementType anElemType = anElem->GetType();
2296 anElemNbNodes = anElem->NbNodes();
2297 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
2299 // loop on nodes of element
2300 const SMDS_MeshNode* aNode = 0;
2301 const SMDS_MeshNode* aNewNode = 0;
2302 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
2304 for ( int k = 0; itNodes->more(); k++) {
2305 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
2306 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
2307 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2308 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2309 if( theCommonGroups )
2310 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2313 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
2314 aNodesArray[k] = aNewNode;
2317 // creates a corresponding element on existent nodes in new mesh
2318 switch ( anElem->GetEntityType() ) {
2319 case SMDSEntity_Polyhedra:
2320 if ( const SMDS_VtkVolume* aVolume =
2321 dynamic_cast<const SMDS_VtkVolume*> (anElem))
2323 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
2324 aVolume->GetQuantities());
2325 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2326 if( theCommonGroups )
2327 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2330 case SMDSEntity_Ball:
2331 if ( const SMDS_BallElement* aBall =
2332 dynamic_cast<const SMDS_BallElement*> (anElem))
2334 aNewElem = aNewEditor.AddElement(aNodesArray, SMDSAbs_Ball,
2335 /*isPoly=*/false, /*id=*/0,
2336 aBall->GetDiameter() );
2337 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2338 if( theCommonGroups )
2339 anIDsBalls[aNbBalls++] = aNewElem->GetID();
2344 aNewElem = aNewEditor.AddElement(aNodesArray,
2347 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2348 if( theCommonGroups ) {
2349 if( anElemType == SMDSAbs_Edge )
2350 anIDsEdges[anNbEdges++] = aNewElem->GetID();
2351 else if( anElemType == SMDSAbs_Face )
2352 anIDsFaces[anNbFaces++] = aNewElem->GetID();
2353 else if( anElemType == SMDSAbs_Volume )
2354 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2360 // copy orphan nodes
2361 SMDS_NodeIteratorPtr itNodes = anInitMeshDS->nodesIterator();
2362 while ( itNodes->more() )
2364 const SMDS_MeshNode* aNode = itNodes->next();
2365 if ( aNode->NbInverseElements() == 0 )
2367 const SMDS_MeshNode* aNewNode =
2368 aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2369 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2370 if( theCommonGroups )
2371 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2376 aListOfGroups = anInitImpl->GetGroups();
2377 SMESH::SMESH_GroupBase_ptr aGroup;
2379 // loop on groups of mesh
2380 SMESH::long_array_var anInitIDs = new SMESH::long_array();
2381 SMESH::long_array_var anNewIDs = new SMESH::long_array();
2382 SMESH::SMESH_Group_var aNewGroup;
2384 SMESH::ElementType aGroupType;
2385 CORBA::String_var aGroupName;
2386 if ( theCommonGroups ) {
2387 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::BALL;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
2389 SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
2391 str += aMeshSObj->GetName();
2396 switch(aGroupType) {
2399 anIDsNodes->length(anNbNodes);
2404 anIDsEdges->length(anNbEdges);
2409 anIDsFaces->length(anNbFaces);
2414 anIDsVolumes->length(anNbVolumes);
2415 anLen = anNbVolumes;
2419 anIDsBalls->length(aNbBalls);
2427 aGroupName = str.c_str();
2429 // add a new group in the mesh
2430 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2432 switch(aGroupType) {
2434 aNewGroup->Add( anIDsNodes );
2437 aNewGroup->Add( anIDsEdges );
2440 aNewGroup->Add( anIDsFaces );
2443 aNewGroup->Add( anIDsVolumes );
2446 aNewGroup->Add( anIDsBalls );
2452 aListOfNewGroups.clear();
2453 aListOfNewGroups.push_back(aNewGroup);
2454 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2459 // check that current group name and type don't have identical ones in union mesh
2460 for (int iG = 0; iG < aListOfGroups->length(); iG++) {
2461 aGroup = aListOfGroups[iG];
2462 aListOfNewGroups.clear();
2463 aGroupType = aGroup->GetType();
2464 aGroupName = aGroup->GetName();
2466 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
2468 // convert a list of IDs
2469 anInitIDs = aGroup->GetListOfID();
2470 anNewIDs->length(anInitIDs->length());
2471 if ( aGroupType == SMESH::NODE )
2472 for (int j = 0; j < anInitIDs->length(); j++) {
2473 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
2476 for (int j = 0; j < anInitIDs->length(); j++) {
2477 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
2480 // check that current group name and type don't have identical ones in union mesh
2481 if ( anIter == aGroupsMap.end() ) {
2482 // add a new group in the mesh
2483 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2484 // add elements into new group
2485 aNewGroup->Add( anNewIDs );
2487 aListOfNewGroups.push_back(aNewGroup);
2488 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2491 else if ( theUniteIdenticalGroups ) {
2492 // unite identical groups
2493 TListOfNewGroups& aNewGroups = anIter->second;
2494 aNewGroups.front()->Add( anNewIDs );
2498 // rename identical groups
2499 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2500 aNewGroup->Add( anNewIDs );
2502 TListOfNewGroups& aNewGroups = anIter->second;
2503 string aNewGroupName;
2504 if (aNewGroups.size() == 1) {
2505 aNewGroupName = string(aGroupName) + "_1";
2506 aNewGroups.front()->SetName(aNewGroupName.c_str());
2508 char aGroupNum[128];
2509 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
2510 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
2511 aNewGroup->SetName(aNewGroupName.c_str());
2512 aNewGroups.push_back(aNewGroup);
2519 if (theMergeNodesAndElements) {
2521 TIDSortedNodeSet aMeshNodes; // no input nodes
2522 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
2523 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
2524 aNewEditor.MergeNodes( aGroupsOfNodes );
2526 aNewEditor.MergeEqualElements();
2531 // Update Python script
2532 aPythonDump << aNewMesh << " = " << this;
2533 if( !theCommonGroups )
2534 aPythonDump << ".Concatenate(";
2536 aPythonDump << ".ConcatenateWithGroups(";
2538 for ( int i = 0; i < theMeshesArray.length(); i++) {
2539 if (i > 0) aPythonDump << ", ";
2540 aPythonDump << theMeshesArray[i];
2542 aPythonDump << "], ";
2543 aPythonDump << theUniteIdenticalGroups << ", "
2544 << theMergeNodesAndElements << ", "
2545 << TVar( theMergeTolerance ) << ")";
2547 delete pPythonDump; // enable python dump from GetGroups()
2549 // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
2550 if ( !aNewMesh->_is_nil() )
2552 SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
2555 // IPAL21468 Change icon of compound because it need not be computed.
2556 SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
2557 SetPixMap( aMeshSObj, "ICON_SMESH_TREE_MESH" );
2560 aNewMeshDS->Modified();
2561 return aNewMesh._retn();
2564 //================================================================================
2566 * \brief Create a mesh by copying a part of another mesh
2567 * \param meshPart - a part of mesh to copy
2568 * \param toCopyGroups - to create in the new mesh groups
2569 * the copied elements belongs to
2570 * \param toKeepIDs - to preserve IDs of the copied elements or not
2571 * \retval SMESH::SMESH_Mesh_ptr - the new mesh
2573 //================================================================================
2575 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
2576 const char* meshName,
2577 CORBA::Boolean toCopyGroups,
2578 CORBA::Boolean toKeepIDs)
2580 Unexpect aCatch(SALOME_SalomeException);
2582 TPythonDump* pyDump = new TPythonDump; // prevent dump from CreateMesh()
2584 // 1. Get source mesh
2586 if ( CORBA::is_nil( meshPart ))
2587 THROW_SALOME_CORBA_EXCEPTION( "bad IDSource", SALOME::BAD_PARAM );
2589 SMESH::SMESH_Mesh_var srcMesh = meshPart->GetMesh();
2590 SMESH_Mesh_i* srcMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( srcMesh );
2592 THROW_SALOME_CORBA_EXCEPTION( "bad mesh of IDSource", SALOME::BAD_PARAM );
2594 SMESHDS_Mesh* srcMeshDS = srcMesh_i->GetImpl().GetMeshDS();
2596 // 2. Make a new mesh
2598 SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil());
2599 SMESH_Mesh_i* newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( newMesh );
2601 THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR );
2602 SALOMEDS::SObject_wrap meshSO = ObjectToSObject(myCurrentStudy, newMesh );
2603 if ( !meshSO->_is_nil() )
2605 SetName( meshSO, meshName, "Mesh" );
2606 SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
2608 SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
2609 ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
2611 // 3. Get elements to copy
2613 SMDS_ElemIteratorPtr srcElemIt; SMDS_NodeIteratorPtr srcNodeIt;
2614 TIDSortedElemSet srcElems;
2615 SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes();
2616 if ( SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
2618 srcElemIt = srcMeshDS->elementsIterator();
2619 srcNodeIt = srcMeshDS->nodesIterator();
2623 SMESH::long_array_var ids = meshPart->GetIDs();
2624 if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes
2626 for (int i=0; i < ids->length(); i++)
2627 if ( const SMDS_MeshElement * elem = srcMeshDS->FindNode( ids[i] ))
2628 srcElems.insert( elem );
2632 for (int i=0; i < ids->length(); i++)
2633 if ( const SMDS_MeshElement * elem = srcMeshDS->FindElement( ids[i] ))
2634 srcElems.insert( elem );
2636 if ( srcElems.empty() )
2637 return newMesh._retn();
2639 typedef SMDS_SetIterator< SMDS_pElement, TIDSortedElemSet::const_iterator > ElIter;
2640 srcElemIt = SMDS_ElemIteratorPtr( new ElIter( srcElems.begin(), srcElems.end() ));
2645 typedef map<SMDS_pElement, SMDS_pElement, TIDCompare> TE2EMap;
2646 TE2EMap e2eMapByType[ SMDSAbs_NbElementTypes ];
2647 TE2EMap& n2nMap = e2eMapByType[ SMDSAbs_Node ];
2649 const SMDS_MeshNode *nSrc, *nTgt;
2650 vector< const SMDS_MeshNode* > nodes;
2651 while ( srcElemIt->more() )
2653 const SMDS_MeshElement * elem = srcElemIt->next();
2655 nodes.resize( elem->NbNodes());
2656 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2658 for ( iN = 0; nIt->more(); ++iN )
2660 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2661 nTgt = newMeshDS->FindNode( nSrc->GetID());
2663 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2668 for ( iN = 0; nIt->more(); ++iN )
2670 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2671 TE2EMap::iterator n2n = n2nMap.insert( make_pair( nSrc, SMDS_pNode(0) )).first;
2673 n2n->second = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2674 nodes[ iN ] = (const SMDS_MeshNode*) n2n->second;
2678 if ( elem->GetType() != SMDSAbs_Node )
2680 int ID = toKeepIDs ? elem->GetID() : 0;
2681 const SMDS_MeshElement * newElem;
2682 switch ( elem->GetEntityType() ) {
2683 case SMDSEntity_Polyhedra:
2684 newElem = editor.GetMeshDS()->
2685 AddPolyhedralVolumeWithID( nodes,
2686 static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
2689 case SMDSEntity_Ball:
2690 newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID,
2691 static_cast<const SMDS_BallElement*>(elem)->GetDiameter());
2694 newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID);
2696 if ( toCopyGroups && !toKeepIDs )
2697 e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem ));
2700 } // while ( srcElemIt->more() )
2702 // 4(b). Copy free nodes
2704 if ( srcNodeIt && srcMeshDS->NbNodes() != newMeshDS->NbNodes() )
2706 while ( srcNodeIt->more() )
2708 nSrc = srcNodeIt->next();
2709 if ( nSrc->NbInverseElements() == 0 )
2712 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2714 n2nMap[ nSrc ] = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2721 int nbNewGroups = 0;
2724 SMESH_Mesh::GroupIteratorPtr gIt = srcMesh_i->GetImpl().GetGroups();
2725 while ( gIt->more() )
2727 SMESH_Group* group = gIt->next();
2728 const SMESHDS_GroupBase* groupDS = group->GetGroupDS();
2730 // Check group type. We copy nodal groups containing nodes of copied element
2731 SMDSAbs_ElementType groupType = groupDS->GetType();
2732 if ( groupType != SMDSAbs_Node &&
2733 newMeshDS->GetMeshInfo().NbElements( groupType ) == 0 )
2734 continue; // group type differs from types of meshPart
2736 // Find copied elements in the group
2737 vector< const SMDS_MeshElement* > groupElems;
2738 SMDS_ElemIteratorPtr eIt = groupDS->GetElements();
2741 const SMDS_MeshElement* foundElem;
2742 if ( groupType == SMDSAbs_Node )
2744 while ( eIt->more() )
2745 if (( foundElem = newMeshDS->FindNode( eIt->next()->GetID() )))
2746 groupElems.push_back( foundElem );
2750 while ( eIt->more() )
2751 if (( foundElem = newMeshDS->FindElement( eIt->next()->GetID() )))
2752 groupElems.push_back( foundElem );
2757 TE2EMap & e2eMap = e2eMapByType[ groupDS->GetType() ];
2758 if ( e2eMap.empty() ) continue;
2759 int minID = e2eMap.begin()->first->GetID();
2760 int maxID = e2eMap.rbegin()->first->GetID();
2761 TE2EMap::iterator e2e;
2762 while ( eIt->more() && groupElems.size() < e2eMap.size())
2764 const SMDS_MeshElement* e = eIt->next();
2765 if ( e->GetID() < minID || e->GetID() > maxID ) continue;
2766 if ((e2e = e2eMap.find( e )) != e2eMap.end())
2767 groupElems.push_back( e2e->second );
2771 if ( !groupElems.empty() )
2773 SMESH::SMESH_Group_var newGroupObj =
2774 newMesh->CreateGroup( SMESH::ElementType(groupType), group->GetName() );
2775 if ( SMESH_GroupBase_i* newGroup_i = SMESH::DownCast<SMESH_GroupBase_i*>( newGroupObj))
2777 SMESHDS_GroupBase * newGroupDS = newGroup_i->GetGroupDS();
2778 SMDS_MeshGroup& smdsGroup = ((SMESHDS_Group*)newGroupDS)->SMDSGroup();
2779 for ( unsigned i = 0; i < groupElems.size(); ++i )
2780 smdsGroup.Add( groupElems[i] );
2788 newMeshDS->Modified();
2790 *pyDump << newMesh << " = " << this
2791 << ".CopyMesh( " << meshPart << ", "
2792 << "'" << meshName << "', "
2793 << toCopyGroups << ", "
2794 << toKeepIDs << ")";
2796 delete pyDump; pyDump = 0; // allow dump in GetGroups()
2798 if ( nbNewGroups > 0 ) // dump created groups
2799 SMESH::ListOfGroups_var groups = newMesh->GetGroups();
2801 return newMesh._retn();
2804 //================================================================================
2806 * SMESH_Gen_i::GetMEDVersion
2808 * Get MED version of the file by its name
2810 //================================================================================
2811 CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
2812 SMESH::MED_VERSION& theVersion)
2814 theVersion = SMESH::MED_V2_1;
2815 MED::EVersion aVersion = MED::GetVersionId( theFileName );
2816 switch( aVersion ) {
2817 case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
2818 case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
2819 case MED::eVUnknown : return false;
2824 //================================================================================
2826 * SMESH_Gen_i::GetMeshNames
2828 * Get names of meshes defined in file with the specified name
2830 //================================================================================
2831 SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
2833 SMESH::string_array_var aResult = new SMESH::string_array();
2834 MED::PWrapper aMed = MED::CrWrapper( theFileName );
2836 MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
2838 aResult->length( aNbMeshes );
2839 for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
2840 MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
2841 aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
2844 return aResult._retn();
2847 //=============================================================================
2851 * Save SMESH module's data
2853 //=============================================================================
2854 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
2858 INFOS( "SMESH_Gen_i::Save" );
2860 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
2861 // san -- in case <myCurrentStudy> differs from theComponent's study,
2862 // use that of the component
2863 if ( myCurrentStudy->_is_nil() ||
2864 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2865 SetCurrentStudy( theComponent->GetStudy() );
2867 // Store study contents as a set of python commands
2868 SavePython(myCurrentStudy);
2870 StudyContext* myStudyContext = GetCurrentStudyContext();
2872 // Declare a byte stream
2873 SALOMEDS::TMPFile_var aStreamFile;
2875 // Obtain a temporary dir
2876 TCollection_AsciiString tmpDir =
2877 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2879 // Create a sequence of files processed
2880 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2881 aFileSeq->length( NUM_TMP_FILES );
2883 TCollection_AsciiString aStudyName( "" );
2885 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2887 // Set names of temporary files
2888 TCollection_AsciiString filename =
2889 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
2890 TCollection_AsciiString meshfile =
2891 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
2892 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
2893 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
2894 filename = tmpDir + filename;
2895 meshfile = tmpDir + meshfile;
2898 HDFdataset* aDataset;
2899 HDFgroup* aTopGroup;
2901 HDFgroup* aSubGroup;
2902 HDFgroup* aSubSubGroup;
2903 hdf_size aSize[ 1 ];
2906 //Remove the files if they exist: BugID: 11225
2907 #ifndef WNT /* unix functionality */
2908 TCollection_AsciiString cmd("rm -f \"");
2910 TCollection_AsciiString cmd("del /F \"");
2917 system(cmd.ToCString());
2919 // MED writer to be used by storage process
2920 DriverMED_W_SMESHDS_Mesh myWriter;
2921 myWriter.SetFile( meshfile.ToCString() );
2924 // SetStoreName() to groups before storing hypotheses to let them refer to
2925 // groups using "store name", which is "Group <group_persistent_id>"
2927 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
2928 for ( ; itBig->More(); itBig->Next() ) {
2929 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
2930 if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
2931 CORBA::Object_var anObject = SObjectToObject( gotBranch );
2932 if ( !CORBA::is_nil( anObject ) ) {
2933 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
2934 if ( !myMesh->_is_nil() ) {
2935 myMesh->Load(); // load from study file if not yet done
2936 TPythonDump pd; // not to dump GetGroups()
2937 SMESH::ListOfGroups_var groups = myMesh->GetGroups();
2938 pd << ""; // to avoid optimizing pd out
2939 for ( int i = 0; i < groups->length(); ++i )
2941 SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
2944 CORBA::String_var objStr = GetORB()->object_to_string( grImpl->_this() );
2945 int anId = myStudyContext->findId( string( objStr.in() ) );
2947 sprintf( grpName, "Group %d", anId );
2948 SMESHDS_GroupBase* aGrpBaseDS = grImpl->GetGroupDS();
2949 aGrpBaseDS->SetStoreName( grpName );
2959 // ---> create HDF file
2960 aFile = new HDFfile( (char*) filename.ToCString() );
2961 aFile->CreateOnDisk();
2963 // --> iterator for top-level objects
2964 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
2965 for ( ; itBig->More(); itBig->Next() ) {
2966 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
2968 // --> hypotheses root branch (only one for the study)
2969 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
2970 // create hypotheses root HDF group
2971 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2972 aTopGroup->CreateOnDisk();
2974 // iterator for all hypotheses
2975 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
2976 for ( ; it->More(); it->Next() ) {
2977 SALOMEDS::SObject_wrap mySObject = it->Value();
2978 CORBA::Object_var anObject = SObjectToObject( mySObject );
2979 if ( !CORBA::is_nil( anObject ) ) {
2980 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2981 if ( !myHyp->_is_nil() ) {
2982 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2984 string hypname = string( myHyp->GetName() );
2985 string libname = string( myHyp->GetLibName() );
2987 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
2988 // WNT and ".so" for X-system) must be deleted
2989 int libname_len = libname.length();
2991 if( libname_len > 4 )
2992 libname.resize( libname_len - 4 );
2994 // PAL17753 (Regresion: missing hypothesis in restored study)
2995 // "lib" also should be removed from the beginning
2996 //if( libname_len > 3 )
2997 //libname.resize( libname_len - 3 );
2998 if( libname_len > 6 )
2999 libname = libname.substr( 3, libname_len - 3 - 3 );
3001 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3002 int id = myStudyContext->findId( string( objStr.in() ) );
3003 string hypdata = string( myImpl->SaveTo() );
3005 // for each hypothesis create HDF group basing on its id
3006 char hypGrpName[30];
3007 sprintf( hypGrpName, "Hypothesis %d", id );
3008 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3009 aGroup->CreateOnDisk();
3010 // --> type name of hypothesis
3011 aSize[ 0 ] = hypname.length() + 1;
3012 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3013 aDataset->CreateOnDisk();
3014 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3015 aDataset->CloseOnDisk();
3016 // --> server plugin library name of hypothesis
3017 aSize[ 0 ] = libname.length() + 1;
3018 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3019 aDataset->CreateOnDisk();
3020 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3021 aDataset->CloseOnDisk();
3022 // --> persistent data of hypothesis
3023 aSize[ 0 ] = hypdata.length() + 1;
3024 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3025 aDataset->CreateOnDisk();
3026 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3027 aDataset->CloseOnDisk();
3028 // close hypothesis HDF group
3029 aGroup->CloseOnDisk();
3034 // close hypotheses root HDF group
3035 aTopGroup->CloseOnDisk();
3037 // --> algorithms root branch (only one for the study)
3038 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
3039 // create algorithms root HDF group
3040 aTopGroup = new HDFgroup( "Algorithms", aFile );
3041 aTopGroup->CreateOnDisk();
3043 // iterator for all algorithms
3044 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
3045 for ( ; it->More(); it->Next() ) {
3046 SALOMEDS::SObject_wrap mySObject = it->Value();
3047 CORBA::Object_var anObject = SObjectToObject( mySObject );
3048 if ( !CORBA::is_nil( anObject ) ) {
3049 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
3050 if ( !myHyp->_is_nil() ) {
3051 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3053 string hypname = string( myHyp->GetName() );
3054 string libname = string( myHyp->GetLibName() );
3056 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
3057 // WNT and ".so" for X-system) must be deleted
3058 int libname_len = libname.length();
3060 if( libname_len > 4 )
3061 libname.resize( libname_len - 4 );
3063 // PAL17753 (Regresion: missing hypothesis in restored study)
3064 // "lib" also should be removed from the beginning
3065 //if( libname_len > 3 )
3066 //libname.resize( libname_len - 3 );
3067 if( libname_len > 6 )
3068 libname = libname.substr( 3, libname_len - 3 - 3 );
3070 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3071 int id = myStudyContext->findId( string( objStr.in() ) );
3072 string hypdata = string( myImpl->SaveTo() );
3074 // for each algorithm create HDF group basing on its id
3075 char hypGrpName[30];
3076 sprintf( hypGrpName, "Algorithm %d", id );
3077 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3078 aGroup->CreateOnDisk();
3079 // --> type name of algorithm
3080 aSize[0] = hypname.length() + 1;
3081 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3082 aDataset->CreateOnDisk();
3083 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3084 aDataset->CloseOnDisk();
3085 // --> server plugin library name of hypothesis
3086 aSize[0] = libname.length() + 1;
3087 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3088 aDataset->CreateOnDisk();
3089 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3090 aDataset->CloseOnDisk();
3091 // --> persistent data of algorithm
3092 aSize[0] = hypdata.length() + 1;
3093 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3094 aDataset->CreateOnDisk();
3095 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3096 aDataset->CloseOnDisk();
3097 // close algorithm HDF group
3098 aGroup->CloseOnDisk();
3103 // close algorithms root HDF group
3104 aTopGroup->CloseOnDisk();
3106 // --> mesh objects roots branches
3107 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
3108 CORBA::Object_var anObject = SObjectToObject( gotBranch );
3109 if ( !CORBA::is_nil( anObject ) ) {
3110 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
3111 if ( !myMesh->_is_nil() ) {
3112 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
3114 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3115 int id = myStudyContext->findId( string( objStr.in() ) );
3116 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
3117 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3118 bool hasShape = myLocMesh.HasShapeToMesh();
3120 // for each mesh open the HDF group basing on its id
3121 char meshGrpName[ 30 ];
3122 sprintf( meshGrpName, "Mesh %d", id );
3123 aTopGroup = new HDFgroup( meshGrpName, aFile );
3124 aTopGroup->CreateOnDisk();
3126 // --> put dataset to hdf file which is a flag that mesh has data
3127 string strHasData = "0";
3128 // check if the mesh is not empty
3129 if ( mySMESHDSMesh->NbNodes() > 0 ) {
3130 // write mesh data to med file
3131 myWriter.SetMesh( mySMESHDSMesh );
3132 myWriter.SetMeshId( id );
3135 aSize[ 0 ] = strHasData.length() + 1;
3136 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
3137 aDataset->CreateOnDisk();
3138 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
3139 aDataset->CloseOnDisk();
3142 // for each mesh open the HDF group basing on its auto color parameter
3143 char meshAutoColorName[ 30 ];
3144 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
3146 anAutoColor[0] = myImpl->GetAutoColor();
3148 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
3149 aDataset->CreateOnDisk();
3150 aDataset->WriteOnDisk( anAutoColor );
3151 aDataset->CloseOnDisk();
3153 // issue 0020693. Store _isModified flag
3154 int isModified = myLocMesh.GetIsModified();
3156 aDataset = new HDFdataset( "_isModified", aTopGroup, HDF_INT32, aSize, 1 );
3157 aDataset->CreateOnDisk();
3158 aDataset->WriteOnDisk( &isModified );
3159 aDataset->CloseOnDisk();
3161 // issue 20918. Store Persistent Id of SMESHDS_Mesh
3162 int meshPersistentId = mySMESHDSMesh->GetPersistentId();
3164 aDataset = new HDFdataset( "meshPersistentId", aTopGroup, HDF_INT32, aSize, 1 );
3165 aDataset->CreateOnDisk();
3166 aDataset->WriteOnDisk( &meshPersistentId );
3167 aDataset->CloseOnDisk();
3169 // write reference on a shape if exists
3170 SALOMEDS::SObject_wrap myRef;
3171 bool shapeRefFound = false;
3172 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef.inout() );
3174 SALOMEDS::SObject_wrap myShape;
3175 bool ok = myRef->ReferencedObject( myShape.inout() );
3177 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
3178 string myRefOnObject = myShape->GetID();
3179 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
3180 aSize[ 0 ] = myRefOnObject.length() + 1;
3181 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
3182 aDataset->CreateOnDisk();
3183 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3184 aDataset->CloseOnDisk();
3189 // write applied hypotheses if exist
3190 SALOMEDS::SObject_wrap myHypBranch;
3191 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() );
3192 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
3193 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
3195 if ( found && (shapeRefFound || !hasShape) ) {
3196 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3197 aGroup->CreateOnDisk();
3199 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myHypBranch );
3201 for ( ; it->More(); it->Next() ) {
3202 SALOMEDS::SObject_wrap mySObject = it->Value();
3203 SALOMEDS::SObject_wrap myRefOnHyp;
3204 bool ok = mySObject->ReferencedObject( myRefOnHyp.inout() );
3206 // san - it is impossible to recover applied hypotheses
3207 // using their entries within Load() method,
3208 // for there are no AttributeIORs in the study when Load() is working.
3209 // Hence, it is better to store persistent IDs of hypotheses as references to them
3211 //string myRefOnObject = myRefOnHyp->GetID();
3212 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3213 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3214 int id = myStudyContext->findId( string( objStr.in() ) );
3215 //if ( myRefOnObject.length() > 0 ) {
3216 //aSize[ 0 ] = myRefOnObject.length() + 1;
3217 char hypName[ 30 ], hypId[ 30 ];
3218 sprintf( hypName, "Hyp %d", ++hypNb );
3219 sprintf( hypId, "%d", id );
3220 aSize[ 0 ] = strlen( hypId ) + 1;
3221 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
3222 aDataset->CreateOnDisk();
3223 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3224 aDataset->WriteOnDisk( hypId );
3225 aDataset->CloseOnDisk();
3229 aGroup->CloseOnDisk();
3232 // write applied algorithms if exist
3233 SALOMEDS::SObject_wrap myAlgoBranch;
3234 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
3235 myAlgoBranch.inout() );
3236 if ( found && !shapeRefFound && hasShape) { // remove applied algos
3237 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
3239 if ( found && (shapeRefFound || !hasShape)) {
3240 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3241 aGroup->CreateOnDisk();
3243 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myAlgoBranch );
3245 for ( ; it->More(); it->Next() ) {
3246 SALOMEDS::SObject_wrap mySObject = it->Value();
3247 SALOMEDS::SObject_wrap myRefOnAlgo;
3248 bool ok = mySObject->ReferencedObject( myRefOnAlgo.inout() );
3250 // san - it is impossible to recover applied algorithms
3251 // using their entries within Load() method,
3252 // for there are no AttributeIORs in the study when Load() is working.
3253 // Hence, it is better to store persistent IDs of algorithms as references to them
3255 //string myRefOnObject = myRefOnAlgo->GetID();
3256 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3257 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3258 int id = myStudyContext->findId( string( objStr.in() ) );
3259 //if ( myRefOnObject.length() > 0 ) {
3260 //aSize[ 0 ] = myRefOnObject.length() + 1;
3261 char algoName[ 30 ], algoId[ 30 ];
3262 sprintf( algoName, "Algo %d", ++algoNb );
3263 sprintf( algoId, "%d", id );
3264 aSize[ 0 ] = strlen( algoId ) + 1;
3265 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
3266 aDataset->CreateOnDisk();
3267 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3268 aDataset->WriteOnDisk( algoId );
3269 aDataset->CloseOnDisk();
3273 aGroup->CloseOnDisk();
3276 // --> submesh objects sub-branches
3278 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
3279 SALOMEDS::SObject_wrap mySubmeshBranch;
3280 found = gotBranch->FindSubObject( i, mySubmeshBranch.inout() );
3282 if ( found ) // check if there is shape reference in submeshes
3284 bool hasShapeRef = false;
3285 SALOMEDS::ChildIterator_wrap itSM =
3286 myCurrentStudy->NewChildIterator( mySubmeshBranch );
3287 for ( ; itSM->More(); itSM->Next() ) {
3288 SALOMEDS::SObject_wrap mySubRef, myShape, mySObject = itSM->Value();
3289 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
3290 mySubRef->ReferencedObject( myShape.inout() );
3291 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
3294 { // remove one submesh
3295 if ( shapeRefFound )
3296 { // unassign hypothesis
3297 SMESH::SMESH_subMesh_var mySubMesh =
3298 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
3299 if ( !mySubMesh->_is_nil() ) {
3300 int shapeID = mySubMesh->GetId();
3301 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
3302 const list<const SMESHDS_Hypothesis*>& hypList =
3303 mySMESHDSMesh->GetHypothesis( S );
3304 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
3305 while ( hyp != hypList.end() ) {
3306 int hypID = (*hyp++)->GetID(); // goto next hyp here because
3307 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
3311 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
3313 } // loop on submeshes of a type
3314 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
3315 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
3318 } // end check if there is shape reference in submeshes
3320 char name_meshgroup[ 30 ];
3321 if ( i == GetSubMeshOnVertexTag() )
3322 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3323 else if ( i == GetSubMeshOnEdgeTag() )
3324 strcpy( name_meshgroup, "SubMeshes On Edge" );
3325 else if ( i == GetSubMeshOnWireTag() )
3326 strcpy( name_meshgroup, "SubMeshes On Wire" );
3327 else if ( i == GetSubMeshOnFaceTag() )
3328 strcpy( name_meshgroup, "SubMeshes On Face" );
3329 else if ( i == GetSubMeshOnShellTag() )
3330 strcpy( name_meshgroup, "SubMeshes On Shell" );
3331 else if ( i == GetSubMeshOnSolidTag() )
3332 strcpy( name_meshgroup, "SubMeshes On Solid" );
3333 else if ( i == GetSubMeshOnCompoundTag() )
3334 strcpy( name_meshgroup, "SubMeshes On Compound" );
3336 // for each type of submeshes create container HDF group
3337 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3338 aGroup->CreateOnDisk();
3340 // iterator for all submeshes of given type
3341 SALOMEDS::ChildIterator_wrap itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
3342 for ( ; itSM->More(); itSM->Next() ) {
3343 SALOMEDS::SObject_wrap mySObject = itSM->Value();
3344 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
3345 if ( !CORBA::is_nil( anSubObject ))
3347 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
3348 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
3349 int subid = myStudyContext->findId( string( objStr.in() ) );
3351 // for each mesh open the HDF group basing on its id
3352 char submeshGrpName[ 30 ];
3353 sprintf( submeshGrpName, "SubMesh %d", subid );
3354 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
3355 aSubGroup->CreateOnDisk();
3357 // write reference on a shape, already checked if it exists
3358 SALOMEDS::SObject_wrap mySubRef, myShape;
3359 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
3360 mySubRef->ReferencedObject( myShape.inout() );
3361 string myRefOnObject = myShape->GetID();
3362 if ( myRefOnObject.length() > 0 ) {
3363 aSize[ 0 ] = myRefOnObject.length() + 1;
3364 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
3365 aDataset->CreateOnDisk();
3366 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3367 aDataset->CloseOnDisk();
3370 // write applied hypotheses if exist
3371 SALOMEDS::SObject_wrap mySubHypBranch;
3372 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(),
3373 mySubHypBranch.inout() );
3375 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3376 aSubSubGroup->CreateOnDisk();
3378 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( mySubHypBranch );
3380 for ( ; it->More(); it->Next() ) {
3381 SALOMEDS::SObject_wrap mySubSObject = it->Value();
3382 SALOMEDS::SObject_wrap myRefOnHyp;
3383 bool ok = mySubSObject->ReferencedObject( myRefOnHyp.inout() );
3385 //string myRefOnObject = myRefOnHyp->GetID();
3386 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3387 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3388 int id = myStudyContext->findId( string( objStr.in() ) );
3389 //if ( myRefOnObject.length() > 0 ) {
3390 //aSize[ 0 ] = myRefOnObject.length() + 1;
3391 char hypName[ 30 ], hypId[ 30 ];
3392 sprintf( hypName, "Hyp %d", ++hypNb );
3393 sprintf( hypId, "%d", id );
3394 aSize[ 0 ] = strlen( hypId ) + 1;
3395 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
3396 aDataset->CreateOnDisk();
3397 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3398 aDataset->WriteOnDisk( hypId );
3399 aDataset->CloseOnDisk();
3403 aSubSubGroup->CloseOnDisk();
3406 // write applied algorithms if exist
3407 SALOMEDS::SObject_wrap mySubAlgoBranch;
3408 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
3409 mySubAlgoBranch.inout() );
3411 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3412 aSubSubGroup->CreateOnDisk();
3414 SALOMEDS::ChildIterator_wrap it =
3415 myCurrentStudy->NewChildIterator( mySubAlgoBranch );
3417 for ( ; it->More(); it->Next() ) {
3418 SALOMEDS::SObject_wrap mySubSObject = it->Value();
3419 SALOMEDS::SObject_wrap myRefOnAlgo;
3420 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo.inout() );
3422 //string myRefOnObject = myRefOnAlgo->GetID();
3423 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3424 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3425 int id = myStudyContext->findId( string( objStr.in() ) );
3426 //if ( myRefOnObject.length() > 0 ) {
3427 //aSize[ 0 ] = myRefOnObject.length() + 1;
3428 char algoName[ 30 ], algoId[ 30 ];
3429 sprintf( algoName, "Algo %d", ++algoNb );
3430 sprintf( algoId, "%d", id );
3431 aSize[ 0 ] = strlen( algoId ) + 1;
3432 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
3433 aDataset->CreateOnDisk();
3434 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3435 aDataset->WriteOnDisk( algoId );
3436 aDataset->CloseOnDisk();
3440 aSubSubGroup->CloseOnDisk();
3442 // close submesh HDF group
3443 aSubGroup->CloseOnDisk();
3446 // close container of submeshes by type HDF group
3447 aGroup->CloseOnDisk();
3450 // All sub-meshes will be stored in MED file
3451 // .. will NOT (PAL 12992)
3452 //if ( shapeRefFound )
3453 //myWriter.AddAllSubMeshes();
3455 // store submesh order if any
3456 const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
3457 if ( theOrderIds.size() ) {
3458 char order_list[ 30 ];
3459 strcpy( order_list, "Mesh Order" );
3460 // count number of submesh ids
3462 TListOfListOfInt::const_iterator idIt = theOrderIds.begin();
3463 for ( ; idIt != theOrderIds.end(); idIt++ )
3464 nbIDs += (*idIt).size();
3465 // number of values = number of IDs +
3466 // number of lists (for separators) - 1
3467 int* smIDs = new int [ nbIDs + theOrderIds.size() - 1 ];
3468 idIt = theOrderIds.begin();
3469 for ( int i = 0; idIt != theOrderIds.end(); idIt++ ) {
3470 const TListOfInt& idList = *idIt;
3471 if (idIt != theOrderIds.begin()) // not first list
3472 smIDs[ i++ ] = -1/* *idList.size()*/; // separator between lists
3473 // dump submesh ids from current list
3474 TListOfInt::const_iterator id_smId = idList.begin();
3475 for( ; id_smId != idList.end(); id_smId++ )
3476 smIDs[ i++ ] = *id_smId;
3479 aSize[ 0 ] = nbIDs + theOrderIds.size() - 1;
3481 aDataset = new HDFdataset( order_list, aTopGroup, HDF_INT32, aSize, 1 );
3482 aDataset->CreateOnDisk();
3483 aDataset->WriteOnDisk( smIDs );
3484 aDataset->CloseOnDisk();
3489 // groups root sub-branch
3490 SALOMEDS::SObject_wrap myGroupsBranch;
3491 for ( int i = GetNodeGroupsTag(); i <= GetBallElementsGroupsTag(); i++ ) {
3492 found = gotBranch->FindSubObject( i, myGroupsBranch.inout() );
3494 char name_group[ 30 ];
3495 if ( i == GetNodeGroupsTag() )
3496 strcpy( name_group, "Groups of Nodes" );
3497 else if ( i == GetEdgeGroupsTag() )
3498 strcpy( name_group, "Groups of Edges" );
3499 else if ( i == GetFaceGroupsTag() )
3500 strcpy( name_group, "Groups of Faces" );
3501 else if ( i == GetVolumeGroupsTag() )
3502 strcpy( name_group, "Groups of Volumes" );
3503 else if ( i == Get0DElementsGroupsTag() )
3504 strcpy( name_group, "Groups of 0D Elements" );
3505 else if ( i == GetBallElementsGroupsTag() )
3506 strcpy( name_group, "Groups of Balls" );
3508 aGroup = new HDFgroup( name_group, aTopGroup );
3509 aGroup->CreateOnDisk();
3511 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myGroupsBranch );
3512 for ( ; it->More(); it->Next() ) {
3513 SALOMEDS::SObject_wrap mySObject = it->Value();
3514 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
3515 if ( !CORBA::is_nil( aSubObject ) ) {
3516 SMESH_GroupBase_i* myGroupImpl =
3517 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
3520 SMESHDS_GroupBase* aGrpBaseDS = myGroupImpl->GetGroupDS();
3524 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
3525 int anId = myStudyContext->findId( string( objStr.in() ) );
3527 // For each group, create a dataset named "Group <group_persistent_id>"
3528 // and store the group's user name into it
3529 const char* grpName = aGrpBaseDS->GetStoreName();
3530 char* aUserName = myGroupImpl->GetName();
3531 aSize[ 0 ] = strlen( aUserName ) + 1;
3533 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
3534 aDataset->CreateOnDisk();
3535 aDataset->WriteOnDisk( aUserName );
3536 aDataset->CloseOnDisk();
3539 // For each group, create a dataset named "Group <group_persistent_id> Color"
3540 // and store the group's color into it
3541 char grpColorName[ 30 ];
3542 sprintf( grpColorName, "ColorGroup %d", anId );
3543 SALOMEDS::Color aColor = myGroupImpl->GetColor();
3545 anRGB[ 0 ] = aColor.R;
3546 anRGB[ 1 ] = aColor.G;
3547 anRGB[ 2 ] = aColor.B;
3549 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
3550 aDataset->CreateOnDisk();
3551 aDataset->WriteOnDisk( anRGB );
3552 aDataset->CloseOnDisk();
3554 // Pass SMESHDS_Group to MED writer
3555 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
3557 myWriter.AddGroup( aGrpDS );
3559 // write reference on a shape if exists
3560 SMESHDS_GroupOnGeom* aGeomGrp =
3561 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
3563 SALOMEDS::SObject_wrap mySubRef, myShape;
3564 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ) &&
3565 mySubRef->ReferencedObject( myShape.inout() ) &&
3566 !CORBA::is_nil( myShape->GetObject() ))
3568 string myRefOnObject = myShape->GetID();
3569 if ( myRefOnObject.length() > 0 ) {
3570 char aRefName[ 30 ];
3571 sprintf( aRefName, "Ref on shape %d", anId);
3572 aSize[ 0 ] = myRefOnObject.length() + 1;
3573 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
3574 aDataset->CreateOnDisk();
3575 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3576 aDataset->CloseOnDisk();
3579 else // shape ref is invalid:
3581 // save a group on geometry as ordinary group
3582 myWriter.AddGroup( aGeomGrp );
3585 else if ( SMESH_GroupOnFilter_i* aFilterGrp_i =
3586 dynamic_cast<SMESH_GroupOnFilter_i*>( myGroupImpl ))
3588 std::string str = aFilterGrp_i->FilterToString();
3589 std::string hdfGrpName = "Filter " + SMESH_Comment(anId);
3590 aSize[ 0 ] = str.length() + 1;
3591 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup, HDF_STRING, aSize, 1);
3592 aDataset->CreateOnDisk();
3593 aDataset->WriteOnDisk( ( char* )( str.c_str() ) );
3594 aDataset->CloseOnDisk();
3598 aGroup->CloseOnDisk();
3602 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
3604 // Flush current mesh information into MED file
3607 // save info on nb of elements
3608 SMESH_PreMeshInfo::SaveToFile( myImpl, id, aFile );
3610 // maybe a shape was deleted in the study
3611 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
3612 TopoDS_Shape nullShape;
3613 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
3616 if ( !mySMESHDSMesh->SubMeshes().empty() )
3620 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3621 aGroup->CreateOnDisk();
3623 // each element belongs to one or none submesh,
3624 // so for each node/element, we store a submesh ID
3626 // Make maps of submesh IDs of elements sorted by element IDs
3627 typedef int TElemID;
3628 typedef int TSubMID;
3629 map< TElemID, TSubMID > eId2smId, nId2smId;
3630 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
3631 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
3632 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
3633 SMDS_NodeIteratorPtr itNode;
3634 SMDS_ElemIteratorPtr itElem;
3635 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3637 TSubMID aSubMeID = itSubM->first;
3638 SMESHDS_SubMesh* aSubMesh = itSubM->second;
3639 if ( aSubMesh->IsComplexSubmesh() )
3640 continue; // submesh containing other submeshs
3642 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
3643 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
3644 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
3646 hint = eId2smId.begin();
3647 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
3648 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
3651 // Care of elements that are not on submeshes
3652 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
3653 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
3654 /* --- stl_map.h says : */
3655 /* A %map relies on unique keys and thus a %pair is only inserted if its */
3656 /* first element (the key) is not already present in the %map. */
3657 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
3659 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
3660 if ( nbElems != eId2smId.size() ) {
3661 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
3662 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
3665 // Store submesh IDs
3666 for ( int isNode = 0; isNode < 2; ++isNode )
3668 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
3669 if ( id2smId.empty() ) continue;
3670 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
3671 // make and fill array of submesh IDs
3672 int* smIDs = new int [ id2smId.size() ];
3673 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
3674 smIDs[ i ] = id_smId->second;
3676 aSize[ 0 ] = id2smId.size();
3677 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3678 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3679 aDataset->CreateOnDisk();
3680 aDataset->WriteOnDisk( smIDs );
3681 aDataset->CloseOnDisk();
3686 aGroup->CloseOnDisk();
3688 // Store node positions on sub-shapes (SMDS_Position):
3689 // ----------------------------------------------------
3691 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3692 aGroup->CreateOnDisk();
3694 // in aGroup, create 5 datasets to contain:
3695 // "Nodes on Edges" - ID of node on edge
3696 // "Edge positions" - U parameter on node on edge
3697 // "Nodes on Faces" - ID of node on face
3698 // "Face U positions" - U parameter of node on face
3699 // "Face V positions" - V parameter of node on face
3701 // Find out nb of nodes on edges and faces
3702 // Collect corresponing sub-meshes
3703 int nbEdgeNodes = 0, nbFaceNodes = 0;
3704 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
3705 // loop on SMESHDS_SubMesh'es
3706 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3708 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
3709 if ( aSubMesh->IsComplexSubmesh() )
3710 continue; // submesh containing other submeshs
3711 int nbNodes = aSubMesh->NbNodes();
3712 if ( nbNodes == 0 ) continue;
3714 int aShapeID = (*itSubM).first;
3715 if ( aShapeID < 1 || aShapeID > mySMESHDSMesh->MaxShapeIndex() )
3717 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
3718 // write only SMDS_FacePosition and SMDS_EdgePosition
3719 switch ( aShapeType ) {
3721 nbFaceNodes += nbNodes;
3722 aFaceSM.push_back( aSubMesh );
3725 nbEdgeNodes += nbNodes;
3726 aEdgeSM.push_back( aSubMesh );
3732 // Treat positions on edges or faces
3733 for ( int onFace = 0; onFace < 2; onFace++ )
3735 // Create arrays to store in datasets
3736 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
3737 if (!nbNodes) continue;
3738 int* aNodeIDs = new int [ nbNodes ];
3739 double* aUPos = new double [ nbNodes ];
3740 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
3743 // loop on sub-meshes
3744 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
3745 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
3746 for ( ; itSM != pListSM->end(); itSM++ )
3748 SMESHDS_SubMesh* aSubMesh = (*itSM);
3750 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
3751 // loop on nodes in aSubMesh
3752 while ( itNode->more() )
3755 const SMDS_MeshNode* node = itNode->next();
3756 aNodeIDs [ iNode ] = node->GetID();
3759 const SMDS_PositionPtr pos = node->GetPosition();
3760 if ( onFace ) { // on FACE
3761 const SMDS_FacePosition* fPos =
3762 dynamic_cast<const SMDS_FacePosition*>( pos );
3764 aUPos[ iNode ] = fPos->GetUParameter();
3765 aVPos[ iNode ] = fPos->GetVParameter();
3772 const SMDS_EdgePosition* ePos =
3773 dynamic_cast<const SMDS_EdgePosition*>( pos );
3775 aUPos[ iNode ] = ePos->GetUParameter();
3781 } // loop on nodes in aSubMesh
3782 } // loop on sub-meshes
3787 aSize[ 0 ] = nbNodes;
3789 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
3790 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3791 aDataset->CreateOnDisk();
3792 aDataset->WriteOnDisk( aNodeIDs );
3793 aDataset->CloseOnDisk();
3796 aDSName = ( onFace ? "Face U positions" : "Edge positions");
3797 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
3798 aDataset->CreateOnDisk();
3799 aDataset->WriteOnDisk( aUPos );
3800 aDataset->CloseOnDisk();
3803 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
3804 aDataset->CreateOnDisk();
3805 aDataset->WriteOnDisk( aVPos );
3806 aDataset->CloseOnDisk();
3811 if ( aVPos ) delete [] aVPos;
3813 } // treat positions on edges or faces
3815 // close "Node Positions" group
3816 aGroup->CloseOnDisk();
3818 } // if ( there are submeshes in SMESHDS_Mesh )
3821 // close mesh HDF group
3822 aTopGroup->CloseOnDisk();
3830 aFile->CloseOnDisk();
3833 // Convert temporary files to stream
3834 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
3836 // Remove temporary files and directory
3838 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3840 INFOS( "SMESH_Gen_i::Save() completed" );
3841 return aStreamFile._retn();
3844 //=============================================================================
3846 * SMESH_Gen_i::SaveASCII
3848 * Save SMESH module's data in ASCII format
3850 //=============================================================================
3852 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
3854 bool isMultiFile ) {
3855 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
3856 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
3857 return aStreamFile._retn();
3859 //after usual saving needs to encipher binary to text string
3860 //Any binary symbol will be represent as "|xx" () hexadecimal format number
3861 int size = aStreamFile.in().length();
3862 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
3863 for ( int i = 0; i < size; i++ )
3864 sprintf( (char*)&(buffer[i*3]), "|%02x", aStreamFile[i] );
3866 buffer[size * 3] = '\0';
3868 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
3870 return anAsciiStreamFile._retn();
3873 //=============================================================================
3875 * SMESH_Gen_i::loadGeomData
3877 * Load GEOM module data
3879 //=============================================================================
3881 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
3883 if ( theCompRoot->_is_nil() )
3886 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
3887 if ( aStudy->_is_nil() )
3890 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3891 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
3894 //=============================================================================
3898 * Load SMESH module's data
3900 //=============================================================================
3902 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
3903 const SALOMEDS::TMPFile& theStream,
3907 INFOS( "SMESH_Gen_i::Load" );
3909 if ( myCurrentStudy->_is_nil() ||
3910 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
3911 SetCurrentStudy( theComponent->GetStudy() );
3913 /* if( !theComponent->_is_nil() )
3915 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
3916 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
3917 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
3920 StudyContext* myStudyContext = GetCurrentStudyContext();
3922 // Get temporary files location
3923 TCollection_AsciiString tmpDir =
3924 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
3926 INFOS( "THE URL++++++++++++++" );
3928 INFOS( "THE TMP PATH+++++++++" );
3931 // Convert the stream into sequence of files to process
3932 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
3935 TCollection_AsciiString aStudyName( "" );
3937 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
3939 // Set names of temporary files
3940 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
3941 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
3945 HDFdataset* aDataset;
3946 HDFgroup* aTopGroup;
3948 HDFgroup* aSubGroup;
3949 HDFgroup* aSubSubGroup;
3952 // ---> open HDF file
3953 aFile = new HDFfile( (char*) filename.ToCString() );
3955 aFile->OpenOnDisk( HDF_RDONLY );
3957 catch ( HDFexception ) {
3958 INFOS( "Load(): " << filename << " not found!" );
3962 TPythonDump pd; // prevent dump during loading
3964 // DriverMED_R_SMESHDS_Mesh myReader;
3965 // myReader.SetFile( meshfile.ToCString() );
3967 // For PAL13473 ("Repetitive mesh") implementation.
3968 // New dependencies between SMESH objects are established:
3969 // now hypotheses can refer to meshes, shapes and other hypotheses.
3970 // To keep data consistent, the following order of data restoration
3972 // 1. Create hypotheses
3973 // 2. Create all meshes
3974 // 3. Load hypotheses' data
3977 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
3978 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
3980 // get total number of top-level groups
3981 int aNbGroups = aFile->nInternalObjects();
3982 if ( aNbGroups > 0 ) {
3983 // --> in first turn we should read&create hypotheses
3984 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
3985 // open hypotheses root HDF group
3986 aTopGroup = new HDFgroup( "Hypotheses", aFile );
3987 aTopGroup->OpenOnDisk();
3989 // get number of hypotheses
3990 int aNbObjects = aTopGroup->nInternalObjects();
3991 for ( int j = 0; j < aNbObjects; j++ ) {
3992 // try to identify hypothesis
3993 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
3994 aTopGroup->InternalObjectIndentify( j, hypGrpName );
3996 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
3997 // open hypothesis group
3998 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3999 aGroup->OpenOnDisk();
4001 // --> get hypothesis id
4002 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
4007 // get number of datasets
4008 int aNbSubObjects = aGroup->nInternalObjects();
4009 for ( int k = 0; k < aNbSubObjects; k++ ) {
4011 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4012 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4013 // --> get hypothesis name
4014 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4015 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4016 aDataset->OpenOnDisk();
4017 size = aDataset->GetSize();
4018 char* hypname_str = new char[ size ];
4019 aDataset->ReadFromDisk( hypname_str );
4020 hypname = string( hypname_str );
4021 delete [] hypname_str;
4022 aDataset->CloseOnDisk();
4024 // --> get hypothesis plugin library name
4025 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4026 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4027 aDataset->OpenOnDisk();
4028 size = aDataset->GetSize();
4029 char* libname_str = new char[ size ];
4030 aDataset->ReadFromDisk( libname_str );
4031 if(MYDEBUG) SCRUTE( libname_str );
4032 libname = string( libname_str );
4033 delete [] libname_str;
4034 aDataset->CloseOnDisk();
4036 // --> get hypothesis data
4037 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4038 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4039 aDataset->OpenOnDisk();
4040 size = aDataset->GetSize();
4041 char* hypdata_str = new char[ size ];
4042 aDataset->ReadFromDisk( hypdata_str );
4043 hypdata = string( hypdata_str );
4044 delete [] hypdata_str;
4045 aDataset->CloseOnDisk();
4048 // close hypothesis HDF group
4049 aGroup->CloseOnDisk();
4051 // --> restore hypothesis from data
4052 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4053 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
4054 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4055 SMESH::SMESH_Hypothesis_var myHyp;
4057 try { // protect persistence mechanism against exceptions
4058 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4061 INFOS( "Exception during hypothesis creation" );
4064 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4066 // myImpl->LoadFrom( hypdata.c_str() );
4067 hypDataList.push_back( make_pair( myImpl, hypdata ));
4068 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
4069 int newId = myStudyContext->findId( iorString.in() );
4070 myStudyContext->mapOldToNew( id, newId );
4073 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4077 // close hypotheses root HDF group
4078 aTopGroup->CloseOnDisk();
4082 // --> then we should read&create algorithms
4083 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
4084 // open algorithms root HDF group
4085 aTopGroup = new HDFgroup( "Algorithms", aFile );
4086 aTopGroup->OpenOnDisk();
4088 // get number of algorithms
4089 int aNbObjects = aTopGroup->nInternalObjects();
4090 for ( int j = 0; j < aNbObjects; j++ ) {
4091 // try to identify algorithm
4092 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
4093 aTopGroup->InternalObjectIndentify( j, hypGrpName );
4095 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
4096 // open algorithm group
4097 aGroup = new HDFgroup( hypGrpName, aTopGroup );
4098 aGroup->OpenOnDisk();
4100 // --> get algorithm id
4101 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
4106 // get number of datasets
4107 int aNbSubObjects = aGroup->nInternalObjects();
4108 for ( int k = 0; k < aNbSubObjects; k++ ) {
4110 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4111 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4112 // --> get algorithm name
4113 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4114 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4115 aDataset->OpenOnDisk();
4116 size = aDataset->GetSize();
4117 char* hypname_str = new char[ size ];
4118 aDataset->ReadFromDisk( hypname_str );
4119 hypname = string( hypname_str );
4120 delete [] hypname_str;
4121 aDataset->CloseOnDisk();
4123 // --> get algorithm plugin library name
4124 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4125 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4126 aDataset->OpenOnDisk();
4127 size = aDataset->GetSize();
4128 char* libname_str = new char[ size ];
4129 aDataset->ReadFromDisk( libname_str );
4130 if(MYDEBUG) SCRUTE( libname_str );
4131 libname = string( libname_str );
4132 delete [] libname_str;
4133 aDataset->CloseOnDisk();
4135 // --> get algorithm data
4136 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4137 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4138 aDataset->OpenOnDisk();
4139 size = aDataset->GetSize();
4140 char* hypdata_str = new char[ size ];
4141 aDataset->ReadFromDisk( hypdata_str );
4142 if(MYDEBUG) SCRUTE( hypdata_str );
4143 hypdata = string( hypdata_str );
4144 delete [] hypdata_str;
4145 aDataset->CloseOnDisk();
4148 // close algorithm HDF group
4149 aGroup->CloseOnDisk();
4151 // --> restore algorithm from data
4152 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4153 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
4154 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4155 SMESH::SMESH_Hypothesis_var myHyp;
4157 try { // protect persistence mechanism against exceptions
4158 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4161 INFOS( "Exception during hypothesis creation" );
4164 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4166 //myImpl->LoadFrom( hypdata.c_str() );
4167 hypDataList.push_back( make_pair( myImpl, hypdata ));
4168 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
4169 int newId = myStudyContext->findId( iorString.in() );
4170 myStudyContext->mapOldToNew( id, newId );
4173 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4177 // close algorithms root HDF group
4178 aTopGroup->CloseOnDisk();
4182 // --> the rest groups should be meshes
4183 for ( int i = 0; i < aNbGroups; i++ ) {
4184 // identify next group
4185 char meshName[ HDF_NAME_MAX_LEN+1 ];
4186 aFile->InternalObjectIndentify( i, meshName );
4188 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
4190 int id = atoi( string( meshName ).substr( 4 ).c_str() );
4194 // open mesh HDF group
4195 aTopGroup = new HDFgroup( meshName, aFile );
4196 aTopGroup->OpenOnDisk();
4198 // get number of child HDF objects
4199 int aNbObjects = aTopGroup->nInternalObjects();
4200 if ( aNbObjects > 0 ) {
4202 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
4203 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
4204 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
4205 if ( !myNewMeshImpl )
4207 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
4209 CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh );
4210 int newId = myStudyContext->findId( iorString.in() );
4211 myStudyContext->mapOldToNew( id, newId );
4214 // try to read and set auto color flag
4215 char aMeshAutoColorName[ 30 ];
4216 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
4217 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
4219 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
4220 aDataset->OpenOnDisk();
4221 size = aDataset->GetSize();
4222 int* anAutoColor = new int[ size ];
4223 aDataset->ReadFromDisk( anAutoColor );
4224 aDataset->CloseOnDisk();
4225 myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
4226 delete [] anAutoColor;
4229 // try to read and set reference to shape
4230 GEOM::GEOM_Object_var aShapeObject;
4231 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
4232 // load mesh "Ref on shape" - it's an entry to SObject
4233 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
4234 aDataset->OpenOnDisk();
4235 size = aDataset->GetSize();
4236 char* refFromFile = new char[ size ];
4237 aDataset->ReadFromDisk( refFromFile );
4238 aDataset->CloseOnDisk();
4239 if ( strlen( refFromFile ) > 0 ) {
4240 SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4242 // Make sure GEOM data are loaded first
4243 //loadGeomData( shapeSO->GetFatherComponent() );
4245 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4246 if ( !CORBA::is_nil( shapeObject ) ) {
4247 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4248 if ( !aShapeObject->_is_nil() )
4249 myNewMeshImpl->SetShape( aShapeObject );
4252 delete [] refFromFile;
4255 // issue 20918. Restore Persistent Id of SMESHDS_Mesh
4256 if( aTopGroup->ExistInternalObject( "meshPersistentId" ) )
4258 aDataset = new HDFdataset( "meshPersistentId", aTopGroup );
4259 aDataset->OpenOnDisk();
4260 size = aDataset->GetSize();
4261 int* meshPersistentId = new int[ size ];
4262 aDataset->ReadFromDisk( meshPersistentId );
4263 aDataset->CloseOnDisk();
4264 myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
4265 delete [] meshPersistentId;
4271 // As all object that can be referred by hypothesis are created,
4272 // we can restore hypothesis data
4274 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
4275 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4277 SMESH_Hypothesis_i* hyp = hyp_data->first;
4278 string & data = hyp_data->second;
4279 hyp->LoadFrom( data.c_str() );
4282 // Restore the rest mesh data
4284 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
4285 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4287 aTopGroup = meshi_group->second;
4288 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4289 //::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4290 //SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
4292 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
4293 bool hasData = false;
4296 CORBA::String_var iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
4297 int newId = myStudyContext->findId( iorString.in() );
4298 int id = myStudyContext->getOldId( newId );
4300 // try to find mesh data dataset
4301 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
4302 // load mesh "has data" flag
4303 aDataset = new HDFdataset( "Has data", aTopGroup );
4304 aDataset->OpenOnDisk();
4305 size = aDataset->GetSize();
4306 char* strHasData = new char[ size ];
4307 aDataset->ReadFromDisk( strHasData );
4308 aDataset->CloseOnDisk();
4309 if ( strcmp( strHasData, "1") == 0 ) {
4310 // read mesh data from MED file
4311 // myReader.SetMesh( mySMESHDSMesh );
4312 // myReader.SetMeshId( id );
4313 // myReader.Perform();
4316 delete [] strHasData;
4319 // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
4320 // nodes and elements are not yet put into sub-meshes)
4321 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4322 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
4323 aGroup->OpenOnDisk();
4324 // get number of applied algorithms
4325 int aNbSubObjects = aGroup->nInternalObjects();
4326 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
4327 for ( int j = 0; j < aNbSubObjects; j++ ) {
4328 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4329 aGroup->InternalObjectIndentify( j, name_dataset );
4330 // check if it is an algorithm
4331 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
4332 aDataset = new HDFdataset( name_dataset, aGroup );
4333 aDataset->OpenOnDisk();
4334 size = aDataset->GetSize();
4335 char* refFromFile = new char[ size ];
4336 aDataset->ReadFromDisk( refFromFile );
4337 aDataset->CloseOnDisk();
4338 // san - it is impossible to recover applied algorithms using their entries within Load() method
4339 //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
4340 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4341 int id = atoi( refFromFile );
4342 delete [] refFromFile;
4343 string anIOR = myStudyContext->getIORbyOldId( id );
4344 if ( !anIOR.empty() ) {
4345 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4346 if ( !CORBA::is_nil( hypObject ) ) {
4347 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4348 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4349 || !myNewMeshImpl->HasShapeToMesh()) )
4350 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4355 aGroup->CloseOnDisk();
4358 // try to get applied hypotheses
4359 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4360 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
4361 aGroup->OpenOnDisk();
4362 // get number of applied hypotheses
4363 int aNbSubObjects = aGroup->nInternalObjects();
4364 for ( int j = 0; j < aNbSubObjects; j++ ) {
4365 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4366 aGroup->InternalObjectIndentify( j, name_dataset );
4367 // check if it is a hypothesis
4368 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4369 aDataset = new HDFdataset( name_dataset, aGroup );
4370 aDataset->OpenOnDisk();
4371 size = aDataset->GetSize();
4372 char* refFromFile = new char[ size ];
4373 aDataset->ReadFromDisk( refFromFile );
4374 aDataset->CloseOnDisk();
4375 // san - it is impossible to recover applied hypotheses using their entries within Load() method
4376 //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
4377 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4378 int id = atoi( refFromFile );
4379 delete [] refFromFile;
4380 string anIOR = myStudyContext->getIORbyOldId( id );
4381 if ( !anIOR.empty() ) {
4382 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4383 if ( !CORBA::is_nil( hypObject ) ) {
4384 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4385 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4386 || !myNewMeshImpl->HasShapeToMesh()) )
4387 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4392 aGroup->CloseOnDisk();
4395 // --> try to find SUB-MESHES containers for each type of submesh
4396 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
4397 char name_meshgroup[ 30 ];
4398 if ( j == GetSubMeshOnVertexTag() )
4399 strcpy( name_meshgroup, "SubMeshes On Vertex" );
4400 else if ( j == GetSubMeshOnEdgeTag() )
4401 strcpy( name_meshgroup, "SubMeshes On Edge" );
4402 else if ( j == GetSubMeshOnWireTag() )
4403 strcpy( name_meshgroup, "SubMeshes On Wire" );
4404 else if ( j == GetSubMeshOnFaceTag() )
4405 strcpy( name_meshgroup, "SubMeshes On Face" );
4406 else if ( j == GetSubMeshOnShellTag() )
4407 strcpy( name_meshgroup, "SubMeshes On Shell" );
4408 else if ( j == GetSubMeshOnSolidTag() )
4409 strcpy( name_meshgroup, "SubMeshes On Solid" );
4410 else if ( j == GetSubMeshOnCompoundTag() )
4411 strcpy( name_meshgroup, "SubMeshes On Compound" );
4413 // try to get submeshes container HDF group
4414 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
4415 // open submeshes containers HDF group
4416 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
4417 aGroup->OpenOnDisk();
4419 // get number of submeshes
4420 int aNbSubMeshes = aGroup->nInternalObjects();
4421 for ( int k = 0; k < aNbSubMeshes; k++ ) {
4423 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
4424 aGroup->InternalObjectIndentify( k, name_submeshgroup );
4425 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
4426 // --> get submesh id
4427 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
4430 // open submesh HDF group
4431 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
4432 aSubGroup->OpenOnDisk();
4434 // try to read and set reference to subshape
4435 GEOM::GEOM_Object_var aSubShapeObject;
4436 SMESH::SMESH_subMesh_var aSubMesh;
4438 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
4439 // load submesh "Ref on shape" - it's an entry to SObject
4440 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
4441 aDataset->OpenOnDisk();
4442 size = aDataset->GetSize();
4443 char* refFromFile = new char[ size ];
4444 aDataset->ReadFromDisk( refFromFile );
4445 aDataset->CloseOnDisk();
4446 if ( strlen( refFromFile ) > 0 ) {
4447 SALOMEDS::SObject_wrap subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
4448 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
4449 if ( !CORBA::is_nil( subShapeObject ) ) {
4450 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
4451 if ( !aSubShapeObject->_is_nil() )
4452 aSubMesh = SMESH::SMESH_subMesh::_duplicate
4453 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
4454 if ( aSubMesh->_is_nil() )
4456 string iorSubString = GetORB()->object_to_string( aSubMesh );
4457 int newSubId = myStudyContext->findId( iorSubString );
4458 myStudyContext->mapOldToNew( subid, newSubId );
4463 if ( aSubMesh->_is_nil() )
4466 // try to get applied algorithms
4467 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4468 // open "applied algorithms" HDF group
4469 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
4470 aSubSubGroup->OpenOnDisk();
4471 // get number of applied algorithms
4472 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4473 for ( int l = 0; l < aNbSubObjects; l++ ) {
4474 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4475 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4476 // check if it is an algorithm
4477 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
4478 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4479 aDataset->OpenOnDisk();
4480 size = aDataset->GetSize();
4481 char* refFromFile = new char[ size ];
4482 aDataset->ReadFromDisk( refFromFile );
4483 aDataset->CloseOnDisk();
4485 int id = atoi( refFromFile );
4486 string anIOR = myStudyContext->getIORbyOldId( id );
4487 if ( !anIOR.empty() ) {
4488 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4489 if ( !CORBA::is_nil( hypObject ) ) {
4490 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4491 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4492 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4497 // close "applied algorithms" HDF group
4498 aSubSubGroup->CloseOnDisk();
4501 // try to get applied hypotheses
4502 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4503 // open "applied hypotheses" HDF group
4504 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
4505 aSubSubGroup->OpenOnDisk();
4506 // get number of applied hypotheses
4507 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4508 for ( int l = 0; l < aNbSubObjects; l++ ) {
4509 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4510 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4511 // check if it is a hypothesis
4512 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4513 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4514 aDataset->OpenOnDisk();
4515 size = aDataset->GetSize();
4516 char* refFromFile = new char[ size ];
4517 aDataset->ReadFromDisk( refFromFile );
4518 aDataset->CloseOnDisk();
4520 int id = atoi( refFromFile );
4521 string anIOR = myStudyContext->getIORbyOldId( id );
4522 if ( !anIOR.empty() ) {
4523 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4524 if ( !CORBA::is_nil( hypObject ) ) {
4525 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4526 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4527 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4532 // close "APPLIED HYPOTHESES" hdf group
4533 aSubSubGroup->CloseOnDisk();
4536 // close SUB-MESH hdf group
4537 aSubGroup->CloseOnDisk();
4540 // close SUB-MESHES containers hdf group
4541 aGroup->CloseOnDisk();
4545 // try to get GROUPS
4546 for ( int ii = GetNodeGroupsTag(); ii <= GetBallElementsGroupsTag(); ii++ ) {
4547 char name_group[ 30 ];
4548 if ( ii == GetNodeGroupsTag() )
4549 strcpy( name_group, "Groups of Nodes" );
4550 else if ( ii == GetEdgeGroupsTag() )
4551 strcpy( name_group, "Groups of Edges" );
4552 else if ( ii == GetFaceGroupsTag() )
4553 strcpy( name_group, "Groups of Faces" );
4554 else if ( ii == GetVolumeGroupsTag() )
4555 strcpy( name_group, "Groups of Volumes" );
4556 else if ( ii == Get0DElementsGroupsTag() )
4557 strcpy( name_group, "Groups of 0D Elements" );
4558 else if ( ii == GetBallElementsGroupsTag() )
4559 strcpy( name_group, "Groups of Balls" );
4561 if ( aTopGroup->ExistInternalObject( name_group ) ) {
4562 aGroup = new HDFgroup( name_group, aTopGroup );
4563 aGroup->OpenOnDisk();
4564 // get number of groups
4565 int aNbSubObjects = aGroup->nInternalObjects();
4566 for ( int j = 0; j < aNbSubObjects; j++ ) {
4567 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4568 aGroup->InternalObjectIndentify( j, name_dataset );
4569 // check if it is an group
4570 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
4572 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
4575 aDataset = new HDFdataset( name_dataset, aGroup );
4576 aDataset->OpenOnDisk();
4578 // Retrieve actual group name
4579 size = aDataset->GetSize();
4580 char* nameFromFile = new char[ size ];
4581 aDataset->ReadFromDisk( nameFromFile );
4582 aDataset->CloseOnDisk();
4584 // Try to find a shape reference
4585 TopoDS_Shape aShape;
4586 char aRefName[ 30 ];
4587 sprintf( aRefName, "Ref on shape %d", subid);
4588 if ( aGroup->ExistInternalObject( aRefName ) ) {
4589 // load mesh "Ref on shape" - it's an entry to SObject
4590 aDataset = new HDFdataset( aRefName, aGroup );
4591 aDataset->OpenOnDisk();
4592 size = aDataset->GetSize();
4593 char* refFromFile = new char[ size ];
4594 aDataset->ReadFromDisk( refFromFile );
4595 aDataset->CloseOnDisk();
4596 if ( strlen( refFromFile ) > 0 ) {
4597 SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4598 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4599 if ( !CORBA::is_nil( shapeObject ) ) {
4600 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4601 if ( !aShapeObject->_is_nil() )
4602 aShape = GeomObjectToShape( aShapeObject );
4606 // Try to read a filter of SMESH_GroupOnFilter
4607 SMESH::Filter_var filter;
4608 SMESH_PredicatePtr predicate;
4609 std::string hdfGrpName = "Filter " + SMESH_Comment(subid);
4610 if ( aGroup->ExistInternalObject( hdfGrpName.c_str() ))
4612 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup );
4613 aDataset->OpenOnDisk();
4614 size = aDataset->GetSize();
4615 char* persistStr = new char[ size ];
4616 aDataset->ReadFromDisk( persistStr );
4617 aDataset->CloseOnDisk();
4618 if ( strlen( persistStr ) > 0 ) {
4619 filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
4620 predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
4624 // Create group servant
4625 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
4626 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
4627 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) );
4628 // Obtain a SMESHDS_Group object
4629 if ( aNewGroup->_is_nil() )
4632 string iorSubString = GetORB()->object_to_string( aNewGroup );
4633 int newSubId = myStudyContext->findId( iorSubString );
4634 myStudyContext->mapOldToNew( subid, newSubId );
4636 SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
4640 if ( SMESH_GroupOnFilter_i* aFilterGroup =
4641 dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
4642 aFilterGroup->SetFilter( filter );
4644 SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
4645 if ( !aGroupBaseDS )
4648 aGroupBaseDS->SetStoreName( name_dataset );
4651 // Read color of the group
4652 char aGroupColorName[ 30 ];
4653 sprintf( aGroupColorName, "ColorGroup %d", subid);
4654 if ( aGroup->ExistInternalObject( aGroupColorName ) )
4656 aDataset = new HDFdataset( aGroupColorName, aGroup );
4657 aDataset->OpenOnDisk();
4658 size = aDataset->GetSize();
4659 double* anRGB = new double[ size ];
4660 aDataset->ReadFromDisk( anRGB );
4661 aDataset->CloseOnDisk();
4662 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
4663 aGroupBaseDS->SetColor( aColor );
4666 // Fill group with contents from MED file
4667 // SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
4669 // myReader.GetGroup( aGrp );
4672 aGroup->CloseOnDisk();
4676 // instead of reading mesh data, we read only brief information of all
4677 // objects: mesh, groups, sub-meshes (issue 0021208 )
4680 SMESH_PreMeshInfo::LoadFromFile( myNewMeshImpl, id,
4681 meshfile.ToCString(), filename.ToCString(),
4685 // read Sub-Mesh ORDER if any
4686 if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
4687 aDataset = new HDFdataset( "Mesh Order", aTopGroup );
4688 aDataset->OpenOnDisk();
4689 size = aDataset->GetSize();
4690 int* smIDs = new int[ size ];
4691 aDataset->ReadFromDisk( smIDs );
4692 aDataset->CloseOnDisk();
4693 TListOfListOfInt anOrderIds;
4694 anOrderIds.push_back( TListOfInt() );
4695 for ( int i = 0; i < size; i++ )
4696 if ( smIDs[ i ] < 0 ) // is separator
4697 anOrderIds.push_back( TListOfInt() );
4699 anOrderIds.back().push_back(smIDs[ i ]);
4701 myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
4705 // update hyps needing full mesh data restored (issue 20918)
4706 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4708 SMESH_Hypothesis_i* hyp = hyp_data->first;
4709 hyp->UpdateAsMeshesRestored();
4712 // notify algos on completed restoration to set sub-mesh event listeners
4713 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4715 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4716 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4718 TopoDS_Shape myLocShape;
4719 if(myLocMesh.HasShapeToMesh())
4720 myLocShape = myLocMesh.GetShapeToMesh();
4722 myLocShape = SMESH_Mesh::PseudoShape();
4724 myLocMesh.GetSubMesh(myLocShape)->
4725 ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
4730 aTopGroup->CloseOnDisk();
4733 aFile->CloseOnDisk();
4736 // Remove temporary files created from the stream
4739 SMESH_File meshFile( meshfile.ToCString() );
4740 if ( !meshFile ) // no meshfile exists
4742 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
4746 Engines::Container_var container = GetContainerRef();
4747 if ( Engines_Container_i* container_i = SMESH::DownCast<Engines_Container_i*>( container ))
4749 container_i->registerTemporaryFile( filename.ToCString() );
4750 container_i->registerTemporaryFile( meshfile.ToCString() );
4751 container_i->registerTemporaryFile( tmpDir.ToCString() );
4755 pd << ""; // prevent optimizing pd out
4757 INFOS( "SMESH_Gen_i::Load completed" );
4761 //=============================================================================
4763 * SMESH_Gen_i::LoadASCII
4765 * Load SMESH module's data in ASCII format
4767 //=============================================================================
4769 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
4770 const SALOMEDS::TMPFile& theStream,
4772 bool isMultiFile ) {
4773 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
4774 return Load( theComponent, theStream, theURL, isMultiFile );
4776 //before call main ::Load method it's need for decipher text format to
4777 //binary ( "|xx" => x' )
4778 int size = theStream.length();
4779 if ( int((size / 3 )*3) != size ) //error size of buffer
4782 int real_size = int(size / 3);
4784 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
4788 for ( int i = 0; i < real_size; i++ )
4790 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
4791 sscanf( tmp, "%x", &c );
4792 sprintf( (char*)&(buffer[i]), "%c", (char)c );
4795 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
4797 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
4800 //=============================================================================
4802 * SMESH_Gen_i::Close
4804 * Clears study-connected data when it is closed
4806 //=============================================================================
4808 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
4810 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
4812 // set correct current study
4813 SALOMEDS::Study_var study = theComponent->GetStudy();
4814 if ( study->StudyId() != GetCurrentStudyID())
4815 setCurrentStudy( study, /*IsBeingClosed=*/true );
4817 // Clear study contexts data
4818 int studyId = GetCurrentStudyID();
4819 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
4820 delete myStudyContextMap[ studyId ];
4821 myStudyContextMap.erase( studyId );
4824 // remove the tmp files meshes are loaded from
4825 SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
4827 myCurrentStudy = SALOMEDS::Study::_nil();
4831 //=============================================================================
4833 * SMESH_Gen_i::ComponentDataType
4835 * Get component data type
4837 //=============================================================================
4839 char* SMESH_Gen_i::ComponentDataType()
4841 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
4842 return CORBA::string_dup( "SMESH" );
4846 //=============================================================================
4848 * SMESH_Gen_i::IORToLocalPersistentID
4850 * Transform data from transient form to persistent
4852 //=============================================================================
4854 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
4855 const char* IORString,
4856 CORBA::Boolean /*isMultiFile*/,
4857 CORBA::Boolean /*isASCII*/ )
4859 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
4860 StudyContext* myStudyContext = GetCurrentStudyContext();
4862 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
4863 int anId = myStudyContext->findId( IORString );
4865 if(MYDEBUG) MESSAGE( "VSR " << anId )
4867 sprintf( strId, "%d", anId );
4868 return CORBA::string_dup( strId );
4871 return CORBA::string_dup( "" );
4874 //=============================================================================
4876 * SMESH_Gen_i::LocalPersistentIDToIOR
4878 * Transform data from persistent form to transient
4880 //=============================================================================
4882 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
4883 const char* aLocalPersistentID,
4884 CORBA::Boolean /*isMultiFile*/,
4885 CORBA::Boolean /*isASCII*/ )
4887 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
4888 StudyContext* myStudyContext = GetCurrentStudyContext();
4890 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
4891 int anId = atoi( aLocalPersistentID );
4892 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
4894 return CORBA::string_dup( "" );
4897 //=======================================================================
4898 //function : RegisterObject
4900 //=======================================================================
4902 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
4904 StudyContext* myStudyContext = GetCurrentStudyContext();
4905 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4906 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
4907 return myStudyContext->addObject( string( iorString.in() ) );
4912 //================================================================================
4914 * \brief Return id of registered object
4915 * \param theObject - the Object
4916 * \retval int - Object id
4918 //================================================================================
4920 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
4922 StudyContext* myStudyContext = GetCurrentStudyContext();
4923 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4924 string iorString = GetORB()->object_to_string( theObject );
4925 return myStudyContext->findId( iorString );
4930 //=============================================================================
4932 * SMESH_Gen_i::SetName
4934 * Set a new object name
4936 //=============================================================================
4937 void SMESH_Gen_i::SetName(const char* theIOR,
4938 const char* theName)
4940 if ( theIOR && strcmp( theIOR, "" ) ) {
4941 CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
4942 SALOMEDS::SObject_wrap aSO = ObjectToSObject( myCurrentStudy, anObject );
4943 if ( !aSO->_is_nil() ) {
4944 SetName( aSO, theName );
4949 int SMESH_Gen_i::GetCurrentStudyID()
4951 return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
4954 // Version information
4955 char* SMESH_Gen_i::getVersion()
4957 #if SMESH_DEVELOPMENT
4958 return CORBA::string_dup(SMESH_VERSION_STR"dev");
4960 return CORBA::string_dup(SMESH_VERSION_STR);
4964 //=============================================================================
4966 * SMESHEngine_factory
4968 * C factory, accessible with dlsym, after dlopen
4970 //=============================================================================
4974 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
4975 PortableServer::POA_ptr poa,
4976 PortableServer::ObjectId* contId,
4977 const char* instanceName,
4978 const char* interfaceName )
4980 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
4981 if(MYDEBUG) SCRUTE(interfaceName);
4982 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
4983 return aSMESHGen->getId() ;