Search in sources :

Example 6 with ElkMargin

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

the class Rectangle method toNodeMargins.

/**
 * Creates a margin that is relative to a {@link LShape}, so that this {@link Rectangle} completely
 * lays inside the margins and is of minimal size. The margins of any side of the shape will be at
 * least 0. If the given shape is a {@link LNode} it's margin is neither modified nor taken into
 * account.
 *
 * @param shape The shape the margins shall lay around.
 * @return A new {@link Margins} laying around the shape.
 */
public ElkMargin toNodeMargins(final LShape shape) {
    final ElkMargin retVal = new ElkMargin();
    final Rectangle shapeRectangle = new Rectangle(0, 0, shape.getSize().x, shape.getSize().y);
    retVal.top = Math.max(0.0, shapeRectangle.top - top);
    retVal.left = Math.max(0.0, shapeRectangle.left - left);
    retVal.bottom = Math.max(0.0, bottom - shapeRectangle.bottom);
    retVal.right = Math.max(0.0, right - shapeRectangle.right);
    return retVal;
}
Also used : ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Example 7 with ElkMargin

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

the class PropertyTest method testPropertyDefaultIDataObject.

@Test
public void testPropertyDefaultIDataObject() {
    // all IDataObjects
    KVector v = new KVector(2, 3);
    testPropertyObject(v);
    KVectorChain vc = new KVectorChain(v, v);
    testPropertyObject(vc);
    ElkPadding ep = new ElkPadding(2, 3);
    testPropertyObject(ep);
    ElkMargin em = new ElkMargin(3, 2);
    testPropertyObject(em);
}
Also used : KVectorChain(org.eclipse.elk.core.math.KVectorChain) KVector(org.eclipse.elk.core.math.KVector) ElkPadding(org.eclipse.elk.core.math.ElkPadding) ElkMargin(org.eclipse.elk.core.math.ElkMargin) Test(org.junit.Test)

Example 8 with ElkMargin

use of org.eclipse.elk.core.math.ElkMargin in project lingua-franca by lf-lang.

the class LinguaFrancaSynthesis method addIOPort.

/**
 * Translate an input/output into a port.
 */
private KPort addIOPort(KNode node, PortInstance lfPort, boolean input, boolean multiport, boolean bank) {
    KPort port = _kPortExtensions.createPort();
    node.getPorts().add(port);
    associateWith(port, lfPort.getDefinition());
    NamedInstanceUtil.linkInstance(port, lfPort);
    _kPortExtensions.setPortSize(port, 6, 6);
    if (input) {
        // multiports are smaller by an offset at the right, hence compensate in inputs
        double offset = multiport ? -3.4 : -3.3;
        setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.WEST);
        setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset);
    } else {
        // multiports are smaller
        double offset = multiport ? -2.6 : -3.3;
        // compensate bank figure width
        offset = bank ? offset - LinguaFrancaShapeExtensions.BANK_FIGURE_X_OFFSET_SUM : offset;
        setLayoutOption(port, CoreOptions.PORT_SIDE, PortSide.EAST);
        setLayoutOption(port, CoreOptions.PORT_BORDER_OFFSET, offset);
    }
    if (bank && !node.getProperty(REACTOR_HAS_BANK_PORT_OFFSET)) {
        // compensate bank figure height
        // https://github.com/eclipse/elk/issues/693
        _utilityExtensions.getPortMarginsInitIfAbsent(node).add(new ElkMargin(0, 0, LinguaFrancaShapeExtensions.BANK_FIGURE_Y_OFFSET_SUM, 0));
        // only once
        node.setProperty(REACTOR_HAS_BANK_PORT_OFFSET, true);
    }
    _linguaFrancaShapeExtensions.addTrianglePort(port, multiport);
    String label = lfPort.getName();
    if (!getBooleanValue(SHOW_PORT_NAMES)) {
        label = "";
    }
    if (getBooleanValue(SHOW_MULTIPORT_WIDTH)) {
        if (lfPort.isMultiport()) {
            label += (lfPort.getWidth() >= 0) ? "[" + lfPort.getWidth() + "]" : "[?]";
        }
    }
    associateWith(_kLabelExtensions.addOutsidePortLabel(port, label, 8), lfPort.getDefinition());
    return port;
}
Also used : KPort(de.cau.cs.kieler.klighd.kgraph.KPort) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

Example 9 with ElkMargin

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

Example 10 with ElkMargin

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

the class NetworkSimplexPlacer method isFlexibleNode.

// ------------------------------------------------------------------------------------------------
// Flexible Ports
// ------------------------------------------------------------------------------------------------
/**
 * A node is <em>flexible</em> if
 * <ul>
 *  <li>its port constraints are <b>not</b> {@link PortConstraints#FIXED_POS}, and</li>
 *  <li>the node's height is large enough to give the ports
 *      on both sides (WEST and EAST) enough room to potentially alter their position.</li>
 * </ul>
 *
 * The rationale for the latter case is the following:
 * if the height of a node is not enough to accommodate all ports
 * and we are not allowed to change the node's size,
 * we simply use the port positions that have been computed by the {@link LabelAndNodeSizeProcessor}.
 * The processor is able to handle this situation properly.
 *
 * @param lNode a node
 * @return whether the node is regarded flexible.
 */
public static boolean isFlexibleNode(final LNode lNode) {
    // dummies are not flexible!
    if (lNode.getType() != NodeType.NORMAL) {
        return false;
    }
    // at least two ports are required ...
    if (lNode.getPorts().size() <= 1) {
        return false;
    }
    // if ports may not be moved there's no use in enlarging the node
    PortConstraints pc = lNode.getProperty(LayeredOptions.PORT_CONSTRAINTS);
    if (pc.isPosFixed()) {
        return false;
    }
    NodeFlexibility nf = getNodeFlexibility(lNode);
    if (nf == NodeFlexibility.NONE) {
        return false;
    }
    // all ports, reuse the existing port positions
    if (!nf.isFlexibleSizeWhereSpacePermits()) {
        // we are not allowed to increase the node's size
        double portSpacing = Spacings.getIndividualOrDefault(lNode, LayeredOptions.SPACING_PORT_PORT);
        ElkMargin additionalPortSpacing = lNode.getProperty(LayeredOptions.SPACING_PORTS_SURROUNDING);
        if (additionalPortSpacing == null) {
            additionalPortSpacing = new ElkMargin(portSpacing, portSpacing, portSpacing, portSpacing);
        }
        // check west side
        List<LPort> westPorts = lNode.getPortSideView(PortSide.WEST);
        double requiredWestHeight = additionalPortSpacing.top + additionalPortSpacing.bottom + (westPorts.size() - 1) * portSpacing;
        if (requiredWestHeight > lNode.getSize().y) {
            return false;
        }
        // check east side
        List<LPort> eastPorts = lNode.getPortSideView(PortSide.EAST);
        double requiredEastHeight = additionalPortSpacing.top + additionalPortSpacing.bottom + (eastPorts.size() - 1) * portSpacing;
        if (requiredEastHeight > lNode.getSize().y) {
            return false;
        }
    }
    return true;
}
Also used : LPort(org.eclipse.elk.alg.layered.graph.LPort) NodeFlexibility.getNodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility.getNodeFlexibility) NodeFlexibility(org.eclipse.elk.alg.layered.options.NodeFlexibility) PortConstraints(org.eclipse.elk.core.options.PortConstraints) ElkMargin(org.eclipse.elk.core.math.ElkMargin)

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