Salome HOME
Merge branch 'master' into Dev_1.1.0
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index e69dce246f6b1ff333720f7bca8b8716dfcb474e..ca7df854dcdf26bcbf700b5da88ef40ad542951e 100644 (file)
@@ -8,14 +8,21 @@
 #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 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();
@@ -33,20 +40,24 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   } else {
     // 1. check whether the references object is a linear
     ObjectPtr anObject = aRefAttr->object();
-    const ModelAPI_ResultValidator* anArcValidator =
-        dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultArc"));
-    bool anArcValid = anArcValidator->isValid(anObject);
-    if (anArcValid)
-      return false;
 
-    // If the object is not a line then it is accepted. It can be a point feature selected
-    const ModelAPI_ResultValidator* aLineValidator =
-        dynamic_cast<const ModelAPI_ResultValidator*>(aFactory->validator("SketchPlugin_ResultLine"));
-    bool aLineValid = aLineValidator->isValid(anObject);
-    if (!aLineValid)
+    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;
-    FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
 
+    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)
@@ -54,13 +65,31 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
   }
   return false;
 }
+// TODO(nds) v1.0.2, master
+//  return false;
+//}
+
+//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
 //{
 //  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
 //  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
 //  for(; anAttr != anAttrs.end(); anAttr++) {
 //    if (*anAttr) {
@@ -84,7 +113,7 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
 //    const FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
 //
 //    std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-//      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+//      aFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
 //    std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
 //    for(; anAttr != anAttrs.end(); anAttr++) {
 //      if (*anAttr && *anAttr != theAttribute) {
@@ -103,7 +132,7 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
 //  const std::list<std::string>& theArguments, const AttributePtr& theAttribute) const
 //{
 //  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttrs = 
-//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
+//    theFeature->data()->attributes(ModelAPI_AttributeRefAttr::typeId());
 //  std::list<std::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
 //  for(; anAttr != anAttrs.end(); anAttr++) {
 //    if (*anAttr) {
@@ -116,3 +145,4 @@ bool SketchPlugin_DistanceAttrValidator::isValid(
 //  }
 //  return true;
 //}
+// =========== end of todo