]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implement changing sketch plane through Python API. Add unit test.
authorazv <azv@opencascade.com>
Tue, 4 Jun 2019 13:16:12 +0000 (16:16 +0300)
committerazv <azv@opencascade.com>
Tue, 4 Jun 2019 13:16:12 +0000 (16:16 +0300)
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/Test/TestChangeSketchPlane1.py [new file with mode: 0644]

index 380ec24691922d127e312c490b917c735a4b0d4e..7476380df64883cc5312f9ef257df8d527045890 100644 (file)
@@ -127,6 +127,26 @@ void SketchAPI_Sketch::setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane)
   execute();
 }
 
+void SketchAPI_Sketch::setPlane(const ModelHighAPI_Selection & thePlane,
+                                bool theRemoveExternalDependency)
+{
+  std::shared_ptr<SketchPlugin_Sketch> aSketch =
+      std::dynamic_pointer_cast<SketchPlugin_Sketch>(feature());
+
+  DocumentPtr aDoc = aSketch->document();
+  bool useVisible = false;
+  FeaturePtr aCurFeatureBefore = aDoc->currentFeature(useVisible);
+  aDoc->setCurrentFeature(aSketch, useVisible);
+
+  if (theRemoveExternalDependency)
+    aSketch->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
+
+  setExternal(thePlane);
+
+  aDoc->setCurrentFeature(aCurFeatureBefore, useVisible);
+}
+
+//--------------------------------------------------------------------------------------
 void SketchAPI_Sketch::setExternal(const ModelHighAPI_Selection & theExternal)
 {
   fillAttribute(theExternal, myexternal);
index 2ec522a9a436108691d8a5ee0e7f8999827e642a..1d3f762a697157a756f226ecd9151d448a09d8ed 100644 (file)
@@ -98,6 +98,11 @@ public:
   SKETCHAPI_EXPORT
   void setPlane(const std::shared_ptr<GeomAPI_Ax3> & thePlane);
 
+  /// Change sketch plane
+  SKETCHAPI_EXPORT
+  void setPlane(const ModelHighAPI_Selection & thePlane,
+                bool theRemoveExternalDependency = false);
+
   /// Set external
   SKETCHAPI_EXPORT
   void setExternal(const ModelHighAPI_Selection & theExternal);
index 629a49ba07cf6047e015381e335141f5a85e4db1..164e2c430ae0fee159cc2da45a56d653492dcd01 100644 (file)
@@ -196,6 +196,7 @@ ADD_UNIT_TESTS(
   Test2860.py
   Test2894.py
   TestArcBehavior.py
+  TestChangeSketchPlane1.py
   TestConstraintAngle.py
   TestConstraintCoincidence.py
   TestConstraintCollinear.py
diff --git a/src/SketchPlugin/Test/TestChangeSketchPlane1.py b/src/SketchPlugin/Test/TestChangeSketchPlane1.py
new file mode 100644 (file)
index 0000000..dd4105f
--- /dev/null
@@ -0,0 +1,107 @@
+# Copyright (C) 2019  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 SketchAPI import *
+from salome.shaper import model
+import math
+
+def checkMiddlePoint(feature, x, y, z, tolerance = 1.e-7):
+    shape = feature.results()[0].resultSubShapePair()[0].shape()
+    assert(shape is not None)
+    middlePoint = shape.middlePoint()
+    assert(math.fabs(middlePoint.x() - x) < tolerance), "X: {} != {}".format(middlePoint.x(), x)
+    assert(math.fabs(middlePoint.y() - y) < tolerance), "Y: {} != {}".format(middlePoint.y(), y)
+    assert(math.fabs(middlePoint.z() - z) < tolerance), "Z: {} != {}".format(middlePoint.z(), z)
+
+
+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/Left"))
+SketchCircle_1 = Sketch_1.addCircle(4, 5.52786404500042, 3)
+SketchProjection_1 = Sketch_1.addProjection(model.selection("EDGE", "[Box_1_1/Front][Box_1_1/Left]"), False)
+SketchLine_1 = SketchProjection_1.createdFeature()
+SketchConstraintDistance_1 = Sketch_1.setDistance(SketchCircle_1.center(), SketchLine_1.result(), 6, True)
+SketchConstraintRadius_1 = Sketch_1.setRadius(SketchCircle_1.results()[1], 3)
+SketchIntersectionPoint_1 = Sketch_1.addIntersectionPoint(model.selection("EDGE", "[Box_1_1/Back][Box_1_1/Top]"), False)
+[SketchPoint_1] = SketchIntersectionPoint_1.intersectionPoints()
+SketchConstraintDistance_2 = Sketch_1.setDistance(SketchAPI_Point(SketchPoint_1).coordinates(), SketchCircle_1.center(), 6, True)
+model.do()
+ExtrusionFuse_1 = model.addExtrusionFuse(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchCircle_1_2r_wire")], model.selection(), 1, 0, [model.selection("SOLID", "Box_1_1")])
+model.end()
+
+SKETCH_DOF = 0
+model.checkSketch(Sketch_1, SKETCH_DOF)
+
+from GeomAPI import GeomAPI_Shape
+
+model.testNbResults(ExtrusionFuse_1, 1)
+model.testNbSubResults(ExtrusionFuse_1, [0])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [8])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
+model.testResultsVolumes(ExtrusionFuse_1, [1028.2743338823])
+
+checkMiddlePoint(ExtrusionFuse_1, 4.96954097, 4.7867868, 5.0160782)
+
+# change plane and check error
+model.begin()
+Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Front"))
+model.end()
+assert(SketchIntersectionPoint_1.feature().error() != "")
+# revert error
+model.undo()
+
+# change plane to get correct sketch
+model.begin()
+Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Right"))
+model.end()
+model.checkSketch(Sketch_1, SKETCH_DOF)
+
+model.testNbResults(ExtrusionFuse_1, 1)
+model.testNbSubResults(ExtrusionFuse_1, [0])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [1])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [8])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
+model.testResultsVolumes(ExtrusionFuse_1, [1028.2743338823])
+
+checkMiddlePoint(ExtrusionFuse_1, 4.96954097, 5.2132132, 5.0160782)
+
+# change plane removing features related to external objects
+model.begin()
+Sketch_1.setPlane(model.selection("FACE", "Box_1_1/Top"), True)
+model.end()
+SKETCH_DOF = 6
+model.checkSketch(Sketch_1, SKETCH_DOF)
+
+model.testNbResults(ExtrusionFuse_1, 1)
+model.testNbSubResults(ExtrusionFuse_1, [2])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.SOLID, [2])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.FACE, [9])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.EDGE, [30])
+model.testNbSubShapes(ExtrusionFuse_1, GeomAPI_Shape.VERTEX, [60])
+model.testResultsVolumes(ExtrusionFuse_1, [1028.2743338823])
+
+checkMiddlePoint(ExtrusionFuse_1, 5.0, 0.73606797, 5.5)
+
+assert(model.checkPythonDump())