use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class InvertedPortProcessor method createEastPortSideDummies.
/**
* Creates the necessary dummy nodes for an input port on the east side of a node, provided that
* the edge connects two different nodes.
*
* @param layeredGraph
* the layered graph.
* @param eastwardPort
* the offending port.
* @param edge
* the edge connected to the port.
* @param layerNodeList
* list of unassigned nodes belonging to the layer of the node the port belongs to.
* The new dummy node is added to this list and must be assigned to the layer later.
*/
private void createEastPortSideDummies(final LGraph layeredGraph, final LPort eastwardPort, final LEdge edge, final List<LNode> layerNodeList) {
assert edge.getTarget() == eastwardPort;
// Ignore self loops
if (edge.getSource().getNode() == eastwardPort.getNode()) {
return;
}
// Dummy node in the same layer
LNode dummy = new LNode(layeredGraph);
dummy.setType(NodeType.LONG_EDGE);
dummy.setProperty(InternalProperties.ORIGIN, edge);
dummy.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
layerNodeList.add(dummy);
LPort dummyInput = new LPort();
dummyInput.setNode(dummy);
dummyInput.setSide(PortSide.WEST);
LPort dummyOutput = new LPort();
dummyOutput.setNode(dummy);
dummyOutput.setSide(PortSide.EAST);
// Reroute the original edge
edge.setTarget(dummyInput);
// Connect the dummy with the original port
LEdge dummyEdge = new LEdge();
dummyEdge.copyProperties(edge);
dummyEdge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
dummyEdge.setSource(dummyOutput);
dummyEdge.setTarget(eastwardPort);
// Set LONG_EDGE_SOURCE and LONG_EDGE_TARGET properties on the LONG_EDGE dummy
setLongEdgeSourceAndTarget(dummy, dummyInput, dummyOutput, eastwardPort);
// Move head labels from the old edge over to the new one
ListIterator<LLabel> labelIterator = edge.getLabels().listIterator();
while (labelIterator.hasNext()) {
LLabel label = labelIterator.next();
EdgeLabelPlacement labelPlacement = label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT);
if (labelPlacement == EdgeLabelPlacement.HEAD) {
// Remember which edge the label originally belonged to, unless it already knows
if (!label.hasProperty(InternalProperties.END_LABEL_EDGE)) {
label.setProperty(InternalProperties.END_LABEL_EDGE, edge);
}
labelIterator.remove();
dummyEdge.getLabels().add(label);
}
}
}
use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class GmfDiagramLayoutConnector method processConnections.
/**
* Creates new edges and takes care of the labels for each connection identified in the
* {@code buildLayoutGraphRecursively} method.
*
* @param mapping
* the layout mapping
*/
protected void processConnections(final LayoutMapping mapping) {
Map<EReference, ElkEdge> reference2EdgeMap = new HashMap<>();
for (ConnectionEditPart connection : mapping.getProperty(CONNECTIONS)) {
boolean isOppositeEdge = false;
Optional<EdgeLabelPlacement> edgeLabelPlacement = Optional.empty();
ElkEdge edge;
// Check whether the edge belongs to an Ecore reference, which may have opposites.
// This is required for the layout of Ecore diagrams, since the bend points of
// opposite references are kept synchronized by the editor.
EObject modelObject = connection.getNotationView().getElement();
if (modelObject instanceof EReference) {
EReference reference = (EReference) modelObject;
edge = reference2EdgeMap.get(reference.getEOpposite());
if (edge != null) {
edgeLabelPlacement = Optional.of(EdgeLabelPlacement.TAIL);
isOppositeEdge = true;
} else {
edge = ElkGraphUtil.createEdge(null);
reference2EdgeMap.put(reference, edge);
}
} else {
edge = ElkGraphUtil.createEdge(null);
}
BiMap<Object, ElkGraphElement> inverseGraphMap = mapping.getGraphMap().inverse();
// find a proper source node and source port
ElkGraphElement sourceElem;
EditPart sourceObj = connection.getSource();
if (sourceObj instanceof ConnectionEditPart) {
sourceElem = inverseGraphMap.get(((ConnectionEditPart) sourceObj).getSource());
if (sourceElem == null) {
sourceElem = inverseGraphMap.get(((ConnectionEditPart) sourceObj).getTarget());
}
} else {
sourceElem = inverseGraphMap.get(sourceObj);
}
ElkConnectableShape sourceShape = null;
ElkPort sourcePort = null;
ElkNode sourceNode = null;
if (sourceElem instanceof ElkNode) {
sourceNode = (ElkNode) sourceElem;
sourceShape = sourceNode;
} else if (sourceElem instanceof ElkPort) {
sourcePort = (ElkPort) sourceElem;
sourceNode = sourcePort.getParent();
sourceShape = sourcePort;
} else {
continue;
}
// find a proper target node and target port
ElkGraphElement targetElem;
EditPart targetObj = connection.getTarget();
if (targetObj instanceof ConnectionEditPart) {
targetElem = inverseGraphMap.get(((ConnectionEditPart) targetObj).getTarget());
if (targetElem == null) {
targetElem = inverseGraphMap.get(((ConnectionEditPart) targetObj).getSource());
}
} else {
targetElem = inverseGraphMap.get(targetObj);
}
ElkConnectableShape targetShape = null;
ElkNode targetNode = null;
ElkPort targetPort = null;
if (targetElem instanceof ElkNode) {
targetNode = (ElkNode) targetElem;
targetShape = targetNode;
} else if (targetElem instanceof ElkPort) {
targetPort = (ElkPort) targetElem;
targetNode = targetPort.getParent();
targetShape = targetPort;
} else {
continue;
}
// calculate offset for edge and label coordinates
ElkNode edgeContainment = ElkGraphUtil.findLowestCommonAncestor(sourceNode, targetNode);
KVector offset = new KVector();
ElkUtil.toAbsolute(offset, edgeContainment);
if (!isOppositeEdge) {
// set source and target
edge.getSources().add(sourceShape);
edge.getTargets().add(targetShape);
// now that source and target are set, put the edge into the graph
edgeContainment.getContainedEdges().add(edge);
mapping.getGraphMap().put(edge, connection);
// store the current coordinates of the edge
setEdgeLayout(edge, connection, offset);
}
// process edge labels
processEdgeLabels(mapping, connection, edge, edgeLabelPlacement, offset);
}
}
use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class LEdge method reverse.
/**
* Reverses the edge, including its bend points. Negates the {@code REVERSED} property. (an edge that was marked as
* being reversed is then unmarked, and the other way around) This does not change any properties on the connected
* ports. End labels are reversed as well ( {@code HEAD} labels become {@code TAIL} labels and vice versa).
*
* @param layeredGraph
* the layered graph
* @param adaptPorts
* If true and a connected port is a collector port (a port used to merge edges), the corresponding
* opposite port is used instead of the original one.
*/
public void reverse(final LGraph layeredGraph, final boolean adaptPorts) {
LPort oldSource = getSource();
LPort oldTarget = getTarget();
setSource(null);
setTarget(null);
if (adaptPorts && oldTarget.getProperty(InternalProperties.INPUT_COLLECT)) {
setSource(LGraphUtil.provideCollectorPort(layeredGraph, oldTarget.getNode(), PortType.OUTPUT, PortSide.EAST));
} else {
setSource(oldTarget);
}
if (adaptPorts && oldSource.getProperty(InternalProperties.OUTPUT_COLLECT)) {
setTarget(LGraphUtil.provideCollectorPort(layeredGraph, oldSource.getNode(), PortType.INPUT, PortSide.WEST));
} else {
setTarget(oldSource);
}
// Switch end labels
for (LLabel label : labels) {
EdgeLabelPlacement labelPlacement = label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT);
if (labelPlacement == EdgeLabelPlacement.TAIL) {
label.setProperty(LayeredOptions.EDGE_LABELS_PLACEMENT, EdgeLabelPlacement.HEAD);
} else if (labelPlacement == EdgeLabelPlacement.HEAD) {
label.setProperty(LayeredOptions.EDGE_LABELS_PLACEMENT, EdgeLabelPlacement.TAIL);
}
}
boolean reversed = getProperty(InternalProperties.REVERSED);
setProperty(InternalProperties.REVERSED, !reversed);
bendPoints = KVectorChain.reverse(bendPoints);
}
use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class LongEdgeSplitter method moveHeadLabels.
/**
* Moves all head labels from a given split edge to the new edge created to split it.
*
* @param oldEdge
* the old edge whose head labels are to be moved.
* @param newEdge
* the new edge whose head labels are to be moved.
*/
private static void moveHeadLabels(final LEdge oldEdge, final LEdge newEdge) {
ListIterator<LLabel> labelIterator = oldEdge.getLabels().listIterator();
while (labelIterator.hasNext()) {
LLabel label = labelIterator.next();
EdgeLabelPlacement labelPlacement = label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT);
if (labelPlacement == EdgeLabelPlacement.HEAD) {
labelIterator.remove();
newEdge.getLabels().add(label);
if (!label.hasProperty(InternalProperties.END_LABEL_EDGE)) {
label.setProperty(InternalProperties.END_LABEL_EDGE, oldEdge);
}
}
}
}
use of org.eclipse.elk.core.options.EdgeLabelPlacement in project elk by eclipse.
the class GmfLayoutEditPolicy method addLabelLayout.
/**
* Adds an edge label layout to the given command.
*
* @param command
* command to which the edge label layout shall be added
* @param klabel
* label with layout data
* @param labelEditPart
* edit part to which layout is applied
* @param scale
* scale factor for coordinates
*/
private void addLabelLayout(final GmfLayoutCommand command, final ElkLabel klabel, final GraphicalEditPart labelEditPart, final double scale) {
ElkGraphElement parent = klabel.getParent();
// node and port labels are processed separately
if (parent instanceof ElkNode || parent instanceof ElkPort) {
View view = (View) labelEditPart.getModel();
int xpos = (int) (klabel.getX() * scale);
int ypos = (int) (klabel.getY() * scale);
Object oldx = ViewUtil.getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X());
Object oldy = ViewUtil.getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y());
if (oldx == null || oldy == null || xpos != (Integer) oldx || ypos != (Integer) oldy) {
command.addShapeLayout(view, new Point(xpos, ypos), null);
}
return;
} else if (parent instanceof ElkEdge) {
// calculate direct new location of the label
Rectangle targetBounds = new Rectangle(labelEditPart.getFigure().getBounds());
targetBounds.x = (int) (klabel.getX() * scale);
targetBounds.y = (int) (klabel.getY() * scale);
ConnectionEditPart connectionEditPart = (ConnectionEditPart) labelEditPart.getParent();
PointList bendPoints = getBendPoints((ElkEdge) parent, connectionEditPart.getFigure(), scale);
EObject modelElement = connectionEditPart.getNotationView().getElement();
EdgeLabelPlacement labelPlacement = klabel.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
// the list of bend points must be reversed
if (modelElement instanceof EReference && labelPlacement == EdgeLabelPlacement.TAIL) {
bendPoints = bendPoints.getCopy();
bendPoints.reverse();
}
// get the referencePoint for the label
int fromEnd, keyPoint = ConnectionLocator.MIDDLE;
if (labelEditPart instanceof LabelEditPart) {
keyPoint = ((LabelEditPart) labelEditPart).getKeyPoint();
}
switch(keyPoint) {
case ConnectionLocator.SOURCE:
fromEnd = SOURCE_LOCATION;
break;
case ConnectionLocator.TARGET:
fromEnd = TARGET_LOCATION;
break;
default:
fromEnd = MIDDLE_LOCATION;
break;
}
Point refPoint = PointListUtilities.calculatePointRelativeToLine(bendPoints, 0, fromEnd, true);
// get the new relative location
Point normalPoint = offsetFromRelativeCoordinate(targetBounds, bendPoints, refPoint);
if (normalPoint != null) {
command.addShapeLayout((View) labelEditPart.getModel(), normalPoint, null);
}
}
}
Aggregations