2 * ModuleBase_Operation.cpp
4 * Created on: Apr 2, 2014
8 #include "ModuleBase_Operation.h"
10 #include <ModelAPI_AttributeDouble.h>
11 #include <ModelAPI_Document.h>
12 #include <ModelAPI_Feature.h>
13 #include <ModelAPI_Object.h>
14 #include <ModelAPI_PluginManager.h>
18 \param XGUI_Workshop - workshop for this operation
20 Constructs an empty operation. Constructor should work very fast because many
21 operators may be created after starting workshop but only several from them
22 may be used. As result this constructor stores given workshop in myApp field
23 and set Waiting status.
25 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* parent)
29 myExecStatus(Rejected),
32 myFeature = ModelAPI_PluginManager::get()->createFeature(theId.toStdString());
38 ModuleBase_Operation::~ModuleBase_Operation()
44 * \brief Unique name of the operation
46 * Returns string name of the operation.
48 QString ModuleBase_Operation::operationId() const
54 * \brief Gets state of operation
55 * \return Value from OperationState enumeration
57 * Gets state of operation (see OperationState enumeration)
59 ModuleBase_Operation::OperationState ModuleBase_Operation::state() const
65 * \brief Verifies whether operation is an ran one (state()==Running)
66 * \return TRUE if operation is active, FALSE otherwise
68 * Verifies whether operation is an running. Returns TRUE if state of operator
71 bool ModuleBase_Operation::isRunning() const
73 return state() == Running;
77 * \brief Verifies whether given operator is valid for this one
78 * \param theOtherOp - other operation
79 * \return Returns TRUE if the given operator is valid for this one
81 * Verifies whether given operator is valid for this one (i.e. can be started "above"
84 bool ModuleBase_Operation::isValid(ModuleBase_Operation*) const
90 * \brief Verifies whether this operator can be always started above any already running one
91 * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
93 * This method must be redefined in derived operation if operation of derived class
94 * must be always can start above any launched one. Default implementation returns FALSE,
95 * so it is being checked for IsValid, but some operations may overload IsGranted()
96 * In this case they will always start, no matter what operation is running.
98 bool ModuleBase_Operation::isGranted() const
104 * Returns pointer to the root document.
106 std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
108 return ModelAPI_PluginManager::get()->rootDocument();
112 * \brief Sets slot which is called when operation is started
113 * \param theReceiver - object containing slot
114 * \param theSlot - slot of theReceiver object
115 * \return TR if slot was connected successfully, FALSE otherwise
117 * Sets slot which is called when operation is started. There is no point in
118 * using this method. It would be better to inherit own operator from base
119 * one and redefine startOperation method
121 bool ModuleBase_Operation::setSlot(const QObject* theReceiver, const char* theSlot)
123 return connect(this, SIGNAL(callSlot()), theReceiver, theSlot);
127 * \brief Sets the flags of operation
128 * \param f - flags of operation to be set
130 * Sets flags of operation (see Flags enumeration)
132 void ModuleBase_Operation::setFlags(const int f)
134 myFlags = myFlags | f;
138 * \brief Clears the flags of operation
139 * \param f - flags of operation to be cleared
141 * Clears flags of operation (see Flags enumeration)
143 void ModuleBase_Operation::clearFlags(const int f)
145 myFlags = myFlags & ~f;
149 * \brief Test the flags of operation
150 * \param f - flags of operation to be tested
152 * Returns TRUE if the specified flags set in the operation (see Flags enumeration)
154 bool ModuleBase_Operation::testFlags(const int f) const
156 return (myFlags & f) == f;
160 * \brief Gets execution status
161 * \return Execution status
163 * Gets execution status
165 int ModuleBase_Operation::execStatus() const
171 * \brief Returns XML representation of the operation's widget.
172 * \return XML QString
174 * Returns XML representation of the operation's widget.
176 const QString& ModuleBase_Operation::xmlRepresentation() const
182 * \brief Sets XML representation of the operation's widget.
183 * \param xmlRepr - XML QString
185 * Sets XML representation of the operation's widget.
187 void ModuleBase_Operation::setXmlRepresentation(const QString& xmlRepr)
193 * \brief Starts operation
195 * Public slot. Verifies whether operation can be started and starts operation.
196 * This slot is not virtual and cannot be redefined. Redefine startOperation method
197 * to change behavior of operation. There is no point in using this method. It would
198 * be better to inherit own operator from base one and redefine startOperation method
201 void ModuleBase_Operation::start()
203 //document()->start(this);
204 document()->startOperation();
211 * \brief Aborts operation
213 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
214 * Redefine abortOperation method to change behavior of operation instead
216 void ModuleBase_Operation::abort()
225 document()->abortOperation();
229 * \brief Commits operation
231 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
232 * Redefine commitOperation method to change behavior of operation instead
234 void ModuleBase_Operation::commit()
243 document()->finishOperation();
247 * \brief Stores a real value in model.
248 * \param theValue - to store
250 * Public slot. Passes theValue into the model.
252 void ModuleBase_Operation::storeReal(double theValue)
254 QString anId = sender()->objectName();
255 std::shared_ptr<ModelAPI_Object> aData = myFeature->data();
256 std::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
257 aReal->setValue(theValue);
261 * \brief Verifies whether operator is ready to start.
262 * \return TRUE if operation is ready to start
264 * Default implementation returns TRUE. Redefine this method to add own verifications
266 bool ModuleBase_Operation::isReadyToStart() const
272 * \brief Virtual method called when operation is started
274 * Virtual method called when operation started (see start() method for more description)
275 * Default implementation calls corresponding slot and commits immediately.
277 void ModuleBase_Operation::startOperation()
284 * \brief Virtual method called when operation is started
286 * Virtual method called when operation stopped - committed or aborted.
288 void ModuleBase_Operation::stopOperation()
293 * \brief Virtual method called when operation aborted
295 * Virtual method called when operation aborted (see abort() method for more description)
297 void ModuleBase_Operation::abortOperation()
302 * \brief Virtual method called when operation committed
304 * Virtual method called when operation committed (see commit() method for more description)
306 void ModuleBase_Operation::commitOperation()
311 * \brief Sets execution status
312 * \param theStatus - execution status
314 * Sets myExecStatus to the given value
316 void ModuleBase_Operation::setExecStatus(const int theVal)
318 myExecStatus = (ExecStatus) theVal;
322 * \brief Sets state of operation
323 * \param theState - state of operation to be set
325 * Sets state of operation (see OperationState enumeration)
327 void ModuleBase_Operation::setState(const ModuleBase_Operation::OperationState theState)