Salome HOME
Issue #3240: Angular Copy is not possible for projected entity
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Wed, 20 May 2020 11:09:41 +0000 (14:09 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Wed, 20 May 2020 11:09:41 +0000 (14:09 +0300)
Fix validator related to copy features: additional check if the original feature is already a copy after an other operation.

src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Validators.cpp
src/SketchPlugin/Test/Test3240.py [new file with mode: 0644]

index 2fd61c769831fd2a9bec753533de269865831f54..01aa67fd842c4a2c85ae14dc911e57a4e12ad30c 100644 (file)
@@ -224,6 +224,7 @@ ADD_UNIT_TESTS(
   Test3132.py
   Test3154.py
   Test3170.py
+  Test3240.py
   Test19089.py
   Test19101.py
   TestArcBehavior.py
index 22c0d2fe16da2e632babd286fee65c9613e571ec..86411bf3f335464f1f0819df4b9b6a5f3b95b79c 100644 (file)
@@ -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<AttributePtr>& aRefs = aCurObj->data()->refsToMe();
+    for (std::set<AttributePtr>::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 (file)
index 0000000..c6b0a29
--- /dev/null
@@ -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())