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, August 24, 1986 7:28:57 pm PDT
DIRECTORY
Atom,
CD,
CDInstances,
CDCommandOps,
CDDirectory,
PopUpMenus,
CDOps,
CDPrivate,
CDProperties,
CDRopeViewer,
CDSequencer,
IO,
PropertyLists,
Rope,
RuntimeError USING [UNCAUGHT],
TerminalIO,
TokenIO,
ViewerTools USING [TiogaContents, TiogaContentsRec];
CDPropertyCommands: CEDAR PROGRAM
IMPORTS Atom, CDCommandOps, CDDirectory, CDOps, CDProperties, CDRopeViewer, CDSequencer, IO, PopUpMenus, Rope, RuntimeError, TerminalIO =
BEGIN
specialRights: BOOLFALSE; -- gives the right to access exclusive properties
Atomize: PROC [r: Rope.ROPE] RETURNS [ATOMNIL] = {
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] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "read signal-name"];
IF inst#NIL THEN {
name: Rope.ROPE;
TerminalIO.WriteRopes[" onto ", CDCommandOps.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.WriteRope[" done\n"]
ELSE TerminalIO.WriteRope[" removed\n"];
}
END;
EnterInstanceNameSP: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "read instance-name"];
IF inst#NIL THEN {
name: Rope.ROPE;
TerminalIO.WriteRopes[" onto ", CDCommandOps.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.WriteRope[" done\n"]
ELSE TerminalIO.WriteRope[" removed\n"];
}
END;
detail: INT ← 0;
--XXX make public on next release; probably in CDCommandOps
WriteValue: PROC [x: REF] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GOTO err;
IF x=NIL THEN TerminalIO.WriteRope["NIL"]
ELSE
WITH x SELECT FROM
ip: REF INT => TerminalIO.WriteF["^%g", IO.int[ip^]];
r: Rope.ROPE => TerminalIO.WriteRope[r];
a: ATOM => TerminalIO.WriteRopes["$", Atom.GetPName[a]];
ra: REF ATOM => TerminalIO.WriteRopes["^$", Atom.GetPName[ra^]];
d: CD.Design => TerminalIO.WriteRopes["design ", (IF d.name=NIL THEN "no name" ELSE d.name)];
ob: CD.Object => TerminalIO.WriteRope[CDOps.ObjectInfo[ob]];
ap: CD.Instance => TerminalIO.WriteRope[CDCommandOps.InstRope[ap]];
l: CDPrivate.LayerRef => TerminalIO.WriteRope[CDOps.LayerName[l.number]];
ENDCASE =>
IF detail=0 THEN TerminalIO.WriteF1["(%b)", IO.int[LOOPHOLE[x]]]
ELSE TerminalIO.WriteRope[IO.PutR[IO.refAny[x]]];
EXITS
err => TerminalIO.WriteRope["??"];
END;
RequestValue: PROC [default: REF] RETURNS [REF] =
BEGIN
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.WriteRope["(on crash: abort is ok)"];
default ← IO.GetRefAny[IO.RIS[TerminalIO.RequestRope["ref any > "]]]
};
ENDCASE --0, 1-- => {NULL};
ENDLOOP;
RETURN [default]
END;
PropertyDesign: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["enter property for the design\n"];
PropertyForSome[comm.design];
END;
PropertyApp: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "enter property of instance"];
IF inst#NIL THEN PropertyForSome[inst];
END;
PropertyOb: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "enter property for an object"];
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.WriteRope["this object class has no user accessable properties\n"];
END;
PropertyForSome: PROC [what: REF] =
BEGIN
value: REF;
atom: ATOM ← Atomize[TerminalIO.RequestRope["type property name: "]];
IF atom=NIL THEN {
TerminalIO.WriteRope[" empty name; not done\n"];
RETURN
};
value ← CDProperties.GetProp[what, atom];
TerminalIO.WriteRope[" old value: "];
WriteValue[value];
TerminalIO.WriteLn[];
IF IsExclusive[atom] THEN {
TerminalIO.WriteRope[" this property is used exclusively by the program; "];
IF ~specialRights THEN {
TerminalIO.WriteRope["interactive access is not possible\n"];
RETURN
}
};
value ← RequestValue[value];
CDProperties.PutProp[onto: what, prop: atom, val: value];
TerminalIO.WriteRope[" done\n"];
END;
--move this procedure to CDProperties
ShowProperties: PROC [from: REF] =
BEGIN
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.WriteRope[" no showable CD properties"];
END;
ShowPropertyList: PROC [pl: CD.PropList] =
BEGIN
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
END;
ShowProperty: PROC [pp: PropertyLists.KeyVal] =
BEGIN
TerminalIO.WriteRope[" name: "];
WriteValue[pp.key];
TerminalIO.WriteRope[" value: "];
WriteValue[pp.val];
TerminalIO.WriteLn[];
END;
ShowPropertiesSP: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "show property lists"];
IF inst#NIL THEN {
IF inst.properties#NIL THEN {
TerminalIO.WriteRope[" --properties on instance\n"];
ShowPropertyList[inst.properties];
};
IF inst.ob.properties#NIL THEN {
TerminalIO.WriteRope[" --properties on object itself\n"];
ShowPropertyList[inst.ob.properties];
};
TerminalIO.WriteRope[" --\n"];
}
END;
ShowPropertiesDesign: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["show properties of design\n"];
ShowPropertyList[comm.design.properties^];
TerminalIO.WriteRope[" --\n"];
END;
SaveComment: CDRopeViewer.SaveProc =
BEGIN
IF discard THEN RETURN;
CDProperties.PutProp[
onto: clientData,
prop: $Tioga,
val: NEW[ViewerTools.TiogaContentsRec←[contents: contents, formatting: formatting]]
]
END;
CommentDesignComm: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["edit comment for design\n"];
CommentSome[what: comm.design, caption: Rope.Cat["[comment for ", comm.design.name, "]"]];
END;
CommentObComm: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "comment object"];
IF inst#NIL THEN {
IF inst.ob.class.inDirectory THEN
CommentSome[what: inst.ob, caption: Rope.Cat["Comment on ", CDOps.ObjectInfo[inst.ob]]]
ELSE TerminalIO.WriteRope["this object class has no comments\n"];
}
END;
CommentAppComm: PROC [comm: CDSequencer.Command] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "comment instance"];
IF inst#NIL THEN {
CommentSome[what: inst, caption: "comment some instance (ChipNDale)"];
}
END;
CommentSome: PROC [what: REF, caption: Rope.ROPE] =
BEGIN
comment, formatting: Rope.ROPENIL;
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];
END;
NameMenuComm: PROC [comm: CDSequencer.Command] = {
m: PopUpMenus.Menu; x: REF;
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "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 [BOOLFALSE] = {
pType: CDProperties.PropertyProcs = CDProperties.FetchProcs[a];
IF pType#NIL THEN RETURN [pType.exclusive]
};
Register: PROC [n: NAT, key: ATOM, entry, doc: Rope.ROPENIL] = {
[] ← 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, CommentAppComm];
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.