]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix the problem of the sketch plane update
authormpv <mpv@opencascade.com>
Tue, 22 Jan 2019 07:32:46 +0000 (10:32 +0300)
committermpv <mpv@opencascade.com>
Tue, 22 Jan 2019 07:32:46 +0000 (10:32 +0300)
src/Model/Model_Update.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/TestUpdateSketch.py [new file with mode: 0644]

index c4cbbc94247dce88769565cb91b5397c193826f5..db6fc41bc4115ab0bf14bd504be450872b6f399e 100755 (executable)
@@ -43,6 +43,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <GeomAPI_Shape.h>
 #include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
 #include <GeomDataAPI_Point2D.h>
 #include <Events_Loop.h>
 #include <Events_LongOp.h>
@@ -565,36 +566,46 @@ bool Model_Update::processFeature(FeaturePtr theFeature)
 
   // update the sketch plane before the sketch sub-elements are recomputed
   // (otherwise sketch will update plane, modify subs, after executed, but with old subs edges)
-  if (aIsModified && theFeature->getKind() == "Sketch") {
+    if (aIsModified && theFeature->getKind() == "Sketch") {
 #ifdef DEB_UPDATE
-    std::cout<<"****** Update sketch args "<<theFeature->name()<<std::endl;
+      std::cout << "****** Update sketch args " << theFeature->name() << std::endl;
 #endif
-    AttributeSelectionPtr anExtSel = theFeature->selection("External");
-    if (anExtSel.get()) {
-      ResultPtr aContext = anExtSel->context();
-      if (aContext.get() && aContext->document().get()) {
-        FeaturePtr anExtBase = aContext->document()->feature(aContext);
-        if (anExtBase.get()) {
-          processFeature(anExtBase);
+      AttributeSelectionPtr anExtSel = theFeature->selection("External");
+      if (anExtSel.get()) {
+        ResultPtr aContext = anExtSel->context();
+        if (aContext.get() && aContext->document().get()) {
+          FeaturePtr anExtBase = aContext->document()->feature(aContext);
+          if (anExtBase.get()) {
+            processFeature(anExtBase);
+          }
+          std::shared_ptr<GeomDataAPI_Point> anOrigin =
+            std::dynamic_pointer_cast<GeomDataAPI_Point>(theFeature->attribute("Origin"));
+          double anOX = anOrigin->x(), anOY = anOrigin->y(), anOZ = anOrigin->z();
+          std::shared_ptr<GeomDataAPI_Dir> aDir =
+            std::dynamic_pointer_cast<GeomDataAPI_Dir>(theFeature->attribute("DirX"));
+          double aDX = aDir->x(), aDY = aDir->y(), aDZ = aDir->z();
+          std::shared_ptr<GeomDataAPI_Dir> aNorm =
+            std::dynamic_pointer_cast<GeomDataAPI_Dir>(theFeature->attribute("Norm"));
+          double aNX = aNorm->x(), aNY = aNorm->y(), aNZ = aNorm->z();
+          // update sketch plane
+          updateArguments(theFeature);
+          //theFeature->attributeChanged("External"); // to recompute origin, direction and normal
+          // check it is updated, so all must be changed
+          if (anOrigin->x() != anOX || anOrigin->y() != anOY || anOrigin->z() != anOZ ||
+              aDir->x() != aDX || aDir->y() != aDY || aDir->z() != aDZ ||
+              aNorm->x() != aNX || aNorm->y() != aNY || aNorm->z() != aNZ)
+          {
+            std::set<FeaturePtr> aWholeR;
+            allReasons(theFeature, aWholeR);
+            std::set<FeaturePtr>::iterator aRIter = aWholeR.begin();
+            for (; aRIter != aWholeR.end(); aRIter++) {
+              if ((*aRIter)->data()->selection("External").get())
+                (*aRIter)->attributeChanged("External");
+            }
+          }
         }
       }
     }
-    std::shared_ptr<GeomAPI_Shape> aShapeBefore = anExtSel->value();
-    if (!aShapeBefore.get() && anExtSel->context()) aShapeBefore = anExtSel->context()->shape();
-    updateArguments(theFeature);
-    std::shared_ptr<GeomAPI_Shape> aShapeAfter = anExtSel->value();
-    if (!aShapeAfter.get() && anExtSel->context()) aShapeAfter = anExtSel->context()->shape();
-    // if selected plane is changed, try to re-take external references of all subs of the sketch
-    if (aShapeBefore.get() && !aShapeBefore->isEqual(aShapeAfter)) {
-      std::set<FeaturePtr> aWholeR;
-      allReasons(theFeature, aWholeR);
-      std::set<FeaturePtr>::iterator aRIter = aWholeR.begin();
-      for(; aRIter != aWholeR.end(); aRIter++) {
-        if ((*aRIter)->data()->selection("External"))
-          (*aRIter)->attributeChanged("External");
-      }
-    }
-  }
 
   if (!aIsModified) { // no modification is needed
     return false;
index a608c992c0574153549b9f27b67253f893d79d62..dad15e6d74b932e9b8f9530f56e2395f63e40718 100644 (file)
@@ -277,6 +277,7 @@ ADD_UNIT_TESTS(
   TestTrimLine02.py
   TestTrimLine03.py
   TestTrimPreview.py
+  TestUpdateSketch.py
 )
 
 if(${SKETCHER_CHANGE_RADIUS_WHEN_MOVE})
diff --git a/src/SketchPlugin/Test/TestUpdateSketch.py b/src/SketchPlugin/Test/TestUpdateSketch.py
new file mode 100644 (file)
index 0000000..0a398be
--- /dev/null
@@ -0,0 +1,60 @@
+## Copyright (C) 2014-2017  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<mailto:webmaster.salome@opencascade.com>
+##
+# -*- coding: utf-8 -*-
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+ParamA = model.addParameter(Part_1_doc, "a", "200")
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchLine_1 = Sketch_1.addLine(19.66215729983772, 107.3479424462301, -0.3378427001622813, 107.3479424462301)
+SketchLine_2 = Sketch_1.addLine(-0.3378427001622813, 107.3479424462301, -0.3378427001622813, 467.3479424462301)
+SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint())
+SketchLine_3 = Sketch_1.addLine(-0.3378427001622813, 467.3479424462301, 49.66215729983772, 467.3479424462301)
+SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint())
+SketchLine_4 = Sketch_1.addLine(-0.3378427001622813, 307.3479424462301, 29.66215729983772, 307.3479424462301)
+SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_4.startPoint(), SketchLine_2.result())
+SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_3.result())
+SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_4.result())
+SketchConstraintHorizontal_3 = Sketch_1.setHorizontal(SketchLine_1.result())
+SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result())
+SketchConstraintLength_1 = Sketch_1.setLength(SketchLine_3.result(), 50)
+SketchConstraintLength_2 = Sketch_1.setLength(SketchLine_4.result(), 30)
+SketchConstraintLength_3 = Sketch_1.setLength(SketchLine_1.result(), 20)
+SketchConstraintDistanceVertical_1 = Sketch_1.setVerticalDistance(SketchLine_1.endPoint(), SketchLine_4.startPoint(), "a")
+SketchConstraintDistanceVertical_2 = Sketch_1.setVerticalDistance(SketchLine_4.startPoint(), SketchLine_2.endPoint(), "a*0.8")
+model.do()
+Edge_1_objects = [model.selection("EDGE", "Sketch_1/SketchLine_3"), model.selection("EDGE", "Sketch_1/SketchLine_4"), model.selection("EDGE", "Sketch_1/SketchLine_1")]
+Edge_1 = model.addEdge(Part_1_doc, Edge_1_objects)
+Revolution_1_objects = [model.selection("EDGE", "Edge_1_1"), model.selection("EDGE", "Edge_1_2"), model.selection("EDGE", "Edge_1_3")]
+Revolution_1 = model.addRevolution(Part_1_doc, Revolution_1_objects, model.selection("EDGE", "Sketch_1/SketchLine_2"), 360, 0)
+Sketch_2 = model.addSketch(Part_1_doc, model.selection("FACE", "Revolution_1_2"))
+SketchCircle_1 = Sketch_2.addCircle(-8.007012574805483, 5.997620437244276, 8.148502128958617)
+model.do()
+# change the height of the second sketch plane
+ParamA.setValue(50)
+model.end()
+# check that the second sketch result is recomputed: is located in the same plane as base
+referenceY = Sketch_2.feature().selection("External").value().middlePoint().y()
+resultY = Sketch_2.feature().results()[0].shape().middlePoint().y()
+assert(referenceY == resultY)