Salome HOME
Updated copyright comment
[modules/shaper.git] / src / SketchAPI / Test / TestSketch.py
index 8cd95163f0a3b3456fd04d9c278dbeb9459cceb1..ac7d4b8929b6f51b7dc6f38c849c5d8deb4bd2fd 100644 (file)
@@ -1,22 +1,21 @@
-## 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>
-##
+# Copyright (C) 2014-2024  CEA, EDF
+#
+# 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
+#
 
 import math
 import unittest
@@ -30,10 +29,12 @@ from salome.shaper import model
 class SketchTestCase(unittest.TestCase):
 
     def setUp(self):
+        model.begin()
         self.session = ModelAPI.ModelAPI_Session.get()
         aPartSet = self.session.moduleDocument()
         self.doc = model.addPart(aPartSet).document()
         model.addCylinder(self.doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 5, 10)
+        model.addCylinder(self.doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10, 90)
         self.sketch = model.addSketch(self.doc, model.defaultPlane("XOY"))
 
     def tearDown(self):
@@ -57,7 +58,7 @@ class SketchTestCase(unittest.TestCase):
         self.checkPoint(aCircle.center(), point)
 
     def test_circle_by_external(self):
-        """ Test 2. Create point circle by external features
+        """ Test 2. Create point and circle by external features
         """
         aPoint = self.sketch.addPoint("PartSet/Origin")
         aCircle = self.sketch.addCircle("[Cylinder_1_1/Face_1][Cylinder_1_1/Face_3]")
@@ -141,6 +142,45 @@ class SketchTestCase(unittest.TestCase):
         self.checkPoint(anArc.center(), aCenter)
         self.assertAlmostEqual(anArc.radius().value(), aRadius, 6)
 
+    def test_arc_by_external(self):
+        """ Test 7. Create arc by external feature
+        """
+        anArc = self.sketch.addArc(model.selection("EDGE", "[Cylinder_2_1/Face_1][Cylinder_2_1/Face_3]"))
+        model.do()
+        point = geom.Pnt2d(0., 0.)
+        self.checkPoint(anArc.center(), point)
+        self.assertAlmostEqual(anArc.radius().value(), 10, 6)
+
+    def test_arc_by_name(self):
+        """ Test 8. Create arc by external feature
+        """
+        anArc = self.sketch.addArc("[Cylinder_2_1/Face_1][Cylinder_2_1/Face_3]")
+        model.do()
+        point = geom.Pnt2d(0., 0.)
+        self.checkPoint(anArc.center(), point)
+        self.assertAlmostEqual(anArc.radius().value(), 10, 6)
+
+    def test_point_by_intersection(self):
+        """ Test 9. Create point as intersection with external edge given by a name
+        """
+        self.sketch.addIntersectionPoint("[Cylinder_2_1/Face_1][Cylinder_2_1/Face_4]")
+        model.do()
+        aPoint = SketchAPI.SketchAPI_Point(model.lastSubFeature(self.sketch, "SketchPoint"))
+
+        point = geom.Pnt2d(10., 0.)
+        self.checkPoint(aPoint.coordinates(), point)
+
+    def test_arc_by_projection(self):
+        """ Test 10. Create arc by projection of external feature
+        """
+        self.sketch.addProjection(model.selection("EDGE", "[Cylinder_2_1/Face_1][Cylinder_2_1/Face_3]"))
+        model.do()
+        anArc = SketchAPI.SketchAPI_Arc(model.lastSubFeature(self.sketch, "SketchArc"))
+
+        point = geom.Pnt2d(0., 0.)
+        self.checkPoint(anArc.center(), point)
+        self.assertAlmostEqual(anArc.radius().value(), 10, 6)
+
 
 if __name__ == "__main__":
     test_program = unittest.main(exit=False)