Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
authorazv <azv@opencascade.com>
Mon, 30 Sep 2019 12:43:54 +0000 (15:43 +0300)
committerazv <azv@opencascade.com>
Tue, 1 Oct 2019 09:01:57 +0000 (12:01 +0300)
Projection of elliptic arcs

src/GeomAPI/GeomAPI_Circ.cpp
src/GeomAPI/GeomAPI_Curve.cpp
src/GeomAPI/GeomAPI_Curve.h
src/GeomAPI/GeomAPI_Ellipse.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Projection.h
src/SketchPlugin/SketchPlugin_Projection.cpp
src/SketchPlugin/SketchPlugin_Projection.h
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/Test/TestProjectionEllipse.py

index facc1ec2a970ac4315c08bbc01f8fa8465e292f3..a3bb8d97a7833ebababfa3a4888bf1bca79b157f 100644 (file)
@@ -58,7 +58,8 @@ GeomAPI_Circ::GeomAPI_Circ(const std::shared_ptr<GeomAPI_Pnt>& theCenter,
 //=================================================================================================
 GeomAPI_Circ::GeomAPI_Circ(const GeomCurvePtr& theCurve)
 {
-  Handle(Geom_Curve) aCurve = theCurve->impl<Handle(Geom_Curve)>();
+  GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
+  Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
   Handle(Geom_Circle) aCirc = Handle(Geom_Circle)::DownCast(aCurve);
   if (aCirc.IsNull())
     throw Standard_ConstructionError("GeomAPI_Circ: Curve is not a circle");
index dd3c57c27c6ab4fa25e7dfd0f3c2f31f063b47b5..fb5f034ab3df1e0a5601c534f88465ed45ab3f61 100644 (file)
@@ -35,7 +35,9 @@
 #define MY_CURVE (*(implPtr<Handle_Geom_Curve>()))
 
 GeomAPI_Curve::GeomAPI_Curve()
-    : GeomAPI_Interface(new Handle_Geom_Curve()), myStart(0), myEnd(1)
+    : GeomAPI_Interface(new Handle_Geom_Curve()),
+      myStart(-Precision::Infinite()),
+      myEnd(Precision::Infinite())
 {
 }
 
@@ -47,6 +49,8 @@ GeomAPI_Curve::GeomAPI_Curve(const std::shared_ptr<GeomAPI_Shape>& theShape)
   if (!anEdge.IsNull()) {
     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, myStart, myEnd);
     if (!aCurve.IsNull()) {
+      if (!BRep_Tool::IsClosed(anEdge))
+        aCurve = new Geom_TrimmedCurve(aCurve, myStart, myEnd);
       setImpl(new Handle(Geom_Curve)(aCurve));
     }
   }
@@ -57,19 +61,53 @@ bool GeomAPI_Curve::isNull() const
   return MY_CURVE.IsNull() == Standard_True;
 }
 
+static bool isCurveType(const Handle(Geom_Curve)& theCurve, const Handle(Standard_Type)& theType)
+{
+  if (theCurve.IsNull())
+    return false;
+  Handle(Geom_Curve) aCurve = theCurve;
+  if (aCurve->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve))
+    aCurve = Handle(Geom_TrimmedCurve)::DownCast(aCurve)->BasisCurve();
+  return aCurve->DynamicType() == theType;
+}
+
 bool GeomAPI_Curve::isLine() const
 {
-  return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Line);
+  return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Line));
 }
 
 bool GeomAPI_Curve::isCircle() const
 {
-  return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
+  return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Circle));
 }
 
 bool GeomAPI_Curve::isEllipse() const
 {
-  return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Ellipse);
+  return isCurveType(MY_CURVE, STANDARD_TYPE(Geom_Ellipse));
+}
+
+double GeomAPI_Curve::startParam()
+{
+  if (Precision::IsInfinite(myStart)) {
+    if (isTrimmed()) {
+      myStart = Handle(Geom_TrimmedCurve)::DownCast(MY_CURVE)->FirstParameter();
+    }
+    else if (MY_CURVE->IsClosed() && MY_CURVE->IsPeriodic())
+      myStart = 0.0;
+  }
+  return myStart;
+}
+
+double GeomAPI_Curve::endParam()
+{
+  if (Precision::IsInfinite(myEnd)) {
+    if (isTrimmed()) {
+      myEnd = Handle(Geom_TrimmedCurve)::DownCast(MY_CURVE)->LastParameter();
+    }
+    else if (MY_CURVE->IsClosed() && MY_CURVE->IsPeriodic())
+      myEnd = MY_CURVE->Period();
+  }
+  return myEnd;
 }
 
 std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
