]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
[PythonAPI] derived sketcher interfaces from Interface base class
authorRenaud NEDELEC <renaud.nedelec@opencascade.com>
Thu, 22 Oct 2015 14:18:06 +0000 (16:18 +0200)
committerRenaud NEDELEC <renaud.nedelec@opencascade.com>
Thu, 22 Oct 2015 14:18:06 +0000 (16:18 +0200)
+ small modifications in tests

src/PythonAPI/Test/TestSketcherAddArc.py
src/PythonAPI/Test/TestSketcherAddPoint.py
src/PythonAPI/model/__init__.py
src/PythonAPI/model/errors.py
src/PythonAPI/model/roots.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 1b64c4465e5b8069728125b151f6c503185f4599..22c43b8262c0ebb28f0e12b36cb021f665873c73 100644 (file)
@@ -30,5 +30,4 @@ class SketcherAddArc(SketcherTestCase):
         
     
 if __name__ == "__main__":
-    suite = unittest.TestLoader().loadTestsFromTestCase(SketcherAddArc)
-    unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
+    unittest.main(verbosity=2)
\ No newline at end of file
index 783f8c17bb854129a2023d265aff500373e17ffa..e7abc535f9f46abd723657c6f18f3e9455e7e9a4 100644 (file)
@@ -3,7 +3,7 @@ import model
 from TestSketcher import SketcherTestCase
 
 class SketcherAddPoint(SketcherTestCase):    
-    def runTest(self):
+    def test_add_point(self):
         point = self.sketch.addPoint(0, 1)
         model.do()
         self.assertEqual(point.pointData().x(), 0.0)        
@@ -11,4 +11,4 @@ class SketcherAddPoint(SketcherTestCase):
         
     
 if __name__ == "__main__":
-    unittest.main()
\ No newline at end of file
+    unittest.main(verbosity=2)
\ No newline at end of file
index 28faea654841064c4250224cc9a3d95cbb43fc23..0e28cac49678ed0ce53ad4af2630838a4322a7e8 100644 (file)
@@ -17,4 +17,5 @@ from boolean   import Intersection    as addIntersection
 
 # Custom exceptions
 
-from errors import WrongNumberOfArguments
\ No newline at end of file
+from errors import WrongNumberOfArguments
+from errors import FeatureInputInvalid
index b848f6058d7956f91afa338e6795ad436752b307..e10ec92eed826dc456a8a7b80908f816e0e89557 100644 (file)
@@ -8,6 +8,10 @@ class WrongNumberOfArguments(ModelError):
     """Exception raised when a wrong number of arguments is given."""
     pass
 
+class FeatureInputInvalid(ModelError):
+    """Exception raised if a feature input is invalid."""
+    pass
+
     #Attributes:
         #expr -- input expression in which the error occurred
         #msg  -- explanation of the error
index b721821b4abfd0dcd66e08c1f22a6b882a9572c2..0cf8ae2740fe8425cbb6d61a533a61e820f7b795 100644 (file)
@@ -29,7 +29,7 @@ class Feature(ModelAPI.ModelAPI_Feature):
 
 
 class Interface():
-    """Base class of hight level Python interfaces to features."""
+    """Base class of high level Python interfaces to features."""
 
     def __init__(self, feature):
         self._feature = feature
@@ -53,12 +53,12 @@ class Interface():
 
         return self._feature.__getattribute__(name)
 
-    def setRealInput (self, inputid, value):
+    def setRealInput(self, inputid, value):
         self._feature.data().real(inputid).setValue(value)
 
-    def areInputValid (self):
+    def areInputValid(self):
         validators = ModelAPI.ModelAPI_Session.get().validators()
         return validators.validate(self._feature)
 
-    def execute (self):
+    def execute(self):
         self._feature.execute()
index b025c4636160e0be7ef2ece7c6e1f3a47bec0eb8..e4d12e3bae84fe89ea70c97da5cfd239ce36447c 100644 (file)
@@ -2,11 +2,14 @@
 
 from GeomDataAPI import geomDataAPI_Point2D
 from model.errors import WrongNumberOfArguments
+from model.roots import Interface
 
-class Arc():
-    """Interface for editing a sketch arc feature."""
-    def __init__(self, arc_feature, *args):
-        self._feature = arc_feature
+class Arc(Interface):
+    """Interface to a sketch arc feature."""
+    def __init__(self, feature, *args):
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "SketchArc")
+        
         self._center = geomDataAPI_Point2D(
             self._feature.data().attribute("ArcCenter")
             )
