]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_IOperation.h
Salome HOME
Sources formated according to the codeing standards
[modules/shaper.git] / src / ModuleBase / ModuleBase_IOperation.h
1 /*
2  * ModuleBase_IOperation.h
3  *
4  *  Created on: May 5, 2014
5  *      Author: nds
6  */
7
8 #ifndef ModuleBase_IOperation_H
9 #define ModuleBase_IOperation_H
10
11 #include <ModuleBase.h>
12
13 #include <QObject>
14 #include <QString>
15 #include <QList>
16
17 #include <boost/shared_ptr.hpp>
18
19 class ModelAPI_Document;
20 class ModuleBase_OperationDescription;
21 //class ModuleBase_ModelWidget;
22
23 /*!
24  \class ModuleBase_IOperation
25  * \brief Base class for all operations
26  *
27  *  Base class for all operations. If you perform an action it is reasonable to create
28  *  operation intended for this. This is a base class for all operations which provides
29  *  mechanism for correct starting operations, starting operations above already started
30  *  ones, committing operations and so on. To create own operation it is reasonable to
31  *  inherit it from this class and redefines virtual methods to provide own behavior
32  *  Main virtual methods are
33  *  - virtual bool      isReadyToStart();
34  *  - virtual void      startOperation();
35  *  - virtual void      abortOperation();
36  *  - virtual void      commitOperation();
37  */
38
39 class MODULEBASE_EXPORT ModuleBase_IOperation : public QObject
40 {
41 Q_OBJECT
42
43  public:
44   /// Constructor
45   /// Constructs an empty operation. Constructor should work very fast because many
46   /// operators may be created after starting workshop but only several from them
47   /// may be used. As result this constructor stores given workshop in myApp field
48   /// and set Waiting status.
49   /// \param theId the operation identifier
50   /// \param theParent the QObject parent
51   ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0);
52   /// Destructor
53   virtual ~ModuleBase_IOperation();
54
55   /// Returns the operation description
56   /// /returns the instance of the description class
57   ModuleBase_OperationDescription* getDescription() const;
58
59   /// Verifies whether this operator can be always started above any already running one
60   /// \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
61   /// This method must be redefined in derived operation if operation of derived class
62   /// must be always can start above any launched one. Default impl returns FALSE,
63   /// so it is being checked for IsValid, but some operations may overload IsGranted()
64   /// In this case they will always start, no matter what operation is running.
65   /// \param theOperation the previous running operation
66   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
67
68   /// Sets a list of model widgets, according to the operation feature xml definition
69   /// \param theXmlRepresentation an xml feature definition
70   /// \param theWidgets a list of widgets
71   //void setModelWidgets(const std::string& theXmlRepresentation,
72   //                     QList<ModuleBase_ModelWidget*> theWidgets);
73
74   /// Returns True if data of its feature was modified during operation
75   virtual bool isModified() const
76   {
77     return myIsModified;
78   }
79
80   /// Returns True id the current operation is launched in editing mode
81   bool isEditOperation() const
82   {
83     return myIsEditing;
84   }
85
86 signals:
87   void started();  /// the operation is started
88   void aborted();  /// the operation is aborted
89   void committed();  /// the operation is committed
90   void stopped();  /// the operation is aborted or committed
91   void resumed();  /// the operation is resumed
92
93  public slots:
94   /// Starts operation
95   /// Public slot. Verifies whether operation can be started and starts operation.
96   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
97   /// to change behavior of operation. There is no point in using this method. It would
98   /// be better to inherit own operator from base one and redefine startOperation method
99   /// instead.
100   void start();
101   /// Resumes operation
102   /// Public slot. Verifies whether operation can be started and starts operation.
103   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
104   /// to change behavior of operation. There is no point in using this method. It would
105   /// be better to inherit own operator from base one and redefine startOperation method
106   /// instead.
107   void resume();
108   /// Aborts operation
109   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
110   /// Redefine abortOperation method to change behavior of operation instead
111   void abort();
112   /// Commits operation
113   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
114   /// Redefine commitOperation method to change behavior of operation instead
115   bool commit();
116
117   /// Alias for start/abort slots
118   /// Public slot. Aborts operation if false, else does nothing.
119   /// Provided for S/S compatibility with QAction's toggle(bool)
120   /// \param theState th flag to abort, if it is true, do nothing, overwise abort
121   void setRunning(bool theState);
122
123   // Data model methods.
124   /// Stores a custom value in model.
125   virtual void storeCustomValue() = 0;
126
127  protected:
128   /// Virtual method called when operation started (see start() method for more description)
129   /// Default impl calls corresponding slot and commits immediately.
130   virtual void startOperation() = 0;
131
132   /// Virtual method called when operation stopped - committed or aborted.
133   virtual void stopOperation() = 0;
134
135   /// Virtual method called when operation aborted (see abort() method for more description)
136   virtual void abortOperation() = 0;
137
138   /// Virtual method called when operation committed (see commit() method for more description)
139   virtual void commitOperation() = 0;
140
141   /// Virtual method called after operation committed (see commit() method for more description)
142   /// it is important that the method is called after the stop() signal is emitted
143   virtual void afterCommitOperation() = 0;
144
145   /// Verifies whether this operator can be commited.
146   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
147   virtual bool canBeCommitted() const;
148
149   /// Returns pointer to the root document.
150   boost::shared_ptr<ModelAPI_Document> document() const;
151
152   /// Editing feature flag
153   bool myIsEditing;
154
155   /// Modified feature flag
156   bool myIsModified;
157
158  private:
159   ModuleBase_OperationDescription* myDescription;  /// the container to have the operation description
160 };
161
162 #endif