Skip to content

Commit

Permalink
Merge pull request #1278 from compas-dev/meshobject
Browse files Browse the repository at this point in the history
allow list of keys for showing vertices/edges/faces
  • Loading branch information
Licini authored Jan 31, 2024
2 parents a8ee4e2 + db32ebc commit ee7621b
Show file tree
Hide file tree
Showing 10 changed files with 207 additions and 117 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Added `group` attribute to `compas_rhino.scene.RhinoSceneObject`.
* 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`.
* Added `_guids_nodes`, `_guids_edges`, `_guids_nodelabels`, `_guids_edgelables`, `_guids_spheres`, `_guids_pipes` attributes to `compas_rhino.scene.GraphObject`.
* Added `_guids_vertices`, `_guids_edges`, `_guids_faces`, `_guids_cells`, `_guids_vertexlabels`, `_guids_edgelables`, `_guids_facelabels`, `_guids_celllabels`, `disjoint` attributes to `compas_rhino.scene.MeshObject`.
* Added test for `compas.scene.Scene` serialisation.

### Changed

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

### Removed

* Removed kwargs from `compas_rhino.scene.MeshObject.draw`.
* Removed kwargs from `compas_rhino.scene.GraphObject.draw`.
* Removed kwargs from `compas_rhino.scene.VolMeshObject.draw`.

## [2.0.0-beta.4] 2024-01-26

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/compas/scene/graphobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class GraphObject(SceneObject):
The size of the nodes. Default is ``1.0``.
edgewidth : float
The width of the edges. Default is ``1.0``.
show_nodes : bool
show_nodes : Union[bool, sequence[float]]
Flag for showing or hiding the nodes. Default is ``True``.
show_edges : bool
show_edges : Union[bool, sequence[tuple[hashable, hashable]]]
Flag for showing or hiding the edges. Default is ``True``.
See Also
Expand Down
15 changes: 9 additions & 6 deletions src/compas/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ class MeshObject(SceneObject):
The size of the vertices. Default is ``1.0``.
edgewidth : float
The width of the edges. Default is ``1.0``.
show_vertices : bool
Flag for showing or hiding the vertices. Default is ``False``.
show_edges : bool
Flag for showing or hiding the edges. Default is ``True``.
show_faces : bool
Flag for showing or hiding the faces. Default is ``True``.
show_vertices : Union[bool, sequence[float]]
Flag for showing or hiding the vertices, or a list of keys for the vertices to show.
Default is ``False``.
show_edges : Union[bool, sequence[tuple[int, int]]]
Flag for showing or hiding the edges, or a list of keys for the edges to show.
Default is ``True``.
show_faces : Union[bool, sequence[int]]
Flag for showing or hiding the faces, or a list of keys for the faces to show.
Default is ``True``.
See Also
--------
Expand Down
3 changes: 2 additions & 1 deletion src/compas/scene/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ def draw(self):

drawn_objects = []
for sceneobject in self.objects:
drawn_objects += sceneobject.draw()
if sceneobject.show:
drawn_objects += sceneobject.draw()

after_draw(drawn_objects)

Expand Down
20 changes: 12 additions & 8 deletions src/compas/scene/volmeshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ class VolMeshObject(SceneObject):
The size of the vertices. Default is ``1.0``.
edgewidth : float
The width of the edges. Default is ``1.0``.
show_vertices : bool
Flag for showing or hiding the vertices. Default is ``False``.
show_edges : bool
Flag for showing or hiding the edges. Default is ``True``.
show_faces : bool
Flag for showing or hiding the faces. Default is ``True``.
show_vertices : Union[bool, sequence[float]]
Flag for showing or hiding the vertices, or a list of keys for the vertices to show.
Default is ``False``.
show_edges : Union[bool, sequence[tuple[int, int]]]
Flag for showing or hiding the edges, or a list of keys for the edges to show.
Default is ``True``.
show_faces : Union[bool, sequence[int]]
Flag for showing or hiding the faces, or a list of keys for the faces to show.
Default is ``False``.
show_cells : bool
Flag for showing or hiding the cells. Default is ``True``.
Flag for showing or hiding the cells, or a list of keys for the cells to show.
Default is ``True``.
See Also
--------
Expand All @@ -72,7 +76,7 @@ def __init__(self, volmesh, **kwargs):
self.edgewidth = kwargs.get("edgewidth", 1.0)
self.show_vertices = kwargs.get("show_vertices", False)
self.show_edges = kwargs.get("show_edges", True)
self.show_faces = kwargs.get("show_faces", True)
self.show_faces = kwargs.get("show_faces", False)
self.show_cells = kwargs.get("show_cells", True)

@property
Expand Down
2 changes: 1 addition & 1 deletion src/compas_rhino/scene/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def ngon(v):
if v < 3:
return
if v == 3:
return [0, 1, 2, 2]
return [0, 1, 2]
if v == 4:
return [0, 1, 2, 3]
return list(range(v))
58 changes: 30 additions & 28 deletions src/compas_rhino/scene/graphobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class GraphObject(RhinoSceneObject, BaseGraphObject):

def __init__(self, graph, **kwargs):
super(GraphObject, self).__init__(graph=graph, **kwargs)
self._guids_nodes = None
self._guids_edges = None
self._guids_nodelabels = None
self._guids_edgelabels = None
self._guids_spheres = None
self._guids_pipes = None

# ==========================================================================
# clear
Expand All @@ -45,8 +51,7 @@ def clear(self):
None
"""
guids = compas_rhino.objects.get_objects(name="{}.*".format(self.graph.name)) # type: ignore
compas_rhino.objects.delete_objects(guids, purge=True)
compas_rhino.objects.delete_objects(self.guids, purge=True)

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

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

# ==========================================================================
# draw
# ==========================================================================

def draw(
self,
nodes=None,
edges=None,
nodecolor=None,
edgecolor=None,
):
def draw(self):
"""Draw the graph using the chosen visualisation settings.
Parameters
----------
nodes : list[int], optional
A list of nodes to draw.
Default is None, in which case all nodes are drawn.
edges : list[tuple[int, int]], optional
A list of edges to draw.
The default is None, in which case all edges are drawn.
nodecolor : :class:`compas.colors.Color` | dict[int, :class:`compas.colors.Color`], optional
The color of the nodes.
edgecolor : :class:`compas.colors.Color` | dict[tuple[int, int], :class:`compas.colors.Color`], optional
The color of the edges.
Returns
-------
list[System.Guid]
The GUIDs of the created Rhino objects.
"""
self.clear()
guids = self.draw_nodes(nodes=nodes, color=nodecolor)
guids += self.draw_edges(edges=edges, color=edgecolor)
guids = self.draw_nodes(nodes=self.show_nodes, color=self.nodecolor, group=self.group)
guids += self.draw_edges(edges=self.show_edges, color=self.edgecolor, group=self.group)
self._guids = guids
return self.guids

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

self.nodecolor = color

if nodes is True:
nodes = list(self.graph.nodes())

for node in nodes or self.graph.nodes(): # type: ignore
name = "{}.node.{}".format(self.graph.name, node) # type: ignore
attr = attributes(name=name, color=self.nodecolor[node], layer=self.layer) # type: ignore
Expand All @@ -141,6 +128,8 @@ def draw_nodes(self, nodes=None, color=None, group=None):
if group:
self.add_to_group(group, guids)

self._guids_nodes = guids

return guids

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

if edges is True:
edges = list(self.graph.edges())

for edge in edges or self.graph.edges(): # type: ignore
u, v = edge

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

self._guids_edges = guids

return guids

# =============================================================================
Expand Down Expand Up @@ -232,6 +226,8 @@ def draw_nodelabels(self, text, color=None, group=None, fontheight=10, fontface=
if group:
self.add_to_group(group, guids)

self._guids_nodelabels = guids

return guids

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

self._guids_edgelabels = guids

return guids

# =============================================================================
Expand Down Expand Up @@ -322,6 +320,8 @@ def draw_spheres(self, radius, color=None, group=None):
if group:
self.add_to_group(group, guids)

self._guids_spheres = guids

return guids

def draw_pipes(self, radius, color=None, group=None):
Expand Down Expand Up @@ -361,4 +361,6 @@ def draw_pipes(self, radius, color=None, group=None):
if group:
self.add_to_group(group, guids)

self._guids_pipes = guids

return guids
Loading

0 comments on commit ee7621b

Please sign in to comment.