Search in sources :

Example 11 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement in project osate2 by osate.

the class DiagramElementLayoutUtil method getConnectionsAffectedByMove.

/**
 * Returns the connections which are affected by moving the specified elements
 * @param movedElement is the element which to get the affected connections
 * @param diagram is the diagram which contains the connections.
 * @param checkDescendants whether to check descendants of the specified elements when looking for connections
 * @return he connections which are affected by moving the specified elements
 */
public static Stream<DiagramElement> getConnectionsAffectedByMove(final DiagramElement movedElement, final AgeDiagram diagram, final boolean checkDescendants) {
    // Build a set containing the moved elements and all of their descendant which are represented as shapes
    final Set<BusinessObjectContext> diagramElements = checkDescendants ? movedElement.getAllDescendants().collect(Collectors.toSet()) : Collections.singleton(movedElement);
    final Stream<DiagramElement> connections = diagram.getAllDiagramNodes().filter(q -> q instanceof DiagramElement && DiagramElementPredicates.isConnection((DiagramElement) q)).map(DiagramElement.class::cast);
    // Iterate over all the connections in the diagram and update their bendpoints if their ends are in the set above.
    return connections.filter(c -> {
        final DiagramElement startElement = c.getStartElement();
        final DiagramElement endElement = c.getEndElement();
        final boolean isFlowIndicator = ((AgeConnection) c.getGraphic()).isFlowIndicator;
        return diagramElements.contains(startElement) && (diagramElements.contains(endElement) || isFlowIndicator);
    });
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) CoreOptions(org.eclipse.elk.core.options.CoreOptions) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) PortSide(org.eclipse.elk.core.options.PortSide) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor) RecursiveGraphLayoutEngine(org.eclipse.elk.core.RecursiveGraphLayoutEngine) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) IStatus(org.eclipse.core.runtime.IStatus) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Graphic(org.osate.ge.graphics.Graphic) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) StatusManager(org.eclipse.ui.statushandlers.StatusManager) IEditorPart(org.eclipse.ui.IEditorPart) EnumSet(java.util.EnumSet) Collection(java.util.Collection) Set(java.util.Set) Status(org.eclipse.core.runtime.Status) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Point(org.osate.ge.graphics.Point) Collectors(java.util.stream.Collectors) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Dimension(org.osate.ge.graphics.Dimension) ElkGraphPackage(org.eclipse.elk.graph.ElkGraphPackage) ModeGraphic(org.osate.ge.graphics.internal.ModeGraphic) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) HashSet(java.util.HashSet) ElkUtil(org.eclipse.elk.core.util.ElkUtil) Style(org.osate.ge.graphics.Style) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) AgeShape(org.osate.ge.graphics.internal.AgeShape) LinkedList(java.util.LinkedList) Activator(org.osate.ge.internal.Activator) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) ElkLabel(org.eclipse.elk.graph.ElkLabel) KVector(org.eclipse.elk.core.math.KVector) Label(org.osate.ge.graphics.internal.Label) BasicProgressMonitor(org.eclipse.elk.core.util.BasicProgressMonitor) ElkShape(org.eclipse.elk.graph.ElkShape) Adapters(org.eclipse.core.runtime.Adapters) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeDiagramUtil(org.osate.ge.internal.diagram.runtime.AgeDiagramUtil) Comparator(java.util.Comparator) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) StyleCalculator(org.osate.ge.internal.diagram.runtime.styling.StyleCalculator) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 12 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement in project osate2 by osate.

the class ElkGraphBuilder method buildLayoutGraph.

private LayoutMapping buildLayoutGraph(final DiagramNode rootDiagramNode) {
    // Create the graph
    final LayoutMapping mapping = new LayoutMapping(null);
    final ElkNode rootNode = ElkGraphUtil.createGraph();
    rootNode.setProperty(CoreOptions.DIRECTION, Direction.RIGHT);
    mapping.setLayoutGraph(rootNode);
    // As of 2020-04-06, INCLUDE_CHILDREN causes layout issues. In particular, labels can overlap with children
    // https://github.com/eclipse/elk/issues/316
    // https://github.com/eclipse/elk/issues/412
    rootNode.setProperty(CoreOptions.HIERARCHY_HANDLING, HierarchyHandling.SEPARATE_CHILDREN);
    if (rootDiagramNode instanceof AgeDiagram) {
        final ElkNode diagramElkNode = ElkGraphUtil.createNode(rootNode);
        mapping.getGraphMap().put(diagramElkNode, rootDiagramNode);
        createElkGraphElementsForNonLabelChildShapes(rootDiagramNode, diagramElkNode, mapping);
    } else if (rootDiagramNode instanceof DiagramElement) {
        createElkGraphElementsForElements(Collections.singleton((DiagramElement) rootDiagramNode), rootNode, mapping);
    }
    createElkGraphElementsForConnections(rootDiagramNode, mapping);
    return mapping;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ElkNode(org.eclipse.elk.graph.ElkNode) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping)

