!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! *** JP This factorization has some flaws in the sense that the ctrl on
! *** JP actions depends on the position of the spectra on the plot page.
! *** JP not on the kind of spectrum action that the user would like.
! *** JP The best way out is unclear
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure l-view-ctrl-spectrum-zoom
  say "Select range lower limit"
  greg1\draw relo
  let view%z%first use_curs[1]
  @ q-view-plot-spectrum-draw-vertical-line-at 'view%z%first'
  say "Set range upper limit"
  greg1\draw relo
  let view%z%last use_curs[1]
  @ q-view-plot-spectrum-draw-vertical-line-at 'view%z%last'
  sic wait 1
  ! Sanity check
  if (view%z%first.eq.view%z%last) then
     message w view "Zero sized range => Not executed"
     return
  endif
  ! Apply
  set\spectral /range 'view%z%first' 'view%z%last' ! *** JP Unit to be dealt with
  @ q-view-topology2view
  let view%compute%area yes
end procedure l-view-ctrl-spectrum-zoom
!
begin procedure l-view-ctrl-spectrum-unzoom
  set\spectral /range * *
  @ q-view-topology2view
  let view%compute%area yes
end procedure l-view-ctrl-spectrum-unzoom
!
begin procedure l-view-ctrl-spectrum-previous
  ! *** JP we could introduce a way to avoid replotting everything.
  let view%z%position view%z%position-topology%z%step
end procedure l-view-ctrl-spectrum-previous
!
begin procedure l-view-ctrl-spectrum-next
  ! *** JP we could introduce a way to avoid replotting everything.
  let view%z%position view%z%position+topology%z%step
end procedure l-view-ctrl-spectrum-next
!
begin procedure l-view-ctrl-spectrum-select-window
  greg1\draw relo * *
  let view%z%window[1] use_curs[1]
  say "Set upper limit"
  greg1\draw relo
  let view%z%window[2] use_curs[1]
  @ q-view-z-window2channel
  let view%compute%area yes
end procedure l-view-ctrl-spectrum-select-window
!
begin procedure l-view-ctrl-spectrum-select-scale
  greg1\draw relo * *
  let view%scale[1] use_curs[2]
  @ l-draw-horizontal-line-at 'view%scale[1]'
  say "Set Y axis upper limit"
  greg1\draw relo
  let view%scale[2] use_curs[2]
  @ l-draw-horizontal-line-at 'view%scale[2]'
end procedure l-view-ctrl-spectrum-select-scale
!
begin procedure l-view-ctrl-spectrum-full-scale
  let view%scale 0
  @ q-view-topology2view
end procedure l-view-ctrl-spectrum-full-scale
!
begin procedure l-view-ctrl-spectrum-select-channel
  greg1\draw relo * *
  let view%z%position use_curs[1]
end procedure l-view-ctrl-spectrum-select-channel
!
begin procedure l-view-ctrl-spectrum-loop
  if (cursor_code.eq."A") then
!     let view%panel%ispe1 mod(view%panel%ispe1,2)+1
  else if (cursor_code.eq."C") then
!     let view%panel%ispe2 mod(view%panel%ispe2,3)+1
  else if (cursor_code.eq."Z") then
     @ l-view-ctrl-spectrum-zoom
  else if (cursor_code.eq."U") then
     @ l-view-ctrl-spectrum-unzoom
  else if (cursor_code.eq."N") then
     @ l-view-ctrl-spectrum-next
  else if (cursor_code.eq."P") then
     @ l-view-ctrl-spectrum-previous
  else if (cursor_code.eq."R") then ! Left click!
     if (ctrlmast%pan%icurr.eq.view%panel%imean)
        @ l-view-ctrl-spectrum-select-window
     else
        @ l-view-ctrl-spectrum-select-channel
     endif
  else if (ctrlmast%pan%icurr.eq.view%panel%ispec) then
     if (cursor_code.eq."*") then
        @ l-view-ctrl-spectrum-select-scale
     else if (cursor_code.eq."B") then
        @ l-view-ctrl-spectrum-full-scale
     endif
  endif
end procedure l-view-ctrl-spectrum-loop
!
begin procedure l-view-ctrl-spectrum-help
  say "   Cursor on spectra:"
  say "      Left  click in Integrated Spectrum: Define velocity range"
  say "      Left  click in Selected   Spectrum: Display selected velocity channel"
  say "      Right click in Selected   Spectrum: Select a brightness scale"
  say "      Press B key in Selected  Spectrum: BACK to full brightness scale"
  say "      Press A key: COORDINATES toggled from absolute to relative and back"
  say "      Press C key: COORDINATES cycled between velocity, frequency, and channels"
  say "      Press Z key:   ZOOM to the defined velocity region"
  say "      Press U key: UNZOOM to the full velocity range"
end procedure l-view-ctrl-spectrum-help
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
