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

Last change on this file since 367 was 325, checked in by pinsard, 16 years ago

modification of some headers (+some corrections) to prepare usage of the new idldoc

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