Copyright (C) 2014-20xx CEA/DEN, EDF R&D
"""
-import model
-import geom
+from salome.shaper import model
+from salome.shaper import geom
class BoxFeature(model.Feature):
@staticmethod
def ID():
"""Return Id of the feature."""
- return "Box"
+ return "Box_script"
@staticmethod
def WIDTH_ID():
p3 = geom.Pnt2d(1, 1)
p4 = geom.Pnt2d(1, 0)
- line = self.base.addPolygon(p1, p2, p3, p4)
+ line = model.addPolygon(self.base, 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.setFixed(line[0].startPoint())
+ self.base.setVertical(line[0])
# Setting the size of the base with default values
# Width
- self.width = self.base.setLength(line[0].result(), 50) # Keeps the constraint for edition
+ self.width = self.base.setLength(line[3], 50) # Keeps the constraint for edition
# Length
- self.length = self.base.setLength(line[3].result(), 50) # Keeps the constraint for edition
+ self.length = self.base.setLength(line[0], 50) # Keeps the constraint for edition
+
+ # Keeping the rectangle
+ self.base.setParallel(line[0], line[2])
+ self.base.setParallel(line[1], line[3])
+ self.base.setPerpendicular(line[0], line[3])
+
+ # execute sketch
+ model.do()
# Creating the extrusion (the box) at default size
# A box result
def execute(self):
"""F.execute() -- execute the feature"""
# Retrieving the user inputs
- width = self.getRealInput(self.WIDTH_ID())
- length = self.getRealInput(self.LENGTH_ID())
- height = self.getRealInput(self.HEIGHT_ID())
-
- width_text = self.getTextInput(self.WIDTH_ID())
- length_text = self.getTextInput(self.LENGTH_ID())
- height_text = self.getTextInput(self.HEIGHT_ID())
+ width = self.real(self.WIDTH_ID())
+ length = self.real(self.LENGTH_ID())
+ height = self.real(self.HEIGHT_ID())
# Editing the box
- self.base.setValue(self.width, width)
- self.base.setText(self.width, width_text)
-
- self.base.setValue(self.length, length)
- self.base.setText(self.length, length_text)
-
- self.box.setSize(height)
+ if width.text() == "":
+ self.base.setValue(self.width, width.value())
+ else:
+ self.base.setValue(self.width, width.text())
+
+ if length.text() == "":
+ self.base.setValue(self.length, length.value())
+ else:
+ self.base.setValue(self.length, length.text())
+
+ if (height.text() == ""):
+ self.box.setSize(height.value())
+ else:
+ self.box.setSize(height.text())
# Publishing the result: not needed for Macro feature
# self.addResult( self.box.result() )