Salome HOME
#1083 errors in parameter
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index 5ffb8b760b196be178ffa85d5f5cba7064ff2eb0..66b0a51aaea3e7bba7235649affbb0df5912f54d 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 /*
  * ModuleBase_Operation.cpp
  *
 
 #include "ModuleBase_OperationDescription.h"
 #include "ModuleBase_ModelWidget.h"
-#include "ModuleBase_WidgetValueFeature.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>
@@ -29,8 +31,7 @@
 
 #include <Events_Loop.h>
 
-#include <TopoDS.hxx>
-#include <TopoDS_Vertex.hxx>
+#include <QTimer>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -38,7 +39,6 @@
 
 ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
     : QObject(theParent),
-      myIsEditing(false),
       myIsModified(false),
       myPropertyPanel(NULL)
 {
@@ -50,180 +50,84 @@ 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::isValid() const
+QString ModuleBase_Operation::id() const
 {
-  if (!myFeature)
-    return true; // rename operation
-  //Get validators for the Id
-  SessionPtr aMgr = ModelAPI_Session::get();
-  ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-  return aFactory->validate(myFeature);
+  return getDescription()->operationId();
 }
 
-bool ModuleBase_Operation::isNestedOperationsEnabled() const
+bool ModuleBase_Operation::isValid() const
 {
   return true;
 }
 
-void ModuleBase_Operation::storeCustomValue()
-{
-  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();
-}
-
-void ModuleBase_Operation::startOperation()
-{
-  if (!myIsEditing)
-    createFeature();
-}
-
-void ModuleBase_Operation::stopOperation()
-{
-}
-
-void ModuleBase_Operation::abortOperation()
-{
-}
-
-void ModuleBase_Operation::commitOperation()
-{
-}
-
-void ModuleBase_Operation::afterCommitOperation()
-{
-}
-
 bool ModuleBase_Operation::canBeCommitted() const
 {
-  return true;
-}
-
-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));
+  return isValid();
 }
 
-FeaturePtr ModuleBase_Operation::createFeature(
-  const bool theFlushMessage, CompositeFeaturePtr theCompositeFeature)
+void ModuleBase_Operation::start()
 {
-  if (theCompositeFeature) {
-    myFeature = theCompositeFeature->addFeature(getDescription()->operationId().toStdString());
-  } else {
-    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);
-     }*/
-  }
+  myIsModified = false;
 
-  if (theFlushMessage)
-    flushCreated();
-  return myFeature;
-}
+  ModelAPI_Session::get()->startOperation(id().toStdString());
 
-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 ((*aIt) == theObj)
-        return true;
-    }
-  }
-  return false;
-}
-
-
-boost::shared_ptr<ModelAPI_Document> ModuleBase_Operation::document() const
-{
-  return ModelAPI_Session::get()->moduleDocument();
+  startOperation();
+  emit started();
 }
 