index 5cdf1db89d6bd08a52897158de8e77200c75b611..3922217f1deb3c0ac52eccabdd75048c6eb35b3b 100644 (file)
@@ -63,11 +63,11 @@ class GeomAPI_Curve : public GeomAPI_Interface
 
   /// Returns start parameter of the curve
   GEOMAPI_EXPORT
-  double startParam() const { return myStart; }
+  double startParam();
 
   /// Returns end parameter of the curve
   GEOMAPI_EXPORT
-  double endParam() const { return myEnd; }
+  double endParam();
 
   /// Returns \c true if the curve is trimmed
   GEOMAPI_EXPORT
index 86a0391cb87990d1406ba34be886cb46b8666644..75a25477cf7474d90e148a6f8412a52696d697a8 100644 (file)
@@ -41,7 +41,8 @@ GeomAPI_Ellipse::GeomAPI_Ellipse(const std::shared_ptr<GeomAPI_Ax2>& theAx2,
 
 GeomAPI_Ellipse::GeomAPI_Ellipse(GeomCurvePtr theCurve)
 {
-  Handle(Geom_Curve) aCurve = theCurve->impl<Handle(Geom_Curve)>();
+  GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
+  Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
   Handle(Geom_Ellipse) anEllipse = Handle(Geom_Ellipse)::DownCast(aCurve);
   if (anEllipse.IsNull())
     throw Standard_ConstructionError("GeomAPI_Ellipse: Curve is not an ellipse");
index 5ffde637143fe0516e7a4d83a990049bdb6e18e9..4aeca665b58a3f44f213d73191ae53d5150e582b 100644 (file)
@@ -33,14 +33,16 @@ class GeomAPI_Edge;
  * \ingroup DataAlgo
  * \brief Project curve onto a plane
  */
-class GEOMALGOAPI_EXPORT GeomAlgoAPI_Projection
+class GeomAlgoAPI_Projection
 {
 public:
-  GeomAlgoAPI_Projection(const std::shared_ptr<GeomAPI_Pln>& thePlane);
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Projection(const std::shared_ptr<GeomAPI_Pln>& thePlane);
 
   /// Project curve to the plane
+  GEOMALGOAPI_EXPORT
   std::shared_ptr<GeomAPI_Curve> project(const std::shared_ptr<GeomAPI_Curve>& theCurve);
   /// Project edge to the plane
+  GEOMALGOAPI_EXPORT
   std::shared_ptr<GeomAPI_Curve> project(const std::shared_ptr<GeomAPI_Edge>& theEdge);
 
 private:
index c0d555059e4317001adbc9ea7f675d3bb983acc3..79eb675ca240ca273480dd8d6d4c92ed3b8f08d9 100644 (file)
@@ -22,6 +22,7 @@
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Ellipse.h>
+#include <SketchPlugin_EllipticArc.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Point.h>
 #include <SketchPlugin_Sketch.h>
@@ -104,22 +105,59 @@ void SketchPlugin_Projection::attributeChanged(const std::string& theID)
   }
 }
 
-static const std::string& projectionType(GeomEdgePtr theEdge,
-                                         GeomVertexPtr theVertex)
+static const std::set<std::string>& POINT_PROJECTION()
+{
+  static std::set<std::string> aProj;
+  if (aProj.empty())
+    aProj.insert(SketchPlugin_Point::ID());
+  return aProj;
+}
+
+static const std::set<std::string>& LINE_PROJECTION()
+{
+  static std::set<std::string> aProj;
+  if (aProj.empty())
+    aProj.insert(SketchPlugin_Line::ID());
+  return aProj;
+}
+
+static const std::set<std::string>& CIRCLE_ELLIPSE_PROJECTION()
+{
+  static std::set<std::string> aProj;
+  if (aProj.empty()) {
+    aProj.insert(SketchPlugin_Circle::ID());
+    aProj.insert(SketchPlugin_Ellipse::ID());
+  }
+  return aProj;
+}
+
+static const std::set<std::string>& ARC_PROJECTION()
+{
+  static std::set<std::string> aProj;
+  if (aProj.empty()) {
+    aProj.insert(SketchPlugin_Arc::ID());
+    aProj.insert(SketchPlugin_EllipticArc::ID());
+  }
+  return aProj;
+}
+
+
+static const std::set<std::string>& possibleProjectionTypes(GeomEdgePtr theEdge,
+                                                            GeomVertexPtr theVertex)
 {
   if (theVertex)
-    return SketchPlugin_Point::ID();
+    return POINT_PROJECTION();
   if (theEdge) {
     if (theEdge->isLine())
-      return SketchPlugin_Line::ID();
-    else if (theEdge->isCircle())
-      return SketchPlugin_Circle::ID();
-    else if (theEdge->isArc())
-      return SketchPlugin_Arc::ID();
-    else if (theEdge->isEllipse())
-      return SketchPlugin_Ellipse::ID();
+      return LINE_PROJECTION();
+    else if (theEdge->isCircle() || theEdge->isArc() || theEdge->isEllipse()) {
+      if (theEdge->isClosed())
+        return CIRCLE_ELLIPSE_PROJECTION();
+      else
+        return ARC_PROJECTION();
+    }
   }
-  static const std::string DUMMY;
+  static const std::set<std::string> DUMMY;
   return DUMMY;
 }
 
@@ -144,7 +182,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
   if (!anEdge && !aVertex)
     return;
 
-  const std::string& aProjType = projectionType(anEdge, aVertex);
+  const std::set<std::string>& aProjType = possibleProjectionTypes(anEdge, aVertex);
 
   AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
   FeaturePtr aProjection;
@@ -152,7 +190,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     aProjection = ModelAPI_Feature::feature(aRefAttr->object());
 
   // if the type of feature differs with already selected, remove it and create once again
-  bool isRebuild = rebuildProjectedFeature(aProjection, aProjType, true);
+  bool isRebuild = rebuildProjectedFeature(aProjection, aProjType);
 
   std::shared_ptr<GeomAPI_Pln> aSketchPlane = sketch()->plane();
 
@@ -170,7 +208,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     std::shared_ptr<GeomAPI_Pnt> aPrjPnt = aSketchPlane->project(aVertex->point());
     std::shared_ptr<GeomAPI_Pnt2d> aPntInSketch = sketch()->to2D(aPrjPnt);
 
-    rebuildProjectedFeature(aProjection, SketchPlugin_Point::ID());
+    rebuildProjectedFeature(aProjection, POINT_PROJECTION(), SketchPlugin_Point::ID());
 
     // update coordinates of projection
     std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
@@ -185,7 +223,7 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     if (aFirstInSketch->distance(aLastInSketch) < tolerance)
       return; // line is semi-orthogonal to the sketch plane
 
-    rebuildProjectedFeature(aProjection, SketchPlugin_Line::ID());
+    rebuildProjectedFeature(aProjection, LINE_PROJECTION(), SketchPlugin_Line::ID());
 
     // update attributes of projection
     std::shared_ptr<GeomDataAPI_Point2D> aStartPnt = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
@@ -195,84 +233,127 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
     aStartPnt->setValue(aFirstInSketch);
     aEndPnt->setValue(aLastInSketch);
   }
