Search in sources :

Example 11 with ElkMargin

use of org.eclipse.elk.core.math.ElkMargin in project elk by eclipse.

the class NetworkSimplexPlacer method transformPorts.

private void transformPorts(final Iterable<LPort> ports, final NodeRep corners) {
    if (Iterables.isEmpty(ports)) {
        // the top and bottom border of the node are already safely spaced apart
        return;
    }
    final double portSpacing = Spacings.getIndividualOrDefault(corners.origin, LayeredOptions.SPACING_PORT_PORT);
    ElkMargin portSurrounding = Spacings.getIndividualOrDefault(corners.origin, LayeredOptions.SPACING_PORTS_SURROUNDING);
    if (portSurrounding == null) {
        // No additional port spacing set
        portSurrounding = new ElkMargin();
    }
    NNode lastNNode = corners.head;
    LPort lastPort = null;
    for (LPort port : ports) {
        // spacing between the current pair of ports (or to the top border of the node)
        double spacing = 0;
        if (lastPort == null) {
            spacing = portSurrounding.top;
        } else {
            spacing = portSpacing;
            spacing += lastPort.getSize().y;
        // TODO only if PORT_LABELS is set?
        // + lastPort.getMargin().bottom
        // + port.getMargin().top;
        }
        // create NNode for the port
        NNode nNode = NNode.of().origin(port).type("port").create(nGraph);
        portMap.put(port, nNode);
        // connect with previous NNode
        NEdge.of().weight(0).delta((int) Math.ceil(spacing)).source(lastNNode).target(nNode).create();
        lastPort = port;
        lastNNode = nNode;
    }
    // and connect to the bottom border
    NEdge.of().weight(0).delta((int) Math.ceil(portSurrounding.bottom + lastPort.getSize().y)).source(lastNNode).target(corners.tail).create();
}
Also used : NNode(org.eclipse.elk.alg.common.networksimplex.NNode) LPort(org.eclipse.elk.alg.layered.graph.LPort) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Example 12 with ElkMargin

use of org.eclipse.elk.core.math.ElkMargin in project elk by eclipse.

the class InteractiveExternalPortPositioner method process.

@Override
public void process(final LGraph layeredGraph, final IElkProgressMonitor progressMonitor) {
    // if the graph does not contain any external ports ...
    if (!layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES).contains(GraphProperties.EXTERNAL_PORTS)) {
        // ... nothing we can do about it
        return;
    }
    // find the minimum and maximum x coordinates of the graph
    for (LNode node : layeredGraph.getLayerlessNodes()) {
        if (node.getType() == NodeType.NORMAL) {
            ElkMargin margins = node.getProperty(LayeredOptions.MARGINS);
            minX = Math.min(minX, node.getPosition().x - margins.left);
            maxX = Math.max(maxX, node.getPosition().x + node.getSize().x + margins.right);
            minY = Math.min(minY, node.getPosition().y - margins.top);
            maxY = Math.max(maxY, node.getPosition().y + node.getSize().y + margins.bottom);
        }
    }
    // assign reasonable coordinates to external port dummies
    for (LNode node : layeredGraph.getLayerlessNodes()) {
        if (node.getType() != NodeType.NORMAL) {
            switch(node.getType()) {
                // SUPPRESS CHECKSTYLE NEXT 50 InnerAssignment
                case EXTERNAL_PORT:
                    LayerConstraint lc = node.getProperty(LayeredOptions.LAYERING_LAYER_CONSTRAINT);
                    if (lc == LayerConstraint.FIRST_SEPARATE) {
                        // it's a WEST port
                        node.getPosition().x = minX - ARBITRARY_SPACING;
                        findYCoordinate(node, (e) -> e.getTarget().getNode()).transform((d) -> node.getPosition().y = d);
                        break;
                    }
                    if (lc == LayerConstraint.LAST_SEPARATE) {
                        // it's a EAST port
                        node.getPosition().x = maxX + ARBITRARY_SPACING;
                        findYCoordinate(node, (e) -> e.getSource().getNode()).transform((d) -> node.getPosition().y = d);
                        break;
                    }
                    InLayerConstraint ilc = node.getProperty(InternalProperties.IN_LAYER_CONSTRAINT);
                    if (ilc == InLayerConstraint.TOP) {
                        findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
                        node.getPosition().y = minY - ARBITRARY_SPACING;
                        break;
                    }
                    if (ilc == InLayerConstraint.BOTTOM) {
                        findNorthSouthPortXCoordinate(node).transform((x) -> node.getPosition().x = x + ARBITRARY_SPACING);
                        node.getPosition().y = maxY + ARBITRARY_SPACING;
                        break;
                    }
                    break;
                default:
                    throw new IllegalArgumentException("The node type " + node.getType() + " is not supported by the " + this.getClass());
            }
        }
    }
}
Also used : ElkMargin(org.eclipse.elk.core.math.ElkMargin) GraphProperties(org.eclipse.elk.alg.layered.options.GraphProperties) Function(com.google.common.base.Function) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayeredOptions(org.eclipse.elk.alg.layered.options.LayeredOptions) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint) InternalProperties(org.eclipse.elk.alg.layered.options.InternalProperties) LGraph(org.eclipse.elk.alg.layered.graph.LGraph) Optional(com.google.common.base.Optional) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) NodeType(org.eclipse.elk.alg.layered.graph.LNode.NodeType) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LNode(org.eclipse.elk.alg.layered.graph.LNode) ElkMargin(org.eclipse.elk.core.math.ElkMargin) InLayerConstraint(org.eclipse.elk.alg.layered.options.InLayerConstraint) LayerConstraint(org.eclipse.elk.alg.layered.options.LayerConstraint)

