I’m still busy adapting the commands that apply changes to the model (remember : the model is the object graph behind a diagram). A couple of days ago, I started reworking the ‘create connector command‘; this is the command that gets executed when you use the ‘Connector tool‘ to add connectors to a line that represents a set (and that does not yet contain connectors).
It appeared that the way in which the connectors are added to the diagram isn’t that nice in some situations. For instance, take the OFFICE-EMPLOYEE set in the EMPSCHM demo schema : when we use the Connector tool and click in the middle of the first line fragment (the one that starts on the OFFICE record and goes down to the first bendpoint) :
Besides the fact that both connectors are put to the right of where I clicked the mousebutton (which is acceptable), all the line fragments seem to go crazy… the diagram editor just inserts the connectors after the last bendpoint (in a straight line situation, we wouldn’t have this problem).
What would be nicer is the diagram editor inserting the connectors before the first bendpoint, like this :
Because the connectors are now inserted before the first bendpoint, the flow of each line fragment is retained. Moreover, the connectors are inserted one on top of the other, which is also a requirement to keep the lines flow smoothly.
So this is what I’m currently playing with 🙂
At first, I had no clue of how to figure out on which line fragment the mousebutton is clicked; it has been ages that I’ve been doing that kind of math… Fortunately, thanks to Google (and StackOverflow) this seemed easy enough : the first thing you have to do is to ‘imagine’ a triangle ABC for each line fragment, with the following points :
- A : the point at which the line fragment starts (this is a point somewhere on a record or index, or a bendpoint)
- B : the point at which the line fragment ends (this is a point somewhere on a record, or a bendpoint)
- C : the point at which the mouse button was clicked.
The next thing you do is calculate the surface (area) for each of these triangles (1 triangle per line fragment, in our example that’s 3 calculations) :
[ Ax * (By – Cy) + Bx * (Cy – Ay) + Cx * (Ay – By) ] / 2
When the surface (area) equals to zero, that line fragment contains the point at which the mousebutton was clicked. Bendpoints are tricky because the points at which they occur always belong to 2 line fragments. The Eclipse Graphical Editing Framework (GEF) also takes a margin of 2 pixels into account because it can be difficult to point at an exact point in the diagram. So… the smallest surface is the winner here; that’s how the diagram editor detects the line fragment on which it has to put the connectors.
The diagram editor now also takes the direction of the target line fragment into account to decide whether the connectors should go side by side or one on top of the other.
The next version of the diagram editor will include all of these improvements.
There are other areas in which the diagram editor can be improved for what is line handling is concerned; please let me know what bothers you the most !
Merry Christmas 🙂