DIRECTORY Atom, CD, CDBasics, CDCallSpecific, CDIO, CDLRUCache, CDOrient, CDProperties, CDRects, CDDefaults, Rope, SafeStorage, TokenIO; CDRectsImpl: CEDAR MONITOR IMPORTS Atom, CD, CDCallSpecific, CDBasics, CDIO, CDLRUCache, CDOrient, CDProperties, CDDefaults, Rope, SafeStorage, TokenIO EXPORTS CDRects SHARES CD = BEGIN permanent: ZONE = SafeStorage.GetPermanentZone[]; lambda: CD.DesignNumber = CD.lambda; dummyRectPtr: CD.RectPtr = permanent.NEW[CD.RectRecord _ [filler: NIL]]; b1Cache: CDLRUCache.LRUCache = CDLRUCache.Create[size: 41, newProc: New]; b2Cache: CDLRUCache.LRUCache = CDLRUCache.Create[size: 41, newProc: New]; b3Cache: CDLRUCache.LRUCache = CDLRUCache.Create[size: 41, newProc: New]; sCache: CDLRUCache.LRUCache = CDLRUCache.Create[size: 31, newProc: New]; New: PROC [] RETURNS [CD.ObPtr] = { ob: CD.ObPtr _ NEW[CD.ObjectDefinition]; ob.specificRef _ dummyRectPtr; RETURN [ob] }; CreateRectProc: TYPE = PROC [size: CD.DesignPosition, l: CD.Level] RETURNS [CD.ObPtr] _ CreateBareRect; createRectArray: REF ARRAY CD.Level OF CreateRectProc = permanent.NEW[ARRAY CD.Level OF CreateRectProc]; -- initialized by default CreateRect: PUBLIC PROC [size: CD.DesignPosition, l: CD.Level] RETURNS [CD.ObPtr] = BEGIN RETURN [createRectArray[l][size, l]] END; HangExtensionsOn: PROC[on: REF CD.ObjectProcs] = BEGIN CDCallSpecific.Register[$Lengthen, on, Lengthen]; CDCallSpecific.Register[$Default, on, Defaulten]; END; UseAsCreateRect: PUBLIC PROC [ l: CD.Level, createRect: PROC [size: CD.DesignPosition, l: CD.Level] RETURNS [CD.ObPtr], hangExtensionsOn: REF CD.ObjectProcs ] = BEGIN IF createRect=NIL THEN createRect _ CreateBareRect; createRectArray[l] _ createRect; IF hangExtensionsOn#NIL THEN HangExtensionsOn[hangExtensionsOn]; CDProperties.PutPropOnLevel[onto: l, prop: $CDxRectCreation, val: $CDxUser]; END; CreateBareRect: PUBLIC PROC [size: CD.DesignPosition, l: CD.Level] RETURNS [CD.ObPtr] = BEGIN usedCache: CDLRUCache.LRUCache = IF size.y<37 THEN b1Cache ELSE IF size.x<16 THEN b2Cache ELSE b3Cache; rp: CD.ObPtr ~ usedCache.UnusedOrNew[]; rp.p _ pForRects; rp.size _ CDBasics.MaxPoint[size, [1, 1]]; rp.level _ l; RETURN [usedCache.ReplaceByAequivalent[rp]] END; CreateSaveRect: PUBLIC PROC [size: CD.DesignPosition, l: CD.Level] RETURNS [CD.ObPtr] = BEGIN rp: CD.ObPtr ~ sCache.UnusedOrNew[]; rp.p _ pForSaveRects; rp.size _ CDBasics.MaxPoint[size, [1, 1]]; rp.level _ l; RETURN [sCache.ReplaceByAequivalent[rp]] END; pForRects: REF CD.ObjectProcs; pForSaveRects: REF CD.ObjectProcs; Init: PROC [] = BEGIN pForRects _ CD.RegisterObjectType[$Rect]; pForRects.drawMe _ pForRects.quickDrawMe _ DrawMeForRects; pForRects.internalRead _ ReadRect; pForRects.internalWrite _ WriteRect; pForRects.describe _ Describe; pForRects.wireTyped _ TRUE; HangExtensionsOn[pForRects]; pForSaveRects _ CD.RegisterObjectType[$SaveRect]; pForSaveRects.drawMe _ pForSaveRects.quickDrawMe _ DrawMeForSaveRects; pForSaveRects.internalRead _ ReadRect; pForSaveRects.internalWrite _ WriteRect; pForSaveRects.describe _ Describe; pForSaveRects.wireTyped _ TRUE; HangExtensionsOn[pForSaveRects]; END; Describe: PROC[me: CD.ObPtr] RETURNS [Rope.ROPE] = BEGIN RETURN [Rope.Concat["rect ", Atom.GetPName[CD.LevelKey[me.level]]]] END; DrawMeForRects: PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: CD.DrawRef] = BEGIN pr.drawRect[CDOrient.RectAt[pos, aptr.ob.size, orient], aptr.ob.level, pr] END; DrawMeForSaveRects: PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: CD.DrawRef] = BEGIN pr.saveRect[CDOrient.RectAt[pos, aptr.ob.size, orient], aptr.ob.level, pr] END; Lengthen: CDCallSpecific.CallProc = BEGIN sz: CD.DesignPosition _ CDBasics.SizeOfRect[aptr.ob.p.insideRect[aptr.ob]]; amount: CD.DesignPosition; IF x=NIL THEN amount _ [0, lambda] ELSE IF ISTYPE [x, REF CD.DesignPosition] THEN amount _ NARROW[x, REF CD.DesignPosition]^ ELSE {done_FALSE; RETURN}; sz _ CDBasics.AddPoints[sz, amount]; IF sz.x<=0 OR sz.y<=0 THEN {done _ FALSE; RETURN}; aptr.ob _ CreateRect[sz, aptr.ob.level]; repaintMe _ TRUE; END; Defaulten: CDCallSpecific.CallProc = BEGIN sz: CD.DesignPosition _ CDBasics.SizeOfRect[aptr.ob.p.insideRect[aptr.ob]]; w: CD.DesignNumber _ CDDefaults.LevelWidth[design, aptr.ob.level]; IF w<=0 THEN {done _ FALSE; RETURN}; sz.x _ w; aptr.ob _ CreateRect[sz, aptr.ob.level]; repaintMe _TRUE; END; SetLength: CDCallSpecific.CallProc = BEGIN newLength: CD.DesignNumber _ NARROW[x, REF CD.DesignNumber]^; sz: CD.DesignPosition _ aptr.ob.size; IF sz.ysz.x THEN sz.x _ newWidth ELSE sz.y _ newWidth; aptr.ob _ CreateRect[sz, aptr.ob.level]; repaintMe _ TRUE; END; WriteRect: CD.InternalWriteProc -- PROC [me: ObPtr] -- = BEGIN sz: CD.DesignPosition = CDBasics.SizeOfRect[me.p.insideRect[me]]; TokenIO.WriteInt[sz.x]; TokenIO.WriteInt[sz.y]; CDIO.WriteLevel[me.level]; END; ReadRect: CD.InternalReadProc --PROC [] RETURNS [ObPtr]-- = BEGIN x: INT = TokenIO.ReadInt[]; y: INT = TokenIO.ReadInt[]; l: CD.Level = CDIO.ReadLevel[]; ob: CD.ObPtr = CreateRect[CD.DesignPosition[x, y], l]; RETURN [ob] END; Init[]; END. RCDRectsImpl.mesa (part of Chipndale) Copyright c 1983 by Xerox Corporation. All rights reserved. Christian Jacobi June 24, 1983 4:58 pm last edited Christian Jacobi November 5, 1984 10:25:28 am PST -- any number of caches; simply for speed up; Yes I know, one big cache could be better -- but this is faster, and the distribution is crazy, such that not all caches have similar -- hit rates --???setWidth: REF CDCallSpecific.CallProc_permanent.NEW[CDCallSpecific.CallProc_SetWidth]; --???setLength: REF CDCallSpecific.CallProc_permanent.NEW[CDCallSpecific.CallProc_SetLength]; Κͺ˜šœ&™&Jšœ Οmœ1™