]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Merge branch 'python_parametric_api' of https://git.salome-platform.org/git/modules...
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Wed, 4 Nov 2015 09:42:04 +0000 (10:42 +0100)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Wed, 4 Nov 2015 09:42:04 +0000 (10:42 +0100)
Conflicts:
src/PythonAPI/model/sketcher/line.py

src/PythonAPI/Test/TestSketcherAddPoint.py
src/PythonAPI/Test/TestSketcherSetCoincident.py
src/PythonAPI/model/roots.py
src/PythonAPI/model/sketcher/line.py
src/PythonAPI/model/sketcher/sketch.py

index 198887b0c57ff48503590a8867173d29fc400842..284d377641ee2c6f425d309e3421d9bea9d953eb 100644 (file)
@@ -16,6 +16,10 @@ class SketcherAddPoint(SketcherTestCase):
         self.assertEqual(point.pointData().x(), 1.0)        
         self.assertEqual(point.pointData().y(), 2.0)
         
+    def test_empty_args(self):
+        with self.assertRaises(TypeError):
+            self.sketch.addPoint()
+        
     
 if __name__ == "__main__":
     unittest.main(verbosity=2)
\ No newline at end of file
index a5c07f7e6a5e6b9d383b47b52f608c5361123cbd..ae07123c87ee92e8b273e1593719af523e8ff96d 100644 (file)
@@ -3,11 +3,21 @@ import model
 from TestSketcher import SketcherTestCase
 
 class SketcherSetCoincident(SketcherTestCase):   
-    def runTest(self):
+    def test_set_coincident(self):
         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()
+    
+    def test_none_type_arguments(self):
+        l2 = self.sketch.addLine(0, 1, 1, 1)
+        with self.assertRaises(TypeError):
+            self.sketch.setCoincident(None, l2.startPointData())
+        
+    def test_empty_arguments(self):
+        l1 = self.sketch.addLine(0, 0, 0, 1)
+        with self.assertRaises(TypeError):
+            self.sketch.setCoincident(l1.endPointData())
 
 if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file
+    unittest.main(verbosity=2)
\ No newline at end of file
index 29080e218d92f7834a01040ab35dd4c49e62e6c1..5f1c294bf13214e7acae6202a80d53cbca385f4e 100644 (file)
@@ -78,7 +78,7 @@ class Interface():
         return self._feature.firstResult()
 
     def lastResult(self):
-        """Return the result in the list of results"""
+        """Return the last result in the list of results"""
         return self._feature.lastResult()
 
     def setRealInput(self, inputid, value):
index 426ea97a41e7dafbe6321b885d007a1400094ecf..d7bb70f84679708cb52e709ef2bcbd27e2533bf3 100644 (file)
@@ -16,11 +16,10 @@ class Line(Interface):
             self._feature.data().attribute("EndPoint")
             )
 
-        # Check that input arguments are not None
+        # If no arguments are given the attributes of the feature 
+        # are'nt initialized
         if args is None:
-            raise WrongNumberOfArguments(
-                "No argument given, at least one argument needed"
-                )
+            return
         
         # Set attribute values and execute
         if len(args) == 4:
@@ -60,7 +59,7 @@ class Line(Interface):
         """Set the end point of the line."""
         self._end_point.setValue(x, y)
 
-    # TODO : methods below will be removed.
+    # TODO : methods below will be removed. 
     # Kept until all tests have been updated
     def startPointData(self):
         return self._start_point
index d0dfcf659741138baab8a15362dc8f1b5a061290..75cf7584254bed76f061a899e08eb9160d00b2c1 100644 (file)
@@ -50,22 +50,14 @@ class Sketch(Interface):
             )
         self._external = self._feature.data().selection("External")
 
-        assert(self._origin)
-        assert(self._dir_x)
-        assert(self._norm)
-        assert(self._external)
-
-        if not args:
-            return
-
-        plane = args[0]
-
-        #   self.resultype ="Face" # Type of Sketch result
-        if isinstance(plane, str):
-            self.__sketchOnFace(plane)
-        else:
-            self.__sketchOnPlane(plane)
-        pass
+        # If no arguments are given the attributes of the feature 
+        # are not Initialized
+        if args is not None:
+            plane = args[0]
+            if isinstance(plane, str):
+                self.__sketchOnFace(plane)
+            else:
+                self.__sketchOnPlane(plane)
 
     def __sketchOnPlane(self, plane):
         """Create the sketch on a plane."""
@@ -88,11 +80,15 @@ class Sketch(Interface):
 
     def addPoint(self, *args):
         """Add a point to this Sketch."""
+        if not args:
+            raise TypeError("No arguments given")
         point_feature = self._feature.addFeature("SketchPoint")
         return Point(point_feature, *args)
 
     def addLine(self, *args):
         """Add a line to this Sketch."""
