]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
authorazv <azv@opencascade.com>
Thu, 3 Oct 2019 07:56:22 +0000 (10:56 +0300)
committerazv <azv@opencascade.com>
Thu, 3 Oct 2019 07:57:18 +0000 (10:57 +0300)
Improve constraint Middle point on elliptic arc.

src/GeomAPI/GeomAPI.i
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/plugin-Sketch.xml
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp
src/SketchSolver/SketchSolver_ConstraintMiddle.cpp

index 56ab015a7362fe37d094886783b38a1164553c7c..4c4110155cfe305b7d424d90bc1b9dfd97648cb4 100644 (file)
   }
 }
 
+%typemap(in) double & (double temp) {
+  if (PyLong_Check($input)) {
+    temp = PyLong_AsLong($input);
+    $1 = &temp;
+  }
+}
+
+%typemap(argout) double & {
+  $result = PyFloat_FromDouble(*$1);
+}
+
 
 // all supported interfaces
 %include "GeomAPI_Interface.h"
index 46a3581146295dfc7617f22fca40a4f7096cf547..1a255e57e054247afb33338ac225a8f10a539b48 100644 (file)
@@ -771,7 +771,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;
     }
   }
index 69d6a1c71d70637290c81fc64e633db4ef402e9a..3db87cbf20aca4c7094b5c0788fd52b6e1564673 100644 (file)
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
           <validator id="SketchPlugin_PerpendicularAttr" parameters="ConstraintEntityB"/>
-          <validator id="GeomValidators_ShapeType" parameters="line,circle"/>
+          <validator id="GeomValidators_ShapeType" parameters="edge"/>
         </sketch_shape_selector>
 
         <sketch_shape_selector id="ConstraintEntityB"
           <validator id="PartSet_DifferentObjects"/>
           <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
           <validator id="SketchPlugin_PerpendicularAttr" parameters="ConstraintEntityA"/>
-          <validator id="GeomValidators_ShapeType" parameters="line,circle"/>
+          <validator id="GeomValidators_ShapeType" parameters="edge"/>
         </sketch_shape_selector>
         <validator id="PartSet_PerpendicularSelection"/>
       </feature>
index 7f416c66b289c62c89b881cac373959e52f111a3..ccc07b05b128905710d2e2b264f15649fdc61445 100644 (file)
@@ -464,6 +464,27 @@ ConstraintWrapperPtr createConstraintPointsCollinear(
       new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_ON_CURVE));
 }
 
