X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPythonAPI%2Fextension%2Fbox.py;h=5897da2c52486ecd5cc36a11a572113de470be78;hb=e4d6b1dd4f9e494bece0c16ca467c255247a62d6;hp=957da5412f570e9299d0dcdc12cb3e50e098d720;hpb=89ae310dae732ef819ebea43b33afd5d44facf73;p=modules%2Fshaper.git diff --git a/src/PythonAPI/extension/box.py b/src/PythonAPI/extension/box.py index 957da5412..5897da2c5 100644 --- a/src/PythonAPI/extension/box.py +++ b/src/PythonAPI/extension/box.py @@ -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