Search in sources :

Example 1 with ElkLabel

use of org.eclipse.elk.graph.ElkLabel in project sirius-components by eclipse-sirius.

the class ELKDiagramConverter method convertLabel.

private void convertLabel(Label label, TextBounds textBounds, ElkGraphElement elkGraphElement, Map<String, ElkGraphElement> id2ElkGraphElements, EdgeLabelPlacement placement) {
    ElkLabel elkLabel = ElkGraphFactory.eINSTANCE.createElkLabel();
    elkLabel.setIdentifier(label.getId());
    elkLabel.setProperty(PROPERTY_TYPE, label.getType());
    elkLabel.setDimensions(textBounds.getSize().getWidth(), textBounds.getSize().getHeight());
    if (label.getText().isEmpty() && !label.getStyle().getIconURL().isEmpty()) {
        // $NON-NLS-1$
        elkLabel.setText(" ");
    } else {
        elkLabel.setText(label.getText());
    }
    elkLabel.setParent(elkGraphElement);
    if (placement != null) {
        elkLabel.setProperty(CoreOptions.EDGE_LABELS_PLACEMENT, placement);
    }
    elkLabel.eAdapters().add(new AlignmentHolder(textBounds.getAlignment()));
    id2ElkGraphElements.put(label.getId(), elkLabel);
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel)

Example 2 with ElkLabel

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

the class DiagramElementLayoutUtil method setLabelPositionsForEdge.

/**
 * @param mapping
 * @param m
 * @param edge
 * @param edgeMidpoint must be relative to the edge's container
 */
private static void setLabelPositionsForEdge(final LayoutMapping mapping, DiagramModification m, final ElkEdge edge, final Point edgeMidpoint) {
    // Handle labels
    for (final ElkLabel edgeLabel : edge.getLabels()) {
        final Object labelValue = mapping.getGraphMap().get(edgeLabel);
        if (labelValue instanceof ConnectionLabelReference) {
            final ConnectionLabelReference labelRef = (ConnectionLabelReference) labelValue;
            if (Boolean.TRUE.equals(edgeLabel.getProperty(CoreOptions.NO_LAYOUT))) {
                labelRef.setPosition(m, null);
            } else {
                final double lx = edgeLabel.getX() - edgeMidpoint.x;
                final double ly = edgeLabel.getY() - edgeMidpoint.y;
                labelRef.setPosition(m, new Point(lx, ly));
            }
        }
    }
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel) Point(org.osate.ge.graphics.Point)

Example 3 with ElkLabel

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

the class ElkGraphBuilder method createElkLabel.

private static ElkLabel createElkLabel(final ElkGraphElement parentLayoutElement, final String txt, final Dimension labelSize) {
    final ElkLabel newLabel = ElkGraphUtil.createLabel(parentLayoutElement);
    newLabel.setText(txt);
    if (labelSize != null) {
        newLabel.setWidth(labelSize.width);
        newLabel.setHeight(labelSize.height);
    }
    return newLabel;
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel)

Example 4 with ElkLabel

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

the class ElkGraphBuilder method createElkLabels.

