Skip to content

Commit

Permalink
update code of Rebar distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
amrit3701 committed Jul 11, 2017
1 parent b743a21 commit 543aab2
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 66 deletions.
55 changes: 43 additions & 12 deletions RebarDistribution.py
Expand Up @@ -38,6 +38,7 @@ class _RebarDistributionDialog():
def __init__(self, Rebar):
self.form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] + ".ui")
self.form.setWindowTitle(QtGui.QApplication.translate("Arch", "Rebar Distribution", None))
self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] + "/icons/RebarDistribution.svg"))
self.Rebar = Rebar

def accept(self):
Expand Down Expand Up @@ -67,19 +68,49 @@ def setRebarDistribution(Rebar, amount1, spacing1, amount2, spacing2, amount3, s
facename = Rebar.Base.Support[0][1][0]
face = structure.Shape.Faces[int(facename[-1]) - 1]
size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
print size
if spacing1 and spacing2 and spacing3:
seg1_area = amount1 * spacing1 - spacing1 / 2
seg3_area = amount3 * spacing3 - spacing3 / 2
seg2_area = size - seg1_area - seg3_area - Rebar.OffsetStart.Value - Rebar.OffsetEnd.Value
actual_amount2 = math.ceil(seg2_area / spacing2)
actual_spacing2 = seg2_area / actual_amount2
CustomSpacing = str(amount1)+"@"+str(spacing1)+"+"+str(int(actual_amount2))+"@"+str(actual_spacing2)+"+"+str(amount3)+"@"+str(spacing3)
#print size
#print "amount1: ", amount1
#print "spacing1: ", spacing1
#print "amount2: ", amount2
#print "spacing2: ", spacing2
#print "amount3: ", amount3
#print "spacing3: ", spacing3
seg1_area = amount1 * spacing1 - spacing1 / 2
seg3_area = amount3 * spacing3 - spacing3 / 2
seg2_area = size - seg1_area - seg3_area - Rebar.OffsetStart.Value - Rebar.OffsetEnd.Value
if spacing1 and spacing2 and spacing3 and amount1 and amount2 and amount3:
pass
else:
if spacing1 and spacing2 and spacing3:
amount2 = math.ceil(seg2_area / spacing2)
spacing2 = seg2_area / amount2
elif amount1 and amount2 and amount3:
spacing2 = math.floor(seg2_area / amount2)
CustomSpacing = str(amount1)+"@"+str(spacing1)+"+"+str(int(amount2))+"@"+str(spacing2)+"+"+str(amount3)+"@"+str(spacing3)
Rebar.CustomSpacing = CustomSpacing
print CustomSpacing
#print CustomSpacing
FreeCAD.ActiveDocument.recompute()

def getupleOfCustomSpacing(span_string):
""" gettupleOfCustomSpacing(span_string): This function take input
in specific syntax and return output in the form of list. For eg.
Input: "3@100+2@200+3@100"
Output: [(3, 100), (2, 200), (3, 100)]"""
import string
span_st = string.strip(span_string)
span_sp = string.split(span_st, '+')
index = 0
spacinglist = []
while index < len(span_sp):
# Find "@" recursively in span_sp array.
in_sp = string.split(span_sp[index], '@')
spacinglist.append((int(in_sp[0]),float(in_sp[1])))
index += 1
return spacinglist

def runRebarDistribution(Rebar):
dialog = _RebarDistributionDialog(Rebar)
dialog.setupUi()
dialog.form.exec_()

dialog = _RebarDistributionDialog(FreeCAD.ActiveDocument.Rebar)
dialog.setupUi()
dialog.form.exec_()
#runRebarDistribution(App.ActiveDocument.Rebar)
11 changes: 9 additions & 2 deletions RebarDistribution.ui
Expand Up @@ -37,6 +37,13 @@
</item>
</layout>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="image">
<property name="text">
<string>image</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
Expand All @@ -55,7 +62,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Amount</string>
<string>No. of rebars (n)</string>
</property>
</widget>
</item>
Expand All @@ -68,7 +75,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Spacing</string>
<string>Spacing (s)</string>
</property>
</widget>
</item>
Expand Down
36 changes: 18 additions & 18 deletions Stirrup.ui
Expand Up @@ -38,7 +38,7 @@
<item row="0" column="1">
<widget class="Gui::InputField" name="sideCover">
<property name="text">
<string>20 mm</string>
<string>20 mm </string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
Expand Down Expand Up @@ -187,22 +187,6 @@
</item>
</layout>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="image">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="heading">
<property name="font">
Expand All @@ -216,13 +200,29 @@
</property>
</widget>
</item>
<item row="4" column="0" alignment="Qt::AlignHCenter">
<item row="4" column="0">
<widget class="QPushButton" name="PickSelectedFace">
<property name="text">
<string>Pick Selected Face</string>
</property>
</widget>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="image">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="PickSelectedFaceLabel">
<property name="text">
Expand Down
3 changes: 3 additions & 0 deletions StraightRebar.py
Expand Up @@ -28,6 +28,7 @@
from PySide import QtCore, QtGui
from Rebarfunc import *
from PySide.QtCore import QT_TRANSLATE_NOOP
from RebarDistribution import runRebarDistribution
import FreeCAD
import FreeCADGui
import ArchCommands
Expand All @@ -50,6 +51,7 @@ def __init__(self, Rebar = None):
self.form.setWindowTitle(QtGui.QApplication.translate("Arch", "Straight Rebar", None))
self.form.amount_radio.clicked.connect(self.amount_radio_clicked)
self.form.spacing_radio.clicked.connect(self.spacing_radio_clicked)
self.form.customSpacing.clicked.connect(lambda: runRebarDistribution(Rebar))
self.form.PickSelectedFace.setCheckable(True)
self.form.PickSelectedFace.toggle()
self.form.PickSelectedFace.clicked.connect(lambda: getSelectedFace(self))
Expand Down Expand Up @@ -190,6 +192,7 @@ def editStraightRebar(Rebar, f_cover, b_cover, s_cover, diameter, amount_spacing
def editDialog(vobj):
FreeCADGui.Control.closeDialog()
obj = _StraightRebarTaskPanel(vobj.Object)
obj.form.customSpacing.setEnabled(True)
obj.form.frontCover.setText(str(vobj.Object.FrontCover))
obj.form.sideCover.setText(str(vobj.Object.SideCover))
obj.form.bottomCover.setText(str(vobj.Object.BottomCover))
Expand Down
78 changes: 44 additions & 34 deletions StraightRebar.ui
Expand Up @@ -23,35 +23,6 @@
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" 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="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="image">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
Expand Down Expand Up @@ -182,7 +153,7 @@
<item row="3" column="1">
<widget class="Gui::InputField" name="diameter">
<property name="text">
<string>8 mm</string>
<string>8</string>
</property>
<property name="unit" stdset="0">
<string notr="true"/>
Expand All @@ -191,7 +162,43 @@
</item>
</layout>
</item>
<item row="4" column="0" alignment="Qt::AlignHCenter">
<item row="0" column="0" alignment="Qt::AlignHCenter">
<widget class="QLabel" name="image">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" 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="4" column="0">
<widget class="QLabel" name="PickSelectedFaceLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0" alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="PickSelectedFace">
<property name="enabled">
<bool>true</bool>
Expand All @@ -204,10 +211,13 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="PickSelectedFaceLabel">
<item row="3" column="0" alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="customSpacing">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
<string>Custom Spacing</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 543aab2

Please sign in to comment.