import PyQt5.QtWidgets as QtWidgets
import PyQt5.QtCore as QtCore
import PyQt5.QtGui as QtGui
import xasy2asy as xasy2asy
import xasyUtils as xasyUtils
import Widg_editBezier as Web
#The magnification isn't being set. Here I'm manually setting it to be the square root of the determinant.
self.info['magnification'] = math.sqrt(abs(self.transf.xx * self.transf.yy - self.transf.xy * self.transf.yx))
if index == 0 and not isCycle:
preCtrl = None
else:
preCtrl = self.asyPath.controlSet[index - 1][1]
if index == len(self.asyPath.nodeSet) - 1 and not isCycle:
postCtrl = None
else:
postCtrl = self.asyPath.controlSet[index % (len(self.asyPath.nodeSet) - 1)][0]
return preCtrl, postCtrl
def findLinkingNode(self, index, subindex):
"""index and subindex are of the control points list."""
if subindex == 0:
return index
else:
if self.asyPath.nodeSet[index + 1] == 'cycle':
return 0
else:
return index + 1
if parentNode == 'cycle':
parentNode = self.asyPath.nodeSet[0]
self.parentNodeIndex = 0
if preCtrl is not None:
self.preCtrlOffset = xasyUtils.funcOnList(
preCtrl, parentNode, lambda a, b: a - b)
else:
self.preCtrlOffset = None
if postCtrl is not None:
self.postCtrlOffset = xasyUtils.funcOnList(
postCtrl, parentNode, lambda a, b: a - b)
else:
self.postCtrlOffset = None
def mouseMove(self, pos, event: QtGui.QMouseEvent):
if self.currentSelMode is None and not self.inTransformMode:
# in this case, search for prosective nodes.
prospectiveNodes = []
prospectiveCtrlpts = []
for i in range(len(self.nodeSelRects)):
rect = self.nodeSelRects[i]
if rect is None:
continue
if rect.contains(pos):
prospectiveNodes.append(i)
self.prosectiveNodes = prospectiveNodes
if not self.info['autoRecompute'] and self.curveMode:
for i in range(len(self.ctrlSelRects)):
recta, rectb = self.ctrlSelRects[i]
if recta.contains(pos):
prospectiveCtrlpts.append((i, 0))
if rectb.contains(pos):
prospectiveCtrlpts.append((i, 1))
if self.inTransformMode:
index, subindex = self.currentSelIndex
newNode = (self.transf.inverted().toQTransform().map(pos.x(), pos.y()))
if self.currentSelMode == CurrentlySelctedType.node:
# static throughout the moving
if self.asyPath.nodeSet[index] == 'cycle':
return
self.asyPath.setNode(index, newNode)
# if also move node:
if self.curveMode:
checkPre, checkPost = self.getPreAndPostCtrlPts(index)
if 1 == 1: # TODO: Replace this with an option to also move control pts.
if checkPre is not None:
self.asyPath.controlSet[index - 1][1] = xasyUtils.funcOnList(
newNode, self.preCtrlOffset, lambda a, b: a + b
)
if checkPost is not None:
self.asyPath.controlSet[index][0] = xasyUtils.funcOnList(
newNode, self.postCtrlOffset, lambda a, b: a + b
)
if self.info['autoRecompute']:
self.quickRecalculateCtrls()
if self.parentNodeIndex == 0 and self.asyPath.nodeSet[-1] == 'cycle':
isCycle = True
rawNewNode = xasyUtils.funcOnList(newNode, parentNode, lambda a, b: a - b)
rawAngle = math.atan2(rawNewNode[1], rawNewNode[0])
newNorm = xasyUtils.twonorm(rawNewNode)
if self.info['editBezierlockMode'] >= Web.LockMode.angleLock:
otherIndex = 1 - subindex # 1 if 0, 0 otherwise.
if otherIndex == 0:
if index < (len(self.asyPath.controlSet) - 1) or isCycle:
newIndex = 0 if isCycle else index + 1
oldOtherCtrlPnt = xasyUtils.funcOnList(
self.asyPath.controlSet[newIndex][0], parentNode, lambda a, b: a - b)
self.asyPath.controlSet[newIndex][0] = xasyUtils.funcOnList(
newPnt, parentNode, lambda a, b: a + b)
else:
if index > 0 or isCycle:
newIndex = -1 if isCycle else index - 1
oldOtherCtrlPnt = xasyUtils.funcOnList(
self.asyPath.controlSet[newIndex][1], parentNode, lambda a, b: a - b)