(DEFINE-FILE-INFO PACKAGE "IL" READTABLE "INTERLISP" BASE 10)
(FILECREATED "15-Aug-90 16:13:26" {DSK}<usr>local>lde>SOURCES>loops>LIBRARY>GAUGEDIALS.;2 7875   

      changes to%:  (FILES GAUGEBOUNDEDMIXIN)
                    (VARS GAUGEDIALSCOMS)

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


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

(PRETTYCOMPRINT GAUGEDIALSCOMS)

(RPAQQ GAUGEDIALSCOMS ((DECLARE%: DONTCOPY (PROP MAKEFILE-ENVIRONMENT GAUGEDIALS))
                           (FILES (FROM VALUEOF LOOPSLIBRARYDIRECTORY)
                                  GAUGEINSTRUMENTS GAUGEBOUNDEDMIXIN)
                           (CLASSES Dial)
                           (METHODS Dial.DrawInstrument Dial.SetParameters Dial.ShowLabels 
                                  Dial.ShowTicks)))
(DECLARE%: DONTCOPY 

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

(FILESLOAD (FROM VALUEOF LOOPSLIBRARYDIRECTORY)
       GAUGEINSTRUMENTS GAUGEBOUNDEDMIXIN)

(DEFCLASSES Dial)
(DEFCLASS Dial
   (MetaClass Class doc "A dial with bounded range, like an auto speedometer" Edited%: 
                                                             (* edited%: "21-May-86 17:43"))
   (Supers BoundedMixin RoundScale)
   (InstanceVariables (labels (0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0)
                             doc "labels for the instrument")
          (ticks 11 tickLength 5 smallTicks 1 doc 
      "ticks on the instrument; value is number or NIL; smallTicks is number between each large tick"
                 )
          (width 10)
          (height 10)
          (displayVal 120 doc "Internal value relative to instrument")
          (lower 120 doc "lower bound for internal displayVal")
          (range -60 doc "range for internal displayVal")))


(\BatchMethodDefs)
(METH Dial  DrawInstrument NIL
      "Does not draw anything" (category (Dial)))


(METH Dial  SetParameters NIL
      "Set up center of circle for dial and needle, and length of radius." (category (Internal)))


(METH Dial  ShowLabels NIL
      "If there are any labels, show them on the dial" (category (Dial)))


(METH Dial  ShowTicks NIL
      "Draw ticks in even intervals from angle of 120 down to 60" (category (Dial)))



(Method ((Dial DrawInstrument) self)                     (* ; "edited: 27-Jan-87 10:36")
   "Does not draw anything"                                  (* ; 
                                                     "Draw two concentric circles to contain ticks")

   (* ;; "(LET* ((xc (@ xc)) (yc (@ yc)) (2xc (TIMES xc 2)) (ht (PLUS yc (TIMES xc (MINUS (TAN (@ lower))))))) (DRAWCIRCLE (@ xc) (@ yc) (@ radius) (@ brushWidth) NIL (@ window)) (DRAWCIRCLE (@ xc) (@ yc) (IDIFFERENCE (@ radius) (@ ticks:,tickLength)) (@ brushWidth) NIL (@ window)) (FILLPOLYGON (APPEND (COND ((GREATERP yc 0) (LIST (CONS xc 0)))) (LIST (CONS xc yc) (CONS -1 ht) (CONS -1 0))) WHITESHADE (@ window)) (FILLPOLYGON (APPEND (COND ((GREATERP yc 0) (LIST (CONS xc 0)))) (LIST (CONS xc yc) (CONS 2xc ht) (CONS 2xc 0))) WHITESHADE (@ window)))")

   self)

(Method ((Dial SetParameters) self)                      (* ; "RBGMartin 30-Jan-87 02:44")
   "Set up center of circle for dial and needle, and length of radius."
   [PROG [xc halfbaseOfCurve heightOfCurve theta (ms (MAXSTRINGWIDTH (@ labels)
                                                            (@ font)]
         (_Super )
         (_@ width%:,min [WIDTHIFWINDOW (PLUS (TIMES ms (PLUS 2 (@ ticks)))
                                              (TIMES 2 (CHARWIDTH (CHARCODE 0)
                                                              (@ font)])
         (_@ width (IMAX (@ width)
                         (@ width%:,min)))
         (_@ height%:,min (HEIGHTIFWINDOW [PLUS (@ spaceForLabelScale)
                                                (@ ticks%:,tickLength)
                                                (TIMES 2 (FONTHEIGHT (@ font)))
                                                (TIMES (DIFFERENCE (@ width%:,min)
                                                              ms)
                                                       (DIFFERENCE 1 (QUOTIENT (SQRT 3)
                                                                            2]
                                 (@ title)))
         (_@ height (IMAX (@ height%:,min)
                          (@ height)))
         (_@ xc (SETQ xc (IQUOTIENT (InteriorWidth self)
                                2)))
         (SETQ halfbaseOfCurve (QUOTIENT [DIFFERENCE (InteriorWidth self)
                                                (TIMES 2 (PLUS ms (TIMES 1.5 (CHARWIDTH (CHARCODE
                                                                                         0)
                                                                                    (@ font)]
                                      2))
         (SETQ heightOfCurve (MIN [DIFFERENCE (InteriorHeight self)
                                         (PLUS (@ spaceForLabelScale)
                                               (@ ticks%:,tickLength)
                                               (TIMES 2 (FONTHEIGHT (@ font)]
                                  halfbaseOfCurve))
         (_@ radius (DIFFERENCE heightOfCurve (QUOTIENT (DIFFERENCE (TIMES heightOfCurve 
                                                                           heightOfCurve)
                                                               (TIMES halfbaseOfCurve halfbaseOfCurve
                                                                      ))
                                                     (TIMES 2 heightOfCurve))))
         (SETQ theta (DIFFERENCE (ARCTAN2 halfbaseOfCurve (MINUS heightOfCurve))
                            90))
         (_@ lower (PLUS 90 (TIMES 2 theta)))
         (_@ range (TIMES -4 theta))
         (_@ needleLength (IDIFFERENCE (@ radius)
                                 (IPLUS 4 (@ ticks%:,tickLength))))
         (_@ yc (IDIFFERENCE (PLUS (@ spaceForLabelScale)
                                   (@ ticks%:,tickLength)
                                   heightOfCurve)
                       (@ radius)))])

(Method ((Dial ShowLabels) self)                         (* ; "edited: 22-May-86 00:18")
   "If there are any labels, show them on the dial"
   [COND
      ((@ labels)
       (DSPRIGHTMARGIN (IPLUS (@ width)
                              50)
              (@ window))                                    (* so that labels on the right won't 
                                                           go to the next line)
       (PROG [(nl (SUB1 (LENGTH (@ labels)]
             (for lab in (@ labels) as i from 0 by 1
                do (ShowRayLabel self (PLUS (@ lower)
                                                (QUOTIENT (TIMES i (@ range))
                                                       nl))
                              lab])

(Method ((Dial ShowTicks) self)                          (* ; "edited: 22-May-86 00:21")
   "Draw ticks in even intervals from angle of 120 down to 60"
   [for a in (EvenIntervals (@ lower)
                            (@ range)
                            (SUB1 (@ ticks))) bind [incr _ (FQUOTIENT (@ range)
                                                                      (SUB1 (@ ticks)]
      do (DrawTick self a (@ ticks%:,smallTicks)
                    incr 0.5) finally (DrawTick self (PLUS (@ lower)
                                                               (@ range)])

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