Salome HOME
Task #3230: Sketcher: create a curve passing through selected points or vertices...
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index 22c0d2fe16da2e632babd286fee65c9613e571ec..4a6cc4b256d0ea557a979cac748e9c108e6eb94d 100644 (file)
@@ -31,6 +31,7 @@
 #include "SketchPlugin_Ellipse.h"
 #include "SketchPlugin_EllipticArc.h"
 #include "SketchPlugin_Fillet.h"
+#include "SketchPlugin_CurveFitting.h"
 #include "SketchPlugin_Line.h"
 #include "SketchPlugin_MacroArc.h"
 #include "SketchPlugin_MacroCircle.h"
@@ -49,6 +50,7 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefAttrList.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
@@ -1893,3 +1895,22 @@ bool SketchPlugin_BSplineValidator::isValid(const AttributePtr& theAttribute,
 
   return true;
 }
+
+bool SketchPlugin_CurveFittingValidator::isValid(const FeaturePtr& theFeature,
+                                                 const std::list<std::string>& theArguments,
+                                                 Events_InfoMessage& theError) const
+{
+  AttributeRefAttrListPtr aRefAttrList =
+      theFeature->refattrlist(SketchPlugin_CurveFitting::POINTS_ID());
+  AttributeBooleanPtr aPeriodicAttr =
+      theFeature->boolean(SketchPlugin_CurveFitting::PERIODIC_ID());
+
+  // check number of selected entities
+  int aMinNbPoints = aPeriodicAttr->value() ? 3 : 2;
+  if (aRefAttrList->size() < aMinNbPoints) {
+    theError = "Not enough points selected. Need at least %1 points.";
+    theError.arg(aMinNbPoints);
+    return false;
+  }
+  return true;
+}