mentor/derived/BinpackAlgClass.m3


 Copyright (C) 1995, Digital Equipment Corporation.       
 All rights reserved.                                     
 See the file COPYRIGHT for a full description.           
                                                          
 Last modified on Thu Feb  9 08:48:22 PST 1995 by kalsow  
      modified on Wed Feb 17 16:46:18 PST 1993 by johnh   
      modified on Thu Sep 24 10:59:20 PDT 1992 by mhb     

********************************************************************

      *  NOTE: This file is generated automatically from the event
      *        definition file Binpack.evt.
      ********************************************************************


MODULE BinpackAlgClass;

<*NOWARN*> IMPORT Rd, ZeusClass, IntList, Fmt, BinpackAux;
<*NOWARN*> IMPORT Algorithm, RealList, Wr, ZeusPanel, FormsVBT;
<*NOWARN*> IMPORT Text, VBT, ZeusUtil;

<* PRAGMA LL *>
Fix any FormsVBT errors; don't handle exceptions for them.
<* FATAL FormsVBT.Error, FormsVBT.Unimplemented *>

REVEAL
  T = Public BRANDED OBJECT
      OVERRIDES
        <* LL = VBT.mu *>
        init := BinpackDefaultInit;
        snapshot := BinpackDefaultSnapshot;
        restore := BinpackDefaultRestore;
        updateEventCounts := BinpackDefaultUpdateCts;
        feTryToDeleteWeight := TryToDeleteWeight;
        feTryToEmptyBin := TryToEmptyBin;
      END;

PROCEDURE BinpackDefaultInit (v: T): Algorithm.T =
  <* LL = VBT.mu *>
  PROCEDURE Attach (id: TEXT; proc: FormsVBT.Proc) =
    BEGIN
      FormsVBT.AttachProc(v.eventData, id, proc, v);
    END Attach;
  BEGIN
    v.eventData := ZeusPanel.NewForm("BinpackEventData.fv");
    Attach("stopatCodeEvents", BinpackDoIt);
    Attach("waitatCodeEvents", BinpackDoIt);
    Attach("eventCounts", BinpackRefreshCts);
    Attach("stopAtSetup", BinpackDoIt);
    Attach("waitAtSetup", BinpackDoIt);
    Attach("stopAtNewWeight", BinpackDoIt);
    Attach("waitAtNewWeight", BinpackDoIt);
    Attach("stopAtPack", BinpackDoIt);
    Attach("waitAtPack", BinpackDoIt);
    Attach("stopAtIgnore", BinpackDoIt);
    Attach("waitAtIgnore", BinpackDoIt);
    Attach("stopAtProbe", BinpackDoIt);
    Attach("waitAtProbe", BinpackDoIt);
    FromFV (v.eventData, v);    (* Get FV and internal data in sync *)
    RETURN Algorithm.T.init(v);
  END BinpackDefaultInit;

PROCEDURE BinpackDoIt (           fv : FormsVBT.T;
                           e  : TEXT;
                           arg: REFANY;
                <*UNUSED*> t  : VBT.TimeStamp) =
  <* LL = VBT.mu *>
  BEGIN
    IF Text.Equal(e, "stopatCodeEvents") THEN
      NARROW(arg, T).stopatCodeEvents :=
          FormsVBT.GetBoolean(fv, "stopatCodeEvents");
    END;
    IF Text.Equal(e, "waitatCodeEvents") THEN
      NARROW(arg, T).waitatCodeEvents :=
          FormsVBT.GetInteger(fv, "waitatCodeEvents");
    END;
    IF Text.Equal(e, "stopAtSetup") THEN
      NARROW(arg, T).eventDataRec.stopAtSetup :=
          FormsVBT.GetBoolean(fv, "stopAtSetup");
    END;
    IF Text.Equal(e, "waitAtSetup") THEN
      NARROW(arg, T).eventDataRec.waitAtSetup :=
          FormsVBT.GetInteger(fv, "waitAtSetup");
    END;
    IF Text.Equal(e, "stopAtNewWeight") THEN
      NARROW(arg, T).eventDataRec.stopAtNewWeight :=
          FormsVBT.GetBoolean(fv, "stopAtNewWeight");
    END;
    IF Text.Equal(e, "waitAtNewWeight") THEN
      NARROW(arg, T).eventDataRec.waitAtNewWeight :=
          FormsVBT.GetInteger(fv, "waitAtNewWeight");
    END;
    IF Text.Equal(e, "stopAtPack") THEN
      NARROW(arg, T).eventDataRec.stopAtPack :=
          FormsVBT.GetBoolean(fv, "stopAtPack");
    END;
    IF Text.Equal(e, "waitAtPack") THEN
      NARROW(arg, T).eventDataRec.waitAtPack :=
          FormsVBT.GetInteger(fv, "waitAtPack");
    END;
    IF Text.Equal(e, "stopAtIgnore") THEN
      NARROW(arg, T).eventDataRec.stopAtIgnore :=
          FormsVBT.GetBoolean(fv, "stopAtIgnore");
    END;
    IF Text.Equal(e, "waitAtIgnore") THEN
      NARROW(arg, T).eventDataRec.waitAtIgnore :=
          FormsVBT.GetInteger(fv, "waitAtIgnore");
    END;
    IF Text.Equal(e, "stopAtProbe") THEN
      NARROW(arg, T).eventDataRec.stopAtProbe :=
          FormsVBT.GetBoolean(fv, "stopAtProbe");
    END;
    IF Text.Equal(e, "waitAtProbe") THEN
      NARROW(arg, T).eventDataRec.waitAtProbe :=
          FormsVBT.GetInteger(fv, "waitAtProbe");
    END;
  END BinpackDoIt;

