1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOME_PYQT_Module.cxx
23 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
25 #include "SALOME_PYQT_Module.h"
26 #include "SALOME_PYQT_PyModule.h"
27 #include "SalomeApp_Application.h"
29 #include <SALOME_LifeCycleCORBA.hxx>
30 #include <Container_init_python.hxx>
33 // NB: Python requests.
34 // General rule for Python requests created by Python-based GUI modules
35 // (SALOME_PYQT_Module and other ones):
36 // all requests should be executed SYNCHRONOUSLY within the main GUI thread.
37 // However, it is obligatory that ANY Python call is wrapped with a request object,
38 // so that ALL Python API calls are serialized with PyInterp_Dispatcher.
40 // NB: Library initialization
41 // Since the SalomePyQtGUI library is not imported in Python it's initialization function
42 // should be called manually (and only once) in order to initialize global sip data
43 // and to get C API from sip : sipBuildResult for example
46 #define INIT_FUNCTION initSalomePyQtGUILight
47 #if defined(SIP_STATIC_MODULE)
48 extern "C" void INIT_FUNCTION();
50 PyMODINIT_FUNC INIT_FUNCTION();
54 \fn CAM_Module* createModule()
55 \brief Module factory function.
58 Creates an instance of SALOME_PYQT_Module object by request
59 of an application when the module is loaded and initialized.
61 \return new module object
65 SALOME_PYQT_EXPORT CAM_Module* createModule()
67 static bool alreadyInitialized = false;
69 if ( !alreadyInitialized ) {
70 PyLockWrapper lck; // GIL acquisition
72 alreadyInitialized = !alreadyInitialized;
75 return new SALOME_PYQT_Module();
80 \class SALOME_PYQT_Module
81 \brief This class implements GUI module for CORBA engine-based Python SALOME modules.
87 SALOME_PYQT_Module::SALOME_PYQT_Module()
88 : SalomeApp_Module( "noname" ) // name is set explicitly at the module initialization
91 myHelper = new PyModuleHelper( this );
97 SALOME_PYQT_Module::~SALOME_PYQT_Module()
99 // as myHelper is a QObject, it should be deleted automatically
103 \brief Get module engine IOR
105 This function tries to get engine IOR from the Python module using engineIOR() function.
106 That function can load module engine using appropriate container if required.
107 If this function is not available in Python module, the default implementation
108 is used which loads engine to the default FactoryServer container.
110 QString SALOME_PYQT_Module::engineIOR() const
112 // call helper to get IOR from Python module
115 if ( ior.isEmpty() ) {
116 // first call helper to get IOR from Python module
117 ior = myHelper->engineIOR();
119 if ( ior.isEmpty() ) {
120 // if IOR is still not specified, try default implementation
121 // which loads engine to the default FactoryServer container.
122 Engines::EngineComponent_var comp;
123 // temporary solution
125 comp = getApp()->lcc()->FindOrLoad_Component( "FactoryServer", name().toLatin1() );
127 catch (CORBA::Exception&) {
129 if ( !CORBA::is_nil( comp ) )
130 ior = QString( getApp()->orb()->object_to_string( comp.in() ) );
137 \brief Initialization of the module.
138 \param app parent application object
139 \sa PyModuleHelper::initialize()
141 void SALOME_PYQT_Module::initialize( CAM_Application* app )
143 // call base implementation
144 SalomeApp_Module::initialize( app );
146 // ... then call helper
147 myHelper->initialize( app );
151 \brief Activation of the module.
152 \param study parent study
153 \return \c true if activation is successful and \c false otherwise
154 \sa PyModuleHelper::activate()
156 bool SALOME_PYQT_Module::activateModule( SUIT_Study* study )
158 // call base implementation and then helper
159 return SalomeApp_Module::activateModule( study ) && myHelper->activate( study );
163 \brief Deactivation of the module.
164 \param study parent study
165 \return \c true if deactivation is successful and \c false otherwise
166 \sa PyModuleHelper::deactivate()
168 bool SALOME_PYQT_Module::deactivateModule( SUIT_Study* study )
171 bool res = myHelper->deactivate( study );
173 // ... then call base implementation
174 return SalomeApp_Module::deactivateModule( study ) && res;
178 \brief Get the dockable windows associated with the module.
179 \param winMap output map of dockable windows in form { <window_type> : <dock_area> }
180 \sa PyModuleHelper::windows()
182 void SALOME_PYQT_Module::windows( QMap<int, int>& winMap ) const
184 // get list of dockable windows from helper
185 winMap = myHelper->windows();
189 \brief Define the compatible view windows associated with the module.
190 \param viewList output list of view windows types
191 \sa PyModuleHelper::viewManagers()
193 void SALOME_PYQT_Module::viewManagers( QStringList& viewList ) const
195 // get list of view types from helper
196 viewList = myHelper->viewManagers();
200 \brief Process study activation.
201 \sa PyModuleHelper::studyActivated()
203 void SALOME_PYQT_Module::studyActivated()
206 myHelper->studyActivated( application()->activeStudy() );
210 \brief Process context popup menu request.
211 \param context popup menu context (e.g. "ObjectBrowser")
212 \param menu popup menu
213 \param title popup menu title (not used)
214 \sa PyModuleHelper::contextMenu()
216 void SALOME_PYQT_Module::contextMenuPopup( const QString& context,
221 myHelper->contextMenu( context, menu );
225 \brief Export preferences for the Python module.
226 \sa PyModuleHelper::createPreferences()
228 void SALOME_PYQT_Module::createPreferences()
231 myHelper->createPreferences();
235 \brief Process module's preferences changing.
236 \param section preference resources section
237 \param parameter preference resources parameter name
238 \sa PyModuleHelper::preferencesChanged()
240 void SALOME_PYQT_Module::preferencesChanged( const QString& section, const QString& parameter )
243 myHelper->preferencesChanged( section, parameter );
247 \brief Test if object \a what can be dragged by the user.
248 \param what data object being tested
249 \return \c true if object can be dragged or \c false otherwise
250 \sa PyModuleHelper::isDraggable()
252 bool SALOME_PYQT_Module::isDraggable( const SUIT_DataObject* what ) const
255 return myHelper->isDraggable( what );
259 \brief Test if drop operation can be done on the \a where object.
260 \param where data object being tested
261 \return \c true if if drop operation is supported by object or \c false otherwise
262 \sa PyModuleHelper::isDropAccepted()
264 bool SALOME_PYQT_Module::isDropAccepted( const SUIT_DataObject* where ) const
267 return myHelper->isDropAccepted( where );
271 \brief Perform drop operation
272 \param what list of data objects being dropped
273 \param where target data object for drop operation
274 \param row line (child item index) where drop operation is performed to
275 \param action current drop action (copy or move)
276 \sa PyModuleHelper::dropObjects()
278 void SALOME_PYQT_Module::dropObjects( const DataObjectList& what, SUIT_DataObject* where,
279 const int row, Qt::DropAction action )
282 myHelper->dropObjects( what, where, row, action );