Salome HOME
Issue #17347: B-Splines in Sketcher
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Validators.cpp
index 46a3581146295dfc7617f22fca40a4f7096cf547..cf8d1ca4a65a7b2fc421b5ec8a8955178ed9fca3 100644 (file)
@@ -65,7 +65,9 @@
 #include <GeomAPI_Lin.h>
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Vertex.h>
+
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point2DArray.h>
 
 #include <algorithm>
 #include <cmath>
@@ -771,7 +773,8 @@ bool SketchPlugin_MiddlePointAttrValidator::isValid(const AttributePtr& theAttri
       if (aFeature->getKind() == SketchPlugin_Point::ID())
         ++aNbPoints;
       else if (aFeature->getKind() == SketchPlugin_Line::ID() ||
-               aFeature->getKind() == SketchPlugin_Arc::ID())
+               aFeature->getKind() == SketchPlugin_Arc::ID() ||
+               aFeature->getKind() == SketchPlugin_EllipticArc::ID())
         ++aNbLines;
     }
   }
@@ -870,7 +873,7 @@ bool SketchPlugin_ArcTransversalPointValidator::isValid(
     }
   }
   else {
-    theError = "Unable to build transversal arc on %1";
+    theError = "Unable to build perpendicular arc on %1";
     theError.arg(anAttrFeature->getKind());
     return false;
   }
@@ -945,8 +948,16 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
   }
   AttributeReferencePtr aFeatureAttr =
             std::dynamic_pointer_cast<ModelAPI_AttributeReference>(theAttribute);
+  std::shared_ptr<SketchPlugin_Feature> aSplitFeature =
+    std::dynamic_pointer_cast<SketchPlugin_Feature>(theAttribute->owner());
 
   ObjectPtr anAttrObject = aFeatureAttr->value();
+  if (!anAttrObject) {
+    AttributePtr aPreviewAttr = aSplitFeature->attribute(SketchPlugin_Trim::PREVIEW_OBJECT());
+    aFeatureAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(aPreviewAttr);
+    anAttrObject = aFeatureAttr->value();
+  }
+
   FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttrObject);
   if (!anAttrFeature)
     return aValid;
@@ -1114,38 +1125,35 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
   std::shared_ptr<GeomAPI_Dir> aNormal = aPlane->direction();
   std::shared_ptr<GeomAPI_Pnt> anOrigin = aPlane->location();
 
+  bool aValid = true;
   if (anEdge->isLine()) {
     std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
     std::shared_ptr<GeomAPI_Dir> aLineDir = aLine->direction();
     double aDot = fabs(aNormal->dot(aLineDir));
-    bool aValid = fabs(aDot - 1.0) >= tolerance * tolerance;
+    aValid = fabs(aDot - 1.0) >= tolerance * tolerance;
     if (!aValid)
       theError = "Error: Line is orthogonal to the sketch plane.";
-    return aValid;
   }
   else if (anEdge->isCircle() || anEdge->isArc()) {
     std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
     std::shared_ptr<GeomAPI_Dir> aCircNormal = aCircle->normal();
     double aDot = fabs(aNormal->dot(aCircNormal));
-    bool aValid = aDot >= tolerance * tolerance;
+    aValid = aDot >= tolerance * tolerance;
     if (!aValid)
       theError.arg(anEdge->isCircle() ? "Error: Circle is orthogonal to the sketch plane."
                                       : "Error: Arc is orthogonal to the sketch plane.");
-    return aValid;
   }
   else if (anEdge->isEllipse()) {
     std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
     std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
     double aDot = fabs(aNormal->dot(anEllipseNormal));
-    bool aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
+    aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
     if (!aValid)
       theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
                                       : "Error: Elliptic Arc is orthogonal to the sketch plane.");
-    return aValid;
   }
 
-  theError = "Error: Selected object is not supported for projection.";
-  return false;
+  return aValid;
 }
 
 
@@ -1770,3 +1778,20 @@ bool SketchPlugin_MultiRotationAngleValidator::isValid(const AttributePtr& theAt
 
   return true;
 }
+
+bool SketchPlugin_BSplineValidator::isValid(const AttributePtr& theAttribute,
+                                            const std::list<std::string>& theArguments,
+                                            Events_InfoMessage& theError) const
+{
+  AttributePoint2DArrayPtr aPolesArray =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
+  if (!aPolesArray)
+    return false;
+
+  if (aPolesArray->size() < 2) {
+    theError = "Number of B-spline poles should be 2 and more";
+    return false;
+  }
+
+  return true;
+}