Search in sources :

Example 1 with KContainerRendering

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

the class LinguaFrancaShapeExtensions method addReactorFigure.

/**
 * Creates the visual representation of a reactor node
 */
public ReactorFigureComponents addReactorFigure(KNode node, ReactorInstance reactorInstance, String text) {
    int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6;
    Function1<KRoundedRectangle, KRendering> style = r -> {
        _kRenderingExtensions.setLineWidth(r, 1);
        _kRenderingExtensions.setForeground(r, Colors.GRAY);
        _kRenderingExtensions.setBackground(r, Colors.GRAY_95);
        return _linguaFrancaStyleExtensions.boldLineSelectionStyle(r);
    };
    KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1);
    _kContainerRenderingExtensions.setGridPlacement(figure, 1);
    style.apply(figure);
    figure.setProperty(REACTOR_CONTENT_CONTAINER, true);
    // minimal node size is necessary if no text will be added
    List<Float> minSize = List.of(2 * figure.getCornerWidth(), 2 * figure.getCornerHeight());
    _kNodeExtensions.setMinimalNodeSize(node, minSize.get(0), minSize.get(1));
    // Add parent container
    KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure);
    _kRenderingExtensions.setInvisible(parentContainer, true);
    setGridPlacementDataFromPointToPoint(parentContainer, LEFT, padding, 0, TOP, padding, 0, RIGHT, padding, 0, BOTTOM, _utilityExtensions.hasContent(reactorInstance) ? 4 : padding, 0);
    // Add centered child container
    KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer);
    _kRenderingExtensions.setInvisible(childContainer, true);
    _kRenderingExtensions.setPointPlacementData(childContainer, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0.5f, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0);
    KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1);
    KText childText = _kContainerRenderingExtensions.addText(childContainer, text);
    DiagramSyntheses.suppressSelectability(childText);
    _linguaFrancaStyleExtensions.underlineSelectionStyle(childText);
    if (!_utilityExtensions.isRoot(reactorInstance) && reactorInstance.getDefinition().getHost() != null) {
        KRendering cloudUploadIcon = _linguaFrancaStyleExtensions.addCloudUploadIcon(childContainer);
        setGridPlacementDataFromPointToPoint(cloudUploadIcon, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
        placement.setNumColumns(2);
        if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) {
            KText reactorHostText = _kContainerRenderingExtensions.addText(childContainer, _utilityExtensions.toText(reactorInstance.getDefinition().getHost()));
            DiagramSyntheses.suppressSelectability(reactorHostText);
            _linguaFrancaStyleExtensions.underlineSelectionStyle(reactorHostText);
            setGridPlacementDataFromPointToPoint(reactorHostText, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
            placement.setNumColumns(3);
        }
    }
    if (reactorInstance.isBank()) {
        List<KRendering> bank = new ArrayList<>();
        KContainerRendering container = _kRenderingExtensions.addInvisibleContainerRendering(node);
        // TODO handle unresolved width
        KRoundedRectangle banks;
        banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
        style.apply(banks);
        setGridPlacementDataFromPointToPoint(banks, LEFT, BANK_FIGURE_X_OFFSET_SUM, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
        if (reactorInstance.getWidth() == 3) {
            banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
            style.apply(banks);
            setGridPlacementDataFromPointToPoint(banks, LEFT, BANK_FIGURE_X_OFFSET_SUM / 2, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM / 2, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM / 2, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 2, 0);
        } else if (reactorInstance.getWidth() != 2 && reactorInstance.getWidth() != 3) {
            banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
            style.apply(banks);
            setGridPlacementDataFromPointToPoint(banks, LEFT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM / 3, 0);
            banks = _kContainerRenderingExtensions.addRoundedRectangle(container, 8, 8, 1);
            style.apply(banks);
            setGridPlacementDataFromPointToPoint(banks, LEFT, BANK_FIGURE_X_OFFSET_SUM / 3, 0, TOP, BANK_FIGURE_Y_OFFSET_SUM / 3, 0, RIGHT, 2 * BANK_FIGURE_X_OFFSET_SUM / 3, 0, BOTTOM, 2 * BANK_FIGURE_Y_OFFSET_SUM / 3, 0);
        }
        container.getChildren().add(figure);
        setGridPlacementDataFromPointToPoint(figure, LEFT, 0, 0, TOP, 0, 0, RIGHT, BANK_FIGURE_X_OFFSET_SUM, 0, BOTTOM, BANK_FIGURE_Y_OFFSET_SUM, 0);
        bank.addAll(container.getChildren());
        KRectangle widthLabelContainer = _kContainerRenderingExtensions.addRectangle(container);
        _kRenderingExtensions.setInvisible(widthLabelContainer, true);
        setGridPlacementDataFromPointToPoint(widthLabelContainer, LEFT, 12, 0, BOTTOM, 9, 0, RIGHT, 6, 0, BOTTOM, 0.5f, 0);
        // Handle unresolved width.
        String widthLabel = reactorInstance.getWidth() >= 0 ? Integer.toString(reactorInstance.getWidth()) : "?";
        KText widthLabelText = _kContainerRenderingExtensions.addText(widthLabelContainer, widthLabel);
        _kRenderingExtensions.setHorizontalAlignment(widthLabelText, HorizontalAlignment.LEFT);
        _kRenderingExtensions.setVerticalAlignment(widthLabelText, VerticalAlignment.BOTTOM);
        _kRenderingExtensions.setFontSize(widthLabelText, 6);
        _linguaFrancaStyleExtensions.noSelectionStyle(widthLabelText);
        associateWith(widthLabelText, reactorInstance.getDefinition().getWidthSpec());
        return new ReactorFigureComponents(container, figure, bank);
    } else {
        return new ReactorFigureComponents(figure, figure, List.of(figure));
    }
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) KArc(de.cau.cs.kieler.klighd.krendering.KArc) Arc(de.cau.cs.kieler.klighd.krendering.Arc) PortSide(org.eclipse.elk.core.options.PortSide) KLabelExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions) Extension(org.eclipse.xtext.xbase.lib.Extension) AbstractSynthesisExtensions(org.lflang.diagram.synthesis.AbstractSynthesisExtensions) KEdgeExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions) KAreaPlacementData(de.cau.cs.kieler.klighd.krendering.KAreaPlacementData) KContainerRenderingExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions) KRenderingExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions) KDecoratorPlacementData(de.cau.cs.kieler.klighd.krendering.KDecoratorPlacementData) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline) LineStyle(de.cau.cs.kieler.klighd.krendering.LineStyle) VerticalAlignment(de.cau.cs.kieler.klighd.krendering.VerticalAlignment) LinguaFrancaSynthesis(org.lflang.diagram.synthesis.LinguaFrancaSynthesis) PositionReferenceY(de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceY) PositionReferenceX(de.cau.cs.kieler.klighd.krendering.extensions.PositionReferenceX) DiagramSyntheses(de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses) KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KEdge(de.cau.cs.kieler.klighd.kgraph.KEdge) KPolylineExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KPolylineExtensions) KPortExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KPortExtensions) KEllipse(de.cau.cs.kieler.klighd.krendering.KEllipse) List(java.util.List) UtilityExtensions(org.lflang.diagram.synthesis.util.UtilityExtensions) KColorExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KColorExtensions) Pair(org.eclipse.xtext.xbase.lib.Pair) StringExtensions(org.eclipse.xtext.xbase.lib.StringExtensions) KGridPlacement(de.cau.cs.kieler.klighd.krendering.KGridPlacement) KPosition(de.cau.cs.kieler.klighd.krendering.KPosition) KNodeExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions) ReactionPortAdjustment(org.lflang.diagram.synthesis.postprocessor.ReactionPortAdjustment) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) KlighdConstants(de.cau.cs.kieler.klighd.KlighdConstants) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) TimerInstance(org.lflang.generator.TimerInstance) KText(de.cau.cs.kieler.klighd.krendering.KText) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KRoundedRectangle(de.cau.cs.kieler.klighd.krendering.KRoundedRectangle) Property(org.eclipse.elk.graph.properties.Property) KRenderingFactory(de.cau.cs.kieler.klighd.krendering.KRenderingFactory) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) ReactionInstance(org.lflang.generator.ReactionInstance) ReactorInstance(org.lflang.generator.ReactorInstance) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) ViewSynthesisShared(de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) Colors(de.cau.cs.kieler.klighd.krendering.Colors) HorizontalAlignment(de.cau.cs.kieler.klighd.krendering.HorizontalAlignment) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ArrayList(java.util.ArrayList) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) KRoundedRectangle(de.cau.cs.kieler.klighd.krendering.KRoundedRectangle) KGridPlacement(de.cau.cs.kieler.klighd.krendering.KGridPlacement) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) KText(de.cau.cs.kieler.klighd.krendering.KText) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering)

