Salome HOME
Using shape selected for sketcher
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_EvalListener.cpp
index ff05cd51027ccdcd8c5a95ee0ed2b7cfe392c386..968c167696992d9599da1d20a57756b88352eff9 100644 (file)
@@ -5,13 +5,18 @@
  *      Author: sbh
  */
 
+#include <pyconfig.h>
+
 #include <ParametersPlugin_EvalListener.h>
+#include <ParametersPlugin_PyInterp.h>
 
 #include <Events_Error.h>
 
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeDouble.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
 
 #include <string>
 #include <sstream>
@@ -39,6 +44,8 @@ void ParametersPlugin_EvalListener::processEvent(const std::shared_ptr<Events_Me
   if (theMessage->eventID() == kEvaluationEvent) {
     std::shared_ptr<ModelAPI_AttributeEvalMessage> aMessage =
         std::dynamic_pointer_cast<ModelAPI_AttributeEvalMessage>(theMessage);
+
+    // Double
     AttributeDoublePtr aDoubleAttribute =
         std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aMessage->attribute());
     if (aDoubleAttribute.get()) {
@@ -46,8 +53,59 @@ void ParametersPlugin_EvalListener::processEvent(const std::shared_ptr<Events_Me
       double aValue = evaluate(aDoubleAttribute->text(), anError);
       if (anError.empty()) {
         aDoubleAttribute->setValue(aValue);
+        aDoubleAttribute->setExpressionInvalid(false);
+      } else { // set feature as invalid-parameter arguments
+        aDoubleAttribute->setExpressionInvalid(true);
       }
     }
+
+    // Point
+    AttributePointPtr aPointAttribute =
+        std::dynamic_pointer_cast<GeomDataAPI_Point>(aMessage->attribute());
+    if (aPointAttribute.get()) {
+      std::string anError[3];
+      double aValue[3] = {
+          evaluate(aPointAttribute->textX(), anError[0]),
+          evaluate(aPointAttribute->textY(), anError[1]),
+          evaluate(aPointAttribute->textZ(), anError[2])
+      };
+      bool isValid[3] = {
+          anError[0].empty(),
+          anError[1].empty(),
+          anError[2].empty()
+      };
+      aPointAttribute->setExpressionInvalid(0, !isValid[0]);
+      aPointAttribute->setExpressionInvalid(1, !isValid[1]);
+      aPointAttribute->setExpressionInvalid(2, !isValid[2]);
+
+      aPointAttribute->setValue(
+          isValid[0] ? aValue[0] : aPointAttribute->x(),
+          isValid[1] ? aValue[1] : aPointAttribute->y(),
+          isValid[2] ? aValue[2] : aPointAttribute->z()
+      );
+    }
+
+    // Point2D
+    AttributePoint2DPtr aPoint2DAttribute =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aMessage->attribute());
+    if (aPoint2DAttribute.get()) {
+      std::string anError[2];
+      double aValue[2] = {
+          evaluate(aPoint2DAttribute->textX(), anError[0]),
+          evaluate(aPoint2DAttribute->textY(), anError[1])
+      };
+      bool isValid[2] = {
+          anError[0].empty(),
+          anError[1].empty()
+      };
+      aPoint2DAttribute->setExpressionInvalid(0, !isValid[0]);
+      aPoint2DAttribute->setExpressionInvalid(1, !isValid[1]);
+
+      aPoint2DAttribute->setValue(
+          isValid[0] ? aValue[0] : aPoint2DAttribute->x(),
+          isValid[1] ? aValue[1] : aPoint2DAttribute->y()
+      );
+    }
   } else {
     Events_Error::send(std::string("ParametersPlugin python interpreter, unhandled message caught: ")
                        + theMessage->eventID().eventText());
@@ -63,7 +121,8 @@ double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression,
   std::list<std::string>::iterator it = anExprParams.begin();
   for ( ; it != anExprParams.end(); it++) {
     double aValue;
-    if (!ModelAPI_Tools::findVariable(*it, aValue)) continue;
+    ResultParameterPtr aParamRes;
+    if (!ModelAPI_Tools::findVariable(*it, aValue, aParamRes)) continue;
 
     std::ostringstream sstream;
     sstream << aValue;
@@ -75,4 +134,3 @@ double ParametersPlugin_EvalListener::evaluate(const std::string& theExpression,
   myInterp->clearLocalContext();
   return result;
 }
-