Skip to content

Commit

Permalink
Make point, line and two-point linestrip shapes selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynjxsjmh committed Sep 28, 2024
1 parent b9c83ff commit e6fd024
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions labelme/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,17 @@ def mouseMoveEvent(self, ev):
self.hEdge = None
shape.highlightVertex(index, shape.MOVE_VERTEX)
self.overrideCursor(CURSOR_POINT)
self.setToolTip(
self.tr(
"Click & Drag to move point\n"
"ALT + SHIFT + Click to delete point"
if shape.shape_type == "point":
self.setToolTip(
self.tr("Click & drag to move shape '%s'") % shape.label
)
else:
self.setToolTip(
self.tr(
"Click & Drag to move point\n"
"ALT + SHIFT + Click to delete point"
)
)
)
self.setStatusTip(self.toolTip())
self.update()
break
Expand All @@ -363,7 +368,15 @@ def mouseMoveEvent(self, ev):
self.setStatusTip(self.toolTip())
self.update()
break
elif shape.containsPoint(pos):
elif (
shape.containsPoint(pos)
or (shape.shape_type == "line" and index_edge is not None)
or (
shape.shape_type == "linestrip"
and len(shape.points) == 2
and index_edge is not None
)
):
if self.selectedVertex():
self.hShape.highlightClear()
self.prevhVertex = self.hVertex
Expand Down Expand Up @@ -567,12 +580,24 @@ def selectShapes(self, shapes):

def selectShapePoint(self, point, multiple_selection_mode):
"""Select the first shape created which contains this point."""
if self.selectedVertex(): # A vertex is marked for selection.
if self.selectedVertex() and self.hShape.shape_type != "point":
# A vertex, not point shape, is marked for selection.
index, shape = self.hVertex, self.hShape
shape.highlightVertex(index, shape.MOVE_VERTEX)
else:
for shape in reversed(self.shapes):
if self.isVisible(shape) and shape.containsPoint(point):
index_vertex = shape.nearestVertex(point, self.epsilon)
index_edge = shape.nearestEdge(point, self.epsilon)
if self.isVisible(shape) and (
shape.containsPoint(point)
or (shape.shape_type == "point" and index_vertex is not None)
or (shape.shape_type == "line" and index_edge is not None)
or (
shape.shape_type == "linestrip"
and len(shape.points) == 2
and index_edge is not None
)
):
self.setHiding()
if shape not in self.selectedShapes:
if multiple_selection_mode:
Expand Down

0 comments on commit e6fd024

Please sign in to comment.