Search in sources :

Example 1 with ElkPadding

use of org.eclipse.elk.core.math.ElkPadding in project lingua-franca by lf-lang.

the class LinguaFrancaStyleExtensions method applyOnEdgePysicalDelayStyle.

public void applyOnEdgePysicalDelayStyle(KLabel label, Colors parentBackgroundColor) {
    if (_onEdgePysicalDelayLabelConfigurator == null) {
        LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
        configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
            KText kText = _kRenderingFactory.createKText();
            _kRenderingExtensions.setFontSize(kText, 8);
            boldTextSelectionStyle(kText);
            kText.setProperty(KlighdInternalProperties.MODEL_ELEMEMT, klabel.getProperty(KlighdInternalProperties.MODEL_ELEMEMT));
            container.getChildren().add(kText);
            return kText;
        });
        configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {

            @Override
            public ElkPadding createDecoratorRendering(KContainerRendering container, KLabel label, LabelDecorationConfigurator.LayoutMode layoutMode) {
                ElkPadding padding = new ElkPadding();
                padding.left = 8;
                padding.right = 16;
                padding.bottom = Math.max(padding.bottom, 1);
                KPolygon polygon = _kRenderingFactory.createKPolygon();
                _kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f);
                _kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f);
                _kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
                _kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
                container.getChildren().add(polygon);
                KSpline kSpline = _kRenderingFactory.createKSpline();
                _kRenderingExtensions.from(kSpline, LEFT, -0.66f, 0, BOTTOM, -0.5f, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, -0.5f, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 3, 0, BOTTOM, 8, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 5, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 5.5f, 0, BOTTOM, -1.5f, 0.5f);
                container.getChildren().add(kSpline);
                kSpline = _kRenderingFactory.createKSpline();
                _kRenderingExtensions.from(kSpline, RIGHT, 15f, 0, BOTTOM, 3.5f, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 14f, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 11, 0, BOTTOM, -8, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 9, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 7, 0, BOTTOM, 8, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 4f, 0, BOTTOM, 2, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 1.5f, 0, BOTTOM, 0.5f, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, 0.2f, 0, BOTTOM, -0.5f, 0.5f);
                _kRenderingExtensions.to(kSpline, RIGHT, -0.7f, 0, BOTTOM, -0.5f, 0.5f);
                container.getChildren().add(kSpline);
                polygon = _kRenderingFactory.createKPolygon();
                _kRenderingExtensions.from(polygon, LEFT, 4, 0, BOTTOM, 0, 0);
                _kRenderingExtensions.to(polygon, LEFT, 8, 0, TOP, 0, 0);
                _kRenderingExtensions.to(polygon, RIGHT, 12, 0, TOP, 0, 0);
                _kRenderingExtensions.to(polygon, RIGHT, 16, 0, BOTTOM, 0, 0);
                _kRenderingExtensions.setBackground(polygon, Colors.WHITE);
                _kRenderingExtensions.setForeground(polygon, Colors.WHITE);
                container.getChildren().add(polygon);
                KPolyline polyline = _kRenderingFactory.createKPolyline();
                _kRenderingExtensions.from(polyline, LEFT, 4, 0, BOTTOM, 0, 0);
                _kRenderingExtensions.to(polyline, LEFT, 8, 0, TOP, 0, 0);
                container.getChildren().add(polyline);
                polyline = _kRenderingFactory.createKPolyline();
                _kRenderingExtensions.from(polyline, RIGHT, 16, 0, BOTTOM, 0, 0);
                _kRenderingExtensions.to(polyline, RIGHT, 12, 0, TOP, 0, 0);
                container.getChildren().add(polyline);
                return padding;
            }
        });
        _onEdgePysicalDelayLabelConfigurator = configurator;
    }
    label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor);
    _onEdgePysicalDelayLabelConfigurator.applyTo(label);
}
Also used : KText(de.cau.cs.kieler.klighd.krendering.KText) KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KLabel(de.cau.cs.kieler.klighd.kgraph.KLabel) LabelDecorationConfigurator(de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) IDecoratorRenderingProvider(de.cau.cs.kieler.klighd.labels.decoration.IDecoratorRenderingProvider) ElkPadding(org.eclipse.elk.core.math.ElkPadding) KSpline(de.cau.cs.kieler.klighd.krendering.KSpline) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline)

Example 2 with ElkPadding

