Salome HOME
Fix #1596: export XAO
[modules/shaper.git] / src / PythonAPI / extension / box.py
index 9377fe345310b0b219bc0a51db86670c5048d0dc..9d4d66ce9822695874efedcfdbc0d093cf513dca 100644 (file)
@@ -3,26 +3,64 @@ Author: Daniel Brunier-Coulin
 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 """
 
-import model
+from model import Interface
 from macros.box.feature import BoxFeature as MY
 
 
-def addBox(self, container, *args):
-    feature = container.addFeature(MY.ID())
+def addBox(part, *args):
+    """Add Box feature to the part and return Box.
+
+    Pass all args to Box __init__ function.
+    """
+    feature = part.addFeature(MY.ID())
     return Box(feature, *args)
 
 
-class Box(model.Interface):
-    """Executes the macro-feature Box."""
+class Box(Interface):
+    """Executes the macro-feature Box.
+
+    Box(feature) -> feature interface without initialization
+    Extrusion(feature, dx, dy, dz) ->
+        feature interface initialized from arguments:
+        - dx, dy, dz -- box dimensions
+    """
+
+    def __init__(self, feature, *args):
+        """x.__init__(...) initializes x; see x.__class__.__doc__ for signature"""
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == MY.ID())
+
+        self._width = self._feature.real(MY.WIDTH_ID())
+        self._length = self._feature.real(MY.LENGTH_ID())
+        self._height = self._feature.real(MY.HEIGHT_ID())
+
+        assert(self._width)
+        assert(self._length)
+        assert(self._height)
+
+        if not args:
+            return
+
+        assert(len(args) == 3)
+        dx, dy, dz = args
+        self.setWidth(dx)
+        self.setLength(dy)
+        self.setHeight(dz)
+
+        self.execute()
+        pass
 
-    def __init__(self, feature, dx, dy, dz):
-        model.Interface.__init__(self, feature)
+    def setWidth(self, width):
+        """B.setWidth(float) -- modify width attribute"""
+        self._width.setValue(width)
+        pass
 
-        self.setRealInput(MY.WIDTH_ID(), dx)
-        self.setRealInput(MY.LENGTH_ID(), dy)
-        self.setRealInput(MY.HEIGHT_ID(), dz)
+    def setLength(self, length):
+        """B.setLength(float) -- modify length attribute"""
+        self._length.setValue(length)
+        pass
 
-        if self.areInputValid():
-            self.execute()
-        else:
-            raise Exception("cannot make the Box")
+    def setHeight(self, height):
+        """B.setHeight(float) -- modify height attribute"""
+        self._height.setValue(height)
+        pass