def realignLayer(thisLayer):
	countOfHandlesOnLayer = 0
	for thisPath in thisLayer.paths:
		for thisNode in thisPath.nodes:
			if thisNode.type == GSOFFCURVE:
				countOfHandlesOnLayer += 1
				selectedNode = NSMutableArray.arrayWithObject_(thisNode)
				thisLayer.setSelection_( selectedNode )
				Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_( thisLayer, thisLayer, moveForward, noModifier )
				Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_( thisLayer, thisLayer, moveBackward, noModifier )
	thisLayer.setSelection_( () )
	return countOfHandlesOnLayer
示例#2
0
    def realignLayer(self,
                     thisLayer,
                     shouldRealign=False,
                     shouldReport=False,
                     shouldVerbose=False):
        moveForward = NSPoint(1, 0)
        moveBackward = NSPoint(-1, 0)
        noModifier = NSNumber.numberWithUnsignedInteger_(0)
        layerCount = 0

        if thisLayer:
            for thisPath in thisLayer.paths:
                oldPathCoordinates = [n.position for n in thisPath.nodes]
                for thisNode in thisPath.nodes:
                    if thisNode.type == GSOFFCURVE:
                        oldPosition = NSPoint(thisNode.position.x,
                                              thisNode.position.y)
                        selectedNode = NSMutableArray.arrayWithObject_(
                            thisNode)
                        thisLayer.setSelection_(selectedNode)
                        self.Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_(
                            thisLayer, thisLayer, moveForward, noModifier)
                        self.Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_(
                            thisLayer, thisLayer, moveBackward, noModifier)

                for i, coordinate in enumerate(oldPathCoordinates):
                    if thisPath.nodes[i].position != coordinate:
                        layerCount += 1

                        # put handle back if not desired by user:
                        if not shouldRealign:
                            thisPath.nodes[i].position = coordinate
        thisLayer.setSelection_(())

        if shouldVerbose:
            if layerCount:
                if shouldRealign:
                    print(u"   ⚠️ Realigned %i handle%s." %
                          (layerCount, "" if layerCount == 1 else "s"))
                else:
                    print(u"   ❌ %i handle%s are unaligned." %
                          (layerCount, "" if layerCount == 1 else "s"))
            else:
                print(u"   ✅ All BCPs OK.")

        return layerCount
    def realignLayer(self,
                     thisLayer,
                     shouldRealign=False,
                     shouldReport=False,
                     shouldVerbose=False):
        moveForward = NSPoint(1, 0)
        moveBackward = NSPoint(-1, 0)
        noModifier = NSNumber.numberWithUnsignedInteger_(0)
        layerCount = 0

        if thisLayer:
            for thisPath in thisLayer.paths:
                oldPathCoordinates = [n.position for n in thisPath.nodes]
                for i, thisNode in enumerate(thisPath.nodes):
                    if thisNode.type == GSOFFCURVE:
                        # oldPosition = NSPoint(thisNode.position.x, thisNode.position.y)
                        oncurve = None
                        if thisNode.prevNode.type != GSOFFCURVE:
                            oncurve = thisNode.prevNode
                            opposingPoint = oncurve.prevNode
                        elif thisNode.nextNode.type != GSOFFCURVE:
                            oncurve = thisNode.nextNode
                            opposingPoint = oncurve.nextNode

                        handleStraight = (oncurve.x - thisNode.x) * (
                            oncurve.y - thisNode.y) == 0.0
                        if oncurve and oncurve.smooth and not handleStraight:
                            # thisNode = angled handle, straighten it
                            thisPath.setSmooth_withCenterPoint_oppositePoint_(
                                thisNode,
                                oncurve.position,
                                opposingPoint.position,
                            )
                        elif oncurve and opposingPoint and oncurve.smooth and handleStraight and opposingPoint.type == GSOFFCURVE:
                            # thisNode = straight handle: align opposite handle
                            thisPath.setSmooth_withCenterPoint_oppositePoint_(
                                opposingPoint,
                                oncurve.position,
                                thisNode.position,
                            )
                        else:
                            selectedNode = NSMutableArray.arrayWithObject_(
                                thisNode)
                            thisLayer.setSelection_(selectedNode)
                            self.Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_(
                                thisLayer, thisLayer, moveForward, noModifier)
                            self.Tool.moveSelectionLayer_shadowLayer_withPoint_withModifier_(
                                thisLayer, thisLayer, moveBackward, noModifier)
                            # TODO:
                            # recode with GSPath.setSmooth_withCenterNode_oppositeNode_()

                for i, coordinate in enumerate(oldPathCoordinates):
                    if thisPath.nodes[i].position != coordinate:
                        layerCount += 1

                        # put handle back if not desired by user:
                        if not shouldRealign:
                            thisPath.nodes[i].position = coordinate
        thisLayer.setSelection_(())

        if shouldReport and shouldVerbose:
            if layerCount:
                if shouldRealign:
                    print(u"   ⚠️ Realigned %i handle%s." %
                          (layerCount, "" if layerCount == 1 else "s"))
                else:
                    print(u"   ❌ %i handle%s are unaligned." %
                          (layerCount, "" if layerCount == 1 else "s"))
            else:
                print(u"   ✅ All BCPs OK.")

        return layerCount