-
-void ModuleBase_Operation::start()
+void ModuleBase_Operation::postpone()
 {
-  ModelAPI_Session::get()->startOperation();
-
-  startOperation();
-  emit started();
+  postponeOperation();
+  emit postponed();
 }
 
 void ModuleBase_Operation::resume()
 {
-  if (myPropertyPanel)
-    connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
-            this,            SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+  resumeOperation();
   emit resumed();
 }
 
 void ModuleBase_Operation::abort()
 {
-  abortOperation();
-  emit aborted();
-  if (myPropertyPanel)
-    disconnect(myPropertyPanel, 0, this, 0);
-
-  stopOperation();
+  // 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);
 
   ModelAPI_Session::get()->abortOperation();
+
   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();
 }
 
 bool ModuleBase_Operation::commit()
 {
   if (canBeCommitted()) {
-    commitOperation();
-    emit committed();
+    SessionPtr aMgr = ModelAPI_Session::get();
 
-  if (myPropertyPanel)
-    disconnect(myPropertyPanel, 0, this, 0);
+    commitOperation();
+    aMgr->finishOperation();
 
     stopOperation();
-    ModelAPI_Session::get()->finishOperation();
-
     emit stopped();
+    emit committed();
 
     afterCommitOperation();
     return true;
@@ -231,110 +135,17 @@ bool ModuleBase_Operation::commit()
   return false;
 }
 
-void ModuleBase_Operation::setRunning(bool theState)
-{
-  if (!theState) {
-    abort();
-  }
-}
-
-bool ModuleBase_Operation::activateByPreselection()
-{
-  if (!myPropertyPanel)
-    return false;
-  if (myPreSelection.empty())
-    return false;
-  const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
-  if (aWidgets.empty())
-    return false;
-  
-  ModuleBase_ModelWidget* aWgt;
-  ModuleBase_ViewerPrs aPrs;
-  QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
-  QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
-  for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
-       (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
-       ++aWIt, ++aPIt) {
-    aWgt = (*aWIt);
-    aPrs = (*aPIt);
-    ModuleBase_WidgetValueFeature aValue;
-    aValue.setObject(aPrs.object());
-    // Check if the selection has a selected point
-    // for today it is impossible to do because
-    // the selected point demands convertation to Sketch plane 2d
-    if (!aWgt->setValue(&aValue))
-      break;
-  }
-  if (canBeCommitted()) {
-    // if all widgets are filled with selection
-    commit();
-    return true;
-  }
-
-  //ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
-  //if ((myPreSelection.size() > 0) && aActiveWgt) {
-  //  const ModuleBase_ViewerPrs& aPrs = myPreSelection.first();
-  //  ModuleBase_WidgetValueFeature aValue;
-  //  aValue.setObject(aPrs.object());
-  //  if (aActiveWgt->setValue(&aValue)) {
-  //    myPreSelection.removeOne(aPrs);
-  //    myPropertyPanel->activateNextWidget();
-  //  }
-  //  // If preselection is enough to make a valid feature - apply it immediately
-  //}
-  return false;
-}
-
-void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection)
+void ModuleBase_Operation::onValuesChanged()
 {
-  myPreSelection.clear();
-
-  // Check that the selected result are not results of operation feature
-  QList<ModuleBase_ViewerPrs> aSelected = theSelection->getSelected();
-  FeaturePtr aFeature = feature();
-  if (aFeature) {
-    std::list<ResultPtr> aResults = aFeature->results();
-    QList<ObjectPtr> aResList;
-    std::list<ResultPtr>::const_iterator aIt;
-    for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt)
-      aResList.append(*aIt);
-
-    foreach (ModuleBase_ViewerPrs aPrs, aSelected) {
-      if ((!aResList.contains(aPrs.object())) && (aPrs.object() != aFeature))
-        myPreSelection.append(aPrs);
-    }
-  } else
-    myPreSelection = aSelected;
+  myIsModified = true;
 }
 
-void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
-{
-  //activateByPreselection();
-  //if (theWidget && myPropertyPanel) {
-  //  myPropertyPanel->activateNextWidget();
-  ////  //emit activateNextWidget(myActiveWidget);
-  //}
-}
-
-bool ModuleBase_Operation::setWidgetValue(ObjectPtr theFeature, double theX, double theY)
-{
-  ModuleBase_ModelWidget* aActiveWgt = myPropertyPanel->activeWidget();
-  if (!aActiveWgt)
-    return false;
-  ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
-  aValue->setObject(theFeature);
-  aValue->setPoint(boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY)));
-  bool isApplyed = aActiveWgt->setValue(aValue);
-
-  delete aValue;
-  myIsModified = (myIsModified || isApplyed);
-  return isApplyed;
-}
-
-
 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
 { 
   myPropertyPanel = theProp; 
-  connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
-          SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
+}
+
+bool ModuleBase_Operation::isGranted(QString theId) const
+{
+  return myGrantedIds.contains(theId);
 }