CDSatellitesCommands.mesa
Copyright © 1985, 1987 by Xerox Corporation. All rights reserved.
Written by: Christian Jacobi, August 29, 1986 9:55:02 pm PDT
This module is descended from the early implementation of satellites by Monier. It has been
rewritten a number of times since then by Sindhu and Serlet to find an implementation that
is comfortable to use both from programs and interactively. This last version is a complete
rewrite by Jacobi, one hopes for the last time!
Old version by: Pradeep Sindhu December 20, 1985 1:25:44 pm PST
Old version by: Pradeep Sindhu March 26, 1986 3:21:40 pm PST
Old version by: Bertrand Serlet August 17, 1986 0:49:00 am PDT
Old version by: Christian Jacobi, July 15, 1986 1:59:30 pm PDT
Old version by: Jean-Marc Frailong July 28, 1986 6:45:49 pm PDT
Last edited by: Christian Jacobi, March 23, 1987 6:26:35 pm PST
DIRECTORY
CD, CDOps, CDPanelFonts, CDSatellites, CDSequencer, CDTexts, IO, Rope, TerminalIO;
CDSatellitesCommands: CEDAR PROGRAM
IMPORTS CD, CDOps, CDPanelFonts, CDSatellites, CDSequencer, CDTexts, IO, TerminalIO =
BEGIN
CountAssociated: PROC [design: CD.Design, master: REF] RETURNS [n: INT𡤀] = {
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF CDTexts.IsText[w.first.ob] AND CDSatellites.IsAssociated[master, w.first] THEN n ← n+1;
ENDLOOP;
};
SelectWithMaster: PROC [design: CD.Design, master: REF, deselectOthers: BOOLTRUE] RETURNS [n: INT𡤀] = {
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF CDTexts.IsText[w.first.ob] AND CDSatellites.IsAssociated[master, w.first] THEN {
n ← n+1; SelectInst[design, w.first]
}
ELSE IF master=w.first THEN SelectInst[design, w.first]
ELSE IF deselectOthers THEN DeSelectInst[design, w.first]
ENDLOOP;
};
SelectObjectSatellites: PROC [design: CD.Design, exclusive: BOOLTRUE] = {
n, m: INT; ob: CD.Object ← CDOps.PushedTopCell[design];
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
n ← SelectWithMaster[design, ob, exclusive];
m ← CountAssociated[design, NIL];
IF m>0
THEN TerminalIO.PutF["select object satellites of pushed in cell: %g satellite(s) selected; %g non-associated texts found\n", [integer[n]], [integer[m]]]
ELSE TerminalIO.PutF["select object satellites of pushed in cell: %g satellite(s) selected; (all texts are satellites)\n", [integer[n]]]
};
SelectNonSatellites: PROC [design: CD.Design, exclusive: BOOLTRUE] = {
n, m: INT; ob: CD.Object ← CDOps.PushedTopCell[design];
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
n ← SelectWithMaster[design, NIL, exclusive];
m ← CountAssociated[design, ob];
TerminalIO.PutF["select non-associated texts: %g text(s) selected; (%g text(s) are object satellites)\n", [integer[n]], [integer[m]]];
};
SelectInstanceSatellites: PROC [design: CD.Design, inst: CD.Instance, exclusive: BOOLTRUE] = {
--inst: a non text instance
n: INT; ob: CD.Object ← CDOps.PushedTopCell[design];
IF inst=NIL OR CDTexts.IsText[inst.ob] THEN ERROR;
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
n ← SelectWithMaster[design, inst, exclusive];
TerminalIO.PutF["select instance satellites of %g; %g satellite(s)\n",
[rope[CD.Describe[inst.ob, inst.properties, design]]],
[integer[n]]
]
};
SelectSatellitesComm: PROC [comm: CDSequencer.Command] = {
inst: CD.Instance; multiple: BOOL; exclusive: BOOL = TRUE;
[inst, multiple] ← CDOps.SelectedInstance[comm.design];
SELECT TRUE FROM
multiple => TerminalIO.PutRope["multiple selection; cant do select satellites\n"];
inst=NIL => SelectObjectSatellites[comm.design, exclusive];
CDTexts.IsText[inst.ob] =>
WITH CDSatellites.GetMaster[CDOps.PushedTopCell[comm.design], inst] SELECT FROM
i: CD.Instance => SelectInstanceSatellites[comm.design, i, exclusive];
o: CD.Object => SelectObjectSatellites[comm.design, exclusive];
ENDCASE => SelectNonSatellites[comm.design, exclusive];
~CDTexts.IsText[inst.ob] => SelectInstanceSatellites[comm.design, inst, exclusive];
ENDCASE => NULL;
};
SelectUnAssociatedTextsComm: PROC [comm: CDSequencer.Command] = {
SelectNonSatellites[comm.design, TRUE];
};
SelectObjectSatellitesComm: PROC [comm: CDSequencer.Command] = {
SelectObjectSatellites[comm.design, TRUE];
};
SetInstanceSatellites: PROC [design: CD.Design, exclusive: BOOL] RETURNS [n: INT𡤀] = {
satellites: CD.InstanceList ← NIL; master: CD.Instance ← NIL;
ob: CD.Object ← CDOps.PushedTopCell[design];
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF w.first.selected THEN {
IF CDTexts.IsText[w.first.ob] THEN satellites ← CONS[w.first, satellites]
ELSE {
IF master#NIL THEN CDSequencer.Quit["failed: more than one master selected"];
master ← w.first
}
}
ENDLOOP;
IF master=NIL THEN CDSequencer.Quit["failed: no master selected"];
IF exclusive THEN CDSatellites.Associate[master, NIL];
FOR w: CD.InstanceList ← satellites, w.rest WHILE w#NIL DO
n ← n+1;
CDSatellites.Associate[master, w.first];
ENDLOOP;
};
SetObjectSatellites: PROC [design: CD.Design, exclusive: BOOL] RETURNS [n: INT𡤀] = {
ob: CD.Object ← CDOps.PushedTopCell[design];
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
IF exclusive THEN CDSatellites.Associate[ob, NIL];
FOR w: CD.InstanceList ← CDOps.InstList[design], w.rest WHILE w#NIL DO
IF w.first.selected AND CDTexts.IsText[w.first.ob] THEN {
CDSatellites.Associate[ob, w.first]; n ← n+1;
};
ENDLOOP;
};
AddInstSatComm: PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["add instance satellites\n"];
[] ← SetInstanceSatellites[comm.design, FALSE];
};
AddObSatellitesComm: PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["add object satellites for pushed in cell\n"];
[] ← SetObjectSatellites[comm.design, FALSE];
};
ReSetInstSatComm: PROC [comm: CDSequencer.Command] = {
n: INT;
TerminalIO.PutRope["reset instance satellites\n"];
n ← SetInstanceSatellites[comm.design, TRUE];
TerminalIO.PutF[" %g satellite(s) in instance group\n", IO.int[n]];
};
ReSetObSatellitesComm: PROC [comm: CDSequencer.Command] = {
n, m: INT;
TerminalIO.PutRope["reset object satellites for pushed in cell\n"];
n ← SetObjectSatellites[comm.design, TRUE];
m ← CountAssociated[comm.design, NIL];
TerminalIO.PutF1[" %g object satellite(s) of pushed in cell\n", IO.int[n]];
IF m>0 THEN
TerminalIO.PutF1[" (there are %g un-associated texts)\n", IO.int[m]];
};
GetTextPart: PROC [comm: CDSequencer.Command, r: Rope.ROPE] RETURNS [i: CD.Instance] = {
--quits command if no success
ob: CD.Object; f: CDTexts.CDFont;
name: Rope.ROPE ← TerminalIO.RequestRope[r];
f ← CDPanelFonts.CurrentFont[comm.design];
IF f=NIL THEN CDSequencer.Quit["failed: no current font"];
IF name=NIL THEN CDSequencer.Quit["failed: empty text"];
ob ← CDTexts.Create[name, f, CD.commentLayer, TRUE];
IF ob=NIL THEN CDSequencer.Quit["failed: text not created"];
i ← CDOps.IncludeObject[comm.design, ob, --CDOps.FitObjectI[ob, comm.pos]-- [comm.pos, original]];
};
DrawInstanceSatelliteComm: PROC [comm: CDSequencer.Command] = {
selected: CD.Instance ← CDOps.TheInstance[comm.design, "draw satellite to master\n"];
IF selected#NIL THEN {
inst: CD.Instance;
ob: CD.Object ← CDOps.PushedTopCell[comm.design];
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
IF CDTexts.IsText[selected.ob] THEN
CDSequencer.Quit["failed: selected instance is text, can't put a satellite on texts\n"];
inst ← GetTextPart[comm, "type instance satellite: "];
CDSatellites.Associate[selected, inst];
};
};
DrawObjectSatelliteComm: PROC [comm: CDSequencer.Command] = {
ob: CD.Object ← CDOps.PushedTopCell[comm.design];
text: CD.Instance ← GetTextPart[comm, "type object satellite for pushed in cell: "];
[] ← CDSatellites.GetSatellites[ob]; --reinstalls invariants
CDSatellites.Associate[ob, text];
};
UnSatelliteComm: PROC [comm: CDSequencer.Command] = {
TerminalIO.PutRope["remove satellite association for selection\n"];
FOR w: CD.InstanceList ← CDOps.InstList[comm.design], w.rest WHILE w#NIL DO
IF w.first.selected THEN CDSatellites.Associate[w.first, NIL];
ENDLOOP;
};
--general utilities
SelectInst: PROC [design: CD.Design, inst: CD.Instance] = {
IF ~inst.selected THEN {
inst.selected←TRUE;
CDOps.RedrawInstance[design, inst];
}
};
DeSelectInst: PROC [design: CD.Design, inst: CD.Instance] = {
IF inst.selected THEN {
inst.selected←FALSE;
CDOps.RedrawInstance[design, inst, TRUE];
}
};
CDSequencer.ImplementCommand[$SatellitesSelectSat, SelectSatellitesComm,, doQueue];
CDSequencer.ImplementCommand[$SatellitesSelObGroup, SelectObjectSatellitesComm,, doQueue];
CDSequencer.ImplementCommand[$SatellitesSelNotGroup, SelectUnAssociatedTextsComm,, doQueue];
CDSequencer.ImplementCommand[$SatellitesDrawInstSat, DrawInstanceSatelliteComm,, doQueueAndMark];
CDSequencer.ImplementCommand[$SatellitesDrawObSat, DrawObjectSatelliteComm,, doQueueAndMark];
CDSequencer.ImplementCommand[$SatellitesAddInstSat, AddInstSatComm,, doQueueAndMark];
CDSequencer.ImplementCommand[$SatellitesAddObSat, AddObSatellitesComm,, doQueueAndMark];
CDSequencer.ImplementCommand[$SatellitesReSetInstSat, ReSetInstSatComm,, doQueueAndMark];
CDSequencer.ImplementCommand[$SatellitesReSetObSat, ReSetObSatellitesComm,, doQueueAndMark];
CDSequencer.ImplementCommand[$SatellitesUndoSat, UnSatelliteComm,, doQueueAndMark];
END.