use of org.eclipse.elk.alg.layered.options.GraphProperties in project elk by eclipse.
the class ElkGraphLayoutTransferrer method applyParentNodeLayout.
/**
* Applies layout information computed for the given graph.
*
* @param lgraph
* the edge that has the layout information.
*/
private void applyParentNodeLayout(final LGraph lgraph) {
ElkNode elknode = (ElkNode) lgraph.getProperty(InternalProperties.ORIGIN);
boolean sizeConstraintsIncludedPortLabels = elknode.getProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS).contains(SizeConstraint.PORT_LABELS);
if (lgraph.getParentNode() == null) {
Set<GraphProperties> graphProps = lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
KVector actualGraphSize = lgraph.getActualSize();
if (graphProps.contains(GraphProperties.EXTERNAL_PORTS)) {
// Ports have positions assigned, the graph's size is final
elknode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FIXED_POS);
ElkUtil.resizeNode(elknode, actualGraphSize.x, actualGraphSize.y, false, true);
} else {
// Ports have not been positioned yet - leave this for next layouter
ElkUtil.resizeNode(elknode, actualGraphSize.x, actualGraphSize.y, true, true);
}
}
// consideration for their labels.
if (sizeConstraintsIncludedPortLabels) {
elknode.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, EnumSet.of(SizeConstraint.PORT_LABELS));
} else {
elknode.setProperty(LayeredOptions.NODE_SIZE_CONSTRAINTS, SizeConstraint.fixed());
}
}
use of org.eclipse.elk.alg.layered.options.GraphProperties in project elk by eclipse.
the class ElkGraphImporter method transformNode.
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node Transformation
/**
* Transforms the given node and its contained ports.
*
* @param elknode
* the node to transform
* @param lgraph
* the layered graph into which the transformed node is put
* @return the transformed node
*/
private LNode transformNode(final ElkNode elknode, final LGraph lgraph) {
// add a new node to the layered graph, copying its position
LNode lnode = new LNode(lgraph);
lnode.copyProperties(elknode);
lnode.setProperty(InternalProperties.ORIGIN, elknode);
lnode.getSize().x = elknode.getWidth();
lnode.getSize().y = elknode.getHeight();
lnode.getPosition().x = elknode.getX();
lnode.getPosition().y = elknode.getY();
lgraph.getLayerlessNodes().add(lnode);
nodeAndPortMap.put(elknode, lnode);
// check if the node is a compound node in the original graph
if (!elknode.getChildren().isEmpty() || elknode.getProperty(LayeredOptions.INSIDE_SELF_LOOPS_ACTIVATE)) {
lnode.setProperty(InternalProperties.COMPOUND_NODE, true);
}
Set<GraphProperties> graphProperties = lgraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
// port constraints and sides cannot be undefined
PortConstraints portConstraints = lnode.getProperty(LayeredOptions.PORT_CONSTRAINTS);
if (portConstraints == PortConstraints.UNDEFINED) {
lnode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
} else if (portConstraints != PortConstraints.FREE) {
// if the port constraints are not free, set the appropriate graph property
graphProperties.add(GraphProperties.NON_FREE_PORTS);
}
// transform the ports
Direction direction = lgraph.getProperty(LayeredOptions.DIRECTION);
for (ElkPort elkport : elknode.getPorts()) {
if (!elkport.getProperty(LayeredOptions.NO_LAYOUT)) {
transformPort(elkport, lnode, graphProperties, direction, portConstraints);
}
}
// add the node's labels
for (ElkLabel elklabel : elknode.getLabels()) {
if (!elklabel.getProperty(LayeredOptions.NO_LAYOUT) && !Strings.isNullOrEmpty(elklabel.getText())) {
lnode.getLabels().add(transformLabel(elklabel));
}
}
if (lnode.getProperty(LayeredOptions.COMMENT_BOX)) {
graphProperties.add(GraphProperties.COMMENTS);
}
// if we have a hypernode without ports, create a default input and output port
if (lnode.getProperty(LayeredOptions.HYPERNODE)) {
graphProperties.add(GraphProperties.HYPERNODES);
graphProperties.add(GraphProperties.HYPEREDGES);
lnode.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
}
return lnode;
}
use of org.eclipse.elk.alg.layered.options.GraphProperties in project elk by eclipse.
the class LGraphUtil method computeGraphProperties.
// /////////////////////////////////////////////////////////////////////////////
// Graph Properties
/**
* Compute the graph properties of the given layered graph. These properties are important
* to determine which intermediate processors are included in the layout run.
* Ideally the properties are computed during the import of the source format into {@link LGraph},
* e.g. as done in {@code KGraphImporter}. This method is offered only for convenience.
* <p>
* The nodes are expected to be in the {@link LGraph#getLayerlessNodes()} list.
* </p>
*
* @param layeredGraph a layered graph
*/
public static void computeGraphProperties(final LGraph layeredGraph) {
Set<GraphProperties> props = layeredGraph.getProperty(InternalProperties.GRAPH_PROPERTIES);
if (!props.isEmpty()) {
props.clear();
}
Direction direction = getDirection(layeredGraph);
for (LNode node : layeredGraph.getLayerlessNodes()) {
if (node.getProperty(LayeredOptions.COMMENT_BOX)) {
props.add(GraphProperties.COMMENTS);
} else if (node.getProperty(LayeredOptions.HYPERNODE)) {
props.add(GraphProperties.HYPERNODES);
props.add(GraphProperties.HYPEREDGES);
} else if (node.getType() == NodeType.EXTERNAL_PORT) {
props.add(GraphProperties.EXTERNAL_PORTS);
}
PortConstraints portConstraints = node.getProperty(LayeredOptions.PORT_CONSTRAINTS);
if (portConstraints == PortConstraints.UNDEFINED) {
// correct the port constraints value
node.setProperty(LayeredOptions.PORT_CONSTRAINTS, PortConstraints.FREE);
} else if (portConstraints != PortConstraints.FREE) {
props.add(GraphProperties.NON_FREE_PORTS);
}
for (LPort port : node.getPorts()) {
if (port.getIncomingEdges().size() + port.getOutgoingEdges().size() > 1) {
props.add(GraphProperties.HYPEREDGES);
}
PortSide portSide = port.getSide();
switch(direction) {
case UP:
case DOWN:
if (portSide == PortSide.EAST || portSide == PortSide.WEST) {
props.add(GraphProperties.NORTH_SOUTH_PORTS);
}
break;
default:
if (portSide == PortSide.NORTH || portSide == PortSide.SOUTH) {
props.add(GraphProperties.NORTH_SOUTH_PORTS);
}
}
for (LEdge edge : port.getOutgoingEdges()) {
if (edge.getTarget().getNode() == node) {
props.add(GraphProperties.SELF_LOOPS);
}
for (LLabel label : edge.getLabels()) {
switch(label.getProperty(LayeredOptions.EDGE_LABELS_PLACEMENT)) {
case CENTER:
props.add(GraphProperties.CENTER_LABELS);
break;
case HEAD:
case TAIL:
props.add(GraphProperties.END_LABELS);
break;
}
}
}
}
}
}
use of org.eclipse.elk.alg.layered.options.GraphProperties in project elk by eclipse.
the class TestGraphCreator method addExternalPortDummyNodeToLayer.
protected LNode addExternalPortDummyNodeToLayer(final Layer layer, final LPort port) {
LNode node = addNodeToLayer(layer);
node.setProperty(InternalProperties.ORIGIN, port);
node.setType(NodeType.EXTERNAL_PORT);
node.setProperty(InternalProperties.EXT_PORT_SIDE, port.getSide());
port.setProperty(InternalProperties.PORT_DUMMY, node);
port.setProperty(InternalProperties.INSIDE_CONNECTIONS, true);
Set<GraphProperties> ps = node.getGraph().getProperty(InternalProperties.GRAPH_PROPERTIES);
ps.add(GraphProperties.EXTERNAL_PORTS);
return node;
}
Aggregations