index a6a0134cb50f3cd6d6654cc9a2408c38e2b56033..1fed091e642c495cf83f79f04f825b92948645e9 100644 (file)
@@ -1,19 +1,21 @@
 """Sketch circle feature interface."""
 
 from GeomDataAPI import geomDataAPI_Point2D
+from model.roots import Interface
 
-class Circle():
+class Circle(Interface):
     """Interface for circle feature data manipulation."""
-
-    def __init__(self, circle_feature, x, y, r):
-        self._feature = circle_feature
+    def __init__(self, feature, x, y, r):
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "SketchCircle")
+        
         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()
+        self.execute()
 
     def centerData(self):
         """Return center data."""
index 22c322f2c986b0520f85cf7f4e861835fd0fdc44..e4b0652f84c24a18fad31eaac446b06d2c8977f4 100644 (file)
@@ -1,15 +1,21 @@
 from GeomDataAPI import geomDataAPI_Point2D
+from model.roots import Interface
+from model.errors import WrongNumberOfArguments
 
-class Line():
+class Line(Interface):
     """Interface for editing of a sketch line feature."""
-    def __init__(self, line_feature, *args):
-        self._feature = line_feature
+    def __init__(self, feature, *args):
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "SketchLine")
+        
+        # Initialize attributes
         self._start_point = geomDataAPI_Point2D(
             self._feature.data().attribute("StartPoint")
             )
         self._end_point = geomDataAPI_Point2D(
             self._feature.data().attribute("EndPoint")
             )
+        # Set attribute values and execute
         if len(args) == 4:
             self.__createByCoordinates(*args)
         elif len(args) == 2:
@@ -17,7 +23,9 @@ class Line():
         elif len(args) == 1:
             self.__createByName(*args)
         else:
-            raise Exception("cannot create the Line")
+            raise WrongNumberOfArguments(
+                "Arc takes 1, 2 or 4 arguments (%s given)" % len(args)
+                )
 
     def __createByCoordinates(self, x1, y1, x2, y2):
         self._start_point.setValue(x1, y1)
index 5ba47e784330a1a633eb84bf647a4ebdf09dcc1c..69b9f88fcd8b3a0aafc64467a1a3845e1a01e50c 100644 (file)
@@ -1,16 +1,28 @@
 """Sketch point feature interface."""
 
 from GeomDataAPI import geomDataAPI_Point2D
+from model.roots import Interface
+from model.errors import FeatureInputInvalid
 
-class Point():
+class Point(Interface):
     """Interface on point feature for data manipulation."""
-    def __init__(self, point_feature, x, y):
-        self._point_feature = point_feature
+    def __init__(self, feature, x, y):
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "SketchPoint")
+        
+        # Initialize attributes of the feature
         self._point_data = geomDataAPI_Point2D(
-            self._point_feature.data().attribute("PointCoordinates")
+            self._feature.data().attribute("PointCoordinates")
             )
         self._point_data.setValue(x, y)
-        self._point_feature.execute()
+        
+        # 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 56b3d9c34ddab0f1b6606a6bd2581bcc75d07b47..f32185c709044c7fd2168104c14f0d00dd9cdb44 100644 (file)
@@ -10,6 +10,7 @@ from model.sketcher.point import Point
 from model.sketcher.line import Line
 from model.sketcher.circle import Circle
 from model.sketcher.arc import Arc
+from model.roots import Interface
 
 def addSketch(doc, plane):
     """Add a Sketch feature to the Part or PartSet and return an interface
@@ -22,7 +23,7 @@ def addSketch(doc, plane):
     feature = featureToCompositeFeature(doc.addFeature("Sketch"))
     return Sketch(feature, plane)
 
-class Sketch():
+class Sketch(Interface):
     """Interface on a Sketch feature."""
     def __init__(self, feature, plane):
         """Initialize a 2D Sketch on the given plane.
@@ -31,7 +32,9 @@ class Sketch():
         - a 3D axis system (geom.Ax3),
         - an existing face identified by its topological name.
         """
-        self._feature = feature
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == "Sketch")
+        
         # Entities used for building the result shape
         self._selection = None
         #   self.resultype ="Face" # Type of Sketch result