Salome HOME
Operation mechanism improved. Methods for starting and finishing operations added...
authorsln <sln@opencascade.com>
Tue, 23 Aug 2005 08:14:01 +0000 (08:14 +0000)
committersln <sln@opencascade.com>
Tue, 23 Aug 2005 08:14:01 +0000 (08:14 +0000)
src/SalomeApp/SalomeApp_Module.cxx
src/SalomeApp/SalomeApp_Module.h

index 22de8288c3e88791cdcddf439bbea534f929a968..f62a3eca47a2b2344841e67bbb493071626ce5f9 100644 (file)
@@ -9,6 +9,9 @@
 #include "SalomeApp_DataModel.h"
 #include "SalomeApp_Application.h"
 #include "SalomeApp_Preferences.h"
+#include "SalomeApp_UpdateFlags.h"
+#include "SalomeApp_Operation.h"
+#include "SalomeApp_SwitchOp.h"
 
 #include <OB_Browser.h>
 
 
 #include <QtxPopupMgr.h>
 
+#include <SVTK_ViewWindow.h>
+#include <OCCViewer_ViewWindow.h>
+#include <OCCViewer_ViewPort3d.h>
+#include <GLViewer_ViewFrame.h>
+#include <GLViewer_ViewPort.h>
+#include <Plot2d_ViewWindow.h>
+
 /*!Constructor.*/
 SalomeApp_Module::SalomeApp_Module( const QString& name )
 : CAM_Module( name ),
-myPopupMgr( 0 )
+myPopupMgr( 0 ),
+mySwitchOp( 0 )
 {
 }
 
 /*!Destructor.*/
 SalomeApp_Module::~SalomeApp_Module()
 {
+  if ( mySwitchOp )
+    delete mySwitchOp;
 }
 
 /*!Initialize module.*/
@@ -48,6 +61,9 @@ bool SalomeApp_Module::activateModule( SUIT_Study* study )
 
   if ( res && application() && application()->resourceMgr() )
     application()->resourceMgr()->raiseTranslators( name() );
+
+  if ( mySwitchOp == 0 )
+    mySwitchOp = new SalomeApp_SwitchOp( this );
     
   return res;
 }
@@ -55,6 +71,9 @@ bool SalomeApp_Module::activateModule( SUIT_Study* study )
 /*!Deactivate module.*/
 bool SalomeApp_Module::deactivateModule( SUIT_Study* )
 {
+  delete mySwitchOp;
+  mySwitchOp = 0;
+  
   return true;
 }
 
@@ -167,7 +186,7 @@ int SalomeApp_Module::addPreference( const QString& label )
   int catId = pref->addPreference( moduleName(), -1 );
   if ( catId == -1 )
     return -1;
-
+                             
   return pref->addPreference( label, catId );
 }
 
@@ -200,3 +219,129 @@ void SalomeApp_Module::setPreferenceProperty( const int id, const QString& prop,
   if ( pref )
     pref->setItemProperty( id, prop, var );
 }
