CDReadInterpressImpl.mesa
Copyright (C) 1984, 1985, 1986 by Xerox Corporation. All rights reserved.
Created by: Christian Jacobi, March 1, 1985 4:52:57 pm PST
Last edited by: Christian Jacobi, October 30, 1986 2:44:45 pm PST
Last Edited by: Gasbarro June 14, 1988 3:24:51 pm PDT
DIRECTORY
CD,
CDBasics,
CDCommandOps,
CDCreateLabels,
CDDirectory,
CDEnvironment,
CDOps,
CDReadInterpress,
CDSequencer,
CDTexts,
CStitching,
FS,
Imager,
ImagerBitmapContext,
ImagerMaskCapture,
ImagerSample,
ImagerTransformation,
Interpress,
IPMaster,
IO,
Rope,
SF,
TerminalIO;
CDReadInterpressImpl:
CEDAR
PROGRAM
IMPORTS CDBasics, CDCommandOps, CDCreateLabels, CDDirectory, CDEnvironment, CDOps, CDSequencer, FS, ImagerBitmapContext, ImagerMaskCapture, ImagerSample, ImagerTransformation, Interpress, IPMaster, Rope, TerminalIO
EXPORTS CDReadInterpress =
BEGIN
DoStop: ERROR = CODE;
CaptureBounds:
PROC [master: Interpress.Master, pageNo:
INT𡤁, scale:
REAL𡤁]
RETURNS [box:
SF.Box] = {
Operator:
PROC [context: Imager.Context] = {
LogProc: Interpress.LogProc = {
TerminalIO.PutF["IP problem: %g, class: %g, explanation: %g\n",
[integer[class]], [atom[code]], [rope[explanation]]
];
};
Interpress.DoPage[master, pageNo, context, LogProc];
};
m: ImagerTransformation.Transformation ~ ImagerTransformation.PreScale[ImagerTransformation.XYToSF[[slow: up, fast: right], 0, 0], scale];
box ← ImagerMaskCapture.CaptureBounds[Operator, m
! ImagerMaskCapture.Cant => {
TerminalIO.PutF["IP problem on capture box: %g", [atom[why]]];
CONTINUE
}
];
};
CreateIPCell:
PUBLIC PROC [design:
CD.Design, fileName: Rope.
ROPE, layer:
CD.Layer, pixelsPerMeter:
REAL, postScale:
INT ← 1, pageNo:
INT ← 1, deviceBitmap:
CD.Rect←[1, 1, 0, 0], stop:
REF
BOOL←
NIL]
RETURNS [cell:
CD.Object←
NIL] = {
LogProc: Interpress.LogProc = {
TerminalIO.PutF["IP problem: %g, class: %g, explanation: %g\n",
[integer[class]], [atom[code]], [rope[explanation]]
];
IF stop^ THEN ERROR DoStop;
};
plane: CStitching.Tesselation; stream: IO.STREAM;
master: Interpress.Master; context: Imager.Context; bitmap: ImagerSample.SampleMap;
imageBox, deviceBox: SF.Box;
pixelsPerInch: REAL ← pixelsPerMeter*Imager.metersPerInch;
IF stop=NIL THEN stop ← NEW[BOOL←FALSE];
stream ←
FS.StreamOpen[fileName
!
FS.Error =>
IF error.group = user
THEN {
TerminalIO.PutRopes[error.explanation, "\n"];
GOTO failed
}
];
master ← Interpress.FromStream[stream, LogProc !
IPMaster.Error => {
TerminalIO.PutF["failed to open IP master: code: %g, index: %g, explanation: %g\n",
[atom[error.code]], [integer[error.index]], [rope[error.explanation]]
];
GOTO failed
};
DoStop => {TerminalIO.PutRope["stopped\n"]; GOTO failed}
];
IF master.pages<1
THEN {
TerminalIO.PutRope["failed: IP master is empty\n"];
GOTO failed
};
IF CDBasics.NonEmpty[deviceBitmap]
THEN
imageBox ← [
min: [s: deviceBitmap.y1, f: deviceBitmap.x1],
max: [s: deviceBitmap.y2, f: deviceBitmap.x2]
]
ELSE imageBox ← CaptureBounds[master, pageNo, pixelsPerMeter];
deviceBox ← [
--in pixels
min: [s: imageBox.min.s-2, f: imageBox.min.f-2],
max: [s: imageBox.max.s+2, f: imageBox.max.f+2]
];
bitmap ← ImagerSample.NewSampleMap[box: deviceBox];
ImagerSample.Clear[bitmap];
context ← ImagerBitmapContext.Create[
deviceSpaceSize: deviceBox.max,
scanMode: Imager.ScanMode[slow: up, fast: right],
surfaceUnitsPerInch: [pixelsPerInch, pixelsPerInch],
pixelUnits: FALSE
];
ImagerBitmapContext.SetBitmap[context, bitmap];
Interpress.DoPage[master, pageNo, context, LogProc
! DoStop => CONTINUE
];
plane ← CDCreateLabels.CStitchSampleMap[bitmap, stop];
cell ← CDCreateLabels.CreateCellFromCStitching[plane: plane, layer: layer, scale: postScale];
IF design#
NIL
AND cell#
NIL
THEN
[] ← CDDirectory.Include[design, cell, Rope.Cat["IP-from-", fileName]];
EXITS failed => NULL
};
pixelsPerMeter: INT ← 2000;
CreateIPCellComm:
PROC [comm: CDSequencer.Command] = {
name: Rope.ROPE; layer: CD.Layer;
cell: CD.Object;
wDir: Rope.ROPE ← CDEnvironment.GetWorkingDirectory[comm.design];
stop: REF BOOL ← NEW[BOOL←FALSE];
scale: INT ← 0;
CDSequencer.UseAbortFlag[comm.design, stop];
layer ← comm.l;
TerminalIO.PutRopes["create a label from IP file (on layer ", CDOps.LayerRope[layer], ")\n"];
name ← TerminalIO.RequestRope[Rope.Cat["ip file [", wDir, "] >"]];
scale ← TerminalIO.RequestInt["Scale: "];
name ← CDEnvironment.MakeName[base: name, ext: "IP", wDir: wDir];
cell ← CreateIPCell[design: comm.design, fileName: name, layer: layer, pixelsPerMeter: pixelsPerMeter, postScale: scale, stop: stop];
CDCommandOps.IncludeOb[comm, cell];
CDSequencer.ImplementCommand[$CreateIPCell, CreateIPCellComm];
--for testing-- CDSequencer.ImplementCommand[$test, CreateIPCellComm];