Merge pull request #1572 from outofculture/arbitrary-scale-center

Arbitrary scale center ROI
This commit is contained in:
Ogi Moore 2021-02-14 08:49:03 -08:00 committed by GitHub
commit 5bfe8d5a46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 21 deletions

View File

@ -126,7 +126,9 @@ r3b.addRotateHandle([0, 1], [1, 0])
## handles rotating/scaling around center ## handles rotating/scaling around center
r3b.addScaleRotateHandle([0, 0.5], [0.5, 0.5]) r3b.addScaleRotateHandle([0, 0.5], [0.5, 0.5])
r3b.addScaleRotateHandle([1, 0.5], [0.5, 0.5])
# handles rotating/scaling around arbitrary point
r3b.addScaleRotateHandle([0.3, 0], [0.9, 0.7])
v3.disableAutoRange('xy') v3.disableAutoRange('xy')
v3.autoRange() v3.autoRange()

View File

@ -575,8 +575,8 @@ class ROI(GraphicsObject):
""" """
pos = Point(pos) pos = Point(pos)
center = Point(center) center = Point(center)
if pos[0] != center[0] and pos[1] != center[1]: if pos[0] == center[0] and pos[1] == center[1]:
raise Exception("Scale/rotate handles must have either the same x or y coordinate as their center point.") raise Exception("Scale/rotate handles cannot be at their center point.")
return self.addHandle({'name': name, 'type': 'sr', 'center': center, 'pos': pos, 'item': item}, index=index) return self.addHandle({'name': name, 'type': 'sr', 'center': center, 'pos': pos, 'item': item}, index=index)
def addRotateFreeHandle(self, pos, center, axes=None, item=None, name=None, index=None): def addRotateFreeHandle(self, pos, center, axes=None, item=None, name=None, index=None):
@ -955,13 +955,6 @@ class ROI(GraphicsObject):
h['pos'] = self.mapFromParent(p1) h['pos'] = self.mapFromParent(p1)
elif h['type'] == 'sr': elif h['type'] == 'sr':
if h['center'][0] == h['pos'][0]:
scaleAxis = 1
nonScaleAxis=0
else:
scaleAxis = 0
nonScaleAxis=1
try: try:
if lp1.length() == 0 or lp0.length() == 0: if lp1.length() == 0 or lp0.length() == 0:
return return
@ -973,17 +966,22 @@ class ROI(GraphicsObject):
return return
if self.rotateSnap or (modifiers & QtCore.Qt.ControlModifier): if self.rotateSnap or (modifiers & QtCore.Qt.ControlModifier):
ang = round(ang / self.rotateSnapAngle) * self.rotateSnapAngle ang = round(ang / self.rotateSnapAngle) * self.rotateSnapAngle
hs = abs(h['pos'][scaleAxis] - c[scaleAxis]) if self.aspectLocked or h['center'][0] != h['pos'][0]:
newState['size'][scaleAxis] = lp1.length() / hs newState['size'][0] = self.state['size'][0] * lp1.length() / lp0.length()
#if self.scaleSnap or (modifiers & QtCore.Qt.ControlModifier): if self.scaleSnap: # use CTRL only for angular snap here.
if self.scaleSnap: ## use CTRL only for angular snap here. newState['size'][0] = round(newState['size'][0] / self.snapSize) * self.snapSize
newState['size'][scaleAxis] = round(newState['size'][scaleAxis] / self.snapSize) * self.snapSize
if newState['size'][scaleAxis] == 0: if self.aspectLocked or h['center'][1] != h['pos'][1]:
newState['size'][scaleAxis] = 1 newState['size'][1] = self.state['size'][1] * lp1.length() / lp0.length()
if self.aspectLocked: if self.scaleSnap: # use CTRL only for angular snap here.
newState['size'][nonScaleAxis] = newState['size'][scaleAxis] newState['size'][1] = round(newState['size'][1] / self.snapSize) * self.snapSize
if newState['size'][0] == 0:
newState['size'][0] = 1
if newState['size'][1] == 0:
newState['size'][1] = 1
c1 = c * newState['size'] c1 = c * newState['size']
tr = QtGui.QTransform() tr = QtGui.QTransform()
tr.rotate(ang) tr.rotate(ang)