Salome HOME
Issue #2929: Make possible enable/disable additional highlighting on mouse moving
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetPointInput.cpp
index 29265d26cdb86288fedd2c82ad34be24a6678b42..faf5ff52791e14db8726cac27fafe84c1298773d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "ModuleBase_WidgetPointInput.h"
@@ -34,6 +33,9 @@
 #include <QFormLayout>
 #include <QLabel>
 
+
+#define ERR_STRING "ERROR"
+
 ModuleBase_WidgetPointInput::ModuleBase_WidgetPointInput(QWidget* theParent,
   ModuleBase_IWorkshop* theWorkshop,
   const Config_WidgetAPI* theData)
@@ -101,6 +103,24 @@ QList<QWidget*> ModuleBase_WidgetPointInput::getControls() const
   return aList;
 }
 
+std::string getParmText(ModuleBase_ParamSpinBox* theSpin, FeaturePtr& theParam)
+{
+  QString aText = theSpin->text();
+  if (aText.contains('=')) {
+    if (!theParam.get()) {
+      theParam = ModuleBase_Tools::createParameter(aText);
+      if (!theParam.get()) {
+        return ERR_STRING;
+      }
+    }
+    else {
+      ModuleBase_Tools::editParameter(theParam, aText);
+    }
+    aText = aText.split('=').at(0);
+  }
+  return aText.toStdString();
+}
+
 //********************************************************************
 bool ModuleBase_WidgetPointInput::storeValueCustom()
 {
@@ -108,8 +128,28 @@ bool ModuleBase_WidgetPointInput::storeValueCustom()
   if (aAttr.get()) {
     if (aAttr->isInitialized()) {
       if (myXSpin->hasVariable() || myYSpin->hasVariable() || myZSpin->hasVariable()) {
-        aAttr->setText(myXSpin->text().toStdString(),
-          myYSpin->text().toStdString(), myZSpin->text().toStdString());
+        std::string aXText = getParmText(myXSpin, myXParam);
+        if (aXText == ERR_STRING) {
+          aAttr->setExpressionError(0, "Parameter cannot be created");
+          aAttr->setExpressionInvalid(0, true);
+          updateObject(myFeature);
+          return false;
+        }
+        std::string aYText = getParmText(myYSpin, myYParam);
+        if (aYText == ERR_STRING) {
+          aAttr->setExpressionError(1, "Parameter cannot be created");
+          aAttr->setExpressionInvalid(1, true);
+          updateObject(myFeature);
+          return false;
+        }
+        std::string aZText = getParmText(myZSpin, myZParam);
+        if (aZText == ERR_STRING) {
+          aAttr->setExpressionError(2, "Parameter cannot be created");
+          aAttr->setExpressionInvalid(2, true);
+          updateObject(myFeature);
+          return false;
+        }
+        aAttr->setText(aXText, aYText, aZText);
       } else {
         aAttr->setValue(myXSpin->value(), myYSpin->value(), myZSpin->value());
       }
@@ -126,24 +166,35 @@ bool ModuleBase_WidgetPointInput::storeValueCustom()
 bool ModuleBase_WidgetPointInput::restoreValueCustom()
 {
   AttributePointPtr aAttr = std::dynamic_pointer_cast<GeomDataAPI_Point>(attribute());
-  if (aAttr.get() && aAttr->isInitialized()) {
-    std::string aXText = aAttr->textX();
-    if (aXText.empty()) {
-      myXSpin->setValue(aAttr->x());
-    } else {
-      myXSpin->setText(aXText.c_str());
-    }
-    std::string aYText = aAttr->textY();
-    if (aYText.empty()) {
-      myYSpin->setValue(aAttr->y());
-    } else {
-      myYSpin->setText(aYText.c_str());
+  if (aAttr.get()) {
+    if (aAttr->isInitialized()) {
+      std::string aXText = aAttr->textX();
+      if (aXText.empty()) {
+        myXSpin->setValue(aAttr->x());
+      }
+      else {
+        myXSpin->setText(aXText.c_str());
+      }
+      std::string aYText = aAttr->textY();
+      if (aYText.empty()) {
+        myYSpin->setValue(aAttr->y());
+      }
+      else {
+        myYSpin->setText(aYText.c_str());
+      }
+      std::string aZText = aAttr->textZ();
+      if (aZText.empty()) {
+        myZSpin->setValue(aAttr->z());
+      }
+      else {
+        myZSpin->setText(aZText.c_str());
+      }
     }
-    std::string aZText = aAttr->textZ();
-    if (aZText.empty()) {
-      myZSpin->setValue(aAttr->z());
-    } else {
-      myZSpin->setText(aZText.c_str());
+    else {
+      aAttr->setValue(myDefaultValue[0], myDefaultValue[1], myDefaultValue[2]);
+      myXSpin->setValue(myDefaultValue[0]);
+      myYSpin->setValue(myDefaultValue[1]);
+      myZSpin->setValue(myDefaultValue[2]);
     }
     return true;
   }
@@ -167,16 +218,29 @@ QIntList ModuleBase_WidgetPointInput::shapeTypes() const
 
 //********************************************************************
 bool ModuleBase_WidgetPointInput
-::setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs)
+::setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
+  const bool theToValidate)
 {
-  GeomShapePtr aShape = thePrs->shape();
-  if (aShape->isVertex()) {
-    GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape));
-    GeomPointPtr aPnt = aVertex->point();
-    myXSpin->setValue(aPnt->x());
-    myYSpin->setValue(aPnt->y());
-    myZSpin->setValue(aPnt->z());
-    return true;
+  if (theValues.size() == 1) {
+    GeomShapePtr aShape = theValues.first()->shape();
+    if (aShape.get() && aShape->isVertex()) {
+      GeomVertexPtr aVertex(new GeomAPI_Vertex(aShape));
+      GeomPointPtr aPnt = aVertex->point();
+      myXSpin->setValue(aPnt->x());
+      myYSpin->setValue(aPnt->y());
+      myZSpin->setValue(aPnt->z());
+      return true;
+    }
   }
   return false;
 }
+
+//********************************************************************
+bool ModuleBase_WidgetPointInput::processEnter()
+{
+  bool isModified = getValueState() == ModifiedInPP;
+  if (isModified) {
+    emit valuesChanged();
+  }
+  return isModified;
+}