<> <> <> <> DIRECTORY CD, CDApplications, CDCommands, CDCommandOps, CDOps, CDOrient, CDSequencer, TerminalIO, CDInline; CDSelectCommands: CEDAR PROGRAM IMPORTS CDApplications, CDCommandOps, CDCommands, CDOps, CDSequencer, TerminalIO, CDInline = BEGIN SelectExclusive: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Select pointed"]; CDCommands.DeselectAll[comm.design]; CDCommands.Select[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; ReSelect: PROC [design: CD.Design, pos: CD.DesignPosition, verbose: BOOL_TRUE] RETURNS [done: BOOL_TRUE] = BEGIN Deselect: PROC[a: CD.ApplicationPtr] = INLINE BEGIN IF a.selected THEN { a.selected _ FALSE; CDOps.DelayedRedraw[design, CDApplications.ARectO[a], TRUE] } END; DeselectList: PROC[list: CD.ApplicationList] = BEGIN FOR w: CD.ApplicationList _ list, w.rest WHILE w#NIL DO Deselect[w.first] ENDLOOP END; ap: CD.ApplicationPtr _ NIL; --any application where pos points to FOR w: CD.ApplicationList _ CDOps.AppList[design], w.rest WHILE w#NIL DO IF CDApplications.PointToO[pos, w.first] AND CDApplications.PointToI[pos, w.first] THEN { <<--hit>> IF w.first.selected THEN { DeselectList[w.rest]; CDOps.ReOrderApplication[design, w.first]; IF verbose THEN CDCommandOps.WriteInfo[w.first]; RETURN } ELSE IF ap=NIL THEN ap _ w.first } ELSE Deselect[w.first] ENDLOOP; <<--if a selected ap is pointed we already did return>> IF ap#NIL THEN { ap.selected _ TRUE; CDOps.ReOrderApplication[design, ap]; CDOps.DelayedRedraw[design, CDApplications.ARectO[ap], FALSE]; IF verbose THEN CDCommandOps.WriteInfo[ap] } ELSE { done _ FALSE; IF verbose THEN TerminalIO.WriteRope[" (no object)"]; } END; RectDist: PROC[pos: CD.DesignPosition, r: CD.Rect] RETURNS [CD.DesignNumber] = <<--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; CloseReSelect: PROC [design: CD.Design, pos: CD.DesignPosition, verbose: BOOL_TRUE, dist: CD.DesignNumber_100] = BEGIN IF ~ReSelect[design, pos, verbose] THEN { ap: CD.ApplicationPtr _ NIL; FOR w: CD.ApplicationList _ CDOps.AppList[design], w.rest WHILE w#NIL DO d: CD.DesignNumber = RectDist[pos, CDApplications.ARectI[w.first]]; IF d> <<--(but dont select an other application if the pointed one is already the right one)>> BEGIN TerminalIO.WriteRope["(Re)Select pointed"]; [] _ ReSelect[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; CloseReSelectCommand: 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>> BEGIN TerminalIO.WriteRope["Select (most close)"]; [] _ CloseReSelect[comm.design, comm.pos, TRUE, 50]; TerminalIO.WriteLn[]; END; DeselectPointed: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Remove selection\n"]; CDCommands.DeSelect[comm.design, comm.pos] END; DeSelectLast: PROC [design: CD.Design, pos: CD.DesignPosition, usePos: BOOL_TRUE] RETURNS [done: BOOL_FALSE] = BEGIN sel: CD.ApplicationPtr _ NIL; FOR w: CD.ApplicationList _ CDOps.AppList[design], w.rest WHILE w#NIL DO IF w.first.selected THEN { IF ~usePos OR CDApplications.PointToI[pos, w.first] THEN sel _ w.first; }; ENDLOOP; IF sel#NIL THEN { sel.selected _ FALSE; done _ TRUE; CDOps.DelayedRedraw[design, CDApplications.ARectO[sel]]; } END; DeselectLastSelected: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Remove selection\n"]; [] _ DeSelectLast[comm.design, comm.pos, TRUE] END; AddSelection: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Add selection "]; CDCommands.Select[comm.design, comm.pos]; TerminalIO.WriteLn[]; END; DeselectAll: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Deselect all\n"]; CDCommands.DeselectAll[comm.design] END; DeleteSelected: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Delete selected\n"]; CDCommands.DeleteSelected[comm.design] END; DeletePointed: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Delete pointed\n"]; CDCommands.DeletePointed[comm.design, comm.pos] END; SelectAll: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Select all\n"]; CDCommands.SelectAll[comm.design] END; AreaAddSelect: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Inclusive select area\n"]; CDCommands.AreaSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos]] END; AAddSelect: PROC [comm: CDSequencer.Command] = <<--Auto select area or pointed>> BEGIN IF comm.pos=comm.sPos THEN { TerminalIO.WriteRope["select inclusive "]; CDCommands.Select[comm.design, comm.pos]; TerminalIO.WriteLn[]; } ELSE { TerminalIO.WriteRope["select inclusive\n"]; CDCommands.AreaSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos]] } END; AreaAddSelectTouching: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["select inclusive touching\n"]; CDCommands.AreaSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos], TRUE] END; AreaOnlySelect: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Exclusive select area\n"]; CDCommands.DeselectAll[comm.design]; CDCommands.AreaSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos]] END; ADeSelect: PROC [comm: CDSequencer.Command] = <<--Auto deselect area or pointed>> BEGIN TerminalIO.WriteRope["deselect\n"]; IF comm.pos=comm.sPos THEN CDCommands.DeSelect[comm.design, comm.pos] ELSE CDCommands.AreaDeSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos]] END; AreaDeSelect: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Deselect area\n"]; CDCommands.AreaDeSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos]] END; AreaDeSelectTouching: PROC [comm: CDSequencer.Command] = BEGIN TerminalIO.WriteRope["Deselect touching\n"]; CDCommands.AreaDeSelect[comm.design, CDInline.ToRect[comm.pos, comm.sPos], TRUE] END; CDSequencer.ImplementCommand[$OnlySelectP, SelectExclusive,, doQueue]; CDSequencer.ImplementCommand[$ReSelectOnlyP, ReSelectExclusive,, doQueue]; CDSequencer.ImplementCommand[$CloseReSelectOnlyP, CloseReSelectCommand,, doQueue]; CDSequencer.ImplementCommand[$AddSelectP, AddSelection,, doQueue]; --oldy-- CDSequencer.ImplementCommand[$DeSelectP, DeselectLastSelected,, 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[$AreaAddSelect, AreaAddSelect,, doQueue]; CDSequencer.ImplementCommand[$AreaAddSelectTouching, AreaAddSelectTouching,, doQueue]; CDSequencer.ImplementCommand[$AAddSelect, AAddSelect,, doQueue]; CDSequencer.ImplementCommand[$AreaDeSelect, AreaDeSelect,, doQueue]; CDSequencer.ImplementCommand[$AreaDeSelectTouching, AreaDeSelectTouching,, doQueue]; CDSequencer.ImplementCommand[$ADeSelect, ADeSelect,, doQueue]; END.