1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Author: Guillaume Boulant (EDF/R&D)
22 #include "SALOME_GuiServices.hxx"
23 #include <SUIT_Session.h>
27 * Get the SALOME application, i.e. the main GUI framework of
28 * SALOME. This function returns a pointer to the singleton instance
29 * of the SalomeApp_Application.
31 * The SALOME application can be used to get reference to
32 * the SALOME KERNEL services such that the naming service, the
33 * lifeCycleCORBA, ... Theses services can be retrieved using static
34 * functions (not required to get the singleton instance):
36 * SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
38 * Please note that this usage can be done only from within the
39 * SALOME session server process, i.e. the process that embed the
42 SalomeApp_Application * getSalomeApplication() {
43 static SalomeApp_Application * app;
45 app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
51 * Get the selection manager of the SALOME application. The
52 * selection manager can be used to get the selected items in the
53 * objects browser that is a GUI display of the active study.
54 * The function returns a pointer to the selectionMgr attribute of
55 * the SalomeApp_Application singleton instance.
57 LightApp_SelectionMgr * getSelectionManager() {
58 SalomeApp_Application* anApp = GUI::getSalomeApplication();
59 if ( anApp == NULL ) return NULL;
60 return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
64 SUIT_ResourceMgr * getResourcesManager() {
65 return SUIT_Session::session()->resourceMgr();
67 // Note that the resource manager can be also retrieved from the
68 // SALOME application using the resourceMgr() method:
72 * This returns the current active study id if an active study is
73 * defined in the SALOME session, returns -1 otherwise. Note that
74 * the active study doesn't make sense outside of the GUI SALOME
75 * process, i.e. the SALOME_SessionServer embedding the
76 * SalomeApp_Application.
78 int getActiveStudyId() {
79 SALOME::Session_var aSession = KERNEL::getSalomeSession();
80 if ( CORBA::is_nil(aSession) ) {
81 INFOS("ERR: can't request for active study because the session is NULL");
84 return aSession->GetActiveStudyId();
88 * This returns the current active study if an active study is
89 * defined in the SALOME session, returns null otherwise.
91 SALOMEDS::Study_ptr getActiveStudy() {
92 return KERNEL::getStudyById(getActiveStudyId());
96 // __GBO__ Question: what is the difference between a
97 // SALOMEDS::Study and a SalomeApp_Study?
98 SalomeApp_Study* getSalomeAppActiveStudy() {
99 SUIT_Application* app = getSalomeApplication();
101 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
107 SALOMEDS::SObject_ptr IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) {
108 if (!iobject.IsNull()) {
109 if (iobject->hasEntry()) {
110 SalomeApp_Study* appStudy = getSalomeAppActiveStudy();
111 if ( appStudy != NULL ) {
115 // Note that the SalomeApp_Study give acces to shared
116 // pointer (i.e. _PTR(<BaseClassName>)) that points to proxy
117 // objects (i.e. SALOMEDSClien_<BaseClassName>) that embeds
118 // the CORBA servants (i.e. SALOMEDS::<BaseClassName>_ptr).
119 // Then to retrieve the corba servant, a method is to
120 // retrieve the SALOMEDS::Study servant first and the to
121 // request this servant to get the SObject given its entry.
123 _PTR(Study) studyClient = appStudy->studyDS();
124 SALOMEDS::Study_var study = KERNEL::getStudyManager()->GetStudyByID(studyClient->StudyId());
125 SALOMEDS::SObject_ptr sobject = study->FindObjectID(iobject->getEntry());
130 return SALOMEDS::SObject::_nil();