source: trunk/ToBeReviewed/WIDGET/AUTOUR_de_XXX/xxxmenubar_event.pro @ 69

Last change on this file since 69 was 69, checked in by smasson, 18 years ago

debug + new xxx

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1;------------------------------------------------
2PRO xxxmenubar_event, event
3@common
4
5
6  case event.value of
7    'Open' :begin
8      oldmeshparams = ccmeshparameters
9      newfile = selectfile()
10      if size(newfile, /type) NE 8 then return
11      widget_control, event.top, /hourglass
12      widget_control, event.top, update = 0
13      widget_control, event.top, get_uvalue = top_uvalue
14; on s''occupe de filelist
15      filelist = extractatt(top_uvalue, 'filelist')
16      filelist = [filelist, newfile.fileparameters.filename]
17      currentfile = n_elements(filelist)-1
18; on update le widget
19      filelistid = widget_info(event.top, find_by_uname = 'filelist')
20      widget_control, filelistid, combobox_additem = file_basename(newfile.fileparameters.filename)
21      widget_control, filelistid, set_combobox_select = currentfile
22; on update les elements filelist et currentfile de la top_uvalue
23      *top_uvalue[1, findline(top_uvalue, 'filelist')] = filelist
24      oldfile = *top_uvalue[1, findline(top_uvalue, 'currentfile')]
25      *top_uvalue[1, findline(top_uvalue, 'currentfile')] = currentfile
26; on s''occupe du nom de la variable
27      vlstid = widget_info(event.top, find_by_uname = 'varlist')
28; quel etait le champ selectionne ? on le reselectionne ?
29      fieldname = widget_info(vlstid, /combobox_gettext)
30      index = where(newfile.fileparameters.listvar EQ fieldname)
31      widget_control, vlstid, set_value = newfile.fileparameters.listvar
32      widget_control, vlstid, set_combobox_select = 0 > index[0]
33; on s''occupe du calendrier
34      date1id = widget_info(event.top, find_by_uname = 'calendar1')
35      widget_control, date1id, get_value = date1
36      widget_control, date1id, /destroy
37      if (where(newfile.fileparameters.time_counter EQ date1))[0] EQ -1 $
38      then date1 = newfile.fileparameters.time_counter[0]
39      date2id = widget_info(event.top, find_by_uname = 'calendar2')
40      widget_control, date2id, get_value = date2
41      widget_control, date2id, /destroy
42      if (where(newfile.fileparameters.time_counter EQ date2))[0] EQ -1 then date2 = date1
43      basecal = widget_info(event.top, find_by_uname = 'basecal')
44      rien = cw_calendar(basecal, newfile.fileparameters.time_counter, date1, uname = 'calendar1' $
45                         , uvalue = {name:'calendar1'}, /frame)
46      rien = cw_calendar(basecal, newfile.fileparameters.time_counter, date2, uname = 'calendar2' $
47                         , uvalue = {name:'calendar2'}, /frame)
48; on update les elements fileparameters, readparameters et meshparameters de la top_uvalue
49      newfileparameters = ptrarr(currentfile+1, /allocate_heap)
50      FOR i = 0, currentfile-1 DO $
51         *newfileparameters[i] = *(extractatt(top_uvalue, 'fileparameters'))[i]
52      *newfileparameters[currentfile] = newfile.fileparameters
53      ptr_free, extractatt(top_uvalue, 'fileparameters')
54      *top_uvalue[1, findline(top_uvalue, 'fileparameters')] = newfileparameters
55;
56      newreadparameters = ptrarr(currentfile+1, /allocate_heap)
57      FOR i = 0, currentfile-1 DO $
58         *newreadparameters[i] = *(extractatt(top_uvalue, 'readparameters'))[i]
59      *newreadparameters[currentfile] = newfile.readparameters
60      ptr_free, extractatt(top_uvalue, 'readparameters')
61      *top_uvalue[1, findline(top_uvalue, 'readparameters')] = newreadparameters
62;
63      newmeshparameters = ptrarr(currentfile+1, /allocate_heap)
64      FOR i = 0, currentfile-1 DO $
65         *newmeshparameters[i] = *(extractatt(top_uvalue, 'meshparameters'))[i]
66      *newmeshparameters[currentfile] = newfile.meshparameters
67      ptr_free, extractatt(top_uvalue, 'meshparameters')
68      *top_uvalue[1, findline(top_uvalue, 'meshparameters')] = newmeshparameters
69; on actualise le widget!
70      if cmpgrid(oldmeshparams) then BEGIN
71        domainid = widget_info(event.top, find_by_uname = 'domain')
72        widget_control, domainid, set_value = -1
73      endif
74      widget_control, event.top, update = 1
75    end
76    'New xxx' :BEGIN
77      widget_control, event.top, get_uvalue = top_uvalue
78      extra = extractatt(top_uvalue, 'extra')
79      xxx, CALLERWIDID = event.top, _extra = extra
80    end
81    'Quit':begin
82      widget_control, event.top, get_uvalue = top_uvalue
83      ptr_free, extractatt(top_uvalue, 'exextra')
84      ptr_free, extractatt(top_uvalue, 'fileparameters')
85      ptr_free, extractatt(top_uvalue, 'readparameters')
86      ptr_free, extractatt(top_uvalue, 'meshparameters')
87      ptr_free, top_uvalue
88      widget_control, event.top, /destroy ;on ferme le widget
89    end
90    'PostScript' :BEGIN
91      IF lmgr(/demo) EQ 1 THEN BEGIN
92        dummy = report('impossible to save as postscript in demo mode')
93        return
94      ENDIF
95      widget_control, event.top, get_uvalue = top_uvalue
96; on recupere la liste des instructions
97      globalcommand = extractatt(top_uvalue, 'globalcommand')
98;      for i = 0, n_elements(globalcommand)-1 do print, globalcommand[i]
99; on complete par le premiere et les dernieres lignes du programme
100      createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
101                 , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript' $
102                 +', PORTRAIT = portrait, LANDSCAPE = landscape' $
103                 +', DATE1IN = date1in, DATE2IN = date2in' $
104                 , /POSTSCRIPT
105    END
106    'Animated gif' :begin
107      IF float(strmid(!version.release,0,3)) GE 6.2 THEN xcreateanim, event.top
108    end
109    'Gif' :BEGIN
110      IF lmgr(/demo) EQ 1 THEN BEGIN
111        dummy = report('impossible to save as an image in demo mode')
112        return
113      ENDIF
114      widget_control, event.top, get_uvalue = top_uvalue
115      smallin = extractatt(top_uvalue, 'smallin')
116      numdessinin = smallin[2]-1
117      smallout = extractatt(top_uvalue, 'smallout')
118      numdessinout = smallout[2]-1
119      tracecadre, smallin, /erase
120      tracecadre, smallout, /erase
121      filename = xquestion('dans quelle fichier gif voulez vous sauver !C l''ecran de xxx?', 'xxx_image.gif')
122      if rstrpos(filename, '.gif') NE strlen(filename)-4 then filename = filename+'.gif'
123      filename = isafile(file = filename, io = imagedir, /new)
124      saveimage, filename, /quiet
125    end
126    'IDL procedure':BEGIN
127      IF lmgr(/demo) EQ 1 THEN BEGIN
128        dummy = report('impossible to save as a idl program file in demo mode')
129        return
130      ENDIF
131; on recupere le nom du fichier
132      filename = xquestion('dans quelle procedure IDL voulez vous sauver !C la realisation de ce graph?', 'xxx_figure.pro')
133; on le complete par un .pro
134      if rstrpos(filename, '.pro') NE strlen(filename)-4 then filename = filename+'.pro'
135      filename = isafile(file = filename, io = homedir, /new)
136      widget_control, event.top, get_uvalue = top_uvalue
137; portrait ou landscape ???
138      options = extractatt(top_uvalue, 'options')   
139      optionsflag = extractatt(top_uvalue, 'optionsflag')
140      portrait = (optionsflag[where(options EQ 'Portrait/Landscape'), 0])[0]
141; on lit les commandes pour faire un plot
142      globalcommand = extractatt(top_uvalue, 'globalcommand')
143; on complete par le premiere et les dernieres lignes du programme
144      thisOS = strupcase(strmid(!version.os_family, 0, 3))
145      CASE thisOS of
146        'MAC':sep = ':'
147        'WIN':sep = '\'
148        ELSE:sep = '/'
149      ENDCASE
150      poslastsep = rstrpos(filename, sep)
151      proname = strmid(filename, poslastsep+1, strlen(filename)-poslastsep-1-4)
152      globalcommand = ['pro '+proname+', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape, DATE1IN = date1in, DATE2IN = date2in, _extra = ex' $
153                       , ' ' $
154                       , '   '+globalcommand $
155                       , ' ' $
156                       , 'return' $
157                       , 'end']
158; on les ecrit dans un programme
159      putfile, filename, globalcommand
160    END
161    'RESTORE kwd of xxx':BEGIN
162      IF lmgr(/demo) EQ 1 THEN BEGIN
163        dummy = report('impossible to save the widget in demo mode')
164        return
165      ENDIF
166; on recupere le nom du fichier
167      filename = xquestion('dans quel fichier bianire voulez vous sauver le widget ?', 'xxx_widget.dat')
168; on le complete par un .dat
169      if rstrpos(filename, '.dat') NE strlen(filename)-4 then filename = filename+'.dat'
170      filename = isafile(file = filename, io = homedir, /new)
171;
172      widget_control, event.top, get_uvalue = uvalue
173      widget_control, extractatt(uvalue, 'graphid'), get_value = win
174      wshow, win
175      wset, win
176      image = tvrd(/true)
177      save, uvalue, image, filename = filename
178    END
179    'Print to prompt':BEGIN
180      commande = getfile(myuniquetmpdir + 'xxx_oneplot.pro')
181      for i = 0,  n_elements(commande)-1 do print, commande[i]
182    end
183   'Portrait/Landscape' :begin
184      widget_control, event.top, get_uvalue = top_uvalue
185      options = extractatt(top_uvalue, 'options')
186      index = where(options EQ 'Portrait/Landscape') & index = index[0]
187      optionsflag = extractatt(top_uvalue, 'optionsflag')
188      key_portrait = 1-optionsflag[index, 0]
189      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, *] = key_portrait
190; fenetre separee ou fenetre collee au widget ?
191      if widget_info(event.top, find_by_uname = 'graph') EQ 0 then BEGIN
192; on tue la fenetre
193        graphid = extractatt(top_uvalue, 'graphid')
194        widget_control, widget_info(graphid, /parent), /destroy
195; on la recree
196        basegraph = widget_base(title = 'xxx window',  group_leader = event.top, uvalue = event.top,  uname = 'basegraph')
197        windsize = givewindowsize()
198        graphid = widget_draw(basegraph, uname = 'graph' $
199                              , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $
200                              , /button_events, retain = 2 $
201                              , xsize = windsize[0], ysize = windsize[1])
202        widget_control, basegraph, /realize
203        xmanager, 'xxx', basegraph, /no_block
204; on redessine ce qu''il y avait dedans
205; on recupere la liste des instructions
206        globalcommand = extractatt(top_uvalue, 'globalcommand')
207; on complete par le premiere et les dernieres lignes du programme
208        createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
209                   , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape' $
210                   , KWDUSED = ', /noerase, PORTRAIT = portrait'
211; on reattribue l''element graphid de la top_uvalue
212        *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid
213      ENDIF ELSE BEGIN
214        extra = extractatt(top_uvalue, 'extra')
215        xxx, CALLERWIDID = event.top, /redraw, _extra = extra
216        widget_control, event.top, /destroy ;on ferme le widget
217      ENDELSE
218    end
219    'Overlay' :begin
220      widget_control, event.top, get_uvalue = top_uvalue
221      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
222      options = extractatt(top_uvalue, 'options')   
223      flags = extractatt(top_uvalue, 'optionsflag')
224      index = where(options EQ 'Overlay')
225; on change le flag sur Longitude / x index
226      flag = 1-flags[index, numdessinin] & flag = flag[0]
227; on le reeatribue
228      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
229    end
230    'Vecteur':BEGIN
231      widget_control, event.top, get_uvalue = top_uvalue
232      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
233      options = extractatt(top_uvalue, 'options')   
234      flags = extractatt(top_uvalue, 'optionsflag')
235      index = where(options EQ 'Vecteur')
236; on change le flag sur Longitude / x index
237      flag = 1-flags[index, numdessinin] & flag = flag[0]
238; on le reeatribue
239      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
240    end
241    'Longitude / x index':BEGIN
242      widget_control, event.top, get_uvalue = top_uvalue
243      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
244      options = extractatt(top_uvalue, 'options')   
245      flags = extractatt(top_uvalue, 'optionsflag')
246      index = where(options EQ 'Longitude / x index')
247; on change le flag sur Longitude / x index
248      flag = 1-flags[index, numdessinin] & flag = flag[0]
249; on le reeatribue
250      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
251; maintenant on va changer les sliders definissant la boxzoom
252      domainid = widget_info(event.top, find_by_uname = 'domain')
253      boxzoom = (extractatt(top_uvalue, 'domaines'))[*, numdessinin]
254; on veut retrouver le type de grille qui est utilisee
255      currentfile = extractatt(top_uvalue, 'currentfile')
256      listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid
257      listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar
258      vlstid = widget_info(event.top, find_by_uname = 'varlist')
259      namevar = widget_info(vlstid, /combobox_gettext)
260      indexvar = where(listvar EQ namevar)
261      vargrid = strupcase(listgrid[indexvar])
262      if flag EQ 0 then BEGIN   ; longitudes
263; on fait un domdef pour retrouver le lon1 lon2 correspondant a la
264; boxzoom definie sur le widget...
265        domdef, boxzoom, gridtype = vargrid, /xindex $
266                , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0]
267        widget_control, domainid, set_value = [lon1, lon2, boxzoom[2:3]]
268      ENDIF ELSE BEGIN          ; xindex
269; maintenant ion veut retrouver firstx, lastx correspondant a la
270; boxzoom definie sur le widget...
271        domdef, boxzoom, gridtype = vargrid $
272                , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0]
273        grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
274        widget_control, domainid, set_value = [firstx, lastx, boxzoom[2:3]]
275      ENDELSE
276; on met a jour la top_uvalue
277      widget_control, domainid, get_value = boxzoom
278      (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boxzoom
279    end
280    'Latitude / y index':begin
281      widget_control, event.top, get_uvalue = top_uvalue
282      numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
283      options = extractatt(top_uvalue, 'options')   
284      flags = extractatt(top_uvalue, 'optionsflag')
285      index = where(options EQ 'Latitude / y index')
286; on change le flag sur Latitude / y index
287      flag = 1-flags[index, numdessinin] & flag = flag[0]
288; on le reeatribue
289      (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
290; maintenant on va changer les sliders definissant la boxzoom
291      domainid = widget_info(event.top, find_by_uname = 'domain')
292      boxzoom = (extractatt(top_uvalue, 'domaines'))[*, numdessinin]
293; on veut retrouver le type de grille qui est utilisee
294      currentfile = extractatt(top_uvalue, 'currentfile')
295      listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid
296      listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar
297      vlstid = widget_info(event.top, find_by_uname = 'varlist')
298      namevar = widget_info(vlstid, /combobox_gettext)
299      indexvar = where(listvar EQ namevar)
300      vargrid = strupcase(listgrid[indexvar])
301      if flag EQ 0 then BEGIN   ; latitudes
302; on fait un domdef pour retrouver le lat1 lat2 correspondant a la
303; boxzoom definie sur le widget...
304        domdef, boxzoom, gridtype = vargrid, /yindex $
305                , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0]
306        widget_control, domainid, set_value = [boxzoom[0:1], lat1, lat2]
307      ENDIF ELSE BEGIN          ; yindex
308; maintenant ion veut retrouver firsty, lasty correspondant a la
309; boxzoom definie sur le widget...
310        domdef, boxzoom, gridtype = vargrid $
311                , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0]
312        grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz
313        widget_control, domainid, set_value = [boxzoom[0:1], firsty, lasty]
314      ENDELSE
315; on met a jour la top_uvalue
316      widget_control, domainid, get_value = boxzoom
317      (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boxzoom
318    END
319  endcase
320  return
321end
Note: See TracBrowser for help on using the repository browser.