Search in sources :

Example 31 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class ElkGraphLayoutTransferrer method applyNodeLayout.

/**
 * Applies layout information computed for the given node.
 *
 * @param lnode
 *            the node that has the layout information.
 * @param offset
 *            offset to add to coordinates.
 */
private void applyNodeLayout(final LNode lnode, final KVector offset) {
    final ElkNode elknode = (ElkNode) lnode.getProperty(InternalProperties.ORIGIN);
    // Apply the nodeID and layerId that were set on the LGraph on the ElkGraph
    final int nodeID = lnode.getProperty(LayeredOptions.CROSSING_MINIMIZATION_POSITION_ID);
    final int layerID = lnode.getProperty(LayeredOptions.LAYERING_LAYER_ID);
    elknode.setProperty(LayeredOptions.CROSSING_MINIMIZATION_POSITION_ID, nodeID);
    elknode.setProperty(LayeredOptions.LAYERING_LAYER_ID, layerID);
    // Set the node position
    elknode.setX(lnode.getPosition().x + offset.x);
    elknode.setY(lnode.getPosition().y + offset.y);
    // Set the node size, if necessary
    if (!elknode.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS).isEmpty() || lnode.getNestedGraph() != null || (lnode.getGraph().getProperty(LayeredOptions.NODE_PLACEMENT_STRATEGY) == NodePlacementStrategy.NETWORK_SIMPLEX && NodeFlexibility.getNodeFlexibility(lnode).isFlexibleSizeWhereSpacePermits())) {
        elknode.setWidth(lnode.getSize().x);
        elknode.setHeight(lnode.getSize().y);
    }
    // Set port positions
    for (LPort lport : lnode.getPorts()) {
        Object origin = lport.getProperty(InternalProperties.ORIGIN);
        if (origin instanceof ElkPort) {
            ElkPort elkport = (ElkPort) origin;
            elkport.setLocation(lport.getPosition().x, lport.getPosition().y);
            elkport.setProperty(LayeredOptions.PORT_SIDE, lport.getSide());
        }
    }
    // Set node label positions, if they were not fixed
    // (that is at least one of the node or the label has a node label placement set)
    final boolean nodeHasLabelPlacement = !lnode.getProperty(LayeredOptions.NODE_LABELS_PLACEMENT).isEmpty();
    for (LLabel llabel : lnode.getLabels()) {
        if (nodeHasLabelPlacement || !llabel.getProperty(LayeredOptions.NODE_LABELS_PLACEMENT).isEmpty()) {
            ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
            elklabel.setDimensions(llabel.getSize().x, llabel.getSize().y);
            elklabel.setLocation(llabel.getPosition().x, llabel.getPosition().y);
        }
    }
    // Set port label positions, if they were not fixed
    if (!PortLabelPlacement.isFixed(lnode.getProperty(LayeredOptions.PORT_LABELS_PLACEMENT))) {
        for (LPort lport : lnode.getPorts()) {
            for (LLabel llabel : lport.getLabels()) {
                ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
                elklabel.setWidth(llabel.getSize().x);
                elklabel.setHeight(llabel.getSize().y);
                elklabel.setLocation(llabel.getPosition().x, llabel.getPosition().y);
            }
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) LPort(org.eclipse.elk.alg.layered.graph.LPort) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint)

Example 32 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class ElkGraphLayoutTransferrer method applyEdgeLayout.

/**
 * Applies layout information computed for the given edge.
 *
 * @param ledge
 *            the edge that has the layout information.
 * @param routing
 *            the kind of routing applied to edges.
 * @param offset
 *            offset to add to coordinates.
 * @param additionalPadding
 *            the additional insets that may have to be taken into account for hierarchical that go
 *            into the bowels of their source node. These are already included in the offset, but
 *            are required separately.
 */
