]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI / sketcher] Added methods for sketch features modification
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Mon, 2 Nov 2015 15:00:27 +0000 (16:00 +0100)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Mon, 2 Nov 2015 15:00:27 +0000 (16:00 +0100)
src/PythonAPI/Test/TestSketcherAddArc.py
src/PythonAPI/Test/TestSketcherAddCircle.py
src/PythonAPI/Test/TestSketcherAddLine.py
src/PythonAPI/Test/TestSketcherAddPoint.py
src/PythonAPI/model/sketcher/arc.py
src/PythonAPI/model/sketcher/circle.py
src/PythonAPI/model/sketcher/line.py
src/PythonAPI/model/sketcher/point.py
src/PythonAPI/model/sketcher/sketch.py

index 22c43b8262c0ebb28f0e12b36cb021f665873c73..9b433f0fde4f756bd9d4d03b3ed506b7c5d466af 100644 (file)
@@ -16,7 +16,7 @@ class SketcherAddArc(SketcherTestCase):
     def test_arc_by_points(self):
         center = geom.Pnt2d(0, 1)
         start = geom.Pnt2d(0, 0)
-        end = geom.Pnt2d(0, 1)
+        end = geom.Pnt2d(1, 1)
         arc = self.sketch.addArc(center, start, end)
         model.do()
         self.assertEqual(arc.startPointData().x(), 0)        
@@ -27,6 +27,19 @@ class SketcherAddArc(SketcherTestCase):
             self.sketch.addArc(0, 1, 1, 1)
         with self.assertRaises(WrongNumberOfArguments):
             self.sketch.addArc(0, 1)
+            
+    def test_modify_arc(self):
+        arc = self.sketch.addArc(0, 1, 0, 0, 1, 1)
+        arc.setCenter(0, 0)
+        arc.setStartPoint(-1.0, 0)
+        arc.setEndPoint(0, 1.0)
+        model.do()
+        self.assertEqual(arc.centerData().x(), 0)        
+        self.assertEqual(arc.centerData().y(), 0)
+        self.assertEqual(arc.startPointData().x(), -1)        
+        self.assertEqual(arc.startPointData().y(), 0)
+        self.assertEqual(arc.endPointData().x(), 0)        
+        self.assertEqual(arc.endPointData().y(), 1)
         
     
 if __name__ == "__main__":
index 48b15b0d3d4359fdff4288384ff620c435b5a127..932bb6881ca5ca3e92df8108a4e704ed0e16e9a0 100644 (file)
@@ -3,13 +3,23 @@ import model
 from TestSketcher import SketcherTestCase
 
 class SketcherAddCircle(SketcherTestCase):    
-    def runTest(self):
+    def test_add_cricle(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)
         
+    def test_modify_circle(self):
+        circle = self.sketch.addCircle(0, 10, 20)
+        model.do()
+        circle.setCenter(10, 10)
+        circle.setRadius(30)
+        model.do()
+        self.assertEqual(circle.centerData().x(), 10.0)        
+        self.assertEqual(circle.centerData().y(), 10.0)
+        self.assertEqual(circle.radiusData().value(), 30.0)
+        
     
 if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file
+    unittest.main(verbosity=2)
\ No newline at end of file
index 2c9254633686266d6d28fefb1e5b1ef566d57c55..fa4ed94c666e029451f39d47be6711abb3617b35 100644 (file)
@@ -3,12 +3,22 @@ import model
 from TestSketcher import SketcherTestCase
 
 class SketcherAddLine(SketcherTestCase):    
-    def runTest(self):
+    def test_add_line(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())
-        
-    
+        self.assertEqual(line.getStartPoint().x(), line.getEndPoint().x())        
+        self.assertNotEqual(line.getStartPoint().y(), line.getEndPoint().y())
+
+    def test_modify_line(self):
+        line = self.sketch.addLine(0, 0, 0, 1)
+        model.do()
+        line.setStartPoint(0, 1)
+        line.setEndPoint(1, 1)
+        self.assertEqual(line.getStartPoint().x(), 0)
+        self.assertEqual(line.getStartPoint().y(), 1)
+        self.assertEqual(line.getEndPoint().x(), 1)
+        self.assertEqual(line.getEndPoint().y(), 1)
+
+
 if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file
+    unittest.main(verbosity=2)
\ No newline at end of file
index e7abc535f9f46abd723657c6f18f3e9455e7e9a4..198887b0c57ff48503590a8867173d29fc400842 100644 (file)
@@ -9,6 +9,13 @@ class SketcherAddPoint(SketcherTestCase):
         self.assertEqual(point.pointData().x(), 0.0)        
         self.assertEqual(point.pointData().y(), 1.0)
         
+    def test_modify_point(self):
+        point = self.sketch.addPoint(0, 1)
+        point.setValue(1, 2)
+        model.do()
+        self.assertEqual(point.pointData().x(), 1.0)        
+        self.assertEqual(point.pointData().y(), 2.0)
+        
     
 if __name__ == "__main__":
     unittest.main(verbosity=2)
\ No newline at end of file
index d685befe4d015455498986a5c5b1a669f95f1b08..9bac67762b25707ea82b72eb94fae69dc6128727 100644 (file)
@@ -27,6 +27,33 @@ class Arc(Interface):
             raise WrongNumberOfArguments(
                 "Arc takes 3 or 6 arguments (%s given)" % len(args)
                 )
+        self._execute()
+        
+    ########
+    #
+    # Set methods
+    #
+    ########
+    
+    def setCenter(self, x, y):
+        """Set arc center."""
+        self._center.setValue(x, y)
+        
+    def setStartPoint(self, x, y):
+        """Set start point."""
+        self._start_point.setValue(x, y)
+        
+    def setEndPoint(self, x, y):
+        """Set end point value."""
+        self._end_point.setValue(x, y)
+        
+    
+    ########
+    #
+    # Getters
+    #
+    ########
+
 
     def centerData(self):
         """Return the center point data."""
