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>
18 #include <ModelAPI_Events.h>
20 #include <Events_Loop.h>
26 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
27 : ModuleBase_IOperation(theId, theParent)
31 ModuleBase_Operation::~ModuleBase_Operation()
35 QString ModuleBase_Operation::id() const
37 return getDescription()->operationId();
40 FeaturePtr ModuleBase_Operation::feature() const
45 bool ModuleBase_Operation::isNestedOperationsEnabled() const
50 void ModuleBase_Operation::storeCustomValue()
54 qDebug() << "ModuleBase_Operation::storeCustom: " <<
55 "trying to store value without opening a transaction.";
60 ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
62 aCustom->storeValue(myFeature);
65 void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
69 void ModuleBase_Operation::startOperation()
72 setFeature(createFeature());
77 void ModuleBase_Operation::stopOperation()
81 void ModuleBase_Operation::abortOperation()
85 void ModuleBase_Operation::commitOperation()
87 if (myFeature) myFeature->execute();
90 void ModuleBase_Operation::afterCommitOperation()
94 void ModuleBase_Operation::flushUpdated()
96 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
99 void ModuleBase_Operation::flushCreated()
101 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
104 FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
106 boost::shared_ptr<ModelAPI_Document> aDoc = document();
107 FeaturePtr aFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
108 if (aFeature) { // TODO: generate an error if feature was not created
111 // Init default values
112 /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
113 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
114 for (; anIt != aLast; anIt++) {
115 (*anIt)->storeValue(aFeature);
124 void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
126 myFeature = theFeature;
129 void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
131 setFeature(theFeature);