-  else if (anEdge->isCircle() || anEdge->isEllipse()) {
+  else if (anEdge->isCircle() || anEdge->isArc() || anEdge->isEllipse()) {
     GeomAlgoAPI_Projection aProjAlgo(aSketchPlane);
     GeomCurvePtr aProjectedCurve = aProjAlgo.project(anEdge);
 
     if (aProjectedCurve->isCircle()) {
-      rebuildProjectedFeature(aProjection, SketchPlugin_Circle::ID());
-
       GeomAPI_Circ aCircle(aProjectedCurve);
-      std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(aCircle.center());
-      std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
-
-      // update attributes of projection
-      std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
-          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-          aProjection->attribute(SketchPlugin_Circle::CENTER_ID()));
-      aCenterPnt->setValue(aCenterInSketch);
-      aProjection->real(SketchPlugin_Circle::RADIUS_ID())->setValue(aCircle.radius());
+      GeomPointPtr aCenter = aSketchPlane->project(aCircle.center());
+      GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
+
+      if (aProjectedCurve->isTrimmed()) {
+        // ARC is a projection
+        rebuildProjectedFeature(aProjection, ARC_PROJECTION(), SketchPlugin_Arc::ID());
+
+        GeomPointPtr aFirst = aProjectedCurve->getPoint(aProjectedCurve->startParam());
+        GeomPointPtr aLast = aProjectedCurve->getPoint(aProjectedCurve->endParam());
+        GeomPnt2dPtr aFirstInSketch = sketch()->to2D(aSketchPlane->project(aFirst));
+        GeomPnt2dPtr aLastInSketch = sketch()->to2D(aSketchPlane->project(aLast));
+
+        double aNormalsDot = aCircle.normal()->dot(aSketchPlane->direction());
+        if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
+          return; // arc is not in the plane, parallel to the sketch plane
+
+        bool isInversed = aNormalsDot < 0.;
+
+        bool aWasBlocked = aProjection->data()->blockSendAttributeUpdated(true);
+
+        // update attributes of projection
+        std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_Arc::CENTER_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_Arc::START_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_Arc::END_ID()));
+        aStartPnt->setValue(aFirstInSketch);
+        aEndPnt->setValue(aLastInSketch);
+        aCenterPnt->setValue(aCenterInSketch);
+        aProjection->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(isInversed);
+
+        aProjection->data()->blockSendAttributeUpdated(aWasBlocked);
+      }
+      else {
+        // CIRCLE is a projection
+        rebuildProjectedFeature(aProjection, CIRCLE_ELLIPSE_PROJECTION(),
+                                SketchPlugin_Circle::ID());
+
+        // update attributes of projection
+        std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_Circle::CENTER_ID()));
+        aCenterPnt->setValue(aCenterInSketch);
+        aProjection->real(SketchPlugin_Circle::RADIUS_ID())->setValue(aCircle.radius());
+      }
     }
     else if (aProjectedCurve->isEllipse()) {
-      rebuildProjectedFeature(aProjection, SketchPlugin_Ellipse::ID());
-
       GeomAPI_Ellipse anEllipse(aProjectedCurve);
-      std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(anEllipse.center());
-      std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
-      std::shared_ptr<GeomAPI_Pnt> aFocus = aSketchPlane->project(anEllipse.firstFocus());
-      std::shared_ptr<GeomAPI_Pnt2d> aFocusInSketch = sketch()->to2D(aFocus);
-
-      // update attributes of projection
-      std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
-          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-          aProjection->attribute(SketchPlugin_Ellipse::CENTER_ID()));
-      aCenterPnt->setValue(aCenterInSketch);
-      std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
-          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-          aProjection->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()));
-      aFocusPnt->setValue(aFocusInSketch);
-      aProjection->real(SketchPlugin_Ellipse::MINOR_RADIUS_ID())->setValue(
-          anEllipse.minorRadius());
+      GeomPointPtr aCenter = aSketchPlane->project(anEllipse.center());
+      GeomPnt2dPtr aCenterInSketch = sketch()->to2D(aCenter);
+      GeomPointPtr aFocus = aSketchPlane->project(anEllipse.firstFocus());
+      GeomPnt2dPtr aFocusInSketch = sketch()->to2D(aFocus);
+
+      if (aProjectedCurve->isTrimmed()) {
+        // ELLIPTIC ARC is a projection
+        rebuildProjectedFeature(aProjection, ARC_PROJECTION(), SketchPlugin_EllipticArc::ID());
+
+        GeomPointPtr aFirst = aProjectedCurve->getPoint(aProjectedCurve->startParam());
+        GeomPointPtr aLast = aProjectedCurve->getPoint(aProjectedCurve->endParam());
+        GeomPnt2dPtr aFirstInSketch = sketch()->to2D(aSketchPlane->project(aFirst));
+        GeomPnt2dPtr aLastInSketch = sketch()->to2D(aSketchPlane->project(aLast));
+
+        double aNormalsDot = anEllipse.normal()->dot(aSketchPlane->direction());
+        if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
+          return; // arc is not in the plane, parallel to the sketch plane
+
+        bool isInversed = aNormalsDot < 0.;
+
+        bool aWasBlocked = aProjection->data()->blockSendAttributeUpdated(true);
+
+        // update attributes of projection
+        std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_EllipticArc::CENTER_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_EllipticArc::FIRST_FOCUS_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_EllipticArc::START_POINT_ID()));
+        std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_EllipticArc::END_POINT_ID()));
+        aStartPnt->setValue(aFirstInSketch);
+        aEndPnt->setValue(aLastInSketch);
+        aCenterPnt->setValue(aCenterInSketch);
+        aFocusPnt->setValue(aFocusInSketch);
+        aProjection->boolean(SketchPlugin_EllipticArc::REVERSED_ID())->setValue(isInversed);
+
+        aProjection->data()->blockSendAttributeUpdated(aWasBlocked);
+      }
+      else {
+        // ELLIPSE is a projection
+        rebuildProjectedFeature(aProjection, CIRCLE_ELLIPSE_PROJECTION(),
+                                SketchPlugin_Ellipse::ID());
+
+        // update attributes of projection
+        std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_Ellipse::CENTER_ID()));
+        aCenterPnt->setValue(aCenterInSketch);
+        std::shared_ptr<GeomDataAPI_Point2D> aFocusPnt =
+            std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+            aProjection->attribute(SketchPlugin_Ellipse::FIRST_FOCUS_ID()));
+        aFocusPnt->setValue(aFocusInSketch);
+        aProjection->real(SketchPlugin_Ellipse::MINOR_RADIUS_ID())->setValue(
+            anEllipse.minorRadius());
+      }
     }
     else
       return;
