CDSymbolicObjectsImpl.mesa (part of ChipNDale)
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, August 8, 1984 12:41:50 pm PDT
last edited Christian Jacobi, January 28, 1986 1:55:46 pm PST
DIRECTORY
CD,
CDInstances,
CDBasics,
CDLayers USING [MakeAbstract],
CDLRUCache,
CDImports,
CDIOExtras,
CDOps,
CDOrient,
CDSymbolicObjects,
CDPrivate,
CDProperties,
CDRects,
Imager,
ImagerPath,
Rope;
CDSymbolicObjectsImpl:
CEDAR
MONITOR
IMPORTS CD, CDInstances, CDBasics, CDLayers, CDLRUCache, CDIOExtras, CDOps, CDOrient, CDPrivate, CDProperties, CDRects, Imager, ImagerPath, Rope
EXPORTS CDSymbolicObjects
SHARES CDLayers =
BEGIN
symNameProp: ATOM = $SignalName;
symLayerProp: ATOM = $layerOfPin;
symOwnerProp: ATOM = $ownerOfPin;
markObject:
CD.Object;
markObjectPath: ImagerPath.Trajectory = CreateMarkObjectPath[];
dummySpecific:
REF SymRec =
NEW[SymRec];
SymRec: TYPE = RECORD [dummy: INT ← 17];
pinLayer: PUBLIC CD.Layer ← CD.NewLayer[NIL, $pinRepresentation];
segmentLayer: PUBLIC CD.Layer ← CD.NewLayer[NIL, $segmentRepresentation];
markLayer: CD.Layer ← CD.combined;
pinCache: CDLRUCache.LRUCache = CDLRUCache.Create[size: 17, newProc: NewPin];
segmentCache: CDLRUCache.LRUCache = CDLRUCache.Create[size: 17, newProc: NewSegment];
pinClass: PUBLIC REF CD.ObjectClass ← CD.RegisterObjectClass[$PinOb0];
segmentClass: PUBLIC REF CD.ObjectClass ← CD.RegisterObjectClass[$SymbolicSegment];
markClass:
PUBLIC
REF
CD.ObjectClass ←
CD.RegisterObjectClass[$AlignmentMarkOb];
NewPin:
PROC []
RETURNS [
CD.Object] = {
ob: CD.Object ← NEW[CD.ObjectRep];
ob.specificRef ← dummySpecific;
ob.layer ← pinLayer;
ob.class ← pinClass;
RETURN [ob]
};
NewSegment:
PROC []
RETURNS [
CD.Object] = {
ob: CD.Object ← NEW[CD.ObjectRep];
ob.specificRef ← dummySpecific;
ob.layer ← segmentLayer;
ob.class ← segmentClass;
RETURN [ob]
};
CreateMarkObjectPath:
PROC []
RETURNS [markObjectPath: ImagerPath.Trajectory] =
BEGIN
markObjectPath ← ImagerPath.MoveTo[[0, 0]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [0, 3]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [1, 2]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [3, 4]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [4, 3]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [2, 1]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [3, 0]];
markObjectPath ← ImagerPath.LineTo[markObjectPath, [0, 0]];
END;
Init:
PROC [] =
BEGIN
--rects
CDLayers.MakeAbstract[pinLayer];
pinClass.drawMe ← pinClass.quickDrawMe ← DrawPin;
pinClass.showMeSelected ← ShowSelectedSymRL;
pinClass.internalRead ← ReadPin;
pinClass.internalWrite ← WritePinOrSegment;
pinClass.wireTyped ← TRUE;
pinClass.symbolic ← TRUE;
pinClass.description ← "pin";
pinClass.describeInst ← DescribeInstance;
CDRects.UseAsCreateRect[pinLayer, RCreatePin, pinClass];
--lines
CDLayers.MakeAbstract[segmentLayer];
segmentClass.drawMe ← segmentClass.quickDrawMe ← DrawSegment;
segmentClass.showMeSelected ← ShowSelectedSymRL;
segmentClass.internalRead ← ReadSegment;
segmentClass.internalWrite ← WritePinOrSegment;
segmentClass.wireTyped ← TRUE;
segmentClass.symbolic ← TRUE;
segmentClass.description ← "segment";
segmentClass.describeInst ← DescribeInstance;
CDRects.UseAsCreateRect[segmentLayer, RCreateSegment, segmentClass];
--points
markClass.drawMe ← markClass.quickDrawMe ← DrawMark;
markClass.internalWrite ← WriteMark;
markClass.internalRead ← ReadMark;
markClass.description ← "mark";
markClass.symbolic ← TRUE;
markObject ←
NEW[
CD.ObjectRep ← [
class: markClass,
size: [4, 4],
layer: markLayer,
specificRef: $AlignmentMarkOb
]];
--common
[] ← CDProperties.RegisterProperty[symLayerProp, $layer];
[] ← CDProperties.RegisterProperty[symOwnerProp, $atom];
CDProperties.InstallProcs[prop: symOwnerProp, new: [makeCopy: CDProperties.CopyVal]];
CDProperties.InstallProcs[prop: symLayerProp, new: [makeCopy: CDProperties.CopyVal]];
END;
CreateMark:
PUBLIC
PROC [dummySize:
CD.Number𡤀]
RETURNS [
CD.Object] =
BEGIN
RETURN [markObject]
END;
CreateSegment:
PUBLIC
PROC [length:
CD.Number, dummyWidth:
CD.Number𡤀]
RETURNS [
CD.Object] =
BEGIN
ob: CD.Object = segmentCache.UnusedOrNew[];
size: CD.Position;
IF dummyWidth<=0 THEN dummyWidth ← 8;
size ← [dummyWidth, length];
ob.size ← CDBasics.MaxPoint[size, [1, 1]];
RETURN [segmentCache.ReplaceByAequivalent[ob]];
END;
RCreateSegment:
PROC [size:
CD.Position, l:
CD.Layer]
RETURNS [
CD.Object] =
BEGIN
RETURN [CreateSegment[size.y, size.x]]
END;
CreatePin:
PUBLIC
PROC [size:
CD.Position]
RETURNS [
CD.Object] =
BEGIN
ob: CD.Object = pinCache.UnusedOrNew[];
ob.size ← CDBasics.MaxPoint[size, [1, 1]];
RETURN [pinCache.ReplaceByAequivalent[ob]];
END;
RCreatePin:
PROC [size:
CD.Position, l:
CD.Layer]
RETURNS [
CD.Object] =
BEGIN
RETURN [CreatePin[size]]
END;
IsSymbolicOb:
PUBLIC
PROC [ob:
CD.Object]
RETURNS [
BOOL] = {
RETURN [ob.class=markClass OR ob.class=segmentClass OR ob.class=pinClass]
};
IsMark:
PUBLIC
PROC [ob:
CD.Object]
RETURNS [
BOOL] = {
RETURN [ob.class=markClass]
};
IsSegment:
PUBLIC
PROC [ob:
CD.Object]
RETURNS [
BOOL] = {
RETURN [ob.class=segmentClass]
};
IsPin:
PUBLIC
PROC [ob:
CD.Object]
RETURNS [
BOOL] = {
RETURN [ob.class=pinClass]
};
SymbolicKind:
PUBLIC
PROC [ob:
CD.Object]
RETURNS [k: CDSymbolicObjects.Kind] = {
SELECT
TRUE
FROM
ob.class=pinClass => k ← pin;
ob.class=segmentClass => k ← segment;
ob.class=markClass => k ← mark;
ENDCASE => k ← notSymbolic
};
SetOwner:
PUBLIC PROC [symInst:
CD.Instance, owner:
ATOM←
NIL] =
BEGIN
IF IsSymbolicOb[symInst.ob]
THEN
CDProperties.PutPropOnInstance[symInst, symOwnerProp, owner]
END;
GetOwner:
PUBLIC PROC [symInst:
CD.Instance]
RETURNS [at:
ATOM] =
BEGIN
WITH CDProperties.GetPropFromInstance[symInst, symOwnerProp]
SELECT
FROM
a: ATOM => at ← a
ENDCASE => at ← NIL
END;
SetName:
PUBLIC PROC [symInst:
CD.Instance, name: Rope.
ROPE] =
BEGIN
IF IsSymbolicOb[symInst.ob]
THEN
CDProperties.PutPropOnInstance[symInst, symNameProp, name]
END;
GetName:
PUBLIC PROC [symInst:
CD.Instance]
RETURNS [r: Rope.
ROPE ←
NIL] =
BEGIN
IF IsSymbolicOb[symInst.ob]
THEN {
WITH CDProperties.GetPropFromInstance[symInst, symNameProp]
SELECT
FROM
n: Rope.ROPE => r ← n;
rt: REF READONLY TEXT => r ← Rope.FromRefText[rt];
ENDCASE => NULL;
}
END;
SetLayer:
PUBLIC PROC [symInst:
CD.Instance, layer:
CD.Layer] =
BEGIN
IF IsSymbolicOb[symInst.ob]
THEN
CDProperties.PutPropOnInstance[symInst, symLayerProp, CDPrivate.layers[layer]]
END;
GetLayer:
PUBLIC PROC [symInst:
CD.Instance]
RETURNS [layer:
CD.Layer] =
BEGIN
WITH CDProperties.GetPropFromInstance[symInst, symLayerProp]
SELECT
FROM
lp: CDPrivate.LayerRef => layer ← lp^.number
ENDCASE => layer ← CD.combined
END;
DirectionFromOrient:
PUBLIC
PROC [o:
CD.Orientation]
RETURNS [dir: CDSymbolicObjects.Direction] =
BEGIN
SELECT o
FROM
CDOrient.original, CDOrient.rotate180X => dir ← west;
CDOrient.rotate90, CDOrient.rotate90X => dir ← south;
CDOrient.rotate180, CDOrient.mirrorX => dir ← east;
CDOrient.rotate270, CDOrient.rotate270X => dir ← north;
ENDCASE => ERROR;
END;
OrientFromDirection:
PUBLIC PROC [dir: CDSymbolicObjects.Direction]
RETURNS [o:
CD.Orientation] =
BEGIN
SELECT dir
FROM
west => o ← CDOrient.original;
south => o ← CDOrient.rotate90;
east => o ← CDOrient.rotate180;
north => o ← CDOrient.rotate270;
ENDCASE => ERROR;
END;
CreateSymInst:
PUBLIC
PROC [name: Rope.
ROPE, denotes:
CD.Rect, dummySize:
CD.Number, layer:
CD.Layer, owner:
ATOM, approachFrom: CDSymbolicObjects.Direction]
RETURNS [symInst:
CD.Instance] =
BEGIN
symOb: CD.Object;
orient: CD.Orientation ← OrientFromDirection[approachFrom];
loc: CD.Position;
denotes ← CDBasics.NormalizeRect[denotes];
IF denotes.x1#denotes.x2
AND denotes.y1#denotes.y2
THEN {
--pin
loc ← CDBasics.BaseOfRect[denotes];
symOb ← CreatePin[CDOrient.OrientedSize[CDBasics.SizeOfRect[denotes], orient]];
}
ELSE
IF denotes.x1=denotes.x2
AND denotes.y1=denotes.y2
THEN {
--mark
p: CD.Position;
symOb ← CreateMark[dummySize];
p ← CDOrient.MapPoint[
pointInCell: [0, 0],
cellSize: symOb.size,
cellInstOrient: orient,
cellInstPos: [0, 0]
];
loc ← [x: denotes.x1-p.x, y: denotes.y1-p.y];
}
ELSE {
--segment
l: CD.Number;
IF denotes.x1=denotes.x2
THEN {
l ← denotes.y2-denotes.y1;
IF approachFrom=south
OR approachFrom=north
THEN {
-- erroneous parameters..
approachFrom ← west;
orient ← OrientFromDirection[approachFrom];
}
}
ELSE {
l ← denotes.x2-denotes.x1;
IF approachFrom=west
OR approachFrom=east
THEN {
-- erroneous parameters..
approachFrom ← south;
orient ← OrientFromDirection[approachFrom];
}
};
symOb ← CreateSegment[length: l, dummyWidth: dummySize];
loc ← CDBasics.BaseOfRect[denotes];
SELECT approachFrom
FROM
west, south => NULL;
east => loc.x ← loc.x-symOb.size.x;
north => loc.y ← loc.y-symOb.size.x;
ENDCASE => ERROR;
};
symInst ← CDInstances.NewInstance[ob: symOb, location: loc, orientation: orient];
IF name#NIL THEN SetName[symInst, name];
IF layer#CD.combined THEN SetLayer[symInst, layer];
IF owner#NIL THEN SetOwner[symInst, owner];
END;
Denotes:
PUBLIC PROC [symInst:
CD.Instance]
RETURNS [
CD.Rect] =
BEGIN
itemInCell: CD.Rect;
SELECT
TRUE
FROM
symInst.ob.class=pinClass => itemInCell ← [x1: 0, y1: 0, x2: symInst.ob.size.x, y2: symInst.ob.size.y];
symInst.ob.class=segmentClass => itemInCell ← [x1: 0, y1: 0, x2: 0, y2: symInst.ob.size.y];
symInst.ob.class=markClass => itemInCell ← [0, 0, 0, 0];
ENDCASE => ERROR;
RETURN [CDOrient.MapRect[
itemInCell: itemInCell,
cellInstPos: symInst.location,
cellSize: symInst.ob.size,
cellInstOrient: symInst.orientation
]]
END;
EnumerateSymbolicObs:
PUBLIC
PROC [cellOb:
CD.Object←
NIL, eachInst: CDSymbolicObjects.InstEnumerator]
RETURNS [quit:
BOOL←
FALSE] =
BEGIN
cp: CD.CellPtr;
WITH cellOb.specificRef
SELECT
FROM
c: CD.CellPtr => cp ← c;
ip: CDImports.ImportPtr => {
-- HACK? until imports handle symbolic objects more reasonably
IF ip.boundInstance=NIL THEN RETURN [TRUE];
quit ← EnumerateSymbolicObs[ip.boundInstance.ob, eachInst];
RETURN
};
ENDCASE => RETURN [TRUE];
FOR list:
CD.InstanceList ← cp.contents, list.rest
WHILE (list#
NIL
AND ~quit)
DO
IF IsSymbolicOb[list.first.ob]
THEN {
quit ← eachInst[list.first]; -- do NOT catch errors
};
ENDLOOP;
END;
FindSymbolicObs:
PUBLIC
PROC [cellOb:
CD.Object←
NIL, name: Rope.
ROPE]
RETURNS [il:
CD.InstanceList←
NIL]=
BEGIN
Enumerate: CDSymbolicObjects.InstEnumerator = {
IF Rope.Equal[GetName[inst], name] THEN il ← CONS[inst, il];
};
[] ← EnumerateSymbolicObs[cellOb, Enumerate];
END;
WritePinOrSegment:
CD.InternalWriteProc
-- PROC [me: Object] -- =
BEGIN
CDIOExtras.WritePos[me.size];
END;
WriteMark:
CD.InternalWriteProc
--PROC [me: Object]-- = {};
ReadPin:
CD.InternalReadProc
--PROC [] RETURNS [Object]-- =
BEGIN
RETURN [CreatePin[CDIOExtras.ReadPos[]]]
END;
ReadSegment:
CD.InternalReadProc
--PROC [] RETURNS [Object]-- =
BEGIN
p: CD.Position ← CDIOExtras.ReadPos[];
RETURN [CreateSegment[p.y, p.x]]
END;
ReadMark:
CD.InternalReadProc
--PROC [] RETURNS [Object]-- = {
RETURN [markObject]};
DescribeInstance:
PROC[i:
CD.Instance]
RETURNS [Rope.
ROPE] =
BEGIN
RETURN [Rope.Cat[CDOps.LayerName[GetLayer[i]], " ", i.ob.class.description]];
END;
ShowSelectedSymRL:
PROC [inst:
CD.Instance, pos:
CD.Position,
orient: CD.Orientation, pr: CD.DrawRef] =
BEGIN
pr.drawRect[CDOrient.RectAt[pos, inst.ob.size, orient], CD.highLightShade, pr]
END;
DrawPin:
PROC [inst:
CD.Instance, pos:
CD.Position, orient:
CD.Orientation,
pr: CD.DrawRef] =
BEGIN
DrawPinInContext:
PROC [context: Imager.Context, ob:
CD.Object, layer:
CD.Layer] =
BEGIN
Imager.MaskVector[context, [0, 0], [ob.size.x, ob.size.y]];
Imager.MaskVector[context, [0, ob.size.y], [ob.size.x, 0]];
END;
IF pr.symbolics
AND (pr.scaleHint*
MIN[inst.ob.size.y, inst.ob.size.x]>3
OR pr.scaleHint<=0)
THEN {
pr.drawContext[pr, DrawPinInContext, inst.ob, pos, orient, pinLayer];
pr.drawComment[r: CDOrient.RectAt[pos, inst.ob.size, orient], comment: GetName[inst], pr: pr]
}
END;
DrawSegment:
PROC [inst:
CD.Instance, pos:
CD.Position, orient:
CD.Orientation,
pr: CD.DrawRef] =
BEGIN
DrawSegmentInContext:
PROC [context: Imager.Context, ob:
CD.Object, layer:
CD.Layer] =
BEGIN
Imager.MaskVector[context, [0, 0], [0, ob.size.y]];
Imager.MaskVector[context, [0, 0], [ob.size.x, ob.size.y/2]];
Imager.MaskVector[context, [0, ob.size.y], [ob.size.x, ob.size.y/2]];
END;
IF pr.symbolics
AND (pr.scaleHint*inst.ob.size.y>3
OR pr.scaleHint<=0)
THEN {
pr.drawContext[pr, DrawSegmentInContext, inst.ob, pos, orient, segmentLayer];
pr.drawComment[r: CDOrient.RectAt[pos, inst.ob.size, orient], comment: GetName[inst], pr: pr]
}
END;
DrawMark:
PROC [inst:
CD.Instance, pos:
CD.Position, orient:
CD.Orientation,
pr: CD.DrawRef] =
BEGIN
DrawPath:
PROC [context: Imager.Context, ob:
CD.Object, layer:
CD.Layer] =
BEGIN
Imager.MaskFillTrajectory[context, markObjectPath];
END;
IF pr.symbolics
AND (pr.scaleHint*inst.ob.size.y>2
OR pr.scaleHint<=0)
THEN {
pr.drawContext[pr, DrawPath, markObject, pos, orient, markLayer]
}
END;
Init[];
END.