-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathHelicalRebar.py
455 lines (431 loc) · 15.3 KB
/
HelicalRebar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# -*- coding: utf-8 -*-
# ***************************************************************************
# * *
# * Copyright (c) 2017 - Amritpal Singh <[email protected]> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
__title__ = "HelicalRebar"
__author__ = "Amritpal Singh"
__url__ = "https://www.freecadweb.org"
import math
from pathlib import Path
import ArchCommands
import FreeCAD
import FreeCADGui
from DraftTools import translate
from PySide import QtGui
from PySide.QtCore import QT_TRANSLATE_NOOP
from PopUpImage import showPopUpImageDialog
from RebarData import RebarTypes
from Rebarfunc import (
getSelectedFace,
getFaceNumber,
getParametersOfFace,
showWarning,
check_selected_face,
facenormalDirection,
)
def getpointsOfHelicalRebar(
FacePRM, s_cover, b_cover, t_cover, pitch, edges, diameter, size, direction
):
"""getpointsOfHelicalRebar(FacePRM, s_cover, b_cover, t_cover):
Return points of the LShape rebar in the form of array for sketch."""
dz = float(pitch) / edges
R = FacePRM[0][0] / 2 - s_cover
points = []
if direction[2] in {-1, 1}:
z = 0
if direction[2] == 1:
zz = FacePRM[1][2] - t_cover
elif direction[2] == -1:
zz = FacePRM[1][2] + b_cover
count = 0
flag = False
while round(z) < abs(size - b_cover - t_cover):
for i in range(0, int(edges) + 1):
if not i and flag:
continue
if not flag:
z -= dz
flag = True
iAngle = i * 360 / edges
x = FacePRM[1][0] + R * math.cos(math.radians(iAngle))
y = FacePRM[1][1] + R * math.sin(math.radians(iAngle))
points.append(FreeCAD.Vector(x, y, zz))
count += 1
if direction[2] == 1:
zz -= dz
elif direction[2] == -1:
zz += dz
z += dz
return points
def createHelicalWire(
FacePRM,
s_cover,
b_cover,
t_cover,
pitch,
size,
direction,
diameter,
helix=None,
):
"""createHelicalWire(FacePRM, SideCover, BottomCover, TopCover, Pitch,
Size, Direction, Diameter, Helix = None):
It creates a helical wire."""
b_cover += diameter / 2
t_cover += diameter / 2
s_cover += diameter / 2
if not helix:
helix = FreeCAD.ActiveDocument.addObject("Part::Helix", "Helix")
helix.Pitch = pitch
helix.Radius = FacePRM[0][0] / 2 - s_cover
helix.Angle = 0
helix.LocalCoord = 0
helix.Height = size - b_cover - t_cover
if round(direction.x) == 1:
helix.Placement.Base = FreeCAD.Vector(
FacePRM[1][0] - b_cover, FacePRM[1][1], FacePRM[1][2]
)
helix.Placement.Rotation = FreeCAD.Rotation(
FreeCAD.Vector(0, -1, 0), 90
)
elif round(direction.x) == -1:
helix.Placement.Base = FreeCAD.Vector(
FacePRM[1][0] + t_cover, FacePRM[1][1], FacePRM[1][2]
)
helix.Placement.Rotation = FreeCAD.Rotation(
FreeCAD.Vector(0, -1, 0), -90
)
elif round(direction.y) == 1:
helix.Placement.Base = FreeCAD.Vector(
FacePRM[1][0], FacePRM[1][1] - b_cover, FacePRM[1][2]
)
helix.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(1, 0, 0), 90)
elif round(direction.y) == -1:
helix.Placement.Base = FreeCAD.Vector(
FacePRM[1][0], FacePRM[1][1] + t_cover, FacePRM[1][2]
)
helix.Placement.Rotation = FreeCAD.Rotation(
FreeCAD.Vector(-1, 0, 0), 90
)
elif round(direction.z) == 1:
helix.Placement.Base = FreeCAD.Vector(
FacePRM[1][0], FacePRM[1][1], FacePRM[1][2] - size + b_cover
)
helix.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(0, 0, 1), 0)
elif round(direction.z) == -1:
helix.Placement.Base = FreeCAD.Vector(
FacePRM[1][0], FacePRM[1][1], FacePRM[1][2] + b_cover
)
helix.Placement.Rotation = FreeCAD.Rotation(FreeCAD.Vector(0, 0, -1), 0)
FreeCAD.ActiveDocument.recompute()
return helix
class _HelicalRebarTaskPanel:
def __init__(self, Rebar=None):
self.form = FreeCADGui.PySideUic.loadUi(
str(Path(__file__).with_suffix(".ui"))
)
self.form.setWindowTitle(
QtGui.QApplication.translate("Arch", "Helical Rebar", None)
)
if not Rebar:
normal = facenormalDirection()
else:
if hasattr(Rebar.Base, "Support"):
normal = facenormalDirection(
Rebar.Base.Support[0][0], Rebar.Base.Support[0][1][0]
)
else:
normal = facenormalDirection(
Rebar.Base.AttachmentSupport[0][0],
Rebar.Base.AttachmentSupport[0][1][0],
)
if not round(normal.z) in {1, -1}:
self.form.topCoverLabel.setText(
translate("RebarAddon", "Left Cover")
)
self.form.bottomCoverLabel.setText(
translate("RebarAddon", "Right Cover")
)
self.form.PickSelectedFace.clicked.connect(self.getSelectedFace)
self.form.image.setPixmap(
QtGui.QPixmap(
str(Path(__file__).parent / "icons" / "HelicalRebar.svg")
)
)
self.form.toolButton.clicked.connect(
lambda: showPopUpImageDialog(
str(
Path(__file__).parent / "icons" / "HelicalRebarDetailed.svg"
)
)
)
# self.form.toolButton.setIcon(
# self.form.toolButton.style().standardIcon(
# QtGui.QStyle.SP_DialogHelpButton
# )
# )
self.Rebar = Rebar
self.SelectedObj = None
self.FaceName = None
@staticmethod
def getStandardButtons():
return (
int(QtGui.QDialogButtonBox.Ok)
| int(QtGui.QDialogButtonBox.Apply)
| int(QtGui.QDialogButtonBox.Cancel)
)
def clicked(self, button):
if button == int(QtGui.QDialogButtonBox.Apply):
self.accept(button)
def getSelectedFace(self):
getSelectedFace(self)
normal = facenormalDirection()
if not round(normal.z) in {1, -1}:
self.form.topCoverLabel.setText(
translate("RebarAddon", "Left Cover")
)
self.form.bottomCoverLabel.setText(
translate("RebarAddon", "Right Cover")
)
else:
self.form.topCoverLabel.setText(
translate("RebarAddon", "Top Cover")
)
self.form.bottomCoverLabel.setText(
translate("RebarAddon", "Bottom Cover")
)
def accept(self, signal=None):
b_cover = self.form.bottomCover.text()
b_cover = FreeCAD.Units.Quantity(b_cover).Value
s_cover = self.form.sideCover.text()
s_cover = FreeCAD.Units.Quantity(s_cover).Value
t_cover = self.form.topCover.text()
t_cover = FreeCAD.Units.Quantity(t_cover).Value
pitch = self.form.pitch.text()
pitch = FreeCAD.Units.Quantity(pitch).Value
diameter = self.form.diameter.text()
diameter = FreeCAD.Units.Quantity(diameter).Value
if not self.Rebar:
rebar = makeHelicalRebar(
s_cover,
b_cover,
diameter,
t_cover,
pitch,
self.SelectedObj,
self.FaceName,
)
else:
rebar = editHelicalRebar(
self.Rebar,
s_cover,
b_cover,
diameter,
t_cover,
pitch,
self.SelectedObj,
self.FaceName,
)
self.Rebar = rebar
if signal == int(QtGui.QDialogButtonBox.Apply):
pass
else:
FreeCADGui.Control.closeDialog()
def makeHelicalRebar(
s_cover, b_cover, diameter, t_cover, pitch, structure=None, facename=None
):
"""makeHelicalRebar(SideCover, BottomCover, Diameter, TopCover, Pitch,
Structure, Facename):
Adds the Helical reinforcement bar to the selected structural object."""
if not structure and not facename:
selected_obj = FreeCADGui.Selection.getSelectionEx()[0]
structure = selected_obj.Object
facename = selected_obj.SubElementNames[0]
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
# StructurePRM = getTrueParametersOfStructure(structure)
FacePRM = getParametersOfFace(structure, facename, False)
if not FacePRM:
FreeCAD.Console.PrintError(
"Cannot identify shape or from which base object structural "
"element is derived\n"
)
return
size = (
ArchCommands.projectToVector(
structure.Shape.copy(), face.normalAt(0, 0)
)
).Length
normal = face.normalAt(0, 0)
# normal = face.Placement.Rotation.inverted().multVec(normal)
import Arch
helix = createHelicalWire(
FacePRM, s_cover, b_cover, t_cover, pitch, size, normal, diameter
)
if hasattr(helix, "Support"):
helix.Support = [(structure, facename)]
else:
helix.AttachmentSupport = [(structure, facename)]
rebar = Arch.makeRebar(
structure, helix, diameter, 1, diameter / 2, name="HelicalRebar"
)
rebar.OffsetStart = diameter / 2
rebar.OffsetEnd = diameter / 2
FreeCAD.ActiveDocument.recompute()
# Adds properties to the rebar object
rebar.addProperty(
"App::PropertyEnumeration",
"RebarShape",
"RebarDialog",
QT_TRANSLATE_NOOP("App::Property", "Shape of rebar"),
).RebarShape = RebarTypes.tolist()
rebar.RebarShape = "HelicalRebar"
rebar.setEditorMode("RebarShape", 2)
rebar.addProperty(
"App::PropertyDistance",
"SideCover",
"RebarDialog",
QT_TRANSLATE_NOOP("App::Property", "Front cover of rebar"),
).SideCover = s_cover
rebar.setEditorMode("SideCover", 2)
rebar.addProperty(
"App::PropertyDistance",
"Pitch",
"RebarDialog",
QT_TRANSLATE_NOOP("App::Property", "Left Side cover of rebar"),
).Pitch = pitch
rebar.setEditorMode("Pitch", 2)
rebar.addProperty(
"App::PropertyDistance",
"BottomCover",
"RebarDialog",
QT_TRANSLATE_NOOP("App::Property", "Bottom cover of rebar"),
).BottomCover = b_cover
rebar.setEditorMode("BottomCover", 2)
rebar.addProperty(
"App::PropertyDistance",
"TopCover",
"RebarDialog",
QT_TRANSLATE_NOOP("App::Property", "Top cover of rebar"),
).TopCover = t_cover
rebar.setEditorMode("TopCover", 2)
FreeCAD.ActiveDocument.recompute()
return rebar
def editHelicalRebar(
Rebar,
s_cover,
b_cover,
diameter,
t_cover,
pitch,
structure=None,
facename=None,
):
sketch = Rebar.Base
if structure and facename:
if hasattr(sketch, "Support"):
sketch.Support = [(structure, facename)]
else:
sketch.AttachmentSupport = [(structure, facename)]
# Check if sketch support is empty.
if hasattr(sketch, "Support"):
if not sketch.Support:
showWarning(
"You have checked: 'Remove external geometry of base sketches when "
"needed.'\nTo uncheck: Edit->Preferences->Arch."
)
return
else:
if not sketch.AttachmentSupport:
showWarning(
"You have checked: 'Remove external geometry of base sketches when "
"needed.'\nTo uncheck: Edit->Preferences->BIM."
)
return
# Assigned values
if hasattr(sketch, "Support"):
facename = sketch.Support[0][1][0]
structure = sketch.Support[0][0]
else:
facename = sketch.AttachmentSupport[0][1][0]
structure = sketch.AttachmentSupport[0][0]
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
# StructurePRM = getTrueParametersOfStructure(structure)
# Get parameters of the face where sketch of rebar is drawn
FacePRM = getParametersOfFace(structure, facename, False)
size = (
ArchCommands.projectToVector(
structure.Shape.copy(), face.normalAt(0, 0)
)
).Length
normal = face.normalAt(0, 0)
# normal = face.Placement.Rotation.inverted().multVec(normal)
createHelicalWire(
FacePRM,
s_cover,
b_cover,
t_cover,
pitch,
size,
normal,
diameter,
Rebar.Base,
)
FreeCAD.ActiveDocument.recompute()
Rebar.Diameter = diameter
Rebar.SideCover = s_cover
Rebar.BottomCover = b_cover
Rebar.TopCover = t_cover
Rebar.Pitch = pitch
FreeCAD.ActiveDocument.recompute()
return Rebar
def editDialog(vobj):
FreeCADGui.Control.closeDialog()
obj = _HelicalRebarTaskPanel(vobj.Object)
obj.form.sideCover.setText(
FreeCAD.Units.Quantity(
vobj.Object.SideCover, FreeCAD.Units.Length
).UserString
)
obj.form.bottomCover.setText(
FreeCAD.Units.Quantity(
vobj.Object.BottomCover, FreeCAD.Units.Length
).UserString
)
obj.form.diameter.setText(
FreeCAD.Units.Quantity(
vobj.Object.Diameter, FreeCAD.Units.Length
).UserString
)
obj.form.topCover.setText(
FreeCAD.Units.Quantity(
vobj.Object.TopCover, FreeCAD.Units.Length
).UserString
)
obj.form.pitch.setText(
FreeCAD.Units.Quantity(
vobj.Object.Pitch, FreeCAD.Units.Length
).UserString
)
FreeCADGui.Control.showDialog(obj)
def CommandHelicalRebar():
selected_obj = check_selected_face()
if selected_obj:
FreeCADGui.Control.showDialog(_HelicalRebarTaskPanel())