!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Tests the panel tabs.
! @author  J. Czechowski IV
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
startmacro/msgid=main/theme=gear4
  switch INTERACTIVE interAct GET DEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE

  call setDatDir

  ! Create a large file that will be paged in plot
  set bigfile "temp_test_panel_tabs_paged_file"
  waveform ^bigfile elem=1M


  pipe init
    switch OPTIONS tabFlags GET DEF="--UNKNOWN--"
    set instructions "PANEL tabs test: Click on each of the tabs to bring up &
                      a new plot. If +ROTATETABS is set then the tabs should &
                      rotate when clicked, if -ROTATETABS is set then the tabs &
                      should remain in the same position when clicked, but &
                      the active tab should be highlighted."
    set frontInst    "Click on the buttons below, to make a given plot the &
                      visible tab or to make another visible."


    set sr 1e5
    panel/setup/controls=gc/wmsgid=main ! special handling of window messages

    waveform/rt _wave{ps=16k} shape=sin form=cf elem=1e9 amp=32e3 freq=sr/10 delta=1/sr

    fft/psd/log _wave _waveb nfft=1k 

    demod/lut _wave _waved{ps=32k} mode=fm

    plot/id=gplot ^{datDir}.world.prm|^{datDir}.sv1.prm|^{datDir}.sv2.prm|^{datDir}.sv3.prm options=+bstore view=geo
    plot/id=3dplot ^{datDir}.alaska.prm view=xyz
    plot/id=srplot ^{datDir}.altitude.prm
    plot/id=bigplot ^bigfile

    shellgui/id=term

    plot/id=plot1 _waveb cnt=motion type=line axis=tf 
    feature ,, hilite {NAME=PK,TYPE=DATA|VLINE,COLOR=WHITE,ENABLE=0,X=sr/8,DX=sr/10} plot1

    plot/id=plot2 _waveb cnt=click axis=bf 

    plot/id=rplot ^{datDir}.apenny.prm axis=frame type=cont

    gcontrol label macro "MACRO"
    gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
    set gc.main.itemColors {PASS=GREEN,FAIL=RED}

    gcontrol text idtext  "Instructions" "^instructions" 24 10 /title
    gcontrol text tabText "Tabs Flags" "^tabFlags" 24 1 /title
    gcontrol text idtext2 "Show Tabs Test" "^frontInst" 24 10 /title
    gcontrol/nc=2 button showHide "Show Tabs" &
      "ShowPenny,ShowWorld" none

  pipe run
  pipe wait
  pipe off

  ! Remove the large file that was paged in plot
  erase ^bigfile

endmacro

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
procedure processMessage m:msg
  !say "Msg ^msg.name = ^msg.data"
  if msg.name EQS "MAIN" then
    assert/text="Panel Tabs (^tabFlags)" "PASS" SUBS msg.data
    pipe stop

  elseif msg.name EQS "SHOWHIDE" then
     if msg.data eqs "SHOWPENNY" then set reg.rplot.display front
     if msg.data eqs "HIDEPENNY" then set reg.rplot.display back
     if msg.data eqs "SHOWWORLD" then set reg.gplot.display front
     if msg.data eqs "HIDEWORLD" then set reg.gplot.display back
  
  elseif msg.fid eqs "PANEL"
    if msg.name eqs "STATE"
      pipe ^msg.data
    elseif msg.name eqs "VIEW"
      set reg.gplot.view msg.data
    elseif msg.name eqs "FEAT"
      if msg.data eqs "NEW"
        set l:nfeat reg.gplot.mp.features.getsize+1
        feature ,, ff {NAME=F^nfeat,TYPE=4,X=10,Y=20,DX=2,DY=2,COLOR=red} gplot
      endif
    elseif msg.name eqs "SHAPE"
      set reg.waveform.shape msg.data
    elseif msg.name eqs "DMOD"
      set reg.demod.mode msg.data
    elseif msg.name eqs "WINDOW" then
      if msg.data eqs "CLOSING" pipe stop
    endif

  elseif msg.fid eqss "PLOT" then
    set fid msg.fid
    if msg.fid eqs "PLOT1"
      set toid "PLOT2"
    else
      set toid "PLOT1"
    endif
    if msg.name eqs "MARK" or msg.name eqs "POINTER" then
      if msg.fid eqs "PLOT2"
        set hilite.x msg.data.x
        set hilite.enable 0x1
      endif
      set reg.waveform.freq msg.data.x
    elseif msg.name eqs "ZOOM" then
      set msg.name "ZOOMX"
      message pass ^toid msg
    elseif msg.name eqs "UNZOOM" then
      message pass ^toid msg
    elseif msg.name eqs "PANXY" then
      pause 0.2
      message prune ,, msg
      set msg.name "PANX"
      message pass ^toid msg
    elseif msg.name eqs "PANX" then
      message pass ^toid msg
    endif

  else
    ! say "Unhandled message ^msg.name from ^msg.fid"
  endif
return

!******************************************************************************!
! Set the dat directory
!******************************************************************************!
procedure setDatDir
  invoke nxmMajor env.nmversion.subString(0,1)
  invoke major java.lang.Integer.valueOf(nxmMajor)
  if major GE 4 then
    invoke s:datDir           nxm.sys.test.DatLocator.getDatDirLocation()
    invoke s:datDirSlash      nxm.sys.test.DatLocator.getDatDirSlashLocation()
    invoke z:sysDatFull       nxm.sys.test.DatLocator.sysDatFull()
    invoke z:sysTestDatExists nxm.sys.test.DatLocator.sysTestDatExists()
  else
    set s:datDir           "nxm.sys.dat"
    set s:datDirSlash      "nxm/sys/dat"
    set z:sysDatFull       true
    set z:sysTestDatExists false
  endif
return
