24 __title__ =
"UShapeRebar" 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 """ getpointsOfUShapeRebar(FacePRM, RightCover, LeftCover, BottomCover, TopCover, Orientation): 42 Return points of the UShape rebar in the form of array for sketch. 43 It takes four different orientations input i.e. 'Bottom', 'Top', 'Left', 'Right'. 45 if orientation ==
"Bottom":
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 x4 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
53 y4 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
54 elif orientation ==
"Top":
55 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
56 y1 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
57 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
58 y2 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
59 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
60 y3 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
61 x4 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
62 y4 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
63 elif orientation ==
"Left":
64 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
65 y1 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
66 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
67 y2 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
68 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
69 y3 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
70 x4 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
71 y4 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
72 elif orientation ==
"Right":
73 x1 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
74 y1 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
75 x2 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
76 y2 = FacePRM[1][1] + FacePRM[0][1] / 2 - t_cover
77 x3 = FacePRM[1][0] - FacePRM[0][0] / 2 + FacePRM[0][0] - r_cover
78 y3 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
79 x4 = FacePRM[1][0] - FacePRM[0][0] / 2 + l_cover
80 y4 = FacePRM[1][1] - FacePRM[0][1] / 2 + b_cover
81 return [FreeCAD.Vector(x1, y1, 0), FreeCAD.Vector(x2, y2, 0),\
82 FreeCAD.Vector(x3, y3, 0), FreeCAD.Vector(x4, y4, 0)]
88 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
90 self.
FaceName = selected_obj.SubElementNames[0]
92 self.
FaceName = Rebar.Base.Support[0][1][0]
94 self.
form = FreeCADGui.PySideUic.loadUi(os.path.splitext(__file__)[0] +
".ui")
95 self.form.setWindowTitle(QtGui.QApplication.translate(
"RebarAddon",
"U-Shape Rebar",
None))
96 self.form.orientation.addItems([
"Bottom",
"Top",
"Right",
"Left"])
101 self.form.PickSelectedFace.clicked.connect(
lambda:
getSelectedFace(self))
102 self.form.orientation.currentIndexChanged.connect(self.
getOrientation)
103 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/UShapeRebarBottom.svg"))
104 self.form.toolButton.setIcon(self.form.toolButton.style().standardIcon(QtGui.QStyle.SP_DialogHelpButton))
105 self.form.toolButton.clicked.connect(
lambda:
showPopUpImageDialog(os.path.split(os.path.abspath(__file__))[0] +
"/icons/UShapeRebarDetailed.svg"))
109 orientation = self.form.orientation.currentText()
110 if orientation ==
"Bottom":
111 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/UShapeRebarBottom.svg"))
112 elif orientation ==
"Top":
113 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/UShapeRebarTop.svg"))
114 elif orientation ==
"Right":
115 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/UShapeRebarRight.svg"))
117 self.form.image.setPixmap(QtGui.QPixmap(os.path.split(os.path.abspath(__file__))[0] +
"/icons/UShapeRebarLeft.svg"))
120 return int(QtGui.QDialogButtonBox.Ok) | int(QtGui.QDialogButtonBox.Apply) | int(QtGui.QDialogButtonBox.Cancel)
123 if button == int(QtGui.QDialogButtonBox.Apply):
127 f_cover = self.form.frontCover.text()
128 f_cover = FreeCAD.Units.Quantity(f_cover).Value
129 b_cover = self.form.bottomCover.text()
130 b_cover = FreeCAD.Units.Quantity(b_cover).Value
131 r_cover = self.form.r_sideCover.text()
132 r_cover = FreeCAD.Units.Quantity(r_cover).Value
133 l_cover = self.form.l_sideCover.text()
134 l_cover = FreeCAD.Units.Quantity(l_cover).Value
135 t_cover = self.form.topCover.text()
136 t_cover = FreeCAD.Units.Quantity(t_cover).Value
137 diameter = self.form.diameter.text()
138 diameter = FreeCAD.Units.Quantity(diameter).Value
139 rounding = self.form.rounding.value()
140 orientation = self.form.orientation.currentText()
141 amount_check = self.form.amount_radio.isChecked()
142 spacing_check = self.form.spacing_radio.isChecked()
145 amount = self.form.amount.value()
146 rebar =
makeUShapeRebar(f_cover, b_cover, r_cover, l_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 =
makeUShapeRebar(f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding,
False, spacing, orientation, self.
SelectedObj, self.
FaceName)
153 amount = self.form.amount.value()
154 rebar =
editUShapeRebar(self.
Rebar, f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding,
True, amount, orientation, self.
SelectedObj, self.
FaceName)
156 spacing = self.form.spacing.text()
157 spacing = FreeCAD.Units.Quantity(spacing).Value
158 rebar =
editUShapeRebar(self.
Rebar, f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding,
False, spacing, orientation, self.
SelectedObj, self.
FaceName)
161 FreeCAD.ActiveDocument.recompute()
163 if signal == int(QtGui.QDialogButtonBox.Apply):
166 FreeCADGui.Control.closeDialog(self)
169 self.form.spacing.setEnabled(
False)
170 self.form.amount.setEnabled(
True)
173 self.form.amount.setEnabled(
False)
174 self.form.spacing.setEnabled(
True)
177 def makeUShapeRebar(f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation = "Bottom", structure = None, facename = None):
178 """ makeUShapeRebar(FrontCover, BottomCover, RightCover, LeftCover, Diameter, Topcover, Rounding, AmountSpacingCheck, AmountSpacingValue, 179 Orientation, Structure, Facename): Adds the U-Shape reinforcement bar to the selected structural object. 180 It takes four different types of orientations as input i.e 'Bottom', 'Top', 'Right', 'Left'. 182 if not structure
and not facename:
183 selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
184 structure = selected_obj.Object
185 facename = selected_obj.SubElementNames[0]
190 FreeCAD.Console.PrintError(
"Cannot identified shape or from which base object sturctural element is derived\n")
196 sketch = FreeCAD.activeDocument().addObject(
'Sketcher::SketchObject',
'Sketch')
197 sketch.MapMode =
"FlatFace" 198 sketch.Support = [(structure, facename)]
199 FreeCAD.ActiveDocument.recompute()
200 sketch.addGeometry(Part.LineSegment(points[0], points[1]),
False)
201 sketch.addGeometry(Part.LineSegment(points[1], points[2]),
False)
203 sketch.addGeometry(Part.LineSegment(points[2], points[3]),
False)
204 if amount_spacing_check:
205 rebar = Arch.makeRebar(structure, sketch, diameter, amount_spacing_value, f_cover)
206 FreeCAD.ActiveDocument.recompute()
208 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
209 rebar = Arch.makeRebar(structure, sketch, diameter, int((size - diameter) / amount_spacing_value), f_cover)
210 rebar.Rounding = rounding
212 rebar.ViewObject.addProperty(
"App::PropertyString",
"RebarShape",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).RebarShape =
"UShapeRebar" 213 rebar.ViewObject.setEditorMode(
"RebarShape", 2)
214 rebar.addProperty(
"App::PropertyDistance",
"FrontCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Front cover of rebar")).FrontCover = f_cover
215 rebar.setEditorMode(
"FrontCover", 2)
216 rebar.addProperty(
"App::PropertyDistance",
"RightCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Right Side cover of rebar")).RightCover = r_cover
217 rebar.setEditorMode(
"RightCover", 2)
218 rebar.addProperty(
"App::PropertyDistance",
"LeftCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Left Side cover of rebar")).LeftCover = l_cover
219 rebar.setEditorMode(
"LeftCover", 2)
220 rebar.addProperty(
"App::PropertyDistance",
"BottomCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Bottom cover of rebar")).BottomCover = b_cover
221 rebar.setEditorMode(
"BottomCover", 2)
222 rebar.addProperty(
"App::PropertyBool",
"AmountCheck",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Amount radio button is checked")).AmountCheck
223 rebar.setEditorMode(
"AmountCheck", 2)
224 rebar.addProperty(
"App::PropertyDistance",
"TopCover",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Top cover of rebar")).TopCover = t_cover
225 rebar.setEditorMode(
"TopCover", 2)
226 rebar.addProperty(
"App::PropertyDistance",
"TrueSpacing",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Spacing between of rebars")).TrueSpacing = amount_spacing_value
227 rebar.setEditorMode(
"TrueSpacing", 2)
228 rebar.addProperty(
"App::PropertyString",
"Orientation",
"RebarDialog", QT_TRANSLATE_NOOP(
"App::Property",
"Shape of rebar")).Orientation = orientation
229 rebar.setEditorMode(
"Orientation", 2)
230 if amount_spacing_check:
231 rebar.AmountCheck =
True 233 rebar.AmountCheck =
False 234 rebar.TrueSpacing = amount_spacing_value
235 rebar.Label =
"UShapeRebar" 236 FreeCAD.ActiveDocument.recompute()
239 def editUShapeRebar(Rebar, f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation, structure = None, facename = None):
241 if structure
and facename:
242 sketch.Support = [(structure, facename)]
244 if not sketch.Support:
245 showWarning(
"You have checked remove external geometry of base sketchs when needed.\nTo unchecked Edit->Preferences->Arch.")
248 facename = sketch.Support[0][1][0]
249 structure = sketch.Support[0][0]
256 sketch.movePoint(0, 1, points[0], 0)
257 FreeCAD.ActiveDocument.recompute()
258 sketch.movePoint(0, 2, points[1], 0)
259 FreeCAD.ActiveDocument.recompute()
260 sketch.movePoint(1, 1, points[1], 0)
261 FreeCAD.ActiveDocument.recompute()
262 sketch.movePoint(1, 2, points[2], 0)
263 FreeCAD.ActiveDocument.recompute()
264 sketch.movePoint(2, 1, points[2], 0)
265 FreeCAD.ActiveDocument.recompute()
266 sketch.movePoint(2, 2, points[3], 0)
267 FreeCAD.ActiveDocument.recompute()
268 Rebar.OffsetStart = f_cover
269 Rebar.OffsetEnd = f_cover
270 if amount_spacing_check:
271 Rebar.Amount = amount_spacing_value
272 FreeCAD.ActiveDocument.recompute()
273 Rebar.AmountCheck =
True 275 size = (ArchCommands.projectToVector(structure.Shape.copy(), face.normalAt(0, 0))).Length
276 Rebar.Amount = int((size - diameter) / amount_spacing_value)
277 FreeCAD.ActiveDocument.recompute()
278 Rebar.AmountCheck =
False 279 Rebar.Diameter = diameter
280 Rebar.FrontCover = f_cover
281 Rebar.RightCover = r_cover
282 Rebar.LeftCover = l_cover
283 Rebar.BottomCover = b_cover
284 Rebar.TopCover = t_cover
285 Rebar.Rounding = rounding
286 Rebar.TrueSpacing = amount_spacing_value
287 Rebar.Orientation = orientation
288 FreeCAD.ActiveDocument.recompute()
292 FreeCADGui.Control.closeDialog()
294 obj.form.frontCover.setText(str(vobj.Object.FrontCover))
295 obj.form.r_sideCover.setText(str(vobj.Object.RightCover))
296 obj.form.l_sideCover.setText(str(vobj.Object.LeftCover))
297 obj.form.bottomCover.setText(str(vobj.Object.BottomCover))
298 obj.form.diameter.setText(str(vobj.Object.Diameter))
299 obj.form.topCover.setText(str(vobj.Object.TopCover))
300 obj.form.rounding.setValue(vobj.Object.Rounding)
301 obj.form.orientation.setCurrentIndex(obj.form.orientation.findText(str(vobj.Object.Orientation)))
302 if vobj.Object.AmountCheck:
303 obj.form.amount.setValue(vobj.Object.Amount)
305 obj.form.amount_radio.setChecked(
False)
306 obj.form.spacing_radio.setChecked(
True)
307 obj.form.amount.setDisabled(
True)
308 obj.form.spacing.setEnabled(
True)
309 obj.form.spacing.setText(str(vobj.Object.TrueSpacing))
311 FreeCADGui.Control.showDialog(obj)
def check_selected_face()
def __init__(self, Rebar=None)
def makeUShapeRebar(f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation="Bottom", structure=None, facename=None)
def getSelectedFace(self)
def runRebarDistribution(self)
def getpointsOfUShapeRebar(FacePRM, r_cover, l_cover, b_cover, t_cover, orientation)
def getStandardButtons(self)
def accept(self, signal=None)
def removeRebarDistribution(self)
def spacing_radio_clicked(self)
def clicked(self, button)
def amount_radio_clicked(self)
def editUShapeRebar(Rebar, f_cover, b_cover, r_cover, l_cover, diameter, t_cover, rounding, amount_spacing_check, amount_spacing_value, orientation, structure=None, facename=None)
def getParametersOfFace(structure, facename, sketch=True)