Salome HOME
Provide hasPreview method for operations with preview
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
index 5daf8e6c66d974db3824dd9ccc599056bb26de7c..17be4cba4286a6e6e63ea45c6ed6e3ec622c681a 100644 (file)
@@ -5,21 +5,23 @@
  *      Author: sbh
  */
 
-
-#ifndef MODULEBASE_OPERATION_H
-#define MODULEBASE_OPERATION_H
+#ifndef ModuleBase_Operation_H
+#define ModuleBase_Operation_H
 
 #include <ModuleBase.h>
+#include <ModuleBase_IOperation.h>
+
+#include <ModelAPI_Feature.h>
 
 #include <QObject>
 #include <QString>
 
-#include <memory>
+#include <boost/shared_ptr.hpp>
 
-class SUIT_Study;
-class XGUI_Workshop;
-class ModelAPI_Feature;
 class ModelAPI_Document;
+class ModuleBase_ModelWidget;
+
+class QKeyEvent;
 
 /*!
  \class ModuleBase_Operation
@@ -37,100 +39,93 @@ class ModelAPI_Document;
  *  - virtual void      commitOperation();
  */
 
-class MODULEBASE_EXPORT ModuleBase_Operation: public QObject
+class MODULEBASE_EXPORT ModuleBase_Operation : public ModuleBase_IOperation
 {
 Q_OBJECT
 
-public:
-  /*! Enum describes state of operation */
-  enum OperationState
-  {
-    Waiting,  //!< Operation is not used (it is not run or suspended)
-    Running,  //!< Operation is started
-  };
-
-  /*!
-   * Enum describes execution status of operation. Execution status often used after
-   * ending work of operation which was started from this one. In this case this
-   * operation can ask previously started operation whether it finished successfully.
-   */
-  enum ExecStatus
-  {
-    Rejected, //!< Operation has not performed any action (modification of data model for example)
-    Accepted  //!< Operation has performed an actions and must be stopped
-  };
-
-  /*!
-   * Enum describes setting of the operation.
-   */
-  enum Flags
-  {
-    None = 0x00, //!< None options
-    Transaction = 0x01 //!< Automatically open (commit/abort) transaction during start (commit/abort).
-  };
-
-public:
-  ModuleBase_Operation(const QString& theId = "", QObject* parent = 0);
+ public:
+  /// Constructor
+  /// \param theId the operation identifier
+  /// \param theParent the QObject parent
+  ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
+  /// Destructor
   virtual ~ModuleBase_Operation();
 
-  // Operation processing.
-  virtual QString operationId() const;
+  // Returns operations Id from it's description
+  QString id() const;
+  /// Returns the operation feature
+  /// \return the feature
+  FeaturePtr feature() const;
 
-  OperationState state() const;
-  bool isRunning() const;
-  virtual bool isValid(ModuleBase_Operation* theOtherOp) const;
-  virtual bool isGranted() const;
+  /// Returns true is feature of operation is valid.
+  virtual bool isValid() const;
 
-  bool setSlot(const QObject* theReceiver, const char* theSlot);
+  /// Returns whether the nested operations are enabled.
+  /// The state can depend on the operation current state.
+  /// \return enabled state
+  virtual bool isNestedOperationsEnabled() const;
 
-  void setFlags(const int);
-  void clearFlags(const int);
-  bool testFlags(const int) const;
+  // Data model methods.
+  /// Stores a custom value in model.
+  void storeCustomValue();
 
-  int execStatus() const;
+  /// Sets the operation feature
+  void setEditingFeature(FeaturePtr theFeature);
 
-  // Widget processing.
-  const QString& xmlRepresentation() const;
-  void setXmlRepresentation(const QString& xmlRepr);
+  /// Returns True if the current operation works with the given object (feature or result)
+  virtual bool hasObject(ObjectPtr theObj) const;
 
-signals:
-  void started();
-  void aborted();
-  void committed();
-  void stopped(); //!< operation aborted or committed
+  virtual void keyReleased(const int theKey) {};
 
-  void callSlot();
+  virtual void activateNextToCurrentWidget() {};
 
-public slots:
-  void start();
-  void abort();
-  void commit();
+  /// If operation needs to redisplay its result during operation
+  /// then this method has to return True
+  virtual bool hasPreview() const { return false; }
 
-  // Data model operations.
-  void storeReal(double);
+ public slots:
+  /// Slots which listen the mode widget activation
+  /// \param theWidget the model widget
+  virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
 
-protected:
-  virtual bool isReadyToStart() const;
+signals:
+  /// Signals about the activating of the next widget
+  /// \param theWidget the previous active widget
+  void activateNextWidget(ModuleBase_ModelWidget* theWidget);
 
+ protected:
+  /// Virtual method called when operation started (see start() method for more description)
+  /// Default impl calls corresponding slot and commits immediately.
   virtual void startOperation();
+  /// Virtual method called when operation stopped - committed or aborted.
   virtual void stopOperation();
+  /// Virtual method called when operation aborted (see abort() method for more description)
   virtual void abortOperation();
+  /// Virtual method called when operation committed (see commit() method for more description)
   virtual void commitOperation();
+  /// Virtual method called after operation committed (see commit() method for more description)
+  virtual void afterCommitOperation();
+
+  /// Send update message by loop
+  void flushUpdated();
+  /// Send created message by loop
+  void flushCreated();
 
-  void setExecStatus(const int);
-  void setState(const OperationState);
+  /// Creates an operation new feature
+  /// \param theFlushMessage the flag whether the create message should be flushed
+  /// \returns the created feature
+  virtual FeaturePtr createFeature(const bool theFlushMessage = true);
 
-  std::shared_ptr<ModelAPI_Document> document() const;
+ protected:
+  /// Sets the operation feature
+  void setFeature(FeaturePtr theFeature);
 
-private:
-  int myFlags;               //!< Operation flags
-  OperationState myState;    //!< Operation state
-  ExecStatus myExecStatus;   //!< Execution status
+  /// Verifies whether this operator can be commited.
+  /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
+  virtual bool canBeCommitted() const;
 
-  //!< Next fields could be extracted into a subclass;
-  QString myOperationId;
-  QString myXmlRepr;
-  std::shared_ptr<ModelAPI_Feature> myFeature;
+ protected:
+  FeaturePtr myFeature;  /// the operation feature to be handled
 };
 
 #endif