Example 2 with KContainerRendering

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

the class InterfaceDependenciesVisualization method addInterfaceDependencies.

/**
 * Adds interface dependencies to the node if this option is active.
 * Visibility will be adjusted based on expansion state.
 */
public Spacing addInterfaceDependencies(KNode node, boolean expanded) {
    Spacing marginInit = null;
    if (getBooleanValue(SHOW_INTERFACE_DEPENDENCIES)) {
        List<Pair<KPort, KPort>> deps = getPortDependencies(node);
        if (!deps.isEmpty()) {
            for (Pair<KPort, KPort> pair : deps) {
                createDependencyEdge(pair, expanded);
            }
            // Fix content (label) of collapsed rendering
            KContainerRendering contentContainer = IterableExtensions.findFirst(Iterables.filter(node.getData(), KContainerRendering.class), it -> {
                return it.getProperty(KlighdProperties.COLLAPSED_RENDERING);
            });
            if (contentContainer != null) {
                if (!contentContainer.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER)) {
                    contentContainer = IteratorExtensions.findFirst(Iterators.filter(contentContainer.eAllContents(), KContainerRendering.class), it -> {
                        return it.getProperty(LinguaFrancaShapeExtensions.REACTOR_CONTENT_CONTAINER);
                    });
                }
                if (contentContainer != null) {
                    List<KRendering> content = ImmutableList.copyOf(contentContainer.getChildren());
                    // Put into two new containers such that they are not centered/maximized
                    KRectangle firstContainer = _kContainerRenderingExtensions.addRectangle(contentContainer);
                    _kRenderingExtensions.setInvisible(firstContainer, true);
                    KRectangle secondContainer = _kContainerRenderingExtensions.addRectangle(firstContainer);
                    _kRenderingExtensions.setInvisible(secondContainer, true);
                    _kContainerRenderingExtensions.setGridPlacement(secondContainer, 1);
                    Iterables.addAll(secondContainer.getChildren(), content);
                    _kRenderingExtensions.setPointPlacementData(secondContainer, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_TOP, 0, 0, 0, 0);
                    // Adjust ports separate dependency edges from label/content
                    if (content.size() > 0) {
                        marginInit = _utilityExtensions.getPortMarginsInitIfAbsent(node).add(new ElkMargin((content.size() * 20) - 8, 0, 0, 0));
                    }
                }
            }
        }
    }
    return marginInit;
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) Iterables(com.google.common.collect.Iterables) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Spacing(org.eclipse.elk.core.math.Spacing) LinguaFrancaStyleExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaStyleExtensions) Inject(com.google.inject.Inject) Random(java.util.Random) Extension(org.eclipse.xtext.xbase.lib.Extension) AbstractSynthesisExtensions(org.lflang.diagram.synthesis.AbstractSynthesisExtensions) Iterators(com.google.common.collect.Iterators) KEdgeExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions) KContainerRenderingExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions) KRenderingExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline) LineStyle(de.cau.cs.kieler.klighd.krendering.LineStyle) ImmutableList(com.google.common.collect.ImmutableList) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) LinguaFrancaSynthesis(org.lflang.diagram.synthesis.LinguaFrancaSynthesis) DiagramSyntheses(de.cau.cs.kieler.klighd.syntheses.DiagramSyntheses) KEdge(de.cau.cs.kieler.klighd.kgraph.KEdge) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KInvisibility(de.cau.cs.kieler.klighd.krendering.KInvisibility) SynthesisOption(de.cau.cs.kieler.klighd.SynthesisOption) Property(org.eclipse.elk.graph.properties.Property) KRenderingFactory(de.cau.cs.kieler.klighd.krendering.KRenderingFactory) Set(java.util.Set) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) LinguaFrancaShapeExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions) Sets(com.google.common.collect.Sets) IteratorExtensions(org.eclipse.xtext.xbase.lib.IteratorExtensions) List(java.util.List) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) KlighdProperties(de.cau.cs.kieler.klighd.util.KlighdProperties) ViewSynthesisShared(de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) Pair(org.eclipse.xtext.xbase.lib.Pair) Spacing(org.eclipse.elk.core.math.Spacing) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) Pair(org.eclipse.xtext.xbase.lib.Pair) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Example 3 with KContainerRendering

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

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

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

