1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESH_Gen_i.cxx
23 // Author : Paul RASCLE, EDF
27 #include <TopExp_Explorer.hxx>
29 #include <TopoDS_Iterator.hxx>
30 #include <TopoDS_Compound.hxx>
31 #include <TopoDS_CompSolid.hxx>
32 #include <TopoDS_Solid.hxx>
33 #include <TopoDS_Shell.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Wire.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <BRep_Tool.hxx>
45 #include <TCollection_AsciiString.hxx>
56 #define LibHandle HMODULE
57 #define LoadLib( name ) LoadLibrary( name )
58 #define GetProc GetProcAddress
59 #define UnLoadLib( handle ) FreeLibrary( handle );
61 #define LibHandle void*
62 #define LoadLib( name ) dlopen( name, RTLD_LAZY )
64 #define UnLoadLib( handle ) dlclose( handle );
67 #include "SMESH_Gen_i.hxx"
68 #include "SMESH_version.h"
70 #include "DriverMED_W_SMESHDS_Mesh.h"
71 #include "DriverMED_R_SMESHDS_Mesh.h"
73 #include "DriverCGNS_Read.hxx"
75 #include "MED_Factory.hxx"
76 #include "SMDS_EdgePosition.hxx"
77 #include "SMDS_FacePosition.hxx"
78 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
79 #include "SMDS_SetIterator.hxx"
80 #include "SMDS_SpacePosition.hxx"
81 #include "SMDS_VertexPosition.hxx"
82 #include "SMESHDS_Document.hxx"
83 #include "SMESHDS_Group.hxx"
84 #include "SMESHDS_GroupOnGeom.hxx"
85 #include "SMESH_Algo_i.hxx"
86 #include "SMESH_File.hxx"
87 #include "SMESH_Group.hxx"
88 #include "SMESH_Group_i.hxx"
89 #include "SMESH_Hypothesis.hxx"
90 #include "SMESH_Hypothesis_i.hxx"
91 #include "SMESH_Mesh.hxx"
92 #include "SMESH_MeshEditor.hxx"
93 #include "SMESH_Mesh_i.hxx"
94 #include "SMESH_PreMeshInfo.hxx"
95 #include "SMESH_PythonDump.hxx"
96 //#include "memoire.h"
98 #include CORBA_SERVER_HEADER(SMESH_Group)
99 #include CORBA_SERVER_HEADER(SMESH_Filter)
100 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
103 #include <GEOM_Client.hxx>
105 #include <Basics_Utils.hxx>
107 #include <OpUtil.hxx>
108 #include <SALOMEDS_Tool.hxx>
109 #include <SALOME_Container_i.hxx>
110 #include <SALOME_LifeCycleCORBA.hxx>
111 #include <SALOME_NamingService.hxx>
112 #include <Utils_CorbaException.hxx>
113 #include <Utils_ExceptHandlers.hxx>
114 #include <Utils_SINGLETON.hxx>
115 #include <utilities.h>
117 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
118 #include CORBA_CLIENT_HEADER(SALOME_Session)
120 // helpers about SALOME::GenericObj
121 #include <SALOMEDS_wrap.hxx>
122 #include <SALOMEDS_Attributes_wrap.hxx>
123 #include <GEOM_wrap.hxx>
131 using SMESH::TPythonDump;
134 #define NUM_TMP_FILES 2
137 static int MYDEBUG = 0;
139 static int MYDEBUG = 0;
142 // Static variables definition
143 GEOM::GEOM_Gen_var SMESH_Gen_i::myGeomGen = GEOM::GEOM_Gen::_nil();
144 CORBA::ORB_var SMESH_Gen_i::myOrb;
145 PortableServer::POA_var SMESH_Gen_i::myPoa;
146 SALOME_NamingService* SMESH_Gen_i::myNS = NULL;
147 SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL;
148 SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL;
151 const int nbElemPerDiagonal = 10;
153 //=============================================================================
155 * GetServant [ static ]
157 * Get servant of the CORBA object
159 //=============================================================================
161 PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theObject )
163 if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) )
166 PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject );
170 INFOS( "GetServant - Unknown exception was caught!!!" );
175 //=============================================================================
177 * SObjectToObject [ static ]
179 * Get CORBA object corresponding to the SALOMEDS::SObject
181 //=============================================================================
183 CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject )
185 SALOMEDS::GenericAttribute_wrap anAttr;
186 CORBA::Object_var anObj;
187 if ( !theSObject->_is_nil() ) {
189 if( theSObject->FindAttribute( anAttr.inout(), "AttributeIOR" ) ) {
190 SALOMEDS::AttributeIOR_wrap anIOR = anAttr;
191 CORBA::String_var aValue = anIOR->Value();
192 if( strcmp( aValue, "" ) != 0 )
193 anObj = GetORB()->string_to_object( aValue );
197 INFOS( "SObjectToObject - Unknown exception was caught!!!" );
203 //=============================================================================
207 * Get SALOME_NamingService object
209 //=============================================================================
211 SALOME_NamingService* SMESH_Gen_i::GetNS()
213 if ( myNS == NULL ) {
214 myNS = SINGLETON_<SALOME_NamingService>::Instance();
215 ASSERT(SINGLETON_<SALOME_NamingService>::IsAlreadyExisting());
216 myNS->init_orb( GetORB() );
221 //=============================================================================
225 * Get SALOME_LifeCycleCORBA object
227 //=============================================================================
228 SALOME_LifeCycleCORBA* SMESH_Gen_i::GetLCC() {
229 if ( myLCC == NULL ) {
230 myLCC = new SALOME_LifeCycleCORBA( GetNS() );
236 //=============================================================================
238 * GetGeomEngine [ static ]
240 * Get GEOM::GEOM_Gen reference
242 //=============================================================================
243 GEOM::GEOM_Gen_var SMESH_Gen_i::GetGeomEngine() {
244 //CCRT GEOM::GEOM_Gen_var aGeomEngine =
245 //CCRT GEOM::GEOM_Gen::_narrow( GetLCC()->FindOrLoad_Component("FactoryServer","GEOM") );
246 //CCRT return aGeomEngine._retn();
247 if(CORBA::is_nil(myGeomGen))
249 Engines::EngineComponent_ptr temp=GetLCC()->FindOrLoad_Component("FactoryServer","GEOM");
250 myGeomGen=GEOM::GEOM_Gen::_narrow(temp);
255 //=============================================================================
257 * SMESH_Gen_i::SMESH_Gen_i
259 * Default constructor: not for use
261 //=============================================================================
263 SMESH_Gen_i::SMESH_Gen_i()
265 INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" );
268 //=============================================================================
270 * SMESH_Gen_i::SMESH_Gen_i
272 * Standard constructor, used with Container
274 //=============================================================================
276 SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb,
277 PortableServer::POA_ptr poa,
278 PortableServer::ObjectId* contId,
279 const char* instanceName,
280 const char* interfaceName )
281 : Engines_Component_i( orb, poa, contId, instanceName, interfaceName )
283 MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" );
285 myOrb = CORBA::ORB::_duplicate(orb);
286 myPoa = PortableServer::POA::_duplicate(poa);
289 _id = myPoa->activate_object( _thisObj );
291 myIsEmbeddedMode = false;
292 myShapeReader = NULL; // shape reader
294 myIsHistoricalPythonDump = true;
295 myToForgetMeshDataOnHypModif = false;
297 // set it in standalone mode only
298 //OSD::SetSignal( true );
300 // 0020605: EDF 1190 SMESH: Display performance. 80 seconds for 52000 cells.
301 // find out mode (embedded or standalone) here else
302 // meshes created before calling SMESH_Client::GetSMESHGen(), which calls
303 // SMESH_Gen_i::SetEmbeddedMode(), have wrong IsEmbeddedMode flag
304 if ( SALOME_NamingService* ns = GetNS() )
306 CORBA::Object_var obj = ns->Resolve( "/Kernel/Session" );
307 SALOME::Session_var session = SALOME::Session::_narrow( obj ) ;
308 if ( !session->_is_nil() )
310 CORBA::String_var str_host = session->getHostname();
311 CORBA::Long s_pid = session->getPID();
312 string my_host = Kernel_Utils::GetHostname();
314 long my_pid = (long)_getpid();
316 long my_pid = (long) getpid();
318 SetEmbeddedMode( s_pid == my_pid && my_host == str_host.in() );
323 //=============================================================================
325 * SMESH_Gen_i::~SMESH_Gen_i
329 //=============================================================================
331 SMESH_Gen_i::~SMESH_Gen_i()
333 MESSAGE( "SMESH_Gen_i::~SMESH_Gen_i" );
335 // delete hypothesis creators
336 map<string, GenericHypothesisCreator_i*>::iterator itHyp;
337 for (itHyp = myHypCreatorMap.begin(); itHyp != myHypCreatorMap.end(); itHyp++)
339 delete (*itHyp).second;
341 myHypCreatorMap.clear();
343 // Clear study contexts data
344 map<int, StudyContext*>::iterator it;
345 for ( it = myStudyContextMap.begin(); it != myStudyContextMap.end(); ++it ) {
348 myStudyContextMap.clear();
349 // delete shape reader
351 delete myShapeReader;
354 //=============================================================================
356 * SMESH_Gen_i::createHypothesis
358 * Create hypothesis of given type
360 //=============================================================================
361 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName,
362 const char* theLibName)
363 throw (SALOME::SALOME_Exception)
365 /* It's Need to tranlate lib name for WIN32 or X platform */
366 std::string aPlatformLibName;
367 if ( theLibName && theLibName[0] != '\0' )
369 int libNameLen = strlen(theLibName);
370 //check for old format "libXXXXXXX.so"
371 if (libNameLen > 7 &&
372 !strncmp( theLibName, "lib", 3 ) &&
373 !strcmp( theLibName+libNameLen-3, ".so" ))
377 aPlatformLibName = std::string( theLibName+3, libNameLen-6 ) + ".dll";
379 aPlatformLibName = theLibName;
384 //try to use new format
386 aPlatformLibName = theLibName + ".dll";
388 aPlatformLibName = "lib" + std::string( theLibName ) + ".so";
393 Unexpect aCatch(SALOME_SalomeException);
394 if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << aPlatformLibName);
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.c_str() );
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.c_str()); // for persistency assurance
448 catch (SALOME_Exception& S_ex)
450 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
454 return hypothesis_i._retn();
456 // activate the CORBA servant of hypothesis
457 hypothesis_i = myHypothesis_i->_this();
458 int nextId = RegisterObject( hypothesis_i );
459 if(MYDEBUG) { MESSAGE( "Add hypo to map with id = "<< nextId ); }
460 else { nextId = 0; } // avoid "unused variable" warning in release mode
462 return hypothesis_i._retn();
465 //=============================================================================
467 * SMESH_Gen_i::createMesh
469 * Create empty mesh on shape
471 //=============================================================================
472 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh()
473 throw ( SALOME::SALOME_Exception )
475 Unexpect aCatch(SALOME_SalomeException);
476 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" );
478 // Get or create the GEOM_Client instance
480 // create a new mesh object servant, store it in a map in study context
481 SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() );
482 // create a new mesh object
483 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
484 meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID(), myIsEmbeddedMode ));
486 // activate the CORBA servant of Mesh
487 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() );
488 int nextId = RegisterObject( mesh );
489 if(MYDEBUG) { MESSAGE( "Add mesh to map with id = "<< nextId); }
490 else { nextId = 0; } // avoid "unused variable" warning in release mode
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;
542 MESSAGE("myIsEmbeddedMode " << myIsEmbeddedMode);
544 if ( !myIsEmbeddedMode ) {
545 //PAL10867: disable signals catching with "noexcepthandler" option
546 char* envNoCatchSignals = getenv("NOT_INTERCEPT_SIGNALS");
547 if (!envNoCatchSignals || !atoi(envNoCatchSignals))
552 char* envDisableFPE = getenv("DISABLE_FPE");
553 if (envDisableFPE && atoi(envDisableFPE))
558 OSD::SetSignal( raiseFPE );
560 // else OSD::SetSignal() is called in GUI
564 //=============================================================================
566 * SMESH_Gen_i::IsEmbeddedMode
570 //=============================================================================
572 CORBA::Boolean SMESH_Gen_i::IsEmbeddedMode()
574 return myIsEmbeddedMode;
577 //=============================================================================
579 * SMESH_Gen_i::SetCurrentStudy
583 //=============================================================================
585 void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy )
587 setCurrentStudy( theStudy );
590 void SMESH_Gen_i::setCurrentStudy( SALOMEDS::Study_ptr theStudy,
591 bool theStudyIsBeingClosed)
593 int curStudyId = GetCurrentStudyID();
594 myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy );
595 // create study context, if it doesn't exist and set current study
596 int studyId = GetCurrentStudyID();
597 if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() )
598 myStudyContextMap[ studyId ] = new StudyContext;
600 // myCurrentStudy may be nil
601 if ( !theStudyIsBeingClosed && !CORBA::is_nil( myCurrentStudy ) ) {
602 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
603 SALOMEDS::SComponent_wrap GEOM_var = myCurrentStudy->FindComponent( "GEOM" );
604 if( !GEOM_var->_is_nil() )
605 aStudyBuilder->LoadWith( GEOM_var, GetGeomEngine() );
606 // NPAL16168, issue 0020210
607 // Let meshes update their data depending on GEOM groups that could change
608 if ( curStudyId != studyId )
610 CORBA::String_var compDataType = ComponentDataType();
611 SALOMEDS::SComponent_wrap me = myCurrentStudy->FindComponent( compDataType.in() );
612 if ( !me->_is_nil() ) {
613 SALOMEDS::ChildIterator_wrap anIter = myCurrentStudy->NewChildIterator( me );
614 for ( ; anIter->More(); anIter->Next() ) {
615 SALOMEDS::SObject_wrap so = anIter->Value();
616 CORBA::Object_var ior = SObjectToObject( so );
617 if ( SMESH_Mesh_i* mesh = SMESH::DownCast<SMESH_Mesh_i*>( ior ))
618 mesh->CheckGeomGroupModif();
625 //=============================================================================
627 * SMESH_Gen_i::GetCurrentStudy
631 //=============================================================================
633 SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy()
635 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() );
636 return SALOMEDS::Study::_duplicate( myCurrentStudy );
639 //=============================================================================
641 * SMESH_Gen_i::GetCurrentStudyContext
643 * Get current study context
645 //=============================================================================
646 StudyContext* SMESH_Gen_i::GetCurrentStudyContext()
648 if ( !CORBA::is_nil( myCurrentStudy ) &&
649 myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() )
650 return myStudyContextMap[ myCurrentStudy->StudyId() ];
655 //=============================================================================
657 * SMESH_Gen_i::CreateHypothesis
659 * Create hypothesis/algorothm of given type and publish it in the study
661 //=============================================================================
663 SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypName,
664 const char* theLibName )
665 throw ( SALOME::SALOME_Exception )
667 Unexpect aCatch(SALOME_SalomeException);
668 // Create hypothesis/algorithm
669 SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName );
671 // Publish hypothesis/algorithm in the study
672 if ( CanPublishInStudy( hyp ) ) {
673 SALOMEDS::SObject_wrap aSO = PublishHypothesis( myCurrentStudy, hyp );
674 if ( !aSO->_is_nil() ) {
675 // Update Python script
676 TPythonDump() << aSO << " = " << this << ".CreateHypothesis('"
677 << theHypName << "', '" << theLibName << "')";
684 //================================================================================
686 * \brief Return a hypothesis holding parameter values corresponding either to the mesh
687 * existing on the given geometry or to size of the geometry.
688 * \param theHypType - hypothesis type name
689 * \param theLibName - plugin library name
690 * \param theMesh - The mesh of interest
691 * \param theGeom - The shape to get parameter values from
692 * \retval SMESH::SMESH_Hypothesis_ptr - The returned hypothesis may be the one existing
693 * in a study and used to compute the mesh, or a temporary one created just to pass
696 //================================================================================
698 SMESH::SMESH_Hypothesis_ptr
699 SMESH_Gen_i::GetHypothesisParameterValues (const char* theHypType,
700 const char* theLibName,
701 SMESH::SMESH_Mesh_ptr theMesh,
702 GEOM::GEOM_Object_ptr theGeom,
703 CORBA::Boolean byMesh)
704 throw ( SALOME::SALOME_Exception )
706 Unexpect aCatch(SALOME_SalomeException);
707 if ( byMesh && CORBA::is_nil( theMesh ) )
708 return SMESH::SMESH_Hypothesis::_nil();
709 if ( byMesh && CORBA::is_nil( theGeom ) )
710 return SMESH::SMESH_Hypothesis::_nil();
712 // -----------------------------------------------
713 // find hypothesis used to mesh theGeom
714 // -----------------------------------------------
716 // get mesh and shape
717 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
718 TopoDS_Shape shape = GeomObjectToShape( theGeom );
719 if ( byMesh && ( !meshServant || meshServant->NbNodes()==0 || shape.IsNull() ))
720 return SMESH::SMESH_Hypothesis::_nil();
721 ::SMESH_Mesh* mesh = meshServant ? &meshServant->GetImpl() : (::SMESH_Mesh*)0;
723 // create a temporary hypothesis to know its dimention
724 SMESH::SMESH_Hypothesis_var tmpHyp = this->createHypothesis( theHypType, theLibName );
725 SMESH_Hypothesis_i* hypServant = SMESH::DownCast<SMESH_Hypothesis_i*>( tmpHyp );
727 return SMESH::SMESH_Hypothesis::_nil();
728 ::SMESH_Hypothesis* hyp = hypServant->GetImpl();
731 // look for a hypothesis of theHypType used to mesh the shape
732 if ( myGen.GetShapeDim( shape ) == hyp->GetDim() )
735 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( theGeom );
736 int nbLocalHyps = aHypList->length();
737 for ( int i = 0; i < nbLocalHyps; i++ ) {
738 CORBA::String_var hypName = aHypList[i]->GetName();
739 if ( strcmp( theHypType, hypName.in() ) == 0 ) // FOUND local!
740 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
742 // check super shapes
743 TopTools_ListIteratorOfListOfShape itShape( mesh->GetAncestors( shape ));
744 while ( nbLocalHyps == 0 && itShape.More() ) {
745 GEOM::GEOM_Object_ptr geomObj = ShapeToGeomObject( itShape.Value() );
746 if ( ! CORBA::is_nil( geomObj )) {
747 SMESH::ListOfHypothesis_var aHypList = theMesh->GetHypothesisList( geomObj );
748 nbLocalHyps = aHypList->length();
749 for ( int i = 0; i < nbLocalHyps; i++ )
750 if ( strcmp( theHypType, aHypList[i]->GetName() ) == 0 ) // FOUND global!
751 return SMESH::SMESH_Hypothesis::_duplicate( aHypList[i] );
757 // let the temporary hypothesis find out somehow parameter values by mesh
758 if ( hyp->SetParametersByMesh( mesh, shape ))
759 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
764 diagonal = mesh->GetShapeDiagonalSize();
766 diagonal = ::SMESH_Mesh::GetShapeDiagonalSize( shape );
767 ::SMESH_Hypothesis::TDefaults dflts;
768 dflts._elemLength = diagonal / myGen.GetBoundaryBoxSegmentation();
769 dflts._nbSegments = myGen.GetDefaultNbSegments();
770 dflts._shape = &shape;
771 // let the temporary hypothesis initialize it's values
772 if ( hyp->SetParametersByDefaults( dflts, mesh ))
773 return SMESH::SMESH_Hypothesis::_duplicate( tmpHyp );
776 return SMESH::SMESH_Hypothesis::_nil();
779 //=============================================================================
781 * Sets number of segments per diagonal of boundary box of geometry by which
782 * default segment length of appropriate 1D hypotheses is defined
784 //=============================================================================
786 void SMESH_Gen_i::SetBoundaryBoxSegmentation( CORBA::Long theNbSegments )
787 throw ( SALOME::SALOME_Exception )
789 if ( theNbSegments > 0 )
790 myGen.SetBoundaryBoxSegmentation( int( theNbSegments ));
792 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
794 //=============================================================================
796 * \brief Sets default number of segments per edge
798 //=============================================================================
799 void SMESH_Gen_i::SetDefaultNbSegments(CORBA::Long theNbSegments)
800 throw ( SALOME::SALOME_Exception )
802 if ( theNbSegments > 0 )
803 myGen.SetDefaultNbSegments( int(theNbSegments) );
805 THROW_SALOME_CORBA_EXCEPTION( "non-positive number of segments", SALOME::BAD_PARAM );
808 //=============================================================================
812 //=============================================================================
814 void SMESH_Gen_i::SetOption(const char* name, const char* value)
816 if ( name && value && strlen( value ) > 0 )
819 if ( strcmp(name, "historical_python_dump") == 0 )
821 myIsHistoricalPythonDump = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
822 msgToGUI = "preferences/SMESH/historical_python_dump/";
823 msgToGUI += myIsHistoricalPythonDump ? "true" : "false";
825 else if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
827 myToForgetMeshDataOnHypModif = ( value[0] == '1' || toupper(value[0]) == 'T' ); // 1 || true
828 msgToGUI = "preferences/SMESH/forget_mesh_on_hyp_modif/";
829 msgToGUI += myToForgetMeshDataOnHypModif ? "true" : "false";
832 // update preferences in case if SetOption() is invoked from python console
833 if ( !msgToGUI.empty() )
835 CORBA::Object_var obj = SMESH_Gen_i::GetNS()->Resolve( "/Kernel/Session" );
836 SALOME::Session_var session = SALOME::Session::_narrow( obj );
837 if ( !CORBA::is_nil( session ) )
838 session->emitMessageOneWay(msgToGUI.c_str());
843 //=============================================================================
845 Return an option value
847 //=============================================================================
849 char* SMESH_Gen_i::GetOption(const char* name)
853 if ( strcmp(name, "historical_python_dump") == 0 )
855 return CORBA::string_dup( myIsHistoricalPythonDump ? "true" : "false" );
857 if ( strcmp(name, "forget_mesh_on_hyp_modif") == 0 )
859 return CORBA::string_dup( myToForgetMeshDataOnHypModif ? "true" : "false" );
862 return CORBA::string_dup( "" );
865 //=============================================================================
867 * SMESH_Gen_i::CreateMesh
869 * Create empty mesh on a shape and publish it in the study
871 //=============================================================================
873 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject )
874 throw ( SALOME::SALOME_Exception )
876 Unexpect aCatch(SALOME_SalomeException);
877 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
879 SMESH::SMESH_Mesh_var mesh = this->createMesh();
881 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
882 ASSERT( meshServant );
883 meshServant->SetShape( theShapeObject );
885 // publish mesh in the study
886 if ( CanPublishInStudy( mesh ) ) {
887 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
888 aStudyBuilder->NewCommand(); // There is a transaction
889 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
890 aStudyBuilder->CommitCommand();
891 if ( !aSO->_is_nil() ) {
892 // Update Python script
893 TPythonDump() << aSO << " = " << this << ".CreateMesh(" << theShapeObject << ")";
900 //=============================================================================
902 * SMESH_Gen_i::CreateEmptyMesh
906 //=============================================================================
908 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateEmptyMesh()
909 throw ( SALOME::SALOME_Exception )
911 Unexpect aCatch(SALOME_SalomeException);
912 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" );
914 SMESH::SMESH_Mesh_var mesh = this->createMesh();
916 // publish mesh in the study
917 if ( CanPublishInStudy( mesh ) ) {
918 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
919 aStudyBuilder->NewCommand(); // There is a transaction
920 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, mesh.in() );
921 aStudyBuilder->CommitCommand();
922 if ( !aSO->_is_nil() ) {
923 // Update Python script
924 TPythonDump() << aSO << " = " << this << ".CreateEmptyMesh()";
931 //=============================================================================
933 * SMESH_Gen_i::CreateMeshFromUNV
935 * Create mesh and import data from UNV file
937 //=============================================================================
939 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName )
940 throw ( SALOME::SALOME_Exception )
942 Unexpect aCatch(SALOME_SalomeException);
943 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" );
945 SMESH::SMESH_Mesh_var aMesh = createMesh();
947 // publish mesh in the study
948 if ( CanPublishInStudy( aMesh ) ) {
949 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
950 aStudyBuilder->NewCommand(); // There is a transaction
951 SALOMEDS::SObject_wrap aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
952 aStudyBuilder->CommitCommand();
953 if ( !aSO->_is_nil() ) {
954 // Update Python script
955 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromUNV(r'" << theFileName << "')";
959 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
961 aServant->ImportUNVFile( theFileName );
963 // Dump creation of groups
964 SMESH::ListOfGroups_var groups = aServant->GetGroups();
966 aServant->GetImpl().GetMeshDS()->Modified();
967 return aMesh._retn();
970 //=============================================================================
972 * SMESH_Gen_i::CreateMeshFromMED
974 * Create mesh and import data from MED file
976 //=============================================================================
978 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileName,
979 SMESH::DriverMED_ReadStatus& theStatus,
980 const char* theCommandNameForPython,
981 const char* theFileNameForPython)
984 char bname[ _MAX_FNAME ];
985 _splitpath( theFileNameForPython, NULL, NULL, bname, NULL );
986 string aFileName = bname;
988 string aFileName = basename( theFileNameForPython );
990 // Retrieve mesh names from the file
991 DriverMED_R_SMESHDS_Mesh myReader;
992 myReader.SetFile( theFileName );
993 myReader.SetMeshId( -1 );
994 Driver_Mesh::Status aStatus;
995 list<string> aNames = myReader.GetMeshNames(aStatus);
996 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
997 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
999 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1002 TPythonDump aPythonDump;
1003 aPythonDump << "([";
1005 if (theStatus == SMESH::DRS_OK) {
1006 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1007 aStudyBuilder->NewCommand(); // There is a transaction
1008 aResult->length( aNames.size() );
1011 // Iterate through all meshes and create mesh objects
1012 for ( list<string>::iterator it = aNames.begin(); it != aNames.end(); it++ ) {
1014 if (i > 0) aPythonDump << ", ";
1017 SMESH::SMESH_Mesh_var mesh = createMesh();
1019 // publish mesh in the study
1020 SALOMEDS::SObject_wrap aSO;
1021 if ( CanPublishInStudy( mesh ) )
1022 // little trick: for MED file theFileName and theFileNameForPython are the same, but they are different for SAUV
1023 // - as names of meshes are stored in MED file, we use them for data publishing
1024 // - as mesh name is not stored in UNV file, we use file name as name of mesh when publishing data
1025 aSO = PublishMesh( myCurrentStudy, mesh.in(), ( theFileName == theFileNameForPython ) ? (*it).c_str() : aFileName.c_str() );
1026 if ( !aSO->_is_nil() ) {
1031 aPythonDump << "mesh_" << i;
1034 // Read mesh data (groups are published automatically by ImportMEDFile())
1035 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1036 ASSERT( meshServant );
1037 SMESH::DriverMED_ReadStatus status1 =
1038 meshServant->ImportMEDFile( theFileName, (*it).c_str() );
1039 if (status1 > theStatus)
1040 theStatus = status1;
1042 aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh );
1043 meshServant->GetImpl().GetMeshDS()->Modified();
1045 aStudyBuilder->CommitCommand();
1048 // Update Python script
1049 aPythonDump << "], status) = " << this << "." << theCommandNameForPython << "(r'" << theFileNameForPython << "')";
1051 // Dump creation of groups
1052 for ( int i = 0; i < aResult->length(); ++i )
1053 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1055 return aResult._retn();
1058 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
1059 SMESH::DriverMED_ReadStatus& theStatus)
1060 throw ( SALOME::SALOME_Exception )
1062 Unexpect aCatch(SALOME_SalomeException);
1063 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" );
1064 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(theFileName, theStatus, "CreateMeshesFromMED", theFileName);
1068 //=============================================================================
1070 * SMESH_Gen_i::CreateMeshFromSAUV
1072 * Create mesh and import data from SAUV file
1074 //=============================================================================
1076 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromSAUV( const char* theFileName,
1077 SMESH::DriverMED_ReadStatus& theStatus)
1078 throw ( SALOME::SALOME_Exception )
1080 Unexpect aCatch(SALOME_SalomeException);
1081 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromSAUV" );
1082 std::string sauvfilename(theFileName);
1083 std::string medfilename(theFileName);
1084 medfilename += ".med";
1087 cmd = "%PYTHONBIN% ";
1092 cmd += "from medutilities import convert ; convert(r'" + sauvfilename + "', 'GIBI', 'MED', 1, r'" + medfilename + "')";
1094 system(cmd.c_str());
1095 SMESH::mesh_array* result = CreateMeshesFromMEDorSAUV(medfilename.c_str(), theStatus, "CreateMeshesFromSAUV", sauvfilename.c_str());
1097 cmd = "%PYTHONBIN% ";
1102 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1104 system(cmd.c_str());
1108 //=============================================================================
1110 * SMESH_Gen_i::CreateMeshFromSTL
1112 * Create mesh and import data from STL file
1114 //=============================================================================
1116 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName )
1117 throw ( SALOME::SALOME_Exception )
1119 Unexpect aCatch(SALOME_SalomeException);
1120 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" );
1122 SMESH::SMESH_Mesh_var aMesh = createMesh();
1125 char bname[ _MAX_FNAME ];
1126 _splitpath( theFileName, NULL, NULL, bname, NULL );
1127 string aFileName = bname;
1129 string aFileName = basename( theFileName );
1131 // publish mesh in the study
1132 if ( CanPublishInStudy( aMesh ) ) {
1133 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1134 aStudyBuilder->NewCommand(); // There is a transaction
1135 SALOMEDS::SObject_wrap aSO = PublishInStudy
1136 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1137 aStudyBuilder->CommitCommand();
1138 if ( !aSO->_is_nil() ) {
1139 // Update Python script
1140 TPythonDump() << aSO << " = " << this << ".CreateMeshesFromSTL(r'" << theFileName << "')";
1144 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1146 aServant->ImportSTLFile( theFileName );
1147 aServant->GetImpl().GetMeshDS()->Modified();
1148 return aMesh._retn();
1151 //================================================================================
1153 * \brief Create meshes and import data from the CGSN file
1155 //================================================================================
1157 SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromCGNS( const char* theFileName,
1158 SMESH::DriverMED_ReadStatus& theStatus)
1159 throw ( SALOME::SALOME_Exception )
1161 Unexpect aCatch(SALOME_SalomeException);
1163 SMESH::mesh_array_var aResult = new SMESH::mesh_array();
1166 // Retrieve nb meshes from the file
1167 DriverCGNS_Read myReader;
1168 myReader.SetFile( theFileName );
1169 Driver_Mesh::Status aStatus;
1170 int nbMeshes = myReader.GetNbMeshes(aStatus);
1171 theStatus = (SMESH::DriverMED_ReadStatus)aStatus;
1173 aResult->length( nbMeshes );
1175 { // open a new scope to make aPythonDump die before PythonDump in SMESH_Mesh::GetGroups()
1178 TPythonDump aPythonDump;
1179 aPythonDump << "([";
1181 if (theStatus == SMESH::DRS_OK)
1183 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1184 aStudyBuilder->NewCommand(); // There is a transaction
1188 // Iterate through all meshes and create mesh objects
1189 for ( ; i < nbMeshes; ++i )
1192 if (i > 0) aPythonDump << ", ";
1195 SMESH::SMESH_Mesh_var mesh = createMesh();
1196 aResult[i] = SMESH::SMESH_Mesh::_duplicate( mesh );
1198 // Read mesh data (groups are published automatically by ImportMEDFile())
1199 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
1200 ASSERT( meshServant );
1202 SMESH::DriverMED_ReadStatus status1 =
1203 meshServant->ImportCGNSFile( theFileName, i, meshName );
1204 if (status1 > theStatus)
1205 theStatus = status1;
1207 meshServant->GetImpl().GetMeshDS()->Modified();
1208 // publish mesh in the study
1209 SALOMEDS::SObject_wrap aSO;
1210 if ( CanPublishInStudy( mesh ) )
1211 aSO = PublishMesh( myCurrentStudy, mesh.in(), meshName.c_str() );
1214 if ( !aSO->_is_nil() ) {
1218 aPythonDump << "mesh_" << i;
1221 aStudyBuilder->CommitCommand();
1224 aPythonDump << "], status) = " << this << ".CreateMeshesFromCGNS(r'" << theFileName << "')";
1226 // Dump creation of groups
1227 for ( int i = 0; i < aResult->length(); ++i )
1228 SMESH::ListOfGroups_var groups = aResult[ i ]->GetGroups();
1230 THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
1233 return aResult._retn();
1236 //================================================================================
1238 * \brief Create a mesh and import data from a GMF file
1240 //================================================================================
1242 SMESH::SMESH_Mesh_ptr
1243 SMESH_Gen_i::CreateMeshesFromGMF( const char* theFileName,
1244 CORBA::Boolean theMakeRequiredGroups,
1245 SMESH::ComputeError_out theError)
1246 throw ( SALOME::SALOME_Exception )
1248 Unexpect aCatch(SALOME_SalomeException);
1250 SMESH::SMESH_Mesh_var aMesh = createMesh();
1252 char bname[ _MAX_FNAME ];
1253 _splitpath( theFileName, NULL, NULL, bname, NULL );
1254 string aFileName = bname;
1256 string aFileName = basename( theFileName );
1258 // publish mesh in the study
1259 if ( CanPublishInStudy( aMesh ) ) {
1260 SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
1261 aStudyBuilder->NewCommand(); // There is a transaction
1262 SALOMEDS::SObject_wrap aSO = PublishInStudy
1263 ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
1264 aStudyBuilder->CommitCommand();
1265 if ( !aSO->_is_nil() ) {
1266 // Update Python script
1267 TPythonDump() << "("<< aSO << ", error) = " << this << ".CreateMeshesFromGMF(r'"
1268 << theFileName << "', "
1269 << theMakeRequiredGroups << " )";
1272 SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
1274 theError = aServant->ImportGMFFile( theFileName, theMakeRequiredGroups );
1275 aServant->GetImpl().GetMeshDS()->Modified();
1276 return aMesh._retn();
1280 //=============================================================================
1282 * SMESH_Gen_i::IsReadyToCompute
1284 * Returns true if mesh contains enough data to be computed
1286 //=============================================================================
1288 CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh,
1289 GEOM::GEOM_Object_ptr theShapeObject )
1290 throw ( SALOME::SALOME_Exception )
1292 Unexpect aCatch(SALOME_SalomeException);
1293 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" );
1295 if ( CORBA::is_nil( theShapeObject ) )
1296 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1297 SALOME::BAD_PARAM );
1299 if ( CORBA::is_nil( theMesh ) )
1300 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1301 SALOME::BAD_PARAM );
1305 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1306 ASSERT( meshServant );
1307 if ( meshServant ) {
1308 // get local TopoDS_Shape
1309 TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject );
1310 // call implementation
1311 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1312 return myGen.CheckAlgoState( myLocMesh, myLocShape );
1315 catch ( SALOME_Exception& S_ex ) {
1316 INFOS( "catch exception "<< S_ex.what() );
1321 //================================================================================
1323 * \brief Find SObject for an algo
1325 //================================================================================
1327 SALOMEDS::SObject_ptr SMESH_Gen_i::GetAlgoSO(const ::SMESH_Algo* algo)
1330 if ( !myCurrentStudy->_is_nil() ) {
1331 // find algo in the study
1332 CORBA::String_var compDataType = ComponentDataType();
1333 SALOMEDS::SComponent_wrap father = myCurrentStudy->FindComponent( compDataType.in() );
1334 if ( !father->_is_nil() ) {
1335 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( father );
1336 for ( ; itBig->More(); itBig->Next() ) {
1337 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
1338 if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
1339 SALOMEDS::ChildIterator_wrap algoIt = myCurrentStudy->NewChildIterator( gotBranch );
1340 for ( ; algoIt->More(); algoIt->Next() ) {
1341 SALOMEDS::SObject_wrap algoSO = algoIt->Value();
1342 CORBA::Object_var algoIOR = SObjectToObject( algoSO );
1343 if ( !CORBA::is_nil( algoIOR )) {
1344 SMESH_Hypothesis_i* impl = SMESH::DownCast<SMESH_Hypothesis_i*>( algoIOR );
1345 if ( impl && impl->GetImpl() == algo )
1346 return algoSO._retn();
1348 } // loop on algo SO's
1351 } // SMESH component iterator
1355 return SALOMEDS::SObject::_nil();
1358 //================================================================================
1360 * \brief Return errors of mesh computation
1362 //================================================================================
1364 SMESH::compute_error_array* SMESH_Gen_i::GetComputeErrors( SMESH::SMESH_Mesh_ptr theMesh,
1365 GEOM::GEOM_Object_ptr theSubObject )
1366 throw ( SALOME::SALOME_Exception )
1368 Unexpect aCatch(SALOME_SalomeException);
1369 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetComputeErrors()" );
1371 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1372 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1374 if ( CORBA::is_nil( theMesh ) )
1375 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1377 SMESH::compute_error_array_var error_array = new SMESH::compute_error_array;
1379 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1382 if(theMesh->HasShapeToMesh())
1383 shape = GeomObjectToShape( theSubObject );
1385 shape = SMESH_Mesh::PseudoShape();
1387 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1389 error_array->length( mesh.GetMeshDS()->MaxShapeIndex() );
1392 SMESH_subMesh *sm = mesh.GetSubMesh(shape);
1393 const bool includeSelf = true, complexShapeFirst = true;
1394 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(includeSelf,
1396 while ( smIt->more() )
1399 // if ( sm->GetSubShape().ShapeType() == TopAbs_VERTEX )
1401 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1402 if ( error && !error->IsOK() && error->myAlgo )
1404 SMESH::ComputeError & errStruct = error_array[ nbErr++ ];
1405 errStruct.code = -( error->myName < 0 ? error->myName + 1: error->myName ); // -1 -> 0
1406 errStruct.comment = error->myComment.c_str();
1407 errStruct.subShapeID = sm->GetId();
1408 SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->myAlgo );
1409 if ( !algoSO->_is_nil() ) {
1410 CORBA::String_var algoName = algoSO->GetName();
1411 errStruct.algoName = algoName;
1414 errStruct.algoName = error->myAlgo->GetName();
1416 errStruct.hasBadMesh = !error->myBadElements.empty();
1419 error_array->length( nbErr );
1422 catch ( SALOME_Exception& S_ex ) {
1423 INFOS( "catch exception "<< S_ex.what() );
1426 return error_array._retn();
1429 //================================================================================
1431 * \brief Return mesh elements preventing computation of a subshape
1433 //================================================================================
1435 SMESH::MeshPreviewStruct*
1436 SMESH_Gen_i::GetBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1437 CORBA::Short theSubShapeID )
1438 throw ( SALOME::SALOME_Exception )
1440 Unexpect aCatch(SALOME_SalomeException);
1441 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetBadInputElements()" );
1443 if ( CORBA::is_nil( theMesh ) )
1444 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1446 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1449 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1451 // mesh implementation
1452 ::SMESH_Mesh& mesh = meshServant->GetImpl();
1453 // submesh by subshape id
1454 if ( SMESH_subMesh * sm = mesh.GetSubMeshContaining( theSubShapeID ))
1457 SMESH_ComputeErrorPtr error = sm->GetComputeError();
1458 if ( error && !error->myBadElements.empty())
1460 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1461 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1463 // get nodes of elements and count elements
1464 TNode2LocalIDMap mapNode2LocalID;
1465 list< TNodeLocalID > connectivity;
1466 int i, nbElements = 0, nbConnNodes = 0;
1468 list<const SMDS_MeshElement*>::iterator elemIt = error->myBadElements.begin();
1469 list<const SMDS_MeshElement*>::iterator elemEnd = error->myBadElements.end();
1470 for ( ; elemIt != elemEnd; ++elemIt, ++nbElements )
1472 SMDS_ElemIteratorPtr nIt = (*elemIt)->nodesIterator();
1473 while ( nIt->more() )
1474 connectivity.push_back
1475 ( mapNode2LocalID.insert( make_pair( nIt->next(), ++nbConnNodes)).first );
1477 // fill node coords and assign local ids to the nodes
1478 int nbNodes = mapNode2LocalID.size();
1479 result->nodesXYZ.length( nbNodes );
1480 TNodeLocalID node2ID = mapNode2LocalID.begin();
1481 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1482 node2ID->second = i;
1483 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1484 result->nodesXYZ[i].x = node->X();
1485 result->nodesXYZ[i].y = node->Y();
1486 result->nodesXYZ[i].z = node->Z();
1488 // fill connectivity
1489 result->elementConnectivities.length( nbConnNodes );
1490 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1491 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1492 result->elementConnectivities[i] = (*connIt)->second;
1494 // fill element types
1495 result->elementTypes.length( nbElements );
1496 for ( i = 0, elemIt = error->myBadElements.begin(); i <nbElements; ++i, ++elemIt )
1498 const SMDS_MeshElement* elem = *elemIt;
1499 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) elem->GetType();
1500 result->elementTypes[i].isPoly = elem->IsPoly();
1501 result->elementTypes[i].nbNodesInElement = elem->NbNodes();
1507 catch ( SALOME_Exception& S_ex ) {
1508 INFOS( "catch exception "<< S_ex.what() );
1511 return result._retn();
1514 //================================================================================
1516 * \brief Create a group of elements preventing computation of a sub-shape
1518 //================================================================================
1520 SMESH::ListOfGroups*
1521 SMESH_Gen_i::MakeGroupsOfBadInputElements( SMESH::SMESH_Mesh_ptr theMesh,
1522 CORBA::Short theSubShapeID,
1523 const char* theGroupName )
1524 throw ( SALOME::SALOME_Exception )
1526 Unexpect aCatch(SALOME_SalomeException);
1528 SMESH::ListOfGroups_var groups;
1530 if ( CORBA::is_nil( theMesh ) )
1531 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1534 if ( SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh ))
1536 groups = meshServant->MakeGroupsOfBadInputElements( theSubShapeID, theGroupName );
1537 TPythonDump() << groups << " = " << this
1538 << ".MakeGroupsOfBadInputElements( "
1539 << theMesh << ", " << theSubShapeID << ", '" << theGroupName << "' )";
1542 catch ( SALOME_Exception& S_ex ) {
1543 INFOS( "catch exception "<< S_ex.what() );
1545 return groups._retn();
1548 //================================================================================
1550 * \brief Returns errors of hypotheses definintion
1551 * \param theMesh - the mesh
1552 * \param theSubObject - the main or sub- shape
1553 * \retval SMESH::algo_error_array* - sequence of errors
1555 //================================================================================
1557 SMESH::algo_error_array* SMESH_Gen_i::GetAlgoState( SMESH::SMESH_Mesh_ptr theMesh,
1558 GEOM::GEOM_Object_ptr theSubObject )
1559 throw ( SALOME::SALOME_Exception )
1561 Unexpect aCatch(SALOME_SalomeException);
1562 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetAlgoState()" );
1564 if ( CORBA::is_nil( theSubObject ) && theMesh->HasShapeToMesh())
1565 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM );
1567 if ( CORBA::is_nil( theMesh ) )
1568 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",SALOME::BAD_PARAM );
1570 SMESH::algo_error_array_var error_array = new SMESH::algo_error_array;
1572 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
1573 ASSERT( meshServant );
1574 if ( meshServant ) {
1575 TopoDS_Shape myLocShape;
1576 if(theMesh->HasShapeToMesh())
1577 myLocShape = GeomObjectToShape( theSubObject );
1579 myLocShape = SMESH_Mesh::PseudoShape();
1581 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1582 list< ::SMESH_Gen::TAlgoStateError > error_list;
1583 list< ::SMESH_Gen::TAlgoStateError >::iterator error;
1584 // call ::SMESH_Gen::GetAlgoState()
1585 myGen.GetAlgoState( myLocMesh, myLocShape, error_list );
1586 error_array->length( error_list.size() );
1588 for ( error = error_list.begin(); error != error_list.end(); ++error )
1590 // fill AlgoStateError structure
1591 SMESH::AlgoStateError & errStruct = error_array[ i++ ];
1592 errStruct.state = SMESH_Mesh_i::ConvertHypothesisStatus( error->_name );
1593 errStruct.algoDim = error->_algoDim;
1594 errStruct.isGlobalAlgo = error->_isGlobalAlgo;
1595 errStruct.algoName = "";
1596 SALOMEDS::SObject_wrap algoSO = GetAlgoSO( error->_algo );
1597 if ( !algoSO->_is_nil() ) {
1598 CORBA::String_var algoName = algoSO->GetName();
1599 errStruct.algoName = algoName.in();
1604 catch ( SALOME_Exception& S_ex ) {
1605 INFOS( "catch exception "<< S_ex.what() );
1607 return error_array._retn();
1610 //=============================================================================
1612 * SMESH_Gen_i::GetSubShapesId
1614 * Get sub-shapes unique ID's list
1616 //=============================================================================
1618 SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject,
1619 const SMESH::object_array& theListOfSubShapeObject )
1620 throw ( SALOME::SALOME_Exception )
1622 Unexpect aCatch(SALOME_SalomeException);
1623 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" );
1625 SMESH::long_array_var shapesId = new SMESH::long_array;
1628 if ( CORBA::is_nil( theMainShapeObject ) )
1629 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1630 SALOME::BAD_PARAM );
1634 TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject);
1635 TopTools_IndexedMapOfShape myIndexToShape;
1636 TopExp::MapShapes(myMainShape,myIndexToShape);
1638 for ( int i = 0; i < theListOfSubShapeObject.length(); i++ )
1640 GEOM::GEOM_Object_var aShapeObject
1641 = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]);
1642 if ( CORBA::is_nil( aShapeObject ) )
1643 THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \
1644 SALOME::BAD_PARAM );
1646 TopoDS_Shape locShape = GeomObjectToShape(aShapeObject);
1647 for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next())
1649 const TopoDS_Face& F = TopoDS::Face(exp.Current());
1650 setId.insert(myIndexToShape.FindIndex(F));
1651 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F));
1653 for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next())
1655 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1656 setId.insert(myIndexToShape.FindIndex(E));
1657 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E));
1659 for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next())
1661 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
1662 setId.insert(myIndexToShape.FindIndex(V));
1663 if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V));
1666 shapesId->length(setId.size());
1667 set<int>::iterator iind;
1669 for (iind = setId.begin(); iind != setId.end(); iind++)
1671 if(MYDEBUG) SCRUTE((*iind));
1672 shapesId[i] = (*iind);
1673 if(MYDEBUG) SCRUTE(shapesId[i]);
1677 catch (SALOME_Exception& S_ex)
1679 THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
1682 return shapesId._retn();
1685 //=============================================================================
1687 * SMESH_Gen_i::Compute
1689 * Compute mesh on a shape
1691 //=============================================================================
1693 CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
1694 GEOM::GEOM_Object_ptr theShapeObject )
1695 throw ( SALOME::SALOME_Exception )
1698 Unexpect aCatch(SALOME_SalomeException);
1699 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" );
1701 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1702 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1703 SALOME::BAD_PARAM );
1705 if ( CORBA::is_nil( theMesh ) )
1706 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1707 SALOME::BAD_PARAM );
1709 // Update Python script
1710 TPythonDump() << "isDone = " << this << ".Compute( "
1711 << theMesh << ", " << theShapeObject << ")";
1715 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1716 meshServant->Load();
1717 ASSERT( meshServant );
1718 if ( meshServant ) {
1719 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1720 meshServant->CheckGeomGroupModif();
1721 // get local TopoDS_Shape
1722 TopoDS_Shape myLocShape;
1723 if(theMesh->HasShapeToMesh())
1724 myLocShape = GeomObjectToShape( theShapeObject );
1726 myLocShape = SMESH_Mesh::PseudoShape();
1727 // call implementation compute
1728 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1729 #ifdef WITH_SMESH_CANCEL_COMPUTE
1730 myGen.PrepareCompute( myLocMesh, myLocShape);
1732 bool ok = myGen.Compute( myLocMesh, myLocShape);
1733 meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
1734 myLocMesh.GetMeshDS()->Modified();
1738 catch ( std::bad_alloc ) {
1739 INFOS( "Compute(): lack of memory" );
1741 catch ( SALOME_Exception& S_ex ) {
1742 INFOS( "Compute(): catch exception "<< S_ex.what() );
1745 INFOS( "Compute(): unknown exception " );
1750 //=============================================================================
1752 * SMESH_Gen_i::CancelCompute
1754 * Cancel Compute mesh on a shape
1756 //=============================================================================
1758 void SMESH_Gen_i::CancelCompute( SMESH::SMESH_Mesh_ptr theMesh,
1759 GEOM::GEOM_Object_ptr theShapeObject )
1761 #ifdef WITH_SMESH_CANCEL_COMPUTE
1762 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1763 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1764 TopoDS_Shape myLocShape;
1765 if(theMesh->HasShapeToMesh())
1766 myLocShape = GeomObjectToShape( theShapeObject );
1768 myLocShape = SMESH_Mesh::PseudoShape();
1769 myGen.CancelCompute( myLocMesh, myLocShape);
1773 //=============================================================================
1775 * SMESH_Gen_i::Precompute
1777 * Compute mesh as preview till indicated dimension on shape
1779 //=============================================================================
1781 SMESH::MeshPreviewStruct* SMESH_Gen_i::Precompute( SMESH::SMESH_Mesh_ptr theMesh,
1782 GEOM::GEOM_Object_ptr theShapeObject,
1783 SMESH::Dimension theDimension,
1784 SMESH::long_array& theShapesId)
1785 throw ( SALOME::SALOME_Exception )
1787 Unexpect aCatch(SALOME_SalomeException);
1788 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Precompute" );
1790 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1791 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1792 SALOME::BAD_PARAM );
1794 if ( CORBA::is_nil( theMesh ) )
1795 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1796 SALOME::BAD_PARAM );
1798 SMESH::MeshPreviewStruct_var result = new SMESH::MeshPreviewStruct;
1801 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1802 meshServant->Load();
1803 ASSERT( meshServant );
1804 if ( meshServant ) {
1805 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
1806 meshServant->CheckGeomGroupModif();
1807 // get local TopoDS_Shape
1808 TopoDS_Shape myLocShape;
1809 if(theMesh->HasShapeToMesh())
1810 myLocShape = GeomObjectToShape( theShapeObject );
1812 return result._retn();;
1814 // call implementation compute
1815 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
1817 ::MeshDimension aDim = (MeshDimension)theDimension;
1818 if ( myGen.Compute( myLocMesh, myLocShape, false, false, aDim, &shapeIds ) )
1820 int nbShapeId = shapeIds.size();
1821 theShapesId.length( nbShapeId );
1822 // iterates on shapes and collect mesh entities into mesh preview
1823 TSetOfInt::const_iterator idIt = shapeIds.begin();
1824 TSetOfInt::const_iterator idEnd = shapeIds.end();
1825 std::map< int, int > mapOfShIdNb;
1826 std::set< SMESH_TLink > setOfEdge;
1827 std::list< SMDSAbs_ElementType > listOfElemType;
1828 typedef map<const SMDS_MeshElement*, int > TNode2LocalIDMap;
1829 typedef TNode2LocalIDMap::iterator TNodeLocalID;
1830 TNode2LocalIDMap mapNode2LocalID;
1831 list< TNodeLocalID > connectivity;
1832 int i, nbConnNodes = 0;
1833 std::set< const SMESH_subMesh* > setOfVSubMesh;
1834 // iterates on shapes
1835 for ( ; idIt != idEnd; idIt++ )
1837 if ( mapOfShIdNb.find( *idIt ) != mapOfShIdNb.end() )
1839 SMESH_subMesh* sm = myLocMesh.GetSubMeshContaining(*idIt);
1840 if ( !sm || !sm->IsMeshComputed() )
1843 const TopoDS_Shape& aSh = sm->GetSubShape();
1844 const int shDim = myGen.GetShapeDim( aSh );
1845 if ( shDim < 1 || shDim > theDimension )
1848 mapOfShIdNb[ *idIt ] = 0;
1849 theShapesId[ mapOfShIdNb.size() - 1 ] = *idIt;
1851 SMESHDS_SubMesh* smDS = sm->GetSubMeshDS();
1852 if ( !smDS ) continue;
1854 if ( theDimension == SMESH::DIM_2D )
1856 SMDS_ElemIteratorPtr faceIt = smDS->GetElements();
1857 while ( faceIt->more() )
1859 const SMDS_MeshElement* face = faceIt->next();
1860 int aNbNode = face->NbNodes();
1862 aNbNode /= 2; // do not take into account additional middle nodes
1864 SMDS_MeshNode* node1 = (SMDS_MeshNode*)face->GetNode( 0 );
1865 for ( int nIndx = 0; nIndx < aNbNode; nIndx++ )
1867 SMDS_MeshNode* node2 = (SMDS_MeshNode*)face->GetNode( nIndx+1 < aNbNode ? nIndx+1 : 0 );
1868 if ( setOfEdge.insert( SMESH_TLink ( node1, node2 ) ).second )
1870 listOfElemType.push_back( SMDSAbs_Edge );
1871 connectivity.push_back
1872 ( mapNode2LocalID.insert( make_pair( node1, ++nbConnNodes)).first );
1873 connectivity.push_back
1874 ( mapNode2LocalID.insert( make_pair( node2, ++nbConnNodes)).first );
1880 else if ( theDimension == SMESH::DIM_1D )
1882 SMDS_NodeIteratorPtr nodeIt = smDS->GetNodes();
1883 while ( nodeIt->more() )
1885 listOfElemType.push_back( SMDSAbs_Node );
1886 connectivity.push_back
1887 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1889 // add corner nodes by first vertex from edge
1890 SMESH_subMeshIteratorPtr edgeSmIt =
1891 sm->getDependsOnIterator(/*includeSelf*/false,
1892 /*complexShapeFirst*/false);
1893 while ( edgeSmIt->more() )
1895 SMESH_subMesh* vertexSM = edgeSmIt->next();
1896 // check that vertex is not already treated
1897 if ( !setOfVSubMesh.insert( vertexSM ).second )
1899 if ( vertexSM->GetSubShape().ShapeType() != TopAbs_VERTEX )
1902 const SMESHDS_SubMesh* vertexSmDS = vertexSM->GetSubMeshDS();
1903 SMDS_NodeIteratorPtr nodeIt = vertexSmDS->GetNodes();
1904 while ( nodeIt->more() )
1906 listOfElemType.push_back( SMDSAbs_Node );
1907 connectivity.push_back
1908 ( mapNode2LocalID.insert( make_pair( nodeIt->next(), ++nbConnNodes)).first );
1914 // fill node coords and assign local ids to the nodes
1915 int nbNodes = mapNode2LocalID.size();
1916 result->nodesXYZ.length( nbNodes );
1917 TNodeLocalID node2ID = mapNode2LocalID.begin();
1918 for ( i = 0; i < nbNodes; ++i, ++node2ID ) {
1919 node2ID->second = i;
1920 const SMDS_MeshNode* node = (const SMDS_MeshNode*) node2ID->first;
1921 result->nodesXYZ[i].x = node->X();
1922 result->nodesXYZ[i].y = node->Y();
1923 result->nodesXYZ[i].z = node->Z();
1925 // fill connectivity
1926 result->elementConnectivities.length( nbConnNodes );
1927 list< TNodeLocalID >::iterator connIt = connectivity.begin();
1928 for ( i = 0; i < nbConnNodes; ++i, ++connIt ) {
1929 result->elementConnectivities[i] = (*connIt)->second;
1932 // fill element types
1933 result->elementTypes.length( listOfElemType.size() );
1934 std::list< SMDSAbs_ElementType >::const_iterator typeIt = listOfElemType.begin();
1935 std::list< SMDSAbs_ElementType >::const_iterator typeEnd = listOfElemType.end();
1936 for ( i = 0; typeIt != typeEnd; ++i, ++typeIt )
1938 SMDSAbs_ElementType elemType = *typeIt;
1939 result->elementTypes[i].SMDS_ElementType = (SMESH::ElementType)elemType;
1940 result->elementTypes[i].isPoly = false;
1941 result->elementTypes[i].nbNodesInElement = elemType == SMDSAbs_Edge ? 2 : 1;
1944 // correct number of shapes
1945 theShapesId.length( mapOfShIdNb.size() );
1949 catch ( std::bad_alloc ) {
1950 INFOS( "Precompute(): lack of memory" );
1952 catch ( SALOME_Exception& S_ex ) {
1953 INFOS( "Precompute(): catch exception "<< S_ex.what() );
1956 INFOS( "Precompute(): unknown exception " );
1958 return result._retn();
1962 //=============================================================================
1964 * SMESH_Gen_i::Evaluate
1966 * Evaluate mesh on a shape
1968 //=============================================================================
1970 SMESH::long_array* SMESH_Gen_i::Evaluate(SMESH::SMESH_Mesh_ptr theMesh,
1971 GEOM::GEOM_Object_ptr theShapeObject)
1972 // SMESH::long_array& theNbElems)
1973 throw ( SALOME::SALOME_Exception )
1975 Unexpect aCatch(SALOME_SalomeException);
1976 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Evaluate" );
1978 if ( CORBA::is_nil( theShapeObject ) && theMesh->HasShapeToMesh())
1979 THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference",
1980 SALOME::BAD_PARAM );
1982 if ( CORBA::is_nil( theMesh ) )
1983 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference",
1984 SALOME::BAD_PARAM );
1986 SMESH::long_array_var nbels = new SMESH::long_array;
1987 nbels->length(SMESH::Entity_Last);
1988 int i = SMESH::Entity_Node;
1989 for (; i < SMESH::Entity_Last; i++)
1992 // Update Python script
1993 TPythonDump() << "theNbElems = " << this << ".Evaluate( "
1994 << theMesh << ", " << theShapeObject << ")";
1998 SMESH_Mesh_i* meshServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( theMesh ).in() );
1999 ASSERT( meshServant );
2000 if ( meshServant ) {
2001 // NPAL16168: "geometrical group edition from a submesh don't modifiy mesh computation"
2002 meshServant->CheckGeomGroupModif();
2003 // get local TopoDS_Shape
2004 TopoDS_Shape myLocShape;
2005 if(theMesh->HasShapeToMesh())
2006 myLocShape = GeomObjectToShape( theShapeObject );
2008 myLocShape = SMESH_Mesh::PseudoShape();
2009 // call implementation compute
2010 ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
2011 MapShapeNbElems aResMap;
2012 /*CORBA::Boolean ret =*/ myGen.Evaluate( myLocMesh, myLocShape, aResMap);
2013 MapShapeNbElemsItr anIt = aResMap.begin();
2014 for(; anIt!=aResMap.end(); anIt++) {
2015 const vector<int>& aVec = (*anIt).second;
2016 for(i = SMESH::Entity_Node; i < aVec.size(); i++) {
2017 int nbElem = aVec[i];
2018 if ( nbElem < 0 ) // algo failed, check that it has reported a message
2020 SMESH_subMesh* sm = anIt->first;
2021 SMESH_ComputeErrorPtr& error = sm->GetComputeError();
2022 const SMESH_Algo* algo = myGen.GetAlgo( myLocMesh, sm->GetSubShape());
2023 if ( (algo && !error.get()) || error->IsOK() )
2024 error.reset( new SMESH_ComputeError( COMPERR_ALGO_FAILED,"Failed to evaluate",algo));
2028 nbels[i] += aVec[i];
2032 return nbels._retn();
2035 catch ( std::bad_alloc ) {
2036 INFOS( "Evaluate(): lack of memory" );
2038 catch ( SALOME_Exception& S_ex ) {
2039 INFOS( "Evaluate(): catch exception "<< S_ex.what() );
2042 INFOS( "Evaluate(): unknown exception " );
2045 return nbels._retn();
2048 //================================================================================
2050 * \brief Return geometrical object the given element is built on
2051 * \param theMesh - the mesh the element is in
2052 * \param theElementID - the element ID
2053 * \param theGeomName - the name of the result geom object if it is not yet published
2054 * \retval GEOM::GEOM_Object_ptr - the found or just published geom object (no need to UnRegister())
2056 //================================================================================
2058 GEOM::GEOM_Object_ptr
2059 SMESH_Gen_i::GetGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2060 CORBA::Long theElementID,
2061 const char* theGeomName)
2062 throw ( SALOME::SALOME_Exception )
2064 Unexpect aCatch(SALOME_SalomeException);
2066 GEOM::GEOM_Object_wrap geom = FindGeometryByMeshElement(theMesh, theElementID);
2067 if ( !geom->_is_nil() ) {
2068 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2069 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2071 // try to find the corresponding SObject
2072 SALOMEDS::SObject_wrap SObj = ObjectToSObject( myCurrentStudy, geom.in() );
2073 if ( SObj->_is_nil() ) // submesh can be not found even if published
2075 // try to find published submesh
2076 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
2077 if ( !geom->IsMainShape() && list->length() == 1 ) {
2078 SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2079 SALOMEDS::ChildIterator_wrap it;
2080 if ( !mainSO->_is_nil() ) {
2081 it = myCurrentStudy->NewChildIterator( mainSO );
2083 if ( !it->_is_nil() ) {
2084 for ( it->InitEx(true); it->More(); it->Next() ) {
2085 SALOMEDS::SObject_wrap so = it->Value();
2086 CORBA::Object_var obj = SObjectToObject( so );
2087 GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
2088 if ( !subGeom->_is_nil() ) {
2089 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2090 if ( subList->length() == 1 && list[0] == subList[0] ) {
2100 if ( SObj->_is_nil() ) // publish a new subshape
2101 SObj = geomGen->AddInStudy( myCurrentStudy, geom, theGeomName, mainShape );
2103 // return only published geometry
2104 if ( !SObj->_is_nil() ) {
2105 //return geom._retn(); -- servant of geom must be UnRegister()ed;
2106 CORBA::Object_var obj = SObjectToObject( SObj );
2107 GEOM::GEOM_Object_var go = GEOM::GEOM_Object::_narrow( obj );
2111 return GEOM::GEOM_Object::_nil();
2114 //================================================================================
2116 * \brief Return geometrical object the given element is built on.
2117 * \param theMesh - the mesh the element is in
2118 * \param theElementID - the element ID
2119 * \retval GEOM::GEOM_Object_ptr - the found or created (UnRegister()!) geom object
2121 //================================================================================
2123 GEOM::GEOM_Object_ptr
2124 SMESH_Gen_i::FindGeometryByMeshElement( SMESH::SMESH_Mesh_ptr theMesh,
2125 CORBA::Long theElementID)
2126 throw ( SALOME::SALOME_Exception )
2128 Unexpect aCatch(SALOME_SalomeException);
2129 if ( CORBA::is_nil( theMesh ) )
2130 THROW_SALOME_CORBA_EXCEPTION( "bad Mesh reference", SALOME::BAD_PARAM );
2132 GEOM::GEOM_Object_var mainShape = theMesh->GetShapeToMesh();
2133 GEOM::GEOM_Gen_ptr geomGen = GetGeomEngine();
2135 // get a core mesh DS
2136 SMESH_Mesh_i* meshServant = SMESH::DownCast<SMESH_Mesh_i*>( theMesh );
2137 if ( meshServant && !geomGen->_is_nil() && !mainShape->_is_nil() )
2139 ::SMESH_Mesh & mesh = meshServant->GetImpl();
2140 SMESHDS_Mesh* meshDS = mesh.GetMeshDS();
2141 // find the element in mesh
2142 if ( const SMDS_MeshElement * elem = meshDS->FindElement( theElementID ) ) {
2143 // find a shape id by the element
2144 if ( int shapeID = ::SMESH_MeshEditor( &mesh ).FindShape( elem )) {
2145 // get a geom object by the shape id
2146 GEOM::GEOM_Object_var geom = ShapeToGeomObject( meshDS->IndexToShape( shapeID ));
2147 if ( geom->_is_nil() ) {
2148 // try to find a published sub-shape
2149 SALOMEDS::SObject_wrap mainSO = ObjectToSObject( myCurrentStudy, mainShape );
2150 SALOMEDS::ChildIterator_wrap it;
2151 if ( !mainSO->_is_nil() ) {
2152 it = myCurrentStudy->NewChildIterator( mainSO );
2154 if ( !it->_is_nil() ) {
2155 for ( it->InitEx(true); it->More(); it->Next() ) {
2156 SALOMEDS::SObject_wrap so = it->Value();
2157 CORBA::Object_var obj = SObjectToObject( so );
2158 GEOM::GEOM_Object_var subGeom = GEOM::GEOM_Object::_narrow( obj );
2159 if ( !subGeom->_is_nil() ) {
2160 GEOM::ListOfLong_var subList = subGeom->GetSubShapeIndices();
2161 if ( subList->length() == 1 && shapeID == subList[0] ) {
2169 if ( geom->_is_nil() ) {
2171 GEOM::GEOM_IShapesOperations_wrap op =
2172 geomGen->GetIShapesOperations( GetCurrentStudyID() );
2173 if ( !op->_is_nil() )
2174 geom = op->GetSubShape( mainShape, shapeID );
2179 if ( !geom->_is_nil() ) {
2180 GeomObjectToShape( geom ); // let geom client remember the found shape
2181 return geom._retn();
2186 return GEOM::GEOM_Object::_nil();
2189 //================================================================================
2191 * SMESH_Gen_i::Concatenate
2193 * Concatenate the given meshes into one mesh
2195 //================================================================================
2197 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::Concatenate(const SMESH::mesh_array& theMeshesArray,
2198 CORBA::Boolean theUniteIdenticalGroups,
2199 CORBA::Boolean theMergeNodesAndElements,
2200 CORBA::Double theMergeTolerance)
2201 throw ( SALOME::SALOME_Exception )
2203 return ConcatenateCommon(theMeshesArray,
2204 theUniteIdenticalGroups,
2205 theMergeNodesAndElements,
2210 //================================================================================
2212 * SMESH_Gen_i::ConcatenateWithGroups
2214 * Concatenate the given meshes into one mesh
2215 * Create the groups of all elements from initial meshes
2217 //================================================================================
2219 SMESH::SMESH_Mesh_ptr
2220 SMESH_Gen_i::ConcatenateWithGroups(const SMESH::mesh_array& theMeshesArray,
2221 CORBA::Boolean theUniteIdenticalGroups,
2222 CORBA::Boolean theMergeNodesAndElements,
2223 CORBA::Double theMergeTolerance)
2224 throw ( SALOME::SALOME_Exception )
2226 return ConcatenateCommon(theMeshesArray,
2227 theUniteIdenticalGroups,
2228 theMergeNodesAndElements,
2233 //================================================================================
2235 * SMESH_Gen_i::ConcatenateCommon
2237 * Concatenate the given meshes into one mesh
2239 //================================================================================
2241 SMESH::SMESH_Mesh_ptr
2242 SMESH_Gen_i::ConcatenateCommon(const SMESH::mesh_array& theMeshesArray,
2243 CORBA::Boolean theUniteIdenticalGroups,
2244 CORBA::Boolean theMergeNodesAndElements,
2245 CORBA::Double theMergeTolerance,
2246 CORBA::Boolean theCommonGroups)
2247 throw ( SALOME::SALOME_Exception )
2249 typedef map<int, int> TIDsMap;
2250 typedef list<SMESH::SMESH_Group_var> TListOfNewGroups;
2251 typedef map< pair<string, SMESH::ElementType>, TListOfNewGroups > TGroupsMap;
2252 typedef std::set<SMESHDS_GroupBase*> TGroups;
2254 TPythonDump* pPythonDump = new TPythonDump;
2255 TPythonDump& aPythonDump = *pPythonDump; // prevent dump of called methods
2258 SMESH::SMESH_Mesh_var aNewMesh = CreateEmptyMesh();
2260 SMESHDS_Mesh* aNewMeshDS = 0;
2261 if ( !aNewMesh->_is_nil() ) {
2262 SMESH_Mesh_i* aNewImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( aNewMesh ).in() );
2264 ::SMESH_Mesh& aLocMesh = aNewImpl->GetImpl();
2265 aNewMeshDS = aLocMesh.GetMeshDS();
2267 TGroupsMap aGroupsMap;
2268 TListOfNewGroups aListOfNewGroups;
2269 SMESH_MeshEditor aNewEditor = ::SMESH_MeshEditor(&aLocMesh);
2270 SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups();
2273 for ( int i = 0; i < theMeshesArray.length(); i++) {
2274 SMESH::SMESH_Mesh_var anInitMesh = theMeshesArray[i];
2275 if ( !anInitMesh->_is_nil() ) {
2276 SMESH_Mesh_i* anInitImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( anInitMesh ).in() );
2278 ::SMESH_Mesh& aInitLocMesh = anInitImpl->GetImpl();
2279 aInitLocMesh.Load();
2280 SMESHDS_Mesh* anInitMeshDS = aInitLocMesh.GetMeshDS();
2285 // loop on elements of mesh
2286 SMDS_ElemIteratorPtr itElems = anInitMeshDS->elementsIterator();
2287 const SMDS_MeshElement* anElem = 0;
2288 const SMDS_MeshElement* aNewElem = 0;
2289 int anElemNbNodes = 0;
2294 int anNbVolumes = 0;
2297 SMESH::long_array_var anIDsNodes = new SMESH::long_array();
2298 SMESH::long_array_var anIDsEdges = new SMESH::long_array();
2299 SMESH::long_array_var anIDsFaces = new SMESH::long_array();
2300 SMESH::long_array_var anIDsVolumes = new SMESH::long_array();
2301 SMESH::long_array_var anIDsBalls = new SMESH::long_array();
2303 if( theCommonGroups ) {
2304 anIDsNodes->length( anInitMeshDS->NbNodes() );
2305 anIDsEdges->length( anInitMeshDS->NbEdges() );
2306 anIDsFaces->length( anInitMeshDS->NbFaces() );
2307 anIDsVolumes->length( anInitMeshDS->NbVolumes() );
2308 anIDsBalls->length( anInitMeshDS->NbBalls() );
2311 for ( int j = 0; itElems->more(); j++) {
2312 anElem = itElems->next();
2313 SMDSAbs_ElementType anElemType = anElem->GetType();
2314 anElemNbNodes = anElem->NbNodes();
2315 std::vector<const SMDS_MeshNode*> aNodesArray (anElemNbNodes);
2317 // loop on nodes of element
2318 const SMDS_MeshNode* aNode = 0;
2319 const SMDS_MeshNode* aNewNode = 0;
2320 SMDS_ElemIteratorPtr itNodes = anElem->nodesIterator();
2322 for ( int k = 0; itNodes->more(); k++) {
2323 aNode = static_cast<const SMDS_MeshNode*>(itNodes->next());
2324 if ( nodesMap.find(aNode->GetID()) == nodesMap.end() ) {
2325 aNewNode = aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2326 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2327 if( theCommonGroups )
2328 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2331 aNewNode = aNewMeshDS->FindNode( nodesMap.find(aNode->GetID())->second );
2332 aNodesArray[k] = aNewNode;
2335 // creates a corresponding element on existent nodes in new mesh
2336 switch ( anElem->GetEntityType() ) {
2337 case SMDSEntity_Polyhedra:
2338 if ( const SMDS_VtkVolume* aVolume =
2339 dynamic_cast<const SMDS_VtkVolume*> (anElem))
2341 aNewElem = aNewMeshDS->AddPolyhedralVolume(aNodesArray,
2342 aVolume->GetQuantities());
2343 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2344 if( theCommonGroups )
2345 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2348 case SMDSEntity_Ball:
2349 if ( const SMDS_BallElement* aBall =
2350 dynamic_cast<const SMDS_BallElement*> (anElem))
2352 aNewElem = aNewEditor.AddElement(aNodesArray, SMDSAbs_Ball,
2353 /*isPoly=*/false, /*id=*/0,
2354 aBall->GetDiameter() );
2355 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2356 if( theCommonGroups )
2357 anIDsBalls[aNbBalls++] = aNewElem->GetID();
2362 aNewElem = aNewEditor.AddElement(aNodesArray,
2365 elemsMap.insert(make_pair(anElem->GetID(), aNewElem->GetID()));
2366 if( theCommonGroups ) {
2367 if( anElemType == SMDSAbs_Edge )
2368 anIDsEdges[anNbEdges++] = aNewElem->GetID();
2369 else if( anElemType == SMDSAbs_Face )
2370 anIDsFaces[anNbFaces++] = aNewElem->GetID();
2371 else if( anElemType == SMDSAbs_Volume )
2372 anIDsVolumes[anNbVolumes++] = aNewElem->GetID();
2378 // copy orphan nodes
2379 SMDS_NodeIteratorPtr itNodes = anInitMeshDS->nodesIterator();
2380 while ( itNodes->more() )
2382 const SMDS_MeshNode* aNode = itNodes->next();
2383 if ( aNode->NbInverseElements() == 0 )
2385 const SMDS_MeshNode* aNewNode =
2386 aNewMeshDS->AddNode(aNode->X(), aNode->Y(), aNode->Z());
2387 nodesMap.insert( make_pair(aNode->GetID(), aNewNode->GetID()) );
2388 if( theCommonGroups )
2389 anIDsNodes[anNbNodes++] = aNewNode->GetID();
2394 aListOfGroups = anInitImpl->GetGroups();
2395 SMESH::SMESH_GroupBase_ptr aGroup;
2397 // loop on groups of mesh
2398 SMESH::long_array_var anInitIDs = new SMESH::long_array();
2399 SMESH::long_array_var anNewIDs = new SMESH::long_array();
2400 SMESH::SMESH_Group_var aNewGroup;
2402 SMESH::ElementType aGroupType;
2403 CORBA::String_var aGroupName;
2404 if ( theCommonGroups ) {
2405 for(aGroupType=SMESH::NODE;aGroupType<=SMESH::BALL;aGroupType=(SMESH::ElementType)(aGroupType+1)) {
2407 SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, anInitMesh );
2409 str += aMeshSObj->GetName();
2414 switch(aGroupType) {
2417 anIDsNodes->length(anNbNodes);
2422 anIDsEdges->length(anNbEdges);
2427 anIDsFaces->length(anNbFaces);
2432 anIDsVolumes->length(anNbVolumes);
2433 anLen = anNbVolumes;
2437 anIDsBalls->length(aNbBalls);
2445 aGroupName = str.c_str();
2447 // add a new group in the mesh
2448 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2450 switch(aGroupType) {
2452 aNewGroup->Add( anIDsNodes );
2455 aNewGroup->Add( anIDsEdges );
2458 aNewGroup->Add( anIDsFaces );
2461 aNewGroup->Add( anIDsVolumes );
2464 aNewGroup->Add( anIDsBalls );
2470 aListOfNewGroups.clear();
2471 aListOfNewGroups.push_back(aNewGroup);
2472 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2477 // check that current group name and type don't have identical ones in union mesh
2478 for (int iG = 0; iG < aListOfGroups->length(); iG++) {
2479 aGroup = aListOfGroups[iG];
2480 aListOfNewGroups.clear();
2481 aGroupType = aGroup->GetType();
2482 aGroupName = aGroup->GetName();
2484 TGroupsMap::iterator anIter = aGroupsMap.find(make_pair(aGroupName, aGroupType));
2486 // convert a list of IDs
2487 anInitIDs = aGroup->GetListOfID();
2488 anNewIDs->length(anInitIDs->length());
2489 if ( aGroupType == SMESH::NODE )
2490 for (int j = 0; j < anInitIDs->length(); j++) {
2491 anNewIDs[j] = nodesMap.find(anInitIDs[j])->second;
2494 for (int j = 0; j < anInitIDs->length(); j++) {
2495 anNewIDs[j] = elemsMap.find(anInitIDs[j])->second;
2498 // check that current group name and type don't have identical ones in union mesh
2499 if ( anIter == aGroupsMap.end() ) {
2500 // add a new group in the mesh
2501 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2502 // add elements into new group
2503 aNewGroup->Add( anNewIDs );
2505 aListOfNewGroups.push_back(aNewGroup);
2506 aGroupsMap.insert(make_pair( make_pair(aGroupName, aGroupType), aListOfNewGroups ));
2509 else if ( theUniteIdenticalGroups ) {
2510 // unite identical groups
2511 TListOfNewGroups& aNewGroups = anIter->second;
2512 aNewGroups.front()->Add( anNewIDs );
2516 // rename identical groups
2517 aNewGroup = aNewImpl->CreateGroup(aGroupType, aGroupName);
2518 aNewGroup->Add( anNewIDs );
2520 TListOfNewGroups& aNewGroups = anIter->second;
2521 string aNewGroupName;
2522 if (aNewGroups.size() == 1) {
2523 aNewGroupName = string(aGroupName) + "_1";
2524 aNewGroups.front()->SetName(aNewGroupName.c_str());
2526 char aGroupNum[128];
2527 sprintf(aGroupNum, "%u", aNewGroups.size()+1);
2528 aNewGroupName = string(aGroupName) + "_" + string(aGroupNum);
2529 aNewGroup->SetName(aNewGroupName.c_str());
2530 aNewGroups.push_back(aNewGroup);
2537 if (theMergeNodesAndElements) {
2539 TIDSortedNodeSet aMeshNodes; // no input nodes
2540 SMESH_MeshEditor::TListOfListOfNodes aGroupsOfNodes;
2541 aNewEditor.FindCoincidentNodes( aMeshNodes, theMergeTolerance, aGroupsOfNodes );
2542 aNewEditor.MergeNodes( aGroupsOfNodes );
2544 aNewEditor.MergeEqualElements();
2549 // Update Python script
2550 aPythonDump << aNewMesh << " = " << this;
2551 if( !theCommonGroups )
2552 aPythonDump << ".Concatenate(";
2554 aPythonDump << ".ConcatenateWithGroups(";
2556 for ( int i = 0; i < theMeshesArray.length(); i++) {
2557 if (i > 0) aPythonDump << ", ";
2558 aPythonDump << theMeshesArray[i];
2560 aPythonDump << "], ";
2561 aPythonDump << theUniteIdenticalGroups << ", "
2562 << theMergeNodesAndElements << ", "
2563 << TVar( theMergeTolerance ) << ")";
2565 delete pPythonDump; // enable python dump from GetGroups()
2567 // 0020577: EDF 1164 SMESH: Bad dump of concatenate with create common groups
2568 if ( !aNewMesh->_is_nil() )
2570 SMESH::ListOfGroups_var groups = aNewMesh->GetGroups();
2573 // IPAL21468 Change icon of compound because it need not be computed.
2574 SALOMEDS::SObject_wrap aMeshSObj = ObjectToSObject( myCurrentStudy, aNewMesh );
2575 SetPixMap( aMeshSObj, "ICON_SMESH_TREE_MESH" );
2578 aNewMeshDS->Modified();
2579 return aNewMesh._retn();
2582 //================================================================================
2584 * \brief Create a mesh by copying a part of another mesh
2585 * \param meshPart - a part of mesh to copy
2586 * \param toCopyGroups - to create in the new mesh groups
2587 * the copied elements belongs to
2588 * \param toKeepIDs - to preserve IDs of the copied elements or not
2589 * \retval SMESH::SMESH_Mesh_ptr - the new mesh
2591 //================================================================================
2593 SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CopyMesh(SMESH::SMESH_IDSource_ptr meshPart,
2594 const char* meshName,
2595 CORBA::Boolean toCopyGroups,
2596 CORBA::Boolean toKeepIDs)
2598 Unexpect aCatch(SALOME_SalomeException);
2600 TPythonDump* pyDump = new TPythonDump; // prevent dump from CreateMesh()
2602 // 1. Get source mesh
2604 if ( CORBA::is_nil( meshPart ))
2605 THROW_SALOME_CORBA_EXCEPTION( "bad IDSource", SALOME::BAD_PARAM );
2607 SMESH::SMESH_Mesh_var srcMesh = meshPart->GetMesh();
2608 SMESH_Mesh_i* srcMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( srcMesh );
2610 THROW_SALOME_CORBA_EXCEPTION( "bad mesh of IDSource", SALOME::BAD_PARAM );
2612 SMESHDS_Mesh* srcMeshDS = srcMesh_i->GetImpl().GetMeshDS();
2614 // 2. Make a new mesh
2616 SMESH::SMESH_Mesh_var newMesh = CreateMesh(GEOM::GEOM_Object::_nil());
2617 SMESH_Mesh_i* newMesh_i = SMESH::DownCast<SMESH_Mesh_i*>( newMesh );
2619 THROW_SALOME_CORBA_EXCEPTION( "can't create a mesh", SALOME::INTERNAL_ERROR );
2620 SALOMEDS::SObject_wrap meshSO = ObjectToSObject(myCurrentStudy, newMesh );
2621 if ( !meshSO->_is_nil() )
2623 SetName( meshSO, meshName, "Mesh" );
2624 SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
2626 SMESHDS_Mesh* newMeshDS = newMesh_i->GetImpl().GetMeshDS();
2627 ::SMESH_MeshEditor editor( &newMesh_i->GetImpl() );
2629 // 3. Get elements to copy
2631 SMDS_ElemIteratorPtr srcElemIt; SMDS_NodeIteratorPtr srcNodeIt;
2632 TIDSortedElemSet srcElems;
2633 SMESH::array_of_ElementType_var srcElemTypes = meshPart->GetTypes();
2634 if ( SMESH::DownCast<SMESH_Mesh_i*>( meshPart ))
2636 srcElemIt = srcMeshDS->elementsIterator();
2637 srcNodeIt = srcMeshDS->nodesIterator();
2641 SMESH::long_array_var ids = meshPart->GetIDs();
2642 if ( srcElemTypes->length() == 1 && srcElemTypes[0] == SMESH::NODE ) // group of nodes
2644 for (int i=0; i < ids->length(); i++)
2645 if ( const SMDS_MeshElement * elem = srcMeshDS->FindNode( ids[i] ))
2646 srcElems.insert( elem );
2650 for (int i=0; i < ids->length(); i++)
2651 if ( const SMDS_MeshElement * elem = srcMeshDS->FindElement( ids[i] ))
2652 srcElems.insert( elem );
2654 if ( srcElems.empty() )
2655 return newMesh._retn();
2657 typedef SMDS_SetIterator< SMDS_pElement, TIDSortedElemSet::const_iterator > ElIter;
2658 srcElemIt = SMDS_ElemIteratorPtr( new ElIter( srcElems.begin(), srcElems.end() ));
2663 typedef map<SMDS_pElement, SMDS_pElement, TIDCompare> TE2EMap;
2664 TE2EMap e2eMapByType[ SMDSAbs_NbElementTypes ];
2665 TE2EMap& n2nMap = e2eMapByType[ SMDSAbs_Node ];
2667 const SMDS_MeshNode *nSrc, *nTgt;
2668 vector< const SMDS_MeshNode* > nodes;
2669 while ( srcElemIt->more() )
2671 const SMDS_MeshElement * elem = srcElemIt->next();
2673 nodes.resize( elem->NbNodes());
2674 SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2676 for ( iN = 0; nIt->more(); ++iN )
2678 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2679 nTgt = newMeshDS->FindNode( nSrc->GetID());
2681 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2686 for ( iN = 0; nIt->more(); ++iN )
2688 nSrc = static_cast<const SMDS_MeshNode*>( nIt->next() );
2689 TE2EMap::iterator n2n = n2nMap.insert( make_pair( nSrc, SMDS_pNode(0) )).first;
2691 n2n->second = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2692 nodes[ iN ] = (const SMDS_MeshNode*) n2n->second;
2696 if ( elem->GetType() != SMDSAbs_Node )
2698 int ID = toKeepIDs ? elem->GetID() : 0;
2699 const SMDS_MeshElement * newElem;
2700 switch ( elem->GetEntityType() ) {
2701 case SMDSEntity_Polyhedra:
2702 newElem = editor.GetMeshDS()->
2703 AddPolyhedralVolumeWithID( nodes,
2704 static_cast<const SMDS_VtkVolume*>(elem)->GetQuantities(),
2707 case SMDSEntity_Ball:
2708 newElem = editor.AddElement( nodes, SMDSAbs_Ball, false, ID,
2709 static_cast<const SMDS_BallElement*>(elem)->GetDiameter());
2712 newElem = editor.AddElement( nodes,elem->GetType(),elem->IsPoly(),ID);
2714 if ( toCopyGroups && !toKeepIDs )
2715 e2eMapByType[ elem->GetType() ].insert( make_pair( elem, newElem ));
2718 } // while ( srcElemIt->more() )
2720 // 4(b). Copy free nodes
2722 if ( srcNodeIt && srcMeshDS->NbNodes() != newMeshDS->NbNodes() )
2724 while ( srcNodeIt->more() )
2726 nSrc = srcNodeIt->next();
2727 if ( nSrc->NbInverseElements() == 0 )
2730 nTgt = newMeshDS->AddNodeWithID( nSrc->X(), nSrc->Y(), nSrc->Z(), nSrc->GetID());
2732 n2nMap[ nSrc ] = newMeshDS->AddNode( nSrc->X(), nSrc->Y(), nSrc->Z() );
2739 int nbNewGroups = 0;
2742 SMESH_Mesh::GroupIteratorPtr gIt = srcMesh_i->GetImpl().GetGroups();
2743 while ( gIt->more() )
2745 SMESH_Group* group = gIt->next();
2746 const SMESHDS_GroupBase* groupDS = group->GetGroupDS();
2748 // Check group type. We copy nodal groups containing nodes of copied element
2749 SMDSAbs_ElementType groupType = groupDS->GetType();
2750 if ( groupType != SMDSAbs_Node &&
2751 newMeshDS->GetMeshInfo().NbElements( groupType ) == 0 )
2752 continue; // group type differs from types of meshPart
2754 // Find copied elements in the group
2755 vector< const SMDS_MeshElement* > groupElems;
2756 SMDS_ElemIteratorPtr eIt = groupDS->GetElements();
2759 const SMDS_MeshElement* foundElem;
2760 if ( groupType == SMDSAbs_Node )
2762 while ( eIt->more() )
2763 if (( foundElem = newMeshDS->FindNode( eIt->next()->GetID() )))
2764 groupElems.push_back( foundElem );
2768 while ( eIt->more() )
2769 if (( foundElem = newMeshDS->FindElement( eIt->next()->GetID() )))
2770 groupElems.push_back( foundElem );
2775 TE2EMap & e2eMap = e2eMapByType[ groupDS->GetType() ];
2776 if ( e2eMap.empty() ) continue;
2777 int minID = e2eMap.begin()->first->GetID();
2778 int maxID = e2eMap.rbegin()->first->GetID();
2779 TE2EMap::iterator e2e;
2780 while ( eIt->more() && groupElems.size() < e2eMap.size())
2782 const SMDS_MeshElement* e = eIt->next();
2783 if ( e->GetID() < minID || e->GetID() > maxID ) continue;
2784 if ((e2e = e2eMap.find( e )) != e2eMap.end())
2785 groupElems.push_back( e2e->second );
2789 if ( !groupElems.empty() )
2791 SMESH::SMESH_Group_var newGroupObj =
2792 newMesh->CreateGroup( SMESH::ElementType(groupType), group->GetName() );
2793 if ( SMESH_GroupBase_i* newGroup_i = SMESH::DownCast<SMESH_GroupBase_i*>( newGroupObj))
2795 SMESHDS_GroupBase * newGroupDS = newGroup_i->GetGroupDS();
2796 SMDS_MeshGroup& smdsGroup = ((SMESHDS_Group*)newGroupDS)->SMDSGroup();
2797 for ( unsigned i = 0; i < groupElems.size(); ++i )
2798 smdsGroup.Add( groupElems[i] );
2806 newMeshDS->Modified();
2808 *pyDump << newMesh << " = " << this
2809 << ".CopyMesh( " << meshPart << ", "
2810 << "'" << meshName << "', "
2811 << toCopyGroups << ", "
2812 << toKeepIDs << ")";
2814 delete pyDump; pyDump = 0; // allow dump in GetGroups()
2816 if ( nbNewGroups > 0 ) // dump created groups
2817 SMESH::ListOfGroups_var groups = newMesh->GetGroups();
2819 return newMesh._retn();
2822 //================================================================================
2824 * SMESH_Gen_i::GetMEDVersion
2826 * Get MED version of the file by its name
2828 //================================================================================
2829 CORBA::Boolean SMESH_Gen_i::GetMEDVersion(const char* theFileName,
2830 SMESH::MED_VERSION& theVersion)
2832 theVersion = SMESH::MED_V2_1;
2833 MED::EVersion aVersion = MED::GetVersionId( theFileName );
2834 switch( aVersion ) {
2835 case MED::eV2_1 : theVersion = SMESH::MED_V2_1; return true;
2836 case MED::eV2_2 : theVersion = SMESH::MED_V2_2; return true;
2837 case MED::eVUnknown : return false;
2842 //================================================================================
2844 * SMESH_Gen_i::GetMeshNames
2846 * Get names of meshes defined in file with the specified name
2848 //================================================================================
2849 SMESH::string_array* SMESH_Gen_i::GetMeshNames(const char* theFileName)
2851 SMESH::string_array_var aResult = new SMESH::string_array();
2852 MED::PWrapper aMed = MED::CrWrapper( theFileName );
2854 MED::TInt aNbMeshes = aMed->GetNbMeshes( &anErr );
2856 aResult->length( aNbMeshes );
2857 for( MED::TInt i = 0; i < aNbMeshes; i++ ) {
2858 MED::PMeshInfo aMeshInfo = aMed->GetPMeshInfo( i+1 );
2859 aResult[i] = CORBA::string_dup( aMeshInfo->GetName().c_str() );
2862 return aResult._retn();
2865 //=============================================================================
2869 * Save SMESH module's data
2871 //=============================================================================
2872 SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent,
2876 INFOS( "SMESH_Gen_i::Save" );
2878 // ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() )
2879 // san -- in case <myCurrentStudy> differs from theComponent's study,
2880 // use that of the component
2881 if ( myCurrentStudy->_is_nil() ||
2882 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
2883 SetCurrentStudy( theComponent->GetStudy() );
2885 // Store study contents as a set of python commands
2886 SavePython(myCurrentStudy);
2888 StudyContext* myStudyContext = GetCurrentStudyContext();
2890 // Declare a byte stream
2891 SALOMEDS::TMPFile_var aStreamFile;
2893 // Obtain a temporary dir
2894 TCollection_AsciiString tmpDir =
2895 ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str();
2897 // Create a sequence of files processed
2898 SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames;
2899 aFileSeq->length( NUM_TMP_FILES );
2901 TCollection_AsciiString aStudyName( "" );
2903 aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() );
2905 // Set names of temporary files
2906 TCollection_AsciiString filename =
2907 aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); // for SMESH data itself
2908 TCollection_AsciiString meshfile =
2909 aStudyName + TCollection_AsciiString( "_SMESH_Mesh.med" ); // for mesh data to be stored in MED file
2910 aFileSeq[ 0 ] = CORBA::string_dup( filename.ToCString() );
2911 aFileSeq[ 1 ] = CORBA::string_dup( meshfile.ToCString() );
2912 filename = tmpDir + filename;
2913 meshfile = tmpDir + meshfile;
2916 HDFdataset* aDataset;
2917 HDFgroup* aTopGroup;
2919 HDFgroup* aSubGroup;
2920 HDFgroup* aSubSubGroup;
2921 hdf_size aSize[ 1 ];
2924 //Remove the files if they exist: BugID: 11225
2925 #ifndef WNT /* unix functionality */
2926 TCollection_AsciiString cmd("rm -f \"");
2928 TCollection_AsciiString cmd("del /F \"");
2935 system(cmd.ToCString());
2937 // MED writer to be used by storage process
2938 DriverMED_W_SMESHDS_Mesh myWriter;
2939 myWriter.SetFile( meshfile.ToCString() );
2942 // SetStoreName() to groups before storing hypotheses to let them refer to
2943 // groups using "store name", which is "Group <group_persistent_id>"
2945 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
2946 for ( ; itBig->More(); itBig->Next() ) {
2947 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
2948 if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
2949 CORBA::Object_var anObject = SObjectToObject( gotBranch );
2950 if ( !CORBA::is_nil( anObject ) ) {
2951 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
2952 if ( !myMesh->_is_nil() ) {
2953 myMesh->Load(); // load from study file if not yet done
2954 TPythonDump pd; // not to dump GetGroups()
2955 SMESH::ListOfGroups_var groups = myMesh->GetGroups();
2956 pd << ""; // to avoid optimizing pd out
2957 for ( int i = 0; i < groups->length(); ++i )
2959 SMESH_GroupBase_i* grImpl = SMESH::DownCast<SMESH_GroupBase_i*>( groups[i]);
2962 CORBA::String_var objStr = GetORB()->object_to_string( grImpl->_this() );
2963 int anId = myStudyContext->findId( string( objStr.in() ) );
2965 sprintf( grpName, "Group %d", anId );
2966 SMESHDS_GroupBase* aGrpBaseDS = grImpl->GetGroupDS();
2967 aGrpBaseDS->SetStoreName( grpName );
2977 // ---> create HDF file
2978 aFile = new HDFfile( (char*) filename.ToCString() );
2979 aFile->CreateOnDisk();
2981 // --> iterator for top-level objects
2982 SALOMEDS::ChildIterator_wrap itBig = myCurrentStudy->NewChildIterator( theComponent );
2983 for ( ; itBig->More(); itBig->Next() ) {
2984 SALOMEDS::SObject_wrap gotBranch = itBig->Value();
2986 // --> hypotheses root branch (only one for the study)
2987 if ( gotBranch->Tag() == GetHypothesisRootTag() ) {
2988 // create hypotheses root HDF group
2989 aTopGroup = new HDFgroup( "Hypotheses", aFile );
2990 aTopGroup->CreateOnDisk();
2992 // iterator for all hypotheses
2993 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
2994 for ( ; it->More(); it->Next() ) {
2995 SALOMEDS::SObject_wrap mySObject = it->Value();
2996 CORBA::Object_var anObject = SObjectToObject( mySObject );
2997 if ( !CORBA::is_nil( anObject ) ) {
2998 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
2999 if ( !myHyp->_is_nil() ) {
3000 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3002 string hypname = string( myHyp->GetName() );
3003 string libname = string( myHyp->GetLibName() );
3005 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
3006 // WNT and ".so" for X-system) must be deleted
3007 int libname_len = libname.length();
3009 if( libname_len > 4 )
3010 libname.resize( libname_len - 4 );
3012 // PAL17753 (Regresion: missing hypothesis in restored study)
3013 // "lib" also should be removed from the beginning
3014 //if( libname_len > 3 )
3015 //libname.resize( libname_len - 3 );
3016 if( libname_len > 6 )
3017 libname = libname.substr( 3, libname_len - 3 - 3 );
3019 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3020 int id = myStudyContext->findId( string( objStr.in() ) );
3021 string hypdata = string( myImpl->SaveTo() );
3023 // for each hypothesis create HDF group basing on its id
3024 char hypGrpName[30];
3025 sprintf( hypGrpName, "Hypothesis %d", id );
3026 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3027 aGroup->CreateOnDisk();
3028 // --> type name of hypothesis
3029 aSize[ 0 ] = hypname.length() + 1;
3030 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3031 aDataset->CreateOnDisk();
3032 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3033 aDataset->CloseOnDisk();
3034 // --> server plugin library name of hypothesis
3035 aSize[ 0 ] = libname.length() + 1;
3036 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3037 aDataset->CreateOnDisk();
3038 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3039 aDataset->CloseOnDisk();
3040 // --> persistent data of hypothesis
3041 aSize[ 0 ] = hypdata.length() + 1;
3042 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3043 aDataset->CreateOnDisk();
3044 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3045 aDataset->CloseOnDisk();
3046 // close hypothesis HDF group
3047 aGroup->CloseOnDisk();
3052 // close hypotheses root HDF group
3053 aTopGroup->CloseOnDisk();
3055 // --> algorithms root branch (only one for the study)
3056 else if ( gotBranch->Tag() == GetAlgorithmsRootTag() ) {
3057 // create algorithms root HDF group
3058 aTopGroup = new HDFgroup( "Algorithms", aFile );
3059 aTopGroup->CreateOnDisk();
3061 // iterator for all algorithms
3062 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( gotBranch );
3063 for ( ; it->More(); it->Next() ) {
3064 SALOMEDS::SObject_wrap mySObject = it->Value();
3065 CORBA::Object_var anObject = SObjectToObject( mySObject );
3066 if ( !CORBA::is_nil( anObject ) ) {
3067 SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow( anObject );
3068 if ( !myHyp->_is_nil() ) {
3069 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
3071 string hypname = string( myHyp->GetName() );
3072 string libname = string( myHyp->GetLibName() );
3074 // Needs for save crossplatform libname, i.e. parth of name ( ".dll" for
3075 // WNT and ".so" for X-system) must be deleted
3076 int libname_len = libname.length();
3078 if( libname_len > 4 )
3079 libname.resize( libname_len - 4 );
3081 // PAL17753 (Regresion: missing hypothesis in restored study)
3082 // "lib" also should be removed from the beginning
3083 //if( libname_len > 3 )
3084 //libname.resize( libname_len - 3 );
3085 if( libname_len > 6 )
3086 libname = libname.substr( 3, libname_len - 3 - 3 );
3088 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3089 int id = myStudyContext->findId( string( objStr.in() ) );
3090 string hypdata = string( myImpl->SaveTo() );
3092 // for each algorithm create HDF group basing on its id
3093 char hypGrpName[30];
3094 sprintf( hypGrpName, "Algorithm %d", id );
3095 aGroup = new HDFgroup( hypGrpName, aTopGroup );
3096 aGroup->CreateOnDisk();
3097 // --> type name of algorithm
3098 aSize[0] = hypname.length() + 1;
3099 aDataset = new HDFdataset( "Name", aGroup, HDF_STRING, aSize, 1 );
3100 aDataset->CreateOnDisk();
3101 aDataset->WriteOnDisk( ( char* )( hypname.c_str() ) );
3102 aDataset->CloseOnDisk();
3103 // --> server plugin library name of hypothesis
3104 aSize[0] = libname.length() + 1;
3105 aDataset = new HDFdataset( "LibName", aGroup, HDF_STRING, aSize, 1 );
3106 aDataset->CreateOnDisk();
3107 aDataset->WriteOnDisk( ( char* )( libname.c_str() ) );
3108 aDataset->CloseOnDisk();
3109 // --> persistent data of algorithm
3110 aSize[0] = hypdata.length() + 1;
3111 aDataset = new HDFdataset( "Data", aGroup, HDF_STRING, aSize, 1 );
3112 aDataset->CreateOnDisk();
3113 aDataset->WriteOnDisk( ( char* )( hypdata.c_str() ) );
3114 aDataset->CloseOnDisk();
3115 // close algorithm HDF group
3116 aGroup->CloseOnDisk();
3121 // close algorithms root HDF group
3122 aTopGroup->CloseOnDisk();
3124 // --> mesh objects roots branches
3125 else if ( gotBranch->Tag() > GetAlgorithmsRootTag() ) {
3126 CORBA::Object_var anObject = SObjectToObject( gotBranch );
3127 if ( !CORBA::is_nil( anObject ) ) {
3128 SMESH::SMESH_Mesh_var myMesh = SMESH::SMESH_Mesh::_narrow( anObject ) ;
3129 if ( !myMesh->_is_nil() ) {
3130 SMESH_Mesh_i* myImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myMesh ).in() );
3132 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3133 int id = myStudyContext->findId( string( objStr.in() ) );
3134 ::SMESH_Mesh& myLocMesh = myImpl->GetImpl();
3135 SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
3136 bool hasShape = myLocMesh.HasShapeToMesh();
3138 // for each mesh open the HDF group basing on its id
3139 char meshGrpName[ 30 ];
3140 sprintf( meshGrpName, "Mesh %d", id );
3141 aTopGroup = new HDFgroup( meshGrpName, aFile );
3142 aTopGroup->CreateOnDisk();
3144 // --> put dataset to hdf file which is a flag that mesh has data
3145 string strHasData = "0";
3146 // check if the mesh is not empty
3147 if ( mySMESHDSMesh->NbNodes() > 0 ) {
3148 // write mesh data to med file
3149 myWriter.SetMesh( mySMESHDSMesh );
3150 myWriter.SetMeshId( id );
3153 aSize[ 0 ] = strHasData.length() + 1;
3154 aDataset = new HDFdataset( "Has data", aTopGroup, HDF_STRING, aSize, 1 );
3155 aDataset->CreateOnDisk();
3156 aDataset->WriteOnDisk( ( char* )( strHasData.c_str() ) );
3157 aDataset->CloseOnDisk();
3160 // for each mesh open the HDF group basing on its auto color parameter
3161 char meshAutoColorName[ 30 ];
3162 sprintf( meshAutoColorName, "AutoColorMesh %d", id );
3164 anAutoColor[0] = myImpl->GetAutoColor();
3166 aDataset = new HDFdataset( meshAutoColorName, aTopGroup, HDF_INT32, aSize, 1 );
3167 aDataset->CreateOnDisk();
3168 aDataset->WriteOnDisk( anAutoColor );
3169 aDataset->CloseOnDisk();
3171 // issue 0020693. Store _isModified flag
3172 int isModified = myLocMesh.GetIsModified();
3174 aDataset = new HDFdataset( "_isModified", aTopGroup, HDF_INT32, aSize, 1 );
3175 aDataset->CreateOnDisk();
3176 aDataset->WriteOnDisk( &isModified );
3177 aDataset->CloseOnDisk();
3179 // issue 20918. Store Persistent Id of SMESHDS_Mesh
3180 int meshPersistentId = mySMESHDSMesh->GetPersistentId();
3182 aDataset = new HDFdataset( "meshPersistentId", aTopGroup, HDF_INT32, aSize, 1 );
3183 aDataset->CreateOnDisk();
3184 aDataset->WriteOnDisk( &meshPersistentId );
3185 aDataset->CloseOnDisk();
3187 // write reference on a shape if exists
3188 SALOMEDS::SObject_wrap myRef;
3189 bool shapeRefFound = false;
3190 bool found = gotBranch->FindSubObject( GetRefOnShapeTag(), myRef.inout() );
3192 SALOMEDS::SObject_wrap myShape;
3193 bool ok = myRef->ReferencedObject( myShape.inout() );
3195 shapeRefFound = (! CORBA::is_nil( myShape->GetObject() ));
3196 string myRefOnObject = myShape->GetID();
3197 if ( shapeRefFound && myRefOnObject.length() > 0 ) {
3198 aSize[ 0 ] = myRefOnObject.length() + 1;
3199 aDataset = new HDFdataset( "Ref on shape", aTopGroup, HDF_STRING, aSize, 1 );
3200 aDataset->CreateOnDisk();
3201 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3202 aDataset->CloseOnDisk();
3207 // write applied hypotheses if exist
3208 SALOMEDS::SObject_wrap myHypBranch;
3209 found = gotBranch->FindSubObject( GetRefOnAppliedHypothesisTag(), myHypBranch.inout() );
3210 if ( found && !shapeRefFound && hasShape) { // remove applied hyps
3211 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myHypBranch );
3213 if ( found && (shapeRefFound || !hasShape) ) {
3214 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
3215 aGroup->CreateOnDisk();
3217 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myHypBranch );
3219 for ( ; it->More(); it->Next() ) {
3220 SALOMEDS::SObject_wrap mySObject = it->Value();
3221 SALOMEDS::SObject_wrap myRefOnHyp;
3222 bool ok = mySObject->ReferencedObject( myRefOnHyp.inout() );
3224 // san - it is impossible to recover applied hypotheses
3225 // using their entries within Load() method,
3226 // for there are no AttributeIORs in the study when Load() is working.
3227 // Hence, it is better to store persistent IDs of hypotheses as references to them
3229 //string myRefOnObject = myRefOnHyp->GetID();
3230 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3231 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3232 int id = myStudyContext->findId( string( objStr.in() ) );
3233 //if ( myRefOnObject.length() > 0 ) {
3234 //aSize[ 0 ] = myRefOnObject.length() + 1;
3235 char hypName[ 30 ], hypId[ 30 ];
3236 sprintf( hypName, "Hyp %d", ++hypNb );
3237 sprintf( hypId, "%d", id );
3238 aSize[ 0 ] = strlen( hypId ) + 1;
3239 aDataset = new HDFdataset( hypName, aGroup, HDF_STRING, aSize, 1 );
3240 aDataset->CreateOnDisk();
3241 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3242 aDataset->WriteOnDisk( hypId );
3243 aDataset->CloseOnDisk();
3247 aGroup->CloseOnDisk();
3250 // write applied algorithms if exist
3251 SALOMEDS::SObject_wrap myAlgoBranch;
3252 found = gotBranch->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
3253 myAlgoBranch.inout() );
3254 if ( found && !shapeRefFound && hasShape) { // remove applied algos
3255 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( myAlgoBranch );
3257 if ( found && (shapeRefFound || !hasShape)) {
3258 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
3259 aGroup->CreateOnDisk();
3261 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myAlgoBranch );
3263 for ( ; it->More(); it->Next() ) {
3264 SALOMEDS::SObject_wrap mySObject = it->Value();
3265 SALOMEDS::SObject_wrap myRefOnAlgo;
3266 bool ok = mySObject->ReferencedObject( myRefOnAlgo.inout() );
3268 // san - it is impossible to recover applied algorithms
3269 // using their entries within Load() method,
3270 // for there are no AttributeIORs in the study when Load() is working.
3271 // Hence, it is better to store persistent IDs of algorithms as references to them
3273 //string myRefOnObject = myRefOnAlgo->GetID();
3274 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3275 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3276 int id = myStudyContext->findId( string( objStr.in() ) );
3277 //if ( myRefOnObject.length() > 0 ) {
3278 //aSize[ 0 ] = myRefOnObject.length() + 1;
3279 char algoName[ 30 ], algoId[ 30 ];
3280 sprintf( algoName, "Algo %d", ++algoNb );
3281 sprintf( algoId, "%d", id );
3282 aSize[ 0 ] = strlen( algoId ) + 1;
3283 aDataset = new HDFdataset( algoName, aGroup, HDF_STRING, aSize, 1 );
3284 aDataset->CreateOnDisk();
3285 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3286 aDataset->WriteOnDisk( algoId );
3287 aDataset->CloseOnDisk();
3291 aGroup->CloseOnDisk();
3294 // --> submesh objects sub-branches
3296 for ( int i = GetSubMeshOnVertexTag(); i <= GetSubMeshOnCompoundTag(); i++ ) {
3297 SALOMEDS::SObject_wrap mySubmeshBranch;
3298 found = gotBranch->FindSubObject( i, mySubmeshBranch.inout() );
3300 if ( found ) // check if there is shape reference in submeshes
3302 bool hasShapeRef = false;
3303 SALOMEDS::ChildIterator_wrap itSM =
3304 myCurrentStudy->NewChildIterator( mySubmeshBranch );
3305 for ( ; itSM->More(); itSM->Next() ) {
3306 SALOMEDS::SObject_wrap mySubRef, myShape, mySObject = itSM->Value();
3307 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
3308 mySubRef->ReferencedObject( myShape.inout() );
3309 if ( !CORBA::is_nil( myShape ) && !CORBA::is_nil( myShape->GetObject() ))
3312 { // remove one submesh
3313 if ( shapeRefFound )
3314 { // unassign hypothesis
3315 SMESH::SMESH_subMesh_var mySubMesh =
3316 SMESH::SMESH_subMesh::_narrow( SObjectToObject( mySObject ));
3317 if ( !mySubMesh->_is_nil() ) {
3318 int shapeID = mySubMesh->GetId();
3319 TopoDS_Shape S = mySMESHDSMesh->IndexToShape( shapeID );
3320 const list<const SMESHDS_Hypothesis*>& hypList =
3321 mySMESHDSMesh->GetHypothesis( S );
3322 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
3323 while ( hyp != hypList.end() ) {
3324 int hypID = (*hyp++)->GetID(); // goto next hyp here because
3325 myLocMesh.RemoveHypothesis( S, hypID ); // hypList changes here
3329 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySObject );
3331 } // loop on submeshes of a type
3332 if ( !shapeRefFound || !hasShapeRef ) { // remove the whole submeshes branch
3333 myCurrentStudy->NewBuilder()->RemoveObjectWithChildren( mySubmeshBranch );
3336 } // end check if there is shape reference in submeshes
3338 char name_meshgroup[ 30 ];
3339 if ( i == GetSubMeshOnVertexTag() )
3340 strcpy( name_meshgroup, "SubMeshes On Vertex" );
3341 else if ( i == GetSubMeshOnEdgeTag() )
3342 strcpy( name_meshgroup, "SubMeshes On Edge" );
3343 else if ( i == GetSubMeshOnWireTag() )
3344 strcpy( name_meshgroup, "SubMeshes On Wire" );
3345 else if ( i == GetSubMeshOnFaceTag() )
3346 strcpy( name_meshgroup, "SubMeshes On Face" );
3347 else if ( i == GetSubMeshOnShellTag() )
3348 strcpy( name_meshgroup, "SubMeshes On Shell" );
3349 else if ( i == GetSubMeshOnSolidTag() )
3350 strcpy( name_meshgroup, "SubMeshes On Solid" );
3351 else if ( i == GetSubMeshOnCompoundTag() )
3352 strcpy( name_meshgroup, "SubMeshes On Compound" );
3354 // for each type of submeshes create container HDF group
3355 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
3356 aGroup->CreateOnDisk();
3358 // iterator for all submeshes of given type
3359 SALOMEDS::ChildIterator_wrap itSM = myCurrentStudy->NewChildIterator( mySubmeshBranch );
3360 for ( ; itSM->More(); itSM->Next() ) {
3361 SALOMEDS::SObject_wrap mySObject = itSM->Value();
3362 CORBA::Object_var anSubObject = SObjectToObject( mySObject );
3363 if ( !CORBA::is_nil( anSubObject ))
3365 SMESH::SMESH_subMesh_var mySubMesh = SMESH::SMESH_subMesh::_narrow( anSubObject ) ;
3366 CORBA::String_var objStr = GetORB()->object_to_string( anSubObject );
3367 int subid = myStudyContext->findId( string( objStr.in() ) );
3369 // for each mesh open the HDF group basing on its id
3370 char submeshGrpName[ 30 ];
3371 sprintf( submeshGrpName, "SubMesh %d", subid );
3372 aSubGroup = new HDFgroup( submeshGrpName, aGroup );
3373 aSubGroup->CreateOnDisk();
3375 // write reference on a shape, already checked if it exists
3376 SALOMEDS::SObject_wrap mySubRef, myShape;
3377 if ( mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ))
3378 mySubRef->ReferencedObject( myShape.inout() );
3379 string myRefOnObject = myShape->GetID();
3380 if ( myRefOnObject.length() > 0 ) {
3381 aSize[ 0 ] = myRefOnObject.length() + 1;
3382 aDataset = new HDFdataset( "Ref on shape", aSubGroup, HDF_STRING, aSize, 1 );
3383 aDataset->CreateOnDisk();
3384 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3385 aDataset->CloseOnDisk();
3388 // write applied hypotheses if exist
3389 SALOMEDS::SObject_wrap mySubHypBranch;
3390 found = mySObject->FindSubObject( GetRefOnAppliedHypothesisTag(),
3391 mySubHypBranch.inout() );
3393 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
3394 aSubSubGroup->CreateOnDisk();
3396 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( mySubHypBranch );
3398 for ( ; it->More(); it->Next() ) {
3399 SALOMEDS::SObject_wrap mySubSObject = it->Value();
3400 SALOMEDS::SObject_wrap myRefOnHyp;
3401 bool ok = mySubSObject->ReferencedObject( myRefOnHyp.inout() );
3403 //string myRefOnObject = myRefOnHyp->GetID();
3404 CORBA::Object_var anObject = SObjectToObject( myRefOnHyp );
3405 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3406 int id = myStudyContext->findId( string( objStr.in() ) );
3407 //if ( myRefOnObject.length() > 0 ) {
3408 //aSize[ 0 ] = myRefOnObject.length() + 1;
3409 char hypName[ 30 ], hypId[ 30 ];
3410 sprintf( hypName, "Hyp %d", ++hypNb );
3411 sprintf( hypId, "%d", id );
3412 aSize[ 0 ] = strlen( hypId ) + 1;
3413 aDataset = new HDFdataset( hypName, aSubSubGroup, HDF_STRING, aSize, 1 );
3414 aDataset->CreateOnDisk();
3415 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3416 aDataset->WriteOnDisk( hypId );
3417 aDataset->CloseOnDisk();
3421 aSubSubGroup->CloseOnDisk();
3424 // write applied algorithms if exist
3425 SALOMEDS::SObject_wrap mySubAlgoBranch;
3426 found = mySObject->FindSubObject( GetRefOnAppliedAlgorithmsTag(),
3427 mySubAlgoBranch.inout() );
3429 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
3430 aSubSubGroup->CreateOnDisk();
3432 SALOMEDS::ChildIterator_wrap it =
3433 myCurrentStudy->NewChildIterator( mySubAlgoBranch );
3435 for ( ; it->More(); it->Next() ) {
3436 SALOMEDS::SObject_wrap mySubSObject = it->Value();
3437 SALOMEDS::SObject_wrap myRefOnAlgo;
3438 bool ok = mySubSObject->ReferencedObject( myRefOnAlgo.inout() );
3440 //string myRefOnObject = myRefOnAlgo->GetID();
3441 CORBA::Object_var anObject = SObjectToObject( myRefOnAlgo );
3442 CORBA::String_var objStr = GetORB()->object_to_string( anObject );
3443 int id = myStudyContext->findId( string( objStr.in() ) );
3444 //if ( myRefOnObject.length() > 0 ) {
3445 //aSize[ 0 ] = myRefOnObject.length() + 1;
3446 char algoName[ 30 ], algoId[ 30 ];
3447 sprintf( algoName, "Algo %d", ++algoNb );
3448 sprintf( algoId, "%d", id );
3449 aSize[ 0 ] = strlen( algoId ) + 1;
3450 aDataset = new HDFdataset( algoName, aSubSubGroup, HDF_STRING, aSize, 1 );
3451 aDataset->CreateOnDisk();
3452 //aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3453 aDataset->WriteOnDisk( algoId );
3454 aDataset->CloseOnDisk();
3458 aSubSubGroup->CloseOnDisk();
3460 // close submesh HDF group
3461 aSubGroup->CloseOnDisk();
3464 // close container of submeshes by type HDF group
3465 aGroup->CloseOnDisk();
3468 // All sub-meshes will be stored in MED file
3469 // .. will NOT (PAL 12992)
3470 //if ( shapeRefFound )
3471 //myWriter.AddAllSubMeshes();
3473 // store submesh order if any
3474 const TListOfListOfInt& theOrderIds = myLocMesh.GetMeshOrder();
3475 if ( theOrderIds.size() ) {
3476 char order_list[ 30 ];
3477 strcpy( order_list, "Mesh Order" );
3478 // count number of submesh ids
3480 TListOfListOfInt::const_iterator idIt = theOrderIds.begin();
3481 for ( ; idIt != theOrderIds.end(); idIt++ )
3482 nbIDs += (*idIt).size();
3483 // number of values = number of IDs +
3484 // number of lists (for separators) - 1
3485 int* smIDs = new int [ nbIDs + theOrderIds.size() - 1 ];
3486 idIt = theOrderIds.begin();
3487 for ( int i = 0; idIt != theOrderIds.end(); idIt++ ) {
3488 const TListOfInt& idList = *idIt;
3489 if (idIt != theOrderIds.begin()) // not first list
3490 smIDs[ i++ ] = -1/* *idList.size()*/; // separator between lists
3491 // dump submesh ids from current list
3492 TListOfInt::const_iterator id_smId = idList.begin();
3493 for( ; id_smId != idList.end(); id_smId++ )
3494 smIDs[ i++ ] = *id_smId;
3497 aSize[ 0 ] = nbIDs + theOrderIds.size() - 1;
3499 aDataset = new HDFdataset( order_list, aTopGroup, HDF_INT32, aSize, 1 );
3500 aDataset->CreateOnDisk();
3501 aDataset->WriteOnDisk( smIDs );
3502 aDataset->CloseOnDisk();
3507 // groups root sub-branch
3508 SALOMEDS::SObject_wrap myGroupsBranch;
3509 for ( int i = GetNodeGroupsTag(); i <= GetBallElementsGroupsTag(); i++ ) {
3510 found = gotBranch->FindSubObject( i, myGroupsBranch.inout() );
3512 char name_group[ 30 ];
3513 if ( i == GetNodeGroupsTag() )
3514 strcpy( name_group, "Groups of Nodes" );
3515 else if ( i == GetEdgeGroupsTag() )
3516 strcpy( name_group, "Groups of Edges" );
3517 else if ( i == GetFaceGroupsTag() )
3518 strcpy( name_group, "Groups of Faces" );
3519 else if ( i == GetVolumeGroupsTag() )
3520 strcpy( name_group, "Groups of Volumes" );
3521 else if ( i == Get0DElementsGroupsTag() )
3522 strcpy( name_group, "Groups of 0D Elements" );
3523 else if ( i == GetBallElementsGroupsTag() )
3524 strcpy( name_group, "Groups of Balls" );
3526 aGroup = new HDFgroup( name_group, aTopGroup );
3527 aGroup->CreateOnDisk();
3529 SALOMEDS::ChildIterator_wrap it = myCurrentStudy->NewChildIterator( myGroupsBranch );
3530 for ( ; it->More(); it->Next() ) {
3531 SALOMEDS::SObject_wrap mySObject = it->Value();
3532 CORBA::Object_var aSubObject = SObjectToObject( mySObject );
3533 if ( !CORBA::is_nil( aSubObject ) ) {
3534 SMESH_GroupBase_i* myGroupImpl =
3535 dynamic_cast<SMESH_GroupBase_i*>( GetServant( aSubObject ).in() );
3538 SMESHDS_GroupBase* aGrpBaseDS = myGroupImpl->GetGroupDS();
3542 CORBA::String_var objStr = GetORB()->object_to_string( aSubObject );
3543 int anId = myStudyContext->findId( string( objStr.in() ) );
3545 // For each group, create a dataset named "Group <group_persistent_id>"
3546 // and store the group's user name into it
3547 const char* grpName = aGrpBaseDS->GetStoreName();
3548 char* aUserName = myGroupImpl->GetName();
3549 aSize[ 0 ] = strlen( aUserName ) + 1;
3551 aDataset = new HDFdataset( grpName, aGroup, HDF_STRING, aSize, 1 );
3552 aDataset->CreateOnDisk();
3553 aDataset->WriteOnDisk( aUserName );
3554 aDataset->CloseOnDisk();
3557 // For each group, create a dataset named "Group <group_persistent_id> Color"
3558 // and store the group's color into it
3559 char grpColorName[ 30 ];
3560 sprintf( grpColorName, "ColorGroup %d", anId );
3561 SALOMEDS::Color aColor = myGroupImpl->GetColor();
3563 anRGB[ 0 ] = aColor.R;
3564 anRGB[ 1 ] = aColor.G;
3565 anRGB[ 2 ] = aColor.B;
3567 aDataset = new HDFdataset( grpColorName, aGroup, HDF_FLOAT64, aSize, 1 );
3568 aDataset->CreateOnDisk();
3569 aDataset->WriteOnDisk( anRGB );
3570 aDataset->CloseOnDisk();
3572 // Pass SMESHDS_Group to MED writer
3573 SMESHDS_Group* aGrpDS = dynamic_cast<SMESHDS_Group*>( aGrpBaseDS );
3575 myWriter.AddGroup( aGrpDS );
3577 // write reference on a shape if exists
3578 SMESHDS_GroupOnGeom* aGeomGrp =
3579 dynamic_cast<SMESHDS_GroupOnGeom*>( aGrpBaseDS );
3581 SALOMEDS::SObject_wrap mySubRef, myShape;
3582 if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef.inout() ) &&
3583 mySubRef->ReferencedObject( myShape.inout() ) &&
3584 !CORBA::is_nil( myShape->GetObject() ))
3586 string myRefOnObject = myShape->GetID();
3587 if ( myRefOnObject.length() > 0 ) {
3588 char aRefName[ 30 ];
3589 sprintf( aRefName, "Ref on shape %d", anId);
3590 aSize[ 0 ] = myRefOnObject.length() + 1;
3591 aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1);
3592 aDataset->CreateOnDisk();
3593 aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) );
3594 aDataset->CloseOnDisk();
3597 else // shape ref is invalid:
3599 // save a group on geometry as ordinary group
3600 myWriter.AddGroup( aGeomGrp );
3603 else if ( SMESH_GroupOnFilter_i* aFilterGrp_i =
3604 dynamic_cast<SMESH_GroupOnFilter_i*>( myGroupImpl ))
3606 std::string str = aFilterGrp_i->FilterToString();
3607 std::string hdfGrpName = "Filter " + SMESH_Comment(anId);
3608 aSize[ 0 ] = str.length() + 1;
3609 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup, HDF_STRING, aSize, 1);
3610 aDataset->CreateOnDisk();
3611 aDataset->WriteOnDisk( ( char* )( str.c_str() ) );
3612 aDataset->CloseOnDisk();
3616 aGroup->CloseOnDisk();
3620 if ( strcmp( strHasData.c_str(), "1" ) == 0 )
3622 // Flush current mesh information into MED file
3625 // save info on nb of elements
3626 SMESH_PreMeshInfo::SaveToFile( myImpl, id, aFile );
3628 // maybe a shape was deleted in the study
3629 if ( !shapeRefFound && !mySMESHDSMesh->ShapeToMesh().IsNull() && hasShape) {
3630 TopoDS_Shape nullShape;
3631 myLocMesh.ShapeToMesh( nullShape ); // remove shape referring data
3634 if ( !mySMESHDSMesh->SubMeshes().empty() )
3638 aGroup = new HDFgroup( "Submeshes", aTopGroup );
3639 aGroup->CreateOnDisk();
3641 // each element belongs to one or none submesh,
3642 // so for each node/element, we store a submesh ID
3644 // Make maps of submesh IDs of elements sorted by element IDs
3645 typedef int TElemID;
3646 typedef int TSubMID;
3647 map< TElemID, TSubMID > eId2smId, nId2smId;
3648 map< TElemID, TSubMID >::iterator hint; // insertion to map is done before hint
3649 const map<int,SMESHDS_SubMesh*>& aSubMeshes = mySMESHDSMesh->SubMeshes();
3650 map<int,SMESHDS_SubMesh*>::const_iterator itSubM ( aSubMeshes.begin() );
3651 SMDS_NodeIteratorPtr itNode;
3652 SMDS_ElemIteratorPtr itElem;
3653 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3655 TSubMID aSubMeID = itSubM->first;
3656 SMESHDS_SubMesh* aSubMesh = itSubM->second;
3657 if ( aSubMesh->IsComplexSubmesh() )
3658 continue; // submesh containing other submeshs
3660 hint = nId2smId.begin(); // optimize insertion basing on increasing order of elem Ids in submesh
3661 for ( itNode = aSubMesh->GetNodes(); itNode->more(); ++hint)
3662 hint = nId2smId.insert( hint, make_pair( itNode->next()->GetID(), aSubMeID ));
3664 hint = eId2smId.begin();
3665 for ( itElem = aSubMesh->GetElements(); itElem->more(); ++hint)
3666 hint = eId2smId.insert( hint, make_pair( itElem->next()->GetID(), aSubMeID ));
3669 // Care of elements that are not on submeshes
3670 if ( mySMESHDSMesh->NbNodes() != nId2smId.size() ) {
3671 for ( itNode = mySMESHDSMesh->nodesIterator(); itNode->more(); )
3672 /* --- stl_map.h says : */
3673 /* A %map relies on unique keys and thus a %pair is only inserted if its */
3674 /* first element (the key) is not already present in the %map. */
3675 nId2smId.insert( make_pair( itNode->next()->GetID(), 0 ));
3677 int nbElems = mySMESHDSMesh->NbEdges() + mySMESHDSMesh->NbFaces() + mySMESHDSMesh->NbVolumes();
3678 if ( nbElems != eId2smId.size() ) {
3679 for ( itElem = mySMESHDSMesh->elementsIterator(); itElem->more(); )
3680 eId2smId.insert( make_pair( itElem->next()->GetID(), 0 ));
3683 // Store submesh IDs
3684 for ( int isNode = 0; isNode < 2; ++isNode )
3686 map< TElemID, TSubMID >& id2smId = isNode ? nId2smId : eId2smId;
3687 if ( id2smId.empty() ) continue;
3688 map< TElemID, TSubMID >::const_iterator id_smId = id2smId.begin();
3689 // make and fill array of submesh IDs
3690 int* smIDs = new int [ id2smId.size() ];
3691 for ( int i = 0; id_smId != id2smId.end(); ++id_smId, ++i )
3692 smIDs[ i ] = id_smId->second;
3694 aSize[ 0 ] = id2smId.size();
3695 string aDSName( isNode ? "Node Submeshes" : "Element Submeshes");
3696 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3697 aDataset->CreateOnDisk();
3698 aDataset->WriteOnDisk( smIDs );
3699 aDataset->CloseOnDisk();
3704 aGroup->CloseOnDisk();
3706 // Store node positions on sub-shapes (SMDS_Position):
3707 // ----------------------------------------------------
3709 aGroup = new HDFgroup( "Node Positions", aTopGroup );
3710 aGroup->CreateOnDisk();
3712 // in aGroup, create 5 datasets to contain:
3713 // "Nodes on Edges" - ID of node on edge
3714 // "Edge positions" - U parameter on node on edge
3715 // "Nodes on Faces" - ID of node on face
3716 // "Face U positions" - U parameter of node on face
3717 // "Face V positions" - V parameter of node on face
3719 // Find out nb of nodes on edges and faces
3720 // Collect corresponing sub-meshes
3721 int nbEdgeNodes = 0, nbFaceNodes = 0;
3722 list<SMESHDS_SubMesh*> aEdgeSM, aFaceSM;
3723 // loop on SMESHDS_SubMesh'es
3724 for ( itSubM = aSubMeshes.begin(); itSubM != aSubMeshes.end() ; itSubM++ )
3726 SMESHDS_SubMesh* aSubMesh = (*itSubM).second;
3727 if ( aSubMesh->IsComplexSubmesh() )
3728 continue; // submesh containing other submeshs
3729 int nbNodes = aSubMesh->NbNodes();
3730 if ( nbNodes == 0 ) continue;
3732 int aShapeID = (*itSubM).first;
3733 if ( aShapeID < 1 || aShapeID > mySMESHDSMesh->MaxShapeIndex() )
3735 int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType();
3736 // write only SMDS_FacePosition and SMDS_EdgePosition
3737 switch ( aShapeType ) {
3739 nbFaceNodes += nbNodes;
3740 aFaceSM.push_back( aSubMesh );
3743 nbEdgeNodes += nbNodes;
3744 aEdgeSM.push_back( aSubMesh );
3750 // Treat positions on edges or faces
3751 for ( int onFace = 0; onFace < 2; onFace++ )
3753 // Create arrays to store in datasets
3754 int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes );
3755 if (!nbNodes) continue;
3756 int* aNodeIDs = new int [ nbNodes ];
3757 double* aUPos = new double [ nbNodes ];
3758 double* aVPos = ( onFace ? new double[ nbNodes ] : 0 );
3761 // loop on sub-meshes
3762 list<SMESHDS_SubMesh*> * pListSM = ( onFace ? &aFaceSM : &aEdgeSM );
3763 list<SMESHDS_SubMesh*>::iterator itSM = pListSM->begin();
3764 for ( ; itSM != pListSM->end(); itSM++ )
3766 SMESHDS_SubMesh* aSubMesh = (*itSM);
3768 SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes();
3769 // loop on nodes in aSubMesh
3770 while ( itNode->more() )
3773 const SMDS_MeshNode* node = itNode->next();
3774 aNodeIDs [ iNode ] = node->GetID();
3777 const SMDS_PositionPtr pos = node->GetPosition();
3778 if ( onFace ) { // on FACE
3779 const SMDS_FacePosition* fPos =
3780 dynamic_cast<const SMDS_FacePosition*>( pos );
3782 aUPos[ iNode ] = fPos->GetUParameter();
3783 aVPos[ iNode ] = fPos->GetVParameter();
3790 const SMDS_EdgePosition* ePos =
3791 dynamic_cast<const SMDS_EdgePosition*>( pos );
3793 aUPos[ iNode ] = ePos->GetUParameter();
3799 } // loop on nodes in aSubMesh
3800 } // loop on sub-meshes
3805 aSize[ 0 ] = nbNodes;
3807 string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges");
3808 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 );
3809 aDataset->CreateOnDisk();
3810 aDataset->WriteOnDisk( aNodeIDs );
3811 aDataset->CloseOnDisk();
3814 aDSName = ( onFace ? "Face U positions" : "Edge positions");
3815 aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1);
3816 aDataset->CreateOnDisk();
3817 aDataset->WriteOnDisk( aUPos );
3818 aDataset->CloseOnDisk();
3821 aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1);
3822 aDataset->CreateOnDisk();
3823 aDataset->WriteOnDisk( aVPos );
3824 aDataset->CloseOnDisk();
3829 if ( aVPos ) delete [] aVPos;
3831 } // treat positions on edges or faces
3833 // close "Node Positions" group
3834 aGroup->CloseOnDisk();
3836 } // if ( there are submeshes in SMESHDS_Mesh )
3839 // close mesh HDF group
3840 aTopGroup->CloseOnDisk();
3848 aFile->CloseOnDisk();
3851 // Convert temporary files to stream
3852 aStreamFile = SALOMEDS_Tool::PutFilesToStream( tmpDir.ToCString(), aFileSeq.in(), isMultiFile );
3854 // Remove temporary files and directory
3856 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
3858 INFOS( "SMESH_Gen_i::Save() completed" );
3859 return aStreamFile._retn();
3862 //=============================================================================
3864 * SMESH_Gen_i::SaveASCII
3866 * Save SMESH module's data in ASCII format
3868 //=============================================================================
3870 SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent,
3872 bool isMultiFile ) {
3873 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" );
3874 SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile );
3875 return aStreamFile._retn();
3877 //after usual saving needs to encipher binary to text string
3878 //Any binary symbol will be represent as "|xx" () hexadecimal format number
3879 int size = aStreamFile.in().length();
3880 _CORBA_Octet* buffer = new _CORBA_Octet[size*3+1];
3881 for ( int i = 0; i < size; i++ )
3882 sprintf( (char*)&(buffer[i*3]), "|%02x", aStreamFile[i] );
3884 buffer[size * 3] = '\0';
3886 SALOMEDS::TMPFile_var anAsciiStreamFile = new SALOMEDS::TMPFile(size*3, size*3, buffer, 1);
3888 return anAsciiStreamFile._retn();
3891 //=============================================================================
3893 * SMESH_Gen_i::loadGeomData
3895 * Load GEOM module data
3897 //=============================================================================
3899 void SMESH_Gen_i::loadGeomData( SALOMEDS::SComponent_ptr theCompRoot )
3901 if ( theCompRoot->_is_nil() )
3904 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theCompRoot->GetStudy() );
3905 if ( aStudy->_is_nil() )
3908 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
3909 aStudyBuilder->LoadWith( theCompRoot, GetGeomEngine() );
3912 //=============================================================================
3916 * Load SMESH module's data
3918 //=============================================================================
3920 bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent,
3921 const SALOMEDS::TMPFile& theStream,
3925 INFOS( "SMESH_Gen_i::Load" );
3927 if ( myCurrentStudy->_is_nil() ||
3928 theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() )
3929 SetCurrentStudy( theComponent->GetStudy() );
3931 /* if( !theComponent->_is_nil() )
3933 //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
3934 if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
3935 loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
3938 StudyContext* myStudyContext = GetCurrentStudyContext();
3940 // Get temporary files location
3941 TCollection_AsciiString tmpDir =
3942 ( char* )( isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir().c_str() );
3944 INFOS( "THE URL++++++++++++++" );
3946 INFOS( "THE TMP PATH+++++++++" );
3949 // Convert the stream into sequence of files to process
3950 SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
3953 TCollection_AsciiString aStudyName( "" );
3954 if ( isMultiFile ) {
3955 CORBA::String_var url = myCurrentStudy->URL();
3956 aStudyName = (char*)SALOMEDS_Tool::GetNameFromPath( url.in() ).c_str();
3958 // Set names of temporary files
3959 TCollection_AsciiString filename = tmpDir + aStudyName + "_SMESH.hdf";
3960 TCollection_AsciiString meshfile = tmpDir + aStudyName + "_SMESH_Mesh.med";
3964 HDFdataset* aDataset;
3965 HDFgroup* aTopGroup;
3967 HDFgroup* aSubGroup;
3968 HDFgroup* aSubSubGroup;
3971 // ---> open HDF file
3972 aFile = new HDFfile( (char*) filename.ToCString() );
3974 aFile->OpenOnDisk( HDF_RDONLY );
3976 catch ( HDFexception ) {
3977 INFOS( "Load(): " << filename << " not found!" );
3981 TPythonDump pd; // prevent dump during loading
3983 // DriverMED_R_SMESHDS_Mesh myReader;
3984 // myReader.SetFile( meshfile.ToCString() );
3986 // For PAL13473 ("Repetitive mesh") implementation.
3987 // New dependencies between SMESH objects are established:
3988 // now hypotheses can refer to meshes, shapes and other hypotheses.
3989 // To keep data consistent, the following order of data restoration
3991 // 1. Create hypotheses
3992 // 2. Create all meshes
3993 // 3. Load hypotheses' data
3996 list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
3997 list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
3999 // get total number of top-level groups
4000 int aNbGroups = aFile->nInternalObjects();
4001 if ( aNbGroups > 0 ) {
4002 // --> in first turn we should read&create hypotheses
4003 if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
4004 // open hypotheses root HDF group
4005 aTopGroup = new HDFgroup( "Hypotheses", aFile );
4006 aTopGroup->OpenOnDisk();
4008 // get number of hypotheses
4009 int aNbObjects = aTopGroup->nInternalObjects();
4010 for ( int j = 0; j < aNbObjects; j++ ) {
4011 // try to identify hypothesis
4012 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
4013 aTopGroup->InternalObjectIndentify( j, hypGrpName );
4015 if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
4016 // open hypothesis group
4017 aGroup = new HDFgroup( hypGrpName, aTopGroup );
4018 aGroup->OpenOnDisk();
4020 // --> get hypothesis id
4021 int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
4026 // get number of datasets
4027 int aNbSubObjects = aGroup->nInternalObjects();
4028 for ( int k = 0; k < aNbSubObjects; k++ ) {
4030 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4031 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4032 // --> get hypothesis name
4033 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4034 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4035 aDataset->OpenOnDisk();
4036 size = aDataset->GetSize();
4037 char* hypname_str = new char[ size ];
4038 aDataset->ReadFromDisk( hypname_str );
4039 hypname = string( hypname_str );
4040 delete [] hypname_str;
4041 aDataset->CloseOnDisk();
4043 // --> get hypothesis plugin library name
4044 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4045 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4046 aDataset->OpenOnDisk();
4047 size = aDataset->GetSize();
4048 char* libname_str = new char[ size ];
4049 aDataset->ReadFromDisk( libname_str );
4050 if(MYDEBUG) SCRUTE( libname_str );
4051 libname = string( libname_str );
4052 delete [] libname_str;
4053 aDataset->CloseOnDisk();
4055 // --> get hypothesis data
4056 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4057 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4058 aDataset->OpenOnDisk();
4059 size = aDataset->GetSize();
4060 char* hypdata_str = new char[ size ];
4061 aDataset->ReadFromDisk( hypdata_str );
4062 hypdata = string( hypdata_str );
4063 delete [] hypdata_str;
4064 aDataset->CloseOnDisk();
4067 // close hypothesis HDF group
4068 aGroup->CloseOnDisk();
4070 // --> restore hypothesis from data
4071 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4072 if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
4073 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4074 SMESH::SMESH_Hypothesis_var myHyp;
4076 try { // protect persistence mechanism against exceptions
4077 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4080 INFOS( "Exception during hypothesis creation" );
4083 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4085 // myImpl->LoadFrom( hypdata.c_str() );
4086 hypDataList.push_back( make_pair( myImpl, hypdata ));
4087 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
4088 int newId = myStudyContext->findId( iorString.in() );
4089 myStudyContext->mapOldToNew( id, newId );
4092 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4096 // close hypotheses root HDF group
4097 aTopGroup->CloseOnDisk();
4101 // --> then we should read&create algorithms
4102 if ( aFile->ExistInternalObject( "Algorithms" ) ) {
4103 // open algorithms root HDF group
4104 aTopGroup = new HDFgroup( "Algorithms", aFile );
4105 aTopGroup->OpenOnDisk();
4107 // get number of algorithms
4108 int aNbObjects = aTopGroup->nInternalObjects();
4109 for ( int j = 0; j < aNbObjects; j++ ) {
4110 // try to identify algorithm
4111 char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
4112 aTopGroup->InternalObjectIndentify( j, hypGrpName );
4114 if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
4115 // open algorithm group
4116 aGroup = new HDFgroup( hypGrpName, aTopGroup );
4117 aGroup->OpenOnDisk();
4119 // --> get algorithm id
4120 int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
4125 // get number of datasets
4126 int aNbSubObjects = aGroup->nInternalObjects();
4127 for ( int k = 0; k < aNbSubObjects; k++ ) {
4129 char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
4130 aGroup->InternalObjectIndentify( k, name_of_subgroup );
4131 // --> get algorithm name
4132 if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
4133 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4134 aDataset->OpenOnDisk();
4135 size = aDataset->GetSize();
4136 char* hypname_str = new char[ size ];
4137 aDataset->ReadFromDisk( hypname_str );
4138 hypname = string( hypname_str );
4139 delete [] hypname_str;
4140 aDataset->CloseOnDisk();
4142 // --> get algorithm plugin library name
4143 if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
4144 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4145 aDataset->OpenOnDisk();
4146 size = aDataset->GetSize();
4147 char* libname_str = new char[ size ];
4148 aDataset->ReadFromDisk( libname_str );
4149 if(MYDEBUG) SCRUTE( libname_str );
4150 libname = string( libname_str );
4151 delete [] libname_str;
4152 aDataset->CloseOnDisk();
4154 // --> get algorithm data
4155 if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
4156 aDataset = new HDFdataset( name_of_subgroup, aGroup );
4157 aDataset->OpenOnDisk();
4158 size = aDataset->GetSize();
4159 char* hypdata_str = new char[ size ];
4160 aDataset->ReadFromDisk( hypdata_str );
4161 if(MYDEBUG) SCRUTE( hypdata_str );
4162 hypdata = string( hypdata_str );
4163 delete [] hypdata_str;
4164 aDataset->CloseOnDisk();
4167 // close algorithm HDF group
4168 aGroup->CloseOnDisk();
4170 // --> restore algorithm from data
4171 if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
4172 if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
4173 ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
4174 SMESH::SMESH_Hypothesis_var myHyp;
4176 try { // protect persistence mechanism against exceptions
4177 myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
4180 INFOS( "Exception during hypothesis creation" );
4183 SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
4185 //myImpl->LoadFrom( hypdata.c_str() );
4186 hypDataList.push_back( make_pair( myImpl, hypdata ));
4187 CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
4188 int newId = myStudyContext->findId( iorString.in() );
4189 myStudyContext->mapOldToNew( id, newId );
4192 if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
4196 // close algorithms root HDF group
4197 aTopGroup->CloseOnDisk();
4201 // --> the rest groups should be meshes
4202 for ( int i = 0; i < aNbGroups; i++ ) {
4203 // identify next group
4204 char meshName[ HDF_NAME_MAX_LEN+1 ];
4205 aFile->InternalObjectIndentify( i, meshName );
4207 if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
4209 int id = atoi( string( meshName ).substr( 4 ).c_str() );
4213 // open mesh HDF group
4214 aTopGroup = new HDFgroup( meshName, aFile );
4215 aTopGroup->OpenOnDisk();
4217 // get number of child HDF objects
4218 int aNbObjects = aTopGroup->nInternalObjects();
4219 if ( aNbObjects > 0 ) {
4221 if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
4222 SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
4223 SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
4224 if ( !myNewMeshImpl )
4226 meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
4228 CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh );
4229 int newId = myStudyContext->findId( iorString.in() );
4230 myStudyContext->mapOldToNew( id, newId );
4233 // try to read and set auto color flag
4234 char aMeshAutoColorName[ 30 ];
4235 sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
4236 if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
4238 aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
4239 aDataset->OpenOnDisk();
4240 size = aDataset->GetSize();
4241 int* anAutoColor = new int[ size ];
4242 aDataset->ReadFromDisk( anAutoColor );
4243 aDataset->CloseOnDisk();
4244 myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
4245 delete [] anAutoColor;
4248 // try to read and set reference to shape
4249 GEOM::GEOM_Object_var aShapeObject;
4250 if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
4251 // load mesh "Ref on shape" - it's an entry to SObject
4252 aDataset = new HDFdataset( "Ref on shape", aTopGroup );
4253 aDataset->OpenOnDisk();
4254 size = aDataset->GetSize();
4255 char* refFromFile = new char[ size ];
4256 aDataset->ReadFromDisk( refFromFile );
4257 aDataset->CloseOnDisk();
4258 if ( strlen( refFromFile ) > 0 ) {
4259 SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4261 // Make sure GEOM data are loaded first
4262 //loadGeomData( shapeSO->GetFatherComponent() );
4264 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4265 if ( !CORBA::is_nil( shapeObject ) ) {
4266 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4267 if ( !aShapeObject->_is_nil() )
4268 myNewMeshImpl->SetShape( aShapeObject );
4271 delete [] refFromFile;
4274 // issue 20918. Restore Persistent Id of SMESHDS_Mesh
4275 if( aTopGroup->ExistInternalObject( "meshPersistentId" ) )
4277 aDataset = new HDFdataset( "meshPersistentId", aTopGroup );
4278 aDataset->OpenOnDisk();
4279 size = aDataset->GetSize();
4280 int* meshPersistentId = new int[ size ];
4281 aDataset->ReadFromDisk( meshPersistentId );
4282 aDataset->CloseOnDisk();
4283 myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
4284 delete [] meshPersistentId;
4290 // As all object that can be referred by hypothesis are created,
4291 // we can restore hypothesis data
4293 list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
4294 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4296 SMESH_Hypothesis_i* hyp = hyp_data->first;
4297 string & data = hyp_data->second;
4298 hyp->LoadFrom( data.c_str() );
4301 // Restore the rest mesh data
4303 list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
4304 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4306 aTopGroup = meshi_group->second;
4307 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4308 //::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4309 //SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
4311 GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
4312 bool hasData = false;
4315 CORBA::String_var iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
4316 int newId = myStudyContext->findId( iorString.in() );
4317 int id = myStudyContext->getOldId( newId );
4319 // try to find mesh data dataset
4320 if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
4321 // load mesh "has data" flag
4322 aDataset = new HDFdataset( "Has data", aTopGroup );
4323 aDataset->OpenOnDisk();
4324 size = aDataset->GetSize();
4325 char* strHasData = new char[ size ];
4326 aDataset->ReadFromDisk( strHasData );
4327 aDataset->CloseOnDisk();
4328 if ( strcmp( strHasData, "1") == 0 ) {
4329 // read mesh data from MED file
4330 // myReader.SetMesh( mySMESHDSMesh );
4331 // myReader.SetMeshId( id );
4332 // myReader.Perform();
4335 delete [] strHasData;
4338 // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
4339 // nodes and elements are not yet put into sub-meshes)
4340 if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4341 aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
4342 aGroup->OpenOnDisk();
4343 // get number of applied algorithms
4344 int aNbSubObjects = aGroup->nInternalObjects();
4345 if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
4346 for ( int j = 0; j < aNbSubObjects; j++ ) {
4347 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4348 aGroup->InternalObjectIndentify( j, name_dataset );
4349 // check if it is an algorithm
4350 if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
4351 aDataset = new HDFdataset( name_dataset, aGroup );
4352 aDataset->OpenOnDisk();
4353 size = aDataset->GetSize();
4354 char* refFromFile = new char[ size ];
4355 aDataset->ReadFromDisk( refFromFile );
4356 aDataset->CloseOnDisk();
4357 // san - it is impossible to recover applied algorithms using their entries within Load() method
4358 //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
4359 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4360 int id = atoi( refFromFile );
4361 delete [] refFromFile;
4362 string anIOR = myStudyContext->getIORbyOldId( id );
4363 if ( !anIOR.empty() ) {
4364 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4365 if ( !CORBA::is_nil( hypObject ) ) {
4366 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4367 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4368 || !myNewMeshImpl->HasShapeToMesh()) )
4369 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4374 aGroup->CloseOnDisk();
4377 // try to get applied hypotheses
4378 if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4379 aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
4380 aGroup->OpenOnDisk();
4381 // get number of applied hypotheses
4382 int aNbSubObjects = aGroup->nInternalObjects();
4383 for ( int j = 0; j < aNbSubObjects; j++ ) {
4384 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4385 aGroup->InternalObjectIndentify( j, name_dataset );
4386 // check if it is a hypothesis
4387 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4388 aDataset = new HDFdataset( name_dataset, aGroup );
4389 aDataset->OpenOnDisk();
4390 size = aDataset->GetSize();
4391 char* refFromFile = new char[ size ];
4392 aDataset->ReadFromDisk( refFromFile );
4393 aDataset->CloseOnDisk();
4394 // san - it is impossible to recover applied hypotheses using their entries within Load() method
4395 //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
4396 //CORBA::Object_var hypObject = SObjectToObject( hypSO );
4397 int id = atoi( refFromFile );
4398 delete [] refFromFile;
4399 string anIOR = myStudyContext->getIORbyOldId( id );
4400 if ( !anIOR.empty() ) {
4401 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4402 if ( !CORBA::is_nil( hypObject ) ) {
4403 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4404 if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
4405 || !myNewMeshImpl->HasShapeToMesh()) )
4406 myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
4411 aGroup->CloseOnDisk();
4414 // --> try to find SUB-MESHES containers for each type of submesh
4415 for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
4416 const char* name_meshgroup;
4417 if ( j == GetSubMeshOnVertexTag() )
4418 name_meshgroup = "SubMeshes On Vertex";
4419 else if ( j == GetSubMeshOnEdgeTag() )
4420 name_meshgroup = "SubMeshes On Edge";
4421 else if ( j == GetSubMeshOnWireTag() )
4422 name_meshgroup = "SubMeshes On Wire";
4423 else if ( j == GetSubMeshOnFaceTag() )
4424 name_meshgroup = "SubMeshes On Face";
4425 else if ( j == GetSubMeshOnShellTag() )
4426 name_meshgroup = "SubMeshes On Shell";
4427 else if ( j == GetSubMeshOnSolidTag() )
4428 name_meshgroup = "SubMeshes On Solid";
4429 else if ( j == GetSubMeshOnCompoundTag() )
4430 name_meshgroup = "SubMeshes On Compound";
4432 // try to get submeshes container HDF group
4433 if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
4434 // open submeshes containers HDF group
4435 aGroup = new HDFgroup( name_meshgroup, aTopGroup );
4436 aGroup->OpenOnDisk();
4438 // get number of submeshes
4439 int aNbSubMeshes = aGroup->nInternalObjects();
4440 for ( int k = 0; k < aNbSubMeshes; k++ ) {
4442 char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
4443 aGroup->InternalObjectIndentify( k, name_submeshgroup );
4444 if ( strncmp( name_submeshgroup, "SubMesh", 7 ) == 0 ) {
4445 // --> get submesh id
4446 int subid = atoi( name_submeshgroup + 7 );
4449 // open submesh HDF group
4450 aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
4451 aSubGroup->OpenOnDisk();
4453 // try to read and set reference to subshape
4454 GEOM::GEOM_Object_var aSubShapeObject;
4455 SMESH::SMESH_subMesh_var aSubMesh;
4457 if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
4458 // load submesh "Ref on shape" - it's an entry to SObject
4459 aDataset = new HDFdataset( "Ref on shape", aSubGroup );
4460 aDataset->OpenOnDisk();
4461 size = aDataset->GetSize();
4462 char* refFromFile = new char[ size ];
4463 aDataset->ReadFromDisk( refFromFile );
4464 aDataset->CloseOnDisk();
4465 if ( strlen( refFromFile ) > 0 ) {
4466 SALOMEDS::SObject_wrap subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
4467 CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
4468 if ( !CORBA::is_nil( subShapeObject ) ) {
4469 aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
4470 if ( !aSubShapeObject->_is_nil() )
4471 aSubMesh = SMESH::SMESH_subMesh::_duplicate
4472 ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
4473 if ( aSubMesh->_is_nil() )
4475 string iorSubString = GetORB()->object_to_string( aSubMesh );
4476 int newSubId = myStudyContext->findId( iorSubString );
4477 myStudyContext->mapOldToNew( subid, newSubId );
4482 if ( aSubMesh->_is_nil() )
4485 // try to get applied algorithms
4486 if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
4487 // open "applied algorithms" HDF group
4488 aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
4489 aSubSubGroup->OpenOnDisk();
4490 // get number of applied algorithms
4491 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4492 for ( int l = 0; l < aNbSubObjects; l++ ) {
4493 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4494 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4495 // check if it is an algorithm
4496 if ( strncmp( name_dataset, "Algo", 4 ) == 0 ) {
4497 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4498 aDataset->OpenOnDisk();
4499 size = aDataset->GetSize();
4500 char* refFromFile = new char[ size ];
4501 aDataset->ReadFromDisk( refFromFile );
4502 aDataset->CloseOnDisk();
4504 int id = atoi( refFromFile );
4505 string anIOR = myStudyContext->getIORbyOldId( id );
4506 if ( !anIOR.empty() ) {
4507 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4508 if ( !CORBA::is_nil( hypObject ) ) {
4509 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4510 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4511 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4516 // close "applied algorithms" HDF group
4517 aSubSubGroup->CloseOnDisk();
4520 // try to get applied hypotheses
4521 if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
4522 // open "applied hypotheses" HDF group
4523 aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
4524 aSubSubGroup->OpenOnDisk();
4525 // get number of applied hypotheses
4526 int aNbSubObjects = aSubSubGroup->nInternalObjects();
4527 for ( int l = 0; l < aNbSubObjects; l++ ) {
4528 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4529 aSubSubGroup->InternalObjectIndentify( l, name_dataset );
4530 // check if it is a hypothesis
4531 if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
4532 aDataset = new HDFdataset( name_dataset, aSubSubGroup );
4533 aDataset->OpenOnDisk();
4534 size = aDataset->GetSize();
4535 char* refFromFile = new char[ size ];
4536 aDataset->ReadFromDisk( refFromFile );
4537 aDataset->CloseOnDisk();
4539 int id = atoi( refFromFile );
4540 string anIOR = myStudyContext->getIORbyOldId( id );
4541 if ( !anIOR.empty() ) {
4542 CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
4543 if ( !CORBA::is_nil( hypObject ) ) {
4544 SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
4545 if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
4546 myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
4551 // close "APPLIED HYPOTHESES" hdf group
4552 aSubSubGroup->CloseOnDisk();
4555 // close SUB-MESH hdf group
4556 aSubGroup->CloseOnDisk();
4559 // close SUB-MESHES containers hdf group
4560 aGroup->CloseOnDisk();
4564 // try to get GROUPS
4565 for ( int ii = GetNodeGroupsTag(); ii <= GetBallElementsGroupsTag(); ii++ ) {
4566 char name_group[ 30 ];
4567 if ( ii == GetNodeGroupsTag() )
4568 strcpy( name_group, "Groups of Nodes" );
4569 else if ( ii == GetEdgeGroupsTag() )
4570 strcpy( name_group, "Groups of Edges" );
4571 else if ( ii == GetFaceGroupsTag() )
4572 strcpy( name_group, "Groups of Faces" );
4573 else if ( ii == GetVolumeGroupsTag() )
4574 strcpy( name_group, "Groups of Volumes" );
4575 else if ( ii == Get0DElementsGroupsTag() )
4576 strcpy( name_group, "Groups of 0D Elements" );
4577 else if ( ii == GetBallElementsGroupsTag() )
4578 strcpy( name_group, "Groups of Balls" );
4580 if ( aTopGroup->ExistInternalObject( name_group ) ) {
4581 aGroup = new HDFgroup( name_group, aTopGroup );
4582 aGroup->OpenOnDisk();
4583 // get number of groups
4584 int aNbSubObjects = aGroup->nInternalObjects();
4585 for ( int j = 0; j < aNbSubObjects; j++ ) {
4586 char name_dataset[ HDF_NAME_MAX_LEN+1 ];
4587 aGroup->InternalObjectIndentify( j, name_dataset );
4588 // check if it is an group
4589 if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
4591 int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
4594 aDataset = new HDFdataset( name_dataset, aGroup );
4595 aDataset->OpenOnDisk();
4597 // Retrieve actual group name
4598 size = aDataset->GetSize();
4599 char* nameFromFile = new char[ size ];
4600 aDataset->ReadFromDisk( nameFromFile );
4601 aDataset->CloseOnDisk();
4603 // Try to find a shape reference
4604 TopoDS_Shape aShape;
4605 char aRefName[ 30 ];
4606 sprintf( aRefName, "Ref on shape %d", subid);
4607 if ( aGroup->ExistInternalObject( aRefName ) ) {
4608 // load mesh "Ref on shape" - it's an entry to SObject
4609 aDataset = new HDFdataset( aRefName, aGroup );
4610 aDataset->OpenOnDisk();
4611 size = aDataset->GetSize();
4612 char* refFromFile = new char[ size ];
4613 aDataset->ReadFromDisk( refFromFile );
4614 aDataset->CloseOnDisk();
4615 if ( strlen( refFromFile ) > 0 ) {
4616 SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
4617 CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
4618 if ( !CORBA::is_nil( shapeObject ) ) {
4619 aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
4620 if ( !aShapeObject->_is_nil() )
4621 aShape = GeomObjectToShape( aShapeObject );
4625 // Try to read a filter of SMESH_GroupOnFilter
4626 SMESH::Filter_var filter;
4627 SMESH_PredicatePtr predicate;
4628 std::string hdfGrpName = "Filter " + SMESH_Comment(subid);
4629 if ( aGroup->ExistInternalObject( hdfGrpName.c_str() ))
4631 aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup );
4632 aDataset->OpenOnDisk();
4633 size = aDataset->GetSize();
4634 char* persistStr = new char[ size ];
4635 aDataset->ReadFromDisk( persistStr );
4636 aDataset->CloseOnDisk();
4637 if ( strlen( persistStr ) > 0 ) {
4638 filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
4639 predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
4643 // Create group servant
4644 SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
4645 SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
4646 ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) );
4647 // Obtain a SMESHDS_Group object
4648 if ( aNewGroup->_is_nil() )
4651 string iorSubString = GetORB()->object_to_string( aNewGroup );
4652 int newSubId = myStudyContext->findId( iorSubString );
4653 myStudyContext->mapOldToNew( subid, newSubId );
4655 SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
4659 if ( SMESH_GroupOnFilter_i* aFilterGroup =
4660 dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
4662 aFilterGroup->SetFilter( filter );
4663 filter->UnRegister();
4665 SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
4666 if ( !aGroupBaseDS )
4669 aGroupBaseDS->SetStoreName( name_dataset );
4672 // Read color of the group
4673 char aGroupColorName[ 30 ];
4674 sprintf( aGroupColorName, "ColorGroup %d", subid);
4675 if ( aGroup->ExistInternalObject( aGroupColorName ) )
4677 aDataset = new HDFdataset( aGroupColorName, aGroup );
4678 aDataset->OpenOnDisk();
4679 size = aDataset->GetSize();
4680 double* anRGB = new double[ size ];
4681 aDataset->ReadFromDisk( anRGB );
4682 aDataset->CloseOnDisk();
4683 Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
4684 aGroupBaseDS->SetColor( aColor );
4687 // Fill group with contents from MED file
4688 // SMESHDS_Group* aGrp = dynamic_cast<SMESHDS_Group*>( aGroupBaseDS );
4690 // myReader.GetGroup( aGrp );
4693 aGroup->CloseOnDisk();
4697 // instead of reading mesh data, we read only brief information of all
4698 // objects: mesh, groups, sub-meshes (issue 0021208 )
4701 SMESH_PreMeshInfo::LoadFromFile( myNewMeshImpl, id,
4702 meshfile.ToCString(), filename.ToCString(),
4706 // read Sub-Mesh ORDER if any
4707 if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
4708 aDataset = new HDFdataset( "Mesh Order", aTopGroup );
4709 aDataset->OpenOnDisk();
4710 size = aDataset->GetSize();
4711 int* smIDs = new int[ size ];
4712 aDataset->ReadFromDisk( smIDs );
4713 aDataset->CloseOnDisk();
4714 TListOfListOfInt anOrderIds;
4715 anOrderIds.push_back( TListOfInt() );
4716 for ( int i = 0; i < size; i++ )
4717 if ( smIDs[ i ] < 0 ) // is separator
4718 anOrderIds.push_back( TListOfInt() );
4720 anOrderIds.back().push_back(smIDs[ i ]);
4722 myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
4726 // update hyps needing full mesh data restored (issue 20918)
4727 for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
4729 SMESH_Hypothesis_i* hyp = hyp_data->first;
4730 hyp->UpdateAsMeshesRestored();
4733 // notify algos on completed restoration to set sub-mesh event listeners
4734 for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
4736 SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
4737 ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
4739 TopoDS_Shape myLocShape;
4740 if(myLocMesh.HasShapeToMesh())
4741 myLocShape = myLocMesh.GetShapeToMesh();
4743 myLocShape = SMESH_Mesh::PseudoShape();
4745 myLocMesh.GetSubMesh(myLocShape)->
4746 ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
4751 aTopGroup->CloseOnDisk();
4754 aFile->CloseOnDisk();
4757 // Remove temporary files created from the stream
4760 SMESH_File meshFile( meshfile.ToCString() );
4761 if ( !meshFile ) // no meshfile exists
4763 SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
4767 Engines::Container_var container = GetContainerRef();
4768 if ( Engines_Container_i* container_i = SMESH::DownCast<Engines_Container_i*>( container ))
4770 container_i->registerTemporaryFile( filename.ToCString() );
4771 container_i->registerTemporaryFile( meshfile.ToCString() );
4772 container_i->registerTemporaryFile( tmpDir.ToCString() );
4776 pd << ""; // prevent optimizing pd out
4778 // creation of tree nodes for all data objects in the study
4779 // to support tree representation customization and drag-n-drop:
4780 SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = theComponent->GetStudy()->GetUseCaseBuilder();
4781 if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
4782 useCaseBuilder->SetRootCurrent();
4783 useCaseBuilder->Append( theComponent ); // component object is added as the top level item
4784 SALOMEDS::ChildIterator_wrap it = theComponent->GetStudy()->NewChildIterator( theComponent );
4785 for (it->InitEx(true); it->More(); it->Next()) {
4786 useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
4790 INFOS( "SMESH_Gen_i::Load completed" );
4794 //=============================================================================
4796 * SMESH_Gen_i::LoadASCII
4798 * Load SMESH module's data in ASCII format
4800 //=============================================================================
4802 bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
4803 const SALOMEDS::TMPFile& theStream,
4805 bool isMultiFile ) {
4806 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
4807 return Load( theComponent, theStream, theURL, isMultiFile );
4809 //before call main ::Load method it's need for decipher text format to
4810 //binary ( "|xx" => x' )
4811 int size = theStream.length();
4812 if ( int((size / 3 )*3) != size ) //error size of buffer
4815 int real_size = int(size / 3);
4817 _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
4821 for ( int i = 0; i < real_size; i++ )
4823 memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
4824 sscanf( tmp, "%x", &c );
4825 sprintf( (char*)&(buffer[i]), "%c", (char)c );
4828 SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
4830 return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
4833 //=============================================================================
4835 * SMESH_Gen_i::Close
4837 * Clears study-connected data when it is closed
4839 //=============================================================================
4841 void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
4843 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
4845 // set correct current study
4846 SALOMEDS::Study_var study = theComponent->GetStudy();
4847 if ( study->StudyId() != GetCurrentStudyID())
4848 setCurrentStudy( study, /*IsBeingClosed=*/true );
4850 // Clear study contexts data
4851 int studyId = GetCurrentStudyID();
4852 if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
4853 delete myStudyContextMap[ studyId ];
4854 myStudyContextMap.erase( studyId );
4857 // remove the tmp files meshes are loaded from
4858 SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
4860 myCurrentStudy = SALOMEDS::Study::_nil();
4864 //=============================================================================
4866 * SMESH_Gen_i::ComponentDataType
4868 * Get component data type
4870 //=============================================================================
4872 char* SMESH_Gen_i::ComponentDataType()
4874 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
4875 return CORBA::string_dup( "SMESH" );
4879 //=============================================================================
4881 * SMESH_Gen_i::IORToLocalPersistentID
4883 * Transform data from transient form to persistent
4885 //=============================================================================
4887 char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
4888 const char* IORString,
4889 CORBA::Boolean /*isMultiFile*/,
4890 CORBA::Boolean /*isASCII*/ )
4892 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
4893 StudyContext* myStudyContext = GetCurrentStudyContext();
4895 if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
4896 int anId = myStudyContext->findId( IORString );
4898 if(MYDEBUG) MESSAGE( "VSR " << anId )
4900 sprintf( strId, "%d", anId );
4901 return CORBA::string_dup( strId );
4904 return CORBA::string_dup( "" );
4907 //=============================================================================
4909 * SMESH_Gen_i::LocalPersistentIDToIOR
4911 * Transform data from persistent form to transient
4913 //=============================================================================
4915 char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
4916 const char* aLocalPersistentID,
4917 CORBA::Boolean /*isMultiFile*/,
4918 CORBA::Boolean /*isASCII*/ )
4920 if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
4921 StudyContext* myStudyContext = GetCurrentStudyContext();
4923 if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
4924 int anId = atoi( aLocalPersistentID );
4925 return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
4927 return CORBA::string_dup( "" );
4930 //=======================================================================
4931 //function : RegisterObject
4933 //=======================================================================
4935 int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
4937 StudyContext* myStudyContext = GetCurrentStudyContext();
4938 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4939 CORBA::String_var iorString = GetORB()->object_to_string( theObject );
4940 return myStudyContext->addObject( string( iorString.in() ) );
4945 //================================================================================
4947 * \brief Return id of registered object
4948 * \param theObject - the Object
4949 * \retval int - Object id
4951 //================================================================================
4953 CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
4955 StudyContext* myStudyContext = GetCurrentStudyContext();
4956 if ( myStudyContext && !CORBA::is_nil( theObject )) {
4957 string iorString = GetORB()->object_to_string( theObject );
4958 return myStudyContext->findId( iorString );
4963 //=============================================================================
4965 * SMESH_Gen_i::SetName
4967 * Set a new object name
4969 //=============================================================================
4970 void SMESH_Gen_i::SetName(const char* theIOR,
4971 const char* theName)
4973 if ( theIOR && strcmp( theIOR, "" ) ) {
4974 CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
4975 SALOMEDS::SObject_wrap aSO = ObjectToSObject( myCurrentStudy, anObject );
4976 if ( !aSO->_is_nil() ) {
4977 SetName( aSO, theName );
4982 int SMESH_Gen_i::GetCurrentStudyID()
4984 return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
4987 // Version information
4988 char* SMESH_Gen_i::getVersion()
4990 #if SMESH_DEVELOPMENT
4991 return CORBA::string_dup(SMESH_VERSION_STR"dev");
4993 return CORBA::string_dup(SMESH_VERSION_STR);
4997 //=================================================================================
4998 // function : Move()
4999 // purpose : Moves objects to the specified position.
5000 // Is used in the drag-n-drop functionality.
5001 //=================================================================================
5002 void SMESH_Gen_i::Move( const SMESH::sobject_list& what,
5003 SALOMEDS::SObject_ptr where,
5006 if ( CORBA::is_nil( where ) ) return;
5008 SALOMEDS::Study_var study = where->GetStudy();
5009 SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
5010 SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
5011 SALOMEDS::SComponent_var father = where->GetFatherComponent();
5012 std::string dataType = father->ComponentDataType();
5013 if ( dataType != "SMESH" ) return; // not a SMESH component
5015 SALOMEDS::SObject_var objAfter;
5016 if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
5017 // insert at given row -> find insertion position
5018 SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
5020 for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
5021 if ( i == row && useCaseIt->More() ) {
5022 objAfter = useCaseIt->Value();
5026 for ( int i = 0; i < what.length(); i++ ) {
5027 SALOMEDS::SObject_var sobj = what[i];
5028 if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
5029 // insert the object to the use case tree
5030 if ( !CORBA::is_nil( objAfter ) )
5031 useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
5033 useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
5037 //=============================================================================
5039 * SMESHEngine_factory
5041 * C factory, accessible with dlsym, after dlopen
5043 //=============================================================================
5047 PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
5048 PortableServer::POA_ptr poa,
5049 PortableServer::ObjectId* contId,
5050 const char* instanceName,
5051 const char* interfaceName )
5053 if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
5054 if(MYDEBUG) SCRUTE(interfaceName);
5055 SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
5056 return aSMESHGen->getId() ;