-  }
-  else if (anEdge->isArc()) {
-    std::shared_ptr<GeomAPI_Pnt> aFirst = aSketchPlane->project(anEdge->firstPoint());
-    std::shared_ptr<GeomAPI_Pnt> aLast = aSketchPlane->project(anEdge->lastPoint());
-    std::shared_ptr<GeomAPI_Pnt2d> aFirstInSketch = sketch()->to2D(aFirst);
-    std::shared_ptr<GeomAPI_Pnt2d> aLastInSketch = sketch()->to2D(aLast);
-
-    std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
-    std::shared_ptr<GeomAPI_Pnt> aCenter = aSketchPlane->project(aCircle->center());
-    std::shared_ptr<GeomAPI_Pnt2d> aCenterInSketch = sketch()->to2D(aCenter);
-
-    double aNormalsDot = aCircle->normal()->dot(aSketchPlane->direction());
-    if (fabs(fabs(aNormalsDot) - 1.0) > tolerance)
-      return; // arc is not in the plane, parallel to the sketch plane
-
-    bool isInversed = aNormalsDot < 0.;
-
-    rebuildProjectedFeature(aProjection, SketchPlugin_Arc::ID());
-
-    bool aWasBlocked = aProjection->data()->blockSendAttributeUpdated(true);
-
-    // update attributes of projection
-    std::shared_ptr<GeomDataAPI_Point2D> aCenterPnt =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aProjection->attribute(SketchPlugin_Arc::CENTER_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aStartPnt =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aProjection->attribute(SketchPlugin_Arc::START_ID()));
-    std::shared_ptr<GeomDataAPI_Point2D> aEndPnt =
-      std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
-        aProjection->attribute(SketchPlugin_Arc::END_ID()));
-    aStartPnt->setValue(aFirstInSketch);
-    aEndPnt->setValue(aLastInSketch);
-    aCenterPnt->setValue(aCenterInSketch);
-    aProjection->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(isInversed);
-
-    aProjection->data()->blockSendAttributeUpdated(aWasBlocked);
   } else
     return;
 
