QEIOTestMain.mesa
Last Edited by: Arnon, June 20, 1985 4:46:23 pm PDT
DIRECTORY
Commander,
Process,
ViewerClasses,
Rope,
Menus,
IO,
Convert,
ViewerIO,
ViewerTools,
ViewerOps,
TypeScript,
Imager,
ImagerColor,
ImagerPath,
AlgebraClasses,
Points,
BigRats,
RatIntervals,
Variables,
DistribPolys,
Polynomials,
AlgebraicNumbers,
ExtensionFields,
Formulas,
QETypes,
QEIO,
Cad2D,
Cads,
Graphs,
GraphOps;
QEIOTestMain: CEDAR PROGRAM
IMPORTS IO, Menus, ViewerIO, ViewerTools, ViewerOps, Convert, TypeScript, QEIO, Cad2D, Imager, ImagerColor, Cads, GraphOps
SHARES Imager =
BEGIN OPEN AC: AlgebraClasses, PTS: Points, BR: BigRats, RI: RatIntervals, VARS: Variables, DP: DistribPolys, POL: Polynomials, AN: AlgebraicNumbers, EF: ExtensionFields, QFF: Formulas, QET: QETypes, QEIO;
SEGMENTWIDTH: REAL = 2.; -- width of segment portion in edge drawing
timesRomanBI: Imager.Font ~ ImagerFont.Scale[ImagerFont.Find["xerox/pressfonts/timesroman-brr"], 10.]; --- why does scale of 10. work?
Cad2DViewer: TYPE = ViewerClasses.Viewer;
Cad2DViewerData: TYPE = REF Cad2DViewerDataRec;
Cad2DViewerDataRec: TYPE = RECORD [
x, y: REAL ← 0.0, -- origin for plot
scale: REAL ← 100.0, -- current scale for Imager
cad2D: QET.Cad ← NIL
];
cad2DViewer: Cad2DViewer;
ts: TypeScript.TS; -- the primary typescript
in, out: IO.STREAM; -- global variables for log writing
dimension: NAT;
cellIndex: QET.CellIndex;
cad: QET.Cad ← NIL;
SetCellIndex: Menus.MenuProc = {
cellIndex ← CellIndexFromRope[ViewerTools.GetSelectionContents[], dimension];
WriteCellIndex[cellIndex, out];
};
SetDimension: Menus.MenuProc = {
dimension ← Convert.CardFromRope[ViewerTools.GetSelectionContents[] ];
out.PutF["Dimension = %g\n\n", IO.card[dimension] ];
};
SetCadFromFile: Menus.MenuProc = {
cad2DViewerData: Cad2DViewerData ← NARROW[cad2DViewer.data];
cad ← CadFileFromRope[ViewerTools.GetSelectionContents[] ];
cad2DViewerData.cad2D ← GetInducedCad[cad, 2];
dimension ← cad.dimension;
WriteCadFile[cad, out];
};
Components: Menus.MenuProc = {
User specifies polynomials with respect to which to cluster by (*,*,@,*,*,@) tuples (@ is new FormulaOperators.Op).
edgePredicate: GraphOps.EdgePredicate ~ {
cell1: QET.Cell ← NARROW[v.rep];
cell2: QET.Cell ← NARROW[w.rep];
RETURN[cell1.basisSignature.structure.class.equal[cell1.basisSignature, cell2.basisSignature] ];
};
inducedCad: QET.Cad ← QEIO.GetInducedCad[cad, dimension];
numComponents: CARDINAL ← GraphOps.DetermineComponents[cad.abstractGraph, Undirected, edgePredicate];
clusters: QET.SignedRegionSeq ← Cads.ExtractClusters[inducedCad, numComponents];
QEIO.WriteSignedRegionSeq[clusters, out];
};
SetCad: Menus.MenuProc = {
cad2DViewerData: Cad2DViewerData ← NARROW[cad2DViewer.data];
cad ← CadFromRope[ViewerTools.GetSelectionContents[] ];
cad2DViewerData.cad2D ← QEIO.GetInducedCad[cad, 2];
dimension ← cad.dimension;
WriteCad[cad, out];
};
SetCoveringSets: Menus.MenuProc = {
CoveringSetsFromRope[ViewerTools.GetSelectionContents[], cad];
WriteCadCoveringSets[cad, out];
};
SetAdjacencies: Menus.MenuProc = {
AdjacenciesFromRope[ViewerTools.GetSelectionContents[], cad];
WriteCadAdjacencies[cad, out];
};
DisplayCad2D: Menus.MenuProc = {
ViewerOps.PaintViewer[viewer: cad2DViewer, hint: client, whatChanged: NIL, clearClient: TRUE];
};
Zoom: Menus.MenuProc = {
selfData: Cad2DViewerData ← NARROW[cad2DViewer.data];
IF mouseButton=red THEN {
selfData.scale ← selfData.scale*2;
selfData.x ← selfData.x - (1.0 / selfData.scale) * 300.0;
selfData.y ← selfData.y - (1.0 / selfData.scale) * 350.0
}
ELSE {
selfData.x ← selfData.x + (1.0 / selfData.scale) * 300.0;
selfData.y ← selfData.y + (1.0 / selfData.scale) * 350.0;
selfData.scale ← selfData.scale/2
};
ViewerOps.PaintViewer[viewer: cad2DViewer, hint: client, whatChanged: NIL, clearClient: TRUE];
};
Horizontal: Menus.MenuProc = {
selfData: Cad2DViewerData ← NARROW[cad2DViewer.data];
IF mouseButton=red THEN selfData.x ← selfData.x - (1.0 / selfData.scale) * 100.0 ELSE
selfData.x ← selfData.x + (1.0 / selfData.scale) * 100.0;
ViewerOps.PaintViewer[viewer: cad2DViewer, hint: client, whatChanged: NIL, clearClient: TRUE];
};
Vertical: Menus.MenuProc = {
selfData: Cad2DViewerData ← NARROW[cad2DViewer.data];
IF mouseButton=red THEN selfData.y ← selfData.y + (1.0 / selfData.scale) * 100.0 ELSE
selfData.y ← selfData.y - (1.0 / selfData.scale) * 100.0;
ViewerOps.PaintViewer[viewer: cad2DViewer, hint: client, whatChanged: NIL, clearClient: TRUE];
};
InitCad2DViewer: ViewerClasses.InitProc -- [self: ViewerClasses.Viewer] -- = {
self.data ← NEW[Cad2DViewerDataRec ← [
x: 8.0,
y: 7.0,
scale: 50.0
]];
self.name ← "Cad2DViewer";
};
PaintCad2DViewer: ViewerClasses.PaintProc = {
[self: Viewer, context: Imager.Context, whatChanged: REF, clear: BOOL]
See ImagerInterpress to expand to write Interpress master, /indigo/peach for how to use Versatec
DoIt: PROC = {
dotWidth: REAL ← 2.0 / selfData.scale ;
segmentWidth: REAL ← 10.0 / selfData.scale ;
context.ScaleT[selfData.scale];
context.TranslateT[ [selfData.x, selfData.y] ];
Cad2D.DisplayCad[selfData.cad2D, context, dotWidth, segmentWidth];
};
selfData: Cad2DViewerData ← NARROW[self.data];
context.ScaleT[0.0254/72]; -- conversion from meters to inches not needed????
context.SetColor[ImagerColor.ColorFromAtom[$Black]];
SELECT whatChanged FROM
NIL => context.DoSaveAll[DoIt];
ENDCASE => ERROR;
};
Paint: ViewerClasses.PaintProc = {
[self: Viewer, context: Imager.Context, whatChanged: REF, clear: BOOL]
See ImagerInterpress to expand to write Interpress master, /indigo/peach for how to use Versatec
PlotFolium: PROC = {
traj: Imager.Trajectory;
context.ScaleT[selfData.scale];
context.TranslateT[ [selfData.x, selfData.y] ];
traj ← ImagerPath.MoveTo[ [1.587, 1.260] ];
traj ← ImagerPath.LineTo[traj, [1.562, 1.090] ];

traj ← ImagerPath.LineTo[traj, [-0.875, 0.249] ];
traj ← ImagerPath.LineTo[traj, [-0.906, 0.267] ];
traj ← ImagerPath.LineTo[traj, [-0.937, 0.284] ];
traj ← ImagerPath.LineTo[traj, [-0.969, 0.303] ];
Imager.MaskStrokeTrajectory[context, traj ];
traj ← ImagerPath.MoveTo[ [1.587, 1.260] ];
traj ← ImagerPath.LineTo[traj, [1.562, 1.402] ];
traj ← ImagerPath.LineTo[traj, [2.469, -3.434] ];
Imager.MaskStrokeTrajectory[context, traj ];
};
selfData: Cad2DViewerData ← NARROW[self.data];
context.ScaleT[0.0254/72]; -- conversion from meters to inches not needed????
context.SetStrokeWidth[SEGMENTWIDTH/ selfData.scale];
context.SetColor[ImagerColor.ColorFromAtom[$Black]];
SELECT whatChanged FROM
NIL => context.DoSaveAll[PlotFolium];
ENDCASE => ERROR;
};
RegisterCad2DViewerClass: PROC ~ {
menu: Menus.Menu ← Menus.CreateMenu[1];
cad2DViewerClass: ViewerClasses.ViewerClass;
Menus.AppendMenuEntry[menu:menu, entry:Menus.CreateEntry [name:"Zoom ", proc: Zoom], line:0];
Menus.AppendMenuEntry[menu:menu, entry:Menus.CreateEntry [name:"Horizontal ", proc: Horizontal], line:0];
Menus.AppendMenuEntry[menu:menu, entry:Menus.CreateEntry [name:"Vertical ", proc: Vertical], line:0];
cad2DViewerClass ← NEW[ViewerClasses.ViewerClassRec ← [
flavor: $Cad2DViewer,
init: InitCad2DViewer,
notify: Notify,
tipTable: TIPUser.InstantiateNewTIPTable["Plot.tip"],
paint: PaintCad2DViewer,
menu: menu
]];
ViewerOps.RegisterViewerClass[flavor: $Cad2DViewer, class: cad2DViewerClass];
};
ts ← TypeScript.Create[info: [name: "QE IO Test" ] ];
Menus.ChangeNumberOfLines[menu: ts.menu, newLines: 2];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"DisplayCad2D", proc: DisplayCad2D], line: 0];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"Cad", proc: SetCad], line: 0];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"CoveringSets", proc: SetCoveringSets], line: 0];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"Adjacencies", proc: SetAdjacencies], line: 0];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"CellIndex", proc: SetCellIndex], line: 0];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"CadFile", proc: SetCadFromFile], line: 1];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"Dimension", proc: SetDimension], line: 0];
Menus.AppendMenuEntry[menu: ts.menu, entry:Menus.CreateEntry [name:"Components", proc: Components], line: 1];
[in: in, out: out] ← ViewerIO.CreateViewerStreams[name: "QE IO Test",viewer: ts];
RegisterCad2DViewerClass[];
cad2DViewer ← ViewerOps.CreateViewer[flavor: $Cad2DViewer, info: [iconic:TRUE, column: color] ];
END.