Using a constraint solver with DiaCanvas
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Creating a diagram is no fun if the different objects on the canvas can not
create relations with each other.
  The easiest way (at first) seems to hard code the behaviour that is
desirable when objects need to have a relation with each other. This is a
quite limited approach, since it is hard to tailor the objects behaviour to
the expectations of the user. It is also hard to veryfy if the code works
correctly under all circumstances, since the code is scattered among a lot
of different objects.
  When using a constraint solver instead we can solve a bunch of problems at
once:

 1. We are free to create any relation between any object on the canvas.
 2. All constraints on the canvas can easely be verified at once.
 3. Stability no strange behaviour can be expected as long as the constraints
    are constructed properly.

1. Create any relation

We can connect a line to an element (e.g. an UML class), but we can also specify
one object to be always below another object (might be usefull for creating
standardized diagrams).

2. Verification

It is easy to assign new values to a bunch of objects and then solve all
constraints at once (this is extremely handly when multiple obbjects are moved
and relations exist between objects that are moved and objects that are not
moved).

3. Stability

By having all relations between objects represented as constraints it is hard
to create situations where unexpected behaviour occurs, since the code is
centralized and can be tested more easely.


Strength of variables
~~~~~~~~~~~~~~~~~~~~~
Every variable is assigned a strength. In a constraint solving situation the
weakest variable will be solved.


Implementation implications
~~~~~~~~~~~~~~~~~~~~~~~~~~~
I (Arjan) have created a small constraint solver based on GObject. The big
advantage is that you can send signals between the different parts of the
constraint solver, this will keep the code clean.

The solver consists of three classes:
- DiaVariable
- DiaConstraint
- DiaSolver

DiaVariable
~~~~~~~~~~~
A Diavariable hold a variable value. If the value changes the "changed_internal"
signal is emited. This signal is emited every time the variable is assigned a
new value.
  The DiaVariable also has a "changed" signal. This signal is emited if its
value is changed by the constraint solver. You usually want to connect to this
signal.

DiaConstraint
~~~~~~~~~~~~~
A Constraint consists of an linear expression. For this purpose a helper class
"DiaExpression" is created. An expression is an array of variable * contant
pairs. This will result in an expression like:

	a*x + b*y +c = 0

A constraint will react on DiaVariable's "changed_internal" signal by
emiting "need_resolve".

DiaSolver
~~~~~~~~~
The solver is the most interesting class of all: this is where the actual work
is done. You can add constraints to the solver. The solver will connect to
the constraints "need_resolve" signal. If a constraint emits the "need_resolve"
signal the constraint will be marked.
  If the resolve() function is called the solver tries to satisfy all
constraints. This is done by looking for the weakest variable in the constraint.
If weakest variable is already edited the constraint is not resolved again.


