Skip to content

Commit

Permalink
completed stirrup
Browse files Browse the repository at this point in the history
  • Loading branch information
amrit3701 committed Jun 30, 2017
1 parent 1a45628 commit 660cd71
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 74 deletions.
25 changes: 22 additions & 3 deletions RebarTools.py
Expand Up @@ -5,7 +5,7 @@
class StraightRebarTool:

def GetResources(self):
return {'Pixmap' : os.path.split(os.path.abspath(__file__))[0]+'/icons/StraightRebar.svg',
return {'Pixmap' : os.path.split(os.path.abspath(__file__))[0]+'/icons/dropdown_list/StraightRebar.svg',
'MenuText': QT_TRANSLATE_NOOP("Arch_Rebar_Straight", "Straight Rebar"),
'ToolTip' : QT_TRANSLATE_NOOP("Arch_Rebar_Straight", "Creates a Striaght bar reinforcement from the selected face of the Structural element.")}

Expand All @@ -23,7 +23,7 @@ def Activated(self):
class UShapeRebarTool:

def GetResources(self):
return {'Pixmap' : os.path.split(os.path.abspath(__file__))[0]+'/icons/UShapeRebar.svg',
return {'Pixmap' : os.path.split(os.path.abspath(__file__))[0]+'/icons/dropdown_list/UShapeRebar.svg',
'MenuText': QT_TRANSLATE_NOOP("Arch_Rebar_UShape", "U-Shape Rebar"),
'ToolTip' : QT_TRANSLATE_NOOP("Arch_Rebar_UShape", "Creates a U-Shape bar reinforcement from the selected face of the Structural element.")}

Expand All @@ -38,8 +38,27 @@ def Activated(self):
# Call to CommandUShaepRebar() function
UShapeRebar.CommandUShapeRebar()

class StirrupTool:

def GetResources(self):
return {#'Pixmap' : os.path.split(os.path.abspath(__file__))[0]+'/icons/dropdown_list/StraightRebar.svg',
'MenuText': QT_TRANSLATE_NOOP("Arch_Rebar_Stirrup", "Stirrup"),
'ToolTip' : QT_TRANSLATE_NOOP("Arch_Rebar_Stirrup", "Creates a Stirrup bar reinforcement from the selected face of the Structural element.")}

def IsActive(self):
if FreeCADGui.ActiveDocument:
return True
else:
return False

def Activated(self):
import Stirrup
# Call to CommandStirrup() function
Stirrup.CommandStirrup()

FreeCADGui.addCommand('Arch_Rebar_Straight', StraightRebarTool())
FreeCADGui.addCommand('Arch_Rebar_UShape', UShapeRebarTool())
FreeCADGui.addCommand('Arch_Rebar_Stirrup', StirrupTool())

# List of all rebar commands
RebarCommands = ["Arch_Rebar_Straight", "Arch_Rebar_UShape"]
RebarCommands = ["Arch_Rebar_Straight", "Arch_Rebar_UShape", "Arch_Rebar_Stirrup"]
12 changes: 12 additions & 0 deletions Rebarfunc.py
Expand Up @@ -140,6 +140,18 @@ def getParametersOfFace(obj, selected_face, sketch=True):
return [(facelength, facewidth), center_of_mass]
return [(facelength, facewidth), (x, y)]

def extendedTangentPartLength(rounding, diameter, angle):
radius = rounding*diameter
x1 = radius/math.tan(math.radians(angle))
x2 = radius/math.cos(math.radians(90-angle))-radius
return x1+x2

def extendedTangentLength(rounding, diameter, angle):
radius = rounding*diameter
x1 = radius/math.sin(math.radians(angle))
x2 = radius*math.tan(math.radians(90-angle))
return x1+x2

def showWarning(message):
""" showWarning(message): This function is used to produce warning
message for the user."""
Expand Down
137 changes: 84 additions & 53 deletions Stirrup.py
Expand Up @@ -4,12 +4,36 @@
import FreeCAD, FreeCADGui, os, sys
import math

def getpointsOfStirrup(FacePRM, s_cover, bent_factor, diameter, rounding, facenormal):
FreeCAD.Console.PrintMessage("diameter: "+str(diameter)+" rounding: "+str(rounding)+"\n")
if round(facenormal[1]) in {1,-1}:
def getpointsOfStirrup(FacePRM, s_cover, bentAngle, diameter, rounding, facenormal):
angle = 180 - bentAngle
tangent_part_length = extendedTangentPartLength(rounding, diameter, angle)
tangent_length = extendedTangentLength(rounding, diameter, angle)
if round(facenormal[0]) in {1,-1}:
x1 = FacePRM[1][0]
y1 = FacePRM[1][1] - FacePRM[0][0]/2 + s_cover
z1 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover + tangent_part_length
x2 = x1 - diameter/4
y2 = FacePRM[1][1] - FacePRM[0][0]/2 + s_cover
z2 = FacePRM[1][2] - FacePRM[0][1]/2 + s_cover
x3 = x2 - diameter/4
y3 = FacePRM[1][1] + FacePRM[0][0]/2 - s_cover
z3 = FacePRM[1][2] - FacePRM[0][1]/2 + s_cover
x4 = x3 - diameter/4
y4 = FacePRM[1][1] + FacePRM[0][0]/2 - s_cover
z4 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover
x5 = x4 - diameter/4
y5 = FacePRM[1][1] - FacePRM[0][0]/2 + s_cover - tangent_part_length
z5 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover
x0 = x1
y0 = y1 + (tangent_length+4*diameter)* math.sin(math.radians(angle))
z0 = z1 - (tangent_length+4*diameter) * math.cos(math.radians(angle))
x6 = x5
y6 = y5 + (tangent_length+4*diameter) * math.sin(math.radians(90-angle))
z6 = z5 - (tangent_length+4*diameter) * math.cos(math.radians(90-angle))
elif round(facenormal[1]) in {1,-1}:
x1 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover
y1 = FacePRM[1][1]
z1 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover + 1.4*diameter*rounding
z1 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover + tangent_part_length
x2 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover
y2 = y1 - diameter/4
z2 = FacePRM[1][2] - FacePRM[0][1]/2 + s_cover
Expand All @@ -19,24 +43,47 @@ def getpointsOfStirrup(FacePRM, s_cover, bent_factor, diameter, rounding, faceno
x4 = FacePRM[1][0] + FacePRM[0][0]/2 - s_cover
y4 = y3 - diameter/4
z4 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover
x5 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover - 1.4*diameter*rounding
x5 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover - tangent_part_length
y5 = y4 - diameter/4
z5 = FacePRM[1][2] + FacePRM[0][1]/2 - s_cover
x0 = x1 + 10 * diameter * math.sin(math.radians(45))
x0 = x1 + (tangent_length+4*diameter)* math.sin(math.radians(angle))
y0 = y1
z0 = z1 - 10 * diameter * math.cos(math.radians(45))
x6 = x5 + 10 * diameter * math.sin(math.radians(45))
z0 = z1 - (tangent_length+4*diameter) * math.cos(math.radians(angle))
x6 = x5 + (tangent_length+4*diameter) * math.sin(math.radians(90-angle))
y6 = y5
z6 = z5 - 10 * diameter * math.cos(math.radians(45))
return [FreeCAD.Vector(x0, y0, z0), FreeCAD.Vector(x1, y1, z1),\
FreeCAD.Vector(x2, y2, z2), FreeCAD.Vector(x3, y3, z3),\
FreeCAD.Vector(x4, y4, z4), FreeCAD.Vector(x5, y5, z5),\
FreeCAD.Vector(x6, y6, z6)]
z6 = z5 - (tangent_length+4*diameter) * math.cos(math.radians(90-angle))
elif round(facenormal[2]) in {1,-1}:
x1 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover
y1 = FacePRM[1][1] + FacePRM[0][1]/2 - s_cover + tangent_part_length
z1 = FacePRM[1][2]
x2 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover
y2 = FacePRM[1][1] - FacePRM[0][1]/2 + s_cover
z2 = z1 - diameter/4
x3 = FacePRM[1][0] + FacePRM[0][0]/2 - s_cover
y3 = FacePRM[1][1] - FacePRM[0][1]/2 + s_cover
z3 = z2 - diameter/4
x4 = FacePRM[1][0] + FacePRM[0][0]/2 - s_cover
y4 = FacePRM[1][1] + FacePRM[0][1]/2 - s_cover
z4 = z3 - diameter/4
x5 = FacePRM[1][0] - FacePRM[0][0]/2 + s_cover - tangent_part_length
y5 = FacePRM[1][1] + FacePRM[0][1]/2 - s_cover
z5 = z4 - diameter/4
x0 = x1 + (tangent_length+4*diameter)* math.sin(math.radians(angle))
y0 = y1 - (tangent_length+4*diameter) * math.cos(math.radians(angle))
z0 = z1
x6 = x5 + (tangent_length+4*diameter) * math.sin(math.radians(90-angle))
y6 = y5 - (tangent_length+4*diameter) * math.cos(math.radians(90-angle))
z6 = z5
return [FreeCAD.Vector(x0, y0, z0), FreeCAD.Vector(x1, y1, z1),\
FreeCAD.Vector(x2, y2, z2), FreeCAD.Vector(x3, y3, z3),\
FreeCAD.Vector(x4, y4, z4), FreeCAD.Vector(x5, y5, z5),\
FreeCAD.Vector(x6, y6, z6)]

class _StirrupTaskPanel:
def __init__(self, Rebar = None):
self.form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0]+".ui")
self.form.setWindowTitle(QtGui.QApplication.translate("Arch", "Stirrup Rebar", None))
self.form.bentAngle.addItems(["135","90"])
self.form.amount_radio.clicked.connect(self.amount_radio_clicked)
self.form.spacing_radio.clicked.connect(self.spacing_radio_clicked)
#self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0]+"/icons/UShapeRebar.svg"))
Expand All @@ -50,29 +97,28 @@ def accept(self):
s_cover = FreeCAD.Units.Quantity(s_cover).Value
f_cover = self.form.frontCover.text()
f_cover = FreeCAD.Units.Quantity(f_cover).Value
bent_factor = self.form.bentFactor.value()
diameter = self.form.diameter.text()
diameter = FreeCAD.Units.Quantity(diameter).Value
bentAngle = int(self.form.bentAngle.currentText())
rounding = self.form.rounding.value()
FreeCAD.Console.PrintMessage("hfhh: "+str(rounding)+" "+str(type(rounding))+"\n")
amount_check = self.form.amount_radio.isChecked()
spacing_check = self.form.spacing_radio.isChecked()
if not self.Rebar:
if amount_check == True:
amount = self.form.amount.value()
makeStirrup(s_cover, f_cover, bent_factor, diameter, rounding, True, amount)
makeStirrup(s_cover, f_cover, bentAngle, diameter, rounding, True, amount)
elif spacing_check == True:
spacing = self.form.spacing.text()
spacing = FreeCAD.Units.Quantity(spacing).Value
makeStirrup(s_cover, f_cover, bent_factor, diameter, rounding, False, spacing)
makeStirrup(s_cover, f_cover, bentAngle, diameter, rounding, False, spacing)
else:
if amount_check == True:
amount = self.form.amount.value()
editStirrup(self.Rebar, s_cover, f_cover, bent_factor, diameter, rounding, True, amount)
editStirrup(self.Rebar, s_cover, f_cover, bentAngle, diameter, rounding, True, amount)
elif spacing_check == True:
spacing = self.form.spacing.text()
spacing = FreeCAD.Units.Quantity(spacing).Value
editStirrup(self.Rebar, s_cover, f_cover, bent_factor, diameter, rounding, False, spacing)
editStirrup(self.Rebar, s_cover, f_cover, bentAngle, diameter, rounding, False, spacing)
FreeCAD.Console.PrintMessage("Done!\n")
FreeCADGui.Control.closeDialog(self)

Expand All @@ -85,10 +131,9 @@ def spacing_radio_clicked(self):
self.form.spacing.setEnabled(True)


def makeStirrup(s_cover, f_cover, bent_factor, diameter, rounding, amount_spacing_check, amount_spacing_value):
""" makeStirrup(f_cover, b_cover, s_cover, diameter, t_cover, rounding, rebarAlong, amount_spacing_check, amount_spacing_value):
Adds the U-Shape reinforcement bar to the selected structural object"""
FreeCAD.Console.PrintMessage(str(rounding)+" "+str(type(rounding))+"\n")
def makeStirrup(s_cover, f_cover, bentAngle, diameter, rounding, amount_spacing_check, amount_spacing_value):
""" makeStirrup(s_cover, f_cover, bentAngle, diameter, rounding, amount_spacing_check, amount_spacing_value):
Adds the Stirrup reinforcement bar to the selected structural object"""
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
StructurePRM = getTrueParametersOfStructure(selected_obj.Object)
FacePRM = getParametersOfFace(selected_obj.Object, selected_obj.SubObjects[0], False)
Expand All @@ -97,43 +142,29 @@ def makeStirrup(s_cover, f_cover, bent_factor, diameter, rounding, amount_spacin
if not FacePRM:
FreeCAD.Console.PrintError("Cannot identified shape or from which base object sturctural element is derived\n")
return
# Calculate the coordinate values of U-Shape rebar
FreeCAD.Console.PrintMessage("faceprm: "+str(FacePRM)+"\n")
#FreeCAD.Console.PrintMessage(str(FacePRM)+"\n")
points = getpointsOfStirrup(FacePRM, s_cover, bent_factor, diameter, rounding, FaceNormal)
FreeCAD.Console.PrintMessage("points: "+str(points)+"\n")
# Calculate the coordinate values of Stirrup
points = getpointsOfStirrup(FacePRM, s_cover, bentAngle, diameter, rounding, FaceNormal)
import Draft
line = Draft.makeWire(points,closed=False,face=True,support=None)
import Arch
# sketch = FreeCAD.activeDocument().addObject('Sketcher::SketchObject','Sketch')
# sketch.MapMode = "FlatFace"
line.Support = [(selected_obj.Object, selected_obj.SubElementNames[0])]
# FreeCAD.ActiveDocument.recompute()
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(x1, y1, 0), FreeCAD.Vector(x2, y2, z2)), False)
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(x2, y2, z2), FreeCAD.Vector(x3, y3, z3)), False)
# import Sketcher
# sketch.addConstraint(Sketcher.Constraint('Coincident',0,2,1,1))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(x3, y3, z3), FreeCAD.Vector(x4, y4, z4)), False)
# sketch.addConstraint(Sketcher.Constraint('Coincident',1,2,2,1))
# sketch.addGeometry(Part.LineSegment(FreeCAD.Vector(x4, y4, z4), FreeCAD.Vector(x1, y1, z4)), False)
if amount_spacing_check == True:
rebar = Arch.makeRebar(selected_obj.Object, line, diameter, amount_spacing_value, f_cover)
rebar.Direction = FaceNormal.negative()
FreeCAD.ActiveDocument.recompute()
# else:
# rebar = Arch.makeRebar(selected_obj.Object, sketch, diameter, int((StructurePRM[1]-diameter)/amount_spacing_value), f_cover)
else:
rebar = Arch.makeRebar(selected_obj.Object, line, diameter, int((StructurePRM[1]-diameter)/amount_spacing_value), f_cover)
rebar.Direction = FaceNormal.negative()
rebar.Rounding = rounding
# # Adds properties to the rebar object
# Adds properties to the rebar object
rebar.ViewObject.addProperty("App::PropertyString","RebarShape","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Shape of rebar")).RebarShape = "Stirrup"
rebar.ViewObject.setEditorMode("RebarShape",2)
rebar.addProperty("App::PropertyDistance","SideCover","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Side cover of rebar")).SideCover = s_cover
rebar.setEditorMode("SideCover",2)
rebar.addProperty("App::PropertyDistance","FrontCover","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Top cover of rebar")).FrontCover = f_cover
rebar.setEditorMode("FrontCover",2)
rebar.addProperty("App::PropertyInteger","BentAngle","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Bent angle between at the end of rebar")).BentAngle = bentAngle
rebar.setEditorMode("BentAngle",2)
rebar.addProperty("App::PropertyInteger","TrueRounding","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Bottom cover of rebar")).TrueRounding = rounding
rebar.setEditorMode("TrueRounding",2)
rebar.addProperty("App::PropertyInteger","BentFactor","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Bottom cover of rebar")).BentFactor = bent_factor
rebar.setEditorMode("BentFactor",2)
rebar.addProperty("App::PropertyBool","AmountCheck","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Amount radio button is checked")).AmountCheck
rebar.setEditorMode("AmountCheck",2)
rebar.addProperty("App::PropertyDistance","TrueSpacing","RebarDialog",QT_TRANSLATE_NOOP("App::Property","Spacing between of rebars")).TrueSpacing = amount_spacing_value
Expand All @@ -145,7 +176,7 @@ def makeStirrup(s_cover, f_cover, bent_factor, diameter, rounding, amount_spacin
rebar.TrueSpacing = amount_spacing_value
FreeCAD.ActiveDocument.recompute()

def editStirrup(Rebar, s_cover, f_cover, bent_factor, diameter, rounding, amount_spacing_check, amount_spacing_value):
def editStirrup(Rebar, s_cover, f_cover, bentAngle, diameter, rounding, amount_spacing_check, amount_spacing_value):
sketch = Rebar.Base
# Check if sketch support is empty.
if not sketch.Support:
Expand All @@ -162,11 +193,12 @@ def editStirrup(Rebar, s_cover, f_cover, bent_factor, diameter, rounding, amount
FaceNormal = face.Placement.Rotation.inverted().multVec(FaceNormal)

# Calculate the coordinates value of U-Shape rebar
points = getpointsOfStirrup(FacePRM, s_cover, bent_factor, diameter, rounding, FaceNormal)
points = getpointsOfStirrup(FacePRM, s_cover, bentAngle, diameter, rounding, FaceNormal)
Rebar.Base.Points = points
FreeCAD.ActiveDocument.recompute()
Rebar.OffsetStart = f_cover
Rebar.OffsetEnd = f_cover
Rebar.BentAngle = bentAngle
Rebar.Rounding = rounding
Rebar.Diameter = diameter
if amount_spacing_check == True:
Expand All @@ -180,7 +212,6 @@ def editStirrup(Rebar, s_cover, f_cover, bent_factor, diameter, rounding, amount
Rebar.FrontCover = f_cover
Rebar.SideCover = s_cover
Rebar.TrueRounding = rounding
Rebar.BentFactor = bent_factor
Rebar.TrueSpacing = amount_spacing_value
FreeCAD.ActiveDocument.recompute()

Expand All @@ -190,8 +221,8 @@ def editDialog(vobj):
obj.form.frontCover.setText(str(vobj.Object.FrontCover))
obj.form.sideCover.setText(str(vobj.Object.SideCover))
obj.form.diameter.setText(str(vobj.Object.Diameter))
obj.form.bentAngle.setCurrentIndex(obj.form.bentAngle.findText(str(vobj.Object.BentAngle)))
obj.form.rounding.setValue(vobj.Object.TrueRounding)
obj.form.bentFactor.setValue(vobj.Object.BentFactor)
if vobj.Object.AmountCheck == True:
obj.form.amount.setValue(vobj.Object.Amount)
else:
Expand All @@ -202,7 +233,7 @@ def editDialog(vobj):
obj.form.spacing.setText(str(vobj.Object.TrueSpacing))
FreeCADGui.Control.showDialog(obj)

#def CommandUShapeRebar():
# selected_obj = check_selected_face()
# if selected_obj:
FreeCADGui.Control.showDialog(_StirrupTaskPanel())
def CommandStirrup():
selected_obj = check_selected_face()
if selected_obj:
FreeCADGui.Control.showDialog(_StirrupTaskPanel())

0 comments on commit 660cd71

Please sign in to comment.