Search in sources :

Example 1 with AgeShape

use of org.osate.ge.graphics.internal.AgeShape in project osate2 by osate.

the class DiagramElementLayoutUtil method getAbsolutePosition.

/**
 * Gets the absolute position of a node. This absolute position only considers the positions of shapes.
 * Connections are ignored.
 * @param dn the node for which to get the absolute position.
 * @return the absolute position.
 */
public static Point getAbsolutePosition(final DiagramNode dn) {
    int x = 0;
    int y = 0;
    for (DiagramNode tmp = dn; tmp instanceof DiagramElement; tmp = tmp.getParent()) {
        final DiagramElement tmpDe = (DiagramElement) tmp;
        if (tmpDe.getGraphic() instanceof AgeShape) {
            // Ignore connections in case the X and Y values are not 0.
            x += tmpDe.getX();
            y += tmpDe.getY();
        }
    }
    return new Point(x, y);
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) AgeShape(org.osate.ge.graphics.internal.AgeShape) Point(org.osate.ge.graphics.Point) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Point(org.osate.ge.graphics.Point)

Example 2 with AgeShape

use of org.osate.ge.graphics.internal.AgeShape in project osate2 by osate.

the class DiagramElementLayoutUtil method applyProperties.

/**
 * Sets the ELK properties of elements in the specified layout mapping based on the layout options.
 * @param layoutMapping
 */
private static void applyProperties(final DiagramNode rootDiagramNode, final LayoutMapping layoutMapping) {
    // Set the minimum node size based on the ports and their assigned sides.
    final IGraphElementVisitor minNodeSizeVisitor = element -> {
        if (element instanceof ElkNode) {
            final ElkNode n = (ElkNode) element;
            final double maxLabelWidth = n.getLabels().stream().mapToDouble(l -> l.getWidth()).max().orElse(0.0);
            final double labelHeightSum = n.getLabels().stream().mapToDouble(l -> l.getHeight()).sum();
            // Determine max width for ports on the left and right sides
            final double maxLeftPortWidth = n.getPorts().stream().filter(p -> p.getProperty(CoreOptions.PORT_SIDE) == PortSide.WEST).mapToDouble(p -> p.getWidth()).max().orElse(0.0);
            final double maxRightPortWidth = n.getPorts().stream().filter(p -> p.getProperty(CoreOptions.PORT_SIDE) == PortSide.EAST).mapToDouble(p -> p.getWidth()).max().orElse(0.0);
            final DiagramNode dn = (DiagramNode) layoutMapping.getGraphMap().get(n);
            double minWidth = 0;
            if (n.getProperty(CoreOptions.NODE_LABELS_PLACEMENT).contains(NodeLabelPlacement.H_CENTER)) {
                // Ensure the minimum width is such that the label can be centered without overlapping with ports.
                // This happens because ports are inside the node due to the PORT_BORDER_OFFSET and ELK centers the labels in the remaining space.
                final double widthForPorts = 2 * Math.max(maxLeftPortWidth, maxRightPortWidth);
                minWidth = Math.max(40, maxLabelWidth + widthForPorts + PORT_WIDTH_PADDING);
            } else {
                final double widthForPorts = maxLeftPortWidth + maxRightPortWidth + PORT_WIDTH_PADDING;
                minWidth = Math.max(40, Math.max(maxLabelWidth, widthForPorts));
            }
            double minHeight = Math.max(35, labelHeightSum);
            if (dn instanceof DiagramElement) {
                final DiagramElement de = ((DiagramElement) dn);
                // Special min height handling for initial modes
                final Graphic graphic = de.getGraphic();
                if (graphic instanceof AgeShape && !((AgeShape) graphic).isResizeable() && de.hasSize()) {
                    final Dimension dim = de.getSize();
                    minHeight = dim.height;
                    minWidth = dim.width;
                    // Adjust size constraints for fixed sized shapes which do not have contents.
                    if (n.getChildren().size() == 0 || n.getLabels().size() == 0 && n.getPorts().size() == 0) {
                        final EnumSet<SizeConstraint> nodeSizeConstraints = EnumSet.of(SizeConstraint.MINIMUM_SIZE);
                        n.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, nodeSizeConstraints);
                    }
                }
                if (graphic instanceof ModeGraphic && ((ModeGraphic) graphic).isInitialMode) {
                    minHeight += ModeGraphic.INITIAL_MODE_AREA_HEIGHT;
                }
                // Special min size handling for elements shown as image
                final Style style = de.getStyle();
                if (style != null && Boolean.TRUE.equals(style.getShowAsImage())) {
                    final Dimension dim = ((DiagramElement) dn).getSize();
                    minHeight = dim.height;
                    minWidth = dim.width;
                }
            }
            // Increase min width and min height for top level nodes.
            if (dn != null && dn.getParent() instanceof AgeDiagram) {
                minWidth = Math.max(minWidth, 200);
                minHeight = Math.max(minHeight, 100);
            }
            n.setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(minWidth, minHeight));
        }
    };
    ElkUtil.applyVisitors(layoutMapping.getLayoutGraph(), minNodeSizeVisitor);
    // If the top level element has a size set, don't shrink it.
    if (rootDiagramNode instanceof DiagramElement) {
        final DiagramElement rootDiagramElement = (DiagramElement) rootDiagramNode;
        final ElkGraphElement rootGraphElement = layoutMapping.getGraphMap().inverse().get(rootDiagramNode);
        if (rootGraphElement != null && rootDiagramElement.hasSize() && DiagramElementPredicates.isResizeable(rootDiagramElement)) {
            final KVector minSize = rootGraphElement.getProperty(CoreOptions.NODE_SIZE_MINIMUM);
            final double newMinWidth = Math.max(rootDiagramElement.getWidth(), minSize == null ? 0.0 : minSize.x);
            final double newMinHeight = Math.max(rootDiagramElement.getHeight(), minSize == null ? 0.0 : minSize.y);
            rootGraphElement.setProperty(CoreOptions.NODE_SIZE_MINIMUM, new KVector(newMinWidth, newMinHeight));
        }
    }
}
Also used : 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) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) ElkNode(org.eclipse.elk.graph.ElkNode) Graphic(org.osate.ge.graphics.Graphic) ModeGraphic(org.osate.ge.graphics.internal.ModeGraphic) EnumSet(java.util.EnumSet) ModeGraphic(org.osate.ge.graphics.internal.ModeGraphic) AgeShape(org.osate.ge.graphics.internal.AgeShape) Dimension(org.osate.ge.graphics.Dimension) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Style(org.osate.ge.graphics.Style) KVector(org.eclipse.elk.core.math.KVector) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) IGraphElementVisitor(org.eclipse.elk.core.util.IGraphElementVisitor)

