]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI] added two tests and added transaction commit step in
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Tue, 20 Oct 2015 10:43:32 +0000 (12:43 +0200)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Tue, 20 Oct 2015 10:43:32 +0000 (12:43 +0200)
previous tests

src/PythonAPI/CMakeLists.txt
src/PythonAPI/Test/TestSketcherAddArc.py
src/PythonAPI/Test/TestSketcherAddCircle.py
src/PythonAPI/Test/TestSketcherAddLine.py
src/PythonAPI/Test/TestSketcherAddPoint.py
src/PythonAPI/Test/TestSketcherSetCoincident.py
src/PythonAPI/Test/TestSketcherSetParallel.py
src/PythonAPI/Test/TestSketcherSetPerpendicular.py [new file with mode: 0644]
src/PythonAPI/Test/TestSketcherSetRadius.py [new file with mode: 0644]
src/PythonAPI/model/sketcher/sketch.py

index 45cedd0516fb51db1053331afd4cd82b6986cf85..936e1aecab02c8634de16f68f44119a379084b1a 100644 (file)
@@ -16,4 +16,6 @@ ADD_UNIT_TESTS(
   TestSketcherAddCircle.py
   TestSketcherSetCoincident.py
   TestSketcherSetParallel.py
+  TestSketcherSetPerpendicular.py
+  TestSketcherSetRadius.py
   ) 
index 87378aef06715a1c9f1a796a10fd3c853e297af0..1b64c4465e5b8069728125b151f6c503185f4599 100644 (file)
@@ -9,6 +9,7 @@ from TestSketcher import SketcherTestCase
 class SketcherAddArc(SketcherTestCase):    
     def test_arc_by_coords(self):
         arc = self.sketch.addArc(0, 1, 0, 0, 1, 1)
+        model.do()
         self.assertEqual(arc.startPointData().x(), 0)        
         self.assertEqual(arc.startPointData().y(), 0)
     
@@ -17,6 +18,7 @@ class SketcherAddArc(SketcherTestCase):
         start = geom.Pnt2d(0, 0)
         end = geom.Pnt2d(0, 1)
         arc = self.sketch.addArc(center, start, end)
+        model.do()
         self.assertEqual(arc.startPointData().x(), 0)        
         self.assertEqual(arc.startPointData().y(), 0)
     
index 3c45e320fd7ffe754ca892a49f25d388e144aee0..48b15b0d3d4359fdff4288384ff620c435b5a127 100644 (file)
@@ -5,6 +5,7 @@ from TestSketcher import SketcherTestCase
 class SketcherAddCircle(SketcherTestCase):    
     def runTest(self):
         circle = self.sketch.addCircle(0, 10, 20)
+        model.do()
         self.assertEqual(circle.centerData().x(), 0.0)        
         self.assertEqual(circle.centerData().y(), 10.0)
         self.assertEqual(circle.radiusData().value(), 20.0)
index ce5b313496679fea7d195fb4bab0ae2d0d2afa30..2c9254633686266d6d28fefb1e5b1ef566d57c55 100644 (file)
@@ -5,6 +5,7 @@ from TestSketcher import SketcherTestCase
 class SketcherAddLine(SketcherTestCase):    
     def runTest(self):
         line = self.sketch.addLine(0, 0, 0, 1)
+        model.do()
         self.assertEqual(line.startPointData().x(), line.endPointData().x())        
         self.assertNotEqual(line.startPointData().y(), line.endPointData().y())
         
index e521c9a08547977ea266b6f5a0d7f9b99a07e48b..783f8c17bb854129a2023d265aff500373e17ffa 100644 (file)
@@ -5,6 +5,7 @@ from TestSketcher import SketcherTestCase
 class SketcherAddPoint(SketcherTestCase):    
     def runTest(self):
         point = self.sketch.addPoint(0, 1)
+        model.do()
         self.assertEqual(point.pointData().x(), 0.0)        
         self.assertEqual(point.pointData().y(), 1.0)
         
index f6a13e12aacc3960ea96714896e9db3dbffb876f..a5c07f7e6a5e6b9d383b47b52f608c5361123cbd 100644 (file)
@@ -7,6 +7,7 @@ class SketcherSetCoincident(SketcherTestCase):
         l1 = self.sketch.addLine(0, 0, 0, 1)
         l2 = self.sketch.addLine(0, 1, 1, 1)
         self.sketch.setCoincident(l1.endPointData(), l2.startPointData())
+        model.do()
 
 if __name__ == "__main__":
     unittest.main()
\ No newline at end of file
index 0f7fa184478e55558355b90b0d08783e078a388f..75c37ecc37eef625b5134ceb771959ce2197dc6b 100644 (file)
@@ -7,6 +7,7 @@ class SketcherSetParallel(SketcherTestCase):
         l1 = self.sketch.addLine(0, 0, 0, 1)
         l2 = self.sketch.addLine(0, 1, 1, 1)
         self.sketch.setParallel(l1.result(), l2.result())
+        model.do()
 
 if __name__ == "__main__":
     unittest.main()
