Skip to content

Commit

Permalink
Exclude calculation of offset for mask shape type
Browse files Browse the repository at this point in the history
  • Loading branch information
healthonrails committed Jan 2, 2024
1 parent 36229c9 commit aefa664
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
15 changes: 5 additions & 10 deletions annolid/gui/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ def shape_type(self):
def shape_type(self, value):
if value is None:
value = "polygon"
if value == 'ai_polygon':
value = 'points'
if value not in [
"polygon",
"rectangle",
Expand Down Expand Up @@ -374,14 +372,11 @@ def makePath(self):
rectangle = self.getCircleRectFromLine(self.points)
path.addEllipse(rectangle)
else:
if self.points:
path = QtGui.QPainterPath(self.points[0])
for p in self.points[1:]:
path.lineTo(p)
return path
else:
return QtGui.QPainterPath()

path = QtGui.QPainterPath(self.points[0])
for p in self.points[1:]:
path.lineTo(p)
return path

def boundingRect(self):
return self.makePath().boundingRect()

Expand Down
41 changes: 24 additions & 17 deletions annolid/gui/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,26 +549,31 @@ def mousePressEvent(self, ev):
if self.createMode != "polygonSAM":
self.current = Shape(shape_type="points" if self.createMode in [
"ai_polygon", "ai_mask"] else self.createMode)
self.current.addPoint(pos)
else:
self.current = MultipoinstShape()
self.current.addPoint(pos, True)
if self.createMode == "point":
self.finalise()
else:
if self.createMode == "circle":
self.current.shape_type = "circle"
self.line.points = [pos, pos]
if (
self.current.addPoint(pos, label=0 if is_shift_pressed else 1)
if self.createMode == "point":
self.finalise()
elif (
self.createMode in ["ai_polygon", "ai_mask"]
and is_shift_pressed
and ev.modifiers() & QtCore.Qt.ControlModifier
):
self.line.point_labels = [0, 0]
self.finalise()
else:
self.line.point_labels = [1, 1]
self.setHiding()
self.drawingPolygon.emit(True)
self.update()
if self.createMode == "circle":
self.current.shape_type = "circle"
self.line.points = [pos, pos]
if (
self.createMode in ["ai_polygon", "ai_mask"]
and is_shift_pressed
):
self.line.point_labels = [0, 0]
else:
self.line.point_labels = [1, 1]
self.setHiding()
self.drawingPolygon.emit(True)
self.update()
else:
self.current = MultipoinstShape()
self.current.addPoint(pos, True)
elif self.editing():
if self.selectedEdge():
self.addPointToEdge()
Expand Down Expand Up @@ -728,6 +733,8 @@ def calculateOffsets(self, point):
top = self.pixmap.height() - 1
bottom = 0
for s in self.selectedShapes:
if s.shape_type == 'mask':
continue
rect = s.boundingRect()
if rect.left() < left:
left = rect.left()
Expand Down

0 comments on commit aefa664

Please sign in to comment.