Search in sources :

Example 96 with ElkNode

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

the class AbstractElkGraphSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ElkGraphPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ElkGraphPackage.ELK_BEND_POINT:
                sequence_ElkBendPoint(context, (ElkBendPoint) semanticObject);
                return;
            case ElkGraphPackage.ELK_EDGE:
                sequence_EdgeLayout_ElkEdge(context, (ElkEdge) semanticObject);
                return;
            case ElkGraphPackage.ELK_EDGE_SECTION:
                if (rule == grammarAccess.getElkEdgeSectionRule()) {
                    sequence_ElkEdgeSection(context, (ElkEdgeSection) semanticObject);
                    return;
                } else if (rule == grammarAccess.getElkSingleEdgeSectionRule()) {
                    sequence_ElkSingleEdgeSection(context, (ElkEdgeSection) semanticObject);
                    return;
                } else
                    break;
            case ElkGraphPackage.ELK_LABEL:
                sequence_ElkLabel_ShapeLayout(context, (ElkLabel) semanticObject);
                return;
            case ElkGraphPackage.ELK_NODE:
                if (rule == grammarAccess.getElkNodeRule()) {
                    sequence_ElkNode_ShapeLayout(context, (ElkNode) semanticObject);
                    return;
                } else if (rule == grammarAccess.getRootNodeRule()) {
                    sequence_RootNode_ShapeLayout(context, (ElkNode) semanticObject);
                    return;
                } else
                    break;
            case ElkGraphPackage.ELK_PORT:
                sequence_ElkPort_ShapeLayout(context, (ElkPort) semanticObject);
                return;
            case ElkGraphPackage.ELK_PROPERTY_TO_VALUE_MAP_ENTRY:
                sequence_Property(context, (Map.Entry) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPort(org.eclipse.elk.graph.ElkPort) Parameter(org.eclipse.xtext.Parameter) ElkBendPoint(org.eclipse.elk.graph.ElkBendPoint) ElkEdgeSection(org.eclipse.elk.graph.ElkEdgeSection) EPackage(org.eclipse.emf.ecore.EPackage) ElkEdge(org.eclipse.elk.graph.ElkEdge)

Example 97 with ElkNode

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

the class BasicCycleBreakerTest method interactiveConfigurator.

@Configurator
public void interactiveConfigurator(final ElkNode elkGraph) {
    // This is a bit more involved. We not only have to set the proper cycle breaking strategy, but we also
    // have to assign bogus coordinates to the nodes
    Deque<ElkNode> nodeQueue = new LinkedList<>();
    nodeQueue.add(elkGraph);
    // Fixed seed to keep tests repeatable
    Random rand = new Random(INTERACTIVE_RANDOM_SEED);
    while (!nodeQueue.isEmpty()) {
        ElkNode node = nodeQueue.poll();
        nodeQueue.addAll(node.getChildren());
        node.setProperty(LayeredOptions.CYCLE_BREAKING_STRATEGY, CycleBreakingStrategy.INTERACTIVE);
        if (node.getX() == 0) {
            node.setX(rand.nextInt(INTERACTIVE_MAX_POS));
        }
        if (node.getY() == 0) {
            node.setY(rand.nextInt(INTERACTIVE_MAX_POS));
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) Random(java.util.Random) LinkedList(java.util.LinkedList) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) Configurator(org.eclipse.elk.alg.test.framework.annotations.Configurator)

Example 98 with ElkNode

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

the class BasicLayerAssignmentTest method interactiveConfigurator.

@Configurator
public void interactiveConfigurator(final ElkNode elkGraph) {
    // This is a bit more involved. We not only have to set the proper cycle breaking strategy, but we also
    // have to assign bogus coordinates to the nodes
    Deque<ElkNode> nodeQueue = new LinkedList<>();
    nodeQueue.add(elkGraph);
    // Fixed seed to keep tests repeatable
    Random rand = new Random(INTERACTIVE_RANDOM_SEED);
    while (!nodeQueue.isEmpty()) {
        ElkNode node = nodeQueue.poll();
        nodeQueue.addAll(node.getChildren());
        node.setProperty(LayeredOptions.LAYERING_STRATEGY, LayeringStrategy.INTERACTIVE);
        if (node.getX() == 0) {
            node.setX(rand.nextInt(INTERACTIVE_MAX_POS));
        }
        if (node.getY() == 0) {
            node.setY(rand.nextInt(INTERACTIVE_MAX_POS));
        }
    }
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) Random(java.util.Random) LinkedList(java.util.LinkedList) LayoutConfigurator(org.eclipse.elk.core.LayoutConfigurator) Configurator(org.eclipse.elk.alg.test.framework.annotations.Configurator)

Example 99 with ElkNode

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

the class Issue682Test method testGraph.

public Triple<ElkNode, ElkNode, ElkLabel> testGraph() {
    ElkNode graph = ElkGraphUtil.createGraph();
    graph.setProperty(CoreOptions.ALGORITHM, LayeredOptions.ALGORITHM_ID);
    graph.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.ORTHOGONAL);
    graph.setProperty(LayeredOptions.DIRECTION, layoutDirection);
    graph.setProperty(LayeredOptions.NODE_LABELS_PADDING, new ElkPadding(21, 32, 43, 54));
    ElkNode parent = ElkGraphUtil.createNode(graph);
    parent.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.NODE_LABELS));
    parent.setProperty(LayeredOptions.NODE_LABELS_PLACEMENT, NodeLabelPlacement.insideTopCenter());
    ElkLabel label = ElkGraphUtil.createLabel("foobar", parent);
    // Arbitrary
    label.setWidth(23);
    label.setHeight(22);
    return new Triple<>(graph, parent, label);
}
Also used : Triple(org.eclipse.elk.core.util.Triple) ElkNode(org.eclipse.elk.graph.ElkNode) ElkLabel(org.eclipse.elk.graph.ElkLabel) ElkPadding(org.eclipse.elk.core.math.ElkPadding)

