From 67309e00c16c3218177b8de1711e900b21a7735b Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Tue, 21 Jul 2020 11:36:51 +0300 Subject: [PATCH] Fix the projection of periodic B-spline curve to non-orthogonal plane. --- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/SketchPlugin_Validators.cpp | 2 +- .../TestProjectionBSplinePeriodicError.py | 62 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/SketchPlugin/Test/TestProjectionBSplinePeriodicError.py diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index d21adaf71..85715599a 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -335,6 +335,7 @@ ADD_UNIT_TESTS( TestProjection.py TestProjectionBSpline.py TestProjectionBSplinePeriodic.py + TestProjectionBSplinePeriodicError.py TestProjectionEllipse.py TestProjectionEllipticArc.py TestProjectionIntoResult.py diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 0ccd6ae4f..18c9f81c2 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1284,7 +1284,7 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, if (aBSplinePlane) { std::shared_ptr aBSplineNormal = aBSplinePlane->direction(); double aDot = fabs(aNormal->dot(aBSplineNormal)); - aValid = fabs(aDot - 1.0) <= tolerance * tolerance; + aValid = aDot > tolerance * tolerance; if (!aValid) { // B-spline's plane is orthogonal to the sketch plane, // thus, need to check whether B-spline is planar. diff --git a/src/SketchPlugin/Test/TestProjectionBSplinePeriodicError.py b/src/SketchPlugin/Test/TestProjectionBSplinePeriodicError.py new file mode 100644 index 000000000..9463efb9c --- /dev/null +++ b/src/SketchPlugin/Test/TestProjectionBSplinePeriodicError.py @@ -0,0 +1,62 @@ +# Copyright (C) 2020 CEA/DEN, EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() + +### Create Sketch +Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) + +### Create SketchBSpline +SketchBSpline_1_poles = [(39.56361839352194, -91.51890167437574), + (70.21199762078012, -72.31423451653721), + (42.28382694294977, -41.98350738641304), + (67.28504300461098, -31.5470157767404), + (50.62385917039768, -3.473688794131494), + (86.7958072325187, 15.01252243343181) + ] +SketchBSpline_1 = Sketch_1.addSpline(poles = SketchBSpline_1_poles) + +### Create SketchBSplinePeriodic +SketchBSplinePeriodic_1_poles = [(42.08285838974091, 63.92994506772382), + (45.90231280862586, 109.3628979208621), + (103.3091534085915, 74.17970450461429), + (80.27079545144119, 67.78674592116529), + (119.1440714423075, 30.71538726951938), + (57.61745686692009, 20.1653082760922) + ] +SketchBSplinePeriodic_1 = Sketch_1.addSpline(poles = SketchBSplinePeriodic_1_poles, periodic = True) +model.do() + +### Create Sketch +Sketch_2 = model.addSketch(partSet, model.defaultPlane("YOZ")) + +### Create SketchProjection +SketchProjection_1 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchBSpline_1"), True) +SketchBSpline_2 = SketchProjection_1.createdFeature() + +### Create SketchProjection +SketchProjection_2 = Sketch_2.addProjection(model.selection("EDGE", "Sketch_1/SketchBSplinePeriodic_1"), True) +model.do() +model.end() + +assert(SketchProjection_1.feature().error() == "") +assert(SketchProjection_2.feature().error() != "") -- 2.39.2