]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Modify box macros and interface to match style and structure requirements.
authorspo <sergey.pokhodenko@opencascade.com>
Fri, 30 Oct 2015 12:21:27 +0000 (15:21 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Fri, 30 Oct 2015 13:42:53 +0000 (16:42 +0300)
src/PythonAPI/extension/box.py
src/PythonAddons/macros/box/feature.py

index 9377fe345310b0b219bc0a51db86670c5048d0dc..4cdfa75a2c870383449b54a616d130a8e2f1e7fa 100644 (file)
@@ -3,26 +3,50 @@ 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):
+def addBox(container, *args):
     feature = container.addFeature(MY.ID())
     return Box(feature, *args)
 
 
-class Box(model.Interface):
+class Box(Interface):
     """Executes the macro-feature Box."""
 
-    def __init__(self, feature, dx, dy, dz):
-        model.Interface.__init__(self, feature)
+    def __init__(self, feature, *args):
+        Interface.__init__(self, feature)
+        assert(self._feature.getKind() == MY.ID())
 
-        self.setRealInput(MY.WIDTH_ID(), dx)
-        self.setRealInput(MY.LENGTH_ID(), dy)
-        self.setRealInput(MY.HEIGHT_ID(), dz)
+        self._width = self._feature.real(MY.WIDTH_ID())
+        self._length = self._feature.real(MY.LENGTH_ID())
+        self._height = self._feature.real(MY.HEIGHT_ID())
 
-        if self.areInputValid():
-            self.execute()
-        else:
-            raise Exception("cannot make the Box")
+        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):
+        self._fill_attribute(self._width, width)
+        pass
+
+    def setLength(self, length):
+        self._fill_attribute(self._length, length)
+        pass
+
+    def setHeight(self, height):
+        self._fill_attribute(self._height, height)
+        pass
index d5d5e8e07c6efaa2bf603bb04e3a5cbf8e8b6adb..f160a396e52a233f49c8d353dd136203b4525e54 100644 (file)
@@ -3,88 +3,88 @@ Authors: Renaud Nedelec - Daniel Brunier-Coulin
 Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 """
 
-import modeler
+import model
 import geom
 
 
-class BoxFeature(modeler.Feature):
+class BoxFeature(model.Feature):
 
 
 # Initializations
 
-  def __init__(self):
-    modeler.Feature.__init__(self)
+    def __init__(self):
+        model.Feature.__init__(self)
 
-  @staticmethod
-  def ID():
-    return "Box"
+    @staticmethod
+    def ID():
+        return "Box"
 
-  @staticmethod
-  def WIDTH_ID():
-    return "width"
+    @staticmethod
+    def WIDTH_ID():
+        return "width"
 
-  @staticmethod
-  def LENGTH_ID():
-    return "length"
+    @staticmethod
+    def LENGTH_ID():
+        return "length"
 
-  @staticmethod
-  def HEIGHT_ID():
-    return "height"
+    @staticmethod
+    def HEIGHT_ID():
+        return "height"
+
+    def getKind(self):
+        return BoxFeature.ID()
 
-  def getKind(self):
-    return BoxFeature.ID()
 
-       
 # Creation of the box at default size
 
-  def initAttributes(self):
+    def initAttributes(self):
+
+        # Creating the input arguments of the feature
+        self.addRealInput(self.WIDTH_ID())
+        self.addRealInput(self.LENGTH_ID())
+        self.addRealInput(self.HEIGHT_ID())
 
-    # Creating the input arguments of the feature
-    self.addRealInput( self.WIDTH_ID() )
-    self.addRealInput( self.LENGTH_ID() )
-    self.addRealInput( self.HEIGHT_ID() )
+        # Creating the base of the box with unit values
+        mypart = model.activeDocument()
+        xoy = model.defaultPlane("XOY")
 
-    # Creating the base of the box with unit values
-    mypart = modeler.activeDocument()
-    xoy    = modeler.defaultPlane("XOY")
+        self.base = model.addSketch(mypart, xoy)
 
-    self.base = modeler.addSketch( mypart, xoy )
+        p1 = geom.Pnt2d(0, 0)
+        p2 = geom.Pnt2d(0, 1)
+        p3 = geom.Pnt2d(1, 1)
+        p4 = geom.Pnt2d(1, 0)
 
-    p1 = geom.Pnt2d( 0, 0 )
-    p2 = geom.Pnt2d( 0, 1 )
-    p3 = geom.Pnt2d( 1, 1 )
-    p4 = geom.Pnt2d( 1, 0 )
+        line = self.base.addPolygon(p1, p2, p3, p4)
 
-    line = self.base.addPolygon(p1, p2, p3, p4)
+        self.base.setParallel(line[0].result(), line[2].result())
+        self.base.setParallel(line[1].result(), line[3].result())
+        self.base.setPerpendicular(line[0].result(), line[3].result())
 
-    self.base.setParallel( line[0].result(), line[2].result() )
-    self.base.setParallel( line[1].result(), line[3].result() )
-    self.base.setPerpendicular( line[0].result(), line[3].result() )
+        # Setting the size of the base with default values
+        self.width = self.base.setLength(line[0].result(), 50)  # Keeps the constraint for edition
+        self.length = self.base.setLength(line[3].result(), 50)  # Keeps the constraint for edition
 
-    # Setting the size of the base with default values
-    self.width  = self.base.setLength( line[0].result(), 50 )   # Keeps the constraint for edition
-    self.length = self.base.setLength( line[3].result(), 50 )   # Keeps the constraint for edition
+        # Creating the extrusion (the box) at default size
+        self.box = model.addExtrusion(mypart, self.base.selectFace(), 50)
 
-    # Creating the extrusion (the box) at default size
-    self.box = modeler.addExtrusion( mypart, self.base.selectFace(), 50 )
 
-       
 # Edition of the box at user size
 
-  def execute(self):
-    # Retrieving the user inputs
-    width  = self.getRealInput( self.WIDTH_ID() )
-    length = self.getRealInput( self.LENGTH_ID() )
-    height = self.getRealInput( self.HEIGHT_ID() )
-
-    # Editing the box
-    self.base.setValue( self.width,  width )
-    self.base.setValue( self.length, length )
-    self.box.setSize( height )
-
-    # Publishing the result: not needed for Macro feature
-    #self.addResult( self.box.result() )
-  
-  def isMacro(self):
-    # Box feature is macro: removes itself on the creation transaction finish
-    return True
+    def execute(self):
+        # Retrieving the user inputs
+        width = self.getRealInput(self.WIDTH_ID())
+        length = self.getRealInput(self.LENGTH_ID())
+        height = self.getRealInput(self.HEIGHT_ID())
+
+        # Editing the box
+        self.base.setValue(self.width, width)
+        self.base.setValue(self.length, length)
+        self.box.setSize(height)
+
+        # Publishing the result: not needed for Macro feature
+        # self.addResult( self.box.result() )
+
+    def isMacro(self):
+        # Box feature is macro: removes itself on the creation transaction finish
+        return True