DIRECTORY OrderedSymbolTableRef USING [Table, CompareProc, CreateTable, LookupSmallest, LookupNextLarger, Insert, DestroyTable, EnumerateIncreasing], Imager USING [Context, MaskStrokeTrajectory, SetGray], ImagerPath USING [Trajectory, MoveTo, LineToX, LineToY], Rope, IPConstants, Misc, IPCoTab, IPCoVerifier; IPCoVerifierImpl: CEDAR PROGRAM IMPORTS OrderedSymbolTableRef, Rope, Misc, IPCoTab, Imager, ImagerPath EXPORTS IPCoVerifier = BEGIN OPEN CT: IPCoTab, IPCoVerifier; Conflict: TYPE = REF ConflictRep; ConflictRep: TYPE = RECORD[comp1, comp2: CompItem]; Create: PUBLIC PROC[yOrdered: BOOL _ TRUE] RETURNS[Ref]={ RETURN[NEW[Rep _ [yOrdered: yOrdered, comps: CompsCreate[yOrdered]]]] }; --Create -- Destroy: PUBLIC PROC [r: Ref] ={CompsDestroy[r.comps]}; -- Destroy-- InsertComponent: PUBLIC PROC[r: Ref, co: IPCoTab.Component]={ CompsInsert[r.comps, co] }; -- InsertComponent-- CompItems: PUBLIC PROC [r: Ref, p: EachCompItemAction] ={ p1: PROC[Item: REF] RETURNS[BOOL] ={RETURN[p[NARROW[Item, CompItem]]]}; OrderedSymbolTableRef.EnumerateIncreasing[r.comps.tab, p1]; }; --CompItems-- GetBRect: PUBLIC PROC[r: Ref] RETURNS [Misc.Rect] ={RETURN [r.bRect]}; --GetBRect-- Verify: PUBLIC PROC [r: Ref] RETURNS[overlaps: LIST OF Misc.Rect _ NIL]={ conflicts: LIST OF Conflict _ NIL; mainComp: CompItem; WHILE (mainComp _ GetMainComp[r.comps]) # NIL DO {r.bRect _ Misc.RectMakeBRect[r.bRect, IPCoTab.GetBRect[mainComp.comp]]; FOR testComps: LIST OF CompItem _ GetTestComps[r.comps, mainComp, r.yOrdered], testComps.rest UNTIL testComps = NIL DO { testComp: CompItem _ testComps.first; intrsctn: Misc.Rect; IF (intrsctn _ ClipComp[mainComp, IPCoTab.GetBRect[testComp.comp]]) = NIL THEN LOOP; IF (intrsctn _ ClipComp[testComp, intrsctn, TRUE, TRUE])# NIL THEN { IF CompComputeHint[mainComp, intrsctn] THEN NULL ELSE {overlaps _ CONS[ClipComp[mainComp, intrsctn], overlaps]; LOOP}}; IF (intrsctn _ ClipComp[mainComp, IPCoTab.GetBRect[testComp.comp]]) = NIL THEN LOOP; IF (intrsctn _ ClipComp[testComp, intrsctn, FALSE]) = NIL THEN LOOP; IF CompComputeHint[mainComp, intrsctn, TRUE] AND CompComputeHint[mainComp, intrsctn, TRUE] THEN {conflicts _ CONS[NEW[ConflictRep_ [mainComp, testComp]],conflicts]; LOOP}; IF CompComputeHint[testComp, intrsctn] THEN LOOP; ERROR}; ENDLOOP}; ENDLOOP; WHILE conflicts # NIL DO { c: Conflict _ conflicts.first; r: Misc.Rect; IF (r _ ClipComp[c.comp1, IPCoTab.GetBRect[c.comp2.comp], FALSE]) = NIL THEN GOTO nextIter; IF (r _ ClipComp[c.comp2, r, FALSE]) = NIL THEN GOTO nextIter; ResolveConflict[c.comp1, c.comp2, r]; EXITS nextIter => {conflicts _ conflicts.rest}}; ENDLOOP; }; -- Verify-- PaintSelf: PUBLIC PROC[r: Ref, context: Imager.Context, xOffset, yOffset: REAL, scaleFactor: REAL _ 1.0, stipple: CARDINAL _ IPConstants.Gray, drawOutline: BOOL _ TRUE, drawComp:BOOL _ FALSE, showCompName: BOOL _ TRUE]={ paintCompItem: EachCompItemAction ={ co: IPCoTab.Component _ cI.comp; IF drawOutline THEN { OPEN h: cI.hint; path: ImagerPath.Trajectory; sw, se, ne, nw: IPCoTab.CornerSpace; originX, originY: REAL; dimX, dimY: REAL; [originX, originY] _ co.origin; originX _ xOffset + (originX * scaleFactor); originY _ yOffset + (originY *scaleFactor); [dimX, dimY] _ CT.GetDim[co]; dimX _ dimX * scaleFactor; dimY _ dimY * scaleFactor; [sw, se, ne, nw] _ CT.GetCornerSps[co]; Imager.SetGray[context, IPConstants.Black]; IF h.sw THEN { path _ ImagerPath.MoveTo[[originX, originY + sw.y * scaleFactor]]; path _ ImagerPath.LineToX[path, originX + sw.x * scaleFactor]; path _ ImagerPath.LineToY[path, originY]} ELSE { path _ ImagerPath.MoveTo[[originX, originY]]}; IF h.se THEN { path _ ImagerPath.LineToX[path, originX+ dimX - se.x * scaleFactor]; path _ ImagerPath.LineToY[path, originY + se.y * scaleFactor]; path _ ImagerPath.LineToX[path, originX + dimX];} ELSE{ path _ ImagerPath.LineToX[path, originX + dimX];}; IF h.ne THEN { path _ ImagerPath.LineToY[path, originY +dimY - ne.y * scaleFactor]; path _ ImagerPath.LineToX[path, originX + dimX - ne.x * scaleFactor]; path _ ImagerPath.LineToY[path, originY + dimY];} ELSE { path _ ImagerPath.LineToY[path, originY + dimY]}; IF h.nw THEN { path _ ImagerPath.LineToX[path, originX + nw.x * scaleFactor]; path _ ImagerPath.LineToY[path, originY + dimY - nw.y * scaleFactor]; path _ ImagerPath.LineToX[path, originX];} ELSE { path _ ImagerPath.LineToX[path, originX]}; IF h.sw THEN { path _ ImagerPath.LineToY[path, originY + sw.y * scaleFactor];} ELSE { path _ ImagerPath.LineToY[path, originY]}; Imager.MaskStrokeTrajectory[context, path];}; IF drawComp THEN IPCoTab.PaintComponent[co, context, xOffset, yOffset, scaleFactor, stipple, showCompName]; }; --paintCompItem-- CompItems[r, paintCompItem] }; --PaintSelf -- xCompareProc: OrderedSymbolTableRef.CompareProc={ c1, c2: IPCoTab.Component; IF r1 = r2 THEN RETURN [equal]; c1 _ NARROW[r1, CompItem].comp; c2 _ NARROW[r2, CompItem].comp; IF IPCoTab.GetOrigin[c1].x > IPCoTab.GetOrigin[c2].x THEN RETURN[greater]; IF IPCoTab.GetOrigin[c1].x < IPCoTab.GetOrigin[c2].x THEN RETURN[less]; IF IPCoTab.GetOrigin[c1].y > IPCoTab.GetOrigin[c2].y THEN RETURN[greater]; IF IPCoTab.GetOrigin[c1].y < IPCoTab.GetOrigin[c2].y THEN RETURN[less]; RETURN[Rope.Compare[IPCoTab.GetName[c1], IPCoTab.GetName[c2]]]}; --xCompareProc-- yCompareProc: OrderedSymbolTableRef.CompareProc={ c1, c2: IPCoTab.Component; IF r1 = r2 THEN RETURN [equal]; c1 _ NARROW[r1, CompItem].comp; c2 _ NARROW[r2, CompItem].comp; IF IPCoTab.GetOrigin[c1].y > IPCoTab.GetOrigin[c2].y THEN RETURN[greater]; IF IPCoTab.GetOrigin[c1].y < IPCoTab.GetOrigin[c2].y THEN RETURN[less]; IF IPCoTab.GetOrigin[c1].x > IPCoTab.GetOrigin[c2].x THEN RETURN[greater]; IF IPCoTab.GetOrigin[c1].x < IPCoTab.GetOrigin[c2].x THEN RETURN[less]; RETURN[Rope.Compare[IPCoTab.GetName[c1], IPCoTab.GetName[c2]]]}; --yCompareProc-- CompsCreate: PROC[yOrdered: BOOL] RETURNS[Comps] = { RETURN[NEW[CompsRep _ [tab:OrderedSymbolTableRef.CreateTable[IF yOrdered THEN yCompareProc ELSE xCompareProc]]]]}; -- CreateComps-- CompsInsert: PROC[comps: Comps, co: IPCoTab.Component] ={ cI: CompItem _ NEW[CompItemRep _ [comp: co]]; OrderedSymbolTableRef.Insert[comps.tab, cI]; }; --CompsInsert-- CompsDestroy: PROC [comps: Comps] ={ OrderedSymbolTableRef.DestroyTable[comps.tab]; }; -- Destroy-- LastMainComp: REF _ NIL; GetMainComp: PROC[comps: Comps] RETURNS[CompItem] ={ IF LastMainComp = NIL THEN {LastMainComp _ OrderedSymbolTableRef.LookupSmallest[comps.tab]} ELSE {LastMainComp _ OrderedSymbolTableRef.LookupNextLarger[comps.tab, LastMainComp]}; RETURN[NARROW[LastMainComp]]}; --GetMainComp-- GetTestComps: PROC[comps: Comps, mComp: CompItem, yOrdered: BOOL] RETURNS[tComps: LIST OF CompItem _ NIL] ={ coDimX, coDimY: NAT; compMaxCoord: INT; [coDimX, coDimY] _ CT.GetDim[mComp.comp]; compMaxCoord _ IF yOrdered THEN mComp.comp.origin.y + coDimY ELSE mComp.comp.origin.x + coDimX; WHILE (mComp _ NARROW[OrderedSymbolTableRef.LookupNextLarger[comps.tab, mComp], CompItem]) #NIL DO IF yOrdered THEN {IF mComp.comp.origin.y > compMaxCoord THEN RETURN} ELSE {IF mComp.comp.origin.x > compMaxCoord THEN RETURN}; tComps _ CONS[mComp, tComps]; ENDLOOP; }; --GetTestComps-- PartialClipping: ERROR[partialResult: Misc.Rect] = CODE; ClipComp: PROC[cI: CompItem, clipRect: Misc.Rect, partialClippingOk: BOOL _ TRUE, trueShape: BOOL _ FALSE] RETURNS[rect: Misc.Rect] ={ OPEN h: cI.hint; comp: IPCoTab.Component _ cI.comp; fullyClipped: BOOL _ TRUE; sw, se, ne, nw: Misc.Rect; IF (rect _ Misc.RectIntersect[IPCoTab.GetBRect[comp], clipRect]) = NIL THEN RETURN; [sw, se, ne, nw] _ IPCoTab.GetCornerRects[comp]; IF trueShape OR h.sw THEN {rect _ Misc.RectSubtract[rect, sw ! Misc.RectSubtractFailure =>{rect _ r1; fullyClipped_ FALSE; CONTINUE}]}; IF trueShape OR h.se THEN {rect _ Misc.RectSubtract[rect, se ! Misc.RectSubtractFailure =>{rect _ r1; fullyClipped_ FALSE; CONTINUE}]}; IF trueShape OR h.ne THEN {rect _ Misc.RectSubtract[rect, ne ! Misc.RectSubtractFailure =>{rect _ r1; fullyClipped_ FALSE; CONTINUE}]}; IF trueShape OR h.nw THEN {rect _ Misc.RectSubtract[rect, nw ! Misc.RectSubtractFailure =>{rect _ r1; fullyClipped_ FALSE; CONTINUE}]}; IF fullyClipped OR partialClippingOk THEN {RETURN[rect]} ELSE {RETURN WITH ERROR PartialClipping[rect]}; }; --ClipComp-- CompComputeHint: PROC [cI: CompItem, rect: Misc.Rect, fakeIt: BOOL _ FALSE] RETURNS [done: BOOL _ FALSE] = { IF rect = NIL THEN ERROR; {OPEN h: cI.hint; comp: IPCoTab.Component _ cI.comp; sw, se, ne, nw: Misc.Rect; [sw, se, ne, nw] _ IPCoTab.GetCornerRects[comp]; IF Misc.RectIntersect[sw, rect] # NIL THEN { IF fakeIt THEN NULL ELSE {h.sw _ TRUE}; IF Misc.RectContainp[sw, rect] THEN {RETURN[TRUE]}}; IF Misc.RectIntersect[se, rect] # NIL THEN { IF fakeIt THEN NULL ELSE {h.se _ TRUE}; IF Misc.RectContainp[se, rect] THEN {RETURN[TRUE]}}; IF Misc.RectIntersect[ne, rect] # NIL THEN { IF fakeIt THEN NULL ELSE {h.ne _ TRUE}; IF Misc.RectContainp[ne, rect] THEN {RETURN[TRUE]}}; IF Misc.RectIntersect[nw, rect] # NIL THEN { IF fakeIt THEN NULL ELSE {h.nw _ TRUE}; IF Misc.RectContainp[nw, rect] THEN {RETURN[TRUE]}}; }; }; --CompComputeHint-- ResolveConflict: PROC[c1, c2: CompItem, r: Misc.Rect] ={ IF r = NIL THEN ERROR ELSE {OPEN h1: c1.hint, h2: c2.hint; sw1, se1, ne1, nw1, sw2, se2, ne2, nw2: Misc.Rect; [sw1, se1, ne1, nw1] _ IPCoTab.GetCornerRects[c1.comp]; [sw2, se2, ne2, nw2] _ IPCoTab.GetCornerRects[c2.comp]; IF sw1.RectContainp[r] THEN {IF NOT ne2.RectContainp[r] THEN ERROR; IF ne2.RectArea > sw1.RectArea THEN {h1.sw _ TRUE} ELSE {h2.ne _ TRUE}; RETURN}; IF se1.RectContainp[r] THEN {IF NOT nw2.RectContainp[r] THEN ERROR; IF nw2.RectArea > se1.RectArea THEN {h1.se _ TRUE} ELSE {h2.nw _ TRUE}; RETURN}; IF ne1.RectContainp[r] THEN {IF NOT sw2.RectContainp[r] THEN ERROR; IF sw2.RectArea > ne1.RectArea THEN {h1.ne _ TRUE} ELSE {h2.sw _ TRUE}; RETURN}; IF nw1.RectContainp[r] THEN {IF NOT se2.RectContainp[r] THEN ERROR; IF se2.RectArea > nw1.RectArea THEN {h1.nw _ TRUE} ELSE {h2.se _ TRUE}; RETURN}; ERROR;} }; --ResolveConflict-- END. D-- File: IPCoVerifierImpl.mesa -- Last Edited by: CSChow, February 2, 1985 2:00:53 am PST Preas, August 2, 1986 12:19:44 pm PDT --Part (1) ComputeHint for mainComp And Check for overlap-- --Part (2) ComputeHint for testComp. Assumed all overlaps handled above. Handle Conflict-- --#########Private##############-- Κ~˜Jšœ™šœ:™:Icode™%—J™J™J˜šΟk ˜ Jšœœp˜‹Jšœœ*˜6Jšœ œ(˜8J˜Jšœ ˜ J˜Jšœ˜Jšœ ˜ —J˜šΟnœœ˜Jšœ?˜FJšœœœœ˜˜>Kšœ*œ˜1Kšœ.˜.—šœœ˜KšœD˜DKšœ>˜>Kšœ2œ˜7Kšœ2˜2—šœœ˜KšœD˜DKšœE˜EKšœ2œ˜8Kšœ1˜1—šœœ˜Kšœ>˜>KšœE˜EKšœ+œ˜1Kšœ*˜*—šœœ˜Kšœ@œ˜FKšœ*˜*Kšœ-˜-——Jšœ œ[˜kJ˜JšœŸ˜—Jšœ˜J˜JšœŸ˜—K– "Cedar" style˜—K– "Cedar" stylešœ"™"– "Cedar" style™K– "Cedar" style˜– "Cedar" stylešœ1˜1K– "Cedar" stylešœ˜K– "Cedar" stylešœ œœ ˜K– "Cedar" stylešœœ˜K– "Cedar" stylešœœ˜K– "Cedar" stylešœ3œœ ˜JK– "Cedar" stylešœ3œœ˜GK– "Cedar" stylešœ3œœ ˜JK– "Cedar" stylešœ3œœ˜GK– "Cedar" stylešœ;Ÿ˜Q—K– "Cedar" style˜– "Cedar" stylešœ1˜1K– "Cedar" stylešœ˜K– "Cedar" stylešœ œœ ˜K– "Cedar" stylešœœ˜K– "Cedar" stylešœœ˜K– "Cedar" stylešœ3œœ ˜JK– "Cedar" stylešœ3œœ˜GK– "Cedar" stylešœ3œœ ˜JK– "Cedar" stylešœ3œœ˜GK– "Cedar" stylešœ;Ÿ˜Q—K– "Cedar" style˜K– "Cedar" style˜– "Cedar" stylešž œœ œœ ˜4K– "Cedar" styleš œœ3œ œœŸ˜ƒ—– "Cedar" stylešž œœ(˜9K– "Cedar" stylešœœ˜-K– "Cedar" stylešœ,˜,K– "Cedar" stylešœŸ˜—K– "Cedar" style˜– "Cedar" stylešž œœ˜$K– "Cedar" stylešœ.˜.K– "Cedar" stylešœŸ ˜—K– "Cedar" style˜K– "Cedar" stylešž œœœ˜– "Cedar" stylešž œœœ ˜4– "Cedar" stylešœœ˜K– "Cedar" stylešœA˜EK– "Cedar" stylešœR˜V—K– "Cedar" stylešœœŸ˜.—K– "Cedar" style˜– "Cedar" stylešž œœ*œœ œœ œ˜lK– "Cedar" stylešœœ˜K– "Cedar" stylešœœ˜K– "Cedar" stylešœœ˜)K– "Cedar" stylešœœ œœ˜_– "Cedar" stylešœ œGœ˜b– "Cedar" stylešœ ˜ K– "Cedar" stylešœœ$œœ˜8K– "Cedar" stylešœœ$œœ˜9—K– "Cedar" stylešœ œ˜K– "Cedar" stylešœ˜K– "Cedar" stylešœŸ˜——K– "Cedar" style˜K– "Cedar" style˜K– "Cedar" stylešžœœœ˜9– "Cedar" stylešžœœ7œœ œœœ˜†– "Cedar" stylešœ ˜K– "Cedar" stylešœ"˜"K– "Cedar" stylešœœœ˜K– "Cedar" style˜K– "Cedar" stylešœAœœœ˜SK– "Cedar" stylešœ0˜0K– "Cedar" styleš œ œœ[œœ˜‡K– "Cedar" styleš œ œœ[œœ˜‡K– "Cedar" styleš œ œœ[œœ˜‡K– "Cedar" styleš œ œœ[œœ˜‡K– "Cedar" stylešœœœœœœœœ˜hK– "Cedar" stylešœŸ ˜——– "Cedar" stylešžœœ)œœœœœ˜lK– "Cedar" stylešœœœœ˜– "Cedar" stylešœœ ˜K– "Cedar" stylešœ"˜"K– "Cedar" style˜K– "Cedar" stylešœ0˜0– "Cedar" stylešœ!œœ˜-K– "Cedar" styleš œœœœ œ˜(K– "Cedar" stylešœœœœ˜4—– "Cedar" stylešœ œœ˜,K– "Cedar" styleš œœœœ œ˜(K– "Cedar" stylešœœœœ˜4—– "Cedar" stylešœ œœ˜,K– "Cedar" styleš œœœœ œ˜(K– "Cedar" stylešœœœœ˜4—– "Cedar" stylešœ œœ˜,K– "Cedar" styleš œœœœ œ˜(K– "Cedar" stylešœœœœ˜4—K– "Cedar" stylešœ˜—K˜KšœŸ˜—K– "Cedar" style˜– "Cedar" stylešžœœ#˜8– "Cedar" stylešœœ˜ K– "Cedar" stylešœ˜ – "Cedar" stylešœœ˜$K– "Cedar" stylešœ2˜2K– "Cedar" stylešœ7˜7K– "Cedar" stylešœ8˜8– "Cedar" styleš œœœœœœ˜CK– "Cedar" styleš œœ œœ œ˜HK– "Cedar" stylešœ˜—– "Cedar" styleš œœœœœœ˜CK– "Cedar" styleš œœ œœ œ˜HK– "Cedar" stylešœ˜—– "Cedar" styleš œœœœœœ˜CK– "Cedar" styleš œœ œœ œ˜HK– "Cedar" stylešœ˜—– "Cedar" styleš œœœœœœ˜CK– "Cedar" styleš œœ œœ œ˜HK– "Cedar" stylešœ˜—K–[]– "Cedar" stylešœ˜——K– "Cedar" stylešœŸ˜—K– "Cedar" style˜K– "Cedar" stylešœ˜——…—'(;κ