Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/approx_xsec_cur.pro'
;+
; NAME:
; Approx_Xsec_Cur
; PURPOSE:
; Process cursor events of draw widget in Approx_Xsecs widget.
; Left button = insert a point into approximate cross-section,
; right button = delete nearest point.
; Called by pro Approx_Xsecs_Ev (in file approx_xsecs.pro).
; CALLING:
; Approx_Xsec_Cur, event, state
; INPUTS:
; event = structure variable defining the widget event.
; state = structure variable, state of the widget.
; OUTPUTS:
; state = new state of the widget.
; EXTERNAL CALLS:
; function Level_info
; PROCEDURE:
; Check the draw event.type in case statement:
; 0 = insert/delete a point (when a button is pressed),
; Left button = insert,
; Middle button = delete nearest point.
; 1 = freeze the List widget (when a button is released).
; 2 = display cursor coordinates (motion events).
; HISTORY:
; Written: Frank Varosi NASA/GSFC 1995.
;-
pro Approx_Xsec_Cur, event, state
cursor, xc, yc,/DATA,/NOWAIT
CASE event.type OF
0: BEGIN
Handle_value, state.ELevel, ELevel,/NO_COPY
if (ELevel.npx GT 0) AND $
Handle_info( ELevel.freq_approx ) then begin
Handle_value, ELevel.freq_approx, freq,/NO_COPY
Handle_value, ELevel.xsec_approx, xsec,/NO_COPY
CASE event.press OF
1: BEGIN ;insert a point.
freq = [freq,xc]
xsec = [xsec,yc]
sf = sort( freq )
freq = freq(sf)
xsec = xsec(sf)
ELevel.npx = N_elements( xsec )
END
2: BEGIN ;delete nearest point.
df = (freq-xc)/(!X.crange(1)-!X.crange(0))
ds = (xsec-yc)/(!Y.crange(1)-!Y.crange(0))
if min( sqrt( df^2+ds^2 ),im ) LT 0.1 then begin
ix = indgen( N_elements( xsec ) )
ix(im) = -1
w = where( ix GE 0, npx )
if (npx GT 0) then begin
freq = freq(ix(w))
xsec = xsec(ix(w))
endif
ELevel.npx = npx
endif
END
else:
ENDCASE
Handle_value, ELevel.freq_approx, freq,/NO_COPY,/SET
Handle_value, ELevel.xsec_approx, xsec,/NO_COPY,/SET
if (ELevel.npx LE 0) then begin
Handle_free, ELevel.freq_approx
Handle_free, ELevel.xsec_approx
ELevel.freq_approx = 0
ELevel.xsec_approx = 0
endif
endif else if (event.press EQ 1) then begin
ELevel.freq_approx = Handle_create( VAL=xc,/NO_COPY )
ELevel.xsec_approx = Handle_create( VAL=yc,/NO_COPY )
ELevel.npx = 1
endif
ELevel.disp = 1 ;indicates change to pro Build_BFree_Tr.
state.modified = 1
wset, state.window
Levid = Level_info( ELevel )
Plot_Xsec, ELevel, TITLE=Levid
Widget_Control, state.info_wid, SET_VAL="Selected: " + Levid
Handle_value, state.ELevel, ELevel,/NO_COPY,/SET
END
1: Widget_Control, state.List_wid, SENS=0
2: Widget_Control, state.cursor_wid, SET_VAL="Freq =" + $
string( xc,F="(F7.3)" ) + $
" Sigma =" + string( yc,F="(F7.3)" )
else:
ENDCASE
end