VirtualConnectionPoints

Webs: Faemalia -:- Greatprawn -:- Playground -:- Technical -:- Tweak
Technical Web Sections: Register -:- Users -:- Changes -:- Index -:- Search -:- Statistics

Quite simple: The user should be able to drag a line onto an object and drop it there to connect. Connection points should be only for marking specific places.

Problems: Backward compatibility -- how do we store this virtual connpoint?

What if we want e.g. zigzaglines pointing to other parts of the object that straight towards the center? Do we want to support that this way now, or should we just let that be done with explicit connpoints?

There was some work in this direction under the 'line gap' code, however I'm not sure if that's the best approach. In particular, it doesn't work for other than lines, we would want this virtual connpoint to work for any connector.

This would require ObjectHighlighting in order to be comprehensible for the user.

-- LarsClausen - 19 Mar 2004

ObjectHighlighting works in the dev branch as of now. Used when connecting. Quite nifty. So we can start looking at virtual connpoints any time now.

Naming connection points

Starting to look at the virtual connection points. First thing is to be able to name connectionpoints, that way we can get away from the backwards compatibility problems. Will probably end up making loading a little slower, if we have to search each object's cp's to find the right name, but I think it'll be worth it. Internally in Dia we will still have the index, so we won't be slowed down by this. Note that naming can also be used for other things, such as naming the connectors on a CPU.

Using names in general allows us to add cp's without having to worry about what happens if the object wants to add a cp as well. It does mean, however, that objects that currently use the ordering of cp's (such as UML Class) will have to name them with their numbers, or they'll get messed up.

Note that by naming the old cp's with their numbers, newly created diagrams can still be read by old versions of Dia and have those cp's work. New cp's, of course, will not work.

Current test implementation (in the dev branch) uses the ordering for cp's that are saved as just a number, and other cp's are searched for. It'd help speed things up a little if we can keep that, but it's not a requirement. Since virtual connectionpoints should be added after the object is created, I think we're ok. Except maybe for objects like UML Class that can have more cp's depending on its data, in which case we would want to be sure that the class-generated cp's are placed in their proper order, i.e. before virtual cp's, when loaded.

Important to remember that the number-name of a cp should correspond to the old placement, and not simply take the index given. Otherwise the addition of a virtual cp will make later regular cp's not work.

I could of course ruthlessly break every single connection in existence. However, I think I will reserve that option for a time when there's no other way out.

Virtual connection points

Now that we can add connection points without worry, let's think about what virtual connection points we want. We have found three different kinds:

Of these, the latter two need to work with the resize functionality, which makes them harder. Most things just resize easily, and the cp's can be automatically calculated based on the ratio. Some things like the UML Component, have areas that don't resize with the rest. How should the cp's deal with these?

The center-connected cp's don't have to worry about those things, as long as they can get a working 'distance from object' number. That'll allow them to have the connector go to exactly the edge of the object regardless of how it resizes, and will remove the need for twiddling the connectors when objects are rearranged. The lines will also mostly go in at a reasonable angle, except for really strange objects. Main downside is that the user cannot have lines go in 'side by side' in parallel. For that, they'll still have to use regular cp's.

I absolutely, totally, 100% want the center-connected points, especially after the dogfood I had this morning. The others are, IMHO, not nearly as useful, as the suffer from the rearrangement problem that normal cp's also have, and I wouldn't mind Dia 1.0 not having those.

Implementation of center-connected virtual connection points.

We need three things for center-connected virtual connection points (center-points!):

Creation is simple: When you drop a line end over an object, a new center-point is created, and the line is connected to it.

Deletion is just as simple: When you disconnect the line from a center-point, that center-point disappears. Obviously, only one line can connect to any one center-point.

Update is the interesting part. Just after creation, and every time either the connected object or the other end of the line moves, the position must be updated. Note that normal cp's don't move when the other end of the line moves, but since the placement here depends on the line angle, we have to update it.

So here's how to update: We make a line that goes from the center to the "other end" of the connector ("other end" defined below). Along that line, we use the distance_from function to do binary search for the edge of the object, i.e. where the distance to the object is >0 but <0.00001 or so. The center-point moves to there, along with the connector.

What is the "other end"? For a line, it's just the other end. For a polyline or zigzagline, it's the other end of the last segment. For a bezier or arc, it's more complex, and I will think about that later.

There's potential interference between this and the autorouting for zigzaglines. Must think about that, too.

-- LarsClausen - 23 Mar 2004

After some pushing and half a patch I got the Right Way [tm] to do center-points (known as main points). It's two flags on a connection point, one that says that the connection gathers handles from the entire object, and one that says that the line connected should stop at the edge. The two together allows the user to 'point at an object' rather than at a connection point, if so desired. It also lets objects be rearranged without having to rearrange lines in most instances. Those two behaviours are what I mostly wanted, it makes simple diagrams simpler.

It is implemented by adding another connectionpoint to most objects, manually going through the code. Mostly, the cp is just in the middle of the object, though in some cases (polygon, beziergon) the middle may be outside the object:( The lines then take care of going only to the edge (autogapping).

-- LarsClausen - 03 Apr 2005


Edit -:- Attach -:- Ref-By -:- Printable -:- More