Salome HOME
Correct projection for periodic B-spline. Update unit tests.
authorazv <azv@opencascade.com>
Thu, 30 Jan 2020 07:07:20 +0000 (10:07 +0300)
committerazv <azv@opencascade.com>
Thu, 30 Jan 2020 07:07:20 +0000 (10:07 +0300)
src/GeomAPI/GeomAPI_BSpline.cpp
src/GeomAPI/GeomAPI_BSpline.h
src/ModelAPI/ModelAPI.i
src/SketchAPI/SketchAPI.i
src/SketchPlugin/SketchPlugin_Projection.cpp
src/SketchPlugin/Test/TestConstraintMiddlePointOnEllipticArc.py
src/SketchPlugin/Test/TestProjectionBSpline.py
src/SketchPlugin/Test/TestProjectionBSplinePeriodic.py

index f7307690835b45ece06175665e56d8327e385a04..cb2aef956615926a3dc704c2ef10e3eb16ce8910 100644 (file)
@@ -71,3 +71,8 @@ std::list<int> GeomAPI_BSpline::mults() const
   const TColStd_Array1OfInteger& aBSplMults = MY_BSPLINE->Multiplicities();
   return std::list<int>(aBSplMults.begin(), aBSplMults.end());
 }
+
+bool GeomAPI_BSpline::isPeriodic() const
+{
+  return MY_BSPLINE->IsPeriodic();
+}
index ae067d0fad458886361e77e9fc7725e018153dee..95468bec452e447402013653e038af3e95fb636d 100644 (file)
@@ -52,6 +52,9 @@ public:
 
   /// Multiplicities of B-spline knots
   GEOMAPI_EXPORT std::list<int> mults() const;
+
+  /// Return \c true if the curve is periodic
+  GEOMAPI_EXPORT bool isPeriodic() const;
 };
 
 //! Pointer on the object
index 913b41b8bebc172ab07dbef5f135e83ab0ed2b4d..d0f093813b9a422003990c9a72319907b416b4b1 100644 (file)
@@ -218,8 +218,5 @@ template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr
 %template(PointList) std::list<std::shared_ptr<GeomAPI_Pnt> >;
 %template(PointSet) std::set<std::shared_ptr<GeomAPI_Pnt> >;
 
-// Geometry casts
-%template(shapeToEdge) shared_ptr_cast<GeomAPI_Edge, GeomAPI_Shape>;
-
 template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr<T2> theObject);
 %template(featureToPresentation) shared_ptr_cast<GeomAPI_IPresentable, ModelAPI_Feature>;
index ad38d9c556d450ac0124df660f948462689a5df3..ee47707e0042c6bf37a723c4d708c9a45e0764d9 100644 (file)
@@ -32,6 +32,7 @@
 %include "doxyhelp.i"
 
 // import other modules
+%import "GeomAPI.i"
 %import "ModelAPI.i"
 %import "ModelHighAPI.i"
 
index e041299b0c5b56a159e06529fa4b329b52a20264..e069a3567a2806864d22a508db7ac7ba0e91a16f 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_BSplinePeriodic.h>
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Ellipse.h>
 #include <SketchPlugin_EllipticArc.h>
@@ -153,8 +154,10 @@ static const std::set<std::string>& ARC_PROJECTION()
 static const std::set<std::string>& BSPLINE_PROJECTION()
 {
   static std::set<std::string> aProj;
-  if (aProj.empty())
+  if (aProj.empty()) {
     aProj.insert(SketchPlugin_BSpline::ID());
+    aProj.insert(SketchPlugin_BSplinePeriodic::ID());
+  }
   return aProj;
 }
 
