1 // File: SalomeApp_Module.cxx
2 // Created: 10/25/2004 11:39:56 AM
3 // Author: Sergey LITONIN
4 // Copyright (C) CEA 2004
6 #include "SalomeApp_Module.h"
8 #include "SalomeApp_Study.h"
9 #include "SalomeApp_DataModel.h"
10 #include "SalomeApp_Application.h"
11 #include "SalomeApp_Preferences.h"
12 #include "SalomeApp_UpdateFlags.h"
13 #include "SalomeApp_Operation.h"
14 #include "SalomeApp_SwitchOp.h"
16 #include <OB_Browser.h>
18 #include <CAM_Study.h>
20 #include <SUIT_MessageBox.h>
21 #include <SUIT_ResourceMgr.h>
23 #include <QtxPopupMgr.h>
25 #include <SVTK_ViewWindow.h>
26 #include <OCCViewer_ViewWindow.h>
27 #include <OCCViewer_ViewPort3d.h>
28 #include <GLViewer_ViewFrame.h>
29 #include <GLViewer_ViewPort.h>
30 #include <Plot2d_ViewWindow.h>
33 SalomeApp_Module::SalomeApp_Module( const QString& name )
41 SalomeApp_Module::~SalomeApp_Module()
47 /*!Initialize module.*/
48 void SalomeApp_Module::initialize( CAM_Application* app )
50 CAM_Module::initialize( app );
52 SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0;
54 resMgr->raiseTranslators( name() );
58 bool SalomeApp_Module::activateModule( SUIT_Study* study )
60 bool res = CAM_Module::activateModule( study );
62 if ( res && application() && application()->resourceMgr() )
63 application()->resourceMgr()->raiseTranslators( name() );
65 if ( mySwitchOp == 0 )
66 mySwitchOp = new SalomeApp_SwitchOp( this );
71 /*!Deactivate module.*/
72 bool SalomeApp_Module::deactivateModule( SUIT_Study* )
81 void SalomeApp_Module::selectionChanged()
86 void SalomeApp_Module::MenuItem()
91 void SalomeApp_Module::windows( QMap<int, int>& ) const
96 void SalomeApp_Module::viewManagers( QStringList& ) const
101 void SalomeApp_Module::createPreferences()
106 void SalomeApp_Module::preferencesChanged( const QString&, const QString& )
110 /*!Gets application.*/
111 SalomeApp_Application* SalomeApp_Module::getApp() const
113 return (SalomeApp_Application*)application();
117 void SalomeApp_Module::onModelOpened()
122 void SalomeApp_Module::onModelSaved()
127 void SalomeApp_Module::onModelClosed()
131 /*!Gets popup manager.(create if not exist)*/
132 QtxPopupMgr* SalomeApp_Module::popupMgr()
135 myPopupMgr = new QtxPopupMgr( 0, this );
139 /*!Gets preferences.*/
140 SalomeApp_Preferences* SalomeApp_Module::preferences() const
142 SalomeApp_Preferences* pref = 0;
144 pref = getApp()->preferences();
148 /*!Create new instance of data model and return it.*/
149 CAM_DataModel* SalomeApp_Module::createDataModel()
151 return new SalomeApp_DataModel(this);
154 /*!Update object browser.*/
155 void SalomeApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root )
157 if( updateDataModel )
158 if( CAM_DataModel* aDataModel = dataModel() )
159 if( SalomeApp_DataModel* aModel = dynamic_cast<SalomeApp_DataModel*>( aDataModel ) )
160 aModel->update( 0, dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
161 getApp()->objectBrowser()->updateTree( root );
164 /*!Context menu popup.*/
165 void SalomeApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
167 SalomeApp_Selection* sel = createSelection();
168 sel->init( client, getApp()->selectionMgr() );
169 popupMgr()->updatePopup( menu, sel );
173 /*!Create and return instance of SalomeApp_Selection.*/
174 SalomeApp_Selection* SalomeApp_Module::createSelection() const
176 return new SalomeApp_Selection();
179 /*!Add preference to preferences.*/
180 int SalomeApp_Module::addPreference( const QString& label )
182 SalomeApp_Preferences* pref = preferences();
186 int catId = pref->addPreference( moduleName(), -1 );
190 return pref->addPreference( label, catId );
193 /*!Add preference to preferences.*/
194 int SalomeApp_Module::addPreference( const QString& label, const int pId, const int type,
195 const QString& section, const QString& param )
197 SalomeApp_Preferences* pref = preferences();
201 return pref->addPreference( moduleName(), label, pId, type, section, param );
204 /*!Gets property of preferences.*/
205 QVariant SalomeApp_Module::preferenceProperty( const int id, const QString& prop ) const
208 SalomeApp_Preferences* pref = preferences();
210 var = pref->itemProperty( id, prop );
215 /*!Set property of preferences.*/
216 void SalomeApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var )
218 SalomeApp_Preferences* pref = preferences();
220 pref->setItemProperty( id, prop, var );
224 * \brief Update something in accordance with update flags
225 * \param theFlags - update flags
227 * Update viewer or/and object browser etc. in accordance with update flags ( see
228 * SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method for their
231 void SalomeApp_Module::update( const int theFlags )
233 if ( theFlags & UF_Model )
235 if( CAM_DataModel* aDataModel = dataModel() )
236 if( SalomeApp_DataModel* aModel = dynamic_cast<SalomeApp_DataModel*>( aDataModel ) )
237 aModel->update( 0, dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
239 if ( theFlags & UF_ObjBrowser )
240 getApp()->objectBrowser()->updateTree( 0 );
241 if ( theFlags & UF_Controls )
243 if ( theFlags & UF_Viewer )
245 if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() )
246 if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() )
248 if ( viewWnd->inherits( "SVTK_ViewWindow" ) )
249 ( (SVTK_ViewWindow*)viewWnd )->Repaint();
250 else if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) )
251 ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate();
252 else if ( viewWnd->inherits( "Plot2d_ViewWindow" ) )
253 ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint();
254 else if ( viewWnd->inherits( "GLViewer_ViewFrame" ) )
255 ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate();
261 * \brief Updates controls
263 * Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is
264 * called from update( UF_Controls ). You may redefine it in concrete module.
266 void SalomeApp_Module::updateControls()
271 * \brief Starts operation with given identifier
272 * \param id - identifier of operation to be started
274 * Module stores operations in map. This method starts operation by id.
275 * If operation isn't in map, then it will be created by createOperation method
276 * and will be inserted to map
278 void SalomeApp_Module::startOperation( const int id )
280 SalomeApp_Operation* op = 0;
281 if( myOperations.contains( id ) )
282 op = myOperations[ id ];
285 op = createOperation( id );
288 myOperations.insert( id, op );
289 op->setModule( this );
290 connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) );
291 connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) );
300 * \brief Creates operation with given identifier
301 * \param id - identifier of operation to be started
302 * \return Pointer on created operation or NULL if operation is not created
304 * Creates operation with given id. You should not call this method, it will be called
305 * automatically from startOperation. You may redefine this method in concrete module to
308 SalomeApp_Operation* SalomeApp_Module::createOperation( const int /*id*/ ) const
314 * \brief Virtual protected slot called when operation stopped
315 * \param theOp - stopped operation
317 * Virtual protected slot called when operation stopped. Redefine this slot if you want to
318 * perform actions after stopping operation
320 void SalomeApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ )
325 * \brief Virtual protected slot called when operation destroyed
326 * \param theOp - destroyed operation
328 * Virtual protected slot called when operation destroyed. Redefine this slot if you want to
329 * perform actions after destroying operation. Base implementation removes pointer on
330 * destroyed operation from the map of operations
332 void SalomeApp_Module::onOperationDestroyed()
334 const QObject* s = sender();
335 if( s && s->inherits( "SalomeApp_Operation" ) )
337 const SalomeApp_Operation* op = ( SalomeApp_Operation* )s;
338 MapOfOperation::const_iterator anIt = myOperations.begin(),
339 aLast = myOperations.end();
340 for( ; anIt!=aLast; anIt++ )
341 if( anIt.data()==op )
343 myOperations.remove( anIt.key() );