source: trunk/SRC/ToBeReviewed/WIDGET/AUTOUR_de_XXX/xxxmenubar_event.pro @ 296

Last change on this file since 296 was 296, checked in by pinsard, 17 years ago

typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 16.0 KB
RevLine 
[150]1;+
[231]2;
[150]3; @file_comments
4;
5; @categories
6;
7; @param EVENT
8;
9; @returns
[226]10;
[150]11; @uses
[226]12;
[150]13; @restrictions
[226]14;
[150]15; @examples
[226]16;
[150]17; @history
[226]18;
19; @version
[150]20; $Id$
21;
[226]22; @todo
[150]23; seb
24;-
[231]25;
[2]26PRO xxxmenubar_event, event
[114]27;
28  compile_opt idl2, strictarrsubs
29;
[2]30@common
[267]31;
[69]32  case event.value of
[226]33    'Open' :begin
[69]34      oldmeshparams = ccmeshparameters
35      newfile = selectfile()
36      if size(newfile, /type) NE 8 then return
37      widget_control, event.top, /hourglass
38      widget_control, event.top, update = 0
39      widget_control, event.top, get_uvalue = top_uvalue
[150]40; We take care of filelist
[69]41      filelist = extractatt(top_uvalue, 'filelist')
42      filelist = [filelist, newfile.fileparameters.filename]
43      currentfile = n_elements(filelist)-1
[150]44; We update the widget
[69]45      filelistid = widget_info(event.top, find_by_uname = 'filelist')
46      widget_control, filelistid, combobox_additem = file_basename(newfile.fileparameters.filename)
47      widget_control, filelistid, set_combobox_select = currentfile
[150]48; We update filelist and currentfile's elements of the top_value
[69]49      *top_uvalue[1, findline(top_uvalue, 'filelist')] = filelist
50      oldfile = *top_uvalue[1, findline(top_uvalue, 'currentfile')]
51      *top_uvalue[1, findline(top_uvalue, 'currentfile')] = currentfile
[150]52; We take care of the name of the variable
[69]53      vlstid = widget_info(event.top, find_by_uname = 'varlist')
[150]54; What is the selected field ? Do we reselect it ?
[69]55      fieldname = widget_info(vlstid, /combobox_gettext)
[226]56      index = where(newfile.fileparameters.listvar EQ fieldname)
[69]57      widget_control, vlstid, set_value = newfile.fileparameters.listvar
58      widget_control, vlstid, set_combobox_select = 0 > index[0]
[150]59; We take care of the calendar.
[74]60      key_caltype = newfile.fileparameters.caltype
[69]61      date1id = widget_info(event.top, find_by_uname = 'calendar1')
62      widget_control, date1id, get_value = date1
63      widget_control, date1id, /destroy
[74]64      jdate1 = jul2date(date1)
65      if (where(newfile.fileparameters.time_counter EQ jdate1))[0] EQ -1 $
66      then jdate1 = newfile.fileparameters.time_counter[0]
[69]67      date2id = widget_info(event.top, find_by_uname = 'calendar2')
68      widget_control, date2id, get_value = date2
69      widget_control, date2id, /destroy
[74]70      jdate2 = jul2date(date2)
71      if (where(newfile.fileparameters.time_counter EQ jdate2))[0] EQ -1 then jdate2 = jdate1
[69]72      basecal = widget_info(event.top, find_by_uname = 'basecal')
[74]73      fakecal = newfile.fileparameters.fakecal
74      rien = cw_calendar(basecal, newfile.fileparameters.time_counter, jdate1, uname = 'calendar1' $
75                         , FAKECAL = fakecal, uvalue = {name:'calendar1'}, /frame)
76      rien = cw_calendar(basecal, newfile.fileparameters.time_counter, jdate2, uname = 'calendar2' $
77                         , FAKECAL = fakecal, uvalue = {name:'calendar2'}, /frame)
[296]78; We update fileparameters, readparameters and meshparameters elements of the top_value
[69]79      newfileparameters = ptrarr(currentfile+1, /allocate_heap)
80      FOR i = 0, currentfile-1 DO $
81         *newfileparameters[i] = *(extractatt(top_uvalue, 'fileparameters'))[i]
82      *newfileparameters[currentfile] = newfile.fileparameters
83      ptr_free, extractatt(top_uvalue, 'fileparameters')
84      *top_uvalue[1, findline(top_uvalue, 'fileparameters')] = newfileparameters
[2]85;
[69]86      newreadparameters = ptrarr(currentfile+1, /allocate_heap)
87      FOR i = 0, currentfile-1 DO $
88         *newreadparameters[i] = *(extractatt(top_uvalue, 'readparameters'))[i]
89      *newreadparameters[currentfile] = newfile.readparameters
90      ptr_free, extractatt(top_uvalue, 'readparameters')
91      *top_uvalue[1, findline(top_uvalue, 'readparameters')] = newreadparameters
[2]92;
[69]93      newmeshparameters = ptrarr(currentfile+1, /allocate_heap)
94      FOR i = 0, currentfile-1 DO $
95         *newmeshparameters[i] = *(extractatt(top_uvalue, 'meshparameters'))[i]
96      *newmeshparameters[currentfile] = newfile.meshparameters
97      ptr_free, extractatt(top_uvalue, 'meshparameters')
98      *top_uvalue[1, findline(top_uvalue, 'meshparameters')] = newmeshparameters
[150]99; We update the widget!
[69]100      if cmpgrid(oldmeshparams) then BEGIN
101        domainid = widget_info(event.top, find_by_uname = 'domain')
102        widget_control, domainid, set_value = -1
103      endif
104      widget_control, event.top, update = 1
105    end
106    'New xxx' :BEGIN
107      widget_control, event.top, get_uvalue = top_uvalue
108      extra = extractatt(top_uvalue, 'extra')
109      xxx, CALLERWIDID = event.top, _extra = extra
110    end
[226]111    'Quit':begin
[69]112      widget_control, event.top, get_uvalue = top_uvalue
113      ptr_free, extractatt(top_uvalue, 'exextra')
114      ptr_free, extractatt(top_uvalue, 'fileparameters')
115      ptr_free, extractatt(top_uvalue, 'readparameters')
116      ptr_free, extractatt(top_uvalue, 'meshparameters')
117      ptr_free, top_uvalue
[150]118      widget_control, event.top, /destroy ;We shut the widget
[69]119    end
120    'PostScript' :BEGIN
121      IF lmgr(/demo) EQ 1 THEN BEGIN
122        dummy = report('impossible to save as postscript in demo mode')
123        return
124      ENDIF
125      widget_control, event.top, get_uvalue = top_uvalue
[150]126; We recuperate the list of instructions
[69]127      globalcommand = extractatt(top_uvalue, 'globalcommand')
128;      for i = 0, n_elements(globalcommand)-1 do print, globalcommand[i]
[150]129; We complete by first and last lines of the program.
[69]130      createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
131                 , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript' $
132                 +', PORTRAIT = portrait, LANDSCAPE = landscape' $
133                 +', DATE1IN = date1in, DATE2IN = date2in' $
134                 , /POSTSCRIPT
135    END
[226]136    'Animated gif' :begin
[69]137      IF float(strmid(!version.release,0,3)) GE 6.2 THEN xcreateanim, event.top
138    end
139    'Gif' :BEGIN
140      IF lmgr(/demo) EQ 1 THEN BEGIN
141        dummy = report('impossible to save as an image in demo mode')
142        return
143      ENDIF
144      widget_control, event.top, get_uvalue = top_uvalue
145      smallin = extractatt(top_uvalue, 'smallin')
146      numdessinin = smallin[2]-1
147      smallout = extractatt(top_uvalue, 'smallout')
148      numdessinout = smallout[2]-1
149      tracecadre, smallin, /erase
150      tracecadre, smallout, /erase
[267]151      filename = xquestion('In which GIF file do you want to save xxx screen ?', 'xxx_image.gif')
[69]152      if rstrpos(filename, '.gif') NE strlen(filename)-4 then filename = filename+'.gif'
153      filename = isafile(file = filename, io = imagedir, /new)
154      saveimage, filename, /quiet
155    end
156    'IDL procedure':BEGIN
157      IF lmgr(/demo) EQ 1 THEN BEGIN
158        dummy = report('impossible to save as a idl program file in demo mode')
159        return
160      ENDIF
[150]161; We recuperate the name of the file
[267]162      filename = xquestion('In which IDL file do you want to save commands for this graph ?', 'xxx_figure.pro')
[150]163; We complete it by a .pro
[69]164      if rstrpos(filename, '.pro') NE strlen(filename)-4 then filename = filename+'.pro'
165      filename = isafile(file = filename, io = homedir, /new)
166      widget_control, event.top, get_uvalue = top_uvalue
[150]167; portrait or landscape ???
[226]168      options = extractatt(top_uvalue, 'options')
[69]169      optionsflag = extractatt(top_uvalue, 'optionsflag')
170      portrait = (optionsflag[where(options EQ 'Portrait/Landscape'), 0])[0]
[150]171; We read commands to do a plot
[69]172      globalcommand = extractatt(top_uvalue, 'globalcommand')
[150]173; We complete by first and last lines of the program
[69]174      thisOS = strupcase(strmid(!version.os_family, 0, 3))
175      CASE thisOS of
176        'MAC':sep = ':'
177        'WIN':sep = '\'
178        ELSE:sep = '/'
179      ENDCASE
180      poslastsep = rstrpos(filename, sep)
181      proname = strmid(filename, poslastsep+1, strlen(filename)-poslastsep-1-4)
182      globalcommand = ['pro '+proname+', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape, DATE1IN = date1in, DATE2IN = date2in, _extra = ex' $
183                       , ' ' $
184                       , '   '+globalcommand $
185                       , ' ' $
186                       , 'return' $
187                       , 'end']
[150]188; We write it in a program
[69]189      putfile, filename, globalcommand
190    END
191    'RESTORE kwd of xxx':BEGIN
192      IF lmgr(/demo) EQ 1 THEN BEGIN
193        dummy = report('impossible to save the widget in demo mode')
194        return
195      ENDIF
[150]196; We recuperate the name of the file
[226]197      filename = xquestion('In which binary file do you want to save the widget ?', 'xxx_widget.dat')
[150]198; We complete it by a .dat
[69]199      if rstrpos(filename, '.dat') NE strlen(filename)-4 then filename = filename+'.dat'
200      filename = isafile(file = filename, io = homedir, /new)
[2]201;
[69]202      widget_control, event.top, get_uvalue = uvalue
203      widget_control, extractatt(uvalue, 'graphid'), get_value = win
204      wshow, win
205      wset, win
206      image = tvrd(/true)
207      save, uvalue, image, filename = filename
208    END
209    'Print to prompt':BEGIN
210      commande = getfile(myuniquetmpdir + 'xxx_oneplot.pro')
211      for i = 0,  n_elements(commande)-1 do print, commande[i]
212    end
[226]213   'Portrait/Landscape' :begin
[69]214      widget_control, event.top, get_uvalue = top_uvalue
215      options = extractatt(top_uvalue, 'options')
216      index = where(options EQ 'Portrait/Landscape') & index = index[0]
217      optionsflag = extractatt(top_uvalue, 'optionsflag')
218      key_portrait = 1-optionsflag[index, 0]
219      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, *] = key_portrait
[150]220; Separated windows or windows stuck to the widget?
[69]221      if widget_info(event.top, find_by_uname = 'graph') EQ 0 then BEGIN
[150]222; We delete the window
[69]223        graphid = extractatt(top_uvalue, 'graphid')
224        widget_control, widget_info(graphid, /parent), /destroy
[150]225; We recreate it.
[69]226        basegraph = widget_base(title = 'xxx window',  group_leader = event.top, uvalue = event.top,  uname = 'basegraph')
227        windsize = givewindowsize()
228        graphid = widget_draw(basegraph, uname = 'graph' $
229                              , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $
230                              , /button_events, retain = 2 $
231                              , xsize = windsize[0], ysize = windsize[1])
232        widget_control, basegraph, /realize
233        xmanager, 'xxx', basegraph, /no_block
[295]234; We redraw what they were into it
[150]235; We recuperate the list of instructions
[69]236        globalcommand = extractatt(top_uvalue, 'globalcommand')
[150]237; We complete by first and last lines of the program
[69]238        createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
239                   , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape' $
240                   , KWDUSED = ', /noerase, PORTRAIT = portrait'
[150]241; We reattribute the graphic element of the top_value
[69]242        *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid
243      ENDIF ELSE BEGIN
244        extra = extractatt(top_uvalue, 'extra')
245        xxx, CALLERWIDID = event.top, /redraw, _extra = extra
[150]246        widget_control, event.top, /destroy ;We shut the widget
[69]247      ENDELSE
248    end
[226]249    'Overlay' :begin
[69]250      widget_control, event.top, get_uvalue = top_uvalue
251      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
[226]252      options = extractatt(top_uvalue, 'options')
[69]253      flags = extractatt(top_uvalue, 'optionsflag')
254      index = where(options EQ 'Overlay')
[150]255; We change the flag on Longitude / x index
[69]256      flag = 1-flags[index, numdessinin] & flag = flag[0]
[150]257; We reattribute it
[69]258      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
259    end
260    'Vecteur':BEGIN
261      widget_control, event.top, get_uvalue = top_uvalue
262      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
[226]263      options = extractatt(top_uvalue, 'options')
[69]264      flags = extractatt(top_uvalue, 'optionsflag')
265      index = where(options EQ 'Vecteur')
[150]266; We change the flag on Longitude / x index
[69]267      flag = 1-flags[index, numdessinin] & flag = flag[0]
[150]268; We reattribute it
[69]269      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
270    end
271    'Longitude / x index':BEGIN
272      widget_control, event.top, get_uvalue = top_uvalue
273      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
[226]274      options = extractatt(top_uvalue, 'options')
[69]275      flags = extractatt(top_uvalue, 'optionsflag')
276      index = where(options EQ 'Longitude / x index')
[150]277; We change the flag on Longitude / x index
[69]278      flag = 1-flags[index, numdessinin] & flag = flag[0]
[150]279; We reattribute it
[69]280      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
[150]281; Now we will change sliders defining the boxzoom
[69]282      domainid = widget_info(event.top, find_by_uname = 'domain')
283      boxzoom = (extractatt(top_uvalue, 'domaines'))[*, numdessinin]
[150]284; We want to find the type of grid which is used
[69]285      currentfile = extractatt(top_uvalue, 'currentfile')
286      listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid
287      listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar
288      vlstid = widget_info(event.top, find_by_uname = 'varlist')
289      namevar = widget_info(vlstid, /combobox_gettext)
290      indexvar = where(listvar EQ namevar)
291      vargrid = strupcase(listgrid[indexvar])
292      if flag EQ 0 then BEGIN   ; longitudes
[150]293; We do a domdef to find the lon1 lon2 corresponding to the boxzoom defined on the widget...
[69]294        domdef, boxzoom, gridtype = vargrid, /xindex $
295                , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0]
296        widget_control, domainid, set_value = [lon1, lon2, boxzoom[2:3]]
297      ENDIF ELSE BEGIN          ; xindex
[150]298; now we want to find firstx, lastx corresponding to the boxzoom defined on the widget...
[69]299        domdef, boxzoom, gridtype = vargrid $
300                , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0]
301        grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
302        widget_control, domainid, set_value = [firstx, lastx, boxzoom[2:3]]
303      ENDELSE
[150]304; We update the top_uvalue
[69]305      widget_control, domainid, get_value = boxzoom
306      (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boxzoom
307    end
[226]308    'Latitude / y index':begin
[69]309      widget_control, event.top, get_uvalue = top_uvalue
310      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
[226]311      options = extractatt(top_uvalue, 'options')
[69]312      flags = extractatt(top_uvalue, 'optionsflag')
313      index = where(options EQ 'Latitude / y index')
[150]314; We change the flag on Latitude / y index
[69]315      flag = 1-flags[index, numdessinin] & flag = flag[0]
[150]316; We reattribute it
[69]317      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
[150]318; Now we will change sliders defining the boxzoom
[69]319      domainid = widget_info(event.top, find_by_uname = 'domain')
320      boxzoom = (extractatt(top_uvalue, 'domaines'))[*, numdessinin]
[150]321; We want to find the type of grid which is used
[69]322      currentfile = extractatt(top_uvalue, 'currentfile')
323      listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid
324      listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar
325      vlstid = widget_info(event.top, find_by_uname = 'varlist')
326      namevar = widget_info(vlstid, /combobox_gettext)
327      indexvar = where(listvar EQ namevar)
328      vargrid = strupcase(listgrid[indexvar])
329      if flag EQ 0 then BEGIN   ; latitudes
[150]330; We do a domdef to find the lat1 lat2 corresponding to the boxzoom defined on the widget...
[69]331        domdef, boxzoom, gridtype = vargrid, /yindex $
332                , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0]
333        widget_control, domainid, set_value = [boxzoom[0:1], lat1, lat2]
334      ENDIF ELSE BEGIN          ; yindex
[150]335; now we want to find firsty, lasty corresponding to the boxzoom defined on the widget...
[69]336        domdef, boxzoom, gridtype = vargrid $
337                , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0]
338        grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
339        widget_control, domainid, set_value = [boxzoom[0:1], firsty, lasty]
340      ENDELSE
[150]341; We update the top_uvalue
[69]342      widget_control, domainid, get_value = boxzoom
343      (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boxzoom
344    END
345  endcase
346  return
[2]347end
Note: See TracBrowser for help on using the repository browser.