@@ -294,12 +375,15 @@ void SketchPlugin_Projection::computeProjection(const std::string& theID)
   }
 }
 
-bool SketchPlugin_Projection::rebuildProjectedFeature(FeaturePtr& theProjection,
-                                                      const std::string& theResultType,
-                                                      bool theRemoveOnly)
+bool SketchPlugin_Projection::rebuildProjectedFeature(
+    FeaturePtr& theProjection,
+    const std::set<std::string>& theSupportedTypes,
+    const std::string& theRequestedFeature)
 {
   bool isRebuild = false;
-  if (theProjection && theProjection->getKind() != theResultType) {
+  if (theProjection &&
+      (theSupportedTypes.find(theProjection->getKind()) == theSupportedTypes.end() ||
+      (!theRequestedFeature.empty() && theProjection->getKind() != theRequestedFeature))) {
     DocumentPtr aDoc = sketch()->document();
 
     AttributeRefAttrPtr aRefAttr = data()->refattr(PROJECTED_FEATURE_ID());
@@ -312,7 +396,7 @@ bool SketchPlugin_Projection::rebuildProjectedFeature(FeaturePtr& theProjection,
     isRebuild = true;
   }
 
-  if (!theProjection && !theRemoveOnly)
-    theProjection = sketch()->addFeature(theResultType);
+  if (!theProjection && !theRequestedFeature.empty())
+    theProjection = sketch()->addFeature(theRequestedFeature);
   return isRebuild;
 }
index f62237608c6143d79ec07fad05648c43a9429f3c..40fd6301a6933faafea9675ea4c5b3d8a6a58e5c 100644 (file)
@@ -90,9 +90,13 @@ private:
 
   /// \brief Delete already calculated projected feature
   ///        if the selection of the projection is changed
+  /// \param[in/out] theProjection   projected feature
+  /// \param[in] theSupportedTypes   types supported relatively to the base selection
+  /// \param[in] theRequestedFeature type of the new feature to be created
+  ///                                (remove only if empty string).
   bool rebuildProjectedFeature(FeaturePtr& theProjection,
-                               const std::string& theResultType,
-                               bool theRemoveOnly = false);
+                               const std::set<std::string>& theSupportedTypes,
+                               const std::string& theRequestedFeature = std::string());
 
   bool myIsComputing;
 };