+template <typename ARCTYPE>
+void createConstraintMiddlePointOnArc(ARCTYPE theArc,
+                                      GCSPointPtr thePoint,
+                                      std::shared_ptr<PlaneGCSSolver_PointWrapper> theAuxParameters,
+                                      std::list<GCSConstraintPtr>& theConstraints)
+{
+  double* u = theAuxParameters->point()->x;
+  double* diff = theAuxParameters->point()->y;
+  *u = (*theArc->startAngle + *theArc->endAngle) * 0.5;
+  *diff = (*theArc->endAngle - *theArc->startAngle) * 0.5;
+
+  theConstraints.push_back(GCSConstraintPtr(
+      new GCS::ConstraintCurveValue(*thePoint, thePoint->x, *theArc, u)));
+  theConstraints.push_back(GCSConstraintPtr(
+      new GCS::ConstraintCurveValue(*thePoint, thePoint->y, *theArc, u)));
+  theConstraints.push_back(GCSConstraintPtr(
+      new GCS::ConstraintDifference(theArc->startAngle, u, diff)));
+  theConstraints.push_back(GCSConstraintPtr(
+      new GCS::ConstraintDifference(u, theArc->endAngle, diff)));
+}
+
 ConstraintWrapperPtr createConstraintMiddlePoint(
     std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
     std::shared_ptr<PlaneGCSSolver_EdgeWrapper> theEntity,
@@ -480,20 +501,13 @@ ConstraintWrapperPtr createConstraintMiddlePoint(
   }
   else {
     std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(theEntity->entity());
-    if (anArc) {
-      double* u = theAuxParameters->point()->x;
-      double* diff = theAuxParameters->point()->y;
-      *u = (*anArc->startAngle + *anArc->endAngle) * 0.5;
-      *diff = (*anArc->endAngle - *anArc->startAngle) * 0.5;
-
-      aConstrList.push_back(GCSConstraintPtr(
-          new GCS::ConstraintCurveValue(*aPoint, aPoint->x, *anArc, u)));
-      aConstrList.push_back(GCSConstraintPtr(
-          new GCS::ConstraintCurveValue(*aPoint, aPoint->y, *anArc, u)));
-      aConstrList.push_back(GCSConstraintPtr(
-          new GCS::ConstraintDifference(anArc->startAngle, u, diff)));
-      aConstrList.push_back(GCSConstraintPtr(
-          new GCS::ConstraintDifference(u, anArc->endAngle, diff)));
+    if (anArc)
+      createConstraintMiddlePointOnArc(anArc, aPoint, theAuxParameters, aConstrList);
+    else {
+      std::shared_ptr<GCS::ArcOfEllipse> aEllArc =
+          std::dynamic_pointer_cast<GCS::ArcOfEllipse>(theEntity->entity());
+      if (aEllArc)
+        createConstraintMiddlePointOnArc(aEllArc, aPoint, theAuxParameters, aConstrList);
     }
   }
 
index 15b8dc285240300051b3f31c671043bd78a58a5b..893747131c8025a66372d12b38bb231336a53ed8 100644 (file)
 #include <PlaneGCSSolver_Tools.h>
 #include <PlaneGCSSolver_UpdateCoincidence.h>
 
+static bool isArc(EntityWrapperPtr theEntity)
+{
+  return theEntity->type() == ENTITY_ARC || theEntity->type() == ENTITY_ELLIPTIC_ARC;
+}
+
 void SketchSolver_ConstraintMiddle::getAttributes(
     EntityWrapperPtr& theValue,
     std::vector<EntityWrapperPtr>& theAttributes)
@@ -32,7 +37,7 @@ void SketchSolver_ConstraintMiddle::getAttributes(
   SketchSolver_Constraint::getAttributes(theValue, theAttributes);
 
   // create auxiliary point if middle point on arc is specified
-  if (theAttributes[2]->type() == ENTITY_ARC) {
+  if (isArc(theAttributes[2])) {
     std::shared_ptr<PlaneGCSSolver_Storage> aStorage =
         std::dynamic_pointer_cast<PlaneGCSSolver_Storage>(myStorage);
 
@@ -65,16 +70,25 @@ void SketchSolver_ConstraintMiddle::notify(const FeaturePtr&      theFeature,
     // update the middle point parameter if the constraint is "point-on-arc".
     if (myOddPoint) {
       EntityWrapperPtr anArcEntity =
-          myAttributes.front()->type() == ENTITY_ARC ? myAttributes.front() : myAttributes.back();
+          isArc(myAttributes.front()) ? myAttributes.front() : myAttributes.back();
       EdgeWrapperPtr anArcEdge =
           std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(anArcEntity);
-      std::shared_ptr<GCS::Arc> anArc;
-      if (anArcEdge)
-        anArc = std::dynamic_pointer_cast<GCS::Arc>(anArcEdge->entity());
-      if (anArc) {
-        // recalculate parameters of middle point according to arc
-        *myOddPoint->x = (*anArc->startAngle + *anArc->endAngle) * 0.5;
-        *myOddPoint->y = (*anArc->endAngle - *anArc->startAngle) * 0.5;
+      if (anArcEdge) {
+        std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(anArcEdge->entity());
+        if (anArc) {
+          // recalculate parameters of middle point according to arc
+          *myOddPoint->x = (*anArc->startAngle + *anArc->endAngle) * 0.5;
+          *myOddPoint->y = (*anArc->endAngle - *anArc->startAngle) * 0.5;
+        }
+        else {
+          std::shared_ptr<GCS::ArcOfEllipse> aEllArc =
+              std::dynamic_pointer_cast<GCS::ArcOfEllipse>(anArcEdge->entity());
+          if (aEllArc) {
+            // recalculate parameters of middle point according to arc
+            *myOddPoint->x = (*aEllArc->startAngle + *aEllArc->endAngle) * 0.5;
+            *myOddPoint->y = (*aEllArc->endAngle - *aEllArc->startAngle) * 0.5;
+          }
+        }
       }
     }
     return;