From 28e22197c4f23971a25f76452b7deea5a1e83bd3 Mon Sep 17 00:00:00 2001 From: Dennis Huebner Date: Thu, 9 Nov 2023 16:43:10 +0100 Subject: [PATCH] ID for edge in progress after connect #392 --- .../features/routing/abstract-edge-router.ts | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/sprotty/src/features/routing/abstract-edge-router.ts b/packages/sprotty/src/features/routing/abstract-edge-router.ts index 7f2cd95a..58dddde0 100644 --- a/packages/sprotty/src/features/routing/abstract-edge-router.ts +++ b/packages/sprotty/src/features/routing/abstract-edge-router.ts @@ -107,7 +107,7 @@ export abstract class AbstractEdgeRouter implements IEdgeRouter { }; } - protected calculateSegment(edge: SRoutableElementImpl, t: number): { segmentStart: Point, segmentEnd: Point, lambda: number} | undefined { + protected calculateSegment(edge: SRoutableElementImpl, t: number): { segmentStart: Point, segmentEnd: Point, lambda: number } | undefined { if (t < 0 || t > 1) return undefined; const routedPoints = this.route(edge); @@ -164,7 +164,7 @@ export abstract class AbstractEdgeRouter implements IEdgeRouter { case 'target': if (edge.target instanceof SDanglingAnchorImpl) return edge.target.position; - else { + else { return route[route.length - 1]; } default: @@ -208,7 +208,7 @@ export abstract class AbstractEdgeRouter implements IEdgeRouter { } protected getAnchorComputer(connectable: SConnectableElementImpl): IAnchorComputer { - return this.anchorRegistry.get(this.kind, connectable.anchorKind); + return this.anchorRegistry.get(this.kind, connectable.anchorKind); } applyHandleMoves(edge: SRoutableElementImpl, moves: ResolvedHandleMove[]): void { @@ -297,6 +297,25 @@ export abstract class AbstractEdgeRouter implements IEdgeRouter { if (hasChanged) { // reset attached elements in index edge.index.remove(edge); + if (edge.id === edgeInProgressID) { + // create a proper edge id after connecting the edge in progress + const idGen = (counter: number) => `${edge.sourceId}_to_${edge.targetId}_${counter}`; + let idx = 0; + let newId = idGen(idx); + while (edge.index.getById(newId) !== undefined) { + newId = idGen(++idx); + } + edge.id = newId; + const progressTargetHandle = edge.children.find(child => child.id === edgeInProgressTargetHandleID); + if (progressTargetHandle instanceof SRoutingHandleImpl) { + // remove in progress target handle + edge.remove(progressTargetHandle); + if (progressTargetHandle.danglingAnchor) { + // remove dangling anchor + progressTargetHandle.danglingAnchor.parent.remove(progressTargetHandle.danglingAnchor); + } + } + } edge.index.add(edge); if (this.getSelfEdgeIndex(edge) > -1) { edge.routingPoints = []; @@ -348,7 +367,7 @@ export abstract class AbstractEdgeRouter implements IEdgeRouter { return [ { x: sourceAnchors.get(Side.BOTTOM).x - delta, y: sourceAnchors.get(Side.BOTTOM).y + standardDist }, { x: sourceAnchors.get(Side.LEFT).x - standardDist, y: sourceAnchors.get(Side.BOTTOM).y + standardDist }, - { x: sourceAnchors.get(Side.LEFT).x - standardDist, y: sourceAnchors.get(Side.LEFT).y + delta}, + { x: sourceAnchors.get(Side.LEFT).x - standardDist, y: sourceAnchors.get(Side.LEFT).y + delta }, ]; case 2: return [