Skip to content
Permalink
Browse files

update makeStraightRebar() and use FreeCAD widgets

  • Loading branch information...
amrit3701 committed Jun 5, 2017
1 parent aaee021 commit 21c427118a7e502a9a04240fe8ea10661ff45794
Showing with 141 additions and 88 deletions.
  1. +93 −56 StraightRebar.ui
  2. +48 −32 TaskPanelStraightRebar.py
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>206</width>
<height>343</height>
<width>197</width>
<height>316</height>
</rect>
</property>
<property name="windowTitle">
@@ -23,20 +23,7 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="heading">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Fill all the values</string>
</property>
</widget>
</item>
<item row="2" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<item row="3" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QPushButton" name="submit">
<property name="enabled">
<bool>true</bool>
@@ -55,108 +42,158 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="heading">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Fill all the values</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QFormLayout" name="formLayout">
<item row="1" column="0">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="frontCoverLabel">
<property name="text">
<string>Front Cover</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="frontCover"/>
<item row="0" column="1">
<widget class="Gui::InputField" name="frontCover">
<property name="text">
<string>0 mm</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="sideCoverLabel">
<property name="text">
<string>Side Cover</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="sideCover"/>
<item row="1" column="1">
<widget class="Gui::InputField" name="sideCover">
<property name="text">
<string>0 mm</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="bottomCoverLabel">
<property name="text">
<string>Bottom Cover</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="bottomCover"/>
<item row="2" column="1">
<widget class="Gui::InputField" name="bottomCover">
<property name="text">
<string>0 mm</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="3" column="0">
<widget class="QLabel" name="diameterLabel">
<property name="text">
<string>Diameter</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="diameter"/>
<item row="3" column="1">
<widget class="Gui::PrefSpinBox" name="diameter"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="amountLabel">
<property name="text">
<string>Amount</string>
</property>
</widget>
</item>
<item row="9" column="0">
<widget class="QLabel" name="spacingLabel">
<property name="text">
<string>Spacing</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="amount_radio">
<widget class="Gui::PrefRadioButton" name="amount_radio">
<property name="text">
<string>Amount</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="spacing_radio">
<widget class="Gui::PrefRadioButton" name="spacing_radio">
<property name="text">
<string>Spacing</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<widget class="QLabel" name="amountLabel">
<property name="text">
<string>Amount</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="amount">
<item row="9" column="1">
<widget class="Gui::InputField" name="spacing">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="spacingLabel">
<property name="text">
<string>Spacing</string>
<string>0 mm</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLineEdit" name="spacing">
<item row="7" column="1">
<widget class="Gui::PrefSpinBox" name="amount">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="rebarAlongLabel">
<property name="text">
<string>Rebar Along</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="rebarAlong"/>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>Gui::InputField</class>
<extends>QLineEdit</extends>
<header>Gui/InputField.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
<customwidget>
<class>Gui::PrefRadioButton</class>
<extends>QRadioButton</extends>
<header>Gui/PrefWidgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -4,7 +4,6 @@
class _StraightRebarTaskPanel:
def __init__(self):
self.form = FreeCADGui.PySideUic.loadUi("<path_of_StraightRebar.ui_file>")
self.form.rebarAlong.addItems(["Length", "Width"])
self.form.amount_radio.clicked.connect(self.amount_radio_clicked)
self.form.spacing_radio.clicked.connect(self.spacing_radio_clicked)
QtCore.QObject.connect(self.form.submit, QtCore.SIGNAL("clicked()"), self.accept)
@@ -14,19 +13,22 @@ def getStandardButtons(self):

def accept(self):
try:
f_cover = int(self.form.frontCover.text())
b_cover = int(self.form.bottomCover.text())
s_cover = int(self.form.sideCover.text())
rebarAlong = str(self.form.rebarAlong.currentText())
f_cover = self.form.frontCover.text()
f_cover = FreeCAD.Units.Quantity(f_cover).getValueAs("mm").Value
b_cover = self.form.bottomCover.text()
b_cover = FreeCAD.Units.Quantity(b_cover).getValueAs("mm").Value
s_cover = self.form.sideCover.text()
s_cover = FreeCAD.Units.Quantity(s_cover).getValueAs("mm").Value
diameter = self.form.diameter.value()
amount_check = self.form.amount_radio.isChecked()
spacing_check = self.form.spacing_radio.isChecked()
if amount_check == True:
amount = int(self.form.amount.text())
makeStraightRebar(f_cover, b_cover, s_cover, diameter, rebarAlong, True, amount)
amount = self.form.amount.value()
makeStraightRebar(f_cover, b_cover, s_cover, diameter, True, amount)
elif spacing_check == True:
spacing = int(self.form.spacing.text())
makeStraightRebar(f_cover, b_cover, s_cover, diameter, rebarAlong, False, spacing)
spacing = self.form.spacing.text()
spacing = FreeCAD.Units.Quantity(spacing).getValueAs("mm").Value
makeStraightRebar(f_cover, b_cover, s_cover, diameter, False, spacing)
FreeCAD.Console.PrintMessage("Done!\n")
self.form.hide()
except Exception as e: FreeCAD.Console.PrintMessage(str(e)+"\n")
@@ -40,34 +42,48 @@ def spacing_radio_clicked(self):
self.form.spacing.setEnabled(True)


