Salome HOME
#1083 errors in parameter
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index 9b24d742d722f407fd27ae9c99fc0a1b7e056f70..66b0a51aaea3e7bba7235649affbb0df5912f54d 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 /*
  * ModuleBase_Operation.cpp
  *
@@ -9,6 +11,10 @@
 
 #include "ModuleBase_OperationDescription.h"
 #include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_ViewerPrs.h"
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_ISelection.h"
+#include "ModuleBase_IViewer.h"
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Result.h>
+#include <ModelAPI_Object.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Session.h>
+
+#include <GeomAPI_Pnt2d.h>
 
 #include <Events_Loop.h>
 
+#include <QTimer>
+
 #ifdef _DEBUG
 #include <QDebug>
 #endif
 
 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
-    : ModuleBase_IOperation(theId, theParent)
+    : QObject(theParent),
+      myIsModified(false),
+      myPropertyPanel(NULL)
 {
+  myDescription = new ModuleBase_OperationDescription(theId);
 }
 
 ModuleBase_Operation::~ModuleBase_Operation()
 {
+  delete myDescription;
 }
 
-QString ModuleBase_Operation::id() const
+const QStringList& ModuleBase_Operation::grantedOperationIds() const
 {
-  return getDescription()->operationId();
+  return myGrantedIds;
 }
 
-FeaturePtr ModuleBase_Operation::feature() const
+void ModuleBase_Operation::setGrantedOperationIds(const QStringList& theList)
 {
-  return myFeature;
+  myGrantedIds = theList;
 }
 
-bool ModuleBase_Operation::isNestedOperationsEnabled() const
+QString ModuleBase_Operation::id() const
 {
-  return true;
+  return getDescription()->operationId();
 }
 
-void ModuleBase_Operation::storeCustomValue()
+bool ModuleBase_Operation::isValid() const
 {
-  if (!myFeature) {
-#ifdef _DEBUG
-    qDebug() << "ModuleBase_Operation::storeCustom: " <<
-    "trying to store value without opening a transaction.";
-#endif
-    return;
-  }
-
-  ModuleBase_ModelWidget* aCustom = dynamic_cast<ModuleBase_ModelWidget*>(sender());
-  if (aCustom)
-    aCustom->storeValue();
+  return true;
 }
 
-void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
+bool ModuleBase_Operation::canBeCommitted() const
 {
+  return isValid();
 }
 
-void ModuleBase_Operation::startOperation()
+void ModuleBase_Operation::start()
 {
-  if (!myIsEditing)
-    createFeature();
-  //emit callSlot();
-  //commit();
-}
+  myIsModified = false;
 
-void ModuleBase_Operation::stopOperation()
-{
-}
+  ModelAPI_Session::get()->startOperation(id().toStdString());
 
-void ModuleBase_Operation::abortOperation()
-{
+  startOperation();
+  emit started();
 }
 
-void ModuleBase_Operation::commitOperation()
+void ModuleBase_Operation::postpone()
 {
+  postponeOperation();
+  emit postponed();
 }
 
-void ModuleBase_Operation::afterCommitOperation()
+void ModuleBase_Operation::resume()
 {
+  resumeOperation();
+  emit resumed();
 }
 
-bool ModuleBase_Operation::canBeCommitted() const
+void ModuleBase_Operation::abort()
 {
-  if (ModuleBase_IOperation::canBeCommitted()) {
-    /*    FeaturePtr aFeature = feature();
-     std::string aId = aFeature->getKind();
-
-     SessionPtr aMgr = ModelAPI_Session::get();
-     ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-     std::list<ModelAPI_Validator*> aValidators;
-     aFactory->validators(aId, aValidators);
-     std::list<ModelAPI_Validator*>::const_iterator aIt;
-     for (aIt = aValidators.cbegin(); aIt != aValidators.cend(); ++aIt) {
-     const ModuleBase_FeatureValidator* aFValidator = 
-     dynamic_cast<const ModuleBase_FeatureValidator*>(*aIt);
-     if (aFValidator) {
-     if (!aFValidator->isValid(aFeature))
-     return false;
-     }
-     }*/
-    return true;
-  }
-  return false;
-}
+  // the viewer update should be blocked in order to avoid the features blinking before they are
+  // hidden
+  //std::shared_ptr<Events_Message> aMsg = std::shared_ptr<Events_Message>(
+  //    new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_BLOCKED)));
+  //Events_Loop::loop()->send(aMsg);
 
-void ModuleBase_Operation::flushUpdated()
-{
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-}
+  ModelAPI_Session::get()->abortOperation();
 
-void ModuleBase_Operation::flushCreated()
-{
-  Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
+  emit stopped();
+  // the viewer update should be unblocked in order to avoid the features blinking before they are
+  // hidden
+  //aMsg = std::shared_ptr<Events_Message>(
+  //              new Events_Message(Events_Loop::eventByName(EVENT_UPDATE_VIEWER_UNBLOCKED)));
+  //Events_Loop::loop()->send(aMsg);
+
+  emit aborted();
 }
 
-FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage)
+bool ModuleBase_Operation::commit()
 {
-  boost::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 (canBeCommitted()) {
+    SessionPtr aMgr = ModelAPI_Session::get();
 
-  if (theFlushMessage)
-    flushCreated();
-  return myFeature;
+    commitOperation();
+    aMgr->finishOperation();
+
+    stopOperation();
+    emit stopped();
+    emit committed();
+
+    afterCommitOperation();
+    return true;
+  }
+  return false;
 }
 
-void ModuleBase_Operation::setFeature(FeaturePtr theFeature)
+void ModuleBase_Operation::onValuesChanged()
 {
-  myFeature = theFeature;
+  myIsModified = true;
 }
 
-void ModuleBase_Operation::setEditingFeature(FeaturePtr theFeature)
-{
-  setFeature(theFeature);
-  myIsEditing = true;
+void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
+{ 
+  myPropertyPanel = theProp; 
 }
 
-bool ModuleBase_Operation::hasObject(ObjectPtr theObj) const
+bool ModuleBase_Operation::isGranted(QString theId) 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 ((*aIt) == theObj)
-        return true;
-    }
-  }
-  return false;
+  return myGrantedIds.contains(theId);
 }
-