Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

Manhattan routing improvement #376

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions client/examples/workflow/workflow-sprotty/src/di.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ const workflowDiagramModule = new ContainerModule((bind, unbind, isBound, rebind
export default function createContainer(widgetId: string): Container {
const container = new Container();

container.load(decorationModule, validationModule, defaultModule, glspMouseToolModule, defaultGLSPModule, glspSelectModule, boundsModule, viewportModule,
container.load(routingModule, decorationModule, validationModule, defaultModule, glspMouseToolModule, defaultGLSPModule, glspSelectModule, boundsModule, viewportModule,
hoverModule, fadeModule, exportModule, expandModule, openModule, buttonModule, modelSourceModule, labelEditModule, labelEditUiModule, glspEditLabelValidationModule,
workflowDiagramModule, saveModule, executeCommandModule, toolFeedbackModule, modelHintsModule,
commandPaletteModule, glspCommandPaletteModule, paletteModule, requestResponseModule, routingModule, edgeLayoutModule,
commandPaletteModule, glspCommandPaletteModule, paletteModule, requestResponseModule, edgeLayoutModule,
layoutCommandsModule);

overrideGLSPViewerOptions(container, {
Expand Down
24 changes: 24 additions & 0 deletions client/packages/sprotty-client/src/features/change-bounds/edges.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/********************************************************************************
* Copyright (c) 2019 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { Action } from "sprotty/lib";

import { ElementAndRoutingPoints } from "../tools/change-bounds-tool";

export class ChangeRoutingPointsAction implements Action {
static readonly KIND = "changeRoutingPoints";
readonly kind = ChangeRoutingPointsAction.KIND;
constructor(public newRoutingPoints: ElementAndRoutingPoints[]) { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { inject, injectable } from "inversify";
import { inject, injectable, optional } from "inversify";
import {
Action,
BoundsAware,
Expand All @@ -25,6 +25,7 @@ import {
MouseListener,
Point,
SetBoundsAction,
Side,
SModelElement,
SModelRoot,
SParentElement,
Expand All @@ -34,6 +35,7 @@ import {
import { GLSPViewerOptions } from "../../base/views/viewer-options";
import { GLSP_TYPES } from "../../types";
import { forEachElement, isNonRoutableSelectedBoundsAware, isSelected, toElementAndBounds } from "../../utils/smodel-util";
import { ChangeRoutingPointsAction } from "../change-bounds/edges";
import { isBoundsAwareMoveable, isResizeable, ResizeHandleLocation, SResizeHandle } from "../change-bounds/model";
import { IMouseTool } from "../mouse-tool/mouse-tool";
import { ChangeBoundsOperationAction } from "../operation/operation-actions";
Expand All @@ -44,6 +46,7 @@ import {
ShowChangeBoundsToolResizeFeedbackAction
} from "../tool-feedback/change-bounds-tool-feedback";
import { IFeedbackActionDispatcher } from "../tool-feedback/feedback-action-dispatcher";
import { RoutingHandler } from "./routing-handler";

/**
* The change bounds tool has the license to move multiple elements or resize a single element by implementing the ChangeBounds operation.
Expand All @@ -58,6 +61,7 @@ import { IFeedbackActionDispatcher } from "../tool-feedback/feedback-action-disp
* To provide a visual client updates during move we install the `FeedbackMoveMouseListener` and to provide visual client updates during resize
* and send the server updates we install the `ChangeBoundsListener`.
*/

@injectable()
export class ChangeBoundsTool implements Tool {
static ID = "glsp.change-bounds-tool";
Expand All @@ -70,15 +74,17 @@ export class ChangeBoundsTool implements Tool {
@inject(GLSP_TYPES.MouseTool) protected mouseTool: IMouseTool,
@inject(KeyTool) protected keyTool: KeyTool,
@inject(GLSP_TYPES.IFeedbackActionDispatcher) protected feedbackDispatcher: IFeedbackActionDispatcher,
@inject(GLSP_TYPES.ViewerOptions) protected opts: GLSPViewerOptions) { }
@inject(GLSP_TYPES.ViewerOptions) protected opts: GLSPViewerOptions,
@inject(RoutingHandler) @optional() protected routingHandler?: RoutingHandler) { }


enable() {
// install feedback move mouse listener for client-side move updates
this.feedbackMoveMouseListener = new FeedbackMoveMouseListener(this.opts);
this.mouseTool.register(this.feedbackMoveMouseListener);

// instlal change bounds listener for client-side resize updates and server-side updates
this.changeBoundsListener = new ChangeBoundsListener(this);
this.changeBoundsListener = new ChangeBoundsListener(this, this.routingHandler);
this.mouseTool.register(this.changeBoundsListener);
this.selectionService.register(this.changeBoundsListener);
this.feedbackDispatcher.registerFeedback(this, [new ShowChangeBoundsToolResizeFeedbackAction]);
Expand All @@ -105,7 +111,8 @@ class ChangeBoundsListener extends MouseListener implements SelectionListener {
private activeResizeElementId: string | undefined = undefined;
private activeResizeHandle: SResizeHandle | undefined = undefined;

constructor(protected tool: ChangeBoundsTool) {
constructor(protected tool: ChangeBoundsTool,
protected routingHandler?: RoutingHandler) {
super();
}

Expand Down Expand Up @@ -155,11 +162,24 @@ class ChangeBoundsListener extends MouseListener implements SelectionListener {
} else {
// Bounds... Change Bounds.
const newBounds: ElementAndBounds[] = [];
forEachElement(target, isNonRoutableSelectedBoundsAware, element =>
createElementAndBounds(element).forEach(bounds => newBounds.push(bounds)));
const newRoutingPoints: ElementAndRoutingPoints[] = [];

// Manhattan routing
if (this.routingHandler) {
newRoutingPoints.push.apply(newRoutingPoints, this.routingHandler.getNewRoutingPoints(target, newBounds, this.tool));
} else {
// Other routing
forEachElement(target, isNonRoutableSelectedBoundsAware, element =>
createElementAndBounds(element).forEach(bounds => newBounds.push(bounds)));
}

if (newBounds.length > 0) {
actions.push(new ChangeBoundsOperationAction(newBounds));
}
// Push new routing points
if (newRoutingPoints.length > 0) {
actions.push(new ChangeRoutingPointsAction(newRoutingPoints));
}
}
this.resetPosition();
return actions;
Expand Down Expand Up @@ -286,7 +306,7 @@ function createChangeBoundsAction(element: SModelElement & BoundsAware): Action[
return [];
}

function createElementAndBounds(element: SModelElement & BoundsAware): ElementAndBounds[] {
export function createElementAndBounds(element: SModelElement & BoundsAware): ElementAndBounds[] {
if (isValidBoundChange(element, element.bounds, element.bounds)) {
return [toElementAndBounds(element)];
}
Expand Down Expand Up @@ -318,4 +338,14 @@ function minHeight(element: SModelElement & BoundsAware): number {
return 1;
}

export interface ElementAndRoutingPoints {
elementId: string
source: Point
target: Point
routingPoints: Point[]
}

export interface SideAndDistance {
side: Side
distance: Number
}
Loading