Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
index 818476d6faf073a3eafc05bd01a95373f7600482..208e3503581df161ca6895fc7981cc60a8da9818 100644 (file)
@@ -5,21 +5,27 @@
  *      Author: sbh
  */
 
-
-#ifndef MODULEBASE_OPERATION_H
-#define MODULEBASE_OPERATION_H
+#ifndef ModuleBase_Operation_H
+#define ModuleBase_Operation_H
 
 #include <ModuleBase.h>
+#include <ModuleBase_ViewerPrs.h>
+
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Document.h>
 
 #include <QObject>
 #include <QString>
+#include <QStringList>
 
-#include <boost/shared_ptr.hpp>
+class ModuleBase_ModelWidget;
+class ModuleBase_OperationDescription;
+class ModuleBase_IPropertyPanel;
+class ModuleBase_ISelection;
+class ModuleBase_IViewer;
+class ModuleBase_WidgetValueFeature;
 
-class SUIT_Study;
-class XGUI_Workshop;
-class ModelAPI_Feature;
-class ModelAPI_Document;
+class QKeyEvent;
 
 /*!
  \class ModuleBase_Operation
@@ -37,104 +43,237 @@ class ModelAPI_Document;
  *  - virtual void      commitOperation();
  */
 
-class MODULEBASE_EXPORT ModuleBase_Operation: public QObject
+class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
 {
 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 the operation description
+  /// /returns the instance of the description class
+  ModuleBase_OperationDescription* getDescription() const { return myDescription; }
 
-  boost::shared_ptr<ModelAPI_Feature> feature() const;
+  /**
+  * Must return true if this operation can be launched as nested for any current operation
+  * and it is not necessary to check this operation on validity. By default 
+  * the operation is not granted.
+  * The method has to be redefined for granted operations.
+  */
+  virtual bool isGranted(QString theId) const;
 
-  OperationState state() const;
-  bool isRunning() const;
-  virtual bool isValid(ModuleBase_Operation* theOtherOp) const;
-  virtual bool isGranted() const;
+  /// Sets a list of model widgets, according to the operation feature xml definition
+  /// \param theXmlRepresentation an xml feature definition
+  /// \param theWidgets a list of widgets
+  //void setModelWidgets(const std::string& theXmlRepresentation,
+  //                     QList<ModuleBase_ModelWidget*> theWidgets);
 
-  bool setSlot(const QObject* theReceiver, const char* theSlot);
+  /// Returns True if data of its feature was modified during operation
+  virtual bool isModified() const { return myIsModified; }
 
-  void setFlags(const int);
-  void clearFlags(const int);
-  bool testFlags(const int) const;
+  /// Returns True id the current operation is launched in editing mode
+  bool isEditOperation() const { return myIsEditing; }
 
-  int execStatus() const;
+  /// Returns list of nested features
+  QStringList nestedFeatures() const { return myNestedFeatures; }
 
-signals:
-  void started();
-  void aborted();
-  void committed();
-  void stopped(); //!< operation aborted or committed
+  /// Sets list of nested features
+  void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
+
+
+  // Returns operations Id from it's description
+  QString id() const;
+
+  /// Returns the operation feature
+  /// \return the feature
+  FeaturePtr feature() const;
+
+  /**
+  * Must return True if the operation's feature is valid.
+  * Since IOperation does not have any feature returns false.
+  */
+  virtual bool isValid() const;
+
+  /// Returns whether the nested operations are enabled.
+  /// The state can depend on the operation current state.
+  /// \return enabled state
+  virtual bool isNestedOperationsEnabled() const;
+
+  /// Sets the operation feature
+  void setFeature(FeaturePtr theFeature);
+
+  /// Returns True if the current operation works with the given object (feature or result)
+  virtual bool hasObject(ObjectPtr theObj) const;
 
-  void callSlot();
+  //virtual void keyReleased(const int theKey) {};
 
-public slots:
+  /// If operation needs to redisplay its result during operation
+  /// then this method has to return True
+  //virtual bool hasPreview() const { return false; }
+
+  /// Initialisation of operation with preliminary selection
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
+  /// \param theViewer a viewer to have the viewer the eye position
+  virtual void initSelection(ModuleBase_ISelection* theSelection,
+                             ModuleBase_IViewer* /* theViewer*/);
+
+  virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
+
+  ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
+
+  /// Activates widgets by preselection if it is accepted
+  virtual bool activateByPreselection();
+
+  /// If the operation works with feature which is sub-feature of another one
+  /// then this variable has to be initialised by parent feature 
+  /// before operation feature creating
+  void setParentFeature(CompositeFeaturePtr theParent) { myParentFeature = theParent; }
+  CompositeFeaturePtr parentFeature() const { return myParentFeature; }
+
+signals:
+  void started();  /// the operation is started
+  void aborted();  /// the operation is aborted
+  void committed();  /// the operation is committed
+  void stopped();  /// the operation is aborted or committed
+  void resumed();  /// the operation is resumed
+  void postponed();  /// the operation is postponed
+
+ public slots:
+  /// Starts operation
+  /// Public slot. Verifies whether operation can be started and starts operation.
+  /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+  /// to change behavior of operation. There is no point in using this method. It would
+  /// be better to inherit own operator from base one and redefine startOperation method
+  /// instead.
   void start();
+
+  /// Deactivates current operation which can be resumed later.
+  void postpone();
+
+  /// Resumes operation
+  /// Public slot. Verifies whether operation can be started and starts operation.
+  /// This slot is not virtual and cannot be redefined. Redefine startOperation method
+  /// to change behavior of operation. There is no point in using this method. It would
+  /// be better to inherit own operator from base one and redefine startOperation method
+  /// instead.
+  void resume();
+
+  /// Aborts operation
+  /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
+  /// Redefine abortOperation method to change behavior of operation instead
   void abort();
-  void commit();
 
-  //true = do nothing, false = abort()
-  //Provided for S/S compatibility with QAction's toggle(bool)
-  void setRunning(bool);
+  /// Commits operation
+  /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
+  /// Redefine commitOperation method to change behavior of operation instead
+  bool commit();
+
+  /// Alias for start/abort slots
+  /// Public slot. Aborts operation if false, else does nothing.
+  /// Provided for S/S compatibility with QAction's toggle(bool)
+  /// \param theState th flag to abort, if it is true, do nothing, overwise abort
+  void setRunning(bool theState);
+
+  // Data model methods.
+  /// Stores a custom value in model.
+  //virtual void storeCustomValue();
+
+  /// Slots which listen the mode widget activation
+  /// \param theWidget the model widget
+  //virtual void onWidgetActivated(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() {}
+
+  /// Implementation of specific steps on postpone operation
+  virtual void postponeOperation() {}
+
+  /// 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();
+
+  /// Creates an operation new feature
+  /// \param theFlushMessage the flag whether the create message should be flushed
+  /// \param theCompositeFeature the feature that must be used for adding the created object or null
+  /// \returns the created 
+  virtual FeaturePtr createFeature(const bool theFlushMessage = true);
+
+  /// 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;
+
+  /// Returns pointer to the root document.
+  std::shared_ptr<ModelAPI_Document> document() const;
+
+  /// Set value to the active widget
+  /// \param theFeature the feature
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  /// \return true if the point is set
+  //virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
+
+  /// Return a widget value point by the selection and the viewer position
+  /// The default realization returns false
+  /// \param thePrs the presentation
+  /// \param theViewer a viewer to have the viewer the eye position
+  /// \param theX the horizontal coordinate
+  /// \param theY the vertical coordinate
+  /// \return true if the point exits in the selection
+  virtual bool getViewerPoint(ModuleBase_ViewerPrs thePrs,
+                                   ModuleBase_IViewer* theViewer,
+                                   double& theX, double& theY);
+
+  // Removes the preselection information and clears the map of preselection
+  void clearPreselection();
+
+ protected:
+  FeaturePtr myFeature;  /// the operation feature to be handled
 
-  // Data model operations.
-  void storeReal(double);
+  /// the container to have the operation description
+  ModuleBase_OperationDescription* myDescription;  
 
-  // Data model operations.
-  void storeCustomValue();
+  /// Editing feature flag
+  bool myIsEditing;
 
-protected:
-  virtual bool isReadyToStart() const;
+  /// Modified feature flag
+  bool myIsModified;
 
-  virtual void startOperation();
-  virtual void stopOperation();
-  virtual void abortOperation();
-  virtual void commitOperation();
+  /// List of nested operations IDs
+  QStringList myNestedFeatures;
 
-  void setExecStatus(const int);
-  void setState(const OperationState);
+  /// List of pre-selected object 
+  QList<ModuleBase_WidgetValueFeature*> myPreSelection;
 
-  boost::shared_ptr<ModelAPI_Document> document() const;
+  /// Access to property panel
+  ModuleBase_IPropertyPanel* myPropertyPanel;
 
-private:
-  int myFlags;               //!< Operation flags
-  OperationState myState;    //!< Operation state
-  ExecStatus myExecStatus;   //!< Execution status
+  /// If the operation works with feature which is sub-feature of another one
+  /// then this variable has to be initialised by parent feature 
+  /// before operation feature creating
+  CompositeFeaturePtr myParentFeature;  
 
-  //!< Next fields could be extracted into a subclass;
-  QString myOperationId;
-  boost::shared_ptr<ModelAPI_Feature> myFeature;
 };
 
 #endif