@@ -44,24 +71,24 @@ class Arc(Interface):
         """Return the arc circular line attribute."""
         return self._feature.lastResult()
 
+
     ########
     #
     # Private methods
     #
     ########
 
+
     def __createByCoordinates(self, center_x, center_y,
                               start_x, start_y,
                               end_x, end_y):
         """Create an arc by point coordinates."""
-        self._center.setValue(center_x, center_y)
-        self._start_point.setValue(start_x, start_y)
-        self._end_point.setValue(end_x, end_y)
-        self._feature.execute()
+        self.setCenter(center_x, center_y)
+        self.setStartPoint(start_x, start_y)
+        self.setEndPoint(end_x, end_y)
 
     def __createByPoints(self, center, start, end):
         """Create an arc with point objects."""
-        self._center.setValue(center.x(), center.y())
-        self._start_point.setValue(start.x(), start.y())
-        self._end_point.setValue(end.x(), end.y())
-        self._feature.execute()
+        self.setCenter(center.x(), center.y())
+        self.setStartPoint(start.x(), start.y())
+        self.setEndPoint(end.x(), end.y())
index 1fed091e642c495cf83f79f04f825b92948645e9..b6ce45e8a33197fd84a3f922726f9428ad7958e6 100644 (file)
@@ -5,7 +5,7 @@ from model.roots import Interface
 
 class Circle(Interface):
     """Interface for circle feature data manipulation."""
-    def __init__(self, feature, x, y, r):
+    def __init__(self, feature, x, y, radius):
         Interface.__init__(self, feature)
         assert(self._feature.getKind() == "SketchCircle")
         
@@ -13,10 +13,18 @@ class Circle(Interface):
             self._feature.data().attribute("CircleCenter")
             )
         self._radius = self._feature.data().real("CircleRadius")
-        self._center.setValue(x, y)
-        self._radius.setValue(r)
+        self.setCenter(x, y)
+        self.setRadius(radius)
         self.execute()
 
+    def setCenter(self, x, y):
+        """Set the center of the circle."""
+        self._center.setValue(x, y)
+        
+    def setRadius(self, radius):
+        """Set the radius of the circle."""
+        self._radius.setValue(radius)
+        
     def centerData(self):
         """Return center data."""
         return self._center
index 2c2113244292c2bb57447c53664e88f5bb14bda3..eb8d735e022f00ad7c554f5d49323c966ae23d2c 100644 (file)
@@ -16,14 +16,12 @@ class Line(Interface):
             self._feature.data().attribute("EndPoint")
             )
 
-        assert(self._start_point)
-        assert(self._end_point)
-
-        if not args:
-            return
-
-        assert(len(args) in (1, 2, 4))
-
+        # Check that input arguments are not None
+        if args is None:
+            raise WrongNumberOfArguments(
+                "No argument given, at least one argument needed"
+                )
+        
         # Set attribute values and execute
         if len(args) == 4:
             self.__createByCoordinates(*args)
@@ -31,24 +29,39 @@ class Line(Interface):
             self.__createByPoints(*args)
         elif len(args) == 1:
             self.__createByName(*args)
-
+        else:
+            raise WrongNumberOfArguments(
+                "Arc takes 1, 2 or 4 arguments (%s given)" % len(args)
+                )
         self._execute()
-        pass
 
     def __createByCoordinates(self, x1, y1, x2, y2):
-        self._start_point.setValue(x1, y1)
-        self._end_point.setValue(x2, y2)
-        pass
+        self.setStartPoint(x1, y1)
+        self.setEndPoint(x2, y2)
 
     def __createByPoints(self, p1, p2):
-        self._start_point.setValue(p1.x(), p1.y())
-        self._end_point.setValue(p2.x(), p2.y())
-        pass
+        self.setStartPoint(p1.x(), p1.y())
+        self.setEndPoint(p2.x(), p2.y())
 
     def __createByName(self, name):
         self._feature.data().selection("External").selectSubShape("EDGE", name)
-        pass
+    
+    #######
+    #
+    # Set methods
+    #
+    #######
+    
+    def setStartPoint(self, x, y):
+        """Set the start point of the line."""
+        self._start_point.setValue(x, y)
+        
+    def setEndPoint(self, x, y):
+        """Set the end point of the line."""
+        self._end_point.setValue(x, y)
 
+    # TODO : methods below will be removed. 
+    # Kept until all tests have been updated
     def startPointData(self):
         return self._start_point
 
index 69b9f88fcd8b3a0aafc64467a1a3845e1a01e50c..3a65acea54df7db4f367652ae2bade242e00c359 100644 (file)
@@ -14,15 +14,12 @@ class Point(Interface):
         self._point_data = geomDataAPI_Point2D(
             self._feature.data().attribute("PointCoordinates")
             )
+        self.setValue(x, y)
+        self._execute()
+
+    def setValue(self, x, y):
+        """Set point coordinates."""
         self._point_data.setValue(x, y)
-        
-        # Control input and execute
-        if self.areInputValid():
-            self.execute()
-        else:
-            raise FeatureInputInvalid(
-                "cannot create the Sketch Point, the input is invalid"
-                )
 
     def pointData (self):
         """Return the point data."""
index a47759071958424249545130b616a119e324fbe4..04f6030313e2a85f4356ad9f66894ae86683d987 100644 (file)
@@ -1,5 +1,6 @@
 """Sketch Feature Interface
 Author: Daniel Brunier-Coulin with contribution by Mikhail Ponikarov
+        finalized by Renaud Nedelec and Sergey Pokhodenko
 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 """