;+ ; ; @file_comments ; ; @categories ; ; @param EVENT ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ; @todo ; seb ;- PRO xxxmenubar_event, event ; compile_opt idl2, strictarrsubs ; @common ; case event.value of 'Open' :begin oldmeshparams = ccmeshparameters newfile = selectfile() if size(newfile, /type) NE 8 then return widget_control, event.top, /hourglass widget_control, event.top, update = 0 widget_control, event.top, get_uvalue = top_uvalue ; We take care of filelist filelist = extractatt(top_uvalue, 'filelist') filelist = [filelist, newfile.fileparameters.filename] currentfile = n_elements(filelist)-1 ; We update the widget filelistid = widget_info(event.top, find_by_uname = 'filelist') widget_control, filelistid, combobox_additem = file_basename(newfile.fileparameters.filename) widget_control, filelistid, set_combobox_select = currentfile ; We update filelist and currentfile's elements of the top_value *top_uvalue[1, findline(top_uvalue, 'filelist')] = filelist oldfile = *top_uvalue[1, findline(top_uvalue, 'currentfile')] *top_uvalue[1, findline(top_uvalue, 'currentfile')] = currentfile ; We take care of the name of the variable vlstid = widget_info(event.top, find_by_uname = 'varlist') ; What is the selected field ? Do we reselect it ? fieldname = widget_info(vlstid, /combobox_gettext) index = where(newfile.fileparameters.listvar EQ fieldname) widget_control, vlstid, set_value = newfile.fileparameters.listvar widget_control, vlstid, set_combobox_select = 0 > index[0] ; We take care of the calendar. key_caltype = newfile.fileparameters.caltype date1id = widget_info(event.top, find_by_uname = 'calendar1') widget_control, date1id, get_value = date1 widget_control, date1id, /destroy jdate1 = jul2date(date1) if (where(newfile.fileparameters.time_counter EQ jdate1))[0] EQ -1 $ then jdate1 = newfile.fileparameters.time_counter[0] date2id = widget_info(event.top, find_by_uname = 'calendar2') widget_control, date2id, get_value = date2 widget_control, date2id, /destroy jdate2 = jul2date(date2) if (where(newfile.fileparameters.time_counter EQ jdate2))[0] EQ -1 then jdate2 = jdate1 basecal = widget_info(event.top, find_by_uname = 'basecal') fakecal = newfile.fileparameters.fakecal rien = cw_calendar(basecal, newfile.fileparameters.time_counter, jdate1, uname = 'calendar1' $ , FAKECAL = fakecal, uvalue = {name:'calendar1'}, /frame) rien = cw_calendar(basecal, newfile.fileparameters.time_counter, jdate2, uname = 'calendar2' $ , FAKECAL = fakecal, uvalue = {name:'calendar2'}, /frame) ; We update fileparameters, readparameters and meshparameters elements of the top_value newfileparameters = ptrarr(currentfile+1, /allocate_heap) FOR i = 0, currentfile-1 DO $ *newfileparameters[i] = *(extractatt(top_uvalue, 'fileparameters'))[i] *newfileparameters[currentfile] = newfile.fileparameters ptr_free, extractatt(top_uvalue, 'fileparameters') *top_uvalue[1, findline(top_uvalue, 'fileparameters')] = newfileparameters ; newreadparameters = ptrarr(currentfile+1, /allocate_heap) FOR i = 0, currentfile-1 DO $ *newreadparameters[i] = *(extractatt(top_uvalue, 'readparameters'))[i] *newreadparameters[currentfile] = newfile.readparameters ptr_free, extractatt(top_uvalue, 'readparameters') *top_uvalue[1, findline(top_uvalue, 'readparameters')] = newreadparameters ; newmeshparameters = ptrarr(currentfile+1, /allocate_heap) FOR i = 0, currentfile-1 DO $ *newmeshparameters[i] = *(extractatt(top_uvalue, 'meshparameters'))[i] *newmeshparameters[currentfile] = newfile.meshparameters ptr_free, extractatt(top_uvalue, 'meshparameters') *top_uvalue[1, findline(top_uvalue, 'meshparameters')] = newmeshparameters ; We update the widget! if cmpgrid(oldmeshparams) then BEGIN domainid = widget_info(event.top, find_by_uname = 'domain') widget_control, domainid, set_value = -1 endif widget_control, event.top, update = 1 end 'New xxx' :BEGIN widget_control, event.top, get_uvalue = top_uvalue extra = extractatt(top_uvalue, 'extra') xxx, CALLERWIDID = event.top, _extra = extra end 'Quit':begin widget_control, event.top, get_uvalue = top_uvalue ptr_free, extractatt(top_uvalue, 'exextra') ptr_free, extractatt(top_uvalue, 'fileparameters') ptr_free, extractatt(top_uvalue, 'readparameters') ptr_free, extractatt(top_uvalue, 'meshparameters') ptr_free, top_uvalue widget_control, event.top, /destroy ;We shut the widget end 'PostScript' :BEGIN IF lmgr(/demo) EQ 1 THEN BEGIN dummy = report('impossible to save as postscript in demo mode') return ENDIF widget_control, event.top, get_uvalue = top_uvalue ; We recuperate the list of instructions globalcommand = extractatt(top_uvalue, 'globalcommand') ; for i = 0, n_elements(globalcommand)-1 do print, globalcommand[i] ; We complete by first and last lines of the program. createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $ , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript' $ +', PORTRAIT = portrait, LANDSCAPE = landscape' $ +', DATE1IN = date1in, DATE2IN = date2in' $ , /POSTSCRIPT END 'Animated gif' :begin IF float(strmid(!version.release,0,3)) GE 6.2 THEN xcreateanim, event.top end 'Gif' :BEGIN IF lmgr(/demo) EQ 1 THEN BEGIN dummy = report('impossible to save as an image in demo mode') return ENDIF widget_control, event.top, get_uvalue = top_uvalue smallin = extractatt(top_uvalue, 'smallin') numdessinin = smallin[2]-1 smallout = extractatt(top_uvalue, 'smallout') numdessinout = smallout[2]-1 tracecadre, smallin, /erase tracecadre, smallout, /erase filename = xquestion('In which GIF file do you want to save xxx screen ?', 'xxx_image.gif') if rstrpos(filename, '.gif') NE strlen(filename)-4 then filename = filename+'.gif' filename = isafile(file = filename, io = imagedir, /new) saveimage, filename, /quiet end 'IDL procedure':BEGIN IF lmgr(/demo) EQ 1 THEN BEGIN dummy = report('impossible to save as a idl program file in demo mode') return ENDIF ; We recuperate the name of the file filename = xquestion('In which IDL file do you want to save commands for this graph ?', 'xxx_figure.pro') ; We complete it by a .pro if rstrpos(filename, '.pro') NE strlen(filename)-4 then filename = filename+'.pro' filename = isafile(file = filename, io = homedir, /new) widget_control, event.top, get_uvalue = top_uvalue ; portrait or landscape ??? options = extractatt(top_uvalue, 'options') optionsflag = extractatt(top_uvalue, 'optionsflag') portrait = (optionsflag[where(options EQ 'Portrait/Landscape'), 0])[0] ; We read commands to do a plot globalcommand = extractatt(top_uvalue, 'globalcommand') ; We complete by first and last lines of the program thisOS = strupcase(strmid(!version.os_family, 0, 3)) CASE thisOS of 'MAC':sep = ':' 'WIN':sep = '\' ELSE:sep = '/' ENDCASE poslastsep = rstrpos(filename, sep) proname = strmid(filename, poslastsep+1, strlen(filename)-poslastsep-1-4) globalcommand = ['pro '+proname+', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape, DATE1IN = date1in, DATE2IN = date2in, _extra = ex' $ , ' ' $ , ' '+globalcommand $ , ' ' $ , 'return' $ , 'end'] ; We write it in a program putfile, filename, globalcommand END 'RESTORE kwd of xxx':BEGIN IF lmgr(/demo) EQ 1 THEN BEGIN dummy = report('impossible to save the widget in demo mode') return ENDIF ; We recuperate the name of the file filename = xquestion('In which binary file do you want to save the widget ?', 'xxx_widget.dat') ; We complete it by a .dat if rstrpos(filename, '.dat') NE strlen(filename)-4 then filename = filename+'.dat' filename = isafile(file = filename, io = homedir, /new) ; widget_control, event.top, get_uvalue = uvalue widget_control, extractatt(uvalue, 'graphid'), get_value = win wshow, win wset, win image = tvrd(/true) save, uvalue, image, filename = filename END 'Print to prompt':BEGIN commande = getfile(myuniquetmpdir + 'xxx_oneplot.pro') for i = 0, n_elements(commande)-1 do print, commande[i] end 'Portrait/Landscape' :begin widget_control, event.top, get_uvalue = top_uvalue options = extractatt(top_uvalue, 'options') index = where(options EQ 'Portrait/Landscape') & index = index[0] optionsflag = extractatt(top_uvalue, 'optionsflag') key_portrait = 1-optionsflag[index, 0] (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, *] = key_portrait ; Separated windows or windows stuck to the widget? if widget_info(event.top, find_by_uname = 'graph') EQ 0 then BEGIN ; We delete the window graphid = extractatt(top_uvalue, 'graphid') widget_control, widget_info(graphid, /parent), /destroy ; We recreate it. basegraph = widget_base(title = 'xxx window', group_leader = event.top, uvalue = event.top, uname = 'basegraph') windsize = givewindowsize() graphid = widget_draw(basegraph, uname = 'graph' $ , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $ , /button_events, retain = 2 $ , xsize = windsize[0], ysize = windsize[1]) widget_control, basegraph, /realize xmanager, 'xxx', basegraph, /no_block ; We redraw what they were into it ; We recuperate the list of instructions globalcommand = extractatt(top_uvalue, 'globalcommand') ; We complete by first and last lines of the program createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $ , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape' $ , KWDUSED = ', /noerase, PORTRAIT = portrait' ; We reattribute the graphic element of the top_value *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid ENDIF ELSE BEGIN extra = extractatt(top_uvalue, 'extra') xxx, CALLERWIDID = event.top, /redraw, _extra = extra widget_control, event.top, /destroy ;We shut the widget ENDELSE end 'Overlay' :begin widget_control, event.top, get_uvalue = top_uvalue numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1 options = extractatt(top_uvalue, 'options') flags = extractatt(top_uvalue, 'optionsflag') index = where(options EQ 'Overlay') ; We change the flag on Longitude / x index flag = 1-flags[index, numdessinin] & flag = flag[0] ; We reattribute it (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag end 'Vecteur':BEGIN widget_control, event.top, get_uvalue = top_uvalue numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1 options = extractatt(top_uvalue, 'options') flags = extractatt(top_uvalue, 'optionsflag') index = where(options EQ 'Vecteur') ; We change the flag on Longitude / x index flag = 1-flags[index, numdessinin] & flag = flag[0] ; We reattribute it (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag end 'Longitude / x index':BEGIN widget_control, event.top, get_uvalue = top_uvalue numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1 options = extractatt(top_uvalue, 'options') flags = extractatt(top_uvalue, 'optionsflag') index = where(options EQ 'Longitude / x index') ; We change the flag on Longitude / x index flag = 1-flags[index, numdessinin] & flag = flag[0] ; We reattribute it (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag ; Now we will change sliders defining the boxzoom domainid = widget_info(event.top, find_by_uname = 'domain') boxzoom = (extractatt(top_uvalue, 'domaines'))[*, numdessinin] ; We want to find the type of grid which is used currentfile = extractatt(top_uvalue, 'currentfile') listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar vlstid = widget_info(event.top, find_by_uname = 'varlist') namevar = widget_info(vlstid, /combobox_gettext) indexvar = where(listvar EQ namevar) vargrid = strupcase(listgrid[indexvar]) if flag EQ 0 then BEGIN ; longitudes ; We do a domdef to find the lon1 lon2 corresponding to the boxzoom defined on the widget... domdef, boxzoom, gridtype = vargrid, /xindex $ , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0] widget_control, domainid, set_value = [lon1, lon2, boxzoom[2:3]] ENDIF ELSE BEGIN ; xindex ; now we want to find firstx, lastx corresponding to the boxzoom defined on the widget... domdef, boxzoom, gridtype = vargrid $ , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0] grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz widget_control, domainid, set_value = [firstx, lastx, boxzoom[2:3]] ENDELSE ; We update the top_uvalue widget_control, domainid, get_value = boxzoom (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boxzoom end 'Latitude / y index':begin widget_control, event.top, get_uvalue = top_uvalue numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1 options = extractatt(top_uvalue, 'options') flags = extractatt(top_uvalue, 'optionsflag') index = where(options EQ 'Latitude / y index') ; We change the flag on Latitude / y index flag = 1-flags[index, numdessinin] & flag = flag[0] ; We reattribute it (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag ; Now we will change sliders defining the boxzoom domainid = widget_info(event.top, find_by_uname = 'domain') boxzoom = (extractatt(top_uvalue, 'domaines'))[*, numdessinin] ; We want to find the type of grid which is used currentfile = extractatt(top_uvalue, 'currentfile') listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar vlstid = widget_info(event.top, find_by_uname = 'varlist') namevar = widget_info(vlstid, /combobox_gettext) indexvar = where(listvar EQ namevar) vargrid = strupcase(listgrid[indexvar]) if flag EQ 0 then BEGIN ; latitudes ; We do a domdef to find the lat1 lat2 corresponding to the boxzoom defined on the widget... domdef, boxzoom, gridtype = vargrid, /yindex $ , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0] widget_control, domainid, set_value = [boxzoom[0:1], lat1, lat2] ENDIF ELSE BEGIN ; yindex ; now we want to find firsty, lasty corresponding to the boxzoom defined on the widget... domdef, boxzoom, gridtype = vargrid $ , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0] grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz widget_control, domainid, set_value = [boxzoom[0:1], firsty, lasty] ENDELSE ; We update the top_uvalue widget_control, domainid, get_value = boxzoom (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boxzoom END endcase return end