(DEFINE-FILE-INFO PACKAGE "IL" READTABLE "INTERLISP" BASE 10)
(FILECREATED "15-Aug-90 15:42:46" {DSK}<usr>local>lde>SOURCES>loops>LIBRARY>GAUGEALPHANUMERICS.;2 13050  

      changes to%:  (VARS GAUGEALPHANUMERICSCOMS)

      previous date%: "23-Feb-88 23:00:07" 
{DSK}<usr>local>lde>SOURCES>loops>LIBRARY>GAUGEALPHANUMERICS.;1)


(* ; "
Copyright (c) 1986, 1987, 1988, 1990 by Venue & Xerox Corporation.  All rights reserved.
")

(PRETTYCOMPRINT GAUGEALPHANUMERICSCOMS)

(RPAQQ GAUGEALPHANUMERICSCOMS
       ((DECLARE%: DONTCOPY (PROP MAKEFILE-ENVIRONMENT GAUGEALPHANUMERICS))
        (FILES (FROM VALUEOF LOOPSLIBRARYDIRECTORY)
               GAUGES)
        (CLASSES AlphaNumeric LCD LCDMixin)
        (METHODS AlphaNumeric.ComputeScale AlphaNumeric.PrintReading AlphaNumeric.Reset 
               AlphaNumeric.Set AlphaNumeric.SetParameters AlphaNumeric.ShowInstrument 
               AlphaNumeric.ShowReading LCD.PrintReading LCD.SetParameters LCD.Shape LCD.ShapeToHold
               LCDMixin.ComputeScale LCDMixin.PrintReading LCDMixin.SmallRegion)))
(DECLARE%: DONTCOPY 

(PUTPROPS GAUGEALPHANUMERICS MAKEFILE-ENVIRONMENT (:PACKAGE "IL" :READTABLE "INTERLISP" :BASE
                                                                 10))
)

(FILESLOAD (FROM VALUEOF LOOPSLIBRARYDIRECTORY)
       GAUGES)

(DEFCLASSES AlphaNumeric LCD LCDMixin)
(DEFCLASS AlphaNumeric
   (MetaClass AbstractClass doc "A gauge which gives an alphanumeric display of a value" Edited%: 
                                                             (* edited%: "29-Jan-87 03:32"))
   (Supers Gauge)
   (InstanceVariables (height 14)
          (width 30)
          (precision 5 doc 
                 "value= num chars in reading. readingRegion is derived from precision and rading")))

(DEFCLASS LCD
   (MetaClass Class Edited%:                             (* RBGMartin "10-Apr-86 16:07")
          doc "This is the default metaClass for all classes")
   (Supers AlphaNumeric))

(DEFCLASS LCDMixin
   (MetaClass AbstractClass Edited%:                     (* edited%: "29-Jan-87 03:34")
          doc "Abstract classes are placeholders in the inheritance network, which cannot themselves be instantiated."
          )
   (Supers AlphaNumeric)
   (InstanceVariables (precision 3 readingRegion NIL doc 
                    "value= num chars in reading. readingRegion is derived from precision and rading"
                             )
          (readingY 7 doc "y position of bottom of reading")))


(\BatchMethodDefs)
(METH AlphaNumeric  ComputeScale (min max)
      "Sets the precision based on the width of min and max" (category (AlphaNumeric)))


(METH AlphaNumeric  PrintReading (printingRegionFlg)
      "Print the displayVal in the window or printingRegion by painting black and then inverting"
      (category (AlphaNumeric)))


(METH AlphaNumeric  Reset (newReading)
      "set reading to value. Same as Set since there is no special way to do this" (category (Gauge)))


(METH AlphaNumeric  Set (newReading)
      "Put number in box" (category (AlphaNumeric)))


(METH AlphaNumeric  SetParameters NIL
      "Make sure the window is large enough for the font." (category (Internal)))


(METH AlphaNumeric  ShowInstrument NIL
      "Nothing needed" (category (Internal)))


(METH AlphaNumeric  ShowReading NIL
      "Put the displayVal up on the instrument" (category (AlphaNumeric)))


(METH LCD  PrintReading NIL
      "Print the displayVal in the printingRegion by painting black and then inverting" (category
                                                                                         NoCategory))


(METH LCD  SetParameters NIL
      "sets min width and height." (category (Internal)))


(METH LCD  Shape (newRegion noUpdateFlg)
      "Shapes outside of region to specified shape. Uses GETREGION and width:,min height:,min"
      (category (Public)))


(METH LCD  ShapeToHold NIL
      "changes dimensions of LCD to the smallest required to hold the reading. If a variable pitch font is used, there may still be blank space on the left and right sides of the reading or the characters of the reading may extend beyond the end if too many are wider than the letter A"
      (category (Gauge)))


(METH LCDMixin  ComputeScale (min max)
      "Sets the precision based on the width of min and max" (category NoCategory))


(METH LCDMixin  PrintReading NIL
      "Print the displayVal in the readingRegion by painting black and then inverting" (category
                                                                                        (AlphaNumeric
                                                                                         )))


(METH LCDMixin  SmallRegion NIL
      "Create small LCD region for mixin display" (category (LCDMixin)))



(Method ((AlphaNumeric ComputeScale) self min max)       (* ; "RBGMartin  5-May-86 12:11")
   "Sets the precision based on the width of min and max"
   (_@ precision (IMAX (if (NEQ min NIL)
                           then                          (* This is here because
                                                           (NCHARS) returns 3)
                                 (NCHARS min)
                         else 

         (* Use 1 instead of 0 to make sure gauge is at least one character wide.)

                               1)
                       (if (NEQ max NIL)
                           then (NCHARS max)
                         else 1))))

(Method ((AlphaNumeric PrintReading) self printingRegionFlg)
                                                             (* ; "RBGMartin 30-Jan-87 05:02")
   "Print the displayVal in the window or printingRegion by painting black and then inverting"
   (AND (_ self HasLispWindow)
        (PROG (w op rdString printingRegion (window (@ window)))
              [SETQ rdString (COND
                                ((Object? (@ reading))
                                 (GetObjectName (@ reading)))
                                (T (@ reading)]
              (SETQ w (NCHARS rdString))
              (COND
                 ((IGREATERP 0 (IDIFFERENCE (@ precision)
                                      w))

         (* * String too long, change precison and make window grow if necessary)

                  (_@ precision w)
                  (_ self Update)))
              [COND
                 (printingRegionFlg (SETQ printingRegion (@ precision%:,readingRegion)]
              (DSPFILL printingRegion BLACKSHADE 'PAINT window)
              (SETQ op (DSPOPERATION 'INVERT window))
              (CENTERPRINTINREGION rdString printingRegion window)
              (DSPOPERATION op window))))

(Method ((AlphaNumeric Reset) self newReading)           (* ; "RBGMartin 11-Apr-86 17:06")
   "set reading to value. Same as Set since there is no special way to do this"
   (_ self Set newReading))

(Method ((AlphaNumeric Set) self newReading)             (* ; "RBGMartin 11-Apr-86 17:06")
   "Put number in box"
   (_@ reading newReading)
   (_ self PrintReading))

(Method ((AlphaNumeric SetParameters) self)              (* ; "RBGMartin 28-Jan-87 17:29")
   "Make sure the window is large enough for the font."
   [PROG NIL
         (_Super )
         (_@ width [MAX (@ width)
                        (_@ width%:,min [WIDTHIFWINDOW (PLUS 2 (TIMES (@ precision)
                                                                      (COND
                                                                         ((NUMBERP (@ reading))
                                                                          (CHARWIDTH 48 (@ font)))
                                                                         (T (CHARWIDTH 65
                                                                                   (@ font)])])

         (* 65 is CHARCODE of A. This is not the widest character, but it is slightly 
       wider than the average width. 48 is CHARCODE of "0")

         (_@ height [MAX (@ height)
                         (_@ height%:,min (HEIGHTIFWINDOW (IPLUS 2 (FONTHEIGHT (@ font)))
                                                 (@ title)))])])

(Method ((AlphaNumeric ShowInstrument) self)             (* ; "RBGMartin 11-Apr-86 17:06")
   "Nothing needed"
   self)

(Method ((AlphaNumeric ShowReading) self)                (* ; "RBGMartin 11-Apr-86 17:06")
   "Put the displayVal up on the instrument"
   (_ self PrintReading))

(Method ((LCD PrintReading) self)                        (* ; "RBGMartin 10-Apr-86 17:11")
   "Print the displayVal in the printingRegion by painting black and then inverting"
                                                             (* ; 
                           "for the class LCD, this is the entire window, so printingRegion is NIL")
   (_Super self PrintReading))

(Method ((LCD SetParameters) self)                       (* ; "RBGMartin 28-Jan-87 17:40")
   "sets min width and height."
   (_Super )
   (_@ precision [NCHARS (COND
                            ((Object? (@ reading))
                             (GetObjectName (@ reading)))
                            (T (@ reading)])
   (_@ width%:,min [WIDTHIFWINDOW (PLUS 2 (TIMES (@ precision)
                                                 (COND
                                                    ((NUMBERP (@ reading))
                                                     (CHARWIDTH 48 (@ font)))
                                                    (T (CHARWIDTH 65 (@ font)])
   (_@ height%:,min [HEIGHTIFWINDOW (IPLUS 2 (FONTHEIGHT (@ font)]))

(Method ((LCD Shape) self newRegion noUpdateFlg)         (* ; "RBGMartin 28-Jan-87 17:44")
   "Shapes outside of region to specified shape. Uses GETREGION and width:,min height:,min"
   (_ self SetParameters)
   (_Super self Shape newRegion noUpdateFlg))

(Method ((LCD ShapeToHold) self)                         (* ; "RBGMartin 28-Jan-87 17:47")
   "changes dimensions of LCD to the smallest required to hold the reading. If a variable pitch font is used, there may still be blank space on the left and right sides of the reading or the characters of the reading may extend beyond the end if too many are wider than the letter A"
   (_@ precision (NCHARS (@ reading)))
   (_@ height 0)
   (_@ width 0)
   (_ self Update))

(Method ((LCDMixin ComputeScale) self min max)           (* ; "RBGMartin  5-May-86 17:44")
   "Sets the precision based on the width of min and max"
   (_Super self ComputeScale min max)
   (_ self SmallRegion))

(Method ((LCDMixin PrintReading) self)                   (* ; "RBGMartin  2-May-86 16:11")
   "Print the displayVal in the readingRegion by painting black and then inverting"
   (_Super self PrintReading T))

(Method ((LCDMixin SmallRegion) self)                    (* ; "RBGMartin  2-May-86 16:02")
   "Create small LCD region for mixin display"
   (_@ precision%:,readingRegion (PROG [(readingHeight (FONTHEIGHT (@ font)))
                                        (readingWidth (COND
                                                         [(NUMBERP (@ reading))
                                                             (* The reading is a number so base 
                                                           the character width on the character 
                                                           "0")
                                                          (IPLUS 4 (ITIMES (@ precision)
                                                                          (CHARWIDTH 48 (@ font)]
                                                         (T 

         (* The reading is non-numeric so base the character width on the character W.
       CHARCODE of W is 87 -
       assuming W is the widest character in the font.)

                                                            (IPLUS 4 (ITIMES (@ precision)
                                                                            (CHARWIDTH 87
                                                                                   (@ font)]
                                       (RETURN (create REGION
                                                      LEFT _ (IQUOTIENT (IDIFFERENCE (InteriorWidth
                                                                                      self)
                                                                               readingWidth)
                                                                    2)
                                                      BOTTOM _ (@ readingY)
                                                      WIDTH _ readingWidth
                                                      HEIGHT _ readingHeight)))))

(\UnbatchMethodDefs)
(PUTPROPS GAUGEALPHANUMERICS COPYRIGHT ("Venue & Xerox Corporation" 1986 1987 1988 1990))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL)))
STOP
