]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Mechanism of operations changed. New file SalomeApp_SwitchOp added to control switchi...
authorsln <sln@opencascade.com>
Tue, 12 Jul 2005 13:44:24 +0000 (13:44 +0000)
committersln <sln@opencascade.com>
Tue, 12 Jul 2005 13:44:24 +0000 (13:44 +0000)
src/SalomeApp/Makefile.in
src/SalomeApp/SalomeApp_Dialog.cxx
src/SalomeApp/SalomeApp_Dialog.h
src/SalomeApp/SalomeApp_Module.cxx
src/SalomeApp/SalomeApp_Module.h
src/SalomeApp/SalomeApp_Operation.cxx
src/SalomeApp/SalomeApp_Operation.h
src/SalomeApp/SalomeApp_SwitchOp.cxx [new file with mode: 0755]
src/SalomeApp/SalomeApp_SwitchOp.h [new file with mode: 0755]

index f5f7ac834faea26e94682cc784d38b66511cb5e8..b95b93c2a21b636efe63e4eeefc412a303fea337 100755 (executable)
@@ -43,7 +43,8 @@ EXPORT_HEADERS= SalomeApp.h \
                SalomeApp_CheckFileDlg.h \
                SalomeApp_Operation.h \
                SalomeApp_Dialog.h \
-               SalomeApp_UpdateFlags.h
+               SalomeApp_UpdateFlags.h \
+               SalomeApp_SwitchOp.cxx
 
 # .po files to transform in .qm
 PO_FILES = SalomeApp_images.po \
@@ -83,7 +84,8 @@ LIB_SRC= SalomeApp_Module.cxx \
         SalomeApp_ListView.cxx \
         SalomeApp_CheckFileDlg.cxx \
         SalomeApp_Operation.cxx \
-        SalomeApp_Dialog.cxx 
+        SalomeApp_Dialog.cxx \
+        SalomeApp_SwitchOp.cxx
 
 LIB_MOC = SalomeApp_AboutDlg.h \
           SalomeApp_Application.h \
@@ -104,7 +106,8 @@ LIB_MOC = SalomeApp_AboutDlg.h \
          SalomeApp_ListView.h \
          SalomeApp_CheckFileDlg.h \
          SalomeApp_Operation.h \
-         SalomeApp_Dialog.h
+         SalomeApp_Dialog.h \
+         SalomeApp_SwitchOp.h
 
 LIB_CLIENT_IDL = SALOMEDS.idl \
                 SALOME_Exception.idl \
index 8fb0786b2a41c72e9e6003a20bad136477968dea..ceaea4a61e18428e4a4f0551b9e9eb8a43a926e3 100644 (file)
@@ -20,7 +20,8 @@
 SalomeApp_Dialog::SalomeApp_Dialog( QWidget* parent, const char* name, bool modal,
                                     bool allowResize, const int f, WFlags wf )
 : QtxDialog( parent, name, modal, allowResize, f, wf ),
-  myIsExclusive( true )
+  myIsExclusive( true ),
+  myIsAutoResumed( false )
 {
   setObjectPixmap( "SalomeApp", tr( "ICON_SELECT" ) );
 }
index c52c9966b2b6900fdbd3c0c6ee84e6cfd65e1410..e0e5cfe52e297047de155edb2d0ec2fee0528e50 100644 (file)
@@ -51,6 +51,12 @@ public:
   //! Set exclusive state  
   void setExclusive( const bool );
 
+  //! Check if operation according to dialog will be resumed automatically when mouse enter the dialog
+  bool isAutoResumed() const;
+
+  //! Set auto resumed state
+  void setAutoResumed( const bool );
+
   //! Show widgets corresponding to id
   void showObject( const int );
 
@@ -203,7 +209,7 @@ private:
 private:
   ObjectMap           myObjects;
   QMap<int,QString>   myTypeNames;
-  bool                myIsExclusive;
+  bool                myIsExclusive, myIsAutoResumed;
   QPixmap             myPixmap;
 };
 
index c1728e3f4cd662a560dcf03d36b6a66c2e858e02..f3a8e6f1f173de81cc226e7bbeb45552ac931563 100644 (file)
@@ -11,6 +11,7 @@
 #include "SalomeApp_Preferences.h"
 #include "SalomeApp_UpdateFlags.h"
 #include "SalomeApp_Operation.h"
+#include "SalomeApp_SwitchOp.h"
 
 #include <OB_Browser.h>
 
@@ -30,7 +31,8 @@
 
 SalomeApp_Module::SalomeApp_Module( const QString& name )
 : CAM_Module( name ),
-myPopupMgr( 0 )
+myPopupMgr( 0 ),
+mySwitchOp( 0 )
 {
 }
 
@@ -232,6 +234,12 @@ void SalomeApp_Module::startOperation( const int id )
       op->setModule( this );
       connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) );
       connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) );
+      if ( mySwitchOp == 0 )
+      {
+        mySwitchOp = new SalomeApp_SwitchOp( this );
+        printf( "sln: new SalomeApp_SwitchOp\n" );
+      }
+      mySwitchOp->connect( op );
     }
   }
 
index abbce5b97950168fa78c8e505084e819a2d5b378..d174902acb7a0561441df32a74d88bd7d0c6b3b9 100644 (file)
@@ -29,6 +29,7 @@ class SalomeApp_Application;
 class SalomeApp_Preferences;
 class SalomeApp_SelectionManager;
 class SalomeApp_Operation;