private void createElkLabels(final DiagramElement parentElement, final ElkGraphElement parentLayoutElement, final LayoutMapping mapping) {
    // Don't create labels for ElkPort. The bounds of the port contain their labels.
    if (parentLayoutElement instanceof ElkPort) {
        return;
    }
    final boolean isConnection = parentElement.getGraphic() instanceof AgeConnection;
    final Style style = styleProvider.getStyle(parentElement);
    if (style.getPrimaryLabelVisible()) {
        // Create Primary Label
        if (parentElement.getLabelName() != null) {
            final ElkLabel elkLabel = createElkLabel(parentLayoutElement, parentElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(parentElement));
            if (isConnection) {
                if (!layoutConnectionLabels) {
                    elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
                }
                mapping.getGraphMap().put(elkLabel, new PrimaryConnectionLabelReference(parentElement));
            }
        }
    }
    // Create label for annotations which are part of the graphic configuration. These are only supported by non-connections.
    if (!isConnection && parentElement.getGraphicalConfiguration().getAnnotation() != null) {
        createElkLabel(parentLayoutElement, parentElement.getGraphicalConfiguration().getAnnotation(), layoutInfoProvider.getAnnotationLabelSize(parentElement));
    }
    // Create Secondary Labels
    parentElement.getChildren().stream().filter(c -> c.getGraphic() instanceof Label).forEachOrdered(labelElement -> {
        final ElkLabel elkLabel = createElkLabel(parentLayoutElement, labelElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(labelElement));
        if (isConnection) {
            if (!layoutConnectionLabels) {
                elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
            }
            mapping.getGraphMap().put(elkLabel, new SecondaryConnectionLabelReference(labelElement));
        }
    });
    if (parentLayoutElement instanceof ElkNode) {
        parentLayoutElement.setProperty(CoreOptions.NODE_LABELS_PLACEMENT, getNodeLabelPlacement(style));
    }
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) PortSide(org.eclipse.elk.core.options.PortSide) Dimension(org.osate.ge.graphics.Dimension) HashMap(java.util.HashMap) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) ArrayList(java.util.ArrayList) Style(org.osate.ge.graphics.Style) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Map(java.util.Map) AgeShape(org.osate.ge.graphics.internal.AgeShape) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) HierarchyHandling(org.eclipse.elk.core.options.HierarchyHandling) EnumSet(java.util.EnumSet) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) Predicate(java.util.function.Predicate) KVector(org.eclipse.elk.core.math.KVector) Collection(java.util.Collection) Label(org.osate.ge.graphics.internal.Label) SizeOptions(org.eclipse.elk.core.options.SizeOptions) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Collectors(java.util.stream.Collectors) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) Direction(org.eclipse.elk.core.options.Direction) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.osate.ge.graphics.internal.Label) Style(org.osate.ge.graphics.Style)

Example 5 with ElkLabel

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

the class GraphRenderer method renderNodeChildren.

/**
 * Paints all children of the given parent node that fall into the given dirty area.
 *
 * @param parent the node whose children 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 nodeAlpha alpha value for nodes
 */
private void renderNodeChildren(final ElkNode parent, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha) {
    for (ElkNode childNode : parent.getChildren()) {
        PaintRectangle rect = boundsMap.get(childNode);
        if (rect == null) {
            rect = new PaintRectangle(childNode, offset, scale);
            boundsMap.put(childNode, rect);
        }
        KVector childOffset = new KVector(rect.x, rect.y);
        // render the child node and its content
        if (!rect.painted && rect.intersects(area)) {
            // paint this node
            graphics.setAlpha(nodeAlpha);
            if (configurator.getNodeFillColor() != null) {
                graphics.setBackground(configurator.getNodeFillColor());
                graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
            }
            if (configurator.getNodeBorderColor() != null) {
                graphics.setForeground(configurator.getNodeBorderColor());
                graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
            }
            rect.painted = true;
            renderNodeChildren(childNode, graphics, area, childOffset, nodeAlpha);
        }
        // render node labels
        if (configurator.getNodeLabelFont() != null) {
            graphics.setFont(configurator.getNodeLabelFont());
            for (ElkLabel label : childNode.getLabels()) {
                renderLabel(label, graphics, area, childOffset, nodeAlpha);
            }
        }
        // render ports
        for (ElkPort port : childNode.getPorts()) {
            renderPort(port, graphics, area, childOffset, nodeAlpha);
        }
    }
    // Paint the edges contained in this node
    for (ElkEdge childEdge : parent.getContainedEdges()) {
        renderEdge(childEdge, graphics, area, offset, nodeAlpha);
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) KVector(org.eclipse.elk.core.math.KVector) ElkEdge(org.eclipse.elk.graph.ElkEdge)

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