clive_cook59@hotmail.com wrote:
> Ben Tupper wrote:
>
>> Clive Cook wrote:
>>
>>> Hi,
>>>
>>> I am trying to write a widget program were buy passing the cursor
>
> over a
>
>>> contour plot a varying 2d plot changes according to the value where
>
> the
>
>>> cursor lies. I have a contour window with two boxes below that
>
> display the
>
>>> corresponding x and y values from the cursor location. So, i want
>
> to take
>
>>> the x value to produce a corresponding plot of the contour values
>
> against
>
>>> the y value.
>>>
>>> How do i take the x value and use that to generate a new plot?
>>>
>>
>> Hi,
>>
>> I'm not sure I completely understand what your needs are. In
>
> general, you can
>
>> transform your mouse location into data space location using
>
> CONVERT_COORD.
>
>> From there you have to have some way of 'getting' the interpolated
>
> values of
>
>> your contour for that location. You can use the well known
>
> Fanningistic
>
>> approach to storing valuable program info in the the top level base's
>
> UVALUE
>
>> property.
>>
>> Is that close?
>>
>> Ben
>>
>> ***START***
>> MyDrawEvent, ev
>>
>> ;get your valuable info
>> Widget_Control, ev.top, GET_UVALUE = info, /NO_COPY
>> ;set the current device state to match the draw widget's
>> Widget_Control, ev.ID, GET_VALUE = winNum
>> Wset, winNum
>>
>> ;convert from cursor coords to data coords
>> xy = CONVERT_COORD(ev.x, ev.y, /DEVICE, /TO_DATA)
>>
>> ;pass your favorite routine to 'get' you contour data
>> theseContourValues = GetMyContourValues(info.ContourData, xy)
>>
>> ;set the current window to you other window for plotting
>> Widget_Control, info.myOtherDrawWidget, GET_VALUE = myOtherWinNum
>> Wset, myOtherWindowNumber
>> ;plot 'contour values against the y value.'
>> Plot, XY[1], theseContourValues
>>
>> ;put your valuable info back in a safe place
>> Widget_Control, ev.top, SET_UVALUE = info, /NO_COPY
>>
>> End ;myDrawEvent
>>
>>
>> ****FINI***
>
>
> Hi Ben,
>
> Thanks for the advice. My problem now is that i seem to have problems
> locating the value of my draw widget (the 2d line plot window)so that
> i can
> set that as the active window. When i configure my widget base i draw 1
> large widget and then thecontour window in the top left in a new widget
> base, followed by a second draw widget to the left in a new widget base
> (contains the 2d line plot), followed my a widget below containing test
> boxes that display the values of the data at the points of the cursor.
> I am
> getting confused as to how to obtain the values of my various draw
> widgets,
> any help would be useful.
>
> I have tried using Dave Fannings methods but i am a little confused
> with
> this.
>
Hi,
You just have to maintain access to the window numbers you want use.
You can keep this info in the UVALUE property of the top level widget.
Here's an example...
**START**
;-----
; event
;-----
PRO WheresMyWidgetEvent, ev
;get the stuff out of the bucket
WIDGET_CONTROL, ev.top, GET_UVALUE = myStuff, /NO_COPY
;first copy the 'original data' to the image display
;then draw a line across at the cursor location
Widget_Control, myStuff.draw0_ID, Get_Value = win0
WSET, win0
DEVICE, COPY = [0,0,myStuff.sz[0],myStuff.sz[1], 0,0, myStuff.pix0]
PLOTS, [0, myStuff.Sz[0]], [ev.Y, ev.Y], /DEVICE
;now copy the 'baseline' chart to the chart display
;then plot the image values across
;
;**** NOTE **** we only know where to draw this because
;we saved a reference to the widget in the bucket
Widget_Control, myStuff.draw1_ID, Get_Value = win1
WSET, win1
DEVICE, COPY = [0,0,myStuff.sz[0],myStuff.sz[1], 0,0, myStuff.pix1]
OPLOT, LINDGEN(myStuff.Sz[0]), myStuff.image[*,ev.y]
;put you important things back in the bucket
WIDGET_CONTROL, ev.top, SET_UVALUE = myStuff, /NO_COPY
END
;------
; main
;------
PRO WheresMyWidget
;make a base widget with 2 draw widgets, one forand image and one for
;a plot... only the widget withg the image will generate events
tlb = widget_base(column = 2)
sz = [200,200]
draw0_ID = widget_draw(tlb, $
MOTION_EVENTS = 1, $
XSIZE = sz[0], YSIZE = sz[1], $
EVENT_PRO = 'WheresMyWidgetEvent')
draw1_ID = widget_draw(tlb,$
XSIZE = sz[0], YSIZE = sz[1])
;pop the widget up
WIDGET_CONTROL, tlb, /Realize
;set the image widget up for drawing
;show the image
;and make the 'refresh' copy on the pixmap
Widget_Control, draw0_ID, Get_Value = win0
WSET, win0
image = DIST(sz)
TV, BYTSCL(Image)
;make a pixmap window for each widget -
;these are used to 'refresh' the widgets
;before we draw on them
WINDOW, xsize = sz[0], ysize = sz[1], /PIXMAP,/FREE
pix0 = !D.window
WSET, pix0
DEVICE, COPY = [0,0,sz[0],sz[1], 0,0, win0]
;set the chart widget up for drawing
;show the chart (without any data yet)
;and make the 'refresh' copy on the pixmap
Widget_Control, draw1_ID, Get_Value = win1
WSET, win1
PLOT, [0,Sz[0]], [0,MAX(image)], $
XTITLE = 'Image Column', $
YTITLE = 'Image Value', $
/NODATA
WINDOW, xsize = sz[0], ysize = sz[1], /PIXMAP, /FREE
pix1= !D.window
WSET, pix1
DEVICE, COPY = [0,0,sz[0],sz[1], 0,0, win1]
;gather your things to put in the TLB's bucket
;and store them
myStuff = $
{Draw0_ID: draw0_ID, $
Draw1_ID: draw1_ID, $
Pix0: pix0, $
Pix1: pix1, $
SZ: sz, $
Image: Image}
WIDGET_CONTROL, tlb, SET_UVALUE = myStuff, /NO_COPY
XMANAGER, 'wheresmywidget', tlb
END
**FINI***
|