]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/ModuleBase/ModuleBase_Operation.cpp
Salome HOME
Issue #273: Add copyright string
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index 9f062b7adbbddf058bae391b0399965fe7a01cc7..516430bd04270fdf20b6874a86eb30022d7cb6b5 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 /*
  * ModuleBase_Operation.cpp
  *
@@ -9,7 +11,6 @@
 
 #include "ModuleBase_OperationDescription.h"
 #include "ModuleBase_ModelWidget.h"
-#include "ModuleBase_WidgetValueFeature.h"
 #include "ModuleBase_ViewerPrs.h"
 #include "ModuleBase_IPropertyPanel.h"
 #include "ModuleBase_ISelection.h"
@@ -30,7 +31,7 @@
 
 #include <Events_Loop.h>
 
-#include <QApplication>
+#include <QTimer>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -181,8 +182,6 @@ void ModuleBase_Operation::postpone()
 
 void ModuleBase_Operation::resume()
 {
-  if (myPropertyPanel)
-    connect(myPropertyPanel, SIGNAL(noMoreWidgets()), SLOT(commit()));
   //  connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
   //          this,            SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
   emit resumed();
@@ -235,24 +234,30 @@ void ModuleBase_Operation::setRunning(bool theState)
 
 bool ModuleBase_Operation::activateByPreselection()
 {
-  if (!myPropertyPanel)
-    return false;
-  if (myPreSelection.empty())
+  if (!myPropertyPanel || myPreSelection.empty()) {
+    myPropertyPanel->activateNextWidget(NULL);
     return false;
+  }
   const QList<ModuleBase_ModelWidget*>& aWidgets = myPropertyPanel->modelWidgets();
-  if (aWidgets.empty())
+  if (aWidgets.empty()) {
+    myPropertyPanel->activateNextWidget(NULL);
     return false;
+  }
   
   ModuleBase_ModelWidget* aWgt, *aFilledWgt = 0;
   QList<ModuleBase_ModelWidget*>::const_iterator aWIt;
-  QList<ModuleBase_WidgetValueFeature*>::const_iterator aPIt;
+  QList<ModuleBase_ViewerPrs>::const_iterator aPIt;
   bool isSet = false;
   for (aWIt = aWidgets.constBegin(), aPIt = myPreSelection.constBegin();
        (aWIt != aWidgets.constEnd()) && (aPIt != myPreSelection.constEnd());
-       ++aWIt, ++aPIt) {
+       ++aWIt) {
     aWgt = (*aWIt);
-    ModuleBase_WidgetValueFeature* aValue = (*aPIt);
-    if (!aWgt->setValue(aValue)) {
+    ModuleBase_ViewerPrs aValue = (*aPIt);
+    if (!aWgt->canSetValue())
+      continue;
+
+    ++aPIt;
+    if (!aWgt->setSelection(aValue)) {
       isSet = false;
       break;
     } else {
@@ -260,19 +265,14 @@ bool ModuleBase_Operation::activateByPreselection()
       aFilledWgt = aWgt;
     }
   }
-  if (isSet && canBeCommitted()) {
-    // if all widgets are filled with selection
-    bool aIsDone = commit();
-    QApplication::processEvents();
-    return aIsDone;
-  }
-  else {
-    //activate next widget
-    if (aFilledWgt) {
-      myPropertyPanel->activateNextWidget(aFilledWgt);
-      return true;
-    }
+
+  if (aFilledWgt) {
+    myPropertyPanel->activateNextWidget(aFilledWgt);
+    emit activatedByPreselection();
+    return true;
   }
+  else
+    myPropertyPanel->activateNextWidget(NULL);
   return false;
 }
 
@@ -302,16 +302,17 @@ void ModuleBase_Operation::initSelection(ModuleBase_ISelection* theSelection,
 
   // convert the selection values to the values, which are set to the operation widgets
 
-  Handle(V3d_View) aView = theViewer->activeView();
-  foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) {
-    ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
-    aValue->setObject(aPrs.object());
-
-    double aX, anY;
-    if (getViewerPoint(aPrs, theViewer, aX, anY))
-      aValue->setPoint(std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
-    myPreSelection.append(aValue);
-  }
+  //Handle(V3d_View) aView = theViewer->activeView();
+  //foreach (ModuleBase_ViewerPrs aPrs, aPreSelected) {
+  //  ModuleBase_WidgetValueFeature* aValue = new ModuleBase_WidgetValueFeature();
+  //  aValue->setObject(aPrs.object());
+
+  //  double aX, anY;
+  //  if (getViewerPoint(aPrs, theViewer, aX, anY))
+  //    aValue->setPoint(std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aX, anY)));
+  //  myPreSelection.append(aValue);
+  //}
+  myPreSelection = aPreSelected;
 }
 
 //void ModuleBase_Operation::onWidgetActivated(ModuleBase_ModelWidget* theWidget)
@@ -347,9 +348,7 @@ bool ModuleBase_Operation::getViewerPoint(ModuleBase_ViewerPrs thePrs,
 
 void ModuleBase_Operation::clearPreselection()
 {
-  while (!myPreSelection.isEmpty()) {
-    delete myPreSelection.takeFirst();
-  }
+  myPreSelection.clear();
 }
 
 void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp) 
@@ -358,9 +357,6 @@ void ModuleBase_Operation::setPropertyPanel(ModuleBase_IPropertyPanel* theProp)
   myPropertyPanel->setEditingMode(isEditOperation());
   //connect(myPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)), this,
   //        SLOT(onWidgetActivated(ModuleBase_ModelWidget*)));
-  if (myPropertyPanel) {
-    connect(myPropertyPanel, SIGNAL(noMoreWidgets()), SLOT(commit()));
-  }
 }
 
 bool ModuleBase_Operation::isGranted(QString theId) const