Skip to content

Commit 466a33a

Browse files
committed
viz resultants nodes edges
1 parent 76bd95f commit 466a33a

2 files changed

Lines changed: 111 additions & 6 deletions

File tree

src/compas_assembly/viewer/app.py

Lines changed: 93 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
from compas.colors import Color
5+
from compas.geometry import Line
56
from compas.utilities import remap_values
67
from compas_assembly.datastructures import Interface
78

@@ -16,6 +17,16 @@
1617

1718

1819
class DEMController(Controller):
20+
def show_nodes(self, *args, **kwargs):
21+
state = args[0]
22+
self.app.nodes.is_visible = state
23+
self.app.view.update()
24+
25+
def show_edges(self, *args, **kwargs):
26+
state = args[0]
27+
self.app.edges.is_visible = state
28+
self.app.view.update()
29+
1930
def show_interfaces(self, *args, **kwargs):
2031
state = args[0]
2132
self.app.interfaces.is_visible = state
@@ -32,6 +43,11 @@ def show_normalforces(self, *args, **kwargs):
3243
self.app.tension.is_visible = state
3344
self.app.view.update()
3445

46+
def show_resultants(self, *args, **kwargs):
47+
state = args[0]
48+
self.app.resultants.is_visible = state
49+
self.app.view.update()
50+
3551
def scale_contactforces(self, *args, **kwargs):
3652
value = args[0]
3753
if value <= 50:
@@ -46,22 +62,32 @@ def scale_contactforces(self, *args, **kwargs):
4662

4763
if self.app._compression:
4864
for o, line in zip(self.app.compression._objects, self.app._compression):
49-
o._data.start = line.midpoint - line.vector * 0.5 * scale
50-
o._data.end = line.midpoint + line.vector * 0.5 * scale
65+
if line.length:
66+
o._data.start = line.midpoint - line.vector * 0.5 * scale
67+
o._data.end = line.midpoint + line.vector * 0.5 * scale
5168
self.app.compression.update()
5269

5370
if self.app._tension:
5471
for o, line in zip(self.app.tension._objects, self.app._tension):
55-
o._data.start = line.midpoint - line.vector * 0.5 * scale
56-
o._data.end = line.midpoint + line.vector * 0.5 * scale
72+
if line.length:
73+
o._data.start = line.midpoint - line.vector * 0.5 * scale
74+
o._data.end = line.midpoint + line.vector * 0.5 * scale
5775
self.app.tension.update()
5876

5977
if self.app._friction:
6078
for o, line in zip(self.app.friction._objects, self.app._friction):
61-
o._data.start = line.midpoint - line.vector * 0.5 * scale
62-
o._data.end = line.midpoint + line.vector * 0.5 * scale
79+
if line.length:
80+
o._data.start = line.midpoint - line.vector * 0.5 * scale
81+
o._data.end = line.midpoint + line.vector * 0.5 * scale
6382
self.app.friction.update()
6483

84+
if self.app._resultants:
85+
for o, line in zip(self.app.resultants._objects, self.app._resultants):
86+
if line.length:
87+
o._data.start = line.midpoint - line.vector * 0.5 * scale
88+
o._data.end = line.midpoint + line.vector * 0.5 * scale
89+
self.app.resultants.update()
90+
6591
self.app.view.update()
6692

6793

@@ -102,6 +128,58 @@ def add_assembly(
102128
color_support=Color.red(),
103129
color_block=Color.grey(),
104130
):
131+
node_point = {}
132+
nodes = []
133+
properties = []
134+
for node in assembly.graph.nodes():
135+
block = assembly.graph.node_attribute(node, "block")
136+
is_support = assembly.graph.node_attribute(node, "is_support")
137+
color = color_support if is_support else color_block
138+
point = block.center()
139+
nodes.append(point)
140+
node_point[node] = point
141+
properties.append(
142+
{
143+
"pointcolor": color,
144+
"pointsize": 10,
145+
}
146+
)
147+
self.nodes = self.add(Collection(nodes, properties))
148+
149+
edges = []
150+
properties = []
151+
for u, v in assembly.graph.edges():
152+
a = node_point[u]
153+
b = node_point[v]
154+
color = Color.black()
155+
edges.append(Line(a, b))
156+
properties.append(
157+
{
158+
"linecolor": color,
159+
"linewidth": 3,
160+
}
161+
)
162+
self.edges = self.add(Collection(edges, properties))
163+
164+
blocks = []
165+
properties = []
166+
for node in assembly.graph.nodes():
167+
block = assembly.graph.node_attribute(node, "block")
168+
is_support = assembly.graph.node_attribute(node, "is_support")
169+
color = color_support if is_support else color_block
170+
blocks.append(block)
171+
properties.append(
172+
{
173+
"facecolor": color.lightened(50),
174+
"linecolor": color,
175+
"linewidth": linewidth,
176+
"show_faces": show_faces,
177+
"show_lines": show_lines,
178+
"show_points": show_points,
179+
}
180+
)
181+
self.blocks = self.add(Collection(blocks, properties), opacity=opacity)
182+
105183
blocks = []
106184
properties = []
107185
for node in assembly.graph.nodes():
@@ -134,6 +212,7 @@ def add_assembly(
134212
compression = []
135213
tension = []
136214
friction = []
215+
resultants = []
137216
for edge in assembly.graph.edges():
138217
interfaces: List[Interface] = assembly.graph.edge_attribute(
139218
edge, "interfaces"
@@ -142,6 +221,7 @@ def add_assembly(
142221
compression += interface.compressionforces
143222
tension += interface.tensionforces
144223
friction += interface.frictionforces
224+
resultants += interface.resultantforce
145225

146226
self._compression = [line.copy() for line in compression]
147227
self.compression = self.add(
@@ -164,6 +244,13 @@ def add_assembly(
164244
linecolor=Color.cyan(),
165245
)
166246

247+
self._resultants = [line.copy() for line in resultants]
248+
self.resultants = self.add(
249+
Collection(resultants),
250+
linewidth=3,
251+
linecolor=Color.green(),
252+
)
253+
167254
def _add_sidebar_items(self, items, *args, **kwargs):
168255
for item in items:
169256
if item["type"] == "radio":

src/compas_assembly/viewer/config.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@
9696
],
9797
"toolbar": [],
9898
"sidebar": [
99+
{
100+
"type": "checkbox",
101+
"text": "Show Nodes",
102+
"action": "show_nodes",
103+
"checked": true
104+
},
105+
{
106+
"type": "checkbox",
107+
"text": "Show Edges",
108+
"action": "show_edges",
109+
"checked": true
110+
},
99111
{
100112
"type": "checkbox",
101113
"text": "Show Interfaces",
@@ -114,6 +126,12 @@
114126
"action": "show_normalforces",
115127
"checked": true
116128
},
129+
{
130+
"type": "checkbox",
131+
"text": "Show Resultants",
132+
"action": "show_resultants",
133+
"checked": true
134+
},
117135
{
118136
"type": "slider",
119137
"annotation": "Scale Contact Forces",

0 commit comments

Comments
 (0)