+class SalomeApp_SwitchOp;
 
 /*
   Class : SalomeApp_Module
@@ -122,6 +123,7 @@ private:
 private:
   QtxPopupMgr*          myPopupMgr;
   MapOfOperation        myOperations;
+  SalomeApp_SwitchOp*   mySwitchOp;
 };
 
 #endif
index e8177867be7ca6e6e835830c798737f87147de8c..ca16c894cbfa981ce83d99e289fac66b65eeeceb 100755 (executable)
@@ -17,6 +17,8 @@
 
 #include <SUIT_Desktop.h>
 
+#include <qapplication.h>
+
 /*
   Class       : SalomeApp_Operation
   Description : Base class for all operations
@@ -195,18 +197,18 @@ bool SalomeApp_Operation::eventFilter( QObject* obj, QEvent* e )
 {
   if( e )
   {
-    if( isAutoResumed() &&
-        ( e->type()==QEvent::Enter  ||
-          e->type()==QEvent::WindowActivate ||
-          e->type()==QEvent::MouseButtonPress ||
-          e->type()==QEvent::MouseButtonDblClick ) )
-      resume();
+//    if( isAutoResumed() &&
+//        ( e->type()==QEvent::Enter  ||
+//          e->type()==QEvent::WindowActivate ||
+//          e->type()==QEvent::MouseButtonPress ||
+//          e->type()==QEvent::MouseButtonDblClick ) )
+//      resume();
       
-    else if( e->type()==QEvent::MouseButtonRelease ||
-             e->type()==QEvent::MouseButtonDblClick ||
-             e->type()==QEvent::MouseMove ||
-             e->type()==QEvent::KeyPress ||
-             e->type()==QEvent::KeyRelease  )
+    if( e->type()==QEvent::MouseButtonRelease ||
+        e->type()==QEvent::MouseButtonDblClick ||
+        e->type()==QEvent::MouseMove ||
+        e->type()==QEvent::KeyPress ||
+        e->type()==QEvent::KeyRelease  )
       return true;
   }
       
@@ -230,13 +232,16 @@ void SalomeApp_Operation::update( const int flags )
 void SalomeApp_Operation::setDialogActive( const bool active )
 {
   if( dlg() )
+  {
     if( active )
     {
       dlg()->removeEventFilter( this );
       activateSelection();
+      dlg()->setActiveWindow();
     }
     else
       dlg()->installEventFilter( this );
+  }
 }
 
 //=======================================================================
index e5138c0001c6fd60b612e2ad511a8241d871e5ca..175b51db2c2c6fb13b72c154dd3a06b08723775d 100755 (executable)
@@ -42,13 +42,6 @@ public:
 
   //! Check if operation will be resumed automatically when mouse enter the dialog
   bool isAutoResumed() const;
-  
-protected:
-
-  //! Set auto resumed state
-  void setAutoResumed( const bool );
-
-  // Important virtual methods (should be redefined in the derived classes)
 
   virtual SalomeApp_Dialog* dlg() const;
   // Get dialog. This method should be redefined in derived classes
@@ -58,6 +51,13 @@ protected:
   //  2. activated in resumeOperation method
   //  3. hidden in abortOperation and commitOperation methods
 
+protected:
+
+  //! Set auto resumed state
+  void setAutoResumed( const bool );
+
+  // Important virtual methods (should be redefined in the derived classes)
+
   virtual void              setDialogActive( const bool );
   // Change the active state of dialog (given by dlg())
   
diff --git a/src/SalomeApp/SalomeApp_SwitchOp.cxx b/src/SalomeApp/SalomeApp_SwitchOp.cxx
new file mode 100755 (executable)
index 0000000..ac40a53
--- /dev/null
@@ -0,0 +1,171 @@
+/**
+*  SALOME SalomeApp
+*
+*  Copyright (C) 2005  CEA/DEN, EDF R&D
+*
+*
+*
+*  File   : SalomeApp_SwitchOp.h
+*  Author : Sergey LITONIN
+*  Module : SALOME
+*/
+
+#include "SalomeApp_SwitchOp.h"
+#include "SalomeApp_Module.h"
+#include "SalomeApp_Operation.h"
+#include "SalomeApp_Dialog.h"
+#include <CAM_Application.h>
+#include <SUIT_Operation.h>
+#include <SUIT_Study.h>
+#include <qevent.h>
+#include <qwidget.h>
+#include <qptrlist.h>
+#include <qapplication.h>
+
+/*!
+ * \brief Constructor
+  * \param theParent - parent of object
+*
+* Creates instance of the object. Connects signals and slots. Install eveny filter
+* on application
+*/
+SalomeApp_SwitchOp::SalomeApp_SwitchOp( SalomeApp_Module* theModule )
+: QObject( theModule )
+{
+  qApp->installEventFilter( this );
+}
+
+/*!
+ * \brief Destructor
+*/
+SalomeApp_SwitchOp::~SalomeApp_SwitchOp()
+{
+  
+}
+
+/*!
+ * \brief SLOT. Called when number of operations changed
+*
+*
+*/
+void SalomeApp_SwitchOp::onOperation()
+{
+}
+
+/*!
+ * \brief Get module
+*
+* Get module. Module is a parent of this class
+*/
+SalomeApp_Module* SalomeApp_SwitchOp::module() const
+{
+  return ( SalomeApp_Module* )parent();
+}
+
+/*!
+ * \brief Get study
+ * \return Active study of application (in current realisation)
+*
+* Get study
+*/
+SUIT_Study* SalomeApp_SwitchOp::study() const
+{
+  return module()->application()->activeStudy();
+}
+
+/*!
+ * \brief Get operation by widget
+  * \param theWg - key widget to find operation
+  * \return Pointer to the operations if it is found or zero 
+*
+* Find operation containing dialog with given widget
+*/
+SalomeApp_Operation* SalomeApp_SwitchOp::operation( QWidget* theWg ) const
+{
+  // get dialog from widget
+  SalomeApp_Dialog* aDlg = 0;
+  QWidget* aParent = theWg;
+  while( aParent && !aParent->inherits( "SalomeApp_Dialog" ) )
+    aParent = aParent->parentWidget();
+
+  if ( aParent && aParent->inherits( "SalomeApp_Dialog" ) )
+    aDlg = (SalomeApp_Dialog*)aParent;
+
+  // try to find operation corresponding to the dialog
+  if ( aDlg != 0 && study() != 0 )
+  {
+    QPtrListIterator<SUIT_Operation> anIter( study()->operations() );
+    while( SUIT_Operation* anOp = anIter.current() )
+    {
+      if ( anOp->inherits( "SalomeApp_Operation" ) &&
+           ((SalomeApp_Operation*)anOp)->dlg() == aDlg )
+        return ((SalomeApp_Operation*)anOp);
+      ++anIter;
+   }
+  }
+
+  return 0;
+}
+
+/*!
+ * \brief Connect signals of operation on the slots of object
+  * \param theOp - operation for connection
+*
+* Connect signals of operation on the slots of object. This method is called by module
+* when it creates operation
+*/
+void SalomeApp_SwitchOp::connect( SalomeApp_Operation* theOp )
+{
+// to do: ???
+//  void              started( SUIT_Operation* );
+//  void              aborted( SUIT_Operation* );
+//  void              resumed( SUIT_Operation* );
+//  void              committed( SUIT_Operation* );
+//  void              suspended( SUIT_Operation* );
+//  void              stopped( SUIT_Operation* );
+}
+
+/*!
+ * \brief Event filter
+  * \param theObj - object
+  * \param theEv - event
+*
+* Event filter. Catched signals off application. If event concerns to dialog then
+* corresponding operation is found and activated.
+*/
+bool SalomeApp_SwitchOp::eventFilter( QObject* theObj, QEvent* theEv )
+{
+  if ( theObj->inherits( "QWidget" ) && ( theEv->type() == QEvent::Enter ) )
+  {
+    SalomeApp_Operation* anOp = operation( (QWidget*)theObj );
+    if ( anOp && !anOp->isActive() && anOp->isAutoResumed() )
+    {
+      if ( study() )
+      {
+        if ( study()->canActivate( anOp ) )
+          study()->resume( anOp );
+      }
+    }
+  }
+
+  return QObject::eventFilter( theObj, theEv );
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/SalomeApp/SalomeApp_SwitchOp.h b/src/SalomeApp/SalomeApp_SwitchOp.h
new file mode 100755 (executable)
index 0000000..8a0b2c9
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+*  SALOME SalomeApp
+*
+*  Copyright (C) 2005  CEA/DEN, EDF R&D
+*
+*
+*
+*  File   : SalomeApp_SwitchOp.h
+*  Author : Sergey LITONIN
+*  Module : SALOME
+*/
+
+
+
+#ifndef SalomeApp_SwitchOp_H
+#define SalomeApp_SwitchOp_H
+
+#include <qobject.h>
+
+class SalomeApp_Module;
+class SalomeApp_Operation;
+class QEvent;
+class SUIT_Study;
+
+/*!
+ * \brief This class is intended for controling switching between operation
+ *
+ * Several operation may be launched simultaneously. This class is intended for
+ * controlling switching between such operations. This class works with operations having
+ * dialogs (activation of other operations is performed by SUIT_Study). When several
+ * operations is launched simultaneously corresponding dialogs are shown on the screen.
+ * Only one operation from the launched ones can be active (active operation). Other
+ * operations are suspended. As result only one dialog from shown ones can be active too.
+ * Other dialogs are disabled. This class installs event filter on application. When mouse
+ * cursor is moved above disabled dialog corresponding event is catched by this class.
+ * It finds corresponding operation and verify whether operation can be resumed (see
+ * SUIT_Study::canActivate( SUIT_Operation* ) method). If yes then current active
+ * operation is suspended and new operation activated. Module contains this class as a
+ * field. Then module is created instance of this class created too.
+ */
+class SalomeApp_SwitchOp : public QObject
+{
+  Q_OBJECT
+
+public:
+
+  SalomeApp_SwitchOp( SalomeApp_Module* );
+  virtual ~SalomeApp_SwitchOp();
+
+  void                      connect( SalomeApp_Operation* );
+
+  // Redefined from base class
+  bool                      eventFilter( QObject*, QEvent* );
+
+private slots:
+
+  void                      onOperation();
+
+private:
+
+  SalomeApp_Module*         module() const;
+  SalomeApp_Operation*      operation( QWidget* ) const;
+  SUIT_Study*               study() const;
+
+private:
+
+  
+};
+
+#endif
+
+
+
+
+
+