Skip to content

Commit b1535d1

Browse files
committed
incorporating horizontal conduit
1 parent fce00f6 commit b1535d1

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

plugin/RV_tna_horizontal.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,95 @@
88
from compas.geometry import Box
99
from compas.geometry import bounding_box
1010
from compas_rv.session import RVSession
11+
from compas_rv.conduits import HorizontalConduit
1112
from compas_tna.equilibrium import horizontal_nodal
1213

1314

1415
def RunCommand():
16+
17+
def redraw (k, xy, edges):
18+
if k % conduit.refreshrate:
19+
return
20+
print(k)
21+
conduit.lines = [[[xy[i][1], -xy[i][0]], [xy[j][1], -xy[j][0]]] for i, j in edges]
22+
conduit.redraw()
23+
24+
# =============================================================================
25+
# Check scene
26+
# =============================================================================
27+
1528
session = RVSession()
1629

1730
form = session.find_formdiagram()
1831
if not form:
32+
print("There is no FormDiagram in the scene.")
1933
return
2034

2135
force = session.find_forcediagram()
2236
if not force:
37+
print("There is no ForceDiagram in the scene.")
2338
return
2439

2540
# =============================================================================
26-
# Compute horizontal
41+
# Options prompt
2742
# =============================================================================
2843

2944
kmax = session.settings.tna.horizontal_kmax
3045
alpha = session.settings.tna.horizontal_alpha
46+
refresh = session.settings.tna.horizontal_refreshrate
47+
48+
options = ['Alpha', 'Iterations', 'RefreshRate']
49+
50+
while True:
51+
option = rs.GetString('Press Enter to run or ESC to exit.', strings=options)
52+
53+
if option is None:
54+
print("Horizontal equilibrium aborted!")
55+
return
56+
57+
if not option:
58+
break
59+
60+
if option == 'Alpha':
61+
alpha_options = ['form{}'.format(int(i * 10)) for i in range(11)]
62+
alpha_default = 0
63+
for i in range(11):
64+
if alpha == i * 10:
65+
alpha_default = i
66+
break
67+
temp = rs.GetString('Select parallelisation weight', alpha_options[alpha_default], alpha_options)
68+
if not temp:
69+
alpha = 100
70+
else:
71+
alpha = int(temp[4:])
72+
73+
elif option == 'Iterations':
74+
new_kmax = rs.GetInteger('Enter number of iterations', kmax, 1, 10000)
75+
if new_kmax or new_kmax is not None:
76+
kmax = new_kmax
77+
78+
elif option == 'RefreshRate':
79+
new_refresh = rs.GetInteger('Refresh rate for dynamic visualisation', refresh, 0, 1000)
80+
if new_refresh or new_refresh is not None:
81+
refresh = new_refresh
82+
83+
if refresh > kmax:
84+
refresh = 0
85+
86+
session.settings.tna.horizontal_kmax = kmax
87+
session.settings.tna.horizontal_alpha = alpha
88+
session.settings.tna.horizontal_refreshrate = refresh
3189

32-
horizontal_nodal(form.diagram, force.diagram, kmax=kmax, alpha=alpha)
90+
# =============================================================================
91+
# Compute horizontal
92+
# =============================================================================
93+
94+
if refresh > 0:
95+
conduit = HorizontalConduit([], refreshrate=refresh)
96+
with conduit.enabled():
97+
horizontal_nodal(form.diagram, force.diagram, kmax=kmax, alpha=alpha, callback=redraw)
98+
else:
99+
horizontal_nodal(form.diagram, force.diagram, kmax=kmax, alpha=alpha)
33100

34101
bbox_form = Box.from_bounding_box(bounding_box(form.diagram.vertices_attributes("xyz")))
35102
bbox_force = Box.from_bounding_box(bounding_box(force.diagram.vertices_attributes("xyz")))
@@ -49,9 +116,12 @@ def RunCommand():
49116
tol_angles = session.settings.tna.horizontal_max_angle
50117

51118
if max_angle < tol_angles:
52-
print(f"Horizontal equilibrium found!\nMaximum angle deviation: {max_angle} < {tol_angles}")
119+
print('Horizontal equilibrium found!')
120+
print('Maximum angle deviation: {} < {}'.format(max_angle, tol_angles))
121+
53122
else:
54-
rs.MessageBox(f"Horizontal equilibrium NOT found! Consider running more iterations.\nMaximum angle deviation: {max_angle} > {tol_angles}")
123+
print('Horizontal equilibrium NOT found! Consider running more iterations.')
124+
print('Maximum angle deviation: {} > {}'.format(max_angle, tol_angles))
55125

56126
rs.UnselectAllObjects()
57127

0 commit comments

Comments
 (0)