2 * ModuleBase_Operation.h
4 * Created on: Apr 2, 2014
8 #ifndef ModuleBase_Operation_H
9 #define ModuleBase_Operation_H
11 #include <ModuleBase.h>
12 #include <ModuleBase_ViewerPrs.h>
14 #include <ModelAPI_Feature.h>
15 #include <ModelAPI_Document.h>
19 #include <QStringList>
21 class ModuleBase_ModelWidget;
22 class ModuleBase_OperationDescription;
23 class ModuleBase_IPropertyPanel;
28 \class ModuleBase_Operation
29 * \brief Base class for all operations
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();
43 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
49 /// \param theId the operation identifier
50 /// \param theParent the QObject parent
51 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
53 virtual ~ModuleBase_Operation();
55 /// Returns the operation description
56 /// /returns the instance of the description class
57 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
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.
65 virtual bool isGranted(ModuleBase_Operation* theOperation) const { return false; }
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);
73 /// Returns True if data of its feature was modified during operation
74 virtual bool isModified() const { return myIsModified; }
76 /// Returns True id the current operation is launched in editing mode
77 bool isEditOperation() const { return myIsEditing; }
79 /// Returns list of nested features
80 QStringList nestedFeatures() const { return myNestedFeatures; }
82 /// Sets list of nested features
83 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
86 // Returns operations Id from it's description
89 /// Returns the operation feature
90 /// \return the feature
91 FeaturePtr feature() const;
94 * Must return True if the operation's feature is valid.
95 * Since IOperation does not have any feature returns false.
97 virtual bool isValid() const;
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;
104 /// Sets the operation feature
105 void setFeature(FeaturePtr theFeature);
107 /// Returns True if the current operation works with the given object (feature or result)
108 virtual bool hasObject(ObjectPtr theObj) const;
110 virtual void keyReleased(const int theKey) {};
112 /// If operation needs to redisplay its result during operation
113 /// then this method has to return True
114 virtual bool hasPreview() const { return false; }
116 /// Initialisation of operation with preliminary selection
117 /// \param theSelected the list of selected presentations
118 /// \param theHighlighted the list of highlighted presentations
119 virtual void initSelection(const std::list<ModuleBase_ViewerPrs>& theSelected,
120 const std::list<ModuleBase_ViewerPrs>& theHighlighted);
122 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
124 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
127 void started(); /// the operation is started
128 void aborted(); /// the operation is aborted
129 void committed(); /// the operation is committed
130 void stopped(); /// the operation is aborted or committed
131 void resumed(); /// the operation is resumed
135 /// Public slot. Verifies whether operation can be started and starts operation.
136 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
137 /// to change behavior of operation. There is no point in using this method. It would
138 /// be better to inherit own operator from base one and redefine startOperation method
141 /// Resumes operation
142 /// Public slot. Verifies whether operation can be started and starts operation.
143 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
144 /// to change behavior of operation. There is no point in using this method. It would
145 /// be better to inherit own operator from base one and redefine startOperation method
149 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
150 /// Redefine abortOperation method to change behavior of operation instead
152 /// Commits operation
153 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
154 /// Redefine commitOperation method to change behavior of operation instead
157 /// Alias for start/abort slots
158 /// Public slot. Aborts operation if false, else does nothing.
159 /// Provided for S/S compatibility with QAction's toggle(bool)
160 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
161 void setRunning(bool theState);
163 // Data model methods.
164 /// Stores a custom value in model.
165 virtual void storeCustomValue();
167 /// Slots which listen the mode widget activation
168 /// \param theWidget the model widget
169 virtual void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
172 /// Virtual method called when operation started (see start() method for more description)
173 /// Default impl calls corresponding slot and commits immediately.
174 virtual void startOperation();
176 /// Virtual method called when operation stopped - committed or aborted.
177 virtual void stopOperation();
179 /// Virtual method called when operation aborted (see abort() method for more description)
180 virtual void abortOperation();
182 /// Virtual method called when operation committed (see commit() method for more description)
183 virtual void commitOperation();
185 /// Virtual method called after operation committed (see commit() method for more description)
186 virtual void afterCommitOperation();
188 /// Send update message by loop
190 /// Send created message by loop
193 /// Creates an operation new feature
194 /// \param theFlushMessage the flag whether the create message should be flushed
195 /// \returns the created feature
196 virtual FeaturePtr createFeature(const bool theFlushMessage = true);
198 /// Verifies whether this operator can be commited.
199 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
200 virtual bool canBeCommitted() const;
202 /// Returns pointer to the root document.
203 boost::shared_ptr<ModelAPI_Document> document() const;
206 virtual void activateByPreselection();
208 /// Set value to the active widget
209 /// \param theFeature the feature
210 /// \param theX the horizontal coordinate
211 /// \param theY the vertical coordinate
212 /// \return true if the point is set
213 virtual bool setWidgetValue(ObjectPtr theFeature, double theX, double theY);
216 FeaturePtr myFeature; /// the operation feature to be handled
218 /// the container to have the operation description
219 ModuleBase_OperationDescription* myDescription;
221 /// Editing feature flag
224 /// Modified feature flag
227 /// List of nested operations IDs
228 QStringList myNestedFeatures;
230 /// List of pre-selected object
231 std::list<ModuleBase_ViewerPrs> myPreSelection;
233 /// Access to property panel
234 ModuleBase_IPropertyPanel* myPropertyPanel;