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

Last change on this file since 198 was 150, checked in by navarro, 18 years ago

english and nicer header (3a)

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