;$Id: d_livetool.pro,v 1.17 2001/01/15 22:26:38 scottm Exp $ ; ; Copyright (c) 1997-2001, Research Systems, Inc. All rights reserved. ; Unauthorized reproduction prohibited. ; ;+ ; FILE: ; d_livetool.pro ; ; CALLING SEQUENCE: d_livetool ; ; PURPOSE: ; This demo shows the various plots in IDL made from 2-D data. ; ; MAJOR TOPICS: Data analysis and plotting ; ; CATEGORY: ; IDL Demo System ; ; INTERNAL FUNCTIONS and PROCEDURES: ; pro d_livetoolEvent - Event handler ; pro d_livetoolCleanup - Cleanup ; pro d_livetool - Main procedure ; ; EXTERNAL FUNCTIONS, PROCEDURES, and FILES: ; livetool.tip ; pro demo_gettips - Read the tip file and create widgets ; ; REFERENCE: IDL Reference Guide, IDL User's Guide ; ; NAMED STRUCTURES: ; none. ; ; COMMON BLOCS: ; none. ; ; MODIFICATION HISTORY: ; 98, ACY - Written. ;- ; ----------------------------------------------------------------------------- ; ; pro d_livetoolLoad, sState CASE sState.currentVizIndex of 0: begin ; plot demo_getdata, y, /ONE, GROUP=sState.wTopBase if n_elements(y) GT 0 then begin WIDGET_CONTROL, /HOURGLASS live_control, y, /UPDATE_DATA, $ WINDOW_IN=(*(sState.pLiveRef)).win end end 1: begin ; image demo_getdata, image, /TWO, GROUP=sState.wTopBase if n_elements(image) GT 0 then begin WIDGET_CONTROL, /HOURGLASS live_control, image, /UPDATE_DATA, $ WINDOW_IN=(*(sState.pLiveRef)).win end end 2: begin ; surface demo_getdata, z, /TWO, GROUP=sState.wTopBase if n_elements(z) GT 0 then begin WIDGET_CONTROL, /HOURGLASS live_control, z, /UPDATE_DATA, $ WINDOW_IN=(*(sState.pLiveRef)).win end end 3: begin ; contour demo_getdata, z, /TWO, GROUP=sState.wTopBase if n_elements(z) GT 0 then begin WIDGET_CONTROL, /HOURGLASS live_control, z, /UPDATE_DATA, $ WINDOW_IN=(*(sState.pLiveRef)).win end end ENDCASE end ; ----------------------------------------------------------------------------- ; ; pro d_livetoolCreateViz, sState, index win = (*(sState.pLiveRef)).win LIVE_DESTROY, (*(sState.pLiveRef)).vis, WINDOW_IN=win CASE index of 0: LIVE_PLOT, $ *(sState.pDataArr[index]), $ WINDOW_IN=win, $ REFERENCE_OUT=*(sState.pLiveRef), $ NAME={DATA:'Y'} 1: LIVE_IMAGE, $ *(sState.pDataArr[index]), $ WINDOW_IN=win, $ REFERENCE_OUT=*(sState.pLiveRef), $ NAME={DATA:'IMAGE'} 2: begin LIVE_SURFACE, $ *(sState.pDataArr[index]), $ STYLE=sState.oLiveSurfStyle, $ WINDOW_IN=win, $ REFERENCE_OUT=*(sState.pLiveRef), $ NAME={DATA:'Z'}, $ /NO_DRAW LIVE_CONTROL, $ (*(sState.pLiveRef)).zaxis, $ PROPERTIES={ $ location:[ $ 0, $ (SIZE(*(sState.pDataArr[index])))[1] - 1 $ ], $ axistitle:'' $ }, $ WINDOW_IN=(*(sState.pLiveRef)).win end 3: LIVE_CONTOUR, $ *(sState.pDataArr[index]), $ STYLE=LIVE_STYLE( $ 'CONTOUR', $ GRAPHIC_PROPERTIES={n_levels: 12} $ ), $ WINDOW_IN=win, $ REFERENCE_OUT=*(sState.pLiveRef), $ NAME={DATA:'Z'}, $ /MANAGE_STYLE ENDCASE end ; ----------------------------------------------------------------------------- ; ; pro d_livetoolInitialData, pDataArr ; data for plot y=bytarr(512) openr, lun, /get, demo_filepath('chirp.dat', $ SUBDIR=['examples','data']) readu, lun, y free_lun, lun *(pDataArr[0]) = y ; data for image read_jpeg, demo_filepath('pollens.jpg', $ SUBDIR=['examples','demo', 'demodata']), $ image, colortable *(pDataArr[1]) = image ; data for surface z = BYTARR(64,64, /NOZERO) OPENR, lun, demo_filepath('elevbin.dat', $ SUBDIR=['examples','data']), $ /GET_LUN READU, lun, z FREE_LUN, lun *(pDataArr[2]) = SMOOTH(z, 3, /EDGE_TRUNCATE) ; use same data for contour ;restore, demo_filepath('marbells.dat', $ ; subdir=['examples','data']) ;z = BYTSCL(elev,MIN=2658,MAX=4241) *(pDataArr[3]) = z end ; ; Purpose: Event handler ; pro d_livetoolEvent, $ sEvent ; IN: event structure ; Quit the application using the close box. ; if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $ 'WIDGET_KILL_REQUEST') then begin ; Must destroy win before destroying widget WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY if N_ELEMENTS(*(sState.pLiveRef)) gt 0 then $ LIVE_DESTROY, WINDOW_IN=(*(sState.pLiveRef)).win WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY WIDGET_CONTROL, sEvent.top, /DESTROY RETURN endif ; Get the info structure from top-level base. ; WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY ; Determine which event. ; WIDGET_CONTROL, sEvent.id, GET_UVALUE=eventval ; Take the following action based on the corresponding event. ; case eventval of "SELECT": begin d_livetoolCreateViz, sState, sEvent.value sState.currentVizIndex = sEvent.value WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY RETURN end "LOAD": begin WIDGET_CONTROL, /HOURGLASS d_livetoolLoad, sState WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY RETURN end "ABOUT": begin ; Display the information. ; topicNum = 3140 ;; livetools ONLINE_HELP, topicNum, /CONTEXT, $ book=demo_filepath("idl_demo.hlp", $ SUBDIR=['examples','demo','demohelp']), $ /FULL_PATH ; Restore the info structure ; WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY end "QUIT": begin ; Must destroy win before destroying widget if N_ELEMENTS(*(sState.pLiveRef)) gt 0 then $ LIVE_DESTROY, WINDOW_IN=(*(sState.pLiveRef)).win ; Restore the info structure before destroying event.top ; WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY ; Destroy widget hierarchy. ; WIDGET_CONTROL, sEvent.top, /DESTROY end ELSE : begin PRINT, 'Case Statement found no matches' ; Restore the info structure ; WIDGET_CONTROL, sEvent.top, Set_UValue=info, /No_Copy end endcase end ; of d_livetoolEvent ; ----------------------------------------------------------------------------- ; ; Purpose: Cleanup procedure ; pro d_livetoolCleanup, $ wTopBase ; IN: top level base associated with the cleanup ; Get the color table saved in the window's user value. ; WIDGET_CONTROL, wTopBase, GET_UVALUE=sState,/No_Copy ; Restore the previous color table. ; TVLCT, sState.colorTable ; Map the group leader base if it exists. ; if (WIDGET_INFO(sState.groupBase, /VALID_ID)) then $ WIDGET_CONTROL, sState.groupBase, /MAP $ else $ LIVE_DESTROY, /ENVIRONMENT, ERROR=void ; Clean up heap variables. ; for i=0,N_TAGS(sState)-1 do begin case SIZE(sState.(i), /TNAME) of 'POINTER': $ PTR_FREE, sState.(i) 'OBJREF': $ OBJ_DESTROY, sState.(i) else: endcase end end ; of CleanupTemplate ; ----------------------------------------------------------------------------- ; ; Purpose: Main procedure of the livetool demo ; pro d_livetool, $ GROUP=group, $ ; IN: (opt) group identifier RECORD_TO_FILENAME=record_to_filename, $ APPTLB = appTLB ; OUT: (opt) TLB of this application ; Check the validity of the group identifier ; ngroup = N_ELEMENTS(group) if (ngroup NE 0) then begin check = WIDGET_INFO(group, /VALID_ID) if (check NE 1) then begin print,'Error, the group identifier is not valid' print, 'Return to the main application' RETURN endif groupBase = group endif else groupBase = 0L ; Get the screen size. ; Device, GET_SCREEN_SIZE = screenSize ; Set up dimensions of the drawing (viewing) area. ; xdim = screenSize[0]*0.6 ydim = xdim*0.8 ; Make the system have a maximum of 256 colors ; numcolors = !d.N_COLORS if( (( !D.NAME EQ 'X') or (!D.NAME EQ 'MAC')) $ and (!d.N_COLORS GE 256L)) then $ DEVICE, PSEUDO_COLOR=8 DEVICE, DECOMPOSED=0, BYPASS_TRANSLATION=0 ; Get the current color table ; TVLCT, savedR, savedG, savedB, /GET ; Build color table from color vectors ; colorTable = [[savedR],[savedG],[savedB]] ; Create the starting up message. ; ;if (ngroup EQ 0) then begin ; drawbase = demo_startmes() ;endif else begin ; drawbase = demo_startmes(GROUP=group) ;endelse ; Define a main widget base. ; if (N_ELEMENTS(group) EQ 0) then begin wTopBase = WIDGET_BASE(TITLE="LIVE TOOLS", /COLUMN, $ /TLB_KILL_REQUEST_EVENTS, $ MAP=0, $ TLB_FRAME_ATTR=1, MBAR=barBase) endif else begin wTopBase = WIDGET_BASE(TITLE="LIVE TOOLS", /COLUMN, $ /TLB_KILL_REQUEST_EVENTS, $ MAP=0, $ GROUP_LEADER=group, $ TLB_FRAME_ATTR=1, MBAR=barBase) endelse ; Create the quit button ; wFileButton = WIDGET_BUTTON(barBase, VALUE= 'File', /MENU) wQuitButton = WIDGET_BUTTON(wFileButton, $ VALUE='Quit', UVALUE='QUIT') ; Create the help button ; wHelpButton = WIDGET_BUTTON(barBase, /HELP, $ VALUE='About', /MENU) wAboutButton = WIDGET_BUTTON(wHelpButton, $ VALUE='About LIVE TOOLS', UVALUE='ABOUT') ; Create the first child of the top level base ; wTopRowBase = WIDGET_BASE(wTopBase, COLUMN=2, /FRAME) ; Create a base for the left column ; wLeftBase = WIDGET_BASE(wTopRowBase, $ /BASE_ALIGN_CENTER, /COLUMN) ; Create a droplist to select the the plot ; initialVizIndex = 2 wPlotDropList = CW_BGROUP(wLeftBase, /COLUMN, $ ['LIVE_PLOT', $ 'LIVE_IMAGE', $ 'LIVE_SURFACE', $ 'LIVE_CONTOUR'], $ /NO_RELEASE, $ /EXCLUSIVE, UVALUE='SELECT', SET_VALUE=initialVizIndex) ; Create the Load button that loads ; a new data set ; wLoadBase = WIDGET_BASE(wLeftBase, /COLUMN, $ YPAD=20) wLoadButton = WIDGET_BUTTON(wLoadBase, $ VALUE='Load New Data', UVALUE='LOAD') ; Create a base for the right column ; ; use bulletin board base here since adding numerous children wRightBase = WIDGET_BASE(wTopRowBase, /frame) pDataArr = PTRARR(4, /alloc) d_livetoolInitialData, pDataArr baseLive = widget_base(wRightBase) ; Create tips texts. ; wStatusBase = WIDGET_BASE(wTopBase, MAP=0, /ROW) ; Realize the widget hierarchy. ; WIDGET_CONTROL, wTopBase, /REALIZE ; Returns the top level base in the appTLB keyword. ; appTLB = wTopBase WIDGET_CONTROL, /HOURGLASS oLiveSurfStyle = LIVE_STYLE( $ 'SURFACE', $ GRAPHIC_PROPERTIES={use_triangles:1b}, $ XAXIS_PROPERTIES={exact:1b}, $ YAXIS_PROPERTIES={exact:1b}, $ ZAXIS_PROPERTIES={exact:1b} $ ) LIVE_SURFACE, *(pDataArr[initialVizIndex]), name={DATA:'Z'}, $ draw_dimensions=[xdim, ydim], $ parent=baseLive, $ REFERENCE_OUT=liveRef, $ STYLE=oLiveSurfStyle, $ /NO_DRAW LIVE_CONTROL, $ liveRef.zaxis, $ PROPERTIES={ $ location:[ $ 0, $ (SIZE(*(pDataArr[initialVizIndex])))[1] - 1 $ ], $ axistitle:'' $ }, $ WINDOW_IN=liveRef.win ; Get the tips ; sText = demo_getTips(demo_filepath('livetool.tip', $ SUBDIR=['examples','demo', 'demotext']), $ wTopBase, $ wStatusBase) ; Create the info structure ; sState={ colorTable: colorTable, $ ; color table to restore DrawXSize: xdim, $ ; Window dimension DrawYSize: ydim, $ WPlotDroplist: wPlotDroplist, $ ; Droplist ID WHelpButton: wHelpButton, $ ; Help button ID WQuitButton: wQuitButton, $ ; Quit button ID WFileButton: wFileButton, $ ; File button ID WTopBase: wTopBase, $ ; Top level base ID WLeftBase: wLeftBase, $ ; Left base ID WStatusBase: wStatusBase, $ ; Statusbase ID groupBase: groupBase, $ ; Base of Group Leader currentVizIndex: initialVizIndex, $ ; index of current vis pDataArr: pDataArr, $ ; pointers to data for viz baseLive: baseLive, $ ; Bases holding visualizations oLiveSurfStyle: oLiveSurfStyle, $ pLiveRef: PTR_NEW(liveRef, /no_copy) $; live tool reference } ; Register the info structure in the user value of the top-level base ; WIDGET_CONTROL, wTopBase, SET_UVALUE=sState, /NO_COPY ; Destroy the starting up window. ; ;WIDGET_CONTROL, drawbase, /DESTROY ; Map the top level base. ; ;widget_control, baseArr[initialVizIndex], /map WIDGET_CONTROL, wTopBase, MAP=1 XMANAGER, "d_livetool", wTopBase, $ /NO_BLOCK, $ EVENT_HANDLER="d_livetoolEvent", CLEANUP="d_livetoolCleanup" end ; main procedure