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>
20 #include <ModelAPI_Validator.h>
22 #include <Events_Loop.h>
28 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
29 : ModuleBase_IOperation(theId, theParent)
33 ModuleBase_Operation::~ModuleBase_Operation()
37 QString ModuleBase_Operation::id() const
39 return getDescription()->operationId();
42 FeaturePtr ModuleBase_Operation::feature() const
47 bool ModuleBase_Operation::isNestedOperationsEnabled() const
52 void ModuleBase_Operation::storeCustomValue()
56 qDebug() << "ModuleBase_Operation::storeCustom: " <<
57 "trying to store value without opening a transaction.";
62 ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
64 aCustom->storeValue();
67 void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
71 void ModuleBase_Operation::startOperation()
79 void ModuleBase_Operation::stopOperation()
83 void ModuleBase_Operation::abortOperation()
87 void ModuleBase_Operation::commitOperation()
91 void ModuleBase_Operation::afterCommitOperation()
95 bool ModuleBase_Operation::canBeCommitted() const
97 if (ModuleBase_IOperation::canBeCommitted()) {
98 /* FeaturePtr aFeature = feature();
99 std::string aId = aFeature->getKind();
101 PluginManagerPtr aMgr = ModelAPI_PluginManager::get();
102 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
103 std::list<ModelAPI_Validator*> aValidators;
104 aFactory->validators(aId, aValidators);
105 std::list<ModelAPI_Validator*>::const_iterator aIt;
106 for (aIt = aValidators.cbegin(); aIt != aValidators.cend(); ++aIt) {
107 const ModuleBase_FeatureValidator* aFValidator =
108 dynamic_cast<const ModuleBase_FeatureValidator*>(*aIt);
110 if (!aFValidator->isValid(aFeature))
119 void ModuleBase_Operation::flushUpdated()
121 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
124 void ModuleBase_Operation::flushCreated()
126 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
129 FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
131 boost::shared_ptr<ModelAPI_Document> aDoc = document();
132 myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
133 if (myFeature) { // TODO: generate an error if feature was not created
135 // Model update should call "execute" of a feature.
136 //myFeature->execute();
137 // Init default values
138 /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
139 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
140 for (; anIt != aLast; anIt++) {
141 (*anIt)->storeValue(aFeature);
150 void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
152 myFeature = theFeature;
155 void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
157 setFeature(theFeature);
161 bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const
163 FeaturePtr aFeature = feature();
165 if (aFeature == theObj)
167 std::list<ResultPtr> aResults = aFeature->results();
168 std::list<ResultPtr>::const_iterator aIt;
169 for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
170 if ((*aIt) == theObj)