1 // File: LightApp_Module.cxx
2 // Created: 6/20/2005 16:30:56 AM
4 // Copyright (C) CEA 2005
6 #include "LightApp_Module.h"
8 #include "CAM_Application.h"
10 #include "LightApp_Application.h"
11 #include "LightApp_DataModel.h"
12 #include "LightApp_Study.h"
13 #include "LightApp_Preferences.h"
14 #include "LightApp_Selection.h"
15 #include "LightApp_Operation.h"
16 #include "LightApp_SwitchOp.h"
17 #include "LightApp_UpdateFlags.h"
18 #include "LightApp_ShowHideOp.h"
20 #include "SUIT_Operation.h"
21 #include <SUIT_Study.h>
22 #include <SUIT_DataObject.h>
23 #include <SUIT_ResourceMgr.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>
31 #include <Plot2d_ViewFrame.h>
33 #include <OB_Browser.h>
35 #include <QtxPopupMgr.h>
39 #include <qstringlist.h>
42 LightApp_Module::LightApp_Module( const QString& name )
53 LightApp_Module::~LightApp_Module()
59 /*!Initialize module.*/
60 void LightApp_Module::initialize( CAM_Application* app )
62 CAM_Module::initialize( app );
64 SUIT_ResourceMgr* resMgr = app ? app->resourceMgr() : 0;
66 resMgr->raiseTranslators( name() );
70 void LightApp_Module::windows( QMap<int, int>& ) const
75 void LightApp_Module::viewManagers( QStringList& ) const
79 /*!Context menu popup.*/
80 void LightApp_Module::contextMenuPopup( const QString& client, QPopupMenu* menu, QString& /*title*/ )
82 LightApp_Selection* sel = createSelection();
83 sel->init( client, getApp()->selectionMgr() );
84 popupMgr()->updatePopup( menu, sel );
88 /*!Update object browser.
89 * For updating model or whole object browser use update() method can be used.
91 void LightApp_Module::updateObjBrowser( bool updateDataModel, SUIT_DataObject* root )
94 if( CAM_DataModel* aDataModel = dataModel() )
95 if( LightApp_DataModel* aModel = dynamic_cast<LightApp_DataModel*>( aDataModel ) )
96 aModel->update( 0, dynamic_cast<LightApp_Study*>( getApp()->activeStudy() ) );
97 getApp()->objectBrowser()->updateTree( root );
101 void LightApp_Module::selectionChanged()
105 /*!Activate module.*/
106 bool LightApp_Module::activateModule( SUIT_Study* study )
108 bool res = CAM_Module::activateModule( study );
110 if ( res && application() && application()->resourceMgr() )
111 application()->resourceMgr()->raiseTranslators( name() );
113 if ( mySwitchOp == 0 )
114 mySwitchOp = new LightApp_SwitchOp( this );
119 /*!Deactivate module.*/
120 bool LightApp_Module::deactivateModule( SUIT_Study* )
129 void LightApp_Module::MenuItem()
134 void LightApp_Module::createPreferences()
139 void LightApp_Module::preferencesChanged( const QString&, const QString& )
143 /*!Gets application.*/
144 LightApp_Application* LightApp_Module::getApp() const
146 return (LightApp_Application*)application();
150 * \brief Update something in accordance with update flags
151 * \param theFlags - update flags
153 * Update viewer or/and object browser etc. in accordance with update flags ( see
154 * LightApp_UpdateFlags enumeration ). Derived modules can redefine this method for their
157 void LightApp_Module::update( const int theFlags )
159 if ( theFlags & UF_Model )
161 if( CAM_DataModel* aDataModel = dataModel() )
162 if( LightApp_DataModel* aModel = dynamic_cast<LightApp_DataModel*>( aDataModel ) )
163 aModel->update( 0, dynamic_cast<LightApp_Study*>( getApp()->activeStudy() ) );
165 if ( theFlags & UF_ObjBrowser )
166 getApp()->objectBrowser()->updateTree( 0 );
167 if ( theFlags & UF_Controls )
169 if ( theFlags & UF_Viewer )
171 if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() )
172 if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() )
174 if ( viewWnd->inherits( "SVTK_ViewWindow" ) )
175 ( (SVTK_ViewWindow*)viewWnd )->Repaint();
176 else if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) )
177 ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate();
178 else if ( viewWnd->inherits( "Plot2d_ViewWindow" ) )
179 ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint();
180 else if ( viewWnd->inherits( "GLViewer_ViewFrame" ) )
181 ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate();
186 * \brief Updates controls
188 * Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is
189 * called from update( UF_Controls ). You may redefine it in concrete module.
191 void LightApp_Module::updateControls()
195 /*!Create new instance of data model and return it.*/
196 CAM_DataModel* LightApp_Module::createDataModel()
198 return new LightApp_DataModel(this);
201 /*!Create and return instance of LightApp_Selection.*/
202 LightApp_Selection* LightApp_Module::createSelection() const
204 return new LightApp_Selection();
208 void LightApp_Module::onModelOpened()
213 void LightApp_Module::onModelSaved()
218 void LightApp_Module::onModelClosed()
222 /*!Gets popup manager.(create if not exist)*/
223 QtxPopupMgr* LightApp_Module::popupMgr()
227 myPopupMgr = new QtxPopupMgr( 0, this );
230 SUIT_Desktop* d = application()->desktop();
233 *disp = createAction( -1, tr( "TOP_DISPLAY" ), p, tr( "MEN_DISPLAY" ), tr( "STB_DISPLAY" ),
234 0, d, false, this, SLOT( onShowHide() ) ),
235 *erase = createAction( -1, tr( "TOP_ERASE" ), p, tr( "MEN_ERASE" ), tr( "STB_ERASE" ),
236 0, d, false, this, SLOT( onShowHide() ) ),
237 *dispOnly = createAction( -1, tr( "TOP_DISPLAY_ONLY" ), p, tr( "MEN_DISPLAY_ONLY" ), tr( "STB_DISPLAY_ONLY" ),
238 0, d, false, this, SLOT( onShowHide() ) );
239 myDisplay = actionId( disp );
240 myErase = actionId( erase );
241 myDisplayOnly = actionId( dispOnly );
243 myPopupMgr->insert( disp, -1, 0 );
244 myPopupMgr->insert( erase, -1, 0 );
245 myPopupMgr->insert( dispOnly, -1, 0 );
246 myPopupMgr->insert( separator(), -1, 0 );
248 QString uniform = "( count( $component ) = 1 ) and ( component != activeModule ) and ( activeModule = '%1' )";
249 uniform = uniform.arg( name() );
250 myPopupMgr->setRule( disp, /*QString( "( not isVisible ) and " ) + */ uniform, true );
251 myPopupMgr->setRule( erase, /*QString( "( isVisible ) and " ) + */ uniform, true );
252 myPopupMgr->setRule( dispOnly, uniform, true );
257 /*!Gets preferences.*/
258 LightApp_Preferences* LightApp_Module::preferences() const
260 LightApp_Preferences* pref = 0;
262 pref = getApp()->preferences();
266 /*!Add preference to preferences.*/
267 int LightApp_Module::addPreference( const QString& label )
269 LightApp_Preferences* pref = preferences();
273 int catId = pref->addPreference( moduleName(), -1 );
277 return pref->addPreference( label, catId );
280 /*!Add preference to preferences.*/
281 int LightApp_Module::addPreference( const QString& label, const int pId, const int type,
282 const QString& section, const QString& param )
284 LightApp_Preferences* pref = preferences();
288 return pref->addPreference( moduleName(), label, pId, type, section, param );
291 /*!Gets property of preferences.*/
292 QVariant LightApp_Module::preferenceProperty( const int id, const QString& prop ) const
295 LightApp_Preferences* pref = preferences();
297 var = pref->itemProperty( id, prop );
301 /*!Set property of preferences.*/
302 void LightApp_Module::setPreferenceProperty( const int id, const QString& prop, const QVariant& var )
304 LightApp_Preferences* pref = preferences();
306 pref->setItemProperty( id, prop, var );
310 * \brief Starts operation with given identifier
311 * \param id - identifier of operation to be started
313 * Module stores operations in map. This method starts operation by id.
314 * If operation isn't in map, then it will be created by createOperation method
315 * and will be inserted to map
317 void LightApp_Module::startOperation( const int id )
319 LightApp_Operation* op = 0;
320 if( myOperations.contains( id ) )
321 op = myOperations[ id ];
324 op = createOperation( id );
327 myOperations.insert( id, op );
328 op->setModule( this );
329 connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) );
330 connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) );
339 * \brief Creates operation with given identifier
340 * \param id - identifier of operation to be started
341 * \return Pointer on created operation or NULL if operation is not created
343 * Creates operation with given id. You should not call this method, it will be called
344 * automatically from startOperation. You may redefine this method in concrete module to
347 LightApp_Operation* LightApp_Module::createOperation( const int id ) const
353 return new LightApp_ShowHideOp( LightApp_ShowHideOp::DISPLAY );
354 else if( id==myErase )
355 return new LightApp_ShowHideOp( LightApp_ShowHideOp::ERASE );
356 else if( id==myDisplayOnly )
357 return new LightApp_ShowHideOp( LightApp_ShowHideOp::DISPLAY_ONLY );
363 * \brief Virtual protected slot called when operation stopped
364 * \param theOp - stopped operation
366 * Virtual protected slot called when operation stopped. Redefine this slot if you want to
367 * perform actions after stopping operation
369 void LightApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ )
374 * \brief Virtual protected slot called when operation destroyed
375 * \param theOp - destroyed operation
377 * Virtual protected slot called when operation destroyed. Redefine this slot if you want to
378 * perform actions after destroying operation. Base implementation removes pointer on
379 * destroyed operation from the map of operations
381 void LightApp_Module::onOperationDestroyed()
383 const QObject* s = sender();
384 if( s && s->inherits( "LightApp_Operation" ) )
386 const LightApp_Operation* op = ( LightApp_Operation* )s;
387 MapOfOperation::const_iterator anIt = myOperations.begin(),
388 aLast = myOperations.end();
389 for( ; anIt!=aLast; anIt++ )
390 if( anIt.data()==op )
392 myOperations.remove( anIt.key() );
398 LightApp_Displayer* LightApp_Module::displayer()
403 void LightApp_Module::onShowHide()
405 if( !sender()->inherits( "QAction" ) || !popupMgr() )
408 QAction* act = ( QAction* )sender();
409 int id = actionId( act );
411 startOperation( id );