!******************************************************************************!
! Tests XYZ graph support for LayerDrawable Features and 3D CSV points
!
! @bug      NXM-3500 XYZ Graph support for LayerDrawable Features and 3D CSV points
! @author:  Jeanette McCall
! @since:   NeXtMidas 3.9.3
!******************************************************************************!
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)

  res first_feat 65

  if interAct then
    set instructions "You should see an 3-dimensiona graph.. \n\n&
                      'WISHING' 'YOU' 'THE' 'VERY' BEST' at locations:\n&
                      (10,10,10), (20,20,20), (30,30,30), (40,40,40) and (50,50,50)\n\n&
                      as well as 20 red circle Features: \n&
                      (65,65,65) ... (84,84,84)\n\n&
                      Use ctrl-click on one of the points to bring up the information of the point.\n\n&
                      The plot axis should extend each time 'Add' is clicked (for now ... give margin later)"


    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 26 /title
      set quals {HEADERROWS=L:1,COLUMNNAMES="D:X,D:Y,D:Z,NAME", LAYER={LT="T5",DATATYPE="XYZ",NAME="NAME",AutoselectEnable="CLICK",AutoSelectMode="Pixel",COLOR=BLUE,SELECTCOLOR=GREEN }}

      plot/id=plot1 nxm.sys.test.points_4_3dgraph.csv^{quals}|{LT="Drawable",name="FEATGROUP"} view=3d

      ! now add a bazillion features to the plot
      call addFeatures

      gcontrol button addFeat        "Add 10 Features    " "Add"     "" /TLeft

    pipe off

  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

  elseif msg.name eqs "ADDFEAT" then
    if msg.data eqs "ADD" then
      call addMoreFeats
    else
      call remFeats
    endif

  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

!******************************************************************************!
! Make a some features and add them to the plot
!******************************************************************************!
procedure addFeatures

  ! initial values for the feature
  set featX first_feat
  set featY first_feat
  set featZ first_feat

  ! create variables to easily access LayerDrawables Layers
  set layFeats reg.plot1.layers.featGroup

  ! Add 100 features to the feature group layerDrawable
  do featNum 1 20
    feature label=f_^{featNum} table={NAME="FEAT_^{FEATNUM}",LAYER=layFeats,TYPE="CIRC",X=featX,Y=featY,Z=featZ,DX=2,COLOR="RED"} plot=plot1

    calc featX featX 1 +
    calc featY featY 1 +
    calc featZ featZ 1 +
  enddo

return


!******************************************************************************!
! Make a few (10) more features and add them to the plot
!******************************************************************************!
procedure addMoreFeats

  do addSome 1 10 1
    calc L:featNum featNum 1 +
    feature label=f_^{featNum} table={NAME="FEAT_^{FEATNUM}",LAYER=layFeats,TYPE="CIRC",X=featX,Y=featY,z=featZ,DX=1,COLOR="YELLOW"} plot=plot1
    calc featX featX 1 +
    calc featY featY 1 +
    calc featZ featZ 1 +
  enddo

return