]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
ParametersPlugin_EvalListener::processEvent() and Model_Update::updateArguments(...
authorSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 26 May 2015 09:02:34 +0000 (12:02 +0300)
committerSergey POKHODENKO <sergey.pokhodenko@opencascade.com>
Tue, 26 May 2015 09:03:27 +0000 (12:03 +0300)
src/GeomDataAPI/GeomDataAPI_Point.h
src/GeomDataAPI/GeomDataAPI_Point2D.h
src/Model/Model_Update.cpp
src/ParametersPlugin/ParametersPlugin_EvalListener.cpp

index 61eaf4a6b842aa24e69d08b315d359a319670015..a940b62cbea33913db36ff33098a52b3ec202b1e 100644 (file)
@@ -70,4 +70,7 @@ class GeomDataAPI_Point : public ModelAPI_Attribute
   GEOMDATAAPI_EXPORT virtual ~GeomDataAPI_Point();
 };
 
+//! Pointer on attribute object
+typedef std::shared_ptr<GeomDataAPI_Point> AttributePointPtr;
+
 #endif
index 0dda71058060807a243a4691610b7fbe7b99467c..c693456a99f66b4636d43ff7665d9fcd758a7da4 100644 (file)
@@ -68,4 +68,7 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute
   GEOMDATAAPI_EXPORT virtual ~GeomDataAPI_Point2D();
 };
 
+//! Pointer on attribute object
+typedef std::shared_ptr<GeomDataAPI_Point2D> AttributePoint2DPtr;
+
 #endif
index 17f344c28ec1efebaaf735712eb95aee27871092..e710c5a876693c6ce87fee66ec6aa5769621e1a2 100644 (file)
@@ -23,6 +23,8 @@
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Point2D.h>
 #include <Events_Loop.h>
 #include <Events_LongOp.h>
 #include <Events_Error.h>
@@ -263,11 +265,12 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
   if (aState == ModelAPI_StateInvalidArgument) // a chance to be corrected
     aState = ModelAPI_StateMustBeUpdated;
   // check the parameters state
-  std::list<AttributePtr> aDoubles = 
-    theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId()); 
+  // Double
+  std::list<AttributePtr> aDoubles =
+    theFeature->data()->attributes(ModelAPI_AttributeDouble::typeId());
   std::list<AttributePtr>::iterator aDoubleIter = aDoubles.begin();
   for(; aDoubleIter != aDoubles.end(); aDoubleIter++) {
-    AttributeDoublePtr aDouble = 
+    AttributeDoublePtr aDouble =
       std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(*aDoubleIter);
     if (aDouble.get() && !aDouble->text().empty()) {
       if (aDouble->expressionInvalid()) {
@@ -275,6 +278,37 @@ void Model_Update::updateArguments(FeaturePtr theFeature) {
       }
     }
   }
+  // Point
+  {
+    std::list<AttributePtr> anAttributes =
+      theFeature->data()->attributes(GeomDataAPI_Point::typeId());
+    std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+    for(; anIter != anAttributes.end(); anIter++) {
+      AttributePointPtr aPointAttribute =
+        std::dynamic_pointer_cast<GeomDataAPI_Point>(*anIter);
+      if (aPointAttribute.get()) {
+        if ((!aPointAttribute->textX().empty() && aPointAttribute->expressionInvalid(0)) ||
+            (!aPointAttribute->textY().empty() && aPointAttribute->expressionInvalid(1)) ||
+            (!aPointAttribute->textZ().empty() && aPointAttribute->expressionInvalid(2)))
+          aState = ModelAPI_StateInvalidArgument;
+      }
+    }
+  }
+  // Point2D
+  {
+    std::list<AttributePtr> anAttributes =
+      theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+    std::list<AttributePtr>::iterator anIter = anAttributes.begin();
+    for(; anIter != anAttributes.end(); anIter++) {
+      AttributePoint2DPtr aPoint2DAttribute =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIter);
+      if (aPoint2DAttribute.get()) {
+        if ((!aPoint2DAttribute->textX().empty() && aPoint2DAttribute->expressionInvalid(0)) ||
+            (!aPoint2DAttribute->textY().empty() && aPoint2DAttribute->expressionInvalid(1)))
+          aState = ModelAPI_StateInvalidArgument;
+      }
+    }
+  }
 
   //if (aState == ModelAPI_StateDone) {// all referenced objects are ready to be used
     //std::cout<<"Execute feature "<<theFeature->getKind()<<std::endl;
index 8fa3af26d26559638dbb739d7d1cbdfbf4c483a5..a8aa64e89f1fa4187716f3a9f70df807283f3bc9 100644 (file)
@@ -12,6 +12,8 @@
 #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 +41,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()) {
@@ -51,6 +55,54 @@ void ParametersPlugin_EvalListener::processEvent(const std::shared_ptr<Events_Me
         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());