@@ -495,10 +498,11 @@ bool SketchPlugin_Projection::fillBSpline(FeaturePtr& theProjection,
                                           const GeomCurvePtr& theCurve,
                                           const GeomPlanePtr& thePlane)
 {
-  rebuildProjectedFeature(theProjection, BSPLINE_PROJECTION(), SketchPlugin_BSpline::ID());
-
   GeomAPI_BSpline aBSpline(theCurve);
 
+  rebuildProjectedFeature(theProjection, BSPLINE_PROJECTION(),
+      aBSpline.isPeriodic() ? SketchPlugin_BSplinePeriodic::ID() : SketchPlugin_BSpline::ID());
+
   theProjection->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline.degree());
 
   AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(
index e9f4d35d4a70eae62d2d07df7b0a05eb7f582755..dc741d409691edcdd0ece73c532aed4098ca2cf7 100644 (file)
@@ -66,12 +66,12 @@ class TestMiddlePointOnEllipticArc(unittest.TestCase):
     self.checkPointOnEllipse(thePoint, anEllipse)
     # check angles
     TOLERANCE = 1.e-5
-    startAngle = 0; startPoint = GeomAPI_Pnt(theArc.startPoint().x(), theArc.startPoint().y(), 0)
-    startAngle = anEllipse.parameter(startPoint, TOLERANCE, startAngle)
-    endAngle = 0; endPoint = GeomAPI_Pnt(theArc.endPoint().x(), theArc.endPoint().y(), 0)
-    endAngle = anEllipse.parameter(endPoint, TOLERANCE, endAngle)
-    midAngle = 0; midPoint = GeomAPI_Pnt(thePoint.x(), thePoint.y(), 0)
-    midAngle = anEllipse.parameter(midPoint, TOLERANCE, midAngle)
+    startPoint = GeomAPI_Pnt(theArc.startPoint().x(), theArc.startPoint().y(), 0)
+    isCalculated, startAngle = anEllipse.parameter(startPoint, TOLERANCE)
+    endPoint = GeomAPI_Pnt(theArc.endPoint().x(), theArc.endPoint().y(), 0)
+    isCalculated, endAngle = anEllipse.parameter(endPoint, TOLERANCE)
+    midPoint = GeomAPI_Pnt(thePoint.x(), thePoint.y(), 0)
+    isCalculated, midAngle = anEllipse.parameter(midPoint, TOLERANCE)
     diffMS = self.toPeriod(midAngle - startAngle)
     diffEM = self.toPeriod(endAngle - midAngle)
     self.assertAlmostEqual(diffMS, diffEM)
index d053681db01b9ab1fd2f4bf07efe58f18b3114ed..8e651ba89e094626f5077bf413c94b1a60201f97 100644 (file)
@@ -23,26 +23,26 @@ model.begin()
 partSet = model.moduleDocument()
 Part_1 = model.addPart(partSet)
 Part_1_doc = Part_1.document()
-Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10, 180)
-Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Cylinder_1_1/Face_5"))
-SketchCircle_1 = Sketch_1.addCircle(-0.87355746875896, 7.873567272779828, 3.095312696967586)
-model.do()
-ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), [model.selection("SOLID", "Cylinder_1_1")])
-Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "ExtrusionCut_1_1")], model.selection("EDGE", "PartSet/OX"), 45)
-Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_1][(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_1)(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_5)(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_4)(Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_3)2]")], False)
+Point_2 = model.addPoint(Part_1_doc, -10, 5, 10)
+Point_3 = model.addPoint(Part_1_doc, -5, 10, 15)
+Point_4 = model.addPoint(Part_1_doc, 10, 0, 20)
+Point_5 = model.addPoint(Part_1_doc, 10, -10, 15)
+Point_6 = model.addPoint(Part_1_doc, -5, -5, 12)
+Interpolation_1_objects = [model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"), model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_4"), model.selection("VERTEX", "Point_5")]
+Interpolation_1 = model.addInterpolation(Part_1_doc, Interpolation_1_objects, False, False)
 
 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
-SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Edge_1_1"), True)
+SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Interpolation_1_1"), True)
 SketchBSpline_1 = SketchProjection_1.createdFeature()
 model.do()
 
 Sketch_3 = model.addSketch(Part_1_doc, model.standardPlane("XOZ"))
-SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "Edge_1_1"), True)
+SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "Interpolation_1_1"), True)
 SketchBSpline_2 = SketchProjection_2.createdFeature()
 model.do()
 
 Sketch_4 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
-SketchProjection_3 = Sketch_4.addProjection(model.selection("EDGE", "Edge_1_1"), True)
+SketchProjection_3 = Sketch_4.addProjection(model.selection("EDGE", "Interpolation_1_1"), True)
 SketchBSpline_3 = SketchProjection_3.createdFeature()
 model.do()
 
@@ -64,7 +64,7 @@ def checkProjection(theBSpline3D, theBSpline2D, theFlags):
                math.fabs((p2d.z() - p3d.z()) * theFlags.z()) < TOLERANCE)
 
 
