]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Now the module stores operations in map and can to start operation by id
authorasl <asl@opencascade.com>
Thu, 7 Jul 2005 08:49:12 +0000 (08:49 +0000)
committerasl <asl@opencascade.com>
Thu, 7 Jul 2005 08:49:12 +0000 (08:49 +0000)
src/SalomeApp/SalomeApp_Module.cxx
src/SalomeApp/SalomeApp_Module.h

index caa39a15664fffffd5b9a89390ecb6b5b88474ff..c1728e3f4cd662a560dcf03d36b6a66c2e858e02 100644 (file)
@@ -10,6 +10,7 @@
 #include "SalomeApp_Application.h"
 #include "SalomeApp_Preferences.h"
 #include "SalomeApp_UpdateFlags.h"
+#include "SalomeApp_Operation.h"
 
 #include <OB_Browser.h>
 
@@ -217,19 +218,49 @@ void SalomeApp_Module::updateControls()
 {
 }
 
+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();
+}
 
+SalomeApp_Operation* SalomeApp_Module::createOperation( const int ) const
+{
+  return 0;
+}
 
+void SalomeApp_Module::onOperationStopped( SUIT_Operation* )
+{
+}
 
-
-
-
-
-
-
-
-
-
-
-
-
+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 4ae6bea4c92eb76e4e21be0d7b72f534b01bb9b5..abbce5b97950168fa78c8e505084e819a2d5b378 100644 (file)
@@ -28,6 +28,7 @@ class SalomeApp_DataModel;
 class SalomeApp_Application;
 class SalomeApp_Preferences;
 class SalomeApp_SelectionManager;
+class SalomeApp_Operation;
 
 /*
   Class : SalomeApp_Module
@@ -86,6 +87,8 @@ protected slots:
   virtual void                        onModelSaved();
   virtual void                        onModelOpened();
   virtual void                        onModelClosed();
+  virtual void                        onOperationStopped( SUIT_Operation* );
+  virtual void                        onOperationDestroyed();
 
 protected:
   QtxPopupMgr*                        popupMgr();
@@ -95,6 +98,17 @@ protected:
   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,
@@ -103,7 +117,11 @@ protected:
   void                                setPreferenceProperty( const int, const QString&, const QVariant& );
 
 private:
-  QtxPopupMgr*                        myPopupMgr;
+  typedef QMap<int,SalomeApp_Operation*> MapOfOperation;
+  
+private:
+  QtxPopupMgr*          myPopupMgr;
+  MapOfOperation        myOperations;
 };
 
 #endif