Skip to content

Commit ee7621b

Browse files
authored
Merge pull request #1278 from compas-dev/meshobject
allow list of keys for showing vertices/edges/faces
2 parents a8ee4e2 + db32ebc commit ee7621b

File tree

10 files changed

+207
-117
lines changed

10 files changed

+207
-117
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added `group` attribute to `compas_rhino.scene.RhinoSceneObject`.
13+
* Added `_guid_mesh`, `_guids_vertices`, `_guids_edges`, `_guids_faces`, `_guids_vertexlabels`, `_guids_edgelables`, `_guids_facelabels`, `_guids_vertexnormals`, `_guids_facenormals`, `_guids_spheres`, `_guids_pipes`, `disjoint` attributes to `compas_rhino.scene.MeshObject`.
14+
* Added `_guids_nodes`, `_guids_edges`, `_guids_nodelabels`, `_guids_edgelables`, `_guids_spheres`, `_guids_pipes` attributes to `compas_rhino.scene.GraphObject`.
15+
* Added `_guids_vertices`, `_guids_edges`, `_guids_faces`, `_guids_cells`, `_guids_vertexlabels`, `_guids_edgelables`, `_guids_facelabels`, `_guids_celllabels`, `disjoint` attributes to `compas_rhino.scene.MeshObject`.
1216
* Added test for `compas.scene.Scene` serialisation.
1317

1418
### Changed
1519

20+
* Changed `compas.scene.Mesh`'s `show_vertices`, `show_edges`, `show_faces` to optionally accept a sequence of keys.
21+
* Changed `compas.scene.Graph`'s `show_nodes`, `show_edges` to optionally accept a sequence of keys.
22+
* Changed `compas.scene.VolMesh`'s `show_vertices`, `show_edges`, `show_faces`, `show_cells` to optionally accept a sequence of keys.
1623
* Fixed missing implementation of `Sphere.base`.
1724
* Fixed bug in `intersection_sphere_sphere`.
1825

1926
### Removed
2027

28+
* Removed kwargs from `compas_rhino.scene.MeshObject.draw`.
29+
* Removed kwargs from `compas_rhino.scene.GraphObject.draw`.
30+
* Removed kwargs from `compas_rhino.scene.VolMeshObject.draw`.
31+
2132
## [2.0.0-beta.4] 2024-01-26
2233

2334
### Added

src/compas/scene/graphobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class GraphObject(SceneObject):
3030
The size of the nodes. Default is ``1.0``.
3131
edgewidth : float
3232
The width of the edges. Default is ``1.0``.
33-
show_nodes : bool
33+
show_nodes : Union[bool, sequence[float]]
3434
Flag for showing or hiding the nodes. Default is ``True``.
35-
show_edges : bool
35+
show_edges : Union[bool, sequence[tuple[hashable, hashable]]]
3636
Flag for showing or hiding the edges. Default is ``True``.
3737
3838
See Also

src/compas/scene/meshobject.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ class MeshObject(SceneObject):
3434
The size of the vertices. Default is ``1.0``.
3535
edgewidth : float
3636
The width of the edges. Default is ``1.0``.
37-
show_vertices : bool
38-
Flag for showing or hiding the vertices. Default is ``False``.
39-
show_edges : bool
40-
Flag for showing or hiding the edges. Default is ``True``.
41-
show_faces : bool
42-
Flag for showing or hiding the faces. Default is ``True``.
37+
show_vertices : Union[bool, sequence[float]]
38+
Flag for showing or hiding the vertices, or a list of keys for the vertices to show.
39+
Default is ``False``.
40+
show_edges : Union[bool, sequence[tuple[int, int]]]
41+
Flag for showing or hiding the edges, or a list of keys for the edges to show.
42+
Default is ``True``.
43+
show_faces : Union[bool, sequence[int]]
44+
Flag for showing or hiding the faces, or a list of keys for the faces to show.
45+
Default is ``True``.
4346
4447
See Also
4548
--------

src/compas/scene/scene.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ def draw(self):
300300

301301
drawn_objects = []
302302
for sceneobject in self.objects:
303-
drawn_objects += sceneobject.draw()
303+
if sceneobject.show:
304+
drawn_objects += sceneobject.draw()
304305