the class LinguaFrancaShapeExtensions method addMainReactorFigure.

/**
 * Creates the main reactor frame.
 */
public KRoundedRectangle addMainReactorFigure(KNode node, ReactorInstance reactorInstance, String text) {
    int padding = getBooleanValue(LinguaFrancaSynthesis.SHOW_HYPERLINKS) ? 8 : 6;
    KRoundedRectangle figure = _kRenderingExtensions.addRoundedRectangle(node, 8, 8, 1);
    _kContainerRenderingExtensions.setGridPlacement(figure, 1);
    _kRenderingExtensions.setLineWidth(figure, 1);
    _kRenderingExtensions.setForeground(figure, Colors.GRAY);
    _kRenderingExtensions.setBackground(figure, Colors.WHITE);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(figure);
    // Create parent container
    KRectangle parentContainer = _kContainerRenderingExtensions.addRectangle(figure);
    _kRenderingExtensions.setInvisible(parentContainer, true);
    setGridPlacementDataFromPointToPoint(parentContainer, LEFT, padding, 0, TOP, padding, 0, RIGHT, padding, 0, BOTTOM, 4, 0);
    // Create child container
    KRectangle childContainer = _kContainerRenderingExtensions.addRectangle(parentContainer);
    _kRenderingExtensions.setInvisible(childContainer, true);
    _kRenderingExtensions.setPointPlacementData(childContainer, _kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0.5f, _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, 0, 0);
    KGridPlacement placement = _kContainerRenderingExtensions.setGridPlacement(childContainer, 1);
    // Add text to the child container
    KText childText = _kContainerRenderingExtensions.addText(childContainer, text);
    DiagramSyntheses.suppressSelectability(childText);
    _linguaFrancaStyleExtensions.underlineSelectionStyle(childText);
    if (reactorInstance.reactorDefinition.isFederated()) {
        KContainerRendering cloudIcon = _linguaFrancaStyleExtensions.addCloudIcon(childContainer);
        setGridPlacementDataFromPointToPoint(cloudIcon, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
        placement.setNumColumns(2);
        if (reactorInstance.reactorDefinition.getHost() != null && getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTOR_HOST)) {
            KText hostNameText = _kContainerRenderingExtensions.addText(childContainer, _utilityExtensions.toText(reactorInstance.reactorDefinition.getHost()));
            DiagramSyntheses.suppressSelectability(hostNameText);
            _linguaFrancaStyleExtensions.underlineSelectionStyle(hostNameText);
            setGridPlacementDataFromPointToPoint(hostNameText, LEFT, 3, 0, TOP, 0, 0, RIGHT, 0, 0, BOTTOM, 0, 0);
            placement.setNumColumns(3);
        }
    }
    return figure;
}
Also used : KText(de.cau.cs.kieler.klighd.krendering.KText) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) KRoundedRectangle(de.cau.cs.kieler.klighd.krendering.KRoundedRectangle) KGridPlacement(de.cau.cs.kieler.klighd.krendering.KGridPlacement) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle)

