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>
22 \param XGUI_Workshop - workshop for this operation
24 Constructs an empty operation. Constructor should work very fast because many
25 operators may be created after starting workshop but only several from them
26 may be used. As result this constructor stores given workshop in myApp field
27 and set Waiting status.
29 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* parent)
33 myExecStatus(Rejected),
41 ModuleBase_Operation::~ModuleBase_Operation()
47 * \brief Unique name of the operation
49 * Returns string name of the operation.
51 QString ModuleBase_Operation::operationId() const
57 * \brief Gets state of operation
58 * \return Value from OperationState enumeration
60 * Gets state of operation (see OperationState enumeration)
62 ModuleBase_Operation::OperationState ModuleBase_Operation::state() const
68 * \brief Verifies whether operation is an ran one (state()==Running)
69 * \return TRUE if operation is active, FALSE otherwise
71 * Verifies whether operation is an running. Returns TRUE if state of operator
74 bool ModuleBase_Operation::isRunning() const
76 return state() == Running;
80 * \brief Verifies whether given operator is valid for this one
81 * \param theOtherOp - other operation
82 * \return Returns TRUE if the given operator is valid for this one
84 * Verifies whether given operator is valid for this one (i.e. can be started "above"
87 bool ModuleBase_Operation::isValid(ModuleBase_Operation*) const
93 * \brief Verifies whether this operator can be always started above any already running one
94 * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
96 * This method must be redefined in derived operation if operation of derived class
97 * must be always can start above any launched one. Default implementation returns FALSE,
98 * so it is being checked for IsValid, but some operations may overload IsGranted()
99 * In this case they will always start, no matter what operation is running.
101 bool ModuleBase_Operation::isGranted() const
107 * Returns pointer to the root document.
109 std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
111 return ModelAPI_PluginManager::get()->rootDocument();
115 * \brief Sets slot which is called when operation is started
116 * \param theReceiver - object containing slot
117 * \param theSlot - slot of theReceiver object
118 * \return TR if slot was connected successfully, FALSE otherwise
120 * Sets slot which is called when operation is started. There is no point in
121 * using this method. It would be better to inherit own operator from base
122 * one and redefine startOperation method
124 bool ModuleBase_Operation::setSlot(const QObject* theReceiver, const char* theSlot)
126 return connect(this, SIGNAL(callSlot()), theReceiver, theSlot);
130 * \brief Sets the flags of operation
131 * \param f - flags of operation to be set
133 * Sets flags of operation (see Flags enumeration)
135 void ModuleBase_Operation::setFlags(const int f)
137 myFlags = myFlags | f;
141 * \brief Clears the flags of operation
142 * \param f - flags of operation to be cleared
144 * Clears flags of operation (see Flags enumeration)
146 void ModuleBase_Operation::clearFlags(const int f)
148 myFlags = myFlags & ~f;
152 * \brief Test the flags of operation
153 * \param f - flags of operation to be tested
155 * Returns TRUE if the specified flags set in the operation (see Flags enumeration)
157 bool ModuleBase_Operation::testFlags(const int f) const
159 return (myFlags & f) == f;
163 * \brief Gets execution status
164 * \return Execution status
166 * Gets execution status
168 int ModuleBase_Operation::execStatus() const
174 * \brief Returns XML representation of the operation's widget.
175 * \return XML QString
177 * Returns XML representation of the operation's widget.
179 const QString& ModuleBase_Operation::xmlRepresentation() const
185 * \brief Sets XML representation of the operation's widget.
186 * \param xmlRepr - XML QString
188 * Sets XML representation of the operation's widget.
190 void ModuleBase_Operation::setXmlRepresentation(const QString& xmlRepr)
196 * \brief Starts operation
198 * Public slot. Verifies whether operation can be started and starts operation.
199 * This slot is not virtual and cannot be redefined. Redefine startOperation method
200 * to change behavior of operation. There is no point in using this method. It would
201 * be better to inherit own operator from base one and redefine startOperation method
204 void ModuleBase_Operation::start()
206 //document()->start(this);
207 document()->startOperation();
214 * \brief Aborts operation
216 * Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
217 * Redefine abortOperation method to change behavior of operation instead
219 void ModuleBase_Operation::abort()
228 document()->abortOperation();
232 * \brief Commits operation
234 * Public slot. Commits operation. This slot is not virtual and cannot be redefined.
235 * Redefine commitOperation method to change behavior of operation instead
237 void ModuleBase_Operation::commit()
246 document()->finishOperation();
250 * \brief Stores a real value in model.
251 * \param theValue - to store
253 * Public slot. Passes theValue into the model.
255 void ModuleBase_Operation::storeReal(double theValue)
259 qDebug() << "ModuleBase_Operation::storeReal: " <<
260 "trying to store value without opening a transaction.";
264 QString anId = sender()->objectName();
265 std::shared_ptr<ModelAPI_Object> aData = myFeature->data();
266 std::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
267 aReal->setValue(theValue);
271 * \brief Verifies whether operator is ready to start.
272 * \return TRUE if operation is ready to start
274 * Default implementation returns TRUE. Redefine this method to add own verifications
276 bool ModuleBase_Operation::isReadyToStart() const
282 * \brief Virtual method called when operation is started
284 * Virtual method called when operation started (see start() method for more description)
285 * Default implementation calls corresponding slot and commits immediately.
287 void ModuleBase_Operation::startOperation()
289 myFeature = ModelAPI_PluginManager::get()->createFeature(myOperationId.toStdString());
295 * \brief Virtual method called when operation is started
297 * Virtual method called when operation stopped - committed or aborted.
299 void ModuleBase_Operation::stopOperation()
304 * \brief Virtual method called when operation aborted
306 * Virtual method called when operation aborted (see abort() method for more description)
308 void ModuleBase_Operation::abortOperation()
313 * \brief Virtual method called when operation committed
315 * Virtual method called when operation committed (see commit() method for more description)
317 void ModuleBase_Operation::commitOperation()
322 * \brief Sets execution status
323 * \param theStatus - execution status
325 * Sets myExecStatus to the given value
327 void ModuleBase_Operation::setExecStatus(const int theVal)
329 myExecStatus = (ExecStatus) theVal;
333 * \brief Sets state of operation
334 * \param theState - state of operation to be set
336 * Sets state of operation (see OperationState enumeration)
338 void ModuleBase_Operation::setState(const ModuleBase_Operation::OperationState theState)