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"
12 #include "LightApp_Preferences.h"
13 #include "SalomeApp_UpdateFlags.h"
14 #include "SalomeApp_Operation.h"
15 #include "SalomeApp_SwitchOp.h"
17 #include "SUIT_Operation.h"
18 #include "CAM_DataModel.h"
20 #include "OB_Browser.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 )
34 : LightApp_Module( name ),
40 SalomeApp_Module::~SalomeApp_Module()
46 /*!Gets application.*/
47 SalomeApp_Application* SalomeApp_Module::getApp() const
49 return (SalomeApp_Application*)application();
53 bool SalomeApp_Module::activateModule( SUIT_Study* study )
55 bool res = LightApp_Module::activateModule( study );
57 if ( mySwitchOp == 0 )
58 mySwitchOp = new SalomeApp_SwitchOp( this );
63 /*!Deactivate module.*/
64 bool SalomeApp_Module::deactivateModule( SUIT_Study* study )
66 bool res = LightApp_Module::deactivateModule( study );
74 /*!Create new instance of data model and return it.*/
75 CAM_DataModel* SalomeApp_Module::createDataModel()
77 return new SalomeApp_DataModel(this);
81 * \brief Update something in accordance with update flags
82 * \param theFlags - update flags
84 * Update viewer or/and object browser etc. in accordance with update flags ( see
85 * SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method for their
88 void SalomeApp_Module::update( const int theFlags )
90 if ( theFlags & UF_Model )
92 if( CAM_DataModel* aDataModel = dataModel() )
93 if( SalomeApp_DataModel* aModel = dynamic_cast<SalomeApp_DataModel*>( aDataModel ) ) {
94 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() );
96 aModel->update( 0, aStudy );
99 if ( theFlags & UF_ObjBrowser )
100 getApp()->objectBrowser()->updateTree( 0 );
101 if ( theFlags & UF_Controls )
103 if ( theFlags & UF_Viewer )
105 if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() )
106 if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() )
108 if ( viewWnd->inherits( "SVTK_ViewWindow" ) )
109 ( (SVTK_ViewWindow*)viewWnd )->Repaint();
110 else if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) )
111 ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate();
112 else if ( viewWnd->inherits( "Plot2d_ViewWindow" ) )
113 ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint();
114 else if ( viewWnd->inherits( "GLViewer_ViewFrame" ) )
115 ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate();
121 * \brief Updates controls
123 * Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is
124 * called from update( UF_Controls ). You may redefine it in concrete module.
126 void SalomeApp_Module::updateControls()
131 * \brief Starts operation with given identifier
132 * \param id - identifier of operation to be started
134 * Module stores operations in map. This method starts operation by id.
135 * If operation isn't in map, then it will be created by createOperation method
136 * and will be inserted to map
138 void SalomeApp_Module::startOperation( const int id )
140 SalomeApp_Operation* op = 0;
141 if( myOperations.contains( id ) )
142 op = myOperations[ id ];
145 op = createOperation( id );
148 myOperations.insert( id, op );
149 op->setModule( this );
150 connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) );
151 connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) );
160 * \brief Creates operation with given identifier
161 * \param id - identifier of operation to be started
162 * \return Pointer on created operation or NULL if operation is not created
164 * Creates operation with given id. You should not call this method, it will be called
165 * automatically from startOperation. You may redefine this method in concrete module to
168 SalomeApp_Operation* SalomeApp_Module::createOperation( const int /*id*/ ) const
174 * \brief Virtual protected slot called when operation stopped
175 * \param theOp - stopped operation
177 * Virtual protected slot called when operation stopped. Redefine this slot if you want to
178 * perform actions after stopping operation
180 void SalomeApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ )
185 * \brief Virtual protected slot called when operation destroyed
186 * \param theOp - destroyed operation
188 * Virtual protected slot called when operation destroyed. Redefine this slot if you want to
189 * perform actions after destroying operation. Base implementation removes pointer on
190 * destroyed operation from the map of operations
192 void SalomeApp_Module::onOperationDestroyed()
194 const QObject* s = sender();
195 if( s && s->inherits( "SalomeApp_Operation" ) )
197 const SalomeApp_Operation* op = ( SalomeApp_Operation* )s;
198 MapOfOperation::const_iterator anIt = myOperations.begin(),
199 aLast = myOperations.end();
200 for( ; anIt!=aLast; anIt++ )
201 if( anIt.data()==op )
203 myOperations.remove( anIt.key() );