]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI / sketcher] added the setEqual method and the setLength test
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Tue, 20 Oct 2015 14:43:13 +0000 (16:43 +0200)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Tue, 20 Oct 2015 14:43:13 +0000 (16:43 +0200)
src/PythonAPI/CMakeLists.txt
src/PythonAPI/Test/TestSketcherSetEqual.py [new file with mode: 0644]
src/PythonAPI/Test/TestSketcherSetLength.py [new file with mode: 0644]
src/PythonAPI/model/sketcher/sketch.py

index 551a8506e4a6cf97ef51f7225578f94fcf9c27b2..ae884173e1a5ac6a284b4f94742564df1f1e33dc 100644 (file)
@@ -19,6 +19,8 @@ ADD_UNIT_TESTS(
   TestSketcherSetPerpendicular.py
   TestSketcherSetHorizontal.py
   TestSketcherSetVertical.py
+  TestSketcherSetLength.py
   TestSketcherSetRadius.py
   TestSketcherSetAngle.py
+  TestSketcherSetEqual.py
   ) 
diff --git a/src/PythonAPI/Test/TestSketcherSetEqual.py b/src/PythonAPI/Test/TestSketcherSetEqual.py
new file mode 100644 (file)
index 0000000..65a7e3c
--- /dev/null
@@ -0,0 +1,42 @@
+import unittest
+import model
+import math
+import TestSketcher
+from TestSketcher import SketcherTestCase
+
+class SketcherSetEqual(SketcherTestCase):   
+    def test_length_equality(self):
+        # Set the constraint
+        l1 = self.sketch.addLine(0, 0, 0, 1)
+        l2 = self.sketch.addLine(0, 0, 1, 1)
+        self.sketch.setEqual(l1.result(), l2.result())
+        # Commit the transaction
+        model.do()
+        # Check the result
+        length_1 = math.sqrt(
+            math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) + 
+            math.pow((l1.endPointData().y() - l1.startPointData().y()), 2)
+            )
+        length_2 = math.sqrt(
+            math.pow((l1.endPointData().x() - l1.startPointData().x()), 2) + 
+            math.pow((l2.endPointData().y() - l2.startPointData().y()), 2)
+            )
+        self.assertAlmostEqual(length_1, length_2, delta=TestSketcher.DELTA)
+        
+    def test_radius_equality(self):
+        # Set the constraint
+        circle_1 = self.sketch.addCircle(0, 0, 10.0)
+        circle_2 = self.sketch.addCircle(1, 2, 25.0)
+        self.sketch.setEqual(circle_1.result(), circle_2.result())
+        # Commit the transaction
+        model.do()
+        # Check the result
+        self.assertAlmostEqual(
+            circle_1.radiusData().value(), 
+            circle_2.radiusData().value(), 
+            delta=TestSketcher.DELTA
+            )
+        
+if __name__ == "__main__":
+    suite = unittest.TestLoader().loadTestsFromTestCase(SketcherSetEqual)
+    unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
diff --git a/src/PythonAPI/Test/TestSketcherSetLength.py b/src/PythonAPI/Test/TestSketcherSetLength.py
new file mode 100644 (file)
index 0000000..b56650b
--- /dev/null
@@ -0,0 +1,22 @@
+import unittest
+import model
+import math
+import TestSketcher
+from TestSketcher import SketcherTestCase
+
+class SketcherSetLength(SketcherTestCase):   
+    def runTest(self):
+        # Set the constraint
+        line = self.sketch.addLine(0, 0, 0, 1)
+        self.sketch.setLength(line.result(), 25.0)
+        # Commit the transaction
+        model.do()
+        # Check the result
+        length = math.sqrt(
+            math.pow((line.endPointData().x() - line.startPointData().x()), 2) + 
+            math.pow((line.endPointData().y() - line.startPointData().y()), 2)
+            )
+        self.assertAlmostEqual(length, 25.0, delta=TestSketcher.DELTA)
+        
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
index 4a809f0b4c006f0e95597ee5369b01f3bacbd13e..7ef6af55254d8ef370ed0cbea090e4ae03b47f63 100644 (file)
@@ -160,6 +160,24 @@ class Sketch():
         self._feature.execute()
         return constraint
     
+    def setRadius(self, circle, radius):
+        """Set the radius of the given circle and add the corresponding 
+        constraint to this Sketch."""
+        constraint = self._feature.addFeature("SketchConstraintRadius")
+        constraint.data().refattr("ConstraintEntityA").setObject(circle)
+        constraint.data().real("ConstraintValue").setValue(radius)
+        return constraint
+    
+    def setEqual(self, object_1, object_2):
+        """Set the radii of two circles or the length of two lines equal.
+        
+        The corresponding constraint is added to the sketch"""
+        constraint = self._feature.addFeature("SketchConstraintEqual")
+        constraint.data().refattr("ConstraintEntityA").setObject(object_1)
+        constraint.data().refattr("ConstraintEntityB").setObject(object_2)
+        self._feature.execute()
+        return constraint
+    
     def setAngle(self, line_1, line_2, angle):
         """Set the angle between the given 2 lines and add the corresponding 
         constraint to the sketch."""
@@ -170,14 +188,6 @@ class Sketch():
         self._feature.execute()
         return constraint
 
-    def setRadius(self, circle, radius):
-        """Set the radius of the given circle and add the corresponding 
-        constraint to this Sketch."""
-        constraint = self._feature.addFeature("SketchConstraintRadius")
-        constraint.data().refattr("ConstraintEntityA").setObject(circle)
-        constraint.data().real("ConstraintValue").setValue(radius)
-        return constraint
-
     #-------------------------------------------------------------
     #
     # Edition of Dimensional Constraints