///cd23/CDImpl.mesa (part of ChipNDale)
Copyright © 1983, 1986 by Xerox Corporation. All rights reserved.
Created by: Christian Jacobi, June 24, 1983 5:07 pm
gbb April 4, 1986 9:30:55 am PST
Last Edited by: Christian Jacobi, September 4, 1986 11:35:38 am PDT
DIRECTORY
Atom,
Basics,
CD,
CDBasics,
CDDefaultProcs,
CDEvents,
CDLayers,
CDPrivate,
Imager,
PrincOps,
RefTab,
Rope,
SafeStorage;
CDImpl: CEDAR MONITOR
IMPORTS Atom, Basics, CD, CDDefaultProcs, CDEvents, CDLayers, RefTab, SafeStorage
EXPORTS CD, CDPrivate
SHARES CDLayers, CDPrivate =
BEGIN
Error: PUBLIC ERROR[ec: CD.ErrorCode ← programmingError, explanation: Rope.ROPENIL] = CODE;
permanent: ZONE = SafeStorage.GetPermanentZone[];
--assume everithing gets correct even if all references are lost,
--don't care about memory area, hint only
layers: PUBLIC REF ARRAY CD.Layer OF CDPrivate.LayerRef =
permanent.NEW[ARRAY CD.Layer OF CDPrivate.LayerRef];
registerTechEvent: CDEvents.EventRegistration = CDEvents.RegisterEventType[$RegisterTechnology];
technologyRegistration: RefTab.Ref = RefTab.Create[]; -- contains technologies
PrivateTRef: TYPE = REF PrivateTRep;
PrivateTRep: PUBLIC TYPE = RECORD [
objectRegisterTab: RefTab.Ref, -- contains object types
layerKeyTab: RefTab.Ref -- contains Layers
];
nilTechnologyPrivate: PrivateTRef = NEW[PrivateTRep ← [
objectRegisterTab: RefTab.Create[], --for technology dependant objects it contains NIL
layerKeyTab: RefTab.Create[]
]];
RegisterObjectClass: PUBLIC PROC [objectType: ATOM, class: CD.ObjectClassRec] RETURNS [CD.ObjectClass] = {
done: BOOL;
c: CD.ObjectClass = permanent.NEW[CD.ObjectClassRec𡤌lass];
c.properties ← CD.InitPropRef[];
IF objectType#NIL THEN c.objectType ← objectType;
IF c.drawMe=NIL THEN c.drawMe ← CDDefaultProcs.DrawMe;
IF c.quickDrawMe=NIL THEN c.quickDrawMe ← CDDefaultProcs.QuickDrawMe;
IF c.showMeSelected=NIL THEN c.showMeSelected ← CDDefaultProcs.ShowMeSelected;
IF c.hitInside=NIL THEN c.hitInside ← CDDefaultProcs.HitInside;
IF c.interestRect=NIL THEN c.interestRect ← CDDefaultProcs.InterestRect;
IF c.describe=NIL THEN c.describe ← CDDefaultProcs.Describe;
IF c.describeInst=NIL THEN c.describeInst ← CDDefaultProcs.DescribeInstance;
IF c.origin=NIL THEN c.origin ← CDDefaultProcs.Origin;
IF c.technology=NIL THEN
done ← RefTab.Insert[nilTechnologyPrivate.objectRegisterTab, objectType, c]
ELSE {
techPriv: PrivateTRef = c.technology.cdPriv;
objectRegisterTab: RefTab.Ref = techPriv.objectRegisterTab;
globFound: BOOL;
x: REF;
[globFound, x] ← RefTab.Fetch[nilTechnologyPrivate.objectRegisterTab, objectType];
--still check if it might be global
IF globFound AND x#NIL THEN done ← FALSE
ELSE {
[] ← RefTab.Insert[nilTechnologyPrivate.objectRegisterTab, objectType, NIL];
--global register it used per technology
done ← RefTab.Insert[objectRegisterTab, objectType, c]; -- technology register
}
};
IF NOT done THEN ERROR Error[doubleRegistration];
RETURN [c]
};
FetchObjectClass: PUBLIC PROC [objectType: REF, technology: CD.Technology←NIL]
RETURNS [CD.ObjectClass] = {
x: REF;
class: CD.ObjectClass ← NIL;
found: BOOL FALSE;
IF technology#NIL THEN { -- search in technology table
techPriv: PrivateTRef = technology.cdPriv;
[found, x] ← RefTab.Fetch[techPriv.objectRegisterTab, objectType];
};
IF NOT found THEN { -- search in global table
[found, x] ← RefTab.Fetch[nilTechnologyPrivate.objectRegisterTab, objectType];
--may find it but have NIL value: then is technologydependant
};
IF found THEN class ← NARROW[x];
RETURN [class]
};
lastLayer: CD.Layer ← 6;
InitiateLayer: PROC [layer: CD.Layer, technology: CD.Technology←NIL, uniqueKey: ATOM] = {
techPriv: PrivateTRef;
layers[layer].technology ← technology;
layers[layer].uniqueKey ← uniqueKey;
CDLayers.MakePaint[layer];
IF technology=NIL THEN techPriv ← nilTechnologyPrivate
ELSE {
techPriv ← technology.cdPriv;
technology.usedLayers ← CONS[layer, technology.usedLayers]
};
[] ← RefTab.Insert[techPriv.layerKeyTab, uniqueKey, layers[layer]];
};
ConvertLayer: PUBLIC ENTRY PROC [technology: CD.Technology, uniqueKey: ATOM, into: CD.Layer] = {
--Helps conversion when layers are renamed
ENABLE UNWIND => NULL;
techPriv: PrivateTRef;
IF uniqueKey=NIL OR uniqueKey=$NIL THEN RETURN WITH ERROR Error[callingError, "bad uniqueKey"]; -- avoid problems with NIL as ATOM; any IO routine might use $NIL instead
IF technology=NIL THEN techPriv ← nilTechnologyPrivate
ELSE techPriv ← technology.cdPriv;
[] ← RefTab.Insert[techPriv.layerKeyTab, uniqueKey, layers[into]];
};
NewLayer: PUBLIC ENTRY PROC [technology: CD.Technology←NIL, uniqueKey: ATOM] RETURNS [CD.Layer] = {
ENABLE UNWIND => NULL;
IF uniqueKey=NIL OR uniqueKey=$NIL THEN
RETURN WITH ERROR Error[callingError, "bad uniqueKey"];
-- avoid problems with NIL as ATOM; any IO routine might use $NIL instead
IF lastLayer>=CD.layerNum-1 THEN
RETURN WITH ERROR Error[noResource, "too many layers requested; (probably too many different technologies used)"];
lastLayer ← lastLayer+1;
InitiateLayer[lastLayer, technology, uniqueKey];
RETURN [lastLayer]
};
FetchLayer: PUBLIC PROC [t: CD.Technology, uniqueKey: ATOM] RETURNS [CD.Layer] = {
found: BOOLFALSE;
l: CD.Layer ← CD.errorLayer;
x: REF;
IF t#NIL THEN {
techPriv: PrivateTRef = t.cdPriv;
[found: found, val: x] ← RefTab.Fetch[techPriv.layerKeyTab, uniqueKey];
};
IF ~found THEN {
[found: found, val: x] ← RefTab.Fetch[nilTechnologyPrivate.layerKeyTab, uniqueKey];
};
IF found THEN l ← NARROW[x, CDPrivate.LayerRef].number;
RETURN [l]
};
LayerTechnology: PUBLIC PROC [l: CD.Layer] RETURNS [CD.Technology] = {
RETURN [layers[l].technology];
};
LayerKey: PUBLIC PROC [l: CD.Layer] RETURNS [ATOM] = {
RETURN [layers[l].uniqueKey];
};
CreateDrawRef: PUBLIC PROC [inf: CD.DrawInformation] RETURNS [dr: CD.DrawRef] = {
dr ← NEW[CD.DrawInformation ← inf];
dr.properties ← NEW[CD.PropList←NIL];
IF dr.drawChild=NIL THEN dr.drawChild�ultProcs.DrawChild;
IF dr.drawRect=NIL THEN dr.drawRect�ultProcs.DrawRect;
IF dr.drawOutLine=NIL THEN dr.drawOutLine�ultProcs.DrawOutLine;
IF dr.drawContext=NIL THEN dr.drawContext�ultProcs.DrawContext;
IF dr.drawComment=NIL THEN dr.drawComment�ultProcs.DrawComment;
IF dr.stopFlag=NIL THEN dr.stopFlag←NEW[BOOLFALSE];
IF dr.priorityChecker=NIL THEN dr.priorityChecker ← CDDefaultProcs.IgnorePriority;
IF dr.setGround=NIL THEN dr.setGround ← CDDefaultProcs.IgnoreGround;
};
RegisterTechnology: PUBLIC PROC [key: ATOM, name: Rope.ROPE, lambda: CD.Number] RETURNS [CD.Technology] = {
--not ENTRY since RefTab.Insert does necessary monitoring and CDEvents.ProcessEvent
--is dangerous
t: CD.Technology = permanent.NEW[CD.TechnologyRep←[
properties: CD.InitPropRef[],
key: key,
name: IF name#NIL THEN name ELSE Atom.GetPName[key],
lambda: lambda,
usedLayers: NIL,
cdPriv: permanent.NEW[PrivateTRep ← [RefTab.Create[], RefTab.Create[]]]
]];
IF ~RefTab.Insert[technologyRegistration, key, t] THEN {
Error[doubleRegistration, "technology exist already"];
};
[] ← CDEvents.ProcessEvent[ev: registerTechEvent, design: NIL, x: t];
RETURN[t]
};
FetchTechnology: PUBLIC PROC [key: ATOM] RETURNS [tech: CD.Technology] = {
RETURN [NARROW[RefTab.Fetch[technologyRegistration, key].val]]
};
EnumerateTechnologies: PUBLIC PROC [proc: CD.TechnologyEnumerator] RETURNS [quit: BOOL] = {
Action: RefTab.EachPairAction = {
quit ← proc[NARROW[val]]
};
quit ← RefTab.Pairs[technologyRegistration, Action];
};
DEnumProc: TYPE = PROC [p: CDPrivate.DesignEnumerator] RETURNS [BOOL];
dEnumerators: LIST OF DEnumProc←NIL;
EnumDesigns: PUBLIC PROC [p: CDPrivate.DesignEnumerator] RETURNS [quit: BOOLFALSE] = {
seen: RefTab.Ref ← RefTab.Create[5];
Inner: CDPrivate.DesignEnumerator = {
IF RefTab.Insert[seen, design, design] THEN quit ← p[design]
};
FOR el: LIST OF DEnumProc ← dEnumerators, el.rest WHILE el#NIL AND ~quit DO
quit ← el.first[Inner];
ENDLOOP;
};
InstallDesignEnumerator: PUBLIC ENTRY PROC [enum: DEnumProc] = {
IF enum#NIL THEN dEnumerators ← CONS[enum, dEnumerators];
};
Hash: PUBLIC PROC[x: REF] RETURNS [h: CARDINAL] = {
Munch: PROC [REF] RETURNS [CARDINAL] = TRUSTED MACHINE CODE {
PrincOps.zXOR;
};
WITH x SELECT FROM
ob: CD.Object => {
h ← Munch[ob.class];
h ← Basics.BITXOR[h, (ob.size.x MOD 100B)*1000B];
h ← Basics.BITXOR[h, (ob.size.y MOD 1000B)*100B];
h ← Basics.BITXOR[h, ob.layer];
};
ENDCASE => h ← Munch[x];
};
blueLayer, redLayer, greenLayer, yellowLayer: CD.Layer;
IF registerTechEvent=NIL THEN ERROR;
FOR l: CD.Layer IN CD.Layer DO
layers[l] ← permanent.NEW[CDPrivate.LayerRec ← [
properties: CD.InitPropRef[],
number: l
]];
layers[l].globalUniqueKey ← layers[l];
ENDLOOP;
InitiateLayer[CD.undefLayer, NIL, $undefLayer];
CDLayers.MakeAbstract[CD.undefLayer];
InitiateLayer[CD.shadeLayer, NIL, $shadeLayer];
InitiateLayer[CD.errorLayer, NIL, $errorLayer];
InitiateLayer[CD.backgroundLayer, NIL, $backGround];
CDLayers.MakeAbstract[CD.backgroundLayer];
InitiateLayer[CD.outlineLayer, NIL, $outline];
CDLayers.MakeAbstract[CD.outlineLayer];
InitiateLayer[CD.selectionLayer, NIL, $selection];
CDLayers.MakeAbstract[CD.selectionLayer];
InitiateLayer[CD.commentLayer, NIL, $comment];
blueLayer ← NewLayer[NIL, $blue];
redLayer ← NewLayer[NIL, $red];
greenLayer ← NewLayer[NIL, $green];
yellowLayer ← NewLayer[NIL, $yellow];
END.