Example 13 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement in project osate2 by osate.

the class ElkGraphBuilder method createElkLabels.

private void createElkLabels(final DiagramElement parentElement, final ElkGraphElement parentLayoutElement, final LayoutMapping mapping) {
    // Don't create labels for ElkPort. The bounds of the port contain their labels.
    if (parentLayoutElement instanceof ElkPort) {
        return;
    }
    final boolean isConnection = parentElement.getGraphic() instanceof AgeConnection;
    final Style style = styleProvider.getStyle(parentElement);
    if (style.getPrimaryLabelVisible()) {
        // Create Primary Label
        if (parentElement.getLabelName() != null) {
            final ElkLabel elkLabel = createElkLabel(parentLayoutElement, parentElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(parentElement));
            if (isConnection) {
                if (!layoutConnectionLabels) {
                    elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
                }
                mapping.getGraphMap().put(elkLabel, new PrimaryConnectionLabelReference(parentElement));
            }
        }
    }
    // Create label for annotations which are part of the graphic configuration. These are only supported by non-connections.
    if (!isConnection && parentElement.getGraphicalConfiguration().getAnnotation() != null) {
        createElkLabel(parentLayoutElement, parentElement.getGraphicalConfiguration().getAnnotation(), layoutInfoProvider.getAnnotationLabelSize(parentElement));
    }
    // Create Secondary Labels
    parentElement.getChildren().stream().filter(c -> c.getGraphic() instanceof Label).forEachOrdered(labelElement -> {
        final ElkLabel elkLabel = createElkLabel(parentLayoutElement, labelElement.getLabelName(), layoutInfoProvider.getPrimaryLabelSize(labelElement));
        if (isConnection) {
            if (!layoutConnectionLabels) {
                elkLabel.setProperty(CoreOptions.NO_LAYOUT, true);
            }
            mapping.getGraphMap().put(elkLabel, new SecondaryConnectionLabelReference(labelElement));
        }
    });
    if (parentLayoutElement instanceof ElkNode) {
        parentLayoutElement.setProperty(CoreOptions.NODE_LABELS_PLACEMENT, getNodeLabelPlacement(style));
    }
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) PortSide(org.eclipse.elk.core.options.PortSide) Dimension(org.osate.ge.graphics.Dimension) HashMap(java.util.HashMap) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) ArrayList(java.util.ArrayList) Style(org.osate.ge.graphics.Style) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Map(java.util.Map) AgeShape(org.osate.ge.graphics.internal.AgeShape) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) HierarchyHandling(org.eclipse.elk.core.options.HierarchyHandling) EnumSet(java.util.EnumSet) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) Predicate(java.util.function.Predicate) KVector(org.eclipse.elk.core.math.KVector) Collection(java.util.Collection) Label(org.osate.ge.graphics.internal.Label) SizeOptions(org.eclipse.elk.core.options.SizeOptions) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Collectors(java.util.stream.Collectors) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) Direction(org.eclipse.elk.core.options.Direction) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.osate.ge.graphics.internal.Label) Style(org.osate.ge.graphics.Style)

Example 14 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement in project osate2 by osate.

the class ElkGraphBuilder method createElkPortsForElements.

/**
 * Before calling this method, all labels for the parent node should have already been created and the node labels placement property must be set for the parent.
 * @param elements
 * @param parent
 * @param mapping
 */
