Salome HOME
Merge branch 'V8_3_BR' into V8_4_BR
[modules/gui.git] / src / Session / Session_Session_i.cxx
index a075efc134e5b70387b5f1878a12233d0ef1598d..95103de9ce9e2bdd5ac6421b9e2917bbeea932c7 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  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
 
 #include "SALOME_NamingService.hxx"
 #include "SALOME_Event.h"
-
+#include "SalomeApp_Engine_i.h"
+#include "LightApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "SALOME_ListIO.hxx"
 #include "SUIT_Session.h"
 #include "SUIT_Desktop.h"
 #include "SUIT_Study.h"
@@ -43,7 +46,7 @@
 #include <OSD_SharedLibrary.hxx>
 #include <OSD_Function.hxx>
 
-#ifdef WNT
+#ifdef WIN32
 # include <process.h>
 #else
 #include <unistd.h>
@@ -61,7 +64,7 @@ SALOME_Session_i::SALOME_Session_i(int argc,
 {
   _argc = argc ;
   _argv = argv ;
-  _isGUI = FALSE ;
+  _isGUI = false ;
   _runningStudies= 0 ;
   _orb = CORBA::ORB::_duplicate(orb) ;
   _poa = PortableServer::POA::_duplicate(poa) ;
@@ -80,10 +83,16 @@ Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibra
   typedef Engines::EngineComponent_ptr TGetImpl(CORBA::ORB_ptr,
                                                 PortableServer::POA_ptr,
                                                 SALOME_NamingService*,QMutex*);
-  OSD_SharedLibrary  aSharedLibrary(const_cast<char*>(theLibraryName));
-  if(aSharedLibrary.DlOpen(OSD_RTLD_LAZY))
-    if(OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
+  OSD_SharedLibrary aSharedLibrary(const_cast<char*>(theLibraryName));
+  if (aSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
+    if (OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
       return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
+  }
+  CORBA::Object_var obj = SalomeApp_Engine_i::EngineForComponent(theLibraryName, true);
+  if (!CORBA::is_nil(obj)){
+    Engines::EngineComponent_var anEngine = Engines::EngineComponent::_narrow(obj);
+    return anEngine._retn();
+  }
   return Engines::EngineComponent::_nil();
 }
 
@@ -248,7 +257,7 @@ CORBA::Long SALOME_Session_i::GetActiveStudyId()
 
 CORBA::Long SALOME_Session_i::getPID() {
   return (CORBA::Long)
-#ifndef WNT
+#ifndef WIN32
     getpid();
 #else
     _getpid();
@@ -303,11 +312,44 @@ void SALOME_Session_i::emitMessage(const char* theMessage)
       if ( SUIT_Session::session()->activeApplication()->desktop() ) {
         ProcessVoidEvent( new TEvent(theMessage) );
       }
+      else {
+       MESSAGE("try to emit message '"<<theMessage<<"' but there is no desktop");
+      }
+    }
+    else {
+      MESSAGE("try to emit message '"<<theMessage<<"' but there is no application");
     }
   }
+  else {
+    MESSAGE("try to emit message '"<<theMessage<<"' but there is no session");
+  }
 }
 
 void SALOME_Session_i::emitMessageOneWay(const char* theMessage)
 {
   emitMessage(theMessage);
 }
+
+SALOME::StringSeq* SALOME_Session_i::getSelection()
+{
+  SALOME::StringSeq_var selection = new SALOME::StringSeq;
+  _GUIMutex->lock();
+  if ( SUIT_Session::session() ) {
+    LightApp_Application* app = dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() );
+    if ( app ) {
+      LightApp_SelectionMgr* selMgr = dynamic_cast<LightApp_SelectionMgr*>( app->selectionMgr() );
+      SALOME_ListIO selected;
+      selMgr->selectedObjects( selected );
+      selection->length( selected.Extent() );
+      int nbSel = 0;
+      for ( SALOME_ListIteratorOfListIO it( selected ); it.More(); it.Next() ) {
+        Handle( SALOME_InteractiveObject ) io = it.Value();
+        if ( io->hasEntry() )
+          selection[nbSel++] = CORBA::string_dup( io->getEntry() );
+      }
+      selection->length( nbSel );
+    }
+  }
+  _GUIMutex->unlock();
+  return selection._retn();
+}