From: azv Date: Thu, 30 Jan 2020 07:07:20 +0000 (+0300) Subject: Correct projection for periodic B-spline. Update unit tests. X-Git-Tag: V9_5_0a1~54^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e812429b9754c7750d3d62bc53145353f62d9acf;p=modules%2Fshaper.git Correct projection for periodic B-spline. Update unit tests. --- diff --git a/src/GeomAPI/GeomAPI_BSpline.cpp b/src/GeomAPI/GeomAPI_BSpline.cpp index f73076908..cb2aef956 100644 --- a/src/GeomAPI/GeomAPI_BSpline.cpp +++ b/src/GeomAPI/GeomAPI_BSpline.cpp @@ -71,3 +71,8 @@ std::list GeomAPI_BSpline::mults() const const TColStd_Array1OfInteger& aBSplMults = MY_BSPLINE->Multiplicities(); return std::list(aBSplMults.begin(), aBSplMults.end()); } + +bool GeomAPI_BSpline::isPeriodic() const +{ + return MY_BSPLINE->IsPeriodic(); +} diff --git a/src/GeomAPI/GeomAPI_BSpline.h b/src/GeomAPI/GeomAPI_BSpline.h index ae067d0fa..95468bec4 100644 --- a/src/GeomAPI/GeomAPI_BSpline.h +++ b/src/GeomAPI/GeomAPI_BSpline.h @@ -52,6 +52,9 @@ public: /// Multiplicities of B-spline knots GEOMAPI_EXPORT std::list mults() const; + + /// Return \c true if the curve is periodic + GEOMAPI_EXPORT bool isPeriodic() const; }; //! Pointer on the object diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 913b41b8b..d0f093813 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -218,8 +218,5 @@ template std::shared_ptr shared_ptr_cast(std::shared_ptr %template(PointList) std::list >; %template(PointSet) std::set >; -// Geometry casts -%template(shapeToEdge) shared_ptr_cast; - template std::shared_ptr shared_ptr_cast(std::shared_ptr theObject); %template(featureToPresentation) shared_ptr_cast; diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index ad38d9c55..ee47707e0 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -32,6 +32,7 @@ %include "doxyhelp.i" // import other modules +%import "GeomAPI.i" %import "ModelAPI.i" %import "ModelHighAPI.i" diff --git a/src/SketchPlugin/SketchPlugin_Projection.cpp b/src/SketchPlugin/SketchPlugin_Projection.cpp index e041299b0..e069a3567 100644 --- a/src/SketchPlugin/SketchPlugin_Projection.cpp +++ b/src/SketchPlugin/SketchPlugin_Projection.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -153,8 +154,10 @@ static const std::set& ARC_PROJECTION() static const std::set& BSPLINE_PROJECTION() { static std::set 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( diff --git a/src/SketchPlugin/Test/TestConstraintMiddlePointOnEllipticArc.py b/src/SketchPlugin/Test/TestConstraintMiddlePointOnEllipticArc.py index e9f4d35d4..dc741d409 100644 --- a/src/SketchPlugin/Test/TestConstraintMiddlePointOnEllipticArc.py +++ b/src/SketchPlugin/Test/TestConstraintMiddlePointOnEllipticArc.py @@ -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) diff --git a/src/SketchPlugin/Test/TestProjectionBSpline.py b/src/SketchPlugin/Test/TestProjectionBSpline.py index d053681db..8e651ba89 100644 --- a/src/SketchPlugin/Test/TestProjectionBSpline.py +++ b/src/SketchPlugin/Test/TestProjectionBSpline.py @@ -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)) diff --git a/src/SketchPlugin/Test/TestProjectionBSplinePeriodic.py b/src/SketchPlugin/Test/TestProjectionBSplinePeriodic.py index 2ebd6b173..30ae55182 100644 --- a/src/SketchPlugin/Test/TestProjectionBSplinePeriodic.py +++ b/src/SketchPlugin/Test/TestProjectionBSplinePeriodic.py @@ -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))