private void createElkPortsForElements(final Collection<DiagramElement> elements, final ElkNode parent, final LayoutMapping mapping) {
    final EnumSet<NodeLabelPlacement> nodeLabelPlacement = parent.getProperty(CoreOptions.NODE_LABELS_PLACEMENT);
    final boolean labelsAtTop = nodeLabelPlacement != null && nodeLabelPlacement.contains(NodeLabelPlacement.V_TOP);
    final double topPadding = labelsAtTop ? parent.getLabels().stream().mapToDouble(l -> l.getY() + l.getHeight()).sum() : 0.0;
    // Group children by the port side to which they should be assigned.
    final List<DiagramElement> dockedShapes = elements.stream().filter(dockedShapeFilter).collect(Collectors.toList());
    final boolean diagramElementIncludesNestedPorts = dockedShapes.stream().flatMap(de -> de.getChildren().stream()).anyMatch(dockedShapeFilter);
    // Set the flag to indicate that there are nested ports which will not be included in the final layout graph
    if (omitNestedPorts && diagramElementIncludesNestedPorts) {
        mapping.getLayoutGraph().setProperty(AgeLayoutOptions.NESTED_PORTS_WERE_OMITTED, true);
    }
    // Set port constraints and graph hierarchy handling of the parent based on whether the diagram element actually has nested ports.
    final boolean hasNestedPorts = !omitNestedPorts && diagramElementIncludesNestedPorts;
    PortConstraints portConstraints;
    if (dockedShapes.size() == 0) {
        // Don't constrain ports if there aren't any. As of 2017-10-11, some other values can affect the layout even if the node does not contain ports.
        portConstraints = PortConstraints.FREE;
    } else {
        if (hasNestedPorts || options.layoutPortsOnDefaultSides) {
            portConstraints = PortConstraints.FIXED_POS;
        } else {
            portConstraints = PortConstraints.FREE;
        }
    }
    parent.setProperty(CoreOptions.PORT_CONSTRAINTS, portConstraints);
    final Map<PortSide, List<DiagramElement>> groupedDockedElements = dockedShapes.stream().collect(Collectors.groupingBy(de -> getPortSide(de, hasNestedPorts), HashMap::new, Collectors.toCollection(ArrayList::new)));
    // Determine padding
    // Need to pad both left and right sides equally if ELK is determining the side of ports. Otherwise, the space for the
    // port may overlap with shapes. This is likely caused by adjusting the border offset of ports
    // to lay out ports within the bounds of the containing shape
    final boolean padOppositeSides = !portConstraints.isSideFixed();
    final ElkPadding parentPadding = new ElkPadding(parent.getParent() == null || parent.getParent().getParent() == null ? 0.0 : portAndContentsPadding);
    for (final Entry<PortSide, List<DiagramElement>> entry : groupedDockedElements.entrySet()) {
        final PortSide side = entry.getKey();
        double maxSize = 0;
        for (final DiagramElement de : entry.getValue()) {
            maxSize = Math.max(maxSize, getOrthogonalSize(de, side));
        }
        // Update padding for the side
        final double sidePadding = maxSize + portAndContentsPadding;
        switch(side) {
            case NORTH:
                parentPadding.top = Math.max(parentPadding.top, sidePadding);
                break;
            case SOUTH:
                parentPadding.bottom = Math.max(parentPadding.bottom, sidePadding);
                break;
            case EAST:
                parentPadding.right = Math.max(parentPadding.right, sidePadding);
                if (padOppositeSides) {
                    parentPadding.left = Math.max(parentPadding.left, sidePadding);
                }
                break;
            case WEST:
                parentPadding.left = Math.max(parentPadding.left, sidePadding);
                if (padOppositeSides) {
                    parentPadding.right = Math.max(parentPadding.right, sidePadding);
                }
                break;
            default:
                // Ignore
                break;
        }
    }
    // Create and position the ports
    for (final Entry<PortSide, List<DiagramElement>> portSideToElementsEntry : groupedDockedElements.entrySet()) {
        final PortSide side = portSideToElementsEntry.getKey();
        final double additionalPadding;
        if (PortSide.SIDES_NORTH_SOUTH.contains(side)) {
            additionalPadding = Math.max(parentPadding.left, parentPadding.right);
        } else {
            additionalPadding = topPadding;
        }
        createAndPositionPorts(parent, portSideToElementsEntry.getValue(), portSideToElementsEntry.getKey(), additionalPadding, mapping, hasNestedPorts);
    }
    // Set the padding
    parent.setProperty(CoreOptions.PADDING, parentPadding);
}
Also used : CoreOptions(org.eclipse.elk.core.options.CoreOptions) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) PortSide(org.eclipse.elk.core.options.PortSide) Dimension(org.osate.ge.graphics.Dimension) HashMap(java.util.HashMap) LayoutMapping(org.eclipse.elk.core.service.LayoutMapping) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) ArrayList(java.util.ArrayList) Style(org.osate.ge.graphics.Style) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) ElkPadding(org.eclipse.elk.core.math.ElkPadding) Map(java.util.Map) AgeShape(org.osate.ge.graphics.internal.AgeShape) DiagramElementPredicates(org.osate.ge.internal.diagram.runtime.DiagramElementPredicates) HierarchyHandling(org.eclipse.elk.core.options.HierarchyHandling) EnumSet(java.util.EnumSet) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkLabel(org.eclipse.elk.graph.ElkLabel) Predicate(java.util.function.Predicate) KVector(org.eclipse.elk.core.math.KVector) Collection(java.util.Collection) Label(org.osate.ge.graphics.internal.Label) SizeOptions(org.eclipse.elk.core.options.SizeOptions) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Collectors(java.util.stream.Collectors) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) DockingPosition(org.osate.ge.DockingPosition) Objects(java.util.Objects) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) List(java.util.List) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) Direction(org.eclipse.elk.core.options.Direction) Entry(java.util.Map.Entry) Optional(java.util.Optional) ElkEdge(org.eclipse.elk.graph.ElkEdge) AgeConnection(org.osate.ge.graphics.internal.AgeConnection) ElkGraphUtil(org.eclipse.elk.graph.util.ElkGraphUtil) StyleProvider(org.osate.ge.internal.diagram.runtime.styling.StyleProvider) Collections(java.util.Collections) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ArrayList(java.util.ArrayList) PortConstraints(org.eclipse.elk.core.options.PortConstraints) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) NodeLabelPlacement(org.eclipse.elk.core.options.NodeLabelPlacement) ArrayList(java.util.ArrayList) List(java.util.List) PortSide(org.eclipse.elk.core.options.PortSide) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 15 with DiagramElement

