24 __title__ =
"StraightRebar" 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 """ getpointsOfStraightRebar(FacePRM, RightTopcover, LeftBottomcover, CoverAlong, Orientation): 42 Return points of the Straight rebar in the form of array for sketch. 44 Case I: When Orientation is 'Horizontal': 45 We have two option in CoverAlong i.e. 'Bottom Side' or 'Top Side' 46 Case II: When Orientation is 'Vertical': 47 We have two option in CoverAlong i.e. 'Left Side' or 'Right Side' 49 if orientation ==
"Horizontal":
50 if coverAlong[0] ==
"Bottom Side":
51 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + lb_cover
52 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + coverAlong[1]
53 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - rt_cover
54 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + coverAlong[1]
55 elif coverAlong[0] ==
"Top Side":
56 cover = FacePRM[0][1] - coverAlong[1]
57 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + lb_cover
58 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + cover
59 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - rt_cover
60 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + cover
61 elif orientation ==
"Vertical":
62 if coverAlong[0] ==
"Left Side":
63 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + coverAlong[1]
64 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + lb_cover
65 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + coverAlong[1]
66 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + FacePRM[0][1] - rt_cover
67 elif coverAlong[0] ==
"Right Side":
68 cover = FacePRM[0][0] - coverAlong[1]
69 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + cover
70 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + lb_cover
71 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + cover
72 y2 = FacePRM[1][1] - FacePRM[0][1] / 2 + FacePRM[0][1] - rt_cover
73 return [FreeCAD.Vector(x1, y1, 0), FreeCAD.Vector(x2, y2, 0)]
79 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
81 self.
FaceName = selected_obj.SubElementNames[0]
83 self.
FaceName = Rebar.Base.Support[0][1][0]
85 self.
form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] +
".ui")
86 self.form.setWindowTitle(QtGui.QApplication.translate(
"RebarAddon",
"Straight Rebar",
None))
87 self.form.orientation.addItems([
"Horizontal",
"Vertical"])
88 self.form.coverAlong.addItems([
"Bottom Side",
"Top Side"])
93 self.form.PickSelectedFace.setCheckable(
True)
94 self.form.PickSelectedFace.toggle()
95 self.form.PickSelectedFace.clicked.connect(
lambda:
getSelectedFace(self))
96 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/StraightRebarH.svg"))
99 self.form.toolButton.setIcon(self.form.toolButton.style().standardIcon(QtGui.QStyle.SP_DialogHelpButton))
100 self.form.toolButton.clicked.connect(
lambda:
showPopUpImageDialog(os.path.split(os.path.abspath(__file__))[0] +
"/icons/StraightRebarDetailed.svg"))
104 orientation = self.form.orientation.currentText()
105 if orientation ==
"Horizontal":
106 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/StraightRebarH.svg"))
107 self.form.r_sideCoverLabel.setText(
"Right Side Cover")
108 self.form.l_sideCoverLabel.setText(
"Left Side Cover")
109 self.form.coverAlong.clear()
110 self.form.coverAlong.addItems([
"Bottom Side",
"Top Side"])
112 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/StraightRebarV.svg"))
113 self.form.r_sideCoverLabel.setText(
"Top Side Cover")
114 self.form.l_sideCoverLabel.setText(
"Bottom Side Cover")
115 self.form.coverAlong.clear()
116 self.form.coverAlong.addItems([
"Right Side",
"Left Side"])
119 coverAlong = self.form.coverAlong.currentText()
120 if coverAlong ==
"Bottom Side":
121 self.form.bottomCoverLabel.setText(
"Bottom Cover")
122 elif coverAlong ==
"Top Side":
123 self.form.bottomCoverLabel.setText(
"Top Cover")
124 elif coverAlong ==
"Right Side":
125 self.form.bottomCoverLabel.setText(
"Right Cover")
127 self.form.bottomCoverLabel.setText(
"Left Cover")
130 return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Apply) | int(QtGui.QDialogButtonBox.Cancel)
133 if button == int(QtGui.QDialogButtonBox.Apply):
137 f_cover = self.form.frontCover.text()
138 f_cover = FreeCAD.Units.Quantity(f_cover).Value
139 cover = self.form.bottomCover.text()
140 cover = FreeCAD.Units.Quantity(cover).Value
141 lb_cover = self.form.l_sideCover.text()
142 lb_cover = FreeCAD.Units.Quantity(lb_cover).Value
143 rt_cover = self.form.r_sideCover.text()
144 rt_cover = FreeCAD.Units.Quantity(rt_cover).Value
145 orientation = self.form.orientation.currentText()
146 coverAlong = self.form.coverAlong.currentText()
147 diameter = self.form.diameter.text()
148 diameter = FreeCAD.Units.Quantity(diameter).Value
149 amount_check = self.form.amount_radio.isChecked()
150 spacing_check = self.form.spacing_radio.isChecked()
153 amount = self.form.amount.value()
154 rebar =
makeStraightRebar(f_cover, (coverAlong, cover), rt_cover, lb_cover, diameter,
True, amount, orientation, self.
SelectedObj, self.
FaceName)
156 spacing = self.form.spacing.text()
157 spacing = FreeCAD.Units.Quantity(spacing).Value
158 rebar =
makeStraightRebar(f_cover, (coverAlong, cover), rt_cover, lb_cover, diameter,
False, spacing, orientation, self.
SelectedObj, self.
FaceName)
161 amount = self.form.amount.value()
162 rebar =
editStraightRebar(self.
Rebar, f_cover, (coverAlong, cover), rt_cover, lb_cover, diameter,
True, amount, orientation, self.
SelectedObj, self.
FaceName)
164 spacing = self.form.spacing.text()
165 spacing = FreeCAD.Units.Quantity(spacing).Value
166 rebar =
editStraightRebar(self.
Rebar, f_cover, (coverAlong, cover), rt_cover, lb_cover, diameter,
False, spacing, orientation, self.
SelectedObj, self.
FaceName)
169 FreeCAD.ActiveDocument.recompute()
171 if signal == int(QtGui.QDialogButtonBox.Apply):
174 FreeCADGui.Control.closeDialog(self)
177 self.form.spacing.setEnabled(
False)
178 self.form.amount.setEnabled(
True)
181 self.form.amount.setEnabled(
False)
182 self.form.spacing.setEnabled(
True)
185 def makeStraightRebar(f_cover, coverAlong, rt_cover, lb_cover, diameter, amount_spacing_check, amount_spacing_value, orientation = "Horizontal", structure = None, facename = None):
186 """ Adds the straight reinforcement bar to the selected structural object. 188 Case I: When orientation of straight rebar is 'Horizontal': 189 makeStraightRebar(FrontCover, CoverAlong, RightCover, LeftCover, Diameter, AmountSpacingCheck, AmountSpacingValue, Orientation = "Horizontal", 191 Note: Type of CoverAlong argument is a tuple. Syntax: (<Along>, <Value>). Here we have horizontal orientation so we can pass Top Side 192 and Bottom Side to <Along> arguments. 193 For eg. ("Top Side", 20) and ("Bottom Side", 20) 195 Case II: When orientation of straight rebar is 'Vertical': 196 makeStraightRebar(FrontCover, CoverAlong, TopCover, BottomCover, Diameter, AmountSpacingCheck, AmountSpacingValue, Orientation = "Horizontal", 198 Note: Type of CoverAlong argument is a tuple. Syntax: (<Along>, <Value>). Here we have vertical orientation so we can pass Left Side 199 and Right Side to <Along> arguments. 200 For eg. ("Left Side", 20) and ("Right Side", 20) 202 if not structure
and not facename:
203 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
204 structure = selected_obj.Object
205 facename = selected_obj.SubElementNames[0]
210 FreeCAD.Console.PrintError(
"Cannot identified shape or from which base object sturctural element is derived\n")
216 sketch = FreeCAD.activeDocument().addObject(
'Sketcher::SketchObject',
'Sketch')
217 sketch.MapMode =
"FlatFace" 218 sketch.Support = [(structure, facename)]
219 FreeCAD.ActiveDocument.recompute()
220 sketch.addGeometry(Part.LineSegment(points[0], points[1]),
False)
221 if amount_spacing_check:
222 rebar = Arch.makeRebar(structure, sketch, diameter, amount_spacing_value, f_cover)
223 FreeCAD.ActiveDocument.recompute()
225 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
226 rebar = Arch.makeRebar(structure, sketch, diameter, int((size - diameter) / amount_spacing_value), f_cover)
228 rebar.ViewObject.addProperty(
"App::PropertyString",
"RebarShape",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).RebarShape =
"StraightRebar" 229 rebar.ViewObject.setEditorMode(
"RebarShape", 2)
230 rebar.addProperty(
"App::PropertyDistance",
"FrontCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Front cover of rebar")).FrontCover = f_cover
231 rebar.setEditorMode(
"FrontCover", 2)
232 rebar.addProperty(
"App::PropertyDistance",
"RightTopCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Right/Top Side cover of rebar")).RightTopCover = rt_cover
233 rebar.setEditorMode(
"RightTopCover", 2)
234 rebar.addProperty(
"App::PropertyDistance",
"LeftBottomCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Left/Bottom Side cover of rebar")).LeftBottomCover = lb_cover
235 rebar.setEditorMode(
"LeftBottomCover", 2)
236 rebar.addProperty(
"App::PropertyString",
"CoverAlong",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Cover along")).CoverAlong = coverAlong[0]
237 rebar.setEditorMode(
"CoverAlong", 2)
238 rebar.addProperty(
"App::PropertyDistance",
"Cover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Cover of rebar along user selected side")).Cover = coverAlong[1]
239 rebar.setEditorMode(
"Cover", 2)
240 rebar.addProperty(
"App::PropertyBool",
"AmountCheck",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Amount radio button is checked")).AmountCheck
241 rebar.setEditorMode(
"AmountCheck", 2)
242 rebar.addProperty(
"App::PropertyDistance",
"TrueSpacing",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Spacing between of rebars")).TrueSpacing = amount_spacing_value
243 rebar.setEditorMode(
"TrueSpacing", 2)
244 rebar.addProperty(
"App::PropertyString",
"Orientation",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).Orientation = orientation
245 rebar.setEditorMode(
"Orientation", 2)
246 if amount_spacing_check:
247 rebar.AmountCheck =
True 249 rebar.AmountCheck =
False 250 rebar.TrueSpacing = amount_spacing_value
251 rebar.Label =
"StraightRebar" 252 FreeCAD.ActiveDocument.recompute()
255 def editStraightRebar(Rebar, f_cover, coverAlong, rt_cover, lb_cover, diameter, amount_spacing_check, amount_spacing_value, orientation, structure = None, facename = None):
257 if structure
and facename:
258 sketch.Support = [(structure, facename)]
259 FreeCAD.ActiveDocument.recompute()
261 if not sketch.Support:
262 showWarning(
"You have checked remove external geometry of base sketchs when needed.\nTo unchecked Edit->Preferences->Arch.")
265 facename = sketch.Support[0][1][0]
266 structure = sketch.Support[0][0]
273 sketch.movePoint(0, 1, points[0], 0)
274 FreeCAD.ActiveDocument.recompute()
275 sketch.movePoint(0, 2, points[1], 0)
276 FreeCAD.ActiveDocument.recompute()
277 Rebar.OffsetStart = f_cover
278 Rebar.OffsetEnd = f_cover
279 if amount_spacing_check:
280 Rebar.Amount = amount_spacing_value
281 FreeCAD.ActiveDocument.recompute()
282 Rebar.AmountCheck =
True 284 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
285 Rebar.Amount = int((size - diameter) / amount_spacing_value)
286 FreeCAD.ActiveDocument.recompute()
287 Rebar.AmountCheck =
False 288 Rebar.FrontCover = f_cover
289 Rebar.RightTopCover = rt_cover
290 Rebar.LeftBottomCover = lb_cover
291 Rebar.CoverAlong = coverAlong[0]
292 Rebar.Cover = coverAlong[1]
293 Rebar.TrueSpacing = amount_spacing_value
294 Rebar.Diameter = diameter
295 Rebar.Orientation = orientation
296 FreeCAD.ActiveDocument.recompute()
300 FreeCADGui.Control.closeDialog()
302 obj.form.frontCover.setText(str(vobj.Object.FrontCover))
303 obj.form.r_sideCover.setText(str(vobj.Object.RightTopCover))
304 obj.form.l_sideCover.setText(str(vobj.Object.LeftBottomCover))
305 obj.form.bottomCover.setText(str(vobj.Object.Cover))
306 obj.form.diameter.setText(str(vobj.Object.Diameter))
307 obj.form.orientation.setCurrentIndex(obj.form.orientation.findText(str(vobj.Object.Orientation)))
308 obj.form.coverAlong.setCurrentIndex(obj.form.coverAlong.findText(str(vobj.Object.CoverAlong)))
309 if vobj.Object.AmountCheck:
310 obj.form.amount.setValue(vobj.Object.Amount)
312 obj.form.amount_radio.setChecked(
False)
313 obj.form.spacing_radio.setChecked(
True)
314 obj.form.amount.setDisabled(
True)
315 obj.form.spacing.setEnabled(
True)
316 obj.form.spacing.setText(str(vobj.Object.TrueSpacing))
318 FreeCADGui.Control.showDialog(obj)
def check_selected_face()
def clicked(self, button)
def getStandardButtons(self)
def spacing_radio_clicked(self)
def getpointsOfStraightRebar(FacePRM, rt_cover, lb_cover, coverAlong, orientation)
def amount_radio_clicked(self)
def getSelectedFace(self)
def runRebarDistribution(self)
def changeCoverAlong(self)
def removeRebarDistribution(self)
def changeOrientation(self)
def CommandStraightRebar()
def editStraightRebar(Rebar, f_cover, coverAlong, rt_cover, lb_cover, diameter, amount_spacing_check, amount_spacing_value, orientation, structure=None, facename=None)
def getParametersOfFace(structure, facename, sketch=True)
def accept(self, signal=None)
def makeStraightRebar(f_cover, coverAlong, rt_cover, lb_cover, diameter, amount_spacing_check, amount_spacing_value, orientation="Horizontal", structure=None, facename=None)
def __init__(self, Rebar=None)