Skip to content

Commit

Permalink
selection stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Nov 8, 2024
1 parent 2c6371d commit 4ee31c4
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 32 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

* Added `RhinoMeshObject.select_faces()`.
* Added `RhinoMeshObject.select_vertices_all()`.
* Added `RhinoMeshObject.select_vertices_boundary()`.
* Added `RhinoMeshObject.select_vertices_degree()`.
* Added `RhinoMeshObject.select_vertices_edgeloop()`.
* Added `RhinoMeshObject.select_vertices_edgestrip()`.
* Added `RhinoMeshObject.select_vertices_manual()`.
* Added `RhinoMeshObject.select_edges_all()`.
* Added `RhinoMeshObject.select_edges_boundary()`.
* Added `RhinoMeshObject.select_edges_loop()`.
* Added `RhinoMeshObject.select_edges_strip()`.
* Added `RhinoMeshObject.select_edges_manual()`.
* Added `RhinoMeshObject.select_faces_all()`.
* Added `RhinoMeshObject.select_faces_boundary()`.
* Added `RhinoMeshObject.select_faces_strip()`.
* Added `RhinoMeshObject.select_faces_manual()`.

### Changed

### Removed

## [0.3.2] 2024-11-07

### Added
Expand Down
143 changes: 111 additions & 32 deletions src/compas_rui/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,22 @@ def select_vertices(self, message="Select Vertices") -> list[int]:
return

if option == "All":
vertices = list(self.mesh.vertices())
vertices = self.select_vertices_all()

elif option == "Boundary":
vertices = list(set(flatten(self.mesh.vertices_on_boundaries())))
vertices = self.select_vertices_boundary()

elif option == "Degree":
D = rs.GetInteger(message="Vertex Degree", number=2, minimum=1)
D = D or 0
vertices = list(self.mesh.vertices_where(vertex_degree=D))
vertices = self.select_vertices_degree()

elif option == "EdgeLoop":
guids = compas_rhino.objects.select_lines(message="Select Loop Edges")
edges = [self._guid_edge[guid] for guid in guids if guid in self._guid_edge] if guids else []
temp = []
for edge in edges:
for u, v in self.mesh.edge_loop(edge):
temp.append(u)
temp.append(v)
vertices = list(set(temp))
vertices = self.select_vertices_edgeloop()

elif option == "EdgeStrip":
raise NotImplementedError
vertices = self.select_vertices_edgestrip()

elif option == "Manual":
guids = compas_rhino.objects.select_points(message="Select Manual Vertices")
vertices = [self._guid_vertex[guid] for guid in guids if guid in self._guid_vertex] if guids else []
vertices = self.select_vertices_manual()

vertex_guid = {vertex: guid for guid, vertex in self._guid_vertex.items()}
guids = [vertex_guid[vertex] for vertex in vertices]
Expand All @@ -65,37 +55,57 @@ def select_vertices(self, message="Select Vertices") -> list[int]:

return vertices

def select_vertices_all(self):
return list(self.mesh.vertices())

def select_vertices_boundary(self):
return list(set(flatten(self.mesh.vertices_on_boundaries())))

def select_vertices_degree(self):
D = rs.GetInteger(message="Vertex Degree", number=2, minimum=1)
D = D or 0
vertices = list(self.mesh.vertices_where(vertex_degree=D))
return vertices

def select_vertices_edgeloop(self):
guids = compas_rhino.objects.select_lines(message="Select Loop Edges")
edges = [self._guid_edge[guid] for guid in guids if guid in self._guid_edge] if guids else []
temp = []
for edge in edges:
for u, v in self.mesh.edge_loop(edge):
temp.append(u)
temp.append(v)
vertices = list(set(temp))
return vertices

def select_vertices_edgestrip(self):
raise NotImplementedError

def select_vertices_manual(self):
guids = compas_rhino.objects.select_points(message="Select Vertices")
vertices = [self._guid_vertex[guid] for guid in guids if guid in self._guid_vertex] if guids else []
return vertices

def select_edges(self, message="Select Edges") -> list[tuple[int, int]]:
options = ["All", "Boundary", "EdgeLoop", "EdgeStrip", "Manual"]
option = rs.GetString(message=message, strings=options)
if not option:
return

if option == "All":
edges = list(self.mesh.edges())
edges = self.select_edges_all()

elif option == "Boundary":
edges = list(set(flatten(self.mesh.edges_on_boundaries())))
edges = self.select_edges_boundary()

elif option == "EdgeLoop":
guids = compas_rhino.objects.select_lines(message="Select Loop Edges")
edges = []
for guid in guids:
edge = self._guid_edge[guid]
for edge in self.mesh.edge_loop(edge):
edges.append(edge)
edges = self.select_edges_loop()

elif option == "EdgeStrip":
guids = compas_rhino.objects.select_lines(message="Select Strip Edges")
edges = []
for guid in guids:
edge = self._guid_edge[guid]
for edge in self.mesh.edge_strip(edge):
edges.append(edge)
edges = self.select_edges_strip()

elif option == "Manual":
guids = compas_rhino.objects.select_lines(message="Select Manual Edges")
edges = [self._guid_edge[guid] for guid in guids if guid in self._guid_edge] if guids else []
edges = self.select_edges_manual()

edges = [(u, v) if self.mesh.has_edge((u, v)) else (v, u) for u, v in edges]
edge_guid = {edge: guid for guid, edge in self._guid_edge.items()}
Expand All @@ -106,6 +116,75 @@ def select_edges(self, message="Select Edges") -> list[tuple[int, int]]:

return edges

def select_edges_all(self):
return list(self.mesh.edges())

def select_edges_boundary(self):
return list(set(flatten(self.mesh.edges_on_boundaries())))

def select_edges_loop(self):
guids = compas_rhino.objects.select_lines(message="Select Loop Edges")
edges = []
for guid in guids:
edge = self._guid_edge[guid]
for edge in self.mesh.edge_loop(edge):
edges.append(edge)
return edges

def select_edges_strip(self):
guids = compas_rhino.objects.select_lines(message="Select Strip Edges")
edges = []
for guid in guids:
edge = self._guid_edge[guid]
for edge in self.mesh.edge_strip(edge):
edges.append(edge)
return edges

def select_edges_manual(self):
guids = compas_rhino.objects.select_lines(message="Select Edges")
edges = [self._guid_edge[guid] for guid in guids if guid in self._guid_edge] if guids else []
return edges

def select_faces(self, message="Select Faces") -> list[int]:
options = ["All", "Boundary", "Strip", "Manual"]
option = rs.GetString(message=message, strings=options)
if not option:
return

if option == "All":
faces = self.select_faces_all()

elif option == "Boundary":
faces = self.select_faces_boundary()

elif option == "Strip":
faces = self.select_faces_strip()

elif option == "Manual":
faces = self.select_faces_manual()

face_guid = {face: guid for guid, face in self._guid_face.items()}
guids = [face_guid[face] for face in faces]

rs.UnselectAllObjects()
rs.SelectObjects(guids)

return faces

def select_faces_all(self):
return list(self.mesh.faces())

def select_faces_boundary(self):
return list(set(flatten(self.mesh.faces_on_boundaries())))

def select_faces_strip(self):
raise NotImplementedError

def select_faces_manual(self):
guids = compas_rhino.objects.select_meshes(message="Select Faces")
faces = [self._guid_face[guid] for guid in guids if guid in self._guid_face] if guids else []
return faces

# =============================================================================
# =============================================================================
# =============================================================================
Expand Down

0 comments on commit 4ee31c4

Please sign in to comment.