From db8f718d668d5b1d12f02633eed48888a7ec8026 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 9 Feb 2018 09:22:08 +0300 Subject: [PATCH] Issue #2440: Can't validate coincidence between a line and an imported line Fix validator for SketchPlugin_Projection feature --- src/SketchPlugin/CMakeLists.txt | 13 +++- src/SketchPlugin/SketchPlugin_Validators.cpp | 20 +++--- src/SketchPlugin/Test/Data/profile_top.brep | 67 ++++++++++++++++++++ src/SketchPlugin/Test/Test2440.py | 61 ++++++++++++++++++ 4 files changed, 148 insertions(+), 13 deletions(-) create mode 100644 src/SketchPlugin/Test/Data/profile_top.brep create mode 100644 src/SketchPlugin/Test/Test2440.py diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index e459746f4..cc169af86 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -234,6 +234,7 @@ ADD_UNIT_TESTS(TestSketchPointLine.py Test2390.py Test2393.py Test2425.py + Test2440.py ) if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE}) @@ -244,4 +245,14 @@ if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE}) TestMoveArc.py TestMovementComplex.py ) -endif() \ No newline at end of file +endif() + +# Copy data-files to corresponding directory +file(GLOB DATA_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Test/Data/*") +foreach(data_file ${DATA_FILES}) + get_filename_component(data_file_name "${data_file}" NAME) + configure_file( + ${data_file} + ${CMAKE_CURRENT_BINARY_DIR}/Data/${data_file_name} + COPYONLY) +endforeach() diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index c95474a55..31d7069da 100755 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -983,10 +983,15 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, if (aFeatureAttr.get()) { GeomShapePtr aVal = aFeatureAttr->value(); ResultPtr aRes = aFeatureAttr->context(); - if(aVal && aVal->isEdge()) { + if (aVal && aVal->isVertex()) + return true; // vertex is always could be projected + if (aVal && aVal->isEdge()) { anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->value())); - } else if(aRes && aRes->shape() && aRes->shape()->isEdge()) { - anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->context()->shape())); + } else if(aRes && aRes->shape()) { + if (aRes->shape()->isVertex()) + return true; // vertex is always could be projected + else if (aRes->shape()->isEdge()) + anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->context()->shape())); } // try to convert result to sketch feature @@ -996,15 +1001,6 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, } } if (!anEdge) { - // check a vertex has been selected - if (aFeatureAttr->value() && aFeatureAttr->value()->isVertex()) - return true; - else { - ResultPtr aRes = aFeatureAttr->context(); - if (aRes && aRes->shape() && aRes->shape()->isVertex()) - return true; - } - theError = "The attribute %1 should be an edge or vertex"; theError.arg(theAttribute->id()); return false; diff --git a/src/SketchPlugin/Test/Data/profile_top.brep b/src/SketchPlugin/Test/Data/profile_top.brep new file mode 100644 index 000000000..3123af524 --- /dev/null +++ b/src/SketchPlugin/Test/Data/profile_top.brep @@ -0,0 +1,67 @@ +DBRep_DrawableShape + +CASCADE Topology V1, (c) Matra-Datavision +Locations 4 +1 + 1 0 0 -0.01125 + 0 1 0 -0 + 0 0 1 -0 +2 1 -1 0 +1 + 1 0 0 0.0225 + 0 1 0 0 + 0 0 1 0 +2 3 -1 1 -1 0 +Curve2ds 2 +1 0 0 1 0 +1 0 -0.022499999999999999 1 0 +Curves 1 +7 0 0 3 7 5 0 -0.022669999999999999 0 0 -0.021815557636274709 0.014608004531572693 0 -0.019166614578016675 0.11480793967161977 0 -0.052234626031663213 0.27403640738417173 0 -0.029241794404817344 0.4425674715597312 -0 -0.023085133924901934 0.52561556816365695 0 -0.021499999999999998 0.54920000000000002 + 0 4 0.043814574059324145 1 0.30070049737938465 1 0.47963546768983012 1 0.55060889652062572 4 +Polygon3D 0 +PolygonOnTriangulations 3 +7 2 10 11 12 13 14 4 +p 0.0021968008 1 0 0.0698166666765063 0.162905555578515 0.261861491070186 0.333306643376888 0.441957769948757 0.550608896520626 +7 1 5 6 7 8 9 3 +p 0.0021968008 1 0 0.0698166666765063 0.162905555578515 0.261861491070186 0.333306643376888 0.441957769948757 0.550608896520626 +7 1 3 4 5 6 7 2 +p 0.0021968008 1 0 0.0698166666765063 0.162905555578515 0.261861491070186 0.333306643376888 0.441957769948757 0.550608896520626 +Surfaces 1 +6 -1 -0 -0 +7 0 0 3 7 5 -0.01125 -0.022669999999999999 0 -0.01125 -0.021815557636274709 0.014608004531572693 -0.01125 -0.019166614578016675 0.11480793967161977 -0.01125 -0.052234626031663213 0.27403640738417173 -0.01125 -0.029241794404817344 0.4425674715597312 -0.01125 -0.023085133924901934 0.52561556816365695 -0.01125 -0.021499999999999998 0.54920000000000002 + 0 4 0.043814574059324145 1 0.30070049737938465 1 0.47963546768983012 1 0.55060889652062572 4 +Triangulations 2 +14 12 1 0.000913647973975481 +-0.01125 -0.02267 0 0.01125 -0.02267 0 -0.01125 -0.0215 0.5492 0.01125 -0.0215 0.5492 -0.01125 -0.0222254068482293 0.0697712335447645 -0.01125 -0.0300174368624765 0.162646115013907 -0.01125 -0.0390495259163521 0.26128471362926 -0.01125 -0.03968333413702 0.332509875161595 -0.01125 -0.0307003401042035 0.440866903854042 0.01125 -0.0222254068482293 0.0697712335447645 0.01125 -0.0300174368624765 0.162646115013907 0.01125 -0.0390495259163521 0.26128471362926 0.01125 -0.03968333413702 0.332509875161595 0.01125 -0.0307003401042035 0.440866903854042 0 0 0 -0.0225 0.550608896520626 0 0.550608896520626 -0.0225 0.0698166666765063 0 0.162905555578515 0 0.261861491070186 0 0.333306643376888 0 0.441957769948757 0 0.0698166666765063 -0.0225 0.162905555578515 -0.0225 0.261861491070186 -0.0225 0.333306643376888 -0.0225 0.441957769948757 -0.0225 5 1 2 5 2 10 6 10 11 6 5 10 7 11 12 7 6 11 8 12 13 8 7 12 9 13 14 9 8 13 3 14 4 3 9 14 +9 7 1 1.21430643318376e-17 +0 -0.02267 0 0 -0.0215 0.5492 0 -0.0222254068482293 0.0697712335447645 0 -0.0300174368624765 0.162646115013907 0 -0.0390495259163521 0.26128471362926 0 -0.03968333413702 0.332509875161595 0 -0.0307003401042035 0.440866903854042 0 0 0.5492 0 0 0 0.274238197758496 0.00672017236285403 -0.274961802241504 0.00555017236285403 0.204466964213732 0.00627557921108332 0.111592082744589 0.0140676092253305 0.0129534841292356 0.0230996982792062 -0.0582716774030992 0.023733506499874 -0.166628706095546 0.0147505124670575 -0.274961802241504 -0.015949827637146 0.274238197758496 -0.015949827637146 7 2 8 6 7 8 5 6 8 4 5 8 9 3 4 9 4 8 1 3 9 + +TShapes 3 +Ve +1e-07 +0 -0.02267 0 +0 0 + +0101101 +* +Ve +1e-07 +0 -0.0215 0.5492 +0 0 + +0101101 +* +Ed + 1e-07 1 1 0 +1 1 0 0 0.550608896520626 +2 1 1 2 0 0.550608896520626 +2 2 1 4 0 0.550608896520626 +6 1 1 4 +6 2 1 2 +6 3 2 0 +0 + +0101000 ++3 0 -2 0 * + ++1 0 \ No newline at end of file diff --git a/src/SketchPlugin/Test/Test2440.py b/src/SketchPlugin/Test/Test2440.py new file mode 100644 index 000000000..0a0ba1bb1 --- /dev/null +++ b/src/SketchPlugin/Test/Test2440.py @@ -0,0 +1,61 @@ +## Copyright (C) 2018-20xx 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 +## + +""" + Test2440.py + Test case for issue #2440 "Can't validate coincidence between a line and an imported line" +""" + + +from SketchAPI import * + +from salome.shaper import model + +from math import fabs + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Import_1 = model.addImport(Part_1_doc, "Data/profile_top.brep") +model.do() +Import_1.setName("profile_top") +Import_1.result().setName("profile_top_1") + +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("YOZ")) +SketchLine_1 = Sketch_1.addLine(-0.5, 0, -0.1, 0.5) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "profile_top_1/Shape2"), False) +SketchPoint_1 = SketchProjection_1.createdFeature() +model.do() + +assert(SketchProjection_1.feature().error() == "") + +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchAPI_Point(SketchPoint_1).coordinates()) +model.do() + +assert(SketchConstraintCoincidence_1.feature().error() == "") +assert(Sketch_1.feature().error() == "") +assert(Sketch_1.solverError().value() == "") + +REF_POINT = [-0.0215, 0.5492] +TOLERANCE = 1.e-7 +assert(fabs(SketchLine_1.endPoint().x() - REF_POINT[0]) < TOLERANCE and fabs(SketchLine_1.endPoint().y() - REF_POINT[1]) < TOLERANCE) + +model.end() -- 2.39.2