use of org.eclipse.elk.graph.ElkConnectableShape in project elk by eclipse.
the class GmfLayoutEditPolicy method getRelativeSourcePoint.
/**
* Create a vector that contains the relative position of the source point to the corresponding source node or
* port.
*
* @param edge
* an edge
* @return the relative source point
*/
private KVector getRelativeSourcePoint(final ElkEdge edge) {
// The edge should have exactly one source shape
ElkConnectableShape sourceShape = edge.getSources().get(0);
// The edge should have one edge section after layout
ElkEdgeSection edgeSection = edge.getSections().get(0);
KVector sourcePoint = new KVector(edgeSection.getStartX(), edgeSection.getStartY());
// We will now make the source point absolute, and then relative to the source node
ElkUtil.toAbsolute(sourcePoint, edge.getContainingNode());
ElkUtil.toRelative(sourcePoint, ElkGraphUtil.connectableShapeToNode(sourceShape));
// 1 being at the right / bottom
if (sourceShape instanceof ElkPort) {
ElkPort sourcePort = (ElkPort) sourceShape;
// calculate the relative position to the port size
if (sourcePort.getWidth() <= 0) {
sourcePoint.x = 0;
} else {
sourcePoint.x = (sourcePoint.x - sourcePort.getX()) / sourcePort.getWidth();
}
if (sourcePort.getHeight() <= 0) {
sourcePoint.y = 0;
} else {
sourcePoint.y = (sourcePoint.y - sourcePort.getY()) / sourcePort.getHeight();
}
} else {
// calculate the relative position to the node size
if (sourceShape.getWidth() <= 0) {
sourcePoint.x = 0;
} else {
sourcePoint.x /= sourceShape.getWidth();
}
if (sourceShape.getHeight() <= 0) {
sourcePoint.y = 0;
} else {
sourcePoint.y /= sourceShape.getHeight();
}
}
// check the bound of the relative position
return sourcePoint.bound(0, 0, 1, 1);
}
use of org.eclipse.elk.graph.ElkConnectableShape in project elk by eclipse.
the class GmfLayoutEditPolicy method getRelativeTargetPoint.
/**
* Create a vector that contains the relative position of the target point to the corresponding
* target node or port.
*
* @param edge
* an edge
* @return the relative target point
*/
private KVector getRelativeTargetPoint(final ElkEdge edge) {
// The edge should have exactly one source shape
ElkConnectableShape targetShape = edge.getTargets().get(0);
// The edge should have one edge section after layout
ElkEdgeSection edgeSection = edge.getSections().get(0);
KVector targetPoint = new KVector(edgeSection.getEndX(), edgeSection.getEndY());
// We will now make the source point absolute, and then relative to the source node
ElkUtil.toAbsolute(targetPoint, edge.getContainingNode());
ElkUtil.toRelative(targetPoint, ElkGraphUtil.connectableShapeToNode(targetShape));
// 1 being at the right / bottom
if (targetShape instanceof ElkPort) {
ElkPort targetPort = (ElkPort) targetShape;
// calculate the relative position to the port size
if (targetPort.getWidth() <= 0) {
targetPoint.x = 0;
} else {
targetPoint.x = (targetPoint.x - targetPort.getX()) / targetPort.getWidth();
}
if (targetPort.getHeight() <= 0) {
targetPoint.y = 0;
} else {
targetPoint.y = (targetPoint.y - targetPort.getY()) / targetPort.getHeight();
}
} else {
// calculate the relative position to the node size
if (targetShape.getWidth() <= 0) {
targetPoint.x = 0;
} else {
targetPoint.x /= targetShape.getWidth();
}
if (targetShape.getHeight() <= 0) {
targetPoint.y = 0;
} else {
targetPoint.y /= targetShape.getHeight();
}
}
// check the bound of the relative position
return targetPoint.bound(0, 0, 1, 1);
}
use of org.eclipse.elk.graph.ElkConnectableShape in project elk by eclipse.
the class RandomGraphGenerator method split.
/**
* Splits an edge by inserting a new node and a new edge. The old edge will have all the old
* sources and just the new node as a target and the new edge will have all the old targets and
* just the new node as a source. The parent of the new node will be the node containing a whole
* edge.
*
* @param edge
* the edge
* @return a pair containing the new node and the new edge
*/
private Pair<ElkNode, ElkEdge> split(final ElkEdge edge) {
ElkNode newNode = createNode(edge.getContainingNode());
ElkEdge newEdge = connect(newNode, edge.getTargets().get(0));
ElkConnectableShape oldTarget = edge.getTargets().get(0);
edge.getTargets().remove(0);
newEdge.getTargets().addAll(edge.getTargets());
edge.getTargets().clear();
edge.getTargets().add(oldTarget);
moveTarget(edge, edge.getTargets().get(0), newNode);
ElkGraphUtil.updateContainment(newEdge);
return new Pair<ElkNode, ElkEdge>(newNode, newEdge);
}
use of org.eclipse.elk.graph.ElkConnectableShape in project elk by eclipse.
the class RandomGraphGenerator method moveSource.
/**
* Changes the source of a given edge to a given node.
*
* @param edge
* the edge
* @param node
* the new source node
*/
private void moveSource(final ElkEdge edge, final ElkConnectableShape oldConnectShape, final ElkConnectableShape newConnectShape) {
ElkPort port = null;
ElkNode oldNode = null;
ElkNode newNode = null;
ElkPort oldPort = null;
ElkPort newPort = null;
if (get(GeneratorOptions.ENABLE_PORTS)) {
if (!edge.getSources().isEmpty()) {
if (oldConnectShape instanceof ElkNodeImpl) {
oldNode = (ElkNode) oldConnectShape;
for (ElkConnectableShape source : edge.getSources()) {
if (source instanceof ElkPortImpl) {
port = (ElkPortImpl) source;
if (port.getParent().equals(oldNode)) {
edge.getSources().remove(port);
if (port.getOutgoingEdges().size() == 0 && port.getIncomingEdges().size() == 1) {
port.getParent().getPorts().remove(port);
}
}
}
}
} else if (oldConnectShape instanceof ElkPortImpl) {
oldPort = (ElkPort) oldConnectShape;
if (edge.getSources().contains(oldPort)) {
edge.getSources().remove(oldPort);
}
if (oldPort.getOutgoingEdges().size() == 0 && oldPort.getIncomingEdges().size() == 1) {
oldPort.getParent().getPorts().remove(oldPort);
}
}
}
if (newConnectShape instanceof ElkNodeImpl) {
newNode = (ElkNode) oldConnectShape;
newPort = retrievePort(newNode, true);
} else if (newConnectShape instanceof ElkPortImpl) {
newPort = (ElkPort) oldConnectShape;
}
if (!isHypernode(newNode)) {
// edge.setSourcePort(newPort);
edge.getSources().add(newPort);
}
} else {
// edge.setSource(node);
if (oldConnectShape instanceof ElkNodeImpl) {
oldNode = (ElkNode) oldConnectShape;
} else if (oldConnectShape instanceof ElkPortImpl) {
oldPort = (ElkPort) oldConnectShape;
oldNode = oldPort.getParent();
}
if (edge.getSources().contains(oldNode)) {
edge.getSources().remove(oldNode);
}
if (newConnectShape instanceof ElkNodeImpl) {
newNode = (ElkNode) newConnectShape;
} else if (newConnectShape instanceof ElkPortImpl) {
newPort = (ElkPort) newConnectShape;
newNode = newPort.getParent();
}
edge.getSources().add(newNode);
}
ElkGraphUtil.updateContainment(edge);
}
use of org.eclipse.elk.graph.ElkConnectableShape in project osate2 by osate.
the class ElkGraphBuilder method createElkGraphElementsForConnections.
/**
* Creates ELK edges for connection diagram nodes which are descendants of the specified node.
* Even though the results of the ELK edge routing are not used, it is still important because it affects the placements of shapes.
*/
private void createElkGraphElementsForConnections(final DiagramNode dn, final LayoutMapping mapping) {
for (final DiagramElement de : dn.getChildren()) {
if (de.getGraphic() instanceof AgeConnection) {
final AgeConnection connection = (AgeConnection) de.getGraphic();
// Flow indicators are represented by a node in the container which has a port and an edge connecting that port to the starting element
final ElkConnectableShape edgeStart = getConnectableShape(de.getStartElement(), mapping);
ElkConnectableShape edgeEnd = null;
if (connection.isFlowIndicator) {
// Find the first undocked ancestor for the flow indicator
final DiagramElement undockedContainer = DiagramElementUtil.getUndockedDiagramElement(de.getParent());
if (undockedContainer == null) {
// Ignore the flow indicator if unable to find a containing element which isn't docked.
continue;
}
// Find the ELK shape for the ancestor
final ElkConnectableShape endContainer = getConnectableShape(undockedContainer, mapping);
if (!(endContainer instanceof ElkNode)) {
// Ignore the flow indicator if the container isn't a node.
continue;
}
// Create the node for the end of the flow indicator
final ElkNode endNode = ElkGraphUtil.createNode((ElkNode) endContainer);
endContainer.setDimensions(0, 0);
endNode.setProperty(CoreOptions.NODE_SIZE_CONSTRAINTS, EnumSet.noneOf(SizeConstraint.class));
endNode.setProperty(CoreOptions.NODE_SIZE_OPTIONS, EnumSet.noneOf(SizeOptions.class));
// Create port
final ElkPort endPort = ElkGraphUtil.createPort(endNode);
endPort.setProperty(CoreOptions.PORT_SIDE, PortSide.WEST);
endPort.setX(0);
endPort.setY(0);
endPort.setWidth(0);
endPort.setHeight(0);
edgeEnd = endPort;
} else {
edgeEnd = getConnectableShape(de.getEndElement(), mapping);
}
if (edgeStart != null && edgeEnd != null) {
final ElkConnectableShape start = edgeStart;
final ElkConnectableShape end = edgeEnd;
boolean insideSelfLoopsYo = true;
// An example of this sort of edge is a steady state state transition in the EMV2
if (start == end) {
insideSelfLoopsYo = false;
}
final ElkEdge newEdge = ElkGraphUtil.createSimpleEdge(start, end);
// Allow edges with the same start and end shape because they layout as intended.
if (start == end && start instanceof ElkPort) {
continue;
}
// Ensure the edge has at least one section. Fixes NPE that can occur when laying out connections
// with the same source and destination port.
ElkGraphUtil.createEdgeSection(newEdge);
newEdge.setProperty(CoreOptions.INSIDE_SELF_LOOPS_YO, insideSelfLoopsYo);
mapping.getGraphMap().put(newEdge, de);
createElkLabels(de, newEdge, mapping);
// along with other edges
if (connection.isFlowIndicator && newEdge.getLabels().isEmpty()) {
final ElkLabel spacingLabel = createElkLabel(newEdge, "<Spacing>", new Dimension(10, 10));
if (!layoutConnectionLabels) {
spacingLabel.setProperty(CoreOptions.NO_LAYOUT, true);
}
}
}
}
createElkGraphElementsForConnections(de, mapping);
}
}
Aggregations