Example 3 with AgeShape

use of org.osate.ge.graphics.internal.AgeShape in project osate2 by osate.

the class DiagramElementLayoutUtil method applyShapeLayout.

private static void applyShapeLayout(final LayoutMapping mapping, final DiagramModification m) {
    // Modify shapes
    for (Entry<ElkGraphElement, Object> e : mapping.getGraphMap().entrySet()) {
        final ElkGraphElement elkElement = e.getKey();
        final Object mappedValue = e.getValue();
        final boolean isTopLevelElement = isTopLevel(elkElement);
        if (!(elkElement instanceof ElkShape)) {
            continue;
        }
        final ElkShape elkShape = (ElkShape) elkElement;
        if (!(mappedValue instanceof DiagramElement)) {
            continue;
        }
        final DiagramElement de = (DiagramElement) mappedValue;
        if (!(de.getGraphic() instanceof AgeShape)) {
            continue;
        }
        if (de.getGraphic() instanceof Label) {
            continue;
        }
        // Set Position. Don't set the position of top level elements
        if (!isTopLevelElement && DiagramElementPredicates.isMoveableShape(de)) {
            // Determine position for the element
            double x = elkShape.getX();
            double y = elkShape.getY();
            // If the diagram element has a parent port, subtract the parent port position from the ELK port position to determine the relative position
            if (de.getDockArea() == DockArea.GROUP) {
                final ElkPort parentPort = (ElkPort) mapping.getGraphMap().inverse().get(de.getParent());
                if (parentPort != null) {
                    final PortSide side = parentPort.getProperty(CoreOptions.PORT_SIDE);
                    if (PortSide.SIDES_NORTH_SOUTH.contains(side)) {
                        x = elkShape.getX() - parentPort.getX();
                    } else if (PortSide.SIDES_EAST_WEST.contains(side)) {
                        y = elkShape.getY() - parentPort.getY();
                    } else {
                        throw new GraphicalEditorException("Unexpected side: " + side);
                    }
                }
            }
            DiagramElementLayoutUtil.moveElement(m, de, new Point(x, y));
            // Set the dock area
            if (de.getDockArea() != DockArea.GROUP && de.getDockArea() != null) {
                final DockArea newDockArea = PortSideUtil.getDockArea(elkShape.getProperty(CoreOptions.PORT_SIDE));
                if (newDockArea != null) {
                    m.setDockArea(de, newDockArea);
                }
            }
        }
        // Set the size
        if (DiagramElementPredicates.isResizeable(de)) {
            m.setSize(de, new Dimension(elkShape.getWidth(), elkShape.getHeight()));
        }
    }
}
Also used : ElkPort(org.eclipse.elk.graph.ElkPort) AgeShape(org.osate.ge.graphics.internal.AgeShape) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.osate.ge.graphics.internal.Label) Point(org.osate.ge.graphics.Point) Dimension(org.osate.ge.graphics.Dimension) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) ElkShape(org.eclipse.elk.graph.ElkShape) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) PortSide(org.eclipse.elk.core.options.PortSide) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Example 4 with AgeShape

