DIRECTORY CD, CDBasics, CDCallSpecific, CDIO, CDLRUCache, CDOrient, CDProperties, CDRects, CDDefaults, CDOps, Rope, SafeStorage, TokenIO; CDRectsImpl: CEDAR MONITOR IMPORTS CD, CDCallSpecific, CDBasics, CDIO, CDLRUCache, CDOrient, CDOps, 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.Layer] RETURNS [CD.ObPtr] _ CreateBareRect; createRectArray: REF ARRAY CD.Layer OF CreateRectProc = permanent.NEW[ARRAY CD.Layer OF CreateRectProc]; -- initialized by default CreateRect: PUBLIC PROC [size: CD.DesignPosition, l: CD.Layer] 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.Layer, createRect: PROC [size: CD.DesignPosition, l: CD.Layer] RETURNS [CD.ObPtr], hangExtensionsOn: REF CD.ObjectProcs ] = BEGIN IF createRect=NIL THEN createRect _ CreateBareRect; createRectArray[l] _ createRect; IF hangExtensionsOn#NIL THEN HangExtensionsOn[hangExtensionsOn]; CDProperties.PutPropOnLayer[onto: l, prop: $CDxRectCreation, val: $CDxUser]; END; CreateBareRect: PUBLIC PROC [size: CD.DesignPosition, l: CD.Layer] 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.layer _ l; RETURN [usedCache.ReplaceByAequivalent[rp]] END; CreateSaveRect: PUBLIC PROC [size: CD.DesignPosition, l: CD.Layer] RETURNS [CD.ObPtr] = BEGIN rp: CD.ObPtr ~ sCache.UnusedOrNew[]; rp.p _ pForSaveRects; rp.size _ CDBasics.MaxPoint[size, [1, 1]]; rp.layer _ 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 ", CDOps.LayerName[me.layer]]] 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.layer, 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.layer, pr] END; Lengthen: CDCallSpecific.CallProc = BEGIN sz: CD.DesignPosition _ CDBasics.SizeOfRect[CD.InterestRect[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.layer]; repaintMe _ TRUE; END; Defaulten: CDCallSpecific.CallProc = BEGIN sz: CD.DesignPosition _ CDBasics.SizeOfRect[CD.InterestRect[aptr.ob]]; w: CD.DesignNumber _ CDDefaults.LayerWidth[design, aptr.ob.layer]; IF w<=0 THEN {done _ FALSE; RETURN}; sz.x _ w; aptr.ob _ CreateRect[sz, aptr.ob.layer]; 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.layer]; repaintMe _ TRUE; END; WriteRect: CD.InternalWriteProc -- PROC [me: ObPtr] -- = BEGIN sz: CD.DesignPosition = CDBasics.SizeOfRect[CD.InterestRect[me]]; TokenIO.WriteInt[sz.x]; TokenIO.WriteInt[sz.y]; CDIO.WriteLayer[me.layer]; END; ReadRect: CD.InternalReadProc --PROC [] RETURNS [ObPtr]-- = BEGIN x: INT = TokenIO.ReadInt[]; y: INT = TokenIO.ReadInt[]; l: CD.Layer = CDIO.ReadLayer[]; ob: CD.ObPtr = CreateRect[CD.DesignPosition[x, y], l]; RETURN [ob] END; Init[]; END. NCDRectsImpl.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, April 11, 1985 9:23: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™