!******************************************************************************!
! This test case tests plot precision discrepancies by checking two plots
! side-by-side to make sure neither shows any discrepancies when
! converting RWC's to pixels.
!
! Arguments: None
!
! @bug      NXM-3624 View precision error when converting to pixels
! @since    NeXtMidas 4.0.0
! @author:  Zachary Matthews
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct   GET DEF=TRUE  SDEF=TRUE ! for normal interactive test(s)
  switch BASELINE    baseline   GET DEF=FALSE SDEF=TRUE ! for defects or more obscure test case(s)
  switch KEEP        keep_files GET DEF=FALSE SDEF=TRUE !

  if interAct then
    set instructions "****LEFT PLOT****:\n\n&
                      1. Plot should be a green Waveform Type 1000.\n\n&
                      2. There should be no vertical black lines crossing the horizontal yellow-line thresholds &
                      (Y=0.75 for top and Y=-0.75 for bottom).\n\n&
                      3. There should be no vertical black lines nor vertical white lines crossing the &
                      horizontal red-line thresholds (Y=0.15 and Y=-0.15 respectively).\n\n&
                      ****RIGHT PLOT****:\n\n&
                      1. Plot should be a white Waveform Type 3000.\n\n&
                      2. There should be no vertical black lines crossing the horizontal yellow-line thresholds &
                      (Y=0.2 for top and Y=-0.2 for bottom)."

    call generate_test_files
    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol label macro "Test MACRO"
      gcontrol menu  main "Exit with Status =" "PASS,FAIL" TABLE={ItemColors={PASS="GREEN",FAIL="RED"}} /tleft

      gcontrol text  idtext "Instructions" instructions 24 32 /title

      plot/id=test1000 test_waveform_1000
      plot/id=test3000 test_waveform_3000
      call add_feature_lines
    pipe off
    call cleanup_test_files
  endif

endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed, unless it is expected
!******************************************************************************!
procedure processException m:emsg
  if expectedException REXISTS then
    assert/text="^reg.main.name: Expected ERROR starts with: ^{expectedException}" expectedException EQSS emsg.data.message
    remove expectedException
  else
    assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
    if "Trace" SUBS ENV.DEBUG then invoke ,, emsg.data.printStackTrace()
  endif
return

!*********************************************************************************
! Generate waveform test files
!*********************************************************************************
procedure generate_test_files
  res format_cf CF
  res freq_1 1000
  res wshape SIN
  res amp 1
  timex "2020:09:09::10:09:04.22" sec=start_time
  res elem    35000
  calc delta 1 83110 /

  res test_waveform_1000 testwaveform1000.tmp
  res test_waveform_3000 testwaveform3000.tmp
  waveform test_waveform_1000 format_cf elem=elem shape=wshape freq=freq_1 amp=amp delta=delta start=^start_time
  group test_waveform_3000 test_waveform_1000 test_waveform_1000
return

!*********************************************************************************
! Cleanup waveform test files
!*********************************************************************************
procedure cleanup_test_files
  if keep_files isFalse then
    IF test_waveform_1000 FEXISTS THEN ERASE test_waveform_1000
    IF test_waveform_3000 FEXISTS THEN ERASE test_waveform_3000
  else
    info "Not erasing these files: ^{test_waveform_1000}, ^{test_waveform_3000}"
  endif
return

!******************************************************************************!
procedure setInstructions s:msgString
  set reg.panel.controls.idtext.value msgString
return
!******************************************************************************!
procedure add_feature_lines
  feature label=LEFT_BLACK_UPPER table={NAME="LEFT_BLACK_UPPER",TYPE=HLINE,Y=0.75,&
                                  COLOR=YELLOW} plot=test1000
  feature label=LEFT_BLACK_LOWER table={NAME="LEFT_BLACK_LOWER",TYPE=HLINE,Y=-0.75,&
                                  COLOR=YELLOW} plot=test1000
  feature label=LEFT_GREEN_UPPER table={NAME="LEFT_GREEN_UPPER",TYPE=HLINE,Y=0.15,&
                                  COLOR=RED} plot=test1000
  feature label=LEFT_GREEN_LOWER table={NAME="LEFT_GREEN_LOWER",TYPE=HLINE,Y=-0.15,&
                                  COLOR=RED} plot=test1000
  feature label=RIGHT_BLACK_UPPER table={NAME="RIGHT_BLACK_UPPER",TYPE=HLINE,Y=0.2,&
                                  COLOR=RED} plot=test3000
  feature label=RIGHT_BLACK_LOWER table={NAME="RIGHT_BLACK_LOWER",TYPE=HLINE,Y=-0.2,&
                                  COLOR=RED} plot=test3000
return
