24 __title__ =
"StirrupRebar" 25 __author__ =
"Amritpal Singh" 26 __url__ =
"https://www.freecadweb.org" 28 from PySide
import QtCore, QtGui
29 from Rebarfunc
import *
30 from PySide.QtCore
import QT_TRANSLATE_NOOP
31 from RebarDistribution
import runRebarDistribution, removeRebarDistribution
32 from PopUpImage
import showPopUpImageDialog
40 def getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, facenormal):
41 """ getpointsOfStirrup(FacePRM, LeftCover, RightCover, TopCover, BottomCover, BentAngle, BentFactor, Diameter, Rounding, FaceNormal): 42 Return the coordinates points of the Stirrup in the form of array.""" 43 angle = 180 - bentAngle
46 if round(facenormal[0])
in {1,-1}:
48 y1 = FacePRM[1][1] - FacePRM[0][0] / 2 + l_cover
49 z1 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover + tangent_part_length
50 y2 = FacePRM[1][1] - FacePRM[0][0] / 2 + l_cover
51 z2 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
52 y3 = FacePRM[1][1] + FacePRM[0][0] / 2 - r_cover
53 z3 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
54 y4 = FacePRM[1][1] + FacePRM[0][0] / 2 - r_cover
55 z4 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
56 y5 = FacePRM[1][1] - FacePRM[0][0] / 2 + l_cover - tangent_part_length
57 z5 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
58 side_length = abs(y5 - y4) - tangent_part_length
59 normal_dis = (diameter * (side_length + tangent_part_length)) / side_length
60 x2 = x1 - normal_dis / 4
61 x3 = x2 - normal_dis / 4
62 x4 = x3 - normal_dis / 4
63 x5 = x4 - normal_dis / 4
64 x0 = x1 + normal_dis / 4
65 y0 = y1 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(angle))
66 z0 = z1 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(angle))
67 x6 = x5 - normal_dis / 4
68 y6 = y5 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(90 - angle))
69 z6 = z5 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(90 - angle))
70 elif round(facenormal[1])
in {1,-1}:
71 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
73 z1 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover + tangent_part_length
74 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
75 z2 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
76 x3 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
77 z3 = FacePRM[1][2] - FacePRM[0][1] / 2 + b_cover
78 x4 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
79 z4 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
80 x5 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover - tangent_part_length
81 z5 = FacePRM[1][2] + FacePRM[0][1] / 2 - t_cover
82 side_length = abs(x5 - x4) - tangent_part_length
83 normal_dis = (diameter * (side_length + tangent_part_length)) / side_length
84 y2 = y1 - normal_dis / 4
85 y3 = y2 - normal_dis / 4
86 y4 = y3 - normal_dis / 4
87 y5 = y4 - normal_dis / 4
88 y0 = y1 + normal_dis / 4
89 x0 = x1 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(angle))
90 z0 = z1 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(angle))
91 x6 = x5 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(90 - angle))
92 y6 = y5 - normal_dis / 4
93 z6 = z5 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(90 - angle))
94 elif round(facenormal[2])
in {1,-1}:
95 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
96 y1 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover + tangent_part_length
98 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
99 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
100 x3 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
101 y3 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
102 x4 = FacePRM[1][0] + FacePRM[0][0] / 2 - r_cover
103 y4 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
104 x5 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover - tangent_part_length
105 y5 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
106 side_length = abs(x5 - x4) - tangent_part_length
107 normal_dis = (diameter * (side_length + tangent_part_length)) / side_length
108 z2 = z1 - normal_dis / 4
109 z3 = z2 - normal_dis / 4
110 z4 = z3 - normal_dis / 4
111 z5 = z4 - normal_dis / 4
112 z0 = z1 + normal_dis / 4
113 x0 = x1 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(angle))
114 y0 = y1 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(angle))
115 x6 = x5 + (tangent_length + bentFactor * diameter) * math.sin(math.radians(90 - angle))
116 y6 = y5 - (tangent_length + bentFactor * diameter) * math.cos(math.radians(90 - angle))
117 z6 = z5 - normal_dis / 4
118 return [FreeCAD.Vector(x0, y0, z0), FreeCAD.Vector(x1, y1, z1),\
119 FreeCAD.Vector(x2, y2, z2), FreeCAD.Vector(x3, y3, z3),\
120 FreeCAD.Vector(x4, y4, z4), FreeCAD.Vector(x5, y5, z5),\
121 FreeCAD.Vector(x6, y6, z6)]
127 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
131 self.
FaceName = Rebar.Base.Support[0][1][0]
133 self.
form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] +
".ui")
134 self.form.setWindowTitle(QtGui.QApplication.translate(
"RebarAddon",
"Stirrup Rebar",
None))
135 self.form.bentAngle.addItems([
"135",
"90"])
138 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0]+
"/icons/Stirrup.svg"))
141 self.form.PickSelectedFace.clicked.connect(
lambda:
getSelectedFace(self))
142 self.form.toolButton.setIcon(self.form.toolButton.style().standardIcon(QtGui.QStyle.SP_DialogHelpButton))
143 self.form.toolButton.clicked.connect(
lambda:
showPopUpImageDialog(os.path.split(os.path.abspath(__file__))[0] +
"/icons/StirrupDetailed.svg"))
147 return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Apply) | int(QtGui.QDialogButtonBox.Cancel)
150 if button == int(QtGui.QDialogButtonBox.Apply):
154 l_cover = self.form.l_sideCover.text()
155 l_cover = FreeCAD.Units.Quantity(l_cover).Value
156 r_cover = self.form.r_sideCover.text()
157 r_cover = FreeCAD.Units.Quantity(r_cover).Value
158 t_cover = self.form.t_sideCover.text()
159 t_cover = FreeCAD.Units.Quantity(t_cover).Value
160 b_cover = self.form.b_sideCover.text()
161 b_cover = FreeCAD.Units.Quantity(b_cover).Value
162 f_cover = self.form.frontCover.text()
163 f_cover = FreeCAD.Units.Quantity(f_cover).Value
164 diameter = self.form.diameter.text()
165 diameter = FreeCAD.Units.Quantity(diameter).Value
166 bentAngle = int(self.form.bentAngle.currentText())
167 bentFactor = self.form.bentFactor.value()
168 rounding = self.form.rounding.value()
169 amount_check = self.form.amount_radio.isChecked()
170 spacing_check = self.form.spacing_radio.isChecked()
173 amount = self.form.amount.value()
174 rebar =
makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter,\
177 spacing = self.form.spacing.text()
178 spacing = FreeCAD.Units.Quantity(spacing).Value
179 rebar =
makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter,\
183 amount = self.form.amount.value()
184 rebar =
editStirrup(self.
Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor,\
187 spacing = self.form.spacing.text()
188 spacing = FreeCAD.Units.Quantity(spacing).Value
189 rebar =
editStirrup(self.
Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor,\
193 FreeCAD.ActiveDocument.recompute()
195 if signal == int(QtGui.QDialogButtonBox.Apply):
198 FreeCADGui.Control.closeDialog(self)
201 self.form.spacing.setEnabled(
False)
202 self.form.amount.setEnabled(
True)
205 self.form.amount.setEnabled(
False)
206 self.form.spacing.setEnabled(
True)
209 def makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter, rounding,\
210 amount_spacing_check, amount_spacing_value, structure =
None, facename =
None):
211 """ makeStirrup(LeftCover, RightCover, TopCover, BottomCover, FrontCover, BentAngle, 212 BentFactor, Diameter, Rounding, AmountSpacingCheck, AmountSpacingValue, Structure, Facename): 213 Adds the Stirrup reinforcement bar to the selected structural object.""" 214 if not structure
and not facename:
215 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
216 structure = selected_obj.Object
217 facename = selected_obj.SubElementNames[0]
221 FaceNormal = face.normalAt(0,0)
224 FreeCAD.Console.PrintError(
"Cannot identified shape or from which base object sturctural element is derived\n")
227 points =
getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, FaceNormal)
229 line = Draft.makeWire(points, closed =
False, face =
True, support =
None)
231 line.Support = [(structure, facename)]
232 if amount_spacing_check:
233 rebar = Arch.makeRebar(structure, line, diameter, amount_spacing_value, f_cover)
235 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
236 rebar = Arch.makeRebar(structure, line, diameter,\
237 int((size - diameter) / amount_spacing_value), f_cover)
238 rebar.Direction = FaceNormal.negative()
239 rebar.Rounding = rounding
241 rebar.ViewObject.addProperty(
"App::PropertyString",
"RebarShape",
"RebarDialog",\
242 QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).RebarShape =
"Stirrup" 243 rebar.ViewObject.setEditorMode(
"RebarShape", 2)
244 rebar.addProperty(
"App::PropertyDistance",
"LeftCover",
"RebarDialog",\
245 QT_TRANSLATE_NOOP(
"App::Property",
"Left Side cover of rebar")).LeftCover = l_cover
246 rebar.setEditorMode(
"LeftCover", 2)
247 rebar.addProperty(
"App::PropertyDistance",
"RightCover",
"RebarDialog",\
248 QT_TRANSLATE_NOOP(
"App::Property",
"Right Side cover of rebar")).RightCover = r_cover
249 rebar.setEditorMode(
"RightCover", 2)
250 rebar.addProperty(
"App::PropertyDistance",
"TopCover",
"RebarDialog",\
251 QT_TRANSLATE_NOOP(
"App::Property",
"Top Side cover of rebar")).TopCover = t_cover
252 rebar.setEditorMode(
"TopCover", 2)
253 rebar.addProperty(
"App::PropertyDistance",
"BottomCover",
"RebarDialog",\
254 QT_TRANSLATE_NOOP(
"App::Property",
"Bottom Side cover of rebar")).BottomCover = b_cover
255 rebar.setEditorMode(
"BottomCover", 2)
256 rebar.addProperty(
"App::PropertyDistance",
"FrontCover",
"RebarDialog",\
257 QT_TRANSLATE_NOOP(
"App::Property",
"Top cover of rebar")).FrontCover = f_cover
258 rebar.setEditorMode(
"FrontCover", 2)
259 rebar.addProperty(
"App::PropertyInteger",
"BentAngle",
"RebarDialog",\
260 QT_TRANSLATE_NOOP(
"App::Property",
"Bent angle between at the end of rebar")).BentAngle = bentAngle
261 rebar.setEditorMode(
"BentAngle", 2)
262 rebar.addProperty(
"App::PropertyInteger",
"BentFactor",
"RebarDialog",\
263 QT_TRANSLATE_NOOP(
"App::Property",
"Bent Length is the equal to BentFactor * Diameter")).BentFactor = bentFactor
264 rebar.setEditorMode(
"BentFactor", 2)
265 rebar.addProperty(
"App::PropertyBool",
"AmountCheck",
"RebarDialog",\
266 QT_TRANSLATE_NOOP(
"App::Property",
"Amount radio button is checked")).AmountCheck
267 rebar.setEditorMode(
"AmountCheck", 2)
268 rebar.addProperty(
"App::PropertyDistance",
"TrueSpacing",
"RebarDialog",\
269 QT_TRANSLATE_NOOP(
"App::Property",
"Spacing between of rebars")).TrueSpacing = amount_spacing_value
270 rebar.setEditorMode(
"TrueSpacing", 2)
271 if amount_spacing_check:
272 rebar.AmountCheck =
True 274 rebar.AmountCheck =
False 275 rebar.TrueSpacing = amount_spacing_value
276 rebar.Label =
"Stirrup" 277 FreeCAD.ActiveDocument.recompute()
280 def editStirrup(Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter, rounding,\
281 amount_spacing_check, amount_spacing_value, structure =
None, facename =
None):
283 if structure
and facename:
284 sketch.Support = [(structure, facename)]
286 if not sketch.Support:
287 showWarning(
"You have checked remove external geometry of base sketchs when needed.\nTo unchecked Edit->Preferences->Arch.")
290 facename = sketch.Support[0][1][0]
291 structure = sketch.Support[0][0]
296 FaceNormal = face.normalAt(0, 0)
299 points =
getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, FaceNormal)
300 Rebar.Base.Points = points
301 FreeCAD.ActiveDocument.recompute()
302 Rebar.Direction = FaceNormal.negative()
303 Rebar.OffsetStart = f_cover
304 Rebar.OffsetEnd = f_cover
305 Rebar.BentAngle = bentAngle
306 Rebar.BentFactor = bentFactor
307 Rebar.Rounding = rounding
308 Rebar.Diameter = diameter
309 if amount_spacing_check:
310 Rebar.Amount = amount_spacing_value
311 FreeCAD.ActiveDocument.recompute()
312 Rebar.AmountCheck =
True 314 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
315 Rebar.Amount = int((size - diameter) / amount_spacing_value)
316 FreeCAD.ActiveDocument.recompute()
317 Rebar.AmountCheck =
False 318 Rebar.FrontCover = f_cover
319 Rebar.LeftCover = l_cover
320 Rebar.RightCover = r_cover
321 Rebar.TopCover = t_cover
322 Rebar.BottomCover = b_cover
323 Rebar.TrueSpacing = amount_spacing_value
324 FreeCAD.ActiveDocument.recompute()
328 FreeCADGui.Control.closeDialog()
330 obj.form.frontCover.setText(str(vobj.Object.FrontCover))
331 obj.form.l_sideCover.setText(str(vobj.Object.LeftCover))
332 obj.form.r_sideCover.setText(str(vobj.Object.RightCover))
333 obj.form.t_sideCover.setText(str(vobj.Object.TopCover))
334 obj.form.b_sideCover.setText(str(vobj.Object.BottomCover))
335 obj.form.diameter.setText(str(vobj.Object.Diameter))
336 obj.form.bentAngle.setCurrentIndex(obj.form.bentAngle.findText(str(vobj.Object.BentAngle)))
337 obj.form.bentFactor.setValue(vobj.Object.BentFactor)
338 obj.form.rounding.setValue(vobj.Object.Rounding)
339 if vobj.Object.AmountCheck:
340 obj.form.amount.setValue(vobj.Object.Amount)
342 obj.form.amount_radio.setChecked(
False)
343 obj.form.spacing_radio.setChecked(
True)
344 obj.form.amount.setDisabled(
True)
345 obj.form.spacing.setEnabled(
True)
346 obj.form.spacing.setText(str(vobj.Object.TrueSpacing))
348 FreeCADGui.Control.showDialog(obj)
def accept(self, signal=None)
def check_selected_face()
def extendedTangentLength(rounding, diameter, angle)
def __init__(self, Rebar=None)
def getSelectedFace(self)
def runRebarDistribution(self)
def removeRebarDistribution(self)
def editStirrup(Rebar, l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter, rounding, amount_spacing_check, amount_spacing_value, structure=None, facename=None)
def getParametersOfFace(structure, facename, sketch=True)
def amount_radio_clicked(self)
def clicked(self, button)
def makeStirrup(l_cover, r_cover, t_cover, b_cover, f_cover, bentAngle, bentFactor, diameter, rounding, amount_spacing_check, amount_spacing_value, structure=None, facename=None)
def getpointsOfStirrup(FacePRM, l_cover, r_cover, t_cover, b_cover, bentAngle, bentFactor, diameter, rounding, facenormal)
def extendedTangentPartLength(rounding, diameter, angle)
def spacing_radio_clicked(self)
def getStandardButtons(self)