IPMainViewerImpl:
CEDAR
PROGRAM
IMPORTS Atom, Commander, Convert, ExprRead, FS, FileNames, IO, IP, IPParams, IPTop, IPCTG, IPCoTab, IPToolBox, IPTopOps, IPNetTab, IPMVEditOps, IPMVStackOps, IPMVBasicOps, MessageWindow, OrderedRefArray, Rope, QuickViewer, TerminalIO
EXPORTS IPMainViewer =
BEGIN
mvTop: PUBLIC IPTop.Ref ← NIL;
topGotInteractively: BOOL ← FALSE;
trialSolutions: PUBLIC OrderedRefArray.Ref ← NIL;
wDir: Rope.ROPE ← FileNames.CurrentWorkingDirectory[];
selectedNet: IPNetTab.Net ← NIL;
showAllNames, showCompNames, showChNames: BOOL ← FALSE;
showCompsOnly, showChsOnly: BOOL ← FALSE;
trackKept: LIST OF REF ← NIL;
prevTrack:
LIST
OF
REF ←
NIL;
--Minor Details
showPinNameCutOff: PUBLIC REAL ← 3.0; --ie. set from interpreter
coStipple:
CARDINAL ← IPConstants.White;
RollBack:
PUBLIC
PROC[fromFile: Rope.
ROPE]
RETURNS [mvTop: IPTop.Ref] = {
SetTopTo[IPTop.ReconstructSelf[fromFile], NIL, TRUE];
}; --RollBack
GetInput:
PUBLIC
PROC[defaultDir, inputFile: Rope.
ROPE]
RETURNS [mvTop: IPTop.Ref, systemName: Rope.
ROPE] = {
tab: SymTab.Ref ← ExprRead.ReadFile[IPToolBox.ConstructFileName[defaultDir, inputFile, "desc"]];
systemName ← ExprRead.FetchRope[tab, "ObjectName", TRUE].val;
mvTop ← IPTop.Create1[defaultDir, inputFile];
}; --GetInput
SetTopTo:
PUBLIC
PROC [newTop: IPTop.Ref, systemName: Rope.
ROPE, gotInteractively:
BOOLEAN] ~ {
IF topGotInteractively AND mvTop # NIL THEN IPTop.DestroySelf[mvTop];
mvTop ← newTop;
QuickViewer.SetViewerName[systemName];
Refresh[];
trialSolutions ← NIL;
trackKept ← prevTrack ← NIL;
topGotInteractively ← gotInteractively;
};
Refresh:
PROC = {QuickViewer.EraseViewer[]; QuickViewer.DrawInViewer[DrawProc]};
--Refresh--
QuitProc:
PROC [] = {
TerminalIO.PutRope["Quiting..."];
IF mvTop # NIL AND topGotInteractively THEN {IPTop.DestroySelf[mvTop]; mvTop ← NIL};
TerminalIO.PutRope["..Done\n"];
}; --QuitProc--
errorMessage: Rope.ROPE;
ClickProc:
PROC[mouseButton:
ATOM, xCoord, yCoord:
REAL] ={
MessageWindow.Append[Rope.Cat[Atom.GetPName[mouseButton], " ",
Convert.RopeFromReal[xCoord], " ",
Convert.RopeFromReal[yCoord]], TRUE];
}; --ClickProc--
MenuHit:
PROC[command:
ATOM, mouse: Menus.MouseButton, shift, control:
BOOL] = {
ENABLE {
TerminalIO.UserAbort => {
errorMessage ← Rope.Cat[Atom.GetPName[command], "...userAbort"];
IF ~IPParams.DebugSystem THEN GOTO err
};
FS.Error => {TerminalIO.PutRope[Rope.Cat[Atom.GetPName[error.code], "...."]];
errorMessage ← error.explanation;
IF ~IPParams.DebugSystem THEN GOTO err};
IO.Error => {TerminalIO.PutRope[Rope.Cat[Atom.GetPName[command], "...."]];
errorMessage ← "Not enough arguments. Please try again";
IF ~IPParams.DebugSystem THEN GOTO err};
IO.EndOfStream => {TerminalIO.PutRope[Rope.Cat[Atom.GetPName[command], "...."]];
errorMessage ← "Input Error. Please try again";
IF ~IPParams.DebugSystem THEN GOTO err};
ExprRead.
Error => {TerminalIO.PutRope[Rope.Cat[Atom.GetPName[command], "...."]];
errorMessage ← msg;
IF ~IPParams.DebugSystem THEN GOTO err};
IPTopOps.InvalidArgs =>{TerminalIO.PutRope[Rope.Cat[Atom.GetPName[op], "..."]];
errorMessage ← "Arguments are not valid";
IF ~IPParams.DebugSystem THEN GOTO err};
IPTopOps.UndoStackEmpty => {TerminalIO.PutRope["...undo stack is emptied..."];
errorMessage ← "Can't undo any further";
IF ~IPParams.DebugSystem THEN GOTO err};
OrderedRefArray.OutOfRange => {
TerminalIO.PutRope[Rope.Cat[Atom.GetPName[command], "...."]];
errorMessage ← Rope.Cat[Convert.RopeFromInt[index], " is not in range"];
IF ~IPParams.DebugSystem THEN GOTO err;
};
IPToolBox.ParseError => {
TerminalIO.PutRope["Input Error..."];
errorMessage ← "Arguments are not valid";
IF ~IPParams.DebugSystem THEN GOTO err};
IP.Error => {
SELECT ec
FROM
missingRegistration => {
TerminalIO.PutRope[Rope.Cat[explanation, "..."]];
errorMessage ← "Unknown name";
IF ~IPParams.DebugSystem THEN GOTO err;
};
doubleRegistration => {
TerminalIO.PutRope[Rope.Cat[explanation, "..."]];
errorMessage ← "Name Conflict";
IF ~IPParams.DebugSystem THEN GOTO err;
};
callingError => {
TerminalIO.PutRope[Rope.Cat[explanation, "..."]];
errorMessage ← "Check Input And Retry or See Implementor";
IF ~IPParams.DebugSystem THEN GOTO err;
};
programmingError, noResource, other => {
TerminalIO.PutRope[Rope.Cat["You just found a bug: ", explanation]];
errorMessage ← "See Implementor";
IF ~IPParams.DebugSystem THEN GOTO err;
};
ENDCASE => ERROR;};
};
refreshFlag: BOOL ← TRUE;
reGeom: BOOL ← FALSE;
SELECT command
FROM
$RollBack => {
file: Rope.ROPE ← TerminalIO.RequestRope["Enter Full Name of Log File to Rollback from: "];
TerminalIO.PutRope[Rope.Cat["Reconstructing From: ", file, "..."]];
SetTopTo[IPTop.ReconstructSelf[file], NIL, TRUE];
TerminalIO.PutRope["..Done\n"];
RETURN};
$GetInput => {
inputFile: Rope.ROPE ← TerminalIO.RequestRope["Enter Name of Description File From Which To Get Data: "];
newTop: IPTop.Ref;
systemName: Rope.ROPE;
[newTop, systemName] ← GetInput[wDir, inputFile];
SetTopTo[newTop, systemName, TRUE];
TerminalIO.PutRope["..Done\n"];
RETURN
};
ENDCASE => NULL;
IF mvTop =
NIL
THEN {
errorMessage ← "System is Empty! Please do Rollback or GetExample to load a new system";
IF ~IPParams.DebugSystem THEN GOTO err}; --ENDIF--
SELECT command
FROM
$Name => {
IF ~shift
AND ~ control
THEN {
SELECT mouse
FROM
$red => {showChNames ← NOT showChNames;};
$yellow => {showAllNames ←
NOT showAllNames;
IF showAllNames
THEN {showCompNames ← TRUE; showChNames ← TRUE;}
ELSE {showCompNames ← FALSE; showChNames ← FALSE;};};
$blue => {showCompNames ← NOT showCompNames};
ENDCASE => ERROR;
TerminalIO.PutRope[(IF showAllNames THEN "Show all names..." ELSE "Not showing all names...")];
showAllNames ← showCompNames AND showChNames;
}; --endIf
IF shift THEN showCompsOnly ← ~ showCompsOnly;
IF control THEN showChsOnly ← ~ showChsOnly;
};
$DefChs => {
TerminalIO.PutRope["DefiningChannels..."];
[] ← mvTop.ReDefineChs[yPrimary:
NOT shift, maxChWidth: control ! IPTop.ComponentsOverlapped => {errorMessage ← "Overlapping Components";
IF ~IPParams.DebugSystem THEN GOTO err}];
prevTrack ← NIL; trackKept ← NIL};
$ClrChs => {
TerminalIO.PutRope["Destroying Channels..."];
IPTop.ClearChannels[mvTop];
prevTrack ← NIL; trackKept ← NIL};
$PaintNet => {
argStream: IO.STREAM ← IO.RIS[TerminalIO.RequestRope["Name of net to be painted: "]];
selectedNet ← IPNetTab.FetchNet[mvTop.nets, IO.GetLineRope[argStream]];
QuickViewer.DrawInViewer[DrawNetProc];
refreshFlag ← FALSE};
$Geom, $CheckPoint, $List, $ChkSlf, $EstChs => {
[reGeom, refreshFlag] ← IPMVBasicOps.MenuHit[mvTop, wDir, command, mouse, shift, control]
};
$Undo, $Un1, $Redo, $Re1, $KepTrk, $ClrStks, $StkSz, $ToSoln => {
[prevTrack, reGeom, refreshFlag] ← IPMVStackOps.MenuHit[mvTop, prevTrack, trackKept, command, mouse, shift, control, trialSolutions]
};
$BrkX, $FomX, $RemZ, $FomZ, $LtoT, $TtoL, $FlxKne, $ExtKne, $Mrr, $Rot, $Ornt, $ClrCnr, $Grw, $Grw1, $Shr, $BrkXs, $SetCo, $MovCo, $SwapCo, $FlipT, $SetCoShp, $SpawnCo => {
[reGeom, refreshFlag] ← IPMVEditOps.MenuHit[mvTop, command, mouse, shift, control];
prevTrack ← NIL;
};
ENDCASE => ERROR;
IF reGeom THEN mvTop.Geometrize[horPosSense: NOT control, verPosSense: NOT shift];
IF refreshFlag THEN Refresh[];
TerminalIO.PutRope["..Done\n"];
EXITS
err => {MessageWindow.Append[errorMessage, TRUE]; MessageWindow.Blink[]; TerminalIO.PutRope["Aborted\n"];};
}; --MenuHit--
DrawNetProc:
PROC[context: Imager.Context, scaleFactor:
REAL] ={
IPNetTab.PaintNet[net: selectedNet, context: context, scaleFactor: scaleFactor, showNetName: FALSE]
}; --DrawNetProc
DrawProc:
PROC [context: Imager.Context, scaleFactor:
REAL] ={
IF mvTop #
NIL
THEN {
IF showCompsOnly
THEN {
IPCoTab.PaintSelf[coTab: mvTop.coTab, context: context, scaleFactor: scaleFactor, coStipple: coStipple, showCoNames: (showCompNames OR showAllNames), showPhyPinNames: (scaleFactor > showPinNameCutOff)];
RETURN};
IF showChsOnly
THEN {
IPCTG.PaintSelf[ctg: mvTop.ctg, context: context, scaleFactor: scaleFactor, showChName: (showChNames OR showAllNames)];
RETURN};
mvTop.PaintSelf[context: context, scaleFactor: scaleFactor, showChNames: (showChNames OR showAllNames), showCompNames: (showCompNames OR showAllNames), showPinNames: (scaleFactor > showPinNameCutOff)];}
}; --DrawProc--
Start: Commander.CommandProc={
mvName: Rope.ROPE;
IF cmd #
NIL
THEN {
argStream: IO.STREAM ← IO.RIS[cmd.commandLine];
mvName ← IO.GetID[argStream! IO.EndOfStream => CONTINUE;]};
BuildViewer[Rope.Cat["Phoenix: ", mvName]]
}; --Start
BuildViewer:
PUBLIC
PROC [mvName: Rope.
ROPE] ~ {
QuickViewer.BuildViewer[DrawProc, QuitProc, MenuHit, ClickProc, mvName, FALSE, LIST[$RollBack, $GetInput, $CheckPoint], LIST[$DefChs, $ClrChs, $Geom,$Name, $List, $PaintNet, $EstChs], LIST[$EditOps, $BrkX, $FomX, $RemZ, $FomZ, $LtoT, $TtoL, $FlxKne, $ExtKne, $Grw, $Grw1, $Shr, $Rot, $Mrr, $Ornt, $ClrCnr], LIST[$OpsExtra, $SetCo, $MovCo, $SwapCo, $FlipT, $SpawnCo, $SetCoShp], LIST[$StkOps, $Undo, $Redo, $KepTrk, $ClrStks, $Un1, $Re1, $StkSz, $ToSoln]]};
Commander.Register[key: "Phoenix", proc: Start, doc: "Create an Phoenix Viewer"];
END.