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

Last change on this file since 325 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: 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;-
156PRO xxx, datafilename, idlfile, argspro, CALLERWIDID = callerwidid $
157         , REDRAW = redraw, SEPARATE = separate, UVALUE = uvalue $
158         , RESTORE = restore, _EXTRA = ex
159;
160  compile_opt idl2, strictarrsubs
161;
162@all_cm
163;------------------------------------------------------------
164; reinitialize the !p, !x, !y, !z variables
165;------------------------------------------------------------
166  reinitplt
167;------------------------------------------------------------
168; we get back the uvalue of the widget that called xxx to create a new widget
169  if keyword_set(restore) then BEGIN
170    restore = isafile(filename = restore, iodir = homedir, _extra = ex)
171    if size(restore, /type) NE 7 then restore = 0 ELSE BEGIN
172      restore, isafile(file = restore, iodir = homedir, _extra = ex)
173      newgrid = *(extractatt(uvalue, 'meshparameters'))[0]
174      change = changegrid(newgrid)
175    ENDELSE
176  endif
177  if n_elements(CallerWidId) NE 0 THEN $
178     widget_control, CallerWidId, get_uvalue = uvalue ELSE CallerWidId = 0
179;------------------------------------------------------------
180;------------------------------------------------------------
181; list of files we want to look at
182;
183  if keyword_set(uvalue) then BEGIN
184    currentfile = extractatt(uvalue, 'currentfile')
185    filelist = extractatt(uvalue, 'filelist')
186    fileparameters = extractatt(uvalue, 'fileparameters')
187    readparameters = extractatt(uvalue, 'readparameters')
188    meshparameters = extractatt(uvalue, 'meshparameters')
189  ENDIF ELSE BEGIN
190    newfile = selectfile(datafilename, idlfile, argspro, _extra = ex)
191    if size(newfile, /type) NE 8 then return
192    fileparameters = ptrarr(1, /allocate_heap)
193    *fileparameters[0] = newfile.fileparameters
194    readparameters = ptrarr(1, /allocate_heap)
195    *readparameters[0] = newfile.readparameters
196    meshparameters = ptrarr(1, /allocate_heap)
197    *meshparameters[0] = newfile.meshparameters
198    currentfile = 0
199    filelist = newfile.fileparameters.filename
200  ENDELSE
201;
202  if keyword_set(uvalue) THEN BEGIN
203    smallin = extractatt(uvalue, 'smallin')
204    smallout = extractatt(uvalue, 'smallout')
205  ENDIF ELSE BEGIN
206    smallin = [1, 1, 1]
207    smallout = [1, 1, 1]
208  ENDELSE
209  nbredessin = smallin[0]*smallin[1]
210  numdessinin = smallin[2]-1
211; warning flg definition must be consistent with cw_pdmenu argument
212; see also flag definition in cw_pagelayout
213  if keyword_set(uvalue) then BEGIN
214    flag = extractatt(uvalue, 'optionsflag')
215    key_portrait = flag[0, numdessinin]
216  ENDIF ELSE flag = [key_portrait, 0, 0, 0, 0]#replicate(1, nbredessin)
217
218;------------------------------------------------------------
219;------------------------------------------------------------
220; We start the widget definition
221;------------------------------------------------------------
222;------------------------------------------------------------
223;
224; widget and screen size
225  scrsize = get_screen_size()*0.95
226  windsize = givewindowsize()
227  xxxsize = [windsize[0] * (1-keyword_set(separate)) + 350, windsize[1]]
228;
229;------------------------------------------------------------
230; The top base
231;------------------------------------------------------------
232  IF xxxsize[0] LE scrsize[0] AND xxxsize[1] LE scrsize[1] THEN BEGIN
233    base = widget_base(title = 'xxx', GROUP_LEADER = group, /tracking_events $
234                       , uname = 'base', space = 0)
235  ENDIF ELSE BEGIN
236    base = widget_base(title = 'xxx', GROUP_LEADER = group, /tracking_events $
237                       , uname = 'base', space = 0 $
238                       , xsize = xxxsize[0], ysize = xxxsize[1] $
239                       , x_scroll_size = (xxxsize[0] < scrsize[0]) $
240                       , y_scroll_size = (xxxsize[1] < scrsize[1]))
241  ENDELSE
242
243;------------------------------------------------------------
244; combobox for plots choice
245;------------------------------------------------------------
246  xoff = 0
247  yoff = 0
248  pltlst = ['plt', 'pltv' $
249            , 'pltz', 'pltz diag up', 'pltz diag dn' $
250            , 'pltt', 'pltt diag up', 'pltt diag dn' $
251            , 'xy', 'xz', 'yz', 'xt', 'yt', 'zt' $
252            , 'x', 'y', 'z', 't']
253  actid = widget_combobox(base, value = pltlst, uname = 'action', uvalue = {name:'action'} $
254                            , xoffset = xoff+5, yoffset = yoff+4, xsize = 90)
255  if keyword_set(uvalue) then BEGIN
256    selectact = (extractatt(uvalue, 'types'))[numdessinin]
257    selectact = (where(pltlst EQ selectact))[0]
258    widget_control, actid, set_combobox_select = 0 > selectact
259  ENDIF ELSE selectfile = 0
260
261;------------------------------------------------------------
262; menu/options
263;------------------------------------------------------------
264  xoff = xoff + 110
265  if keyword_set(uvalue) then begin
266    options = extractatt(uvalue, 'options')
267  ENDIF ELSE options = ['Portrait/Landscape', 'Overlay', 'Vecteur' $
268                        , 'Longitude / x index', 'Latitude / y index']
269
270   desc = [ '1\File', $
271            '0\Open' , $
272            '0\New xxx' , $
273            '2\Quit', $
274            '1\Save as' , $
275            '0\PostScript' , $
276            '0\Animated gif' , $
277            '0\Gif' , $
278            '0\IDL procedure', $
279            '0\RESTORE kwd of xxx', $
280            '2\Print to prompt', $
281            '1\Flag options']
282   descsuite = options
283   if n_elements(descsuite) GE 2 then $
284    descsuite[0:n_elements(descsuite)-2] = '0\'+descsuite[0:n_elements(descsuite)-2]
285   descsuite[n_elements(descsuite)-1] = '2\'+descsuite[n_elements(descsuite)-1]
286   desc = [desc, descsuite]
287;
288   menu = cw_pdmenu(base, desc, /RETURN_NAME, uname = 'menubar', uvalue = {name:'menubar'} $
289                    , xoffset = xoff, yoffset = yoff)
290
291;------------------------------------------------------------
292; Ok button
293;------------------------------------------------------------
294  yoff = yoff + 37
295  xoff = 5
296; button 'OK'
297  baseok = widget_button(base, value = ' OK ', uvalue = {name:'ok'}, uname = 'ok button' $
298                         , /frame, xoffset = xoff, yoffset = yoff)
299
300;------------------------------------------------------------
301; Page Layout
302;------------------------------------------------------------
303; page layout
304  xoff = xoff + 65
305  dummyid = cw_pagelayout(base, smallin, /row, /frame, xoffset = xoff, yoffset = yoff)
306;
307;------------------------------------------------------------
308; List of Variables
309;------------------------------------------------------------
310  xoff = xoff + 140
311  currentlistvar = (*fileparameters[currentfile]).listvar
312  vlstid = widget_combobox(base, value = currentlistvar, uvalue = {name:'varlist'} $
313                           , uname = 'varlist', xoffset = xoff, yoffset = yoff+1)
314  if keyword_set(uvalue) then BEGIN
315    selectvar = (extractatt(uvalue, 'varinfo'))[1, numdessinin]
316    selectvar = (where(currentlistvar EQ selectvar))[0]
317    widget_control, vlstid, set_combobox_select = 0 > selectvar
318  ENDIF ELSE selectvar = 0
319;------------------------------------------------------------
320; List of files
321;------------------------------------------------------------
322  yoff = yoff + 35
323  flstid = widget_combobox(base, value = file_basename(filelist), uname = 'filelist' $
324                           , xsize = 345, yoffset = yoff, uvalue = {name:'filelist'})
325  if keyword_set(uvalue) then BEGIN
326    selectfile = (extractatt(uvalue, 'varinfo'))[0, numdessinin]
327    selectfile = (where(file_basename(filelist) EQ selectfile))[0]
328    widget_control, flstid, set_combobox_select = 0 > selectfile
329  ENDIF ELSE selectfile = 0
330;------------------------------------------------------------
331; Text for computation
332;------------------------------------------------------------
333  yoff = yoff + 32
334; computation done on the files...
335  if keyword_set(uvalue) then txtvalue = (extractatt(uvalue, 'txtcmd'))[numdessinin] $
336  ELSE txtvalue = '"' + varexp + '"'
337  dummyid = widget_text(base, value = txtvalue, uvalue = {name:'txtcmd'}, uname = 'txtcmd' $
338                        , /editable, yoffset = yoff, xsize = 54, /frame)
339;------------------------------------------------------------
340; Calendar
341;------------------------------------------------------------
342  yoff = yoff + 40
343  currentcalendar = (*fileparameters[currentfile]).time_counter
344  key_caltype = (*fileparameters[currentfile]).caltype
345  fakecal = (*fileparameters[currentfile]).fakecal
346  if keyword_set(uvalue) then begin
347    dates = (extractatt(uvalue, 'dates'))[*, numdessinin]
348    date1 = date2jul(dates[0])
349    date2 = date2jul(dates[1])
350  ENDIF
351  basecalid = widget_base(base, column = 2, space = 0, yoffset = yoff, uname = 'basecal')
352  dummyid = cw_calendar(basecalid, currentcalendar, date1, FAKECAL = fakecal, uname = 'calendar1', uvalue = {name:'calendar1'}, /frame)
353  dummyid = cw_calendar(basecalid, currentcalendar, date2, FAKECAL = fakecal, uname = 'calendar2', uvalue = {name:'calendar2'}, /frame)
354;------------------------------------------------------------
355; Domain
356;------------------------------------------------------------
357  yoff = yoff + 60
358  vargrid = strupcase((*fileparameters[currentfile]).listgrid[selectvar])
359  IF vargrid EQ 'W' then zgrid = 'W' ELSE zgrid = 'T'
360  if keyword_set(uvalue) then boxzoom = (extractatt(uvalue, 'domaines'))[*, numdessinin]
361  dummyid = cw_domain(base, uname = 'domain', uvalue = {name:'domain'}, /unzoom, /frame $
362                      , boxzoom = boxzoom, yoffset = yoff, xoffset = 15)
363;------------------------------------------------------------
364; Plots specifications
365;------------------------------------------------------------
366  yoff = yoff + 230
367  speid = cw_specifie(base, uname = 'specifie', uvalue = {name:'specifie'}, /frame, /column $
368                      , /forxxx, yoffset = yoff)
369  if keyword_set(uvalue) then BEGIN
370    exextra = *((extractatt(uvalue, 'exextra'))[numdessinin])
371    IF n_elements(exextra) NE 0 THEN widget_control, speid, set_value = exextra
372  ENDIF
373;------------------------------------------------------------
374; drawing part
375;------------------------------------------------------------
376  if keyword_set(separate) then $
377     basegraph = widget_base(title = 'xxx window',  group_leader = base, uvalue = base) $
378  ELSE basegraph = base
379
380  graphid = widget_draw(basegraph, uname = 'graph', /button_events, retain = 2 $
381                        , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $
382                        , xoffset = 350*(1-keyword_set(separate)) $
383                        , xsize = windsize[0], ysize = windsize[1]); , tooltip = 'toto')
384;------------------------------------------------------------
385; realize the widget
386;------------------------------------------------------------
387  widget_control, base, /realize
388  if keyword_set(separate) then begin
389    widget_control, basegraph, /realize
390    xmanager, 'xxx', basegraph, /no_block
391  endif
392
393;------------------------------------------------------------
394  if keyword_set(uvalue) then BEGIN ;
395; We recopy the pointer uvalue in top_uvalue.
396; Beware, we have to redefine completely top_value from variables
397; pointed by uvalue. Otherwise, if we simply do top_value = uvalue,
398; when we delete by uvalue and variables on which it point, we
399; also delete variables on which point top_value.
400    case 1 of
401      keyword_set(redraw):BEGIN
402        top_uvalue = uvalue
403        widget_control, base, set_uvalue = top_uvalue
404; we find homedir
405        homedir = isadirectory(io = homedir, title = 'Bad definition of homedir')
406; We recuperae the list of instructions
407        globalcommand = extractatt(top_uvalue, 'globalcommand')
408; We complete by first and last lines of the program
409        createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
410                   , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript' $
411                   +', PORTRAIT = portrait, LANDSCAPE = landscape' $
412                   , /noerase
413      END
414      keyword_set(restore):begin
415        top_uvalue = uvalue
416        widget_control, base, set_uvalue = top_uvalue
417        widget_control, graphid, get_value = win
418        wshow, win
419        wset, win
420        tv, image, /true
421; widgets's state
422        updatewidget, base
423;
424      END
425      ELSE:BEGIN
426        top_uvalue = ptrarr(2, 29, /allocate_heap)
427        FOR i =  0, 28 do *top_uvalue[0, i] = *uvalue[0, i]
428        FOR i =  0, 14 do *top_uvalue[1, i] = *uvalue[1, i]
429        FOR i = 18, 27 do *top_uvalue[1, i] = *uvalue[1, i]
430        numfile = n_elements(extractatt(uvalue, 'filelist'))
431        *top_uvalue[1, 15] = ptrarr(numfile, /allocate_heap)
432        *top_uvalue[1, 16] = ptrarr(numfile, /allocate_heap)
433        *top_uvalue[1, 17] = ptrarr(numfile, /allocate_heap)
434        for i = 0, numfile-1 do begin
435          *(*top_uvalue[1, 15])[i] = *(*uvalue[1, 15])[i]
436          *(*top_uvalue[1, 16])[i] = *(*uvalue[1, 16])[i]
437          *(*top_uvalue[1, 17])[i] = *(*uvalue[1, 17])[i]
438        endfor
439        *top_uvalue[1, 28] = ptrarr(nbredessin, /allocate_heap)
440        for i = 0, nbredessin-1 do *(*top_uvalue[1, 28])[i] = *(*uvalue[1, 28])[i]
441        widget_control, base, set_uvalue = top_uvalue
442; Copy the screen of the widget of uvalue in top_value's one
443        if keyword_set(CallerWidId)  then begin
444          widget_control, extractatt(uvalue, 'graphid'), get_value = win
445          wshow, win
446          wset, win
447          image = tvrd(/true)
448          widget_control, graphid, get_value = win
449          wshow, win
450          wset, win
451          tv, image, /true
452        ENDIF
453      END
454    endcase
455    *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid
456;
457ENDIF ELSE BEGIN
458; Otherwise we will define all elements we will hook at the widget
459; thanks to the top_value which is a pointer array with 2
460; columns: names and variables.
461; We initialize all these elements.
462; Variables concerning the widget in its generality.
463    if NOT keyword_set(ex)  then ex = {nothing:0}
464; variables se rapportant aux differents fichiers que l''on peut lire
465; variables specifiques a chaque dessin
466;
467
468; creation of the pointer we will hook at the widget.
469    top_uvalue = ptrarr(2, 29, /allocate_heap)
470; variables refering to the widget
471    *top_uvalue[0, 0] = 'options' & *top_uvalue[1, 0] = options
472    *top_uvalue[0, 1] = 'smallin' & *top_uvalue[1, 1] = smallin
473    *top_uvalue[0, 2] = 'smallout' & *top_uvalue[1, 2] = smallout
474    *top_uvalue[0, 3] = 'graphid' & *top_uvalue[1, 3] = graphid
475    *top_uvalue[0, 4] = 'alreadyvector' & *top_uvalue[1, 4] = -1
476    *top_uvalue[0, 5] = 'alreadyover' & *top_uvalue[1, 5] = -1
477    *top_uvalue[0, 6] = 'alreadyread' & *top_uvalue[1, 6] = -1
478    *top_uvalue[0, 7] = 'currentreadcmd' & *top_uvalue[1, 7] = ''
479    *top_uvalue[0, 8] = 'globalcommand' & *top_uvalue[1, 8] = ''
480    *top_uvalue[0, 9] = 'globaloldcommand' & *top_uvalue[1, 9] = ''
481    *top_uvalue[0, 10] = 'no more used' & *top_uvalue[1, 10] = 9999
482    *top_uvalue[0, 11] = 'noticebase' & *top_uvalue[1, 11] = 0l
483    *top_uvalue[0, 12] = 'extra' & *top_uvalue[1, 12] = ex
484; variables refering to different files we can read
485    *top_uvalue[0, 13] = 'currentfile' & *top_uvalue[1, 13] = currentfile
486    *top_uvalue[0, 14] = 'filelist' & *top_uvalue[1, 14] = filelist
487    *top_uvalue[0, 15] = 'fileparameters' & *top_uvalue[1, 15] = fileparameters
488    *top_uvalue[0, 16] = 'readparameters' & *top_uvalue[1, 16] = readparameters
489    *top_uvalue[0, 17] = 'meshparameters' & *top_uvalue[1, 17] = meshparameters
490; variables refering to different drawing we can do
491    *top_uvalue[0, 18] = 'penvs' & *top_uvalue[1, 18] = replicate(!p, nbredessin)
492    *top_uvalue[0, 19] = 'xenvs' & *top_uvalue[1, 19] = replicate(!x, nbredessin)
493    *top_uvalue[0, 20] = 'yenvs' & *top_uvalue[1, 20] = replicate(!y, nbredessin)
494    *top_uvalue[0, 21] = 'nameprocedures' & *top_uvalue[1, 21] = strarr(nbredessin)
495    *top_uvalue[0, 22] = 'types' & *top_uvalue[1, 22] = strarr(nbredessin)
496    *top_uvalue[0, 23] = 'varinfo' & *top_uvalue[1, 23] = strarr(2, nbredessin)
497    *top_uvalue[0, 24] = 'domaines' & *top_uvalue[1, 24] = fltarr(6, nbredessin)
498    *top_uvalue[0, 25] = 'dates' & *top_uvalue[1, 25] = lonarr(2, nbredessin)
499    *top_uvalue[0, 26] = 'txtcmd' & *top_uvalue[1, 26] = strarr(nbredessin)
500    *top_uvalue[0, 27] = 'optionsflag' & *top_uvalue[1, 27] = flag
501    *top_uvalue[0, 28] = 'exextra' & *top_uvalue[1, 28] = ptrarr(nbredessin, /allocate_heap)
502;
503    widget_control, base, set_uvalue = top_uvalue
504    createhistory, base, smallin
505;
506  ENDELSE
507;------------------------------------------------------------
508  xmanager, 'xxx', base, /no_block
509;------------------------------------------------------------
510;------------------------------------------------------------
511  return
512end
Note: See TracBrowser for help on using the repository browser.