-- ChipFeatureImpl.mesa

-- A package to expand Chipmonk geometries for circuit
-- extraction.

-- last modified by E. McCreight, July 2, 1982  5:40 PM
-- written by E. McCreight, December 11, 1981  11:46 AM

DIRECTORY
  ChipExpand,
  ChipFeature,
  ChipNetDefs,
  ChipUserInt,
  CWF,
  LeftFeaturePQ,
  ppddefs,
  ppdefs;

ChipFeatureImpl: PROGRAM
  IMPORTS ChipNetDefs, ChipUserInt, CWF,
    LeftFeaturePQ, ppddefs, ppdefs
  EXPORTS ChipFeature =
  BEGIN OPEN CWF, ppdefs, ppddefs, ChipNetDefs;


  FreeFeaturePtr: TYPE = LONG POINTER TO FreeFeature ← NIL;
  FreeFeature: TYPE = RECORD[nxt: FreeFeaturePtr];
    -- a kind of overlaid variant record for Feature, guaranteed to
    -- be shorter than Feature

  freeFeatures: FreeFeaturePtr ← NIL;

  NewFeature: PUBLIC PROCEDURE[cover: CoordRect ← [0,0,0,0],
    lev: ExtractLevel ← unknown,
    caller: ItemRef ← [NIL, 0],
    lq: LeftFeaturePQ.LeftFeaturePQHandle ← NIL]
    RETURNS[FeaturePtr] =
    BEGIN
    f: FeaturePtr;
    IF freeFeatures#NIL THEN
      BEGIN
      p: FreeFeaturePtr ← freeFeatures;
      freeFeatures ← p.nxt;
      f ← LOOPHOLE[p, FeaturePtr];
      END
    ELSE f ← featureZ.NEW[Feature];
    f↑ ← [
      cover: cover,
      lev: lev,
      caller: caller];
    IF lq#NIL THEN LeftFeaturePQ.InsertLeftFeaturePQ[lq, f];
    RETURN[f];
    END; -- of NewFeature


  DestroyFeature: PUBLIC PROCEDURE[f: FeaturePtr]
    RETURNS[FeaturePtr] =
    BEGIN
    IF f.net#NIL THEN f.net ← DeRefNet[f.net];
    LOOPHOLE[f, FreeFeaturePtr].nxt ← freeFeatures;
    freeFeatures ← LOOPHOLE[f, FreeFeaturePtr];
    RETURN[NIL]
    END;


  NoteMark: PUBLIC PROCEDURE[r: CoordRect, s: STRING,
    arg1, arg2, arg3: POINTER ← NIL] =
    BEGIN
    markX, markY: Coord;
    [[x: markX, y: markY]] ← ScalePointFromChipmonk[markPnt];
    IF r.x1<=markX AND markX<=r.x2 AND
      r.y1<=markY AND markY<=r.y2 THEN
      BEGIN
      resultS: STRING ← [200];
      SWF3[resultS, s, arg1, arg2, arg3];
      ChipUserInt.DebugAtPoint[markPnt, resultS];
      END;
    END; -- of NoteMark


  BWCursor: PUBLIC PROCEDURE[world: CoordPoint] =
    BEGIN
    x, y: locNum;
    onBWScreen: BOOLEAN;
    screen: Point;
    [[x: x, y: y]] ← ScalePointToChipmonk[world];
    [onBWScreen, screen.x, screen.y,,] ←
      ppddefs.bwscaleRect[x, y, x, y];
    IF onBWScreen THEN
      BEGIN
      MouseX: POINTER TO INTEGER = LOOPHOLE[424B];
      MouseY: POINTER TO INTEGER = LOOPHOLE[425B];
      MouseX↑ ← screen.x+colWidth-curx;
      MouseY↑ ← screen.y-cury;
      END;
    IF anyKavail[] THEN
      ChipUserInt.DebugAtPoint[[x: x, y: y],
        "Keyboard interrupt here..."L];
    END; -- of BWCursor

  END. -- of ChipFeatureImpl