305306
after_draw(drawn_objects)
306307

src/compas/scene/volmeshobject.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ class VolMeshObject(SceneObject):
3838
The size of the vertices. Default is ``1.0``.
3939
edgewidth : float
4040
The width of the edges. Default is ``1.0``.
41-
show_vertices : bool
42-
Flag for showing or hiding the vertices. Default is ``False``.
43-
show_edges : bool
44-
Flag for showing or hiding the edges. Default is ``True``.
45-
show_faces : bool
46-
Flag for showing or hiding the faces. Default is ``True``.
41+
show_vertices : Union[bool, sequence[float]]
42+
Flag for showing or hiding the vertices, or a list of keys for the vertices to show.
43+
Default is ``False``.
44+
show_edges : Union[bool, sequence[tuple[int, int]]]
45+
Flag for showing or hiding the edges, or a list of keys for the edges to show.
46+
Default is ``True``.
47+
show_faces : Union[bool, sequence[int]]
48+
Flag for showing or hiding the faces, or a list of keys for the faces to show.
49+
Default is ``False``.
4750
show_cells : bool
48-
Flag for showing or hiding the cells. Default is ``True``.
51+
Flag for showing or hiding the cells, or a list of keys for the cells to show.
52+
Default is ``True``.
4953
5054
See Also
5155
--------
@@ -72,7 +76,7 @@ def __init__(self, volmesh, **kwargs):
7276
self.edgewidth = kwargs.get("edgewidth", 1.0)
7377
self.show_vertices = kwargs.get("show_vertices", False)
7478
self.show_edges = kwargs.get("show_edges", True)
75-
self.show_faces = kwargs.get("show_faces", True)
79+
self.show_faces = kwargs.get("show_faces", False)
7680
self.show_cells = kwargs.get("show_cells", True)
7781

7882
@property

src/compas_rhino/scene/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def ngon(v):
4545
if v < 3:
4646
return
4747
if v == 3:
48-
return [0, 1, 2, 2]
48+
return [0, 1, 2]
4949
if v == 4:
5050
return [0, 1, 2, 3]
5151
return list(range(v))

src/compas_rhino/scene/graphobject.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class GraphObject(RhinoSceneObject, BaseGraphObject):
3232

3333
def __init__(self, graph, **kwargs):
3434
super(GraphObject, self).__init__(graph=graph, **kwargs)
35+
self._guids_nodes = None
36+
self._guids_edges = None
37+
self._guids_nodelabels = None
38+
self._guids_edgelabels = None
39+
self._guids_spheres = None
40+
self._guids_pipes = None
3541

