Search in sources :

Example 1 with SlidableAnchor

use of org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor in project elk by eclipse.

the class GmfLayoutEditPolicy method addEdgeLayout.

/**
 * Adds an edge layout to the given command.
 *
 * @param command
 *            command to which an edge layout shall be added
 * @param elkEdge
 *            edge with layout data
 * @param connectionEditPart
 *            edit part to which layout is applied
 * @param scale
 *            scale factor for coordinates
 */
private void addEdgeLayout(final GmfLayoutCommand command, final ElkEdge elkEdge, final ConnectionEditPart connectionEditPart, final double scale) {
    if (connectionEditPart.getSource() != null && connectionEditPart.getTarget() != null) {
        // create source terminal identifier
        INodeEditPart sourceEditPart = (INodeEditPart) connectionEditPart.getSource();
        ConnectionAnchor sourceAnchor;
        if (sourceEditPart instanceof ConnectionEditPart) {
            // if the edge source is a connection, don't consider the source point
            sourceAnchor = new SlidableAnchor(sourceEditPart.getFigure());
        } else {
            KVector sourceRel = getRelativeSourcePoint(elkEdge);
            sourceAnchor = new SlidableAnchor(sourceEditPart.getFigure(), new PrecisionPoint(sourceRel.x, sourceRel.y));
        }
        String sourceTerminal = sourceEditPart.mapConnectionAnchorToTerminal(sourceAnchor);
        // create target terminal identifier
        INodeEditPart targetEditPart = (INodeEditPart) connectionEditPart.getTarget();
        ConnectionAnchor targetAnchor;
        if (targetEditPart instanceof ConnectionEditPart) {
            // if the edge target is a connection, don't consider the target point
            targetAnchor = new SlidableAnchor(targetEditPart.getFigure());
        } else {
            KVector targetRel = getRelativeTargetPoint(elkEdge);
            targetAnchor = new SlidableAnchor(targetEditPart.getFigure(), new PrecisionPoint(targetRel.x, targetRel.y));
        }
        String targetTerminal = targetEditPart.mapConnectionAnchorToTerminal(targetAnchor);
        PointList bendPoints = getBendPoints(elkEdge, connectionEditPart.getFigure(), scale);
        // check whether the connection is a note attachment to an edge, then remove bend points
        if (sourceEditPart instanceof ConnectionEditPart || targetEditPart instanceof ConnectionEditPart) {
            while (bendPoints.size() > 2) {
                bendPoints.removePoint(1);
            }
        }
        // retrieve junction points and transform them to absolute coordinates
        KVectorChain junctionPoints = elkEdge.getProperty(CoreOptions.JUNCTION_POINTS);
        String serializedJP = null;
        if (junctionPoints != null) {
            for (KVector point : junctionPoints) {
                ElkUtil.toAbsolute(point, elkEdge.getContainingNode());
            }
            serializedJP = junctionPoints.toString();
        }
        command.addEdgeLayout((Edge) connectionEditPart.getModel(), bendPoints, sourceTerminal, targetTerminal, serializedJP);
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) ConnectionAnchor(org.eclipse.draw2d.ConnectionAnchor) ConnectionEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) INodeEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart) KVectorChain(org.eclipse.elk.core.math.KVectorChain) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) KVector(org.eclipse.elk.core.math.KVector) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Example 2 with SlidableAnchor

use of org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor in project statecharts by Yakindu.

the class AdjustIdentityAnchorCommand method handleEdge.

private void handleEdge(Edge edge, EditPart editPart, boolean sourceAnchor) {
    Anchor anchorToModify;
    if (sourceAnchor) {
        anchorToModify = edge.getSourceAnchor();
    } else {
        anchorToModify = edge.getTargetAnchor();
    }
    String terminalString = composeTerminalString(DEFAULT_POINT);
    if (anchorToModify instanceof IdentityAnchor) {
        terminalString = ((IdentityAnchor) anchorToModify).getId();
    }
    PrecisionPoint anchorPoint = BaseSlidableAnchor.parseTerminalString(terminalString);
    PrecisionPoint newPoint = computeNewAnchor(anchorPoint, editPart);
    String newTerminalString = new SlidableAnchor(null, newPoint).getTerminal();
    if (anchorToModify instanceof IdentityAnchor) {
        ((IdentityAnchor) anchorToModify).setId(newTerminalString);
    } else if (anchorToModify == null) {
        // Create a new one
        IdentityAnchor newAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
        newAnchor.setId(newTerminalString);
        if (sourceAnchor) {
            edge.setSourceAnchor(newAnchor);
        } else {
            edge.setTargetAnchor(newAnchor);
        }
    }
}
Also used : IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) IdentityAnchor(org.eclipse.gmf.runtime.notation.IdentityAnchor) Anchor(org.eclipse.gmf.runtime.notation.Anchor) BaseSlidableAnchor(org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor) SlidableAnchor(org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor) BaseSlidableAnchor(org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint)

Aggregations

PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)2 SlidableAnchor (org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor)2 ConnectionAnchor (org.eclipse.draw2d.ConnectionAnchor)1 PointList (org.eclipse.draw2d.geometry.PointList)1 KVector (org.eclipse.elk.core.math.KVector)1 KVectorChain (org.eclipse.elk.core.math.KVectorChain)1 ConnectionEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart)1 INodeEditPart (org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart)1 BaseSlidableAnchor (org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor)1 Anchor (org.eclipse.gmf.runtime.notation.Anchor)1 IdentityAnchor (org.eclipse.gmf.runtime.notation.IdentityAnchor)1