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

Commit

Permalink
Manhattan routing improved to avoid crossing through diagram elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldulca committed Sep 18, 2019
1 parent 50858f0 commit 2817d55
Show file tree
Hide file tree
Showing 10 changed files with 630 additions and 22 deletions.
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 @@ -106,10 +106,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
34 changes: 34 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,34 @@
/********************************************************************************
* 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, KeyListener, SModelRoot } from "sprotty/lib";
import { matchesKeystroke } from "sprotty/lib/utils/keyboard";

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

export class SaveModelEdgesAction implements Action {
static readonly KIND = "saveModelEdges";
readonly kind = SaveModelEdgesAction.KIND;
constructor(public newRoutingPoints: ElementAndRoutingPoints[]) { }
}

export class SaveModelKeyboardListener extends KeyListener {
keyDown(element: SModelRoot, event: KeyboardEvent): Action[] {
if (matchesKeystroke(event, 'KeyS', 'ctrlCmd')) {
return [new SaveModelEdgesAction([])];
}
return [];
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { injectable } from "inversify";
import {
Action, ActionHandlerRegistry, ActionMessage,
ApplyLabelEditAction, CollapseExpandAction, CollapseExpandAllAction,
CollapseExpandAction, CollapseExpandAllAction,
ComputedBoundsAction, DiagramServer, ExportSvgAction, ICommand, LayoutAction,
OpenAction, RequestBoundsCommand, RequestModelAction, RequestPopupModelAction,
ServerStatusAction, SwitchEditModeCommand
Expand All @@ -31,6 +31,7 @@ import { IdentifiableRequestAction } from "../features/request-response/action-d
import { SaveModelAction } from "../features/save/save";
import { GlspRedoAction, GlspUndoAction } from "../features/undo-redo/model";
import { RequestMarkersAction } from "../features/validation/validate";
import { SaveModelEdgesAction } from "../features/change-bounds/edges";

@injectable()
export class GLSPWebsocketDiagramServer extends DiagramServer {
Expand Down Expand Up @@ -71,10 +72,6 @@ export class GLSPWebsocketDiagramServer extends DiagramServer {
public getSourceURI(): string {
return this._sourceUri;
}

protected handleComputedBounds(action: ComputedBoundsAction): boolean {
return true;
}
}

export function registerDefaultGLSPServerActions(registry: ActionHandlerRegistry, diagramServer: DiagramServer) {
Expand Down Expand Up @@ -103,7 +100,7 @@ export function registerDefaultGLSPServerActions(registry: ActionHandlerRegistry
registry.register(IdentifiableRequestAction.KIND, diagramServer);
registry.register(RequestMarkersAction.KIND, diagramServer);
registry.register(LayoutAction.KIND, diagramServer);
registry.register(ApplyLabelEditAction.KIND, diagramServer);
registry.register(SaveModelEdgesAction.KIND, diagramServer);

// Register an empty handler for SwitchEditMode, to avoid runtime exceptions.
// We don't want to support SwitchEditMode, but sprotty still sends some corresponding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static class Kind {
public static final String LAYOUT = "layout";
public static final String VALIDATE_LABEL_EDIT_ACTION = "validateLabelEdit";
public static final String SET_LABEL_EDIT_VALIDATION_RESULT_ACTION = "setLabelEditValidationResult";
public static final String SAVE_MODEL_EDGES = "saveModelEdges";
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.eclipsesource.glsp.api.action.kind;

import java.util.List;

import com.eclipsesource.glsp.api.action.Action;
import com.eclipsesource.glsp.api.model.ElementAndRoutingPoints;

public class SaveModelEdgesAction extends Action{

private List<ElementAndRoutingPoints> newRoutingPoints;

public SaveModelEdgesAction() {
super(Action.Kind.SAVE_MODEL_EDGES);
}

public SaveModelEdgesAction(List<ElementAndRoutingPoints> elementAndRoutingPoints) {
this();
this.newRoutingPoints = elementAndRoutingPoints;
}

public List<ElementAndRoutingPoints> getNewRoutingPoints() {
return newRoutingPoints;
}

public void setNewRoutingPoints(List<ElementAndRoutingPoints> newRoutingPoints) {
this.newRoutingPoints = newRoutingPoints;
}

@Override
public String toString() {
return "SaveModelEdgesAction [newRoutingPoints=" + newRoutingPoints + "]";
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.eclipsesource.glsp.api.model;

import java.util.List;

import com.eclipsesource.glsp.graph.GPoint;

public class ElementAndRoutingPoints {

private String elementId;
private List<GPoint> routingPoints;


public String getElementId() {
return elementId;

}
public void setElementId(String elementId) {
this.elementId = elementId;
}
public List<GPoint> getRoutingPoints() {
return routingPoints;
}
public void setRoutingPoints(List<GPoint> routingPoints) {
this.routingPoints = routingPoints;
}
@Override
public String toString() {
return "ElementAndRoutingPoints [elementId=" + elementId + ", routingPoints=" + routingPoints + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((elementId == null) ? 0 : elementId.hashCode());
result = prime * result + ((routingPoints == null) ? 0 : routingPoints.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ElementAndRoutingPoints other = (ElementAndRoutingPoints) obj;
if (elementId == null) {
if (other.elementId != null)
return false;
} else if (!elementId.equals(other.elementId))
return false;
if (routingPoints == null) {
if (other.routingPoints != null)
return false;
} else if (!routingPoints.equals(other.routingPoints))
return false;
return true;
}





}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.eclipsesource.glsp.server.actionhandler;

import java.util.List;
import java.util.Optional;

import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.EList;

import com.eclipsesource.glsp.api.action.Action;
import com.eclipsesource.glsp.api.action.kind.SaveModelEdgesAction;
import com.eclipsesource.glsp.api.model.ElementAndRoutingPoints;
import com.eclipsesource.glsp.api.model.GraphicalModelState;
import com.eclipsesource.glsp.graph.GEdge;
import com.eclipsesource.glsp.graph.GModelElement;
import com.eclipsesource.glsp.graph.GPoint;
import com.google.inject.Inject;

public class SaveModelEdgesHandler extends AbstractActionHandler{

private static final Logger LOG = Logger.getLogger(SaveModelActionHandler.class);

@Inject
private ModelSubmissionHandler modelSubmissionHandler;

@Override
public boolean handles(Action action) {
return action instanceof SaveModelEdgesAction;
}
@Override
protected Optional<Action> execute(Action action, GraphicalModelState modelState) {

SaveModelEdgesAction saveModelEdgesAction = (SaveModelEdgesAction)action;
List<ElementAndRoutingPoints> elementAndRoutingPointsList = saveModelEdgesAction.getNewRoutingPoints();
for(ElementAndRoutingPoints elementAndRoutingPoints : elementAndRoutingPointsList) {
Optional<GModelElement> modelElement = modelState.getIndex().get(elementAndRoutingPoints.getElementId());
if(modelElement.isPresent() && modelElement.get() instanceof GEdge) {
GEdge edge = (GEdge) modelElement.get();
EList<GPoint> routingPoints = edge.getRoutingPoints();
routingPoints.clear();
routingPoints.addAll(elementAndRoutingPoints.getRoutingPoints());

}

}
return modelSubmissionHandler.doSubmitModel(true, modelState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import com.eclipsesource.glsp.server.actionhandler.SelectActionHandler;
import com.eclipsesource.glsp.server.actionhandler.UndoRedoActionHandler;
import com.eclipsesource.glsp.server.actionhandler.ValidateLabelEditActionHandler;
import com.eclipsesource.glsp.server.actionhandler.SaveModelEdgesHandler;
import com.eclipsesource.glsp.server.diagram.DIDiagramConfigurationProvider;
import com.eclipsesource.glsp.server.factory.DefaultGraphGsonConfiguratorFactory;
import com.eclipsesource.glsp.server.jsonrpc.DefaultGLSPClientProvider;
Expand All @@ -78,7 +79,7 @@ public abstract class DefaultGLSPModule extends GLSPModule {
RequestPopupModelActionHandler.class, SaveModelActionHandler.class, UndoRedoActionHandler.class,
SelectActionHandler.class, ExecuteServerCommandActionHandler.class, RequestTypeHintsActionHandler.class,
RequestCommandPaletteActionsHandler.class, RequestMarkersHandler.class, LayoutActionHandler.class,
ValidateLabelEditActionHandler.class);
ValidateLabelEditActionHandler.class, SaveModelEdgesHandler.class);

@Override
protected void configure() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Set;

import com.eclipsesource.glsp.api.action.Action;
import com.eclipsesource.glsp.api.action.kind.ApplyLabelEditOperationAction;
import com.eclipsesource.glsp.api.action.kind.CenterAction;
import com.eclipsesource.glsp.api.action.kind.ChangeBoundsOperationAction;
import com.eclipsesource.glsp.api.action.kind.ChangeContainerOperationAction;
Expand Down Expand Up @@ -48,19 +47,18 @@
import com.eclipsesource.glsp.api.action.kind.RequestTypeHintsAction;
import com.eclipsesource.glsp.api.action.kind.RerouteConnectionOperationAction;
import com.eclipsesource.glsp.api.action.kind.SaveModelAction;
import com.eclipsesource.glsp.api.action.kind.SaveModelEdgesAction;
import com.eclipsesource.glsp.api.action.kind.SelectAction;
import com.eclipsesource.glsp.api.action.kind.SelectAllAction;
import com.eclipsesource.glsp.api.action.kind.ServerStatusAction;
import com.eclipsesource.glsp.api.action.kind.SetBoundsAction;
import com.eclipsesource.glsp.api.action.kind.SetEditLabelValidationResultAction;
import com.eclipsesource.glsp.api.action.kind.SetLayersAction;
import com.eclipsesource.glsp.api.action.kind.SetModelAction;
import com.eclipsesource.glsp.api.action.kind.SetOperationsAction;
import com.eclipsesource.glsp.api.action.kind.SetPopupModelAction;
import com.eclipsesource.glsp.api.action.kind.ToogleLayerAction;
import com.eclipsesource.glsp.api.action.kind.UndoAction;
import com.eclipsesource.glsp.api.action.kind.UpdateModelAction;
import com.eclipsesource.glsp.api.action.kind.ValidateLabelEditAction;
import com.eclipsesource.glsp.api.provider.ActionProvider;

public class DefaultActionProvider implements ActionProvider {
Expand All @@ -72,7 +70,7 @@ public DefaultActionProvider() {
}

private void addDefaultActions() {
defaultActions.add(new ApplyLabelEditOperationAction());
defaultActions.add(new SaveModelEdgesAction());
defaultActions.add(new CenterAction());
defaultActions.add(new ChangeBoundsOperationAction());
defaultActions.add(new CollapseExpandAction());
Expand Down Expand Up @@ -104,7 +102,6 @@ private void addDefaultActions() {
defaultActions.add(new SetModelAction());
defaultActions.add(new SetOperationsAction());
defaultActions.add(new SetPopupModelAction());
defaultActions.add(new SetEditLabelValidationResultAction());
defaultActions.add(new ToogleLayerAction());
defaultActions.add(new UpdateModelAction());
defaultActions.add(new ExecuteServerCommandAction());
Expand All @@ -113,7 +110,6 @@ private void addDefaultActions() {
defaultActions.add(new ReconnectConnectionOperationAction());
defaultActions.add(new RerouteConnectionOperationAction());
defaultActions.add(new LayoutAction());
defaultActions.add(new ValidateLabelEditAction());
}

@Override
Expand Down

0 comments on commit 2817d55

Please sign in to comment.