]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI] added some more unit tests rnc/sketcher_api
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Mon, 19 Oct 2015 11:37:36 +0000 (13:37 +0200)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Mon, 19 Oct 2015 11:37:36 +0000 (13:37 +0200)
src/PythonAPI/CMakeLists.txt
src/PythonAPI/Test/TestSketcherAddCircle.py [new file with mode: 0644]
src/PythonAPI/Test/TestSketcherAddLine.py
src/PythonAPI/Test/TestSketcherSetParallel.py [new file with mode: 0644]
src/PythonAPI/modeler/sketcher/circle.py
src/PythonAPI/modeler/sketcher/sketch.py

index bda9c204c4d3c75752fc18e6e0944d0e989bdf2d..534588452f96431e919d0d0c90306f4074f86cae 100644 (file)
@@ -11,5 +11,7 @@ INCLUDE(UnitTest)
 ADD_UNIT_TESTS(
   TestModeler.py
   TestSketcherAddLine.py
+  TestSketcherAddCircle.py
   TestSketcherSetCoincident.py
+  TestSketcherSetParallel.py
   ) 
diff --git a/src/PythonAPI/Test/TestSketcherAddCircle.py b/src/PythonAPI/Test/TestSketcherAddCircle.py
new file mode 100644 (file)
index 0000000..ac956e0
--- /dev/null
@@ -0,0 +1,14 @@
+import unittest
+import modeler
+from TestSketcher import SketcherTestCase
+
+class SketcherAddCircle(SketcherTestCase):    
+    def runTest(self):
+        circle = self.sketch.addCircle(0, 10, 20)
+        self.assertEqual(circle.centerData().x(), 0.0)        
+        self.assertEqual(circle.centerData().y(), 10.0)
+        self.assertEqual(circle.radiusData().value(), 20.0)
+        
+    
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
index 41322e80fbbe59852ab3de39e38b4ed3ea6b2a54..a0e4a9a280067fc04bedd9679e12c65d1bdb9cd8 100644 (file)
@@ -2,7 +2,7 @@ import unittest
 import modeler
 from TestSketcher import SketcherTestCase
 
-class SketcherAddLineTestCase(SketcherTestCase):    
+class SketcherAddLine(SketcherTestCase):    
     def runTest(self):
         line = self.sketch.addLine(0, 0, 0, 1)
         self.assertEqual(line.startPointData().x(), line.endPointData().x())        
diff --git a/src/PythonAPI/Test/TestSketcherSetParallel.py b/src/PythonAPI/Test/TestSketcherSetParallel.py
new file mode 100644 (file)
index 0000000..d37d027
--- /dev/null
@@ -0,0 +1,12 @@
+import unittest
+import modeler
+from TestSketcher import SketcherTestCase
+
+class SketcherSetParallel(SketcherTestCase):   
+    def runTest(self):
+        l1 = self.sketch.addLine(0, 0, 0, 1)
+        l2 = self.sketch.addLine(0, 1, 1, 1)
+        self.sketch.setParallel(l1.result(), l2.result())
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file
index 855651731fec403530f8a4dc679de002754c5a61..08c890bec05875d4f674fd66f821b0aea238b0d3 100644 (file)
@@ -1,15 +1,27 @@
+"""Sketch circle feature interface."""
+
 from GeomDataAPI import geomDataAPI_Point2D
 
-class Circle():
+def addCircle(sketch, x, y, r):
+    feature = sketch.addFeature("SketchCircle")
+    return CircleInterface(feature, x, y, r)
 
-  def __init__(self, sketch, x, y, r):
-    self.my = sketch.addFeature("SketchCircle")
-    geomDataAPI_Point2D( self.my.data().attribute("CircleCenter") ).setValue(x, y)
-    self.my.data().real("CircleRadius").setValue(r)
-    self.my.execute()
+class CircleInterface():
+    def __init__(self, circle_feature, x, y, r):
+        self._feature = circle_feature
+        self._center = geomDataAPI_Point2D(
+            self._feature.data().attribute("CircleCenter")
+            )
+        self._radius = self._feature.data().real("CircleRadius")
+        self._center.setValue(x, y)
+        self._radius.setValue(r)
+        self._feature.execute()
 
-  def centerData (self):
-    return geomDataAPI_Point2D( self.my.data().attribute("CircleCenter") )
+    def centerData (self):
+        return self._center
+    
+    def radiusData (self):
+        return self._radius
 
-  def result (self):
-    return self.my.lastResult()   # Returns the circular line attribute
+    def result (self):
+        return self._feature.lastResult()   # Returns the circular line attribute
index 20ddfd842805cb7d5fc89fa04628c1af910c0037..479bb8c4413ff028b6f55c2d6a078ee76c8d996c 100644 (file)
@@ -8,7 +8,7 @@ from GeomDataAPI import *
 from GeomAlgoAPI import *
 import modeler.sketcher.point as sk_point
 import modeler.sketcher.line as sk_line
-from modeler.sketcher.circle import Circle
+import modeler.sketcher.circle as sk_circle
 
 def addSketch(doc, plane):
     """Add a Sketch feature to the Part or PartSet and return an interface
@@ -102,7 +102,8 @@ class Sketch():
 
     def addCircle (self, *args):
         """Adds a circle to this Sketch."""
-        return Circle(self._feature, *args)
+        circle_interface = sk_circle.addCircle(self._feature, *args)
+        return circle_interface
 
 
     # Creation of Geometrical and Dimensional Constraints