use of org.osate.ge.graphics.internal.AgeShape in project osate2 by osate.

the class ElkGraphBuilder method addPositionOffsets.

/**
 * Adds position offset along axis for the specified port, graphic port, and children
 * @param de
 * @param offset
 * @param side
 * @param mapping
 */
private void addPositionOffsets(final DiagramElement de, final double offset, final PortSide side, final LayoutMapping mapping) {
    final ElkPort childPort = (ElkPort) mapping.getGraphMap().inverse().get(de);
    final double newPosition = addPositionOffset(childPort, side, offset);
    // Only attempt to update child ports if nested ports are not being omitted.
    if (!omitNestedPorts) {
        de.getChildren().stream().filter(child -> child.getGraphic() instanceof AgeShape && !(child.getGraphic() instanceof Label) && child.getDockArea() != null).forEach(childDiagramElement -> addPositionOffsets(childDiagramElement, newPosition, side, mapping));
    }
}
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) ElkPort(org.eclipse.elk.graph.ElkPort) AgeShape(org.osate.ge.graphics.internal.AgeShape) ElkLabel(org.eclipse.elk.graph.ElkLabel) Label(org.osate.ge.graphics.internal.Label)

Example 5 with AgeShape

use of org.osate.ge.graphics.internal.AgeShape in project osate2 by osate.

the class DiagramElementPredicates method isMoveableShape.

/**
 * Returns true if the specified diagram element is a shape that can be moved. This includes regular shapes and secondary labels for
 * connections and flow indicators.
 * @param de the diagram element to check
 * @return true if the specified diagram element is a shape that can be moved.
 */
public static boolean isMoveableShape(final DiagramElement de) {
    final Graphic graphic = de.getGraphic();
    final boolean shapeSecondaryLabel = graphic instanceof Label && de.getParent() instanceof DiagramElement && ((DiagramElement) de.getParent()).getGraphic() instanceof AgeShape;
    return graphic instanceof AgeShape && !shapeSecondaryLabel;
}
Also used : Graphic(org.osate.ge.graphics.Graphic) Label(org.osate.ge.graphics.internal.Label) AgeShape(org.osate.ge.graphics.internal.AgeShape)

Aggregations

AgeShape (org.osate.ge.graphics.internal.AgeShape)5 Label (org.osate.ge.graphics.internal.Label)4 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)4 PortSide (org.eclipse.elk.core.options.PortSide)3 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)3 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)3 ElkLabel (org.eclipse.elk.graph.ElkLabel)3 ElkPort (org.eclipse.elk.graph.ElkPort)3 Dimension (org.osate.ge.graphics.Dimension)3 Point (org.osate.ge.graphics.Point)3 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)3 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 EnumSet (java.util.EnumSet)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2