Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlois Zoitl2018-09-03 10:21:33 +0000
committerAlois Zoitl2018-09-03 11:06:19 +0000
commit7f0df9183221e63b4864f11ebf059e3144e6e0ae (patch)
tree74712abe77cd34ab6264165b3fe3d7eccdc35df7
parent71a8369a540cd1cd21575d05f5c11f9ab3865305 (diff)
downloadorg.eclipse.4diac.ide-7f0df9183221e63b4864f11ebf059e3144e6e0ae.tar.gz
org.eclipse.4diac.ide-7f0df9183221e63b4864f11ebf059e3144e6e0ae.tar.xz
org.eclipse.4diac.ide-7f0df9183221e63b4864f11ebf059e3144e6e0ae.zip
[497979] reworked connection routing to correctly store bendpoints
with this fix now the adjustable connection router correctly generates the routing information according to IEC 61499-2 and this is also now stored correctly in the xml file. Furthermore the whole router infrastructure was reworked to allow finally fixing also the zoom problem and also give the posiblity to introduce cascading routers for handling connection overlap issues. Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=497979 Change-Id: Ie64230e3adc65374ae0beadcf4a5d4eeb7c8a1c8 Signed-off-by: Alois Zoitl <alois.zoitl@gmx.at>
-rw-r--r--plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/RerouteAction.java6
-rw-r--r--plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/AbstractReconnectConnectionCommand.java1
-rw-r--r--plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ListFBCreateCommand.java1
-rw-r--r--plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/ConnectionEditPart.java25
-rw-r--r--plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/EditorWithInterfaceEditPart.java22
-rw-r--r--plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/commands/AdjustConnectionCommand.java93
-rw-r--r--plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/editparts/AbstractDiagramEditPart.java24
-rw-r--r--plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/figures/HideableConnection.java14
-rw-r--r--plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/LineSegmentHandle.java9
-rw-r--r--plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/MoveableRouter.java261
-rw-r--r--plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/dataexport/FBNetworkExporter.java18
11 files changed, 189 insertions, 285 deletions
diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/RerouteAction.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/RerouteAction.java
index 522e9c146c..9bd1812f0d 100644
--- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/RerouteAction.java
+++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/actions/RerouteAction.java
@@ -17,7 +17,6 @@ import java.util.Iterator;
import java.util.List;
import org.eclipse.draw2d.Connection;
-import org.eclipse.fordiac.ide.gef.router.MoveableRouter;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
@@ -37,11 +36,6 @@ public class RerouteAction implements IObjectActionDelegate {
@Override
public void run(IAction action) {
for (Connection conn : connections) {
- if (conn.getConnectionRouter() instanceof MoveableRouter) {
- ((MoveableRouter) conn.getConnectionRouter()).setDeltaX1(conn, 0);
- ((MoveableRouter) conn.getConnectionRouter()).setDeltaX2(conn, 0);
- ((MoveableRouter) conn.getConnectionRouter()).setDeltaY(conn, 0);
- }
conn.revalidate();
}
diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/AbstractReconnectConnectionCommand.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/AbstractReconnectConnectionCommand.java
index 27dafe2152..10f2f0b084 100644
--- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/AbstractReconnectConnectionCommand.java
+++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/AbstractReconnectConnectionCommand.java
@@ -11,7 +11,6 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.application.commands;
-import org.eclipse.fordiac.ide.application.ApplicationPlugin;
import org.eclipse.fordiac.ide.gef.editparts.InterfaceEditPart;
import org.eclipse.fordiac.ide.model.commands.create.AbstractConnectionCreateCommand;
import org.eclipse.fordiac.ide.model.commands.delete.DeleteConnectionCommand;
diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ListFBCreateCommand.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ListFBCreateCommand.java
index 949eaf0839..9dbc8960be 100644
--- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ListFBCreateCommand.java
+++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/commands/ListFBCreateCommand.java
@@ -14,7 +14,6 @@ package org.eclipse.fordiac.ide.application.commands;
import java.util.List;
-import org.eclipse.fordiac.ide.application.ApplicationPlugin;
import org.eclipse.fordiac.ide.application.utilities.CreationPopupDialog;
import org.eclipse.fordiac.ide.application.utilities.ICreationExecutor;
import org.eclipse.fordiac.ide.model.Palette.FBTypePaletteEntry;
diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/ConnectionEditPart.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/ConnectionEditPart.java
index 9f4eabd28c..0501cf48c3 100644
--- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/ConnectionEditPart.java
+++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/ConnectionEditPart.java
@@ -14,7 +14,6 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.application.editparts;
-import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PolygonDecoration;
import org.eclipse.draw2d.PolylineConnection;
@@ -29,7 +28,6 @@ import org.eclipse.fordiac.ide.application.policies.DisableConnectionHandleRoleE
import org.eclipse.fordiac.ide.application.policies.FeedbackConnectionEndpointEditPolicy;
import org.eclipse.fordiac.ide.gef.figures.HideableConnection;
import org.eclipse.fordiac.ide.gef.router.BendpointPolicyRouter;
-import org.eclipse.fordiac.ide.gef.router.MoveableRouter;
import org.eclipse.fordiac.ide.gef.router.RouterUtil;
import org.eclipse.fordiac.ide.model.libraryElement.AdapterConnection;
import org.eclipse.fordiac.ide.model.libraryElement.Connection;
@@ -104,9 +102,7 @@ public class ConnectionEditPart extends AbstractConnectionEditPart {
@Override
protected IFigure createFigure() {
- PolylineConnection connection = null;
-
- connection = RouterUtil.getConnectionRouterFactory(null).createConnectionFigure();
+ PolylineConnection connection = RouterUtil.getConnectionRouterFactory(null).createConnectionFigure();
String status = getModel().getAttributeValue(HIDEN_CON);
if (connection instanceof HideableConnection) {
@@ -116,6 +112,7 @@ public class ConnectionEditPart extends AbstractConnectionEditPart {
((HideableConnection) connection)
.setLabel(getModel().getSourceElement().getName() + "." + getModel().getSource().getName()); //$NON-NLS-1$
}
+ ((HideableConnection) connection).setModel(getModel());
}
PolygonDecoration arrow = new PolygonDecoration();
@@ -151,20 +148,12 @@ public class ConnectionEditPart extends AbstractConnectionEditPart {
protected void refreshVisuals() {
super.refreshVisuals();
- if (getConnectionFigure() instanceof PolylineConnection) {
- ConnectionRouter router = getConnectionFigure().getConnectionRouter();
- if (getModel() != null) {
- if (router instanceof MoveableRouter) {
- ((MoveableRouter) router).setDeltaX1(getConnectionFigure(), getModel().getDx1());
- ((MoveableRouter) router).setDeltaX2(getConnectionFigure(), getModel().getDx2());
- ((MoveableRouter) router).setDeltaY(getConnectionFigure(), getModel().getDy());
- }
- if (getModel().isBrokenConnection()) {
- ((PolylineConnection) getConnectionFigure()).setLineStyle(SWT.LINE_DASH);
+ if ((getConnectionFigure() instanceof PolylineConnection) && (getModel() != null)) {
+ if (getModel().isBrokenConnection()) {
+ ((PolylineConnection) getConnectionFigure()).setLineStyle(SWT.LINE_DASH);
- } else {
- ((PolylineConnection) getConnectionFigure()).setLineStyle(SWT.LINE_SOLID);
- }
+ } else {
+ ((PolylineConnection) getConnectionFigure()).setLineStyle(SWT.LINE_SOLID);
}
}
}
diff --git a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/EditorWithInterfaceEditPart.java b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/EditorWithInterfaceEditPart.java
index f9c3e5eb27..70e47a03fc 100644
--- a/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/EditorWithInterfaceEditPart.java
+++ b/plugins/org.eclipse.fordiac.ide.application/src/org/eclipse/fordiac/ide/application/editparts/EditorWithInterfaceEditPart.java
@@ -15,19 +15,17 @@ package org.eclipse.fordiac.ide.application.editparts;
import java.util.Collections;
import java.util.List;
-import org.eclipse.draw2d.ConnectionLayer;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.FreeformLayout;
import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Layer;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.OrderedLayout;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.fordiac.ide.gef.editparts.AbstractFBNetworkEditPart;
-import org.eclipse.fordiac.ide.gef.router.RouterUtil;
import org.eclipse.gef.EditPart;
-import org.eclipse.gef.LayerConstants;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.ControlListener;
@@ -76,16 +74,14 @@ public abstract class EditorWithInterfaceEditPart extends AbstractFBNetworkEditP
rightInterfaceContainer.add(rightEventContainer);
rightInterfaceContainer.add(rightVarContainer);
rightInterfaceContainer.add(rightAdapterContainer);
- FreeformLayer f = new FreeformLayer();
- f.setBorder(new MarginBorder(10));
- f.setLayoutManager(new FreeformLayout());
- f.setOpaque(false);
- f.add(leftInterfaceContainer);
- f.add(rightInterfaceContainer);
- // Create the static router for the connection layer
- ConnectionLayer connLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
- connLayer.setConnectionRouter(RouterUtil.getConnectionRouter(f));
- return f;
+ Layer editorFigure = new FreeformLayer();
+ editorFigure.setBorder(new MarginBorder(10));
+ editorFigure.setLayoutManager(new FreeformLayout());
+ editorFigure.setOpaque(false);
+ editorFigure.add(leftInterfaceContainer);
+ editorFigure.add(rightInterfaceContainer);
+ updateRouter(editorFigure);
+ return editorFigure;
}
public FreeformLayer getCastedFigure() {
diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/commands/AdjustConnectionCommand.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/commands/AdjustConnectionCommand.java
index a3b0bb0a6c..174f3f78da 100644
--- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/commands/AdjustConnectionCommand.java
+++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/commands/AdjustConnectionCommand.java
@@ -12,9 +12,11 @@
*******************************************************************************/
package org.eclipse.fordiac.ide.gef.commands;
+import java.text.MessageFormat;
+
import org.eclipse.draw2d.Connection;
-import org.eclipse.draw2d.ConnectionRouter;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.fordiac.ide.gef.Activator;
import org.eclipse.fordiac.ide.gef.router.MoveableRouter;
import org.eclipse.gef.commands.Command;
@@ -37,69 +39,40 @@ public class AdjustConnectionCommand extends Command {
@Override
public void execute() {
- ConnectionRouter router = connection.getConnectionRouter();
- if (router instanceof MoveableRouter) {
- MoveableRouter mr = (MoveableRouter) router;
- switch (index) {
- case 1:
- Point sourceP = connection.getSourceAnchor().getLocation(
- connection.getSourceAnchor().getReferencePoint());
- connection.translateToRelative(sourceP);
- int newX = point.x;
- int delta = newX - sourceP.x;
- mr.setDeltaX1(connection, delta);
- modelConnection.setDx1(delta);
- break;
- case 2:
- Point p3 = connection.getTargetAnchor().getLocation(
- connection.getTargetAnchor().getReferencePoint()).getCopy();
- Point temp = connection.getSourceAnchor().getLocation(
- connection.getSourceAnchor().getReferencePoint()).getCopy();
- connection.translateToRelative(p3);
- connection.translateToRelative(temp);
- int dif = Math.abs(p3.y - temp.y);
- int y = 0;
- if (p3.y < temp.y) {
- y = p3.y + dif / 2;
- } else {
- y = temp.y + dif / 2;
- }
- int deltaY = point.y - y;
- mr.setDeltaY(connection, deltaY);
- modelConnection.setDy(deltaY);
- break;
- case 3:
- sourceP = connection.getTargetAnchor().getLocation(
- connection.getTargetAnchor().getReferencePoint());
- connection.translateToRelative(sourceP);
- newX = point.x;
- delta = newX - sourceP.x;
- mr.setDeltaX2(connection, delta);
- modelConnection.setDx2(delta);
- break;
- default:
- break;
+ Point sourceP = getSourcePoint();
+ Point destP = getDestinationPoint();
+ switch (index) {
+ case 1:
+ int newDx1 = Math.max(point.x - sourceP.x, MoveableRouter.MIN_CONNECTION_FB_DISTANCE);
+ if(0 == modelConnection.getDx2()) {
+ //we have three segment connection check that we are not beyond the input
+ newDx1 = Math.min(newDx1, destP.x - sourceP.x - MoveableRouter.MIN_CONNECTION_FB_DISTANCE);
}
- connection.revalidate();
+ modelConnection.setDx1(newDx1);
+ break;
+ case 2:
+ modelConnection.setDy(point.y - sourceP.y);
+ break;
+ case 3:
+ modelConnection.setDx2(Math.max(destP.x - point.x, MoveableRouter.MIN_CONNECTION_FB_DISTANCE));
+ break;
+ default:
+ Activator.getDefault().logError(MessageFormat.format("Wrong connection segment index ({0}) provided to AdjustConnectionCommand!", index));
+ break;
}
+ connection.revalidate();
}
- @Override
- public boolean canExecute() {
- Point ref1 = connection.getTargetAnchor().getReferencePoint();
- Point ref2 = connection.getSourceAnchor().getReferencePoint();
- Point min = connection.getTargetAnchor().getLocation(ref2).getCopy();
- Point p2 = connection.getSourceAnchor().getLocation(ref1).getCopy();
- connection.translateToRelative(min);
- connection.translateToRelative(p2);
- int x = p2.x;
- int newX = point.x;
- int delta = newX - p2.x;
- // Point 2 (the first after the source anchor)
- if (min.x - 20 > p2.x + 20) {
- return (x + delta < min.x - 20);
- }
- return true;
+ private Point getDestinationPoint() {
+ Point destP = connection.getTargetAnchor().getLocation(connection.getTargetAnchor().getReferencePoint()).getCopy();
+ connection.translateToRelative(destP);
+ return destP;
+ }
+
+ private Point getSourcePoint() {
+ Point sourceP = connection.getSourceAnchor().getLocation(connection.getSourceAnchor().getReferencePoint()).getCopy();
+ connection.translateToRelative(sourceP);
+ return sourceP;
}
@Override
diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/editparts/AbstractDiagramEditPart.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/editparts/AbstractDiagramEditPart.java
index 6f48824acc..bcb5cf728b 100644
--- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/editparts/AbstractDiagramEditPart.java
+++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/editparts/AbstractDiagramEditPart.java
@@ -15,7 +15,9 @@ package org.eclipse.fordiac.ide.gef.editparts;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.draw2d.AutomaticRouter;
import org.eclipse.draw2d.ConnectionLayer;
+import org.eclipse.draw2d.FanRouter;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.FreeformLayout;
@@ -52,16 +54,14 @@ public abstract class AbstractDiagramEditPart extends AbstractGraphicalEditPart
*/
@Override
protected IFigure createFigure() {
- Figure f = new FreeformLayer();
- f.setBorder(new MarginBorder(10));
- f.setLayoutManager(new FreeformLayout());
- f.setOpaque(false);
+ IFigure newFigure = new FreeformLayer();
+ newFigure.setBorder(new MarginBorder(10));
+ newFigure.setLayoutManager(new FreeformLayout());
+ newFigure.setOpaque(false);
- // Create the static router for the connection layer
- ConnectionLayer connLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
- connLayer.setConnectionRouter(RouterUtil.getConnectionRouter(f));
+ updateRouter(newFigure);
- return f;
+ return newFigure;
}
/*
@@ -160,7 +160,7 @@ public abstract class AbstractDiagramEditPart extends AbstractGraphicalEditPart
}
if (event.getProperty().equals(
DiagramPreferences.CONNECTION_ROUTER)) {
- updateRouter();
+ updateRouter(getFigure());
}
}
};
@@ -168,10 +168,10 @@ public abstract class AbstractDiagramEditPart extends AbstractGraphicalEditPart
return listener;
}
- protected void updateRouter() {
+
+ protected void updateRouter(IFigure figure) {
ConnectionLayer connLayer = (ConnectionLayer) getLayer(LayerConstants.CONNECTION_LAYER);
- connLayer.setConnectionRouter(RouterUtil
- .getConnectionRouter(getFigure()));
+ connLayer.setConnectionRouter(RouterUtil.getConnectionRouter(figure));
}
protected void updateGrid() {
diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/figures/HideableConnection.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/figures/HideableConnection.java
index 0663dc3ce1..fd6be0e7af 100644
--- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/figures/HideableConnection.java
+++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/figures/HideableConnection.java
@@ -14,7 +14,6 @@ package org.eclipse.fordiac.ide.gef.figures;
import org.eclipse.draw2d.FigureUtilities;
import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.MouseListener;
import org.eclipse.draw2d.PolylineConnection;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
@@ -23,11 +22,20 @@ import org.eclipse.draw2d.geometry.Rectangle;
public class HideableConnection extends PolylineConnection {
- static final int BEND_POINT_BEVEL_SIZE = 5;
+ public static final int BEND_POINT_BEVEL_SIZE = 5;
boolean hidden = false;
String label = ""; //$NON-NLS-1$
Rectangle moveRect = new Rectangle();
+ org.eclipse.fordiac.ide.model.libraryElement.Connection model;
+
+ public void setModel(org.eclipse.fordiac.ide.model.libraryElement.Connection newModel){
+ model = newModel;
+ }
+
+ public org.eclipse.fordiac.ide.model.libraryElement.Connection getModel() {
+ return model;
+ }
public String getLabel() {
return label;
@@ -97,7 +105,7 @@ public class HideableConnection extends PolylineConnection {
g.drawPolyline(beveledPoints);
}
- private Point calcualtedBeveledPoint(Point refPoint, Point otherPoint, int bevelSize){
+ private static Point calcualtedBeveledPoint(Point refPoint, Point otherPoint, int bevelSize){
if(0 == (refPoint.x - otherPoint.x)){
return new Point(refPoint.x,
refPoint.y + (((refPoint.y - otherPoint.y) > 0) ? -bevelSize : bevelSize));
diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/LineSegmentHandle.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/LineSegmentHandle.java
index b7bfc9cf25..d21574c599 100644
--- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/LineSegmentHandle.java
+++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/LineSegmentHandle.java
@@ -16,8 +16,8 @@ import org.eclipse.draw2d.Connection;
import org.eclipse.draw2d.Cursors;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.fordiac.ide.gef.figures.HideableConnection;
import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.SharedCursors;
import org.eclipse.gef.handles.BendpointCreationHandle;
import org.eclipse.swt.graphics.Color;
@@ -36,12 +36,11 @@ public class LineSegmentHandle extends BendpointCreationHandle {
Point pt2 = points.getPoint(index + 1);
if (Math.abs(pt1.x - pt2.x) < Math.abs(pt1.y - pt2.y)) {
setCursor(Cursors.SIZEWE);
- setPreferredSize(DEFAULT_HANDLE_SIZE-2, Math.abs(pt1.y-pt2.y));
+ setPreferredSize(DEFAULT_HANDLE_SIZE - 2, Math.abs(pt1.y-pt2.y) - 2 * HideableConnection.BEND_POINT_BEVEL_SIZE);
} else {
setCursor(Cursors.SIZENS);
- setPreferredSize(Math.abs(pt1.x-pt2.x),DEFAULT_HANDLE_SIZE-2);
- }
-
+ setPreferredSize(Math.abs(pt1.x-pt2.x) - 2 * HideableConnection.BEND_POINT_BEVEL_SIZE, DEFAULT_HANDLE_SIZE - 2);
+ }
}
@Override
diff --git a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/MoveableRouter.java b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/MoveableRouter.java
index 636b22b1e2..1421ad0bf6 100644
--- a/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/MoveableRouter.java
+++ b/plugins/org.eclipse.fordiac.ide.gef/src/org/eclipse/fordiac/ide/gef/router/MoveableRouter.java
@@ -1,5 +1,6 @@
/*******************************************************************************
- * Copyright (c) 2008, 2009, 2011, 2012, 2015 - 2017 Profactor GmbH, TU Wien ACIN,
+ * Copyright (c) 2008, 2009, 2011, 2012, 2015 - 2017 Profactor GmbH, TU Wien ACIN
+ * 2018 Johannes Kepler University
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,23 +10,24 @@
* Contributors:
* Gerhard Ebenhofer, Alois Zoitl
* - initial API and implementation and/or initial documentation
+ * Alois Zoitl - reworked connection routing and store routing results
+ * correctly in model
*******************************************************************************/
package org.eclipse.fordiac.ide.gef.router;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import org.eclipse.draw2d.BendpointConnectionRouter;
import org.eclipse.draw2d.Connection;
-import org.eclipse.draw2d.ConnectionAnchor;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.PrecisionPoint;
import org.eclipse.fordiac.ide.gef.FixedAnchor;
import org.eclipse.fordiac.ide.gef.commands.AdjustConnectionCommand;
import org.eclipse.fordiac.ide.gef.editparts.InterfaceEditPart;
+import org.eclipse.fordiac.ide.gef.figures.HideableConnection;
+import org.eclipse.fordiac.ide.model.libraryElement.LibraryElementFactory;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editparts.AbstractConnectionEditPart;
@@ -33,170 +35,121 @@ import org.eclipse.gef.editpolicies.BendpointEditPolicy;
import org.eclipse.gef.handles.ConnectionHandle;
import org.eclipse.gef.requests.BendpointRequest;
-public class MoveableRouter extends BendpointConnectionRouter implements
- BendpointPolicyRouter {
+public class MoveableRouter extends BendpointConnectionRouter implements BendpointPolicyRouter {
+ public static final int MIN_CONNECTION_FB_DISTANCE = 20;
private static final PrecisionPoint A_POINT = new PrecisionPoint();
- private static final Map<Connection, Integer> deltasX1 = new HashMap<>();
- private static final Map<Connection, Integer> deltasX2 = new HashMap<>();
- private static final Map<Connection, Integer> deltasY = new HashMap<>();
-
- private final boolean invalidate = true;
-
- private final List<Connection> connections = new ArrayList<>();
-
- public void setDeltaX2(Connection connection, int deltaX2) {
- deltasX2.put(connection, deltaX2);
- }
-
- public int getDeltaX2(Connection connection) {
- if (deltasX2.containsKey(connection)) {
- return deltasX2.get(connection);
- }
- return 0;
- }
-
- public void setDeltaX1(Connection connection, int deltaX1) {
- deltasX1.put(connection, deltaX1);
- }
-
- public int getDeltaX1(Connection connection) {
- if (deltasX1.containsKey(connection)) {
- return deltasX1.get(connection);
- }
- return 0;
- }
-
- public void setDeltaY(Connection connection, int deltaY) {
- deltasY.put(connection, deltaY);
- }
-
- public int getDeltaY(Connection connection) {
- if (deltasY.containsKey(connection)) {
- return deltasY.get(connection);
- }
- return 0;
- }
-
- @Override
- public void invalidate(Connection connection) {
- if (invalidate) {
- super.invalidate(connection);
- if (!connections.contains(connection)) {
- connections.add(connection);
- }
- }
- }
-
@Override
public void route(Connection conn) {
PointList points = conn.getPoints();
points.removeAllPoints();
-
- Point ref1, ref2;
- ConnectionAnchor source, dest;
-
+
+ Point sourceP;
+ Point destP;
if(needsSwap(conn)){
- dest = conn.getSourceAnchor();
- source = conn.getTargetAnchor();
- }else{
- source = conn.getSourceAnchor();
- dest = conn.getTargetAnchor();
+ destP = conn.getSourceAnchor().getLocation(conn.getSourceAnchor().getReferencePoint()).getCopy();
+ sourceP = conn.getTargetAnchor().getLocation(conn.getTargetAnchor().getReferencePoint()).getCopy();
+ } else {
+ sourceP = conn.getSourceAnchor().getLocation(conn.getSourceAnchor().getReferencePoint()).getCopy();
+ destP = conn.getTargetAnchor().getLocation(conn.getTargetAnchor().getReferencePoint()).getCopy();
}
- ref1 = dest.getReferencePoint();
- ref2 = source.getReferencePoint();
-
- Point checkYSource = dest.getLocation(ref2).getCopy();
- Point checkYDest = source.getLocation(ref1).getCopy();
- conn.translateToRelative(checkYSource);
- conn.translateToRelative(checkYDest);
-
- // Point 1 (directly at source anchor)
- A_POINT.setLocation(source.getLocation(ref1));
+ A_POINT.setLocation(sourceP);
conn.translateToRelative(A_POINT);
-
points.addPoint(A_POINT);
- Point min = dest.getLocation(ref2).getCopy();
- Point p2 = source.getLocation(ref1).getCopy();
- int x = p2.x;
-
- // Point 2 (the first after the source anchor)
- int newx = 0;
- if (min.x - 20 > p2.x + 20) {
- newx = Math.min(min.x - 20, x + Math.max(20, getDeltaX1(conn)));
+
+ if(conn instanceof HideableConnection) {
+ setHideableConnectionBendPoints((HideableConnection)conn, sourceP, destP, points);
} else {
- newx = x + Math.max(20, getDeltaX1(conn));
+ //During connection creation we don't have a right connection and no model but we want
+ //to provide the same routing as it would be one.
+ setCreationBendPoints(sourceP, destP, conn, points);
}
- int deltaX = newx - p2.x;
- int relativeX = 0;
-
- // check on 3 or 5 segment connection
- Point p3 = dest.getLocation(ref2).getCopy();
- Point temp = source.getLocation(ref1).getCopy();
- if (p3.x - 40 <= temp.x) { // need 5 segment line
- // add point 2 only if necessary
- A_POINT.setLocation(p2);
- conn.translateToRelative(A_POINT);
- relativeX = A_POINT.x += deltaX;
- points.addPoint(A_POINT);
+ A_POINT.setLocation(destP);
+ conn.translateToRelative(A_POINT);
+ points.addPoint(A_POINT);
+ conn.setPoints(points);
+ }
+
+ private static void setHideableConnectionBendPoints(HideableConnection conn, Point sourceP, Point destP, PointList points) {
+ if(null != conn.getModel()) {
+ valdidateConnectionRoutingParams(conn.getModel(), sourceP, destP);
+ createBendPointList(sourceP, destP, conn, conn.getModel(), points);
+ }
+ }
- int dif = Math.abs(p3.y - temp.y);
- int y = 0;
- if (p3.y < temp.y) {
- y = p3.y + dif / 2;
- } else {
- y = temp.y + dif / 2;
+ private static void valdidateConnectionRoutingParams(org.eclipse.fordiac.ide.model.libraryElement.Connection conn, Point sourceP, Point destP) {
+ if(0 == conn.getDx1()) {
+ if(sourceP.y != destP.y || requires5SegementConnection(sourceP, destP)) {
+ //this is a new connection which is not a straight line or we need to regenerate it
+ if (requires5SegementConnection(sourceP, destP)) { // we need a 5 segment line
+ generateInitial5SegmentParams(conn, sourceP, destP);
+ } else { // we need a 3 segment line
+ generateInitial3SegmentParams(conn, sourceP, destP);
+ }
}
+ } else if(sourceP.y == destP.y && requires5SegementConnection(sourceP, destP)) {
+ //we now have a straight line
+ conn.setDx1(0);
+ } else if(0 == conn.getDx2()) {
+ //we have three point connection
+ if(requires5SegementConnection(sourceP, destP)) {
+ generateInitial5SegmentParams(conn, sourceP, destP);
+ } else if ( sourceP.x + conn.getDx1() > destP.x - MIN_CONNECTION_FB_DISTANCE){
+ conn.setDx1(destP.x - MIN_CONNECTION_FB_DISTANCE);
+ }
+ } else {
+ //we have a five point connection check if we should transform it into a 3 point
+ if(!requires5SegementConnection(sourceP, destP)) {
+ conn.setDx2(0);
+ conn.setDy(0);
+ }
+ }
+ }
- // endpoint of second segment - startpoint of third segment
- Point p5 = new Point(p2.x, y);
- A_POINT.setLocation(p5);
- conn.translateToRelative(A_POINT);
- A_POINT.x = relativeX;
- A_POINT.y += getDeltaY(conn);
- points.addPoint(A_POINT);
-
- // endpint of third segment - startpoint of fourth segment
- x = p3.x;
- Point p4 = new Point(x, y);
- A_POINT.setLocation(p4);
- conn.translateToRelative(A_POINT);
- A_POINT.x = Math.min(A_POINT.x + getDeltaX2(conn), A_POINT.x - 20);
- A_POINT.y += getDeltaY(conn);
- points.addPoint(A_POINT);
-
- // endpoint of fourth segment - startpoint of last segment
- p3.x = x;
- A_POINT.setLocation(p3);
- conn.translateToRelative(A_POINT);
- A_POINT.x = Math.min(A_POINT.x + getDeltaX2(conn), A_POINT.x - 20);
- points.addPoint(A_POINT);
-
- } else { // need 3 segment line - only if the y values are not identical
+ private static void generateInitial3SegmentParams(org.eclipse.fordiac.ide.model.libraryElement.Connection conn,
+ Point sourceP, Point destP) {
+ conn.setDx1((destP.x - sourceP.x)/2);
+ }
- if (checkYSource.y != checkYDest.y) { // 3 segment line is only necessary
- // if the y values are NOT identical
+ private static void generateInitial5SegmentParams(org.eclipse.fordiac.ide.model.libraryElement.Connection conn,
+ Point sourceP, Point destP) {
+ conn.setDx1(MIN_CONNECTION_FB_DISTANCE); // move it of the side of the fb
+ conn.setDx2(MIN_CONNECTION_FB_DISTANCE); // move it of the side of the fb
+ conn.setDy((destP.y - sourceP.y)/2);
+ }
- // add point 2 only if necessary
- A_POINT.setLocation(p2);
- conn.translateToRelative(A_POINT);
- relativeX = A_POINT.x += deltaX;
- points.addPoint(A_POINT);
+ private static boolean requires5SegementConnection(Point sourceP, Point destP) {
+ return destP.x - sourceP.x <= 2 * MIN_CONNECTION_FB_DISTANCE;
+ }
- A_POINT.setLocation(p3);
- conn.translateToRelative(A_POINT);
- A_POINT.x = relativeX;
- points.addPoint(A_POINT);
- }
+ private static void createBendPointList(Point sourceP, Point destP, Connection conn,
+ org.eclipse.fordiac.ide.model.libraryElement.Connection modelConn, PointList points) {
+ if(0 != modelConn.getDx1()) {
+ addBendPoint(conn, points, new Point(sourceP.x + modelConn.getDx1(), sourceP.y));
+ if (0 == modelConn.getDx2()) {
+ //we have a three segment connection
+ addBendPoint(conn, points, new Point(sourceP.x + modelConn.getDx1(), destP.y));
+ }else{
+ //we have a five segment connection
+ addBendPoint(conn, points, new Point(sourceP.x + modelConn.getDx1(), sourceP.y + modelConn.getDy()));
+ addBendPoint(conn, points, new Point(destP.x - modelConn.getDx2(), sourceP.y + modelConn.getDy()));
+ addBendPoint(conn, points, new Point(destP.x - modelConn.getDx2(), destP.y));
+ }
}
- A_POINT.setLocation(dest.getLocation(ref2));
- conn.translateToRelative(A_POINT);
- points.addPoint(A_POINT);
-
- conn.setPoints(points);
+ }
+
+ private static void setCreationBendPoints(Point sourceP, Point destP, Connection conn, PointList points) {
+ org.eclipse.fordiac.ide.model.libraryElement.Connection modelConn = LibraryElementFactory.eINSTANCE.createEventConnection();
+ valdidateConnectionRoutingParams(modelConn, sourceP, destP);
+ createBendPointList(sourceP, destP, conn, modelConn, points);
+ }
+
+ private static void addBendPoint(Connection conn, PointList points, Point p) {
+ conn.translateToRelative(p);
+ points.addPoint(p);
}
private static boolean needsSwap(Connection conn) {
@@ -208,12 +161,6 @@ public class MoveableRouter extends BendpointConnectionRouter implements
}
@Override
- public void remove(Connection connection) {
- super.remove(connection);
- connections.remove(connection);
- }
-
- @Override
public EditPolicy getBendpointPolicy(final Object modelObject) {
if (modelObject instanceof org.eclipse.fordiac.ide.model.libraryElement.Connection) {
return new BendpointEditPolicy() {
@@ -248,20 +195,14 @@ public class MoveableRouter extends BendpointConnectionRouter implements
}
}
- @SuppressWarnings("rawtypes")
@Override
- protected List createSelectionHandles() {
- return createHandlesForAutomaticBendpoints();
- }
-
- private List<ConnectionHandle> createHandlesForAutomaticBendpoints() {
- List<ConnectionHandle> list = new ArrayList<ConnectionHandle>();
+ protected List<ConnectionHandle> createSelectionHandles() {
+ List<ConnectionHandle> list = new ArrayList<>();
AbstractConnectionEditPart connEP = (AbstractConnectionEditPart) getHost();
PointList points = getConnection().getPoints();
for (int i = 1; i < points.size() - 2; i++) {
list.add(new LineSegmentHandle(connEP, i));
}
-
return list;
}
};
diff --git a/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/dataexport/FBNetworkExporter.java b/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/dataexport/FBNetworkExporter.java
index 0f7d92bcb3..5c02595aa7 100644
--- a/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/dataexport/FBNetworkExporter.java
+++ b/plugins/org.eclipse.fordiac.ide.model/src/org/eclipse/fordiac/ide/model/dataexport/FBNetworkExporter.java
@@ -144,12 +144,18 @@ class FBNetworkExporter {
private static void setConnectionCoordinates(
final Connection connection, Element connectionElement) {
- connectionElement.setAttribute(LibraryElementTags.DX1_ATTRIBUTE,
- CommonElementExporter.reConvertCoordinate(connection.getDx1()).toString());
- connectionElement.setAttribute(LibraryElementTags.DX2_ATTRIBUTE,
- CommonElementExporter.reConvertCoordinate(connection.getDx2()).toString());
- connectionElement.setAttribute(LibraryElementTags.DY_ATTRIBUTE,
- CommonElementExporter.reConvertCoordinate(connection.getDy()).toString());
+ if(0 != connection.getDx1()) {
+ //only export connection routing information if not a straight line
+ connectionElement.setAttribute(LibraryElementTags.DX1_ATTRIBUTE,
+ CommonElementExporter.reConvertCoordinate(connection.getDx1()).toString());
+ if(0 != connection.getDx2()) {
+ //only export the second two if a five segment connection
+ connectionElement.setAttribute(LibraryElementTags.DX2_ATTRIBUTE,
+ CommonElementExporter.reConvertCoordinate(connection.getDx2()).toString());
+ connectionElement.setAttribute(LibraryElementTags.DY_ATTRIBUTE,
+ CommonElementExporter.reConvertCoordinate(connection.getDy()).toString());
+ }
+ }
}
}

Back to the top