<<--File: IPMainViewerImpl.mesa >> <> <> <<>> <<--Intro: This interface is self-documentary. Use this as reference>> <<--Imports: >> <<-- (I) IPMVBasicOps = basic operations>> <<-- (II) IPMVEditOps = editing operations>> <<-- (III) IPMVStackOps = stack related operations>> DIRECTORY IO, TerminalIO, Rope, Convert, QuickViewer, Graphics, MessageWindow, Menus, Commander, FS, FileNames, Atom, SymTab, ExprRead, OrderedRefArray, IP, IPParams, IPConstants, IPTopOps, IPNetTab, IPTop, IPCTG, IPCoTab, IPToolBox, IPMVEditOps, IPMVStackOps, IPMVBasicOps, IPMainViewer; IPMainViewerImpl: CEDAR PROGRAM IMPORTS IO, TerminalIO, Atom, MessageWindow, Rope, FS, FileNames, Commander, Convert, ExprRead, QuickViewer, OrderedRefArray, IP, IPParams, IPTop, IPCTG, IPCoTab, IPToolBox, IPTopOps, IPNetTab, IPMVEditOps, IPMVStackOps, IPMVBasicOps EXPORTS IPMainViewer = BEGIN OPEN TIO: TerminalIO, Top: IPTop; MVTop: PUBLIC Top.Ref _ NIL; TrialSolutions: PUBLIC OrderedRefArray.Ref _ NIL; wDir: PUBLIC Rope.ROPE; mvName: Rope.ROPE _ "Phoenix"; 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] ={ SetTopTo[Top.ReconstructSelf[fromFile]]; Refresh[]; TrialSolutions _ NIL; trackKept _ prevTrack _ NIL; }; --RollBack GetInput: PUBLIC PROC[defaultDir, inputFile: Rope.ROPE] ={ tab: SymTab.Ref _ ExprRead.ReadFile[IPToolBox.ConstructFileName[defaultDir, inputFile, "desc"]]; systemName: Rope.ROPE _ ExprRead.FetchRope[tab, "ObjectName", TRUE].val; SetTopTo[Top.Create1[defaultDir, inputFile]]; IF systemName # NIL THEN QuickViewer.SetViewerName[mvName _ systemName]; Refresh[]; TrialSolutions _ NIL; trackKept _ prevTrack _ NIL; }; --GetInputFile CleanUp: PROC = {IF MVTop # NIL THEN IPTop.DestroySelf[MVTop]; MVTop _ NIL}; --CleanUp-- Refresh: PROC = {QuickViewer.EraseViewer[]; QuickViewer.DrawInViewer[DrawProc]}; --Refresh-- SetTopTo: PROC[newTop: Top.Ref] = {CleanUp[]; MVTop _ newTop}; --SetTopTo-- QuitProc: PROC [] = { TIO.WriteRope["Quiting..."]; CleanUp[]; TIO.WriteRope["..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 { TIO.UserAbort => { errorMessage _ Rope.Cat[Atom.GetPName[command], "...userAbort"]; IF ~IPParams.DebugSystem THEN GOTO err }; FS.Error => {TIO.WriteRope[Rope.Cat[Atom.GetPName[error.code], "...."]]; errorMessage _ error.explanation; IF ~IPParams.DebugSystem THEN GOTO err}; IO.Error => {TIO.WriteRope[Rope.Cat[Atom.GetPName[command], "...."]]; errorMessage _ "Not enough arguments. Please try again"; IF ~IPParams.DebugSystem THEN GOTO err}; IO.EndOfStream => {TIO.WriteRope[Rope.Cat[Atom.GetPName[command], "...."]]; errorMessage _ "Input Error. Please try again"; IF ~IPParams.DebugSystem THEN GOTO err}; ExprRead.Error => {TIO.WriteRope[Rope.Cat[Atom.GetPName[command], "...."]]; errorMessage _ msg; IF ~IPParams.DebugSystem THEN GOTO err}; IPTopOps.InvalidArgs =>{TIO.WriteRope[Rope.Cat[Atom.GetPName[op], "..."]]; errorMessage _ "Arguments are not valid"; IF ~IPParams.DebugSystem THEN GOTO err}; IPTopOps.UndoStackEmpty => {TIO.WriteRope["...undo stack is emptied..."]; errorMessage _ "Can't undo any further"; IF ~IPParams.DebugSystem THEN GOTO err}; OrderedRefArray.OutOfRange => { TIO.WriteRope[Rope.Cat[Atom.GetPName[command], "...."]]; errorMessage _ Rope.Cat[Convert.RopeFromInt[index], " is not in range"]; IF ~IPParams.DebugSystem THEN GOTO err; }; IPToolBox.ParseError => { TIO.WriteRope["Input Error..."]; errorMessage _ "Arguments are not valid"; IF ~IPParams.DebugSystem THEN GOTO err}; IP.Error => { SELECT ec FROM missingRegistration => { TIO.WriteRope[Rope.Cat[explanation, "..."]]; errorMessage _ "Unknown name"; IF ~IPParams.DebugSystem THEN GOTO err; }; doubleRegistration => { TIO.WriteRope[Rope.Cat[explanation, "..."]]; errorMessage _ "Name Conflict"; IF ~IPParams.DebugSystem THEN GOTO err; }; callingError => { TIO.WriteRope[Rope.Cat[explanation, "..."]]; errorMessage _ "Check Input And Retry or See Implementor"; IF ~IPParams.DebugSystem THEN GOTO err; }; programmingError, noResource, other => { TIO.WriteRope[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 _ TIO.RequestRope["Enter Full Name of Log File to Rollback from: "]; TIO.WriteRope[Rope.Cat["Reconstructing From: ", file, "..."]]; RollBack[file]; TIO.WriteRope["..Done\n"]; RETURN}; $GetInput => { inputFile: Rope.ROPE _ TIO.RequestRope["Enter Name of Description File From Which To Get Data: "]; GetInput[wDir, inputFile]; TIO.WriteRope["..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; TIO.WriteRope[(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 => { TIO.WriteRope["DefiningChannels..."]; [] _ MVTop.ReDefineChs[yPrimary: NOT shift, maxChWidth: control ! Top.ComponentsOverlapped => {errorMessage _ "Overlapping Components"; IF ~IPParams.DebugSystem THEN GOTO err}]; prevTrack _ NIL; trackKept _ NIL}; $ClrChs => { TIO.WriteRope["Destroying Channels..."]; IPTop.ClearChannels[MVTop]; prevTrack _ NIL; trackKept _ NIL}; $PaintNet => { argStream: IO.STREAM _ IO.RIS[TIO.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[]; TIO.WriteRope["..Done\n"]; EXITS err => {MessageWindow.Append[errorMessage, TRUE]; MessageWindow.Blink[]; TIO.WriteRope["Aborted\n"];}; }; --MenuHit-- DrawNetProc: PROC[context: Graphics.Context, scaleFactor: REAL] ={ IPNetTab.PaintNet[net: selectedNet, context: context, scaleFactor: scaleFactor, showNetName: FALSE] }; --DrawNetProc DrawProc: PROC [context: Graphics.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-- BuildViewer: Commander.CommandProc={ IF cmd # NIL THEN { argStream: IO.STREAM _ IO.RIS[cmd.commandLine]; mvName _ IO.GetID[argStream! IO.EndOfStream => CONTINUE;]}; 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]]; }; --BuildViewer Commander.Register[key: "IPMainViewer", proc: BuildViewer, doc: "Create an IPMainViewer"]; [] _ BuildViewer[NIL]; wDir _ FileNames.CurrentWorkingDirectory[]; END.