From: Artem Zhidkov Date: Sun, 17 May 2020 20:35:53 +0000 (+0300) Subject: Issue 19101: Sketch in error when running a dumped study X-Git-Tag: V9_5_0b1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8b79c317cdb6ae12c8f16c2c9ac0067fdc066478;p=modules%2Fshaper.git Issue 19101: Sketch in error when running a dumped study Eliminate projection of a point lying in the same sketch. --- diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 23e34d4d5..0a4a01218 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -227,6 +227,7 @@ ADD_UNIT_TESTS( Test3154.py Test3170.py Test19089.py + Test19101.py TestArcBehavior.py TestBSplineAddPole.py TestChangeSketchPlane1.py diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index b4463445b..d6c7d5d93 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1161,20 +1161,21 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, AttributeSelectionPtr aFeatureAttr = std::dynamic_pointer_cast(theAttribute); + std::shared_ptr aVertex; std::shared_ptr anEdge; std::shared_ptr aSketchFeature; if (aFeatureAttr.get()) { GeomShapePtr aVal = aFeatureAttr->value(); ResultPtr aRes = aFeatureAttr->context(); 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())); + aVertex = std::shared_ptr(new GeomAPI_Vertex(aVal)); + else if (aVal && aVal->isEdge()) { + anEdge = std::shared_ptr(new GeomAPI_Edge(aVal)); } else if(aRes && aRes->shape()) { if (aRes->shape()->isVertex()) - return true; // vertex is always could be projected + aVertex = std::shared_ptr(new GeomAPI_Vertex(aRes->shape())); else if (aRes->shape()->isEdge()) - anEdge = std::shared_ptr(new GeomAPI_Edge(aFeatureAttr->context()->shape())); + anEdge = std::shared_ptr(new GeomAPI_Edge(aRes->shape())); } // try to convert result to sketch feature @@ -1183,7 +1184,7 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, std::dynamic_pointer_cast(ModelAPI_Feature::feature(aRes)); } } - if (!anEdge) { + if (!aVertex && !anEdge) { theError = "The attribute %1 should be an edge or vertex"; theError.arg(theAttribute->id()); return false; @@ -1215,7 +1216,9 @@ bool SketchPlugin_ProjectionValidator::isValid(const AttributePtr& theAttribute, std::shared_ptr anOrigin = aPlane->location(); bool aValid = true; - if (anEdge->isLine()) { + if (aVertex) + aValid = true; // vertex is always could be projected + else if (anEdge->isLine()) { std::shared_ptr aLine = anEdge->line(); std::shared_ptr aLineDir = aLine->direction(); double aDot = fabs(aNormal->dot(aLineDir)); diff --git a/src/SketchPlugin/Test/Test19101.py b/src/SketchPlugin/Test/Test19101.py new file mode 100644 index 000000000..a44bbc8b9 --- /dev/null +++ b/src/SketchPlugin/Test/Test19101.py @@ -0,0 +1,44 @@ +# 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() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +Box_1 = model.addBox(Part_1_doc, 10, 10, 10) +Sketch_1 = model.addSketch(Part_1_doc, model.selection("FACE", "Box_1_1/Top")) +SketchLine_1 = Sketch_1.addLine(3.455185109181585, 2.504529791754867, 6.714574768930328, 7.155950452021305) +SketchProjection_1 = Sketch_1.addProjection(model.selection("VERTEX", "[Box_1_1/Front][Box_1_1/Right][Box_1_1/Top]"), True) +SketchPoint_1 = SketchProjection_1.createdFeature() +SketchProjection_2 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Left][Box_1_1/Top]"), True) +SketchLine_2 = SketchProjection_2.createdFeature() +SketchProjection_3 = Sketch_1.addProjection(model.selection("EDGE", "Sketch_1/SketchLine_1"), True) +SketchProjection_4 = Sketch_1.addProjection(model.selection("VERTEX", "Sketch_1/SketchLine_1_EndVertex"), True) +model.do() + +model.end() + +from ModelAPI import * +validators = ModelAPI_Session.get().validators() +assert(validators.validate(SketchProjection_1.feature())) +assert(validators.validate(SketchProjection_2.feature())) +assert(not validators.validate(SketchProjection_3.feature())) +assert(not validators.validate(SketchProjection_4.feature()))