Example 100 with ElkNode

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

the class Issue701Test method testFixedInsideLabels.

/**
 * Check behavior for port labels that is fixed, empty {@link PortLabelPlacement) property, but partially located
 * inside the node.
 */
@Test
public void testFixedInsideLabels(final ElkNode graph) {
    ElkNode containerForInsideLabels = GraphTestUtils.getChild(graph, "ContainerWithFixedLabels", "Container_OneBorderNode_LabelFixedPartiallyInside");
    // Ensure there is no label overlaps
    if (GraphTestUtils.haveOverlaps(assembleLabels(containerForInsideLabels))) {
        fail("Overlaps between labels detected in \"Container_OneBorderNode_LabelFixedPartiallyInside\"!");
    }
    // Port on north
    ElkNode node1 = GraphTestUtils.getChild(containerForInsideLabels, "MyNode1");
    ElkPort portOfNode1 = GraphTestUtils.getPort(node1, "P1");
    assertNodeWidthAccordingToPortWidth(node1, portOfNode1, null, false);
    assertNodeHeightAccordingToPortHeight(node1, portOfNode1, null, false);
    // Port on south
    ElkNode node3 = GraphTestUtils.getChild(containerForInsideLabels, "MyNode3");
    ElkPort portOfNode3 = GraphTestUtils.getPort(node3, "P1");
    assertNodeWidthAccordingToPortWidth(node3, portOfNode3, null, false);
    assertNodeHeightAccordingToPortHeight(node3, portOfNode3, null, false);
    // Port on east
    ElkNode node2 = GraphTestUtils.getChild(containerForInsideLabels, "MyNode2");
    ElkPort portOfNode2 = GraphTestUtils.getPort(node2, "P1");
    assertNodeHeightAccordingToPortHeight(node2, portOfNode2, null, true);
    assertNodeWidthAccordingToPortWidth(node2, portOfNode2, null, true);
    // Port on east
    // TODO: Specific case with label centered under the port
    ElkNode node2Bis = GraphTestUtils.getChild(containerForInsideLabels, "MyNode2Bis");
    ElkPort portOfNode2Bis = GraphTestUtils.getPort(node2, "P1");
    // assertNodeHeightAccordingToPortHeight(node2Bis, portOfNode2Bis, null, true);
    // assertNodeWidthAccordingToPortWidth(node2Bis, portOfNode2Bis, null, true);
    // Port on west
    ElkNode node4 = GraphTestUtils.getChild(containerForInsideLabels, "MyNode4");
    ElkPort portOfNode4 = GraphTestUtils.getPort(node4, "P1");
    assertNodeWidthAccordingToPortWidth(node4, portOfNode4, null, true);
    assertNodeHeightAccordingToPortHeight(node4, portOfNode4, null, true);
    // Port on west
    // TODO: Specific case with label centered under the port
    ElkNode node4Bis = GraphTestUtils.getChild(containerForInsideLabels, "MyNode4Bis");
    ElkPort portOfNode4Bis = GraphTestUtils.getPort(node4Bis, "P1");
// assertNodeWidthAccordingToPortWidth(node4Bis, portOfNode4Bis, null, true);
// assertNodeHeightAccordingToPortHeight(node4Bis, portOfNode4Bis, null, true);
}
Also used : ElkNode(org.eclipse.elk.graph.ElkNode) ElkPort(org.eclipse.elk.graph.ElkPort) Test(org.junit.Test)

Aggregations

ElkNode (org.eclipse.elk.graph.ElkNode)267 ElkEdge (org.eclipse.elk.graph.ElkEdge)64 ElkPort (org.eclipse.elk.graph.ElkPort)55 Test (org.junit.Test)52 KVector (org.eclipse.elk.core.math.KVector)51 ElkLabel (org.eclipse.elk.graph.ElkLabel)39 ElkPadding (org.eclipse.elk.core.math.ElkPadding)36 ArrayList (java.util.ArrayList)27 List (java.util.List)25 ElkEdgeSection (org.eclipse.elk.graph.ElkEdgeSection)24 LinkedList (java.util.LinkedList)23 BasicProgressMonitor (org.eclipse.elk.core.util.BasicProgressMonitor)22 ElkGraphElement (org.eclipse.elk.graph.ElkGraphElement)21 ElkConnectableShape (org.eclipse.elk.graph.ElkConnectableShape)17 SizeConstraint (org.eclipse.elk.core.options.SizeConstraint)15 Lists (com.google.common.collect.Lists)12 Collection (java.util.Collection)12 KVectorChain (org.eclipse.elk.core.math.KVectorChain)10 HashMap (java.util.HashMap)9 RecursiveGraphLayoutEngine (org.eclipse.elk.core.RecursiveGraphLayoutEngine)9