-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathRebarfunc.py
889 lines (787 loc) · 32.4 KB
/
Rebarfunc.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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
# -*- 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__ = "GenericRebarFunctions"
__author__ = "Amritpal Singh"
__url__ = "https://www.freecadweb.org"
from PySide import QtCore, QtGui
from PySide.QtCore import QT_TRANSLATE_NOOP
from DraftGeomUtils import vec, isCubic
import FreeCAD
import FreeCADGui
import math
# --------------------------------------------------------------------------
# Generic functions
# --------------------------------------------------------------------------
def getEdgesAngle(edge1, edge2):
"""getEdgesAngle(edge1, edge2): returns a angle between two edges."""
vec1 = vec(edge1)
vec2 = vec(edge2)
angle = vec1.getAngle(vec2)
angle = math.degrees(angle)
return angle
def checkRectangle(edges):
"""checkRectangle(edges=[]): This function checks whether the given form
rectangle or not. It will return True when edges form rectangular shape or
return False when edges not form a rectangular shape."""
angles = [
round(getEdgesAngle(edges[0], edges[1])),
round(getEdgesAngle(edges[0], edges[2])),
round(getEdgesAngle(edges[0], edges[3])),
]
if angles.count(90) == 2 and (
angles.count(180) == 1 or angles.count(0) == 1
):
return True
else:
return False
def getBaseStructuralObject(obj):
"""getBaseStructuralObject(obj): This function will return last base
structural object."""
if not obj.Base:
return obj
else:
return getBaseStructuralObject(obj.Base)
def getBaseObject(obj):
"""getBaseObject(obj): This function will return last base object."""
if hasattr(obj, "Base"):
return getBaseObject(obj.Base)
else:
return obj
def getFaceNumber(s):
"""getFaceNumber(facename): This will return a face number from face name.
For eg.:
Input: "Face12"
Output: 12"""
head = s.rstrip("0123456789")
tail = s[len(head) :] # noqa: E203
return int(tail)
def facenormalDirection(structure=None, facename=None):
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]
normal = face.normalAt(0, 0)
normal = structure.Placement.Rotation.inverted().multVec(normal)
return normal
def gettupleOfNumberDiameter(diameter_string):
"""gettupleOfNumberDiameter(diameter_string): This function take input in
specific syntax and return output in the form of list. For eg.
Input: "3#100+2#200+3#100"
Output: [(3, 100), (2, 200), (3, 100)]"""
diameter_st = diameter_string.strip()
diameter_sp = diameter_st.split("+")
index = 0
number_diameter_list = []
while index < len(diameter_sp):
# Find "#" recursively in diameter_sp array.
in_sp = diameter_sp[index].split("#")
number_diameter_list.append(
(int(in_sp[0]), float(in_sp[1].replace("mm", "")))
)
index += 1
return number_diameter_list
# --------------------------------------------------------------------------
# Main functions which is use while creating any rebar.
# --------------------------------------------------------------------------
def getTrueParametersOfStructure(obj):
"""getTrueParametersOfStructure(obj): This function return actual length,
width and height of the structural element in the form of array like
[Length, Width, Height]"""
baseObject = getBaseObject(obj)
# If selected_obj is not derived from any base object
if baseObject:
# If selected_obj is derived from SketchObject
if baseObject.isDerivedFrom("Sketcher::SketchObject"):
edges = baseObject.Shape.Edges
if checkRectangle(edges):
for edge in edges:
# Representation vector of edge
rep_vector = edge.Vertexes[1].Point.sub(
edge.Vertexes[0].Point
)
rep_vector_angle = round(
math.degrees(
rep_vector.getAngle(FreeCAD.Vector(1, 0, 0))
)
)
if rep_vector_angle in {0, 180}:
length = edge.Length
else:
width = edge.Length
else:
return None
else:
return None
height = obj.Height.Value
else:
structuralBaseObject = getBaseStructuralObject(obj)
length = structuralBaseObject.Length.Value
width = structuralBaseObject.Width.Value
height = structuralBaseObject.Height.Value
return [length, width, height]
def getParametersOfFace(structure, facename, sketch=True):
"""getParametersOfFace(structure, facename, sketch = True):
This function will return length, width and points of center of mass of a
given face w.r.t sketch value.
For eg.:
Case 1: When sketch is True: We use True when we want to create rebars from
sketch (planar rebars) and the sketch is strictly based on 2D, so we
neglected the normal axis of the face.
Output: [(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY)]
Case 2: When sketch is False: When we want to create non-planar rebars (like
stirrup) or rebar from a wire. Also for creating rebar from wire we will
require three coordinates (x, y, z).
Output: [(FaceLength, FaceWidth), (CenterOfMassX, CenterOfMassY,
CenterOfMassZ)]
"""
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
center_of_mass = face.CenterOfMass
# center_of_mass = center_of_mass.sub(
# getBaseStructuralObject(structure).Placement.Base
# )
center_of_mass = center_of_mass.sub(structure.Placement.Base)
Edges = []
facePRM = []
# When structure is cubic. It support all structure is derived from
# any other object (like a sketch, wire etc).
if isCubic(structure.Shape):
for edge in face.Edges:
if not Edges:
Edges.append(edge)
else:
# Checks whether similar edges is already present in Edges list
# or not.
if round((vec(edge)).Length) not in [
round((vec(x)).Length) for x in Edges
]:
Edges.append(edge)
if len(Edges) == 1:
Edges.append(edge)
# facePRM holds length of a edges.
facePRM = [(vec(edge)).Length for edge in Edges]
face_normal = face.normalAt(0, 0)
if round(face_normal[0]) in (-1, 1):
x = center_of_mass[1]
y = center_of_mass[2]
elif round(face_normal[1]) in (-1, 1):
x = center_of_mass[0]
y = center_of_mass[2]
elif round(face_normal[2]) in (-1, 1):
x = center_of_mass[0]
y = center_of_mass[1]
# When edge is parallel to y-axis
if round(Edges[0].tangentAt(0)[1]) in {1, -1}:
if round(Edges[1].tangentAt(0)[0]) in {1, -1}:
# Change order when edge along x-axis is at second place.
facePRM.reverse()
elif round(Edges[0].tangentAt(0)[2]) in {1, -1}:
facePRM.reverse()
facelength = facePRM[0]
facewidth = facePRM[1]
# When structure is not cubic. For founding parameters of given face
# I have used bounding box.
else:
boundbox = face.BoundBox
# Check that one length of bounding box is zero. Here bounding box
# looks like a plane.
if 0 in {
round(boundbox.XLength),
round(boundbox.YLength),
round(boundbox.ZLength),
}:
normal = face.normalAt(0, 0)
normal = face.Placement.Rotation.inverted().multVec(normal)
# print "x: ", boundbox.XLength
# print "y: ", boundbox.YLength
# print "z: ", boundbox.ZLength
# Set length and width of user selected face of structural element
flag = True
# FIXME: Improve below logic.
for i in range(len(normal)):
if round(normal[i]) == 0:
if flag and i == 0:
x = center_of_mass[i]
facelength = boundbox.XLength
flag = False
elif flag and i == 1:
x = center_of_mass[i]
facelength = boundbox.YLength
flag = False
if i == 1:
y = center_of_mass[i]
facewidth = boundbox.YLength
elif i == 2:
y = center_of_mass[i]
facewidth = boundbox.ZLength
# print [(facelength, facewidth), (x, y)]
# Return parameter of the face when rebar is not created from the sketch.
# For eg. non-planar rebars like stirrup etc.
if not sketch:
center_of_mass = face.CenterOfMass
return [(facelength, facewidth), center_of_mass]
# TODO: Add support when bounding box have depth. Here bounding box looks
# like cuboid. If we given curved face.
return [(facelength, facewidth), (x, y)]
# -------------------------------------------------------------------------
# Functions which is mainly used while creating stirrup.
# -------------------------------------------------------------------------
def extendedTangentPartLength(rounding, diameter, angle):
"""extendedTangentPartLength(rounding, diameter, angle): Get a extended
length of rounding on corners."""
radius = rounding * diameter
x1 = radius / math.tan(math.radians(angle))
x2 = radius / math.cos(math.radians(90 - angle)) - radius
return x1 + x2
def extendedTangentLength(rounding, diameter, angle):
"""extendedTangentLength(rounding, diameter, angle): Get a extended
length of rounding at the end of Stirrup for bent."""
radius = rounding * diameter
x1 = radius / math.sin(math.radians(angle))
x2 = radius * math.tan(math.radians(90 - angle))
return x1 + x2
# -------------------------------------------------------------------------
# Classes and functions which are mainly used while creating Column and
# Beam Reinforcement.
# -------------------------------------------------------------------------
def setGroupProperties(properties, group_obj):
for prop in properties:
group_obj.addProperty(
prop[0],
prop[1],
"RebarDialog",
QT_TRANSLATE_NOOP("App::Property", prop[2]),
)
group_obj.setEditorMode(prop[1], prop[3])
def setGroupPropertiesValues(properties_values, group_obj):
for prop in properties_values:
setattr(group_obj, prop[0], prop[1])
# -------------------------------------------------------------------------
# Classes and functions which are mainly used while creating Column
# Reinforcement.
# -------------------------------------------------------------------------
class _RebarGroup:
"""A Rebar Group object."""
def __init__(self, obj_name):
self.Type = "RebarGroup"
self.rebar_group = FreeCAD.ActiveDocument.addObject(
"App::DocumentObjectGroupPython", obj_name
)
self.ties_group = self.rebar_group.newObject(
"App::DocumentObjectGroupPython", "Ties"
)
self.main_rebars_group = self.rebar_group.newObject(
"App::DocumentObjectGroupPython", "MainRebars"
)
# Add properties to rebar_group object
properties = [
("App::PropertyLinkList", "RebarGroups", "List of rebar groups", 1)
]
setGroupProperties(properties, self.rebar_group)
self.rebar_group.RebarGroups = [self.ties_group, self.main_rebars_group]
self.Object = self.rebar_group
def execute(self, obj):
pass
def addTies(self, ties_list):
"""Add Ties to ties_group object."""
if isinstance(ties_list, list):
self.ties_group.addObjects(ties_list)
else:
self.ties_group.addObject(ties_list)
ties_list = [ties_list]
prev_ties_list = self.ties_group.Ties
prev_ties_list.extend(ties_list)
self.ties_group.Ties = prev_ties_list
def addMainRebars(self, main_rebars_list):
"""Add Main Rebars to main_rebars group object."""
self.main_rebars_group.addObjects(main_rebars_list)
prev_main_rebars_list = self.main_rebars_group.MainRebars
main_rebars_list.extend(prev_main_rebars_list)
self.main_rebars_group.MainRebars = main_rebars_list
class _ViewProviderRebarGroup:
"""A View Provider for the Rebar Group object."""
def __init__(self, vobj):
vobj.Proxy = self
self.Object = vobj.Object
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def doubleClicked(self, vobj):
from ColumnReinforcement import MainColumnReinforcement
MainColumnReinforcement.editDialog(vobj)
def getLRebarOrientationLeftRightCover(
hook_orientation,
hook_extension,
hook_extend_along,
l_cover_of_tie,
r_cover_of_tie,
t_cover_of_tie,
b_cover_of_tie,
dia_of_tie,
dia_of_rebars,
rounding_of_rebars,
face_length,
):
"""getLRebarOrientationLeftRightCover(HookOrientation, HookExtension,
HookExtendAlong, LeftCoverOfTie, RightCoverOfTie, TopCoverOfTie,
BottomCoverOfTie, DiameterOfTie, DiameterOfRebars, RoundingOfRebars,
FaceLength):
Return orientation and left and right cover of LShapeRebar in the form of
dictionary of list.
It takes eight different orientations input for LShapeHook i.e. 'Top
Inside', 'Top Outside', 'Bottom Inside', 'Bottom Outside', 'Top Right',
'Top Left', 'Bottom Right', 'Bottom Left'.
It takes two different inputs for hook_extend_along i.e. 'x-axis', 'y-axis'.
"""
if hook_extend_along == "y-axis":
# Swap values of covers
l_cover_of_tie, b_cover_of_tie = b_cover_of_tie, l_cover_of_tie
r_cover_of_tie, t_cover_of_tie = t_cover_of_tie, r_cover_of_tie
l_cover = []
r_cover = []
l_cover.append(l_cover_of_tie + dia_of_tie)
if hook_orientation in ("Top Inside", "Bottom Inside"):
# Assign orientation value
if hook_orientation == "Top Inside":
list_orientation = ["Top Left", "Top Right"]
else:
list_orientation = ["Bottom Left", "Bottom Right"]
r_cover.append(
face_length
- l_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
- rounding_of_rebars * dia_of_rebars
- hook_extension
)
l_cover.append(
face_length
- r_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
- rounding_of_rebars * dia_of_rebars
- hook_extension
)
elif hook_orientation in ("Top Outside", "Bottom Outside"):
if hook_orientation == "Top Outside":
list_orientation = ["Top Left", "Top Right"]
else:
list_orientation = ["Bottom Left", "Bottom Right"]
r_cover.append(
face_length
- l_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
+ rounding_of_rebars * dia_of_rebars
+ hook_extension
)
l_cover.append(
face_length
- r_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
+ rounding_of_rebars * dia_of_rebars
+ hook_extension
)
elif hook_orientation in ("Top Left", "Bottom Left"):
if hook_orientation == "Top Left":
list_orientation = ["Top Left", "Top Right"]
else:
list_orientation = ["Bottom Left", "Bottom Right"]
r_cover.append(
face_length
- l_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
+ rounding_of_rebars * dia_of_rebars
+ hook_extension
)
l_cover.append(
face_length
- r_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
- rounding_of_rebars * dia_of_rebars
- hook_extension
)
elif hook_orientation in ("Top Right", "Bottom Right"):
if hook_orientation == "Top Right":
list_orientation = ["Top Left", "Top Right"]
else:
list_orientation = ["Bottom Left", "Bottom Right"]
r_cover.append(
face_length
- l_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
- rounding_of_rebars * dia_of_rebars
- hook_extension
)
l_cover.append(
face_length
- r_cover_of_tie
- dia_of_tie
- dia_of_rebars / 2
+ rounding_of_rebars * dia_of_rebars
+ hook_extension
)
r_cover.append(r_cover_of_tie + dia_of_tie)
l_rebar_orientation_cover = {
"list_orientation": list_orientation,
"l_cover": l_cover,
"r_cover": r_cover,
}
return l_rebar_orientation_cover
def getFacenameforRebar(hook_extend_along, facename, structure):
"""getFacenameforRebar(HookExtendAlong, Facename, Structure):
Return facename of face normal to selected/provided face
It takes two different inputs for hook_extend_along i.e. 'x-axis', 'y-axis'.
"""
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
normal1 = face.normalAt(0, 0)
faces = structure.Shape.Faces
for index, face in enumerate(faces, start=1):
normal2 = face.normalAt(0, 0)
if hook_extend_along == "x-axis":
if (
int(normal1.dot(normal2)) == 0
and int(normal1.cross(normal2).x) == 1
):
facename_for_rebars = "Face" + str(index)
break
else:
if (
int(normal1.dot(normal2)) == 0
and int(normal1.cross(normal2).y) == 1
):
facename_for_rebars = "Face" + str(index)
break
return facename_for_rebars
# -------------------------------------------------------------------------
# Classes and functions which are mainly used while creating Beam Reinforcement.
# -------------------------------------------------------------------------
class _BeamReinforcementGroup:
"""A Beam Reinforcement Group object."""
def __init__(self):
self.Type = "BeamReinforcementGroup"
self.rebar_group = FreeCAD.ActiveDocument.addObject(
"App::DocumentObjectGroupPython", "BeamReinforcement"
)
self.stirrups_group = self.rebar_group.newObject(
"App::DocumentObjectGroupPython", "Stirrups"
)
self.top_reinforcement_group = self.rebar_group.newObject(
"App::DocumentObjectGroupPython", "TopReinforcement"
)
self.bottom_reinforcement_group = self.rebar_group.newObject(
"App::DocumentObjectGroupPython", "BottomReinforcement"
)
self.shear_reinforcement_group = self.rebar_group.newObject(
"App::DocumentObjectGroupPython", "ShearReinforcement"
)
self.left_rebars_group = self.shear_reinforcement_group.newObject(
"App::DocumentObjectGroupPython", "LeftRebars"
)
self.right_rebars_group = self.shear_reinforcement_group.newObject(
"App::DocumentObjectGroupPython", "RightRebars"
)
# Add properties to rebar_group object
properties = [
(
"App::PropertyLinkList",
"ReinforcementGroups",
"List of reinforcement groups",
1,
)
]
setGroupProperties(properties, self.rebar_group)
self.rebar_group.ReinforcementGroups = [
self.stirrups_group,
self.top_reinforcement_group,
self.bottom_reinforcement_group,
self.shear_reinforcement_group,
]
# Add properties to stirrups_group object
properties = [
("App::PropertyLinkList", "Stirrups", "List of Stirrups", 1),
(
"App::PropertyString",
"StirrupsConfiguration",
"Configuration of Stirrups in Beam Reinforcement",
1,
),
]
setGroupProperties(properties, self.stirrups_group)
# Add properties to top_reinforcement_group object
properties = [
(
"App::PropertyLinkList",
"TopRebars",
"List of top reinforcement rebars",
1,
)
]
setGroupProperties(properties, self.top_reinforcement_group)
# Add properties to bottom_reinforcement_group object
properties = [
(
"App::PropertyLinkList",
"BottomRebars",
"List of bottom reinforcement rebars",
1,
)
]
setGroupProperties(properties, self.bottom_reinforcement_group)
# Add properties to shear_reinforcement_group object
properties = [
(
"App::PropertyLinkList",
"ShearReinforcementGroups",
"List of shear reinforcement groups",
1,
)
]
setGroupProperties(properties, self.shear_reinforcement_group)
self.shear_reinforcement_group.ShearReinforcementGroups = [
self.left_rebars_group,
self.right_rebars_group,
]
# Add properties to left_rebars_group object
properties = [
(
"App::PropertyLinkList",
"LeftRebars",
"List of shear reinforcement left rebars",
1,
)
]
setGroupProperties(properties, self.left_rebars_group)
# Add properties to right_rebars_group object
properties = [
(
"App::PropertyLinkList",
"RightRebars",
"List of shear reinforcement right rebars",
1,
)
]
setGroupProperties(properties, self.right_rebars_group)
self.Object = self.rebar_group
def execute(self, obj):
pass
def addStirrups(self, stirrups_list):
"""Add Stirrups to stirrups_group object."""
if isinstance(stirrups_list, list):
self.stirrups_group.addObjects(stirrups_list)
else:
self.stirrups_group.addObject(stirrups_list)
stirrups_list = [stirrups_list]
prev_stirrups_list = self.stirrups_group.Stirrups
prev_stirrups_list.extend(stirrups_list)
self.stirrups_group.Stirrups = prev_stirrups_list
def addTopRebars(self, top_rebars_list):
"""Add top reinforcement rebars to top_reinforcement_group object."""
self.top_reinforcement_group.addObjects(top_rebars_list)
prev_top_rebars_list = self.top_reinforcement_group.TopRebars
prev_top_rebars_list.extend(top_rebars_list)
self.top_reinforcement_group.TopRebars = prev_top_rebars_list
def addBottomRebars(self, bottom_rebars_list):
"""Add bottom reinforcement rebars to bottom_reinforcement_group
object."""
self.bottom_reinforcement_group.addObjects(bottom_rebars_list)
prev_bottom_rebars_list = self.bottom_reinforcement_group.BottomRebars
prev_bottom_rebars_list.extend(bottom_rebars_list)
self.bottom_reinforcement_group.BottomRebars = prev_bottom_rebars_list
def addLeftRebars(self, left_rebars_list):
"""Add left reinforcement rebars to left_reinforcement_group object."""
self.left_rebars_group.addObjects(left_rebars_list)
prev_left_rebars_list = self.left_rebars_group.LeftRebars
prev_left_rebars_list.extend(left_rebars_list)
self.left_rebars_group.LeftRebars = prev_left_rebars_list
def addRightRebars(self, right_rebars_list):
"""Add right reinforcement rebars to right_reinforcement_group
object."""
self.right_rebars_group.addObjects(right_rebars_list)
prev_right_rebars_list = self.right_rebars_group.RightRebars
prev_right_rebars_list.extend(right_rebars_list)
self.right_rebars_group.RightRebars = prev_right_rebars_list
def getFacenamesforBeamReinforcement(facename, structure):
"""getFacenamesforBeamReinforcement(Facename, Structure):
Return tuple of facenames of faces normal to selected/provided face to
create straight/lshaped rebars.
"""
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
normal1 = face.normalAt(0, 0)
faces = structure.Shape.Faces
index = 1
for face in faces:
normal2 = face.normalAt(0, 0)
if (
int(normal1.dot(normal2)) == 0
and int(normal1.cross(normal2).z) == -1
):
facename_for_tb_rebars = "Face" + str(index)
if normal2.z == -1:
facename_for_s_rebars = "Face" + str(index)
index += 1
return facename_for_tb_rebars, facename_for_s_rebars
def getFacenamesforFootingReinforcement(facename, structure):
"""getFacenamesforFootingReinforcement(Facename, Structure):
Return tuple of facenames of faces normal to selected/provided face to
create mesh/column of rebars.
"""
face = structure.Shape.Faces[getFaceNumber(facename) - 1]
normal1 = face.normalAt(0, 0)
faces = structure.Shape.Faces
index = 1
for face in faces:
normal2 = face.normalAt(0, 0)
if (
int(normal1.dot(normal2)) == 0
and int(normal1.cross(normal2).z) == -1
):
facename_for_cross_rebars = "Face" + str(index)
if normal2.z == 1:
facename_for_column_rebars = "Face" + str(index)
index += 1
return facename_for_cross_rebars, facename_for_column_rebars
def getdictofNumberDiameterOffset(number_diameter_offset_tuple):
"""getdictofNumberDiameterOffset(NumberDiameterOffsetTuple):
This function take input in specific syntax and return output in the form of
dictionary. For eg.
Input: ("2#20@50+3#16@100+2#20@50", "1#18@30+2#14@30+1#18@30")
Output: {
'layer1': [(2, 20, 50), (3, 16, 100), (2, 20, 50)],
'layer2': [(1, 18, 30), (2, 14, 30), (1, 18, 30)],
}
"""
number_diameter_offset_dict = {}
for i, number_diameter_offset_string in enumerate(
number_diameter_offset_tuple
):
number_diameter_offset_dict[
"layer" + str(i + 1)
] = gettupleOfNumberDiameterOffset(number_diameter_offset_string)
return number_diameter_offset_dict
def gettupleOfNumberDiameterOffset(number_diameter_offset_string):
"""gettupleOfNumberDiameterOffset(NumberDiameterOffsetString):
This function take input in specific syntax and return output in the form of
tuple. For eg.
Input: "2#20@50+3#16@100+2#20@50"
Output: [(2, 20, 50), (3, 16, 100), (2, 20, 50)]
"""
import re
number_diameter_offset_st = number_diameter_offset_string.strip()
number_diameter_offset_sp = number_diameter_offset_st.split("+")
index = 0
number_diameter_offset_list = []
while index < len(number_diameter_offset_sp):
# Find "#" and "@" recursively in number_diameter_offset_sp array.
in_sp = re.split("#|@", number_diameter_offset_sp[index])
number_diameter_offset_list.append(
(
int(in_sp[0]),
float(in_sp[1].replace("mm", "")),
float(in_sp[2].replace("mm", "")),
)
)
index += 1
return number_diameter_offset_list
class _ViewProviderBeamReinforcementGroup:
"""A View Provider for the Beam Reinforcement Group object."""
def __init__(self, vobj):
vobj.Proxy = self
self.Object = vobj.Object
def __getstate__(self):
return None
def __setstate__(self, state):
return None
def doubleClicked(self, vobj):
from BeamReinforcement import MainBeamReinforcement
MainBeamReinforcement.editDialog(vobj)
# -------------------------------------------------------------------------
# Warning / Alert functions when user do something wrong.
# --------------------------------------------------------------------------
def check_selected_face():
"""check_selected_face(): This function checks whether user have selected
any face or not."""
selected_objs = FreeCADGui.Selection.getSelectionEx()
if not selected_objs:
showWarning("Select any face of the structural element.")
selected_obj = None
else:
selected_face_names = selected_objs[0].SubElementNames
if not selected_face_names:
selected_obj = None
showWarning("Select any face of the structural element.")
elif "Face" in selected_face_names[0]:
if len(selected_face_names) > 1:
showWarning(
"You have selected more than one face of the structural "
"element."
)
selected_obj = None
elif len(selected_face_names) == 1:
selected_obj = selected_objs[0]
else:
showWarning("Select any face of the selected the face.")
selected_obj = None
return selected_obj
def getSelectedFace(self):
selected_objs = FreeCADGui.Selection.getSelectionEx()
if selected_objs:
if len(selected_objs[0].SubObjects) == 1:
if "Face" in selected_objs[0].SubElementNames[0]:
self.SelectedObj = selected_objs[0].Object
self.FaceName = selected_objs[0].SubElementNames[0]
self.form.PickSelectedFaceLabel.setText(
"Selected face is " + self.FaceName
)
else:
showWarning("Select any face of the structural element.")
else:
showWarning("Select only one face of the structural element.")
else:
showWarning("Select any face of the structural element.")
def get_rebar_amount_from_spacing(bar_distribution_len, bar_dia, spacing):
"""get_rebar_amount_from_spacing(bar_distribution_len, bar_dia, spacing):
Return rebar amount from spacing."""
return math.ceil((bar_distribution_len - bar_dia) / spacing) + 1
def showWarning(message):
"""showWarning(message): This function is used to produce warning
message for the user."""
msg = QtGui.QMessageBox()
msg.setIcon(QtGui.QMessageBox.Warning)
msg.setText(translate("RebarAddon", message))
msg.setStandardButtons(QtGui.QMessageBox.Ok)
msg.exec_()
# Qt translation handling
def translate(context, text, disambig=None):
return QtCore.QCoreApplication.translate(context, text, disambig)
def print_in_freecad_console(*msg):
"""Print given arguments on FreeCAD console."""
s = ""
for m in msg:
s += str(m) + ", "
FreeCAD.Console.PrintMessage(str(s) + "\n")