!******************************************************************************!
! purpose: allow easy calling of tests and commands for fuller demo
!
! author : Jeanette McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE SDEF=TRUE

  if interAct then

    AUX READ=+HOME
    set aux.png "^{aux.1}screenshots"
    set aux.slides "^{aux.1}slides"
    call loadSlideNames

    invoke nmroot nxm.sys.lib.Shell.getNmRoot()
    res nxmLogo "^{nmroot}htdocs/NXM.png"

    ! initalize SSL for WMS
    invoke sslInitComplete nxm.sys.lib.SSLUtilities.isInitDone()
    if sslInitComplete ISFALSE then
      sslconfigure /insecure /propsforuser /bigtlsmax
    endif

    call loadDemoTable
    if fullDemo isTrue
      call loadDemoSettings
    else
      res operationalKML ""
      table wmsConfig {}
    endif

    res htmlstr "<html>&
             <body BGCOLOR="#000000" TEXT="#80c0c0" LINK="#ff8080" VLINK="#ff0000" ALINK="#a05050">&
             <div ALIGN="left">&
             <table BGCOLOR="#000080" BORDER=3 BORDERCOLOR="#0000ff"><tr>&
             <td><h1><font FACE="courier" SIZE=6><font SIZE=6>W</font>ELCOME TO THE NEXTMIDAS DEMO!</font></h1></td>&
             </tr></table>&
             </body></html>"

    pipe on
      set sr 1e5
      waveform/rt _wave{ps=32k} shape=sin form=cf elem=inf amp=32e3 freq=sr/10 delta=1/sr
      fft/psd/log _wave _waveb nfft=1k

      panel/msgid=MAIN/setup/controls=gc/menubar

      gcontrol label  MACRO   "MACRO"
      gcontrol menu   MAIN    "Click EXIT to close =" "EXIT" TABLE={ItemColors={EXIT="#80c0c0"}} /tleft  /lh=30 /WFS=20 /wtheme={CWFG=WHITE}
      gcontrol stext  WELCOME "Welcome to the NeXtMidas Demo!" htmlstr 16 6

      gcontrol label  SLIDESLBL "SLIDES"
      gcontrol lval   SLIDES    "Slides" 0 0 ^numslides 1 /gauge /wtheme={CWFG=WHITE}

      gcontrol label  DEMO_BUTTONS "DEMO BUTTONS"
      gcontrol button DEMOENHANCED "" "DEMOENHANCED" /lh=60 /WFS=18 /wtheme={CWFG=WHITE}
      gcontrol button SNAPPER      "" "Panel Options" /lh=60  /WFS=18 /wtheme={CWFG=WHITE}
      gcontrol button JAVAGUI      "" "Java Swing Design" /lh=60  /WFS=18 /wtheme={CWFG=WHITE}
      gcontrol button MAPS         "" "Map Types and Data" /lh=60 /WFS=18 /wtheme={CWFG=WHITE}
      gcontrol button GEO_MATH     "" "Geospacial Math" /lh=60  /WFS=18 /wtheme={CWFG=WHITE}
      gcontrol button DSP          "DSP library"  "WINDOW,NEWRATE" "WINDOW" /lh=60 /WFS=18 /wtheme={CWFG=WHITE}

      gcontrol label  OP_SCREENSHOTS  "OPERATIONAL SCREENSHOTS"
      gcontrol file   SCREENSHOTS  "  Operational Screenshots" "" "*.png" "PNG" /wtheme={CWFG=WHITE}
      plot/id=slides  "^nxmLogo"
      shellgui/id=idshellgui/attach

    pipe off

  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg

if msg.name eqs "MAIN"
  assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
  pipe stop

elseif msg.name eqs "DEMOENHANCED"  then
  demoenhanced

elseif msg.name eqs "SNAPPER"  then
  %test_snapper

elseif msg.name eqss "JAVAGUI"  then
  %test_plot_jinternalframe

elseif msg.name eqss "MAPS"  then
  %map_types_and_data_demo "^operationalKML" wmsConfig "^operationalT5"

elseif msg.name eqss "GEO_MATH"  then
  %test_plot_cones_orbit

elseif msg.name eqss "SCREENSHOTS"  then
  message send slides name=openfile info=-1 data="^{msg.data}.png{AUX=PNG}"

elseif msg.name eqss "SLIDES" then
  if msg.data EQ 0 then
    message send slides name=openfile info=-1 data="\"^nxmLogo\""
  else
    calc l:slideindex msg.data 1 -
    message send slides name=openfile info=-1 data="^{myslides.^slideindex}"
  endif
elseif msg.name eqss "DSP"  then
  if msg.data eqss "WINDOW" then
    home test dsp
    %demo_window
    home /restore
  elseif msg.data eqss "NEWRATE" then
    home test dsp
    %demo_newrate_nyquist
    home /restore
  endif
else
  say "^reg.main.name: Unhandled message name: ^msg.name from fid: ^msg.fid"
endif

return
!*************************************************************************************
! Load Demo Table from READ AUX
!*************************************************************************************
procedure loadDemoTable
  if demo_config.tbl fexists then
    say "Using demo_config.tbl for configuration"
    table demo_options CREATE demo_config.tbl
    res fullDemo true
  else
    say "demo_config.tbl does not exist, this will limit demo options"
    res fullDemo false
  endif
return
!*************************************************************************************
! Grab the Demo Settings from the Demo Table
!*************************************************************************************
procedure loadDemoSettings
  table demo_options getkey OPERATIONAL_KML operationalKML
  table demo_options getkey WMS_CONFIG wmsConfig
  table demo_options getkey OPERATIONAL_T5 operationalT5
return
!*************************************************************************************
! Load the slides from the 
!*************************************************************************************
procedure loadSlideNames
  files/list=slideslist ext=png aux=slides
  invoke myslides slideslist.split(",")
  invoke numslides myslides.size()
return
