+ if (!myFeature)
+ return true; // rename operation
+ if (myFeature->isAction())
+ return true;
+ //Get validators for the Id
+ SessionPtr aMgr = ModelAPI_Session::get();
+ ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+ return aFactory->validate(myFeature);
+}
+
+
+bool ModuleBase_Operation::canBeCommitted() const
+{
+ return isValid();
+}
+
+void ModuleBase_Operation::flushUpdated()
+{
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+}
+
+void ModuleBase_Operation::flushCreated()
+{
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+}
+
+FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
+{
+ if (myParentFeature.get()) {
+ myFeature = myParentFeature->addFeature(getDescription()->operationId().toStdString());
+ } else {
+ std::shared_ptr<ModelAPI_Document> aDoc = document();
+ myFeature = aDoc->addFeature(getDescription()->operationId().toStdString());
+ }
+ if (myFeature) { // TODO: generate an error if feature was not created
+ myIsModified = true;
+ // Model update should call "execute" of a feature.
+ //myFeature->execute();
+ // Init default values
+ /*QList<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
+ QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
+ for (; anIt != aLast; anIt++) {
+ (*anIt)->storeValue(aFeature);
+ }*/
+ }
+
+ if (theFlushMessage)
+ flushCreated();
+ return myFeature;
+}
+
+void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
+{
+ myFeature = theFeature;
+ myIsEditing = true;
+}
+
+bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const
+{
+ FeaturePtr aFeature = feature();
+ if (aFeature) {
+ if (aFeature == theObj)
+ return true;
+ std::list<ResultPtr> aResults = aFeature->results();
+ std::list<ResultPtr>::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+ if (theObj == (*aIt))
+ return true;
+ }
+ }
+ return false;
+}
+
+
+std::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
+{
+ return ModelAPI_Session::get()->moduleDocument();
+}
+
+
+void ModuleBase_Operation::start()
+{
+ QString anId = getDescription()->operationId();
+ ModelAPI_Session::get()->startOperation(anId.toStdString());
+
+ if (!myIsEditing)
+ createFeature();
+
+ startOperation();
+ emit started();
+
+}
+
+void ModuleBase_Operation::postpone()
+{
+ postponeOperation();
+ emit postponed();
+}
+
+void ModuleBase_Operation::resume()
+{
+ resumeOperation();
+ emit resumed();
+}
+
+void ModuleBase_Operation::abort()
+{
+ abortOperation();
+ emit aborted();
+
+ stopOperation();
+
+ ModelAPI_Session::get()->abortOperation();
+ emit stopped();
+}
+
+bool ModuleBase_Operation::commit()
+{
+ if (canBeCommitted()) {
+ commitOperation();
+ // check whether there are modifications performed during the current operation
+ // in the model
+ // in case if there are no modifications, do not increase the undo/redo stack
+ if (ModelAPI_Session::get()->isModified())
+ ModelAPI_Session::get()->finishOperation();
+ else
+ ModelAPI_Session::get()->abortOperation();
+
+ stopOperation();
+ emit stopped();
+ emit committed();
+
+ afterCommitOperation();
+ return true;