PROCEDURE BinpackRefreshCts (
                <*UNUSED*> fv  : FormsVBT.T;
                <*UNUSED*> e   : TEXT;
                           arg : REFANY;
                <*UNUSED*> t   : VBT.TimeStamp) =
  <* LL = VBT.mu *>
  BEGIN
    NARROW(arg, T).updateEventCounts(FALSE);
  END BinpackRefreshCts;

PROCEDURE FromFV (fv : FormsVBT.T; alg: T) =
  <* LL = VBT.mu *>
  BEGIN
    alg.stopatCodeEvents :=
        FormsVBT.GetBoolean(fv, "stopatCodeEvents");
    alg.waitatCodeEvents :=
        FormsVBT.GetInteger(fv, "waitatCodeEvents");
    alg.eventDataRec.stopAtSetup :=
        FormsVBT.GetBoolean(fv, "stopAtSetup");
    alg.eventDataRec.waitAtSetup :=
        FormsVBT.GetInteger(fv, "waitAtSetup");
    alg.eventDataRec.stopAtNewWeight :=
        FormsVBT.GetBoolean(fv, "stopAtNewWeight");
    alg.eventDataRec.waitAtNewWeight :=
        FormsVBT.GetInteger(fv, "waitAtNewWeight");
    alg.eventDataRec.stopAtPack :=
        FormsVBT.GetBoolean(fv, "stopAtPack");
    alg.eventDataRec.waitAtPack :=
        FormsVBT.GetInteger(fv, "waitAtPack");
    alg.eventDataRec.stopAtIgnore :=
        FormsVBT.GetBoolean(fv, "stopAtIgnore");
    alg.eventDataRec.waitAtIgnore :=
        FormsVBT.GetInteger(fv, "waitAtIgnore");
    alg.eventDataRec.stopAtProbe :=
        FormsVBT.GetBoolean(fv, "stopAtProbe");
    alg.eventDataRec.waitAtProbe :=
        FormsVBT.GetInteger(fv, "waitAtProbe");
  END FromFV;

<*UNUSED*>
PROCEDURE ToFV (fv : FormsVBT.T; alg: T) =
  <* LL = VBT.mu *>
  BEGIN
    FormsVBT.PutBoolean(fv, "stopatCodeEvents", alg.stopatCodeEvents);
    FormsVBT.PutInteger(fv, "waitatCodeEvents", alg.waitatCodeEvents);
    FormsVBT.PutBoolean(fv, "stopAtSetup",
                        alg.eventDataRec.stopAtSetup);
    FormsVBT.PutInteger(fv, "waitAtSetup",
                        alg.eventDataRec.waitAtSetup);
    FormsVBT.PutBoolean(fv, "stopAtNewWeight",
                        alg.eventDataRec.stopAtNewWeight);
    FormsVBT.PutInteger(fv, "waitAtNewWeight",
                        alg.eventDataRec.waitAtNewWeight);
    FormsVBT.PutBoolean(fv, "stopAtPack",
                        alg.eventDataRec.stopAtPack);
    FormsVBT.PutInteger(fv, "waitAtPack",
                        alg.eventDataRec.waitAtPack);
    FormsVBT.PutBoolean(fv, "stopAtIgnore",
                        alg.eventDataRec.stopAtIgnore);
    FormsVBT.PutInteger(fv, "waitAtIgnore",
                        alg.eventDataRec.waitAtIgnore);
    FormsVBT.PutBoolean(fv, "stopAtProbe",
                        alg.eventDataRec.stopAtProbe);
    FormsVBT.PutInteger(fv, "waitAtProbe",
                        alg.eventDataRec.waitAtProbe);
    CountsToFV (fv, alg);
  END ToFV;

