Skip to content

Commit

Permalink
ID for edge in progress after connect #392
Browse files Browse the repository at this point in the history
  • Loading branch information
dhuebner committed Nov 15, 2023
1 parent 28dc7b8 commit 524520e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/sprotty/src/features/routing/abstract-edge-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -297,6 +297,17 @@ 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) {
idx++;
newId = idGen(idx);;
}
edge.id = newId;
}
edge.index.add(edge);
if (this.getSelfEdgeIndex(edge) > -1) {
edge.routingPoints = [];
Expand Down Expand Up @@ -348,7 +359,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 [
Expand Down

0 comments on commit 524520e

Please sign in to comment.