use of org.osate.ge.internal.diagram.runtime.DiagramElement in project osate2 by osate.

the class SelectionPropertyTester method test.

@Override
public boolean test(final Object receiver, final String property, final Object[] args, final Object expectedValue) {
    final ISelection selection = (ISelection) receiver;
    if (property.equals("allAreDiagramElementsWithSameParent")) {
        return DiagramElementUtil.allHaveSameParent(SelectionUtil.getSelectedDiagramElements(selection, false));
    } else if (property.equals("singleNamedElementInComponentImplementation")) {
        // Returns false if there is more than one element or if the element is not
        // a descendant of a component implementation or if the diagram element's BO is not a named element.
        final List<DiagramElement> diagramElements = SelectionUtil.getSelectedDiagramElements(selection, false);
        return diagramElements.size() == 1 && ToolUtil.findComponentImplementationBoc(diagramElements.get(0)) != null;
    } else if (property.contentEquals("namedElementsInSameComponentImplementation")) {
        // Returns false if all selected elements are not descendants of the
        // same component implementation or if any diagram element's BO is not a named element.
        final List<DiagramElement> diagramElements = SelectionUtil.getSelectedDiagramElements(selection, false);
        // Get component implementation ancestor for each named element
        final List<BusinessObjectContext> ciBocs = diagramElements.stream().map(de -> ToolUtil.findComponentImplementationBoc(de)).collect(Collectors.toList());
        // Require at least one component implement BOC and the first must be non-null.
        if (ciBocs.size() == 0 || ciBocs.get(0) == null) {
            return false;
        }
        // Require all component implementation BOCs to be equal
        final BusinessObjectContext firstBoc = ciBocs.get(0);
        return ciBocs.stream().allMatch(tmpBoc -> tmpBoc == firstBoc);
    }
    return false;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) List(java.util.List) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) BusinessObjectContext(org.osate.ge.BusinessObjectContext) PropertyTester(org.eclipse.core.expressions.PropertyTester) SelectionUtil(org.osate.ge.internal.ui.util.SelectionUtil) ISelection(org.eclipse.jface.viewers.ISelection) Collectors(java.util.stream.Collectors) ToolUtil(org.osate.ge.internal.ui.tools.ToolUtil) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)131 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)45 List (java.util.List)31 Point (org.osate.ge.graphics.Point)29 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)29 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)26 Objects (java.util.Objects)25 IEditorPart (org.eclipse.ui.IEditorPart)23 ArrayList (java.util.ArrayList)22 Collectors (java.util.stream.Collectors)22 BusinessObjectContext (org.osate.ge.BusinessObjectContext)21 Collection (java.util.Collection)19 Collections (java.util.Collections)18 Dimension (org.osate.ge.graphics.Dimension)18 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)18 Optional (java.util.Optional)16 AgeConnection (org.osate.ge.graphics.internal.AgeConnection)16 DiagramElementUtil (org.osate.ge.internal.util.DiagramElementUtil)16 ElkPort (org.eclipse.elk.graph.ElkPort)14 Node (javafx.scene.Node)13