CDPropertyCommands.mesa (part of ChipNDale)
Copyright © 1983, 1985 by Xerox Corporation. All rights reserved.
by Christian Jacobi, November 7, 1983 5:39 pm
last edited Christian Jacobi, January 7, 1986 1:17:03 pm PST
DIRECTORY
Atom,
CD,
CDInstances,
CDCommandOps,
CDDirectory,
CDMenus,
CDOps,
CDPrivate,
CDProperties,
CDRopeViewer,
CDSequencer,
IO,
Properties,
Rope,
RuntimeError USING [UNCAUGHT],
TerminalIO,
TokenIO,
ViewerTools USING [TiogaContents, TiogaContentsRec];
CDPropertyCommands: CEDAR PROGRAM
IMPORTS Atom, CDCommandOps, CDDirectory, CDMenus, CDOps, CDProperties, CDRopeViewer, CDSequencer, IO, 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.WriteRope[" onto "];
CDCommandOps.WriteInfo[inst];
name ← TerminalIO.RequestRope[" type name: "];
--if name = nil, property will be removed
IF Rope.IsEmpty[name] THEN name←NIL;
CDProperties.PutPropOnInstance[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.WriteRope[" onto "];
CDCommandOps.WriteInfo[inst];
name ← TerminalIO.RequestRope[" type name: "];
--if name = nil, property will be removed
IF Rope.IsEmpty[name] THEN name←NIL;
CDProperties.PutPropOnInstance[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.Info[ob]];
ap: CD.Instance => CDCommandOps.WriteInfo[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
ShowProperty[list.first]
ENDLOOP
END;
ShowProperty: PROC [pp: Properties.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 Properties"];
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.Info[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] =
BEGIN
inst: CD.Instance ← CDCommandOps.TheInstance[comm, "property and name menu"];
IF inst=NIL THEN
CDSequencer.ExecuteCommand[comm: comm, command: $NameMenuOnlyDesign]
ELSE IF inst.ob.class.inDirectory THEN
CDSequencer.ExecuteCommand[comm: comm, command: $NameMenuFull]
ELSE
CDSequencer.ExecuteCommand[comm: comm, command: $NameMenuOnlyApp]
END;
IsExclusive: PROC [a: ATOM] RETURNS [BOOLFALSE] =
BEGIN
pType: CDProperties.PropertyProcs = CDProperties.FetchProcs[a];
IF pType#NIL THEN RETURN [pType.exclusive]
END;
-- 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];
[] ← CDMenus.CreateMenu["Names & Properties", $NameMenuFull];
CDMenus.ImplementMenuCommand[$NameMenuFull, $NameMenuFull];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Rename design", key: $RenameDesign]; --CDMoveCopyCommands
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Rename object", key: $RenameS]; --CDCellCommands
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Property (design)", key: $PropertyDesign];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Property (instance)", key: $PropertyApp];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Property (object)", key: $PropertyOb];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Comment (design)", key: $CommentDesign];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Comment (instance)", key: $CommentApp];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Comment (object)", key: $CommentOb];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Instance-name", key: $InstanceNameS];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Signal-name (instance)", key: $SignalNameS];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Show prop (design)", key: $ShowPropertiesDesign];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Show prop (i&o)", key: $ShowPropertiesS];
CDMenus.CreateEntry[menu: $NameMenuFull, entry: "Display signal-names", key: $DisplayNames]; --CDVCommands
[] ← CDMenus.CreateMenu["Names & Properties", $NameMenuOnlyApp];
CDMenus.ImplementMenuCommand[$NameMenuOnlyApp, $NameMenuOnlyApp];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Rename design", key: $RenameDesign]; --CDMoveCopyCommands
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Property (design)", key: $PropertyDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Property (instance)", key: $PropertyApp];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Comment (design)", key: $CommentDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Comment (instance)", key: $CommentApp];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Instance-name (instance)", key: $InstanceNameS];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Signal-name (instance)", key: $SignalNameS];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Show prop (design)", key: $ShowPropertiesDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Show prop (i&o)", key: $ShowPropertiesS];
CDMenus.CreateEntry[menu: $NameMenuOnlyApp, entry: "Display signal-names", key: $DisplayNames]; --CDVCommands
[] ← CDMenus.CreateMenu["Names & Properties", $NameMenuOnlyDesign];
CDMenus.ImplementMenuCommand[$NameMenuOnlyDesign, $NameMenuOnlyDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyDesign, entry: "Rename design", key: $RenameDesign]; --CDMoveCopyCommands
CDMenus.CreateEntry[menu: $NameMenuOnlyDesign, entry: "Property (design)", key: $PropertyDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyDesign, entry: "Comment (design)", key: $CommentDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyDesign, entry: "Show prop (design)", key: $ShowPropertiesDesign];
CDMenus.CreateEntry[menu: $NameMenuOnlyDesign, entry: "Display signal-names", key: $DisplayNames]; --CDVCommands
CDSequencer.ImplementCommand[$NameMenu, NameMenuComm];
CDSequencer.ImplementCommand[$NameMenu2, NameMenuComm];
END.