+
+/*!
+ * \brief Update something in accordance with update flags
+  * \param theFlags - update flags
+*
+* Update viewer or/and object browser etc. in accordance with update flags ( see
+* SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method for their
+* own purposes
+*/
+void SalomeApp_Module::update( const int theFlags )
+{
+  if ( theFlags & UF_Model )
+  {
+    if( CAM_DataModel* aDataModel = dataModel() )
+      if( SalomeApp_DataModel* aModel = dynamic_cast<SalomeApp_DataModel*>( aDataModel ) )
+        aModel->update( 0, dynamic_cast<SalomeApp_Study*>( getApp()->activeStudy() ) );
+  }
+  if ( theFlags & UF_ObjBrowser )
+    getApp()->objectBrowser()->updateTree( 0 );
+  if ( theFlags & UF_Controls )
+    updateControls();
+  if ( theFlags & UF_Viewer )
+  {
+    if ( SUIT_ViewManager* viewMgr = getApp()->activeViewManager() )
+      if ( SUIT_ViewWindow* viewWnd = viewMgr->getActiveView() )
+      {
+        if ( viewWnd->inherits( "SVTK_ViewWindow" ) )
+          ( (SVTK_ViewWindow*)viewWnd )->Repaint();
+        else if ( viewWnd->inherits( "OCCViewer_ViewWindow" ) )
+          ( (OCCViewer_ViewWindow*)viewWnd )->getViewPort()->onUpdate();
+        else if ( viewWnd->inherits( "Plot2d_ViewWindow" ) )
+          ( (Plot2d_ViewWindow*)viewWnd )->getViewFrame()->Repaint();
+        else if ( viewWnd->inherits( "GLViewer_ViewFrame" ) )
+          ( (GLViewer_ViewFrame*)viewWnd )->getViewPort()->onUpdate();
+      }
+  }
+}
+
+/*!
+ * \brief Updates controls
+*
+* Updates (i.e. disable/enable) controls states (menus, tool bars etc.). This method is
+* called from update( UF_Controls ). You may redefine it in concrete module.
+*/
+void SalomeApp_Module::updateControls()
+{
+}
+
+/*!
+ * \brief Starts operation with given identifier
+  * \param id - identifier of operation to be started
+*
+* Module stores operations in map. This method starts operation by id.
+* If operation isn't in map, then it will be created by createOperation method
+* and will be inserted to map
+*/
+void SalomeApp_Module::startOperation( const int id )
+{
+  SalomeApp_Operation* op = 0;
+  if( myOperations.contains( id ) )
+    op = myOperations[ id ];
+  else
+  {
+    op = createOperation( id );
+    if( op )
+    {
+      myOperations.insert( id, op );
+      op->setModule( this );
+      connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) );
+      connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) );
+    }
+  }
+
+  if( op )
+    op->start();
+}
+
+/*!
+ * \brief Creates operation with given identifier
+  * \param id - identifier of operation to be started
+  * \return Pointer on created operation or NULL if operation is not created
+*
+* Creates operation with given id. You should not call this method, it will be called
+* automatically from startOperation. You may redefine this method in concrete module to
+* create operations. 
+*/
+SalomeApp_Operation* SalomeApp_Module::createOperation( const int /*id*/ ) const
+{
+  return 0;
+}
+
+/*!
+ * \brief Virtual protected slot called when operation stopped
+  * \param theOp - stopped operation
+*
+* Virtual protected slot called when operation stopped. Redefine this slot if you want to
+* perform actions after stopping operation
+*/
+void SalomeApp_Module::onOperationStopped( SUIT_Operation* /*theOp*/ )
+{
+}
+
+/*!
+ * \brief Virtual protected slot called when operation destroyed
+  * \param theOp - destroyed operation
+*
+* Virtual protected slot called when operation destroyed. Redefine this slot if you want to
+* perform actions after destroying operation. Base implementation removes pointer on
+* destroyed operation from the map of operations
+*/
+void SalomeApp_Module::onOperationDestroyed()
+{
+  const QObject* s = sender();
+  if( s && s->inherits( "SalomeApp_Operation" ) )
+  {
+    const SalomeApp_Operation* op = ( SalomeApp_Operation* )s;
+    MapOfOperation::const_iterator anIt = myOperations.begin(),
+                                   aLast = myOperations.end();
+    for( ; anIt!=aLast; anIt++ )
+      if( anIt.data()==op )
+      {
+        myOperations.remove( anIt.key() );
+        break;
+      }
+  }
+}
index e6b62ed130ed04c22599d5443a928b06d7d54ec9..644608c5d8c0f8aa6008c8988f7eb8cba6d2bdba 100644 (file)
@@ -28,11 +28,12 @@ class SalomeApp_DataModel;
 class SalomeApp_Application;
 class SalomeApp_Preferences;
 class SalomeApp_SelectionManager;
+class SalomeApp_Operation;
+class SalomeApp_SwitchOp;
 
 /*!
 Description : Base class for all salome modules
* \brief Base class for all salome modules
 */
-
 class SALOMEAPP_EXPORT SalomeApp_Module : public CAM_Module
 {
   Q_OBJECT
@@ -56,12 +57,20 @@ public:
   virtual void                        contextMenuPopup( const QString&, QPopupMenu*, QString& );
 
   virtual void                        createPreferences();
-
+  
   /*! Convenient shortcuts*/
   SalomeApp_Application*              getApp() const;
-  
-  void                                updateObjBrowser( bool = true, SUIT_DataObject* = 0 );
 
+  virtual void                        update( const int );
+  // Update viewer or/and object browser etc. in accordance with update flags
+  // ( see SalomeApp_UpdateFlags enumeration ). Derived modules can redefine this method
+  // for their own purposes
+    
+  void                                updateObjBrowser( bool = true, SUIT_DataObject* = 0 );
+  // Update object bropwser ( for updating model or whole object browser use update() method
+  // can be used )
+  
   virtual void                        selectionChanged();
   virtual void                        preferencesChanged( const QString&, const QString& );
 
@@ -77,6 +86,8 @@ protected slots:
   virtual void                        onModelSaved();
   virtual void                        onModelOpened();
   virtual void                        onModelClosed();
+  virtual void                        onOperationStopped( SUIT_Operation* );
+  virtual void                        onOperationDestroyed();
 
 protected:
   QtxPopupMgr*                        popupMgr();
@@ -84,16 +95,33 @@ protected:
 
   virtual CAM_DataModel*              createDataModel();
   virtual SalomeApp_Selection*        createSelection() const;
+  virtual void                        updateControls();
+
+  /*! Module stores operations in map. This method starts operation by id.
+   *  If operation isn't in map, then it will be created by createOperation method
+   *  and will be inserted to map
+   */
+  void                                startOperation( const int );
+
+  /*! Create operation by its id. You must not call this method, it will be called automatically
+   *  by startOperation. Please redefine this method in current module
+   */
+  virtual SalomeApp_Operation*        createOperation( const int ) const;
 
   int                                 addPreference( const QString& label );
   int                                 addPreference( const QString& label, const int pId, const int = -1,
-                                                    const QString& section = QString::null,
-                                                    const QString& param = QString::null );
+                                                     const QString& section = QString::null,
+                                                     const QString& param = QString::null );
   QVariant                            preferenceProperty( const int, const QString& ) const;
   void                                setPreferenceProperty( const int, const QString&, const QVariant& );
 
 private:
-  QtxPopupMgr*                        myPopupMgr;
+  typedef QMap<int,SalomeApp_Operation*> MapOfOperation;
+  
+private:
+  QtxPopupMgr*          myPopupMgr;
+  MapOfOperation        myOperations;
+  SalomeApp_SwitchOp*   mySwitchOp;
 };
 
 #endif