use of org.eclipse.elk.core.math.ElkPadding in project lingua-franca by lf-lang.

the class LinguaFrancaStyleExtensions method applyOnEdgePysicalStyle.

public void applyOnEdgePysicalStyle(KLabel label, Colors parentBackgroundColor) {
    if (_onEdgePysicalLabelConfigurator == null) {
        LabelDecorationConfigurator configurator = LabelDecorationConfigurator.create().withInlineLabels(true);
        configurator = configurator.withLabelTextRenderingProvider((KContainerRendering container, KLabel klabel) -> {
            KText kText = _kRenderingFactory.createKText();
            _kRenderingExtensions.setInvisible(kText, true);
            container.getChildren().add(kText);
            return kText;
        });
        configurator = configurator.addDecoratorRenderingProvider(new IDecoratorRenderingProvider() {

            @Override
            public ElkPadding createDecoratorRendering(final KContainerRendering container, final KLabel label, final LabelDecorationConfigurator.LayoutMode layoutMode) {
                ElkPadding padding = new ElkPadding();
                padding.left = 3;
                padding.right = 3;
                padding.bottom = Math.max(padding.bottom, 1);
                KPolygon polygon = _kRenderingFactory.createKPolygon();
                _kRenderingExtensions.from(polygon, LEFT, 0, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(polygon, LEFT, 0, 0, TOP, 1, 0.5f);
                _kRenderingExtensions.to(polygon, RIGHT, 0, 0, TOP, 1, 0.5f);
                _kRenderingExtensions.to(polygon, RIGHT, 0, 0, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.setBackground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
                _kRenderingExtensions.setForeground(polygon, label.getProperty(LABEL_PARENT_BACKGROUND));
                container.getChildren().add(polygon);
                KSpline kSpline = _kRenderingFactory.createKSpline();
                _kRenderingExtensions.from(kSpline, LEFT, (-0.66f), 0, BOTTOM, (-0.5f), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 1, 0, BOTTOM, (-0.5f), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.1f, BOTTOM, 8, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.2f, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.3f, BOTTOM, (-8), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.4f, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.45f, BOTTOM, 4f, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.5f, BOTTOM, 8, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.55f, BOTTOM, 4f, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.6f, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.65f, BOTTOM, (-4), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.7f, BOTTOM, (-8), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.8f, BOTTOM, (-4), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0, 0.9f, BOTTOM, 0, 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, (-1), 1, BOTTOM, (-0.5f), 0.5f);
                _kRenderingExtensions.to(kSpline, LEFT, 0.66f, 1, BOTTOM, (-0.5f), 0.5f);
                container.getChildren().add(kSpline);
                return padding;
            }
        });
        _onEdgePysicalLabelConfigurator = configurator;
    }
    label.setProperty(LABEL_PARENT_BACKGROUND, parentBackgroundColor);
    _onEdgePysicalLabelConfigurator.applyTo(label);
}
Also used : KText(de.cau.cs.kieler.klighd.krendering.KText) KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KLabel(de.cau.cs.kieler.klighd.kgraph.KLabel) LabelDecorationConfigurator(de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) IDecoratorRenderingProvider(de.cau.cs.kieler.klighd.labels.decoration.IDecoratorRenderingProvider) ElkPadding(org.eclipse.elk.core.math.ElkPadding) KSpline(de.cau.cs.kieler.klighd.krendering.KSpline)

Example 3 with ElkPadding

use of org.eclipse.elk.core.math.ElkPadding in project lingua-franca by lf-lang.

the class LinguaFrancaSynthesis method transform.

// -------------------------------------------------------------------------
@Override
public KNode transform(final Model model) {
    KNode rootNode = _kNodeExtensions.createNode();
    try {
        // Find main
        Reactor main = IterableExtensions.findFirst(model.getReactors(), _utilityExtensions::isMainOrFederated);
        if (main != null) {
            ReactorInstance reactorInstance = new ReactorInstance(main, new SynthesisErrorReporter());
            rootNode.getChildren().addAll(createReactorNode(reactorInstance, true, null, null, new HashMap<>()));
        } else {
            KNode messageNode = _kNodeExtensions.createNode();
            _linguaFrancaShapeExtensions.addErrorMessage(messageNode, TEXT_NO_MAIN_REACTOR, null);
            rootNode.getChildren().add(messageNode);
        }
        // Show all reactors
        if (main == null || getBooleanValue(SHOW_ALL_REACTORS)) {
            List<KNode> reactorNodes = new ArrayList<>();
            for (Reactor reactor : model.getReactors()) {
                if (reactor == main)
                    continue;
                ReactorInstance reactorInstance = new ReactorInstance(reactor, new SynthesisErrorReporter(), new HashSet<>());
                reactorNodes.addAll(createReactorNode(reactorInstance, main == null, HashBasedTable.<ReactorInstance, PortInstance, KPort>create(), HashBasedTable.<ReactorInstance, PortInstance, KPort>create(), new HashMap<>()));
            }
            if (!reactorNodes.isEmpty()) {
                // To allow ordering, we need box layout but we also need layered layout for ports thus wrap all node
                // TODO use rect packing in the future
                reactorNodes.add(0, IterableExtensions.head(rootNode.getChildren()));
                int index = 0;
                for (KNode node : reactorNodes) {
                    if (node.getProperty(CoreOptions.COMMENT_BOX))
                        continue;
                    KNode child = _kNodeExtensions.createNode();
                    child.getChildren().add(node);
                    // Add comment nodes
                    for (KEdge edge : node.getIncomingEdges()) {
                        if (!edge.getSource().getProperty(CoreOptions.COMMENT_BOX))
                            continue;
                        child.getChildren().add(edge.getSource());
                    }
                    _kRenderingExtensions.addInvisibleContainerRendering(child);
                    setLayoutOption(child, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
                    setLayoutOption(child, CoreOptions.PADDING, new ElkPadding(0));
                    // Order!
                    setLayoutOption(child, CoreOptions.PRIORITY, reactorNodes.size() - index);
                    rootNode.getChildren().add(child);
                    index++;
                }
                setLayoutOption(rootNode, CoreOptions.ALGORITHM, BoxLayouterOptions.ALGORITHM_ID);
                setLayoutOption(rootNode, CoreOptions.SPACING_NODE_NODE, 25.0);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        KNode messageNode = _kNodeExtensions.createNode();
        _linguaFrancaShapeExtensions.addErrorMessage(messageNode, "Error in Diagram Synthesis", e.getClass().getSimpleName() + " occurred. Could not create diagram.");
        rootNode.getChildren().add(messageNode);
    }
    return rootNode;
}
Also used : PortInstance(org.lflang.generator.PortInstance) SynthesisErrorReporter(org.lflang.diagram.synthesis.util.SynthesisErrorReporter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KEdge(de.cau.cs.kieler.klighd.kgraph.KEdge) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) ReactorInstance(org.lflang.generator.ReactorInstance) Reactor(org.lflang.lf.Reactor) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 4 with ElkPadding

use of org.eclipse.elk.core.math.ElkPadding in project sirius-components by eclipse-sirius.

the class NodeLabelPositionProvider method getVerticalPosition.

private double getVerticalPosition(NodeLayoutData node, LabelLayoutData label) {
    double y = 0d;
    EnumSet<NodeLabelPlacement> nodeLabelPlacementSet = this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.NODE_LABELS_PLACEMENT);
    ElkPadding nodeLabelsPadding = this.layoutConfigurator.configureByType(node.getNodeType()).getProperty(CoreOptions.NODE_LABELS_PADDING);
    boolean outside = this.isOutside(nodeLabelPlacementSet);
    double topPadding = 0d;
    double bottomPadding = 0d;
    if (nodeLabelsPadding == null) {
        nodeLabelsPadding = CoreOptions.NODE_LABELS_PADDING.getDefault();
    }
    topPadding = nodeLabelsPadding.getTop();
    bottomPadding = nodeLabelsPadding.getBottom();
    for (NodeLabelPlacement nodeLabelPlacement : nodeLabelPlacementSet) {
        switch(nodeLabelPlacement) {
            case V_TOP:
                if (outside) {
                    y = -(label.getTextBounds().getSize().getHeight()) - topPadding;
                } else {
                    y = topPadding;
                }
                break;
            case V_CENTER:
                y = (node.getSize().getHeight() - label.getTextBounds().getSize().getHeight()) / 2;
                break;
            case V_BOTTOM:
                if (outside) {
                    y = -(label.getTextBounds().getSize().getHeight());
                } else {
                    y = node.getSize().getHeight() - label.getTextBounds().getSize().getHeight() - bottomPadding;
                }
                break;
            default:
                break;
        }
    }
    return y;
}
Also used : NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 5 with ElkPadding

use of org.eclipse.elk.core.math.ElkPadding in project sirius-components by eclipse-sirius.

the class LayoutConfiguratorRegistry method getDefaultLayoutConfigurator.

public ISiriusWebLayoutConfigurator getDefaultLayoutConfigurator() {
    // @formatter:off
    SiriusWebLayoutConfigurator configurator = new SiriusWebLayoutConfigurator();
    configurator.configureByType(ELKDiagramConverter.DEFAULT_DIAGRAM_TYPE).setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID).setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.INCLUDE_CHILDREN).setProperty(LayeredOptions.LAYERING_STRATEGY, LayeringStrategy.NETWORK_SIMPLEX).setProperty(LayeredOptions.SPACING_NODE_NODE, SPACING_NODE_NODE).setProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, SPACING_NODE_NODE).setProperty(LayeredOptions.SPACING_EDGE_NODE, SPACING_NODE_EDGE).setProperty(LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, SPACING_NODE_EDGE);
    configurator.configureByType(NodeType.NODE_RECTANGLE).setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.free()).setProperty(CoreOptions.NODE_SIZE_OPTIONS, EnumSet.of(SizeOptions.ASYMMETRICAL)).setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(LayoutOptionValues.MIN_WIDTH_CONSTRAINT, LayoutOptionValues.MIN_HEIGHT_CONSTRAINT)).setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter()).setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(MIN_WIDTH_CONSTRAINT, MIN_HEIGHT_CONSTRAINT)).setProperty(CoreOptions.PORT_BORDER_OFFSET, DEFAULT_PORT_BORDER_OFFSET).setProperty(CoreOptions.PORT_LABELS_PLACEMENT, PortLabelPlacement.outside());
    configurator.configureByType(NodeType.NODE_LIST).setProperty(CoreOptions.ALGORITHM, FixedLayouterOptions.ALGORITHM_ID).setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter()).setProperty(CoreOptions.NODE_SIZE_FIXED_GRAPH_SIZE, true).setProperty(CoreOptions.PORT_BORDER_OFFSET, DEFAULT_PORT_BORDER_OFFSET);
    configurator.configureByType(NodeType.NODE_LIST_ITEM).setProperty(CoreOptions.NO_LAYOUT, true).setProperty(CoreOptions.NODE_LABELS_PADDING, new ElkPadding(0d, 12d, 0d, 6d));
    configurator.configureByType(NodeType.NODE_IMAGE).setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE, SizeConstraint.PORT_LABELS, SizeConstraint.PORTS)).setProperty(CoreOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.outsideTopCenter()).setProperty(CoreOptions.PORT_BORDER_OFFSET, DEFAULT_PORT_BORDER_OFFSET);
    // This image type does not match any diagram item. We add it to define the image size as constraint for the node image parent.
    configurator.configureByType(ELKDiagramConverter.DEFAULT_IMAGE_TYPE).setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
    configurator.configure(ElkEdge.class).setProperty(CoreOptions.SPACING_EDGE_LABEL, 3d);
    return configurator;
}
Also used : KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Aggregations

ElkPadding (org.eclipse.elk.core.math.ElkPadding)72 ElkNode (org.eclipse.elk.graph.ElkNode)34 KVector (org.eclipse.elk.core.math.KVector)25 Test (org.junit.Test)18 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)15 ElkLabel (org.eclipse.elk.graph.ElkLabel)10 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)9 ElkEdge (org.eclipse.elk.graph.ElkEdge)9 KText (de.cau.cs.kieler.klighd.krendering.KText)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)5 KLabel (de.cau.cs.kieler.klighd.kgraph.KLabel)4 KContainerRendering (de.cau.cs.kieler.klighd.krendering.KContainerRendering)4 ElkMargin (org.eclipse.elk.core.math.ElkMargin)4 ElkPort (org.eclipse.elk.graph.ElkPort)4 KNode (de.cau.cs.kieler.klighd.kgraph.KNode)3 HashSet (java.util.HashSet)3 NodeStatement (org.eclipse.elk.alg.graphviz.dot.dot.NodeStatement)3 Subgraph (org.eclipse.elk.alg.graphviz.dot.dot.Subgraph)3