Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Need guidance porting connection router from Zest 1.7 to current
Need guidance porting connection router from Zest 1.7 to current [message #1799811] Fri, 14 December 2018 06:12 Go to next message
Gerald Rosenberg is currently offline Gerald RosenbergFriend
Messages: 106
Registered: July 2009
Senior Member
Have a Zest 1.7 connection router that I am trying to port to GEF/Zest 5. Looks like the two Gef routers are the only examples available. Unfortunately, being rather new to Gef 5, did not find them very helpful at this point.

Can you please provide some guidance, preferably an outline of the steps necessary to complete the port.

(If it helps, the working Zest 1.7 router is attached.)

Thanks!


import java.util.List;

import javafx.geometry.Bounds;

import org.eclipse.gef.fx.nodes.AbstractRouter;
import org.eclipse.gef.fx.nodes.Connection;
import org.eclipse.gef.geometry.planar.Point;

//
// +-----------+
// |           |
// |           +---+\
// |           |     \         +--------------+
// +-----------+      \        |              |
//                     \+----->+              |
//                             |              |
//                             +--------------+
//
public class BranchedConnectionRouter extends AbstractRouter {

	private int vDst = 20;
	private int begOffset = 16;
	private int endOffset = 24;

	private class Branch {
		Point beg;
		Point bend1;
		Point bend2;
		Point end;

		Branch(Point beg, Point end) {
			this.beg = beg;
			this.end = end;
			bend1 = new Point(beg.x + begOffset, beg.y);
			bend2 = new Point(end.x - endOffset, end.y);
		}
	}

	public BranchedConnectionRouter() {
		super();
	}

	@Override
	protected Point getAnchoredReferencePoint(List<Point> points, int index) {
		if (index < 0 || index >= points.size()) throw new IndexOutOfBoundsException();

		Connection conn = getConnection();
		Branch branch = calcBranchPath(conn);

		// Q: how to proceed here ???

		return null;
	}

	// adjusting bendpoints for appearence
	private Branch calcBranchPath(Connection conn) {
		Branch branch = new Branch(conn.getStartPoint(), conn.getEndPoint());

		Bounds begBounds = conn.getStartAnchor().getAnchorage().getBoundsInLocal();
		Bounds endBounds = conn.getEndAnchor().getAnchorage().getBoundsInLocal();
		double height = (begBounds.getHeight() + endBounds.getHeight()) / 4;

		if (branch.beg.y + vDst < branch.end.y - vDst) {
			branch.bend1.y += vDst;
			branch.bend2.y -= vDst;

		} else if (branch.beg.y + height < branch.end.y) {
			double midY = (branch.end.y - branch.beg.y) / 2;
			branch.bend1.y += midY;
			branch.bend2.y -= midY;

		} else if (branch.beg.y <= branch.end.y) {
			branch.bend2.y += vDst;
			branch.bend1.y = branch.bend2.y;

		} else if (branch.beg.y - vDst > branch.end.y + vDst) {
			branch.bend1.y -= vDst;
			branch.bend2.y += vDst;

		} else if (branch.beg.y - height > branch.end.y) {
			double midY = (branch.beg.y - branch.end.y) / 2;
			branch.bend1.y -= midY;
			branch.bend2.y += midY;

		} else if (branch.beg.y > branch.end.y) {
			branch.bend2.y -= vDst;
			branch.bend1.y = branch.bend2.y;
		}

		return branch;
	}
}
Re: Need guidance porting connection router from Zest 1.7 to current [message #1802535 is a reply to message #1799811] Mon, 11 February 2019 15:59 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Gerald,

I am not fully aware of the Zest 1.x functionality. Maybe you need to give me a heads-up. (And take the following info with a grain of salt.)

Connection functionality was moved to GEF FX where Connection is used in conjunction with Anchor, Router, and Interpolator as follows:
- An Anchor is responsible for computing a position in dependence on arbitrary parameters.
- The Router is responsible for adjusting these computed positions in order to fulfill some routing constraints.
- The final set of points is passed onto the Interpolator that is responsible for generating a curve geometry (GEF Geometry) based on these points (not necessarily through these points).

Hence, the main abstractions capable of creating a branched connection would be router and interpolator.

I believe the router mechanism is way too complicated due to the complex anchor mechanism. But you could extend StraightRouter to make it easier. Then, you can override the protected method route(ControlPointManipulator cpm, Vector inDirection, Vector outDirection) that returns the vector that leads to the next point. The current point can be accessed using cpm.getPoint().

However, you could also implement an interpolator that adds branch points. The interface is much simpler, because an interpolator does not need to work with anchors, really.

Maybe you should start by implementing an interpolator and see how far you can get.

Best regards,
Matthias
Previous Topic:Change parent of child on GEF5
Next Topic:Part+Visuals
Goto Forum:
  


Current Time: Sun Dec 01 20:39:40 GMT 2024

Powered by FUDForum. Page generated in 0.03276 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top