From 38268b12fad44d04c0c1fe2260d7297a885a183a Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Wed, 20 May 2020 14:09:41 +0300 Subject: [PATCH] Issue #3240: Angular Copy is not possible for projected entity Fix validator related to copy features: additional check if the original feature is already a copy after an other operation. --- src/SketchPlugin/CMakeLists.txt | 1 + src/SketchPlugin/SketchPlugin_Validators.cpp | 18 +++++++- src/SketchPlugin/Test/Test3240.py | 46 ++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/SketchPlugin/Test/Test3240.py diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index 2fd61c769..01aa67fd8 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -224,6 +224,7 @@ ADD_UNIT_TESTS( Test3132.py Test3154.py Test3170.py + Test3240.py Test19089.py Test19101.py TestArcBehavior.py diff --git a/src/SketchPlugin/SketchPlugin_Validators.cpp b/src/SketchPlugin/SketchPlugin_Validators.cpp index 22c0d2fe1..86411bf3f 100644 --- a/src/SketchPlugin/SketchPlugin_Validators.cpp +++ b/src/SketchPlugin/SketchPlugin_Validators.cpp @@ -1784,7 +1784,23 @@ bool SketchPlugin_ReplicationReferenceValidator::isValid( AttributeRefListPtr aRefList = aMultiFeature->reflist(theArguments.front()); for (int i = 0; i < aRefList->size(); ++i) { - FeaturePtr aRefOwner = ModelAPI_Feature::feature(aRefList->object(i)); + ObjectPtr aCurObj = aRefList->object(i); + // First of all, check if the current object is referred twice or more by the constraint. + // In this case, it mentions the object is original and placed to the copied entities too. + // It might be passed through. + int aNbRefs = 0; + const std::set& aRefs = aCurObj->data()->refsToMe(); + for (std::set::const_iterator aRIt = aRefs.begin(); + aRIt != aRefs.end(); ++aRIt) { + FeaturePtr anOwner = ModelAPI_Feature::feature((*aRIt)->owner()); + if (anOwner == aMultiFeature) + ++aNbRefs; + } + if (aNbRefs > 1) + continue; + + // check the referred feature is in the list of copies + FeaturePtr aRefOwner = ModelAPI_Feature::feature(aCurObj); if (aRefOwner == anAttrOwnerFeature) { theError = "Attribute refers to the object generated by this feature"; diff --git a/src/SketchPlugin/Test/Test3240.py b/src/SketchPlugin/Test/Test3240.py new file mode 100644 index 000000000..c6b0a2971 --- /dev/null +++ b/src/SketchPlugin/Test/Test3240.py @@ -0,0 +1,46 @@ +# 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 GeomAPI import * +from SketchAPI import * + +from salome.shaper import model + +ORIGIN = GeomAPI_Pnt(0, 0, 0) +NB_COPIES = 8 +TOLERANCE = 1.e-7 + +model.begin() +partSet = model.moduleDocument() +Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY")) +SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "OX"), True) +SketchLine_1 = SketchProjection_1.createdFeature() +SketchMultiRotation_1 = Sketch_1.addRotation([SketchLine_1.result()], SketchAPI_Line(SketchLine_1).startPoint(), 360, NB_COPIES, True) +[SketchLine_1, SketchLine_2, SketchLine_3, SketchLine_4, SketchLine_5, SketchLine_6, SketchLine_7, SketchLine_8] = SketchMultiRotation_1.rotated() +model.do() +model.end() + +model.testNbResults(Sketch_1, 1) +model.testNbSubShapes(Sketch_1, GeomAPI_Shape.EDGE, [NB_COPIES]) +model.testNbSubShapes(Sketch_1, GeomAPI_Shape.VERTEX, [2 * NB_COPIES]) + +midPnt = Sketch_1.defaultResult().shape().middlePoint() +assert(midPnt.distance(ORIGIN) < TOLERANCE) + +assert(model.checkPythonDump()) -- 2.39.2