DIRECTORY CD, CDBasics, CDCSUtil, CDErrors, CDOps, CStitching, D2Basic, Rope; CDCSUtilImpl: CEDAR PROGRAM IMPORTS CD, CDBasics, CDErrors, CDOps, CStitching EXPORTS CDCSUtil = BEGIN OPEN CDCSUtil; didStop: SIGNAL = CODE; New: PUBLIC PROC [filledWith: REF_NIL, data: REF _ NIL, stopFlag: REF BOOL _ NIL] RETURNS [plane: Tesselation] = { plane _ CStitching.NewTesselation[data, stopFlag]; CStitching.ChangeRect[plane, CDBasics.universe, filledWith]; }; Dispose: PUBLIC PROC [basis: Tesselation] = { IF basis#NIL THEN CStitching.ChangeRect[basis, CDBasics.universe]; }; StateRec: TYPE = RECORD [ scale: Scale, lLa: ARRAY CD.Layer OF StateLayerList _ ALL[NIL] ]; StateLayerList: TYPE = LIST OF StateLayer _ NIL; StateLayer: TYPE = RECORD [plane: Tesselation _ NIL, delta: INT _ 0]; UndividedScaleCsFromCDRect: PROC [r: CD.Rect, off: CD.Position, num: INT] RETURNS [rect: D2Basic.Rect] = INLINE { rect _ [ x1: (r.x1+off.x)*num, x2: (r.x2+off.x)*num, y1: (r.y1+off.y)*num, y2: (r.y2+off.y)*num ]; }; ScaleCsFromCDRect: PROC [r: CD.Rect, off: CD.Position, num: INT, denom: INT] RETURNS [rect: D2Basic.Rect] = INLINE { rect _ [ x1: (r.x1+off.x)*num/denom, x2: (r.x2+off.x)*num/denom, y1: (r.y1+off.y)*num/denom, y2: (r.y2+off.y)*num/denom ]; }; GoodScaleCsFromCDRect: PROC [r: CD.Rect, off: CD.Position, num: INT, denom: INT] RETURNS [rect: D2Basic.Rect] = INLINE { max: INT = LAST[INT]/num-1; range: PROC[n: INT] RETURNS [INT] = INLINE { RETURN [MIN[MAX[n, -max], max]] }; rect _ [ x1: range[r.x1+off.x]*num/denom, x2: range[r.x2+off.x]*num/denom, y1: range[r.y1+off.y]*num/denom, y2: range[r.y2+off.y]*num/denom ]; }; MyDrawRect: PROC [pr: CD.DrawRef, r: CD.Rect, l: CD.Layer] = { state: REF StateRec _ NARROW[pr.devicePrivate]; IF state.lLa[l]#NIL THEN { rect: CD.Rect = IF state.scale.denom=1 THEN UndividedScaleCsFromCDRect[r, state.scale.off, state.scale.num] ELSE ScaleCsFromCDRect[r, state.scale.off, state.scale.num, state.scale.denom]; FOR sl: StateLayerList _ state.lLa[l], sl.rest WHILE sl#NIL DO CStitching.ChangeRect[plane: sl.first.plane, rect: CDBasics.Extend[rect, sl.first.delta], new: $covered] ENDLOOP; }; }; Make: PUBLIC PROC [what: CDWorld, layers: Layers, into: Tesselation_NIL] RETURNS [Tesselation] = { cf: REF CD.ContextFilter _ NEW[CD.ContextFilter_ALL[FALSE]]; maxGrow: CD.Number _ 0; pr: CD.DrawRef _ CD.CreateDrawRef[[ stopFlag: what.stopFlag, design: what.design, drawChild: what.drawChild, drawContext: what.drawContext, drawRect: MyDrawRect, contextFilter: cf ]]; state: REF StateRec; state _ NEW[StateRec_[scale: what.scale]]; pr.devicePrivate _ state; IF into=NIL THEN into _ New[stopFlag: pr.stopFlag]; FOR l: Layers _ layers, l.rest WHILE l#NIL DO sl: StateLayer _ [ plane: IF l.first.plane=NIL THEN into ELSE l.first.plane, delta: l.first.deltaDiameter ]; cf[l.first.source] _ TRUE; state.lLa[l.first.source] _ CONS[sl, state.lLa[l.first.source]]; maxGrow _ MAX[maxGrow, l.first.growClip]; ENDLOOP; pr.interestClip _ CDBasics.Extend[what.restrict, MAX[maxGrow, what.minGrowClip]]; IF what.ob#NIL THEN { CD.DrawOb[pr, what.ob]; --first call is not through what.drawChild } ELSE CDOps.DrawDesign[what.design, pr]; RETURN [into]; }; BackRect: PUBLIC PROC [what: CDWorld, csRect: CStitching.Rect] RETURNS [CD.Rect] = { n: INT = what.scale.num; RETURN [[ x1: (csRect.x1*what.scale.denom)/n - what.scale.off.x, x2: (csRect.x2*what.scale.denom+n-1)/n - what.scale.off.x, y1: (csRect.y1*what.scale.denom)/n - what.scale.off.y, y2: (csRect.y2*what.scale.denom+n-1)/n - what.scale.off.y ]]; }; ExtractErrors: PUBLIC PROC [what: CDWorld, x: Tesselation, msg: Rope.ROPE, owner: ATOM_NIL, dispose: BOOL_TRUE, remFirst: BOOL_TRUE, except: REF_NIL] RETURNS [num: INT_0] = { InternalMsg: CStitching.TileProc = { csr: CD.Rect _ tile.Area[]; IF x.stopFlag^ THEN SIGNAL didStop; [] _ CDErrors.IncludeMessage[what.design, what.ob, BackRect[what, csr], msg, owner]; num _ num+1; }; IF remFirst THEN { CDErrors.RemoveMessages[what.design, what.ob, owner]; }; IF x#NIL THEN CStitching.EnumerateArea[plane: x, rect: GoodScaleCsFromCDRect[what.restrict, what.scale.off, what.scale.num, what.scale.denom], eachTile: InternalMsg, data: what, skip: except ! didStop => CONTINUE]; CDOps.DoTheDelayedRedraws[what.design]; --helps debugging and backgrounders IF dispose THEN Dispose[x]; }; Fill: PUBLIC PROC [x: Tesselation, into: Tesselation_NIL, except: REF_NIL, dispose: BOOL_FALSE] RETURNS [Tesselation] = { IF into=NIL THEN into _ New[stopFlag: x.stopFlag]; IF ~x.stopFlag^ AND ~into.stopFlag^ THEN { CStitching.EnumerateArea[plane: x, rect: CDBasics.universe, eachTile: InternalFillTTile, data: into, skip: except]; }; IF dispose THEN Dispose[x]; RETURN [into] }; InternalFillTTile: CStitching.TileProc = { CStitching.ChangeRect[plane: NARROW[data], rect: CStitching.Area[tile], new: $covered] }; Rem: PUBLIC PROC [x: Tesselation, into: Tesselation_NIL, except: REF_NIL, dispose: BOOL_FALSE] RETURNS [Tesselation] = { IF into=NIL THEN into _ New[filledWith: $covered, stopFlag: x.stopFlag]; IF ~x.stopFlag^ AND ~into.stopFlag^ THEN { CStitching.EnumerateArea[plane: x, rect: CDBasics.universe, eachTile: InternalRemTTile, data: into, skip: except]; }; IF dispose THEN Dispose[x]; RETURN [into]; }; InternalRemTTile: CStitching.TileProc = { CStitching.ChangeRect[plane: NARROW[data], rect: CStitching.Area[tile], new: NIL] }; FillGrow: PUBLIC PROC [x: Tesselation, grow: INT_0, into: Tesselation_NIL, except: REF_NIL, use: REF_$covered, dispose: BOOL_FALSE] RETURNS [Tesselation] = { InternalGrowTTile: CStitching.TileProc = { r: CD.Rect _ CDBasics.Extend[CDBasics.Intersection[CDBasics.universe, CStitching.Area[tile]], grow]; CStitching.ChangeRect[plane: into, rect: r, new: use]; IF into.stopFlag^ THEN SIGNAL didStop; }; IF into=NIL THEN into _ New[stopFlag: x.stopFlag]; IF ~x.stopFlag^ AND ~into.stopFlag^ THEN { CStitching.EnumerateArea[plane: x, rect: CDBasics.universe, eachTile: InternalGrowTTile, data: NIL, skip: except ! didStop => CONTINUE]; }; IF dispose THEN Dispose[x]; RETURN [into]; }; Copy: PUBLIC PROC [x: Tesselation, into: Tesselation_NIL, dispose: BOOL_FALSE] RETURNS [Tesselation] = { IF into=NIL THEN into _ New[stopFlag: x.stopFlag]; IF ~x.stopFlag^ AND ~into.stopFlag^ THEN { CStitching.EnumerateArea[plane: x, rect: CDBasics.universe, eachTile: InternalCopyTile, data: into]; }; IF dispose THEN Dispose[x]; RETURN [into] }; InternalCopyTile: CStitching.TileProc = { CStitching.ChangeRect[plane: NARROW[data], rect: CStitching.Area[tile], new: tile.value] }; Not: PUBLIC PROC [x: Tesselation, dispose: BOOL_FALSE] RETURNS [Tesselation] = { RETURN [Rem[x: x, into: NIL, except: NIL, dispose: dispose]] }; AndIn: PUBLIC PROC [x: Tesselation, into: Tesselation, dispose: BOOL_FALSE] RETURNS [Tesselation] = { RETURN [Rem[x: x, into: into, except: $covered, dispose: dispose]] }; OrIn: PUBLIC PROC [x: Tesselation, into: Tesselation, dispose: BOOL_FALSE] RETURNS [Tesselation] = { RETURN [Fill[x: x, into: into, except: NIL, dispose: dispose]] }; AndNotIn: PUBLIC PROC [x: Tesselation, into: Tesselation, dispose: BOOL_FALSE] RETURNS [Tesselation] = { RETURN [Rem[x: x, into: into, except: NIL, dispose: dispose]] }; And: PUBLIC PROC [t1, t2, t3, t4: Tesselation_NIL] RETURNS [into: Tesselation] = { into _ Copy[t1]; IF t2#NIL THEN into _ AndIn[t2, into]; IF t3#NIL THEN into _ AndIn[t3, into]; IF t4#NIL THEN into _ AndIn[t4, into]; }; Or: PUBLIC PROC [t1, t2, t3, t4: Tesselation_NIL] RETURNS [into: Tesselation] = { into _ Copy[t1]; IF t2#NIL THEN into _ OrIn[t2, into]; IF t3#NIL THEN into _ OrIn[t3, into]; IF t4#NIL THEN into _ OrIn[t4, into]; }; AndNot: PUBLIC PROC [a, n: Tesselation] RETURNS [Tesselation] = { RETURN [AndNotIn[n, Copy[a]]]; }; Grow: PUBLIC PROC [x: Tesselation, amount: INT_0, dispose: BOOL_FALSE] RETURNS [t: Tesselation] = { RETURN [ IF amount>0 THEN FillGrow[x: x, grow: amount, into: New[stopFlag: x.stopFlag], except: NIL, use: $covered, dispose: dispose] ELSE IF amount<0 THEN FillGrow[x: x, grow: -amount, into: New[filledWith: $covered, stopFlag: x.stopFlag], except: $covered, use: NIL, dispose: dispose] ELSE Fill[x: x, into: New[stopFlag: x.stopFlag], except: NIL, dispose: dispose] ] }; END. êCDCSUtilImpl.mesa Copyright c 1985, 1986 by Xerox Corporation. All rights reserved. Created by Christian Jacobi, December 12, 1985 2:19:57 pm PST Last edited by: Christian Jacobi, December 1, 1986 6:59:31 pm PST --a AND (~n) Ê ˜codešœ™Kšœ Ïmœ7™BKšœ=™=K™AK˜—K˜šÏk ˜ Kšžœ˜Kšœ ˜ Kšœ ˜ Kšœ ˜ K˜Kšœ ˜ Kšœ˜Kšœ˜—K˜šÏn œžœž˜Kšžœžœ'˜1Kšžœ ˜—Kšž œ ˜K˜Kšœ žœžœ˜K˜šŸœžœžœžœžœžœžœ žœžœžœžœ˜rKšœ2˜2Kšœ<˜Kšœžœ žœ˜/šžœžœžœ˜šœžœ˜Kšžœžœ@˜[KšžœK˜O—šžœ,žœžœž˜>Kšœh˜hKšžœ˜—K˜—Kšœ˜—K˜šŸœž œ3žœžœ˜bKš œžœžœžœžœžœžœ˜K˜—K˜š Ÿœž œ.žœžœžœ˜hKšžœ žœ˜=K˜—K˜š Ÿœžœžœžœžœ˜RKšœ˜Kšžœžœžœ˜&Kšžœžœžœ˜&Kšžœžœžœ˜&K˜—K˜š Ÿœžœžœžœžœ˜RKšœ˜Kšžœžœžœ˜%Kšžœžœžœ˜%Kšžœžœžœ˜%K˜—K˜šŸœž œžœ˜AKšœ ™ Kšžœ˜K˜—K˜šŸœžœžœžœ žœžœžœ˜cšžœ˜šžœ žœ˜KšœFžœ"˜k—šžœžœ ž˜Kšœlžœ˜‚—šž˜Kšœ4žœ˜J—K˜—K˜—K˜Kšžœ˜K˜—…— +ƒ