; IDL> testwid ; PRO testwid_event, event ; ; help, event, /struct ; Id = widget_info(event.top,find_by_uname = 'c''est lui') ; widget_control, event.id, get_uvalue=uval ; if n_elements(uval) EQ 0 then return ; case uval of ; 'done':widget_control, event.top, /destroy ; 'set':BEGIN ; widget_control, event.id, get_value = value & value = value[0] ; nothing = execute('boite ='+value) ; widget_control, Id, set_value = boite ; END ; 'get':BEGIN ; widget_control, Id, get_value = value ; print, value ; END ; ELSE: ; endcase ; return ; end ; PRO testwid, _extra = ex ; base=widget_base(/COLUMN) ; print, 'base=', base ; nothing = widget_label(base, value = 'beginning of the test') ; ; ; nothing = cw_domain(base,_extra = ex, uname = 'c''est lui', uvalue = 'c''est lui') ; print, 'cw_domain ID =', nothing ; ; ; nothing = widget_label(base, value = 'end of the test') ; nothing = widget_text(base, value = '[40, 100, -10, 10]', uvalue = 'set', /editable) ; nothing = widget_button(base, value = 'get', uvalue = 'get') ; nothing = widget_button(base, value = 'done', uvalue = 'done') ; widget_control, base, /REALIZE ; xmanager,'testwid', base ; return ; end ; ; ;********************************************************************* pro cw_domain_set_value, id, value @common ;------------------------------------------------ ; quel est le type de boite? topid = findtopid(id) widget_control, topid, get_uvalue=top_uvalue currentplot = (extractatt(top_uvalue, 'petitin'))[2]-1 options = extractatt(top_uvalue, 'options') flags = extractatt(top_uvalue, 'optionsflag') flags = flags[*, currentplot] IF (flags[where(options EQ 'Longitude / x index')])[0] EQ 0 THEN $ xtype = 'geographic' ELSE xtype = 'index' IF (flags[where(options EQ 'Latitude / y index')])[0] EQ 0 THEN $ ytype = 'geographic' ELSE ytype = 'index' ;------------------------------------------------ ; comment completer la boite? IF xtype EQ 'geographic' then begin lonn1 = lon1 lonn2 = lon2 xtitle = 'lon' ENDIF ELSE BEGIN lonn1 = premierxt lonn2 = dernierxt xtitle = 'x index' ENDELSE IF ytype EQ 'geographic' then begin latt1 = lat1 latt2 = lat2 ytitle = 'lat' ENDIF ELSE BEGIN latt1 = premieryt latt2 = dernieryt ytitle = 'y index' ENDELSE ;------------------------------------------------ proff1 = floor(min([gdepw[0], gdept[0]])) proff2 = ceil(max([gdepw[0], gdept[0]])) ;------------------------------------------------ Case N_Elements(Value) OF 0:boite = [lonn1, lonn2, latt1, latt2, proff1, proff2] 1:BEGIN if value EQ -1 then boite = [lonn1, lonn2, latt1, latt2, proff1, proff2] $ ELSE boite=[lonn1, lonn2, latt1, latt2, 0.,value[0]] END 2:boite=[lonn1, lonn2, latt1, latt2, value[0],value[1]] 4:boite=[Value] 5:boite=[Value[0:3], 0, Value[4]] 6:boite = Value Else:BEGIN rien = report('Mauvaise Definition de Boite') END ENDCASE ;------------------------------------------------ boite[0] = floor(boite[0]) boite[1] = ceil(boite[1]) boite[2] = floor(boite[2]) boite[3] = ceil(boite[3]) if n_elements(boite GE 5) then begin boite[4] = floor(boite[4]) boite[5] = ceil(boite[5]) endif ;------------------------------------------------ ;------------------------------------------------ widget_control,widget_info(id,find_by_uname = 'lon1'), get_uvalue = uvalue strict = uvalue.strict ; ; les longitudes ; ; min et max possible if xtype EQ 'geographic' then begin min = floor(min([glamt,glamu,glamv], max = max)) max = ceil(max) ENDIF ELSE BEGIN min = 0 max = jpi-1 ENDELSE ; les id des widgets lon1id = widget_info(id,find_by_uname = 'lon1') lon2id = widget_info(id,find_by_uname = 'lon2') ; doit-on changer de type d''axe x: longitude/index lonbase = widget_info(id,find_by_uname = 'lonbase') widget_control, lonbase, get_uvalue = lonbase_uvalue if lonbase_uvalue.name NE xtype then BEGIN widget_control, lonbase, update = 0 ; on casse tout widget_control, lon1id, /destroy widget_control, lon2id, /destroy ; on reconstruit lon1id = cw_slider_pm(lonbase,value=min > boite[0] < ((boite[1] < max)-keyword_set(strict)) $ , uvalue={name:'lon1', strict:keyword_set(strict)},uname ='lon1' $ , title = xtitle+'1', minimum = min $ , maximum = (boite[1] < max)-keyword_set(strict)) lon2id = cw_slider_pm(lonbase,value=((min > boite[0])+keyword_set(strict)) > boite[1] < max $ , uvalue={name:'lon2', strict:keyword_set(strict)} $ , uname='lon2', title = xtitle+'2', maximum = max $ , minimum = (min > boite[0])+keyword_set(strict)) widget_control, lonbase, set_uvalue = {name:xtype} widget_control, lonbase, update = 1 ENDIF ELSE BEGIN ; la nouvelle valeur qu''ils vont avoir cursorvalue1 = min > boite[0] < ((boite[1] < max)-strict) cursorvalue2 = ((min > boite[0])+strict) > boite[1] < max ; on change les bornes des slider widget_control, lon1id, set_value = {slider_min:min, slider_max:cursorvalue2-strict} widget_control, lon2id, set_value = {slider_min:cursorvalue1+strict, slider_max:max} ; on attribut la nouvelle valeur widget_control, lon1id , set_value = cursorvalue1 widget_control, lon2id, set_value = cursorvalue2 ENDELSE ; ; les latitudes ; ; min et max possible if ytype EQ 'geographic' then begin min = floor(min([gphit,gphiu,gphiv], max = max)) max = ceil(max) ENDIF ELSE BEGIN min = 0 max = jpj-1 ENDELSE ; doit-on changer de type d''axe y: latitude/index latbase = widget_info(id,find_by_uname = 'latbase') widget_control, latbase, get_uvalue = latbase_uvalue lat1id = widget_info(id,find_by_uname = 'lat1') lat2id = widget_info(id,find_by_uname = 'lat2') if latbase_uvalue.name NE ytype then BEGIN widget_control, latbase, update = 0 widget_control, lat1id, /destroy widget_control, lat2id, /destroy lat1id = cw_slider_pm(latbase,value=min > boite[2] < ((boite[3] < max)-keyword_set(strict)) $ , uvalue={name:'lat1', strict:keyword_set(strict)},uname ='lat1' $ , title = ytitle+'1', minimum =min $ , maximum = ((boite[3] < max)-keyword_set(strict))) lat2id = cw_slider_pm(latbase,value=((min > boite[2])+keyword_set(strict)) > boite[3] < max $ , uvalue={name:'lat2', strict:keyword_set(strict)} $ , uname ='lat2', title = ytitle+'2' ,maximum = max $ , minimum =(min > boite[2])+keyword_set(strict)) widget_control, latbase, set_uvalue = {name:ytype} widget_control, latbase, update = 1 ENDIF ELSE BEGIN cursorvalue1 = min > boite[2] < ((boite[3] < max)-strict) cursorvalue2 = ((min > boite[2])+strict) > boite[3] < max widget_control, lat1id, set_value = {slider_min:min, slider_max:cursorvalue2-strict} widget_control, lat2id, set_value = {slider_min:cursorvalue1+strict, slider_max:max} widget_control, lat1id, set_value = cursorvalue1 widget_control, lat2id, set_value = cursorvalue2 ENDELSE ; ; if n_elements(boite) EQ 4 then return ; ; la profondeur ; depthlev1id = widget_info(id,find_by_uname = 'depthlev1') depthlev2id = widget_info(id,find_by_uname = 'depthlev2') depth1id = widget_info(id,find_by_uname = 'depth1') depth2id = widget_info(id,find_by_uname = 'depth2') widget_control, depthlev1id, get_uvalue = depthlev1_uval ; a-t-on change de type de grille ?, faut=il changerl''axe verticale? widget_control, findtopid(id), get_uvalue = top_uvalue zgrid = extractatt(top_uvalue, 'zgrid') grid_t = zgrid EQ 'T' if grid_t NE depthlev1_uval.grid_t then BEGIN widget_control, depthlev2id, get_uvalue = depthlev2_uval depthlev1_uval.grid_t = grid_t depthlev2_uval.grid_t = grid_t ; if grid_t then gdep = gdept ELSE gdep = gdepw gdep1 = floor(gdep) gdep2 = ceil(gdep) identique = where(gdep2-gdep1 EQ 0) if identique[0] NE -1 then gdep2[identique] = gdep2[identique] +1 depthlev1_uval.value = gdep1 depthlev2_uval.value = gdep2 ; widget_control, depthlev1id, set_value = {value:strtrim(gdep1, 1)} widget_control, depthlev2id, set_value = {value:strtrim(gdep2, 1)} ; widget_control, depthlev1id, set_uvalue = depthlev1_uval widget_control, depthlev2id, set_uvalue = depthlev2_uval ENDIF ELSE BEGIN gdep1 = depthlev1_uval.value gdep2 = gdep1+1 ENDELSE ; on s''assure que les profs donnees contiennent bien au moins un ; niveau. if boite[4] GT boite[5] then begin rien = boite[4] boite[4] = boite[5] boite[5] = rien endif ; rien = where(gdep1 LT boite[4], indice1) indice1 = indice1 < (jpk-1) rien = where(gdep2 LE boite[5], indice2) indice2 = indice1 > (indice2-1) ; if indice1 EQ indice2 then BEGIN if (where(gdep1 GE boite[4] AND gdep2 LE boite[5]))[0] EQ -1 then begin indice1 = 0 > (indice1-(grid_t EQ 1)) indice2 = indice1 endif boite[4] = gdep1[indice1] boite[5] = boite[4]+1 endif ; maintenant que les values et les indexes sont definis proprement, ; on peut les appliquer widget_control, depthlev1id, set_value = {droplist_select:indice1} widget_control, depthlev2id, set_value = {droplist_select:indice2} ; controler les min et les max des sliders... if indice1 EQ 0 then min1 = 0 ELSE min1 = gdep2[indice1-1] max1 = (min1+1) > gdep1[indice2] widget_control, depth1id, set_value = {slider_min:min1, slider_max:max1, value:boite[4]} min2 = gdep2[indice1] if indice2 EQ jpk-1 then BEGIN max2 = max([gdept, gdepw]) max2 = strtrim(string(max2,format='(e8.0)'), 1) max2 = float('1'+strmid(max2, 1))+float(max2) ENDIF ELSE max2 = gdep1[indice2+1] widget_control, depth2id, set_value = {slider_min:min2, slider_max:max2, value:boite[5]} ; return end ;********************************************************************* FUNCTION cw_domain_get_value, id box = lonarr(6) possiblecase = ['lon1', 'lon2','lat1', 'lat2','depth1','depth2'] for i = 0, 5 do begin widget_control,widget_info(id,find_by_uname = possiblecase[i]) $ , get_value = value box[i] = value.value endfor return, box end ;********************************************************************* FUNCTION cw_domain_event, event @common ; help, /struct, event if (where(tag_names(event) EQ 'OUT'))[0] NE -1 then if event.out NE 0 then return, -1 widget_control, event.id, get_uvalue=uval case uval.name of 'lon1':widget_control,widget_info(event.handler,find_by_uname = 'lon2') $ , set_value = {slider_min:event.value+uval.strict} 'lon2':widget_control,widget_info(event.handler,find_by_uname = 'lon1') $ , set_value = {slider_max:event.value-uval.strict} 'lat1':widget_control,widget_info(event.handler,find_by_uname = 'lat2') $ , set_value = {slider_min:event.value+uval.strict} 'lat2':widget_control,widget_info(event.handler,find_by_uname = 'lat1') $ , set_value = {slider_max:event.value-uval.strict} 'unzoom':BEGIN id = widget_info(event.handler,find_by_uname = 'lon1') widget_control, id, get_value = value widget_control, id, set_value = {slider_min:value.slider_min_max[0]} widget_control, id, set_value = value.slider_min_max[0] id = widget_info(event.handler,find_by_uname = 'lat1') widget_control, id, get_value = value widget_control, id, set_value = {slider_min:value.slider_min_max[0]} widget_control, id, set_value = value.slider_min_max[0] id = widget_info(event.handler,find_by_uname = 'lon2') widget_control, id, get_value = value widget_control, id, set_value = {slider_max:value.slider_min_max[1]} widget_control, id, set_value = value.slider_min_max[1] id = widget_info(event.handler,find_by_uname = 'lat2') widget_control, id, get_value = value widget_control, id, set_value = {slider_max:value.slider_min_max[1]} widget_control, id, set_value = value.slider_min_max[1] END 'depthlev1':BEGIN ; ids... depth1id = widget_info(event.handler,find_by_uname = 'depth1') depth2id = widget_info(event.handler,find_by_uname = 'depth2') depthlev2id = widget_info(event.handler,find_by_uname = 'depthlev2') ; faut-il changer depthlev2 ? widget_control, depthlev2id, get_value = depthlev2_value if depthlev2_value.droplist_select LT event.index then BEGIN ; on redefinie la valeur de depthlev2id widget_control, depthlev2id, set_value = {droplist_select:event.index} ; donc on redefinit la valeur et le max du slider 2 widget_control, depthlev2id, get_uvalue = depthlev2_uval if event.index EQ jpk-1 then BEGIN max = max([gdept, gdepw]) max = strtrim(string(max,format='(e8.0)'), 1) max = float('1'+strmid(max, 1))+float(max) ENDIF ELSE max = depthlev2_uval.value[event.index+1]-1 widget_control, depth2id $ , set_value = {slider_max:max, value:depthlev2_uval.value[event.index]} ; du coup on redefinie donc le max du slider 1 widget_control, depth1id, set_value = {slider_max:uval.value[event.index]} END ; on redefinie la valeur et le min du slider depth 1 if event.index EQ 0 then min = 0 ELSE min = uval.value[event.index-1]+1 widget_control, depth1id, set_value = {slider_min:min, value:uval.value[event.index]} ; du coup on change aussi la valeur du min du slider depth 2 widget_control, depth2id, set_value = {slider_min:uval.value[event.index]+1} END 'depthlev2':BEGIN ; ids... depth1id = widget_info(event.handler,find_by_uname = 'depth1') depth2id = widget_info(event.handler,find_by_uname = 'depth2') depthlev1id = widget_info(event.handler,find_by_uname = 'depthlev1') ; faut-il changer depthlev1 ? widget_control, depthlev1id, get_value = depthlev1_value if depthlev1_value.droplist_select GT event.index then BEGIN ; on redefinie la valeur de depthlev1id widget_control, depthlev1id, set_value = {droplist_select:event.index} ; donc on redefinit la valeur et le min du slider 1 widget_control, depthlev1id, get_uvalue = depthlev1_uval if event.index EQ 0 then min = 0 ELSE min = uval.value[event.index-1] widget_control, depth1id $ , set_value = {slider_min:min, value:depthlev1_uval.value[event.index]} ; du coup on redefinie donc le min du slider 2 widget_control, depth2id, set_value = {slider_min:uval.value[event.index]} END ; on redefinie la valeur et le max du slider depth 2 if event.index EQ jpk-1 then BEGIN max = max([gdept, gdepw]) max = strtrim(string(max,format='(e8.0)'), 1) max = float('1'+strmid(max, 1))+float(max) ENDIF ELSE max = uval.value[event.index+1]-1 widget_control, depth2id, set_value = {slider_max:max, value:uval.value[event.index]} ; du coup on change aussi la valeur du max du slider depth 1 widget_control, depth1id, set_value = {slider_max:uval.value[event.index]-1} END 'depth1':BEGIN ; ids... depth2id = widget_info(event.handler,find_by_uname = 'depth2') depthlev1id = widget_info(event.handler,find_by_uname = 'depthlev1') ; doit-on changer depthlev1 ? widget_control, depthlev1id, get_value = depthlev1_value widget_control, depthlev1id, get_uvalue = depthlev1_uval rien = where(depthlev1_uval.value LT event.value, indice) indice = indice < (jpk-1) if indice NE depthlev1_value.droplist_select then begin ; on change le min de depth2 widget_control, depth2id, set_value = {slider_min:depthlev1_uval.value[indice]+1} ; on redefinie la valeur de depthlev1id widget_control, depthlev1id, set_value = {droplist_select:indice} ; donc on redefinit le min du slider 1 if indice EQ 0 then min = 0 ELSE min = depthlev1_uval.value[indice-1]+1 widget_control, event.id, set_value = {slider_min:min} endif END 'depth2':BEGIN ; ids... depth1id = widget_info(event.handler,find_by_uname = 'depth1') depthlev2id = widget_info(event.handler,find_by_uname = 'depthlev2') ; doit-on changer depthlev2 ? widget_control, depthlev2id, get_value = depthlev2_value widget_control, depthlev2id, get_uvalue = depthlev2_uval rien = where(depthlev2_uval.value LE event.value, indice) indice = 0 > (indice-1) if indice NE depthlev2_value.droplist_select then begin ; on change le max de depth1 widget_control, depth1id, set_value = {slider_max:depthlev2_uval.value[indice]-1} ; on redefinie la valeur de depthlev2id widget_control, depthlev2id, set_value = {droplist_select:indice} ; donc on redefinit le max du slider 2 if indice EQ jpk-1 then BEGIN max = max([gdept, gdepw]) max = strtrim(string(max,format='(e8.0)'), 1) max = float('1'+strmid(max, 1))+float(max) ENDIF ELSE max = depthlev2_uval.value[indice+1]-1 widget_control, event.id, set_value = {slider_max:max} endif END ELSE: ENDCASE ; slidesliceid = widget_info(event.top, find_by_uname = 'slide_slice') ; if slidesliceid NE 0 then widget_control, slidesliceid, set_value = 1 return,{ID:event.handler, TOP:event.top, HANDLER:0L $ , BOX:cw_domain_get_value(event.handler)} end ;********************************************************************* FUNCTION cw_domain, parent, BOITE = boite, STRICT = strict, UVALUE = uvalue, UNAME = uname, ROW = row, COLUMN = column, UNZOOM = unzoom, _extra = ex ; @common ; cheking exclusive keywords column = keyword_set(column)*(1-keyword_set(row)) row = keyword_set(row)*(1-keyword_set(column)) +(keyword_set(row) EQ column) ; def de la boite if NOT keyword_set(boite) then boite = [lon1, lon2, lat1, lat2 $ , min([gdepw[0], gdept[0]]), max([gdepw[0], gdept[0]]) ] Case N_Elements(Boite) OF 0:boite = [lon1, lon2, lat1, lat2, prof1, prof2] 1:boite=[lon1, lon2, lat1, lat2, 0.,boite[0]] 2:boite=[lon1, lon2, lat1, lat2, boite[0],boite[1]] 4:boite=[Boite, prof1, prof2] 5:boite=[Boite[0:3], 0, Boite[4]] 6: Else: return, report('Mauvaise Definition de Boite') ENDCASE ; boite[0] = floor(boite[0]) boite[1] = ceil(boite[1]) boite[2] = floor(boite[2]) boite[3] = ceil(boite[3]) boite[4] = floor(boite[4]) boite[5] = ceil(boite[5]) ;------------------------------------------------ if NOT keyword_set(uvalue) then uvalue = '' if NOT keyword_set(uname) then uname = '' base = widget_base(parent, /row $ , space = 1, xpad = 1, ypad = 1 $ , EVENT_FUNC = 'cw_domain_event' $ , FUNC_GET_VALUE='cw_domain_get_value' $ , PRO_SET_VALUE='cw_domain_set_value' $ , UVALUE = uvalue, UNAME = uname, _extra = ex) ;-------------longitude--------------------------- basehori = widget_base(base, ROW = row, COLUMN = column) ;-------------longitude--------------------------- min = floor(min([glamt,glamu,glamv], max = max)) max = ceil(max) lonbase = widget_base(basehori, /ROW, space = 1, xpad = 1, ypad = 1, uname = 'lonbase') lon1id = cw_slider_pm(lonbase,value=min > boite[0] < ((boite[1] < max)-keyword_set(strict)) $ , uvalue={name:'lon1', strict:keyword_set(strict)},uname ='lon1' $ , title = 'lon1', minimum = min $ , maximum = (boite[1] < max)-keyword_set(strict)) lon2id = cw_slider_pm(lonbase,value=((min > boite[0])+keyword_set(strict)) > boite[1] < max $ , uvalue={name:'lon2', strict:keyword_set(strict)} $ , uname='lon2', title = 'lon2', maximum = max $ , minimum = (min > boite[0])+keyword_set(strict)) widget_control, lonbase, set_uvalue = {name:'geographic'} ;---------------latitude------------------------- min = floor(min([gphit,gphiu,gphiv], max = max)) max = ceil(max) latbase = widget_base(basehori, /ROW, space = 1, xpad = 1, ypad = 1, uname = 'latbase') lat1id = cw_slider_pm(latbase,value=min > boite[2] < ((boite[3] < max)-keyword_set(strict)) $ , uvalue={name:'lat1', strict:keyword_set(strict)},uname ='lat1' $ , title = 'lat1', minimum =min $ , maximum = ((boite[3] < max)-keyword_set(strict))) lat2id = cw_slider_pm(latbase,value=((min > boite[2])+keyword_set(strict)) > boite[3] < max $ , uvalue={name:'lat2', strict:keyword_set(strict)} $ , uname ='lat2', title = 'lat2' ,maximum = max $ , minimum =(min > boite[2])+keyword_set(strict)) widget_control, latbase, set_uvalue = {name:'geographic'} ;----------------unzoom------------------------ if keyword_set(unzoom) then rien = widget_button(basehori,value='unzoom', uvalue={name:'unzoom'}) ;----------------depth------------------------ basevert = widget_base(base, ROW = row, COLUMN = column) basedepth = widget_base(basevert, /row) ; if strupcase(vargrid) EQ 'W' then gdep = gdepw ELSE gdep = gdept gdep1 = floor(gdep) gdep2 = ceil(gdep) identique = where(gdep2-gdep1 EQ 0) if identique[0] NE -1 then gdep2[identique] = gdep2[identique] +1 sgdep1 = strtrim(gdep1, 1) sgdep2 = strtrim(gdep2, 1) ; basedepthdrop = widget_base(basedepth, column = column, row = row) ; dephtid=cw_droplist_pm(basedepthdrop,value=''+sgdep1, uvalue={name:'depthlev1', value:gdep1, grid_t:strupcase(vargrid) NE 'W'}, uname='depthlev1') rien = where(gdep1 LT boite[4], indice1) indice1 = indice1 < (jpk-1) widget_control, dephtid, set_value = {droplist_select:indice1} ; dephtid=cw_droplist_pm(basedepthdrop,value=''+sgdep2, uvalue={name:'depthlev2', value:gdep2, grid_t:strupcase(vargrid) NE 'W'}, uname='depthlev2') rien = where(gdep2 LE boite[5], indice2) indice2 = indice1 > (indice2-1) widget_control, dephtid, set_value = {droplist_select:indice2} ; basedepthslid = widget_base(basedepth, column = column, row = row) ; if indice1 EQ 0 then min1 = 0 ELSE min1 = gdep2[indice1-1] max1 = (min1+1) > gdep1[indice2] rien = cw_slider_pm(basedepthslid, value= min1 > boite[4] < (boite[5] < max1) $ , uvalue = {name:'depth1'}, uname = 'depth1' $ , title = 'depth1', minimum = min1, maximum = max1) ; min2 = gdep2[indice1] if indice2 EQ jpk-1 then BEGIN max2 = max([gdept, gdepw]) max2 = strtrim(string(max2,format='(e8.0)'), 1) max2 = float('1'+strmid(max2, 1))+float(max2) ENDIF ELSE max2 = gdep1[indice2+1] if max2 EQ min2 then max2 = min2+1 rien = cw_slider_pm(basedepthslid, value= (min2 > boite[4]) > boite[5] < max2 $ , uvalue={name:'depth2'}, minimum = min2 $ , uname = 'depth2', title = 'depth2' ,maximum = max2) ;-------------------------------------------- ; ; ; return, base end