Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID for edge in progress after connect #405

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 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,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);
spoenemann marked this conversation as resolved.
Show resolved Hide resolved
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 = [];
Expand Down Expand Up @@ -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 [
Expand Down