Salome HOME
Merge branch 'master' into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index 43186329b9ea56e7f6e811899bfb4c2bea1b06b5..ca7df854dcdf26bcbf700b5da88ef40ad542951e 100644 (file)
@@ -8,56 +8,82 @@
 #include "SketchPlugin_ConstraintDistance.h"
 #include <ModelAPI_Data.h>
 #include <ModelAPI_Validator.h>
-#include <ModelAPI_ResultValidator.h>
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_Session.h>
+
+#include <GeomValidators_Edge.h>
+
 #include <GeomDataAPI_Point2D.h>
 
-bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
-                                                 const std::list<std::string>& theArguments,
-                                                 const ObjectPtr& theObject,
-                                                 const GeomShapePtr& theShape) const
+bool SketchPlugin_DistanceAttrValidator::isValid(
+  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+//bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
+//                                                 const std::list<std::string>& theArguments,
+//                                                 const ObjectPtr& theObject,
+//                                                 const GeomShapePtr& theShape) const
+// ======= end of todo master
 {
+  // there is a check whether the feature contains a point and a linear edge or two point values
   std::string aParamA = theArguments.front();
   SessionPtr aMgr = ModelAPI_Session::get();
   ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
 
-  const ModelAPI_ResultValidator* anArcValidator =
-      dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
-  bool anArcValid = anArcValidator->isValid(theObject);
-  if (anArcValid)
+  AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+  if (!aRefAttr)
     return false;
 
-
-  // If the object is not a line then it is accepted
-  const ModelAPI_ResultValidator* aLineValidator =
-      dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
-  bool aLineValid = aLineValidator->isValid(theObject);
-  if (!aLineValid)
+  bool isObject = aRefAttr->isObject();
+  if (!isObject) {
+    // an attribute is a point. A point value is valid always for the distance
     return true;
+  } else {
+    // 1. check whether the references object is a linear
+    ObjectPtr anObject = aRefAttr->object();
 
-  // If it is a line then we have to check that first attribute id not a line
-  std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(theFeature->data(), aParamA);
-  if (aPoint)
-    return true;
-  return false;
-}
+    const ModelAPI_AttributeValidator* anEdgeValidator = 
+      dynamic_cast<const GeomValidators_Edge*>(aFactory->validator("GeomValidators_Edge"));
+    std::list<std::string> anArguments;
+    anArguments.push_back("circle");
+    bool anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+    // the circle line is not a valid case
+    if (anEdgeValid)
+      return false;
+      
+    anArguments.clear();
+    anArguments.push_back("line");
+    anEdgeValid = anEdgeValidator->isValid(aRefAttr, anArguments);
+    // if the attribute value is not a line, that means it is a vertex. A vertex is always valid
+    if (!anEdgeValid)
+      return true;
 
-bool SketchPlugin_DistanceAttrValidator::isValid(
-  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
-{
-  // any point attribute is acceptable for the distance operation
-  return true;
+    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+    // If it is a line then we have to check that first attribute id not a line
+    std::shared_ptr<GeomDataAPI_Point2D> aPoint = getFeaturePoint(aFeature->data(), aParamA);
+    if (aPoint)
+      return true;
+  }
+  return false;
 }
+// TODO(nds) v1.0.2, master
+//  return false;
+//}
 
-bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
-                                                 const std::list<std::string>& theArguments,
-                                                 const AttributePtr& theAttribute) const
-{
-  return isValid(theAttribute, theArguments);
-}
+//bool SketchPlugin_DistanceAttrValidator::isValid(
+//  const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+//{
+//  // any point attribute is acceptable for the distance operation
+//  return true;
+//}
+//
+//bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
+//                                                 const std::list<std::string>& theArguments,
+//                                                 const AttributePtr& theAttribute) const
+//{
+//  return isValid(theAttribute, theArguments);
+//}
 
+// commented in v1.0.2, master:
 //bool SketchPlugin_DifferentObjectsValidator::isValid(const FeaturePtr& theFeature,
 //                                                 const std::list<std::string>& theArguments,
 //                                                 const ObjectPtr& theObject) const
@@ -119,3 +145,4 @@ bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
 //  }
 //  return true;
 //}
+// =========== end of todo