CDPropertyCommands.mesa (part of ChipNDale)
Copyright © 1983, 1985 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, November 7, 1983 5:39 pm
Last edited by: Christian Jacobi, October 23, 1986 10:41:43 am PDT
DIRECTORY
Atom,
CD,
CDInstances,
CDDirectory,
PopUpMenus,
CDOps,
CDPrivate,
CDProperties,
CDRopeViewer,
CDSequencer,
IO,
PropertyLists,
Rope,
RuntimeError USING [UNCAUGHT],
TerminalIO,
TokenIO,
ViewerTools USING [TiogaContents, TiogaContentsRec];
CDPropertyCommands:
CEDAR
PROGRAM
IMPORTS Atom, CDDirectory, CDOps, CDProperties, CDRopeViewer, CDSequencer, IO, PopUpMenus, Rope, RuntimeError, TerminalIO =
BEGIN
specialRights: BOOL ← FALSE; -- gives the right to access exclusive properties
Atomize:
PROC [r: Rope.
ROPE]
RETURNS [
ATOM←
NIL] = {
IF Rope.Length[r]>1 AND Rope.Fetch[r]='$ THEN r ← Rope.Substr[r, 1, Rope.Length[r]-1];
IF ~Rope.IsEmpty[r] THEN RETURN [Atom.MakeAtom[r]]
};
EnterSignalNameSP:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "read signal-name"];
IF inst#
NIL
THEN {
name: Rope.ROPE;
TerminalIO.PutRopes[" onto ", CDOps.InstRope[inst]];
name ← TerminalIO.RequestRope[" type name: "];
--if name = nil, property will be removed
IF Rope.IsEmpty[name] THEN name←NIL;
CDProperties.PutInstanceProp[onto: inst, prop: $SignalName, val: name];
IF name#NIL THEN TerminalIO.PutRope[" done\n"]
ELSE TerminalIO.PutRope[" removed\n"];
}
};
EnterInstanceNameSP:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "read instance-name"];
IF inst#
NIL
THEN {
name: Rope.ROPE;
TerminalIO.PutRopes[" onto ", CDOps.InstRope[inst]];
name ← TerminalIO.RequestRope[" type name: "];
--if name = nil, property will be removed
IF Rope.IsEmpty[name] THEN name←NIL;
CDProperties.PutInstanceProp[onto: inst, prop: $InstanceName, val: name];
IF name#NIL THEN TerminalIO.PutRope[" done\n"]
ELSE TerminalIO.PutRope[" removed\n"];
}
};
--XXX make public on next release; probably in ?
WriteValue:
PROC [x:
REF] = {
ENABLE RuntimeError.UNCAUGHT => GOTO err;
IF x=NIL THEN TerminalIO.PutRope["NIL"]
ELSE
WITH x
SELECT
FROM
ip: REF INT => TerminalIO.PutF["^%g", IO.int[ip^]];
r: Rope.ROPE => TerminalIO.PutRope[r];
a: ATOM => TerminalIO.PutRopes["$", Atom.GetPName[a]];
ra: REF ATOM => TerminalIO.PutRopes["^$", Atom.GetPName[ra^]];
d: CD.Design => TerminalIO.PutRopes["design ", (IF d.name=NIL THEN "no name" ELSE d.name)];
ob: CD.Object => TerminalIO.PutRope[CDOps.ObjectRope[ob]];
i: CD.Instance => TerminalIO.PutRope[CDOps.InstRope[i]];
l: CDPrivate.LayerRef => TerminalIO.PutRope[CDOps.LayerRope[l.number]];
ENDCASE => TerminalIO.PutF1["(%b)", IO.int[LOOPHOLE[x]]]
EXITS err => TerminalIO.PutRope["??"];
};
RequestValue:
PROC [default:
REF]
RETURNS [
REF] = {
n: CARDINAL𡤀
WHILE n=0
DO
n ← TerminalIO.RequestSelection["property value", LIST["leave it", "remove", "INT", "ROPE", "ATOM", "REF ANY"]];
SELECT n
FROM
2 => {default ← NIL};
3 => {default ← NEW[INT←TerminalIO.RequestInt["int > "]]};
4 => {default ← TerminalIO.RequestRope["rope > "]};
5 => {default ← Atomize[TerminalIO.RequestRope["atom > "]]};
6 => {
TerminalIO.PutRope["(on crash: abort is ok)"];
default ← IO.GetRefAny[IO.RIS[TerminalIO.RequestRope["ref any > "]]]
};
ENDCASE --0, 1-- => {NULL};
ENDLOOP;
RETURN [default]
};
PropertyDesign:
PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["enter property for the design\n"];
PropertyForSome[comm.design];
};
PropertyApp:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "enter property of instance\n"];
IF inst#NIL THEN PropertyForSome[inst];
};
PropertyOb:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "enter property for an object\n"];
IF inst#
NIL
THEN
IF inst.ob.class.inDirectory
OR specialRights
THEN {
PropertyForSome[inst.ob];
IF inst.ob.class.inDirectory
THEN
CDDirectory.PropagateChange[inst.ob, comm.design];
}
ELSE TerminalIO.PutRope["this object class has no user accessable properties\n"];
};
PropertyForSome:
PROC [what:
REF] = {
value: REF;
atom: ATOM ← Atomize[TerminalIO.RequestRope["type property name: "]];
IF atom=
NIL
THEN {
TerminalIO.PutRope[" empty name; not done\n"];
RETURN
};
value ← CDProperties.GetProp[what, atom];
TerminalIO.PutRope[" old value: "];
WriteValue[value];
TerminalIO.PutRope["\n"];
IF IsExclusive[atom]
THEN {
TerminalIO.PutRope[" this property is used exclusively by the program; "];
IF ~specialRights
THEN {
TerminalIO.PutRope["interactive access is not possible\n"];
RETURN
}
};
value ← RequestValue[value];
CDProperties.PutProp[onto: what, prop: atom, val: value];
TerminalIO.PutRope[" done\n"];
};
--move this procedure to CDProperties
ShowProperties:
PROC [from:
REF] = {
WITH from
SELECT
FROM
a: CD.Instance => ShowPropertyList[a.properties];
o: CD.Object => ShowPropertyList[o.properties];
d: CD.Design => ShowPropertyList[d.properties^];
t: CD.Technology => ShowPropertyList[t.properties^];
--l: CD.LayerRef => ...;
--at: ATOM => ...;
ENDCASE => TerminalIO.PutRope[" no showable CD properties"];
};
ShowPropertyList:
PROC [pl:
CD.PropList] = {
FOR list:
CD.PropList ← pl, list.rest
WHILE list#
NIL
DO
WITH list.first.key
SELECT
FROM
ra: REF ATOM => IF ra^=$MayBeRemoved THEN LOOP
ENDCASE => NULL;
ShowProperty[list.first];
ENDLOOP
};
ShowProperty:
PROC [pp: PropertyLists.KeyVal] = {
TerminalIO.PutRope[" name: "];
WriteValue[pp.key];
TerminalIO.PutRope[" value: "];
WriteValue[pp.val];
TerminalIO.PutRope["\n"];
};
ShowPropertiesSP:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "show property lists\n"];
IF inst#
NIL
THEN {
IF inst.properties#
NIL
THEN {
TerminalIO.PutRope[" --properties on instance\n"];
ShowPropertyList[inst.properties];
};
IF inst.ob.properties#
NIL
THEN {
TerminalIO.PutRope[" --properties on object itself\n"];
ShowPropertyList[inst.ob.properties];
};
TerminalIO.PutRope[" --\n"];
}
};
ShowPropertiesDesign:
PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["show properties of design\n"];
ShowPropertyList[comm.design.properties^];
TerminalIO.PutRope[" --\n"];
};
SaveComment: CDRopeViewer.SaveProc = {
IF discard THEN RETURN;
CDProperties.PutProp[
onto: clientData,
prop: $Tioga,
val: NEW[ViewerTools.TiogaContentsRec←[contents: contents, formatting: formatting]]
]
};
CommentDesignComm:
PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["edit comment for design\n"];
CommentSome[what: comm.design, caption: Rope.Cat["[comment for ", comm.design.name, "]"]];
};
CommentObComm:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "comment object\n"];
IF inst#
NIL
THEN {
IF inst.ob.class.inDirectory
THEN
CommentSome[what: inst.ob, caption: Rope.Cat["Comment on ", CDOps.ObjectRope[inst.ob]]]
ELSE TerminalIO.PutRope["this object class has no comments\n"];
}
};
CommentInstComm:
PROC [comm: CDSequencer.Command] = {
inst: CD.Instance ← CDOps.TheInstance[comm.design, "comment instance"];
IF inst#
NIL
THEN {
CommentSome[what: inst, caption: "comment some instance (ChipNDale)"];
}
};
CommentSome:
PROC [what:
REF, caption: Rope.
ROPE] = {
comment, formatting: Rope.ROPE ← NIL;
WITH CDProperties.GetProp[from: what, prop: $Tioga]
SELECT
FROM
t: ViewerTools.TiogaContents => {
comment ← t.contents;
formatting ← t.formatting;
};
r: Rope.ROPE => comment ← r;
ENDCASE => NULL;
CDRopeViewer.Edit[contents: comment, formatting: formatting, caption: caption, save: SaveComment, clientData: what];
};
NameMenuComm:
PROC [comm: CDSequencer.Command] = {
m: PopUpMenus.Menu; x: REF;
inst: CD.Instance ← CDOps.TheInstance[comm.design, "property and name menu"];
IF inst=NIL THEN m ← mD
ELSE IF inst.ob.class.inDirectory THEN m ← mFull
ELSE m ← mInst;
x ← PopUpMenus.Call[m, comm];
WITH x
SELECT
FROM
a: ATOM => CDSequencer.ExecuteCommand[comm: comm, key: a]
ENDCASE => NULL
};
IsExclusive:
PROC [a:
ATOM]
RETURNS [
BOOL←
FALSE] = {
pType: CDProperties.PropertyProcs = CDProperties.FetchProcs[a];
IF pType#NIL THEN RETURN [pType.exclusive]
};
Register:
PROC [n:
NAT, key:
ATOM, entry, doc: Rope.
ROPE ←
NIL] = {
[] ← PopUpMenus.Entry[mFull, entry, NIL, key, doc];
IF n<=1 THEN RETURN;
[] ← PopUpMenus.Entry[mInst, entry, NIL, key, doc];
IF n<=2 THEN RETURN;
[] ← PopUpMenus.Entry[mD, entry, NIL, key, doc];
};
mFull: PopUpMenus.Menu ← PopUpMenus.Create["Names & PropertyLists", NIL];
mInst: PopUpMenus.Menu ← PopUpMenus.Create["Names & PropertyLists", NIL];
mD: PopUpMenus.Menu ← PopUpMenus.Create["Names & PropertyLists", NIL];
-- module initialization
CDSequencer.ImplementCommand[$CommentDesign, CommentDesignComm];
CDSequencer.ImplementCommand[$CommentApp, CommentInstComm];
CDSequencer.ImplementCommand[$CommentOb, CommentObComm];
CDSequencer.ImplementCommand[$SignalNameS, EnterSignalNameSP];
CDSequencer.ImplementCommand[$InstanceNameS, EnterInstanceNameSP];
CDSequencer.ImplementCommand[$PropertyDesign, PropertyDesign];
CDSequencer.ImplementCommand[$PropertyApp, PropertyApp];
CDSequencer.ImplementCommand[$PropertyOb, PropertyOb];
CDSequencer.ImplementCommand[$ShowPropertiesS, ShowPropertiesSP,, doQueue];
CDSequencer.ImplementCommand[$ShowPropertiesDesign, ShowPropertiesDesign,, doQueue];
Register[3, $RenameDesign, "rename design"];
Register[1, $RenameS, "rename object"];
Register[3, $PropertyDesign, "property (design)", "add/change a property"];
Register[2, $PropertyApp, "property (instance)", "add/change a property"];
Register[1, $PropertyOb, "property (object)", "add/change a property"];
Register[3, $CommentDesign, "comment (design)", "edit the comment view"];
Register[2, $CommentApp, "comment (instance)", "edit the comment view"];
Register[1, $CommentOb, "comment (object)", "edit the comment view"];
Register[2, $InstanceNameS, "instance-name", "accept an instancename"];
Register[2, $SignalNameS, "signal-name (instance)", "accept a signalname"];
Register[3, $ShowPropertiesDesign, "list prop (design)", "list properties hanging on design"];
Register[2, $ShowPropertiesS, "list prop (i&o)", "<N-left> | list properties of selected object"];
Register[3, $DisplayNames, "display signal-names", "<N-right> | signal names of all visible objects"];
CDSequencer.ImplementCommand[$NameMenu, NameMenuComm, , dontQueue];
END.