Search in sources :

Example 1 with KPolygon

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

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

use of de.cau.cs.kieler.klighd.krendering.KPolygon 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 4 with KPolygon

use of de.cau.cs.kieler.klighd.krendering.KPolygon 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 5 with KPolygon

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

Aggregations

KPolygon (de.cau.cs.kieler.klighd.krendering.KPolygon)9 KText (de.cau.cs.kieler.klighd.krendering.KText)6 KContainerRendering (de.cau.cs.kieler.klighd.krendering.KContainerRendering)4 KPosition (de.cau.cs.kieler.klighd.krendering.KPosition)4 KLabel (de.cau.cs.kieler.klighd.kgraph.KLabel)3 KPolyline (de.cau.cs.kieler.klighd.krendering.KPolyline)3 IDecoratorRenderingProvider (de.cau.cs.kieler.klighd.labels.decoration.IDecoratorRenderingProvider)3 LabelDecorationConfigurator (de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator)3 ElkPadding (org.eclipse.elk.core.math.ElkPadding)3 KSpline (de.cau.cs.kieler.klighd.krendering.KSpline)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 KRectangle (de.cau.cs.kieler.klighd.krendering.KRectangle)1 KRendering (de.cau.cs.kieler.klighd.krendering.KRendering)1 Pair (org.eclipse.xtext.xbase.lib.Pair)1 ReactorInstance (org.lflang.generator.ReactorInstance)1