use of org.eclipse.elk.graph.ElkEdgeSection in project elk by eclipse.
the class Issue546Test method testEdgeStartsAtPort.
@Test
public void testEdgeStartsAtPort(final ElkNode graph) {
// We'll look at all edges
LinkedList<ElkNode> nodeQueue = new LinkedList<>();
nodeQueue.add(graph);
while (!nodeQueue.isEmpty()) {
ElkNode currNode = nodeQueue.poll();
nodeQueue.addAll(currNode.getChildren());
// edge is connected to ports
for (ElkEdge edge : currNode.getContainedEdges()) {
// Retrieve absolute port rectangle, slightly enlarged
ElkPort srcPort = ElkGraphUtil.connectableShapeToPort(edge.getSources().get(0));
KVector srcPortPos = ElkUtil.absolutePosition(srcPort);
Rectangle2D.Double srcPortRect = new Rectangle2D.Double(srcPortPos.x - TOLERANCE, srcPortPos.y - TOLERANCE, srcPort.getWidth() + 2 * TOLERANCE, srcPort.getHeight() + 2 * TOLERANCE);
// Retrieve absolut edge source position
ElkEdgeSection section = edge.getSections().get(0);
KVector srcPoint = new KVector(section.getStartX(), section.getStartY());
ElkUtil.toAbsolute(srcPoint, currNode);
// Ensure that the source point is roughly on the port anchor
assertTrue("Source point " + srcPoint + " is not close enough to port " + srcPortRect, srcPortRect.contains(srcPoint.x, srcPoint.y));
}
}
}
use of org.eclipse.elk.graph.ElkEdgeSection in project elk by eclipse.
the class ElkGraphLayoutTransferrer method applyEdgeLayout.
/**
* Applies layout information computed for the given edge.
*
* @param ledge
* the edge that has the layout information.
* @param routing
* the kind of routing applied to edges.
* @param offset
* offset to add to coordinates.
* @param additionalPadding
* the additional insets that may have to be taken into account for hierarchical that go
* into the bowels of their source node. These are already included in the offset, but
* are required separately.
*/
private void applyEdgeLayout(final LEdge ledge, final EdgeRouting routing, final KVector offset, final LPadding additionalPadding) {
ElkEdge elkedge = (ElkEdge) ledge.getProperty(InternalProperties.ORIGIN);
// untouched if another routing algorithm is selected.
if (elkedge == null) {
return;
}
KVectorChain bendPoints = ledge.getBendPoints();
// The standard offset may need to be modified if the edge needs to end up in a coordinate system of
// a graph in a higher hierarchy level
KVector edgeOffset = new KVector(offset);
edgeOffset.add(calculateHierarchicalOffset(ledge));
// Adapt the offset value and add the source port position to the vector chain
KVector sourcePoint;
if (LGraphUtil.isDescendant(ledge.getTarget().getNode(), ledge.getSource().getNode())) {
// The external port's anchor position, relative to the node's top left corner
LPort sourcePort = ledge.getSource();
sourcePoint = KVector.sum(sourcePort.getPosition(), sourcePort.getAnchor());
// The source point will later have the passed offset added to it, which it doesn't actually
// need, so we subtract it now (notice that the external port's position was already relative
// to its node's top left corner, while adding the offset now would mean that it was relative
// to the top left corner + its insets area)
sourcePoint.sub(offset);
} else {
sourcePoint = ledge.getSource().getAbsoluteAnchor();
}
bendPoints.addFirst(sourcePoint);
// Add the target port position to the vector chain, including additional offset
KVector targetPoint = ledge.getTarget().getAbsoluteAnchor();
if (ledge.getProperty(InternalProperties.TARGET_OFFSET) != null) {
targetPoint.add(ledge.getProperty(InternalProperties.TARGET_OFFSET));
}
bendPoints.addLast(targetPoint);
// Translate the bend points by the offset and apply the bend points
bendPoints.offset(edgeOffset);
// Give the edge a proper edge section to store routing information
ElkEdgeSection elkedgeSection = ElkGraphUtil.firstEdgeSection(elkedge, true, true);
elkedgeSection.setIncomingShape(elkedge.getSources().get(0));
elkedgeSection.setOutgoingShape(elkedge.getTargets().get(0));
ElkUtil.applyVectorChain(bendPoints, elkedgeSection);
// Apply layout to labels
for (LLabel llabel : ledge.getLabels()) {
ElkLabel elklabel = (ElkLabel) llabel.getProperty(InternalProperties.ORIGIN);
elklabel.setWidth(llabel.getSize().x);
elklabel.setHeight(llabel.getSize().y);
elklabel.setLocation(llabel.getPosition().x + edgeOffset.x, llabel.getPosition().y + edgeOffset.y);
elklabel.setProperty(LabelDummySwitcher.INCLUDE_LABEL, llabel.getProperty(LabelDummySwitcher.INCLUDE_LABEL));
}
// Copy junction points
KVectorChain junctionPoints = ledge.getProperty(LayeredOptions.JUNCTION_POINTS);
if (junctionPoints != null) {
junctionPoints.offset(edgeOffset);
elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, junctionPoints);
} else {
elkedge.setProperty(LayeredOptions.JUNCTION_POINTS, null);
}
// Mark the edge with information about its routing
if (routing == EdgeRouting.SPLINES) {
// SPLINES means that bend points shall be interpreted as control points for splines
elkedge.setProperty(LayeredOptions.EDGE_ROUTING, EdgeRouting.SPLINES);
} else {
// null means that bend points shall be interpreted as bend points
elkedge.setProperty(LayeredOptions.EDGE_ROUTING, null);
}
}
use of org.eclipse.elk.graph.ElkEdgeSection in project elk by eclipse.
the class ElkGraphUtil method firstEdgeSection.
/**
* Returns the edge's first edge section or creates one if there is none.
*
* @param edge the edge whose first edge section to retrieve.
* @param resetSection {@code true} if all bend points should be removed and the location reset on the section
* before it is returned.
* @param removeOtherSections {@code true} if all the other edge sections, if any, should be removed.
* @return the first edge section.
*/
public static ElkEdgeSection firstEdgeSection(final ElkEdge edge, final boolean resetSection, final boolean removeOtherSections) {
if (edge.getSections().isEmpty()) {
// Create and return a new section
return createEdgeSection(edge);
} else {
// Retrieve the first section
ElkEdgeSection section = edge.getSections().get(0);
if (resetSection) {
section.getBendPoints().clear();
section.setStartLocation(0, 0);
section.setEndLocation(0, 0);
}
if (removeOtherSections) {
List<ElkEdgeSection> sections = edge.getSections();
while (sections.size() > 1) {
sections.remove(sections.size() - 1);
}
}
return section;
}
}
use of org.eclipse.elk.graph.ElkEdgeSection in project elk by eclipse.
the class OverallLayoutTest method testEdgeOrthogonality.
/**
* Tests if the edge routing produced perfectly orthogonal edges. This test only makes sense if
* the orthogonal edge router is used.
*/
@Test
public void testEdgeOrthogonality() {
LinkedList<KVector> bendPoints = new LinkedList<>();
for (ElkEdge edge : simpleGraph.getContainedEdges()) {
for (ElkEdgeSection section : edge.getSections()) {
// Assemble list of bend points
bendPoints.clear();
bendPoints.add(new KVector(section.getStartX(), section.getStartY()));
section.getBendPoints().stream().map(bp -> new KVector(bp.getX(), bp.getY())).forEach(vec -> bendPoints.add(vec));
bendPoints.add(new KVector(section.getEndX(), section.getEndY()));
if (bendPoints.size() >= 2) {
// Check whether the bend points run orthogonally
Iterator<KVector> bendPointIterator = bendPoints.iterator();
KVector prevBendPoint = bendPointIterator.next();
while (bendPointIterator.hasNext()) {
KVector currBendPoint = bendPointIterator.next();
assertTrue(prevBendPoint.x == currBendPoint.x || prevBendPoint.y == currBendPoint.y);
prevBendPoint = currBendPoint;
}
}
}
}
}
use of org.eclipse.elk.graph.ElkEdgeSection in project elk by eclipse.
the class GmfDiagramLayoutConnector method setEdgeLayout.
/**
* Stores the layout information of the given connection edit part into an edge layout.
*
* @param edge
* an edge layout
* @param connection
* a connection edit part
* @param offset
* offset to be subtracted from coordinates
*/
protected void setEdgeLayout(final ElkEdge edge, final ConnectionEditPart connection, final KVector offset) {
Connection figure = connection.getConnectionFigure();
PointList pointList = figure.getPoints();
// our edge will have exactly one edge section
ElkEdgeSection edgeSection = ElkGraphUtil.createEdgeSection(edge);
// source point
Point firstPoint = pointList.getPoint(0);
edgeSection.setStartX(firstPoint.x - offset.x);
edgeSection.setStartY(firstPoint.y - offset.y);
// bend points
for (int i = 1; i < pointList.size() - 1; i++) {
Point point = pointList.getPoint(i);
ElkGraphUtil.createBendPoint(edgeSection, point.x - offset.x, point.y - offset.y);
}
// target point
Point lastPoint = pointList.getPoint(pointList.size() - 1);
edgeSection.setEndX(lastPoint.x - offset.x);
edgeSection.setEndY(lastPoint.y - offset.y);
// We would set the modified flag to false here, but that doesn't exist anymore
}
Aggregations