Skip to content
Snippets Groups Projects
Commit 6f5c1902 authored by Ulrich Schöpp's avatar Ulrich Schöpp Committed by Ulrich Schöpp
Browse files

Take port labels into account in auto layout


Signed-off-by: default avatarUlrich Schöpp <schoepp@fortiss.org>
Issue-Ref: 4184
parent 37506f6a
No related branches found
No related tags found
1 merge request!166Polish diagram appearance
AutoLayoutMenu.java 67dc2d04a6f39ec72ea640b745997baa8ff63a49 GREEN
DiagramTapeMeasure.java 9db44b0331006ec7e43f5395039d2fa0e3b065ac YELLOW
DiagramTapeMeasure.java d607529c055a9f0f8857c4f7923e244a7e2199cd YELLOW
IAutoLayouter.java de1b11d9e202c7e23352ad85684dbf8a3fd17c7d GREEN
IAutoLayouterTapeMeasure.java df186e0ba505e0ecda211b1df76cf12f3245b47e GREEN
KielerAutoLayouter.java 575de49001c0d263af20cf8ac4db7a23ce77845d YELLOW
IAutoLayouterTapeMeasure.java 9781aedaab3a85370542aacee9c49475ad7586c5 YELLOW
KielerAutoLayouter.java 5167afee2f65bb298873fe8c8db51906d3b02098 YELLOW
......@@ -97,4 +97,11 @@ public class DiagramTapeMeasure implements IAutoLayouterTapeMeasure {
Bounds textExtend = getTextExtent(connection);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
/** {@inheritDoc} */
@Override
public int getConnectorLabelWidth(IConnector connector) {
Bounds textExtend = getTextExtent(connector);
return textExtend != null ? (int)textExtend.getWidth() : 0;
}
}
......@@ -38,6 +38,9 @@ public interface IAutoLayouterTapeMeasure {
/** Estimates the height requirements of the given connector. */
public int getConnectorHeight(IConnector connector);
/** Estimates the width requirements for the label of the given connector. */
public int getConnectorLabelWidth(IConnector connector);
/** Estimates the width requirements of the given connection. */
public int getConnectionWidth(IConnection connection);
}
......@@ -36,8 +36,8 @@ import org.eclipse.elk.alg.layered.options.LayeredOptions;
import org.eclipse.elk.core.AbstractLayoutProvider;
import org.eclipse.elk.core.data.LayoutMetaDataService;
import org.eclipse.elk.core.options.Direction;
import org.eclipse.elk.core.options.EdgeLabelPlacement;
import org.eclipse.elk.core.options.EdgeRouting;
import org.eclipse.elk.core.options.PortLabelPlacement;
import org.eclipse.elk.core.options.PortSide;
import org.eclipse.elk.core.util.BasicProgressMonitor;
import org.eclipse.elk.graph.ElkEdge;
......@@ -60,6 +60,7 @@ import org.fortiss.tooling.base.model.layout.ILayoutedModelElement;
import org.fortiss.tooling.base.model.layout.Points;
import org.fortiss.tooling.base.model.layout.impl.PointsImpl;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
/**
......@@ -113,12 +114,12 @@ public class KielerAutoLayouter implements IAutoLayouter {
rootNode.setProperty(LayeredOptions.FEEDBACK_EDGES, true);
rootNode.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
rootNode.setProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS,
10.0 * DEFAULT_GRID_SIZE);
rootNode.setProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS,
5.0 * DEFAULT_GRID_SIZE);
rootNode.setProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS,
2.0 * DEFAULT_GRID_SIZE);
rootNode.setProperty(LayeredOptions.INTERACTIVE_REFERENCE_POINT,
InteractiveReferencePoint.TOP_LEFT);
rootNode.setProperty(LayeredOptions.EDGE_LABELS_PLACEMENT, EdgeLabelPlacement.HEAD);
rootNode.setProperty(LayeredOptions.PORT_LABELS_PLACEMENT, PortLabelPlacement.outside());
AbstractLayoutProvider layoutProvider = new LayeredLayoutProvider();
BasicProgressMonitor progressMonitor = new BasicProgressMonitor();
......@@ -326,14 +327,15 @@ public class KielerAutoLayouter implements IAutoLayouter {
}
}
for(IConnector connector : outputConnectors) {
ElkPort k =
createKPortFromIConnector(connector, elkNode, outboundConnectorsToElkPorts);
ElkPort k = createKPortFromIConnector(tapeMeasure, connector, elkNode,
outboundConnectorsToElkPorts);
if(undirectedConnectors.contains(connector)) {
undirectedConnectorsToElkPorts.put(connector, k);
}
}
for(IConnector connector : inputConnectors) {
createKPortFromIConnector(connector, elkNode, inboundConnectorsToElkPorts);
createKPortFromIConnector(tapeMeasure, connector, elkNode,
inboundConnectorsToElkPorts);
}
}
......@@ -387,6 +389,8 @@ public class KielerAutoLayouter implements IAutoLayouter {
* {@link IConnector})
* and a {@link IConnector}-to- {@link ElkPort} map.
*
* @param tapeMeasure
* {@link IAutoLayouterTapeMeasure} to estimate the label width
* @param connector
* {@link IConnector} to be converted to {@link ElkPort}
* @param elkNode
......@@ -396,12 +400,19 @@ public class KielerAutoLayouter implements IAutoLayouter {
*
* @return {@link ElkNode} representing the given {@link IConnector}.
*/
private ElkPort createKPortFromIConnector(IConnector connector, ElkNode elkNode,
EMap<IConnector, ElkPort> connectorsToelkPorts) {
private ElkPort createKPortFromIConnector(IAutoLayouterTapeMeasure tapeMeasure,
IConnector connector, ElkNode elkNode, EMap<IConnector, ElkPort> connectorsToelkPorts) {
ElkPort elkPort = createPort(elkNode);
elkPort.setParent(elkNode);
elkPort.setHeight(DEFAULT_CONNECTOR_SIZE);
if(connector instanceof INamedElement) {
ElkLabel elkPortLabel = createLabel(elkPort);
String name = ((INamedElement)connector).getName();
elkPortLabel.setWidth(tapeMeasure.getConnectorLabelWidth(connector));
elkPortLabel.setText(name);
}
connectorsToelkPorts.put(connector, elkPort);
return elkPort;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment