X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Gen_i.cxx;h=5d1d45ed6addc59484de84454e1c7a216f6ba744;hp=fb6ed194996773cc282b73cbca102d68415e2e94;hb=4f7811fdb1e758270519988f66fcb79aa65322ea;hpb=51569f091c2d18be76ea9bd3e68ca0247cc731c3 diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index fb6ed1949..5d1d45ed6 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -26,7 +26,6 @@ // Module : SMESH // $Header$ -using namespace std; #include #include #include @@ -63,19 +62,17 @@ using namespace std; #include "SMESHDS_Document.hxx" #include "SMESHDS_Group.hxx" -#include "SMESH_topo.hxx" +#include "SMESHDS_GroupOnGeom.hxx" #include "SMESH_Group.hxx" +#include "SMDS_EdgePosition.hxx" +#include "SMDS_FacePosition.hxx" + #include CORBA_SERVER_HEADER(SMESH_Group) #include CORBA_SERVER_HEADER(SMESH_Filter) -#include "SMESH_Filter_i.hxx" -#include "Document_Reader.h" #include "DriverMED_W_SMESHDS_Mesh.h" #include "DriverMED_R_SMESHDS_Mesh.h" -#include "DriverMED_R_SMESHDS_Document.h" -#include "DriverUNV_R_SMESHDS_Document.h" -#include "DriverDAT_R_SMESHDS_Document.h" #include "SALOMEDS_Tool.hxx" #include "SALOME_NamingService.hxx" @@ -89,137 +86,24 @@ using namespace std; #include "Utils_ExceptHandlers.hxx" #include +#include + +using namespace std; #define NUM_TMP_FILES 2 -// Tags definition =========================================================== -// Top level -long Tag_HypothesisRoot = 1; // hypotheses root -long Tag_AlgorithmsRoot = 2; // algorithms root -// Mesh/Submesh -long Tag_RefOnShape = 1; // references to shape -long Tag_RefOnAppliedHypothesis = 2; // applied hypotheses root -long Tag_RefOnAppliedAlgorithms = 3; // applied algorithms root -// Mesh only -long Tag_SubMeshOnVertex = 4; // sub-meshes roots by type -long Tag_SubMeshOnEdge = 5; // ... -long Tag_SubMeshOnFace = 6; // ... -long Tag_SubMeshOnSolid = 7; // ... -long Tag_SubMeshOnCompound = 8; // ... -long Tag_NodeGroups = 9; // Group roots by type -long Tag_EdgeGroups = 10; // ... -long Tag_FaceGroups = 11; // ... -long Tag_VolumeGroups = 12; // ... -// =========================================================================== +#ifdef _DEBUG_ +static int MYDEBUG = 0; +#else +static int MYDEBUG = 0; +#endif // Static variables definition CORBA::ORB_var SMESH_Gen_i::myOrb; PortableServer::POA_var SMESH_Gen_i::myPoa; SALOME_NamingService* SMESH_Gen_i::myNS = NULL; SALOME_LifeCycleCORBA* SMESH_Gen_i::myLCC = NULL; - -//============================================================================= -/*! - * FindMaxChildTag [ static internal ] - * - * Finds maximum child tag for the given object - */ -//============================================================================= - -static long FindMaxChildTag( SALOMEDS::SObject_ptr theSObject ) -{ - long aTag = 0; - if ( !theSObject->_is_nil() ) { - SALOMEDS::Study_var aStudy = theSObject->GetStudy(); - if ( !aStudy->_is_nil() ) { - SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator( theSObject ); - for ( ; anIter->More(); anIter->Next() ) { - long nTag = anIter->Value()->Tag(); - if ( nTag > aTag ) - aTag = nTag; - } - } - } - return aTag; -} - -//============================================================================= -/*! - * Get...Tag [ static ] - * - * Methods which determine SMESH data model structure - */ -//============================================================================= - -long SMESH_Gen_i::GetHypothesisRootTag() -{ - return Tag_HypothesisRoot; -} - -long SMESH_Gen_i::GetAlgorithmsRootTag() -{ - return Tag_AlgorithmsRoot; -} - -long SMESH_Gen_i::GetRefOnShapeTag() -{ - return Tag_RefOnShape; -} - -long SMESH_Gen_i::GetRefOnAppliedHypothesisTag() -{ - return Tag_RefOnAppliedHypothesis; -} - -long SMESH_Gen_i::GetRefOnAppliedAlgorithmsTag() -{ - return Tag_RefOnAppliedAlgorithms; -} - -long SMESH_Gen_i::GetSubMeshOnVertexTag() -{ - return Tag_SubMeshOnVertex; -} - -long SMESH_Gen_i::GetSubMeshOnEdgeTag() -{ - return Tag_SubMeshOnEdge; -} - -long SMESH_Gen_i::GetSubMeshOnFaceTag() -{ - return Tag_SubMeshOnFace; -} - -long SMESH_Gen_i::GetSubMeshOnSolidTag() -{ - return Tag_SubMeshOnSolid; -} - -long SMESH_Gen_i::GetSubMeshOnCompoundTag() -{ - return Tag_SubMeshOnCompound; -} - -long SMESH_Gen_i::GetNodeGroupsTag() -{ - return Tag_NodeGroups; -} - -long SMESH_Gen_i::GetEdgeGroupsTag() -{ - return Tag_EdgeGroups; -} - -long SMESH_Gen_i::GetFaceGroupsTag() -{ - return Tag_FaceGroups; -} - -long SMESH_Gen_i::GetVolumeGroupsTag() -{ - return Tag_VolumeGroups; -} +SMESH_Gen_i* SMESH_Gen_i::mySMESHGen = NULL; //============================================================================= /*! @@ -238,7 +122,7 @@ PortableServer::ServantBase_var SMESH_Gen_i::GetServant( CORBA::Object_ptr theOb return aServant; } catch (...) { - MESSAGE( "GetServant - Unknown exception was caught!!!" ); + INFOS( "GetServant - Unknown exception was caught!!!" ); return NULL; } } @@ -265,7 +149,7 @@ CORBA::Object_var SMESH_Gen_i::SObjectToObject( SALOMEDS::SObject_ptr theSObject } } catch( ... ) { - MESSAGE( "SObjectToObject - Unknown exception was caught!!!" ); + INFOS( "SObjectToObject - Unknown exception was caught!!!" ); } } return anObj; @@ -327,7 +211,7 @@ GEOM::GEOM_Gen_ptr SMESH_Gen_i::GetGeomEngine() { SMESH_Gen_i::SMESH_Gen_i() { - MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : default constructor" ); + INFOS( "SMESH_Gen_i::SMESH_Gen_i : default constructor" ); } //============================================================================= @@ -345,7 +229,7 @@ SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb, const char* interfaceName ) : Engines_Component_i( orb, poa, contId, instanceName, interfaceName ) { - MESSAGE( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" ); + INFOS( "SMESH_Gen_i::SMESH_Gen_i : standard constructor" ); myOrb = CORBA::ORB::_duplicate(orb); myPoa = PortableServer::POA::_duplicate(poa); @@ -354,6 +238,7 @@ SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb, _id = myPoa->activate_object( _thisObj ); myShapeReader = NULL; // shape reader + mySMESHGen = this; } //============================================================================= @@ -366,7 +251,7 @@ SMESH_Gen_i::SMESH_Gen_i( CORBA::ORB_ptr orb, SMESH_Gen_i::~SMESH_Gen_i() { - MESSAGE( "SMESH_Gen_i::~SMESH_Gen_i" ); + INFOS( "SMESH_Gen_i::~SMESH_Gen_i" ); // delete hypothesis creators map::iterator itHyp; @@ -387,21 +272,6 @@ SMESH_Gen_i::~SMESH_Gen_i() delete myShapeReader; } -//============================================================================= -/*! - * SMESH_Gen_i::CreateFilterManager - * - * Create filter manager - */ -//============================================================================= - -SMESH::FilterManager_ptr SMESH_Gen_i::CreateFilterManager() -{ - SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i(); - SMESH::FilterManager_var anObj = aFilter->_this(); - return anObj._retn(); -} - //============================================================================= /*! * SMESH_Gen_i::createHypothesis @@ -414,11 +284,8 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName throw (SALOME::SALOME_Exception) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName); + if(MYDEBUG) MESSAGE( "Create Hypothesis <" << theHypName << "> from " << theLibName); - // get study context - StudyContext* myStudyContext = GetCurrentStudyContext(); - // create a new hypothesis object servant SMESH_Hypothesis_i* myHypothesis_i = 0; SMESH::SMESH_Hypothesis_var hypothesis_i; @@ -429,7 +296,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName if (myHypCreatorMap.find(string(theHypName)) == myHypCreatorMap.end()) { // load plugin library - MESSAGE("Loading server meshers plugin library ..."); + if(MYDEBUG) MESSAGE("Loading server meshers plugin library ..."); void* libHandle = dlopen (theLibName, RTLD_LAZY); if (!libHandle) { @@ -439,7 +306,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName } // get method, returning hypothesis creator - MESSAGE("Find GetHypothesisCreator() method ..."); + if(MYDEBUG) MESSAGE("Find GetHypothesisCreator() method ..."); typedef GenericHypothesisCreator_i* (*GetHypothesisCreator)(const char* theHypName); GetHypothesisCreator procHandle = (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" ); @@ -450,7 +317,7 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName } // get hypothesis creator - MESSAGE("Get Hypothesis Creator for " << theHypName); + if(MYDEBUG) MESSAGE("Get Hypothesis Creator for " << theHypName); GenericHypothesisCreator_i* aCreator = procHandle(theHypName); if (!aCreator) { @@ -462,10 +329,9 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName } // create a new hypothesis object, store its ref. in studyContext - MESSAGE("Create Hypothesis " << theHypName); + if(MYDEBUG) MESSAGE("Create Hypothesis " << theHypName); myHypothesis_i = - myHypCreatorMap[string(theHypName)]->Create - (myPoa, myCurrentStudy->StudyId(), &myGen); + myHypCreatorMap[string(theHypName)]->Create (myPoa, GetCurrentStudyID(), &myGen); // _CS_gbo Explicit activation (no longer made in the constructor). myHypothesis_i->Activate(); myHypothesis_i->SetLibName(theLibName); // for persistency assurance @@ -480,9 +346,8 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::createHypothesis(const char* theHypName // activate the CORBA servant of hypothesis hypothesis_i = SMESH::SMESH_Hypothesis::_narrow( myHypothesis_i->_this() ); - string iorString = GetORB()->object_to_string( hypothesis_i ); - int nextId = myStudyContext->addObject( iorString ); - MESSAGE( "Add hypo to map with id = "<< nextId << " and IOR = " << iorString.c_str() ); + int nextId = RegisterObject( hypothesis_i ); + if(MYDEBUG) MESSAGE( "Add hypo to map with id = "<< nextId ); return hypothesis_i._retn(); } @@ -498,25 +363,19 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::createMesh() throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "SMESH_Gen_i::createMesh" ); - - // get current study - StudyContext* myStudyContext = GetCurrentStudyContext(); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::createMesh" ); // Get or create the GEOM_Client instance try { // create a new mesh object servant, store it in a map in study context - SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), - this, - myCurrentStudy->StudyId() ); + SMESH_Mesh_i* meshServant = new SMESH_Mesh_i( GetPOA(), this, GetCurrentStudyID() ); // create a new mesh object - meshServant->SetImpl( myGen.CreateMesh( myCurrentStudy->StudyId() ) ); + meshServant->SetImpl( myGen.CreateMesh( GetCurrentStudyID() )); // activate the CORBA servant of Mesh - SMESH::SMESH_Mesh_var mesh = meshServant->_this(); - string iorString = GetORB()->object_to_string( mesh ); - int nextId = myStudyContext->addObject( iorString ); - MESSAGE( "Add mesh to map with id = "<< nextId << " and IOR = " << iorString.c_str() ); + SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( meshServant->_this() ); + int nextId = RegisterObject( mesh ); + if(MYDEBUG) MESSAGE( "Add mesh to map with id = "<< nextId); return mesh._retn(); } catch (SALOME_Exception& S_ex) { @@ -551,17 +410,19 @@ GEOM_Client* SMESH_Gen_i::GetShapeReader() void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy ) { - MESSAGE( "SMESH_Gen_i::SetCurrentStudy" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy" ); myCurrentStudy = SALOMEDS::Study::_duplicate( theStudy ); // create study context, if it doesn't exist and set current study - int studyId = myCurrentStudy->StudyId(); - MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId ); + int studyId = GetCurrentStudyID(); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SetCurrentStudy: study Id = " << studyId ); if ( myStudyContextMap.find( studyId ) == myStudyContextMap.end() ) { myStudyContextMap[ studyId ] = new StudyContext; } // set current study for geom engine + /* if ( !CORBA::is_nil( GetGeomEngine() ) ) GetGeomEngine()->GetCurrentStudy( myCurrentStudy->StudyId() ); + */ } //============================================================================= @@ -574,7 +435,7 @@ void SMESH_Gen_i::SetCurrentStudy( SALOMEDS::Study_ptr theStudy ) SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy() { - MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << myCurrentStudy->StudyId() ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetCurrentStudy: study Id = " << GetCurrentStudyID() ); return SALOMEDS::Study::_duplicate( myCurrentStudy ); } @@ -587,9 +448,11 @@ SALOMEDS::Study_ptr SMESH_Gen_i::GetCurrentStudy() //============================================================================= StudyContext* SMESH_Gen_i::GetCurrentStudyContext() { - ASSERT( !CORBA::is_nil( myCurrentStudy ) ) - ASSERT( myStudyContextMap.find( myCurrentStudy->StudyId() ) != myStudyContextMap.end() ); - return myStudyContextMap[ myCurrentStudy->StudyId() ]; + if ( !CORBA::is_nil( myCurrentStudy ) && + myStudyContextMap.find( GetCurrentStudyID() ) != myStudyContextMap.end() ) + return myStudyContextMap[ myCurrentStudy->StudyId() ]; + else + return 0; } //============================================================================= @@ -605,14 +468,13 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - ASSERT( !CORBA::is_nil( myCurrentStudy ) ); // Create hypothesis/algorithm SMESH::SMESH_Hypothesis_var hyp = this->createHypothesis( theHypName, theLibName ); // Publish hypothesis/algorithm in the study - if ( this->CanPublishInStudy( hyp ) ) { - this->PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), hyp, "" ); - } + if ( CanPublishInStudy( hyp ) ) + PublishHypothesis( myCurrentStudy, hyp ); + return hyp._retn(); } @@ -624,25 +486,49 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam */ //============================================================================= -SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Shape_ptr theShape ) +SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObject ) throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "SMESH_Gen_i::CreateMesh" ); - ASSERT( !CORBA::is_nil( myCurrentStudy ) ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMesh" ); // create mesh SMESH::SMESH_Mesh_var mesh = this->createMesh(); - // publish mesh in the study - if ( this->CanPublishInStudy( mesh ) ) { - this->PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), mesh.in(), "" ); - } // set shape SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); ASSERT( meshServant ); - meshServant->SetShape( theShape ); + meshServant->SetShape( theShapeObject ); + // publish mesh in the study + if ( CanPublishInStudy( mesh ) ) + PublishMesh( myCurrentStudy, mesh.in() ); return mesh._retn(); } - + +//============================================================================= +/*! + * SMESH_Gen_i::CreateMeshFromUNV + * + * Create mesh and import data from UNV file + */ +//============================================================================= + +SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName ) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromUNV" ); + + SMESH::SMESH_Mesh_var aMesh = createMesh(); + string aFileName; // = boost::filesystem::path(theFileName).leaf(); + // publish mesh in the study + if ( CanPublishInStudy( aMesh ) ) + PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() ); + + SMESH_Mesh_i* aServant = dynamic_cast( GetServant( aMesh ).in() ); + ASSERT( aServant ); + aServant->ImportUNVFile( theFileName ); + return aMesh._retn(); +} + //============================================================================= /*! * SMESH_Gen_i::CreateMeshFromMED @@ -656,42 +542,67 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" ); - ASSERT( !CORBA::is_nil( myCurrentStudy ) ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshFromMED" ); // Retrieve mesh names from the file DriverMED_R_SMESHDS_Mesh myReader; myReader.SetFile( theFileName ); myReader.SetMeshId( -1 ); - list aNames = myReader.GetMeshNames(); - + Driver_Mesh::Status aStatus; + list aNames = myReader.GetMeshNames(aStatus); SMESH::mesh_array_var aResult = new SMESH::mesh_array(); - aResult->length( aNames.size() ); - int i = 0; - - // Iterate through all meshes and create mesh objects - theStatus = SMESH::DRS_OK; - for ( list::iterator it = aNames.begin(); it != aNames.end(); it++ ) { - // create mesh - SMESH::SMESH_Mesh_var mesh = createMesh(); + theStatus = (SMESH::DriverMED_ReadStatus)aStatus; + if(theStatus == SMESH::DRS_OK){ + aResult->length( aNames.size() ); + int i = 0; - // publish mesh in the study - if ( CanPublishInStudy( mesh ) ) { - PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), mesh.in(), (*it).c_str() ); + // Iterate through all meshes and create mesh objects + for ( list::iterator it = aNames.begin(); it != aNames.end(); it++ ) { + // create mesh + SMESH::SMESH_Mesh_var mesh = createMesh(); + + // publish mesh in the study + if ( CanPublishInStudy( mesh ) ) + PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() ); + + // Read mesh data (groups are published automatically by ImportMEDFile()) + SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); + ASSERT( meshServant ); + SMESH::DriverMED_ReadStatus status1 = + meshServant->ImportMEDFile( theFileName, (*it).c_str() ); + if (status1 > theStatus) + theStatus = status1; + + aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh ); } + } + return aResult._retn(); +} - // Read mesh data (groups are published automatically by ImportMEDFile()) - SMESH_Mesh_i* meshServant = dynamic_cast( GetServant( mesh ).in() ); - ASSERT( meshServant ); - SMESH::DriverMED_ReadStatus status1 = - meshServant->ImportMEDFile( theFileName, (*it).c_str() ); - if (status1 > theStatus) - theStatus = status1; +//============================================================================= +/*! + * SMESH_Gen_i::CreateMeshFromSTL + * + * Create mesh and import data from STL file + */ +//============================================================================= - aResult[i++] = SMESH::SMESH_Mesh::_duplicate( mesh ); - } +SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName ) + throw ( SALOME::SALOME_Exception ) +{ + Unexpect aCatch(SALOME_SalomeException); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::CreateMeshesFromSTL" ); - return aResult._retn(); + SMESH::SMESH_Mesh_var aMesh = createMesh(); + string aFileName; // = boost::filesystem::path(theFileName).leaf(); + // publish mesh in the study + if ( CanPublishInStudy( aMesh ) ) + PublishInStudy( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() ); + + SMESH_Mesh_i* aServant = dynamic_cast( GetServant( aMesh ).in() ); + ASSERT( aServant ); + aServant->ImportSTLFile( theFileName ); + return aMesh._retn(); } //============================================================================= @@ -703,14 +614,14 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, //============================================================================= CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh, - GEOM::GEOM_Shape_ptr theShape ) + GEOM::GEOM_Object_ptr theShapeObject ) throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "SMESH_Gen_i::IsReadyToCompute" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IsReadyToCompute" ); - if ( CORBA::is_nil( theShape ) ) - THROW_SALOME_CORBA_EXCEPTION( "bad shape reference", + if ( CORBA::is_nil( theShapeObject ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM ); if ( CORBA::is_nil( theMesh ) ) @@ -723,14 +634,14 @@ CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh, ASSERT( meshServant ); if ( meshServant ) { // get local TopoDS_Shape - TopoDS_Shape myLocShape = GetShapeReader()->GetShape( GetGeomEngine(), theShape ); + TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject ); // call implementation ::SMESH_Mesh& myLocMesh = meshServant->GetImpl(); return myGen.CheckAlgoState( myLocMesh, myLocShape ); } } catch ( SALOME_Exception& S_ex ) { - MESSAGE( "catch exception "<< S_ex.what() ); + INFOS( "catch exception "<< S_ex.what() ); } return false; } @@ -743,53 +654,52 @@ CORBA::Boolean SMESH_Gen_i::IsReadyToCompute( SMESH::SMESH_Mesh_ptr theMesh, */ //============================================================================= -SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Shape_ptr theMainShape, - const SMESH::shape_array& theListOfSubShape ) +SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Object_ptr theMainShapeObject, + const SMESH::object_array& theListOfSubShapeObject ) throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "SMESH_Gen_i::GetSubShapesId" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::GetSubShapesId" ); SMESH::long_array_var shapesId = new SMESH::long_array; set setId; - if ( CORBA::is_nil( theMainShape ) ) - THROW_SALOME_CORBA_EXCEPTION( "bad shape reference", + if ( CORBA::is_nil( theMainShapeObject ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM ); try { - if (! myShapeReader) myShapeReader = new GEOM_Client(GetContainerRef()); - ASSERT(myShapeReader); - TopoDS_Shape myMainShape = GetShapeReader()->GetShape(GetGeomEngine(),theMainShape); + TopoDS_Shape myMainShape = GeomObjectToShape(theMainShapeObject); TopTools_IndexedMapOfShape myIndexToShape; TopExp::MapShapes(myMainShape,myIndexToShape); - for (int i=0; iGetShape(GetGeomEngine(),aShape); + GEOM::GEOM_Object_var aShapeObject + = GEOM::GEOM_Object::_narrow(theListOfSubShapeObject[i]); + if ( CORBA::is_nil( aShapeObject ) ) + THROW_SALOME_CORBA_EXCEPTION ("bad shape object reference", \ + SALOME::BAD_PARAM ); + + TopoDS_Shape locShape = GeomObjectToShape(aShapeObject); for (TopExp_Explorer exp(locShape,TopAbs_FACE); exp.More(); exp.Next()) { const TopoDS_Face& F = TopoDS::Face(exp.Current()); setId.insert(myIndexToShape.FindIndex(F)); - SCRUTE(myIndexToShape.FindIndex(F)); + if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(F)); } for (TopExp_Explorer exp(locShape,TopAbs_EDGE); exp.More(); exp.Next()) { const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); setId.insert(myIndexToShape.FindIndex(E)); - SCRUTE(myIndexToShape.FindIndex(E)); + if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(E)); } for (TopExp_Explorer exp(locShape,TopAbs_VERTEX); exp.More(); exp.Next()) { const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current()); setId.insert(myIndexToShape.FindIndex(V)); - SCRUTE(myIndexToShape.FindIndex(V)); + if(MYDEBUG) SCRUTE(myIndexToShape.FindIndex(V)); } } shapesId->length(setId.size()); @@ -797,9 +707,9 @@ SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Shape_ptr theMai int i=0; for (iind = setId.begin(); iind != setId.end(); iind++) { - SCRUTE((*iind)); + if(MYDEBUG) SCRUTE((*iind)); shapesId[i] = (*iind); - SCRUTE(shapesId[i]); + if(MYDEBUG) SCRUTE(shapesId[i]); i++; } } @@ -820,14 +730,14 @@ SMESH::long_array* SMESH_Gen_i::GetSubShapesId( GEOM::GEOM_Shape_ptr theMai //============================================================================= CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, - GEOM::GEOM_Shape_ptr theShape ) + GEOM::GEOM_Object_ptr theShapeObject ) throw ( SALOME::SALOME_Exception ) { Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "SMESH_Gen_i::Compute" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Compute" ); - if ( CORBA::is_nil( theShape ) ) - THROW_SALOME_CORBA_EXCEPTION( "bad shape reference", + if ( CORBA::is_nil( theShapeObject ) ) + THROW_SALOME_CORBA_EXCEPTION( "bad shape object reference", SALOME::BAD_PARAM ); if ( CORBA::is_nil( theMesh ) ) @@ -840,17 +750,17 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, ASSERT( meshServant ); if ( meshServant ) { // get local TopoDS_Shape - TopoDS_Shape myLocShape = GetShapeReader()->GetShape( GetGeomEngine(), theShape ); - // call implementarion compute + TopoDS_Shape myLocShape = GeomObjectToShape( theShapeObject ); + // call implementation compute ::SMESH_Mesh& myLocMesh = meshServant->GetImpl(); return myGen.Compute( myLocMesh, myLocShape); } } catch ( SALOME_Exception& S_ex ) { - MESSAGE( "Compute(): catch exception "<< S_ex.what() ); + INFOS( "Compute(): catch exception "<< S_ex.what() ); } catch ( ... ) { - MESSAGE( "Compute(): unknown exception " ); + INFOS( "Compute(): unknown exception " ); } return false; } @@ -868,7 +778,13 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, { INFOS( "SMESH_Gen_i::Save" ); - ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() ) +// ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() ) + // san -- in case differs from theComponent's study, + // use that of the component + if ( myCurrentStudy->_is_nil() || + theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() ) + SetCurrentStudy( theComponent->GetStudy() ); + StudyContext* myStudyContext = GetCurrentStudyContext(); // Declare a byte stream @@ -876,7 +792,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // Obtain a temporary dir TCollection_AsciiString tmpDir = - ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : SALOMEDS_Tool::GetTmpDir(); + ( isMultiFile ) ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str(); // Create a sequence of files processed SALOMEDS::ListOfFileNames_var aFileSeq = new SALOMEDS::ListOfFileNames; @@ -884,7 +800,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, TCollection_AsciiString aStudyName( "" ); if ( isMultiFile ) - aStudyName = ( SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ) ); + aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() ); // Set names of temporary files TCollection_AsciiString filename = @@ -1163,8 +1079,12 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, strcpy( name_meshgroup, "SubMeshes On Vertex" ); else if ( i == GetSubMeshOnEdgeTag() ) strcpy( name_meshgroup, "SubMeshes On Edge" ); + else if ( i == GetSubMeshOnWireTag() ) + strcpy( name_meshgroup, "SubMeshes On Wire" ); else if ( i == GetSubMeshOnFaceTag() ) strcpy( name_meshgroup, "SubMeshes On Face" ); + else if ( i == GetSubMeshOnShellTag() ) + strcpy( name_meshgroup, "SubMeshes On Shell" ); else if ( i == GetSubMeshOnSolidTag() ) strcpy( name_meshgroup, "SubMeshes On Solid" ); else if ( i == GetSubMeshOnCompoundTag() ) @@ -1191,7 +1111,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // // Put submesh data to MED convertor // if ( myImpl->_mapSubMesh.find( mySubMesh->GetId() ) != myImpl->_mapSubMesh.end() ) { -// MESSAGE( "VSR - SMESH_Gen_i::Save(): saving submesh with ID = " +// if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving submesh with ID = " // << mySubMesh->GetId() << " to MED file" ); // ::SMESH_subMesh* aLocalSubmesh = myImpl->_mapSubMesh[mySubMesh->GetId()]; // myWriter.AddSubMesh( aLocalSubmesh->GetSubMeshDS(), subid ); @@ -1312,12 +1232,12 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, aGroup->CreateOnDisk(); SALOMEDS::ChildIterator_var it = myCurrentStudy->NewChildIterator( myGroupsBranch ); - int grpNb = 0; for ( ; it->More(); it->Next() ) { SALOMEDS::SObject_var mySObject = it->Value(); CORBA::Object_var aSubObject = SObjectToObject( mySObject ); if ( !CORBA::is_nil( aSubObject ) ) { - SMESH_Group_i* myGroupImpl = dynamic_cast( GetServant( aSubObject ).in() ); + SMESH_GroupBase_i* myGroupImpl = + dynamic_cast( GetServant( aSubObject ).in() ); if ( !myGroupImpl ) continue; @@ -1337,13 +1257,37 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, // Store the group contents into MED file if ( myLocMesh.GetGroup( myGroupImpl->GetLocalID() ) ) { - MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = " + if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen_i::Save(): saving group with StoreName = " << grpName << " to MED file" ); - SMESHDS_Group* aGrpDS = myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS(); - aGrpDS->SetStoreName( grpName ); + SMESHDS_GroupBase* aGrpBaseDS = + myLocMesh.GetGroup( myGroupImpl->GetLocalID() )->GetGroupDS(); + aGrpBaseDS->SetStoreName( grpName ); // Pass SMESHDS_Group to MED writer - myWriter.AddGroup( aGrpDS ); + SMESHDS_Group* aGrpDS = dynamic_cast( aGrpBaseDS ); + if ( aGrpDS ) + myWriter.AddGroup( aGrpDS ); + + // write reference on a shape if exists + SMESHDS_GroupOnGeom* aGeomGrp = + dynamic_cast( aGrpBaseDS ); + if ( aGeomGrp ) { + SALOMEDS::SObject_var mySubRef, myShape; + if (mySObject->FindSubObject( GetRefOnShapeTag(), mySubRef ) && + mySubRef->ReferencedObject( myShape )) + { + string myRefOnObject = myShape->GetID(); + if ( myRefOnObject.length() > 0 ) { + char aRefName[ 30 ]; + sprintf( aRefName, "Ref on shape %d", anId); + aSize[ 0 ] = myRefOnObject.length() + 1; + aDataset = new HDFdataset(aRefName, aGroup, HDF_STRING, aSize, 1); + aDataset->CreateOnDisk(); + aDataset->WriteOnDisk( ( char* )( myRefOnObject.c_str() ) ); + aDataset->CloseOnDisk(); + } + } + } } } } @@ -1351,9 +1295,144 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, } } - // Flush current mesh information into MED file - if ( strcmp( strHasData.c_str(), "1" ) == 0 ) - myWriter.Add(); + if ( strcmp( strHasData.c_str(), "1" ) == 0 ) + { + // Flush current mesh information into MED file + myWriter.Perform(); + + + // Store node positions on sub-shapes (SMDS_Position): + + aGroup = new HDFgroup( "Node Positions", aTopGroup ); + aGroup->CreateOnDisk(); + + // in aGroup, create 5 datasets to contain: + // "Nodes on Edges" - ID of node on edge + // "Edge positions" - U parameter on node on edge + // "Nodes on Faces" - ID of node on face + // "Face U positions" - U parameter of node on face + // "Face V positions" - V parameter of node on face + + // Find out nb of nodes on edges and faces + // Collect corresponing sub-meshes + int nbEdgeNodes = 0, nbFaceNodes = 0; + list aEdgeSM, aFaceSM; + // loop on SMESHDS_SubMesh'es + const map& aSubMeshes = mySMESHDSMesh->SubMeshes(); + map::const_iterator itSubM ( aSubMeshes.begin() ); + for ( ; itSubM != aSubMeshes.end() ; itSubM++ ) + { + SMESHDS_SubMesh* aSubMesh = (*itSubM).second; + if ( aSubMesh->IsComplexSubmesh() ) + continue; // submesh containing other submeshs + int nbNodes = aSubMesh->NbNodes(); + if ( nbNodes == 0 ) continue; + + int aShapeID = (*itSubM).first; + int aShapeType = mySMESHDSMesh->IndexToShape( aShapeID ).ShapeType(); + // write only SMDS_FacePosition and SMDS_EdgePosition + switch ( aShapeType ) { + case TopAbs_FACE: + nbFaceNodes += nbNodes; + aFaceSM.push_back( aSubMesh ); + break; + case TopAbs_EDGE: + nbEdgeNodes += nbNodes; + aEdgeSM.push_back( aSubMesh ); + break; + default: + continue; + } + } + // Treat positions on edges or faces + for ( int onFace = 0; onFace < 2; onFace++ ) + { + // Create arrays to store in datasets + int iNode = 0, nbNodes = ( onFace ? nbFaceNodes : nbEdgeNodes ); + if (!nbNodes) continue; + int* aNodeIDs = new int [ nbNodes ]; + double* aUPos = new double [ nbNodes ]; + double* aVPos = ( onFace ? new double[ nbNodes ] : 0 ); + + // Fill arrays + // loop on sub-meshes + list * pListSM = ( onFace ? &aFaceSM : &aEdgeSM ); + list::iterator itSM = pListSM->begin(); + for ( ; itSM != pListSM->end(); itSM++ ) + { + SMESHDS_SubMesh* aSubMesh = (*itSM); + if ( aSubMesh->IsComplexSubmesh() ) + continue; // submesh containing other submeshs + + SMDS_NodeIteratorPtr itNode = aSubMesh->GetNodes(); + // loop on nodes in aSubMesh + while ( itNode->more() ) + { + //node ID + const SMDS_MeshNode* node = itNode->next(); + aNodeIDs [ iNode ] = node->GetID(); + + // Position + const SMDS_PositionPtr pos = node->GetPosition(); + if ( onFace ) { // on FACE + const SMDS_FacePosition* fPos = + dynamic_cast( pos.get() ); + if ( fPos ) { + aUPos[ iNode ] = fPos->GetUParameter(); + aVPos[ iNode ] = fPos->GetVParameter(); + iNode++; + } + else + nbNodes--; + } + else { // on EDGE + const SMDS_EdgePosition* ePos = + dynamic_cast( pos.get() ); + if ( ePos ) { + aUPos[ iNode ] = ePos->GetUParameter(); + iNode++; + } + else + nbNodes--; + } + } // loop on nodes in aSubMesh + } // loop on sub-meshes + + // Write datasets + if ( nbNodes ) + { + aSize[ 0 ] = nbNodes; + // IDS + string aDSName( onFace ? "Nodes on Faces" : "Nodes on Edges"); + aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_INT32, aSize, 1 ); + aDataset->CreateOnDisk(); + aDataset->WriteOnDisk( aNodeIDs ); + aDataset->CloseOnDisk(); + + // U Positions + aDSName = ( onFace ? "Face U positions" : "Edge positions"); + aDataset = new HDFdataset( (char*)aDSName.c_str(), aGroup, HDF_FLOAT64, aSize, 1); + aDataset->CreateOnDisk(); + aDataset->WriteOnDisk( aUPos ); + aDataset->CloseOnDisk(); + // V Positions + if ( onFace ) { + aDataset = new HDFdataset( "Face V positions", aGroup, HDF_FLOAT64, aSize, 1); + aDataset->CreateOnDisk(); + aDataset->WriteOnDisk( aVPos ); + aDataset->CloseOnDisk(); + } + } + delete [] aNodeIDs; + delete [] aUPos; + if ( aVPos ) delete [] aVPos; + + } // treat positions on edges or faces + + // close "Node Positions" group + aGroup->CloseOnDisk(); + + } // if ( hasData ) // close mesh HDF group aTopGroup->CloseOnDisk(); @@ -1389,7 +1468,7 @@ SALOMEDS::TMPFile* SMESH_Gen_i::Save( SALOMEDS::SComponent_ptr theComponent, SALOMEDS::TMPFile* SMESH_Gen_i::SaveASCII( SALOMEDS::SComponent_ptr theComponent, const char* theURL, bool isMultiFile ) { - MESSAGE( "SMESH_Gen_i::SaveASCII" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::SaveASCII" ); SALOMEDS::TMPFile_var aStreamFile = Save( theComponent, theURL, isMultiFile ); return aStreamFile._retn(); } @@ -1430,12 +1509,15 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, { INFOS( "SMESH_Gen_i::Load" ); - ASSERT( theComponent->GetStudy()->StudyId() == myCurrentStudy->StudyId() ) + if ( myCurrentStudy->_is_nil() || + theComponent->GetStudy()->StudyId() != myCurrentStudy->StudyId() ) + SetCurrentStudy( theComponent->GetStudy() ); + StudyContext* myStudyContext = GetCurrentStudyContext(); // Get temporary files location TCollection_AsciiString tmpDir = - isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : SALOMEDS_Tool::GetTmpDir(); + isMultiFile ? TCollection_AsciiString( ( char* )theURL ) : ( char* )SALOMEDS_Tool::GetTmpDir().c_str(); // Convert the stream into sequence of files to process SALOMEDS::ListOfFileNames_var aFileSeq = SALOMEDS_Tool::PutStreamToFiles( theStream, @@ -1443,7 +1525,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, isMultiFile ); TCollection_AsciiString aStudyName( "" ); if ( isMultiFile ) - aStudyName = ( SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ) ); + aStudyName = ( (char*)SALOMEDS_Tool::GetNameFromPath( myCurrentStudy->URL() ).c_str() ); // Set names of temporary files TCollection_AsciiString filename = tmpDir + aStudyName + TCollection_AsciiString( "_SMESH.hdf" ); @@ -1464,7 +1546,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, aFile->OpenOnDisk( HDF_RDONLY ); } catch ( HDFexception ) { - MESSAGE( "Load(): " << filename << " not found!" ); + INFOS( "Load(): " << filename << " not found!" ); return false; } @@ -1522,7 +1604,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, size = aDataset->GetSize(); char* libname_str = new char[ size ]; aDataset->ReadFromDisk( libname_str ); - SCRUTE( libname_str ); + if(MYDEBUG) SCRUTE( libname_str ); libname = string( libname_str ); delete libname_str; aDataset->CloseOnDisk(); @@ -1544,7 +1626,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, // --> restore hypothesis from data if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty - MESSAGE("VSR - load hypothesis : id = " << id << + if(MYDEBUG) MESSAGE("VSR - load hypothesis : id = " << id << ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str()); SMESH::SMESH_Hypothesis_var myHyp; @@ -1552,7 +1634,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() ); } catch (...) { - MESSAGE( "Exception during hypothesis creation" ); + INFOS( "Exception during hypothesis creation" ); } SMESH_Hypothesis_i* myImpl = dynamic_cast( GetServant( myHyp ).in() ); @@ -1563,7 +1645,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myStudyContext->mapOldToNew( id, newId ); } else - MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" ); + if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" ); } } } @@ -1619,7 +1701,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, size = aDataset->GetSize(); char* libname_str = new char[ size ]; aDataset->ReadFromDisk( libname_str ); - SCRUTE( libname_str ); + if(MYDEBUG) SCRUTE( libname_str ); libname = string( libname_str ); delete libname_str; aDataset->CloseOnDisk(); @@ -1631,7 +1713,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, size = aDataset->GetSize(); char* hypdata_str = new char[ size ]; aDataset->ReadFromDisk( hypdata_str ); - SCRUTE( hypdata_str ); + if(MYDEBUG) SCRUTE( hypdata_str ); hypdata = string( hypdata_str ); delete hypdata_str; aDataset->CloseOnDisk(); @@ -1642,7 +1724,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, // --> restore algorithm from data if ( id > 0 && !hypname.empty()/* && !hypdata.empty()*/ ) { // VSR : persistent data can be empty - MESSAGE("VSR - load algo : id = " << id << + if(MYDEBUG) MESSAGE("VSR - load algo : id = " << id << ", name = " << hypname.c_str() << ", persistent string = " << hypdata.c_str()); SMESH::SMESH_Hypothesis_var myHyp; @@ -1650,7 +1732,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myHyp = this->createHypothesis( hypname.c_str(), libname.c_str() ); } catch (...) { - MESSAGE( "Exception during hypothesis creation" ); + INFOS( "Exception during hypothesis creation" ); } SMESH_Hypothesis_i* myImpl = dynamic_cast( GetServant( myHyp ).in() ); @@ -1661,7 +1743,7 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, myStudyContext->mapOldToNew( id, newId ); } else - MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" ); + if(MYDEBUG) MESSAGE( "VSR - SMESH_Gen::Load - can't get servant" ); } } } @@ -1691,10 +1773,10 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, int aNbObjects = aTopGroup->nInternalObjects(); if ( aNbObjects > 0 ) { // create mesh - MESSAGE( "VSR - load mesh : id = " << id ); + if(MYDEBUG) MESSAGE( "VSR - load mesh : id = " << id ); SMESH::SMESH_Mesh_var myNewMesh = this->createMesh(); SMESH_Mesh_i* myNewMeshImpl = dynamic_cast( GetServant( myNewMesh ).in() ); - if ( !myNewMeshImpl ) + if ( !myNewMeshImpl ) continue; string iorString = GetORB()->object_to_string( myNewMesh ); int newId = myStudyContext->findId( iorString ); @@ -1716,13 +1798,13 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, // read mesh data from MED file myReader.SetMesh( mySMESHDSMesh ); myReader.SetMeshId( id ); - myReader.ReadMySelf(); + myReader.Perform(); hasData = true; } } // try to read and set reference to shape - GEOM::GEOM_Shape_var aShape; + 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 ); @@ -1739,9 +1821,9 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, CORBA::Object_var shapeObject = SObjectToObject( shapeSO ); if ( !CORBA::is_nil( shapeObject ) ) { - aShape = GEOM::GEOM_Shape::_narrow( shapeObject ); - if ( !aShape->_is_nil() ) - myNewMeshImpl->setShape( aShape ); + aShapeObject = GEOM::GEOM_Object::_narrow( shapeObject ); + if ( !aShapeObject->_is_nil() ) + myNewMeshImpl->SetShape( aShapeObject ); } } } @@ -1752,7 +1834,6 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, aGroup->OpenOnDisk(); // get number of applied hypotheses int aNbSubObjects = aGroup->nInternalObjects(); - MESSAGE( "VSR - number of applied hypotheses = " << aNbSubObjects ); for ( int j = 0; j < aNbSubObjects; j++ ) { char name_dataset[ HDF_NAME_MAX_LEN+1 ]; aGroup->InternalObjectIndentify( j, name_dataset ); @@ -1775,22 +1856,22 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, 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() && !aShape->_is_nil() ) - myNewMeshImpl->addHypothesis( aShape, anHyp ); + if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() ) + myNewMeshImpl->addHypothesis( aShapeObject, anHyp ); } } } } aGroup->CloseOnDisk(); } - + // try to get applied algorithms if ( aTopGroup->ExistInternalObject( "Applied Algorithms" ) ) { aGroup = new HDFgroup( "Applied Algorithms", aTopGroup ); aGroup->OpenOnDisk(); // get number of applied algorithms int aNbSubObjects = aGroup->nInternalObjects(); - MESSAGE( "VSR - number of applied algos " << aNbSubObjects ); + 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 ); @@ -1813,8 +1894,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, 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() && !aShape->_is_nil() ) - myNewMeshImpl->addHypothesis( aShape, anHyp ); + if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() ) + myNewMeshImpl->addHypothesis( aShapeObject, anHyp ); } } } @@ -1829,8 +1910,12 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, strcpy( name_meshgroup, "SubMeshes On Vertex" ); else if ( j == GetSubMeshOnEdgeTag() ) strcpy( name_meshgroup, "SubMeshes On Edge" ); + else if ( j == GetSubMeshOnWireTag() ) + strcpy( name_meshgroup, "SubMeshes On Wire" ); else if ( j == GetSubMeshOnFaceTag() ) strcpy( name_meshgroup, "SubMeshes On Face" ); + else if ( j == GetSubMeshOnShellTag() ) + strcpy( name_meshgroup, "SubMeshes On Shell" ); else if ( j == GetSubMeshOnSolidTag() ) strcpy( name_meshgroup, "SubMeshes On Solid" ); else if ( j == GetSubMeshOnCompoundTag() ) @@ -1858,9 +1943,9 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, aSubGroup->OpenOnDisk(); // try to read and set reference to subshape - GEOM::GEOM_Shape_var aSubShape; + 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 ); @@ -1873,10 +1958,10 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, SALOMEDS::SObject_var subShapeSO = myCurrentStudy->FindObjectID( refFromFile ); CORBA::Object_var subShapeObject = SObjectToObject( subShapeSO ); if ( !CORBA::is_nil( subShapeObject ) ) { - aSubShape = GEOM::GEOM_Shape::_narrow( subShapeObject ); - if ( !aSubShape->_is_nil() ) + aSubShapeObject = GEOM::GEOM_Object::_narrow( subShapeObject ); + if ( !aSubShapeObject->_is_nil() ) aSubMesh = SMESH::SMESH_subMesh::_duplicate - ( myNewMeshImpl->createSubMesh( aSubShape ) ); + ( myNewMeshImpl->createSubMesh( aSubShapeObject ) ); if ( aSubMesh->_is_nil() ) continue; string iorSubString = GetORB()->object_to_string( aSubMesh ); @@ -1892,12 +1977,12 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, // VSR: Get submesh data from MED convertor // int anInternalSubmeshId = aSubMesh->GetId(); // this is not a persistent ID, it's an internal one computed from sub-shape // if (myNewMeshImpl->_mapSubMesh.find(anInternalSubmeshId) != myNewMeshImpl->_mapSubMesh.end()) { -// MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " << +// if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): loading from MED file submesh with ID = " << // subid << " for subshape # " << anInternalSubmeshId); // SMESHDS_SubMesh* aSubMeshDS = // myNewMeshImpl->_mapSubMesh[anInternalSubmeshId]->CreateSubMeshDS(); // if ( !aSubMeshDS ) { -// MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " << +// if(MYDEBUG) MESSAGE("VSR - SMESH_Gen_i::Load(): FAILED to create a submesh for subshape # " << // anInternalSubmeshId << " in current mesh!"); // } // else @@ -1931,8 +2016,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, 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() && !aShape->_is_nil() ) - myNewMeshImpl->addHypothesis( aSubShape, anHyp ); + if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() ) + myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp ); } } } @@ -1968,8 +2053,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, 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() && !aShape->_is_nil() ) - myNewMeshImpl->addHypothesis( aSubShape, anHyp ); + if ( !anHyp->_is_nil() && !aShapeObject->_is_nil() ) + myNewMeshImpl->addHypothesis( aSubShapeObject, anHyp ); } } } @@ -1987,23 +2072,122 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, } } - if(hasData){ + if(hasData) { // Read sub-meshes from MED - MESSAGE("JFA - Create all sub-meshes"); + if(MYDEBUG) MESSAGE("JFA - Create all sub-meshes"); myReader.CreateAllSubMeshes(); - } + + + // Read node positions on sub-shapes (SMDS_Position) + + if ( aTopGroup->ExistInternalObject( "Node Positions" )) + { + // There are 5 datasets to read: + // "Nodes on Edges" - ID of node on edge + // "Edge positions" - U parameter on node on edge + // "Nodes on Faces" - ID of node on face + // "Face U positions" - U parameter of node on face + // "Face V positions" - V parameter of node on face + char* aEid_DSName = "Nodes on Edges"; + char* aEu_DSName = "Edge positions"; + char* aFu_DSName = "Face U positions"; + //char* aFid_DSName = "Nodes on Faces"; + //char* aFv_DSName = "Face V positions"; + + // data to retrieve + int nbEids = 0, nbFids = 0; + int *aEids = 0, *aFids = 0; + double *aEpos = 0, *aFupos = 0, *aFvpos = 0; + + // open a group + aGroup = new HDFgroup( "Node Positions", aTopGroup ); + aGroup->OpenOnDisk(); + + // loop on 5 data sets + int aNbObjects = aGroup->nInternalObjects(); + for ( int i = 0; i < aNbObjects; i++ ) + { + // identify dataset + char aDSName[ HDF_NAME_MAX_LEN+1 ]; + aGroup->InternalObjectIndentify( i, aDSName ); + // read data + aDataset = new HDFdataset( aDSName, aGroup ); + aDataset->OpenOnDisk(); + if ( aDataset->GetType() == HDF_FLOAT64 ) // Positions + { + double* pos = new double [ aDataset->GetSize() ]; + aDataset->ReadFromDisk( pos ); + // which one? + if ( strncmp( aDSName, aEu_DSName, strlen( aEu_DSName )) == 0 ) + aEpos = pos; + else if ( strncmp( aDSName, aFu_DSName, strlen( aFu_DSName )) == 0 ) + aFupos = pos; + else + aFvpos = pos; + } + else // NODE IDS + { + int* ids = new int [ aDataset->GetSize() ]; + aDataset->ReadFromDisk( ids ); + // on face or nodes? + if ( strncmp( aDSName, aEid_DSName, strlen( aEid_DSName )) == 0 ) { + aEids = ids; + nbEids = aDataset->GetSize(); + } + else { + aFids = ids; + nbFids = aDataset->GetSize(); + } + } + } // loop on 5 datasets + + // Set node positions on edges or faces + for ( int onFace = 0; onFace < 2; onFace++ ) + { + int nbNodes = ( onFace ? nbFids : nbEids ); + if ( nbNodes == 0 ) continue; + int* aNodeIDs = ( onFace ? aFids : aEids ); + double* aUPos = ( onFace ? aFupos : aEpos ); + double* aVPos = ( onFace ? aFvpos : 0 ); + // loop on node IDs + for ( int iNode = 0; iNode < nbNodes; iNode++ ) + { + const SMDS_MeshNode* node = mySMESHDSMesh->FindNode( aNodeIDs[ iNode ]); + ASSERT( node ); + SMDS_PositionPtr aPos = node->GetPosition(); + ASSERT( aPos ) + if ( onFace ) { + ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_FACE ); + SMDS_FacePosition* fPos = const_cast + ( static_cast( aPos.get() )); + fPos->SetUParameter( aUPos[ iNode ]); + fPos->SetVParameter( aVPos[ iNode ]); + } + else { + ASSERT( aPos->GetTypeOfPosition() == SMDS_TOP_EDGE ); + SMDS_EdgePosition* fPos = const_cast + ( static_cast( aPos.get() )); + fPos->SetUParameter( aUPos[ iNode ]); + } + } + } + if ( aEids ) delete [] aEids; + if ( aFids ) delete [] aFids; + if ( aEpos ) delete [] aEpos; + if ( aFupos ) delete [] aFupos; + if ( aFvpos ) delete [] aFvpos; + + aGroup->CloseOnDisk(); + + } // if ( aTopGroup->ExistInternalObject( "Node Positions" ) ) + } // if ( hasData ) // Recompute State (as computed sub-meshes are restored from MED) - if ( !aShape->_is_nil() ) { + if ( !aShapeObject->_is_nil() ) { MESSAGE("JFA - Compute State Engine ..."); -// map::iterator anAllSubMeshes = myNewMeshImpl->_mapSubMesh.begin(); -// for (; anAllSubMeshes != myNewMeshImpl->_mapSubMesh.end(); anAllSubMeshes++) -// { -// (*anAllSubMeshes).second->GetSubMeshDS(); // init SMESH_subMesh::_meshDS -// (*anAllSubMeshes).second->ComputeStateEngine(SMESH_subMesh::SUBMESH_RESTORED); -// } - TopoDS_Shape myLocShape = GetShapeReader()->GetShape( GetGeomEngine(), aShape ); - myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine(SMESH_subMesh::SUBMESH_RESTORED); + TopoDS_Shape myLocShape = GeomObjectToShape( aShapeObject ); + myNewMeshImpl->GetImpl().GetSubMesh(myLocShape)->ComputeStateEngine + (SMESH_subMesh::SUBMESH_RESTORED); MESSAGE("JFA - Compute State Engine finished"); } @@ -2041,11 +2225,33 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, 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_var 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 ); + } + } + } // Create group servant - SMESH::SMESH_Group_var aNewGroup = SMESH::SMESH_Group::_duplicate - ( myNewMeshImpl->createGroup( (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1), - nameFromFile ) ); + SMESH::ElementType type = (SMESH::ElementType)(ii - GetNodeGroupsTag() + 1); + SMESH::SMESH_GroupBase_var aNewGroup = SMESH::SMESH_GroupBase::_duplicate + ( myNewMeshImpl->createGroup( type, nameFromFile, aShape ) ); // Obtain a SMESHDS_Group object if ( aNewGroup->_is_nil() ) continue; @@ -2054,7 +2260,8 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, int newSubId = myStudyContext->findId( iorSubString ); myStudyContext->mapOldToNew( subid, newSubId ); - SMESH_Group_i* aGroupImpl = dynamic_cast( GetServant( aNewGroup ).in() ); + SMESH_GroupBase_i* aGroupImpl = + dynamic_cast( GetServant( aNewGroup ).in() ); if ( !aGroupImpl ) continue; @@ -2062,11 +2269,13 @@ bool SMESH_Gen_i::Load( SALOMEDS::SComponent_ptr theComponent, if ( !aLocalGroup ) continue; - SMESHDS_Group* aGroupDS = aLocalGroup->GetGroupDS(); - aGroupDS->SetStoreName( name_dataset ); + SMESHDS_GroupBase* aGroupBaseDS = aLocalGroup->GetGroupDS(); + aGroupBaseDS->SetStoreName( name_dataset ); // Fill group with contents from MED file - myReader.GetGroup( aGroupDS ); + SMESHDS_Group* aGrp = dynamic_cast( aGroupBaseDS ); + if ( aGrp ) + myReader.GetGroup( aGrp ); } } aGroup->CloseOnDisk(); @@ -2102,7 +2311,7 @@ bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent, const SALOMEDS::TMPFile& theStream, const char* theURL, bool isMultiFile ) { - MESSAGE( "SMESH_Gen_i::LoadASCII" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LoadASCII" ); return Load( theComponent, theStream, theURL, isMultiFile ); } @@ -2116,10 +2325,10 @@ bool SMESH_Gen_i::LoadASCII( SALOMEDS::SComponent_ptr theComponent, void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent ) { - MESSAGE( "SMESH_Gen_i::Close" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::Close" ); // Clear study contexts data - int studyId = myCurrentStudy->StudyId(); + int studyId = GetCurrentStudyID(); if ( myStudyContextMap.find( studyId ) != myStudyContextMap.end() ) { delete myStudyContextMap[ studyId ]; myStudyContextMap.erase( studyId ); @@ -2137,8 +2346,8 @@ void SMESH_Gen_i::Close( SALOMEDS::SComponent_ptr theComponent ) char* SMESH_Gen_i::ComponentDataType() { - MESSAGE( "SMESH_Gen_i::ComponentDataType" ); - return strdup( "SMESH" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::ComponentDataType" ); + return CORBA::string_dup( "SMESH" ); } @@ -2150,24 +2359,24 @@ char* SMESH_Gen_i::ComponentDataType() */ //============================================================================= -char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject, +char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr /*theSObject*/, const char* IORString, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII ) + CORBA::Boolean /*isMultiFile*/, + CORBA::Boolean /*isASCII*/ ) { - MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::IORToLocalPersistentID" ); StudyContext* myStudyContext = GetCurrentStudyContext(); - if ( strcmp( IORString, "" ) != 0 ) { + if ( myStudyContext && strcmp( IORString, "" ) != 0 ) { int anId = myStudyContext->findId( IORString ); if ( anId ) { - MESSAGE( "VSR " << anId ) + if(MYDEBUG) MESSAGE( "VSR " << anId ) char strId[ 20 ]; sprintf( strId, "%d", anId ); return CORBA::string_dup( strId ); } } - return strdup( "" ); + return CORBA::string_dup( "" ); } //============================================================================= @@ -2178,309 +2387,34 @@ char* SMESH_Gen_i::IORToLocalPersistentID( SALOMEDS::SObject_ptr theSObject, */ //============================================================================= -char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr theSObject, +char* SMESH_Gen_i::LocalPersistentIDToIOR( SALOMEDS::SObject_ptr /*theSObject*/, const char* aLocalPersistentID, - CORBA::Boolean isMultiFile, - CORBA::Boolean isASCII ) + CORBA::Boolean /*isMultiFile*/, + CORBA::Boolean /*isASCII*/ ) { - MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID ); + if(MYDEBUG) MESSAGE( "SMESH_Gen_i::LocalPersistentIDToIOR(): id = " << aLocalPersistentID ); StudyContext* myStudyContext = GetCurrentStudyContext(); - if ( strcmp( aLocalPersistentID, "" ) != 0 ) { + if ( myStudyContext && strcmp( aLocalPersistentID, "" ) != 0 ) { int anId = atoi( aLocalPersistentID ); return CORBA::string_dup( myStudyContext->getIORbyOldId( anId ).c_str() ); } - return strdup( "" ); + return CORBA::string_dup( "" ); } -//============================================================================= -/*! - * SMESH_Gen_i::CanPublishInStudy - * - * Returns true if object can be published in the study - */ -//============================================================================= +//======================================================================= +//function : RegisterObject +//purpose : +//======================================================================= -bool SMESH_Gen_i::CanPublishInStudy(CORBA::Object_ptr theIOR) +int SMESH_Gen_i::RegisterObject(CORBA::Object_ptr theObject) { - SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(theIOR); - if( !aMesh->_is_nil() ) - return true; - - SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(theIOR); - if( !aSubMesh->_is_nil() ) - return true; - - SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(theIOR); - if( !aHyp->_is_nil() ) - return true; - - SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(theIOR); - if( !aGroup->_is_nil() ) - return true; - - return false; -} - -//============================================================================= -/*! - * SMESH_Gen_i::PublishInStudy - * - * Publish object in the study - */ -//============================================================================= - -SALOMEDS::SObject_ptr SMESH_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, - SALOMEDS::SObject_ptr theSObject, - CORBA::Object_ptr theIOR, - const char* theName) -throw (SALOME::SALOME_Exception) -{ - Unexpect aCatch(SALOME_SalomeException); - MESSAGE( "********** SMESH_Gen_i::PublishInStudy()" ); - SALOMEDS::SObject_var aSO; - - // san - first try to find SObject corresponding to SMESH component in theStudy - // It is dangerous to use FindComponent("MESH") for this, as some other component - // of type "MESH" might be present in theStudy. - // So component's user name obtained from ModuleCatalog is passed to FindObject()... - SALOME_ModuleCatalog::ModuleCatalog_var aCat = - SALOME_ModuleCatalog::ModuleCatalog::_narrow( GetNS()->Resolve("/Kernel/ModulCatalog") ); - if ( CORBA::is_nil( aCat ) ) - return aSO._retn(); - - SALOME_ModuleCatalog::Acomponent_var aComp = aCat->GetComponent( "SMESH" ); - if ( CORBA::is_nil( aComp ) ) - return aSO._retn(); - - SALOMEDS::SComponent_var father = - SALOMEDS::SComponent::_narrow( theStudy->FindObject( strdup( aComp->componentusername() ) ) ); - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); - - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributePixMap_var aPixmap; - - if ( father->_is_nil() ) { - father = aStudyBuilder->NewComponent( "MESH" ); - anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributeName" ); - aName = SALOMEDS::AttributeName::_narrow( anAttr ); - aName ->SetValue( strdup( aComp->componentusername() ) ); - anAttr = aStudyBuilder->FindOrCreateAttribute( father, "AttributePixMap" ); - aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); - aPixmap ->SetPixMap( "ICON_OBJBROWSER_SMESH" ); - aStudyBuilder->DefineComponentInstance( father, SMESH_Gen::_this() ); - } - - if ( father->_is_nil() ) - return aSO._retn(); - - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::AttributeSelectable_var aSelAttr; - TCollection_AsciiString anObjName("obj"); - - // Publishing a mesh - SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( theIOR ); - if( !aMesh->_is_nil() ) { - // Find correct free tag - long aTag = FindMaxChildTag( father.in() ); - if ( aTag <= GetAlgorithmsRootTag() ) - aTag = GetAlgorithmsRootTag() + 1; - else - aTag++; - // Add New Mesh - SALOMEDS::SObject_var newMesh = aStudyBuilder->NewObjectToTag( father, aTag ); - anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributePixMap" ); - aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); - aPixmap ->SetPixMap( "ICON_SMESH_TREE_MESH" ); - anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributeIOR" ); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR ->SetValue( GetORB()->object_to_string( aMesh ) ); - aSO = SALOMEDS::SObject::_narrow( newMesh ); - anObjName = TCollection_AsciiString( "Mesh" ); - } - - // Publishing a sub-mesh - SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( theIOR ); - if( aSO->_is_nil() && !aSubMesh->_is_nil() ) { - // try to obtain a parent mesh's SObject - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing submesh..." ); - SALOMEDS::SObject_var aParentSO; - SMESH::SMESH_Mesh_var aParentMesh; - SMESH_subMesh_i* aServant = dynamic_cast( GetServant( aSubMesh ).in() ); - if ( aServant != NULL ) { - aParentMesh = aServant->_mesh_i->_this(); - if ( !aParentMesh->_is_nil() ) { - aParentSO = theStudy->FindObjectIOR( GetORB()->object_to_string( aParentMesh ) ); - } - } - - // Find submesh sub-tree tag - if ( !aParentSO->_is_nil() ) { - long aRootTag = GetSubMeshOnVertexTag(); - char* aRootName = ""; - - SMESH_Mesh_i* aMeshServant = aServant->_mesh_i; - if ( aMeshServant->_mapSubMesh.find( aServant->GetId() ) != aMeshServant->_mapSubMesh.end() ) { - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): local submesh found" ) - SMESH_subMesh* aLocalSubMesh = aMeshServant->_mapSubMesh[aServant->GetId()]; - switch ( aLocalSubMesh->GetSubShape().ShapeType() ) { - case TopAbs_VERTEX: - aRootTag = GetSubMeshOnVertexTag(); - aRootName = "SubMeshes on Vertex"; - break; - case TopAbs_EDGE: - aRootTag = GetSubMeshOnEdgeTag(); - aRootName = "SubMeshes on Edge"; - break; - case TopAbs_FACE: - aRootTag = GetSubMeshOnFaceTag(); - aRootName = "SubMeshes on Face"; - break; - case TopAbs_SOLID: - aRootTag = GetSubMeshOnSolidTag(); - aRootName = "SubMeshes on Solid"; - break; - default: - aRootTag = GetSubMeshOnCompoundTag(); - aRootName = "SubMeshes on Compound"; - break; - } - } - - // Find or create submesh root - SALOMEDS::SObject_var aRootSO; - if ( !aParentSO->FindSubObject ( aRootTag, aRootSO ) ) { - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): creating submesh root..." ) - aRootSO = aStudyBuilder->NewObjectToTag( aParentSO, aRootTag ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeName" ); - aName = SALOMEDS::AttributeName::_narrow( anAttr ); - aName ->SetValue( aRootName ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeSelectable" ); - aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr ); - aSelAttr ->SetSelectable( false ); - } - - // Add new submesh to corresponding sub-tree - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): adding submesh to study..." ) - SALOMEDS::SObject_var newMesh = aStudyBuilder->NewObject( aRootSO ); - anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributePixMap" ); - aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); - aPixmap ->SetPixMap( "ICON_SMESH_TREE_MESH" ); - anAttr = aStudyBuilder->FindOrCreateAttribute( newMesh, "AttributeIOR" ); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR ->SetValue( GetORB()->object_to_string( aSubMesh ) ); - aSO = SALOMEDS::SObject::_narrow( newMesh ); - anObjName = TCollection_AsciiString( "SubMesh" ); - } - } - - // Publishing a hypothesis or algorithm - SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theIOR ); - if( aSO->_is_nil() && !aHyp->_is_nil() ) { - //Find or Create Hypothesis root - SALOMEDS::SObject_var HypothesisRoot; - Standard_Integer aRootTag = - SMESH::SMESH_Algo::_narrow( theIOR )->_is_nil() ? GetHypothesisRootTag() : GetAlgorithmsRootTag(); - - if ( !father->FindSubObject ( aRootTag, HypothesisRoot ) ) { - HypothesisRoot = aStudyBuilder->NewObjectToTag( father, aRootTag ); - anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributeName" ); - aName = SALOMEDS::AttributeName::_narrow( anAttr ); - aName ->SetValue( aRootTag == GetHypothesisRootTag() ? "Hypotheses" : "Algorithms" ); - anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributeSelectable" ); - aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr ); - aSelAttr ->SetSelectable( false ); - anAttr = aStudyBuilder->FindOrCreateAttribute( HypothesisRoot, "AttributePixMap" ); - aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); - aPixmap ->SetPixMap( aRootTag == GetHypothesisRootTag() ? "ICON_SMESH_TREE_HYPO" : "ICON_SMESH_TREE_ALGO" ); - } - - // Add New Hypothesis - string aPmName; - SALOMEDS::SObject_var newHypo = aStudyBuilder->NewObject( HypothesisRoot ); - anAttr = aStudyBuilder->FindOrCreateAttribute( newHypo, "AttributePixMap" ); - aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); - aPmName = ( aRootTag == GetHypothesisRootTag() ? "ICON_SMESH_TREE_HYPO_" : "ICON_SMESH_TREE_ALGO_" ); - aPmName += aHyp->GetName(); - aPixmap ->SetPixMap( aPmName.c_str() ); - anAttr = aStudyBuilder->FindOrCreateAttribute( newHypo, "AttributeIOR" ); - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - anIOR ->SetValue( GetORB()->object_to_string( aHyp ) ); - aSO = SALOMEDS::SObject::_narrow( newHypo ); - anObjName = TCollection_AsciiString( aHyp->GetName() ); - } - - // Publishing a group - SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(theIOR); - if( aSO->_is_nil() && !aGroup->_is_nil() ) { - // try to obtain a parent mesh's SObject - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group..." ); - SALOMEDS::SObject_var aParentSO; - SMESH::SMESH_Mesh_var aParentMesh; - SMESH_Group_i* aServant = dynamic_cast( GetServant( aGroup ).in() ); - if ( aServant != NULL ) { - aParentMesh = SMESH::SMESH_Mesh::_narrow( GetPOA()->servant_to_reference( aServant->GetMeshServant() ) ); - if ( !aParentMesh->_is_nil() ) { - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: refernce to mesh is OK" ); - string anIOR = GetORB()->object_to_string( aParentMesh ); - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: mesh IOR = "<FindObjectIOR( anIOR.c_str() ); - } - } - - // Find proper group sub-tree tag - if ( !aParentSO->_is_nil() ) { - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: parent mesh found" ); - int aType = (int)aGroup->GetType(); - const char* aRootNames[] = { "Compound Groups", "Groups of Nodes", "Groups of Edges", "Groups of Faces", "Groups of Volumes" }; - - // Currently, groups with heterogenous content are not supported - if ( aType != SMESH::ALL ) { - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): publishing group: group type OK" ); - long aRootTag = GetNodeGroupsTag() + aType - 1; - - // Find or create groups root - SALOMEDS::SObject_var aRootSO; - if ( !aParentSO->FindSubObject ( aRootTag, aRootSO ) ) { - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): creating groups root..." ) - aRootSO = aStudyBuilder->NewObjectToTag( aParentSO, aRootTag ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeName" ); - aName = SALOMEDS::AttributeName::_narrow( anAttr ); - aName ->SetValue( aRootNames[aType] ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aRootSO, "AttributeSelectable" ); - aSelAttr = SALOMEDS::AttributeSelectable::_narrow( anAttr ); - aSelAttr ->SetSelectable( false ); - } - - // Add new group to corresponding sub-tree - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): adding group to study..." ) - SALOMEDS::SObject_var aGroupSO = aStudyBuilder->NewObject( aRootSO ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" ); - aPixmap = SALOMEDS::AttributePixMap::_narrow( anAttr ); - aPixmap ->SetPixMap( "ICON_SMESH_TREE_GROUP" ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aGroupSO, "AttributeIOR" ); - anIOR = SALOMEDS::AttributeIOR::_narrow( anAttr ); - anIOR ->SetValue( GetORB()->object_to_string( aGroup ) ); - aSO = SALOMEDS::SObject::_narrow( aGroupSO ); - anObjName = TCollection_AsciiString( "Group" ); - } - } - } - - // Setting SObject's name - if ( !aSO->_is_nil() ) { - if ( strlen( theName ) == 0 ) - anObjName += TCollection_AsciiString( "_" ) + TCollection_AsciiString( aSO->Tag() ); - else - anObjName = TCollection_AsciiString( strdup( theName ) ); - anAttr = aStudyBuilder->FindOrCreateAttribute( aSO, "AttributeName" ); - aName = SALOMEDS::AttributeName::_narrow( anAttr ); - aName ->SetValue( anObjName.ToCString() ); + StudyContext* myStudyContext = GetCurrentStudyContext(); + if ( myStudyContext && !CORBA::is_nil( theObject )) { + string iorString = GetORB()->object_to_string( theObject ); + return myStudyContext->addObject( iorString ); } - - MESSAGE( "********** SMESH_Gen_i::PublishInStudy(): COMPLETED" ) - return aSO._retn(); + return 0; } //============================================================================= @@ -2499,10 +2433,9 @@ extern "C" const char* instanceName, const char* interfaceName ) { - MESSAGE( "PortableServer::ObjectId* SMESHEngine_factory()" ); - SCRUTE(interfaceName); - SMESH_Gen_i * mySMESH_Gen - = new SMESH_Gen_i(orb, poa, contId, instanceName, interfaceName); - return mySMESH_Gen->getId() ; + 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() ; } }