pro Graff_draw, pdefs, event, track_flag ;+ ; GRAFF_DRAW ; Process a draw event in draw mode ; ; Usage: ; graff_draw, pdefs, event ; ; Argument: ; pdefs struct in/out The plot definition structure. ; event struct input The draw event that triggered this ; track_flag byte input A flag to say if it's a tracking event. ; ; History: ; Carved from graffer: 17/8/95; SJT ; Modify to cope with function data (by ignoring it): 18/8/95; ; SJT ; Add tracking event handling: 5/12/95; SJT ;- handle_value, pdefs.data, data, /no_copy if (track_flag) then begin if (data(pdefs.cset).type eq 0) then graff_msg, pdefs.ids.hlptxt, $ 'Left = add point, Middle = move point, Right = delete point' handle_value, pdefs.data, data, /no_copy, /set return endif xy = convert_coord(event.x, event.y, /device, /to_data) handle_value, data(pdefs.cset).xydata, xydata, /no_copy if (data(pdefs.cset).type lt 0) then begin ; Function, can't manipulate it ; Re-save and exit handle_value, data(pdefs.cset).xydata, xydata, /no_copy, /set handle_value, pdefs.data, data, /no_copy, /set if (event.type ne 2) then graff_msg, pdefs.ids.message, $ "Can't manipulate function data" return end if (data(pdefs.cset).type ge 1) then begin ; Has errors, can't manipulate it ; Re-save and exit handle_value, data(pdefs.cset).xydata, xydata, /no_copy, /set handle_value, pdefs.data, data, /no_copy, /set if (event.type ne 2) then graff_msg, pdefs.ids.message, $ "Can't do cursor operations on error bar data" return end case event.type of 0: if (event.press eq 2) then begin ; Press event (only used for moves) if (data(pdefs.cset).ndata ge 1) then begin ddata = convert_coord(xydata, /data, /to_device) dist = sqrt((ddata(0, *)-event.x)^2 + $ (ddata(1, *)-event.y)^2) md = min(dist, imin) if (md lt 5) then pdefs.transient.imove = imin $ else graff_msg, pdefs.ids.message, $ "No datum within 5 pixels of selected location" endif end 1: begin ; Release event case event.release of 1: begin ; Left: add a point if (data(pdefs.cset).ndata le 1) then $ xydata(*, data(pdefs.cset).ndata) = xy(0:1) $ else xydata = [[xydata], [xy(0:1)]] data(pdefs.cset).ndata = data(pdefs.cset).ndata+1 end 2: if (data(pdefs.cset).ndata ne 0 and $ pdefs.transient.imove ne -1) then begin ; Centre: move one xydata(*, pdefs.transient.imove) = xy(0:1) pdefs.transient.imove = -1 end 4: if (data(pdefs.cset).ndata ne 0) then begin ; Right: delete. ddata = convert_coord(xydata, /data, /to_device) dist = sqrt((ddata(0, *)-event.x)^2 + $ (ddata(1, *)-event.y)^2) md = min(dist, imin) if (md lt 5) then begin if (data(pdefs.cset).ndata le 2) then begin if (imin eq 0) then xydata(*, 0) = xydata(*, 1) endif else if (imin eq 0) then $ xydata = xydata(*, 1:*) $ else if (imin eq data(pdefs.cset).ndata-1) then $ xydata = xydata(*, 0:imin-1) $ else xydata = [[xydata(*, 0:imin-1)], $ [xydata(*, imin+1:*)]] data(pdefs.cset).ndata = data(pdefs.cset).ndata-1 endif else graff_msg, pdefs.ids.message, $ "No datum within 5 pixels of selected location" end endcase end 2: begin ; Motion events idraw_flag = 0 device, set_graph = 10 if (pdefs.transient.opflag) then begin if (pdefs.xtype) then plots, 10.^!X.crange, $ replicate(pdefs.transient.opos(1), 2) $ else plots, !X.crange, replicate(pdefs.transient.opos(1), 2) if (pdefs.ytype) then plots, $ replicate(pdefs.transient.opos(0), 2), 10.^!Y.crange $ else plots, replicate(pdefs.transient.opos(0), 2), $ !Y.crange endif if (pdefs.xtype) then plots, 10.^!X.crange, $ replicate(xy(1), 2) $ else plots, !X.crange, replicate(xy(1), 2) if (pdefs.ytype) then plots, replicate(xy(0), 2), $ 10.^!Y.crange $ else plots, replicate(xy(0), 2), !Y.crange device, set_graph = 3 pdefs.transient.opos = xy(0:1) pdefs.transient.opflag = 1b widget_control, pdefs.ids.xcp, set_value = xy(0) widget_control, pdefs.ids.ycp, set_value = xy(1) end Else: ; Shouldn't be any scroll events endcase handle_value, data(pdefs.cset).xydata, xydata, /no_copy, /set handle_value, pdefs.data, data, /no_copy, /set end