Search in sources :

Example 1 with EdgeLabelPlacement

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);
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement)

Example 2 with EdgeLabelPlacement

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);
    }
}
Also used : ConnectionEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) ElkNode(org.eclipse.elk.graph.ElkNode) HashMap(java.util.HashMap) ElkPort(org.eclipse.elk.graph.ElkPort) ResizableCompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ResizableCompartmentEditPart) ShapeNodeEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart) RootEditPart(org.eclipse.gef.RootEditPart) CompartmentEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart) RenderedDiagramRootEditPart(org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart) EditPart(org.eclipse.gef.EditPart) IGraphicalEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart) AbstractBorderItemEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart) LabelEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart) ConnectionEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) DiagramEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) KVector(org.eclipse.elk.core.math.KVector) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) EReference(org.eclipse.emf.ecore.EReference) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 3 with EdgeLabelPlacement

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);
}
Also used : EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement)

Example 4 with EdgeLabelPlacement

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);
            }
        }
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement)

Example 5 with EdgeLabelPlacement

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);
        }
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) LabelEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart) ConnectionEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) View(org.eclipse.gmf.runtime.notation.View) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) EReference(org.eclipse.emf.ecore.EReference) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Aggregations

EdgeLabelPlacement (org.eclipse.elk.core.options.EdgeLabelPlacement)8 ElkLabel (org.eclipse.elk.graph.ElkLabel)3 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)2 KVector (org.eclipse.elk.core.math.KVector)2 ElkEdge (org.eclipse.elk.graph.ElkEdge)2 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 ElkPort (org.eclipse.elk.graph.ElkPort)2 EObject (org.eclipse.emf.ecore.EObject)2 EReference (org.eclipse.emf.ecore.EReference)2 ConnectionEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart)2 LabelEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart)2 HashMap (java.util.HashMap)1 Point (org.eclipse.draw2d.geometry.Point)1 PointList (org.eclipse.draw2d.geometry.PointList)1 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1