From 792925c2624d09088a0d92767bf79d0939b85a65 Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 11 Dec 2009 09:35:20 +0000 Subject: [PATCH] Debug --- idl/GEOM_Gen.idl | 6 ---- src/GEOM_I/GEOM_Gen_i.cc | 62 +++++++++++++++++++------------- src/GEOM_I/GEOM_Gen_i.hh | 11 ++++++ src/GEOM_I/GEOM_IOperations_i.cc | 4 ++- src/GEOM_I/GEOM_Object_i.cc | 37 +++++++++++++++++++ src/GEOM_I/GEOM_Object_i.hh | 2 ++ 6 files changed, 91 insertions(+), 31 deletions(-) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 1951cbe02..a2aac3e4d 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -3201,12 +3201,6 @@ module GEOM ListOfGO PublishNamedShapesInStudy(in SALOMEDS::Study theStudy, //in SObject theSObject, in Object theObject); - - /*! - * Returns a pointer to SALOME Notebook interface. - * \param theStudyID is a SALOMEDS Study ID - */ - SALOME::Notebook GetNotebook(in long theStudyID); }; }; diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index bff850673..adb3180e1 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -62,6 +62,27 @@ #include "SALOMEDS_Tool.hxx" +// Static variables definition +PortableServer::POA_var GEOM_Gen_i::myPoa; + +//============================================================================= +// function : GetServant() +// purpose : Get servant of the CORBA object +//============================================================================= +PortableServer::ServantBase_var GEOM_Gen_i::GetServant( CORBA::Object_ptr theObject ) +{ + if( CORBA::is_nil( theObject ) || CORBA::is_nil( GetPOA() ) ) + return NULL; + try { + PortableServer::Servant aServant = GetPOA()->reference_to_servant( theObject ); + return aServant; + } + catch (...) { + INFOS( "GetServant - Unknown exception was caught!!!" ); + return NULL; + } +} + //============================================================================ // function : GEOM_Gen_i() // purpose : constructor to be called for servant creation. @@ -73,6 +94,8 @@ GEOM_Gen_i::GEOM_Gen_i(CORBA::ORB_ptr orb, const char *interfaceName) : Engines_Component_i(orb, poa, contId, instanceName, interfaceName) { + myPoa = PortableServer::POA::_duplicate(poa); + _thisObj = this; _id = _poa->activate_object(_thisObj); name_service = new SALOME_NamingService(_orb); @@ -321,27 +344,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy, aNameAttrib->Destroy(); //Set NoteBook variables used in the object creation - /*ASL: temporary commented - TCollection_AsciiString aVars; - CORBA::String_var aString=aShape->GetParameters(); - SALOMEDS::ListOfListOfStrings_var aSections = theStudy->ParseVariables(aString); - for(int i = 0, n = aSections->length(); i < n; i++) { - SALOMEDS::ListOfStrings aListOfVars = aSections[i]; - for(int j = 0, m = aListOfVars.length(); j < m; j++) { - if(theStudy->IsVariable(aListOfVars[j].in())) - aVars += TCollection_AsciiString(aListOfVars[j].in()); - if(j != m-1) - aVars += ":"; - } - if(i != n-1) - aVars += "|"; - } - - anAttr = aStudyBuilder->FindOrCreateAttribute(aResultSO, "AttributeString"); - SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow(anAttr); - aStringAttrib->SetValue(aVars.ToCString()); - aStringAttrib->Destroy(); - */ + if( GEOM_Object_i* aServant = dynamic_cast( GetServant( aShape ).in() ) ) + aServant->UpdateStringAttribute(); aFather->Destroy(); @@ -1816,14 +1820,24 @@ char* GEOM_Gen_i::getObjectInfo(CORBA::Long studyId, const char* entry) } //================================================================================= -// function : GetNotebook() -// purpose : Returns a pointer to SALOME Notebook object by an id of the study +// function : GetStudy() +// purpose : Returns a pointer to SALOMEDS Study object by its id //================================================================================= -SALOME::Notebook_ptr GEOM_Gen_i::GetNotebook( CORBA::Long theStudyID ) +SALOMEDS::Study_ptr GEOM_Gen_i::GetStudy(CORBA::Long theStudyID) { CORBA::Object_var aSMObject = name_service->Resolve( "/myStudyManager" ); SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow( aSMObject ); SALOMEDS::Study_var aStudy = aStudyManager->GetStudyByID( theStudyID ); + return aStudy._retn(); +} + +//================================================================================= +// function : GetNotebook() +// purpose : Returns a pointer to SALOME Notebook object by an id of the study +//================================================================================= +SALOME::Notebook_ptr GEOM_Gen_i::GetNotebook( CORBA::Long theStudyID ) +{ + SALOMEDS::Study_ptr aStudy = GetStudy( theStudyID ); SALOME::Notebook_var aNotebook = aStudy->GetNotebook(); return aNotebook._retn(); } diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 967cd9ca5..a28e6bc02 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -62,6 +62,15 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi { public: + //-----------------------------------------------------------------------// + // Static methods // + //-----------------------------------------------------------------------// + + // Get SMESH module's POA object + static PortableServer::POA_var GetPOA() { return myPoa;} + // Get object of the CORBA reference + static PortableServer::ServantBase_var GetServant( CORBA::Object_ptr theObject ); + //-----------------------------------------------------------------------// // Constructor / Destructor // //-----------------------------------------------------------------------// @@ -242,6 +251,7 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi virtual bool hasObjectInfo(); virtual char* getObjectInfo(CORBA::Long studyId, const char* entry); + SALOMEDS::Study_ptr GetStudy(CORBA::Long theStudyID); SALOME::Notebook_ptr GetNotebook(CORBA::Long theStudyID); //-----------------------------------------------------------------------// @@ -276,6 +286,7 @@ class GEOM_I_EXPORT GEOM_Gen_i: virtual public POA_GEOM::GEOM_Gen, virtual publi GEOM::ListOfGO_var aResList); private: + static PortableServer::POA_var myPoa; // POA reference ::GEOMImpl_Gen* _impl; SALOME_NamingService * name_service; diff --git a/src/GEOM_I/GEOM_IOperations_i.cc b/src/GEOM_I/GEOM_IOperations_i.cc index 5116b98cf..81086012e 100644 --- a/src/GEOM_I/GEOM_IOperations_i.cc +++ b/src/GEOM_I/GEOM_IOperations_i.cc @@ -20,6 +20,7 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com #include "GEOM_IOperations_i.hh" +#include "GEOM_Gen_i.hh" #include "GEOM_Engine.hxx" @@ -139,7 +140,8 @@ GEOM::GEOM_Object_ptr GEOM_IOperations_i::GetObject(Handle(GEOM_Object) theObjec GO = _engine->GetObject(theObject->GetDocID(), anEntry.ToCString()); GEOM::GEOM_Object_ptr aResult = GO._retn(); if (theIsDependent && !CORBA::is_nil(aResult)) { - SALOME::Notebook_ptr aNotebook = _engine->GetNotebook(aResult->GetStudyID()); + GEOM_Gen_i* aGEOMGen = dynamic_cast(GEOM_Gen_i::GetServant(_engine).in()); + SALOME::Notebook_ptr aNotebook = aGEOMGen->GetNotebook(aResult->GetStudyID()); if (!CORBA::is_nil(aNotebook)) aResult->StoreDependencies(aNotebook); } diff --git a/src/GEOM_I/GEOM_Object_i.cc b/src/GEOM_I/GEOM_Object_i.cc index 2e9b99946..83e536deb 100644 --- a/src/GEOM_I/GEOM_Object_i.cc +++ b/src/GEOM_I/GEOM_Object_i.cc @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -446,6 +447,8 @@ void GEOM_Object_i::SetParameters( SALOME::Notebook_ptr theNotebook, const SALOM aFunc->SetParam( i+1, TCollection_AsciiString( aParam.c_str() ) ); _parameters.push_back( aParam ); } + + UpdateStringAttribute(); } SALOME::StringArray* GEOM_Object_i::GetParameters() @@ -529,3 +532,37 @@ void GEOM_Object_i::StoreDependencies( SALOME::Notebook_ptr theNotebook ) theNotebook->AddDependency( _this(), obj._retn() ); } } + +void GEOM_Object_i::UpdateStringAttribute() +{ + GEOM_Gen_i* aGEOMGen = dynamic_cast( GEOM_Gen_i::GetServant( _engine ).in() ); + + SALOME::Notebook_ptr aNotebook = aGEOMGen->GetNotebook( GetStudyID() ); + + SALOME::StringArray* anObjectParameters = aNotebook->GetObjectParameters( GetComponent(), GetEntry() ); + int aParametersLength = anObjectParameters ? anObjectParameters->length() : 0; + if( aParametersLength == 0 ) + return; + + SALOMEDS::Study_ptr aStudy = aGEOMGen->GetStudy( GetStudyID() ); + SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); + SALOMEDS::SObject_var aSObject = aStudy->FindObjectID( GetStudyEntry() ); + if( CORBA::is_nil( aSObject ) ) + return; + + SALOMEDS::GenericAttribute_var anAttr = aStudyBuilder->FindOrCreateAttribute( aSObject, "AttributeString" ); + SALOMEDS::AttributeString_var aStringAttrib = SALOMEDS::AttributeString::_narrow( anAttr ); + + std::string aString; + for( int i = 0, n = anObjectParameters->length(); i < n; i++ ) { + std::string aParameter = anObjectParameters->operator[](i).in(); + if( aParameter != "" ) + { + if( aString != "" ) + aString += ", "; + aString += aParameter; + } + } + aStringAttrib->SetValue( aString.c_str() ); + aStringAttrib->Destroy(); +} diff --git a/src/GEOM_I/GEOM_Object_i.hh b/src/GEOM_I/GEOM_Object_i.hh index d3e40bad0..97545eddd 100644 --- a/src/GEOM_I/GEOM_Object_i.hh +++ b/src/GEOM_I/GEOM_Object_i.hh @@ -104,6 +104,8 @@ class GEOM_I_EXPORT GEOM_Object_i : public virtual POA_GEOM::GEOM_Object, public virtual void Update( SALOME::Notebook_ptr theNotebook ); + virtual void UpdateStringAttribute(); + Handle(GEOM_Object) GetImpl() { return _impl; } private: -- 2.39.2