The example shown below shows how to define a simple format constraint and how to integrate it into a given design command.
Assumed we have a sequence of buttons. For a button, varying appearances are available. But each button which is part of the sequence should have the same appearance.
Such a condition may be expressed as the following format constraint.
"Children of a given container produced by a certain design command should use the same pattern of this command."
Using DCL, it could be expressed this way:
PatternVar formatConstraint samePattern(pvar v,designobj curDO)
select = selectSubtree(0,-1,-1);
{
if ( pVarGetProperty(getPVar(curDO,"PatternVar"))==pVarGetProperty(v) ) {
pVarRestrict(v,pVarGetValue(getPVar(curDO,"PatternVar")));
}
}
To understand how this piece of code works, a little knowledge about the processing of format constraints is useful. They are evaluated before a layout object is constructed, because assertions about format may affect the construction process.
In our sample constraint, patterns are removed from the pattern set of the next command to execute. Then these patterns cannot be selected by the construction process, leading to the desired effect of a more unique layout.
This pattern set is represented by a pattern variable. The domain of such a pattern variable consists in all patterns provided by a certain design command, which is stored as the variable's property.
Then the constraint works as follows: first, the properties (the design commands)of the target variable and an object curDO from the constraint scope are compared. If they are equal, the method pVarRestrict reduces v's domain to the pattern selected for the construction of curDO.
Now we have to notify the design command which represents the sequence that it should use the format constraint specified above.
design sequence() {
pattern first:
...
constraints = samePattern;
{
...
}
}
Now for each child object being added to a sequence the constraint samePattern is checked.
Screenshots below demonstrate the effect of the constraint:

without Constraint

with Constraint
The first picture shows a result created without the constraint: buttons with varying appearance are valid. The second picture shows the same task after activating the constraint: each button has now the same appearance.