Salome HOME
Make HELLO component appear into "salome sesionless"
[samples/hello.git] / src / HELLOGUI / HELLOGUI.cxx
index f602fe75f11bb5761fbe26a0bf181dfd410cf589..d9c8dc4362fe91c34fd94268605b6db961d97bb8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,6 +22,7 @@
 
 #include "HELLOGUI.h"
 #include "HELLO_version.h"
+#include "HELLO_Component_Generator.hxx"
 
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
@@ -40,6 +41,8 @@
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SALOMEDS_SObject.hxx>
 #include <SALOMEDS_Study.hxx>
+#include "SALOME_NamingService_Abstract.hxx"
+#include "SALOME_KernelServices.hxx"
 
 #include <QInputDialog>
 
@@ -93,7 +96,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
@@ -158,9 +161,9 @@ void HELLOGUI::initialize( CAM_Application* app )
 
   // create toolbars
   int aToolId;
-  aToolId = createTool ( tr( "TOOL_TEST" ) );                           // Test toolbar
+  aToolId = createTool ( tr( "TOOL_TEST" ), QString( "HelloTest" ) );   // Test toolbar
   createTool( OpTestMe, aToolId );                                      // Test - Test me
-  aToolId = createTool ( tr( "TOOL_HELLO" ) );                          // Hello toolbar
+  aToolId = createTool ( tr( "TOOL_HELLO" ), QString( "HelloMain" ) );  // Hello toolbar
   createTool( OpHello, aToolId );                                       // Hello - Hello
   createTool( OpGoodbye, aToolId );                                     // Hello - Goodbye
 
@@ -256,9 +259,11 @@ void HELLOGUI::windows( QMap<int, int>& theMap ) const
   // want Object browser, in the left area
   theMap.insert( SalomeApp_Application::WT_ObjectBrowser,
                 Qt::LeftDockWidgetArea );
+#ifndef DISABLE_PYCONSOLE
   // want Python console, in the bottom area
   theMap.insert( SalomeApp_Application::WT_PyConsole,
                 Qt::BottomDockWidgetArea );
+#endif
 }
 
 /*!
@@ -763,9 +768,6 @@ void HELLOGUI::testMe()
 */
 void HELLOGUI::hello()
 {
-  SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( 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" ),
@@ -773,7 +775,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);
@@ -841,7 +843,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);
@@ -882,9 +884,20 @@ void HELLOGUI::goodbye()
 void HELLOGUI::init()
 {
   // initialize HELLO module engine (load, if necessary)
-  if ( CORBA::is_nil( myEngine ) ) {
-    Engines::EngineComponent_var comp =
-    SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "HELLO" );
+  if ( CORBA::is_nil( myEngine ) )
+  {
+    SALOME_NamingService_Abstract *ns = SalomeApp_Application::namingService();
+    Engines::EngineComponent_var comp;
+    if(ns->IsTrueNS())
+    {
+      comp = SalomeApp_Application::lcc()->FindOrLoad_Component( "FactoryServer", "HELLO" );
+    }
+    else
+    {
+      comp = RetrieveHELLOInstance();
+      CORBA::Object_var comp2 = CORBA::Object::_narrow(comp);
+      KERNEL::RegisterCompo("HELLO",comp2);
+    }
     myEngine = HELLO_ORB::HELLO_Gen::_narrow( comp );
   }
 }
@@ -892,11 +905,13 @@ void HELLOGUI::init()
 // Export the module
 extern "C" {
   // FACTORY FUNCTION: create an instance of the Hello module GUI
+  HELLO_EXPORT
   CAM_Module* createModule()
   {
     return new HELLOGUI();
   }
   // VERSIONING FUNCTION: get Hello module's version identifier
+  HELLO_EXPORT
   char* getModuleVersion() 
   {
     return (char*)HELLO_VERSION_STR; // HELLO_VERSION_STR is defined in HELLO_version.h