-bspline0 = GeomAPI_BSpline(GeomAPI_Curve(Edge_1.results()[-1].resultSubShapePair()[0].shape()))
+bspline0 = GeomAPI_BSpline(GeomAPI_Curve(Interpolation_1.results()[-1].resultSubShapePair()[0].shape()))
 
 bsplineShape1 = SketchBSpline_1.results()[-1].resultSubShapePair()[0].shape()
 checkProjection(bspline0, bsplineShape1, GeomAPI_Pnt(1, 1, 0))
index 2ebd6b173629ad1755a9a81e407a3367b87ad3d4..30ae551825bac768b1d09396aed01374deadfeb9 100644 (file)
@@ -23,26 +23,26 @@ model.begin()
 partSet = model.moduleDocument()
 Part_1 = model.addPart(partSet)
 Part_1_doc = Part_1.document()
-Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10, 180)
-Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Cylinder_1_1/Face_5"))
-SketchCircle_1 = Sketch_1.addCircle(-0.9379111501048892, 5.54816019935757, 2.957303770750356)
-model.do()
-ExtrusionCut_1 = model.addExtrusionCut(Part_1_doc, [model.selection("FACE", "Sketch_1/Face-SketchCircle_1_2r")], model.selection(), [model.selection("SOLID", "Cylinder_1_1")])
-Rotation_1 = model.addRotation(Part_1_doc, [model.selection("SOLID", "ExtrusionCut_1_1")], model.selection("EDGE", "PartSet/OX"), 45)
-Edge_1 = model.addEdge(Part_1_doc, [model.selection("EDGE", "[Rotation_1_1/MF:Rotated&Cylinder_1_1/Face_1][Rotation_1_1/MF:Rotated&Sketch_1/SketchCircle_1_2]")], False)
+Point_2 = model.addPoint(Part_1_doc, -10, 5, 10)
+Point_3 = model.addPoint(Part_1_doc, -5, 10, 15)
+Point_4 = model.addPoint(Part_1_doc, 10, 0, 20)
+Point_5 = model.addPoint(Part_1_doc, 10, -10, 15)
+Point_6 = model.addPoint(Part_1_doc, -5, -5, 12)
+Interpolation_1_objects = [model.selection("VERTEX", "Point_1"), model.selection("VERTEX", "Point_2"), model.selection("VERTEX", "Point_3"), model.selection("VERTEX", "Point_4"), model.selection("VERTEX", "Point_5")]
+Interpolation_1 = model.addInterpolation(Part_1_doc, Interpolation_1_objects, True, False)
 
 Sketch_2 = model.addSketch(Part_1_doc, model.standardPlane("XOY"))
-SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Edge_1_1"), True)
+SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Interpolation_1_1"), True)
 SketchBSpline_1 = SketchProjection_1.createdFeature()
 model.do()
 
 Sketch_3 = model.addSketch(Part_1_doc, model.standardPlane("XOZ"))
-SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "Edge_1_1"), True)
+SketchProjection_2 = Sketch_3.addProjection(model.selection("EDGE", "Interpolation_1_1"), True)
 SketchBSpline_2 = SketchProjection_2.createdFeature()
 model.do()
 
 Sketch_4 = model.addSketch(Part_1_doc, model.standardPlane("YOZ"))
-SketchProjection_3 = Sketch_4.addProjection(model.selection("EDGE", "Edge_1_1"), True)
+SketchProjection_3 = Sketch_4.addProjection(model.selection("EDGE", "Interpolation_1_1"), True)
 SketchBSpline_3 = SketchProjection_3.createdFeature()
 model.do()
 
@@ -64,7 +64,7 @@ def checkProjection(theBSpline3D, theBSpline2D, theFlags):
                math.fabs((p2d.z() - p3d.z()) * theFlags.z()) < TOLERANCE)
 
 
-bspline0 = GeomAPI_BSpline(GeomAPI_Curve(Edge_1.results()[-1].resultSubShapePair()[0].shape()))
+bspline0 = GeomAPI_BSpline(GeomAPI_Curve(Interpolation_1.results()[-1].resultSubShapePair()[0].shape()))
 
 bsplineShape1 = SketchBSpline_1.results()[-1].resultSubShapePair()[0].shape()
 checkProjection(bspline0, bsplineShape1, GeomAPI_Pnt(1, 1, 0))