Back to index

salome-gui  6.5.0
SALOME_GuiServices.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 // Author: Guillaume Boulant (EDF/R&D)
00021 
00022 #include "SALOME_GuiServices.hxx"
00023 #include <SUIT_Session.h>
00024 
00025 namespace GUI {
00042   SalomeApp_Application * getSalomeApplication() {
00043     static SalomeApp_Application * app;
00044     if ( app == NULL ) {
00045       app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
00046     }
00047     return app;
00048   }
00049 
00057   LightApp_SelectionMgr * getSelectionManager() {
00058     SalomeApp_Application* anApp = GUI::getSalomeApplication();
00059     if ( anApp == NULL ) return NULL;
00060     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
00061   }
00062 
00063 
00064   SUIT_ResourceMgr * getResourcesManager() {
00065     return SUIT_Session::session()->resourceMgr();
00066   }
00067   // Note that the resource manager can be also retrieved from the
00068   // SALOME application using the resourceMgr() method:
00069   // 
00070 
00078   int getActiveStudyId() {
00079     SALOME::Session_var aSession = KERNEL::getSalomeSession();
00080     if ( CORBA::is_nil(aSession) ) {
00081       INFOS("ERR: can't request for active study because the session is NULL");
00082       return -1;
00083     }
00084     return aSession->GetActiveStudyId();
00085   }
00086 
00091   SALOMEDS::Study_ptr getActiveStudy() {
00092     return KERNEL::getStudyById(getActiveStudyId());
00093   }
00094 
00095 
00096   // __GBO__ Question: what is the difference between a
00097   // SALOMEDS::Study and a SalomeApp_Study?
00098   SalomeApp_Study* getSalomeAppActiveStudy() {
00099     SUIT_Application* app = getSalomeApplication();
00100     if( app )
00101       return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
00102     else
00103       return NULL;
00104   }
00105 
00106 
00107   SALOMEDS::SObject_ptr IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) {
00108     if (!iobject.IsNull()) {
00109       if (iobject->hasEntry()) {
00110         SalomeApp_Study* appStudy = getSalomeAppActiveStudy();
00111         if ( appStudy != NULL ) {
00112           //
00113           // IMPORTANT NOTE:
00114           //
00115           // Note that the SalomeApp_Study give acces to shared
00116           // pointer (i.e. _PTR(<BaseClassName>)) that points to proxy
00117           // objects (i.e. SALOMEDSClien_<BaseClassName>) that embeds
00118           // the CORBA servants (i.e. SALOMEDS::<BaseClassName>_ptr).
00119           // Then to retrieve the corba servant, a method is to
00120           // retrieve the SALOMEDS::Study servant first and the to
00121           // request this servant to get the SObject given its entry.
00122           //
00123           _PTR(Study) studyClient = appStudy->studyDS();
00124           SALOMEDS::Study_var study = KERNEL::getStudyManager()->GetStudyByID(studyClient->StudyId());
00125           SALOMEDS::SObject_ptr sobject = study->FindObjectID(iobject->getEntry());
00126           return sobject;
00127         }
00128       }
00129     }
00130     return SALOMEDS::SObject::_nil();
00131   }
00132 
00133 }
00134