;+ ;NAME: ; thm_ui_verify_data ; ;PURPOSE: ; this window allows the user to view and change the meta data associated with GUI data, either tplot variables ; being imported or GUI data being exported. ; ;CALLING SEQUENCE: ; thm_ui_verify_data,names,loadedData,windowStorage,gui_id=gui_id,edit=edit,newnames=newnames ; ; Inputs: ; names: The names for which verification is done ; loadedData: The loadedData object ; windowstorage: The windowStorage object ; ;Keywords: ; gui_id: id of top level base widget from calling program(not required if not used inside the gui) ; edit: Set this to indicate that this is only being used to edit metadata. This means that data will not be deleted on failure/error ; newnames: This returns the set of datanames after any modifcations ; ;OUTPUT: ; ;HISTORY: ;$LastChangedBy: egrimes $ ;$LastChangedDate: 2013-04-03 14:18:44 -0700 (Wed, 03 Apr 2013) $ ;$LastChangedRevision: 11947 $ ;$URL: svn+ssh://thmsvn@ambrosia.ssl.berkeley.edu/repos/thmsoc/tags/tdas_8_00/idl/themis/thm_ui_new/panels/thm_ui_verify_data.pro $ ; ;-------------------------------------------------------------------------------- ;updates a page with the new contents from the metadata element at index pro thm_ui_update_verify,state compile_opt hidden,idl2 index = state.currentindex if index eq -1 || ~ptr_valid(state.metaData) then begin if index eq -1 then begin value ='' endif else begin value='' endelse for i = 0,6 do begin if i ne 5 then begin widget_control,state.textWidgets[i],set_value=value endif else begin widget_control,state.textWidgets[i],set_combobox_select=where(state.validcoords eq 'N/A') endelse endfor endif else begin Widget_Control, state.textWidgets[0], set_value=(*state.metaData)[index].name Widget_Control, state.textWidgets[1], set_value=(*state.metaData)[index].mission Widget_Control, state.textWidgets[2], set_value=(*state.metaData)[index].observatory Widget_Control, state.textWidgets[3], set_value=(*state.metaData)[index].instrument Widget_Control, state.textWidgets[4], set_value=(*state.metaData)[index].unit Widget_Control, state.textWidgets[5], set_combobox_select=(*state.metaData)[index].coordinate Widget_Control, state.textWidgets[6], set_value=(*state.metaData)[index].filename endelse end pro thm_ui_update_meta,state,element,value compile_opt idl2,hidden list = widget_info(state.varList,/list_select) if ~ptr_valid(state.metadata) || list[0] eq -1 then return idx = where(element eq strlowcase(tag_names((*state.metadata)[0])),c) if c eq 0 then return for i = 0,n_elements(list)-1 do begin (*state.metadata)[list[i]].(idx) = value endfor end pro thm_ui_verify_data_event,event compile_opt hidden,idl2 Widget_Control, event.TOP, Get_uvalue=state, /No_Copy ;Put a catch here to insure that the state remains defined err_xxx = 0 Catch, err_xxx IF (err_xxx NE 0) THEN BEGIN Catch, /Cancel Help, /Last_Message, Output = err_msg thm_ui_sbar_hwin_update, state, err_msg, /error, err_msgbox_title='Error in Verify Data' Widget_Control, event.TOP, Set_UValue=state, /No_Copy widget_control, event.top,/destroy RETURN ENDIF IF(Tag_Names(event, /Structure_Name) EQ 'WIDGET_KILL_REQUEST') THEN BEGIN state.historyWin->update,'Widget Killed' IF ~keyword_set(state.edit) && ptr_valid(state.metadata) THEN BEGIN numData=N_Elements(*state.metaData) IF numData GT 0 THEN FOR i=0,numData-1 DO result=state.loadedData->Remove(state.origNames[i]) ENDIF Widget_Control, event.TOP, Set_uValue=state, /No_Copy Widget_Control, event.top, /Destroy RETURN ENDIF Widget_Control, event.id, Get_UValue=uval state.historywin->update,'THM_UI_VERIFY_DATA: User value: '+uval ,/dontshow CASE uval OF 'CANC': BEGIN IF ~keyword_set(state.edit) && ptr_valid(state.metadata) THEN BEGIN numData=N_Elements(*state.metaData) IF numData GT 0 THEN BEGIN FOR i=0,numData-1 DO BEGIN if ~in_set(state.origNames[i], state.origGuiNames) then $ result=state.loadedData->Remove(state.origNames[i]) ENDFOR ENDIF ENDIF Widget_Control, event.TOP, Set_uValue=state, /No_Copy Widget_Control, event.top, /Destroy RETURN END 'OK': BEGIN state.historyWin->update,'Closing verify panel' if ptr_valid(state.metadata) && n_elements(*state.metaData) gt 0 then begin numData=N_Elements(*state.metaData) existingData=state.loadedData->GetAll(/Parent) FOR i=0,numData-1 DO BEGIN ;This check verifies that the requested name is in the set of selected names, but that the name is not THIS variable's name(which would be the case if the name was left unchanged) if in_set((*state.metadata)[i].name,existingData) && (*state.metadata)[i].name ne state.origNames[i] then begin messageString=String('The name '+(*state.metaData)[i].name +' is already used by another variable. Name will not be changed') response=dialog_message(messageString,/CENTER) state.loadedData->SetDataInfo, $ state.origNames[i], $ Mission=(*state.metaData)[i].mission, $ Observatory=(*state.metaData)[i].observatory,$ Instrument=(*state.metaData)[i].instrument, $ Units=(*state.metaData)[i].unit, $ Coordinate_System=state.validCoords[(*state.metaData)[i].coordinate], $ windowstorage=state.windowStorage, fail=fail if obj_valid(state.callSequence) && ~fail then begin state.callSequence->addDataInfoOp,$ state.origNames[i], $ (*state.metaData)[i].mission, $ (*state.metaData)[i].observatory,$ (*state.metaData)[i].instrument, $ (*state.metaData)[i].unit, $ state.validCoords[(*state.metaData)[i].coordinate] endif endif else begin state.loadedData->SetDataInfo, $ state.origNames[i], $ newname=(*state.metadata)[i].name,$ Mission=(*state.metaData)[i].mission, $ Observatory=(*state.metaData)[i].observatory,$ Instrument=(*state.metaData)[i].instrument, $ Units=(*state.metaData)[i].unit, $ Coordinate_System=state.validCoords[(*state.metaData)[i].coordinate], $ windowstorage=state.windowStorage, fail=fail if obj_valid(state.callSequence) && ~fail then begin state.callSequence->addDataInfoOp,$ state.origNames[i], $ newname=(*state.metadata)[i].name,$ (*state.metaData)[i].mission, $ (*state.metaData)[i].observatory,$ (*state.metaData)[i].instrument, $ (*state.metaData)[i].unit, $ state.validCoords[(*state.metaData)[i].coordinate] endif endelse IF Fail EQ 1 THEN BEGIN result=state.loadedData->Remove(state.metaData[i].name) messageString=String('Error setting meta data values for '+state.names[i]+'. Do you want to continue?') result=dialog_message(messageString,/QUESTION,/CENTER, title='Error in Verify Data') IF result EQ 'No' && ~keyword_set(state.edit) THEN BEGIN if i lt numData-1 then begin for j = i+1,numData-1 do begin result=state.loadedData->Remove(state.metaData[i].name) endfor endif Widget_Control, event.TOP, Set_uValue=state, /No_Copy RETURN ENDIF ENDIF ENDFOR ENDIF *state.success = 1 Widget_Control, event.TOP, Set_uValue=state, /No_Copy Widget_Control, event.top, /Destroy RETURN END 'VARLIST': BEGIN state.currentIndex = event.index thm_ui_update_verify,state END 'NAME': BEGIN Widget_Control, state.textWidgets[0], Get_Value=value current_select = widget_info(state.varList,/list_select) if current_select[0] ne -1 && n_elements(current_select) eq 1 then begin thm_ui_update_meta,state,'name',value state.names[current_select[0]] = value Widget_Control, state.varList, set_value=state.names Widget_Control, state.varList, set_list_select=current_select endif else if n_elements(current_select) ne 1 then begin state.statusbar->update,'Cannot update more than one name at once' endif END 'MISSION': BEGIN Widget_Control, state.textWidgets[1], Get_Value=value thm_ui_update_meta,state,'mission',value END 'OBSERVATORY': BEGIN Widget_Control, state.textWidgets[2], Get_Value=value thm_ui_update_meta,state,'observatory',value END 'INSTRUMENT': BEGIN Widget_Control, state.textWidgets[3], Get_Value=value thm_ui_update_meta,state,'instrument',value END 'UNIT': BEGIN Widget_Control, state.textWidgets[4], Get_Value=value thm_ui_update_meta,state,'unit',value END 'COORDINATE': BEGIN index = event.index if index[0] ne -1 then begin thm_ui_update_meta,state,'coordinate',index endif END 'UP': BEGIN IF ptr_valid(state.metadata) && state.currentIndex ne - 1 then begin state.currentIndex = (-1 + state.currentIndex + n_elements(*state.metadata)) mod n_elements(*state.metadata) widget_control,state.varList,set_list_select=state.currentIndex thm_ui_update_verify,state endif END 'DOWN': BEGIN IF ptr_valid(state.metadata) && state.currentIndex ne - 1 then begin state.currentIndex = (1 + state.currentIndex + n_elements(*state.metadata)) mod n_elements(*state.metadata) widget_control,state.varList,set_list_select=state.currentIndex thm_ui_update_verify,state endif END ELSE: dprint, 'Not yet implemented' ENDCASE Widget_Control, event.top, Set_uValue=state, /No_Copy RETURN END ;---------------------------------------------------------------------------- PRO thm_ui_verify_data, gui_id, names, loadedData, windowstorage, historywin, edit=edit,newnames=newnames,success=success,callSequence=callSequence compile_opt idl2 err_xxx = 0 Catch, err_xxx If(err_xxx Ne 0) Then Begin Catch, /Cancel Help, /Last_Message, output = err_msg FOR j = 0, N_Elements(err_msg)-1 DO historywin->update,err_msg[j] ;Print, 'Error--See history' ok = error_message('An unknown error occured starting Verify Data. See console for details.',$ /noname, /center, title='Error in Verify Data') Widget_Control,tlb,/destroy thm_gui_error,gui_id, historywin RETURN EndIf tlb = Widget_Base(/col, Title='Verify Data', /floating, Group_Leader=gui_id, /Modal, $ /tlb_kill_request_events) mainBase = Widget_Base(tlb, /row, tab_mode=1) varListBase = Widget_Base(mainBase, /col) varLabelBase = Widget_Base(varListBase, /row) varTextBase = Widget_Base(varListBase, /row) arrowBase = Widget_Base(varListBase, /row, /align_center) metaDataBase = Widget_Base(mainBase, /col) metaLabelBase=Widget_Base(metaDataBase, /row, ypad=2) metaFrameBase=Widget_Base(metaDataBase, /col, frame=3) variableBase = Widget_Base(metaFrameBase, /row, ypad=1) missionBase = Widget_Base(metaFrameBase, /row, ypad=1) observatoryBase = Widget_Base(metaFrameBase, /row, ypad=1) instrumentBase = Widget_Base(metaFrameBase, /row, ypad=1) unitBase = Widget_Base(metaFrameBase, /row, ypad=1) coordinateBase = Widget_Base(metaFrameBase, /row, ypad=1) filenameBase = Widget_Base(metaFrameBase, /row, ypad=1) ; arrowBase = Widget_Base(metaFrameBase, /row, /align_center) button_row = widget_base(tlb,/row, /align_center, tab_mode=1) status_row = widget_base(tlb,/row) ; initialize the valid missions, instruments, probes, and coordinate systems validMissions = ['THEMIS'] validInstruments = [' ASI ', ' ASK', ' ESA', ' EFI', ' FBK', ' FFT', ' FGM', $ ' FIT ', ' GMAG', ' MOM', ' SCM', ' SPIN', ' SST', ' STATE'] validProbes = [' * (All)', ' A (P5)', ' B (P1)', ' C (P2)', ' D (P3)', $ ' E (P4)', ' F (Flatsat)'] validCoords = ['N/A','DSL', 'SSL', 'GSE', 'GEI', 'SPG', 'GSM', 'GEO', 'SM','ENP','RTN','GCI','HDZ'] ; get pre-existing gui variable names origGuiNames = loadedData->GetAll(/Parent) ; initialize the meta data structure metaDataStruc = {name:'', mission:'', observatory:'', instrument:'',unit:'', coordinate:0, $ filename:''} IF N_Elements(names) GT 0 THEN BEGIN metaData=replicate(metaDataStruc, N_Elements(names)) FOR i=0,N_Elements(names)-1 DO BEGIN loadedData->GetDataInfo, names[i], mission=mission, observatory=observatory, $ instrument=instrument, units=unit, coordinate_system=coordinate, filename=filename, fail=fail IF fail THEN BEGIN ok = error_message('Error retrieving data for ' + names[i], $ /center, title='Error in Verify Data') continue endif metaData[i].name=names[i] metaData[i].mission=mission metaData[i].observatory=observatory metaData[i].instrument=instrument metaData[i].unit=unit index=where(strlowcase(validCoords) EQ strlowcase(coordinate)) IF index EQ -1 THEN index = 0 metaData[i].coordinate=index metaData[i].filename=filename ENDFOR metaData = ptr_new(metaData) ENDIF ELSE BEGIN metaData=ptr_new() names = ['update,'Verify panel opened' ;keep windows in X11 from snaping back to ;center during tree widget events if !d.NAME eq 'X' then begin widget_control, tlb, xoffset=0, yoffset=0 endif XManager, 'thm_ui_verify_data', tlb historywin->update,'Verify panel closing' if arg_present(newnames) && ptr_valid(metaData) then begin newnames = (*metaData)[*].name endif success = *success_ptr RETURN END