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

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

corrections of some misspellings in some *.pro

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