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 ); }
477 else { nextId = 0; } // avoid "unused variable" warning in release mode
479 return hypothesis_i._retn();
482 //=============================================================================
484 * SMESH_Gen_i::createMesh
486 * Create empty mesh on shape
488 //=============================================================================
489 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
490 throw ( SALOME::SALOME_Exception )
492 Unexpect aCatch(SALOME_SalomeException);
493 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
495 // Get or create the GEOM_Client instance
497 // create a new mesh object servant, store it in a map in study context
498 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
499 // create a new mesh object
500 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
501 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
503 // activate the CORBA servant of Mesh
504 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
505 int nextId = RegisterObject( mesh );
506 if(MYDEBUG) { MESSAGE( "Add mesh to map with id = "<< nextId); }
507 else { nextId = 0; } // avoid "unused variable" warning in release mode
510 catch (SALOME_Exception& S_ex) {
511 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
513 return SMESH::SMESH_Mesh::_nil();
516 //=============================================================================
518 * SMESH_Gen_i::GetShapeReader
522 //=============================================================================
523 GEOM_Client* SMESH_Gen_i::GetShapeReader()
525 // create shape reader if necessary
526 if ( !myShapeReader )
527 myShapeReader = new GEOM_Client(GetContainerRef());
528 ASSERT( myShapeReader );
529 return myShapeReader;
532 //=============================================================================
534 * SMESH_Gen_i::SetGeomEngine
536 * Set GEOM::GEOM_Gen reference
538 //=============================================================================
539 //GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
540 void SMESH_Gen_i::SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo )
542 //Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
543 //myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
544 myGeomGen=GEOM::GEOM_Gen::_duplicate(geomcompo);
548 //=============================================================================
550 * SMESH_Gen_i::SetEmbeddedMode
554 //=============================================================================
556 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
558 myIsEmbeddedMode = theMode;
559 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
561 if ( !myIsEmbeddedMode ) {
562 //PAL10867: disable signals catching with "noexcepthandler" option
563 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
564 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
569 char* envDisableFPE = getenv("DISABLE_FPE");
570 if (envDisableFPE && atoi(envDisableFPE))
575 OSD::SetSignal( raiseFPE );
577 // else OSD::SetSignal() is called in GUI
581 //=============================================================================
583 * SMESH_Gen_i::IsEmbeddedMode
587 //=============================================================================
589 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
591 return myIsEmbeddedMode;
594 //=============================================================================
596 * SMESH_Gen_i::SetCurrentStudy
600 //=============================================================================
602 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
604 setCurrentStudy( theStudy );
607 void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy,
608 bool theStudyIsBeingClosed)
610 int curStudyId = GetCurrentStudyID();
611 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
612 // create study context, if it doesn't exist and set current study
613 int studyId = GetCurrentStudyID();
614 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() )
615 myStudyContextMap[ studyId ] = new StudyContext;
617 // myCurrentStudy may be nil
618 if ( !theStudyIsBeingClosed && !CORBA::is_nil( myCurrentStudy ) ) {
619 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
620 SALOMEDS::SComponent_wrap GEOM_var = myCurrentStudy->FindComponent( "GEOM" );
621 if( !GEOM_var->_is_nil() )
622 aStudyBuilder->LoadWith( GEOM_var, GetGeomEngine() );
623 // NPAL16168, issue 0020210
624 // Let meshes update their data depending on GEOM groups that could change
625 if ( curStudyId != studyId )
627 CORBA::String_var compDataType = ComponentDataType();
628 SALOMEDS::SComponent_wrap me = myCurrentStudy->FindComponent( compDataType.in() );
629 if ( !me->_is_nil() ) {
630 SALOMEDS::ChildIterator_wrap anIter = myCurrentStudy->NewChildIterator( me );
631 for ( ; anIter->More(); anIter->Next() ) {
632 SALOMEDS::SObject_wrap so = anIter->Value();
633 CORBA::Object_var ior = SObjectToObject( so );
634 if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
635 mesh->CheckGeomGroupModif();
642 //=============================================================================
644 * SMESH_Gen_i::GetCurrentStudy
648 //=============================================================================
650 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
652 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
653 return SALOMEDS::Study::_duplicate( myCurrentStudy );
656 //=============================================================================
658 * SMESH_Gen_i::GetCurrentStudyContext
660 * Get current study context
662 //=============================================================================
663 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
665 if ( !CORBA::is_nil( myCurrentStudy ) &&
666 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
667 return myStudyContextMap[ myCurrentStudy->StudyId() ];
672 //=============================================================================
674 * SMESH_Gen_i::CreateHypothesis
676 * Create hypothesis/algorothm of given type and publish it in the study
678 //=============================================================================
680 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
681 const char* theLibName )
682 throw ( SALOME::SALOME_Exception )
684 Unexpect aCatch(SALOME_SalomeException);
685 // Create hypothesis/algorithm
686 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
688 // Publish hypothesis/algorithm in the study
689 if ( CanPublishInStudy( hyp ) ) {
690 SALOMEDS::SObject_wrap aSO = PublishHypothesis( myCurrentStudy, hyp );
691 if ( !aSO->_is_nil() ) {
692 // Update Python script
693 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
694 << theHypName << "', '" << theLibName << "')";
701 //================================================================================
703 * \brief Return a hypothesis holding parameter values corresponding either to the mesh
704 * existing on the given geometry or to size of the geometry.
705 * \param theHypType - hypothesis type name
706 * \param theLibName - plugin library name
707 * \param theMesh - The mesh of interest
708 * \param theGeom - The shape to get parameter values from
709 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
710 * in a study and used to compute the mesh, or a temporary one created just to pass
713 //================================================================================
715 SMESH::SMESH_Hypothesis_ptr
716 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
717 const char* theLibName,
718 SMESH::SMESH_Mesh_ptr theMesh,
719 GEOM::GEOM_Object_ptr theGeom,
720 CORBA::Boolean byMesh)
721 throw ( SALOME::SALOME_Exception )
723 Unexpect aCatch(SALOME_SalomeException);
724 if ( byMesh && CORBA::is_nil( theMesh ) )
725 return SMESH::SMESH_Hypothesis::_nil();
726 if ( byMesh && CORBA::is_nil( theGeom ) )
727 return SMESH::SMESH_Hypothesis::_nil();
729 // -----------------------------------------------
730 // find hypothesis used to mesh theGeom
731 // -----------------------------------------------
733 // get mesh and shape
734 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
735 TopoDS_Shape shape = GeomObjectToShape( theGeom );
736 if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
737 return SMESH::SMESH_Hypothesis::_nil();
738 ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
740 // create a temporary hypothesis to know its dimention
741 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
742 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
744 return SMESH::SMESH_Hypothesis::_nil();
745 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
748 // look for a hypothesis of theHypType used to mesh the shape
749 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
752 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
753 int nbLocalHyps = aHypList->length();
754 for ( int i = 0; i < nbLocalHyps; i++ ) {
755 CORBA::String_var hypName = aHypList[i]->GetName();
756 if ( strcmp( theHypType, hypName.in() ) == 0 ) // FOUND local!
757 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
759 // check super shapes
760 TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
761 while ( nbLocalHyps == 0 && itShape.More() ) {
762 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
763 if ( ! CORBA::is_nil( geomObj )) {
764 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
765 nbLocalHyps = aHypList->length();
766 for ( int i = 0; i < nbLocalHyps; i++ )
767 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
768 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
774 // let the temporary hypothesis find out somehow parameter values by mesh
775 if ( hyp->SetParametersByMesh( mesh, shape ))
776 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
781 diagonal = mesh->GetShapeDiagonalSize();
783 diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
784 ::SMESH_Hypothesis::TDefaults dflts;
785 dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
786 dflts._nbSegments = myGen.GetDefaultNbSegments();
787 dflts._shape = &shape;
788 // let the temporary hypothesis initialize it's values
789 if ( hyp->SetParametersByDefaults( dflts, mesh ))
790 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
793 return SMESH::SMESH_Hypothesis::_nil();
796 //=============================================================================
798 * Sets number of segments per diagonal of boundary box of geometry by which
799 * default segment length of appropriate 1D hypotheses is defined
801 //=============================================================================
803 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
804 throw ( SALOME::SALOME_Exception )
806 if ( theNbSegments > 0 )
807 myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
809 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
811 //=============================================================================
813 * \brief Sets default number of segments per edge
815 //=============================================================================
816 void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
817 throw ( SALOME::SALOME_Exception )
819 if ( theNbSegments > 0 )
820 myGen.SetDefaultNbSegments( int(theNbSegments) );
822 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
825 //=============================================================================
829 //=============================================================================
831 void SMESH_Gen_i::SetOption(const char* name, const char* value)
833 if ( name && value && strlen( value ) > 0 )
836 if ( strcmp(name, "historical_python_dump") == 0 )
838 myIsHistoricalPythonDump = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
839 msgToGUI = "preferences/SMESH/historical_python_dump/";
840 msgToGUI += myIsHistoricalPythonDump ? "true" : "false";
842 else if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
844 myToForgetMeshDataOnHypModif = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
845 msgToGUI = "preferences/SMESH/forget_mesh_on_hyp_modif/";
846 msgToGUI += myToForgetMeshDataOnHypModif ? "true" : "false";
849 // update preferences in case if SetOption() is invoked from python console
850 if ( !msgToGUI.empty() )
852 CORBA::Object_var obj = SMESH_Gen_i::GetNS()->Resolve( "/Kernel/Session" );
853 SALOME::Session_var session = SALOME::Session::_narrow( obj );
854 if ( !CORBA::is_nil( session ) )
855 session->emitMessageOneWay(msgToGUI.c_str());
860 //=============================================================================
862 Return an option value
864 //=============================================================================
866 char* SMESH_Gen_i::GetOption(const char* name)
870 if ( strcmp(name, "historical_python_dump") == 0 )
872 return CORBA::string_dup( myIsHistoricalPythonDump ? "true" : "false" );
874 if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
876 return CORBA::string_dup( myToForgetMeshDataOnHypModif ? "true" : "false" );
879 return CORBA::string_dup( "" );
882 //=============================================================================
884 * SMESH_Gen_i::CreateMesh
886 * Create empty mesh on a shape and publish it in the study
888 //=============================================================================
890 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
891 throw ( SALOME::SALOME_Exception )
893 Unexpect aCatch(SALOME_SalomeException);
894 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
896 SMESH::SMESH_Mesh_var mesh = this->createMesh();
898 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
899 ASSERT( meshServant );
900 meshServant->SetShape( theShapeObject );
902 // publish mesh in the study
903 if ( CanPublishInStudy( mesh ) ) {
904 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
905 aStudyBuilder->NewCommand(); // There is a transaction
906 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
907 aStudyBuilder->CommitCommand();
908 if ( !aSO->_is_nil() ) {
909 // Update Python script
910 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
917 //=============================================================================
919 * SMESH_Gen_i::CreateEmptyMesh
923 //=============================================================================
925 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
926 throw ( SALOME::SALOME_Exception )
928 Unexpect aCatch(SALOME_SalomeException);
929 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
931 SMESH::SMESH_Mesh_var mesh = this->createMesh();
933 // publish mesh in the study
934 if ( CanPublishInStudy( mesh ) ) {
935 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
936 aStudyBuilder->NewCommand(); // There is a transaction
937 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
938 aStudyBuilder->CommitCommand();
939 if ( !aSO->_is_nil() ) {
940 // Update Python script
941 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
948 //=============================================================================
950 * SMESH_Gen_i::CreateMeshFromUNV
952 * Create mesh and import data from UNV file
954 //=============================================================================
956 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
957 throw ( SALOME::SALOME_Exception )
959 Unexpect aCatch(SALOME_SalomeException);
960 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
962 SMESH::SMESH_Mesh_var aMesh = createMesh();
964 // publish mesh in the study
965 if ( CanPublishInStudy( aMesh ) ) {
966 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
967 aStudyBuilder->NewCommand(); // There is a transaction
968 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
969 aStudyBuilder->CommitCommand();
970 if ( !aSO->_is_nil() ) {
971 // Update Python script
972 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromUNV(r'" << theFileName << "')";
976 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
978 aServant->ImportUNVFile( theFileName );
980 // Dump creation of groups
981 SMESH::ListOfGroups_var groups = aServant->GetGroups();
983 aServant->GetImpl().GetMeshDS()->Modified();
984 return aMesh._retn();
987 //=============================================================================
989 * SMESH_Gen_i::CreateMeshFromMED
991 * Create mesh and import data from MED file
993 //=============================================================================
995 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileName,
996 SMESH::DriverMED_ReadStatus& theStatus,
997 const char* theCommandNameForPython,
998 const char* theFileNameForPython)
1001 char bname[ _MAX_FNAME ];
1002 _splitpath( theFileNameForPython, NULL, NULL, bname, NULL );
1003 string aFileName = bname;
1005 string aFileName = basename( theFileNameForPython );
1007 // Retrieve mesh names from the file
1008 DriverMED_R_SMESHDS_Mesh myReader;
1009 myReader.SetFile( theFileName );
1010 myReader.SetMeshId( -1 );
1011 Driver_Mesh::Status aStatus;
1012 list<string> aNames = myReader.GetMeshNames(aStatus);
1013 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
1014 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1016 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1019 TPythonDump aPythonDump;
1020 aPythonDump << "([";
1022 if (theStatus == SMESH::DRS_OK) {
1023 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1024 aStudyBuilder->NewCommand(); // There is a transaction
1025 aResult->length( aNames.size() );
1028 // Iterate through all meshes and create mesh objects
1029 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
1031 if (i > 0) aPythonDump << ", ";
1034 SMESH::SMESH_Mesh_var mesh = createMesh();
1036 // publish mesh in the study
1037 SALOMEDS::SObject_wrap aSO;
1038 if ( CanPublishInStudy( mesh ) )
1039 // little trick: for MED file theFileName and theFileNameForPython are the same, but they are different for SAUV
1040 // - as names of meshes are stored in MED file, we use them for data publishing
1041 // - as mesh name is not stored in UNV file, we use file name as name of mesh when publishing data
1042 aSO = PublishMesh( myCurrentStudy, mesh.in(), ( theFileName == theFileNameForPython ) ? (*it).c_str() : aFileName.c_str() );
1043 if ( !aSO->_is_nil() ) {
1048 aPythonDump << "mesh_" << i;
1051 // Read mesh data (groups are published automatically by ImportMEDFile())
1052 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1053 ASSERT( meshServant );
1054 SMESH::DriverMED_ReadStatus status1 =
1055 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
1056 if (status1 > theStatus)
1057 theStatus = status1;
1059 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
1060 meshServant->GetImpl().GetMeshDS()->Modified();
1062 aStudyBuilder->CommitCommand();
1065 // Update Python script
1066 aPythonDump << "], status) = " << this << "." << theCommandNameForPython << "(r'" << theFileNameForPython << "')";
1068 // Dump creation of groups
1069 for ( int i = 0; i < aResult->length(); ++i )
1070 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1072 return aResult._retn();
1075 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
1076 SMESH::DriverMED_ReadStatus& theStatus)
1077 throw ( SALOME::SALOME_Exception )
1079 Unexpect aCatch(SALOME_SalomeException);
1080 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
1081 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(theFileName, theStatus, "CreateMeshesFromMED", theFileName);
1085 //=============================================================================
1087 * SMESH_Gen_i::CreateMeshFromSAUV
1089 * Create mesh and import data from SAUV file
1091 //=============================================================================
1093 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName,
1094 SMESH::DriverMED_ReadStatus& theStatus)
1095 throw ( SALOME::SALOME_Exception )
1097 Unexpect aCatch(SALOME_SalomeException);
1098 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromSAUV" );
1099 std::string sauvfilename(theFileName);
1100 std::string medfilename(theFileName);
1101 medfilename += ".med";
1104 cmd = "%PYTHONBIN% ";
1109 cmd += "from medutilities import convert ; convert(r'" + sauvfilename + "', 'GIBI', 'MED', 1, r'" + medfilename + "')";
1111 system(cmd.c_str());
1112 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), theStatus, "CreateMeshesFromSAUV", sauvfilename.c_str());
1114 cmd = "%PYTHONBIN% ";
1119 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1121 system(cmd.c_str());
1125 //=============================================================================
1127 * SMESH_Gen_i::CreateMeshFromSTL
1129 * Create mesh and import data from STL file
1131 //=============================================================================
1133 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
1134 throw ( SALOME::SALOME_Exception )
1136 Unexpect aCatch(SALOME_SalomeException);
1137 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
1139 SMESH::SMESH_Mesh_var aMesh = createMesh();
1142 char bname[ _MAX_FNAME ];
1143 _splitpath( theFileName, NULL, NULL, bname, NULL );
1144 string aFileName = bname;
1146 string aFileName = basename( theFileName );
1148 // publish mesh in the study
1149 if ( CanPublishInStudy( aMesh ) ) {
1150 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1151 aStudyBuilder->NewCommand(); // There is a transaction
1152 SALOMEDS::SObject_wrap aSO = PublishInStudy
1153 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1154 aStudyBuilder->CommitCommand();
1155 if ( !aSO->_is_nil() ) {
1156 // Update Python script
1157 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL(r'" << theFileName << "')";
1161 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1163 aServant->ImportSTLFile( theFileName );
1164 aServant->GetImpl().GetMeshDS()->Modified();
1165 return aMesh._retn();
1168 //================================================================================
1170 * \brief Create meshes and import data from the CGSN file
1172 //================================================================================
1174 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName,
1175 SMESH::DriverMED_ReadStatus& theStatus)
1176 throw ( SALOME::SALOME_Exception )
1178 Unexpect aCatch(SALOME_SalomeException);
1180 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
1183 // Retrieve nb meshes from the file
1184 DriverCGNS_Read myReader;
1185 myReader.SetFile( theFileName );
1186 Driver_Mesh::Status aStatus;
1187 int nbMeshes = myReader.GetNbMeshes(aStatus);
1188 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1190 aResult->length( nbMeshes );
1192 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1195 TPythonDump aPythonDump;
1196 aPythonDump << "([";
1198 if (theStatus == SMESH::DRS_OK)
1200 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1201 aStudyBuilder->NewCommand(); // There is a transaction
1205 // Iterate through all meshes and create mesh objects
1206 for ( ; i < nbMeshes; ++i )
1209 if (i > 0) aPythonDump << ", ";
1212 SMESH::SMESH_Mesh_var mesh = createMesh();
1213 aResult[i] = SMESH::SMESH_Mesh::_duplicate( mesh );
1215 // Read mesh data (groups are published automatically by ImportMEDFile())
1216 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1217 ASSERT( meshServant );
1219 SMESH::DriverMED_ReadStatus status1 =
1220 meshServant->ImportCGNSFile( theFileName, i, meshName );
1221 if (status1 > theStatus)
1222 theStatus = status1;
1224 meshServant->GetImpl().GetMeshDS()->Modified();
1225 // publish mesh in the study
1226 SALOMEDS::SObject_wrap aSO;
1227 if ( CanPublishInStudy( mesh ) )
1228 aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() );
1231 if ( !aSO->_is_nil() ) {
1235 aPythonDump << "mesh_" << i;
1238 aStudyBuilder->CommitCommand();
1241 aPythonDump << "], status) = " << this << ".CreateMeshesFromCGNS(r'" << theFileName << "')";
1243 // Dump creation of groups
1244 for ( int i = 0; i < aResult->length(); ++i )
1245 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1247 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
1250 return aResult._retn();
1253 //================================================================================
1255 * \brief Create a mesh and import data from a GMF file
1257 //================================================================================
1259 SMESH::SMESH_Mesh_ptr
1260 SMESH_Gen_i::CreateMeshesFromGMF( const char* theFileName,
1261 CORBA::Boolean theMakeRequiredGroups,
1262 SMESH::ComputeError_out theError)
1263 throw ( SALOME::SALOME_Exception )
1265 Unexpect aCatch(SALOME_SalomeException);
1267 SMESH::SMESH_Mesh_var aMesh = createMesh();
1269 char bname[ _MAX_FNAME ];
1270 _splitpath( theFileName, NULL, NULL, bname, NULL );
1271 string aFileName = bname;
1273 string aFileName = basename( theFileName );
1275 // publish mesh in the study
1276 if ( CanPublishInStudy( aMesh ) ) {
1277 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1278 aStudyBuilder->NewCommand(); // There is a transaction
1279 SALOMEDS::SObject_wrap aSO = PublishInStudy
1280 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1281 aStudyBuilder->CommitCommand();
1282 if ( !aSO->_is_nil() ) {
1283 // Update Python script
1284 TPythonDump() << "("<< aSO << ", error) = " << this << ".CreateMeshesFromGMF(r'"
1285 << theFileName << "', "
1286 << theMakeRequiredGroups << " )";
1289 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1291 theError = aServant->ImportGMFFile( theFileName, theMakeRequiredGroups );
1292 aServant->GetImpl().GetMeshDS()->Modified();
1293 return aMesh._retn();
1297 //=============================================================================
1299 * SMESH_Gen_i::IsReadyToCompute
1301 * Returns true if mesh contains enough data to be computed
1303 //=============================================================================
1305 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
1306 GEOM::GEOM_Object_ptr theShapeObject )
1307 throw ( SALOME::SALOME_Exception )
1309 Unexpect aCatch(SALOME_SalomeException);
1310 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
1312 if ( CORBA::is_nil( theShapeObject ) )
1313 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1314 SALOME::BAD_PARAM );
1316 if ( CORBA::is_nil( theMesh ) )
1317 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1318 SALOME::BAD_PARAM );
1322 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1323 ASSERT( meshServant );
1324 if ( meshServant ) {
1325 // get local TopoDS_Shape
1326 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1327 // call implementation
1328 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1329 return myGen.CheckAlgoState( myLocMesh, myLocShape );
1332 catch ( SALOME_Exception& S_ex ) {
1333 INFOS( "catch exception "<< S_ex.what() );
1338 //================================================================================
1340 * \brief Find SObject for an algo
1342 //================================================================================
1344 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
1347 if ( !myCurrentStudy->_is_nil() ) {
1348 // find algo in the study
1349 CORBA::String_var compDataType = ComponentDataType();
1350 SALOMEDS::SComponent_wrap father = myCurrentStudy->FindComponent( compDataType.in() );
1351 if ( !father->_is_nil() ) {
1352 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( father );
1353 for ( ; itBig->More(); itBig->Next() ) {
1354 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
1355 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1356 SALOMEDS::ChildIterator_wrap algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1357 for ( ; algoIt->More(); algoIt->Next() ) {
1358 SALOMEDS::SObject_wrap algoSO = algoIt->Value();
1359 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1360 if ( !CORBA::is_nil( algoIOR )) {
1361 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1362 if ( impl && impl->GetImpl() == algo )
1363 return algoSO._retn();
1365 } // loop on algo SO's
1368 } // SMESH component iterator
1372 return SALOMEDS::SObject::_nil();
1375 //================================================================================
1377 * \brief Return errors of mesh computation
1379 //================================================================================
1381 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1382 GEOM::GEOM_Object_ptr theSubObject )
1383 throw ( SALOME::SALOME_Exception )
1385 Unexpect aCatch(SALOME_SalomeException);
1386 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1388 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1389 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1391 if ( CORBA::is_nil( theMesh ) )
1392 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1394 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1396 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1399 if(theMesh->HasShapeToMesh())
1400 shape = GeomObjectToShape( theSubObject );
1402 shape = SMESH_Mesh::PseudoShape();
1404 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1406 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1409 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1410 const bool includeSelf = true, complexShapeFirst = true;
1411 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1413 while ( smIt->more() )
1416 // if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1418 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1419 if ( error && !error->IsOK() && error->myAlgo )
1421 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1422 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1423 errStruct.comment = error->myComment.c_str();
1424 errStruct.subShapeID = sm->GetId();
1425 SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->myAlgo );
1426 if ( !algoSO->_is_nil() ) {
1427 CORBA::String_var algoName = algoSO->GetName();
1428 errStruct.algoName = algoName;
1431 errStruct.algoName = error->myAlgo->GetName();
1433 errStruct.hasBadMesh = !error->myBadElements.empty();
1436 error_array->length( nbErr );
1439 catch ( SALOME_Exception& S_ex ) {
1440 INFOS( "catch exception "<< S_ex.what() );
1443 return error_array._retn();
1446 //================================================================================
1448 * \brief Return mesh elements preventing computation of a subshape
1450 //================================================================================
1452 SMESH::MeshPreviewStruct*
1453 SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1454 CORBA::Short theSubShapeID )
1455 throw ( SALOME::SALOME_Exception )
1457 Unexpect aCatch(SALOME_SalomeException);
1458 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetBadInputElements()" );
1460 if ( CORBA::is_nil( theMesh ) )
1461 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1463 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1466 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1468 // mesh implementation
1469 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1470 // submesh by subshape id
1471 if ( SMESH_subMesh * sm = mesh.GetSubMeshContaining( theSubShapeID ))
1474 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1475 if ( error && !error->myBadElements.empty())
1477 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1478 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1480 // get nodes of elements and count elements
1481 TNode2LocalIDMap mapNode2LocalID;
1482 list< TNodeLocalID > connectivity;
1483 int i, nbElements = 0, nbConnNodes = 0;
1485 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
1486 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
1487 for ( ; elemIt != elemEnd; ++elemIt, ++nbElements )
1489 SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator();
1490 while ( nIt->more() )
1491 connectivity.push_back
1492 ( mapNode2LocalID.insert( make_pair( nIt->next(), ++nbConnNodes)).first );
1494 // fill node coords and assign local ids to the nodes
1495 int nbNodes = mapNode2LocalID.size();
1496 result->nodesXYZ.length( nbNodes );
1497 TNodeLocalID node2ID = mapNode2LocalID.begin();
1498 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1499 node2ID->second = i;
1500 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1501 result->nodesXYZ[i].x = node->X();
1502 result->nodesXYZ[i].y = node->Y();
1503 result->nodesXYZ[i].z = node->Z();
1505 // fill connectivity
1506 result->elementConnectivities.length( nbConnNodes );
1507 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1508 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1509 result->elementConnectivities[i] = (*connIt)->second;
1511 // fill element types
1512 result->elementTypes.length( nbElements );
1513 for ( i = 0, elemIt = error->myBadElements.begin(); i <nbElements; ++i, ++elemIt )
1515 const SMDS_MeshElement* elem = *elemIt;
1516 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType();
1517 result->elementTypes[i].isPoly = elem->IsPoly();
1518 result->elementTypes[i].nbNodesInElement = elem->NbNodes();
1524 catch ( SALOME_Exception& S_ex ) {
1525 INFOS( "catch exception "<< S_ex.what() );
1528 return result._retn();
1531 //================================================================================
1533 * \brief Create a group of elements preventing computation of a sub-shape
1535 //================================================================================
1537 SMESH::ListOfGroups*
1538 SMESH_Gen_i::MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1539 CORBA::Short theSubShapeID,
1540 const char* theGroupName )
1541 throw ( SALOME::SALOME_Exception )
1543 Unexpect aCatch(SALOME_SalomeException);
1545 SMESH::ListOfGroups_var groups;
1547 if ( CORBA::is_nil( theMesh ) )
1548 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1551 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1553 groups = meshServant->MakeGroupsOfBadInputElements( theSubShapeID, theGroupName );
1554 TPythonDump() << groups << " = " << this
1555 << ".MakeGroupsOfBadInputElements( "
1556 << theMesh << ", " << theSubShapeID << ", '" << theGroupName << "' )";
1559 catch ( SALOME_Exception& S_ex ) {
1560 INFOS( "catch exception "<< S_ex.what() );
1562 return groups._retn();
1565 //================================================================================
1567 * \brief Returns errors of hypotheses definintion
1568 * \param theMesh - the mesh
1569 * \param theSubObject - the main or sub- shape
1570 * \retval SMESH::algo_error_array* - sequence of errors
1572 //================================================================================
1574 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1575 GEOM::GEOM_Object_ptr theSubObject )
1576 throw ( SALOME::SALOME_Exception )
1578 Unexpect aCatch(SALOME_SalomeException);
1579 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1581 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1582 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1584 if ( CORBA::is_nil( theMesh ) )
1585 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1587 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1589 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1590 ASSERT( meshServant );
1591 if ( meshServant ) {
1592 TopoDS_Shape myLocShape;
1593 if(theMesh->HasShapeToMesh())
1594 myLocShape = GeomObjectToShape( theSubObject );
1596 myLocShape = SMESH_Mesh::PseudoShape();
1598 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1599 list< ::SMESH_Gen::TAlgoStateError > error_list;
1600 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1601 // call ::SMESH_Gen::GetAlgoState()
1602 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1603 error_array->length( error_list.size() );
1605 for ( error = error_list.begin(); error != error_list.end(); ++error )
1607 // fill AlgoStateError structure
1608 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1609 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1610 errStruct.algoDim = error->_algoDim;
1611 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1612 errStruct.algoName = "";
1613 SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->_algo );
1614 if ( !algoSO->_is_nil() ) {
1615 CORBA::String_var algoName = algoSO->GetName();
1616 errStruct.algoName = algoName.in();
1621 catch ( SALOME_Exception& S_ex ) {
1622 INFOS( "catch exception "<< S_ex.what() );
1624 return error_array._retn();
1627 //=============================================================================
1629 * SMESH_Gen_i::GetSubShapesId
1631 * Get sub-shapes unique ID's list
1633 //=============================================================================
1635 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1636 const SMESH::object_array& theListOfSubShapeObject )
1637 throw ( SALOME::SALOME_Exception )
1639 Unexpect aCatch(SALOME_SalomeException);
1640 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1642 SMESH::long_array_var shapesId = new SMESH::long_array;
1645 if ( CORBA::is_nil( theMainShapeObject ) )
1646 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1647 SALOME::BAD_PARAM );
1651 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1652 TopTools_IndexedMapOfShape myIndexToShape;
1653 TopExp::MapShapes(myMainShape,myIndexToShape);
1655 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1657 GEOM::GEOM_Object_var aShapeObject
1658 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1659 if ( CORBA::is_nil( aShapeObject ) )
1660 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1661 SALOME::BAD_PARAM );
1663 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1664 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1666 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1667 setId.insert(myIndexToShape.FindIndex(F));
1668 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1670 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1672 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1673 setId.insert(myIndexToShape.FindIndex(E));
1674 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1676 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1678 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1679 setId.insert(myIndexToShape.FindIndex(V));
1680 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1683 shapesId->length(setId.size());
1684 set<int>::iterator iind;
1686 for (iind = setId.begin(); iind != setId.end(); iind++)
1688 if(MYDEBUG) SCRUTE((*iind));
1689 shapesId[i] = (*iind);
1690 if(MYDEBUG) SCRUTE(shapesId[i]);
1694 catch (SALOME_Exception& S_ex)
1696 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1699 return shapesId._retn();
1702 //=============================================================================
1704 * SMESH_Gen_i::Compute
1706 * Compute mesh on a shape
1708 //=============================================================================
1710 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1711 GEOM::GEOM_Object_ptr theShapeObject )
1712 throw ( SALOME::SALOME_Exception )
1715 Unexpect aCatch(SALOME_SalomeException);
1716 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1718 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1719 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1720 SALOME::BAD_PARAM );
1722 if ( CORBA::is_nil( theMesh ) )
1723 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1724 SALOME::BAD_PARAM );
1726 // Update Python script
1727 TPythonDump() << "isDone = " << this << ".Compute( "
1728 << theMesh << ", " << theShapeObject << ")";
1732 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1733 meshServant->Load();
1734 ASSERT( meshServant );
1735 if ( meshServant ) {
1736 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1737 meshServant->CheckGeomGroupModif();
1738 // get local TopoDS_Shape
1739 TopoDS_Shape myLocShape;
1740 if(theMesh->HasShapeToMesh())
1741 myLocShape = GeomObjectToShape( theShapeObject );
1743 myLocShape = SMESH_Mesh::PseudoShape();
1744 // call implementation compute
1745 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1746 #ifdef WITH_SMESH_CANCEL_COMPUTE
1747 myGen.PrepareCompute( myLocMesh, myLocShape);
1749 bool ok = myGen.Compute( myLocMesh, myLocShape);
1750 meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
1751 myLocMesh.GetMeshDS()->Modified();
1755 catch ( std::bad_alloc ) {
1756 INFOS( "Compute(): lack of memory" );
1758 catch ( SALOME_Exception& S_ex ) {
1759 INFOS( "Compute(): catch exception "<< S_ex.what() );
1762 INFOS( "Compute(): unknown exception " );
1767 //=============================================================================
1769 * SMESH_Gen_i::CancelCompute
1771 * Cancel Compute mesh on a shape
1773 //=============================================================================
1775 void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
1776 GEOM::GEOM_Object_ptr theShapeObject )
1778 #ifdef WITH_SMESH_CANCEL_COMPUTE
1779 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1780 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1781 TopoDS_Shape myLocShape;
1782 if(theMesh->HasShapeToMesh())
1783 myLocShape = GeomObjectToShape( theShapeObject );
1785 myLocShape = SMESH_Mesh::PseudoShape();
1786 myGen.CancelCompute( myLocMesh, myLocShape);
1790 //=============================================================================
1792 * SMESH_Gen_i::Precompute
1794 * Compute mesh as preview till indicated dimension on shape
1796 //=============================================================================
1798 SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh,
1799 GEOM::GEOM_Object_ptr theShapeObject,
1800 SMESH::Dimension theDimension,
1801 SMESH::long_array& theShapesId)
1802 throw ( SALOME::SALOME_Exception )
1804 Unexpect aCatch(SALOME_SalomeException);
1805 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Precompute" );
1807 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1808 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1809 SALOME::BAD_PARAM );
1811 if ( CORBA::is_nil( theMesh ) )
1812 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1813 SALOME::BAD_PARAM );
1815 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1818 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1819 meshServant->Load();
1820 ASSERT( meshServant );
1821 if ( meshServant ) {
1822 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1823 meshServant->CheckGeomGroupModif();
1824 // get local TopoDS_Shape
1825 TopoDS_Shape myLocShape;
1826 if(theMesh->HasShapeToMesh())
1827 myLocShape = GeomObjectToShape( theShapeObject );
1829 return result._retn();;
1831 // call implementation compute
1832 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1834 ::MeshDimension aDim = (MeshDimension)theDimension;
1835 if ( myGen.Compute( myLocMesh, myLocShape, false, false, aDim, &shapeIds ) )
1837 int nbShapeId = shapeIds.size();
1838 theShapesId.length( nbShapeId );
1839 // iterates on shapes and collect mesh entities into mesh preview
1840 TSetOfInt::const_iterator idIt = shapeIds.begin();
1841 TSetOfInt::const_iterator idEnd = shapeIds.end();
1842 std::map< int, int > mapOfShIdNb;
1843 std::set< SMESH_TLink > setOfEdge;
1844 std::list< SMDSAbs_ElementType > listOfElemType;
1845 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1846 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1847 TNode2LocalIDMap mapNode2LocalID;
1848 list< TNodeLocalID > connectivity;
1849 int i, nbConnNodes = 0;
1850 std::set< const SMESH_subMesh* > setOfVSubMesh;
1851 // iterates on shapes
1852 for ( ; idIt != idEnd; idIt++ )
1854 if ( mapOfShIdNb.find( *idIt ) != mapOfShIdNb.end() )
1856 SMESH_subMesh* sm = myLocMesh.GetSubMeshContaining(*idIt);
1857 if ( !sm || !sm->IsMeshComputed() )
1860 const TopoDS_Shape& aSh = sm->GetSubShape();
1861 const int shDim = myGen.GetShapeDim( aSh );
1862 if ( shDim < 1 || shDim > theDimension )
1865 mapOfShIdNb[ *idIt ] = 0;
1866 theShapesId[ mapOfShIdNb.size() - 1 ] = *idIt;
1868 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1869 if ( !smDS ) continue;
1871 if ( theDimension == SMESH::DIM_2D )
1873 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1874 while ( faceIt->more() )
1876 const SMDS_MeshElement* face = faceIt->next();
1877 int aNbNode = face->NbNodes();
1879 aNbNode /= 2; // do not take into account additional middle nodes
1881 SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
1882 for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
1884 SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
1885 if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
1887 listOfElemType.push_back( SMDSAbs_Edge );
1888 connectivity.push_back
1889 ( mapNode2LocalID.insert( make_pair( node1, ++nbConnNodes)).first );
1890 connectivity.push_back
1891 ( mapNode2LocalID.insert( make_pair( node2, ++nbConnNodes)).first );
1897 else if ( theDimension == SMESH::DIM_1D )
1899 SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
1900 while ( nodeIt->more() )
1902 listOfElemType.push_back( SMDSAbs_Node );
1903 connectivity.push_back
1904 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1906 // add corner nodes by first vertex from edge
1907 SMESH_subMeshIteratorPtr edgeSmIt =
1908 sm->getDependsOnIterator(/*includeSelf*/false,
1909 /*complexShapeFirst*/false);
1910 while ( edgeSmIt->more() )
1912 SMESH_subMesh* vertexSM = edgeSmIt->next();
1913 // check that vertex is not already treated
1914 if ( !setOfVSubMesh.insert( vertexSM ).second )
1916 if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
1919 const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
1920 SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
1921 while ( nodeIt->more() )
1923 listOfElemType.push_back( SMDSAbs_Node );
1924 connectivity.push_back
1925 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1931 // fill node coords and assign local ids to the nodes
1932 int nbNodes = mapNode2LocalID.size();
1933 result->nodesXYZ.length( nbNodes );
1934 TNodeLocalID node2ID = mapNode2LocalID.begin();
1935 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1936 node2ID->second = i;
1937 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1938 result->nodesXYZ[i].x = node->X();
1939 result->nodesXYZ[i].y = node->Y();
1940 result->nodesXYZ[i].z = node->Z();
1942 // fill connectivity
1943 result->elementConnectivities.length( nbConnNodes );
1944 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1945 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1946 result->elementConnectivities[i] = (*connIt)->second;
1949 // fill element types
1950 result->elementTypes.length( listOfElemType.size() );
1951 std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
1952 std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
1953 for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
1955 SMDSAbs_ElementType elemType = *typeIt;
1956 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
1957 result->elementTypes[i].isPoly = false;
1958 result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
1961 // correct number of shapes
1962 theShapesId.length( mapOfShIdNb.size() );
1966 catch ( std::bad_alloc ) {
1967 INFOS( "Precompute(): lack of memory" );
1969 catch ( SALOME_Exception& S_ex ) {
1970 INFOS( "Precompute(): catch exception "<< S_ex.what() );
1973 INFOS( "Precompute(): unknown exception " );
1975 return result._retn();
1979 //=============================================================================
1981 * SMESH_Gen_i::Evaluate
1983 * Evaluate mesh on a shape
1985 //=============================================================================
1987 SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
1988 GEOM::GEOM_Object_ptr theShapeObject)
1989 // SMESH::long_array& theNbElems)
1990 throw ( SALOME::SALOME_Exception )
1992 Unexpect aCatch(SALOME_SalomeException);
1993 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
1995 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1996 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1997 SALOME::BAD_PARAM );
1999 if ( CORBA::is_nil( theMesh ) )
2000 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
2001 SALOME::BAD_PARAM );
2003 SMESH::long_array_var nbels = new SMESH::long_array;
2004 nbels->length(SMESH::Entity_Last);
2005 int i = SMESH::Entity_Node;
2006 for (; i < SMESH::Entity_Last; i++)
2009 // Update Python script
2010 TPythonDump() << "theNbElems = " << this << ".Evaluate( "
2011 << theMesh << ", " << theShapeObject << ")";
2015 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
2016 ASSERT( meshServant );
2017 if ( meshServant ) {
2018 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
2019 meshServant->CheckGeomGroupModif();
2020 // get local TopoDS_Shape
2021 TopoDS_Shape myLocShape;
2022 if(theMesh->HasShapeToMesh())
2023 myLocShape = GeomObjectToShape( theShapeObject );
2025 myLocShape = SMESH_Mesh::PseudoShape();
2026 // call implementation compute
2027 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
2028 MapShapeNbElems aResMap;
2029 /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
2030 MapShapeNbElemsItr anIt = aResMap.begin();
2031 for(; anIt!=aResMap.end(); anIt++) {
2032 const vector<int>& aVec = (*anIt).second;
2033 for(i = SMESH::Entity_Node; i < aVec.size(); i++) {
2034 int nbElem = aVec[i];
2035 if ( nbElem < 0 ) // algo failed, check that it has reported a message
2037 SMESH_subMesh* sm = anIt->first;
2038 SMESH_ComputeErrorPtr& error = sm->GetComputeError();
2039 const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
2040 if ( (algo && !error.get()) || error->IsOK() )
2041 error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
2045 nbels[i] += aVec[i];
2049 return nbels._retn();
2052 catch ( std::bad_alloc ) {
2053 INFOS( "Evaluate(): lack of memory" );
2055 catch ( SALOME_Exception& S_ex ) {
2056 INFOS( "Evaluate(): catch exception "<< S_ex.what() );
2059 INFOS( "Evaluate(): unknown exception " );
2062 return nbels._retn();
2065 //================================================================================
2067 * \brief Return geometrical object the given element is built on
2068 * \param theMesh - the mesh the element is in
2069 * \param theElementID - the element ID
2070 * \param theGeomName - the name of the result geom object if it is not yet published
2071 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object (no need to UnRegister())
2073 //================================================================================
2075 GEOM::GEOM_Object_ptr
2076 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2077 CORBA::Long theElementID,
2078 const char* theGeomName)
2079 throw ( SALOME::SALOME_Exception )
2081 Unexpect aCatch(SALOME_SalomeException);
2083 GEOM::GEOM_Object_wrap geom = FindGeometryByMeshElement(theMesh, theElementID);
2084 if ( !geom->_is_nil() ) {
2085 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2086 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2088 // try to find the corresponding SObject
2089 SALOMEDS::SObject_wrap SObj = ObjectToSObject( myCurrentStudy, geom.in() );
2090 if ( SObj->_is_nil() ) // submesh can be not found even if published
2092 // try to find published submesh
2093 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
2094 if ( !geom->IsMainShape() && list->length() == 1 ) {
2095 SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2096 SALOMEDS::ChildIterator_wrap it;
2097 if ( !mainSO->_is_nil() ) {
2098 it = myCurrentStudy->NewChildIterator( mainSO );
2100 if ( !it->_is_nil() ) {
2101 for ( it->InitEx(true); it->More(); it->Next() ) {
2102 SALOMEDS::SObject_wrap so = it->Value();
2103 CORBA::Object_var obj = SObjectToObject( so );
2104 GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
2105 if ( !subGeom->_is_nil() ) {
2106 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2107 if ( subList->length() == 1 && list[0] == subList[0] ) {
2117 if ( SObj->_is_nil() ) // publish a new subshape
2118 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
2120 // return only published geometry
2121 if ( !SObj->_is_nil() ) {
2122 //return geom._retn(); -- servant of geom must be UnRegister()ed;
2123 CORBA::Object_var obj = SObjectToObject( SObj );
2124 GEOM::GEOM_Object_var go = GEOM::GEOM_Object::_narrow( obj );
2128 return GEOM::GEOM_Object::_nil();
2131 //================================================================================
2133 * \brief Return geometrical object the given element is built on.
2134 * \param theMesh - the mesh the element is in
2135 * \param theElementID - the element ID
2136 * \retval GEOM::GEOM_Object_ptr - the found or created (UnRegister()!) geom object
2138 //================================================================================
2140 GEOM::GEOM_Object_ptr
2141 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2142 CORBA::Long theElementID)
2143 throw ( SALOME::SALOME_Exception )
2145 Unexpect aCatch(SALOME_SalomeException);
2146 if ( CORBA::is_nil( theMesh ) )
2147 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
2149 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2150 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2152 // get a core mesh DS
2153 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
2154 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
2156 ::SMESH_Mesh & mesh = meshServant->GetImpl();
2157 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
2158 // find the element in mesh
2159 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
2160 // find a shape id by the element
2161 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
2162 // get a geom object by the shape id
2163 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
2164 if ( geom->_is_nil() ) {
2165 // try to find a published sub-shape
2166 SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2167 SALOMEDS::ChildIterator_wrap it;
2168 if ( !mainSO->_is_nil() ) {
2169 it = myCurrentStudy->NewChildIterator( mainSO );
2171 if ( !it->_is_nil() ) {
2172 for ( it->InitEx(true); it->More(); it->Next() ) {
2173 SALOMEDS::SObject_wrap so = it->Value();
2174 CORBA::Object_var obj = SObjectToObject( so );
2175 GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
2176 if ( !subGeom->_is_nil() ) {
2177 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2178 if ( subList->length() == 1 && shapeID == subList[0] ) {
2186 if ( geom->_is_nil() ) {
2188 GEOM::GEOM_IShapesOperations_wrap op =
2189 geomGen->GetIShapesOperations( GetCurrentStudyID() );
2190 if ( !op->_is_nil() )
2191 geom = op->GetSubShape( mainShape, shapeID );
2196 if ( !geom->_is_nil() ) {
2197 GeomObjectToShape( geom ); // let geom client remember the found shape
2198 return geom._retn();
2203 return GEOM::GEOM_Object::_nil();
2206 //================================================================================
2208 * SMESH_Gen_i::Concatenate
2210 * Concatenate the given meshes into one mesh
2212 //================================================================================
2214 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
2215 CORBA::Boolean theUniteIdenticalGroups,
2216 CORBA::Boolean theMergeNodesAndElements,
2217 CORBA::Double theMergeTolerance)
2218 throw ( SALOME::SALOME_Exception )
2220 return ConcatenateCommon(theMeshesArray,
2221 theUniteIdenticalGroups,
2222 theMergeNodesAndElements,
2227 //================================================================================
2229 * SMESH_Gen_i::ConcatenateWithGroups
2231 * Concatenate the given meshes into one mesh
2232 * Create the groups of all elements from initial meshes
2234 //================================================================================
2236 SMESH::SMESH_Mesh_ptr
2237 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
2238 CORBA::Boolean theUniteIdenticalGroups,
2239 CORBA::Boolean theMergeNodesAndElements,
2240 CORBA::Double theMergeTolerance)
2241 throw ( SALOME::SALOME_Exception )
2243 return ConcatenateCommon(theMeshesArray,
2244 theUniteIdenticalGroups,
2245 theMergeNodesAndElements,
2250 //================================================================================
2252 * SMESH_Gen_i::ConcatenateCommon
2254 * Concatenate the given meshes into one mesh
2256 //================================================================================
2258 SMESH::SMESH_Mesh_ptr
2259 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
2260 CORBA::Boolean theUniteIdenticalGroups,
2261 CORBA::Boolean theMergeNodesAndElements,
2262 CORBA::Double theMergeTolerance,
2263 CORBA::Boolean theCommonGroups)
2264 throw ( SALOME::SALOME_Exception )
2266 typedef map<int, int> TIDsMap;
2267 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
2268 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
2269 typedef std::set<SMESHDS_GroupBase*> TGroups;
2271 TPythonDump* pPythonDump = new TPythonDump;
2272 TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
2275 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
2277 SMESHDS_Mesh* aNewMeshDS = 0;
2278 if ( !aNewMesh->_is_nil() ) {
2279 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
2281 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
2282 aNewMeshDS = aLocMesh.GetMeshDS();
2284 TGroupsMap aGroupsMap;
2285 TListOfNewGroups aListOfNewGroups;
2286 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
2287 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
2290 for ( int i = 0; i < theMeshesArray.length(); i++) {
2291 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
2292 if ( !anInitMesh->_is_nil() ) {
2293 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
2295 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
2296 aInitLocMesh.Load();
2297 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
2302 // loop on elements of mesh
2303 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
2304 const SMDS_MeshElement* anElem = 0;
2305 const SMDS_MeshElement* aNewElem = 0;
2306 int anElemNbNodes = 0;
2311 int anNbVolumes = 0;
2314 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
2315 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
2316 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
2317 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
2318 SMESH::long_array_var anIDsBalls = new SMESH::long_array();
2320 if( theCommonGroups ) {
2321 anIDsNodes->length( anInitMeshDS->NbNodes() );
2322 anIDsEdges->length( anInitMeshDS->NbEdges() );
2323 anIDsFaces->length( anInitMeshDS->NbFaces() );
2324 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
2325 anIDsBalls->length( anInitMeshDS->NbBalls() );
2328 for ( int j = 0; itElems->more(); j++) {
2329 anElem = itElems->next();
2330 SMDSAbs_ElementType anElemType = anElem->GetType();
2331 anElemNbNodes = anElem->NbNodes();
2332 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
2334 // loop on nodes of element
2335 const SMDS_MeshNode* aNode = 0;
2336 const SMDS_MeshNode* aNewNode = 0;
2337 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
2339 for ( int k = 0; itNodes->more(); k++) {
2340 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
2341 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
2342 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2343 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2344 if( theCommonGroups )
2345 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2348 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
2349 aNodesArray[k] = aNewNode;
2352 // creates a corresponding element on existent nodes in new mesh
2353 switch ( anElem->GetEntityType() ) {
2354 case SMDSEntity_Polyhedra:
2355 if ( const SMDS_VtkVolume* aVolume =
2356 dynamic_cast<const SMDS_VtkVolume*> (anElem))
2358 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
2359 aVolume->GetQuantities());
2360 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2361 if( theCommonGroups )
2362 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2365 case SMDSEntity_Ball:
2366 if ( const SMDS_BallElement* aBall =
2367 dynamic_cast<const SMDS_BallElement*> (anElem))
2369 aNewElem = aNewEditor.AddElement(aNodesArray, SMDSAbs_Ball,
2370 /*isPoly=*/false, /*id=*/0,
2371 aBall->GetDiameter() );
2372 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2373 if( theCommonGroups )
2374 anIDsBalls[aNbBalls++] = aNewElem->GetID();
2379 aNewElem = aNewEditor.AddElement(aNodesArray,
2382 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2383 if( theCommonGroups ) {
2384 if( anElemType == SMDSAbs_Edge )
2385 anIDsEdges[anNbEdges++] = aNewElem->GetID();
2386 else if( anElemType == SMDSAbs_Face )
2387 anIDsFaces[anNbFaces++] = aNewElem->GetID();
2388 else if( anElemType == SMDSAbs_Volume )
2389 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2395 // copy orphan nodes
2396 SMDS_NodeIteratorPtr itNodes = anInitMeshDS->nodesIterator();
2397 while ( itNodes->more() )
2399 const SMDS_MeshNode* aNode = itNodes->next();
2400 if ( aNode->NbInverseElements() == 0 )
2402 const SMDS_MeshNode* aNewNode =
2403 aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2404 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2405 if( theCommonGroups )
2406 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2411 aListOfGroups = anInitImpl->GetGroups();
2412 SMESH::SMESH_GroupBase_ptr aGroup;
2414 // loop on groups of mesh
2415 SMESH::long_array_var anInitIDs = new SMESH::long_array();
2416 SMESH::long_array_var anNewIDs = new SMESH::long_array();
2417 SMESH::SMESH_Group_var aNewGroup;
2419 SMESH::ElementType aGroupType;
2420 CORBA::String_var aGroupName;
2421 if ( theCommonGroups ) {
2422 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::BALL;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
2424 SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
2426 str += aMeshSObj->GetName();
2431 switch(aGroupType) {
2434 anIDsNodes->length(anNbNodes);
2439 anIDsEdges->length(anNbEdges);
2444 anIDsFaces->length(anNbFaces);
2449 anIDsVolumes->length(anNbVolumes);
2450 anLen = anNbVolumes;
2454 anIDsBalls->length(aNbBalls);
2462 aGroupName = str.c_str();
2464 // add a new group in the mesh
2465 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2467 switch(aGroupType) {
2469 aNewGroup->Add( anIDsNodes );
2472 aNewGroup->Add( anIDsEdges );
2475 aNewGroup->Add( anIDsFaces );
2478 aNewGroup->Add( anIDsVolumes );
2481 aNewGroup->Add( anIDsBalls );
2487 aListOfNewGroups.clear();
2488 aListOfNewGroups.push_back(aNewGroup);
2489 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2494 // check that current group name and type don't have identical ones in union mesh
2495 for (int iG = 0; iG < aListOfGroups->length(); iG++) {
2496 aGroup = aListOfGroups[iG];
2497 aListOfNewGroups.clear();
2498 aGroupType = aGroup->GetType();
2499 aGroupName = aGroup->GetName();
2501 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
2503 // convert a list of IDs
2504 anInitIDs = aGroup->GetListOfID();
2505 anNewIDs->length(anInitIDs->length());
2506 if ( aGroupType == SMESH::NODE )
2507 for (int j = 0; j < anInitIDs->length(); j++) {
2508 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
2511 for (int j = 0; j < anInitIDs->length(); j++) {
2512 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
2515 // check that current group name and type don't have identical ones in union mesh
2516 if ( anIter == aGroupsMap.end() ) {
2517 // add a new group in the mesh
2518 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2519 // add elements into new group
2520 aNewGroup->Add( anNewIDs );
2522 aListOfNewGroups.push_back(aNewGroup);
2523 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2526 else if ( theUniteIdenticalGroups ) {
2527 // unite identical groups
2528 TListOfNewGroups& aNewGroups = anIter->second;
2529 aNewGroups.front()->Add( anNewIDs );
2533 // rename identical groups
2534 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2535 aNewGroup->Add( anNewIDs );
2537 TListOfNewGroups& aNewGroups = anIter->second;
2538 string aNewGroupName;
2539 if (aNewGroups.size() == 1) {
2540 aNewGroupName = string(aGroupName) + "_1";
2541 aNewGroups.front()->SetName(aNewGroupName.c_str());
2543 char aGroupNum[128];
2544 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
2545 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
2546 aNewGroup->SetName(aNewGroupName.c_str());
2547 aNewGroups.push_back(aNewGroup);
2554 if (theMergeNodesAndElements) {
2556 TIDSortedNodeSet aMeshNodes; // no input nodes
2557 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
2558 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
2559 aNewEditor.MergeNodes( aGroupsOfNodes );
2561 aNewEditor.MergeEqualElements();
2566 // Update Python script
2567 aPythonDump << aNewMesh << " = " << this;
2568 if( !theCommonGroups )
2569 aPythonDump << ".Concatenate(";
2571 aPythonDump << ".ConcatenateWithGroups(";
2573 for ( int i = 0; i < theMeshesArray.length(); i++) {
2574 if (i > 0) aPythonDump << ", ";
2575 aPythonDump << theMeshesArray[i];
2577 aPythonDump << "], ";
2578 aPythonDump << theUniteIdenticalGroups << ", "
2579 << theMergeNodesAndElements << ", "
2580 << TVar( theMergeTolerance ) << ")";
2582 delete pPythonDump; // enable python dump from GetGroups()
2584 // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
2585 if ( !aNewMesh->_is_nil() )
2587 SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
2590 // IPAL21468 Change icon of compound because it need not be computed.
2591 SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
2592 SetPixMap( aMeshSObj, "ICON_SMESH_TREE_MESH" );
2595 aNewMeshDS->Modified();
2596 return aNewMesh._retn();
2599 //================================================================================
2601 * \brief Create a mesh by copying a part of another mesh
2602 * \param meshPart - a part of mesh to copy
2603 * \param toCopyGroups - to create in the new mesh groups
2604 * the copied elements belongs to
2605 * \param toKeepIDs - to preserve IDs of the copied elements or not
2606 * \retval SMESH::SMESH_Mesh_ptr - the new mesh
2608 //================================================================================
2610 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
2611 const char* meshName,
2612 CORBA::Boolean toCopyGroups,
2613 CORBA::Boolean toKeepIDs)
2615 Unexpect aCatch(SALOME_SalomeException);
2617 TPythonDump* pyDump = new TPythonDump; // prevent dump from CreateMesh()
2619 // 1. Get source mesh
2621 if ( CORBA::is_nil( meshPart ))
2622 THROW_SALOME_CORBA_EXCEPTION( "bad IDSource", SALOME::BAD_PARAM );
2624 SMESH::SMESH_Mesh_var srcMesh = meshPart->GetMesh();
2625 SMESH_Mesh_i* srcMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( srcMesh );
2627 THROW_SALOME_CORBA_EXCEPTION( "bad mesh of IDSource", SALOME::BAD_PARAM );
2629 SMESHDS_Mesh* srcMeshDS = srcMesh_i->GetImpl().GetMeshDS();
2631 // 2. Make a new mesh
2633 SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil());
2634 SMESH_Mesh_i* newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( newMesh );
2636 THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR );
2637 SALOMEDS::SObject_wrap meshSO = ObjectToSObject(myCurrentStudy, newMesh );
2638 if ( !meshSO->_is_nil() )
2640 SetName( meshSO, meshName, "Mesh" );
2641 SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
2643 SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
2644 ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
2646 // 3. Get elements to copy
2648 SMDS_ElemIteratorPtr srcElemIt; SMDS_NodeIteratorPtr srcNodeIt;
2649 TIDSortedElemSet srcElems;
2650 SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes();
2651 if ( SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
2653 srcElemIt = srcMeshDS->elementsIterator();
2654 srcNodeIt = srcMeshDS->nodesIterator();
2658 SMESH::long_array_var ids = meshPart->GetIDs();
2659 if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes
2661 for (int i=0; i < ids->length(); i++)
2662 if ( const SMDS_MeshElement * elem = srcMeshDS->FindNode( ids[i] ))
2663 srcElems.insert( elem );
2667 for (int i=0; i < ids->length(); i++)
2668 if ( const SMDS_MeshElement * elem = srcMeshDS->FindElement( ids[i] ))
2669 srcElems.insert( elem );
2671 if ( srcElems.empty() )
2672 return newMesh._retn();
2674 typedef SMDS_SetIterator< SMDS_pElement, TIDSortedElemSet::const_iterator > ElIter;
2675 srcElemIt = SMDS_ElemIteratorPtr( new ElIter( srcElems.begin(), srcElems.end() ));
2680 typedef map<SMDS_pElement, SMDS_pElement, TIDCompare> TE2EMap;
2681 TE2EMap e2eMapByType[ SMDSAbs_NbElementTypes ];
2682 TE2EMap& n2nMap = e2eMapByType[ SMDSAbs_Node ];
2684 const SMDS_MeshNode *nSrc, *nTgt;
2685 vector< const SMDS_MeshNode* > nodes;
2686 while ( srcElemIt->more() )
2688 const SMDS_MeshElement * elem = srcElemIt->next();
2690 nodes.resize( elem->NbNodes());
2691 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2693 for ( iN = 0; nIt->more(); ++iN )
2695 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2696 nTgt = newMeshDS->FindNode( nSrc->GetID());
2698 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2703 for ( iN = 0; nIt->more(); ++iN )
2705 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2706 TE2EMap::iterator n2n = n2nMap.insert( make_pair( nSrc, SMDS_pNode(0) )).first;
2708 n2n->second = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2709 nodes[ iN ] = (const SMDS_MeshNode*) n2n->second;
2713 if ( elem->GetType() != SMDSAbs_Node )
2715 int ID = toKeepIDs ? elem->GetID() : 0;
2716 const SMDS_MeshElement * newElem;
2717 switch ( elem->GetEntityType() ) {
2718 case SMDSEntity_Polyhedra:
2719 newElem = editor.GetMeshDS()->
2720 AddPolyhedralVolumeWithID( nodes,
2721 static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
2724 case SMDSEntity_Ball:
2725 newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID,
2726 static_cast<const SMDS_BallElement*>(elem)->GetDiameter());
2729 newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID);
2731 if ( toCopyGroups && !toKeepIDs )
2732 e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem ));
2735 } // while ( srcElemIt->more() )
2737 // 4(b). Copy free nodes
2739 if ( srcNodeIt && srcMeshDS->NbNodes() != newMeshDS->NbNodes() )
2741 while ( srcNodeIt->more() )
2743 nSrc = srcNodeIt->next();
2744 if ( nSrc->NbInverseElements() == 0 )
2747 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2749 n2nMap[ nSrc ] = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2756 int nbNewGroups = 0;
2759 SMESH_Mesh::GroupIteratorPtr gIt = srcMesh_i->GetImpl().GetGroups();
2760 while ( gIt->more() )
2762 SMESH_Group* group = gIt->next();
2763 const SMESHDS_GroupBase* groupDS = group->GetGroupDS();
2765 // Check group type. We copy nodal groups containing nodes of copied element
2766 SMDSAbs_ElementType groupType = groupDS->GetType();
2767 if ( groupType != SMDSAbs_Node &&
2768 newMeshDS->GetMeshInfo().NbElements( groupType ) == 0 )
2769 continue; // group type differs from types of meshPart
2771 // Find copied elements in the group
2772 vector< const SMDS_MeshElement* > groupElems;
2773 SMDS_ElemIteratorPtr eIt = groupDS->GetElements();
2776 const SMDS_MeshElement* foundElem;
2777 if ( groupType == SMDSAbs_Node )
2779 while ( eIt->more() )
2780 if (( foundElem = newMeshDS->FindNode( eIt->next()->GetID() )))
2781 groupElems.push_back( foundElem );
2785 while ( eIt->more() )
2786 if (( foundElem = newMeshDS->FindElement( eIt->next()->GetID() )))
2787 groupElems.push_back( foundElem );
2792 TE2EMap & e2eMap = e2eMapByType[ groupDS->GetType() ];
2793 if ( e2eMap.empty() ) continue;
2794 int minID = e2eMap.begin()->first->GetID();
2795 int maxID = e2eMap.rbegin()->first->GetID();
2796 TE2EMap::iterator e2e;
2797 while ( eIt->more() && groupElems.size() < e2eMap.size())
2799 const SMDS_MeshElement* e = eIt->next();
2800 if ( e->GetID() < minID || e->GetID() > maxID ) continue;
2801 if ((e2e = e2eMap.find( e )) != e2eMap.end())
2802 groupElems.push_back( e2e->second );
2806 if ( !groupElems.empty() )
2808 SMESH::SMESH_Group_var newGroupObj =
2809 newMesh->CreateGroup( SMESH::ElementType(groupType), group->GetName() );
2810 if ( SMESH_GroupBase_i* newGroup_i = SMESH::DownCast<SMESH_GroupBase_i*>( newGroupObj))
2812 SMESHDS_GroupBase * newGroupDS = newGroup_i->GetGroupDS();
2813 SMDS_MeshGroup& smdsGroup = ((SMESHDS_Group*)newGroupDS)->SMDSGroup();
2814 for ( unsigned i = 0; i < groupElems.size(); ++i )
2815 smdsGroup.Add( groupElems[i] );
2823 newMeshDS->Modified();
2825 *pyDump << newMesh << " = " << this
2826 << ".CopyMesh( " << meshPart << ", "
2827 << "'" << meshName << "', "
2828 << toCopyGroups << ", "
2829 << toKeepIDs << ")";
2831 delete pyDump; pyDump = 0; // allow dump in GetGroups()
2833 if ( nbNewGroups > 0 ) // dump created groups
2834 SMESH::ListOfGroups_var groups = newMesh->GetGroups();
2836 return newMesh._retn();
2839 //================================================================================
2841 * SMESH_Gen_i::GetMEDVersion
2843 * Get MED version of the file by its name
2845 //================================================================================
2846 CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
2847 SMESH::MED_VERSION& theVersion)
2849 theVersion = SMESH::MED_V2_1;
2850 MED::EVersion aVersion = MED::GetVersionId( theFileName );
2851 switch( aVersion ) {
2852 case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
2853 case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
2854 case MED::eVUnknown : return false;
2859 //================================================================================
2861 * SMESH_Gen_i::GetMeshNames
2863 * Get names of meshes defined in file with the specified name
2865 //================================================================================
2866 SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
2868 SMESH::string_array_var aResult = new SMESH::string_array();
2869 MED::PWrapper aMed = MED::CrWrapper( theFileName );
2871 MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
2873 aResult->length( aNbMeshes );
2874 for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
2875 MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
2876 aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
2879 return aResult._retn();
2882 //=============================================================================
2886 * Save SMESH module's data
2888 //=============================================================================
2889 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
2893 INFOS( "SMESH_Gen_i::Save" );
2895 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
2896 // san -- in case <myCurrentStudy> differs from theComponent's study,
2897 // use that of the component
2898 if ( myCurrentStudy->_is_nil() ||
2899 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2900 SetCurrentStudy( theComponent->GetStudy() );
2902 // Store study contents as a set of python commands
2903 SavePython(myCurrentStudy);
2905 StudyContext* myStudyContext = GetCurrentStudyContext();
2907 // Declare a byte stream
2908 SALOMEDS::TMPFile_var aStreamFile;
2910 // Obtain a temporary dir
2911 TCollection_AsciiString tmpDir =
2912 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2914 // Create a sequence of files processed
2915 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2916 aFileSeq->length( NUM_TMP_FILES );
2918 TCollection_AsciiString aStudyName( "" );
2920 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2922 // Set names of temporary files
2923 TCollection_AsciiString filename =
2924 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
2925 TCollection_AsciiString meshfile =
2926 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
2927 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
2928 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
2929 filename = tmpDir + filename;
2930 meshfile = tmpDir + meshfile;
2933 HDFdataset* aDataset;
2934 HDFgroup* aTopGroup;
2936 HDFgroup* aSubGroup;
2937 HDFgroup* aSubSubGroup;
2938 hdf_size aSize[ 1 ];
2941 //Remove the files if they exist: BugID: 11225
2942 #ifndef WNT /* unix functionality */
2943 TCollection_AsciiString cmd("rm -f \"");
2945 TCollection_AsciiString cmd("del /F \"");
2952 system(cmd.ToCString());
2954 // MED writer to be used by storage process
2955 DriverMED_W_SMESHDS_Mesh myWriter;
2956 myWriter.SetFile( meshfile.ToCString() );
2959 // SetStoreName() to groups before storing hypotheses to let them refer to
2960 // groups using "store name", which is "Group <group_persistent_id>"
2962 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
2963 for ( ; itBig->More(); itBig->Next() ) {
2964 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
2965 if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
2966 CORBA::Object_var anObject = SObjectToObject( gotBranch );
2967 if ( !CORBA::is_nil( anObject ) ) {
2968 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
2969 if ( !myMesh->_is_nil() ) {
2970 myMesh->Load(); // load from study file if not yet done
2971 TPythonDump pd; // not to dump GetGroups()
2972 SMESH::ListOfGroups_var groups = myMesh->GetGroups();
2973 pd << ""; // to avoid optimizing pd out
2974 for ( int i = 0; i < groups->length(); ++i )
2976 SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
2979 CORBA::String_var objStr = GetORB()->object_to_string( grImpl->_this() );
2980 int anId = myStudyContext->findId( string( objStr.in() ) );
2982 sprintf( grpName, "Group %d", anId );
2983 SMESHDS_GroupBase* aGrpBaseDS = grImpl->GetGroupDS();
2984 aGrpBaseDS->SetStoreName( grpName );
2994 // ---> create HDF file
2995 aFile = new HDFfile( (char*) filename.ToCString() );
2996 aFile->CreateOnDisk();
2998 // --> iterator for top-level objects
2999 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
3000 for ( ; itBig->More(); itBig->Next() ) {
3001 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
3003 // --> hypotheses root branch (only one for the study)
3004 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
3005 // create hypotheses root HDF group
3006 aTopGroup = new HDFgroup( "Hypotheses", aFile );
3007 aTopGroup->CreateOnDisk();
3009 // iterator for all hypotheses
3010 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
3011 for ( ; it->More(); it->Next() ) {
3012 SALOMEDS::SObject_wrap mySObject = it->Value();
3013 CORBA::Object_var anObject = SObjectToObject( mySObject );
3014 if ( !CORBA::is_nil( anObject ) ) {
3015 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
3016 if ( !myHyp->_is_nil() ) {
3017 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3019 string hypname = string( myHyp->GetName() );
3020 string libname = string( myHyp->GetLibName() );
3022 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
3023 // WNT and ".so" for X-system) must be deleted
3024 int libname_len = libname.length();
3026 if( libname_len > 4 )
3027 libname.resize( libname_len - 4 );
3029 // PAL17753 (Regresion: missing hypothesis in restored study)
3030 // "lib" also should be removed from the beginning
3031 //if( libname_len > 3 )
3032 //libname.resize( libname_len - 3 );
3033 if( libname_len > 6 )
3034 libname = libname.substr( 3, libname_len - 3 - 3 );
3036 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3037 int id = myStudyContext->findId( string( objStr.in() ) );
3038 string hypdata = string( myImpl->SaveTo() );
3040 // for each hypothesis create HDF group basing on its id
3041 char hypGrpName[30];
3042 sprintf( hypGrpName, "Hypothesis %d", id );
3043 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3044 aGroup->CreateOnDisk();
3045 // --> type name of hypothesis
3046 aSize[ 0 ] = hypname.length() + 1;
3047 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3048 aDataset->CreateOnDisk();
3049 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3050 aDataset->CloseOnDisk();
3051 // --> server plugin library name of hypothesis
3052 aSize[ 0 ] = libname.length() + 1;
3053 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3054 aDataset->CreateOnDisk();
3055 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3056 aDataset->CloseOnDisk();
3057 // --> persistent data of hypothesis
3058 aSize[ 0 ] = hypdata.length() + 1;
3059 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3060 aDataset->CreateOnDisk();
3061 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3062 aDataset->CloseOnDisk();
3063 // close hypothesis HDF group
3064 aGroup->CloseOnDisk();
3069 // close hypotheses root HDF group
3070 aTopGroup->CloseOnDisk();
3072 // --> algorithms root branch (only one for the study)
3073 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
3074 // create algorithms root HDF group
3075 aTopGroup = new HDFgroup( "Algorithms", aFile );
3076 aTopGroup->CreateOnDisk();
3078 // iterator for all algorithms
3079 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
3080 for ( ; it->More(); it->Next() ) {
3081 SALOMEDS::SObject_wrap mySObject = it->Value();
3082 CORBA::Object_var anObject = SObjectToObject( mySObject );
3083 if ( !CORBA::is_nil( anObject ) ) {
3084 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
3085 if ( !myHyp->_is_nil() ) {
3086 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3088 string hypname = string( myHyp->GetName() );
3089 string libname = string( myHyp->GetLibName() );
3091 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
3092 // WNT and ".so" for X-system) must be deleted
3093 int libname_len = libname.length();
3095 if( libname_len > 4 )
3096 libname.resize( libname_len - 4 );
3098 // PAL17753 (Regresion: missing hypothesis in restored study)
3099 // "lib" also should be removed from the beginning
3100 //if( libname_len > 3 )
3101 //libname.resize( libname_len - 3 );
3102 if( libname_len > 6 )
3103 libname = libname.substr( 3, libname_len - 3 - 3 );
3105 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3106 int id = myStudyContext->findId( string( objStr.in() ) );
3107 string hypdata = string( myImpl->SaveTo() );
3109 // for each algorithm create HDF group basing on its id
3110 char hypGrpName[30];
3111 sprintf( hypGrpName, "Algorithm %d", id );
3112 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3113 aGroup->CreateOnDisk();
3114 // --> type name of algorithm
3115 aSize[0] = hypname.length() + 1;
3116 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3117 aDataset->CreateOnDisk();
3118 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3119 aDataset->CloseOnDisk();
3120 // --> server plugin library name of hypothesis
3121 aSize[0] = libname.length() + 1;
3122 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3123 aDataset->CreateOnDisk();
3124 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3125 aDataset->CloseOnDisk();
3126 // --> persistent data of algorithm
3127 aSize[0] = hypdata.length() + 1;
3128 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3129 aDataset->CreateOnDisk();
3130 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3131 aDataset->CloseOnDisk();
3132 // close algorithm HDF group
3133 aGroup->CloseOnDisk();
3138 // close algorithms root HDF group
3139 aTopGroup->CloseOnDisk();
3141 // --> mesh objects roots branches
3142 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
3143 CORBA::Object_var anObject = SObjectToObject( gotBranch );
3144 if ( !CORBA::is_nil( anObject ) ) {
3145 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
3146 if ( !myMesh->_is_nil() ) {
3147 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
3149 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3150 int id = myStudyContext->findId( string( objStr.in() ) );
3151 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
3152 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3153 bool hasShape = myLocMesh.HasShapeToMesh();
3155 // for each mesh open the HDF group basing on its id
3156 char meshGrpName[ 30 ];
3157 sprintf( meshGrpName, "Mesh %d", id );
3158 aTopGroup = new HDFgroup( meshGrpName, aFile );
3159 aTopGroup->CreateOnDisk();
3161 // --> put dataset to hdf file which is a flag that mesh has data
3162 string strHasData = "0";
3163 // check if the mesh is not empty
3164 if ( mySMESHDSMesh->NbNodes() > 0 ) {
3165 // write mesh data to med file
3166 myWriter.SetMesh( mySMESHDSMesh );
3167 myWriter.SetMeshId( id );
3170 aSize[ 0 ] = strHasData.length() + 1;
3171 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
3172 aDataset->CreateOnDisk();
3173 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
3174 aDataset->CloseOnDisk();
3177 // for each mesh open the HDF group basing on its auto color parameter
3178 char meshAutoColorName[ 30 ];
3179 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
3181 anAutoColor[0] = myImpl->GetAutoColor();
3183 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
3184 aDataset->CreateOnDisk();
3185 aDataset->WriteOnDisk( anAutoColor );
3186 aDataset->CloseOnDisk();
3188 // issue 0020693. Store _isModified flag
3189 int isModified = myLocMesh.GetIsModified();
3191 aDataset = new HDFdataset( "_isModified", aTopGroup, HDF_INT32, aSize, 1 );
3192 aDataset->CreateOnDisk();
3193 aDataset->WriteOnDisk( &isModified );
3194 aDataset->CloseOnDisk();
3196 // issue 20918. Store Persistent Id of SMESHDS_Mesh
3197 int meshPersistentId = mySMESHDSMesh->GetPersistentId();
3199 aDataset = new HDFdataset( "meshPersistentId", aTopGroup, HDF_INT32, aSize, 1 );
3200 aDataset->CreateOnDisk();
3201 aDataset->WriteOnDisk( &meshPersistentId );
3202 aDataset->CloseOnDisk();
3204 // write reference on a shape if exists
3205 SALOMEDS::SObject_wrap myRef;
3206 bool shapeRefFound = false;
3207 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef.inout() );
3209 SALOMEDS::SObject_wrap myShape;
3210 bool ok = myRef->ReferencedObject( myShape.inout() );
3212 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
3213 string myRefOnObject = myShape->GetID();
3214 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
3215 aSize[ 0 ] = myRefOnObject.length() + 1;
3216 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
3217 aDataset->CreateOnDisk();
3218 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3219 aDataset->CloseOnDisk();
3224 // write applied hypotheses if exist
3225 SALOMEDS::SObject_wrap myHypBranch;
3226 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() );
3227 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
3228 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
3230 if ( found && (shapeRefFound || !hasShape) ) {
3231 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3232 aGroup->CreateOnDisk();
3234 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myHypBranch );
3236 for ( ; it->More(); it->Next() ) {
3237 SALOMEDS::SObject_wrap mySObject = it->Value();
3238 SALOMEDS::SObject_wrap myRefOnHyp;
3239 bool ok = mySObject->ReferencedObject( myRefOnHyp.inout() );
3241 // san - it is impossible to recover applied hypotheses
3242 // using their entries within Load() method,
3243 // for there are no AttributeIORs in the study when Load() is working.
3244 // Hence, it is better to store persistent IDs of hypotheses as references to them
3246 //string myRefOnObject = myRefOnHyp->GetID();
3247 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3248 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3249 int id = myStudyContext->findId( string( objStr.in() ) );
3250 //if ( myRefOnObject.length() > 0 ) {
3251 //aSize[ 0 ] = myRefOnObject.length() + 1;
3252 char hypName[ 30 ], hypId[ 30 ];
3253 sprintf( hypName, "Hyp %d", ++hypNb );
3254 sprintf( hypId, "%d", id );
3255 aSize[ 0 ] = strlen( hypId ) + 1;
3256 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
3257 aDataset->CreateOnDisk();
3258 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3259 aDataset->WriteOnDisk( hypId );
3260 aDataset->CloseOnDisk();
3264 aGroup->CloseOnDisk();
3267 // write applied algorithms if exist
3268 SALOMEDS::SObject_wrap myAlgoBranch;
3269 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
3270 myAlgoBranch.inout() );
3271 if ( found && !shapeRefFound && hasShape) { // remove applied algos
3272 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
3274 if ( found && (shapeRefFound || !hasShape)) {
3275 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3276 aGroup->CreateOnDisk();
3278 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myAlgoBranch );
3280 for ( ; it->More(); it->Next() ) {
3281 SALOMEDS::SObject_wrap mySObject = it->Value();
3282 SALOMEDS::SObject_wrap myRefOnAlgo;
3283 bool ok = mySObject->ReferencedObject( myRefOnAlgo.inout() );
3285 // san - it is impossible to recover applied algorithms
3286 // using their entries within Load() method,
3287 // for there are no AttributeIORs in the study when Load() is working.
3288 // Hence, it is better to store persistent IDs of algorithms as references to them
3290 //string myRefOnObject = myRefOnAlgo->GetID();
3291 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3292 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3293 int id = myStudyContext->findId( string( objStr.in() ) );
3294 //if ( myRefOnObject.length() > 0 ) {
3295 //aSize[ 0 ] = myRefOnObject.length() + 1;
3296 char algoName[ 30 ], algoId[ 30 ];
3297 sprintf( algoName, "Algo %d", ++algoNb );
3298 sprintf( algoId, "%d", id );
3299 aSize[ 0 ] = strlen( algoId ) + 1;
3300 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
3301 aDataset->CreateOnDisk();
3302 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3303 aDataset->WriteOnDisk( algoId );
3304 aDataset->CloseOnDisk();
3308 aGroup->CloseOnDisk();
3311 // --> submesh objects sub-branches
3313 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
3314 SALOMEDS::SObject_wrap mySubmeshBranch;
3315 found = gotBranch->FindSubObject( i, mySubmeshBranch.inout() );
3317 if ( found ) // check if there is shape reference in submeshes
3319 bool hasShapeRef = false;
3320 SALOMEDS::ChildIterator_wrap itSM =
3321 myCurrentStudy->NewChildIterator( mySubmeshBranch );
3322 for ( ; itSM->More(); itSM->Next() ) {
3323 SALOMEDS::SObject_wrap mySubRef, myShape, mySObject = itSM->Value();
3324 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
3325 mySubRef->ReferencedObject( myShape.inout() );
3326 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
3329 { // remove one submesh
3330 if ( shapeRefFound )
3331 { // unassign hypothesis
3332 SMESH::SMESH_subMesh_var mySubMesh =
3333 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
3334 if ( !mySubMesh->_is_nil() ) {
3335 int shapeID = mySubMesh->GetId();
3336 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
3337 const list<const SMESHDS_Hypothesis*>& hypList =
3338 mySMESHDSMesh->GetHypothesis( S );
3339 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
3340 while ( hyp != hypList.end() ) {
3341 int hypID = (*hyp++)->GetID(); // goto next hyp here because
3342 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
3346 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
3348 } // loop on submeshes of a type
3349 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
3350 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
3353 } // end check if there is shape reference in submeshes
3355 char name_meshgroup[ 30 ];
3356 if ( i == GetSubMeshOnVertexTag() )
3357 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3358 else if ( i == GetSubMeshOnEdgeTag() )
3359 strcpy( name_meshgroup, "SubMeshes On Edge" );
3360 else if ( i == GetSubMeshOnWireTag() )
3361 strcpy( name_meshgroup, "SubMeshes On Wire" );
3362 else if ( i == GetSubMeshOnFaceTag() )
3363 strcpy( name_meshgroup, "SubMeshes On Face" );
3364 else if ( i == GetSubMeshOnShellTag() )
3365 strcpy( name_meshgroup, "SubMeshes On Shell" );
3366 else if ( i == GetSubMeshOnSolidTag() )
3367 strcpy( name_meshgroup, "SubMeshes On Solid" );
3368 else if ( i == GetSubMeshOnCompoundTag() )
3369 strcpy( name_meshgroup, "SubMeshes On Compound" );
3371 // for each type of submeshes create container HDF group
3372 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3373 aGroup->CreateOnDisk();
3375 // iterator for all submeshes of given type
3376 SALOMEDS::ChildIterator_wrap itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
3377 for ( ; itSM->More(); itSM->Next() ) {
3378 SALOMEDS::SObject_wrap mySObject = itSM->Value();
3379 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
3380 if ( !CORBA::is_nil( anSubObject ))
3382 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
3383 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
3384 int subid = myStudyContext->findId( string( objStr.in() ) );
3386 // for each mesh open the HDF group basing on its id
3387 char submeshGrpName[ 30 ];
3388 sprintf( submeshGrpName, "SubMesh %d", subid );
3389 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
3390 aSubGroup->CreateOnDisk();
3392 // write reference on a shape, already checked if it exists
3393 SALOMEDS::SObject_wrap mySubRef, myShape;
3394 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
3395 mySubRef->ReferencedObject( myShape.inout() );
3396 string myRefOnObject = myShape->GetID();
3397 if ( myRefOnObject.length() > 0 ) {
3398 aSize[ 0 ] = myRefOnObject.length() + 1;
3399 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
3400 aDataset->CreateOnDisk();
3401 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3402 aDataset->CloseOnDisk();
3405 // write applied hypotheses if exist
3406 SALOMEDS::SObject_wrap mySubHypBranch;
3407 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(),
3408 mySubHypBranch.inout() );
3410 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3411 aSubSubGroup->CreateOnDisk();
3413 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( mySubHypBranch );
3415 for ( ; it->More(); it->Next() ) {
3416 SALOMEDS::SObject_wrap mySubSObject = it->Value();
3417 SALOMEDS::SObject_wrap myRefOnHyp;
3418 bool ok = mySubSObject->ReferencedObject( myRefOnHyp.inout() );
3420 //string myRefOnObject = myRefOnHyp->GetID();
3421 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3422 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3423 int id = myStudyContext->findId( string( objStr.in() ) );
3424 //if ( myRefOnObject.length() > 0 ) {
3425 //aSize[ 0 ] = myRefOnObject.length() + 1;
3426 char hypName[ 30 ], hypId[ 30 ];
3427 sprintf( hypName, "Hyp %d", ++hypNb );
3428 sprintf( hypId, "%d", id );
3429 aSize[ 0 ] = strlen( hypId ) + 1;
3430 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
3431 aDataset->CreateOnDisk();
3432 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3433 aDataset->WriteOnDisk( hypId );
3434 aDataset->CloseOnDisk();
3438 aSubSubGroup->CloseOnDisk();
3441 // write applied algorithms if exist
3442 SALOMEDS::SObject_wrap mySubAlgoBranch;
3443 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
3444 mySubAlgoBranch.inout() );
3446 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3447 aSubSubGroup->CreateOnDisk();
3449 SALOMEDS::ChildIterator_wrap it =
3450 myCurrentStudy->NewChildIterator( mySubAlgoBranch );
3452 for ( ; it->More(); it->Next() ) {
3453 SALOMEDS::SObject_wrap mySubSObject = it->Value();
3454 SALOMEDS::SObject_wrap myRefOnAlgo;
3455 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo.inout() );
3457 //string myRefOnObject = myRefOnAlgo->GetID();
3458 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3459 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3460 int id = myStudyContext->findId( string( objStr.in() ) );
3461 //if ( myRefOnObject.length() > 0 ) {
3462 //aSize[ 0 ] = myRefOnObject.length() + 1;
3463 char algoName[ 30 ], algoId[ 30 ];
3464 sprintf( algoName, "Algo %d", ++algoNb );
3465 sprintf( algoId, "%d", id );
3466 aSize[ 0 ] = strlen( algoId ) + 1;
3467 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
3468 aDataset->CreateOnDisk();
3469 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3470 aDataset->WriteOnDisk( algoId );
3471 aDataset->CloseOnDisk();
3475 aSubSubGroup->CloseOnDisk();
3477 // close submesh HDF group
3478 aSubGroup->CloseOnDisk();
3481 // close container of submeshes by type HDF group
3482 aGroup->CloseOnDisk();
3485 // All sub-meshes will be stored in MED file
3486 // .. will NOT (PAL 12992)
3487 //if ( shapeRefFound )
3488 //myWriter.AddAllSubMeshes();
3490 // store submesh order if any
3491 const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
3492 if ( theOrderIds.size() ) {
3493 char order_list[ 30 ];
3494 strcpy( order_list, "Mesh Order" );
3495 // count number of submesh ids
3497 TListOfListOfInt::const_iterator idIt = theOrderIds.begin();
3498 for ( ; idIt != theOrderIds.end(); idIt++ )
3499 nbIDs += (*idIt).size();
3500 // number of values = number of IDs +
3501 // number of lists (for separators) - 1
3502 int* smIDs = new int [ nbIDs + theOrderIds.size() - 1 ];
3503 idIt = theOrderIds.begin();
3504 for ( int i = 0; idIt != theOrderIds.end(); idIt++ ) {
3505 const TListOfInt& idList = *idIt;
3506 if (idIt != theOrderIds.begin()) // not first list
3507 smIDs[ i++ ] = -1/* *idList.size()*/; // separator between lists
3508 // dump submesh ids from current list
3509 TListOfInt::const_iterator id_smId = idList.begin();
3510 for( ; id_smId != idList.end(); id_smId++ )
3511 smIDs[ i++ ] = *id_smId;
3514 aSize[ 0 ] = nbIDs + theOrderIds.size() - 1;
3516 aDataset = new HDFdataset( order_list, aTopGroup, HDF_INT32, aSize, 1 );
3517 aDataset->CreateOnDisk();
3518 aDataset->WriteOnDisk( smIDs );
3519 aDataset->CloseOnDisk();
3524 // groups root sub-branch
3525 SALOMEDS::SObject_wrap myGroupsBranch;
3526 for ( int i = GetNodeGroupsTag(); i <= GetBallElementsGroupsTag(); i++ ) {
3527 found = gotBranch->FindSubObject( i, myGroupsBranch.inout() );
3529 char name_group[ 30 ];
3530 if ( i == GetNodeGroupsTag() )
3531 strcpy( name_group, "Groups of Nodes" );
3532 else if ( i == GetEdgeGroupsTag() )
3533 strcpy( name_group, "Groups of Edges" );
3534 else if ( i == GetFaceGroupsTag() )
3535 strcpy( name_group, "Groups of Faces" );
3536 else if ( i == GetVolumeGroupsTag() )
3537 strcpy( name_group, "Groups of Volumes" );
3538 else if ( i == Get0DElementsGroupsTag() )
3539 strcpy( name_group, "Groups of 0D Elements" );
3540 else if ( i == GetBallElementsGroupsTag() )
3541 strcpy( name_group, "Groups of Balls" );
3543 aGroup = new HDFgroup( name_group, aTopGroup );
3544 aGroup->CreateOnDisk();
3546 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myGroupsBranch );
3547 for ( ; it->More(); it->Next() ) {
3548 SALOMEDS::SObject_wrap mySObject = it->Value();
3549 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
3550 if ( !CORBA::is_nil( aSubObject ) ) {
3551 SMESH_GroupBase_i* myGroupImpl =
3552 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
3555 SMESHDS_GroupBase* aGrpBaseDS = myGroupImpl->GetGroupDS();
3559 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
3560 int anId = myStudyContext->findId( string( objStr.in() ) );
3562 // For each group, create a dataset named "Group <group_persistent_id>"
3563 // and store the group's user name into it
3564 const char* grpName = aGrpBaseDS->GetStoreName();
3565 char* aUserName = myGroupImpl->GetName();
3566 aSize[ 0 ] = strlen( aUserName ) + 1;
3568 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
3569 aDataset->CreateOnDisk();
3570 aDataset->WriteOnDisk( aUserName );
3571 aDataset->CloseOnDisk();
3574 // For each group, create a dataset named "Group <group_persistent_id> Color"
3575 // and store the group's color into it
3576 char grpColorName[ 30 ];
3577 sprintf( grpColorName, "ColorGroup %d", anId );
3578 SALOMEDS::Color aColor = myGroupImpl->GetColor();
3580 anRGB[ 0 ] = aColor.R;
3581 anRGB[ 1 ] = aColor.G;
3582 anRGB[ 2 ] = aColor.B;
3584 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
3585 aDataset->CreateOnDisk();
3586 aDataset->WriteOnDisk( anRGB );
3587 aDataset->CloseOnDisk();
3589 // Pass SMESHDS_Group to MED writer
3590 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
3592 myWriter.AddGroup( aGrpDS );
3594 // write reference on a shape if exists
3595 SMESHDS_GroupOnGeom* aGeomGrp =
3596 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
3598 SALOMEDS::SObject_wrap mySubRef, myShape;
3599 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ) &&
3600 mySubRef->ReferencedObject( myShape.inout() ) &&
3601 !CORBA::is_nil( myShape->GetObject() ))
3603 string myRefOnObject = myShape->GetID();
3604 if ( myRefOnObject.length() > 0 ) {
3605 char aRefName[ 30 ];
3606 sprintf( aRefName, "Ref on shape %d", anId);
3607 aSize[ 0 ] = myRefOnObject.length() + 1;
3608 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
3609 aDataset->CreateOnDisk();
3610 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3611 aDataset->CloseOnDisk();
3614 else // shape ref is invalid:
3616 // save a group on geometry as ordinary group
3617 myWriter.AddGroup( aGeomGrp );
3620 else if ( SMESH_GroupOnFilter_i* aFilterGrp_i =
3621 dynamic_cast<SMESH_GroupOnFilter_i*>( myGroupImpl ))
3623 std::string str = aFilterGrp_i->FilterToString();
3624 std::string hdfGrpName = "Filter " + SMESH_Comment(anId);
3625 aSize[ 0 ] = str.length() + 1;
3626 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup, HDF_STRING, aSize, 1);
3627 aDataset->CreateOnDisk();
3628 aDataset->WriteOnDisk( ( char* )( str.c_str() ) );
3629 aDataset->CloseOnDisk();
3633 aGroup->CloseOnDisk();
3637 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
3639 // Flush current mesh information into MED file
3642 // save info on nb of elements
3643 SMESH_PreMeshInfo::SaveToFile( myImpl, id, aFile );
3645 // maybe a shape was deleted in the study
3646 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
3647 TopoDS_Shape nullShape;
3648 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
3651 if ( !mySMESHDSMesh->SubMeshes().empty() )
3655 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3656 aGroup->CreateOnDisk();
3658 // each element belongs to one or none submesh,
3659 // so for each node/element, we store a submesh ID
3661 // Make maps of submesh IDs of elements sorted by element IDs
3662 typedef int TElemID;
3663 typedef int TSubMID;
3664 map< TElemID, TSubMID > eId2smId, nId2smId;
3665 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
3666 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
3667 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
3668 SMDS_NodeIteratorPtr itNode;
3669 SMDS_ElemIteratorPtr itElem;
3670 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3672 TSubMID aSubMeID = itSubM->first;
3673 SMESHDS_SubMesh* aSubMesh = itSubM->second;
3674 if ( aSubMesh->IsComplexSubmesh() )
3675 continue; // submesh containing other submeshs
3677 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
3678 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
3679 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
3681 hint = eId2smId.begin();
3682 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
3683 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
3686 // Care of elements that are not on submeshes
3687 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
3688 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
3689 /* --- stl_map.h says : */
3690 /* A %map relies on unique keys and thus a %pair is only inserted if its */
3691 /* first element (the key) is not already present in the %map. */
3692 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
3694 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
3695 if ( nbElems != eId2smId.size() ) {
3696 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
3697 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
3700 // Store submesh IDs
3701 for ( int isNode = 0; isNode < 2; ++isNode )
3703 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
3704 if ( id2smId.empty() ) continue;
3705 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
3706 // make and fill array of submesh IDs
3707 int* smIDs = new int [ id2smId.size() ];
3708 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
3709 smIDs[ i ] = id_smId->second;
3711 aSize[ 0 ] = id2smId.size();
3712 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3713 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3714 aDataset->CreateOnDisk();
3715 aDataset->WriteOnDisk( smIDs );
3716 aDataset->CloseOnDisk();
3721 aGroup->CloseOnDisk();
3723 // Store node positions on sub-shapes (SMDS_Position):
3724 // ----------------------------------------------------
3726 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3727 aGroup->CreateOnDisk();
3729 // in aGroup, create 5 datasets to contain:
3730 // "Nodes on Edges" - ID of node on edge
3731 // "Edge positions" - U parameter on node on edge
3732 // "Nodes on Faces" - ID of node on face
3733 // "Face U positions" - U parameter of node on face
3734 // "Face V positions" - V parameter of node on face
3736 // Find out nb of nodes on edges and faces
3737 // Collect corresponing sub-meshes
3738 int nbEdgeNodes = 0, nbFaceNodes = 0;
3739 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
3740 // loop on SMESHDS_SubMesh'es
3741 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3743 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
3744 if ( aSubMesh->IsComplexSubmesh() )
3745 continue; // submesh containing other submeshs
3746 int nbNodes = aSubMesh->NbNodes();
3747 if ( nbNodes == 0 ) continue;
3749 int aShapeID = (*itSubM).first;
3750 if ( aShapeID < 1 || aShapeID > mySMESHDSMesh->MaxShapeIndex() )
3752 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
3753 // write only SMDS_FacePosition and SMDS_EdgePosition
3754 switch ( aShapeType ) {
3756 nbFaceNodes += nbNodes;
3757 aFaceSM.push_back( aSubMesh );
3760 nbEdgeNodes += nbNodes;
3761 aEdgeSM.push_back( aSubMesh );
3767 // Treat positions on edges or faces
3768 for ( int onFace = 0; onFace < 2; onFace++ )
3770 // Create arrays to store in datasets
3771 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
3772 if (!nbNodes) continue;
3773 int* aNodeIDs = new int [ nbNodes ];
3774 double* aUPos = new double [ nbNodes ];
3775 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
3778 // loop on sub-meshes
3779 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
3780 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
3781 for ( ; itSM != pListSM->end(); itSM++ )
3783 SMESHDS_SubMesh* aSubMesh = (*itSM);
3785 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
3786 // loop on nodes in aSubMesh
3787 while ( itNode->more() )
3790 const SMDS_MeshNode* node = itNode->next();
3791 aNodeIDs [ iNode ] = node->GetID();
3794 const SMDS_PositionPtr pos = node->GetPosition();
3795 if ( onFace ) { // on FACE
3796 const SMDS_FacePosition* fPos =
3797 dynamic_cast<const SMDS_FacePosition*>( pos );
3799 aUPos[ iNode ] = fPos->GetUParameter();
3800 aVPos[ iNode ] = fPos->GetVParameter();
3807 const SMDS_EdgePosition* ePos =
3808 dynamic_cast<const SMDS_EdgePosition*>( pos );
3810 aUPos[ iNode ] = ePos->GetUParameter();
3816 } // loop on nodes in aSubMesh
3817 } // loop on sub-meshes
3822 aSize[ 0 ] = nbNodes;
3824 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
3825 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3826 aDataset->CreateOnDisk();
3827 aDataset->WriteOnDisk( aNodeIDs );
3828 aDataset->CloseOnDisk();
3831 aDSName = ( onFace ? "Face U positions" : "Edge positions");
3832 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
3833 aDataset->CreateOnDisk();
3834 aDataset->WriteOnDisk( aUPos );
3835 aDataset->CloseOnDisk();
3838 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
3839 aDataset->CreateOnDisk();
3840 aDataset->WriteOnDisk( aVPos );
3841 aDataset->CloseOnDisk();
3846 if ( aVPos ) delete [] aVPos;
3848 } // treat positions on edges or faces
3850 // close "Node Positions" group
3851 aGroup->CloseOnDisk();
3853 } // if ( there are submeshes in SMESHDS_Mesh )
3856 // close mesh HDF group
3857 aTopGroup->CloseOnDisk();
3865 aFile->CloseOnDisk();
3868 // Convert temporary files to stream
3869 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
3871 // Remove temporary files and directory
3873 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3875 INFOS( "SMESH_Gen_i::Save() completed" );
3876 return aStreamFile._retn();
3879 //=============================================================================
3881 * SMESH_Gen_i::SaveASCII
3883 * Save SMESH module's data in ASCII format
3885 //=============================================================================
3887 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
3889 bool isMultiFile ) {
3890 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
3891 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
3892 return aStreamFile._retn();
3894 //after usual saving needs to encipher binary to text string
3895 //Any binary symbol will be represent as "|xx" () hexadecimal format number
3896 int size = aStreamFile.in().length();
3897 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
3898 for ( int i = 0; i < size; i++ )
3899 sprintf( (char*)&(buffer[i*3]), "|%02x", aStreamFile[i] );
3901 buffer[size * 3] = '\0';
3903 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
3905 return anAsciiStreamFile._retn();
3908 //=============================================================================
3910 * SMESH_Gen_i::loadGeomData
3912 * Load GEOM module data
3914 //=============================================================================
3916 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
3918 if ( theCompRoot->_is_nil() )
3921 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
3922 if ( aStudy->_is_nil() )
3925 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3926 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
3929 //=============================================================================
3933 * Load SMESH module's data
3935 //=============================================================================
3937 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
3938 const SALOMEDS::TMPFile& theStream,
3942 INFOS( "SMESH_Gen_i::Load" );
3944 if ( myCurrentStudy->_is_nil() ||
3945 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
3946 SetCurrentStudy( theComponent->GetStudy() );
3948 /* if( !theComponent->_is_nil() )
3950 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
3951 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
3952 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
3955 StudyContext* myStudyContext = GetCurrentStudyContext();
3957 // Get temporary files location
3958 TCollection_AsciiString tmpDir =
3959 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
3961 INFOS( "THE URL++++++++++++++" );
3963 INFOS( "THE TMP PATH+++++++++" );
3966 // Convert the stream into sequence of files to process
3967 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
3970 TCollection_AsciiString aStudyName( "" );
3972 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
3974 // Set names of temporary files
3975 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
3976 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
3980 HDFdataset* aDataset;
3981 HDFgroup* aTopGroup;
3983 HDFgroup* aSubGroup;
3984 HDFgroup* aSubSubGroup;
3987 // ---> open HDF file
3988 aFile = new HDFfile( (char*) filename.ToCString() );
3990 aFile->OpenOnDisk( HDF_RDONLY );
3992 catch ( HDFexception ) {
3993 INFOS( "Load(): " << filename << " not found!" );
3997 TPythonDump pd; // prevent dump during loading
3999 // DriverMED_R_SMESHDS_Mesh myReader;
4000 // myReader.SetFile( meshfile.ToCString() );
4002 // For PAL13473 ("Repetitive mesh") implementation.
4003 // New dependencies between SMESH objects are established:
4004 // now hypotheses can refer to meshes, shapes and other hypotheses.
4005 // To keep data consistent, the following order of data restoration
4007 // 1. Create hypotheses
4008 // 2. Create all meshes
4009 // 3. Load hypotheses' data
4012 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
4013 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
4015 // get total number of top-level groups
4016 int aNbGroups = aFile->nInternalObjects();
4017 if ( aNbGroups > 0 ) {
4018 // --> in first turn we should read&create hypotheses
4019 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
4020 // open hypotheses root HDF group
4021 aTopGroup = new HDFgroup( "Hypotheses", aFile );
4022 aTopGroup->OpenOnDisk();
4024 // get number of hypotheses
4025 int aNbObjects = aTopGroup->nInternalObjects();
4026 for ( int j = 0; j < aNbObjects; j++ ) {
4027 // try to identify hypothesis
4028 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
4029 aTopGroup->InternalObjectIndentify( j, hypGrpName );
4031 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
4032 // open hypothesis group
4033 aGroup = new HDFgroup( hypGrpName, aTopGroup );
4034 aGroup->OpenOnDisk();
4036 // --> get hypothesis id
4037 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
4042 // get number of datasets
4043 int aNbSubObjects = aGroup->nInternalObjects();
4044 for ( int k = 0; k < aNbSubObjects; k++ ) {
4046 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4047 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4048 // --> get hypothesis name
4049 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4050 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4051 aDataset->OpenOnDisk();
4052 size = aDataset->GetSize();
4053 char* hypname_str = new char[ size ];
4054 aDataset->ReadFromDisk( hypname_str );
4055 hypname = string( hypname_str );
4056 delete [] hypname_str;
4057 aDataset->CloseOnDisk();
4059 // --> get hypothesis plugin library name
4060 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4061 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4062 aDataset->OpenOnDisk();
4063 size = aDataset->GetSize();
4064 char* libname_str = new char[ size ];
4065 aDataset->ReadFromDisk( libname_str );
4066 if(MYDEBUG) SCRUTE( libname_str );
4067 libname = string( libname_str );
4068 delete [] libname_str;
4069 aDataset->CloseOnDisk();
4071 // --> get hypothesis data
4072 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4073 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4074 aDataset->OpenOnDisk();
4075 size = aDataset->GetSize();
4076 char* hypdata_str = new char[ size ];
4077 aDataset->ReadFromDisk( hypdata_str );
4078 hypdata = string( hypdata_str );
4079 delete [] hypdata_str;
4080 aDataset->CloseOnDisk();
4083 // close hypothesis HDF group
4084 aGroup->CloseOnDisk();
4086 // --> restore hypothesis from data
4087 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4088 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
4089 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4090 SMESH::SMESH_Hypothesis_var myHyp;
4092 try { // protect persistence mechanism against exceptions
4093 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4096 INFOS( "Exception during hypothesis creation" );
4099 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4101 // myImpl->LoadFrom( hypdata.c_str() );
4102 hypDataList.push_back( make_pair( myImpl, hypdata ));
4103 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
4104 int newId = myStudyContext->findId( iorString.in() );
4105 myStudyContext->mapOldToNew( id, newId );
4108 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4112 // close hypotheses root HDF group
4113 aTopGroup->CloseOnDisk();
4117 // --> then we should read&create algorithms
4118 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
4119 // open algorithms root HDF group
4120 aTopGroup = new HDFgroup( "Algorithms", aFile );
4121 aTopGroup->OpenOnDisk();
4123 // get number of algorithms
4124 int aNbObjects = aTopGroup->nInternalObjects();
4125 for ( int j = 0; j < aNbObjects; j++ ) {
4126 // try to identify algorithm
4127 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
4128 aTopGroup->InternalObjectIndentify( j, hypGrpName );
4130 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
4131 // open algorithm group
4132 aGroup = new HDFgroup( hypGrpName, aTopGroup );
4133 aGroup->OpenOnDisk();
4135 // --> get algorithm id
4136 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
4141 // get number of datasets
4142 int aNbSubObjects = aGroup->nInternalObjects();
4143 for ( int k = 0; k < aNbSubObjects; k++ ) {
4145 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4146 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4147 // --> get algorithm name
4148 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4149 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4150 aDataset->OpenOnDisk();
4151 size = aDataset->GetSize();
4152 char* hypname_str = new char[ size ];
4153 aDataset->ReadFromDisk( hypname_str );
4154 hypname = string( hypname_str );
4155 delete [] hypname_str;
4156 aDataset->CloseOnDisk();
4158 // --> get algorithm plugin library name
4159 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4160 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4161 aDataset->OpenOnDisk();
4162 size = aDataset->GetSize();
4163 char* libname_str = new char[ size ];
4164 aDataset->ReadFromDisk( libname_str );
4165 if(MYDEBUG) SCRUTE( libname_str );
4166 libname = string( libname_str );
4167 delete [] libname_str;
4168 aDataset->CloseOnDisk();
4170 // --> get algorithm data
4171 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4172 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4173 aDataset->OpenOnDisk();
4174 size = aDataset->GetSize();
4175 char* hypdata_str = new char[ size ];
4176 aDataset->ReadFromDisk( hypdata_str );
4177 if(MYDEBUG) SCRUTE( hypdata_str );
4178 hypdata = string( hypdata_str );
4179 delete [] hypdata_str;
4180 aDataset->CloseOnDisk();
4183 // close algorithm HDF group
4184 aGroup->CloseOnDisk();
4186 // --> restore algorithm from data
4187 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4188 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
4189 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4190 SMESH::SMESH_Hypothesis_var myHyp;
4192 try { // protect persistence mechanism against exceptions
4193 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4196 INFOS( "Exception during hypothesis creation" );
4199 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4201 //myImpl->LoadFrom( hypdata.c_str() );
4202 hypDataList.push_back( make_pair( myImpl, hypdata ));
4203 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
4204 int newId = myStudyContext->findId( iorString.in() );
4205 myStudyContext->mapOldToNew( id, newId );
4208 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4212 // close algorithms root HDF group
4213 aTopGroup->CloseOnDisk();
4217 // --> the rest groups should be meshes
4218 for ( int i = 0; i < aNbGroups; i++ ) {
4219 // identify next group
4220 char meshName[ HDF_NAME_MAX_LEN+1 ];
4221 aFile->InternalObjectIndentify( i, meshName );
4223 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
4225 int id = atoi( string( meshName ).substr( 4 ).c_str() );
4229 // open mesh HDF group
4230 aTopGroup = new HDFgroup( meshName, aFile );
4231 aTopGroup->OpenOnDisk();
4233 // get number of child HDF objects
4234 int aNbObjects = aTopGroup->nInternalObjects();
4235 if ( aNbObjects > 0 ) {
4237 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
4238 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
4239 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
4240 if ( !myNewMeshImpl )
4242 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
4244 CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh );
4245 int newId = myStudyContext->findId( iorString.in() );
4246 myStudyContext->mapOldToNew( id, newId );
4249 // try to read and set auto color flag
4250 char aMeshAutoColorName[ 30 ];
4251 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
4252 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
4254 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
4255 aDataset->OpenOnDisk();
4256 size = aDataset->GetSize();
4257 int* anAutoColor = new int[ size ];
4258 aDataset->ReadFromDisk( anAutoColor );
4259 aDataset->CloseOnDisk();
4260 myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
4261 delete [] anAutoColor;
4264 // try to read and set reference to shape
4265 GEOM::GEOM_Object_var aShapeObject;
4266 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
4267 // load mesh "Ref on shape" - it's an entry to SObject
4268 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
4269 aDataset->OpenOnDisk();
4270 size = aDataset->GetSize();
4271 char* refFromFile = new char[ size ];
4272 aDataset->ReadFromDisk( refFromFile );
4273 aDataset->CloseOnDisk();
4274 if ( strlen( refFromFile ) > 0 ) {
4275 SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4277 // Make sure GEOM data are loaded first
4278 //loadGeomData( shapeSO->GetFatherComponent() );
4280 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4281 if ( !CORBA::is_nil( shapeObject ) ) {
4282 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4283 if ( !aShapeObject->_is_nil() )
4284 myNewMeshImpl->SetShape( aShapeObject );
4287 delete [] refFromFile;
4290 // issue 20918. Restore Persistent Id of SMESHDS_Mesh
4291 if( aTopGroup->ExistInternalObject( "meshPersistentId" ) )
4293 aDataset = new HDFdataset( "meshPersistentId", aTopGroup );
4294 aDataset->OpenOnDisk();
4295 size = aDataset->GetSize();
4296 int* meshPersistentId = new int[ size ];
4297 aDataset->ReadFromDisk( meshPersistentId );
4298 aDataset->CloseOnDisk();
4299 myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
4300 delete [] meshPersistentId;
4306 // As all object that can be referred by hypothesis are created,
4307 // we can restore hypothesis data
4309 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
4310 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4312 SMESH_Hypothesis_i* hyp = hyp_data->first;
4313 string & data = hyp_data->second;
4314 hyp->LoadFrom( data.c_str() );
4317 // Restore the rest mesh data
4319 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
4320 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4322 aTopGroup = meshi_group->second;
4323 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4324 //::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4325 //SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
4327 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
4328 bool hasData = false;
4331 CORBA::String_var iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
4332 int newId = myStudyContext->findId( iorString.in() );
4333 int id = myStudyContext->getOldId( newId );
4335 // try to find mesh data dataset
4336 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
4337 // load mesh "has data" flag
4338 aDataset = new HDFdataset( "Has data", aTopGroup );
4339 aDataset->OpenOnDisk();
4340 size = aDataset->GetSize();
4341 char* strHasData = new char[ size ];
4342 aDataset->ReadFromDisk( strHasData );
4343 aDataset->CloseOnDisk();
4344 if ( strcmp( strHasData, "1") == 0 ) {
4345 // read mesh data from MED file
4346 // myReader.SetMesh( mySMESHDSMesh );
4347 // myReader.SetMeshId( id );
4348 // myReader.Perform();
4351 delete [] strHasData;
4354 // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
4355 // nodes and elements are not yet put into sub-meshes)
4356 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4357 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
4358 aGroup->OpenOnDisk();
4359 // get number of applied algorithms
4360 int aNbSubObjects = aGroup->nInternalObjects();
4361 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
4362 for ( int j = 0; j < aNbSubObjects; j++ ) {
4363 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4364 aGroup->InternalObjectIndentify( j, name_dataset );
4365 // check if it is an algorithm
4366 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
4367 aDataset = new HDFdataset( name_dataset, aGroup );
4368 aDataset->OpenOnDisk();
4369 size = aDataset->GetSize();
4370 char* refFromFile = new char[ size ];
4371 aDataset->ReadFromDisk( refFromFile );
4372 aDataset->CloseOnDisk();
4373 // san - it is impossible to recover applied algorithms using their entries within Load() method
4374 //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
4375 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4376 int id = atoi( refFromFile );
4377 delete [] refFromFile;
4378 string anIOR = myStudyContext->getIORbyOldId( id );
4379 if ( !anIOR.empty() ) {
4380 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4381 if ( !CORBA::is_nil( hypObject ) ) {
4382 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4383 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4384 || !myNewMeshImpl->HasShapeToMesh()) )
4385 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4390 aGroup->CloseOnDisk();
4393 // try to get applied hypotheses
4394 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4395 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
4396 aGroup->OpenOnDisk();
4397 // get number of applied hypotheses
4398 int aNbSubObjects = aGroup->nInternalObjects();
4399 for ( int j = 0; j < aNbSubObjects; j++ ) {
4400 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4401 aGroup->InternalObjectIndentify( j, name_dataset );
4402 // check if it is a hypothesis
4403 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4404 aDataset = new HDFdataset( name_dataset, aGroup );
4405 aDataset->OpenOnDisk();
4406 size = aDataset->GetSize();
4407 char* refFromFile = new char[ size ];
4408 aDataset->ReadFromDisk( refFromFile );
4409 aDataset->CloseOnDisk();
4410 // san - it is impossible to recover applied hypotheses using their entries within Load() method
4411 //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
4412 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4413 int id = atoi( refFromFile );
4414 delete [] refFromFile;
4415 string anIOR = myStudyContext->getIORbyOldId( id );
4416 if ( !anIOR.empty() ) {
4417 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4418 if ( !CORBA::is_nil( hypObject ) ) {
4419 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4420 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4421 || !myNewMeshImpl->HasShapeToMesh()) )
4422 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4427 aGroup->CloseOnDisk();
4430 // --> try to find SUB-MESHES containers for each type of submesh
4431 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
4432 char name_meshgroup[ 30 ];
4433 if ( j == GetSubMeshOnVertexTag() )
4434 strcpy( name_meshgroup, "SubMeshes On Vertex" );
4435 else if ( j == GetSubMeshOnEdgeTag() )
4436 strcpy( name_meshgroup, "SubMeshes On Edge" );
4437 else if ( j == GetSubMeshOnWireTag() )
4438 strcpy( name_meshgroup, "SubMeshes On Wire" );
4439 else if ( j == GetSubMeshOnFaceTag() )
4440 strcpy( name_meshgroup, "SubMeshes On Face" );
4441 else if ( j == GetSubMeshOnShellTag() )
4442 strcpy( name_meshgroup, "SubMeshes On Shell" );
4443 else if ( j == GetSubMeshOnSolidTag() )
4444 strcpy( name_meshgroup, "SubMeshes On Solid" );
4445 else if ( j == GetSubMeshOnCompoundTag() )
4446 strcpy( name_meshgroup, "SubMeshes On Compound" );
4448 // try to get submeshes container HDF group
4449 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
4450 // open submeshes containers HDF group
4451 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
4452 aGroup->OpenOnDisk();
4454 // get number of submeshes
4455 int aNbSubMeshes = aGroup->nInternalObjects();
4456 for ( int k = 0; k < aNbSubMeshes; k++ ) {
4458 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
4459 aGroup->InternalObjectIndentify( k, name_submeshgroup );
4460 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
4461 // --> get submesh id
4462 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
4465 // open submesh HDF group
4466 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
4467 aSubGroup->OpenOnDisk();
4469 // try to read and set reference to subshape
4470 GEOM::GEOM_Object_var aSubShapeObject;
4471 SMESH::SMESH_subMesh_var aSubMesh;
4473 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
4474 // load submesh "Ref on shape" - it's an entry to SObject
4475 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
4476 aDataset->OpenOnDisk();
4477 size = aDataset->GetSize();
4478 char* refFromFile = new char[ size ];
4479 aDataset->ReadFromDisk( refFromFile );
4480 aDataset->CloseOnDisk();
4481 if ( strlen( refFromFile ) > 0 ) {
4482 SALOMEDS::SObject_wrap subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
4483 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
4484 if ( !CORBA::is_nil( subShapeObject ) ) {
4485 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
4486 if ( !aSubShapeObject->_is_nil() )
4487 aSubMesh = SMESH::SMESH_subMesh::_duplicate
4488 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
4489 if ( aSubMesh->_is_nil() )
4491 string iorSubString = GetORB()->object_to_string( aSubMesh );
4492 int newSubId = myStudyContext->findId( iorSubString );
4493 myStudyContext->mapOldToNew( subid, newSubId );
4498 if ( aSubMesh->_is_nil() )
4501 // try to get applied algorithms
4502 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4503 // open "applied algorithms" HDF group
4504 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
4505 aSubSubGroup->OpenOnDisk();
4506 // get number of applied algorithms
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 an algorithm
4512 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
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 algorithms" HDF group
4533 aSubSubGroup->CloseOnDisk();
4536 // try to get applied hypotheses
4537 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4538 // open "applied hypotheses" HDF group
4539 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
4540 aSubSubGroup->OpenOnDisk();
4541 // get number of applied hypotheses
4542 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4543 for ( int l = 0; l < aNbSubObjects; l++ ) {
4544 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4545 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4546 // check if it is a hypothesis
4547 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4548 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4549 aDataset->OpenOnDisk();
4550 size = aDataset->GetSize();
4551 char* refFromFile = new char[ size ];
4552 aDataset->ReadFromDisk( refFromFile );
4553 aDataset->CloseOnDisk();
4555 int id = atoi( refFromFile );
4556 string anIOR = myStudyContext->getIORbyOldId( id );
4557 if ( !anIOR.empty() ) {
4558 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4559 if ( !CORBA::is_nil( hypObject ) ) {
4560 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4561 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4562 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4567 // close "APPLIED HYPOTHESES" hdf group
4568 aSubSubGroup->CloseOnDisk();
4571 // close SUB-MESH hdf group
4572 aSubGroup->CloseOnDisk();
4575 // close SUB-MESHES containers hdf group
4576 aGroup->CloseOnDisk();
4580 // try to get GROUPS
4581 for ( int ii = GetNodeGroupsTag(); ii <= GetBallElementsGroupsTag(); ii++ ) {
4582 char name_group[ 30 ];
4583 if ( ii == GetNodeGroupsTag() )
4584 strcpy( name_group, "Groups of Nodes" );
4585 else if ( ii == GetEdgeGroupsTag() )
4586 strcpy( name_group, "Groups of Edges" );
4587 else if ( ii == GetFaceGroupsTag() )
4588 strcpy( name_group, "Groups of Faces" );
4589 else if ( ii == GetVolumeGroupsTag() )
4590 strcpy( name_group, "Groups of Volumes" );
4591 else if ( ii == Get0DElementsGroupsTag() )
4592 strcpy( name_group, "Groups of 0D Elements" );
4593 else if ( ii == GetBallElementsGroupsTag() )
4594 strcpy( name_group, "Groups of Balls" );
4596 if ( aTopGroup->ExistInternalObject( name_group ) ) {
4597 aGroup = new HDFgroup( name_group, aTopGroup );
4598 aGroup->OpenOnDisk();
4599 // get number of groups
4600 int aNbSubObjects = aGroup->nInternalObjects();
4601 for ( int j = 0; j < aNbSubObjects; j++ ) {
4602 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4603 aGroup->InternalObjectIndentify( j, name_dataset );
4604 // check if it is an group
4605 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
4607 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
4610 aDataset = new HDFdataset( name_dataset, aGroup );
4611 aDataset->OpenOnDisk();
4613 // Retrieve actual group name
4614 size = aDataset->GetSize();
4615 char* nameFromFile = new char[ size ];
4616 aDataset->ReadFromDisk( nameFromFile );
4617 aDataset->CloseOnDisk();
4619 // Try to find a shape reference
4620 TopoDS_Shape aShape;
4621 char aRefName[ 30 ];
4622 sprintf( aRefName, "Ref on shape %d", subid);
4623 if ( aGroup->ExistInternalObject( aRefName ) ) {
4624 // load mesh "Ref on shape" - it's an entry to SObject
4625 aDataset = new HDFdataset( aRefName, aGroup );
4626 aDataset->OpenOnDisk();
4627 size = aDataset->GetSize();
4628 char* refFromFile = new char[ size ];
4629 aDataset->ReadFromDisk( refFromFile );
4630 aDataset->CloseOnDisk();
4631 if ( strlen( refFromFile ) > 0 ) {
4632 SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4633 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4634 if ( !CORBA::is_nil( shapeObject ) ) {
4635 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4636 if ( !aShapeObject->_is_nil() )
4637 aShape = GeomObjectToShape( aShapeObject );
4641 // Try to read a filter of SMESH_GroupOnFilter
4642 SMESH::Filter_var filter;
4643 SMESH_PredicatePtr predicate;
4644 std::string hdfGrpName = "Filter " + SMESH_Comment(subid);
4645 if ( aGroup->ExistInternalObject( hdfGrpName.c_str() ))
4647 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup );
4648 aDataset->OpenOnDisk();
4649 size = aDataset->GetSize();
4650 char* persistStr = new char[ size ];
4651 aDataset->ReadFromDisk( persistStr );
4652 aDataset->CloseOnDisk();
4653 if ( strlen( persistStr ) > 0 ) {
4654 filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
4655 predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
4659 // Create group servant
4660 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
4661 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
4662 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) );
4663 // Obtain a SMESHDS_Group object
4664 if ( aNewGroup->_is_nil() )
4667 string iorSubString = GetORB()->object_to_string( aNewGroup );
4668 int newSubId = myStudyContext->findId( iorSubString );
4669 myStudyContext->mapOldToNew( subid, newSubId );
4671 SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
4675 if ( SMESH_GroupOnFilter_i* aFilterGroup =
4676 dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
4677 aFilterGroup->SetFilter( filter );
4679 SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
4680 if ( !aGroupBaseDS )
4683 aGroupBaseDS->SetStoreName( name_dataset );
4686 // Read color of the group
4687 char aGroupColorName[ 30 ];
4688 sprintf( aGroupColorName, "ColorGroup %d", subid);
4689 if ( aGroup->ExistInternalObject( aGroupColorName ) )
4691 aDataset = new HDFdataset( aGroupColorName, aGroup );
4692 aDataset->OpenOnDisk();
4693 size = aDataset->GetSize();
4694 double* anRGB = new double[ size ];
4695 aDataset->ReadFromDisk( anRGB );
4696 aDataset->CloseOnDisk();
4697 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
4698 aGroupBaseDS->SetColor( aColor );
4701 // Fill group with contents from MED file
4702 // SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
4704 // myReader.GetGroup( aGrp );
4707 aGroup->CloseOnDisk();
4711 // instead of reading mesh data, we read only brief information of all
4712 // objects: mesh, groups, sub-meshes (issue 0021208 )
4715 SMESH_PreMeshInfo::LoadFromFile( myNewMeshImpl, id,
4716 meshfile.ToCString(), filename.ToCString(),
4720 // read Sub-Mesh ORDER if any
4721 if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
4722 aDataset = new HDFdataset( "Mesh Order", aTopGroup );
4723 aDataset->OpenOnDisk();
4724 size = aDataset->GetSize();
4725 int* smIDs = new int[ size ];
4726 aDataset->ReadFromDisk( smIDs );
4727 aDataset->CloseOnDisk();
4728 TListOfListOfInt anOrderIds;
4729 anOrderIds.push_back( TListOfInt() );
4730 for ( int i = 0; i < size; i++ )
4731 if ( smIDs[ i ] < 0 ) // is separator
4732 anOrderIds.push_back( TListOfInt() );
4734 anOrderIds.back().push_back(smIDs[ i ]);
4736 myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
4740 // update hyps needing full mesh data restored (issue 20918)
4741 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4743 SMESH_Hypothesis_i* hyp = hyp_data->first;
4744 hyp->UpdateAsMeshesRestored();
4747 // notify algos on completed restoration to set sub-mesh event listeners
4748 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4750 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4751 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4753 TopoDS_Shape myLocShape;
4754 if(myLocMesh.HasShapeToMesh())
4755 myLocShape = myLocMesh.GetShapeToMesh();
4757 myLocShape = SMESH_Mesh::PseudoShape();
4759 myLocMesh.GetSubMesh(myLocShape)->
4760 ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
4765 aTopGroup->CloseOnDisk();
4768 aFile->CloseOnDisk();
4771 // Remove temporary files created from the stream
4774 SMESH_File meshFile( meshfile.ToCString() );
4775 if ( !meshFile ) // no meshfile exists
4777 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
4781 Engines::Container_var container = GetContainerRef();
4782 if ( Engines_Container_i* container_i = SMESH::DownCast<Engines_Container_i*>( container ))
4784 container_i->registerTemporaryFile( filename.ToCString() );
4785 container_i->registerTemporaryFile( meshfile.ToCString() );
4786 container_i->registerTemporaryFile( tmpDir.ToCString() );
4790 pd << ""; // prevent optimizing pd out
4792 INFOS( "SMESH_Gen_i::Load completed" );
4796 //=============================================================================
4798 * SMESH_Gen_i::LoadASCII
4800 * Load SMESH module's data in ASCII format
4802 //=============================================================================
4804 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
4805 const SALOMEDS::TMPFile& theStream,
4807 bool isMultiFile ) {
4808 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
4809 return Load( theComponent, theStream, theURL, isMultiFile );
4811 //before call main ::Load method it's need for decipher text format to
4812 //binary ( "|xx" => x' )
4813 int size = theStream.length();
4814 if ( int((size / 3 )*3) != size ) //error size of buffer
4817 int real_size = int(size / 3);
4819 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
4823 for ( int i = 0; i < real_size; i++ )
4825 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
4826 sscanf( tmp, "%x", &c );
4827 sprintf( (char*)&(buffer[i]), "%c", (char)c );
4830 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
4832 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
4835 //=============================================================================
4837 * SMESH_Gen_i::Close
4839 * Clears study-connected data when it is closed
4841 //=============================================================================
4843 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
4845 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
4847 // set correct current study
4848 SALOMEDS::Study_var study = theComponent->GetStudy();
4849 if ( study->StudyId() != GetCurrentStudyID())
4850 setCurrentStudy( study, /*IsBeingClosed=*/true );
4852 // Clear study contexts data
4853 int studyId = GetCurrentStudyID();
4854 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
4855 delete myStudyContextMap[ studyId ];
4856 myStudyContextMap.erase( studyId );
4859 // remove the tmp files meshes are loaded from
4860 SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
4862 myCurrentStudy = SALOMEDS::Study::_nil();
4866 //=============================================================================
4868 * SMESH_Gen_i::ComponentDataType
4870 * Get component data type
4872 //=============================================================================
4874 char* SMESH_Gen_i::ComponentDataType()
4876 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
4877 return CORBA::string_dup( "SMESH" );
4881 //=============================================================================
4883 * SMESH_Gen_i::IORToLocalPersistentID
4885 * Transform data from transient form to persistent
4887 //=============================================================================
4889 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
4890 const char* IORString,
4891 CORBA::Boolean /*isMultiFile*/,
4892 CORBA::Boolean /*isASCII*/ )
4894 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
4895 StudyContext* myStudyContext = GetCurrentStudyContext();
4897 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
4898 int anId = myStudyContext->findId( IORString );
4900 if(MYDEBUG) MESSAGE( "VSR " << anId )
4902 sprintf( strId, "%d", anId );
4903 return CORBA::string_dup( strId );
4906 return CORBA::string_dup( "" );
4909 //=============================================================================
4911 * SMESH_Gen_i::LocalPersistentIDToIOR
4913 * Transform data from persistent form to transient
4915 //=============================================================================
4917 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
4918 const char* aLocalPersistentID,
4919 CORBA::Boolean /*isMultiFile*/,
4920 CORBA::Boolean /*isASCII*/ )
4922 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
4923 StudyContext* myStudyContext = GetCurrentStudyContext();
4925 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
4926 int anId = atoi( aLocalPersistentID );
4927 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
4929 return CORBA::string_dup( "" );
4932 //=======================================================================
4933 //function : RegisterObject
4935 //=======================================================================
4937 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
4939 StudyContext* myStudyContext = GetCurrentStudyContext();
4940 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4941 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
4942 return myStudyContext->addObject( string( iorString.in() ) );
4947 //================================================================================
4949 * \brief Return id of registered object
4950 * \param theObject - the Object
4951 * \retval int - Object id
4953 //================================================================================
4955 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
4957 StudyContext* myStudyContext = GetCurrentStudyContext();
4958 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4959 string iorString = GetORB()->object_to_string( theObject );
4960 return myStudyContext->findId( iorString );
4965 //=============================================================================
4967 * SMESH_Gen_i::SetName
4969 * Set a new object name
4971 //=============================================================================
4972 void SMESH_Gen_i::SetName(const char* theIOR,
4973 const char* theName)
4975 if ( theIOR && strcmp( theIOR, "" ) ) {
4976 CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
4977 SALOMEDS::SObject_wrap aSO = ObjectToSObject( myCurrentStudy, anObject );
4978 if ( !aSO->_is_nil() ) {
4979 SetName( aSO, theName );
4984 int SMESH_Gen_i::GetCurrentStudyID()
4986 return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
4989 // Version information
4990 char* SMESH_Gen_i::getVersion()
4992 #if SMESH_DEVELOPMENT
4993 return CORBA::string_dup(SMESH_VERSION_STR"dev");
4995 return CORBA::string_dup(SMESH_VERSION_STR);
4999 //=============================================================================
5001 * SMESHEngine_factory
5003 * C factory, accessible with dlsym, after dlopen
5005 //=============================================================================
5009 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
5010 PortableServer::POA_ptr poa,
5011 PortableServer::ObjectId* contId,
5012 const char* instanceName,
5013 const char* interfaceName )
5015 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
5016 if(MYDEBUG) SCRUTE(interfaceName);
5017 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
5018 return aSMESHGen->getId() ;