Home » Eclipse Projects » GEF » Connection: how to update control points
Connection: how to update control points [message #1794083] |
Thu, 23 August 2018 09:56 |
Shenwei Zheng Messages: 22 Registered: December 2016 |
Junior Member |
|
|
Hi all,
I defined a connection with orthogonal router. The start dynamic anchor has a bottom middle computation strategy and the end dynamic anchor has a top middle computation strategy. I added one control point, with which I want to specify the position of the horizontal line of the connection. The left image is what I desired but sometime is came out with the right one.
related code:
DynamicAnchor startAnchor = new DynamicAnchor(startRectangle);
DynamicAnchor startAnchor = new DynamicAnchor(endRectangle);
startAnchor.setComputationStrategy(new BottomMiddleStrategy(0, 0));
endRectangle.setComputationStrategy(new TopMiddleStrategy(0, 0));
Connection connection = new Connection();
connection.setRouter(new OrthogonalRouter());
connection.setStartAnchor(startAnchor);
connection.setEndAnchor(endAnchor);
connection.addControlPoint(0, new Point(endRectangle.getTranslateX() + endRectangle.getWidth() / 2, endRectangle.getTranslateY() -50);
BottomMiddleStrategy.java
public class BottomMiddleStrategy implements IComputationStrategy
{
private double offsetWidth;
private double offsetHeihgt;
public BottomMiddleStrategy(double offSetWidth, double offSetHeight)
{
this.offsetWidth = offSetWidth;
this.offsetHeihgt = offSetHeight;
}
@Override
public Point computePositionInScene(Node anchorage, Node anchored, Set<Parameter< ? >> parameters)
{
double width = anchorage.getLayoutBounds().getWidth() / 2 + anchorage.getLayoutBounds().getMinX() + offsetWidth;
double height = anchorage.getLayoutBounds().getHeight() + anchorage.getLayoutBounds().getMinY() + offsetHeihgt;
return NodeUtils.localToScene(anchorage, new Point(width, height));
}
@Override
public Set<Class< ? extends Parameter< ? >>> getRequiredParameters()
{
Set<Class< ? extends Parameter< ? >>> parameters = new HashSet<>();
parameters.add(AnchorageReferenceGeometry.class);
parameters.add(AnchoredReferencePoint.class);
return parameters;
}
}
When the position of start or end is changed, I have to manualy update the control point. I tried three variants:
1. remove my defined control point and add it again. But it looks like there too more control points. As my understanding, when I added a single control point, connection will add other control points to make the connection to be orthogonal. When the 'real' control point is removed, other control points stay in the connection. So this variant will not work. (Not sure if I am correct)
if (connection.getControlPoint(0) != null)
{
connection.removeControlPoint(0);
}
connection.addControlPoint(0, new Point(endRectangle.getTranslateX() + endRectangle.getWidth() / 2, endRectangle.getTranslateY() -50);
2. remove all controls points and add the defined control point again. But sometimes I got the right image.
connection.removeAllControlPoints();
connection.addControlPoint(0, new Point(endRectangle.getTranslateX() + endRectangle.getWidth() / 2, endRectangle.getTranslateY() -50);
3. based on the second variant, I added a second control point. But I got an exception which I cannot find out where is the problem.
java.lang.IllegalArgumentException: Index out of range (index: 0, size: 0).
at org.eclipse.gef.fx.nodes.Connection.removeControlPoint(Connection.java:1499)
at org.eclipse.gef.fx.nodes.Connection.removeAllControlPoints(Connection.java:1391)
Maybe there is a simple way to have a orthogonal connection as I desired. Does someone have a better solution? Thank you.
Best Regards
Shenwei
[Updated on: Thu, 23 August 2018 09:59] Report message to a moderator
|
|
|
Re: Connection: how to update control points [message #1801047 is a reply to message #1794083] |
Fri, 11 January 2019 16:19 |
|
Hi Shenwei,
the problem should be within OrthogonalRouter not manipulating segments that are already orthogonal but overlapping an anchorage outline, as noted in a comment in the implementation:
https://github.com/eclipse/gef/blob/eb158dd82e9ccac54f943df7364f930d12544430/org.eclipse.gef.fx/src/org/eclipse/gef/fx/nodes/OrthogonalRouter.java#L249
// given the direction, determine if points have to be added
if (isSufficientlyHorizontal(outDirection)
|| isSufficientlyVertical(outDirection)) {
// XXX: We may have to adjust an already orthogonal segment in
// case it overlaps with an anchorage outline.
// currentDirection = routeOrthogonalSegment(connection,
// controlPointManipulator, currentDirection, i,
// currentPoint);
return super.route(cpm, inDirection, outDirection);
} else {
return routeNonOrthogonalSegment(cpm.getConnection(), cpm,
inDirection, outDirection, cpm.getIndex(), cpm.getPoint());
}
The API is open for extension, so you can try to override OrthogonalRouter#route() to 1) get a better understanding of the problem at hand, and 2) eventually fix the problem by implementing another constraint w.r.t. segments overlapping anchorage outlines.
For investigation, it would be beneficial if you could provide a test case that will yield undesired routing.
Best regards,
Matthias
|
|
| |
Goto Forum:
Current Time: Thu Oct 03 23:55:41 GMT 2024
Powered by FUDForum. Page generated in 0.04137 seconds
|