From 483f6a1f9b2c4d31cfd7aad71a8da40d14cce20c Mon Sep 17 00:00:00 2001 From: mpa Date: Fri, 3 Feb 2017 16:18:45 +0300 Subject: [PATCH] Deleted Study parameter --- bin/test_hello.py | 10 +++++----- doc/input/index.doc | 17 +++++++---------- idl/HELLO_Gen.idl | 6 ++---- resources/HELLOCatalog.xml.in | 11 ----------- src/HELLO/CMakeLists.txt | 1 + src/HELLO/HELLO.cxx | 35 ++++++++++++++++++----------------- src/HELLO/HELLO.hxx | 4 ++-- src/HELLOGUI/HELLOGUI.cxx | 9 +++------ 8 files changed, 38 insertions(+), 55 deletions(-) diff --git a/bin/test_hello.py b/bin/test_hello.py index 28c76ee..6f15512 100755 --- a/bin/test_hello.py +++ b/bin/test_hello.py @@ -31,27 +31,27 @@ hello = salome.lcc.FindOrLoadComponent('FactoryServer', 'HELLO') # test HELLO module print "Say hello to John: should be OK" -if hello.hello(salome.myStudy, "John") != HELLO_ORB.OP_OK: +if hello.hello("John") != HELLO_ORB.OP_OK: print "ERROR: wrong operation code is returned" else: print "OK" print "Say hello to John: should answer 'already met'" -if hello.hello(salome.myStudy, "John") != HELLO_ORB.OP_ERR_ALREADY_MET: +if hello.hello("John") != HELLO_ORB.OP_ERR_ALREADY_MET: print "ERROR: wrong operation code is returned" else: print "OK" print "Say goodbye to Margaret: should answer 'did not meet yet'" -if hello.goodbye(salome.myStudy, "Margaret") != HELLO_ORB.OP_ERR_DID_NOT_MEET: +if hello.goodbye("Margaret") != HELLO_ORB.OP_ERR_DID_NOT_MEET: print "ERROR: wrong operation code is returned" else: print "OK" print "Say hello to John: should be OK" -if hello.goodbye(salome.myStudy, "John") != HELLO_ORB.OP_OK: +if hello.goodbye("John") != HELLO_ORB.OP_OK: print "ERROR: wrong operation code is returned" else: print "OK" print "Say hello to John: should answer 'did not meet yet'" -if hello.goodbye(salome.myStudy, "John") != HELLO_ORB.OP_ERR_DID_NOT_MEET: +if hello.goodbye("John") != HELLO_ORB.OP_ERR_DID_NOT_MEET: print "ERROR: wrong operation code is returned" else: print "OK" diff --git a/doc/input/index.doc b/doc/input/index.doc index 3811601..a49d21b 100644 --- a/doc/input/index.doc +++ b/doc/input/index.doc @@ -28,7 +28,7 @@ The example module chosen to illustrate the process of SALOME module development is very simple. The module contains a single component and this component provides several services called \b hello and \b goodbye. -Each of these functions accepts a reference to the SALOME study and +Each of these functions accepts a character string as the arguments and returns the status of the operation. The component also provides a simple GUI. @@ -447,11 +447,11 @@ In particular, \a HELLO class implements \a hello() and \a goodbye() functions that are defined in the IDL interface \a HELLO_ORB::HELLO_Gen. \code -HELLO_ORB::status HELLO::hello( SALOMEDS::Study_ptr study, const char* name ) +HELLO_ORB::status HELLO::hello( const char* name ) { ... } -HELLO_ORB::status HELLO::goodbye( SALOMEDS::Study_ptr study, const char* name ) +HELLO_ORB::status HELLO::goodbye( const char* name ) { ... } @@ -727,9 +727,6 @@ CORBA service. \code void HELLOGUI::hello() { - SalomeApp_Study* study = dynamic_cast( application()->activeStudy() ); - _PTR(Study) studyDS = study->studyDS(); - // request user name bool ok; QString name = QInputDialog::getText( getApp()->desktop(), tr( "QUE_HELLO_TITLE" ), tr( "QUE_ENTER_NAME" ), @@ -737,7 +734,7 @@ void HELLOGUI::hello() if ( ok && !name.trimmed().isEmpty() ) { // say hello to SALOME - HELLO_ORB::status status = engine()->hello( _CAST(Study, studyDS)->GetStudy(), (const char*)name.toLatin1() ); + HELLO_ORB::status status = engine()->hello( (const char*)name.toLatin1() ); // update Object browser getApp()->updateObjectBrowser(true); @@ -802,7 +799,7 @@ void HELLOGUI::goodbye() if ( !name.trimmed().isEmpty() ) { // say goodby to SALOME - HELLO_ORB::status status = engine()->goodbye( _CAST(Study, studyDS)->GetStudy(), (const char*)name.toLatin1() ); + HELLO_ORB::status status = engine()->goodbye( (const char*)name.toLatin1() ); // update Object browser getApp()->updateObjectBrowser(true); @@ -991,7 +988,7 @@ by means of the \a container variable: >> salome.salome_init() >> import HELLO_ORB >> c = container.load_impl("HELLO", "HELLO") ->> c.hello(salome.myStudy, "Christian") +>> c.hello("Christian") The last instruction invokes HELLO module's service \a hello(). Proceed as @@ -1033,7 +1030,7 @@ is contained in the \c runHELLO.py \a test() function. import salome salome.salome_init() c = test(clt) - c.hello(salome.myStudy, "Christian") + c.hello("Christian") The test function creates the LifeCycle object. It then asks for the diff --git a/idl/HELLO_Gen.idl b/idl/HELLO_Gen.idl index 1dfbc73..f009318 100644 --- a/idl/HELLO_Gen.idl +++ b/idl/HELLO_Gen.idl @@ -56,20 +56,18 @@ module HELLO_ORB { /*! \brief Say hello to \a name - \param study SALOME study \param name person's name \return operation status */ - status hello( in SALOMEDS::Study study, in string name ) + status hello( in string name ) raises (SALOME::SALOME_Exception); /*! \brief Say goodbye to \a name - \param study SALOME study \param name person's name \return operation status */ - status goodbye( in SALOMEDS::Study study, in string name ) + status goodbye( in string name ) raises (SALOME::SALOME_Exception); /*! diff --git a/resources/HELLOCatalog.xml.in b/resources/HELLOCatalog.xml.in index a6d104c..949d7ba 100644 --- a/resources/HELLOCatalog.xml.in +++ b/resources/HELLOCatalog.xml.in @@ -42,7 +42,6 @@ Vadim SANDLER @SALOMEHELLO_VERSION@ Sample module - 1 1 HELLO.png @@ -58,11 +57,6 @@ Hello function 1 - - study - Study - study - name string @@ -85,11 +79,6 @@ Goodbye function 0 - - study - Study - study - name string diff --git a/src/HELLO/CMakeLists.txt b/src/HELLO/CMakeLists.txt index cc43c35..f005bcc 100644 --- a/src/HELLO/CMakeLists.txt +++ b/src/HELLO/CMakeLists.txt @@ -37,6 +37,7 @@ SET(_link_LIBRARIES ${KERNEL_SalomeIDLKernel} ${KERNEL_OpUtil} ${KERNEL_SalomeContainer} + ${KERNEL_SalomeKernelHelpers} SalomeIDLHELLO ) diff --git a/src/HELLO/HELLO.cxx b/src/HELLO/HELLO.cxx index e9a5636..5513802 100755 --- a/src/HELLO/HELLO.cxx +++ b/src/HELLO/HELLO.cxx @@ -23,6 +23,7 @@ #include "HELLO.hxx" #include "HELLO_version.h" +#include #include #include CORBA_CLIENT_HEADER(SALOMEDS) #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes) @@ -74,11 +75,10 @@ HELLO::~HELLO() /*! \brief Say hello to \a name - \param study SALOME study \param name person's name \return operation status */ -HELLO_ORB::status HELLO::hello( SALOMEDS::Study_ptr study, const char* name ) +HELLO_ORB::status HELLO::hello( const char* name ) { // set exception handler to catch unexpected CORBA exceptions Unexpect aCatch(SALOME_SalomeException); @@ -86,23 +86,24 @@ HELLO_ORB::status HELLO::hello( SALOMEDS::Study_ptr study, const char* name ) // set result status to error initially HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN; + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); // check if reference to study is valid - if ( !CORBA::is_nil( study ) ) { + if ( !CORBA::is_nil( aStudy ) ) { // get full object path std::string fullName = studyName( name ); // check if the object with the same name is already registered in the study - SALOMEDS::SObject_var sobj = study->FindObjectByPath( fullName.c_str() ); + SALOMEDS::SObject_var sobj = aStudy->FindObjectByPath( fullName.c_str() ); if ( !CORBA::is_nil( sobj ) ) { // person is already registered in the study -> ERROR result = HELLO_ORB::OP_ERR_ALREADY_MET; } else { // person is not registered yet -> register - SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); // study builder - SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); // use case builder + SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder(); // study builder + SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder(); // use case builder // find HELLO component; create it if not found - SALOMEDS::SComponent_var father = study->FindComponent( "HELLO" ); + SALOMEDS::SComponent_var father = aStudy->FindComponent( "HELLO" ); if ( CORBA::is_nil( father ) ) { // create component father = studyBuilder->NewComponent( "HELLO" ); @@ -140,11 +141,10 @@ HELLO_ORB::status HELLO::hello( SALOMEDS::Study_ptr study, const char* name ) /*! \brief Say goodbye to \a name - \param study SALOME study \param name person's name \return operation status */ -HELLO_ORB::status HELLO::goodbye( SALOMEDS::Study_ptr study, const char* name ) +HELLO_ORB::status HELLO::goodbye( const char* name ) { // set exception handler to catch unexpected CORBA exceptions Unexpect aCatch(SALOME_SalomeException); @@ -152,8 +152,9 @@ HELLO_ORB::status HELLO::goodbye( SALOMEDS::Study_ptr study, const char* name ) // set result status to error initially HELLO_ORB::status result = HELLO_ORB::OP_ERR_UNKNOWN; + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); // check if reference to study is valid - if ( !CORBA::is_nil( study ) ) { + if ( !CORBA::is_nil( aStudy ) ) { // get full object path std::string fullName = studyName( name ); @@ -162,9 +163,9 @@ HELLO_ORB::status HELLO::goodbye( SALOMEDS::Study_ptr study, const char* name ) // check if the object with the same name is registered in the study // find all objects with same name - SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); // study builder - SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); // use case builder - SALOMEDS::SObject_var sobj = study->FindObjectByPath( fullName.c_str() ); + SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder(); // study builder + SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder(); // use case builder + SALOMEDS::SObject_var sobj = aStudy->FindObjectByPath( fullName.c_str() ); while ( !CORBA::is_nil( sobj ) ) { std::list toRemove; toRemove.push_back( sobj ); @@ -187,7 +188,7 @@ HELLO_ORB::status HELLO::goodbye( SALOMEDS::Study_ptr study, const char* name ) // set operation status to OK as at least one object is removed result = HELLO_ORB::OP_OK; } - sobj = study->FindObjectByPath( fullName.c_str() ); + sobj = aStudy->FindObjectByPath( fullName.c_str() ); } } @@ -211,9 +212,9 @@ void HELLO::copyOrMove( const HELLO_ORB::object_list& what, { if ( CORBA::is_nil( where ) ) return; // bad parent - SALOMEDS::Study_var study = where->GetStudy(); // study - SALOMEDS::StudyBuilder_var studyBuilder = study->NewBuilder(); // study builder - SALOMEDS::UseCaseBuilder_var useCaseBuilder = study->GetUseCaseBuilder(); // use case builder + SALOMEDS::Study_var aStudy = KERNEL::getStudyServant(); + SALOMEDS::StudyBuilder_var studyBuilder = aStudy->NewBuilder(); // study builder + SALOMEDS::UseCaseBuilder_var useCaseBuilder = aStudy->GetUseCaseBuilder(); // use case builder SALOMEDS::SComponent_var father = where->GetFatherComponent(); // father component std::string dataType = father->ComponentDataType(); if ( dataType != "HELLO" ) return; // not a HELLO component diff --git a/src/HELLO/HELLO.hxx b/src/HELLO/HELLO.hxx index 36b2350..7b61e14 100644 --- a/src/HELLO/HELLO.hxx +++ b/src/HELLO/HELLO.hxx @@ -50,8 +50,8 @@ public: const char* interfaceName ); virtual ~HELLO(); - HELLO_ORB::status hello ( SALOMEDS::Study_ptr study, const char* name ); - HELLO_ORB::status goodbye( SALOMEDS::Study_ptr study, const char* name ); + HELLO_ORB::status hello ( const char* name ); + HELLO_ORB::status goodbye( const char* name ); void copyOrMove( const HELLO_ORB::object_list& what, SALOMEDS::SObject_ptr where, CORBA::Long row, CORBA::Boolean isCopy ); diff --git a/src/HELLOGUI/HELLOGUI.cxx b/src/HELLOGUI/HELLOGUI.cxx index 8eccb30..f40eca0 100644 --- a/src/HELLOGUI/HELLOGUI.cxx +++ b/src/HELLOGUI/HELLOGUI.cxx @@ -93,7 +93,7 @@ HELLO_ORB::HELLO_Gen_var HELLOGUI::engine() Perform general module initialization (like creation of actions, menus, toolbars, etc). - \note This function is invoked only once per study, when the module + \note This function is invoked only once, when the module is first time activated by the user. The study associated with the application might not exist (created or opened) when this function is invoked, so it is not @@ -765,9 +765,6 @@ void HELLOGUI::testMe() */ void HELLOGUI::hello() { - SalomeApp_Study* study = dynamic_cast( application()->activeStudy() ); - _PTR(Study) studyDS = study->studyDS(); - // request user name bool ok; QString name = QInputDialog::getText( getApp()->desktop(), tr( "QUE_HELLO_TITLE" ), tr( "QUE_ENTER_NAME" ), @@ -775,7 +772,7 @@ void HELLOGUI::hello() if ( ok && !name.trimmed().isEmpty() ) { // say hello to SALOME - HELLO_ORB::status status = engine()->hello( _CAST(Study, studyDS)->GetStudy(), (const char*)name.toLatin1() ); + HELLO_ORB::status status = engine()->hello( (const char*)name.toLatin1() ); // update Object browser getApp()->updateObjectBrowser(true); @@ -843,7 +840,7 @@ void HELLOGUI::goodbye() if ( !name.trimmed().isEmpty() ) { // say goodby to SALOME - HELLO_ORB::status status = engine()->goodbye( _CAST(Study, studyDS)->GetStudy(), (const char*)name.toLatin1() ); + HELLO_ORB::status status = engine()->goodbye( (const char*)name.toLatin1() ); // update Object browser getApp()->updateObjectBrowser(true); -- 2.39.2