+        if not args:
+            raise TypeError("No arguments given")
         line_feature = self._feature.addFeature("SketchLine")
         line_interface = Line(line_feature, *args)
         # if the line is created by name add a rigid constraint
@@ -106,11 +102,15 @@ class Sketch(Interface):
 
     def addCircle(self, *args):
         """Add a circle to this Sketch."""
+        if not args:
+            raise TypeError("No arguments given")
         circle_feature = self._feature.addFeature("SketchCircle")
         return Circle(circle_feature, *args)
 
     def addArc(self, *args):
         """Add an arc to this Sketch."""
+        if not args:
+            raise TypeError("No arguments given")
         arc_feature = self._feature.addFeature("SketchArc")
         return Arc(arc_feature, *args)
 
@@ -123,7 +123,12 @@ class Sketch(Interface):
     def setCoincident(self, p1, p2):
         """Set coincident the two given points and add the corresponding
         constraint to this Sketch."""
-        assert(p1 and p2)
+        # assert(p1 and p2) NOTE : if an argument is missing python
+        # will raise TypeError by itself.
+        # It seems better to check only that provided arguments are not 
+        # None
+        if p1 is None or p2 is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintCoincidence")
         constraint.data().refattr("ConstraintEntityA").setAttr(p1)
         constraint.data().refattr("ConstraintEntityB").setAttr(p2)
@@ -133,7 +138,8 @@ class Sketch(Interface):
     def setParallel(self, l1, l2):
         """Set parallel the two given lines and add the corresponding
         constraint to this Sketch."""
-        assert(l1 and l2)
+        if l1 is None or l2 is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintParallel")
         constraint.data().refattr("ConstraintEntityA").setObject(l1)
         constraint.data().refattr("ConstraintEntityB").setObject(l2)
@@ -143,7 +149,8 @@ class Sketch(Interface):
     def setPerpendicular(self, l1, l2):
         """Set perpendicular the two given lines and add the corresponding
         constraint to this Sketch."""
-        assert(l1 and l2)
+        if l1 is None or l2 is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintPerpendicular")
         constraint.data().refattr("ConstraintEntityA").setObject(l1)
         constraint.data().refattr("ConstraintEntityB").setObject(l2)
@@ -153,6 +160,8 @@ class Sketch(Interface):
     def setHorizontal(self, line):
         """Set horizontal the given line and add the corresponding
         constraint to this Sketch."""
+        if line is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintHorizontal")
         constraint.data().refattr("ConstraintEntityA").setObject(line)
         self.execute()
@@ -161,6 +170,8 @@ class Sketch(Interface):
     def setVertical(self, line):
         """Set vertical the given line and add the corresponding
         constraint to this Sketch."""
+        if line is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintVertical")
         constraint.data().refattr("ConstraintEntityA").setObject(line)
         self.execute()
@@ -169,13 +180,13 @@ class Sketch(Interface):
     def setDistance(self, point, line, length):
         """Set the distance between the given point and line, and add
         the corresponding constraint to this Sketch."""
-        assert(point and line)
+        if point is None or line is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintDistance")
         if isinstance(line, basestring):
             # Add the edge identified by the given topological name
             # to this Sketch
             line = self.addLine(line).result()
-            assert(line)
         constraint.data().refattr("ConstraintEntityA").setAttr(point)
         constraint.data().refattr("ConstraintEntityB").setObject(line)
         constraint.data().real("ConstraintValue").setValue(length)
@@ -185,7 +196,8 @@ class Sketch(Interface):
     def setLength(self, line, length):
         """Set the length of the given line and add the corresponding
         constraint to this Sketch."""
-        assert(line)
+        if line is None:
+            raise TypeError("NoneType argument given")
         constraint = self._feature.addFeature("SketchConstraintLength")
         constraint.data().refattr("ConstraintEntityA").setObject(line)
         constraint.data().real("ConstraintValue").setValue(length)
@@ -231,12 +243,14 @@ class Sketch(Interface):
         return constraint
 
     def setFillet(self, line_1, line_2, radius):
-        """Set a fillet constraint between the 3 given lines with the given
+        """Set a fillet constraint between the 2 given lines with the given
         filleting radius."""
         constraint = self._feature.addFeature("SketchConstraintFillet")
-        constraint.data().refattr("ConstraintEntityA").setObject(line_1)
-        constraint.data().refattr("ConstraintEntityB").setObject(line_2)
-        constraint.data().real("ConstraintValue").setValue(radius)
+        constraint.data().reflist("ConstraintEntityA").clear
+        constraint.data().reflist("ConstraintEntityA").append(line_1)
+        constraint.data().reflist("ConstraintEntityB").clear
+        constraint.data().reflist("ConstraintEntityB").append(line_1)
+        
         self.execute()
         return constraint