Skip to content

Commit e106ecf

Browse files
committed
align datastructure objects in rhino
1 parent fdd577a commit e106ecf

File tree

5 files changed

+88
-67
lines changed

5 files changed

+88
-67
lines changed

src/compas/scene/volmeshobject.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class VolMeshObject(SceneObject):
4646
Default is ``True``.
4747
show_faces : Union[bool, sequence[int]]
4848
Flag for showing or hiding the faces, or a list of keys for the faces to show.
49-
Default is ``True``.
49+
Default is ``False``.
5050
show_cells : bool
5151
Flag for showing or hiding the cells, or a list of keys for the cells to show.
5252
Default is ``True``.
@@ -76,7 +76,7 @@ def __init__(self, volmesh, **kwargs):
7676
self.edgewidth = kwargs.get("edgewidth", 1.0)
7777
self.show_vertices = kwargs.get("show_vertices", False)
7878
self.show_edges = kwargs.get("show_edges", True)
79-
self.show_faces = kwargs.get("show_faces", True)
79+
self.show_faces = kwargs.get("show_faces", False)
8080
self.show_cells = kwargs.get("show_cells", True)
8181

8282
@property

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

src/compas_rhino/scene/meshobject.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,12 @@ class MeshObject(RhinoSceneObject, BaseMeshObject):
4242
disjoint : bool, optional
4343
Draw the faces of the mesh disjointed.
4444
Default is ``False``.
45-
group : str, optional
46-
The name of the group to add the mesh components. The group will be created if not already present.
47-
Default is ``None``.
4845
4946
"""
5047

51-
def __init__(self, mesh, **kwargs):
48+
def __init__(self, mesh, disjoint=False, **kwargs):
5249
super(MeshObject, self).__init__(mesh=mesh, **kwargs)
53-
self.disjoint = kwargs.get("disjoint", False)
54-
self.group = kwargs.get("group", None)
50+
self.disjoint = disjoint
5551
self._guid_mesh = None
5652
self._guids_faces = None
5753
self._guids_edges = None

src/compas_rhino/scene/sceneobject.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ class RhinoSceneObject(SceneObject):
1515
----------
1616
layer : str, optional
1717
A layer name.
18+
group : str, optional
19+
The name of the group to add the mesh components. The group will be created if not already present.
20+
Default is ``None``.
1821
**kwargs : dict, optional
1922
Additional keyword arguments.
2023
2124
"""
2225

23-
def __init__(self, layer=None, **kwargs):
26+
def __init__(self, layer=None, group=None, **kwargs):
2427
super(RhinoSceneObject, self).__init__(**kwargs)
2528
self.layer = layer
29+
self.group = group
2630

2731
def get_group(self, name):
2832
"""Find the group with the given name, or create a new one.

0 commit comments

Comments
 (0)