index 7f081fb0cef60b1017f7894f791797e7a0063dd5..46a3581146295dfc7617f22fca40a4f7096cf547 100644 (file)
@@ -1137,10 +1137,10 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute,
     std::shared_ptr<GeomAPI_Ellipse> anEllipse = anEdge->ellipse();
     std::shared_ptr<GeomAPI_Dir> anEllipseNormal = anEllipse->normal();
     double aDot = fabs(aNormal->dot(anEllipseNormal));
-    bool aValid = aDot >= tolerance * tolerance;
+    bool aValid = fabs(aDot - 1.0) <= tolerance * tolerance;
     if (!aValid)
-      theError.arg(anEdge->isEllipse() ? "Error: Ellipse is orthogonal to the sketch plane."
-                                       : "Error: Elliptic Arc is orthogonal to the sketch plane.");
+      theError.arg(anEdge->isClosed() ? "Error: Ellipse is orthogonal to the sketch plane."
+                                      : "Error: Elliptic Arc is orthogonal to the sketch plane.");
     return aValid;
   }
 
index 9dbaabc983f765f278ecf58c947326ea821e55a8..c6a97d98deeeb8f78f90ef45ca31ec69daaef110 100644 (file)
@@ -49,11 +49,12 @@ model.end()
 
 from GeomAPI import *
 
-circle2 = SketchCircle_2.results()[-1].resultSubShapePair()[0].shape()
-assert(circle2.isEdge() and circle2.edge().isCircle())
 ellipse1 = SketchEllipse_1.results()[-1].resultSubShapePair()[0].shape()
 assert(ellipse1.isEdge() and ellipse1.edge().isEllipse())
 ellipse2 = SketchEllipse_2.results()[-1].resultSubShapePair()[0].shape()
 assert(ellipse2.isEdge() and ellipse2.edge().isEllipse())
 
+# TODO [limitation]: projection of an ellipse to non-parallel plane is forbiden (OCCT issue #31016)
+assert(Sketch_2.feature().error() != "")
+
 assert(model.checkPythonDump())