Salome HOME
Issue #273: Add copyright string
[modules/shaper.git] / src / ModuleBase / ModuleBase_Operation.cpp
index eca9c1c2ae9097aa802bee7b97d48c91c4cfa9ce..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"
@@ -233,28 +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) {
     aWgt = (*aWIt);
-    ModuleBase_WidgetValueFeature* aValue = (*aPIt);
+    ModuleBase_ViewerPrs aValue = (*aPIt);
     if (!aWgt->canSetValue())
       continue;
 
     ++aPIt;
-    if (!aWgt->setValue(aValue)) {
+    if (!aWgt->setSelection(aValue)) {
       isSet = false;
       break;
     } else {
@@ -262,19 +265,14 @@ bool ModuleBase_Operation::activateByPreselection()
       aFilledWgt = aWgt;
     }
   }
-  if (isSet && canBeCommitted()) {
-    // if all widgets are filled with selection - commit
-    // in order to commit the operation outside of starting procedure - use timer event
-    QTimer::singleShot(50, this, SLOT(commit()));
+
+  if (aFilledWgt) {
+    myPropertyPanel->activateNextWidget(aFilledWgt);
+    emit activatedByPreselection();
     return true;
   }
-  else {
-    //activate next widget
-    if (aFilledWgt) {
-      myPropertyPanel->activateNextWidget(aFilledWgt);
-      return true;
-    }
-  }
+  else
+    myPropertyPanel->activateNextWidget(NULL);
   return false;
 }
 
@@ -304,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)
@@ -349,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)