GetSketch:
PUBLIC
PROC [control: Control]
RETURNS [sketch: IntegerPairSequences] ~ {
nSketch: NAT ¬ 0;
chain: Chain ¬ NARROW[control.sketchRef];
chainIntegerPairs: IntegerPairSequence ¬ chain.pairs;
start: Run ¬ chain.firstRun;
FOR run: Run ¬ start, run.next WHILE run # NIL DO nSketch ¬ nSketch+1; ENDLOOP;
sketch ¬ NEW[IntegerPairSequencesRep[nSketch]];
FOR run: Run ¬ start, run.next
WHILE run #
NIL
DO
n: INTEGER ¬ 0;
sketchIntegerPairs: IntegerPairSequence ¬
NEW[IntegerPairSequenceRep[run.stop-run.start+1]];
sketchIntegerPairs.length ¬ sketchIntegerPairs.maxLength;
sketch[sketch.length] ¬ sketchIntegerPairs;
sketch.length ¬ sketch.length+1;
FOR r:
NAT
IN [run.start..run.stop]
DO
sketchIntegerPairs[n] ¬ chainIntegerPairs[r];
n ¬ n+1;
ENDLOOP;
ENDLOOP;
};
SetSketch:
PUBLIC
PROC [control: Control, sketch: IntegerPairSequences, repaint:
BOOL ¬
TRUE] ~ {
run: Run ¬ NIL;
iIntegerPair, nIntegerPairs: CARDINAL ¬ 0;
chain: Chain ¬ NARROW[control.sketchRef];
FOR n: INT IN [0..sketch.length) DO nIntegerPairs ¬ nIntegerPairs+sketch[n].length; ENDLOOP;
IF nIntegerPairs > chain.pairs.maxLength THEN chain.pairs ¬ NEW[IntegerPairSequenceRep[nIntegerPairs]];
FOR n:
INT
IN [0..sketch.length)
DO
pairs: IntegerPairSequence ¬ sketch[n];
FOR i: INT IN [0..pairs.length) DO chain.pairs[i+iIntegerPair] ¬ pairs[i]; ENDLOOP;
IF run #
NIL
THEN {run.next ¬ NEW[RunRep]; run ¬ run.next}
ELSE chain.firstRun ¬ run ¬ NEW[RunRep];
run.start ¬ iIntegerPair;
iIntegerPair ¬ iIntegerPair+pairs.length;
run.stop ¬ iIntegerPair-1;
ENDLOOP;
IF repaint THEN RequestPaint[control, FALSE, NIL];
};