Search in sources :

Example 1 with IndividualSpacings

use of org.eclipse.elk.core.util.IndividualSpacings in project elk by eclipse.

the class CuttingUtils method insertDummies.

/**
 * Inserts two in-layer dummies and a varying number of long edge dummies for the passed edge.
 *
 * Let {@code originalEdge = e = (u,v)}. In-layer dummies {@code il_1} and {@code il_2} are inserted into layers
 * {@code L(u)} and {@code L(v)}. Long edge dummies {@code d_1, ..., d_m} are inserted into the layers
 * {@code L(u)+1, ..., L(v)-1}.
 *
 * The resulting chain of edges looks as follows (if {@code offsetFirstInLayerDummy} is 1).
 *
 * <pre>
 *                               v
 *                               î
 * il_1 -> d_1 -> ... -> d_m -> il_2
 *  î
 *  u
 * </pre>
 *
 * @param layeredGraph
 *            the underlying graph with a given layering.
 * @param originalEdge
 *            the edge to be split
 * @param offsetFirstInLayerDummy
 *            the dummy nodes are inserted at the end of each layer. For the first in-layer dummy this is not always
 *            desired and can be modified using this offset.
 */
public static List<LEdge> insertDummies(final LGraph layeredGraph, final LEdge originalEdge, final int offsetFirstInLayerDummy) {
    // to visually separate the backward wrapping edges, add some additional spacing
    double edgeNodeSpacing = layeredGraph.getProperty(LayeredOptions.SPACING_EDGE_NODE);
    double additionalSpacing = layeredGraph.getProperty(LayeredOptions.WRAPPING_ADDITIONAL_EDGE_SPACING);
    IndividualSpacings is = new IndividualSpacings();
    is.setProperty(LayeredOptions.SPACING_EDGE_NODE, edgeNodeSpacing + additionalSpacing);
    LEdge edge = originalEdge;
    LPort targetPort = edge.getTarget();
    LNode src = edge.getSource().getNode();
    LNode tgt = edge.getTarget().getNode();
    int srcIndex = src.getLayer().getIndex();
    int tgtIndex = tgt.getLayer().getIndex();
    List<LEdge> createdEdges = Lists.newArrayList();
    for (int i = srcIndex; i <= tgtIndex; i++) {
        // Create dummy node
        LNode dummyNode = new LNode(layeredGraph);
        dummyNode.setType(NodeType.LONG_EDGE);
        dummyNode.setProperty(InternalProperties.ORIGIN, edge);
        dummyNode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
        dummyNode.setProperty(LayeredOptions.SPACING_INDIVIDUAL, is);
        Layer nextLayer = layeredGraph.getLayers().get(i);
        if (i == srcIndex) {
            dummyNode.setLayer(nextLayer.getNodes().size() - offsetFirstInLayerDummy, nextLayer);
        } else {
            dummyNode.setLayer(nextLayer);
        }
        // Set thickness of the edge
        double thickness = edge.getProperty(LayeredOptions.EDGE_THICKNESS);
        if (thickness < 0) {
            thickness = 0;
            edge.setProperty(LayeredOptions.EDGE_THICKNESS, thickness);
        }
        dummyNode.getSize().y = thickness;
        double portPos = Math.floor(thickness / 2);
        // Create dummy input and output ports
        LPort dummyInput = new LPort();
        dummyInput.setSide(PortSide.WEST);
        dummyInput.setNode(dummyNode);
        dummyInput.getPosition().y = portPos;
        LPort dummyOutput = new LPort();
        dummyOutput.setSide(PortSide.EAST);
        dummyOutput.setNode(dummyNode);
        dummyOutput.getPosition().y = portPos;
        edge.setTarget(dummyInput);
        // Create a dummy edge
        LEdge dummyEdge = new LEdge();
        dummyEdge.copyProperties(edge);
        dummyEdge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
        dummyEdge.setSource(dummyOutput);
        dummyEdge.setTarget(targetPort);
        setDummyProperties(dummyNode, edge, dummyEdge);
        createdEdges.add(dummyEdge);
        edge = dummyEdge;
    }
    return createdEdges;
}
Also used : IndividualSpacings(org.eclipse.elk.core.util.IndividualSpacings) LEdge(org.eclipse.elk.alg.layered.graph.LEdge) LPort(org.eclipse.elk.alg.layered.graph.LPort) LNode(org.eclipse.elk.alg.layered.graph.LNode) Layer(org.eclipse.elk.alg.layered.graph.Layer)

Example 2 with IndividualSpacings

use of org.eclipse.elk.core.util.IndividualSpacings 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)

Example 3 with IndividualSpacings

use of org.eclipse.elk.core.util.IndividualSpacings in project lingua-franca by lf-lang.

the class UtilityExtensions method getPortMarginsInitIfAbsent.

/**
 * Returns the port placement margins for the node.
 * If this spacing does not yet exist, the properties are initialized.
 */
public ElkMargin getPortMarginsInitIfAbsent(KNode node) {
    IndividualSpacings spacing = node.getProperty(CoreOptions.SPACING_INDIVIDUAL);
    if (spacing == null) {
        spacing = new IndividualSpacings();
        node.setProperty(CoreOptions.SPACING_INDIVIDUAL, spacing);
    }
    ElkMargin margin = spacing.getProperty(CoreOptions.SPACING_PORTS_SURROUNDING);
    if (margin == null) {
        margin = new ElkMargin();
        node.setProperty(CoreOptions.SPACING_PORTS_SURROUNDING, margin);
    }
    return margin;
}
Also used : IndividualSpacings(org.eclipse.elk.core.util.IndividualSpacings) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Aggregations

IndividualSpacings (org.eclipse.elk.core.util.IndividualSpacings)3 ElkMargin (org.eclipse.elk.core.math.ElkMargin)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 LEdge (org.eclipse.elk.alg.layered.graph.LEdge)1 LNode (org.eclipse.elk.alg.layered.graph.LNode)1 LPort (org.eclipse.elk.alg.layered.graph.LPort)1 Layer (org.eclipse.elk.alg.layered.graph.Layer)1 ElkPadding (org.eclipse.elk.core.math.ElkPadding)1 KVector (org.eclipse.elk.core.math.KVector)1 KVectorChain (org.eclipse.elk.core.math.KVectorChain)1