Search in sources :

Example 1 with Point

use of org.osate.ge.graphics.Point in project osate2 by osate.

the class DiagramElementLayoutUtil method findMidpoint.

private static Point findMidpoint(final List<Point> points) {
    if (points.size() < 2) {
        throw new IllegalArgumentException("At least two points must be specified");
    }
    final double totalLength = length(points);
    double lengthToTarget = totalLength / 2.0;
    for (int i = 1; i < points.size(); i++) {
        final Point p1 = points.get(i - 1);
        final Point p2 = points.get(i);
        final double segmentLength = length(p1, p2);
        if (lengthToTarget > segmentLength) {
            lengthToTarget -= segmentLength;
        } else {
            final double frac = lengthToTarget / segmentLength;
            return new Point(p1.x + (p2.x - p1.x) * frac, p1.y + (p2.y - p1.y) * frac);
        }
    }
    throw new GraphicalEditorException("Unexpected case: midpoint not found");
}
Also used : Point(org.osate.ge.graphics.Point) SizeConstraint(org.eclipse.elk.core.options.SizeConstraint) Point(org.osate.ge.graphics.Point) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Example 2 with Point

use of org.osate.ge.graphics.Point in project osate2 by osate.

the class DiagramElementLayoutUtil method setLabelPositionsForEdge.

/**
 * @param mapping
 * @param m
 * @param edge
 * @param edgeMidpoint must be relative to the edge's container
 */
private static void setLabelPositionsForEdge(final LayoutMapping mapping, DiagramModification m, final ElkEdge edge, final Point edgeMidpoint) {
    // Handle labels
    for (final ElkLabel edgeLabel : edge.getLabels()) {
        final Object labelValue = mapping.getGraphMap().get(edgeLabel);
        if (labelValue instanceof ConnectionLabelReference) {
            final ConnectionLabelReference labelRef = (ConnectionLabelReference) labelValue;
            if (Boolean.TRUE.equals(edgeLabel.getProperty(CoreOptions.NO_LAYOUT))) {
                labelRef.setPosition(m, null);
            } else {
                final double lx = edgeLabel.getX() - edgeMidpoint.x;
                final double ly = edgeLabel.getY() - edgeMidpoint.y;
                labelRef.setPosition(m, new Point(lx, ly));
            }
        }
    }
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel) Point(org.osate.ge.graphics.Point)

Example 3 with Point

use of org.osate.ge.graphics.Point 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 4 with Point

use of org.osate.ge.graphics.Point in project osate2 by osate.

the class DiagramElementLayoutUtil method layoutIncrementally.

/**
 * Performs layout on elements in the specified diagram which have not been laid out.
 * @param diagram the diagram for which to perform the incremental layout
 * @param mod the modification to use to modify the diagram
 * @param layoutInfoProvider the layout info provider which provides additional information required for laying out the diagram
 */
