+ if ( theComponent->GetStudy()->StudyId() != GetCurrentStudyID() )
+ SetCurrentStudy( theComponent->GetStudy() );
+
+ /* if( !theComponent->_is_nil() )
+ {
+ //SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( theComponent->GetStudy() );
+ if( !myCurrentStudy->FindComponent( "GEOM" )->_is_nil() )
+ loadGeomData( myCurrentStudy->FindComponent( "GEOM" ) );
+ }*/
+
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+
+ // Get temporary files location
+ TCollection_AsciiString tmpDir =
+ ( char* )( isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir().c_str() );
+
+ // Convert the stream into sequence of files to process
+ SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream,
+ tmpDir.ToCString(),
+ isMultiFile );
+ TCollection_AsciiString aStudyName( "" );
+ if ( isMultiFile ) {
+ CORBA::String_var url = myCurrentStudy->URL();
+ aStudyName = (char*)SALOMEDS_Tool::GetNameFromPath( url.in() ).c_str();
+ }
+ // Set names of temporary files
+ TCollection_AsciiString filename = tmpDir + aStudyName + "_SMESH.hdf";
+ TCollection_AsciiString meshfile = tmpDir + aStudyName + "_SMESH_Mesh.med";
+
+ int size;
+ HDFfile* aFile;
+ HDFdataset* aDataset;
+ HDFgroup* aTopGroup;
+ HDFgroup* aGroup;
+ HDFgroup* aSubGroup;
+ HDFgroup* aSubSubGroup;
+
+ // Read data
+ // ---> open HDF file
+ aFile = new HDFfile( (char*) filename.ToCString() );
+ try {
+ aFile->OpenOnDisk( HDF_RDONLY );
+ }
+ catch ( HDFexception ) {
+ INFOS( "Load(): " << filename << " not found!" );
+ return false;
+ }
+
+ TPythonDump pd; // prevent dump during loading
+
+ // DriverMED_R_SMESHDS_Mesh myReader;
+ // myReader.SetFile( meshfile.ToCString() );
+
+ // For PAL13473 ("Repetitive mesh") implementation.
+ // New dependencies between SMESH objects are established:
+ // now hypotheses can refer to meshes, shapes and other hypotheses.
+ // To keep data consistent, the following order of data restoration
+ // imposed:
+ // 1. Create hypotheses
+ // 2. Create all meshes
+ // 3. Load hypotheses' data
+ // 4. All the rest
+
+ list< pair< SMESH_Hypothesis_i*, string > > hypDataList;
+ list< pair< SMESH_Mesh_i*, HDFgroup* > > meshGroupList;
+ list< SMESH::Filter_var > filters;
+
+ // get total number of top-level groups
+ int aNbGroups = aFile->nInternalObjects();
+ if ( aNbGroups > 0 ) {
+ // --> in first turn we should read&create hypotheses
+ if ( aFile->ExistInternalObject( "Hypotheses" ) ) {
+ // open hypotheses root HDF group
+ aTopGroup = new HDFgroup( "Hypotheses", aFile );
+ aTopGroup->OpenOnDisk();
+
+ // get number of hypotheses
+ int aNbObjects = aTopGroup->nInternalObjects();
+ for ( int j = 0; j < aNbObjects; j++ ) {
+ // try to identify hypothesis
+ char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
+ aTopGroup->InternalObjectIndentify( j, hypGrpName );
+
+ if ( string( hypGrpName ).substr( 0, 10 ) == string( "Hypothesis" ) ) {
+ // open hypothesis group
+ aGroup = new HDFgroup( hypGrpName, aTopGroup );
+ aGroup->OpenOnDisk();
+
+ // --> get hypothesis id
+ int id = atoi( string( hypGrpName ).substr( 10 ).c_str() );
+ string hypname;
+ string libname;
+ string hypdata;
+
+ // get number of datasets
+ int aNbSubObjects = aGroup->nInternalObjects();
+ for ( int k = 0; k < aNbSubObjects; k++ ) {
+ // identify dataset
+ char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( k, name_of_subgroup );
+ // --> get hypothesis name
+ if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
+ aDataset = new HDFdataset( name_of_subgroup, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* hypname_str = new char[ size ];
+ aDataset->ReadFromDisk( hypname_str );
+ hypname = string( hypname_str );
+ delete [] hypname_str;
+ aDataset->CloseOnDisk();
+ }
+ // --> get hypothesis plugin library name
+ if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
+ aDataset = new HDFdataset( name_of_subgroup, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* libname_str = new char[ size ];
+ aDataset->ReadFromDisk( libname_str );
+ if(MYDEBUG) SCRUTE( libname_str );
+ libname = string( libname_str );
+ delete [] libname_str;
+ aDataset->CloseOnDisk();
+ }
+ // --> get hypothesis data
+ if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
+ aDataset = new HDFdataset( name_of_subgroup, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* hypdata_str = new char[ size ];
+ aDataset->ReadFromDisk( hypdata_str );
+ hypdata = string( hypdata_str );
+ delete [] hypdata_str;
+ aDataset->CloseOnDisk();
+ }
+ }
+ // close hypothesis HDF group
+ aGroup->CloseOnDisk();
+
+ // --> restore hypothesis from data
+ if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
+ if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id <<
+ ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
+ SMESH::SMESH_Hypothesis_var myHyp;
+
+ try { // protect persistence mechanism against exceptions
+ myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
+ }
+ catch (...) {
+ INFOS( "Exception during hypothesis creation" );
+ }
+
+ SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
+ if ( myImpl ) {
+ // myImpl->LoadFrom( hypdata.c_str() );
+ hypDataList.push_back( make_pair( myImpl, hypdata ));
+ CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
+ int newId = myStudyContext->findId( iorString.in() );
+ myStudyContext->mapOldToNew( id, newId );
+ }
+ else
+ if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
+ }
+ }
+ }
+ // close hypotheses root HDF group
+ aTopGroup->CloseOnDisk();
+ aTopGroup = 0;
+ }
+
+ // --> then we should read&create algorithms
+ if ( aFile->ExistInternalObject( "Algorithms" ) ) {
+ // open algorithms root HDF group
+ aTopGroup = new HDFgroup( "Algorithms", aFile );
+ aTopGroup->OpenOnDisk();
+
+ // get number of algorithms
+ int aNbObjects = aTopGroup->nInternalObjects();
+ for ( int j = 0; j < aNbObjects; j++ ) {
+ // try to identify algorithm
+ char hypGrpName[ HDF_NAME_MAX_LEN+1 ];
+ aTopGroup->InternalObjectIndentify( j, hypGrpName );
+
+ if ( string( hypGrpName ).substr( 0, 9 ) == string( "Algorithm" ) ) {
+ // open algorithm group
+ aGroup = new HDFgroup( hypGrpName, aTopGroup );
+ aGroup->OpenOnDisk();
+
+ // --> get algorithm id
+ int id = atoi( string( hypGrpName ).substr( 9 ).c_str() );
+ string hypname;
+ string libname;
+ string hypdata;
+
+ // get number of datasets
+ int aNbSubObjects = aGroup->nInternalObjects();
+ for ( int k = 0; k < aNbSubObjects; k++ ) {
+ // identify dataset
+ char name_of_subgroup[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( k, name_of_subgroup );
+ // --> get algorithm name
+ if ( strcmp( name_of_subgroup, "Name" ) == 0 ) {
+ aDataset = new HDFdataset( name_of_subgroup, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* hypname_str = new char[ size ];
+ aDataset->ReadFromDisk( hypname_str );
+ hypname = string( hypname_str );
+ delete [] hypname_str;
+ aDataset->CloseOnDisk();
+ }
+ // --> get algorithm plugin library name
+ if ( strcmp( name_of_subgroup, "LibName" ) == 0 ) {
+ aDataset = new HDFdataset( name_of_subgroup, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* libname_str = new char[ size ];
+ aDataset->ReadFromDisk( libname_str );
+ if(MYDEBUG) SCRUTE( libname_str );
+ libname = string( libname_str );
+ delete [] libname_str;
+ aDataset->CloseOnDisk();
+ }
+ // --> get algorithm data
+ if ( strcmp( name_of_subgroup, "Data" ) == 0 ) {
+ aDataset = new HDFdataset( name_of_subgroup, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* hypdata_str = new char[ size ];
+ aDataset->ReadFromDisk( hypdata_str );
+ if(MYDEBUG) SCRUTE( hypdata_str );
+ hypdata = string( hypdata_str );
+ delete [] hypdata_str;
+ aDataset->CloseOnDisk();
+ }
+ }
+ // close algorithm HDF group
+ aGroup->CloseOnDisk();
+
+ // --> restore algorithm from data
+ if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty
+ if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id <<
+ ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str());
+ SMESH::SMESH_Hypothesis_var myHyp;
+
+ try { // protect persistence mechanism against exceptions
+ myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() );
+ }
+ catch (...) {
+ INFOS( "Exception during hypothesis creation" );
+ }
+
+ SMESH_Hypothesis_i* myImpl = dynamic_cast<SMESH_Hypothesis_i*>( GetServant( myHyp ).in() );
+ if ( myImpl ) {
+ //myImpl->LoadFrom( hypdata.c_str() );
+ hypDataList.push_back( make_pair( myImpl, hypdata ));
+ CORBA::String_var iorString = GetORB()->object_to_string( myHyp );
+ int newId = myStudyContext->findId( iorString.in() );
+ myStudyContext->mapOldToNew( id, newId );
+ }
+ else
+ if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" );
+ }
+ }
+ }
+ // close algorithms root HDF group
+ aTopGroup->CloseOnDisk();
+ aTopGroup = 0;
+ }
+
+ // --> the rest groups should be meshes
+ for ( int i = 0; i < aNbGroups; i++ ) {
+ // identify next group
+ char meshName[ HDF_NAME_MAX_LEN+1 ];
+ aFile->InternalObjectIndentify( i, meshName );
+
+ if ( string( meshName ).substr( 0, 4 ) == string( "Mesh" ) ) {
+ // --> get mesh id
+ int id = atoi( string( meshName ).substr( 4 ).c_str() );
+ if ( id <= 0 )
+ continue;
+
+ // open mesh HDF group
+ aTopGroup = new HDFgroup( meshName, aFile );
+ aTopGroup->OpenOnDisk();
+
+ // get number of child HDF objects
+ int aNbObjects = aTopGroup->nInternalObjects();
+ if ( aNbObjects > 0 ) {
+ // create mesh
+ if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id );
+ SMESH::SMESH_Mesh_var myNewMesh = this->createMesh();
+ SMESH_Mesh_i* myNewMeshImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( myNewMesh ).in() );
+ if ( !myNewMeshImpl )
+ continue;
+ meshGroupList.push_back( make_pair( myNewMeshImpl, aTopGroup ));
+
+ CORBA::String_var iorString = GetORB()->object_to_string( myNewMesh );
+ int newId = myStudyContext->findId( iorString.in() );
+ myStudyContext->mapOldToNew( id, newId );
+
+ // ouv : NPAL12872
+ // try to read and set auto color flag
+ char aMeshAutoColorName[ 30 ];
+ sprintf( aMeshAutoColorName, "AutoColorMesh %d", id);
+ if( aTopGroup->ExistInternalObject( aMeshAutoColorName ) )
+ {
+ aDataset = new HDFdataset( aMeshAutoColorName, aTopGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ int* anAutoColor = new int[ size ];
+ aDataset->ReadFromDisk( anAutoColor );
+ aDataset->CloseOnDisk();
+ myNewMeshImpl->GetImpl().SetAutoColor( (bool)anAutoColor[0] );
+ delete [] anAutoColor;
+ }
+
+ // try to read and set reference to shape
+ GEOM::GEOM_Object_var aShapeObject;
+ if ( aTopGroup->ExistInternalObject( "Ref on shape" ) ) {
+ // load mesh "Ref on shape" - it's an entry to SObject
+ aDataset = new HDFdataset( "Ref on shape", aTopGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+ if ( strlen( refFromFile ) > 0 ) {
+ SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
+
+ // Make sure GEOM data are loaded first
+ //loadGeomData( shapeSO->GetFatherComponent() );
+
+ CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
+ if ( !CORBA::is_nil( shapeObject ) ) {
+ aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
+ if ( !aShapeObject->_is_nil() )
+ myNewMeshImpl->SetShape( aShapeObject );
+ }
+ }
+ delete [] refFromFile;
+ }
+
+ // issue 20918. Restore Persistent Id of SMESHDS_Mesh
+ if( aTopGroup->ExistInternalObject( "meshPersistentId" ) )
+ {
+ aDataset = new HDFdataset( "meshPersistentId", aTopGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ int* meshPersistentId = new int[ size ];
+ aDataset->ReadFromDisk( meshPersistentId );
+ aDataset->CloseOnDisk();
+ myNewMeshImpl->GetImpl().GetMeshDS()->SetPersistentId( *meshPersistentId );
+ delete [] meshPersistentId;
+ }
+ }
+ }
+ } // reading MESHes
+
+ // As all object that can be referred by hypothesis are created,
+ // we can restore hypothesis data
+
+ list< pair< SMESH_Hypothesis_i*, string > >::iterator hyp_data;
+ for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
+ {
+ SMESH_Hypothesis_i* hyp = hyp_data->first;
+ string & data = hyp_data->second;
+ hyp->LoadFrom( data.c_str() );
+ }
+
+ // Restore the rest mesh data
+
+ list< pair< SMESH_Mesh_i*, HDFgroup* > >::iterator meshi_group;
+ for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
+ {
+ aTopGroup = meshi_group->second;
+ SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
+ //::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
+ //SMESHDS_Mesh* mySMESHDSMesh = myLocMesh.GetMeshDS();
+
+ GEOM::GEOM_Object_var aShapeObject = myNewMeshImpl->GetShapeToMesh();
+ bool hasData = false;
+
+ // get mesh old id
+ CORBA::String_var iorString = GetORB()->object_to_string( myNewMeshImpl->_this() );
+ int newId = myStudyContext->findId( iorString.in() );
+ int id = myStudyContext->getOldId( newId );
+
+ // try to find mesh data dataset
+ if ( aTopGroup->ExistInternalObject( "Has data" ) ) {
+ // load mesh "has data" flag
+ aDataset = new HDFdataset( "Has data", aTopGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* strHasData = new char[ size ];
+ aDataset->ReadFromDisk( strHasData );
+ aDataset->CloseOnDisk();
+ if ( strcmp( strHasData, "1") == 0 ) {
+ // read mesh data from MED file
+ // myReader.SetMesh( mySMESHDSMesh );
+ // myReader.SetMeshId( id );
+ // myReader.Perform();
+ hasData = true;
+ }
+ delete [] strHasData;
+ }
+
+ // Try to get applied ALGORITHMS (mesh is not cleared by algo addition because
+ // nodes and elements are not yet put into sub-meshes)
+ if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) {
+ aGroup = new HDFgroup( "Applied Algorithms", aTopGroup );
+ aGroup->OpenOnDisk();
+ // get number of applied algorithms
+ int aNbSubObjects = aGroup->nInternalObjects();
+ if(MYDEBUG) MESSAGE( "VSR - number of applied algos " << aNbSubObjects );
+ for ( int j = 0; j < aNbSubObjects; j++ ) {
+ char name_dataset[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( j, name_dataset );
+ // check if it is an algorithm
+ if ( string( name_dataset ).substr( 0, 4 ) == string( "Algo" ) ) {
+ aDataset = new HDFdataset( name_dataset, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+ // san - it is impossible to recover applied algorithms using their entries within Load() method
+ //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
+ //CORBA::Object_var hypObject = SObjectToObject( hypSO );
+ int id = atoi( refFromFile );
+ delete [] refFromFile;
+ string anIOR = myStudyContext->getIORbyOldId( id );
+ if ( !anIOR.empty() ) {
+ CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
+ if ( !CORBA::is_nil( hypObject ) ) {
+ SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
+ if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
+ || !myNewMeshImpl->HasShapeToMesh()) )
+ myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
+ }
+ }
+ }
+ }
+ aGroup->CloseOnDisk();
+ }
+
+ // try to get applied hypotheses
+ if ( aTopGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
+ aGroup = new HDFgroup( "Applied Hypotheses", aTopGroup );
+ aGroup->OpenOnDisk();
+ // get number of applied hypotheses
+ int aNbSubObjects = aGroup->nInternalObjects();
+ for ( int j = 0; j < aNbSubObjects; j++ ) {
+ char name_dataset[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( j, name_dataset );
+ // check if it is a hypothesis
+ if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
+ aDataset = new HDFdataset( name_dataset, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+ // san - it is impossible to recover applied hypotheses using their entries within Load() method
+ //SALOMEDS::SObject_wrap hypSO = myCurrentStudy->FindObjectID( refFromFile );
+ //CORBA::Object_var hypObject = SObjectToObject( hypSO );
+ int id = atoi( refFromFile );
+ delete [] refFromFile;
+ string anIOR = myStudyContext->getIORbyOldId( id );
+ if ( !anIOR.empty() ) {
+ CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
+ if ( !CORBA::is_nil( hypObject ) ) {
+ SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
+ if ( !anHyp->_is_nil() && (!aShapeObject->_is_nil()
+ || !myNewMeshImpl->HasShapeToMesh()) )
+ myNewMeshImpl->addHypothesis( aShapeObject, anHyp );
+ }
+ }
+ }
+ }
+ aGroup->CloseOnDisk();
+ }
+
+ // --> try to find SUB-MESHES containers for each type of submesh
+ for ( int j = GetSubMeshOnVertexTag(); j <= GetSubMeshOnCompoundTag(); j++ ) {
+ const char* name_meshgroup = 0;
+ if ( j == GetSubMeshOnVertexTag() )
+ name_meshgroup = "SubMeshes On Vertex";
+ else if ( j == GetSubMeshOnEdgeTag() )
+ name_meshgroup = "SubMeshes On Edge";
+ else if ( j == GetSubMeshOnWireTag() )
+ name_meshgroup = "SubMeshes On Wire";
+ else if ( j == GetSubMeshOnFaceTag() )
+ name_meshgroup = "SubMeshes On Face";
+ else if ( j == GetSubMeshOnShellTag() )
+ name_meshgroup = "SubMeshes On Shell";
+ else if ( j == GetSubMeshOnSolidTag() )
+ name_meshgroup = "SubMeshes On Solid";
+ else if ( j == GetSubMeshOnCompoundTag() )
+ name_meshgroup = "SubMeshes On Compound";
+
+ // try to get submeshes container HDF group
+ if ( aTopGroup->ExistInternalObject( name_meshgroup ) ) {
+ // open submeshes containers HDF group
+ aGroup = new HDFgroup( name_meshgroup, aTopGroup );
+ aGroup->OpenOnDisk();
+
+ // get number of submeshes
+ int aNbSubMeshes = aGroup->nInternalObjects();
+ for ( int k = 0; k < aNbSubMeshes; k++ ) {
+ // identify submesh
+ char name_submeshgroup[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( k, name_submeshgroup );
+ if ( strncmp( name_submeshgroup, "SubMesh", 7 ) == 0 ) {
+ // --> get submesh id
+ int subid = atoi( name_submeshgroup + 7 );
+ if ( subid <= 0 )
+ continue;
+ // open submesh HDF group
+ aSubGroup = new HDFgroup( name_submeshgroup, aGroup );
+ aSubGroup->OpenOnDisk();
+
+ // try to read and set reference to subshape
+ GEOM::GEOM_Object_var aSubShapeObject;
+ SMESH::SMESH_subMesh_var aSubMesh;
+
+ if ( aSubGroup->ExistInternalObject( "Ref on shape" ) ) {
+ // load submesh "Ref on shape" - it's an entry to SObject
+ aDataset = new HDFdataset( "Ref on shape", aSubGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+ if ( strlen( refFromFile ) > 0 ) {
+ SALOMEDS::SObject_wrap subShapeSO = myCurrentStudy->FindObjectID( refFromFile );
+ CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO );
+ if ( !CORBA::is_nil( subShapeObject ) ) {
+ aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject );
+ if ( !aSubShapeObject->_is_nil() )
+ aSubMesh = SMESH::SMESH_subMesh::_duplicate
+ ( myNewMeshImpl->createSubMesh( aSubShapeObject ) );
+ if ( aSubMesh->_is_nil() )
+ continue;
+ string iorSubString = GetORB()->object_to_string( aSubMesh );
+ int newSubId = myStudyContext->findId( iorSubString );
+ myStudyContext->mapOldToNew( subid, newSubId );
+ }
+ }
+ }
+
+ if ( aSubMesh->_is_nil() )
+ continue;
+
+ // try to get applied algorithms
+ if ( aSubGroup->ExistInternalObject( "Applied Algorithms" ) ) {
+ // open "applied algorithms" HDF group
+ aSubSubGroup = new HDFgroup( "Applied Algorithms", aSubGroup );
+ aSubSubGroup->OpenOnDisk();
+ // get number of applied algorithms
+ int aNbSubObjects = aSubSubGroup->nInternalObjects();
+ for ( int l = 0; l < aNbSubObjects; l++ ) {
+ char name_dataset[ HDF_NAME_MAX_LEN+1 ];
+ aSubSubGroup->InternalObjectIndentify( l, name_dataset );
+ // check if it is an algorithm
+ if ( strncmp( name_dataset, "Algo", 4 ) == 0 ) {
+ aDataset = new HDFdataset( name_dataset, aSubSubGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+
+ int id = atoi( refFromFile );
+ string anIOR = myStudyContext->getIORbyOldId( id );
+ if ( !anIOR.empty() ) {
+ CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
+ if ( !CORBA::is_nil( hypObject ) ) {
+ SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
+ if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
+ myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
+ }
+ }
+ }
+ }
+ // close "applied algorithms" HDF group
+ aSubSubGroup->CloseOnDisk();
+ }
+
+ // try to get applied hypotheses
+ if ( aSubGroup->ExistInternalObject( "Applied Hypotheses" ) ) {
+ // open "applied hypotheses" HDF group
+ aSubSubGroup = new HDFgroup( "Applied Hypotheses", aSubGroup );
+ aSubSubGroup->OpenOnDisk();
+ // get number of applied hypotheses
+ int aNbSubObjects = aSubSubGroup->nInternalObjects();
+ for ( int l = 0; l < aNbSubObjects; l++ ) {
+ char name_dataset[ HDF_NAME_MAX_LEN+1 ];
+ aSubSubGroup->InternalObjectIndentify( l, name_dataset );
+ // check if it is a hypothesis
+ if ( string( name_dataset ).substr( 0, 3 ) == string( "Hyp" ) ) {
+ aDataset = new HDFdataset( name_dataset, aSubSubGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+
+ int id = atoi( refFromFile );
+ string anIOR = myStudyContext->getIORbyOldId( id );
+ if ( !anIOR.empty() ) {
+ CORBA::Object_var hypObject = GetORB()->string_to_object( anIOR.c_str() );
+ if ( !CORBA::is_nil( hypObject ) ) {
+ SMESH::SMESH_Hypothesis_var anHyp = SMESH::SMESH_Hypothesis::_narrow( hypObject );
+ if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() )
+ myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp );
+ }
+ }
+ }
+ }
+ // close "APPLIED HYPOTHESES" hdf group
+ aSubSubGroup->CloseOnDisk();
+ }
+
+ // close SUB-MESH hdf group
+ aSubGroup->CloseOnDisk();
+ }
+ }
+ // close SUB-MESHES containers hdf group
+ aGroup->CloseOnDisk();
+ }
+ }
+
+ // try to get GROUPS
+ for ( int ii = GetNodeGroupsTag(); ii <= GetBallElementsGroupsTag(); ii++ ) {
+ char name_group[ 30 ];
+ if ( ii == GetNodeGroupsTag() )
+ strcpy( name_group, "Groups of Nodes" );
+ else if ( ii == GetEdgeGroupsTag() )
+ strcpy( name_group, "Groups of Edges" );
+ else if ( ii == GetFaceGroupsTag() )
+ strcpy( name_group, "Groups of Faces" );
+ else if ( ii == GetVolumeGroupsTag() )
+ strcpy( name_group, "Groups of Volumes" );
+ else if ( ii == Get0DElementsGroupsTag() )
+ strcpy( name_group, "Groups of 0D Elements" );
+ else if ( ii == GetBallElementsGroupsTag() )
+ strcpy( name_group, "Groups of Balls" );
+
+ if ( aTopGroup->ExistInternalObject( name_group ) ) {
+ aGroup = new HDFgroup( name_group, aTopGroup );
+ aGroup->OpenOnDisk();
+ // get number of groups
+ int aNbSubObjects = aGroup->nInternalObjects();
+ for ( int j = 0; j < aNbSubObjects; j++ ) {
+ char name_dataset[ HDF_NAME_MAX_LEN+1 ];
+ aGroup->InternalObjectIndentify( j, name_dataset );
+ // check if it is an group
+ if ( string( name_dataset ).substr( 0, 5 ) == string( "Group" ) ) {
+ // --> get group id
+ int subid = atoi( string( name_dataset ).substr( 5 ).c_str() );
+ if ( subid <= 0 )
+ continue;
+ aDataset = new HDFdataset( name_dataset, aGroup );
+ aDataset->OpenOnDisk();
+
+ // Retrieve actual group name
+ size = aDataset->GetSize();
+ char* nameFromFile = new char[ size ];
+ aDataset->ReadFromDisk( nameFromFile );
+ aDataset->CloseOnDisk();
+
+ // Try to find a shape reference
+ TopoDS_Shape aShape;
+ char aRefName[ 30 ];
+ sprintf( aRefName, "Ref on shape %d", subid);
+ if ( aGroup->ExistInternalObject( aRefName ) ) {
+ // load mesh "Ref on shape" - it's an entry to SObject
+ aDataset = new HDFdataset( aRefName, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* refFromFile = new char[ size ];
+ aDataset->ReadFromDisk( refFromFile );
+ aDataset->CloseOnDisk();
+ if ( strlen( refFromFile ) > 0 ) {
+ SALOMEDS::SObject_wrap shapeSO = myCurrentStudy->FindObjectID( refFromFile );
+ CORBA::Object_var shapeObject = SObjectToObject( shapeSO );
+ if ( !CORBA::is_nil( shapeObject ) ) {
+ aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject );
+ if ( !aShapeObject->_is_nil() )
+ aShape = GeomObjectToShape( aShapeObject );
+ }
+ }
+ }
+ // Try to read a filter of SMESH_GroupOnFilter
+ SMESH::Filter_var filter;
+ SMESH_PredicatePtr predicate;
+ std::string hdfGrpName = "Filter " + SMESH_Comment(subid);
+ if ( aGroup->ExistInternalObject( hdfGrpName.c_str() ))
+ {
+ aDataset = new HDFdataset( hdfGrpName.c_str(), aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ char* persistStr = new char[ size ];
+ aDataset->ReadFromDisk( persistStr );
+ aDataset->CloseOnDisk();
+ if ( strlen( persistStr ) > 0 ) {
+ filter = SMESH_GroupOnFilter_i::StringToFilter( persistStr );
+ predicate = SMESH_GroupOnFilter_i::GetPredicate( filter );
+ filters.push_back( filter );
+ }
+ }
+
+ // Create group servant
+ SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1);
+ SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate
+ ( myNewMeshImpl->createGroup( type, nameFromFile, aShape, predicate ) );
+ // Obtain a SMESHDS_Group object
+ if ( aNewGroup->_is_nil() )
+ continue;
+
+ string iorSubString = GetORB()->object_to_string( aNewGroup );
+ int newSubId = myStudyContext->findId( iorSubString );
+ myStudyContext->mapOldToNew( subid, newSubId );
+
+ SMESH_GroupBase_i* aGroupImpl = SMESH::DownCast< SMESH_GroupBase_i*>( aNewGroup );
+ if ( !aGroupImpl )
+ continue;
+
+ if ( SMESH_GroupOnFilter_i* aFilterGroup =
+ dynamic_cast< SMESH_GroupOnFilter_i*>( aGroupImpl ))
+ {
+ aFilterGroup->SetFilter( filter );
+ filter->UnRegister();
+ }
+ SMESHDS_GroupBase* aGroupBaseDS = aGroupImpl->GetGroupDS();
+ if ( !aGroupBaseDS )
+ continue;
+
+ aGroupBaseDS->SetStoreName( name_dataset );
+
+ // ouv : NPAL12872
+ // Read color of the group
+ char aGroupColorName[ 30 ];
+ sprintf( aGroupColorName, "ColorGroup %d", subid);
+ if ( aGroup->ExistInternalObject( aGroupColorName ) )
+ {
+ aDataset = new HDFdataset( aGroupColorName, aGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ double* anRGB = new double[ size ];
+ aDataset->ReadFromDisk( anRGB );
+ aDataset->CloseOnDisk();
+ Quantity_Color aColor( anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB );
+ aGroupBaseDS->SetColor( aColor );
+ }
+ }
+ }
+ aGroup->CloseOnDisk();
+ }
+ } // reading GROUPs
+
+ // instead of reading mesh data, we read only brief information of all
+ // objects: mesh, groups, sub-meshes (issue 0021208 )
+ if ( hasData )
+ {
+ SMESH_PreMeshInfo::LoadFromFile( myNewMeshImpl, id,
+ meshfile.ToCString(), filename.ToCString(),
+ !isMultiFile );
+ }
+
+ // read Sub-Mesh ORDER if any
+ if( aTopGroup->ExistInternalObject( "Mesh Order" ) ) {
+ aDataset = new HDFdataset( "Mesh Order", aTopGroup );
+ aDataset->OpenOnDisk();
+ size = aDataset->GetSize();
+ int* smIDs = new int[ size ];
+ aDataset->ReadFromDisk( smIDs );
+ aDataset->CloseOnDisk();
+ TListOfListOfInt anOrderIds;
+ anOrderIds.push_back( TListOfInt() );
+ for ( int i = 0; i < size; i++ )
+ if ( smIDs[ i ] < 0 ) // is separator
+ anOrderIds.push_back( TListOfInt() );
+ else
+ anOrderIds.back().push_back(smIDs[ i ]);
+
+ myNewMeshImpl->GetImpl().SetMeshOrder( anOrderIds );
+ }
+ } // loop on meshes
+
+ // update hyps needing full mesh data restored (issue 20918)
+ for ( hyp_data = hypDataList.begin(); hyp_data != hypDataList.end(); ++hyp_data )
+ {
+ SMESH_Hypothesis_i* hyp = hyp_data->first;
+ hyp->UpdateAsMeshesRestored();
+ }
+
+ // notify algos on completed restoration to set sub-mesh event listeners
+ for ( meshi_group = meshGroupList.begin(); meshi_group != meshGroupList.end(); ++meshi_group )
+ {
+ SMESH_Mesh_i* myNewMeshImpl = meshi_group->first;
+ ::SMESH_Mesh& myLocMesh = myNewMeshImpl->GetImpl();
+
+ TopoDS_Shape myLocShape;
+ if(myLocMesh.HasShapeToMesh())
+ myLocShape = myLocMesh.GetShapeToMesh();
+ else
+ myLocShape = SMESH_Mesh::PseudoShape();
+
+ myLocMesh.GetSubMesh(myLocShape)->
+ ComputeStateEngine (SMESH_subMesh::SUBMESH_RESTORED);
+ }
+
+ // let filters detect dependency on mesh groups via FT_BelongToMeshGroup predicate (22877)
+ list< SMESH::Filter_var >::iterator f = filters.begin();
+ for ( ; f != filters.end(); ++f )
+ if ( SMESH::Filter_i * fi = SMESH::DownCast< SMESH::Filter_i*>( *f ))
+ fi->FindBaseObjects();
+
+
+ // close mesh group
+ if(aTopGroup)
+ aTopGroup->CloseOnDisk();
+ }
+ // close HDF file
+ aFile->CloseOnDisk();
+ delete aFile;
+
+ // Remove temporary files created from the stream
+ if ( !isMultiFile )
+ {
+ SMESH_File meshFile( meshfile.ToCString() );
+ if ( !meshFile ) // no meshfile exists
+ {
+ SALOMEDS_Tool::RemoveTemporaryFiles( tmpDir.ToCString(), aFileSeq.in(), true );
+ }
+ else
+ {
+ Engines::Container_var container = GetContainerRef();
+ if ( Engines_Container_i* container_i = SMESH::DownCast<Engines_Container_i*>( container ))
+ {
+ container_i->registerTemporaryFile( filename.ToCString() );
+ container_i->registerTemporaryFile( meshfile.ToCString() );
+ container_i->registerTemporaryFile( tmpDir.ToCString() );
+ }
+ }
+ }
+ pd << ""; // prevent optimizing pd out
+
+ // creation of tree nodes for all data objects in the study
+ // to support tree representation customization and drag-n-drop:
+ SALOMEDS::Study_var study = theComponent->GetStudy();
+ SALOMEDS::UseCaseBuilder_wrap useCaseBuilder = study->GetUseCaseBuilder();
+ if ( !useCaseBuilder->IsUseCaseNode( theComponent ) ) {
+ useCaseBuilder->SetRootCurrent();
+ useCaseBuilder->Append( theComponent ); // component object is added as the top level item
+ SALOMEDS::ChildIterator_wrap it = study->NewChildIterator( theComponent );
+ for (it->InitEx(true); it->More(); it->Next()) {
+ useCaseBuilder->AppendTo( it->Value()->GetFather(), it->Value() );
+ }
+ }
+
+ return true;
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::LoadASCII
+ *
+ * Load SMESH module's data in ASCII format
+ */
+//=============================================================================
+
+bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent,
+ const SALOMEDS::TMPFile& theStream,
+ const char* theURL,
+ bool isMultiFile ) {
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" );
+ return Load( theComponent, theStream, theURL, isMultiFile );
+
+ //before call main ::Load method it's need for decipher text format to
+ //binary ( "|xx" => x' )
+ int size = theStream.length();
+ if ( int((size / 3 )*3) != size ) //error size of buffer
+ return false;
+
+ int real_size = int(size / 3);
+
+ _CORBA_Octet* buffer = new _CORBA_Octet[real_size];
+ char tmp[3];
+ tmp[2]='\0';
+ unsigned int c = -1;
+ for ( int i = 0; i < real_size; i++ )
+ {
+ memcpy( &(tmp[0]), &(theStream[i*3+1]), 2 );
+ sscanf( tmp, "%x", &c );
+ sprintf( (char*)&(buffer[i]), "%c", (char)c );
+ }
+
+ SALOMEDS::TMPFile_var aRealStreamFile = new SALOMEDS::TMPFile(real_size, real_size, buffer, 1);
+
+ return Load( theComponent, *(aRealStreamFile._retn()), theURL, isMultiFile );
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::Close
+ *
+ * Clears study-connected data when it is closed
+ */
+//=============================================================================
+
+void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent )
+{
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" );
+
+ // set correct current study
+ SALOMEDS::Study_var study = theComponent->GetStudy();
+ if ( study->StudyId() != GetCurrentStudyID())
+ setCurrentStudy( study, /*IsBeingClosed=*/true );
+
+ // Clear study contexts data
+ int studyId = GetCurrentStudyID();
+ if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) {
+ delete myStudyContextMap[ studyId ];
+ myStudyContextMap.erase( studyId );
+ }
+
+ // remove the tmp files meshes are loaded from
+ SMESH_PreMeshInfo::RemoveStudyFiles_TMP_METHOD( theComponent );
+
+ myCurrentStudy = SALOMEDS::Study::_nil();
+ return;
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::ComponentDataType
+ *
+ * Get component data type
+ */
+//=============================================================================
+
+char* SMESH_Gen_i::ComponentDataType()
+{
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" );
+ return CORBA::string_dup( "SMESH" );
+}
+
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::IORToLocalPersistentID
+ *
+ * Transform data from transient form to persistent
+ */
+//=============================================================================
+
+char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/,
+ const char* IORString,
+ CORBA::Boolean /*isMultiFile*/,
+ CORBA::Boolean /*isASCII*/ )
+{
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" );
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+
+ if ( myStudyContext && strcmp( IORString, "" ) != 0 ) {
+ int anId = myStudyContext->findId( IORString );
+ if ( anId ) {
+ if(MYDEBUG) MESSAGE( "VSR " << anId )
+ char strId[ 20 ];
+ sprintf( strId, "%d", anId );
+ return CORBA::string_dup( strId );
+ }
+ }
+ return CORBA::string_dup( "" );
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::LocalPersistentIDToIOR
+ *
+ * Transform data from persistent form to transient
+ */
+//=============================================================================
+
+char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/,
+ const char* aLocalPersistentID,
+ CORBA::Boolean /*isMultiFile*/,
+ CORBA::Boolean /*isASCII*/ )
+{
+ if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID );
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+
+ if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) {
+ int anId = atoi( aLocalPersistentID );
+ return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() );
+ }
+ return CORBA::string_dup( "" );
+}
+
+//=======================================================================
+//function : RegisterObject
+//purpose :
+//=======================================================================
+
+int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject)
+{
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+ if ( myStudyContext && !CORBA::is_nil( theObject )) {
+ CORBA::String_var iorString = GetORB()->object_to_string( theObject );
+ return myStudyContext->addObject( string( iorString.in() ) );
+ }
+ return 0;
+}
+
+//================================================================================
+/*!
+ * \brief Return id of registered object
+ * \param theObject - the Object
+ * \retval int - Object id
+ */
+//================================================================================
+
+CORBA::Long SMESH_Gen_i::GetObjectId(CORBA::Object_ptr theObject)
+{
+ StudyContext* myStudyContext = GetCurrentStudyContext();
+ if ( myStudyContext && !CORBA::is_nil( theObject )) {
+ string iorString = GetORB()->object_to_string( theObject );
+ return myStudyContext->findId( iorString );
+ }
+ return 0;
+}
+
+//=============================================================================
+/*!
+ * SMESH_Gen_i::SetName
+ *
+ * Set a new object name
+ */
+//=============================================================================
+void SMESH_Gen_i::SetName(const char* theIOR,
+ const char* theName)
+{
+ if ( theIOR && strcmp( theIOR, "" ) ) {
+ CORBA::Object_var anObject = GetORB()->string_to_object( theIOR );
+ SALOMEDS::SObject_wrap aSO = ObjectToSObject( myCurrentStudy, anObject );
+ if ( !aSO->_is_nil() ) {
+ SetName( aSO, theName );
+ }
+ }
+}
+
+int SMESH_Gen_i::GetCurrentStudyID()
+{
+ return myCurrentStudy->_is_nil() || myCurrentStudy->_non_existent() ? -1 : myCurrentStudy->StudyId();
+}
+
+// Version information
+char* SMESH_Gen_i::getVersion()
+{
+#if SMESH_DEVELOPMENT
+ return CORBA::string_dup(SMESH_VERSION_STR"dev");
+#else
+ return CORBA::string_dup(SMESH_VERSION_STR);
+#endif
+}
+
+//=================================================================================
+// function : Move()
+// purpose : Moves objects to the specified position.
+// Is used in the drag-n-drop functionality.
+//=================================================================================
+void SMESH_Gen_i::Move( const SMESH::sobject_list& what,
+ SALOMEDS::SObject_ptr where,
+ CORBA::Long row )
+{
+ if ( CORBA::is_nil( where ) ) return;
+
+ SALOMEDS::Study_var study = where->GetStudy();
+ SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder();
+ SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder();
+ SALOMEDS::SComponent_var father = where->GetFatherComponent();
+ std::string dataType = father->ComponentDataType();
+ if ( dataType != "SMESH" ) return; // not a SMESH component
+
+ SALOMEDS::SObject_var objAfter;
+ if ( row >= 0 && useCaseBuilder->HasChildren( where ) ) {
+ // insert at given row -> find insertion position
+ SALOMEDS::UseCaseIterator_var useCaseIt = useCaseBuilder->GetUseCaseIterator( where );
+ int i;
+ for ( i = 0; i < row && useCaseIt->More(); i++, useCaseIt->Next() );
+ if ( i == row && useCaseIt->More() ) {
+ objAfter = useCaseIt->Value();
+ }
+ }
+
+ for ( CORBA::ULong i = 0; i < what.length(); i++ ) {
+ SALOMEDS::SObject_var sobj = what[i];
+ if ( CORBA::is_nil( sobj ) ) continue; // skip bad object
+ // insert the object to the use case tree
+ if ( !CORBA::is_nil( objAfter ) )
+ useCaseBuilder->InsertBefore( sobj, objAfter ); // insert at given row
+ else
+ useCaseBuilder->AppendTo( where, sobj ); // append to the end of list
+ }
+}
+//================================================================================
+/*!
+ * \brief Returns true if algorithm can be used to mesh a given geometry
+ * \param [in] theAlgoType - the algorithm type
+ * \param [in] theLibName - a name of the Plug-in library implementing the algorithm
+ * \param [in] theGeomObject - the geometry to mesh
+ * \param [in] toCheckAll - if \c True, returns \c True if all shapes are meshable,
+ * else, returns \c True if at least one shape is meshable
+ * \return CORBA::Boolean - can or can't
+ */
+//================================================================================
+
+CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType,
+ const char* theLibName,
+ GEOM::GEOM_Object_ptr theGeomObject,
+ CORBA::Boolean toCheckAll)
+{
+ SMESH_TRY;
+
+ std::string aPlatformLibName;
+ typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char*);
+ GenericHypothesisCreator_i* aCreator =
+ getHypothesisCreator(theAlgoType, theLibName, aPlatformLibName);
+ if (aCreator)
+ {
+ TopoDS_Shape shape = GeomObjectToShape( theGeomObject );
+ return shape.IsNull() || aCreator->IsApplicable( shape, toCheckAll );
+ }
+ else
+ {
+ return false;
+ }
+
+ SMESH_CATCH( SMESH::doNothing );
+
+#ifdef _DEBUG_
+ cout << "SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "") << endl;
+#endif
+ return true;
+}
+
+//=================================================================================
+// function : GetInsideSphere
+// purpose : Collect indices of elements, which are located inside the sphere
+//=================================================================================
+SMESH::long_array* SMESH_Gen_i::GetInsideSphere( SMESH::SMESH_IDSource_ptr meshPart,
+ SMESH::ElementType theElemType,
+ CORBA::Double theX,
+ CORBA::Double theY,
+ CORBA::Double theZ,
+ CORBA::Double theR)
+{
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ if ( meshPart->_is_nil() )
+ return aResult._retn();
+
+ // 1. Create geometrical object
+ gp_Pnt aP( theX, theY, theZ );
+ TopoDS_Shape aShape = BRepPrimAPI_MakeSphere( aP, theR ).Shape();
+
+ std::vector<long> lst =_GetInside(meshPart, theElemType, aShape);
+
+ if ( lst.size() > 0 ) {
+ aResult->length( lst.size() );
+ for ( size_t i = 0; i < lst.size(); i++ ) {
+ aResult[i] = lst[i];
+ }
+ }
+ return aResult._retn();
+}
+
+SMESH::long_array* SMESH_Gen_i::GetInsideBox( SMESH::SMESH_IDSource_ptr meshPart,
+ SMESH::ElementType theElemType,
+ CORBA::Double theX1,
+ CORBA::Double theY1,
+ CORBA::Double theZ1,
+ CORBA::Double theX2,
+ CORBA::Double theY2,
+ CORBA::Double theZ2) {
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ if( meshPart->_is_nil() )
+ return aResult._retn();
+
+ TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( theX1, theY1, theZ1 ), gp_Pnt( theX2, theY2, theZ2 ) ).Shape();
+
+ std::vector<long> lst =_GetInside(meshPart, theElemType, aShape);
+
+ if( lst.size() > 0 ) {
+ aResult->length( lst.size() );
+ for ( size_t i = 0; i < lst.size(); i++ ) {
+ aResult[i] = lst[i];
+ }
+ }
+ return aResult._retn();
+}
+
+SMESH::long_array* SMESH_Gen_i::GetInsideCylinder( SMESH::SMESH_IDSource_ptr meshPart,
+ SMESH::ElementType theElemType,
+ CORBA::Double theX,
+ CORBA::Double theY,
+ CORBA::Double theZ,
+ CORBA::Double theDX,
+ CORBA::Double theDY,
+ CORBA::Double theDZ,
+ CORBA::Double theH,
+ CORBA::Double theR ){
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ if( meshPart->_is_nil() )
+ return aResult._retn();
+
+ gp_Pnt aP( theX, theY, theZ );
+ gp_Vec aV( theDX, theDY, theDZ );
+ gp_Ax2 anAxes (aP, aV);
+
+ TopoDS_Shape aShape = BRepPrimAPI_MakeCylinder(anAxes, theR, Abs(theH)).Shape();
+
+ std::vector<long> lst =_GetInside(meshPart, theElemType, aShape);
+
+ if( lst.size() > 0 ) {
+ aResult->length( lst.size() );
+ for ( size_t i = 0; i < lst.size(); i++ ) {
+ aResult[i] = lst[i];
+ }
+ }
+ return aResult._retn();
+}
+
+SMESH::long_array* SMESH_Gen_i::GetInside( SMESH::SMESH_IDSource_ptr meshPart,
+ SMESH::ElementType theElemType,
+ GEOM::GEOM_Object_ptr theGeom,
+ CORBA::Double theTolerance ) {
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ if( meshPart->_is_nil() || theGeom->_is_nil() )
+ return aResult._retn();
+
+ TopoDS_Shape aShape = GeomObjectToShape( theGeom );
+
+ std::vector<long> lst =_GetInside(meshPart, theElemType, aShape, &theTolerance);
+
+ if( lst.size() > 0 ) {
+ aResult->length( lst.size() );
+ for ( size_t i = 0; i < lst.size(); i++ ) {
+ aResult[i] = lst[i];
+ }
+ }
+ return aResult._retn();
+}
+
+
+
+std::vector<long> SMESH_Gen_i::_GetInside( SMESH::SMESH_IDSource_ptr meshPart,
+ SMESH::ElementType theElemType,
+ TopoDS_Shape& aShape,
+ double* theTolerance) {
+
+ std::vector<long> res;
+ SMESH::SMESH_Mesh_var mesh = meshPart->GetMesh();
+
+ if ( mesh->_is_nil() )
+ return res;
+
+ SMESH_Mesh_i* anImpl = dynamic_cast<SMESH_Mesh_i*>( GetServant( mesh ).in() );
+ if ( !anImpl )
+ return res;
+
+ const SMDS_Mesh* meshDS = anImpl->GetImpl().GetMeshDS();
+
+ if ( !meshDS )
+ return res;
+
+ SMDSAbs_ElementType aType = SMDSAbs_ElementType(theElemType);
+ SMESH::Controls::ElementsOnShape* anElementsOnShape = new SMESH::Controls::ElementsOnShape();
+ anElementsOnShape->SetAllNodes( true );
+ anElementsOnShape->SetMesh( meshDS );
+ anElementsOnShape->SetShape( aShape, aType );
+
+ if(theTolerance)
+ anElementsOnShape->SetTolerance(*theTolerance);
+
+ SMESH::SMESH_Mesh_var msource = SMESH::SMESH_Mesh::_narrow(meshPart);
+ if ( !msource->_is_nil() ) { // Mesh case
+ SMDS_ElemIteratorPtr elemIt = meshDS->elementsIterator( aType );
+ if ( elemIt ) {
+ while ( elemIt->more() ) {
+ const SMDS_MeshElement* anElem = elemIt->next();
+ long anId = anElem->GetID();
+ if ( anElementsOnShape->IsSatisfy( anId ) )
+ res.push_back( anId );
+ }
+ }
+ }
+ SMESH::SMESH_Group_var gsource = SMESH::SMESH_Group::_narrow(meshPart);
+ if ( !gsource->_is_nil() ) {
+ if(theElemType == SMESH::NODE) {
+ SMESH::long_array_var nodes = gsource->GetNodeIDs();
+ for ( CORBA::ULong i = 0; i < nodes->length(); ++i ) {
+ if ( const SMDS_MeshNode* node = meshDS->FindNode( nodes[i] )) {
+ long anId = node->GetID();
+ if ( anElementsOnShape->IsSatisfy( anId ) )
+ res.push_back( anId );
+ }
+ }
+ } else if (gsource->GetType() == theElemType || theElemType == SMESH::ALL ) {
+ SMESH::long_array_var elems = gsource->GetListOfID();
+ for ( CORBA::ULong i = 0; i < elems->length(); ++i ) {
+ if ( const SMDS_MeshElement* elem = meshDS->FindElement( elems[i] )) {
+ long anId = elem->GetID();
+ if ( anElementsOnShape->IsSatisfy( anId ) )
+ res.push_back( anId );
+ }
+ }
+ }
+ }
+ SMESH::SMESH_subMesh_var smsource = SMESH::SMESH_subMesh::_narrow(meshPart);
+ if ( !smsource->_is_nil() ) {
+ SMESH::long_array_var elems = smsource->GetElementsByType( theElemType );
+ for ( CORBA::ULong i = 0; i < elems->length(); ++i ) {
+ const SMDS_MeshElement* elem = ( theElemType == SMESH::NODE ) ? meshDS->FindNode( elems[i] ) : meshDS->FindElement( elems[i] );
+ if (elem) {
+ long anId = elem->GetID();
+ if ( anElementsOnShape->IsSatisfy( anId ) )
+ res.push_back( anId );
+ }
+ }
+ }
+ return res;
+}
+
+
+//=============================================================================
+/*!
+ * SMESHEngine_factory
+ *
+ * C factory, accessible with dlsym, after dlopen
+ */
+//=============================================================================
+
+extern "C"
+{ SMESH_I_EXPORT
+ PortableServer::ObjectId* SMESHEngine_factory( CORBA::ORB_ptr orb,
+ PortableServer::POA_ptr poa,
+ PortableServer::ObjectId* contId,
+ const char* instanceName,
+ const char* interfaceName )
+ {
+ if(MYDEBUG) MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" );
+ if(MYDEBUG) SCRUTE(interfaceName);
+ SMESH_Gen_i* aSMESHGen = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName);
+ return aSMESHGen->getId() ;
+ }