CDPlotImpl.mesa
Don Curry May 2, 1988 1:50:14 pm PDT
DIRECTORY
CD, CDBasics, CDDirectory, CDIO, CDOps, CDPDPlot, CDSequencer, CDViewer, CMos, CommandTool, Commander, Convert, ImagerPD, IO, Nectarine, PDFileWriter, PeachPrint, Rope, SymTab, ThisMachine, ViewerOps;
CDPlotImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDDirectory, CDIO, CDOps, CDPDPlot, CDSequencer, CDViewer, CommandTool, Commander, Convert, IO, Nectarine, PeachPrint, Rope, SymTab, ThisMachine, ViewerOps =
BEGIN
Printer:  TYPE = REF PrinterRec;
PrinterRec: TYPE = RECORD[
name:   Rope.ROPE     ← NIL,
color:   BOOL       ← FALSE,
iFace:   {peach, tsetter}    ← peach,
ipType:  PrinterType     ← nil,
deviceKey: ATOM      ← NIL,
device:  REF CDPDPlot.DeviceDesc ← NIL ];
PageMode:  TYPE = CDPDPlot.PageMode;
PrinterType:  TYPE = ImagerPD.PrinterType;
thisMachine: Printer = NEW[ PrinterRec ← [name: ThisMachine.Name[], iFace: peach ] ];
doc: Rope.ROPE = "
CDPlot Server Design Nx𡤁 Ny𡤁
-l load - just load for interactive use
-b black and white => nectarine
-e expand - do peach expand
-k kill comment layer - big win for layouts
-n no send
-f fixFonts - good for layouts";
CDPlotProc: Commander.CommandProc = {
ENABLE {
ABORTED  => GOTO Abort;
PeachPrint.PupAborted => GOTO Abort };
design:   CD.Design;
printer:   Printer;
dName:   Rope.ROPE;
pName:   Rope.ROPE;
nn, nofNums: INT ← 0;
xn, yn:   INT ← 1;
clip:    CD.Rect ← [0, 0, 0, 0];
argv:    CommandTool.ArgumentVector ← CommandTool.Parse[cmd];
load, exp, fixFonts, killCmnt, noSend: BOOLFALSE;
color:           BOOLTRUE;
FOR ii: INT DECREASING IN [1..argv.argc) DO
rope: Rope.ROPE ← CommandTool.ArgN[cmd, ii];
SELECT rope.Fetch[0] FROM
'- => SELECT rope.Fetch[1] FROM
'l, 'L => load  ← TRUE; -- just load for interactive use
'b, 'B => color  ← FALSE;
'e, 'E => exp  ← TRUE;
'k, 'K => killCmnt ← TRUE;
'n, 'N => noSend ← TRUE;
'f, 'F => fixFonts ← TRUE;
ENDCASE;
IN ['0..'9] => {
temp: INTMAX[0, Convert.IntFromRope[rope]];
SELECT nofNums FROM
0 => {xn   ← MIN[20,  MAX[1, Convert.IntFromRope[rope]]]};
1 => {yn ← xn; xn ← MIN[20,  MAX[1, Convert.IntFromRope[rope]]]};
2 => {nn   ← MIN[xn*yn-1, MAX[0, Convert.IntFromRope[rope]]]};
ENDCASE => ERROR;
nofNums ← nofNums +1};
ENDCASE => {pName ← dName; dName ← rope} ENDLOOP;
IF NOT IsPrinterName[pName] AND IsPrinterName[dName] THEN
{temp: Rope.ROPE ← dName; dName ← pName; pName ← temp};
printer ← GetPrinter[pName: pName, color: color];
IF printer=NIL THEN
{cmd.out.PutF["Printer: %g not registered\n", IO.rope[pName]]; RETURN};
color ← printer.color;
IF exp THEN [] ← CommandTool.DoCommand["PeachExpand", cmd];
[design, clip] ← GetDesignClip[dName, cmd];
IF design=NIL THEN {cmd.out.PutF["Design: %g not found\n", IO.rope[dName]]; RETURN};
CDSequencer.ExecuteCommand[$UnqueuedLoadAllImps, design, dontQueue];
IF design#NIL AND nofNums=3 THEN {clip ← GetNthOfXYSections[nn, xn, yn, clip]; xn←yn𡤁};
IF load OR design=NIL THEN {cmd.out.PutRope["CDPlot loaded\n"]; RETURN};
IF color
THEN {
[] ← CommandTool.DoCommand["STPServer start", cmd];
[] ← CommandTool.DoCommand["Install CDPDPlot", cmd];
printer.device.contextFilter[CD.commentLayer] ← ~killCmnt;
FOR yindex: INT IN [0..yn) DO
ENABLE Error => {cmd.out.PutRope[msg]; ERROR ABORTED};
yClip: CD.Rect ← GetNthOfXYSections[yindex, 1, yn, clip];
fileName: Rope.ROPE ← PeachPrint.FileName[long, primary, 1, NIL];
task: REF CDPDPlot.TaskDesc;
IF xn > 1 THEN fileName ← fileName.Substr[0, fileName.Length[]-1];
task ← NEW[CDPDPlot.TaskDesc ← [
design:   design,
dd:    printer.device,
fileName:   fileName,
clip:    yClip,
substituteFonts: ~fixFonts,
scale:    -1,
abort:    NIL,
strips:    xn ]];
CDPDPlot.Plot[task];
IF ~noSend THEN FOR xx: INT IN [1..xn] DO
IF exp
THEN {
PrintPD[thisMachine, primary,  xx, cmd];
PrintPD[printer,   secondary, xx, cmd]}
ELSE
PrintPD[printer, primary, xx, cmd]
ENDLOOP
ENDLOOP}
ELSE {
[] ← CommandTool.DoCommand["Install Nectarine", cmd];
FOR yindex: INT IN [0..yn) DO
FOR xindex: INT IN [0..xn) DO
index:   INT ← yindex*xn + xindex;
useClip:  BOOL  ← xn>1 OR yn>1;
xyClip:  CD.Rect ← GetNthOfXYSections[index, xn, yn, clip];
firstNm:  Rope.ROPE ← Nectarine.DoInterpress[
design:    design,
chipNDaleWindow: xyClip,
clip:     useClip,
onlySel:    FALSE,
singleLayer:   FALSE,
layer:     CD.undefLayer,
lambda:    0.0,
firstPage:    TRUE,
lastPage:    TRUE,
abortFlag:   NIL].masterName;
secondNm: Rope.ROPE ← PeachPrint.FileName[long, secondary, index+1, ".pd"];
line:   Rope.ROPE ← Rope.Cat["InterpressToPD ", secondNm, " ← ", firstNm];
[] ← CommandTool.DoCommand
[Rope.Cat[line, " ", printerNames[printer.ipType] ], cmd];
IF ~noSend THEN PrintPD[printer, secondary, 1, cmd];
ENDLOOP ENDLOOP};
EXITS Abort => {cmd.out.PutF["aborted\n"]; RETURN[$Failure]; } };
ParseName: PROC[name: Rope.ROPE] RETURNS[root, ext: Rope.ROPE] = {
index: INT ← Rope.Find[name, "."];
SELECT index FROM
-1      => RETURN[name, NIL];
0      => RETURN[NIL,  NIL];
name.Length[]-1 => RETURN[Rope.Substr[name, 0, index], NIL]
ENDCASE    => RETURN[Rope.Substr[name, 0, index], Rope.Substr[name, index+1]]};
GetDesignClip: PROC [name: Rope.ROPE, cmd: Commander.Handle]
RETURNS [design: CD.Design, clip: CD.Rect] = {
inst:  CD.Instance;
root, ext: Rope.ROPE;
[root, ext] ← ParseName[name];
design  ← GetDesign[root, cmd];
IF design=NIL THEN RETURN[NIL, [0,0,0,0]];
clip ← CDOps.BoundingBox[design];
IF Rope.Length[ext]=0 OR Rope.Equal[ext, "dale", FALSE] THEN RETURN[design, clip];
inst ← GetTopDesignObjInst[design, ext];
IF inst=NIL THEN RETURN[NIL, [0,0,0,0]];
clip ← CDBasics.MapRect[CD.InterestRect[inst.ob], inst.trans];
RETURN[design, clip]};
GetTopDesignObjInst: PROC [design: CD.Design, name: Rope.ROPE] RETURNS[inst: CD.Instance]={
object: CD.Object ← CDDirectory.Fetch[design, name].object;
IF object=NIL THEN RETURN[NIL];
FOR l: CD.InstanceList ← CDOps.InstList[design], l.rest WHILE l#NIL DO
IF l.first.ob=object THEN RETURN[l.first]; ENDLOOP;
RETURN[NIL]};
GetDesign: PROC [name: Rope.ROPE, cmd: Commander.Handle]
RETURNS [design: CD.Design] = {
design ← FindDesignViewer[name];
IF design#NIL THEN RETURN[design];
IF Rope.Length[name]=0 THEN RETURN[NIL];
design ← CDIO.ReadDesign[name];
IF design#NIL THEN RETURN[design];
design ← CDIO.ReadDesign[name] };
FindDesignViewer: PROC[name: Rope.ROPE] RETURNS[design: CD.Design←NIL] = {
Checker: ViewerOps.EnumProc ~ {design ← CDViewer.DesignOf[v]; RETURN[design=NIL]};
IF name.Length[]#0 THEN RETURN[CDViewer.FindDesign[name]];
ViewerOps.EnumerateViewers[Checker] };
IsPrinterName: PROC [pName: Rope.ROPE] RETURNS[BOOL] =
{RETURN[
SymTab.Fetch[printerTable, PrinterKey[pName, TRUE]].found
OR
SymTab.Fetch[printerTable, PrinterKey[pName, FALSE]].found ]};
PrinterKey: PROC [pName: Rope.ROPE, color: BOOL] RETURNS[Rope.ROPE] =
{RETURN[Rope.Cat[(IF color THEN "+" ELSE "-"), pName]]};
GetPrinter: PROC [pName: Rope.ROPE, color: BOOL]
RETURNS [printer: Printer] = {
found: BOOL;
val:  REF;
IF pName#NIL
THEN {
[found, val] ← SymTab.Fetch[printerTable, PrinterKey[pName, color]];
IF ~found THEN color ← ~color;
[found, val] ← SymTab.Fetch[printerTable, PrinterKey[pName, color]];
IF ~found THEN RETURN[NIL];
printer ← NARROW[val]}
ELSE printer ← IF color THEN defaultColorPrinter ELSE defaultBWPrinter;
IF color AND printer.device=NIL
THEN printer.device ← CDPDPlot.MakeDevice[printer.deviceKey]};
GetNthOfXYSections: PROC [n, x, y: INT, clip: CD.Rect] RETURNS[CD.Rect] = {
pos: CD.Position;
size: CD.Position ← CDBasics.SizeOfRect  [clip];
size.y ← (size.y + (y-1))/y;
size.x ← (size.x + (x-1))/x;
pos ← [clip.x1 + size.x * (n MOD x), clip.y1 + size.y * (n / x)];
RETURN[CDBasics.RectAt[pos, size]]};
PrintPD: PROC [printer: Printer, order: PeachPrint.FileNameOrder, index: INT,
cmd: Commander.Handle] = {
file: Rope.ROPE ← PeachPrint.FileName[long, order, index, ".pd"];
IF printer.iFace=tsetter
THEN []𡤌ommandTool.DoCommand[Rope.Cat["Tsetter ",  printer.name, " ", file], cmd]
ELSE []𡤌ommandTool.DoCommand[Rope.Cat["PeachPrint ", printer.name, " ", file], cmd]};
Want to do the commnad line version (above) in order to not load the IP stuff unless needed.
See: [Cedar]<CedarChest6.0>InterpressTools>PrintFileConvertImpl.InterpressToPDAction
InterpressToPD: PROC
[iName: ROPE, oName: ROPE, printerType: ImagerPD.PrinterType, cmd: Commander.Handle] ~ {
printerTypePPD: ARRAY ImagerPD.PrinterType OF REAL ← [
nil:   5, raven300:  6, raven384:  6, o3:     5,
plateMaker: 9, o5:    5, puffin:  6, colorVersatec: 5,
versatec:  5, color400:  7, c150:   4, o11:    5,
o12:   5, o13:   5, o14:   5, o15:    5 ];
realPPD:  REAL ~ printerTypePPD[printerType];
interpress: Interpress.OpenMaster ~ Interpress.Open[iName, Log, cmd];
pd:   ImagerPD.PD ~
ImagerPD.CreateFromPrinterType[oName, printerType, NIL, NIL, realPPD];
FOR i: INT IN [0..interpress.pages) DO
action: PROC [context: Imager.Context] ~
{Interpress.DoPage[master: interpress, context: context, page: i+1]};
cmd.out.PutF[" [%g", IO.int[i+1]];
ImagerPD.DoPage[pd: pd, action: action, pixelUnits: FALSE];
cmd.out.PutChar[']];
ENDLOOP;
cmd.out.PutChar[' ];
ImagerPD.Close[pd] };
printerNames: ARRAY PrinterType OF Rope.ROPE ← [
nil:    NIL,
raven300:   "Raven300",
raven384:   "Raven384",
o3:     NIL,
plateMaker:  "PlateMaker",
o5:     NIL,
puffin:   "Puffin",
colorVersatec: "ColorVersatec",
versatec:   "Versatec",
color400:   "Color400",
c150:    "C150",
d4020:    "d4020",
bw400:   "bw400",
o13:    NIL,
o14:    NIL,
o15:    NIL ];
Error: ERROR [msg: Rope.ROPE] = CODE;
Init: PROC = {
Store: PROC[printerRec: PrinterRec] = {
printer: Printer ← NEW[PrinterRec ← printerRec];
[] ← SymTab.Store[printerTable, PrinterKey[printer.name, printer.color], printer]};
colorKey: Rope.ROPE = PrinterKey["Sleepy", col];
bwKey: Rope.ROPE = PrinterKey["Sleepy", bw];
col: BOOL = TRUE;
bw: BOOL = FALSE;
Store[["Sleepy",  col, peach, colorVersatec, $Versatec ]];
Store[["Sleepy",  bw, peach, versatec      ]];
Store[["MtFuji",  col, peach, color400,   $Color400 ]];
Store[["MtFuji",  bw, peach, bw400       ]];
Store[["Stinger",  bw, tsetter, raven384      ]];
defaultColorPrinter ← NARROW[SymTab.Fetch[printerTable, colorKey ].val];
defaultBWPrinter ← NARROW[SymTab.Fetch[printerTable, bwKey  ].val]};
printerTable:    SymTab.Ref ← SymTab.Create[case: FALSE];
defaultColorPrinter:  Printer;
defaultBWPrinter:  Printer;
Init[];
Commander.Register[key:"CDPlot", proc: CDPlotProc, doc: doc];
END.