Example 13 with ElkMargin

use of org.eclipse.elk.core.math.ElkMargin in project elk by eclipse.

the class LayoutMetaDataService method initElkReflect.

/**
 * Registers all basic data types with {@link ElkReflect}. This method should only be called from the outside if
 * layout algorithms are supposed to be called directly, which we don't recommend.
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void initElkReflect() {
    // every class that implements IDataObject
    // or is used for internal properties must be registered here
    // IDataObject
    ElkReflect.register(KVector.class, () -> new KVector(), (v) -> ((KVector) v).clone());
    ElkReflect.register(KVectorChain.class, () -> new KVectorChain(), (vc) -> new KVectorChain((KVectorChain) vc));
    ElkReflect.register(ElkMargin.class, () -> new ElkMargin(), (m) -> new ElkMargin((ElkMargin) m));
    ElkReflect.register(ElkPadding.class, () -> new ElkPadding(), (p) -> new ElkPadding((ElkPadding) p));
    ElkReflect.register(IndividualSpacings.class, () -> new IndividualSpacings(), (is) -> new IndividualSpacings((IndividualSpacings) is));
    // Commonly used classes for internal properties
    ElkReflect.register(ArrayList.class, () -> new ArrayList(), (al) -> ((ArrayList) al).clone());
    ElkReflect.register(LinkedList.class, () -> new LinkedList(), (ll) -> Lists.newLinkedList((LinkedList) ll));
    ElkReflect.register(HashSet.class, () -> new HashSet(), (hs) -> Sets.newHashSet((HashSet) hs));
    ElkReflect.register(LinkedHashSet.class, () -> new LinkedHashSet(), (hs) -> Sets.newLinkedHashSet((HashSet) hs));
    ElkReflect.register(TreeSet.class, () -> new TreeSet(), (ts) -> Sets.newTreeSet((TreeSet) ts));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IndividualSpacings(org.eclipse.elk.core.util.IndividualSpacings) KVectorChain(org.eclipse.elk.core.math.KVectorChain) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) LinkedList(java.util.LinkedList) ElkMargin(org.eclipse.elk.core.math.ElkMargin) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

ElkMargin (org.eclipse.elk.core.math.ElkMargin)13 KVector (org.eclipse.elk.core.math.KVector)5 LPort (org.eclipse.elk.alg.layered.graph.LPort)4 ElkPadding (org.eclipse.elk.core.math.ElkPadding)3 KPort (de.cau.cs.kieler.klighd.kgraph.KPort)2 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)2 LNode (org.eclipse.elk.alg.layered.graph.LNode)2 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)2 IndividualSpacings (org.eclipse.elk.core.util.IndividualSpacings)2 ElkNode (org.eclipse.elk.graph.ElkNode)2 Function (com.google.common.base.Function)1 Optional (com.google.common.base.Optional)1 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Sets (com.google.common.collect.Sets)1 Inject (com.google.inject.Inject)1 SynthesisOption (de.cau.cs.kieler.klighd.SynthesisOption)1 KEdge (de.cau.cs.kieler.klighd.kgraph.KEdge)1 KNode (de.cau.cs.kieler.klighd.kgraph.KNode)1