Search in sources :

Example 6 with KRectangle

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

the class ReactorIcons method handleIcon.

public void handleIcon(KContainerRendering rendering, ReactorDecl reactor, boolean collapsed) {
    if (!collapsed) {
        return;
    }
    URL iconLocation = locateIcon(reactor);
    if (iconLocation != null) {
        ImageData data = loadImage(iconLocation);
        if (data != null) {
            KRectangle figure = _kContainerRenderingExtensions.addRectangle(rendering);
            _kRenderingExtensions.setInvisible(figure, true);
            KGridPlacementData figurePlacement = _kRenderingExtensions.setGridPlacementData(figure, data.width, data.height);
            _kRenderingExtensions.to(_kRenderingExtensions.from(figurePlacement, _kRenderingExtensions.LEFT, 3, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 3, 0, _kRenderingExtensions.BOTTOM, 3, 0);
            KRectangle icon = _kContainerRenderingExtensions.addRectangle(figure);
            _kRenderingExtensions.setInvisible(icon, true);
            _kContainerRenderingExtensions.addImage(icon, data);
            _kRenderingExtensions.setPointPlacementData(icon, _kRenderingExtensions.createKPosition(_kRenderingExtensions.LEFT, 0, 0.5f, _kRenderingExtensions.TOP, 0, 0.5f), _kRenderingExtensions.H_CENTRAL, _kRenderingExtensions.V_CENTRAL, 0, 0, data.width, data.height);
        }
    }
}
Also used : KGridPlacementData(de.cau.cs.kieler.klighd.krendering.KGridPlacementData) ImageData(org.eclipse.swt.graphics.ImageData) URL(java.net.URL) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle)

Example 7 with KRectangle

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

the class LinguaFrancaSynthesis method createReactorNode.