Aggregations

KContainerRendering (de.cau.cs.kieler.klighd.krendering.KContainerRendering)8 KText (de.cau.cs.kieler.klighd.krendering.KText)6 KPolygon (de.cau.cs.kieler.klighd.krendering.KPolygon)5 KLabel (de.cau.cs.kieler.klighd.kgraph.KLabel)4 KPolyline (de.cau.cs.kieler.klighd.krendering.KPolyline)4 LabelDecorationConfigurator (de.cau.cs.kieler.klighd.labels.decoration.LabelDecorationConfigurator)4 KRectangle (de.cau.cs.kieler.klighd.krendering.KRectangle)3 IDecoratorRenderingProvider (de.cau.cs.kieler.klighd.labels.decoration.IDecoratorRenderingProvider)3 ElkPadding (org.eclipse.elk.core.math.ElkPadding)3 KEdge (de.cau.cs.kieler.klighd.kgraph.KEdge)2 KNode (de.cau.cs.kieler.klighd.kgraph.KNode)2 KPort (de.cau.cs.kieler.klighd.kgraph.KPort)2 KRendering (de.cau.cs.kieler.klighd.krendering.KRendering)2 KRenderingFactory (de.cau.cs.kieler.klighd.krendering.KRenderingFactory)2 KSpline (de.cau.cs.kieler.klighd.krendering.KSpline)2 LineStyle (de.cau.cs.kieler.klighd.krendering.LineStyle)2 ViewSynthesisShared (de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared)2 KContainerRenderingExtensions (de.cau.cs.kieler.klighd.krendering.extensions.KContainerRenderingExtensions)2 KEdgeExtensions (de.cau.cs.kieler.klighd.krendering.extensions.KEdgeExtensions)2 KRenderingExtensions (de.cau.cs.kieler.klighd.krendering.extensions.KRenderingExtensions)2