PROCEDURE CountsToFV (fv : FormsVBT.T; alg: T) =
  <* LL = VBT.mu *>
  BEGIN
    FormsVBT.PutText(fv, "ctOfSetup",
                        Fmt.Int(alg.eventDataRec.ctOfSetup));
    FormsVBT.PutText(fv, "ctOfNewWeight",
                        Fmt.Int(alg.eventDataRec.ctOfNewWeight));
    FormsVBT.PutText(fv, "ctOfPack",
                        Fmt.Int(alg.eventDataRec.ctOfPack));
    FormsVBT.PutText(fv, "ctOfIgnore",
                        Fmt.Int(alg.eventDataRec.ctOfIgnore));
    FormsVBT.PutText(fv, "ctOfProbe",
                        Fmt.Int(alg.eventDataRec.ctOfProbe));
  END CountsToFV;

PROCEDURE BinpackDefaultUpdateCts ( v: T; reset: BOOLEAN) =
  <* LL = VBT.mu *>
  BEGIN
    IF reset THEN
      v.eventDataRec.ctOfSetup := 0;
      v.eventDataRec.ctOfNewWeight := 0;
      v.eventDataRec.ctOfPack := 0;
      v.eventDataRec.ctOfIgnore := 0;
      v.eventDataRec.ctOfProbe := 0;
    END;
    CountsToFV (v.eventData, v);
  END BinpackDefaultUpdateCts;

PROCEDURE BinpackDefaultSnapshot (v: T; wr: Wr.T)
  RAISES {ZeusClass.Error} =
  <* LL = VBT.mu *>
  BEGIN
    TRY
      Wr.PutChar(wr, '(')
    EXCEPT
    ELSE
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultSnapshot write error");
    END;
    IF v.eventData = NIL THEN
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultSnapshot: " &
          "eventData not set!");
    END;
    TRY
      v.eventData.snapshot(wr)
    EXCEPT
      FormsVBT.Error (msg) =>
        RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultSnapshot FV error: "
          & msg);
    ELSE
      RAISE ZeusClass.Error(
        "BinpackAlgClass.BinpackDefaultSnapshot error");
    END;
    Algorithm.T.snapshot(v, wr);
    TRY
      Wr.PutChar(wr, ')')
    EXCEPT
    ELSE
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultSnapshot write error");
    END;
  END BinpackDefaultSnapshot;

PROCEDURE BinpackDefaultRestore (v: T; rd: Rd.T)
  RAISES {ZeusClass.Error} =
  <* LL = VBT.mu *>
  BEGIN
    IF rd = NIL THEN RETURN END;
    IF NOT ZeusUtil.EatChar(rd, '(') THEN
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultRestore read error");
    END;
    IF v.eventData = NIL THEN
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultRestore: " &
          "eventData not set!");
    END;
    TRY
      v.eventData.restore(rd);
      v.updateEventCounts(FALSE);
      FromFV(v.eventData, v);
    EXCEPT
    ELSE
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultRestore error");
    END;
    Algorithm.T.restore(v, rd);
    IF NOT ZeusUtil.EatChar(rd, ')') THEN
      RAISE ZeusClass.Error(
          "BinpackAlgClass.BinpackDefaultRestore read error");
    END;
  END BinpackDefaultRestore;

PROCEDURE TryToDeleteWeight (self: T
    ; <*UNUSED*> id: INTEGER
) =
  <* LL = VBT.mu *>
  BEGIN
    self.evtHandled := FALSE;
  END TryToDeleteWeight;

PROCEDURE TryToEmptyBin (self: T
    ; <*UNUSED*> bin: INTEGER
) =
  <* LL = VBT.mu *>
  BEGIN
    self.evtHandled := FALSE;
  END TryToEmptyBin;

BEGIN
END BinpackAlgClass.