source: trunk/SRC/ToBeReviewed/WIDGET/xxx.pro @ 254

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

improvements/corrections of some *.pro headers

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 20.3 KB
Line 
1;+
2;
3; @file_comments
4; see <a href="../../../xmldoc/mini_notice.html">Mini Guide for Basic Commands in the XXX Program</a>
5;
6; @categories
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;
24PRO xxx_event, event
25;
26  compile_opt idl2, strictarrsubs
27;
28@common
29;------------------------------------------------------------
30;    = widget_info(event.top,find_by_uname = '')
31; What is the type of event ?
32;   if event.id EQ 622 then help,  event,  /struct
33   widget_control, event.id, get_uvalue=uval
34   if (tag_names(event, /structure_name))[0] EQ 'WIDGET_TRACKING' then uval = {name:'ActiverFenetre'}
35   if keyword_set(uval) EQ 0 then return
36;help,  event, /struct
37;help, uval , /struct
38; case on the type of event
39   widget_control, event.top, get_uvalue = top_uvalue
40; If we activate the keyword separate at the call of xxx
41   if size(top_uvalue, /type) EQ 3 then begin
42      event.top = top_uvalue
43      widget_control, event.top, get_uvalue = top_uvalue
44   endif
45; we delete the small widget created by notice.pro if it exists
46   noticebase = extractatt(top_uvalue, 'noticebase')
47   if noticebase NE 0 then BEGIN
48      widget_control, noticebase, /destroy
49      *top_uvalue[1, findline(top_uvalue, 'noticebase')] = 0l
50   endif
51;
52   options = extractatt(top_uvalue, 'options')
53   case uval.name OF
54      'menubar':xxxmenubar_event, event
55      'ok':nouveaudessin = 1
56      'specifie':
57      'action':
58      'calendar1':BEGIN
59         date2id = widget_info(event.top, find_by_uname = 'calendar2')
60         widget_control, date2id, get_value = date2
61         if event.value GT date2 then widget_control, date2id, set_value = event.value
62      END
63      'calendar2':BEGIN
64         date1id = widget_info(event.top, find_by_uname = 'calendar1')
65         widget_control, date1id, get_value = date1
66         if event.value LT date1 then widget_control, date1id, set_value = event.value
67      END
68      'domain':
69      'varlist':BEGIN
70         currentfile  = extractatt(top_uvalue, 'currentfile')
71         listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar
72         name = listvar[event.index]
73         changefield, event.top, name
74      END
75      'txtcmd':
76      'filelist':BEGIN
77         changefile, event.top, event.index
78      END
79      'ActiverFenetre':BEGIN
80         if event.enter EQ 1 AND !d.name NE 'PS' then BEGIN
81;            graphid = widget_info(event.top,find_by_uname = 'graph')
82            graphid = extractatt(top_uvalue, 'graphid')
83            widget_control,graphid,get_value=win
84            wset, win
85            widget_control,event.top,get_uvalue=top_uvalue
86            numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
87            !p = (extractatt(top_uvalue, 'penvs'))[numdessinin]
88            !x = (extractatt(top_uvalue, 'xenvs'))[numdessinin]
89            !y = (extractatt(top_uvalue, 'yenvs'))[numdessinin]
90         endif
91      END
92      'graph':BEGIN
93         quelclick = identifyclick(event)
94         case quelclick.type of
95            'inutile':return
96            'long':longclickaction, event
97            'single':singleclickaction, event
98            'double':doubleclickaction, event
99         endcase
100      END
101   endcase
102   if keyword_set(nouveaudessin) then letsdraw, event.top
103   return
104end
105;
106;+
107;
108; @file_comments
109; A maximum of possibilities with a minimum of clics
110;
111; @categories
112; Widget
113;
114; @param DATAFILENAME
115;
116; @param IDLFILE
117;
118; @param ARGSPRO
119;
120; @keyword SEPARATE
121; To separate the button part and the drawing part in 2 windows.
122; Useful for small screens, but be careful to do not saturate the
123; video memory of some antiquated Tx.
124;
125; @keyword RESTORE
126; 'toto.dat' or toto.dat is a file created at the time of a precedent
127; use of xxx thanks to the command "Widget" of the menu "save as".
128;
129; @keyword _EXTRA
130; Used to pass keywords
131;
132; @keyword CALLERWIDID
133;
134; @keyword REDRAW
135;
136;
137; @keyword SEPARATE
138;
139;
140; @keyword UVALUE
141; The user value to be associated with the widget.
142;
143; @uses
144; common.pro
145;
146; @history
147; Sebastien Masson (smasson\@lodyc.jussieu.fr)
148;
149; @version
150; $Id$
151;
152; @todo
153; seb: documenter le reste des keywords
154;
155;-
156;
157PRO xxx, datafilename, idlfile, argspro, CALLERWIDID = CallerWidId $
158         , REDRAW = redraw, SEPARATE = separate, UVALUE = uvalue $
159         , RESTORE = restore, _EXTRA = ex
160;
161  compile_opt idl2, strictarrsubs
162;
163@all_cm
164;------------------------------------------------------------
165; reinitialize the !p, !x, !y, !z variables
166;------------------------------------------------------------
167  reinitplt
168;------------------------------------------------------------
169; we get back the uvalue of the widget that called xxx to create a new widget
170  if keyword_set(restore) then BEGIN
171    restore = isafile(filename = restore, iodir = homedir, _extra = ex)
172    if size(restore, /type) NE 7 then restore = 0 ELSE BEGIN
173      restore, isafile(file = restore, iodir = homedir, _extra = ex)
174      newgrid = *(extractatt(uvalue, 'meshparameters'))[0]
175      change = changegrid(newgrid)
176    ENDELSE
177  endif
178  if n_elements(CallerWidId) NE 0 THEN $
179     widget_control, CallerWidId, get_uvalue = uvalue ELSE CallerWidId = 0
180;------------------------------------------------------------
181;------------------------------------------------------------
182; list of files we want to look at
183;
184  if keyword_set(uvalue) then BEGIN
185    currentfile = extractatt(uvalue, 'currentfile')
186    filelist = extractatt(uvalue, 'filelist')
187    fileparameters = extractatt(uvalue, 'fileparameters')
188    readparameters = extractatt(uvalue, 'readparameters')
189    meshparameters = extractatt(uvalue, 'meshparameters')
190  ENDIF ELSE BEGIN
191    newfile = selectfile(datafilename, idlfile, argspro, _extra = ex)
192    if size(newfile, /type) NE 8 then return
193    fileparameters = ptrarr(1, /allocate_heap)
194    *fileparameters[0] = newfile.fileparameters
195    readparameters = ptrarr(1, /allocate_heap)
196    *readparameters[0] = newfile.readparameters
197    meshparameters = ptrarr(1, /allocate_heap)
198    *meshparameters[0] = newfile.meshparameters
199    currentfile = 0
200    filelist = newfile.fileparameters.filename
201  ENDELSE
202;
203  if keyword_set(uvalue) THEN BEGIN
204    smallin = extractatt(uvalue, 'smallin')
205    smallout = extractatt(uvalue, 'smallout')
206  ENDIF ELSE BEGIN
207    smallin = [1, 1, 1]
208    smallout = [1, 1, 1]
209  ENDELSE
210  nbredessin = smallin[0]*smallin[1]
211  numdessinin = smallin[2]-1
212; warning flg definition must be consistent with cw_pdmenu argument
213; see also flag definition in cw_pagelayout
214  if keyword_set(uvalue) then BEGIN
215    flag = extractatt(uvalue, 'optionsflag')
216    key_portrait = flag[0, numdessinin]
217  ENDIF ELSE flag = [key_portrait, 0, 0, 0, 0]#replicate(1, nbredessin)
218
219;------------------------------------------------------------
220;------------------------------------------------------------
221; We start the widget definition
222;------------------------------------------------------------
223;------------------------------------------------------------
224;
225; widget and screen size
226  scrsize = get_screen_size()*0.95
227  windsize = givewindowsize()
228  xxxsize = [windsize[0] * (1-keyword_set(separate)) + 350, windsize[1]]
229;
230;------------------------------------------------------------
231; The top base
232;------------------------------------------------------------
233  IF xxxsize[0] LE scrsize[0] AND xxxsize[1] LE scrsize[1] THEN BEGIN
234    base = widget_base(title = 'xxx', GROUP_LEADER = group, /tracking_events $
235                       , uname = 'base', space = 0)
236  ENDIF ELSE BEGIN
237    base = widget_base(title = 'xxx', GROUP_LEADER = group, /tracking_events $
238                       , uname = 'base', space = 0 $
239                       , xsize = xxxsize[0], ysize = xxxsize[1] $
240                       , x_scroll_size = (xxxsize[0] < scrsize[0]) $
241                       , y_scroll_size = (xxxsize[1] < scrsize[1]))
242  ENDELSE
243
244;------------------------------------------------------------
245; combobox for plots choice
246;------------------------------------------------------------
247  xoff = 0
248  yoff = 0
249  pltlst = ['plt', 'pltv' $
250            , 'pltz', 'pltz diag up', 'pltz diag dn' $
251            , 'pltt', 'pltt diag up', 'pltt diag dn' $
252            , 'xy', 'xz', 'yz', 'xt', 'yt', 'zt' $
253            , 'x', 'y', 'z', 't']
254  actid = widget_combobox(base, value = pltlst, uname = 'action', uvalue = {name:'action'} $
255                            , xoffset = xoff+5, yoffset = yoff+4, xsize = 90)
256  if keyword_set(uvalue) then BEGIN
257    selectact = (extractatt(uvalue, 'types'))[numdessinin]
258    selectact = (where(pltlst EQ selectact))[0]
259    widget_control, actid, set_combobox_select = 0 > selectact
260  ENDIF ELSE selectfile = 0
261
262;------------------------------------------------------------
263; menu/options
264;------------------------------------------------------------
265  xoff = xoff + 110
266  if keyword_set(uvalue) then begin
267    options = extractatt(uvalue, 'options')
268  ENDIF ELSE options = ['Portrait/Landscape', 'Overlay', 'Vecteur' $
269                        , 'Longitude / x index', 'Latitude / y index']
270
271   desc = [ '1\File', $
272            '0\Open' , $
273            '0\New xxx' , $
274            '2\Quit', $
275            '1\Save as' , $
276            '0\PostScript' , $
277            '0\Animated gif' , $
278            '0\Gif' , $
279            '0\IDL procedure', $
280            '0\RESTORE kwd of xxx', $
281            '2\Print to prompt', $
282            '1\Flag options']
283   descsuite = options
284   if n_elements(descsuite) GE 2 then $
285    descsuite[0:n_elements(descsuite)-2] = '0\'+descsuite[0:n_elements(descsuite)-2]
286   descsuite[n_elements(descsuite)-1] = '2\'+descsuite[n_elements(descsuite)-1]
287   desc = [desc, descsuite]
288;
289   menu = cw_pdmenu(base, desc, /RETURN_NAME, uname = 'menubar', uvalue = {name:'menubar'} $
290                    , xoffset = xoff, yoffset = yoff)
291
292;------------------------------------------------------------
293; Ok button
294;------------------------------------------------------------
295  yoff = yoff + 37
296  xoff = 5
297; button 'OK'
298  baseok = widget_button(base, value = ' OK ', uvalue = {name:'ok'}, uname = 'ok button' $
299                         , /frame, xoffset = xoff, yoffset = yoff)
300
301;------------------------------------------------------------
302; Page Layout
303;------------------------------------------------------------
304; page layout
305  xoff = xoff + 65
306  dummyid = cw_pagelayout(base, smallin, /row, /frame, xoffset = xoff, yoffset = yoff)
307;
308;------------------------------------------------------------
309; List of Variables
310;------------------------------------------------------------
311  xoff = xoff + 140
312  currentlistvar = (*fileparameters[currentfile]).listvar
313  vlstid = widget_combobox(base, value = currentlistvar, uvalue = {name:'varlist'} $
314                           , uname = 'varlist', xoffset = xoff, yoffset = yoff+1)
315  if keyword_set(uvalue) then BEGIN
316    selectvar = (extractatt(uvalue, 'varinfo'))[1, numdessinin]
317    selectvar = (where(currentlistvar EQ selectvar))[0]
318    widget_control, vlstid, set_combobox_select = 0 > selectvar
319  ENDIF ELSE selectvar = 0
320;------------------------------------------------------------
321; List of files
322;------------------------------------------------------------
323  yoff = yoff + 35
324  flstid = widget_combobox(base, value = file_basename(filelist), uname = 'filelist' $
325                           , xsize = 345, yoffset = yoff, uvalue = {name:'filelist'})
326  if keyword_set(uvalue) then BEGIN
327    selectfile = (extractatt(uvalue, 'varinfo'))[0, numdessinin]
328    selectfile = (where(file_basename(filelist) EQ selectfile))[0]
329    widget_control, flstid, set_combobox_select = 0 > selectfile
330  ENDIF ELSE selectfile = 0
331;------------------------------------------------------------
332; Text for computation
333;------------------------------------------------------------
334  yoff = yoff + 32
335; computation done on the files...
336  if keyword_set(uvalue) then txtvalue = (extractatt(uvalue, 'txtcmd'))[numdessinin] $
337  ELSE txtvalue = '"' + varexp + '"'
338  dummyid = widget_text(base, value = txtvalue, uvalue = {name:'txtcmd'}, uname = 'txtcmd' $
339                        , /editable, yoffset = yoff, xsize = 54, /frame)
340;------------------------------------------------------------
341; Calendar
342;------------------------------------------------------------
343  yoff = yoff + 40
344  currentcalendar = (*fileparameters[currentfile]).time_counter
345  key_caltype = (*fileparameters[currentfile]).caltype
346  fakecal = (*fileparameters[currentfile]).fakecal
347  if keyword_set(uvalue) then begin
348    dates = (extractatt(uvalue, 'dates'))[*, numdessinin]
349    date1 = date2jul(dates[0])
350    date2 = date2jul(dates[1])
351  ENDIF
352  basecalid = widget_base(base, column = 2, space = 0, yoffset = yoff, uname = 'basecal')
353  dummyid = cw_calendar(basecalid, currentcalendar, date1, FAKECAL = fakecal, uname = 'calendar1', uvalue = {name:'calendar1'}, /frame)
354  dummyid = cw_calendar(basecalid, currentcalendar, date2, FAKECAL = fakecal, uname = 'calendar2', uvalue = {name:'calendar2'}, /frame)
355;------------------------------------------------------------
356; Domain
357;------------------------------------------------------------
358  yoff = yoff + 60
359  vargrid = strupcase((*fileparameters[currentfile]).listgrid[selectvar])
360  IF vargrid EQ 'W' then zgrid = 'W' ELSE zgrid = 'T'
361  if keyword_set(uvalue) then boxzoom = (extractatt(uvalue, 'domaines'))[*, numdessinin]
362  dummyid = cw_domain(base, uname = 'domain', uvalue = {name:'domain'}, /unzoom, /frame $
363                      , boxzoom = boxzoom, yoffset = yoff, xoffset = 15)
364;------------------------------------------------------------
365; Plots specifications
366;------------------------------------------------------------
367  yoff = yoff + 230
368  speid = cw_specifie(base, uname = 'specifie', uvalue = {name:'specifie'}, /frame, /column $
369                      , /forxxx, yoffset = yoff)
370  if keyword_set(uvalue) then BEGIN
371    exextra = *((extractatt(uvalue, 'exextra'))[numdessinin])
372    IF n_elements(exextra) NE 0 THEN widget_control, speid, set_value = exextra
373  ENDIF
374;------------------------------------------------------------
375; drawing part
376;------------------------------------------------------------
377  if keyword_set(separate) then $
378     basegraph = widget_base(title = 'xxx window',  group_leader = base, uvalue = base) $
379  ELSE basegraph = base
380
381  graphid = widget_draw(basegraph, uname = 'graph', /button_events, retain = 2 $
382                        , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $
383                        , xoffset = 350*(1-keyword_set(separate)) $
384                        , xsize = windsize[0], ysize = windsize[1]); , tooltip = 'toto')
385;------------------------------------------------------------
386; realize the widget
387;------------------------------------------------------------
388  widget_control, base, /realize
389  if keyword_set(separate) then begin
390    widget_control, basegraph, /realize
391    xmanager, 'xxx', basegraph, /no_block
392  endif
393
394;------------------------------------------------------------
395  if keyword_set(uvalue) then BEGIN ;
396; We recopy the pointer uvalue in top_uvalue.
397; Beware, we have to redefine completely top_value from variables
398; pointed by uvalue. Otherwise, if we simply do top_value = uvalue,
399; when we delete by uvalue and variables on which it point, we
400; also delete variables on which point top_value.
401    case 1 of
402      keyword_set(redraw):BEGIN
403        top_uvalue = uvalue
404        widget_control, base, set_uvalue = top_uvalue
405; we find homedir
406        homedir = isadirectory(io = homedir, title = 'Bad definition of homedir')
407; We recuperae the list of instructions
408        globalcommand = extractatt(top_uvalue, 'globalcommand')
409; We complete by first and last lines of the program
410        createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
411                   , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript' $
412                   +', PORTRAIT = portrait, LANDSCAPE = landscape' $
413                   , /noerase
414      END
415      keyword_set(restore):begin
416        top_uvalue = uvalue
417        widget_control, base, set_uvalue = top_uvalue
418        widget_control, graphid, get_value = win
419        wshow, win
420        wset, win
421        tv, image, /true
422; widgets's state
423        updatewidget, base
424;
425      END
426      ELSE:BEGIN
427        top_uvalue = ptrarr(2, 29, /allocate_heap)
428        FOR i =  0, 28 do *top_uvalue[0, i] = *uvalue[0, i]
429        FOR i =  0, 14 do *top_uvalue[1, i] = *uvalue[1, i]
430        FOR i = 18, 27 do *top_uvalue[1, i] = *uvalue[1, i]
431        numfile = n_elements(extractatt(uvalue, 'filelist'))
432        *top_uvalue[1, 15] = ptrarr(numfile, /allocate_heap)
433        *top_uvalue[1, 16] = ptrarr(numfile, /allocate_heap)
434        *top_uvalue[1, 17] = ptrarr(numfile, /allocate_heap)
435        for i = 0, numfile-1 do begin
436          *(*top_uvalue[1, 15])[i] = *(*uvalue[1, 15])[i]
437          *(*top_uvalue[1, 16])[i] = *(*uvalue[1, 16])[i]
438          *(*top_uvalue[1, 17])[i] = *(*uvalue[1, 17])[i]
439        endfor
440        *top_uvalue[1, 28] = ptrarr(nbredessin, /allocate_heap)
441        for i = 0, nbredessin-1 do *(*top_uvalue[1, 28])[i] = *(*uvalue[1, 28])[i]
442        widget_control, base, set_uvalue = top_uvalue
443; Copy the screen of the widget of uvalue in top_value's one
444        if keyword_set(CallerWidId)  then begin
445          widget_control, extractatt(uvalue, 'graphid'), get_value = win
446          wshow, win
447          wset, win
448          image = tvrd(/true)
449          widget_control, graphid, get_value = win
450          wshow, win
451          wset, win
452          tv, image, /true
453        ENDIF
454      END
455    endcase
456    *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid
457;
458ENDIF ELSE BEGIN
459; Otherwise we will define all elements we will hook at the widget
460; thanks to the top_value which is a pointer array with 2
461; columns: names and variables.
462; We initialize all these elements.
463; Variables concerning the widget in its generality.
464    if NOT keyword_set(ex)  then ex = {nothing:0}
465; variables se rapportant aux differents fichiers que l''on peut lire
466; variables specifiques a chaque dessin
467;
468
469; creation of the pointer we will hook at the widget.
470    top_uvalue = ptrarr(2, 29, /allocate_heap)
471; variables refering to the widget
472    *top_uvalue[0, 0] = 'options' & *top_uvalue[1, 0] = options
473    *top_uvalue[0, 1] = 'smallin' & *top_uvalue[1, 1] = smallin
474    *top_uvalue[0, 2] = 'smallout' & *top_uvalue[1, 2] = smallout
475    *top_uvalue[0, 3] = 'graphid' & *top_uvalue[1, 3] = graphid
476    *top_uvalue[0, 4] = 'alreadyvector' & *top_uvalue[1, 4] = -1
477    *top_uvalue[0, 5] = 'alreadyover' & *top_uvalue[1, 5] = -1
478    *top_uvalue[0, 6] = 'alreadyread' & *top_uvalue[1, 6] = -1
479    *top_uvalue[0, 7] = 'currentreadcmd' & *top_uvalue[1, 7] = ''
480    *top_uvalue[0, 8] = 'globalcommand' & *top_uvalue[1, 8] = ''
481    *top_uvalue[0, 9] = 'globaloldcommand' & *top_uvalue[1, 9] = ''
482    *top_uvalue[0, 10] = 'no more used' & *top_uvalue[1, 10] = 9999
483    *top_uvalue[0, 11] = 'noticebase' & *top_uvalue[1, 11] = 0l
484    *top_uvalue[0, 12] = 'extra' & *top_uvalue[1, 12] = ex
485; variables refering to different files we can read
486    *top_uvalue[0, 13] = 'currentfile' & *top_uvalue[1, 13] = currentfile
487    *top_uvalue[0, 14] = 'filelist' & *top_uvalue[1, 14] = filelist
488    *top_uvalue[0, 15] = 'fileparameters' & *top_uvalue[1, 15] = fileparameters
489    *top_uvalue[0, 16] = 'readparameters' & *top_uvalue[1, 16] = readparameters
490    *top_uvalue[0, 17] = 'meshparameters' & *top_uvalue[1, 17] = meshparameters
491; variables refering to different drawing we can do
492    *top_uvalue[0, 18] = 'penvs' & *top_uvalue[1, 18] = replicate(!p, nbredessin)
493    *top_uvalue[0, 19] = 'xenvs' & *top_uvalue[1, 19] = replicate(!x, nbredessin)
494    *top_uvalue[0, 20] = 'yenvs' & *top_uvalue[1, 20] = replicate(!y, nbredessin)
495    *top_uvalue[0, 21] = 'nameprocedures' & *top_uvalue[1, 21] = strarr(nbredessin)
496    *top_uvalue[0, 22] = 'types' & *top_uvalue[1, 22] = strarr(nbredessin)
497    *top_uvalue[0, 23] = 'varinfo' & *top_uvalue[1, 23] = strarr(2, nbredessin)
498    *top_uvalue[0, 24] = 'domaines' & *top_uvalue[1, 24] = fltarr(6, nbredessin)
499    *top_uvalue[0, 25] = 'dates' & *top_uvalue[1, 25] = lonarr(2, nbredessin)
500    *top_uvalue[0, 26] = 'txtcmd' & *top_uvalue[1, 26] = strarr(nbredessin)
501    *top_uvalue[0, 27] = 'optionsflag' & *top_uvalue[1, 27] = flag
502    *top_uvalue[0, 28] = 'exextra' & *top_uvalue[1, 28] = ptrarr(nbredessin, /allocate_heap)
503;
504    widget_control, base, set_uvalue = top_uvalue
505    createhistory, base, smallin
506;
507  ENDELSE
508;------------------------------------------------------------
509  xmanager, 'xxx', base, /no_block
510;------------------------------------------------------------
511;------------------------------------------------------------
512  return
513end
Note: See TracBrowser for help on using the repository browser.