[2] | 1 | pro xcreateanim_event, event |
---|
[114] | 2 | ; |
---|
| 3 | compile_opt idl2, strictarrsubs |
---|
| 4 | ; |
---|
[2] | 5 | @common |
---|
| 6 | ; on recupere les aguments contenus ds le widget |
---|
[74] | 7 | if tag_names(event, /structure_name) NE 'WIDGET_BUTTON' then return |
---|
| 8 | widget_control, event.id, get_uvalue = uval |
---|
| 9 | if n_elements(uval) EQ 0 then return |
---|
| 10 | if uval EQ 'cancel' then begin |
---|
| 11 | widget_control, event.top, /destroy |
---|
| 12 | return |
---|
| 13 | ENDIF |
---|
[2] | 14 | ; on va ecrire l''animation! |
---|
| 15 | ; |
---|
[74] | 16 | widget_control, event.top, get_uvalue = local_uvalue |
---|
| 17 | widget_control, local_uvalue.parent, get_uvalue = top_uvalue |
---|
[2] | 18 | ; |
---|
[74] | 19 | calendar = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).time_counter |
---|
| 20 | key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).caltype |
---|
| 21 | fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[local_uvalue.indexfile]).fakecal |
---|
[2] | 22 | ; |
---|
[74] | 23 | widget_control, widget_info(event.top, find_by_uname = 'Filename') $ |
---|
| 24 | , get_value = nomfic & nomfic = nomfic[0] |
---|
[2] | 25 | ; |
---|
[74] | 26 | widget_control, widget_info(event.top, find_by_uname = 'directorie') $ |
---|
| 27 | , get_value = animdir & animdir = animdir[0] |
---|
[2] | 28 | ; |
---|
[74] | 29 | widget_control, widget_info(event.top, find_by_uname = 'debut') $ |
---|
| 30 | , get_value = vdate1 |
---|
| 31 | index1 = where(calendar eq date2jul(vdate1)) & index1 = index1[0] |
---|
| 32 | if index1 EQ -1 then return |
---|
[2] | 33 | ; |
---|
[74] | 34 | widget_control, widget_info(event.handler, find_by_uname = 'fin') $ |
---|
| 35 | , get_value = vdate2 |
---|
| 36 | index2 = where(calendar eq date2jul(vdate2)) & index2 = index2[0] |
---|
| 37 | if index2 EQ -1 OR index2 LE index1 then return |
---|
[2] | 38 | ; on detruit le widget avant de creer le fichier .ps |
---|
[74] | 39 | widget_control, event.top, /destroy |
---|
[2] | 40 | ; |
---|
| 41 | ; creation de la routine qui nous serviera pour faire le dessin |
---|
| 42 | ; |
---|
| 43 | ; on recupere la liste des instructions |
---|
[74] | 44 | globalcommand = extractatt(top_uvalue, 'globalcommand') |
---|
[2] | 45 | ; on complete par le premiere et les dernieres lignes du programme |
---|
[74] | 46 | createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $ |
---|
| 47 | , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript, DATE1IN = date1in, DATE2IN = date2in' |
---|
[2] | 48 | ; |
---|
| 49 | ;--------creation du fichier---------- |
---|
| 50 | ; |
---|
| 51 | ; recupere le nombre d'octets surlequel on code la palette |
---|
[74] | 52 | device, get_visual_depth = depth |
---|
[2] | 53 | ; taille de l''image (en nombre de pixel: |
---|
[74] | 54 | xsize = !d.x_size |
---|
| 55 | ysize = !d.y_size |
---|
[2] | 56 | ; |
---|
| 57 | ; on verifie que le nom du fichier termine bien par .gif |
---|
[74] | 58 | if strpos(nomfic, '.gif') EQ -1 then nomfic = nomfic+'.gif' |
---|
[2] | 59 | |
---|
[74] | 60 | current_window = !d.window |
---|
| 61 | window, /free, /pixmap, xsize = xsize, ysize = ysize |
---|
[2] | 62 | |
---|
| 63 | |
---|
| 64 | ; indication du numero de l''image que l''on est en train de creer |
---|
[74] | 65 | base = widget_base() |
---|
| 66 | sliderid = widget_slider(base, minimum = 1, maximum = index2-index1+1, value = 1 $ |
---|
| 67 | , title = 'image number: ') |
---|
| 68 | widget_control, base, /realize |
---|
[2] | 69 | ; |
---|
| 70 | ; commencement du fichier gif. ecriture d''une image vide |
---|
[74] | 71 | IF keyword_set(fakecal) THEN date = index1 ELSE date = jul2date(calendar[index1]) |
---|
| 72 | xxx2ps, /noerase, date1in = date, date2in = date |
---|
[2] | 73 | ; |
---|
| 74 | ; |
---|
[74] | 75 | image = tvrd(true = depth GT 8) |
---|
[2] | 76 | ;- If an 8-bit image was read, reduce the number of colors |
---|
[74] | 77 | if depth le 8 then begin |
---|
| 78 | tvlct, red, green, blue, /get |
---|
| 79 | reduce_colors, image, index |
---|
| 80 | red = red[index] |
---|
| 81 | green = green[index] |
---|
| 82 | blue = blue[index] |
---|
| 83 | endif |
---|
[2] | 84 | ; |
---|
[74] | 85 | if depth gt 8 then $ |
---|
[2] | 86 | ;- Convert 24-bit image to 8-bit |
---|
[74] | 87 | image = color_quan(image, 1, red, green, blue, colors = 256, get_translation = translation, /map_all) |
---|
[2] | 88 | ; |
---|
| 89 | ; |
---|
[74] | 90 | write_gif, animdir+nomfic, image, red, green, blue, /multiple |
---|
| 91 | wdelete, !d.window |
---|
[2] | 92 | ; |
---|
| 93 | ; boucle de creation et d''ecriture ds le fichier. |
---|
| 94 | ; |
---|
[74] | 95 | IF index2 GT index1 THEN BEGIN |
---|
| 96 | FOR ind = index1+1, index2 do BEGIN |
---|
[2] | 97 | ; |
---|
| 98 | widget_control, sliderid, set_value = ind-index1+1 ; on bouge le slider |
---|
| 99 | ; |
---|
[74] | 100 | window, /free, /pixmap, xsize = xsize, ysize = ysize |
---|
| 101 | IF keyword_set(fakecal) THEN date = ind ELSE date = jul2date(calendar[ind]) |
---|
[2] | 102 | xxx2ps, /noerase, date1 = date, date2 = date |
---|
| 103 | ; |
---|
| 104 | image = tvrd(true = depth GT 8) |
---|
| 105 | ; |
---|
| 106 | if depth gt 8 then $ |
---|
[74] | 107 | image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ; |
---|
[2] | 108 | ; |
---|
[74] | 109 | write_gif, animdir+nomfic, image, red, green, blue, /multiple |
---|
[2] | 110 | wdelete, !d.window |
---|
[74] | 111 | ENDFOR |
---|
| 112 | ENDIF |
---|
[2] | 113 | ; on met une derniere image blanche |
---|
[74] | 114 | window, /free, /pixmap, xsize = xsize, ysize = ysize |
---|
| 115 | reinitplt |
---|
| 116 | plot, [0], [0], /nodata |
---|
| 117 | image = tvrd(true = depth GT 8) |
---|
[2] | 118 | ; |
---|
[74] | 119 | if depth gt 8 then $ |
---|
| 120 | image = color_quan(image, 1, aaa, bbb, ccc, colors = 256, translation = translation) ; |
---|
[2] | 121 | ; |
---|
[74] | 122 | write_gif, animdir+nomfic, image, red, green, blue, /multiple |
---|
| 123 | wdelete, !d.window |
---|
[2] | 124 | ; fermeture du fichier |
---|
[74] | 125 | write_gif, animdir+nomfic, /close |
---|
| 126 | widget_control, base, /destroy |
---|
[2] | 127 | ; rebascule en mode "normal" |
---|
[74] | 128 | thisOS = strupcase(strmid(!version.os_family, 0, 3)) |
---|
[2] | 129 | ; |
---|
[74] | 130 | wset, current_window |
---|
[2] | 131 | |
---|
| 132 | ; si on est sous x on essaie de lancer xanim... |
---|
| 133 | |
---|
[74] | 134 | if thisOS NE 'MAC' AND thisOS NE 'WIN' then begin |
---|
| 135 | spawn, 'which xanim', result |
---|
| 136 | if strpos(result[0], 'xanim') EQ strlen(result[0])-5 then spawn, 'xanim '+animdir+nomfic+' &' |
---|
| 137 | endif |
---|
[2] | 138 | ; |
---|
[74] | 139 | |
---|
| 140 | return |
---|
[2] | 141 | end |
---|
| 142 | ;---------------------------------------------------------------- |
---|
| 143 | PRO xcreateanim, parent |
---|
[114] | 144 | ; |
---|
| 145 | compile_opt idl2, strictarrsubs |
---|
| 146 | ; |
---|
[2] | 147 | @common |
---|
| 148 | ; |
---|
| 149 | widget_control, parent, get_uvalue = top_uvalue |
---|
| 150 | ; |
---|
| 151 | ; on va s''assurer que toutes les procedures de sont pas pltt |
---|
| 152 | ; |
---|
| 153 | procedures = extractatt(top_uvalue, 'nameprocedures') |
---|
| 154 | if total(procedures EQ 'pltt') NE 0 then begin |
---|
| 155 | nothing = report('Certains des plots ont un axe se rapportant au temps. !C Animation impossible!', /error) |
---|
| 156 | return |
---|
| 157 | ENDIF |
---|
| 158 | ; |
---|
| 159 | ; on va s''assurer que toutes les figures ont le meme calendrier |
---|
| 160 | ; |
---|
| 161 | filelist = extractatt(top_uvalue, 'filelist') |
---|
[69] | 162 | filenames = (extractatt(top_uvalue, 'varinfo'))[0, *] |
---|
[2] | 163 | filenames = reform(filenames) |
---|
| 164 | filenames = filenames[uniq(filenames, sort(filenames))] |
---|
| 165 | if strtrim(filenames[0], 1) EQ '' then filenames = filenames[1:n_elements(filenames)-1] |
---|
| 166 | indexfile = (where(filelist EQ filenames[0]))[0] |
---|
| 167 | calendar = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).time_counter |
---|
[74] | 168 | key_caltype = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).caltype |
---|
| 169 | fakecal = (*(extractatt(top_uvalue, 'fileparameters'))[indexfile]).fakecal |
---|
[2] | 170 | if n_elements(filenames) GT 1 then begin |
---|
| 171 | for i = 1, n_elements(filenames)-1 do begin |
---|
| 172 | indexfilebis = (where(filelist EQ filenames[i]))[0] |
---|
| 173 | calendarbis = (*(extractatt(top_uvalue, 'fileparameters'))[indexfilebis]).time_counter |
---|
| 174 | if n_elements(calendarbis) NE n_elements(calendar) then begin |
---|
| 175 | nothing = report('Les diffrents plots n''utilisent pas le meme calendrier. !C Animation impossible!', /error) |
---|
| 176 | return |
---|
| 177 | ENDIF |
---|
| 178 | if total(calendar NE calendarbis) NE 0 then begin |
---|
| 179 | nothing = report('Les diffrents plots n''utilisent pas le meme calendrier. !C Animation impossible!', /error) |
---|
| 180 | return |
---|
| 181 | endif |
---|
| 182 | endfor |
---|
| 183 | endif |
---|
| 184 | ; |
---|
| 185 | ; c''est possible de faire une animation |
---|
| 186 | ; |
---|
[69] | 187 | base = widget_base(/column, title = 'animation creation', uvalue = {parent:parent, indexfile:indexfile}) |
---|
| 188 | rien = widget_label(base, value = 'animation name') |
---|
[2] | 189 | rien = widget_text(base,value='anim_idl.gif', uname='Filename', /editable) |
---|
[69] | 190 | rien = widget_label(base, value = 'animation directory') |
---|
[2] | 191 | if n_elements(animdir) EQ 0 then cd, current = animdir |
---|
| 192 | rien = widget_text(base,value=animdir, uname='directorie', /editable) |
---|
[69] | 193 | rien = widget_label(base, value = 'starting date') |
---|
[74] | 194 | rien = cw_calendar(base, calendar, calendar[0] $ |
---|
| 195 | , FAKECAL = fakecal, uname = 'debut', uvalue = {name:'calendar'}, /frame) |
---|
[69] | 196 | rien = widget_label(base, value = 'ending date') |
---|
[2] | 197 | rien = cw_calendar(base, calendar, calendar[n_elements(calendar)-1] $ |
---|
[74] | 198 | , FAKECAL = fakecal, uname = 'fin', uvalue = {name:'calendar'}, /frame) |
---|
[2] | 199 | rien = widget_button(base,value='OK', uvalue = 'ok') |
---|
| 200 | rien = widget_button(base,value='Cancel', uvalue = 'cancel') |
---|
| 201 | ; |
---|
| 202 | widget_control,base,/realize |
---|
| 203 | xmanager,'xcreateanim', base, /no_block |
---|
| 204 | |
---|
| 205 | return |
---|
| 206 | end |
---|