private void applyEdgeLayout(final LEdge ledge, final EdgeRouting routing, final KVector offset, final LPadding additionalPadding) {
    ElkEdge elkedge = (ElkEdge) ledge.getProperty(InternalProperties.ORIGIN);
    // untouched if another routing algorithm is selected.
    if (elkedge == null) {
        return;
    }
    KVectorChain bendPoints = ledge.getBendPoints();
    // The standard offset may need to be modified if the edge needs to end up in a coordinate system of
    // a graph in a higher hierarchy level
    KVector edgeOffset = new KVector(offset);
    edgeOffset.add(calculateHierarchicalOffset(ledge));
    // Adapt the offset value and add the source port position to the vector chain
    KVector sourcePoint;
    if (LGraphUtil.isDescendant(ledge.getTarget().getNode(), ledge.getSource().getNode())) {
        // The external port's anchor position, relative to the node's top left corner
        LPort sourcePort = ledge.getSource();
        sourcePoint = KVector.sum(sourcePort.getPosition(), sourcePort.getAnchor());
        // The source point will later have the passed offset added to it, which it doesn't actually
        // need, so we subtract it now (notice that the external port's position was already relative
        // to its node's top left corner, while adding the offset now would mean that it was relative
        // to the top left corner + its insets area)
        sourcePoint.sub(offset);
    } else {
        sourcePoint = ledge.getSource().getAbsoluteAnchor();
    }
    bendPoints.addFirst(sourcePoint);
    // Add the target port position to the vector chain, including additional offset
    KVector targetPoint = ledge.getTarget().getAbsoluteAnchor();
    if (ledge.getProperty(InternalProperties.TARGET_OFFSET) != null) {
        targetPoint.add(ledge.getProperty(InternalProperties.TARGET_OFFSET));
    }
    bendPoints.addLast(targetPoint);
    // Translate the bend points by the offset and apply the bend points
    bendPoints.offset(edgeOffset);
    // Give the edge a proper edge section to store routing information
    ElkEdgeSection elkedgeSection = ElkGraphUtil.firstEdgeSection(elkedge, true, true);
    elkedgeSection.setIncomingShape(elkedge.getSources().get(0));
    elkedgeSection.setOutgoingShape(elkedge.getTargets().get(0));
    ElkUtil.applyVectorChain(bendPoints, elkedgeSection);
    // Apply layout to labels
    for (LLabel llabel : ledge.getLabels()) {
        ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
        elklabel.setWidth(llabel.getSize().x);
        elklabel.setHeight(llabel.getSize().y);
        elklabel.setLocation(llabel.getPosition().x + edgeOffset.x, llabel.getPosition().y + edgeOffset.y);
        elklabel.setProperty(LabelDummySwitcher.INCLUDE_LABEL, llabel.getProperty(LabelDummySwitcher.INCLUDE_LABEL));
    }
    // Copy junction points
    KVectorChain junctionPoints = ledge.getProperty(LayeredOptions.JUNCTION_POINTS);
    if (junctionPoints != null) {
        junctionPoints.offset(edgeOffset);
        elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, junctionPoints);
    } else {
        elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
    }
    // Mark the edge with information about its routing
    if (routing == EdgeRouting.SPLINES) {
        // SPLINES means that bend points shall be interpreted as control points for splines
        elkedge.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.SPLINES);
    } else {
        // null means that bend points shall be interpreted as bend points
        elkedge.setProperty(LayeredOptions.EDGE_ROUTING, null);
    }
}
Also used : LLabel(org.eclipse.elk.alg.layered.graph.LLabel) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVectorChain(org.eclipse.elk.core.math.KVectorChain) LPort(org.eclipse.elk.alg.layered.graph.LPort) KVector(org.eclipse.elk.core.math.KVector) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 33 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class ElkGraphImporter method transformNode.

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Transformation
/**
 * Transforms the given node and its contained ports.
 *
 * @param elknode
 *            the node to transform
 * @param lgraph
 *            the layered graph into which the transformed node is put
 * @return the transformed node
 */
private LNode transformNode(final ElkNode elknode, final LGraph lgraph) {
    // add a new node to the layered graph, copying its position
    LNode lnode = new LNode(lgraph);
    lnode.copyProperties(elknode);
    lnode.setProperty(InternalProperties.ORIGIN, elknode);
    lnode.getSize().x = elknode.getWidth();
    lnode.getSize().y = elknode.getHeight();
    lnode.getPosition().x = elknode.getX();
    lnode.getPosition().y = elknode.getY();
    lgraph.getLayerlessNodes().add(lnode);
    nodeAndPortMap.put(elknode, lnode);
    // check if the node is a compound node in the original graph
    if (!elknode.getChildren().isEmpty() || elknode.getProperty(LayeredOptions.INSIDE_SELF_LOOPS_ACTIVATE)) {
        lnode.setProperty(InternalProperties.COMPOUND_NODE, true);
    }
    Set<GraphProperties> graphProperties = lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
    // port constraints and sides cannot be undefined
    PortConstraints portConstraints = lnode.getProperty(LayeredOptions.PORT_CONSTRAINTS);
    if (portConstraints == PortConstraints.UNDEFINED) {
        lnode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
    } else if (portConstraints != PortConstraints.FREE) {
        // if the port constraints are not free, set the appropriate graph property
        graphProperties.add(GraphProperties.NON_FREE_PORTS);
    }
    // transform the ports
    Direction direction = lgraph.getProperty(LayeredOptions.DIRECTION);
    for (ElkPort elkport : elknode.getPorts()) {
        if (!elkport.getProperty(LayeredOptions.NO_LAYOUT)) {
            transformPort(elkport, lnode, graphProperties, direction, portConstraints);
        }
    }
    // add the node's labels
    for (ElkLabel elklabel : elknode.getLabels()) {
        if (!elklabel.getProperty(LayeredOptions.NO_LAYOUT) && !Strings.isNullOrEmpty(elklabel.getText())) {
            lnode.getLabels().add(transformLabel(elklabel));
        }
    }
    if (lnode.getProperty(LayeredOptions.COMMENT_BOX)) {
        graphProperties.add(GraphProperties.COMMENTS);
    }
    // if we have a hypernode without ports, create a default input and output port
    if (lnode.getProperty(LayeredOptions.HYPERNODE)) {
        graphProperties.add(GraphProperties.HYPERNODES);
        graphProperties.add(GraphProperties.HYPEREDGES);
        lnode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
    }
    return lnode;
}
Also used : GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Direction(org.eclipse.elk.core.options.Direction)