def makeStraightRebar(f_cover, b_cover, s_cover, diameter, rebarAlong, amount_spacing_check, amount_spacing_value):
"""makeStraightRebar(f_cover, b_cover, s_cover, diameter, rebarAlong, amount_spacing_check, amount_spacing_value):
def makeStraightRebar(f_cover, b_cover, s_cover, diameter, amount_spacing_check, amount_spacing_value):
"""makeStraightRebar(f_cover, b_cover, s_cover, diameter, amount_spacing_check, amount_spacing_value):
Adds the straight reinforcement bar to the selected structural object"""
try:
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
length = int(selected_obj.Object.Length)
width = int(selected_obj.Object.Width)
height = int(selected_obj.Object.Height)
sketch = App.activeDocument().addObject('Sketcher::SketchObject','Sketch')
sketch.MapMode = "FlatFace"
if rebarAlong == "Length":
sketch.Support = [(selected_obj.Object, "Face1")]
sketch.addGeometry(Part.LineSegment(App.Vector(s_cover, -(height/2)+b_cover, 0), App.Vector(length-s_cover, -(height/2)+b_cover, 0)), False)
if amount_spacing_check == True:
structure = Arch.makeRebar(selected_obj.Object, sketch, diameter, amount_spacing_value, f_cover)
else:
structure = Arch.makeRebar(selected_obj.Object, sketch, diameter, (length-diameter)/amount_spacing_value, f_cover)
elif rebarAlong == "Width":
sketch.Support = [(selected_obj.Object, "Face6")]
sketch.addGeometry(Part.LineSegment(App.Vector(-(width/2)+s_cover, -(height/2)+b_cover, 0), App.Vector((width/2)-s_cover, -(height/2)+b_cover, 0)), False)
if amount_spacing_check == True:
structure = Arch.makeRebar(selected_obj.Object, sketch, diameter, amount_spacing_value, f_cover)
else:
structure = Arch.makeRebar(selected_obj.Object, sketch, diameter, (width-diameter)/amount_spacing_value, f_cover)
selected_face = selected_obj.SubObjects[0]
normal = selected_face.normalAt(0,0)
normal = selected_face.Placement.Rotation.inverted().multVec(normal)
center_of_mass = selected_face.CenterOfMass
# Set length and width of user selected face of structural element
flag = True
for i in range(len(normal)):
if round(normal[i]) == 0:
if flag and i == 0:
x = center_of_mass[i]
length = selected_obj.Object.Length.Value
flag = False
elif flag and i == 1:
x = center_of_mass[i]
length = selected_obj.Object.Width.Value
flag = False
if i == 1:
y = center_of_mass[i]
width = selected_obj.Object.Width.Value
elif i == 2:
y = center_of_mass[i]
width = selected_obj.Object.Height.Value
sketch = FreeCAD.activeDocument().addObject('Sketcher::SketchObject','Sketch')
sketch.MapMode = "FlatFace"
# Calculate the start and end points for staight line (x1, y2) and (x2, y2)
x1 = x - length/2 + s_cover
y1 = y - width/2 + b_cover
x2 = x - length/2 + length - s_cover
y2 = y - width/2 + b_cover
sketch.Support = [(selected_obj.Object, selected_obj.SubElementNames[0])]
sketch.addGeometry(Part.LineSegment(App.Vector(x1, y1, 0), App.Vector(x2, y2, 0)), False)
if amount_spacing_check == True:
structure = Arch.makeRebar(selected_obj.Object, sketch, diameter, amount_spacing_value, f_cover)
else:
structure = Arch.makeRebar(selected_obj.Object, sketch, diameter, int((width-diameter)/amount_spacing_value), f_cover)
FreeCAD.ActiveDocument.recompute()
except Exception as e: FreeCAD.Console.PrintMessage(str(e)+"\n")



if FreeCAD.GuiUp:
FreeCADGui.Control.showDialog(_StraightRebarTaskPanel())

0 comments on commit 21c4271

Please sign in to comment.
You can’t perform that action at this time.