#include "ModuleBase_Operation.h"
+#include "ModuleBase_WidgetCustom.h"
+
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Feature.h>
return myOperationId;
}
+boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
+{
+ return myFeature;
+}
+
/*!
* \brief Gets state of operation
* \return Value from OperationState enumeration
* \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this )
*
* This method must be redefined in derived operation if operation of derived class
- * must be always can start above any launched one. Default implementation returns FALSE,
+ * must be always can start above any launched one. Default impl returns FALSE,
* so it is being checked for IsValid, but some operations may overload IsGranted()
* In this case they will always start, no matter what operation is running.
*/
/*
* Returns pointer to the root document.
*/
-std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
+boost::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
{
return ModelAPI_PluginManager::get()->rootDocument();
}
return myExecStatus;
}
-/*!
- * \brief Returns XML representation of the operation's widget.
- * \return XML QString
- *
- * Returns XML representation of the operation's widget.
- */
-const QString& ModuleBase_Operation::xmlRepresentation() const
-{
- return myXmlRepr;
-}
-
-/*!
- * \brief Sets XML representation of the operation's widget.
- * \param xmlRepr - XML QString
- *
- * Sets XML representation of the operation's widget.
- */
-void ModuleBase_Operation::setXmlRepresentation(const QString& xmlRepr)
-{
- myXmlRepr = xmlRepr;
-}
-
/*!
* \brief Starts operation
*
emit started();
}
+/*!
+ * \brief Resumes operation
+ *
+ * Public slot. Verifies whether operation can be started and starts operation.
+ * This slot is not virtual and cannot be redefined. Redefine startOperation method
+ * to change behavior of operation. There is no point in using this method. It would
+ * be better to inherit own operator from base one and redefine startOperation method
+ * instead.
+ */
+void ModuleBase_Operation::resume()
+{
+}
+
/*!
* \brief Aborts operation
*
emit aborted();
stopOperation();
- emit stopped();
document()->abortOperation();
+ emit stopped();
}
/*!
emit committed();
stopOperation();
- emit stopped();
document()->finishOperation();
+ emit stopped();
+}
+
+/*
+ * \brief Alias for start/abort slots
+ *
+ * Public slot. Aborts operation if false, else does nothing.
+ * Provided for S/S compatibility with QAction's toggle(bool)
+ */
+void ModuleBase_Operation::setRunning(bool on)
+{
+ if (!on) {
+ abort();
+ }
}
/*!
return;
}
QString anId = sender()->objectName();
- std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
- std::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
+ boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+ boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
aReal->setValue(theValue);
}
+/*!
+ * \brief Stores a real value in model.
+ * \param theValue - to store
+ *
+ * Public slot. Passes theValue into the model.
+ */
+void ModuleBase_Operation::storeCustomValue()
+{
+ if(!myFeature){
+ #ifdef _DEBUG
+ qDebug() << "ModuleBase_Operation::storeCustom: " <<
+ "trying to store value without opening a transaction.";
+ #endif
+ return;
+ }
+
+ ModuleBase_WidgetCustom* aCustom = dynamic_cast<ModuleBase_WidgetCustom*>(sender());
+ if (aCustom)
+ aCustom->store(myFeature);
+}
+
/*!
* \brief Verifies whether operator is ready to start.
* \return TRUE if operation is ready to start
*
- * Default implementation returns TRUE. Redefine this method to add own verifications
+ * Default impl returns TRUE. Redefine this method to add own verifications
*/
bool ModuleBase_Operation::isReadyToStart() const
{
* \brief Virtual method called when operation is started
*
* Virtual method called when operation started (see start() method for more description)
- * Default implementation calls corresponding slot and commits immediately.
+ * Default impl calls corresponding slot and commits immediately.
*/
void ModuleBase_Operation::startOperation()
{
- std::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
+ boost::shared_ptr<ModelAPI_Document> aDoc = ModelAPI_PluginManager::get()->rootDocument();
myFeature = aDoc->addFeature(myOperationId.toStdString());
- myFeature->execute();
+ if (myFeature) // TODO: generate an error if feature was not created
+ myFeature->execute();
//emit callSlot();
//commit();
}
*/
void ModuleBase_Operation::commitOperation()
{
- myFeature->execute();
+ if (myFeature) myFeature->execute();
}
/*!