Salome HOME
Exclude ModuleBase_IOperation class.
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.h
1 /*
2  * ModuleBase_Operation.h
3  *
4  *  Created on: Apr 2, 2014
5  *      Author: sbh
6  */
7
8 #ifndef ModuleBase_Operation_H
9 #define ModuleBase_Operation_H
10
11 #include <ModuleBase.h>
12
13 #include <ModelAPI_Feature.h>
14
15 #include <QObject>
16 #include <QString>
17 #include <QStringList>
18
19 #include <boost/shared_ptr.hpp>
20
21 class ModelAPI_Document;
22 class ModuleBase_ModelWidget;
23 class ModuleBase_OperationDescription;
24
25 class QKeyEvent;
26
27 /*!
28  \class ModuleBase_Operation
29  * \brief Base class for all operations
30  *
31  *  Base class for all operations. If you perform an action it is reasonable to create
32  *  operation intended for this. This is a base class for all operations which provides
33  *  mechanism for correct starting operations, starting operations above already started
34  *  ones, committing operations and so on. To create own operation it is reasonable to
35  *  inherit it from this class and redefines virtual methods to provide own behavior
36  *  Main virtual methods are
37  *  - virtual bool      isReadyToStart();
38  *  - virtual void      startOperation();
39  *  - virtual void      abortOperation();
40  *  - virtual void      commitOperation();
41  */
42
43 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
44 {
45 Q_OBJECT
46
47  public:
48   /// Constructor
49   /// \param theId the operation identifier
50   /// \param theParent the QObject parent
51   ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
52   /// Destructor
53   virtual ~ModuleBase_Operation();
54
55   /// Returns the operation description
56   /// /returns the instance of the description class
57   ModuleBase_OperationDescription* getDescription() const { return myDescription; }
58
59   /**
60   * Must return true if this operation can be launched as nested for any current operation
61   * and it is not necessary to check this operation on validity. By default 
62   * the operation is not granted.
63   * The method has to be redefined for granted operations.
64   */
65   virtual bool isGranted(ModuleBase_Operation* theOperation) const  { return false; }
66
67   /// Sets a list of model widgets, according to the operation feature xml definition
68   /// \param theXmlRepresentation an xml feature definition
69   /// \param theWidgets a list of widgets
70   //void setModelWidgets(const std::string& theXmlRepresentation,
71   //                     QList<ModuleBase_ModelWidget*> theWidgets);
72
73   /// Returns True if data of its feature was modified during operation
74   virtual bool isModified() const { return myIsModified; }
75
76   /// Returns True id the current operation is launched in editing mode
77   bool isEditOperation() const { return myIsEditing; }
78
79   /// Returns list of nested features
80   QStringList nestedFeatures() const { return myNestedFeatures; }
81
82   /// Sets list of nested features
83   void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
84
85
86   // Returns operations Id from it's description
87   QString id() const;
88
89   /// Returns the operation feature
90   /// \return the feature
91   FeaturePtr feature() const;
92
93   /**
94   * Must return True if the operation's feature is valid.
95   * Since IOperation does not have any feature returns false.
96   */
97   virtual bool isValid() const;
98
99   /// Returns whether the nested operations are enabled.
100   /// The state can depend on the operation current state.
101   /// \return enabled state
102   virtual bool isNestedOperationsEnabled() const;
103
104   /// Sets the operation feature
105   void setEditingFeature(FeaturePtr theFeature);
106
107   /// Returns True if the current operation works with the given object (feature or result)
108   virtual bool hasObject(ObjectPtr theObj) const;
109
110   virtual void keyReleased(const int theKey) {};
111
112   virtual void activateNextToCurrentWidget() {};
113
114   /// If operation needs to redisplay its result during operation
115   /// then this method has to return True
116   virtual bool hasPreview() const { return false; }
117
118 signals:
119   void started();  /// the operation is started
120   void aborted();  /// the operation is aborted
121   void committed();  /// the operation is committed
122   void stopped();  /// the operation is aborted or committed
123   void resumed();  /// the operation is resumed
124
125   /// Signals about the activating of the next widget
126   /// \param theWidget the previous active widget
127   void activateNextWidget(ModuleBase_ModelWidget* theWidget);
128
129  public slots:
130   /// Starts operation
131   /// Public slot. Verifies whether operation can be started and starts operation.
132   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
133   /// to change behavior of operation. There is no point in using this method. It would
134   /// be better to inherit own operator from base one and redefine startOperation method
135   /// instead.
136   void start();
137   /// Resumes operation
138   /// Public slot. Verifies whether operation can be started and starts operation.
139   /// This slot is not virtual and cannot be redefined. Redefine startOperation method
140   /// to change behavior of operation. There is no point in using this method. It would
141   /// be better to inherit own operator from base one and redefine startOperation method
142   /// instead.
143   void resume();
144   /// Aborts operation
145   /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
146   /// Redefine abortOperation method to change behavior of operation instead
147   void abort();
148   /// Commits operation
149   /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
150   /// Redefine commitOperation method to change behavior of operation instead
151   bool commit();
152
153   /// Alias for start/abort slots
154   /// Public slot. Aborts operation if false, else does nothing.
155   /// Provided for S/S compatibility with QAction's toggle(bool)
156   /// \param theState th flag to abort, if it is true, do nothing, overwise abort
157   void setRunning(bool theState);
158
159   // Data model methods.
160   /// Stores a custom value in model.
161   virtual void storeCustomValue();
162
163   /// Slots which listen the mode widget activation
164   /// \param theWidget the model widget
165   virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
166
167  protected:
168   /// Virtual method called when operation started (see start() method for more description)
169   /// Default impl calls corresponding slot and commits immediately.
170   virtual void startOperation();
171
172   /// Virtual method called when operation stopped - committed or aborted.
173   virtual void stopOperation();
174
175   /// Virtual method called when operation aborted (see abort() method for more description)
176   virtual void abortOperation();
177
178   /// Virtual method called when operation committed (see commit() method for more description)
179   virtual void commitOperation();
180
181   /// Virtual method called after operation committed (see commit() method for more description)
182   virtual void afterCommitOperation();
183
184   /// Send update message by loop
185   void flushUpdated();
186   /// Send created message by loop
187   void flushCreated();
188
189   /// Creates an operation new feature
190   /// \param theFlushMessage the flag whether the create message should be flushed
191   /// \returns the created feature
192   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
193
194   /// Sets the operation feature
195   void setFeature(FeaturePtr theFeature);
196
197   /// Verifies whether this operator can be commited.
198   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
199   virtual bool canBeCommitted() const;
200
201   /// Returns pointer to the root document.
202   boost::shared_ptr<ModelAPI_Document> document() const;
203
204
205  protected:
206   FeaturePtr myFeature;  /// the operation feature to be handled
207
208   /// the container to have the operation description
209   ModuleBase_OperationDescription* myDescription;  
210
211   /// Editing feature flag
212   bool myIsEditing;
213
214   /// Modified feature flag
215   bool myIsModified;
216
217   /// List of nested operations IDs
218   QStringList myNestedFeatures;
219
220 };
221
222 #endif