2 * ModuleBase_Operation.cpp
4 * Created on: Apr 2, 2014
8 #include "ModuleBase_Operation.h"
10 #include "ModuleBase_OperationDescription.h"
11 #include "ModuleBase_ModelWidget.h"
13 #include <ModelAPI_AttributeDouble.h>
14 #include <ModelAPI_Document.h>
15 #include <ModelAPI_Feature.h>
16 #include <ModelAPI_Data.h>
17 #include <ModelAPI_Document.h>
23 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
24 : ModuleBase_IOperation(theId, theParent)
28 ModuleBase_Operation::~ModuleBase_Operation()
32 QString ModuleBase_Operation::id() const
34 return getDescription()->operationId();
37 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::feature() const
42 bool ModuleBase_Operation::isNestedOperationsEnabled()
47 void ModuleBase_Operation::storeReal(double theValue)
51 qDebug() << "ModuleBase_Operation::storeReal: " <<
52 "trying to store value without opening a transaction.";
56 QString anId = sender()->objectName();
57 boost::shared_ptr<ModelAPI_Data> aData = myFeature->data();
58 boost::shared_ptr<ModelAPI_AttributeDouble> aReal = aData->real(anId.toStdString());
59 aReal->setValue(theValue);
62 void ModuleBase_Operation::storeCustomValue()
66 qDebug() << "ModuleBase_Operation::storeCustom: " <<
67 "trying to store value without opening a transaction.";
72 ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
74 aCustom->storeValue(myFeature);
77 void ModuleBase_Operation::startOperation()
79 setFeature(createFeature());
84 void ModuleBase_Operation::stopOperation()
88 void ModuleBase_Operation::abortOperation()
92 void ModuleBase_Operation::commitOperation()
94 if (myFeature) myFeature->execute();
97 boost::shared_ptr<ModelAPI_Feature> ModuleBase_Operation::createFeature()
99 boost::shared_ptr<ModelAPI_Document> aDoc = document();
100 boost::shared_ptr<ModelAPI_Feature> aFeature = aDoc->addFeature(
101 getDescription()->operationId().toStdString());
102 if (aFeature) // TODO: generate an error if feature was not created
107 void ModuleBase_Operation::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
109 myFeature = theFeature;