2 * ModuleBase_IOperation.h
4 * Created on: May 5, 2014
8 #ifndef ModuleBase_IOperation_H
9 #define ModuleBase_IOperation_H
11 #include <ModuleBase.h>
17 #include <boost/shared_ptr.hpp>
19 class ModelAPI_Document;
20 class ModuleBase_OperationDescription;
21 //class ModuleBase_ModelWidget;
24 \class ModuleBase_IOperation
25 * \brief Base class for all operations
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();
39 class MODULEBASE_EXPORT ModuleBase_IOperation : public QObject
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);
53 virtual ~ModuleBase_IOperation();
55 /// Returns the operation description
56 /// /returns the instance of the description class
57 ModuleBase_OperationDescription* getDescription() const;
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;
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);
74 /// Returns True if data of its feature was modified during operation
75 virtual bool isModified() const
80 /// Returns True id the current operation is launched in editing mode
81 bool isEditOperation() const
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
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
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
109 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
110 /// Redefine abortOperation method to change behavior of operation instead
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
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);
123 // Data model methods.
124 /// Stores a custom value in model.
125 virtual void storeCustomValue() = 0;
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;
132 /// Virtual method called when operation stopped - committed or aborted.
133 virtual void stopOperation() = 0;
135 /// Virtual method called when operation aborted (see abort() method for more description)
136 virtual void abortOperation() = 0;
138 /// Virtual method called when operation committed (see commit() method for more description)
139 virtual void commitOperation() = 0;
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;
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;
149 /// Returns pointer to the root document.
150 boost::shared_ptr<ModelAPI_Document> document() const;
152 /// Editing feature flag
155 /// Modified feature flag
159 ModuleBase_OperationDescription* myDescription; /// the container to have the operation description