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