public static void layoutIncrementally(final AgeDiagram diagram, final DiagramModification mod, final LayoutInfoProvider layoutInfoProvider) {
    Objects.requireNonNull(diagram, "diagram must not be null");
    Objects.requireNonNull(mod, "mod must not be null");
    Objects.requireNonNull(layoutInfoProvider, "layoutInfoProvider must not be null");
    final IncrementalLayoutMode currentLayoutMode = LayoutPreferences.getCurrentIncrementalLayoutMode();
    // Get all the nodes that need to be layed out.
    final Set<DiagramNode> unfilteredNodesToLayout = getNodesToLayoutIncrementally(diagram, currentLayoutMode, new HashSet<>());
    if (unfilteredNodesToLayout.size() == 0) {
        return;
    }
    // Lay our flow indicators. In the container is eventually layed out, this will be replaced but in cases where that is not the case,
    // we provide a default layout. Flow indicators are connections and as such will be filtered in the next step.
    layoutFlowIndicators(mod, unfilteredNodesToLayout.stream().filter(DiagramNodePredicates::isFlowIndicator).map(DiagramElement.class::cast), layoutInfoProvider);
    final Collection<DiagramNode> nodesToLayout = DiagramElementLayoutUtil.filterUnnecessaryNodes(unfilteredNodesToLayout, currentLayoutMode == IncrementalLayoutMode.LAYOUT_DIAGRAM);
    if (nodesToLayout.size() == 0) {
        // If the filtered node list is empty then the unfiltered list still contain feature self loop connections that need to be layed out.
        unfilteredNodesToLayout.stream().filter(DiagramElementLayoutUtil::isFeatureSelfLoopConnection).map(DiagramElement.class::cast).forEachOrdered(de -> layoutFeatureSelfLoopConnection(de, mod, layoutInfoProvider));
        return;
    }
    final LayoutOptions layoutOptions = LayoutOptions.createFromPreferences();
    if (currentLayoutMode == IncrementalLayoutMode.LAYOUT_DIAGRAM) {
        layout(INCREMENTAL_LAYOUT_LABEL, diagram, layoutInfoProvider, layoutOptions);
    } else {
        layout(mod, nodesToLayout, new StyleCalculator(diagram.getConfiguration(), StyleProvider.EMPTY), layoutInfoProvider, layoutOptions);
        // Set Positions of elements which do not have a position set.
        for (final DiagramNode dn : nodesToLayout) {
            if (dn instanceof DiagramElement) {
                final DiagramElement de = (DiagramElement) dn;
                if (!de.hasPosition()) {
                    if (de.getDockArea() == null) {
                        mod.setPosition(de, new Point(0.0, 0.0));
                    } else if (de.getDockArea() != DockArea.GROUP && de.getParent() instanceof DiagramElement) {
                        final DiagramElement parent = (DiagramElement) de.getParent();
                        final DockingPosition defaultDockingPosition = de.getGraphicalConfiguration().getDefaultDockingPosition();
                        final DockArea defaultDockArea = DockArea.fromDockingPosition(defaultDockingPosition);
                        if (parent.hasSize()) {
                            final Stream<DiagramElement> otherElementsAlongSide = parent.getChildren().stream().filter(c -> c.hasPosition() && c.hasSize() && c.getDockArea() == defaultDockArea);
                            // Determine the position of the new element along it's preferred docking position.
                            double locationAlongSide;
                            if (defaultDockingPosition == DockingPosition.TOP || defaultDockingPosition == DockingPosition.BOTTOM) {
                                locationAlongSide = otherElementsAlongSide.max(Comparator.comparingDouble(c -> c.getY())).map(c -> c.getX() + c.getWidth()).orElse(0.0);
                            } else {
                                locationAlongSide = otherElementsAlongSide.max(Comparator.comparingDouble(c -> c.getY())).map(c -> c.getY() + c.getHeight()).orElse(0.0);
                            }
                            // Set position based on the docking position
                            switch(defaultDockingPosition) {
                                case TOP:
                                    mod.setPosition(de, new Point(locationAlongSide, 0));
                                    break;
                                case BOTTOM:
                                    mod.setPosition(de, new Point(locationAlongSide, parent.getHeight()));
                                    break;
                                case LEFT:
                                    mod.setPosition(de, new Point(0, locationAlongSide));
                                    break;
                                case RIGHT:
                                    mod.setPosition(de, new Point(parent.getWidth(), locationAlongSide));
                                    break;
                                default:
                                    break;
                            }
                        }
                        mod.setDockArea(de, defaultDockArea);
                    }
                }
            }
        }
    }
}
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) StyleCalculator(org.osate.ge.internal.diagram.runtime.styling.StyleCalculator) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Point(org.osate.ge.graphics.Point) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) DockArea(org.osate.ge.internal.diagram.runtime.DockArea) DockingPosition(org.osate.ge.DockingPosition) Stream(java.util.stream.Stream)

Example 5 with Point

use of org.osate.ge.graphics.Point in project osate2 by osate.

the class DiagramSerialization method convertElementToMetamodel.

