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