Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make point, line and two-point linestrip shapes selectable #1502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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