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>
19 #include <ModelAPI_Result.h>
21 #include <Events_Loop.h>
27 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
28 : ModuleBase_IOperation(theId, theParent)
32 ModuleBase_Operation::~ModuleBase_Operation()
36 QString ModuleBase_Operation::id() const
38 return getDescription()->operationId();
41 FeaturePtr ModuleBase_Operation::feature() const
46 bool ModuleBase_Operation::isNestedOperationsEnabled() const
51 void ModuleBase_Operation::storeCustomValue()
55 qDebug() << "ModuleBase_Operation::storeCustom: " <<
56 "trying to store value without opening a transaction.";
61 ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
63 aCustom->storeValue(myFeature);
66 void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
70 void ModuleBase_Operation::startOperation()
78 void ModuleBase_Operation::stopOperation()
82 void ModuleBase_Operation::abortOperation()
86 void ModuleBase_Operation::commitOperation()
88 if (myFeature) myFeature->execute();
91 void ModuleBase_Operation::afterCommitOperation()
95 void ModuleBase_Operation::flushUpdated()
97 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
100 void ModuleBase_Operation::flushCreated()
102 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
105 FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
107 boost::shared_ptr<ModelAPI_Document> aDoc = document();
108 myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
109 if (myFeature) { // TODO: generate an error if feature was not created
111 myFeature->execute();
112 // Init default values
113 /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
114 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
115 for (; anIt != aLast; anIt++) {
116 (*anIt)->storeValue(aFeature);
125 void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
127 myFeature = theFeature;
130 void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
132 setFeature(theFeature);
136 bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const
138 FeaturePtr aFeature = feature();
140 if (aFeature.get() == theObj.get())
142 std::list<ResultPtr> aResults = aFeature->results();
143 std::list<ResultPtr>::const_iterator aIt;
144 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
145 if ((*aIt).get() == theObj.get())