3642
# ==========================================================================
3743
# clear
@@ -45,8 +51,7 @@ def clear(self):
4551
None
4652
4753
"""
48-
guids = compas_rhino.objects.get_objects(name="{}.*".format(self.graph.name)) # type: ignore
49-
compas_rhino.objects.delete_objects(guids, purge=True)
54+
compas_rhino.objects.delete_objects(self.guids, purge=True)
5055

5156
def clear_nodes(self):
5257
"""Delete all nodes drawn by this scene object.
@@ -56,8 +61,7 @@ def clear_nodes(self):
5661
None
5762
5863
"""
59-
guids = compas_rhino.objects.get_objects(name="{}.node.*".format(self.graph.name)) # type: ignore
60-
compas_rhino.objects.delete_objects(guids, purge=True)
64+
compas_rhino.objects.delete_objects(self._guids_nodes, purge=True)
6165

6266
def clear_edges(self):
6367
"""Delete all edges drawn by this scene object.
@@ -67,44 +71,24 @@ def clear_edges(self):
6771
None
6872
6973
"""
70-
guids = compas_rhino.objects.get_objects(name="{}.edge.*".format(self.graph.name)) # type: ignore
71-
compas_rhino.objects.delete_objects(guids, purge=True)
74+
compas_rhino.objects.delete_objects(self._guids_edges, purge=True)
7275

7376
# ==========================================================================
7477
# draw
7578
# ==========================================================================
7679

77-
def draw(
78-
self,
79-
nodes=None,
80-
edges=None,
81-
nodecolor=None,
82-
edgecolor=None,
83-
):
80+
def draw(self):
8481
"""Draw the graph using the chosen visualisation settings.
8582
86-
Parameters
87-
----------
88-
nodes : list[int], optional
89-
A list of nodes to draw.
90-
Default is None, in which case all nodes are drawn.
91-
edges : list[tuple[int, int]], optional
92-
A list of edges to draw.
93-
The default is None, in which case all edges are drawn.
94-
nodecolor : :class:`compas.colors.Color` | dict[int, :class:`compas.colors.Color`], optional
95-
The color of the nodes.
96-
edgecolor : :class:`compas.colors.Color` | dict[tuple[int, int], :class:`compas.colors.Color`], optional
97-
The color of the edges.
98-
9983
Returns
10084
-------
10185
list[System.Guid]
10286
The GUIDs of the created Rhino objects.
10387
10488
"""
10589
self.clear()
106-
guids = self.draw_nodes(nodes=nodes, color=nodecolor)
107-
guids += self.draw_edges(edges=edges, color=edgecolor)
90+
guids = self.draw_nodes(nodes=self.show_nodes, color=self.nodecolor, group=self.group)
91+
guids += self.draw_edges(edges=self.show_edges, color=self.edgecolor, group=self.group)
10892
self._guids = guids
10993
return self.guids
11094

@@ -129,6 +113,9 @@ def draw_nodes(self, nodes=None, color=None, group=None):
129113

130114
self.nodecolor = color
131115

116+
if nodes is True:
117+
nodes = list(self.graph.nodes())
118+
132119
for node in nodes or self.graph.nodes(): # type: ignore
133120
name = "{}.node.{}".format(self.graph.name, node) # type: ignore
134121
attr = attributes(name=name, color=self.nodecolor[node], layer=self.layer) # type: ignore
@@ -141,6 +128,8 @@ def draw_nodes(self, nodes=None, color=None, group=None):
141128
if group:
142129
self.add_to_group(group, guids)
143130

131+
self._guids_nodes = guids
132+
144133
return guids
145134

146135
def draw_edges(self, edges=None, color=None, group=None, show_direction=False):
@@ -169,6 +158,9 @@ def draw_edges(self, edges=None, color=None, group=None, show_direction=False):
169158
arrow = "end" if show_direction else None
170159
self.edgecolor = color
171160

161+
if edges is True:
162+
edges = list(self.graph.edges())
163+
172164
for edge in edges or self.graph.edges(): # type: ignore
173165
u, v = edge
174166

@@ -184,6 +176,8 @@ def draw_edges(self, edges=None, color=None, group=None, show_direction=False):
184176
if group:
185177
self.add_to_group(group, guids)
186178

179+
self._guids_edges = guids
180+
187181
return guids
188182

189183
# =============================================================================
@@ -232,6 +226,8 @@ def draw_nodelabels(self, text, color=None, group=None, fontheight=10, fontface=
232226
if group:
233227
self.add_to_group(group, guids)
234228

229+
self._guids_nodelabels = guids
230+
235231
return guids
236232

237233
def draw_edgelabels(self, text, color=None, group=None, fontheight=10, fontface="Arial Regular"):
@@ -280,6 +276,8 @@ def draw_edgelabels(self, text, color=None, group=None, fontheight=10, fontface=
280276
if group:
281277
self.add_to_group(group, guids)
282278

279+
self._guids_edgelabels = guids
280+
283281
return guids
284282

285283
# =============================================================================
@@ -322,6 +320,8 @@ def draw_spheres(self, radius, color=None, group=None):
322320
if group:
323321
self.add_to_group(group, guids)
324322

323+
self._guids_spheres = guids
324+
325325
return guids
326326

327327
def draw_pipes(self, radius, color=None, group=None):
@@ -361,4 +361,6 @@ def draw_pipes(self, radius, color=None, group=None):
361361
if group:
362362
self.add_to_group(group, guids)
363363

364+
self._guids_pipes = guids
365+
364366
return guids

0 commit comments

Comments
 (0)