Search in sources :

Example 6 with ElkGraphElement

use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.

the class LayoutConfigurationManager method createConfigurator.

/**
 * Create a layout configurator and initialize it with the option values from the given layout
 * configuration store provider.
 */
public <T> LayoutConfigurator createConfigurator(final LayoutMapping layoutMapping) {
    LayoutConfigurator result = new LayoutConfigurator();
    if (configProvider != null) {
        configureElement(layoutMapping.getLayoutGraph(), layoutMapping, result);
        Iterator<ElkGraphElement> allElements = Iterators.filter(layoutMapping.getLayoutGraph().eAllContents(), ElkGraphElement.class);
        while (allElements.hasNext()) {
            ElkGraphElement element = allElements.next();
            configureElement(element, layoutMapping, result);
        }
    }
    return result;
}
Also used : ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator)

Example 7 with ElkGraphElement

use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.

the class DotExporter method transform.

/**
 * Transforms the KGraph instance to a Dot instance using the given command.
 *
 * @param transData the transformation data instance
 */
public void transform(final IDotTransformationData<ElkNode, GraphvizModel> transData) {
    BiMap<String, ElkGraphElement> graphElems = HashBiMap.create();
    transData.setProperty(GRAPH_ELEMS, graphElems);
    ElkNode elkgraph = transData.getSourceGraph();
    GraphvizModel graphvizModel = DotFactory.eINSTANCE.createGraphvizModel();
    Graph graph = DotFactory.eINSTANCE.createGraph();
    graph.setType(GraphType.DIGRAPH);
    graphvizModel.getGraphs().add(graph);
    transformNodes(elkgraph, graph.getStatements(), new KVector(), transData);
    transformEdges(elkgraph, graph.getStatements(), transData);
    transData.getTargetGraphs().add(graphvizModel);
}
Also used : GraphvizModel(org.eclipse.elk.alg.graphviz.dot.dot.GraphvizModel) Graph(org.eclipse.elk.alg.graphviz.dot.dot.Graph) ElkNode(org.eclipse.elk.graph.ElkNode) KVector(org.eclipse.elk.core.math.KVector) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement)

Example 8 with ElkGraphElement

use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.

the class ElkUtil method printElementPath.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// DEBUGGING
/**
 * Print information on the given graph element to the given string builder.
 */
public static void printElementPath(final ElkGraphElement element, final StringBuilder builder) {
    // Print the containing element
    if (element.eContainer() instanceof ElkGraphElement) {
        printElementPath((ElkGraphElement) element.eContainer(), builder);
        builder.append(" > ");
    } else {
        builder.append("Root ");
    }
    // Print the class name
    String className = element.eClass().getName();
    if (className.startsWith("Elk")) {
        // CHECKSTYLEOFF MagicNumber
        builder.append(className.substring(3));
    // CHECKSTYLEON MagicNumber
    } else {
        builder.append(className);
    }
    // Print the identifier if present
    String identifier = element.getIdentifier();
    if (!Strings.isNullOrEmpty(identifier)) {
        builder.append(' ').append(identifier);
        return;
    }
    // Print the label if present
    if (element instanceof ElkLabel) {
        String text = ((ElkLabel) element).getText();
        if (!Strings.isNullOrEmpty(text)) {
            builder.append(' ').append(text);
            return;
        }
    }
    for (ElkLabel label : element.getLabels()) {
        String text = label.getText();
        if (!Strings.isNullOrEmpty(text)) {
            builder.append(' ').append(text);
            return;
        }
    }
    // If it's an edge and no identifier nor label is present, print source and target
    if (element instanceof ElkEdge) {
        ElkEdge edge = (ElkEdge) element;
        if (edge.isConnected()) {
            builder.append(" (");
            ListIterator<ElkConnectableShape> sourceIter = edge.getSources().listIterator();
            while (sourceIter.hasNext()) {
                if (sourceIter.nextIndex() > 0) {
                    builder.append(", ");
                }
                printElementPath(sourceIter.next(), builder);
            }
            builder.append(" -> ");
            ListIterator<ElkConnectableShape> targetIter = edge.getTargets().listIterator();
            while (targetIter.hasNext()) {
                if (targetIter.nextIndex() > 0) {
                    builder.append(", ");
                }
                printElementPath(targetIter.next(), builder);
            }
            builder.append(")");
        }
    }
}
Also used : ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkConnectableShape(org.eclipse.elk.graph.ElkConnectableShape) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 9 with ElkGraphElement

use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.

the class GmfLayoutEditPolicy method addLabelLayout.

/**
 * Adds an edge label layout to the given command.
 *
 * @param command
 *            command to which the edge label layout shall be added
 * @param klabel
 *            label with layout data
 * @param labelEditPart
 *            edit part to which layout is applied
 * @param scale
 *            scale factor for coordinates
 */
