1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : SMESH_Gen_i.cxx
24 // Author : Paul RASCLE, EDF
28 #include <TopExp_Explorer.hxx>
30 #include <TopoDS_Iterator.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <TopoDS_CompSolid.hxx>
33 #include <TopoDS_Solid.hxx>
34 #include <TopoDS_Shell.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Wire.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TCollection_AsciiString.hxx>
49 #include "Utils_CorbaException.hxx"
51 #include "utilities.h"
62 #define LibHandle HMODULE
63 #define LoadLib( name ) LoadLibrary( name )
64 #define GetProc GetProcAddress
65 #define UnLoadLib( handle ) FreeLibrary( handle );
67 #define LibHandle void*
68 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
70 #define UnLoadLib( handle ) dlclose( handle );
75 #include "SMESH_Gen_i.hxx"
76 #include "SMESH_Mesh_i.hxx"
77 #include "SMESH_Hypothesis_i.hxx"
78 #include "SMESH_Algo_i.hxx"
79 #include "SMESH_Group_i.hxx"
80 #include "SMESH_PythonDump.hxx"
82 #include "SMESHDS_Document.hxx"
83 #include "SMESHDS_Group.hxx"
84 #include "SMESHDS_GroupOnGeom.hxx"
85 #include "SMESH_Mesh.hxx"
86 #include "SMESH_Hypothesis.hxx"
87 #include "SMESH_Group.hxx"
88 #include "SMESH_MeshEditor.hxx"
90 #include "SMDS_EdgePosition.hxx"
91 #include "SMDS_FacePosition.hxx"
92 #include "SMDS_VertexPosition.hxx"
93 #include "SMDS_SpacePosition.hxx"
94 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
96 #include CORBA_SERVER_HEADER(SMESH_Group)
97 #include CORBA_SERVER_HEADER(SMESH_Filter)
98 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
100 #include "DriverMED_W_SMESHDS_Mesh.h"
101 #include "DriverMED_R_SMESHDS_Mesh.h"
103 #include "SALOMEDS_Tool.hxx"
104 #include "SALOME_NamingService.hxx"
105 #include "SALOME_LifeCycleCORBA.hxx"
106 #include "Utils_SINGLETON.hxx"
107 #include "OpUtil.hxx"
109 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
110 #include CORBA_CLIENT_HEADER(SALOME_Session)
112 #include "GEOM_Client.hxx"
113 #include "Utils_ExceptHandlers.hxx"
114 #include "Basics_Utils.hxx"
119 using SMESH::TPythonDump;
121 #define NUM_TMP_FILES 2
124 static int MYDEBUG = 0;
126 static int MYDEBUG = 0;
129 // Static variables definition
130 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
131 CORBA::ORB_var SMESH_Gen_i::myOrb;
132 PortableServer::POA_var SMESH_Gen_i::myPoa;
133 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
134 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
135 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
138 const int nbElemPerDiagonal = 10;
140 //=============================================================================
142 * GetServant [ static ]
144 * Get servant of the CORBA object
146 //=============================================================================
148 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
150 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
153 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
157 INFOS( "GetServant - Unknown exception was caught!!!" );
162 //=============================================================================
164 * SObjectToObject [ static ]
166 * Get CORBA object corresponding to the SALOMEDS::SObject
168 //=============================================================================
170 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
172 SALOMEDS::GenericAttribute_var anAttr;
173 CORBA::Object_var anObj;
174 if ( !theSObject->_is_nil() ) {
176 if( theSObject->FindAttribute( anAttr, "AttributeIOR" ) ) {
177 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr );
178 CORBA::String_var aValue = anIOR->Value();
179 if( strcmp( aValue, "" ) != 0 )
180 anObj = GetORB()->string_to_object( aValue );
184 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
190 //=============================================================================
194 * Get SALOME_NamingService object
196 //=============================================================================
198 SALOME_NamingService* SMESH_Gen_i::GetNS()
200 if ( myNS == NULL ) {
201 myNS = SINGLETON_<SALOME_NamingService>::Instance();
202 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
203 myNS->init_orb( GetORB() );
208 //=============================================================================
212 * Get SALOME_LifeCycleCORBA object
214 //=============================================================================
215 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
216 if ( myLCC == NULL ) {
217 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
223 //=============================================================================
225 * GetGeomEngine [ static ]
227 * Get GEOM::GEOM_Gen reference
229 //=============================================================================
230 GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() {
231 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
232 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
233 //CCRT return aGeomEngine._retn();
234 if(CORBA::is_nil(myGeomGen))
236 Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
237 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
242 //=============================================================================
244 * SMESH_Gen_i::SMESH_Gen_i
246 * Default constructor: not for use
248 //=============================================================================
250 SMESH_Gen_i::SMESH_Gen_i()
252 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
255 //=============================================================================
257 * SMESH_Gen_i::SMESH_Gen_i
259 * Standard constructor, used with Container
261 //=============================================================================
263 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
264 PortableServer::POA_ptr poa,
265 PortableServer::ObjectId* contId,
266 const char* instanceName,
267 const char* interfaceName )
268 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
270 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
272 myOrb = CORBA::ORB::_duplicate(orb);
273 myPoa = PortableServer::POA::_duplicate(poa);
276 _id = myPoa->activate_object( _thisObj );
278 myIsEmbeddedMode = false;
279 myShapeReader = NULL; // shape reader
282 // set it in standalone mode only
283 //OSD::SetSignal( true );
285 // 0020605: EDF 1190 SMESH: Display performance. 80 seconds for 52000 cells.
286 // find out mode (embedded or standalone) here else
287 // meshes created before calling SMESH_Client::GetSMESHGen(), which calls
288 // SMESH_Gen_i::SetEmbeddedMode(), have wrong IsEmbeddedMode flag
289 if ( SALOME_NamingService* ns = GetNS() )
291 CORBA::Object_var obj = ns->Resolve( "/Kernel/Session" );
292 SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
293 if ( !session->_is_nil() )
295 CORBA::String_var s_host = session->getHostname();
296 CORBA::Long s_pid = session->getPID();
297 string my_host = Kernel_Utils::GetHostname();
299 long my_pid = (long)_getpid();
301 long my_pid = (long) getpid();
303 SetEmbeddedMode( s_pid == my_pid && my_host == s_host.in() );
308 //=============================================================================
310 * SMESH_Gen_i::~SMESH_Gen_i
314 //=============================================================================
316 SMESH_Gen_i::~SMESH_Gen_i()
318 INFOS( "SMESH_Gen_i::~SMESH_Gen_i" );
320 // delete hypothesis creators
321 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
322 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
324 delete (*itHyp).second;
326 myHypCreatorMap.clear();
328 // Clear study contexts data
329 map<int, StudyContext*>::iterator it;
330 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
333 myStudyContextMap.clear();
334 // delete shape reader
335 if ( !myShapeReader )
336 delete myShapeReader;
339 //=============================================================================
341 * SMESH_Gen_i::createHypothesis
343 * Create hypothesis of given type
345 //=============================================================================
346 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
347 const char* theLibName)
348 throw (SALOME::SALOME_Exception)
350 /* It's Need to tranlate lib name for WIN32 or X platform */
351 char* aPlatformLibName = 0;
352 if ( theLibName && theLibName[0] != '\0' )
354 int libNameLen = strlen(theLibName);
355 //check for old format "libXXXXXXX.so"
356 if (libNameLen > 7 &&
357 !strncmp( theLibName, "lib", 3 ) &&
358 !strcmp( theLibName+libNameLen-3, ".so" ))
362 aPlatformLibName = new char[libNameLen - 1];
363 aPlatformLibName[0] = '\0';
364 aPlatformLibName = strncat( aPlatformLibName, theLibName+3, libNameLen-6 );
365 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
366 aPlatformLibName[libNameLen - 2] = '\0';
368 aPlatformLibName = new char[ libNameLen + 1];
369 aPlatformLibName[0] = '\0';
370 aPlatformLibName = strcat( aPlatformLibName, theLibName );
371 aPlatformLibName[libNameLen] = '\0';
376 //try to use new format
378 aPlatformLibName = new char[ libNameLen + 5 ];
379 aPlatformLibName[0] = '\0';
380 aPlatformLibName = strcat( aPlatformLibName, theLibName );
381 aPlatformLibName = strcat( aPlatformLibName, ".dll" );
383 aPlatformLibName = new char[ libNameLen + 7 ];
384 aPlatformLibName[0] = '\0';
385 aPlatformLibName = strcat( aPlatformLibName, "lib" );
386 aPlatformLibName = strcat( aPlatformLibName, theLibName );
387 aPlatformLibName = strcat( aPlatformLibName, ".so" );
393 Unexpect aCatch(SALOME_SalomeException);
394 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName/*theLibName*/);
396 // create a new hypothesis object servant
397 SMESH_Hypothesis_i* myHypothesis_i = 0;
398 SMESH::SMESH_Hypothesis_var hypothesis_i;
402 // check, if creator for this hypothesis type already exists
403 if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end())
405 // load plugin library
406 if(MYDEBUG) MESSAGE("Loading server meshers plugin library ...");
407 LibHandle libHandle = LoadLib( aPlatformLibName/*theLibName*/ );
410 // report any error, if occured
412 const char* anError = dlerror();
413 throw(SALOME_Exception(anError));
415 throw(SALOME_Exception(LOCALIZED( "Can't load server meshers plugin library" )));
419 // get method, returning hypothesis creator
420 if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ...");
421 typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName);
422 GetHypothesisCreator procHandle =
423 (GetHypothesisCreator)GetProc( libHandle, "GetHypothesisCreator" );
426 throw(SALOME_Exception(LOCALIZED("bad hypothesis plugin library")));
427 UnLoadLib(libHandle);
430 // get hypothesis creator
431 if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName);
432 GenericHypothesisCreator_i* aCreator = procHandle(theHypName);
435 throw(SALOME_Exception(LOCALIZED("no such a hypothesis in this plugin")));
438 // map hypothesis creator to a hypothesis name
439 myHypCreatorMap[string(theHypName)] = aCreator;
442 // create a new hypothesis object, store its ref. in studyContext
443 if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName);
445 myHypCreatorMap[string(theHypName)]->Create(myPoa, GetCurrentStudyID(), &myGen);
446 myHypothesis_i->SetLibName(aPlatformLibName/*theLibName*/); // for persistency assurance
448 catch (SALOME_Exception& S_ex)
450 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
453 if ( aPlatformLibName )
454 delete[] aPlatformLibName;
457 return hypothesis_i._retn();
459 // activate the CORBA servant of hypothesis
460 hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() );
461 int nextId = RegisterObject( hypothesis_i );
462 if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId );
464 return hypothesis_i._retn();
467 //=============================================================================
469 * SMESH_Gen_i::createMesh
471 * Create empty mesh on shape
473 //=============================================================================
474 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
475 throw ( SALOME::SALOME_Exception )
477 Unexpect aCatch(SALOME_SalomeException);
478 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
480 // Get or create the GEOM_Client instance
482 // create a new mesh object servant, store it in a map in study context
483 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
484 // create a new mesh object
485 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
487 // activate the CORBA servant of Mesh
488 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
489 int nextId = RegisterObject( mesh );
490 if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId);
493 catch (SALOME_Exception& S_ex) {
494 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
496 return SMESH::SMESH_Mesh::_nil();
499 //=============================================================================
501 * SMESH_Gen_i::GetShapeReader
505 //=============================================================================
506 GEOM_Client* SMESH_Gen_i::GetShapeReader()
508 // create shape reader if necessary
509 if ( !myShapeReader )
510 myShapeReader = new GEOM_Client(GetContainerRef());
511 ASSERT( myShapeReader );
512 return myShapeReader;
515 //=============================================================================
517 * SMESH_Gen_i::SetGeomEngine
519 * Set GEOM::GEOM_Gen reference
521 //=============================================================================
522 //GEOM::GEOM_Gen_ptr SMESH_Gen_i::SetGeomEngine( const char* containerLoc )
523 void SMESH_Gen_i::SetGeomEngine( GEOM::GEOM_Gen_ptr geomcompo )
525 //Engines::Component_ptr temp=GetLCC()->FindOrLoad_Component(containerLoc,"GEOM");
526 //myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
527 myGeomGen=GEOM::GEOM_Gen::_duplicate(geomcompo);
531 //=============================================================================
533 * SMESH_Gen_i::SetEmbeddedMode
537 //=============================================================================
539 void SMESH_Gen_i::SetEmbeddedMode( CORBA::Boolean theMode )
541 myIsEmbeddedMode = theMode;
543 if ( !myIsEmbeddedMode ) {
544 //PAL10867: disable signals catching with "noexcepthandler" option
545 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
546 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
551 char* envDisableFPE = getenv("DISABLE_FPE");
552 if (envDisableFPE && atoi(envDisableFPE))
557 OSD::SetSignal( raiseFPE );
559 // else OSD::SetSignal() is called in GUI
563 //=============================================================================
565 * SMESH_Gen_i::IsEmbeddedMode
569 //=============================================================================
571 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
573 return myIsEmbeddedMode;
576 //=============================================================================
578 * SMESH_Gen_i::SetCurrentStudy
582 //=============================================================================
584 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
586 int curStudyId = GetCurrentStudyID();
587 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
588 // create study context, if it doesn't exist and set current study
589 int studyId = GetCurrentStudyID();
590 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) {
591 myStudyContextMap[ studyId ] = new StudyContext;
594 // myCurrentStudy may be nil
595 if ( !CORBA::is_nil( myCurrentStudy ) ) {
596 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
597 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
598 aStudyBuilder->LoadWith( myCurrentStudy->FindComponent( "GEOM" ), GetGeomEngine() );
600 // NPAL16168, issue 0020210
601 // Let meshes update their data depending on GEOM groups that could change
602 if ( curStudyId != studyId )
604 //SALOMEDS::SComponent_var me = PublishComponent( myCurrentStudy );
605 SALOMEDS::SComponent_var me = SALOMEDS::SComponent::_narrow
606 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
607 if ( !me->_is_nil() ) {
608 SALOMEDS::ChildIterator_var anIter = myCurrentStudy->NewChildIterator( me );
609 for ( ; anIter->More(); anIter->Next() ) {
610 SALOMEDS::SObject_var so = anIter->Value();
611 CORBA::Object_var ior = SObjectToObject( so );
612 if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
613 mesh->CheckGeomGroupModif();
620 //=============================================================================
622 * SMESH_Gen_i::GetCurrentStudy
626 //=============================================================================
628 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
630 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
631 return SALOMEDS::Study::_duplicate( myCurrentStudy );
634 //=============================================================================
636 * SMESH_Gen_i::GetCurrentStudyContext
638 * Get current study context
640 //=============================================================================
641 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
643 if ( !CORBA::is_nil( myCurrentStudy ) &&
644 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
645 return myStudyContextMap[ myCurrentStudy->StudyId() ];
650 //=============================================================================
652 * SMESH_Gen_i::CreateHypothesis
654 * Create hypothesis/algorothm of given type and publish it in the study
656 //=============================================================================
658 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
659 const char* theLibName )
660 throw ( SALOME::SALOME_Exception )
662 Unexpect aCatch(SALOME_SalomeException);
663 // Create hypothesis/algorithm
664 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
666 // Publish hypothesis/algorithm in the study
667 if ( CanPublishInStudy( hyp ) ) {
668 SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp );
669 if ( !aSO->_is_nil() ) {
670 // Update Python script
671 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
672 << theHypName << "', '" << theLibName << "')";
679 //================================================================================
681 * \brief Return a hypothesis holding parameter values corresponding either to the mesh
682 * existing on the given geometry or to size of the geometry.
683 * \param theHypType - hypothesis type name
684 * \param theLibName - plugin library name
685 * \param theMesh - The mesh of interest
686 * \param theGeom - The shape to get parameter values from
687 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
688 * in a study and used to compute the mesh, or a temporary one created just to pass
691 //================================================================================
693 SMESH::SMESH_Hypothesis_ptr
694 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
695 const char* theLibName,
696 SMESH::SMESH_Mesh_ptr theMesh,
697 GEOM::GEOM_Object_ptr theGeom,
698 CORBA::Boolean byMesh)
699 throw ( SALOME::SALOME_Exception )
701 Unexpect aCatch(SALOME_SalomeException);
702 if ( byMesh && CORBA::is_nil( theMesh ) )
703 return SMESH::SMESH_Hypothesis::_nil();
704 if ( byMesh && CORBA::is_nil( theGeom ) )
705 return SMESH::SMESH_Hypothesis::_nil();
707 // -----------------------------------------------
708 // find hypothesis used to mesh theGeom
709 // -----------------------------------------------
711 // get mesh and shape
712 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
713 TopoDS_Shape shape = GeomObjectToShape( theGeom );
714 if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
715 return SMESH::SMESH_Hypothesis::_nil();
716 ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
718 // create a temporary hypothesis to know its dimention
719 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
720 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
722 return SMESH::SMESH_Hypothesis::_nil();
723 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
726 // look for a hypothesis of theHypType used to mesh the shape
727 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
730 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
731 int nbLocalHyps = aHypList->length();
732 for ( int i = 0; i < nbLocalHyps; i++ )
733 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND local!
734 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
735 // check super shapes
736 TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
737 while ( nbLocalHyps == 0 && itShape.More() ) {
738 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
739 if ( ! CORBA::is_nil( geomObj )) {
740 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
741 nbLocalHyps = aHypList->length();
742 for ( int i = 0; i < nbLocalHyps; i++ )
743 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
744 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
750 // let the temporary hypothesis find out some how parameter values by mesh
751 if ( hyp->SetParametersByMesh( mesh, shape ))
752 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
757 diagonal = mesh->GetShapeDiagonalSize();
759 diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
760 ::SMESH_Hypothesis::TDefaults dflts;
761 dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
762 dflts._nbSegments = myGen.GetDefaultNbSegments();
763 // let the temporary hypothesis initialize it's values
764 if ( hyp->SetParametersByDefaults( dflts, mesh ))
765 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
768 return SMESH::SMESH_Hypothesis::_nil();
771 //=============================================================================
773 * Sets number of segments per diagonal of boundary box of geometry by which
774 * default segment length of appropriate 1D hypotheses is defined
776 //=============================================================================
778 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
779 throw ( SALOME::SALOME_Exception )
781 if ( theNbSegments > 0 )
782 myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
784 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
786 //=============================================================================
788 * \brief Sets default number of segments per edge
790 //=============================================================================
791 void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
792 throw ( SALOME::SALOME_Exception )
794 if ( theNbSegments > 0 )
795 myGen.SetDefaultNbSegments( int(theNbSegments) );
797 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
800 //=============================================================================
802 * SMESH_Gen_i::CreateMesh
804 * Create empty mesh on a shape and publish it in the study
806 //=============================================================================
808 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
809 throw ( SALOME::SALOME_Exception )
811 Unexpect aCatch(SALOME_SalomeException);
812 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
814 SMESH::SMESH_Mesh_var mesh = this->createMesh();
816 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
817 ASSERT( meshServant );
818 meshServant->SetShape( theShapeObject );
820 // publish mesh in the study
821 if ( CanPublishInStudy( mesh ) ) {
822 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
823 aStudyBuilder->NewCommand(); // There is a transaction
824 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
825 aStudyBuilder->CommitCommand();
826 if ( !aSO->_is_nil() ) {
827 // Update Python script
828 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
835 //=============================================================================
837 * SMESH_Gen_i::CreateEmptyMesh
841 //=============================================================================
843 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
844 throw ( SALOME::SALOME_Exception )
846 Unexpect aCatch(SALOME_SalomeException);
847 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
849 SMESH::SMESH_Mesh_var mesh = this->createMesh();
851 // publish mesh in the study
852 if ( CanPublishInStudy( mesh ) ) {
853 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
854 aStudyBuilder->NewCommand(); // There is a transaction
855 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
856 aStudyBuilder->CommitCommand();
857 if ( !aSO->_is_nil() ) {
858 // Update Python script
859 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
866 //=============================================================================
868 * SMESH_Gen_i::CreateMeshFromUNV
870 * Create mesh and import data from UNV file
872 //=============================================================================
874 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
875 throw ( SALOME::SALOME_Exception )
877 Unexpect aCatch(SALOME_SalomeException);
878 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
880 SMESH::SMESH_Mesh_var aMesh = createMesh();
882 // publish mesh in the study
883 if ( CanPublishInStudy( aMesh ) ) {
884 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
885 aStudyBuilder->NewCommand(); // There is a transaction
886 SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
887 aStudyBuilder->CommitCommand();
888 if ( !aSO->_is_nil() ) {
889 // Update Python script
890 TPythonDump() << aSO << " = smeshgen.CreateMeshesFromUNV('" << theFileName << "')";
894 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
896 aServant->ImportUNVFile( theFileName );
898 // Dump creation of groups
899 aServant->GetGroups();
901 return aMesh._retn();
904 //=============================================================================
906 * SMESH_Gen_i::CreateMeshFromMED
908 * Create mesh and import data from MED file
910 //=============================================================================
912 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
913 SMESH::DriverMED_ReadStatus& theStatus)
914 throw ( SALOME::SALOME_Exception )
916 Unexpect aCatch(SALOME_SalomeException);
917 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
919 // Retrieve mesh names from the file
920 DriverMED_R_SMESHDS_Mesh myReader;
921 myReader.SetFile( theFileName );
922 myReader.SetMeshId( -1 );
923 Driver_Mesh::Status aStatus;
924 list<string> aNames = myReader.GetMeshNames(aStatus);
925 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
926 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
928 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
931 TPythonDump aPythonDump;
933 //TCollection_AsciiString aStr ("([");
935 if (theStatus == SMESH::DRS_OK) {
936 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
937 aStudyBuilder->NewCommand(); // There is a transaction
938 aResult->length( aNames.size() );
941 // Iterate through all meshes and create mesh objects
942 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
944 //if (i > 0) aStr += ", ";
945 if (i > 0) aPythonDump << ", ";
948 SMESH::SMESH_Mesh_var mesh = createMesh();
950 // publish mesh in the study
951 SALOMEDS::SObject_var aSO;
952 if ( CanPublishInStudy( mesh ) )
953 aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
954 if ( !aSO->_is_nil() ) {
957 //aStr += aSO->GetID();
960 aPythonDump << "mesh_" << i;
962 // aStr += TCollection_AsciiString(i);
965 // Read mesh data (groups are published automatically by ImportMEDFile())
966 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
967 ASSERT( meshServant );
968 SMESH::DriverMED_ReadStatus status1 =
969 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
970 if (status1 > theStatus)
973 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
975 aStudyBuilder->CommitCommand();
978 // Update Python script
979 aPythonDump << "], status) = " << this << ".CreateMeshesFromMED('" << theFileName << "')";
981 // Dump creation of groups
982 for ( int i = 0; i < aResult->length(); ++i )
983 aResult[ i ]->GetGroups();
985 return aResult._retn();
988 //=============================================================================
990 * SMESH_Gen_i::CreateMeshFromSTL
992 * Create mesh and import data from STL file
994 //=============================================================================
996 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
997 throw ( SALOME::SALOME_Exception )
999 Unexpect aCatch(SALOME_SalomeException);
1000 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
1002 SMESH::SMESH_Mesh_var aMesh = createMesh();
1004 // publish mesh in the study
1005 if ( CanPublishInStudy( aMesh ) ) {
1006 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1007 aStudyBuilder->NewCommand(); // There is a transaction
1008 SALOMEDS::SObject_var aSO = PublishInStudy
1009 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1010 aStudyBuilder->CommitCommand();
1011 if ( !aSO->_is_nil() ) {
1012 // Update Python script
1013 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL('" << theFileName << "')";
1017 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1019 aServant->ImportSTLFile( theFileName );
1020 return aMesh._retn();
1023 //=============================================================================
1025 * SMESH_Gen_i::IsReadyToCompute
1027 * Returns true if mesh contains enough data to be computed
1029 //=============================================================================
1031 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
1032 GEOM::GEOM_Object_ptr theShapeObject )
1033 throw ( SALOME::SALOME_Exception )
1035 Unexpect aCatch(SALOME_SalomeException);
1036 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
1038 if ( CORBA::is_nil( theShapeObject ) )
1039 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1040 SALOME::BAD_PARAM );
1042 if ( CORBA::is_nil( theMesh ) )
1043 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1044 SALOME::BAD_PARAM );
1048 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1049 ASSERT( meshServant );
1050 if ( meshServant ) {
1051 // get local TopoDS_Shape
1052 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1053 // call implementation
1054 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1055 return myGen.CheckAlgoState( myLocMesh, myLocShape );
1058 catch ( SALOME_Exception& S_ex ) {
1059 INFOS( "catch exception "<< S_ex.what() );
1064 //================================================================================
1066 * \brief Find SObject for an algo
1068 //================================================================================
1070 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
1073 if ( !myCurrentStudy->_is_nil() ) {
1074 // find algo in the study
1075 SALOMEDS::SComponent_var father = SALOMEDS::SComponent::_narrow
1076 ( myCurrentStudy->FindComponent( ComponentDataType() ) );
1077 if ( !father->_is_nil() ) {
1078 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( father );
1079 for ( ; itBig->More(); itBig->Next() ) {
1080 SALOMEDS::SObject_var gotBranch = itBig->Value();
1081 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1082 SALOMEDS::ChildIterator_var algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1083 for ( ; algoIt->More(); algoIt->Next() ) {
1084 SALOMEDS::SObject_var algoSO = algoIt->Value();
1085 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1086 if ( !CORBA::is_nil( algoIOR )) {
1087 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1088 if ( impl && impl->GetImpl() == algo )
1089 return algoSO._retn();
1091 } // loop on algo SO's
1094 } // SMESH component iterator
1098 return SALOMEDS::SObject::_nil();
1101 //================================================================================
1103 * \brief Return errors of mesh computation
1105 //================================================================================
1107 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1108 GEOM::GEOM_Object_ptr theSubObject )
1109 throw ( SALOME::SALOME_Exception )
1111 Unexpect aCatch(SALOME_SalomeException);
1112 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1114 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1115 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1117 if ( CORBA::is_nil( theMesh ) )
1118 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1120 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1122 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1125 if(theMesh->HasShapeToMesh())
1126 shape = GeomObjectToShape( theSubObject );
1128 shape = SMESH_Mesh::PseudoShape();
1130 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1132 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1135 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1136 const bool includeSelf = true, complexShapeFirst = true;
1137 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1139 while ( smIt->more() )
1142 if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1144 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1145 if ( error && !error->IsOK() && error->myAlgo )
1147 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1148 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1149 errStruct.comment = error->myComment.c_str();
1150 errStruct.subShapeID = sm->GetId();
1151 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->myAlgo );
1152 if ( !algoSO->_is_nil() )
1153 errStruct.algoName = algoSO->GetName();
1155 errStruct.algoName = error->myAlgo->GetName();
1156 errStruct.hasBadMesh = !error->myBadElements.empty();
1159 error_array->length( nbErr );
1162 catch ( SALOME_Exception& S_ex ) {
1163 INFOS( "catch exception "<< S_ex.what() );
1166 return error_array._retn();
1170 //================================================================================
1172 * \brief Return mesh elements preventing computation of a subshape
1174 //================================================================================
1176 SMESH::MeshPreviewStruct*
1177 SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1178 CORBA::Short theSubShapeID )
1179 throw ( SALOME::SALOME_Exception )
1181 Unexpect aCatch(SALOME_SalomeException);
1182 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetBadInputElements()" );
1184 if ( CORBA::is_nil( theMesh ) )
1185 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1187 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1190 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1192 // mesh implementation
1193 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1194 // submesh by subshape id
1195 if ( SMESH_subMesh * sm = mesh.GetSubMeshContaining( theSubShapeID ))
1198 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1199 if ( error && !error->myBadElements.empty())
1201 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1202 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1204 // get nodes of elements and count elements
1205 TNode2LocalIDMap mapNode2LocalID;
1206 list< TNodeLocalID > connectivity;
1207 int i, nbElements = 0, nbConnNodes = 0;
1209 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
1210 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
1211 for ( ; elemIt != elemEnd; ++elemIt, ++nbElements )
1213 SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator();
1214 while ( nIt->more() )
1215 connectivity.push_back
1216 ( mapNode2LocalID.insert( make_pair( nIt->next(), ++nbConnNodes)).first );
1218 // fill node coords and assign local ids to the nodes
1219 int nbNodes = mapNode2LocalID.size();
1220 result->nodesXYZ.length( nbNodes );
1221 TNodeLocalID node2ID = mapNode2LocalID.begin();
1222 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1223 node2ID->second = i;
1224 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1225 result->nodesXYZ[i].x = node->X();
1226 result->nodesXYZ[i].y = node->Y();
1227 result->nodesXYZ[i].z = node->Z();
1229 // fill connectivity
1230 result->elementConnectivities.length( nbConnNodes );
1231 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1232 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1233 result->elementConnectivities[i] = (*connIt)->second;
1235 // fill element types
1236 result->elementTypes.length( nbElements );
1237 for ( i = 0, elemIt = error->myBadElements.begin(); i <nbElements; ++i, ++elemIt )
1239 const SMDS_MeshElement* elem = *elemIt;
1240 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType();
1241 result->elementTypes[i].isPoly = elem->IsPoly();
1242 result->elementTypes[i].nbNodesInElement = elem->NbNodes();
1248 catch ( SALOME_Exception& S_ex ) {
1249 INFOS( "catch exception "<< S_ex.what() );
1252 return result._retn();
1255 //================================================================================
1257 * \brief Returns errors of hypotheses definintion
1258 * \param theMesh - the mesh
1259 * \param theSubObject - the main or sub- shape
1260 * \retval SMESH::algo_error_array* - sequence of errors
1262 //================================================================================
1264 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1265 GEOM::GEOM_Object_ptr theSubObject )
1266 throw ( SALOME::SALOME_Exception )
1268 Unexpect aCatch(SALOME_SalomeException);
1269 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1271 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1272 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1274 if ( CORBA::is_nil( theMesh ) )
1275 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1277 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1279 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1280 ASSERT( meshServant );
1281 if ( meshServant ) {
1282 TopoDS_Shape myLocShape;
1283 if(theMesh->HasShapeToMesh())
1284 myLocShape = GeomObjectToShape( theSubObject );
1286 myLocShape = SMESH_Mesh::PseudoShape();
1288 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1289 list< ::SMESH_Gen::TAlgoStateError > error_list;
1290 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1291 // call ::SMESH_Gen::GetAlgoState()
1292 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1293 error_array->length( error_list.size() );
1295 for ( error = error_list.begin(); error != error_list.end(); ++error )
1297 // fill AlgoStateError structure
1298 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1299 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1300 errStruct.algoDim = error->_algoDim;
1301 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1302 errStruct.algoName = "";
1303 SALOMEDS::SObject_var algoSO = GetAlgoSO( error->_algo );
1304 if ( !algoSO->_is_nil() )
1305 errStruct.algoName = algoSO->GetName();
1309 catch ( SALOME_Exception& S_ex ) {
1310 INFOS( "catch exception "<< S_ex.what() );
1312 return error_array._retn();
1315 //=============================================================================
1317 * SMESH_Gen_i::GetSubShapesId
1319 * Get sub-shapes unique ID's list
1321 //=============================================================================
1323 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1324 const SMESH::object_array& theListOfSubShapeObject )
1325 throw ( SALOME::SALOME_Exception )
1327 Unexpect aCatch(SALOME_SalomeException);
1328 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1330 SMESH::long_array_var shapesId = new SMESH::long_array;
1333 if ( CORBA::is_nil( theMainShapeObject ) )
1334 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1335 SALOME::BAD_PARAM );
1339 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1340 TopTools_IndexedMapOfShape myIndexToShape;
1341 TopExp::MapShapes(myMainShape,myIndexToShape);
1343 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1345 GEOM::GEOM_Object_var aShapeObject
1346 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1347 if ( CORBA::is_nil( aShapeObject ) )
1348 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1349 SALOME::BAD_PARAM );
1351 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1352 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1354 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1355 setId.insert(myIndexToShape.FindIndex(F));
1356 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1358 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1360 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1361 setId.insert(myIndexToShape.FindIndex(E));
1362 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1364 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1366 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1367 setId.insert(myIndexToShape.FindIndex(V));
1368 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1371 shapesId->length(setId.size());
1372 set<int>::iterator iind;
1374 for (iind = setId.begin(); iind != setId.end(); iind++)
1376 if(MYDEBUG) SCRUTE((*iind));
1377 shapesId[i] = (*iind);
1378 if(MYDEBUG) SCRUTE(shapesId[i]);
1382 catch (SALOME_Exception& S_ex)
1384 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1387 return shapesId._retn();
1390 //=============================================================================
1392 * SMESH_Gen_i::Compute
1394 * Compute mesh on a shape
1396 //=============================================================================
1398 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1399 GEOM::GEOM_Object_ptr theShapeObject )
1400 throw ( SALOME::SALOME_Exception )
1402 Unexpect aCatch(SALOME_SalomeException);
1403 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1405 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1406 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1407 SALOME::BAD_PARAM );
1409 if ( CORBA::is_nil( theMesh ) )
1410 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1411 SALOME::BAD_PARAM );
1413 // Update Python script
1414 TPythonDump() << "isDone = " << this << ".Compute( "
1415 << theMesh << ", " << theShapeObject << ")";
1419 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1420 ASSERT( meshServant );
1421 if ( meshServant ) {
1422 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1423 meshServant->CheckGeomGroupModif();
1424 // get local TopoDS_Shape
1425 TopoDS_Shape myLocShape;
1426 if(theMesh->HasShapeToMesh())
1427 myLocShape = GeomObjectToShape( theShapeObject );
1429 myLocShape = SMESH_Mesh::PseudoShape();
1430 // call implementation compute
1431 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1432 return myGen.Compute( myLocMesh, myLocShape);
1435 catch ( std::bad_alloc ) {
1436 INFOS( "Compute(): lack of memory" );
1438 catch ( SALOME_Exception& S_ex ) {
1439 INFOS( "Compute(): catch exception "<< S_ex.what() );
1442 INFOS( "Compute(): unknown exception " );
1447 //=============================================================================
1449 * SMESH_Gen_i::Precompute
1451 * Compute mesh as preview till indicated dimension on shape
1453 //=============================================================================
1455 SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh,
1456 GEOM::GEOM_Object_ptr theShapeObject,
1457 SMESH::Dimension theDimension,
1458 SMESH::long_array& theShapesId)
1459 throw ( SALOME::SALOME_Exception )
1461 Unexpect aCatch(SALOME_SalomeException);
1462 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Precompute" );
1464 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1465 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1466 SALOME::BAD_PARAM );
1468 if ( CORBA::is_nil( theMesh ) )
1469 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1470 SALOME::BAD_PARAM );
1472 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1475 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1476 ASSERT( meshServant );
1477 if ( meshServant ) {
1478 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1479 meshServant->CheckGeomGroupModif();
1480 // get local TopoDS_Shape
1481 TopoDS_Shape myLocShape;
1482 if(theMesh->HasShapeToMesh())
1483 myLocShape = GeomObjectToShape( theShapeObject );
1485 return result._retn();;
1487 // call implementation compute
1488 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1490 ::MeshDimension aDim = (MeshDimension)theDimension;
1491 if ( myGen.Compute( myLocMesh, myLocShape, false, aDim, &shapeIds ) )
1493 int nbShapeId = shapeIds.size();
1494 theShapesId.length( nbShapeId );
1495 // iterates on shapes and collect mesh entities into mesh preview
1496 TSetOfInt::const_iterator idIt = shapeIds.begin();
1497 TSetOfInt::const_iterator idEnd = shapeIds.end();
1498 std::map< int, int > mapOfShIdNb;
1499 std::set< SMESH_TLink > setOfEdge;
1500 std::list< SMDSAbs_ElementType > listOfElemType;
1501 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1502 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1503 TNode2LocalIDMap mapNode2LocalID;
1504 list< TNodeLocalID > connectivity;
1505 int i, nbConnNodes = 0;
1506 std::set< const SMESH_subMesh* > setOfVSubMesh;
1507 // iterates on shapes
1508 for ( ; idIt != idEnd; idIt++ )
1510 if ( mapOfShIdNb.find( *idIt ) != mapOfShIdNb.end() )
1512 SMESH_subMesh* sm = myLocMesh.GetSubMeshContaining(*idIt);
1513 if ( !sm || !sm->IsMeshComputed() )
1516 const TopoDS_Shape& aSh = sm->GetSubShape();
1517 const int shDim = myGen.GetShapeDim( aSh );
1518 if ( shDim < 1 || shDim > theDimension )
1521 mapOfShIdNb[ *idIt ] = 0;
1522 theShapesId[ mapOfShIdNb.size() - 1 ] = *idIt;
1524 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1525 if ( !smDS ) continue;
1527 if ( theDimension == SMESH::DIM_2D )
1529 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1530 while ( faceIt->more() )
1532 const SMDS_MeshElement* face = faceIt->next();
1533 int aNbNode = face->NbNodes();
1535 aNbNode /= 2; // do not take into account additional middle nodes
1537 SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
1538 for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
1540 SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
1541 if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
1543 listOfElemType.push_back( SMDSAbs_Edge );
1544 connectivity.push_back
1545 ( mapNode2LocalID.insert( make_pair( node1, ++nbConnNodes)).first );
1546 connectivity.push_back
1547 ( mapNode2LocalID.insert( make_pair( node2, ++nbConnNodes)).first );
1553 else if ( theDimension == SMESH::DIM_1D )
1555 SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
1556 while ( nodeIt->more() )
1558 listOfElemType.push_back( SMDSAbs_Node );
1559 connectivity.push_back
1560 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1562 // add corner nodes by first vertex from edge
1563 SMESH_subMeshIteratorPtr edgeSmIt =
1564 sm->getDependsOnIterator(/*includeSelf*/false,
1565 /*complexShapeFirst*/false);
1566 while ( edgeSmIt->more() )
1568 SMESH_subMesh* vertexSM = edgeSmIt->next();
1569 // check that vertex is not already treated
1570 if ( !setOfVSubMesh.insert( vertexSM ).second )
1572 if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
1575 const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
1576 SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
1577 while ( nodeIt->more() )
1579 listOfElemType.push_back( SMDSAbs_Node );
1580 connectivity.push_back
1581 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1587 // fill node coords and assign local ids to the nodes
1588 int nbNodes = mapNode2LocalID.size();
1589 result->nodesXYZ.length( nbNodes );
1590 TNodeLocalID node2ID = mapNode2LocalID.begin();
1591 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1592 node2ID->second = i;
1593 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1594 result->nodesXYZ[i].x = node->X();
1595 result->nodesXYZ[i].y = node->Y();
1596 result->nodesXYZ[i].z = node->Z();
1598 // fill connectivity
1599 result->elementConnectivities.length( nbConnNodes );
1600 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1601 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1602 result->elementConnectivities[i] = (*connIt)->second;
1605 // fill element types
1606 result->elementTypes.length( listOfElemType.size() );
1607 std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
1608 std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
1609 for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
1611 SMDSAbs_ElementType elemType = *typeIt;
1612 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
1613 result->elementTypes[i].isPoly = false;
1614 result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
1617 // correct number of shapes
1618 theShapesId.length( mapOfShIdNb.size() );
1622 catch ( std::bad_alloc ) {
1623 INFOS( "Precompute(): lack of memory" );
1625 catch ( SALOME_Exception& S_ex ) {
1626 INFOS( "Precompute(): catch exception "<< S_ex.what() );
1629 INFOS( "Precompute(): unknown exception " );
1631 return result._retn();
1635 //=============================================================================
1637 * SMESH_Gen_i::Evaluate
1639 * Evaluate mesh on a shape
1641 //=============================================================================
1643 SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
1644 GEOM::GEOM_Object_ptr theShapeObject)
1645 // SMESH::long_array& theNbElems)
1646 throw ( SALOME::SALOME_Exception )
1648 Unexpect aCatch(SALOME_SalomeException);
1649 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
1651 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1652 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1653 SALOME::BAD_PARAM );
1655 if ( CORBA::is_nil( theMesh ) )
1656 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1657 SALOME::BAD_PARAM );
1659 SMESH::long_array_var nbels = new SMESH::long_array;
1660 nbels->length(SMESH::Entity_Last);
1661 int i = SMESH::Entity_Node;
1662 for (; i < SMESH::Entity_Last; i++)
1665 // Update Python script
1666 TPythonDump() << "theNbElems = " << this << ".Evaluate( "
1667 << theMesh << ", " << theShapeObject << ")";
1671 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1672 ASSERT( meshServant );
1673 if ( meshServant ) {
1674 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1675 meshServant->CheckGeomGroupModif();
1676 // get local TopoDS_Shape
1677 TopoDS_Shape myLocShape;
1678 if(theMesh->HasShapeToMesh())
1679 myLocShape = GeomObjectToShape( theShapeObject );
1681 myLocShape = SMESH_Mesh::PseudoShape();
1682 // call implementation compute
1683 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1684 MapShapeNbElems aResMap;
1685 /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
1686 MapShapeNbElemsItr anIt = aResMap.begin();
1687 for(; anIt!=aResMap.end(); anIt++) {
1688 const vector<int>& aVec = (*anIt).second;
1689 for(i = SMESH::Entity_Node; i < aVec.size(); i++) {
1690 int nbElem = aVec[i];
1691 if ( nbElem < 0 ) // algo failed, check that it has reported a message
1693 SMESH_subMesh* sm = anIt->first;
1694 SMESH_ComputeErrorPtr& error = sm->GetComputeError();
1695 const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
1696 if ( algo && !error.get() || error->IsOK() )
1697 error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
1701 nbels[i] += aVec[i];
1705 return nbels._retn();
1708 catch ( std::bad_alloc ) {
1709 INFOS( "Evaluate(): lack of memory" );
1711 catch ( SALOME_Exception& S_ex ) {
1712 INFOS( "Evaluate(): catch exception "<< S_ex.what() );
1715 INFOS( "Evaluate(): unknown exception " );
1718 return nbels._retn();
1721 //================================================================================
1723 * \brief Return geometrical object the given element is built on
1724 * \param theMesh - the mesh the element is in
1725 * \param theElementID - the element ID
1726 * \param theGeomName - the name of the result geom object if it is not yet published
1727 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object
1729 //================================================================================
1731 GEOM::GEOM_Object_ptr
1732 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1733 CORBA::Long theElementID,
1734 const char* theGeomName)
1735 throw ( SALOME::SALOME_Exception )
1737 Unexpect aCatch(SALOME_SalomeException);
1739 GEOM::GEOM_Object_var geom = FindGeometryByMeshElement(theMesh, theElementID);
1740 if ( !geom->_is_nil() ) {
1741 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1742 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1744 // try to find the corresponding SObject
1745 SALOMEDS::SObject_var SObj = ObjectToSObject( myCurrentStudy, geom.in() );
1746 if ( SObj->_is_nil() ) // submesh can be not found even if published
1748 // try to find published submesh
1749 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
1750 if ( !geom->IsMainShape() && list->length() == 1 ) {
1751 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1752 SALOMEDS::ChildIterator_var it;
1753 if ( !mainSO->_is_nil() )
1754 it = myCurrentStudy->NewChildIterator( mainSO );
1755 if ( !it->_is_nil() ) {
1756 for ( it->InitEx(true); SObj->_is_nil() && it->More(); it->Next() ) {
1757 GEOM::GEOM_Object_var subGeom =
1758 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1759 if ( !subGeom->_is_nil() ) {
1760 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1761 if ( subList->length() == 1 && list[0] == subList[0] ) {
1770 if ( SObj->_is_nil() ) // publish a new subshape
1771 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
1773 // return only published geometry
1774 if ( !SObj->_is_nil() )
1775 return geom._retn();
1777 return GEOM::GEOM_Object::_nil();
1780 //================================================================================
1782 * \brief Return geometrical object the given element is built on.
1783 * \param theMesh - the mesh the element is in
1784 * \param theElementID - the element ID
1785 * \retval GEOM::GEOM_Object_ptr - the found geom object
1787 //================================================================================
1789 GEOM::GEOM_Object_ptr
1790 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
1791 CORBA::Long theElementID)
1792 throw ( SALOME::SALOME_Exception )
1794 Unexpect aCatch(SALOME_SalomeException);
1795 if ( CORBA::is_nil( theMesh ) )
1796 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
1798 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
1799 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
1801 // get a core mesh DS
1802 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1803 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
1805 ::SMESH_Mesh & mesh = meshServant->GetImpl();
1806 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
1807 // find the element in mesh
1808 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
1809 // find a shape id by the element
1810 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
1811 // get a geom object by the shape id
1812 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
1813 if ( geom->_is_nil() ) {
1814 // try to find a published sub-shape
1815 SALOMEDS::SObject_var mainSO = ObjectToSObject( myCurrentStudy, mainShape );
1816 SALOMEDS::ChildIterator_var it;
1817 if ( !mainSO->_is_nil() )
1818 it = myCurrentStudy->NewChildIterator( mainSO );
1819 if ( !it->_is_nil() ) {
1820 for ( it->InitEx(true); it->More(); it->Next() ) {
1821 GEOM::GEOM_Object_var subGeom =
1822 GEOM::GEOM_Object::_narrow( SObjectToObject( it->Value() ));
1823 if ( !subGeom->_is_nil() ) {
1824 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
1825 if ( subList->length() == 1 && shapeID == subList[0] ) {
1833 if ( geom->_is_nil() ) {
1835 GEOM::GEOM_IShapesOperations_var op =
1836 geomGen->GetIShapesOperations( GetCurrentStudyID() );
1837 if ( !op->_is_nil() )
1838 geom = op->GetSubShape( mainShape, shapeID );
1840 if ( !geom->_is_nil() ) {
1841 GeomObjectToShape( geom ); // let geom client remember the found shape
1842 return geom._retn();
1847 return GEOM::GEOM_Object::_nil();
1850 //================================================================================
1852 * SMESH_Gen_i::Concatenate
1854 * Concatenate the given meshes into one mesh
1856 //================================================================================
1858 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
1859 CORBA::Boolean theUniteIdenticalGroups,
1860 CORBA::Boolean theMergeNodesAndElements,
1861 CORBA::Double theMergeTolerance)
1862 throw ( SALOME::SALOME_Exception )
1864 return ConcatenateCommon(theMeshesArray,
1865 theUniteIdenticalGroups,
1866 theMergeNodesAndElements,
1871 //================================================================================
1873 * SMESH_Gen_i::ConcatenateWithGroups
1875 * Concatenate the given meshes into one mesh
1876 * Create the groups of all elements from initial meshes
1878 //================================================================================
1880 SMESH::SMESH_Mesh_ptr
1881 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
1882 CORBA::Boolean theUniteIdenticalGroups,
1883 CORBA::Boolean theMergeNodesAndElements,
1884 CORBA::Double theMergeTolerance)
1885 throw ( SALOME::SALOME_Exception )
1887 return ConcatenateCommon(theMeshesArray,
1888 theUniteIdenticalGroups,
1889 theMergeNodesAndElements,
1894 //================================================================================
1896 * SMESH_Gen_i::ConcatenateCommon
1898 * Concatenate the given meshes into one mesh
1900 //================================================================================
1902 SMESH::SMESH_Mesh_ptr
1903 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
1904 CORBA::Boolean theUniteIdenticalGroups,
1905 CORBA::Boolean theMergeNodesAndElements,
1906 CORBA::Double theMergeTolerance,
1907 CORBA::Boolean theCommonGroups)
1908 throw ( SALOME::SALOME_Exception )
1910 typedef map<int, int> TIDsMap;
1911 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
1912 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
1913 typedef std::set<SMESHDS_GroupBase*> TGroups;
1915 TPythonDump* pPythonDump = new TPythonDump;
1916 TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
1919 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
1921 if ( !aNewMesh->_is_nil() ) {
1922 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
1924 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
1925 SMESHDS_Mesh* aNewMeshDS = aLocMesh.GetMeshDS();
1927 TGroupsMap aGroupsMap;
1928 TListOfNewGroups aListOfNewGroups;
1929 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
1930 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
1933 for ( int i = 0; i < theMeshesArray.length(); i++) {
1934 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
1935 if ( !anInitMesh->_is_nil() ) {
1936 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
1938 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
1939 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
1944 // loop on elements of mesh
1945 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
1946 const SMDS_MeshElement* anElem = 0;
1947 const SMDS_MeshElement* aNewElem = 0;
1948 int anElemNbNodes = 0;
1953 int anNbVolumes = 0;
1955 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
1956 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
1957 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
1958 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
1960 if( theCommonGroups ) {
1961 anIDsNodes->length( anInitMeshDS->NbNodes() );
1962 anIDsEdges->length( anInitMeshDS->NbEdges() );
1963 anIDsFaces->length( anInitMeshDS->NbFaces() );
1964 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
1967 for ( int j = 0; itElems->more(); j++) {
1968 anElem = itElems->next();
1969 SMDSAbs_ElementType anElemType = anElem->GetType();
1970 anElemNbNodes = anElem->NbNodes();
1971 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
1973 // loop on nodes of element
1974 const SMDS_MeshNode* aNode = 0;
1975 const SMDS_MeshNode* aNewNode = 0;
1976 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
1978 for ( int k = 0; itNodes->more(); k++) {
1979 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
1980 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
1981 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
1982 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
1983 if( theCommonGroups )
1984 anIDsNodes[anNbNodes++] = aNewNode->GetID();
1987 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
1988 aNodesArray[k] = aNewNode;
1991 // creates a corresponding element on existent nodes in new mesh
1992 if ( anElem->IsPoly() && anElemType == SMDSAbs_Volume )
1994 const SMDS_PolyhedralVolumeOfNodes* aVolume =
1995 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
1997 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
1998 aVolume->GetQuanities());
1999 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2000 if( theCommonGroups )
2001 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2006 aNewElem = aNewEditor.AddElement(aNodesArray,
2009 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2010 if( theCommonGroups ) {
2011 if( anElemType == SMDSAbs_Edge )
2012 anIDsEdges[anNbEdges++] = aNewElem->GetID();
2013 else if( anElemType == SMDSAbs_Face )
2014 anIDsFaces[anNbFaces++] = aNewElem->GetID();
2015 else if( anElemType == SMDSAbs_Volume )
2016 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2021 aListOfGroups = anInitImpl->GetGroups();
2022 SMESH::SMESH_GroupBase_ptr aGroup;
2024 // loop on groups of mesh
2025 SMESH::long_array_var anInitIDs = new SMESH::long_array();
2026 SMESH::long_array_var anNewIDs = new SMESH::long_array();
2027 SMESH::SMESH_Group_var aNewGroup;
2029 SMESH::ElementType aGroupType;
2030 CORBA::String_var aGroupName;
2031 if ( theCommonGroups ) {
2032 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::VOLUME;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
2034 SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
2036 str += aMeshSObj->GetName();
2041 switch(aGroupType) {
2044 anIDsNodes->length(anNbNodes);
2049 anIDsEdges->length(anNbEdges);
2054 anIDsFaces->length(anNbFaces);
2059 anIDsVolumes->length(anNbVolumes);
2060 anLen = anNbVolumes;
2067 aGroupName = str.c_str();
2069 // add a new group in the mesh
2070 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2072 switch(aGroupType) {
2074 aNewGroup->Add( anIDsNodes );
2077 aNewGroup->Add( anIDsEdges );
2080 aNewGroup->Add( anIDsFaces );
2083 aNewGroup->Add( anIDsVolumes );
2089 aListOfNewGroups.clear();
2090 aListOfNewGroups.push_back(aNewGroup);
2091 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2096 // check that current group name and type don't have identical ones in union mesh
2097 for (int i = 0; i < aListOfGroups->length(); i++) {
2098 aGroup = aListOfGroups[i];
2099 aListOfNewGroups.clear();
2100 aGroupType = aGroup->GetType();
2101 aGroupName = aGroup->GetName();
2103 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
2105 // convert a list of IDs
2106 anInitIDs = aGroup->GetListOfID();
2107 anNewIDs->length(anInitIDs->length());
2108 if ( aGroupType == SMESH::NODE )
2109 for (int j = 0; j < anInitIDs->length(); j++) {
2110 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
2113 for (int j = 0; j < anInitIDs->length(); j++) {
2114 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
2117 // check that current group name and type don't have identical ones in union mesh
2118 if ( anIter == aGroupsMap.end() ) {
2119 // add a new group in the mesh
2120 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2121 // add elements into new group
2122 aNewGroup->Add( anNewIDs );
2124 aListOfNewGroups.push_back(aNewGroup);
2125 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2128 else if ( theUniteIdenticalGroups ) {
2129 // unite identical groups
2130 TListOfNewGroups& aNewGroups = anIter->second;
2131 aNewGroups.front()->Add( anNewIDs );
2135 // rename identical groups
2136 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2137 aNewGroup->Add( anNewIDs );
2139 TListOfNewGroups& aNewGroups = anIter->second;
2140 string aNewGroupName;
2141 if (aNewGroups.size() == 1) {
2142 aNewGroupName = string(aGroupName) + "_1";
2143 aNewGroups.front()->SetName(aNewGroupName.c_str());
2145 char aGroupNum[128];
2146 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
2147 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
2148 aNewGroup->SetName(aNewGroupName.c_str());
2149 aNewGroups.push_back(aNewGroup);
2156 if (theMergeNodesAndElements) {
2158 set<const SMDS_MeshNode*> aMeshNodes; // no input nodes
2159 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
2160 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
2161 aNewEditor.MergeNodes( aGroupsOfNodes );
2163 aNewEditor.MergeEqualElements();
2168 // Update Python script
2169 aPythonDump << aNewMesh << " = " << this;
2170 if( !theCommonGroups )
2171 aPythonDump << ".Concatenate(";
2173 aPythonDump << ".ConcatenateWithGroups(";
2175 for ( int i = 0; i < theMeshesArray.length(); i++) {
2176 if (i > 0) aPythonDump << ", ";
2177 aPythonDump << theMeshesArray[i];
2179 aPythonDump << "], ";
2180 aPythonDump << theUniteIdenticalGroups << ", "
2181 << theMergeNodesAndElements << ", "
2182 << theMergeTolerance << ")";
2184 delete pPythonDump; // enable python dump from GetGroups()
2186 // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
2187 if ( !aNewMesh->_is_nil() )
2189 SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
2192 // IPAL21468 Change icon of compound because it need not be computed.
2193 SALOMEDS::SObject_var aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
2194 if( !aMeshSObj->_is_nil() ) {
2195 SALOMEDS::GenericAttribute_var anAttr;
2196 SALOMEDS::StudyBuilder_var aBuilder = myCurrentStudy->NewBuilder();
2197 anAttr = aBuilder->FindOrCreateAttribute( aMeshSObj,"AttributePixMap" );
2198 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
2199 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
2202 return aNewMesh._retn();
2205 //================================================================================
2207 * SMESH_Gen_i::GetMEDVersion
2209 * Get MED version of the file by its name
2211 //================================================================================
2212 CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
2213 SMESH::MED_VERSION& theVersion)
2215 theVersion = SMESH::MED_V2_1;
2216 MED::EVersion aVersion = MED::GetVersionId( theFileName );
2217 switch( aVersion ) {
2218 case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
2219 case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
2220 case MED::eVUnknown : return false;
2225 //================================================================================
2227 * SMESH_Gen_i::GetMeshNames
2229 * Get names of meshes defined in file with the specified name
2231 //================================================================================
2232 SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
2234 SMESH::string_array_var aResult = new SMESH::string_array();
2235 MED::PWrapper aMed = MED::CrWrapper( theFileName );
2237 MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
2239 aResult->length( aNbMeshes );
2240 for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
2241 MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
2242 aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
2245 return aResult._retn();
2248 //=============================================================================
2252 * Save SMESH module's data
2254 //=============================================================================
2255 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
2259 INFOS( "SMESH_Gen_i::Save" );
2261 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
2262 // san -- in case <myCurrentStudy> differs from theComponent's study,
2263 // use that of the component
2264 if ( myCurrentStudy->_is_nil() ||
2265 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2266 SetCurrentStudy( theComponent->GetStudy() );
2268 // Store study contents as a set of python commands
2269 SavePython(myCurrentStudy);
2271 StudyContext* myStudyContext = GetCurrentStudyContext();
2273 // Declare a byte stream
2274 SALOMEDS::TMPFile_var aStreamFile;
2276 // Obtain a temporary dir
2277 TCollection_AsciiString tmpDir =
2278 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2280 // Create a sequence of files processed
2281 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2282 aFileSeq->length( NUM_TMP_FILES );
2284 TCollection_AsciiString aStudyName( "" );
2286 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2288 // Set names of temporary files
2289 TCollection_AsciiString filename =
2290 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
2291 TCollection_AsciiString meshfile =
2292 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
2293 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
2294 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
2295 filename = tmpDir + filename;
2296 meshfile = tmpDir + meshfile;
2299 HDFdataset* aDataset;
2300 HDFgroup* aTopGroup;
2302 HDFgroup* aSubGroup;
2303 HDFgroup* aSubSubGroup;
2304 hdf_size aSize[ 1 ];
2307 //Remove the files if they exist: BugID: 11225
2308 #ifndef WNT /* unix functionality */
2309 TCollection_AsciiString cmd("rm -f \"");
2311 TCollection_AsciiString cmd("del /F \"");
2318 system(cmd.ToCString());
2320 // MED writer to be used by storage process
2321 DriverMED_W_SMESHDS_Mesh myWriter;
2322 myWriter.SetFile( meshfile.ToCString() );
2325 // ---> create HDF file
2326 aFile = new HDFfile( (char*) filename.ToCString() );
2327 aFile->CreateOnDisk();
2329 // --> iterator for top-level objects
2330 SALOMEDS::ChildIterator_var itBig = myCurrentStudy->NewChildIterator( theComponent );
2331 for ( ; itBig->More(); itBig->Next() ) {
2332 SALOMEDS::SObject_var gotBranch = itBig->Value();
2334 // --> hypotheses root branch (only one for the study)
2335 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
2336 // create hypotheses root HDF group
2337 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2338 aTopGroup->CreateOnDisk();
2340 // iterator for all hypotheses
2341 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
2342 for ( ; it->More(); it->Next() ) {
2343 SALOMEDS::SObject_var mySObject = it->Value();
2344 CORBA::Object_var anObject = SObjectToObject( mySObject );
2345 if ( !CORBA::is_nil( anObject ) ) {
2346 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2347 if ( !myHyp->_is_nil() ) {
2348 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2350 string hypname = string( myHyp->GetName() );
2351 string libname = string( myHyp->GetLibName() );
2353 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
2354 // WNT and ".so" for X-system) must be deleted
2355 int libname_len = libname.length();
2357 if( libname_len > 4 )
2358 libname.resize( libname_len - 4 );
2360 // PAL17753 (Regresion: missing hypothesis in restored study)
2361 // "lib" also should be removed from the beginning
2362 //if( libname_len > 3 )
2363 //libname.resize( libname_len - 3 );
2364 if( libname_len > 6 )
2365 libname = libname.substr( 3, libname_len - 3 - 3 );
2367 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2368 int id = myStudyContext->findId( string( objStr.in() ) );
2369 string hypdata = string( myImpl->SaveTo() );
2371 // for each hypothesis create HDF group basing on its id
2372 char hypGrpName[30];
2373 sprintf( hypGrpName, "Hypothesis %d", id );
2374 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2375 aGroup->CreateOnDisk();
2376 // --> type name of hypothesis
2377 aSize[ 0 ] = hypname.length() + 1;
2378 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
2379 aDataset->CreateOnDisk();
2380 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
2381 aDataset->CloseOnDisk();
2382 // --> server plugin library name of hypothesis
2383 aSize[ 0 ] = libname.length() + 1;
2384 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
2385 aDataset->CreateOnDisk();
2386 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
2387 aDataset->CloseOnDisk();
2388 // --> persistent data of hypothesis
2389 aSize[ 0 ] = hypdata.length() + 1;
2390 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
2391 aDataset->CreateOnDisk();
2392 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
2393 aDataset->CloseOnDisk();
2394 // close hypothesis HDF group
2395 aGroup->CloseOnDisk();
2400 // close hypotheses root HDF group
2401 aTopGroup->CloseOnDisk();
2403 // --> algorithms root branch (only one for the study)
2404 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
2405 // create algorithms root HDF group
2406 aTopGroup = new HDFgroup( "Algorithms", aFile );
2407 aTopGroup->CreateOnDisk();
2409 // iterator for all algorithms
2410 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( gotBranch );
2411 for ( ; it->More(); it->Next() ) {
2412 SALOMEDS::SObject_var mySObject = it->Value();
2413 CORBA::Object_var anObject = SObjectToObject( mySObject );
2414 if ( !CORBA::is_nil( anObject ) ) {
2415 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2416 if ( !myHyp->_is_nil() ) {
2417 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
2419 string hypname = string( myHyp->GetName() );
2420 string libname = string( myHyp->GetLibName() );
2422 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
2423 // WNT and ".so" for X-system) must be deleted
2424 int libname_len = libname.length();
2426 if( libname_len > 4 )
2427 libname.resize( libname_len - 4 );
2429 // PAL17753 (Regresion: missing hypothesis in restored study)
2430 // "lib" also should be removed from the beginning
2431 //if( libname_len > 3 )
2432 //libname.resize( libname_len - 3 );
2433 if( libname_len > 6 )
2434 libname = libname.substr( 3, libname_len - 3 - 3 );
2436 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2437 int id = myStudyContext->findId( string( objStr.in() ) );
2438 string hypdata = string( myImpl->SaveTo() );
2440 // for each algorithm create HDF group basing on its id
2441 char hypGrpName[30];
2442 sprintf( hypGrpName, "Algorithm %d", id );
2443 aGroup = new HDFgroup( hypGrpName, aTopGroup );
2444 aGroup->CreateOnDisk();
2445 // --> type name of algorithm
2446 aSize[0] = hypname.length() + 1;
2447 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
2448 aDataset->CreateOnDisk();
2449 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
2450 aDataset->CloseOnDisk();
2451 // --> server plugin library name of hypothesis
2452 aSize[0] = libname.length() + 1;
2453 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
2454 aDataset->CreateOnDisk();
2455 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
2456 aDataset->CloseOnDisk();
2457 // --> persistent data of algorithm
2458 aSize[0] = hypdata.length() + 1;
2459 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
2460 aDataset->CreateOnDisk();
2461 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
2462 aDataset->CloseOnDisk();
2463 // close algorithm HDF group
2464 aGroup->CloseOnDisk();
2469 // close algorithms root HDF group
2470 aTopGroup->CloseOnDisk();
2472 // --> mesh objects roots branches
2473 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
2474 CORBA::Object_var anObject = SObjectToObject( gotBranch );
2475 if ( !CORBA::is_nil( anObject ) ) {
2476 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
2477 if ( !myMesh->_is_nil() ) {
2478 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
2480 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2481 int id = myStudyContext->findId( string( objStr.in() ) );
2482 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
2483 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
2484 bool hasShape = myLocMesh.HasShapeToMesh();
2486 // for each mesh open the HDF group basing on its id
2487 char meshGrpName[ 30 ];
2488 sprintf( meshGrpName, "Mesh %d", id );
2489 aTopGroup = new HDFgroup( meshGrpName, aFile );
2490 aTopGroup->CreateOnDisk();
2492 // --> put dataset to hdf file which is a flag that mesh has data
2493 string strHasData = "0";
2494 // check if the mesh is not empty
2495 if ( mySMESHDSMesh->NbNodes() > 0 ) {
2496 // write mesh data to med file
2497 myWriter.SetMesh( mySMESHDSMesh );
2498 myWriter.SetMeshId( id );
2501 aSize[ 0 ] = strHasData.length() + 1;
2502 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
2503 aDataset->CreateOnDisk();
2504 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
2505 aDataset->CloseOnDisk();
2508 // for each mesh open the HDF group basing on its auto color parameter
2509 char meshAutoColorName[ 30 ];
2510 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
2512 anAutoColor[0] = myImpl->GetAutoColor();
2514 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
2515 aDataset->CreateOnDisk();
2516 aDataset->WriteOnDisk( anAutoColor );
2517 aDataset->CloseOnDisk();
2519 // write reference on a shape if exists
2520 SALOMEDS::SObject_var myRef;
2521 bool shapeRefFound = false;
2522 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef );
2524 SALOMEDS::SObject_var myShape;
2525 bool ok = myRef->ReferencedObject( myShape );
2527 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
2528 string myRefOnObject = myShape->GetID();
2529 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
2530 aSize[ 0 ] = myRefOnObject.length() + 1;
2531 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
2532 aDataset->CreateOnDisk();
2533 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2534 aDataset->CloseOnDisk();
2539 // write applied hypotheses if exist
2540 SALOMEDS::SObject_var myHypBranch;
2541 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch );
2542 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
2543 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
2545 if ( found && (shapeRefFound || !hasShape) ) {
2546 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
2547 aGroup->CreateOnDisk();
2549 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myHypBranch );
2551 for ( ; it->More(); it->Next() ) {
2552 SALOMEDS::SObject_var mySObject = it->Value();
2553 SALOMEDS::SObject_var myRefOnHyp;
2554 bool ok = mySObject->ReferencedObject( myRefOnHyp );
2556 // san - it is impossible to recover applied hypotheses
2557 // using their entries within Load() method,
2558 // for there are no AttributeIORs in the study when Load() is working.
2559 // Hence, it is better to store persistent IDs of hypotheses as references to them
2561 //string myRefOnObject = myRefOnHyp->GetID();
2562 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2563 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2564 int id = myStudyContext->findId( string( objStr.in() ) );
2565 //if ( myRefOnObject.length() > 0 ) {
2566 //aSize[ 0 ] = myRefOnObject.length() + 1;
2567 char hypName[ 30 ], hypId[ 30 ];
2568 sprintf( hypName, "Hyp %d", ++hypNb );
2569 sprintf( hypId, "%d", id );
2570 aSize[ 0 ] = strlen( hypId ) + 1;
2571 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
2572 aDataset->CreateOnDisk();
2573 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2574 aDataset->WriteOnDisk( hypId );
2575 aDataset->CloseOnDisk();
2579 aGroup->CloseOnDisk();
2582 // write applied algorithms if exist
2583 SALOMEDS::SObject_var myAlgoBranch;
2584 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(), myAlgoBranch );
2585 if ( found && !shapeRefFound && hasShape) { // remove applied algos
2586 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
2588 if ( found && (shapeRefFound || !hasShape)) {
2589 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
2590 aGroup->CreateOnDisk();
2592 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myAlgoBranch );
2594 for ( ; it->More(); it->Next() ) {
2595 SALOMEDS::SObject_var mySObject = it->Value();
2596 SALOMEDS::SObject_var myRefOnAlgo;
2597 bool ok = mySObject->ReferencedObject( myRefOnAlgo );
2599 // san - it is impossible to recover applied algorithms
2600 // using their entries within Load() method,
2601 // for there are no AttributeIORs in the study when Load() is working.
2602 // Hence, it is better to store persistent IDs of algorithms as references to them
2604 //string myRefOnObject = myRefOnAlgo->GetID();
2605 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2606 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2607 int id = myStudyContext->findId( string( objStr.in() ) );
2608 //if ( myRefOnObject.length() > 0 ) {
2609 //aSize[ 0 ] = myRefOnObject.length() + 1;
2610 char algoName[ 30 ], algoId[ 30 ];
2611 sprintf( algoName, "Algo %d", ++algoNb );
2612 sprintf( algoId, "%d", id );
2613 aSize[ 0 ] = strlen( algoId ) + 1;
2614 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
2615 aDataset->CreateOnDisk();
2616 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2617 aDataset->WriteOnDisk( algoId );
2618 aDataset->CloseOnDisk();
2622 aGroup->CloseOnDisk();
2625 // --> submesh objects sub-branches
2627 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
2628 SALOMEDS::SObject_var mySubmeshBranch;
2629 found = gotBranch->FindSubObject( i, mySubmeshBranch );
2631 if ( found ) // check if there is shape reference in submeshes
2633 bool hasShapeRef = false;
2634 SALOMEDS::ChildIterator_var itSM =
2635 myCurrentStudy->NewChildIterator( mySubmeshBranch );
2636 for ( ; itSM->More(); itSM->Next() ) {
2637 SALOMEDS::SObject_var mySubRef, myShape, mySObject = itSM->Value();
2638 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2639 mySubRef->ReferencedObject( myShape );
2640 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
2643 { // remove one submesh
2644 if ( shapeRefFound )
2645 { // unassign hypothesis
2646 SMESH::SMESH_subMesh_var mySubMesh =
2647 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
2648 if ( !mySubMesh->_is_nil() ) {
2649 int shapeID = mySubMesh->GetId();
2650 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
2651 const list<const SMESHDS_Hypothesis*>& hypList =
2652 mySMESHDSMesh->GetHypothesis( S );
2653 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
2654 while ( hyp != hypList.end() ) {
2655 int hypID = (*hyp++)->GetID(); // goto next hyp here because
2656 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
2660 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
2662 } // loop on submeshes of a type
2663 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
2664 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
2667 } // end check if there is shape reference in submeshes
2669 char name_meshgroup[ 30 ];
2670 if ( i == GetSubMeshOnVertexTag() )
2671 strcpy( name_meshgroup, "SubMeshes On Vertex" );
2672 else if ( i == GetSubMeshOnEdgeTag() )
2673 strcpy( name_meshgroup, "SubMeshes On Edge" );
2674 else if ( i == GetSubMeshOnWireTag() )
2675 strcpy( name_meshgroup, "SubMeshes On Wire" );
2676 else if ( i == GetSubMeshOnFaceTag() )
2677 strcpy( name_meshgroup, "SubMeshes On Face" );
2678 else if ( i == GetSubMeshOnShellTag() )
2679 strcpy( name_meshgroup, "SubMeshes On Shell" );
2680 else if ( i == GetSubMeshOnSolidTag() )
2681 strcpy( name_meshgroup, "SubMeshes On Solid" );
2682 else if ( i == GetSubMeshOnCompoundTag() )
2683 strcpy( name_meshgroup, "SubMeshes On Compound" );
2685 // for each type of submeshes create container HDF group
2686 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
2687 aGroup->CreateOnDisk();
2689 // iterator for all submeshes of given type
2690 SALOMEDS::ChildIterator_var itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
2691 for ( ; itSM->More(); itSM->Next() ) {
2692 SALOMEDS::SObject_var mySObject = itSM->Value();
2693 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
2694 if ( !CORBA::is_nil( anSubObject ))
2696 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
2697 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
2698 int subid = myStudyContext->findId( string( objStr.in() ) );
2700 // for each mesh open the HDF group basing on its id
2701 char submeshGrpName[ 30 ];
2702 sprintf( submeshGrpName, "SubMesh %d", subid );
2703 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
2704 aSubGroup->CreateOnDisk();
2706 // write reference on a shape, already checked if it exists
2707 SALOMEDS::SObject_var mySubRef, myShape;
2708 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ))
2709 mySubRef->ReferencedObject( myShape );
2710 string myRefOnObject = myShape->GetID();
2711 if ( myRefOnObject.length() > 0 ) {
2712 aSize[ 0 ] = myRefOnObject.length() + 1;
2713 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
2714 aDataset->CreateOnDisk();
2715 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2716 aDataset->CloseOnDisk();
2719 // write applied hypotheses if exist
2720 SALOMEDS::SObject_var mySubHypBranch;
2721 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(), mySubHypBranch );
2723 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
2724 aSubSubGroup->CreateOnDisk();
2726 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubHypBranch );
2728 for ( ; it->More(); it->Next() ) {
2729 SALOMEDS::SObject_var mySubSObject = it->Value();
2730 SALOMEDS::SObject_var myRefOnHyp;
2731 bool ok = mySubSObject->ReferencedObject( myRefOnHyp );
2733 //string myRefOnObject = myRefOnHyp->GetID();
2734 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
2735 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2736 int id = myStudyContext->findId( string( objStr.in() ) );
2737 //if ( myRefOnObject.length() > 0 ) {
2738 //aSize[ 0 ] = myRefOnObject.length() + 1;
2739 char hypName[ 30 ], hypId[ 30 ];
2740 sprintf( hypName, "Hyp %d", ++hypNb );
2741 sprintf( hypId, "%d", id );
2742 aSize[ 0 ] = strlen( hypId ) + 1;
2743 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
2744 aDataset->CreateOnDisk();
2745 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2746 aDataset->WriteOnDisk( hypId );
2747 aDataset->CloseOnDisk();
2751 aSubSubGroup->CloseOnDisk();
2754 // write applied algorithms if exist
2755 SALOMEDS::SObject_var mySubAlgoBranch;
2756 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(), mySubAlgoBranch );
2758 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
2759 aSubSubGroup->CreateOnDisk();
2761 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( mySubAlgoBranch );
2763 for ( ; it->More(); it->Next() ) {
2764 SALOMEDS::SObject_var mySubSObject = it->Value();
2765 SALOMEDS::SObject_var myRefOnAlgo;
2766 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo );
2768 //string myRefOnObject = myRefOnAlgo->GetID();
2769 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
2770 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
2771 int id = myStudyContext->findId( string( objStr.in() ) );
2772 //if ( myRefOnObject.length() > 0 ) {
2773 //aSize[ 0 ] = myRefOnObject.length() + 1;
2774 char algoName[ 30 ], algoId[ 30 ];
2775 sprintf( algoName, "Algo %d", ++algoNb );
2776 sprintf( algoId, "%d", id );
2777 aSize[ 0 ] = strlen( algoId ) + 1;
2778 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
2779 aDataset->CreateOnDisk();
2780 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2781 aDataset->WriteOnDisk( algoId );
2782 aDataset->CloseOnDisk();
2786 aSubSubGroup->CloseOnDisk();
2788 // close submesh HDF group
2789 aSubGroup->CloseOnDisk();
2792 // close container of submeshes by type HDF group
2793 aGroup->CloseOnDisk();
2796 // All sub-meshes will be stored in MED file
2797 // .. will NOT (PAL 12992)
2798 //if ( shapeRefFound )
2799 //myWriter.AddAllSubMeshes();
2801 // store submesh order if any
2802 const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
2803 if ( theOrderIds.size() ) {
2804 char order_list[ 30 ];
2805 strcpy( order_list, "Mesh Order" );
2806 // count number of submesh ids
2808 TListOfListOfInt::const_iterator idIt = theOrderIds.begin();
2809 for ( ; idIt != theOrderIds.end(); idIt++ )
2810 nbIDs += (*idIt).size();
2811 // number of values = number of IDs +
2812 // number of lists (for separators) - 1
2813 int* smIDs = new int [ nbIDs + theOrderIds.size() - 1 ];
2814 idIt = theOrderIds.begin();
2815 for ( int i = 0; idIt != theOrderIds.end(); idIt++ ) {
2816 const TListOfInt& idList = *idIt;
2817 if (idIt != theOrderIds.begin()) // not first list
2818 smIDs[ i++ ] = -1/* *idList.size()*/; // separator between lists
2819 // dump submesh ids from current list
2820 TListOfInt::const_iterator id_smId = idList.begin();
2821 for( ; id_smId != idList.end(); id_smId++ )
2822 smIDs[ i++ ] = *id_smId;
2825 aSize[ 0 ] = nbIDs + theOrderIds.size() - 1;
2827 aDataset = new HDFdataset( order_list, aTopGroup, HDF_INT32, aSize, 1 );
2828 aDataset->CreateOnDisk();
2829 aDataset->WriteOnDisk( smIDs );
2830 aDataset->CloseOnDisk();
2835 // groups root sub-branch
2836 SALOMEDS::SObject_var myGroupsBranch;
2837 for ( int i = GetNodeGroupsTag(); i <= GetVolumeGroupsTag(); i++ ) {
2838 found = gotBranch->FindSubObject( i, myGroupsBranch );
2840 char name_group[ 30 ];
2841 if ( i == GetNodeGroupsTag() )
2842 strcpy( name_group, "Groups of Nodes" );
2843 else if ( i == GetEdgeGroupsTag() )
2844 strcpy( name_group, "Groups of Edges" );
2845 else if ( i == GetFaceGroupsTag() )
2846 strcpy( name_group, "Groups of Faces" );
2847 else if ( i == GetVolumeGroupsTag() )
2848 strcpy( name_group, "Groups of Volumes" );
2850 aGroup = new HDFgroup( name_group, aTopGroup );
2851 aGroup->CreateOnDisk();
2853 SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch );
2854 for ( ; it->More(); it->Next() ) {
2855 SALOMEDS::SObject_var mySObject = it->Value();
2856 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
2857 if ( !CORBA::is_nil( aSubObject ) ) {
2858 SMESH_GroupBase_i* myGroupImpl =
2859 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
2863 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
2864 int anId = myStudyContext->findId( string( objStr.in() ) );
2866 // For each group, create a dataset named "Group <group_persistent_id>"
2867 // and store the group's user name into it
2869 sprintf( grpName, "Group %d", anId );
2870 char* aUserName = myGroupImpl->GetName();
2871 aSize[ 0 ] = strlen( aUserName ) + 1;
2873 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
2874 aDataset->CreateOnDisk();
2875 aDataset->WriteOnDisk( aUserName );
2876 aDataset->CloseOnDisk();
2879 // For each group, create a dataset named "Group <group_persistent_id> Color"
2880 // and store the group's color into it
2881 char grpColorName[ 30 ];
2882 sprintf( grpColorName, "ColorGroup %d", anId );
2883 SALOMEDS::Color aColor = myGroupImpl->GetColor();
2885 anRGB[ 0 ] = aColor.R;
2886 anRGB[ 1 ] = aColor.G;
2887 anRGB[ 2 ] = aColor.B;
2889 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
2890 aDataset->CreateOnDisk();
2891 aDataset->WriteOnDisk( anRGB );
2892 aDataset->CloseOnDisk();
2894 // Store the group contents into MED file
2895 if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) {
2897 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = "
2898 << grpName << " to MED file" );
2899 SMESHDS_GroupBase* aGrpBaseDS =
2900 myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS();
2901 aGrpBaseDS->SetStoreName( grpName );
2903 // Pass SMESHDS_Group to MED writer
2904 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
2906 myWriter.AddGroup( aGrpDS );
2908 // write reference on a shape if exists
2909 SMESHDS_GroupOnGeom* aGeomGrp =
2910 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
2912 SALOMEDS::SObject_var mySubRef, myShape;
2913 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) &&
2914 mySubRef->ReferencedObject( myShape ) &&
2915 !CORBA::is_nil( myShape->GetObject() ))
2917 string myRefOnObject = myShape->GetID();
2918 if ( myRefOnObject.length() > 0 ) {
2919 char aRefName[ 30 ];
2920 sprintf( aRefName, "Ref on shape %d", anId);
2921 aSize[ 0 ] = myRefOnObject.length() + 1;
2922 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
2923 aDataset->CreateOnDisk();
2924 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
2925 aDataset->CloseOnDisk();
2928 else // shape ref is invalid:
2930 // save a group on geometry as ordinary group
2931 myWriter.AddGroup( aGeomGrp );
2937 aGroup->CloseOnDisk();
2941 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
2943 // Flush current mesh information into MED file
2946 // maybe a shape was deleted in the study
2947 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
2948 TopoDS_Shape nullShape;
2949 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
2952 if ( !mySMESHDSMesh->SubMeshes().empty() )
2956 aGroup = new HDFgroup( "Submeshes", aTopGroup );
2957 aGroup->CreateOnDisk();
2959 // each element belongs to one or none submesh,
2960 // so for each node/element, we store a submesh ID
2962 // Make maps of submesh IDs of elements sorted by element IDs
2963 typedef int TElemID;
2964 typedef int TSubMID;
2965 map< TElemID, TSubMID > eId2smId, nId2smId;
2966 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
2967 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
2968 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
2969 SMDS_NodeIteratorPtr itNode;
2970 SMDS_ElemIteratorPtr itElem;
2971 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
2973 TSubMID aSubMeID = itSubM->first;
2974 SMESHDS_SubMesh* aSubMesh = itSubM->second;
2975 if ( aSubMesh->IsComplexSubmesh() )
2976 continue; // submesh containing other submeshs
2978 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
2979 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
2980 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
2982 hint = eId2smId.begin();
2983 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
2984 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
2987 // Care of elements that are not on submeshes
2988 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
2989 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
2990 /* --- stl_map.h says : */
2991 /* A %map relies on unique keys and thus a %pair is only inserted if its */
2992 /* first element (the key) is not already present in the %map. */
2993 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
2995 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
2996 if ( nbElems != eId2smId.size() ) {
2997 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
2998 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
3001 // Store submesh IDs
3002 for ( int isNode = 0; isNode < 2; ++isNode )
3004 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
3005 if ( id2smId.empty() ) continue;
3006 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
3007 // make and fill array of submesh IDs
3008 int* smIDs = new int [ id2smId.size() ];
3009 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
3010 smIDs[ i ] = id_smId->second;
3012 aSize[ 0 ] = id2smId.size();
3013 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3014 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3015 aDataset->CreateOnDisk();
3016 aDataset->WriteOnDisk( smIDs );
3017 aDataset->CloseOnDisk();
3022 // Store node positions on sub-shapes (SMDS_Position):
3023 // ----------------------------------------------------
3025 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3026 aGroup->CreateOnDisk();
3028 // in aGroup, create 5 datasets to contain:
3029 // "Nodes on Edges" - ID of node on edge
3030 // "Edge positions" - U parameter on node on edge
3031 // "Nodes on Faces" - ID of node on face
3032 // "Face U positions" - U parameter of node on face
3033 // "Face V positions" - V parameter of node on face
3035 // Find out nb of nodes on edges and faces
3036 // Collect corresponing sub-meshes
3037 int nbEdgeNodes = 0, nbFaceNodes = 0;
3038 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
3039 // loop on SMESHDS_SubMesh'es
3040 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3042 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
3043 if ( aSubMesh->IsComplexSubmesh() )
3044 continue; // submesh containing other submeshs
3045 int nbNodes = aSubMesh->NbNodes();
3046 if ( nbNodes == 0 ) continue;
3048 int aShapeID = (*itSubM).first;
3049 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
3050 // write only SMDS_FacePosition and SMDS_EdgePosition
3051 switch ( aShapeType ) {
3053 nbFaceNodes += nbNodes;
3054 aFaceSM.push_back( aSubMesh );
3057 nbEdgeNodes += nbNodes;
3058 aEdgeSM.push_back( aSubMesh );
3064 // Treat positions on edges or faces
3065 for ( int onFace = 0; onFace < 2; onFace++ )
3067 // Create arrays to store in datasets
3068 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
3069 if (!nbNodes) continue;
3070 int* aNodeIDs = new int [ nbNodes ];
3071 double* aUPos = new double [ nbNodes ];
3072 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
3075 // loop on sub-meshes
3076 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
3077 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
3078 for ( ; itSM != pListSM->end(); itSM++ )
3080 SMESHDS_SubMesh* aSubMesh = (*itSM);
3082 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
3083 // loop on nodes in aSubMesh
3084 while ( itNode->more() )
3087 const SMDS_MeshNode* node = itNode->next();
3088 aNodeIDs [ iNode ] = node->GetID();
3091 const SMDS_PositionPtr pos = node->GetPosition();
3092 if ( onFace ) { // on FACE
3093 const SMDS_FacePosition* fPos =
3094 dynamic_cast<const SMDS_FacePosition*>( pos.get() );
3096 aUPos[ iNode ] = fPos->GetUParameter();
3097 aVPos[ iNode ] = fPos->GetVParameter();
3104 const SMDS_EdgePosition* ePos =
3105 dynamic_cast<const SMDS_EdgePosition*>( pos.get() );
3107 aUPos[ iNode ] = ePos->GetUParameter();
3113 } // loop on nodes in aSubMesh
3114 } // loop on sub-meshes
3119 aSize[ 0 ] = nbNodes;
3121 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
3122 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3123 aDataset->CreateOnDisk();
3124 aDataset->WriteOnDisk( aNodeIDs );
3125 aDataset->CloseOnDisk();
3128 aDSName = ( onFace ? "Face U positions" : "Edge positions");
3129 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
3130 aDataset->CreateOnDisk();
3131 aDataset->WriteOnDisk( aUPos );
3132 aDataset->CloseOnDisk();
3135 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
3136 aDataset->CreateOnDisk();
3137 aDataset->WriteOnDisk( aVPos );
3138 aDataset->CloseOnDisk();
3143 if ( aVPos ) delete [] aVPos;
3145 } // treat positions on edges or faces
3147 // close "Node Positions" group
3148 aGroup->CloseOnDisk();
3150 } // if ( there are submeshes in SMESHDS_Mesh )
3153 // close mesh HDF group
3154 aTopGroup->CloseOnDisk();
3162 aFile->CloseOnDisk();
3165 // Convert temporary files to stream
3166 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
3168 // Remove temporary files and directory
3170 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3172 INFOS( "SMESH_Gen_i::Save() completed" );
3173 return aStreamFile._retn();
3176 //=============================================================================
3178 * SMESH_Gen_i::SaveASCII
3180 * Save SMESH module's data in ASCII format
3182 //=============================================================================
3184 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
3186 bool isMultiFile ) {
3187 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
3188 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
3189 return aStreamFile._retn();
3191 //after usual saving needs to encipher binary to text string
3192 //Any binary symbol will be represent as "|xx" () hexadecimal format number
3193 int size = aStreamFile.in().length();
3194 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
3195 for ( int i = 0; i < size; i++ )
3196 sprintf( (char*)&(buffer[i*3]), "|%02x", (char*)(aStreamFile[i]) );
3198 buffer[size * 3] = '\0';
3200 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
3202 return anAsciiStreamFile._retn();
3205 //=============================================================================
3207 * SMESH_Gen_i::loadGeomData
3209 * Load GEOM module data
3211 //=============================================================================
3213 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
3215 if ( theCompRoot->_is_nil() )
3218 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
3219 if ( aStudy->_is_nil() )
3222 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3223 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
3225 //=============================================================================
3227 * \brief Creates SMDS_Position according to shape type
3229 //=============================================================================
3231 class PositionCreator {
3233 SMDS_PositionPtr MakePosition(const TopAbs_ShapeEnum type) {
3234 return (this->*myFuncTable[ type ])();
3237 myFuncTable.resize( (size_t) TopAbs_SHAPE, & PositionCreator::defaultPosition );
3238 myFuncTable[ TopAbs_FACE ] = & PositionCreator::facePosition;
3239 myFuncTable[ TopAbs_EDGE ] = & PositionCreator::edgePosition;
3240 myFuncTable[ TopAbs_VERTEX ] = & PositionCreator::vertexPosition;
3243 SMDS_PositionPtr edgePosition() const { return SMDS_PositionPtr( new SMDS_EdgePosition ); }
3244 SMDS_PositionPtr facePosition() const { return SMDS_PositionPtr( new SMDS_FacePosition ); }
3245 SMDS_PositionPtr vertexPosition() const { return SMDS_PositionPtr( new SMDS_VertexPosition); }
3246 SMDS_PositionPtr defaultPosition() const { return SMDS_SpacePosition::originSpacePosition(); }
3247 typedef SMDS_PositionPtr (PositionCreator:: * FmakePos)() const;
3248 vector<FmakePos> myFuncTable;
3251 //=============================================================================
3255 * Load SMESH module's data
3257 //=============================================================================
3259 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
3260 const SALOMEDS::TMPFile& theStream,
3264 INFOS( "SMESH_Gen_i::Load" );
3266 if ( myCurrentStudy->_is_nil() ||
3267 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
3268 SetCurrentStudy( theComponent->GetStudy() );
3270 /* if( !theComponent->_is_nil() )
3272 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
3273 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
3274 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
3277 StudyContext* myStudyContext = GetCurrentStudyContext();
3279 // Get temporary files location
3280 TCollection_AsciiString tmpDir =
3281 isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
3283 INFOS( "THE URL++++++++++++++" )
3285 INFOS( "THE TMP PATH+++++++++" );
3288 // Convert the stream into sequence of files to process
3289 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
3292 TCollection_AsciiString aStudyName( "" );
3294 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
3296 // Set names of temporary files
3297 TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" );
3298 TCollection_AsciiString meshfile = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" );
3302 HDFdataset* aDataset;
3303 HDFgroup* aTopGroup;
3305 HDFgroup* aSubGroup;
3306 HDFgroup* aSubSubGroup;
3309 // ---> open HDF file
3310 aFile = new HDFfile( (char*) filename.ToCString() );
3312 aFile->OpenOnDisk( HDF_RDONLY );
3314 catch ( HDFexception ) {
3315 INFOS( "Load(): " << filename << " not found!" );
3319 DriverMED_R_SMESHDS_Mesh myReader;
3320 myReader.SetFile( meshfile.ToCString() );
3322 // For PAL13473 ("Repetitive mesh") implementation.
3323 // New dependencies between SMESH objects are established:
3324 // now hypotheses can refer to meshes, shapes and other hypotheses.
3325 // To keep data consistent, the following order of data restoration
3327 // 1. Create hypotheses
3328 // 2. Create all meshes
3329 // 3. Load hypotheses' data
3332 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
3333 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
3335 // get total number of top-level groups
3336 int aNbGroups = aFile->nInternalObjects();
3337 if ( aNbGroups > 0 ) {
3338 // --> in first turn we should read&create hypotheses
3339 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
3340 // open hypotheses root HDF group
3341 aTopGroup = new HDFgroup( "Hypotheses", aFile );
3342 aTopGroup->OpenOnDisk();
3344 // get number of hypotheses
3345 int aNbObjects = aTopGroup->nInternalObjects();
3346 for ( int j = 0; j < aNbObjects; j++ ) {
3347 // try to identify hypothesis
3348 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
3349 aTopGroup->InternalObjectIndentify( j, hypGrpName );
3351 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
3352 // open hypothesis group
3353 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3354 aGroup->OpenOnDisk();
3356 // --> get hypothesis id
3357 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
3362 // get number of datasets
3363 int aNbSubObjects = aGroup->nInternalObjects();
3364 for ( int k = 0; k < aNbSubObjects; k++ ) {
3366 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
3367 aGroup->InternalObjectIndentify( k, name_of_subgroup );
3368 // --> get hypothesis name
3369 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
3370 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3371 aDataset->OpenOnDisk();
3372 size = aDataset->GetSize();
3373 char* hypname_str = new char[ size ];
3374 aDataset->ReadFromDisk( hypname_str );
3375 hypname = string( hypname_str );
3376 delete [] hypname_str;
3377 aDataset->CloseOnDisk();
3379 // --> get hypothesis plugin library name
3380 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
3381 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3382 aDataset->OpenOnDisk();
3383 size = aDataset->GetSize();
3384 char* libname_str = new char[ size ];
3385 aDataset->ReadFromDisk( libname_str );
3386 if(MYDEBUG) SCRUTE( libname_str );
3387 libname = string( libname_str );
3388 delete [] libname_str;
3389 aDataset->CloseOnDisk();
3391 // --> get hypothesis data
3392 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
3393 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3394 aDataset->OpenOnDisk();
3395 size = aDataset->GetSize();
3396 char* hypdata_str = new char[ size ];
3397 aDataset->ReadFromDisk( hypdata_str );
3398 hypdata = string( hypdata_str );
3399 delete [] hypdata_str;
3400 aDataset->CloseOnDisk();
3403 // close hypothesis HDF group
3404 aGroup->CloseOnDisk();
3406 // --> restore hypothesis from data
3407 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
3408 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
3409 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
3410 SMESH::SMESH_Hypothesis_var myHyp;
3412 try { // protect persistence mechanism against exceptions
3413 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
3416 INFOS( "Exception during hypothesis creation" );
3419 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3421 // myImpl->LoadFrom( hypdata.c_str() );
3422 hypDataList.push_back( make_pair( myImpl, hypdata ));
3423 string iorString = GetORB()->object_to_string( myHyp );
3424 int newId = myStudyContext->findId( iorString );
3425 myStudyContext->mapOldToNew( id, newId );
3428 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
3432 // close hypotheses root HDF group
3433 aTopGroup->CloseOnDisk();
3437 // --> then we should read&create algorithms
3438 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
3439 // open algorithms root HDF group
3440 aTopGroup = new HDFgroup( "Algorithms", aFile );
3441 aTopGroup->OpenOnDisk();
3443 // get number of algorithms
3444 int aNbObjects = aTopGroup->nInternalObjects();
3445 for ( int j = 0; j < aNbObjects; j++ ) {
3446 // try to identify algorithm
3447 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
3448 aTopGroup->InternalObjectIndentify( j, hypGrpName );
3450 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
3451 // open algorithm group
3452 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3453 aGroup->OpenOnDisk();
3455 // --> get algorithm id
3456 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
3461 // get number of datasets
3462 int aNbSubObjects = aGroup->nInternalObjects();
3463 for ( int k = 0; k < aNbSubObjects; k++ ) {
3465 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
3466 aGroup->InternalObjectIndentify( k, name_of_subgroup );
3467 // --> get algorithm name
3468 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
3469 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3470 aDataset->OpenOnDisk();
3471 size = aDataset->GetSize();
3472 char* hypname_str = new char[ size ];
3473 aDataset->ReadFromDisk( hypname_str );
3474 hypname = string( hypname_str );
3475 delete [] hypname_str;
3476 aDataset->CloseOnDisk();
3478 // --> get algorithm plugin library name
3479 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
3480 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3481 aDataset->OpenOnDisk();
3482 size = aDataset->GetSize();
3483 char* libname_str = new char[ size ];
3484 aDataset->ReadFromDisk( libname_str );
3485 if(MYDEBUG) SCRUTE( libname_str );
3486 libname = string( libname_str );
3487 delete [] libname_str;
3488 aDataset->CloseOnDisk();
3490 // --> get algorithm data
3491 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
3492 aDataset = new HDFdataset( name_of_subgroup, aGroup );
3493 aDataset->OpenOnDisk();
3494 size = aDataset->GetSize();
3495 char* hypdata_str = new char[ size ];
3496 aDataset->ReadFromDisk( hypdata_str );
3497 if(MYDEBUG) SCRUTE( hypdata_str );
3498 hypdata = string( hypdata_str );
3499 delete [] hypdata_str;
3500 aDataset->CloseOnDisk();
3503 // close algorithm HDF group
3504 aGroup->CloseOnDisk();
3506 // --> restore algorithm from data
3507 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
3508 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
3509 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
3510 SMESH::SMESH_Hypothesis_var myHyp;
3512 try { // protect persistence mechanism against exceptions
3513 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
3516 INFOS( "Exception during hypothesis creation" );
3519 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3521 //myImpl->LoadFrom( hypdata.c_str() );
3522 hypDataList.push_back( make_pair( myImpl, hypdata ));
3523 string iorString = GetORB()->object_to_string( myHyp );
3524 int newId = myStudyContext->findId( iorString );
3525 myStudyContext->mapOldToNew( id, newId );
3528 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
3532 // close algorithms root HDF group
3533 aTopGroup->CloseOnDisk();
3537 // --> the rest groups should be meshes
3538 for ( int i = 0; i < aNbGroups; i++ ) {
3539 // identify next group
3540 char meshName[ HDF_NAME_MAX_LEN+1 ];
3541 aFile->InternalObjectIndentify( i, meshName );
3543 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
3545 int id = atoi( string( meshName ).substr( 4 ).c_str() );
3549 // open mesh HDF group
3550 aTopGroup = new HDFgroup( meshName, aFile );
3551 aTopGroup->OpenOnDisk();
3553 // get number of child HDF objects
3554 int aNbObjects = aTopGroup->nInternalObjects();
3555 if ( aNbObjects > 0 ) {
3557 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
3558 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
3559 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
3560 if ( !myNewMeshImpl )
3562 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
3564 string iorString = GetORB()->object_to_string( myNewMesh );
3565 int newId = myStudyContext->findId( iorString );
3566 myStudyContext->mapOldToNew( id, newId );
3569 // try to read and set auto color flag
3570 char aMeshAutoColorName[ 30 ];
3571 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
3572 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
3574 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
3575 aDataset->OpenOnDisk();
3576 size = aDataset->GetSize();
3577 int* anAutoColor = new int[ size ];
3578 aDataset->ReadFromDisk( anAutoColor );
3579 aDataset->CloseOnDisk();
3580 myNewMeshImpl->SetAutoColor( (bool)anAutoColor[0] );
3583 // try to read and set reference to shape
3584 GEOM::GEOM_Object_var aShapeObject;
3585 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
3586 // load mesh "Ref on shape" - it's an entry to SObject
3587 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
3588 aDataset->OpenOnDisk();
3589 size = aDataset->GetSize();
3590 char* refFromFile = new char[ size ];
3591 aDataset->ReadFromDisk( refFromFile );
3592 aDataset->CloseOnDisk();
3593 if ( strlen( refFromFile ) > 0 ) {
3594 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
3596 // Make sure GEOM data are loaded first
3597 //loadGeomData( shapeSO->GetFatherComponent() );
3599 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
3600 if ( !CORBA::is_nil( shapeObject ) ) {
3601 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
3602 if ( !aShapeObject->_is_nil() )
3603 myNewMeshImpl->SetShape( aShapeObject );
3611 // As all object that can be referred by hypothesis are created,
3612 // we can restore hypothesis data
3614 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
3615 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
3617 SMESH_Hypothesis_i* hyp = hyp_data->first;
3618 string & data = hyp_data->second;
3619 hyp->LoadFrom( data.c_str() );
3622 // Restore the rest mesh data
3624 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
3625 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
3627 aTopGroup = meshi_group->second;
3628 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
3629 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
3630 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3632 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
3633 bool hasData = false;
3636 string iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
3637 int newId = myStudyContext->findId( iorString );
3638 int id = myStudyContext->getOldId( newId );
3640 // try to find mesh data dataset
3641 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
3642 // load mesh "has data" flag
3643 aDataset = new HDFdataset( "Has data", aTopGroup );
3644 aDataset->OpenOnDisk();
3645 size = aDataset->GetSize();
3646 char* strHasData = new char[ size ];
3647 aDataset->ReadFromDisk( strHasData );
3648 aDataset->CloseOnDisk();
3649 if ( strcmp( strHasData, "1") == 0 ) {
3650 // read mesh data from MED file
3651 myReader.SetMesh( mySMESHDSMesh );
3652 myReader.SetMeshId( id );
3658 // try to get applied algorithms
3659 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3660 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3661 aGroup->OpenOnDisk();
3662 // get number of applied algorithms
3663 int aNbSubObjects = aGroup->nInternalObjects();
3664 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
3665 for ( int j = 0; j < aNbSubObjects; j++ ) {
3666 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3667 aGroup->InternalObjectIndentify( j, name_dataset );
3668 // check if it is an algorithm
3669 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3670 aDataset = new HDFdataset( name_dataset, aGroup );
3671 aDataset->OpenOnDisk();
3672 size = aDataset->GetSize();
3673 char* refFromFile = new char[ size ];
3674 aDataset->ReadFromDisk( refFromFile );
3675 aDataset->CloseOnDisk();
3677 // san - it is impossible to recover applied algorithms using their entries within Load() method
3679 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3680 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3681 int id = atoi( refFromFile );
3682 string anIOR = myStudyContext->getIORbyOldId( id );
3683 if ( !anIOR.empty() ) {
3684 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3685 if ( !CORBA::is_nil( hypObject ) ) {
3686 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3687 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3688 || !myNewMeshImpl->HasShapeToMesh()) )
3689 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3694 aGroup->CloseOnDisk();
3697 // try to get applied hypotheses
3698 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3699 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3700 aGroup->OpenOnDisk();
3701 // get number of applied hypotheses
3702 int aNbSubObjects = aGroup->nInternalObjects();
3703 for ( int j = 0; j < aNbSubObjects; j++ ) {
3704 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3705 aGroup->InternalObjectIndentify( j, name_dataset );
3706 // check if it is a hypothesis
3707 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3708 aDataset = new HDFdataset( name_dataset, aGroup );
3709 aDataset->OpenOnDisk();
3710 size = aDataset->GetSize();
3711 char* refFromFile = new char[ size ];
3712 aDataset->ReadFromDisk( refFromFile );
3713 aDataset->CloseOnDisk();
3715 // san - it is impossible to recover applied hypotheses using their entries within Load() method
3717 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3718 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3719 int id = atoi( refFromFile );
3720 string anIOR = myStudyContext->getIORbyOldId( id );
3721 if ( !anIOR.empty() ) {
3722 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3723 if ( !CORBA::is_nil( hypObject ) ) {
3724 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3725 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
3726 || !myNewMeshImpl->HasShapeToMesh()) )
3727 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
3732 aGroup->CloseOnDisk();
3735 // --> try to find submeshes containers for each type of submesh
3736 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
3737 char name_meshgroup[ 30 ];
3738 if ( j == GetSubMeshOnVertexTag() )
3739 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3740 else if ( j == GetSubMeshOnEdgeTag() )
3741 strcpy( name_meshgroup, "SubMeshes On Edge" );
3742 else if ( j == GetSubMeshOnWireTag() )
3743 strcpy( name_meshgroup, "SubMeshes On Wire" );
3744 else if ( j == GetSubMeshOnFaceTag() )
3745 strcpy( name_meshgroup, "SubMeshes On Face" );
3746 else if ( j == GetSubMeshOnShellTag() )
3747 strcpy( name_meshgroup, "SubMeshes On Shell" );
3748 else if ( j == GetSubMeshOnSolidTag() )
3749 strcpy( name_meshgroup, "SubMeshes On Solid" );
3750 else if ( j == GetSubMeshOnCompoundTag() )
3751 strcpy( name_meshgroup, "SubMeshes On Compound" );
3753 // try to get submeshes container HDF group
3754 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
3755 // open submeshes containers HDF group
3756 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3757 aGroup->OpenOnDisk();
3759 // get number of submeshes
3760 int aNbSubMeshes = aGroup->nInternalObjects();
3761 for ( int k = 0; k < aNbSubMeshes; k++ ) {
3763 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
3764 aGroup->InternalObjectIndentify( k, name_submeshgroup );
3765 if ( string( name_submeshgroup ).substr( 0, 7 ) == string( "SubMesh" ) ) {
3766 // --> get submesh id
3767 int subid = atoi( string( name_submeshgroup ).substr( 7 ).c_str() );
3770 // open submesh HDF group
3771 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
3772 aSubGroup->OpenOnDisk();
3774 // try to read and set reference to subshape
3775 GEOM::GEOM_Object_var aSubShapeObject;
3776 SMESH::SMESH_subMesh_var aSubMesh;
3778 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
3779 // load submesh "Ref on shape" - it's an entry to SObject
3780 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
3781 aDataset->OpenOnDisk();
3782 size = aDataset->GetSize();
3783 char* refFromFile = new char[ size ];
3784 aDataset->ReadFromDisk( refFromFile );
3785 aDataset->CloseOnDisk();
3786 if ( strlen( refFromFile ) > 0 ) {
3787 SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
3788 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
3789 if ( !CORBA::is_nil( subShapeObject ) ) {
3790 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
3791 if ( !aSubShapeObject->_is_nil() )
3792 aSubMesh = SMESH::SMESH_subMesh::_duplicate
3793 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
3794 if ( aSubMesh->_is_nil() )
3796 string iorSubString = GetORB()->object_to_string( aSubMesh );
3797 int newSubId = myStudyContext->findId( iorSubString );
3798 myStudyContext->mapOldToNew( subid, newSubId );
3803 if ( aSubMesh->_is_nil() )
3806 // VSR: Get submesh data from MED convertor
3807 // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape
3808 // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) {
3809 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " <<
3810 // subid << " for subshape # " << anInternalSubmeshId);
3811 // SMESHDS_SubMesh* aSubMeshDS =
3812 // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS();
3813 // if ( !aSubMeshDS ) {
3814 // if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " <<
3815 // anInternalSubmeshId << " in current mesh!");
3818 // myReader.GetSubMesh( aSubMeshDS, subid );
3821 // try to get applied algorithms
3822 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
3823 // open "applied algorithms" HDF group
3824 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3825 aSubSubGroup->OpenOnDisk();
3826 // get number of applied algorithms
3827 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3828 for ( int l = 0; l < aNbSubObjects; l++ ) {
3829 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3830 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3831 // check if it is an algorithm
3832 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
3833 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3834 aDataset->OpenOnDisk();
3835 size = aDataset->GetSize();
3836 char* refFromFile = new char[ size ];
3837 aDataset->ReadFromDisk( refFromFile );
3838 aDataset->CloseOnDisk();
3840 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3841 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3842 int id = atoi( refFromFile );
3843 string anIOR = myStudyContext->getIORbyOldId( id );
3844 if ( !anIOR.empty() ) {
3845 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3846 if ( !CORBA::is_nil( hypObject ) ) {
3847 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3848 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3849 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3854 // close "applied algorithms" HDF group
3855 aSubSubGroup->CloseOnDisk();
3858 // try to get applied hypotheses
3859 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
3860 // open "applied hypotheses" HDF group
3861 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3862 aSubSubGroup->OpenOnDisk();
3863 // get number of applied hypotheses
3864 int aNbSubObjects = aSubSubGroup->nInternalObjects();
3865 for ( int l = 0; l < aNbSubObjects; l++ ) {
3866 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
3867 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
3868 // check if it is a hypothesis
3869 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
3870 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
3871 aDataset->OpenOnDisk();
3872 size = aDataset->GetSize();
3873 char* refFromFile = new char[ size ];
3874 aDataset->ReadFromDisk( refFromFile );
3875 aDataset->CloseOnDisk();
3877 //SALOMEDS::SObject_var hypSO = myCurrentStudy->FindObjectID( refFromFile );
3878 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
3879 int id = atoi( refFromFile );
3880 string anIOR = myStudyContext->getIORbyOldId( id );
3881 if ( !anIOR.empty() ) {
3882 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
3883 if ( !CORBA::is_nil( hypObject ) ) {
3884 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
3885 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
3886 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
3891 // close "applied hypotheses" HDF group
3892 aSubSubGroup->CloseOnDisk();
3895 // close submesh HDF group
3896 aSubGroup->CloseOnDisk();
3899 // close submeshes containers HDF group
3900 aGroup->CloseOnDisk();
3906 // Read sub-meshes from MED
3907 // -------------------------
3908 if(MYDEBUG) MESSAGE("Create all sub-meshes");
3909 bool submeshesInFamilies = ( ! aTopGroup->ExistInternalObject( "Submeshes" ));
3910 if ( submeshesInFamilies )
3912 // old way working before fix of PAL 12992
3913 myReader.CreateAllSubMeshes();
3918 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3919 aGroup->OpenOnDisk();
3921 int maxID = mySMESHDSMesh->MaxShapeIndex();
3922 vector< SMESHDS_SubMesh * > subMeshes( maxID + 1, (SMESHDS_SubMesh*) 0 );
3923 vector< TopAbs_ShapeEnum > smType ( maxID + 1, TopAbs_SHAPE );
3925 PositionCreator aPositionCreator;
3927 SMDS_NodeIteratorPtr nIt = mySMESHDSMesh->nodesIterator();
3928 SMDS_ElemIteratorPtr eIt = mySMESHDSMesh->elementsIterator();
3929 for ( int isNode = 0; isNode < 2; ++isNode )
3931 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3932 if ( aGroup->ExistInternalObject( (char*) aDSName.c_str() ))
3934 aDataset = new HDFdataset( (char*) aDSName.c_str(), aGroup );
3935 aDataset->OpenOnDisk();
3936 // read submesh IDs for all elements sorted by ID
3937 int nbElems = aDataset->GetSize();
3938 int* smIDs = new int [ nbElems ];
3939 aDataset->ReadFromDisk( smIDs );
3940 aDataset->CloseOnDisk();
3942 // get elements sorted by ID
3943 TIDSortedElemSet elemSet;
3945 while ( nIt->more() ) elemSet.insert( nIt->next() );
3947 while ( eIt->more() ) elemSet.insert( eIt->next() );
3948 //ASSERT( elemSet.size() == nbElems ); -- issue 20182
3949 // -- Most probably a bad study was saved when there were
3950 // not fixed bugs in SMDS_MeshInfo
3951 if ( elemSet.size() < nbElems ) {
3953 cout << "SMESH_Gen_i::Load(), warning: Node position data is invalid" << endl;
3955 nbElems = elemSet.size();
3957 // add elements to submeshes
3958 TIDSortedElemSet::iterator iE = elemSet.begin();
3959 for ( int i = 0; i < nbElems; ++i, ++iE )
3961 int smID = smIDs[ i ];
3962 if ( smID == 0 ) continue;
3963 const SMDS_MeshElement* elem = *iE;
3964 if( smID > maxID ) {
3965 // corresponding subshape no longer exists: maybe geom group has been edited
3966 if ( myNewMeshImpl->HasShapeToMesh() )
3967 mySMESHDSMesh->RemoveElement( elem );
3970 // get or create submesh
3971 SMESHDS_SubMesh* & sm = subMeshes[ smID ];
3973 sm = mySMESHDSMesh->NewSubMesh( smID );
3974 smType[ smID ] = mySMESHDSMesh->IndexToShape( smID ).ShapeType();
3978 SMDS_PositionPtr pos = aPositionCreator.MakePosition( smType[ smID ]);
3979 pos->SetShapeId( smID );
3980 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( static_cast<const SMDS_MeshNode*>( elem ));
3981 node->SetPosition( pos );
3982 sm->AddNode( node );
3984 sm->AddElement( elem );
3990 } // end reading submeshes
3992 // Read node positions on sub-shapes (SMDS_Position)
3994 if ( aTopGroup->ExistInternalObject( "Node Positions" ))
3996 // There are 5 datasets to read:
3997 // "Nodes on Edges" - ID of node on edge
3998 // "Edge positions" - U parameter on node on edge
3999 // "Nodes on Faces" - ID of node on face
4000 // "Face U positions" - U parameter of node on face
4001 // "Face V positions" - V parameter of node on face
4002 const char* aEid_DSName = "Nodes on Edges";
4003 const char* aEu_DSName = "Edge positions";
4004 const char* aFu_DSName = "Face U positions";
4005 //char* aFid_DSName = "Nodes on Faces";
4006 //char* aFv_DSName = "Face V positions";
4009 int nbEids = 0, nbFids = 0;
4010 int *aEids = 0, *aFids = 0;
4011 double *aEpos = 0, *aFupos = 0, *aFvpos = 0;
4014 aGroup = new HDFgroup( "Node Positions", aTopGroup );
4015 aGroup->OpenOnDisk();
4017 // loop on 5 data sets
4018 int aNbObjects = aGroup->nInternalObjects();
4019 for ( int i = 0; i < aNbObjects; i++ )
4022 char aDSName[ HDF_NAME_MAX_LEN+1 ];
4023 aGroup->InternalObjectIndentify( i, aDSName );
4025 aDataset = new HDFdataset( aDSName, aGroup );
4026 aDataset->OpenOnDisk();
4027 if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions
4029 double* pos = new double [ aDataset->GetSize() ];
4030 aDataset->ReadFromDisk( pos );
4032 if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 )
4034 else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 )
4041 int aSize = aDataset->GetSize();
4043 // for reading files, created from 18.07.2005 till 10.10.2005
4044 if (aDataset->GetType() == HDF_STRING)
4045 aSize /= sizeof(int);
4047 int* ids = new int [aSize];
4048 aDataset->ReadFromDisk( ids );
4049 // on face or nodes?
4050 if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) {
4059 aDataset->CloseOnDisk();
4060 } // loop on 5 datasets
4062 // Set node positions on edges or faces
4063 for ( int onFace = 0; onFace < 2; onFace++ )
4065 int nbNodes = ( onFace ? nbFids : nbEids );
4066 if ( nbNodes == 0 ) continue;
4067 int* aNodeIDs = ( onFace ? aFids : aEids );
4068 double* aUPos = ( onFace ? aFupos : aEpos );
4069 double* aVPos = ( onFace ? aFvpos : 0 );
4071 for ( int iNode = 0; iNode < nbNodes; iNode++ )
4073 const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]);
4074 if ( !node ) continue; // maybe removed while Loading() if geometry changed
4075 SMDS_PositionPtr aPos = node->GetPosition();
4078 // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE );-- issue 20182
4079 // -- Most probably a bad study was saved when there were
4080 // not fixed bugs in SMDS_MeshInfo
4081 if ( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
4082 SMDS_FacePosition* fPos = const_cast<SMDS_FacePosition*>
4083 ( static_cast<const SMDS_FacePosition*>( aPos.get() ));
4084 fPos->SetUParameter( aUPos[ iNode ]);
4085 fPos->SetVParameter( aVPos[ iNode ]);
4089 // ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE );-- issue 20182
4090 if ( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ) {
4091 SMDS_EdgePosition* fPos = const_cast<SMDS_EdgePosition*>
4092 ( static_cast<const SMDS_EdgePosition*>( aPos.get() ));
4093 fPos->SetUParameter( aUPos[ iNode ]);
4098 if ( aEids ) delete [] aEids;
4099 if ( aFids ) delete [] aFids;
4100 if ( aEpos ) delete [] aEpos;
4101 if ( aFupos ) delete [] aFupos;
4102 if ( aFvpos ) delete [] aFvpos;
4104 aGroup->CloseOnDisk();
4106 } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) )
4109 // Recompute State (as computed sub-meshes are restored from MED)
4110 if ( !aShapeObject->_is_nil() || !myNewMeshImpl->HasShapeToMesh()) {
4111 MESSAGE("Compute State Engine ...");
4112 TopoDS_Shape myLocShape;
4113 if(myNewMeshImpl->HasShapeToMesh())
4114 myLocShape = GeomObjectToShape( aShapeObject );
4116 myLocShape = SMESH_Mesh::PseudoShape();
4118 myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine
4119 (SMESH_subMesh::SUBMESH_RESTORED);
4120 MESSAGE("Compute State Engine finished");
4123 // try to get groups
4124 for ( int ii = GetNodeGroupsTag(); ii <= GetVolumeGroupsTag(); ii++ ) {
4125 char name_group[ 30 ];
4126 if ( ii == GetNodeGroupsTag() )
4127 strcpy( name_group, "Groups of Nodes" );
4128 else if ( ii == GetEdgeGroupsTag() )
4129 strcpy( name_group, "Groups of Edges" );
4130 else if ( ii == GetFaceGroupsTag() )
4131 strcpy( name_group, "Groups of Faces" );
4132 else if ( ii == GetVolumeGroupsTag() )
4133 strcpy( name_group, "Groups of Volumes" );
4135 if ( aTopGroup->ExistInternalObject( name_group ) ) {
4136 aGroup = new HDFgroup( name_group, aTopGroup );
4137 aGroup->OpenOnDisk();
4138 // get number of groups
4139 int aNbSubObjects = aGroup->nInternalObjects();
4140 for ( int j = 0; j < aNbSubObjects; j++ ) {
4141 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4142 aGroup->InternalObjectIndentify( j, name_dataset );
4143 // check if it is an group
4144 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
4146 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
4149 aDataset = new HDFdataset( name_dataset, aGroup );
4150 aDataset->OpenOnDisk();
4152 // Retrieve actual group name
4153 size = aDataset->GetSize();
4154 char* nameFromFile = new char[ size ];
4155 aDataset->ReadFromDisk( nameFromFile );
4156 aDataset->CloseOnDisk();
4158 // Try to find a shape reference
4159 TopoDS_Shape aShape;
4160 char aRefName[ 30 ];
4161 sprintf( aRefName, "Ref on shape %d", subid);
4162 if ( aGroup->ExistInternalObject( aRefName ) ) {
4163 // load mesh "Ref on shape" - it's an entry to SObject
4164 aDataset = new HDFdataset( aRefName, aGroup );
4165 aDataset->OpenOnDisk();
4166 size = aDataset->GetSize();
4167 char* refFromFile = new char[ size ];
4168 aDataset->ReadFromDisk( refFromFile );
4169 aDataset->CloseOnDisk();
4170 if ( strlen( refFromFile ) > 0 ) {
4171 SALOMEDS::SObject_var shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4172 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4173 if ( !CORBA::is_nil( shapeObject ) ) {
4174 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4175 if ( !aShapeObject->_is_nil() )
4176 aShape = GeomObjectToShape( aShapeObject );
4180 // Create group servant
4181 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
4182 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
4183 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) );
4184 // Obtain a SMESHDS_Group object
4185 if ( aNewGroup->_is_nil() )
4188 string iorSubString = GetORB()->object_to_string( aNewGroup );
4189 int newSubId = myStudyContext->findId( iorSubString );
4190 myStudyContext->mapOldToNew( subid, newSubId );
4192 SMESH_GroupBase_i* aGroupImpl =
4193 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aNewGroup ).in() );
4197 SMESH_Group* aLocalGroup = myLocMesh.GetGroup( aGroupImpl->GetLocalID() );
4201 SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS();
4202 aGroupBaseDS->SetStoreName( name_dataset );
4205 // Read color of the group
4206 char aGroupColorName[ 30 ];
4207 sprintf( aGroupColorName, "ColorGroup %d", subid);
4208 if ( aGroup->ExistInternalObject( aGroupColorName ) )
4210 aDataset = new HDFdataset( aGroupColorName, aGroup );
4211 aDataset->OpenOnDisk();
4212 size = aDataset->GetSize();
4213 double* anRGB = new double[ size ];
4214 aDataset->ReadFromDisk( anRGB );
4215 aDataset->CloseOnDisk();
4216 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
4217 aGroupBaseDS->SetColor( aColor );
4220 // Fill group with contents from MED file
4221 SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
4223 myReader.GetGroup( aGrp );
4226 aGroup->CloseOnDisk();
4229 // read submeh order if any
4230 if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
4231 aDataset = new HDFdataset( "Mesh Order", aTopGroup );
4232 aDataset->OpenOnDisk();
4233 size = aDataset->GetSize();
4234 int* smIDs = new int[ size ];
4235 aDataset->ReadFromDisk( smIDs );
4236 aDataset->CloseOnDisk();
4237 TListOfListOfInt anOrderIds;
4238 anOrderIds.push_back( TListOfInt() );
4239 for ( int i = 0; i < size; i++ )
4240 if ( smIDs[ i ] < 0 ) // is separator
4241 anOrderIds.push_back( TListOfInt() );
4243 anOrderIds.back().push_back(smIDs[ i ]);
4245 myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
4250 aTopGroup->CloseOnDisk();
4253 aFile->CloseOnDisk();
4256 // Remove temporary files created from the stream
4258 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
4260 INFOS( "SMESH_Gen_i::Load completed" );
4264 //=============================================================================
4266 * SMESH_Gen_i::LoadASCII
4268 * Load SMESH module's data in ASCII format
4270 //=============================================================================
4272 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
4273 const SALOMEDS::TMPFile& theStream,
4275 bool isMultiFile ) {
4276 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
4277 return Load( theComponent, theStream, theURL, isMultiFile );
4279 //before call main ::Load method it's need for decipher text format to
4280 //binary ( "|xx" => x' )
4281 int size = theStream.length();
4282 if ( int((size / 3 )*3) != size ) //error size of buffer
4285 int real_size = int(size / 3);
4287 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
4291 for ( int i = 0; i < real_size; i++ )
4293 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
4294 sscanf( tmp, "%x", &c );
4295 sprintf( (char*)&(buffer[i]), "%c", (char)c );
4298 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
4300 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
4303 //=============================================================================
4305 * SMESH_Gen_i::Close
4307 * Clears study-connected data when it is closed
4309 //=============================================================================
4311 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
4313 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
4315 // set correct current study
4316 if (theComponent->GetStudy()->StudyId() != GetCurrentStudyID())
4317 SetCurrentStudy(theComponent->GetStudy());
4319 // Clear study contexts data
4320 int studyId = GetCurrentStudyID();
4321 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
4322 delete myStudyContextMap[ studyId ];
4323 myStudyContextMap.erase( studyId );
4326 // delete SMESH_Mesh's
4327 // See bug IPAL19437.
4329 // StudyContextStruct* context = myGen.GetStudyContext( studyId );
4330 // map< int, SMESH_Mesh* >::iterator i_mesh = context->mapMesh.begin();
4331 // for ( ; i_mesh != context->mapMesh.end(); ++i_mesh ) {
4332 // printf( "--------------------------- SMESH_Gen_i::Close, delete aGroup = %p \n", i_mesh->second );
4333 // delete i_mesh->second;
4337 // delete SMESHDS_Mesh's
4338 // it's too long on big meshes
4339 // if ( context->myDocument ) {
4340 // delete context->myDocument;
4341 // context->myDocument = 0;
4344 myCurrentStudy = SALOMEDS::Study::_nil();
4348 //=============================================================================
4350 * SMESH_Gen_i::ComponentDataType
4352 * Get component data type
4354 //=============================================================================
4356 char* SMESH_Gen_i::ComponentDataType()
4358 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
4359 return CORBA::string_dup( "SMESH" );
4363 //=============================================================================
4365 * SMESH_Gen_i::IORToLocalPersistentID
4367 * Transform data from transient form to persistent
4369 //=============================================================================
4371 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
4372 const char* IORString,
4373 CORBA::Boolean /*isMultiFile*/,
4374 CORBA::Boolean /*isASCII*/ )
4376 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
4377 StudyContext* myStudyContext = GetCurrentStudyContext();
4379 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
4380 int anId = myStudyContext->findId( IORString );
4382 if(MYDEBUG) MESSAGE( "VSR " << anId )
4384 sprintf( strId, "%d", anId );
4385 return CORBA::string_dup( strId );
4388 return CORBA::string_dup( "" );
4391 //=============================================================================
4393 * SMESH_Gen_i::LocalPersistentIDToIOR
4395 * Transform data from persistent form to transient
4397 //=============================================================================
4399 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
4400 const char* aLocalPersistentID,
4401 CORBA::Boolean /*isMultiFile*/,
4402 CORBA::Boolean /*isASCII*/ )
4404 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
4405 StudyContext* myStudyContext = GetCurrentStudyContext();
4407 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
4408 int anId = atoi( aLocalPersistentID );
4409 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
4411 return CORBA::string_dup( "" );
4414 //=======================================================================
4415 //function : RegisterObject
4417 //=======================================================================
4419 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
4421 StudyContext* myStudyContext = GetCurrentStudyContext();
4422 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4423 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
4424 return myStudyContext->addObject( string( iorString.in() ) );
4429 //================================================================================
4431 * \brief Return id of registered object
4432 * \param theObject - the Object
4433 * \retval int - Object id
4435 //================================================================================
4437 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
4439 StudyContext* myStudyContext = GetCurrentStudyContext();
4440 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4441 string iorString = GetORB()->object_to_string( theObject );
4442 return myStudyContext->findId( iorString );
4447 //=============================================================================
4449 * SMESH_Gen_i::SetName
4451 * Set a new object name
4453 //=============================================================================
4454 void SMESH_Gen_i::SetName(const char* theIOR,
4455 const char* theName)
4457 if ( theIOR && strcmp( theIOR, "" ) ) {
4458 CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
4459 SALOMEDS::SObject_var aSO = ObjectToSObject( myCurrentStudy, anObject );
4460 if ( !aSO->_is_nil() ) {
4461 SetName( aSO, theName );
4466 int SMESH_Gen_i::GetCurrentStudyID()
4468 return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
4471 //=============================================================================
4473 * SMESHEngine_factory
4475 * C factory, accessible with dlsym, after dlopen
4477 //=============================================================================
4481 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
4482 PortableServer::POA_ptr poa,
4483 PortableServer::ObjectId* contId,
4484 const char* instanceName,
4485 const char* interfaceName )
4487 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
4488 if(MYDEBUG) SCRUTE(interfaceName);
4489 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
4490 return aSMESHGen->getId() ;