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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations