Search in sources :

Example 1 with KPosition

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

the class LinguaFrancaShapeExtensions method addTimerFigure.

/**
 * Creates the visual representation of a timer node
 */
public KEllipse addTimerFigure(KNode node, TimerInstance timer) {
    _kNodeExtensions.setMinimalNodeSize(node, 30, 30);
    KEllipse figure = _kRenderingExtensions.addEllipse(node);
    _kRenderingExtensions.setBackground(figure, Colors.GRAY_95);
    _linguaFrancaStyleExtensions.noSelectionStyle(figure);
    _kRenderingExtensions.setLineWidth(figure, 1);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure);
    List<KPosition> polylinePoints = List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.1f), _kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(LEFT, 0, 0.7f, TOP, 0, 0.7f));
    KPolyline polyline = _kContainerRenderingExtensions.addPolyline(figure, 1, polylinePoints);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(polyline);
    List<String> labelParts = new ArrayList<>();
    if (timer.getOffset() != TimerInstance.DEFAULT_OFFSET && timer.getOffset() != null) {
        labelParts.add(timer.getOffset().toString());
    }
    if (timer.getPeriod() != TimerInstance.DEFAULT_PERIOD && timer.getPeriod() != null) {
        if (timer.getOffset() == TimerInstance.DEFAULT_OFFSET) {
            labelParts.add(timer.getOffset().toString());
        }
        labelParts.add(timer.getPeriod().toString());
    }
    if (!labelParts.isEmpty()) {
        _kLabelExtensions.addOutsideBottomCenteredNodeLabel(node, "(" + String.join(", ", labelParts) + ")", 8);
    }
    return figure;
}
Also used : KEllipse(de.cau.cs.kieler.klighd.krendering.KEllipse) ArrayList(java.util.ArrayList) KPosition(de.cau.cs.kieler.klighd.krendering.KPosition) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline)

Example 2 with KPosition

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

the class LinguaFrancaShapeExtensions method addActionDecorator.

/**
 * Creates the triangular line decorator with text.
 */
public KPolygon addActionDecorator(KPolyline line, String text) {
    final float size = 18;
    // Create action decorator
    KPolygon actionDecorator = _kContainerRenderingExtensions.addPolygon(line);
    _kRenderingExtensions.setBackground(actionDecorator, Colors.WHITE);
    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));
    actionDecorator.getPoints().addAll(pointsToAdd);
    // Set placement data of the action decorator
    KDecoratorPlacementData placementData = _kRenderingFactory.createKDecoratorPlacementData();
    placementData.setRelative(0.5f);
    placementData.setAbsolute(-size / 2);
    placementData.setWidth(size);
    placementData.setHeight(size);
    placementData.setYOffset(-size * 0.66f);
    placementData.setRotateWithLine(true);
    actionDecorator.setPlacementData(placementData);
    // Add text to the action decorator
    KText textToAdd = _kContainerRenderingExtensions.addText(actionDecorator, 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);
    return actionDecorator;
}
Also used : KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KDecoratorPlacementData(de.cau.cs.kieler.klighd.krendering.KDecoratorPlacementData) KText(de.cau.cs.kieler.klighd.krendering.KText) KPosition(de.cau.cs.kieler.klighd.krendering.KPosition)

Example 3 with KPosition

use of de.cau.cs.kieler.klighd.krendering.KPosition 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)

Example 4 with KPosition

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

the class LinguaFrancaShapeExtensions method addShutdownFigure.

/**
 * Creates the visual representation of a shutdown trigger.
 */
public KPolygon addShutdownFigure(KNode node) {
    _kNodeExtensions.setMinimalNodeSize(node, 18, 18);
    KPolygon figure = _kRenderingExtensions.addPolygon(node);
    _kRenderingExtensions.setLineWidth(figure, 1);
    _kRenderingExtensions.setBackground(figure, Colors.WHITE);
    _linguaFrancaStyleExtensions.noSelectionStyle(figure);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure);
    List<KPosition> pointsToAdd = List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0.5f, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(RIGHT, 0, 0.5f, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0.5f));
    figure.getPoints().addAll(pointsToAdd);
    return figure;
}
Also used : KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KPosition(de.cau.cs.kieler.klighd.krendering.KPosition)

Example 5 with KPosition

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

the class LinguaFrancaShapeExtensions method addTrianglePort.

/**
 * Creates the visual representation of a reactor port.
 */
public KPolygon addTrianglePort(KPort port, boolean multiport) {
    port.setSize(8, 8);
    // Create triangle port
    KPolygon trianglePort = _kRenderingExtensions.addPolygon(port);
    // Set line width and background color according to multiport or not
    float lineWidth = multiport ? 2.2f : 1;
    _kRenderingExtensions.setLineWidth(trianglePort, lineWidth);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(trianglePort);
    Colors background = multiport ? Colors.WHITE : Colors.BLACK;
    _kRenderingExtensions.setBackground(trianglePort, background);
    List<KPosition> pointsToAdd;
    if (multiport) {
        // Compensate for line width by making triangle smaller
        // Do not adjust by port size because this will affect port distribution and cause offsets between parallel connections
        pointsToAdd = List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0.6f, 0), _kRenderingExtensions.createKPosition(RIGHT, 1.2f, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0.6f, 0));
    } else {
        pointsToAdd = List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0));
    }
    trianglePort.getPoints().addAll(pointsToAdd);
    return trianglePort;
}
Also used : KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) Colors(de.cau.cs.kieler.klighd.krendering.Colors) KPosition(de.cau.cs.kieler.klighd.krendering.KPosition)

Aggregations

KPosition (de.cau.cs.kieler.klighd.krendering.KPosition)5 KPolygon (de.cau.cs.kieler.klighd.krendering.KPolygon)4 KText (de.cau.cs.kieler.klighd.krendering.KText)2 KPort (de.cau.cs.kieler.klighd.kgraph.KPort)1 Colors (de.cau.cs.kieler.klighd.krendering.Colors)1 KDecoratorPlacementData (de.cau.cs.kieler.klighd.krendering.KDecoratorPlacementData)1 KEllipse (de.cau.cs.kieler.klighd.krendering.KEllipse)1 KPolyline (de.cau.cs.kieler.klighd.krendering.KPolyline)1 ArrayList (java.util.ArrayList)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1