;+ ; NAME: ; cw_tplat ; PURPOSE: (one line) ; Create a photometry template widget. ; DESCRIPTION: ; This compound widget is invoked on a Top Level Base (from The Template ; Manager) and represents an individual template. ; Each template managed by The Template Manager has its own TLB and ; appears as a separate widget. ; The template structure for each template is stored in the user-value of ; its TLB. ; CATEGORY: ; Compound Widgets ; CALLING SEQUENCE: ; ; INPUTS: ; parent : ID of parent base. ; OPTIONAL INPUT PARAMETERS: ; ; KEYWORD PARAMETERS: ; UVALUE = Optional user-value. ; VALUE = The 'value' of the widget. Defined to be the template structure. ; This value may be obtained, or set, by using the widget_control ; procedure with its appropriate keywords. The value structure is: ; {numobj:0, mode:0B, modified:0B, new:[1B], $ ; objnam:[''], x:[0.0], y:[0.0] } ; OUTPUTS: ; ; COMMON BLOCKS: ; ; SIDE EFFECTS: ; ; RESTRICTIONS: ; ; PROCEDURE: ; ; MODIFICATION HISTORY: ; Written by Doug Loucks, Lowell Observatory, June 24, 1994. Adapted from ; a previous section of code in the main template manager procedure. ; 96/01/16 - MWB, fixed bug that crashed template manager after deleting ; objects from template. ;- ; ------------------------------------------------------------------------------ ; Function cw_tplat_fmt ; Format the object names and coordinates for the list widget. ; ------------------------------------------------------------------------------ function cw_tplat_fmt, tplate if tplate.numobj gt 0 then begin ;Return the formatted object list. return, string( indgen( tplate.numobj ), format='(I3)' ) + $ string( tplate.objnam, format='(A20)' ) + $ string( tplate.x, format='(F10.3)' ) + $ string( tplate.y, format='(F10.3)' ) endif else begin ;Return a null string. return, '' endelse end ; ------------------------------------------------------------------------------ ; Function cw_tplat_gvl ; Get_value function. ; ------------------------------------------------------------------------------ function cw_tplat_gvl, id stash = widget_info( id, /child ) widget_control, stash, get_uvalue=state, /no_copy widget_control, state.tplateid, get_uvalue=tplate widget_control, stash, set_uvalue=state, /no_copy return, tplate end ; ------------------------------------------------------------------------------ ; Procedure cw_tplat_svl ; Set_value procedure. ; ------------------------------------------------------------------------------ pro cw_tplat_svl, id, tplate stash = widget_info( id, /child ) widget_control, stash, get_uvalue=state, /no_copy widget_control, state.tplateid, set_uvalue=tplate if tplate.numobj gt 0 then begin widget_control, state.objlistid, set_value=cw_tplat_fmt(tplate) endif else begin widget_control, state.objlistid, set_value='' endelse widget_control, state.editid, set_value='' widget_control, stash, set_uvalue=state, /no_copy end ; ------------------------------------------------------------------------------ ; Function cw_tplat_eve ; Event Handler. ; ------------------------------------------------------------------------------ function cw_tplat_eve, event widget_control,event.id,/hourglass bel = string(7B) stash = widget_info(event.handler,/child) widget_control,stash,get_uvalue=state,/no_copy out_event = 0 case event.id of state.delobjid : begin if state.selected ge 1 then begin ;Access the selected template. widget_control, state.tplateid, get_uvalue=tplate, /no_copy con = qannounc( ['Delete selected object?'], $ title='Delete Object Confirmation', xsize=40, $ true='Yes, continue', false='No, cancel request' ) if con then begin ;Delete the object: ;Set the objnam to the null string as a flag for the WHERE. This ;is the ideal sentinal, because the object names are not allowed ;to be null (null entries are stored as ''). tplate.objnam[state.selected] = '' keep = where( tplate.objnam ne '', count ) if count ne 0 then begin ;There are objects to be kept. Extract them. numobj = count mode = tplate.mode modified = tplate.modified new = tplate.new[keep] objnam = tplate.objnam[keep] x = tplate.x[keep] y = tplate.y[keep] ;Re-build the template structure. tplate = {numobj:numobj, mode:mode, modified:modified, $ new:new, objnam:objnam, x:x, y:y } endif else begin ;There was only one object. Make it a skeleton. tplate.numobj = 0 tplate.mode = 0B tplate.modified = 0B tplate.objnam = [''] tplate.new = [0B] tplate.x = [0.0] tplate.y = [0.0] endelse ;Refresh the object list widget. state.selected = -1 widget_control, state.objlistid, set_value=cw_tplat_fmt(tplate), $ set_list_select=state.selected out_event=event endif widget_control, state.tplateid, set_uvalue=tplate, /no_copy endif end state.editid : begin widget_control, state.tplateid, get_uvalue=tplate, /no_copy if state.selected ge 0 then begin widget_control,event.id,get_value=tobjnam objnam = strtrim(tobjnam[0],2) if objnam eq '' then objnam='' tplate.objnam[state.selected] = objnam widget_control, state.objlistid, set_value=cw_tplat_fmt(tplate), $ set_list_select=state.selected tplate.modified = 1 endif else begin widget_control, state.editid, set_value='' endelse widget_control, state.tplateid, set_uvalue=tplate, /no_copy end state.modeid : begin widget_control, state.tplateid, get_uvalue=tplate, /no_copy tplate.mode = event.value widget_control, state.tplateid, set_uvalue=tplate, /no_copy ;TBD out_event=event end state.objlistid : begin widget_control, state.tplateid, get_uvalue=tplate, /no_copy state.selected = event.index objnam = tplate.objnam[event.index] if objnam eq '' then objnam='' widget_control, state.editid, set_value=objnam widget_control, state.tplateid, set_uvalue=tplate, /no_copy end state.purgid : begin widget_control, state.tplateid, get_uvalue=tplate if tplate.numobj gt 0 then begin answer = qannounc('Purge the objects in this template?', $ truelabel='Yes, continue',xsize=40) if answer ne 0 then begin ;Yes, purge the template. tplate = {numobj:0, mode:0B, modified:0B, new:[0B], $ objnam:[''], x:[0.0], y:[0.0] } widget_control,state.objlistid,set_value='' widget_control,state.editid,set_value='' state.selected = -1 endif out_event=event endif widget_control, state.tplateid, set_uvalue=tplate end else : begin ;Unknown event. message, 'Unknown event:', /info help, event, /structure end endcase widget_control, stash, set_uvalue=state, /no_copy return, out_event end ; ------------------------------------------------------------------------------ ; Function cw_tplat ; Create a template widget. ; The template, itself, is a structure, stored internally. It may be 'put' ; or 'retrieved' through the widget_control keywords set_value and get_value. ; ------------------------------------------------------------------------------ function cw_tplat, parent, UVALUE=uvalue, VALUE=value ;Note: The 'value' of this compound widget is a structure which represents ;the template. It has the following format: ; tplate = {numobj:0, mode:0B, modified:0B, new:[0B], $ ; objnam:[''], x:[0.0], y:[0.0] } state = { $ debugid:0L, $ delobjid:0L, $ editid:0L, $ initialid:0L, $ modeid:0L, $ objlistid:0L, $ purgid:0L, $ selected:-1, $ tplateid:0L $ } if keyword_set(uvalue) then begin mainbase = widget_base(parent,column=1,event_func='cw_tplat_eve', $ func_get_value='cw_tplat_gvl',pro_set_value='cw_tplat_svl', $ uvalue=uvalue) endif else begin mainbase = widget_base(parent,column=1,event_func='cw_tplat_eve', $ func_get_value='cw_tplat_gvl',pro_set_value='cw_tplat_svl') endelse if keyword_set(value) then begin ;Force the template structure to be the incoming value. tplate = value endif else begin ;Create a skeleton template structure. tplate = {numobj:0, mode:0B, modified:0B, new:[0B], $ objnam:[''], x:[0.0], y:[0.0] } endelse if tplate.numobj gt 0 then tplate.mode=1B wb = widget_base(mainbase,row=1) state.modeid = cw_bgroup(wb,['Add','Active'],/exclusive,frame=1, $ /no_release,row=1,set_value=tplate.mode) state.delobjid = widget_button(wb,value='Delete Object') state.purgid = widget_button(wb,value='Purge Objects') ;This is where the template structure is stored. state.tplateid = state.purgid if tplate.numobj gt 0 then begin state.objlistid = widget_list(mainbase,value=cw_tplat_fmt(tplate),ysize=5) endif else begin state.objlistid = widget_list(mainbase,ysize=5) endelse state.editid = cw_field(mainbase,title='Change name of selected object:',/return_events) widget_control, state.tplateid, set_uvalue=tplate, /no_copy stash = widget_info(mainbase,/child) widget_control,stash,set_uvalue=state,/no_copy return,mainbase end