!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure l-view-ctrl-image-zoom
  ! 1. Define zoom area
  define double tlc[2] brc[2]
  say "Select top, left corner"
  greg1\draw relo
  let tlc use_curs
  greg1\pencil 0 /col negative
  @ l-draw-vertical-line-at 'tlc[1]'
  @ l-draw-horizontal-line-at 'tlc[2]'
  greg1\pencil 0 /default
  say "Select bottom, right corner"
  greg1\draw relo
  let brc use_curs
  let view%x%first tlc[1]
  let view%x%last brc[1]
  let view%y%first brc[2]
  let view%y%last tlc[2]
  gtvl\clear segment
  gtvl\clear segment
  ! 2. Sanity check
  if ((view%x%first.eq.view%x%last).or.(view%y%first.eq.view%y%last)) then
     message w view "Zero sized range => Not executed"
     return
  endif
  ! 3. Compute new center, size and aspect
  let view%center[1] 0.5*(view%x%first+view%x%last)
  let view%center[2] 0.5*(view%y%first+view%y%last)
  let view%size[1] -(view%x%last-view%x%first) ! *** JP Specific to x spatial axis => not generic
  let view%size[2] view%y%last-view%y%first
  let view%aspect abs(view%size[1]/view%size[2])
  ! 4. Visualize zoom area
  greg1\pencil 0 /col negative
  gtvl\change directory "<greg<"'ctrlmast%pan%name[view%panel%ichan]'
  @ l-draw-rectangle-from view%x view%y
  gtvl\change directory  "<greg<"'ctrlmast%pan%name[view%panel%iarea]'
  @ l-draw-rectangle-from view%x view%y
  greg1\pencil 0 /default
  sic wait 1
  ! 5. Apply
  set\spatial /size 'view%size[1]' 'view%size[2]' radian /center 'view%center[1]' 'view%center[2]' relative radian
  @ q-view-topology2view
  let view%compute%mean yes
end procedure l-view-ctrl-image-zoom
!
begin procedure l-view-ctrl-image-unzoom
  set\spatial /size * * * /center * * rel * ! *** JP there is a bug. I can't replace rel by *
  @ q-view-topology2view
  let view%compute%mean yes
end procedure l-view-ctrl-image-unzoom
!
begin procedure l-view-ctrl-image-select-pixel
  greg1\draw relo * *
  let view%x%position use_curs[1]/sec
  let view%y%position use_curs[2]/sec
end procedure l-view-ctrl-image-select-pixel
!
begin procedure l-view-ctrl-image-define-polygon
  say "Define polygon"
  on error return
  greg2\polygon
  ! Save defined polygon
  if exist(view%poly%xy) then
     delete /var view%poly%xy
  endif
  define double view%poly%xy[poly%nxy,2] /global
  let view%poly%xy[1] poly%x
  let view%poly%xy[2] poly%y
  let view%compute%mean yes
end procedure l-view-ctrl-image-define-polygon
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure l-view-ctrl-image-loop
  if (cursor_code.eq."A") then
!     let view%panel%imap1 mod(view%panel%imap1,2)+1
  else if (cursor_code.eq."C") then
!     let view%panel%imap2 mod(view%panel%imap2,3)+1
  else if (cursor_code.eq."Z") then
     @ l-view-ctrl-image-zoom
  else if (cursor_code.eq."U") then
     @ l-view-ctrl-image-unzoom
  else if (cursor_code.eq."R") then ! Left  click!
     @ l-view-ctrl-image-select-pixel
  else if (cursor_code.eq."*") then ! Right click!
     @ l-view-ctrl-image-define-polygon
  endif
end procedure l-view-ctrl-image-loop
!
begin procedure l-view-ctrl-image-help
  say "   Cursor on images:"
  say "      Left  click: Display spectrum at pointed position"
  say "      Right click: Define a polygon"
  say "      Press A key: COORDINATES toggled from absolute to relative and back"
  say "      Press C key: COORDINATES cycled between units"
  say "      Press Z key:   ZOOM to the defined spatial region"
  say "      Press U key: UNZOOM to the full field of view"
end procedure l-view-ctrl-image-help
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