private Collection<KNode> createReactorNode(ReactorInstance reactorInstance, boolean expandDefault, Table<ReactorInstance, PortInstance, KPort> inputPortsReg, Table<ReactorInstance, PortInstance, KPort> outputPortsReg, Map<ReactorInstance, KNode> allReactorNodes) {
    Reactor reactor = reactorInstance.reactorDefinition;
    KNode node = _kNodeExtensions.createNode();
    allReactorNodes.put(reactorInstance, node);
    associateWith(node, reactor);
    _utilityExtensions.setID(node, reactorInstance.uniqueID());
    // save to distinguish nodes associated with the same reactor
    NamedInstanceUtil.linkInstance(node, reactorInstance);
    List<KNode> nodes = new ArrayList<>();
    nodes.add(node);
    String label = createReactorLabel(reactorInstance);
    if (reactorInstance.recursive) {
        // Mark this node
        node.setProperty(REACTOR_RECURSIVE_INSTANTIATION, true);
        // Mark root
        allReactorNodes.get(reactorInstance.root()).setProperty(REACTOR_RECURSIVE_INSTANTIATION, true);
    }
    if (reactor == null) {
        _linguaFrancaShapeExtensions.addErrorMessage(node, TEXT_REACTOR_NULL, null);
    } else if (reactorInstance.isMainOrFederated()) {
        KRoundedRectangle figure = _linguaFrancaShapeExtensions.addMainReactorFigure(node, reactorInstance, label);
        if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE && !reactorInstance.parameters.isEmpty()) {
            KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(figure);
            _kRenderingExtensions.setInvisible(rectangle, true);
            _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(rectangle), _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 4, 0);
            _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT);
            addParameterList(rectangle, reactorInstance.parameters);
        }
        if (reactorInstance.recursive) {
            nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE));
            _linguaFrancaStyleExtensions.errorStyle(figure);
        } else {
            _kContainerRenderingExtensions.addChildArea(figure);
            node.getChildren().addAll(transformReactorNetwork(reactorInstance, new HashMap<>(), new HashMap<>(), allReactorNodes));
        }
        Iterables.addAll(nodes, createUserComments(reactor, node));
        configureReactorNodeLayout(node);
        // Additional layout adjustment for main node
        setLayoutOption(node, CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
        setLayoutOption(node, CoreOptions.DIRECTION, Direction.RIGHT);
        setLayoutOption(node, CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.MINIMUM_SIZE));
        setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_BK_FIXED_ALIGNMENT, FixedAlignment.BALANCED);
        setLayoutOption(node, LayeredOptions.NODE_PLACEMENT_BK_EDGE_STRAIGHTENING, EdgeStraighteningStrategy.IMPROVE_STRAIGHTNESS);
        setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE, LayeredOptions.SPACING_EDGE_NODE.getDefault() * 1.1f);
        setLayoutOption(node, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS, LayeredOptions.SPACING_EDGE_NODE_BETWEEN_LAYERS.getDefault() * 1.1f);
        if (!getBooleanValue(SHOW_HYPERLINKS)) {
            setLayoutOption(node, CoreOptions.PADDING, new ElkPadding(-1, 6, 6, 6));
            setLayoutOption(node, LayeredOptions.SPACING_COMPONENT_COMPONENT, LayeredOptions.SPACING_COMPONENT_COMPONENT.getDefault() * 0.5f);
        }
    } else {
        ReactorInstance instance = reactorInstance;
        // Expanded Rectangle
        ReactorFigureComponents comps = _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label);
        comps.getOuter().setProperty(KlighdProperties.EXPANDED_RENDERING, true);
        for (KRendering figure : comps.getFigures()) {
            associateWith(figure, reactor);
            _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID);
        }
        _reactorIcons.handleIcon(comps.getReactor(), reactor, false);
        if (getBooleanValue(SHOW_HYPERLINKS)) {
            // Collapse button
            KText button = _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_HIDE_ACTION);
            _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(button), _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 0, 0);
            _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID);
            _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID);
        }
        if (getObjectValue(REACTOR_PARAMETER_MODE) == ReactorParameterDisplayModes.TABLE && !instance.parameters.isEmpty()) {
            KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(comps.getReactor());
            _kRenderingExtensions.setInvisible(rectangle, true);
            if (!getBooleanValue(SHOW_HYPERLINKS)) {
                _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(rectangle), _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 4, 0);
            } else {
                _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(rectangle), _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 4, 0), _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 0, 0);
            }
            _kRenderingExtensions.setHorizontalAlignment(rectangle, HorizontalAlignment.LEFT);
            addParameterList(rectangle, instance.parameters);
        }
        if (instance.recursive) {
            comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle);
        } else {
            _kContainerRenderingExtensions.addChildArea(comps.getReactor());
        }
        // Collapse Rectangle
        comps = _linguaFrancaShapeExtensions.addReactorFigure(node, reactorInstance, label);
        comps.getOuter().setProperty(KlighdProperties.COLLAPSED_RENDERING, true);
        for (KRendering figure : comps.getFigures()) {
            associateWith(figure, reactor);
            if (_utilityExtensions.hasContent(instance) && !instance.recursive) {
                _kRenderingExtensions.addDoubleClickAction(figure, MemorizingExpandCollapseAction.ID);
            }
        }
        _reactorIcons.handleIcon(comps.getReactor(), reactor, true);
        if (getBooleanValue(SHOW_HYPERLINKS)) {
            // Expand button
            if (_utilityExtensions.hasContent(instance) && !instance.recursive) {
                KText button = _linguaFrancaShapeExtensions.addTextButton(comps.getReactor(), TEXT_SHOW_ACTION);
                _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(button), _kRenderingExtensions.LEFT, 8, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 8, 0, _kRenderingExtensions.BOTTOM, 8, 0);
                _kRenderingExtensions.addSingleClickAction(button, MemorizingExpandCollapseAction.ID);
                _kRenderingExtensions.addDoubleClickAction(button, MemorizingExpandCollapseAction.ID);
            }
        }
        if (instance.recursive) {
            comps.getFigures().forEach(_linguaFrancaStyleExtensions::errorStyle);
        }
        // Create ports
        Map<PortInstance, KPort> inputPorts = new HashMap<>();
        Map<PortInstance, KPort> outputPorts = new HashMap<>();
        for (PortInstance input : ListExtensions.reverseView(instance.inputs)) {
            inputPorts.put(input, addIOPort(node, input, true, input.isMultiport(), reactorInstance.isBank()));
        }
        for (PortInstance output : instance.outputs) {
            outputPorts.put(output, addIOPort(node, output, false, output.isMultiport(), reactorInstance.isBank()));
        }
        // Mark ports
        inputPorts.values().forEach(it -> it.setProperty(REACTOR_INPUT, true));
        outputPorts.values().forEach(it -> it.setProperty(REACTOR_OUTPUT, true));
        // Add content
        if (_utilityExtensions.hasContent(instance) && !instance.recursive) {
            node.getChildren().addAll(transformReactorNetwork(instance, inputPorts, outputPorts, allReactorNodes));
        }
        // Pass port to given tables
        if (!_utilityExtensions.isRoot(instance)) {
            if (inputPortsReg != null) {
                for (Map.Entry<PortInstance, KPort> entry : inputPorts.entrySet()) {
                    inputPortsReg.put(instance, entry.getKey(), entry.getValue());
                }
            }
            if (outputPortsReg != null) {
                for (Map.Entry<PortInstance, KPort> entry : outputPorts.entrySet()) {
                    outputPortsReg.put(instance, entry.getKey(), entry.getValue());
                }
            }
        }
        if (instance.recursive) {
            setLayoutOption(node, KlighdProperties.EXPAND, false);
            nodes.add(addErrorComment(node, TEXT_ERROR_RECURSIVE));
        } else {
            setLayoutOption(node, KlighdProperties.EXPAND, expandDefault);
            // Interface Dependencies
            _interfaceDependenciesVisualization.addInterfaceDependencies(node, expandDefault);
        }
        if (!_utilityExtensions.isRoot(instance)) {
            // add the annotation now.
            if (!getBooleanValue(SHOW_ALL_REACTORS)) {
                Iterables.addAll(nodes, createUserComments(reactor, node));
            }
        } else {
            Iterables.addAll(nodes, createUserComments(reactor, node));
        }
        configureReactorNodeLayout(node);
    }
    // Find and annotate cycles
    if (getBooleanValue(CYCLE_DETECTION) && _utilityExtensions.isRoot(reactorInstance)) {
        KNode errNode = detectAndAnnotateCycles(node, reactorInstance, allReactorNodes);
        if (errNode != null) {
            nodes.add(errNode);
        }
    }
    return nodes;
}
Also used : LineCap(de.cau.cs.kieler.klighd.krendering.LineCap) CoreOptions(org.eclipse.elk.core.options.CoreOptions) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Exceptions(org.eclipse.xtext.xbase.lib.Exceptions) MemorizingExpandCollapseAction(org.lflang.diagram.synthesis.action.MemorizingExpandCollapseAction) LinguaFrancaStyleExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaStyleExtensions) PortSide(org.eclipse.elk.core.options.PortSide) KLabelExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions) FileUtil(org.lflang.util.FileUtil) HashBasedTable(com.google.common.collect.HashBasedTable) ExpandAllReactorsAction(org.lflang.diagram.synthesis.action.ExpandAllReactorsAction) Extension(org.eclipse.xtext.xbase.lib.Extension) CollapseAllReactorsAction(org.lflang.diagram.synthesis.action.CollapseAllReactorsAction) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) 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) HashMultimap(com.google.common.collect.HashMultimap) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline) LineStyle(de.cau.cs.kieler.klighd.krendering.LineStyle) Map(java.util.Map) TriggerInstance(org.lflang.generator.TriggerInstance) ReactorIcons(org.lflang.diagram.synthesis.util.ReactorIcons) Connection(org.lflang.lf.Connection) EnumSet(java.util.EnumSet) 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) NamedInstanceUtil(org.lflang.diagram.synthesis.util.NamedInstanceUtil) SynthesisOption(de.cau.cs.kieler.klighd.SynthesisOption) Collection(java.util.Collection) Set(java.util.Set) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) EObject(org.eclipse.emf.ecore.EObject) LinguaFrancaShapeExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions) BoxLayouterOptions(org.eclipse.elk.core.options.BoxLayouterOptions) List(java.util.List) InterfaceDependenciesVisualization(org.lflang.diagram.synthesis.util.InterfaceDependenciesVisualization) KlighdProperties(de.cau.cs.kieler.klighd.util.KlighdProperties) Direction(org.eclipse.elk.core.options.Direction) UtilityExtensions(org.lflang.diagram.synthesis.util.UtilityExtensions) KLabel(de.cau.cs.kieler.klighd.kgraph.KLabel) KStyle(de.cau.cs.kieler.klighd.krendering.KStyle) Pair(org.eclipse.xtext.xbase.lib.Pair) StringExtensions(org.eclipse.xtext.xbase.lib.StringExtensions) AbstractDiagramSynthesis(de.cau.cs.kieler.klighd.syntheses.AbstractDiagramSynthesis) FileConfig(org.lflang.FileConfig) ASTUtils(org.lflang.ASTUtils) Iterables(com.google.common.collect.Iterables) KNodeExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ListExtensions(org.eclipse.xtext.xbase.lib.ListExtensions) ModeDiagrams(org.lflang.diagram.synthesis.util.ModeDiagrams) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) EdgeStraighteningStrategy(org.eclipse.elk.alg.layered.options.EdgeStraighteningStrategy) ShowCycleAction(org.lflang.diagram.synthesis.action.ShowCycleAction) ElkPadding(org.eclipse.elk.core.math.ElkPadding) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) CycleVisualization(org.lflang.diagram.synthesis.util.CycleVisualization) TimerInstance(org.lflang.generator.TimerInstance) LinkedList(java.util.LinkedList) SynthesisErrorReporter(org.lflang.diagram.synthesis.util.SynthesisErrorReporter) KText(de.cau.cs.kieler.klighd.krendering.KText) FixedAlignment(org.eclipse.elk.alg.layered.options.FixedAlignment) FilterCycleAction(org.lflang.diagram.synthesis.action.FilterCycleAction) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KRoundedRectangle(de.cau.cs.kieler.klighd.krendering.KRoundedRectangle) RuntimeRange(org.lflang.generator.RuntimeRange) Model(org.lflang.lf.Model) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Property(org.eclipse.elk.graph.properties.Property) Conversions(org.eclipse.xtext.xbase.lib.Conversions) KVector(org.eclipse.elk.core.math.KVector) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) PortInstance(org.lflang.generator.PortInstance) ReactionInstance(org.lflang.generator.ReactionInstance) ParameterInstance(org.lflang.generator.ParameterInstance) SendRange(org.lflang.generator.SendRange) ActionInstance(org.lflang.generator.ActionInstance) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) ReactorInstance(org.lflang.generator.ReactorInstance) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) ReactorFigureComponents(org.lflang.diagram.synthesis.styles.ReactorFigureComponents) DisplayedActionData(de.cau.cs.kieler.klighd.DisplayedActionData) ViewSynthesisShared(de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) Reactor(org.lflang.lf.Reactor) Colors(de.cau.cs.kieler.klighd.krendering.Colors) HorizontalAlignment(de.cau.cs.kieler.klighd.krendering.HorizontalAlignment) Table(com.google.common.collect.Table) PortInstance(org.lflang.generator.PortInstance) ArrayList(java.util.ArrayList) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KRoundedRectangle(de.cau.cs.kieler.klighd.krendering.KRoundedRectangle) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) KText(de.cau.cs.kieler.klighd.krendering.KText) ReactorInstance(org.lflang.generator.ReactorInstance) ReactorFigureComponents(org.lflang.diagram.synthesis.styles.ReactorFigureComponents) Reactor(org.lflang.lf.Reactor) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Map(java.util.Map) HashMap(java.util.HashMap)