private void addLabelLayout(final GmfLayoutCommand command, final ElkLabel klabel, final GraphicalEditPart labelEditPart, final double scale) {
    ElkGraphElement parent = klabel.getParent();
    // node and port labels are processed separately
    if (parent instanceof ElkNode || parent instanceof ElkPort) {
        View view = (View) labelEditPart.getModel();
        int xpos = (int) (klabel.getX() * scale);
        int ypos = (int) (klabel.getY() * scale);
        Object oldx = ViewUtil.getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X());
        Object oldy = ViewUtil.getStructuralFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y());
        if (oldx == null || oldy == null || xpos != (Integer) oldx || ypos != (Integer) oldy) {
            command.addShapeLayout(view, new Point(xpos, ypos), null);
        }
        return;
    } else if (parent instanceof ElkEdge) {
        // calculate direct new location of the label
        Rectangle targetBounds = new Rectangle(labelEditPart.getFigure().getBounds());
        targetBounds.x = (int) (klabel.getX() * scale);
        targetBounds.y = (int) (klabel.getY() * scale);
        ConnectionEditPart connectionEditPart = (ConnectionEditPart) labelEditPart.getParent();
        PointList bendPoints = getBendPoints((ElkEdge) parent, connectionEditPart.getFigure(), scale);
        EObject modelElement = connectionEditPart.getNotationView().getElement();
        EdgeLabelPlacement labelPlacement = klabel.getProperty(CoreOptions.EDGE_LABELS_PLACEMENT);
        // the list of bend points must be reversed
        if (modelElement instanceof EReference && labelPlacement == EdgeLabelPlacement.TAIL) {
            bendPoints = bendPoints.getCopy();
            bendPoints.reverse();
        }
        // get the referencePoint for the label
        int fromEnd, keyPoint = ConnectionLocator.MIDDLE;
        if (labelEditPart instanceof LabelEditPart) {
            keyPoint = ((LabelEditPart) labelEditPart).getKeyPoint();
        }
        switch(keyPoint) {
            case ConnectionLocator.SOURCE:
                fromEnd = SOURCE_LOCATION;
                break;
            case ConnectionLocator.TARGET:
                fromEnd = TARGET_LOCATION;
                break;
            default:
                fromEnd = MIDDLE_LOCATION;
                break;
        }
        Point refPoint = PointListUtilities.calculatePointRelativeToLine(bendPoints, 0, fromEnd, true);
        // get the new relative location
        Point normalPoint = offsetFromRelativeCoordinate(targetBounds, bendPoints, refPoint);
        if (normalPoint != null) {
            command.addShapeLayout((View) labelEditPart.getModel(), normalPoint, null);
        }
    }
}
Also used : PointList(org.eclipse.draw2d.geometry.PointList) LabelEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart) ConnectionEditPart(org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart) ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) View(org.eclipse.gmf.runtime.notation.View) Point(org.eclipse.draw2d.geometry.Point) PrecisionPoint(org.eclipse.draw2d.geometry.PrecisionPoint) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EdgeLabelPlacement(org.eclipse.elk.core.options.EdgeLabelPlacement) ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement) EReference(org.eclipse.emf.ecore.EReference) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 10 with ElkGraphElement

use of org.eclipse.elk.graph.ElkGraphElement in project elk by eclipse.

the class GraphIdentifierGenerator method assertAllIdsUnique.

// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Uniqueness
private GraphIdentifierGenerator assertAllIdsUnique(final EObject element) {
    Set<String> knownIds = Sets.newHashSet();
    Iterator<ElkGraphElement> elementIt = Iterators.filter(element.eAllContents(), ElkGraphElement.class);
    while (elementIt.hasNext()) {
        ElkGraphElement e = elementIt.next();
        while (knownIds.contains(e.getIdentifier())) {
            String newId = e.getIdentifier() + "_g" + fourDigitPaddedRandomNumber();
            e.setIdentifier(newId);
        }
        knownIds.add(e.getIdentifier());
    }
    return this;
}
Also used : ElkGraphElement(org.eclipse.elk.graph.ElkGraphElement)

Aggregations

ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)24 ElkNode (org.eclipse.elk.graph.ElkNode)17 ElkEdge (org.eclipse.elk.graph.ElkEdge)11 ElkLabel (org.eclipse.elk.graph.ElkLabel)10 ElkPort (org.eclipse.elk.graph.ElkPort)10 KVector (org.eclipse.elk.core.math.KVector)7 PortSide (org.eclipse.elk.core.options.PortSide)5 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)5 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)4 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)4 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)4 Collection (java.util.Collection)3 Collections (java.util.Collections)3 EnumSet (java.util.EnumSet)3 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Entry (java.util.Map.Entry)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3