<> <> <> <> <> DIRECTORY BasicTime, CD, CDBasics, CDCommandOps, CDInstances, CDSimpleOps, CDOps, CDOrient, CDRects, CDSequencer, TerminalIO; CDBasicCommands: CEDAR PROGRAM IMPORTS BasicTime, CDCommandOps, CDInstances, CDSimpleOps, CDOps, CDSequencer, TerminalIO, CDRects, CDBasics = BEGIN AddARect: PROC[design: CD.Design, r: CD.Rect, l: CD.Layer] = BEGIN ob: CD.Object; sz: CD.Position _ CDBasics.SizeOfRect[r]; orient: CD.Orientation _ CDOrient.original; IF sz.y> BEGIN InternalAddWire[comm: comm, firstOnly: FALSE] END; ContinueWire: PROC [comm: CDSequencer.Command] = BEGIN InternalAddWire[comm: comm, firstOnly: TRUE] END; InternalAddWire: PROC [comm: CDSequencer.Command, firstOnly: BOOL_FALSE] = <<--this procedure knows EXACTLY the algorithm used for showing>> <<--temporary wires in the cursor part>> BEGIN start: CD.Position _ comm.sPos; stop: CD.Position _ comm.pos; wireWidth: CD.Number _ comm.n; IF wireWidth=0 THEN {AddRect[comm]; RETURN}; TerminalIO.WriteRope["draw wire\n"]; IF --firstHorizontal-- comm.b THEN { IF stop.x<=start.x AND stop.x>=start.x-wireWidth AND (stop.ystart.y+wireWidth) THEN { --crazy vertical wire IF ABS[start.y-stop.y]> IF stop.y>=start.y AND stop.y<=start.y+wireWidth THEN { --horizontal wire stop.y _ start.y+wireWidth; AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l] } ELSE { --L shaped (firsthorizontal) IF start.x<=stop.x THEN {stop.x _ stop.x+wireWidth} ELSE {t: CD.Number=stop.x; stop.x _ start.x; start.x _ t}; stop.y _ start.y+wireWidth; AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l]; IF firstOnly THEN RETURN; start.x _ comm.pos.x; stop.y _ comm.pos.y; stop.x _ start.x+wireWidth; AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l]; } } ELSE { -- NOT firstHorizontalVC -- IF stop.y<=start.y AND stop.y>=start.y-wireWidth AND (stop.xstart.x+wireWidth) THEN { --crazy horizontal wire IF ABS[stop.x-start.x]> IF stop.x>=start.x AND stop.x<=start.x+wireWidth THEN { --vertical wire stop.x _ start.x+wireWidth; AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l] } ELSE { --L shaped (firstVertical) IF start.y<=stop.y THEN {stop.y _ stop.y+wireWidth} ELSE {t: CD.Number = stop.y; stop.y _ start.y; start.y _ t}; stop.x _ start.x+wireWidth; AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l]; IF firstOnly THEN RETURN; start.y _ comm.pos.y; stop.y _ start.y+wireWidth; stop.x _ comm.pos.x; AddARect[comm.design, CDBasics.ToRect[start, stop], comm.l]; } } END; DeleteSelected: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["delete selected "]; CDSimpleOps.DeleteSelected[comm.design]; TerminalIO.WriteLn[]; END; Undelete: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["un-delete\n"]; CDSimpleOps.Undelete[comm.design] END; AbortCommand: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["try to abort current command\n"]; CDSequencer.AbortDesignsCommand[comm.design] END; SelectExclusive: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["select pointed"]; CDSimpleOps.DeselectAll[comm.design]; CDSimpleOps.Select[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; ReSelectExclusive: PROC [design: CD.Design, pos: CD.Position, verbose: BOOL_TRUE] RETURNS [done: BOOL_TRUE] = BEGIN Deselect: PROC[i: CD.Instance] = INLINE BEGIN IF i.selected THEN { i.selected _ FALSE; CDOps.RedrawInstance[design, i] } END; DeselectList: PROC[list: CD.InstanceList] = BEGIN FOR w: CD.InstanceList _ list, w.rest WHILE w#NIL DO Deselect[w.first] ENDLOOP END; inst: CD.Instance _ NIL; --any application where pos points to FOR w: CD.InstanceList _ CDOps.InstList[design], w.rest WHILE w#NIL DO IF CDInstances.PointToI[pos, w.first] THEN { <<--hit>> IF w.first.selected THEN { DeselectList[w.rest]; CDOps.ReOrderInstance[design, w.first]; IF verbose THEN TerminalIO.WriteRope[CDCommandOps.InstRope[w.first]]; RETURN } ELSE IF inst=NIL THEN inst _ w.first } ELSE Deselect[w.first] ENDLOOP; <<--if a selected inst is pointed we already did return>> IF inst#NIL THEN { inst.selected _ TRUE; CDOps.ReOrderInstance[design, inst]; CDOps.RedrawInstance[design, inst, FALSE]; IF verbose THEN TerminalIO.WriteRope[CDCommandOps.InstRope[inst]] } ELSE { done _ FALSE; IF verbose THEN TerminalIO.WriteRope[" (no object)"]; } END; RectDist: PROC[pos: CD.Position, r: CD.Rect] RETURNS [CD.Number] = <<--Distance between a point and a rectangle>> BEGIN RETURN [MAX[ (IF pos.xr.x2 THEN (pos.x-r.x2) ELSE 0), (IF pos.yr.y2 THEN (pos.y-r.y2) ELSE 0) ]] END; CloseReSelectExclusive: PROC [design: CD.Design, pos: CD.Position, verbose: BOOL_TRUE, dist: CD.Number_100] = BEGIN IF ~ReSelectExclusive[design, pos, verbose] THEN { inst: CD.Instance _ NIL; FOR w: CD.InstanceList _ CDOps.InstList[design], w.rest WHILE w#NIL DO d: CD.Number = RectDist[pos, CDInstances.InstRectI[w.first]]; IF d> <<--(but dont select an other application if the pointed one is already the right one)>> BEGIN TerminalIO.WriteRope["select"]; [] _ ReSelectExclusive[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; --crazy heuristics to determine which kind of selection is wanted lastPos: CD.Position; lastKey: REF _ NIL; lastTime: BasicTime.GMT _ BasicTime.earliestGMT; SameAsLast: PROC[comm: CDSequencer.Command] RETURNS [yes: BOOL] = BEGIN lambda: CD.Number = comm.design.technology.lambda; ReallyClose: PROC [p1, p2: CD.Position] RETURNS [BOOL] = INLINE { RETURN [ABS[p1.x-p2.x]<=lambda AND ABS[p1.y-p2.y]<=lambda] }; now: BasicTime.GMT _ BasicTime.Now[]; yes _ ReallyClose[lastPos, comm.pos] AND lastKey=comm.key AND BasicTime.Period[lastTime, now]<=2; lastPos _ comm.pos; lastKey _ comm.key; lastTime _ now; END; CloseReSelectComm: PROC [comm: CDSequencer.Command] = <<--select pointed application exclusive;>> <<--(but dont select an other application if the pointed one is already the right one)>> <<--if there is none, select closest>> <<--cycle through if exactly sme position>> BEGIN TerminalIO.WriteRope["select "]; IF SameAsLast[comm] THEN CDSimpleOps.DeselectAll[comm.design]; [] _ CloseReSelectExclusive[comm.design, comm.pos, TRUE, 50]; TerminalIO.WriteLn[]; END; MultiOnlySelectComm: PROC [comm: CDSequencer.Command] = BEGIN NotRect: PROC [p1, p2: CD.Position] RETURNS [BOOL] = INLINE BEGIN RETURN [ABS[p1.x-p2.x]<=lambda OR ABS[p1.y-p2.y]<=lambda] END; lambda: CD.Number = comm.design.technology.lambda; IF NotRect[comm.pos, comm.sPos] THEN CloseReSelectComm[comm] ELSE AreaOnlySelect[comm]; END; DoubleAddSelectComm: PROC [comm: CDSequencer.Command] = BEGIN IF SameAsLast[comm] THEN { TerminalIO.WriteRope["change selection "]; [] _ DeSelectLast[comm.design, comm.pos, TRUE]; } ELSE TerminalIO.WriteRope["add selection "]; CDSimpleOps.Select[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; DeselectPointed: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["remove selection "]; CDSimpleOps.DeSelect[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; DeSelectLast: PROC [design: CD.Design, pos: CD.Position, usePos: BOOL_TRUE] RETURNS [done: BOOL_FALSE] = BEGIN sel: CD.Instance _ NIL; FOR w: CD.InstanceList _ CDOps.InstList[design], w.rest WHILE w#NIL DO IF w.first.selected THEN { IF ~usePos OR CDInstances.PointToI[pos, w.first] THEN sel _ w.first; }; ENDLOOP; IF sel#NIL THEN { sel.selected _ FALSE; done _ TRUE; CDOps.RedrawInstance[design, sel] } END; DeselectLastSelected: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["remove selection "]; [] _ DeSelectLast[comm.design, comm.pos, TRUE]; TerminalIO.WriteLn[]; END; AddSelection: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["add selection "]; CDSimpleOps.Select[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; DeselectAll: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["de-select all\n"]; CDSimpleOps.DeselectAll[comm.design] END; SelectAll: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["select all\n"]; CDSimpleOps.SelectAll[comm.design] END; AreaAddSelect: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["inclusive select area\n"]; CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]] END; MultiAddSelect: PROC [comm: CDSequencer.Command] = <<--Auto select area or pointed or changed>> BEGIN NotRect: PROC [p1, p2: CD.Position] RETURNS [BOOL] = INLINE BEGIN RETURN [ABS[p1.x-p2.x]<=lambda OR ABS[p1.y-p2.y]<=lambda] END; lambda: CD.Number = comm.design.technology.lambda; IF NotRect[comm.pos, comm.sPos] THEN DoubleAddSelectComm[comm] ELSE { TerminalIO.WriteRope["select inclusive area\n"]; CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]] } END; AreaAddSelectTouching: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["select inclusive touching\n"]; CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos], TRUE] END; AreaOnlySelect: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["select area\n"]; CDSimpleOps.DeselectAll[comm.design]; CDSimpleOps.AreaSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]] END; ADeSelect: PROC [comm: CDSequencer.Command] = <<--Auto deselect area or pointed>> BEGIN TerminalIO.WriteRope["de-select "]; IF comm.pos=comm.sPos THEN CDSimpleOps.DeSelect[comm.design, comm.pos] ELSE CDSimpleOps.AreaDeSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]]; TerminalIO.WriteLn[]; END; AreaDeSelect: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["de-select area\n"]; CDSimpleOps.AreaDeSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos]] END; AreaDeSelectTouching: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["de-select touching\n"]; CDSimpleOps.AreaDeSelect[comm.design, CDBasics.ToRect[comm.pos, comm.sPos], TRUE] END; CDSequencer.ImplementCommand[$AbortCommand, AbortCommand,, dontQueue]; CDSequencer.ImplementCommand[$DrawRect, AddRect]; CDSequencer.ImplementCommand[$DrawWire, AddWire]; CDSequencer.ImplementCommand[$ContinueWire, ContinueWire]; CDSequencer.ImplementCommand[$DeleteS, DeleteSelected]; CDSequencer.ImplementCommand[$Undel, Undelete]; CDSequencer.ImplementCommand[$OnlySelectP, SelectExclusive,, doQueue]; CDSequencer.ImplementCommand[$ReSelectOnlyP, ReSelectExclusiveComm,, doQueue]; CDSequencer.ImplementCommand[$CloseReSelectOnlyP, CloseReSelectComm,, doQueue]; CDSequencer.ImplementCommand[$AddSelectP, AddSelection,, doQueue]; CDSequencer.ImplementCommand[$DeSelectLP, DeselectLastSelected,, doQueue]; CDSequencer.ImplementCommand[$DeSelectFP, DeselectPointed,, doQueue]; CDSequencer.ImplementCommand[$DeSelectS, DeselectAll,, doQueue]; CDSequencer.ImplementCommand[$SelectAll, SelectAll,, doQueue]; CDSequencer.ImplementCommand[$AreaOnlySelect, AreaOnlySelect,, doQueue]; CDSequencer.ImplementCommand[$MultiOnlySelect, MultiOnlySelectComm,, doQueue]; CDSequencer.ImplementCommand[$AreaAddSelect, AreaAddSelect,, doQueue]; CDSequencer.ImplementCommand[$AreaAddSelectTouching, AreaAddSelectTouching,, doQueue]; CDSequencer.ImplementCommand[$MultiAddSelect, MultiAddSelect,, doQueue]; CDSequencer.ImplementCommand[$DoubleAddSelect, DoubleAddSelectComm,, doQueue]; CDSequencer.ImplementCommand[$AreaDeSelect, AreaDeSelect,, doQueue]; CDSequencer.ImplementCommand[$AreaDeSelectTouching, AreaDeSelectTouching,, doQueue]; CDSequencer.ImplementCommand[$ADeSelect, ADeSelect,, doQueue]; END.