\ No newline at end of file
diff --git a/src/PythonAPI/Test/TestSketcherSetPerpendicular.py b/src/PythonAPI/Test/TestSketcherSetPerpendicular.py
new file mode 100644 (file)
index 0000000..61dcfd3
--- /dev/null
@@ -0,0 +1,19 @@
+import unittest
+import model
+from TestSketcher import SketcherTestCase
+
+class SketcherSetPerpendicular(SketcherTestCase):   
+    def runTest(self):
+        l1 = self.sketch.addLine(0, 0, 0, 1)
+        l2 = self.sketch.addLine(0, 0, 1, 1)
+        self.sketch.setPerpendicular(l1.result(), l2.result())
+        model.do()
+        
+        dot_product = (l1.endPointData().x() - l1.startPointData().x()) * \
+                      (l2.endPointData().x() - l2.startPointData().x()) + \
+                      (l1.endPointData().y() - l1.startPointData().y()) * \
+                      (l2.endPointData().y() - l2.startPointData().y())
+        self.assertEqual(dot_product, 0.0)
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
diff --git a/src/PythonAPI/Test/TestSketcherSetRadius.py b/src/PythonAPI/Test/TestSketcherSetRadius.py
new file mode 100644 (file)
index 0000000..d0fe52b
--- /dev/null
@@ -0,0 +1,13 @@
+import unittest
+import model
+from TestSketcher import SketcherTestCase
+
+class SketcherSetRadius(SketcherTestCase):   
+    def runTest(self):
+        circle = self.sketch.addCircle(0, 10, 20)
+        self.sketch.setRadius(circle.result(), 30)
+        model.do()
+        self.assertEqual(circle.radiusData().value(), 30.0)
+        
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
index 30ddbfedc4d90c1675c362f2591fd18c5eb12bf7..81df548aa9f8c158f1ffb3fb64eff50610a58d75 100644 (file)
@@ -25,13 +25,15 @@ def addSketch(doc, plane):
 class Sketch():
     """Interface on a Sketch feature."""
     def __init__(self, feature, plane):
-        """Initialize a 2D Sketch on the given plane
+        """Initialize a 2D Sketch on the given plane.
+        
         The plane can be defined either by:
         - a 3D axis system (geom.Ax3),
         - an existing face identified by its topological name.
         """
         self._feature = feature
-        self._selection = None     # Entities used for building the result shape
+        # Entities used for building the result shape
+        self._selection = None
         #   self.resultype ="Face" # Type of Sketch result
         if isinstance(plane, str):
             self.__sketchOnFace(plane)
@@ -56,7 +58,7 @@ class Sketch():
         self._feature.data().selection("External").selectSubShape("FACE", plane)
 
 
-# Creation of Geometries
+    # Creation of Geometries
 
     def addPoint (self, *args):
         """Add a point to this Sketch."""
@@ -78,45 +80,6 @@ class Sketch():
         arc_feature = self._feature.addFeature("SketchArc")
         return Arc(arc_feature, *args)
 
-    def addPolyline (self, *coords):
-        """Adds a poly-line to this Sketch.
-        
-        The end of consecutive segments are defined as coincident.
-        """
-        c0 = coords[0]
-        c1 = coords[1]
-        polyline = []
-        line_1 = self.addLine(c0, c1)
-        polyline.append(line_1)
-        # Adding and connecting next lines
-        for c2 in coords[2:]:
-            line_2 = self.addLine(c1, c2)
-            self.setCoincident(line_1.endPointData(), line_2.startPointData())
-            polyline.append(line_2)
-            c1 = c2
-            line_1 = line_2
-        return polyline
-
-    def addPolygon (self, *coords):
-        """Add a polygon to this Sketch.
-        
-        The end of consecutive segments are defined as coincident.
-        """
-        pg = self.addPolyline(*coords)
-        # Closing the poly-line supposed being defined by at least 3 points
-        c0 = coords[0]
-        cn = coords[len(coords) - 1]
-        ln = self.addLine(cn, c0)
-        self.setCoincident(
-            pg[len(coords) - 2].endPointData(), ln.startPointData()
-            )
-        self.setCoincident(
-            ln.endPointData(), pg[0].startPointData()
-            )
-        pg.append(ln)
-        return pg
-
-
     # Creation of Geometrical and Dimensional Constraints
 
     def setCoincident (self, p1, p2):
@@ -180,9 +143,50 @@ class Sketch():
     def setValue (self, constraint, value):
         """Modify the value of the given dimensional constraint."""
         constraint.data().real("ConstraintValue").setValue(value)
+     
+     
+    # Macro functions combining geometry creation and constraints
+     
+    def addPolyline (self, *coords):
+        """Add a poly-line to this Sketch.
+        
+        The end of consecutive segments are defined as coincident.
+        """
+        c0 = coords[0]
+        c1 = coords[1]
+        polyline = []
+        line_1 = self.addLine(c0, c1)
+        polyline.append(line_1)
+        # Adding and connecting next lines
+        for c2 in coords[2:]:
+            line_2 = self.addLine(c1, c2)
+            self.setCoincident(line_1.endPointData(), line_2.startPointData())
+            polyline.append(line_2)
+            c1 = c2
+            line_1 = line_2
+        return polyline
+
+    def addPolygon (self, *coords):
+        """Add a polygon to this Sketch.
+        
+        The end of consecutive segments are defined as coincident.
+        """
+        pg = self.addPolyline(*coords)
+        # Closing the poly-line supposed being defined by at least 3 points
+        c0 = coords[0]
+        cn = coords[len(coords) - 1]
+        ln = self.addLine(cn, c0)
+        self.setCoincident(
+            pg[len(coords) - 2].endPointData(), ln.startPointData()
+            )
+        self.setCoincident(
+            ln.endPointData(), pg[0].startPointData()
+            )
+        pg.append(ln)
+        return pg
 
 
-# Getters
+    # Getters
 
     def selectFace (self, *args):
         """Select the geometrical entities of this Sketch on which