1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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 if an active study is
73 * defined in the SALOME session, returns null otherwise.
75 SALOMEDS::Study_ptr getStudyServant() {
76 return SALOMEDS::Study::_duplicate(KERNEL::getStudyServant());
79 // __GBO__ Question: what is the difference between a
80 // SALOMEDS::Study and a SalomeApp_Study?
81 SalomeApp_Study* getSalomeAppActiveStudy() {
82 SUIT_Application* app = getSalomeApplication();
84 return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
90 SALOMEDS::SObject_ptr IObjectToSObject(const Handle(SALOME_InteractiveObject)& iobject) {
91 if (!iobject.IsNull()) {
92 if (iobject->hasEntry()) {
93 SalomeApp_Study* appStudy = getSalomeAppActiveStudy();
94 if ( appStudy != NULL ) {
98 // Note that the SalomeApp_Study give acces to shared
99 // pointer (i.e. _PTR(<BaseClassName>)) that points to proxy
100 // objects (i.e. SALOMEDSClien_<BaseClassName>) that embeds
101 // the CORBA servants (i.e. SALOMEDS::<BaseClassName>_ptr).
102 // Then to retrieve the corba servant, a method is to
103 // retrieve the SALOMEDS::Study servant first and the to
104 // request this servant to get the SObject given its entry.
106 SALOMEDS::SObject_ptr sobject = KERNEL::getStudyServant()->FindObjectID(iobject->getEntry());
111 return SALOMEDS::SObject::_nil();