A constraint is a relation between two objects that must be maintained. A constraint is defined by a relation object. Class relation is a super-class for all predefined relations.
Constraints deal properly with cycles. Contradictory constraints lead to unpredictable results.
Constraints are commonly used to maintain relations between
graphicals. They can also be used to maintain a relation between dialog
objects and
model objects. The example below illustrates both usages.
:- pce_global(@center, new(identity(center))).
constraint_demo :-
new(P, picture('Constraint Demo')),
send(new(D, dialog), below, P),
send(P, display, new(B1, box(100,100))),
send(P, display, new(B2, box(50,50))),
send_list([B1, B2], recogniser,
handler_group(new(resize_gesture),
new(move_gesture))),
new(_, constraint(B1, B2, @center)),
send(D, append, new(S1, slider(center_x, 0, 500, 200))),
send(D, append, new(S2, slider(center_y, 0, 500, 200))),
send_list([S1, S2], drag, @on),
send(D, append, button(quit, message(D, destroy))),
new(_, constraint(S1, B1,
identity(selection, center_x))),
new(_, constraint(S2, B2,
identity(selection, center_y))),
send(D, open).
Bugs:
Currently, the constraint mechanism implies that everytime a send-message is accepted by a constrainted object, the associated relation is evaluated. This is unnecessary expensive and limits the application area of constraints to exist only between objects that do not receive time-critical messages.
It is not possible to create a relation with ITSELF. The following does
make_square(S, W) :-
new(S, box(W,W)),
new(_, constraint(S, S, indentity(width, height))).
<-to
consistent with constraint<-from.
The constraint may be found though object<-all_constraints
from either constrained object.
forwards Only propagate constraint <-from to constraint<-tobackwards Only propagate constraint <-to to constraint<-fromnone Propagate both ways front constraint <-from has changed. Avoid loopback constraint <-to has changed. Avoid loop
relation ->createUpon establishing. relation ->forwardsconstraint <-from has changedrelation ->backwardsconstraint <-to has changed
-from
<-from
and constraint<-to),
the constraint<-relation
describing the constraint and optionally whether the constraint should
propagate changes in both or only one direction. By default a constraint
propagates changes either way. With propagate equals forwards
only changes to constraint<-from
are propagated to
constraint<-to
and with propagate equals backwards the other way around.