<> <> <> DIRECTORY Graphics USING [Context, Color, PaintMode, black], List USING [AList], MBQueue USING [Queue], RefTab USING [Ref], Rope USING [ROPE], SymTab USING [Ref]; CD: CEDAR DEFINITIONS = <<--CD stands for ChipnDale, >> BEGIN <<-- measures>> <<-- independent of cordinate system>> Number: TYPE = INT; Position: TYPE = RECORD [x, y: Number]; Rect: TYPE = RECORD [x1, y1, x2, y2: Number]; <<--a Rect is called normalized if (x1>x2) OR (y1>y2) means that the Rect is empty.>> <<--all Rects are normalized, except if a special comment denies >> <<--Rect's are closed: they include all the endpoints; as you expect, points have size 0.>> <<-- design coordinates>> DesignNumber: TYPE = Number; DesignPosition: TYPE = Position; DesignRect: TYPE = Rect; lambda: DesignNumber = 2; <<--your program must not depend on the value of lambda>> <<>> Orientation: TYPE = [0..15] _ 0; <<--Module CDOrient exports all you probably need about Orientations;>> <<--If your program depends on the representation of Orientation, it>> <<--is probably wrong.>> original: Orientation = 0; <<-- Errors>> Error: ERROR [ec: ErrorCode _ programmingError, explanation: Rope.ROPE _ NIL]; ErrorCode: TYPE = {programmingError, callingError, noResource, doubleRegistration, missingRegistration, other}; <<-- properties>> Properties: TYPE = List.AList; <<--friendly use expected: don't assign properties without first register >> <<--their names with CDProperties.>> <<--use only CDProperties to access Properties>> <<-- levels>> levelNumber: NAT = 256; Level: TYPE = [0..levelNumber); combined: Level = 0; -- level used for object containing different or unknown levels highLightShade: Level = 1; -- visualization; not for generating masks highLightError: Level = 2; -- visualization; not for generating masks NewLevel: PROC [technology: Technology, uniqueKey: ATOM] RETURNS [Level]; <<--may raise Error[noResource] and others>> <<--the technolgy implementation must guarantee for uniqueness of uniqueKey's>> <<-- (unique only for the technology)>> FetchLevel: PROC [t: Technology, uniqueKey: ATOM] RETURNS [Level]; LevelTechnology: PROC [l: Level] RETURNS [Technology]; LevelKey: PROC [l: Level] RETURNS [ATOM]; <<--object, cells, applications>> markNum: NAT = 256; ObPtr: TYPE = REF ObjectDefinition; ObjectDefinition: TYPE = RECORD [ p: REF READONLY ObjectProcs, -- never modify p nor p^ size: DesignPosition _ [lambda, lambda], level: Level _ combined, marked: [0..markNum) _ 0, specificRef: REF ANY _ NIL, properties: Properties _ NIL -- see warning ]; <<--Several applications may point to same object: consider on modifications.>> <<--Some implementors of object-types share the bits of different objectdefinitions>> <<--if they are the same, excluding properties. User of properties loose. >> CellPtr: TYPE = REF CellRecord; CellRecord: TYPE = RECORD [ contents: ApplicationList _ NIL, name: Rope.ROPE _ NIL, key: Rope.ROPE _ NIL, simplifyOn: NAT _ LAST[NAT] ]; RectPtr: TYPE = REF RectRecord; RectRecord: TYPE = RECORD [filler: PRIVATE REF]; ApplicationList: TYPE = LIST OF ApplicationPtr_NIL; ApplicationPtr: TYPE = REF Application; Application: TYPE = RECORD [ ob: ObPtr, location: DesignPosition, orientation: Orientation, selected: BOOLEAN, properties: Properties _ NIL ]; ObjectProcs: TYPE = RECORD [ -- generic procedures for an object quickDrawMe: DrawProc, drawMe: DrawProc, showMeSelected: DrawProc, hitInside: HitInsideProc, -- if called, aptr.ob.p.hitInside MUST be the called procedure itself insideRect: RectProc, further: PRIVATE RefTab.Ref, technology: PRIVATE Technology, -- dont rely on it, it is often NIL objectType: ATOM, hasChildren: BOOL, -- if hasChildren then included in directory directoryProcs: REF _ NIL, wireTyped: BOOL, -- if wiretyped then insideRect.y corresponds length internalWrite: InternalWriteProc, internalRead: InternalReadProc, match: MatchProc_NIL, describe: DescribeProc_NIL ]; DrawProc: TYPE = PROC [aptr: ApplicationPtr, pos: DesignPosition, orient: Orientation, pr: REF DrawInformation]; <<--ignores aptr.location and aptr.orientation, may use aptr.properties>> HitInsideProc: TYPE = PROC [aptr: ApplicationPtr, hitRect: DesignRect] RETURNS [BOOL]; RectProc: TYPE = PROC [ob: ObPtr] RETURNS [DesignRect]; InternalWriteProc: TYPE = PROC [me: ObPtr]; InternalReadProc: TYPE = PROC [] RETURNS [ObPtr]; DescribeProc: TYPE = PROC [me: ObPtr] RETURNS [Rope.ROPE]; MatchProc: TYPE = PROC [me: ObPtr, r: DesignRect, level: Level, prim: BOOL, horz: BOOL] RETURNS [BOOL]; RegisterObjectType: PROC [objectType: ATOM, technology: Technology_NIL] RETURNS [REF ObjectProcs]; <<--may raise Error[doubleRegistration] and others>> <<--Also initializes procedures with default values >> <<--An object type may be used either in arbitrary technology or technology-independent.>> <<--This should be the only way to create data of type ObjectProcsRec>> FetchObjectProcs: PROC [objectType: REF, technology: Technology_NIL] RETURNS [REF --READONLY-- ObjectProcs]; <<--may raise Error[missingRegistration] >> <<--consider ObjectProcs as readonly if you are not the implementor of the object type >> <<-- Design>> PushRec: TYPE = RECORD [ dummyCell: ApplicationPtr, <> mightReplace: ApplicationPtr_NIL, specific: CellPtr, -- cache of dummyCell.ob.specificRef changed: BOOL_FALSE, indirectlyChanged: BOOL_FALSE, deletedList: REF_NIL ]; Design: TYPE = REF DesignRec; DesignRec: TYPE = RECORD [ -- use only CDOps.CreateDesign to create record actual: LIST OF PushRec, -- actual.first is most deeply pushed cell; cellDirectory: PRIVATE CellTableRef, -- pushed cells are copied and not part of the cellDirectory name: Rope.ROPE_NIL, technology: Technology_NIL, designValues: DesignValues_NIL, --CDValue queue: MBQueue.Queue, seqPrivate: SequencerRef, properties: Properties_NIL <<--CDValue supports more fields >> ]; SequencerRef: TYPE = REF SequencerDesignPrivate; SequencerDesignPrivate: TYPE; CellTableRef: PRIVATE TYPE = SymTab.Ref; DesignValues: TYPE = REF DesignValuesRep; --CDValue DesignValuesRep: TYPE; --CDValue <<-- Technology>> <<>> Technology: TYPE = REF TechnologyRec; TechnologyRec: TYPE = RECORD [ -- use RegisterTechnology to create record key: ATOM_NIL, name: Rope.ROPE_NIL, technologyPrivate: PRIVATE TechnologyPrivate, technologyValues: TechnologyValues, --CDValue technologyCommands: TechnologyCommands, --CDSequencer usedLevels: LIST OF Level, -- without constant levels defined in CD properties: Properties_NIL <<--CDValue supports more fields>> ]; TechnologyValues: TYPE = REF TechnologyValuesRep; --CDValue TechnologyCommands: TYPE = REF TechnologyCommandsRep; --CDSequencer TechnologyPrivate: TYPE = PRIVATE REF TechnologyPrivateRep; TechnologyValuesRep: TYPE; --CDValue TechnologyCommandsRep: TYPE; --CDSequencer TechnologyPrivateRep: TYPE; RegisterTechnology: PROC [key: ATOM, name: Rope.ROPE_NIL] RETURNS [Technology]; <<--This must be the only way to create data of type TechnologyRec>> <<--may raise Error[doubleRegistration] and others>> <<--[Implementors of technologies: look further rules in CDTechnology]>> FetchTechnology: PROC [key: ATOM] RETURNS [Technology]; <<--may raise Error[missingRegistration] and others>> <<-- drawing>> DrawRef: TYPE = REF DrawInformation; DrawInformation: TYPE = RECORD [ worldClip: DesignRect, -- in doubt is larger than device minimalSize: Number, -- if xyz> deviceContext: PRIVATE Graphics.Context, viewerSave: ViewerSave_NIL, -- speed up for viewers saveRect's internal's design: Design, nesting: ApplicationList, -- shares Application's but not ApplicationPtr's pushLevel: CARDINAL _ 0 ]; <<--DrawInformation records should not be copied unless the state of drawing is>> <<--separately initialized (including viewerSave for viewers). >> ViewerPrivate: TYPE = REF ViewerPrivateRep; ViewerPrivateRep: TYPE; ViewerSave: TYPE = REF ViewerSaveRep; ViewerSaveRep: TYPE; DrawRectProc: TYPE = PROC [r: DesignRect, l: Level, pr: DrawRef]; OutLineProc: TYPE = PROC [r: DesignRect, pr: DrawRef]; DrawCommentProc: TYPE = PROC [r: DesignRect, comment: Rope.ROPE, pr: DrawRef]; ContextFilter: TYPE = ARRAY Level OF RECORD [ doit: BOOL_FALSE, paintMode: Graphics.PaintMode _ opaque, color: Graphics.Color _ Graphics.black ]; ContextDraw: TYPE = PROC [context: Graphics.Context]; DrawToContext: PROC[pr: DrawRef, proc: ContextDraw, level: Level]; <<--calls proc which may use context; mode and color are set to level's need>> <<--call is suppressed if level does not need drawing; this is default.>> <<--on recursive calls, the context may or may not include previous transformations >> NewNullDeviceDrawRef: PROC [design: Design, deviceContext: Graphics.Context_NIL] RETURNS [DrawRef]; <<--for conveniance; usefull null procedures and default values>> <<--DrawRef's may also be created differently, if state of redrawing>> <<--gets proper initialization>> END.