Salome HOME
Issue #1648: Dump Python in the High Level Parameterized Geometry API
[modules/shaper.git] / src / PythonAPI / extension / box.py
index 957da5412f570e9299d0dcdc12cb3e50e098d720..5897da2c52486ecd5cc36a11a572113de470be78 100644 (file)
@@ -3,21 +3,64 @@ Author: Daniel Brunier-Coulin
 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 """
 
-import modeler
+from model import Interface
 from macros.box.feature import BoxFeature as MY
 
 
-class Box(modeler.Interface):
-  """Executes the macro-feature Box.
-  """
-  def __init__(self, part, dx, dy, dz):
-    modeler.Interface.__init__(self, part, MY.ID())
+def addBoxScript(part, *args):
+    """Add Box feature to the part and return Box.
 
-    self.setRealInput( MY.WIDTH_ID(), dx )
-    self.setRealInput( MY.LENGTH_ID(), dy )
-    self.setRealInput( MY.HEIGHT_ID(), dz )
+    Pass all args to Box __init__ function.
+    """
+    feature = part.addFeature(MY.ID())
+    return Box(feature, *args)
 
-    if self.areInputValid():
-      self.execute()
-    else:
-      raise Exception("cannot make the Box")
\ No newline at end of file
+
+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 setWidth(self, width):
+        """B.setWidth(float) -- modify width attribute"""
+        self._width.setValue(width)
+        pass
+
+    def setLength(self, length):
+        """B.setLength(float) -- modify length attribute"""
+        self._length.setValue(length)
+        pass
+
+    def setHeight(self, height):
+        """B.setHeight(float) -- modify height attribute"""
+        self._height.setValue(height)
+        pass