Search in sources :

Example 11 with KPort

use of de.cau.cs.kieler.klighd.kgraph.KPort in project lingua-franca by lf-lang.

the class LinguaFrancaSynthesis method addIOPort.

/**
 * Translate an input/output into a port.
 */
private KPort addIOPort(KNode node, PortInstance lfPort, boolean input, boolean multiport, boolean bank) {
    KPort port = _kPortExtensions.createPort();
    node.getPorts().add(port);
    associateWith(port, lfPort.getDefinition());
    NamedInstanceUtil.linkInstance(port, lfPort);
    _kPortExtensions.setPortSize(port, 6, 6);
    if (input) {
        // multiports are smaller by an offset at the right, hence compensate in inputs
        double offset = multiport ? -3.4 : -3.3;
        setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST);
        setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset);
    } else {
        // multiports are smaller
        double offset = multiport ? -2.6 : -3.3;
        // compensate bank figure width
        offset = bank ? offset - LinguaFrancaShapeExtensions.BANK_FIGURE_X_OFFSET_SUM : offset;
        setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST);
        setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset);
    }
    if (bank && !node.getProperty(REACTOR_HAS_BANK_PORT_OFFSET)) {
        // compensate bank figure height
        // https://github.com/eclipse/elk/issues/693
        _utilityExtensions.getPortMarginsInitIfAbsent(node).add(new ElkMargin(0, 0, LinguaFrancaShapeExtensions.BANK_FIGURE_Y_OFFSET_SUM, 0));
        // only once
        node.setProperty(REACTOR_HAS_BANK_PORT_OFFSET, true);
    }
    _linguaFrancaShapeExtensions.addTrianglePort(port, multiport);
    String label = lfPort.getName();
    if (!getBooleanValue(SHOW_PORT_NAMES)) {
        label = "";
    }
    if (getBooleanValue(SHOW_MULTIPORT_WIDTH)) {
        if (lfPort.isMultiport()) {
            label += (lfPort.getWidth() >= 0) ? "[" + lfPort.getWidth() + "]" : "[?]";
        }
    }
    associateWith(_kLabelExtensions.addOutsidePortLabel(port, label, 8), lfPort.getDefinition());
    return port;
}
Also used : KPort(de.cau.cs.kieler.klighd.kgraph.KPort) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Example 12 with KPort

use of de.cau.cs.kieler.klighd.kgraph.KPort in project lingua-franca by lf-lang.

the class LinguaFrancaShapeExtensions method addActionFigureAndPorts.

/**
 * Creates the triangular action node with text and ports.
 */
public Pair<KPort, KPort> addActionFigureAndPorts(KNode node, String text) {
    final float size = 18;
    _kNodeExtensions.setMinimalNodeSize(node, size, size);
    KPolygon figure = _kRenderingExtensions.addPolygon(node);
    _kRenderingExtensions.setBackground(figure, Colors.WHITE);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure);
    List<KPosition> pointsToAdd = List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0));
    figure.getPoints().addAll(pointsToAdd);
    // Add text to the action figure
    KText textToAdd = _kContainerRenderingExtensions.addText(figure, text);
    _kRenderingExtensions.setFontSize(textToAdd, 8);
    _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd);
    DiagramSyntheses.suppressSelectability(textToAdd);
    _kRenderingExtensions.setPointPlacementData(textToAdd, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, (size * 0.15f), 0.5f, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, size, size);
    // Add input port
    KPort in = _kPortExtensions.createPort();
    node.getPorts().add(in);
    in.setSize(0, 0);
    DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_SIDE, PortSide.WEST);
    DiagramSyntheses.setLayoutOption(in, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4));
    // Add output port
    KPort out = _kPortExtensions.createPort();
    node.getPorts().add(out);
    DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_SIDE, PortSide.EAST);
    DiagramSyntheses.setLayoutOption(out, CoreOptions.PORT_BORDER_OFFSET, -size / ((double) 4));
    return new Pair<KPort, KPort>(in, out);
}
Also used : KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KText(de.cau.cs.kieler.klighd.krendering.KText) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KPosition(de.cau.cs.kieler.klighd.krendering.KPosition) Pair(org.eclipse.xtext.xbase.lib.Pair)

Aggregations

KPort (de.cau.cs.kieler.klighd.kgraph.KPort)12 KEdge (de.cau.cs.kieler.klighd.kgraph.KEdge)9 KNode (de.cau.cs.kieler.klighd.kgraph.KNode)8 Pair (org.eclipse.xtext.xbase.lib.Pair)6 KRendering (de.cau.cs.kieler.klighd.krendering.KRendering)5 ElkMargin (org.eclipse.elk.core.math.ElkMargin)5 Iterables (com.google.common.collect.Iterables)4 SynthesisOption (de.cau.cs.kieler.klighd.SynthesisOption)4 KContainerRendering (de.cau.cs.kieler.klighd.krendering.KContainerRendering)4 KPolyline (de.cau.cs.kieler.klighd.krendering.KPolyline)4 KRectangle (de.cau.cs.kieler.klighd.krendering.KRectangle)4 LineStyle (de.cau.cs.kieler.klighd.krendering.LineStyle)4 ViewSynthesisShared (de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared)4 KContainerRenderingExtensions (de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions)4 KEdgeExtensions (de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions)4 KRenderingExtensions (de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions)4 KlighdProperties (de.cau.cs.kieler.klighd.util.KlighdProperties)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 KText (de.cau.cs.kieler.klighd.krendering.KText)3