private static void convertElementToMetamodel(final IProject project, final org.osate.ge.diagram.DiagramNode mmContainer, final DiagramElement e) {
    // Write BO Reference
    final org.osate.ge.diagram.DiagramElement newElement = new org.osate.ge.diagram.DiagramElement();
    mmContainer.getElement().add(newElement);
    newElement.setUuid(e.getId().toString());
    newElement.setBo(e.getRelativeReference().toMetamodel());
    // Store embedded business object data.
    if (e.getBusinessObject() instanceof EmbeddedBusinessObject) {
        final EmbeddedBusinessObject bo = (EmbeddedBusinessObject) e.getBusinessObject();
        newElement.setBoData(bo.getData());
    }
    newElement.setManual(true);
    if (e.hasPosition()) {
        newElement.setPosition(e.getPosition().toMetamodel());
    }
    if (e.hasSize() && DiagramElementPredicates.isResizeable(e)) {
        newElement.setSize(e.getSize().toMetamodel());
    }
    if (e.getDockArea() != null && e.getDockArea() != DockArea.GROUP) {
        // Don't serialize null or group dock areas
        newElement.setDockArea(e.getDockArea().id);
    }
    final Style currentStyle = e.getStyle();
    final org.osate.ge.graphics.Color backgroundColor = currentStyle.getBackgroundColor();
    if (backgroundColor != null) {
        newElement.setBackground(colorToHex(backgroundColor));
    }
    final IPath image = currentStyle.getImagePath();
    if (image != null) {
        // Get image path relative to the diagram's project
        final String portablePath = image.makeRelativeTo(project.getFullPath()).toPortableString();
        newElement.setImage(portablePath);
        newElement.setShowAsImage(currentStyle.getShowAsImage());
    }
    final org.osate.ge.graphics.Color fontColor = currentStyle.getFontColor();
    if (fontColor != null) {
        newElement.setFontColor(colorToHex(fontColor));
    }
    final org.osate.ge.graphics.Color outlineColor = currentStyle.getOutlineColor();
    if (outlineColor != null) {
        newElement.setOutline(colorToHex(outlineColor));
    }
    final Double fontSize = currentStyle.getFontSize();
    if (fontSize != null) {
        newElement.setFontSize(fontSize);
    }
    final Double lineWidth = currentStyle.getLineWidth();
    if (lineWidth != null) {
        newElement.setLineWidth(lineWidth);
    }
    if (currentStyle.getPrimaryLabelVisible() != null) {
        newElement.setPrimaryLabelVisible(currentStyle.getPrimaryLabelVisible());
    }
    // Connection Specific
    if (e.getBendpoints().size() > 0) {
        final org.osate.ge.diagram.BendpointList mmBendpoints = new org.osate.ge.diagram.BendpointList();
        newElement.setBendpoints(mmBendpoints);
        for (final Point bendpoint : e.getBendpoints()) {
            mmBendpoints.getPoint().add(bendpoint.toMetamodel());
        }
    }
    if (e.getConnectionPrimaryLabelPosition() != null) {
        newElement.setPrimaryLabelPosition(e.getConnectionPrimaryLabelPosition().toMetamodel());
    }
    convertElementsToMetamodel(project, newElement, e.getChildren());
}
Also used : Color(org.osate.ge.graphics.Color) IPath(org.eclipse.core.runtime.IPath) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) Point(org.osate.ge.graphics.Point) Style(org.osate.ge.graphics.Style)

Aggregations

Point (org.osate.ge.graphics.Point)27 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)19 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)9 AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)8 Dimension (org.osate.ge.graphics.Dimension)7 DockArea (org.osate.ge.internal.diagram.runtime.DockArea)7 List (java.util.List)5 ElkLabel (org.eclipse.elk.graph.ElkLabel)5 Style (org.osate.ge.graphics.Style)5 AgeShape (org.osate.ge.graphics.internal.AgeShape)5 GraphicalEditorException (org.osate.ge.internal.GraphicalEditorException)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)3 ImmutableList (com.google.common.collect.ImmutableList)3 Lists (com.google.common.collect.Lists)3 Comparator (java.util.Comparator)3