24 __title__ =
"LShapeRebar" 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
41 """ getpointsOfLShapeRebar(FacePRM, LeftCover, RightCover, BottomCover, TopCover, Orientation): 42 Return points of the LShape rebar in the form of array for sketch. 43 It takes four different orientations input i.e. 'Bottom Left', 'Bottom Right ', 'Top Left', 'Top Right'. 45 if orientation ==
"Bottom Left":
46 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
47 y1 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
48 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
49 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
50 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
51 y3 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
52 elif orientation ==
"Bottom Right":
53 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
54 y1 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
55 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
56 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
57 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
58 y3 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
59 elif orientation ==
"Top Left":
60 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
61 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
62 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
63 y2 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
64 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
65 y3 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
66 elif orientation ==
"Top Right":
67 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
68 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
69 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
70 y2 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
71 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
72 y3 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
73 return [FreeCAD.Vector(x1, y1, 0), FreeCAD.Vector(x2, y2, 0),\
74 FreeCAD.Vector(x3, y3, 0)]
80 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
82 self.
FaceName = selected_obj.SubElementNames[0]
84 self.
FaceName = Rebar.Base.Support[0][1][0]
86 self.
form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] +
".ui")
87 self.form.setWindowTitle(QtGui.QApplication.translate(
"RebarAddon",
"L-Shape Rebar",
None))
88 self.form.orientation.addItems([
"Bottom Right",
"Bottom Left",
"Top Right",
"Top Left"])
93 self.form.PickSelectedFace.clicked.connect(
lambda:
getSelectedFace(self))
94 self.form.orientation.currentIndexChanged.connect(self.
getOrientation)
95 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/LShapeRebarBR.svg"))
96 self.form.toolButton.setIcon(self.form.toolButton.style().standardIcon(QtGui.QStyle.SP_DialogHelpButton))
97 self.form.toolButton.clicked.connect(
lambda:
showPopUpImageDialog(os.path.split(os.path.abspath(__file__))[0] +
"/icons/LShapeRebarDetailed.svg"))
101 orientation = self.form.orientation.currentText()
102 if orientation ==
"Bottom Right":
103 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/LShapeRebarBR.svg"))
104 elif orientation ==
"Bottom Left":
105 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/LShapeRebarBL.svg"))
106 elif orientation ==
"Top Right":
107 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/LShapeRebarTR.svg"))
109 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/LShapeRebarTL.svg"))
112 return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Apply) | int(QtGui.QDialogButtonBox.Cancel)
115 if button == int(QtGui.QDialogButtonBox.Apply):
119 f_cover = self.form.frontCover.text()
120 f_cover = FreeCAD.Units.Quantity(f_cover).Value
121 b_cover = self.form.bottomCover.text()
122 b_cover = FreeCAD.Units.Quantity(b_cover).Value
123 l_cover = self.form.l_sideCover.text()
124 l_cover = FreeCAD.Units.Quantity(l_cover).Value
125 r_cover = self.form.r_sideCover.text()
126 r_cover = FreeCAD.Units.Quantity(r_cover).Value
127 t_cover = self.form.topCover.text()
128 t_cover = FreeCAD.Units.Quantity(t_cover).Value
129 diameter = self.form.diameter.text()
130 diameter = FreeCAD.Units.Quantity(diameter).Value
131 rounding = self.form.rounding.value()
132 orientation = self.form.orientation.currentText()
133 amount_check = self.form.amount_radio.isChecked()
134 spacing_check = self.form.spacing_radio.isChecked()
137 amount = self.form.amount.value()
138 rebar =
makeLShapeRebar(f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding,
True, amount, orientation, self.
SelectedObj, self.
FaceName)
140 spacing = self.form.spacing.text()
141 spacing = FreeCAD.Units.Quantity(spacing).Value
142 rebar =
makeLShapeRebar(f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding,
False, spacing, orientation, self.
SelectedObj, self.
FaceName)
145 amount = self.form.amount.value()
146 rebar =
editLShapeRebar(self.
Rebar, f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding,
True, amount, orientation, self.
SelectedObj, self.
FaceName)
148 spacing = self.form.spacing.text()
149 spacing = FreeCAD.Units.Quantity(spacing).Value
150 rebar =
editLShapeRebar(self.
Rebar, f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding,
False, spacing, orientation, self.
SelectedObj, self.
FaceName)
153 FreeCAD.ActiveDocument.recompute()
155 if signal == int(QtGui.QDialogButtonBox.Apply):
158 FreeCADGui.Control.closeDialog(self)
161 self.form.spacing.setEnabled(
False)
162 self.form.amount.setEnabled(
True)
165 self.form.amount.setEnabled(
False)
166 self.form.spacing.setEnabled(
True)
169 def makeLShapeRebar(f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation = "Bottom Left", structure = None, facename = None):
170 """ makeLShapeRebar(FrontCover, BottomCover, LeftCover, RightCover, Diameter, TopCover, Rounding, AmountSpacingCheck, AmountSpacingValue, 171 Orientation, Structure, Facename): Adds the L-Shape reinforcement bar to the selected structural object. 172 It takes four different orientations input i.e. 'Bottom Left', 'Bottom Right ', 'Top Left', 'Top Right'. 174 if not structure
and not facename:
175 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
176 structure = selected_obj.Object
177 facename = selected_obj.SubElementNames[0]
182 FreeCAD.Console.PrintError(
"Cannot identified shape or from which base object sturctural element is derived\n")
188 sketch = FreeCAD.activeDocument().addObject(
'Sketcher::SketchObject',
'Sketch')
189 sketch.MapMode =
"FlatFace" 190 sketch.Support = [(structure, facename)]
191 FreeCAD.ActiveDocument.recompute()
192 sketch.addGeometry(Part.LineSegment(points[0], points[1]),
False)
193 sketch.addGeometry(Part.LineSegment(points[1], points[2]),
False)
195 if amount_spacing_check:
196 rebar = Arch.makeRebar(structure, sketch, diameter, amount_spacing_value, f_cover)
197 FreeCAD.ActiveDocument.recompute()
199 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
200 rebar = Arch.makeRebar(structure, sketch, diameter, int((size - diameter) / amount_spacing_value), f_cover)
201 rebar.Rounding = rounding
203 rebar.ViewObject.addProperty(
"App::PropertyString",
"RebarShape",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).RebarShape =
"LShapeRebar" 204 rebar.ViewObject.setEditorMode(
"RebarShape", 2)
205 rebar.addProperty(
"App::PropertyDistance",
"FrontCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Front cover of rebar")).FrontCover = f_cover
206 rebar.setEditorMode(
"FrontCover", 2)
207 rebar.addProperty(
"App::PropertyDistance",
"LeftCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Left Side cover of rebar")).LeftCover = l_cover
208 rebar.setEditorMode(
"LeftCover", 2)
209 rebar.addProperty(
"App::PropertyDistance",
"RightCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Right Side cover of rebar")).RightCover = r_cover
210 rebar.setEditorMode(
"RightCover", 2)
211 rebar.addProperty(
"App::PropertyDistance",
"BottomCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Bottom cover of rebar")).BottomCover = b_cover
212 rebar.setEditorMode(
"BottomCover", 2)
213 rebar.addProperty(
"App::PropertyBool",
"AmountCheck",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Amount radio button is checked")).AmountCheck
214 rebar.setEditorMode(
"AmountCheck", 2)
215 rebar.addProperty(
"App::PropertyDistance",
"TopCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Top cover of rebar")).TopCover = t_cover
216 rebar.setEditorMode(
"TopCover", 2)
217 rebar.addProperty(
"App::PropertyDistance",
"TrueSpacing",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Spacing between of rebars")).TrueSpacing = amount_spacing_value
218 rebar.addProperty(
"App::PropertyString",
"Orientation",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).Orientation = orientation
219 rebar.setEditorMode(
"Orientation", 2)
220 rebar.setEditorMode(
"TrueSpacing", 2)
221 if amount_spacing_check:
222 rebar.AmountCheck =
True 224 rebar.AmountCheck =
False 225 rebar.TrueSpacing = amount_spacing_value
226 rebar.Label =
"LShapeRebar" 227 FreeCAD.ActiveDocument.recompute()
230 def editLShapeRebar(Rebar, f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation, structure = None, facename = None):
232 if structure
and facename:
233 sketch.Support = [(structure, facename)]
235 if not sketch.Support:
236 showWarning(
"You have checked remove external geometry of base sketchs when needed.\nTo unchecked Edit->Preferences->Arch.")
239 facename = sketch.Support[0][1][0]
240 structure = sketch.Support[0][0]
247 sketch.movePoint(0, 1, points[0], 0)
248 FreeCAD.ActiveDocument.recompute()
249 sketch.movePoint(0, 2, points[1], 0)
250 FreeCAD.ActiveDocument.recompute()
251 sketch.movePoint(1, 1, points[1], 0)
252 FreeCAD.ActiveDocument.recompute()
253 sketch.movePoint(1, 2, points[2], 0)
254 FreeCAD.ActiveDocument.recompute()
255 Rebar.OffsetStart = f_cover
256 Rebar.OffsetEnd = f_cover
257 if amount_spacing_check:
258 Rebar.Amount = amount_spacing_value
259 FreeCAD.ActiveDocument.recompute()
260 Rebar.AmountCheck =
True 262 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
263 Rebar.Amount = int((size - diameter) / amount_spacing_value)
264 FreeCAD.ActiveDocument.recompute()
265 Rebar.AmountCheck =
False 266 Rebar.Diameter = diameter
267 Rebar.FrontCover = f_cover
268 Rebar.LeftCover = l_cover
269 Rebar.RightCover = r_cover
270 Rebar.BottomCover = b_cover
271 Rebar.TopCover = t_cover
272 Rebar.Rounding = rounding
273 Rebar.TrueSpacing = amount_spacing_value
274 Rebar.Orientation = orientation
275 FreeCAD.ActiveDocument.recompute()
279 FreeCADGui.Control.closeDialog()
281 obj.form.frontCover.setText(str(vobj.Object.FrontCover))
282 obj.form.l_sideCover.setText(str(vobj.Object.LeftCover))
283 obj.form.r_sideCover.setText(str(vobj.Object.RightCover))
284 obj.form.bottomCover.setText(str(vobj.Object.BottomCover))
285 obj.form.diameter.setText(str(vobj.Object.Diameter))
286 obj.form.topCover.setText(str(vobj.Object.TopCover))
287 obj.form.rounding.setValue(vobj.Object.Rounding)
288 obj.form.orientation.setCurrentIndex(obj.form.orientation.findText(str(vobj.Object.Orientation)))
289 if vobj.Object.AmountCheck:
290 obj.form.amount.setValue(vobj.Object.Amount)
292 obj.form.amount_radio.setChecked(
False)
293 obj.form.spacing_radio.setChecked(
True)
294 obj.form.amount.setDisabled(
True)
295 obj.form.spacing.setEnabled(
True)
296 obj.form.spacing.setText(str(vobj.Object.TrueSpacing))
298 FreeCADGui.Control.showDialog(obj)
def check_selected_face()
def accept(self, signal=None)
def editLShapeRebar(Rebar, f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation, structure=None, facename=None)
def amount_radio_clicked(self)
def getSelectedFace(self)
def runRebarDistribution(self)
def __init__(self, Rebar=None)
def getpointsOfLShapeRebar(FacePRM, l_cover, r_cover, b_cover, t_cover, orientation)
def removeRebarDistribution(self)
def spacing_radio_clicked(self)
def clicked(self, button)
def makeLShapeRebar(f_cover, b_cover, l_cover, r_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation="Bottom Left", structure=None, facename=None)
def getParametersOfFace(structure, facename, sketch=True)
def getStandardButtons(self)