0

I'm using GEF and Draw2d to create a graph.

I have have a 3 level structure I want to show, which means:

RootEditPart
/
Level1EditPart
/
Level2EditPart
/
Level3EditPart

Where Level2 has multiple children.

I want to draw connections between the Level3EditParts (within a Level2 container).

What I'm confused about is where I set a line routing algorithm for these connections, and how it gets inherited through the parent/Child EditPart/Figure hierarchy.

Ideally, I'd like to use the ShortestPathConnectionRouter. I tried to use this by setting this as the connection router for the connection layer, using the figure from my Level2EditPart. My understanding was that it would then use the children of this figure as the obstacles to avoid (so it will not draw lines through my other Level3s, but try to avoid them).

It's not working like that though, when I debug the code it looks like in the ShortestPathRoutingAlgorithm is using one co-ordinate system for the Connection Figure (which I'm guessing is the co-ordinate syste for the Connections Layer), and another for the Level3 Figures (the co-ordinate system of their parent. the Level2 Figure). This means that it never manages to work out when it's intersecting one of my Level3s, so never tries to avoid them.

So I'm either misunderstanding the capabilities of the ShortestPathConnectionRouter or I have set it up incorrectly. Can anyone give me some help?

skaffman
  • 398,947
  • 96
  • 818
  • 769
katsharp
  • 2,551
  • 24
  • 27

1 Answers1

0

You cannot set the ShortestPathConnectionRouter as the connection layer's router since you have to provide it a parent figure in the constructor. To use this router, you have to set it for every connection where you want to use it and you must also provide a parent figure which can be easily retrieved like this:

if(getSource().getParent() instanceof MyNodeEditPart) {
    MyNodeEditPart parent = (MyNodeEditPart) getSource().getParent();
    conn.setConnectionRouter(new ShortestPathConnectionRouter(parent.getFigure()));
}

This way it will work.

vainolo
  • 6,907
  • 4
  • 24
  • 47