Example 34 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class AbstractElkGraphJsonSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ElkGraphPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ElkGraphPackage.ELK_EDGE:
                sequence_ElkEdgeSources_ElkEdgeTargets_ElkGraphElementLabels_ElkGraphElementProperties_ElkId(context, (ElkEdge) semanticObject);
                return;
            case ElkGraphPackage.ELK_LABEL:
                sequence_ElkGraphElementLabels_ElkGraphElementProperties_ElkId_LabelElement_ShapeElement(context, (ElkLabel) semanticObject);
                return;
            case ElkGraphPackage.ELK_NODE:
                sequence_ElkGraphElementLabels_ElkGraphElementProperties_ElkId_ElkNode_ElkNodeChildren_ElkNodeEdges_ElkNodePorts_ShapeElement(context, (ElkNode) semanticObject);
                return;
            case ElkGraphPackage.ELK_PORT:
                sequence_ElkGraphElementLabels_ElkGraphElementProperties_ElkId_ShapeElement(context, (ElkPort) semanticObject);
                return;
            case ElkGraphPackage.ELK_PROPERTY_TO_VALUE_MAP_ENTRY:
                sequence_Property(context, (Map.Entry) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) Parameter(org.eclipse.xtext.Parameter) EPackage(org.eclipse.emf.ecore.EPackage) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 35 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project elk by eclipse.

the class GraphRenderer method renderPort.

/**
 * Paints a port for the given dirty area.
 *
 * @param port the port to paint
 * @param graphics the graphics context used to paint
 * @param area dirty area that needs painting
 * @param offset offset to be added to relative coordinates
 * @param labelAlpha alpha value for labels
 */
private void renderPort(final ElkPort port, final GC graphics, final Rectangle area, final KVector offset, final int labelAlpha) {
    PaintRectangle rect = boundsMap.get(port);
    if (rect == null) {
        rect = new PaintRectangle(port, offset, scale);
        boundsMap.put(port, rect);
    }
    if (!rect.painted && rect.intersects(area)) {
        graphics.setAlpha(255);
        if (configurator.getPortFillColor() != null) {
            graphics.setBackground(configurator.getPortFillColor());
            graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
        }
        if (configurator.getPortBorderColor() != null) {
            graphics.setForeground(configurator.getPortBorderColor());
            graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
        }
        rect.painted = true;
    }
    // paint port labels
    if (configurator.getPortLabelFont() != null) {
        graphics.setFont(configurator.getPortLabelFont());
        KVector portOffset = new KVector(rect.x, rect.y);
        for (ElkLabel label : port.getLabels()) {
            renderLabel(label, graphics, area, portOffset, labelAlpha);
        }
    }
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector)

Aggregations

ElkLabel (org.eclipse.elk.graph.ElkLabel)64 ElkNode (org.eclipse.elk.graph.ElkNode)33 KVector (org.eclipse.elk.core.math.KVector)25 ElkPort (org.eclipse.elk.graph.ElkPort)23 ElkEdge (org.eclipse.elk.graph.ElkEdge)20 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)14 KVectorChain (org.eclipse.elk.core.math.KVectorChain)12 ElkPadding (org.eclipse.elk.core.math.ElkPadding)10 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)9 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)7 PortSide (org.eclipse.elk.core.options.PortSide)6 List (java.util.List)5 LLabel (org.eclipse.elk.alg.layered.graph.LLabel)5 LPort (org.eclipse.elk.alg.layered.graph.LPort)5 ElkBendPoint (org.eclipse.elk.graph.ElkBendPoint)5 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)5 Test (org.junit.Test)5 Lists (com.google.common.collect.Lists)4 Rectangle (org.eclipse.draw2d.geometry.Rectangle)4 DCElement (org.eclipse.elk.alg.disco.graph.DCElement)4