Salome HOME
Issue #2206 Avoid the ability to cancel the current sketch when saving,
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.h
index 0cda5543cac21bd86caa7adc9ea582a2ee03585a..b180436b3c53ab4fce86064f119c3864a4fab889 100755 (executable)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        XGUI_OperationMgr.h
-// Created:     20 Apr 2014
-// Author:      Natalia ERMOLAEVA
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #ifndef XGUI_OperationMgr_H
 #define XGUI_OperationMgr_H
@@ -20,6 +34,7 @@ class QKeyEvent;
 
 class ModuleBase_IWorkshop;
 class XGUI_Workshop;
+class XGUI_ShortCutListener;
 
 /**\class XGUI_OperationMgr
  * \ingroup GUI
@@ -33,7 +48,15 @@ class XGUI_Workshop;
 class XGUI_EXPORT XGUI_OperationMgr : public QObject
 {
 Q_OBJECT
- public:
+public:
+  /// Enumeration of kind of message that is used when trying to stop the active operation
+  enum XGUI_MessageKind
+  {
+    XGUI_AbortOperationMessage, //< warns and give possibility to abort current operation
+    XGUI_InformationMessage //< ask to apply the current operation before performing something
+  };
+
+public:
   /// Constructor
   /// \param theParent the parent
   /// \param theWorkshop a reference to workshop
@@ -42,11 +65,19 @@ Q_OBJECT
   /// Destructor
   virtual ~XGUI_OperationMgr();
 
+  /// Switch on short cut listener
+  void activate();
+  /// Switch off short cut listener
+  void deactivate();
+
   /// Set reference to workshop
   /// \param theWorkshop reference to workshop
   void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
   { myWorkshop = theWorkshop; };
 
+  /// Current workshop
+  ModuleBase_IWorkshop* workshop() const { return myWorkshop; }
+
   /// Returns the current operation or NULL
   /// \return the current operation
   ModuleBase_Operation* currentOperation() const;
@@ -64,7 +95,9 @@ Q_OBJECT
   /// Returns true if the operation can be aborted. If the operation is modified,
   /// the warning message box is shown.
   /// \param theOperation an operation which is checked on stop
-  bool canStopOperation(ModuleBase_Operation* theOperation);
+  /// \param theMessageKind a kind of message in warning message box
+  bool canStopOperation(ModuleBase_Operation* theOperation,
+                        const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
 
   /// Find and return operation by its Id.
   ModuleBase_Operation* findOperation(const QString& theId) const;
@@ -79,9 +112,6 @@ Q_OBJECT
   /// else, or if there is no parent - returns NULL
   ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
 
-  /// Redefinition of virtual function
-  virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
-
   /// Start the operation and append it to the stack of operations
   /// \param theOperation the started operation
   /// \return the state whether the current operation is started
@@ -90,7 +120,13 @@ Q_OBJECT
   /// Returns whether the operation can be started. Check if there is already started operation and
   /// the granted parameter of the launched operation
   /// \param theId id of the operation which is going to start
-  bool canStartOperation(const QString& theId);
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  bool canStartOperation(const QString& theId, bool& isCommitted);
+
+  /// If Apply is enabled and operation has modification, it is applyed, otherwise aborted
+  /// \param theOperation the started operation
+  /// \param isCommitted boolean value if the operation was committed otherwise it was aborted
+  void stopOperation(ModuleBase_Operation* theOperation, bool& isCommitted);
 
   /// Aborts the parameter operation if it is current, else abort operations from the stack
   /// of operations until the operation is found. All operations upper the parameter one are
@@ -98,31 +134,32 @@ Q_OBJECT
   /// \param theOperation an aborted operation
   void abortOperation(ModuleBase_Operation* theOperation);
 
-  /// Returns enable apply state 
-  /// \return theEnabled a boolean value
-  bool isApplyEnabled() const;
+  /// Abort all operations
+  /// \param theMessageKind kind of shown warning message
+  bool abortAllOperations(const XGUI_MessageKind& theMessageKind = XGUI_AbortOperationMessage);
+
+  /// Commits the current operation.
+  bool commitOperation();
+
+  /// Returns true if SHIFT is pressed
+  /// \param thePressed new boolean state
+  void setSHIFTPressed(const bool thePressed) { mySHIFTPressed = thePressed; }
 
-  /// Returns valid state of the parent operation. If the current operation is the last one
-  /// it returns the valid state of the operation
+  /// Returns true if SHIFT is pressed
   /// \return boolean value
-  bool isParentOperationValid() const;
+  bool hasSHIFTPressed() const { return mySHIFTPressed; }
 
 public slots:
-  /// Slot that commits the current operation.
-  void onCommitOperation();
   /// Slot that aborts the current operation.
   void onAbortOperation();
+  /// Slot that aborts all operations. It shows aborting message
+  void onAbortAllOperation();
   /// Slot that validates the current operation using the validateOperation method.
   void onValidateOperation();
   /// Commit all operations
   bool commitAllOperations();
-  /// Abort all operations
-  bool abortAllOperations();
 
 signals:
-  /// Signal about an operation is started. It is emitted after the start() of operation is done.
-  void operationStarted(ModuleBase_Operation* theOperation);
-
   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
   /// \param theOperation a stopped operation
   void operationStopped(ModuleBase_Operation* theOperation);
@@ -136,24 +173,16 @@ signals:
   /// Emitted when current operation is aborted
   void operationAborted(ModuleBase_Operation* theOperation);
 
-  /// Signal is emitted after the current operation is filled with existing preselection.
-  void operationActivatedByPreselection();
-
   /// Signal is emitted after the key released click.
   void keyEnterReleased();
 
- protected:
-  /// Sets apply state to the value and emit signal about this state is changed
-  /// \param theEnabled the state value
-  void setApplyEnabled(const bool theEnabled);
-
 public: // TEMPORARY, it should be protected and be performed automatically
   /// Emits nestedStateChange for operations with an information about validity of the operation
   /// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
   void updateApplyOfOperations(ModuleBase_Operation* theOperation = 0);
 
-  /// Commits the current operatin if it is valid
-  bool commitOperation();
+  /// Updates the current operation state after undo/redo actions calling
+  void updateOperationByUndoRedo();
 
 protected: // TEMPORARY
   /// Sets the current operation or NULL
@@ -173,10 +202,23 @@ protected: // TEMPORARY
 
  public slots:
   /// SLOT, that is called by the key in the property panel is clicked.
+  /// \param theObject a sender of the event
   /// \param theEvent the mouse event
-  bool onKeyReleased(QKeyEvent* theEvent);
+  bool onKeyReleased(QObject *theObject, QKeyEvent* theEvent);
+
+  /// The functionaly, that should be done by delete click
+  /// Fistly the active widget processes it, then workshop. If no one does not
+  /// process it, do nothing
+  /// \param theObject a sender of the event
+  bool onProcessDelete(QObject* theObject);
 
   protected slots:
+  /// The functionaly, that should be done by enter click
+  /// Fistly the active widget processes it, then module. If no one does not
+  /// process it, the current operation is committed
+  /// \param theObject a sender of the event
+  bool onProcessEnter(QObject *theObject);
+
   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
   /// If there is a suspended operation, restart it.
   void onOperationStopped();
@@ -205,7 +247,10 @@ protected: // TEMPORARY
   void onOperationResumed();
 
 private:
-  XGUI_Workshop* workshop() const;
+  /// Checks if the object is a parent or a child under
+  /// \param theObject an investivated object
+  /// \param theParent a candidate to be a parent
+  static bool isChildObject(const QObject* theObject, const QObject* theParent);
 
  private:
   typedef QList<ModuleBase_Operation*> Operations;  ///< definition for a list of operations
@@ -215,8 +260,8 @@ private:
   /// Current workshop
   ModuleBase_IWorkshop* myWorkshop;
 
-  /// Lock/Unlock access to Ok button in property panel
-  bool myIsApplyEnabled;
+  XGUI_ShortCutListener* myShortCutListener;
+  bool mySHIFTPressed;
 };
 
 #endif