use of org.eclipse.elk.core.options.SizeConstraint in project osate2 by osate.
the class ElkGraphBuilder method createElkGraphElementForNonLabelAndUndockedShape.
private Optional<ElkGraphElement> createElkGraphElementForNonLabelAndUndockedShape(final DiagramElement de, final ElkNode layoutParent, final LayoutMapping mapping) {
final ElkNode newNode = ElkGraphUtil.createNode(layoutParent);
mapping.getGraphMap().put(newNode, de);
if (de.hasPosition()) {
newNode.setLocation(de.getX(), de.getY());
}
// Setting the size is disabled because setting it causes shapes which have a flow path(along with corresponding ports) to grow.
// if (de.hasSize()) {
// newNode.setDimensions(de.getWidth(), de.getHeight());
// }
final EnumSet<SizeConstraint> nodeSizeConstraints = EnumSet.of(SizeConstraint.PORTS, SizeConstraint.MINIMUM_SIZE, SizeConstraint.NODE_LABELS);
newNode.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, nodeSizeConstraints);
newNode.setProperty(CoreOptions.INSIDE_SELF_LOOPS_ACTIVATE, true);
newNode.setProperty(CoreOptions.NODE_SIZE_OPTIONS, EnumSet.of(SizeOptions.DEFAULT_MINIMUM_SIZE, SizeOptions.ASYMMETRICAL));
// Create labels
createElkLabels(de, newNode, mapping);
// Create Children
createElkGraphElementsForNonLabelChildShapes(de, newNode, mapping);
return Optional.of(newNode);
}
use of org.eclipse.elk.core.options.SizeConstraint in project elk by eclipse.
the class ElkLayered method resizeGraph.
// //////////////////////////////////////////////////////////////////////////////
// Graph Postprocessing (Size and External Ports)
/**
* Sets the size of the given graph such that size constraints are adhered to.
* Furthermore, the border spacing is added to the graph size and the graph offset.
* Afterwards, the border spacing property is reset to 0.
*
* <p>Major parts of this method are adapted from
* {@link ElkUtil#resizeNode(org.eclipse.elk.graph.ElkNode, double, double, boolean, boolean)}.</p>
*
* <p>Note: This method doesn't care about labels of compound nodes since those labels are not
* attached to the graph.</p>
*
* @param lgraph the graph to resize.
*/
private void resizeGraph(final LGraph lgraph) {
Set<SizeConstraint> sizeConstraint = lgraph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS);
Set<SizeOptions> sizeOptions = lgraph.getProperty(LayeredOptions.NODE_SIZE_OPTIONS);
KVector calculatedSize = lgraph.getActualSize();
KVector adjustedSize = new KVector(calculatedSize);
// calculate the new size
if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
KVector minSize = lgraph.getProperty(LayeredOptions.NODE_SIZE_MINIMUM);
// if minimum width or height are not set, maybe default to default values
if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
if (minSize.x <= 0) {
minSize.x = ElkUtil.DEFAULT_MIN_WIDTH;
}
if (minSize.y <= 0) {
minSize.y = ElkUtil.DEFAULT_MIN_HEIGHT;
}
}
// apply new size including border spacing
adjustedSize.x = Math.max(calculatedSize.x, minSize.x);
adjustedSize.y = Math.max(calculatedSize.y, minSize.y);
}
resizeGraphNoReallyIMeanIt(lgraph, calculatedSize, adjustedSize);
}
use of org.eclipse.elk.core.options.SizeConstraint in project elk by eclipse.
the class ElkGraphImporter method calculateMinimumGraphSize.
/**
* Asks the label and node size thing to calculate the minimum size necessary for the graph to be large enough for
* its ports and stuff (if it's not the top level graph).
*
* @param elkgraph
* the original ELK graph.
* @param lgraph
* the imported LGraph. Its properties may be updated over the course of this method.
*/
private void calculateMinimumGraphSize(final ElkNode elkgraph, final LGraph lgraph) {
// If the graph is on the top level, don't bother
if (elkgraph.getParent() == null) {
return;
}
// If the graph has no size constraints, don't bother either
EnumSet<SizeConstraint> sizeConstraints = lgraph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS);
// The method should only be called if shouldCalculateMinimumGraphSize(...) returns true
assert !sizeConstraints.isEmpty();
// Ensure that the port constraints are not UNDEFINED
if (elkgraph.getProperty(LayeredOptions.PORT_CONSTRAINTS) == PortConstraints.UNDEFINED) {
elkgraph.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
}
// Size constraints are not empty, so calculate the size the node and label placement code thing would like to
// give the graph
GraphAdapter<?> graphAdapter = ElkGraphAdapters.adapt(elkgraph.getParent());
NodeAdapter<?> nodeAdapter = ElkGraphAdapters.adaptSingleNode(elkgraph);
KVector minSize = NodeLabelAndSizeCalculator.process(graphAdapter, nodeAdapter, false, true);
// Apply the minimum size a sa property and make sure the minimum size is respected by ELK Layered by making
// sure the necessary size constraint exists
sizeConstraints.add(SizeConstraint.MINIMUM_SIZE);
KVector configuredMinSize = lgraph.getProperty(LayeredOptions.NODE_SIZE_MINIMUM);
configuredMinSize.x = Math.max(minSize.x, configuredMinSize.x);
configuredMinSize.y = Math.max(minSize.y, configuredMinSize.y);
}
use of org.eclipse.elk.core.options.SizeConstraint in project elk by eclipse.
the class ElkUtil method effectiveMinSizeConstraintFor.
/**
* Returns the minimum size of the node according to the {@link CoreOptions#NODE_SIZE_MINIMUM} constraint. If that
* constraint is not set, the size returned by this method will be {@code (0, 0)}.
*
* @param node the node whose minimum size to compute.
* @return the minimum size.
*/
public static KVector effectiveMinSizeConstraintFor(final ElkNode node) {
Set<SizeConstraint> sizeConstraint = node.getProperty(CoreOptions.NODE_SIZE_CONSTRAINTS);
if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
Set<SizeOptions> sizeOptions = node.getProperty(CoreOptions.NODE_SIZE_OPTIONS);
KVector minSize = new KVector(node.getProperty(CoreOptions.NODE_SIZE_MINIMUM));
// If minimum width or height are not set, maybe default to default values
if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
if (minSize.x <= 0) {
minSize.x = DEFAULT_MIN_WIDTH;
}
if (minSize.y <= 0) {
minSize.y = DEFAULT_MIN_HEIGHT;
}
}
return minSize;
} else {
return new KVector();
}
}
use of org.eclipse.elk.core.options.SizeConstraint in project elk by eclipse.
the class HierarchicalNodeResizingProcessor method resizeGraph.
// //////////////////////////////////////////////////////////////////////////////
// Graph Postprocessing (Size and External Ports)
/**
* Sets the size of the given graph such that size constraints are adhered to. Furthermore, the padding is
* added to the graph size and the graph offset. Afterwards, the border spacing property is reset to 0.
*
* <p>
* Major parts of this method are adapted from
* {@link ElkUtil#resizeNode(org.eclipse.elk.graph.ElkNode, double, double, boolean, boolean)}.
* </p>
*
* <p>
* Note: This method doesn't care about labels of compound nodes since those labels are not attached to the graph.
* </p>
*
* @param lgraph
* the graph to resize.
*/
private void resizeGraph(final LGraph lgraph) {
Set<SizeConstraint> sizeConstraint = lgraph.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS);
Set<SizeOptions> sizeOptions = lgraph.getProperty(LayeredOptions.NODE_SIZE_OPTIONS);
// getActualSize() used to take the border spacing (what is now included in the padding)
// into account, which is why by this point it had to be cleared since it had already
// been applied to the offset and the graph size. It currently does not take the padding
// into account anymore, but if it does, it needs to be cleared again
KVector calculatedSize = lgraph.getActualSize();
KVector adjustedSize = new KVector(calculatedSize);
// calculate the new size
if (sizeConstraint.contains(SizeConstraint.MINIMUM_SIZE)) {
KVector minSize = lgraph.getProperty(LayeredOptions.NODE_SIZE_MINIMUM);
// if minimum width or height are not set, maybe default to default values
if (sizeOptions.contains(SizeOptions.DEFAULT_MINIMUM_SIZE)) {
if (minSize.x <= 0) {
minSize.x = ElkUtil.DEFAULT_MIN_WIDTH;
}
if (minSize.y <= 0) {
minSize.y = ElkUtil.DEFAULT_MIN_HEIGHT;
}
}
// apply new size including border spacing
adjustedSize.x = Math.max(calculatedSize.x, minSize.x);
adjustedSize.y = Math.max(calculatedSize.y, minSize.y);
}
resizeGraphNoReallyIMeanIt(lgraph, calculatedSize, adjustedSize);
}
Aggregations