Example 8 with KRectangle

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

the class LinguaFrancaSynthesis method detectAndAnnotateCycles.

private KNode detectAndAnnotateCycles(KNode node, ReactorInstance reactorInstance, Map<ReactorInstance, KNode> allReactorNodes) {
    if (node.getProperty(REACTOR_RECURSIVE_INSTANTIATION)) {
        _filterCycleAction.resetCycleFiltering(node);
        return addErrorComment(node, TEXT_ERROR_CONTAINS_RECURSION);
    } else {
        // only detect dependency cycles if not recursive
        try {
            boolean hasCycle = _cycleVisualization.detectAndHighlightCycles(reactorInstance, allReactorNodes, it -> {
                if (it instanceof KNode) {
                    List<KRendering> renderings = IterableExtensions.toList(Iterables.filter(((KNode) it).getData(), KRendering.class));
                    if (renderings.size() == 1) {
                        _linguaFrancaStyleExtensions.errorStyle(IterableExtensions.head(renderings));
                    } else {
                        IterableExtensions.filter(renderings, rendering -> {
                            return rendering.getProperty(KlighdProperties.COLLAPSED_RENDERING);
                        }).forEach(_linguaFrancaStyleExtensions::errorStyle);
                    }
                } else if (it instanceof KEdge) {
                    Iterables.filter(((KEdge) it).getData(), KRendering.class).forEach(_linguaFrancaStyleExtensions::errorStyle);
                    // TODO initiallyHide does not work with incremental (https://github.com/kieler/KLighD/issues/37)
                    // cycleEgde.initiallyShow() // Show hidden order dependencies
                    _kRenderingExtensions.setInvisible(_kRenderingExtensions.getKRendering(it), false);
                } else if (it instanceof KPort) {
                    Iterables.filter(((KPort) it).getData(), KRendering.class).forEach(_linguaFrancaStyleExtensions::errorStyle);
                // it.reverseTrianglePort()
                }
            });
            if (hasCycle) {
                KNode err = addErrorComment(node, TEXT_ERROR_CONTAINS_CYCLE);
                // Add to existing figure
                KRectangle rectangle = _kContainerRenderingExtensions.addRectangle(_kRenderingExtensions.getKContainerRendering(err));
                _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(rectangle), _kRenderingExtensions.LEFT, 3, 0, _kRenderingExtensions.TOP, (-1), 0), _kRenderingExtensions.RIGHT, 3, 0, _kRenderingExtensions.BOTTOM, 3, 0);
                _linguaFrancaStyleExtensions.noSelectionStyle(rectangle);
                _kRenderingExtensions.setInvisible(rectangle, true);
                _kContainerRenderingExtensions.setGridPlacement(rectangle, 2);
                KRectangle subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle);
                _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(subrectangle), _kRenderingExtensions.LEFT, 0, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 2, 0, _kRenderingExtensions.BOTTOM, 0, 0);
                _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle);
                _kRenderingExtensions.addSingleClickAction(subrectangle, ShowCycleAction.ID);
                KText subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, TEXT_ERROR_CYCLE_BTN_SHOW);
                // Copy text style
                List<KStyle> styles = ListExtensions.map(IterableExtensions.head(_kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), EcoreUtil::copy);
                subrectangleText.getStyles().addAll(styles);
                _kRenderingExtensions.setFontSize(subrectangleText, 5);
                _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0);
                _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText);
                _kRenderingExtensions.addSingleClickAction(subrectangleText, ShowCycleAction.ID);
                subrectangle = _kContainerRenderingExtensions.addRectangle(rectangle);
                _kRenderingExtensions.to(_kRenderingExtensions.from(_kRenderingExtensions.setGridPlacementData(subrectangle), _kRenderingExtensions.LEFT, 0, 0, _kRenderingExtensions.TOP, 0, 0), _kRenderingExtensions.RIGHT, 0, 0, _kRenderingExtensions.BOTTOM, 0, 0);
                _linguaFrancaStyleExtensions.noSelectionStyle(subrectangle);
                _kRenderingExtensions.addSingleClickAction(subrectangle, FilterCycleAction.ID);
                subrectangleText = _kContainerRenderingExtensions.addText(subrectangle, _filterCycleAction.isCycleFiltered(node) ? TEXT_ERROR_CYCLE_BTN_UNFILTER : TEXT_ERROR_CYCLE_BTN_FILTER);
                // Copy text style
                styles = ListExtensions.map(IterableExtensions.head(_kRenderingExtensions.getKContainerRendering(err).getChildren()).getStyles(), EcoreUtil::copy);
                subrectangleText.getStyles().addAll(styles);
                _kRenderingExtensions.setFontSize(subrectangleText, 5);
                _kRenderingExtensions.setSurroundingSpace(subrectangleText, 1, 0);
                _linguaFrancaStyleExtensions.noSelectionStyle(subrectangleText);
                _kRenderingExtensions.addSingleClickAction(subrectangleText, FilterCycleAction.ID);
                _filterCycleAction.markCycleFilterText(subrectangleText, err);
                // if user interactively requested a filtered diagram keep it filtered during updates
                if (_filterCycleAction.isCycleFiltered(node)) {
                    _filterCycleAction.filterCycle(node);
                }
                return err;
            }
        } catch (Exception e) {
            _filterCycleAction.resetCycleFiltering(node);
            e.printStackTrace();
            return addErrorComment(node, TEXT_ERROR_CYCLE_DETECTION);
        }
    }
    return null;
}
Also used : LineCap(de.cau.cs.kieler.klighd.krendering.LineCap) CoreOptions(org.eclipse.elk.core.options.CoreOptions) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Exceptions(org.eclipse.xtext.xbase.lib.Exceptions) MemorizingExpandCollapseAction(org.lflang.diagram.synthesis.action.MemorizingExpandCollapseAction) LinguaFrancaStyleExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaStyleExtensions) PortSide(org.eclipse.elk.core.options.PortSide) KLabelExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KLabelExtensions) FileUtil(org.lflang.util.FileUtil) HashBasedTable(com.google.common.collect.HashBasedTable) ExpandAllReactorsAction(org.lflang.diagram.synthesis.action.ExpandAllReactorsAction) Extension(org.eclipse.xtext.xbase.lib.Extension) CollapseAllReactorsAction(org.lflang.diagram.synthesis.action.CollapseAllReactorsAction) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) 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) HashMultimap(com.google.common.collect.HashMultimap) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline) LineStyle(de.cau.cs.kieler.klighd.krendering.LineStyle) Map(java.util.Map) TriggerInstance(org.lflang.generator.TriggerInstance) ReactorIcons(org.lflang.diagram.synthesis.util.ReactorIcons) Connection(org.lflang.lf.Connection) EnumSet(java.util.EnumSet) 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) NamedInstanceUtil(org.lflang.diagram.synthesis.util.NamedInstanceUtil) SynthesisOption(de.cau.cs.kieler.klighd.SynthesisOption) Collection(java.util.Collection) Set(java.util.Set) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) EObject(org.eclipse.emf.ecore.EObject) LinguaFrancaShapeExtensions(org.lflang.diagram.synthesis.styles.LinguaFrancaShapeExtensions) BoxLayouterOptions(org.eclipse.elk.core.options.BoxLayouterOptions) List(java.util.List) InterfaceDependenciesVisualization(org.lflang.diagram.synthesis.util.InterfaceDependenciesVisualization) KlighdProperties(de.cau.cs.kieler.klighd.util.KlighdProperties) Direction(org.eclipse.elk.core.options.Direction) UtilityExtensions(org.lflang.diagram.synthesis.util.UtilityExtensions) KLabel(de.cau.cs.kieler.klighd.kgraph.KLabel) KStyle(de.cau.cs.kieler.klighd.krendering.KStyle) Pair(org.eclipse.xtext.xbase.lib.Pair) StringExtensions(org.eclipse.xtext.xbase.lib.StringExtensions) AbstractDiagramSynthesis(de.cau.cs.kieler.klighd.syntheses.AbstractDiagramSynthesis) FileConfig(org.lflang.FileConfig) ASTUtils(org.lflang.ASTUtils) Iterables(com.google.common.collect.Iterables) KNodeExtensions(de.cau.cs.kieler.klighd.krendering.extensions.KNodeExtensions) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ListExtensions(org.eclipse.xtext.xbase.lib.ListExtensions) ModeDiagrams(org.lflang.diagram.synthesis.util.ModeDiagrams) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) EdgeStraighteningStrategy(org.eclipse.elk.alg.layered.options.EdgeStraighteningStrategy) ShowCycleAction(org.lflang.diagram.synthesis.action.ShowCycleAction) ElkPadding(org.eclipse.elk.core.math.ElkPadding) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) CycleVisualization(org.lflang.diagram.synthesis.util.CycleVisualization) TimerInstance(org.lflang.generator.TimerInstance) LinkedList(java.util.LinkedList) SynthesisErrorReporter(org.lflang.diagram.synthesis.util.SynthesisErrorReporter) KText(de.cau.cs.kieler.klighd.krendering.KText) FixedAlignment(org.eclipse.elk.alg.layered.options.FixedAlignment) FilterCycleAction(org.lflang.diagram.synthesis.action.FilterCycleAction) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KRoundedRectangle(de.cau.cs.kieler.klighd.krendering.KRoundedRectangle) RuntimeRange(org.lflang.generator.RuntimeRange) Model(org.lflang.lf.Model) PortConstraints(org.eclipse.elk.core.options.PortConstraints) Property(org.eclipse.elk.graph.properties.Property) Conversions(org.eclipse.xtext.xbase.lib.Conversions) KVector(org.eclipse.elk.core.math.KVector) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) KContainerRendering(de.cau.cs.kieler.klighd.krendering.KContainerRendering) PortInstance(org.lflang.generator.PortInstance) ReactionInstance(org.lflang.generator.ReactionInstance) ParameterInstance(org.lflang.generator.ParameterInstance) SendRange(org.lflang.generator.SendRange) ActionInstance(org.lflang.generator.ActionInstance) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) ReactorInstance(org.lflang.generator.ReactorInstance) IterableExtensions(org.eclipse.xtext.xbase.lib.IterableExtensions) ReactorFigureComponents(org.lflang.diagram.synthesis.styles.ReactorFigureComponents) DisplayedActionData(de.cau.cs.kieler.klighd.DisplayedActionData) ViewSynthesisShared(de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) Reactor(org.lflang.lf.Reactor) Colors(de.cau.cs.kieler.klighd.krendering.Colors) HorizontalAlignment(de.cau.cs.kieler.klighd.krendering.HorizontalAlignment) Table(com.google.common.collect.Table) KStyle(de.cau.cs.kieler.klighd.krendering.KStyle) KEdge(de.cau.cs.kieler.klighd.kgraph.KEdge) KPort(de.cau.cs.kieler.klighd.kgraph.KPort) KNode(de.cau.cs.kieler.klighd.kgraph.KNode) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle) KText(de.cau.cs.kieler.klighd.krendering.KText) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil)

Example 9 with KRectangle

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

the class LinguaFrancaShapeExtensions method addReactionFigure.

/**
 * Creates the visual representation of a reaction node
 */
public KPolygon addReactionFigure(KNode node, ReactionInstance reaction) {
    int minHeight = 22;
    int minWidth = 45;
    ReactorInstance reactor = reaction.getParent();
    _kNodeExtensions.setMinimalNodeSize(node, minWidth, minHeight);
    // Create base shape
    KPolygon baseShape = _kRenderingExtensions.addPolygon(node);
    associateWith(baseShape, reaction);
    _kRenderingExtensions.setLineWidth(baseShape, 1);
    _kRenderingExtensions.setForeground(baseShape, Colors.GRAY_45);
    _kRenderingExtensions.setBackground(baseShape, Colors.GRAY_65);
    _linguaFrancaStyleExtensions.boldLineSelectionStyle(baseShape);
    baseShape.getPoints().addAll(List.of(_kRenderingExtensions.createKPosition(LEFT, 0, 0, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, REACTION_POINTINESS, 0, TOP, 0, 0), _kRenderingExtensions.createKPosition(RIGHT, 0, 0, TOP, 0, 0.5f), _kRenderingExtensions.createKPosition(RIGHT, REACTION_POINTINESS, 0, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, 0, 0, BOTTOM, 0, 0), _kRenderingExtensions.createKPosition(LEFT, REACTION_POINTINESS, 0, BOTTOM, 0, 0.5f)));
    IterableExtensions.head(baseShape.getStyles()).setModifierId(ReactionPortAdjustment.ID);
    KRectangle contentContainer = _kContainerRenderingExtensions.addRectangle(baseShape);
    associateWith(contentContainer, reaction);
    _kRenderingExtensions.setInvisible(contentContainer, true);
    _kRenderingExtensions.<KRectangle>setPointPlacementData(contentContainer, _kRenderingExtensions.LEFT, REACTION_POINTINESS, 0, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.H_LEFT, _kRenderingExtensions.V_TOP, REACTION_POINTINESS, 0, minWidth - REACTION_POINTINESS * 2, minHeight);
    _kContainerRenderingExtensions.setGridPlacement(contentContainer, 1);
    if (reactor.reactions.size() > 1) {
        KText textToAdd = _kContainerRenderingExtensions.addText(contentContainer, Integer.toString(reactor.reactions.indexOf(reaction) + 1));
        _kRenderingExtensions.setFontBold(textToAdd, true);
        _linguaFrancaStyleExtensions.noSelectionStyle(textToAdd);
        DiagramSyntheses.suppressSelectability(textToAdd);
    }
    // optional reaction level
    if (getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_LEVEL)) {
        // then some reactions will have level -1.
        try {
            String levels = IterableExtensions.join(reaction.getLevels(), ", ");
            KText levelsText = _kContainerRenderingExtensions.addText(contentContainer, ("level: " + levels));
            _kRenderingExtensions.setFontBold(levelsText, false);
            _linguaFrancaStyleExtensions.noSelectionStyle(levelsText);
            DiagramSyntheses.suppressSelectability(levelsText);
        } catch (Exception ex) {
        // If the graph has cycles, the above fails. Continue without showing levels.
        }
    }
    // optional code content
    boolean hasCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && !StringExtensions.isNullOrEmpty(reaction.getDefinition().getCode().getBody());
    if (hasCode) {
        KText hasCodeText = _kContainerRenderingExtensions.addText(contentContainer, _utilityExtensions.trimCode(reaction.getDefinition().getCode()));
        associateWith(hasCodeText, reaction);
        _kRenderingExtensions.setFontSize(hasCodeText, 6);
        _kRenderingExtensions.setFontName(hasCodeText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME);
        _linguaFrancaStyleExtensions.noSelectionStyle(hasCodeText);
        _kRenderingExtensions.setHorizontalAlignment(hasCodeText, HorizontalAlignment.LEFT);
        _kRenderingExtensions.setVerticalAlignment(hasCodeText, VerticalAlignment.TOP);
        setGridPlacementDataFromPointToPoint(hasCodeText, _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 5, 0, _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 5, 0);
    }
    if (reaction.declaredDeadline != null) {
        boolean hasDeadlineCode = getBooleanValue(LinguaFrancaSynthesis.SHOW_REACTION_CODE) && !StringExtensions.isNullOrEmpty(reaction.getDefinition().getDeadline().getCode().getBody());
        if (hasCode || hasDeadlineCode) {
            KPolyline line = _kContainerRenderingExtensions.addHorizontalLine(contentContainer, 0);
            setGridPlacementDataFromPointToPoint(line, _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 3, 0, _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 6, 0);
        }
        // delay with stopwatch
        KRectangle labelContainer = _kContainerRenderingExtensions.addRectangle(contentContainer);
        _kRenderingExtensions.setInvisible(labelContainer, true);
        KRendering placement = setGridPlacementDataFromPointToPoint(labelContainer, _kRenderingExtensions.LEFT, hasDeadlineCode ? 0 : -REACTION_POINTINESS * 0.5f, 0, _kRenderingExtensions.TOP, 0, reactor.reactions.size() > 1 || hasCode || hasDeadlineCode ? 0 : 0.5f, _kRenderingExtensions.RIGHT, 0, 0, _kRenderingExtensions.BOTTOM, 0, 0);
        _kRenderingExtensions.setHorizontalAlignment(placement, HorizontalAlignment.LEFT);
        KRectangle stopWatchFigure = addStopwatchFigure(labelContainer);
        _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchFigure, 0, 0, 0, 0);
        KText stopWatchText = _kContainerRenderingExtensions.addText(labelContainer, reaction.declaredDeadline.maxDelay.toString());
        associateWith(stopWatchText, reaction.getDefinition().getDeadline().getDelay());
        _kRenderingExtensions.setForeground(stopWatchText, Colors.BROWN);
        _kRenderingExtensions.setFontBold(stopWatchText, true);
        _kRenderingExtensions.setFontSize(stopWatchText, 7);
        _linguaFrancaStyleExtensions.underlineSelectionStyle(stopWatchText);
        _kRenderingExtensions.setLeftTopAlignedPointPlacementData(stopWatchText, 15, 0, 0, 0);
        // optional code content
        if (hasDeadlineCode) {
            KText contentContainerText = _kContainerRenderingExtensions.addText(contentContainer, _utilityExtensions.trimCode(reaction.getDefinition().getDeadline().getCode()));
            associateWith(contentContainerText, reaction.deadline);
            _kRenderingExtensions.setForeground(contentContainerText, Colors.BROWN);
            _kRenderingExtensions.setFontSize(contentContainerText, 6);
            _kRenderingExtensions.setFontName(contentContainerText, KlighdConstants.DEFAULT_MONOSPACE_FONT_NAME);
            setGridPlacementDataFromPointToPoint(contentContainerText, _kRenderingExtensions.LEFT, 5, 0, _kRenderingExtensions.TOP, 0, 0, _kRenderingExtensions.RIGHT, 5, 0, _kRenderingExtensions.BOTTOM, 5, 0);
            _kRenderingExtensions.setHorizontalAlignment(contentContainerText, HorizontalAlignment.LEFT);
            _linguaFrancaStyleExtensions.noSelectionStyle(contentContainerText);
        }
    }
    return baseShape;
}
Also used : KPolygon(de.cau.cs.kieler.klighd.krendering.KPolygon) KText(de.cau.cs.kieler.klighd.krendering.KText) ReactorInstance(org.lflang.generator.ReactorInstance) KRendering(de.cau.cs.kieler.klighd.krendering.KRendering) KPolyline(de.cau.cs.kieler.klighd.krendering.KPolyline) KRectangle(de.cau.cs.kieler.klighd.krendering.KRectangle)

Example 10 with KRectangle

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

KRectangle (de.cau.cs.kieler.klighd.krendering.KRectangle)12 KText (de.cau.cs.kieler.klighd.krendering.KText)8 KPolyline (de.cau.cs.kieler.klighd.krendering.KPolyline)6 KRoundedRectangle (de.cau.cs.kieler.klighd.krendering.KRoundedRectangle)6 KEdge (de.cau.cs.kieler.klighd.kgraph.KEdge)5 KNode (de.cau.cs.kieler.klighd.kgraph.KNode)5 KContainerRendering (de.cau.cs.kieler.klighd.krendering.KContainerRendering)5 KRendering (de.cau.cs.kieler.klighd.krendering.KRendering)5 Pair (org.eclipse.xtext.xbase.lib.Pair)5 KPort (de.cau.cs.kieler.klighd.kgraph.KPort)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 Iterables (com.google.common.collect.Iterables)3 SynthesisOption (de.cau.cs.kieler.klighd.SynthesisOption)3 Colors (de.cau.cs.kieler.klighd.krendering.Colors)3 HorizontalAlignment (de.cau.cs.kieler.klighd.krendering.HorizontalAlignment)3 KEllipse (de.cau.cs.kieler.klighd.krendering.KEllipse)3