; $Id: dm_filemenu.pro,v 1.12 2008/03/19 20:46:50 ymqiu Exp $
;#######################################################################
;
; NAME:
;  dm_filemenu
;
; PURPOSE:
;
;
; CATEGORY:
;  dcs_mslice
;
; AUTHOR:
;  Yiming Qiu
;  NIST Center for Neutron Research
;  100 Bureau Drive, Gaithersburg, MD 20899-6102
;  United States
;  yiming.qiu@nist.gov
;  March, 2008
;
; LICENSE:
;  The software in this file is written by an employee of
;  National Institute of Standards and Technology
;  as part of the DAVE software project.
;
;  The DAVE software package is not subject to copyright protection
;  and is in the public domain. It should be considered as an
;  experimental neutron scattering data reduction, visualization, and
;  analysis system. As such, the authors assume no responsibility
;  whatsoever for its use, and make no guarantees, expressed or
;  implied, about its quality, reliability, or any other
;  characteristic. The use of certain trade names or commercial
;  products does not imply any endorsement of a particular product,
;  nor does it imply that the named product is necessarily the best
;  product for the stated purpose. We would appreciate acknowledgment
;  if the DAVE software is used or if the code in this file is
;  included in another product.
;
;#######################################################################

pro dcs_mslice::dm_filemenu,init=init
    ftypemenu = widget_info(self.tlb,find_by_uname='ftypeMenu')
    ftoolmenu = widget_info(self.tlb,find_by_uname='ftoolMenu')
    if keyword_set(init) then begin  ;initialization
       ;instrument name or file types to be shown in the menu
       self.ftypename = ptr_new(['DCS','SPE','INX','MACS'])
       ;corresponding file type extensions
       self.ftypeext  = ptr_new(['DCS','SPE','INX','NG0'])

       for i=0,n_elements(*self.ftypename)-1 do begin
           void = dm_widget_button(ftypemenu,value=(*self.ftypename)[i],uname='ftype_'+dm_to_string(i))
       endfor
    endif

    ;construct tool menus
    ;delete all possible menu items in ftoolMenu
    tmp = widget_info(ftoolmenu,/child)
    while (tmp ne 0) do begin
       widget_control, tmp,/destroy
       tmp = widget_info(ftoolmenu,/child)
    endwhile
    ;reconstruct tool menus according to file type and preset some parameters
    case self.ftype of  ;warning: don't use a tool uname starts with 'ftype_' !!!
       0:   begin   ;DCS file
            widget_control,ftoolmenu,sensitive=1
            void = widget_button(ftoolmenu,value='Convert DCS Files to SPE Format',uname='dcs_cspeBut')
            void = widget_button(ftoolmenu,value='Plot DCS Crystal Alignment Files',uname='dcs_algnBut')
            *(self.rebinsize) = [1s,2s,4s,5s,8s,10s,20s,25s,40s,50s]
            ptr_free,self.detPosPtr
            self.detPosPtr = dm_load_detpos(/dcs)       ;load detector position information
            self.intn_typ  = 0      ;default S(q,w) intensity type
            self.edep_yn   = 1
            self.instrgeom = 0
            fixedgeom      = 1      ;a direct geometry instrument only
            end
       1:   begin   ;SPE file   no tools available
            widget_control,ftoolmenu,sensitive=0
            self.intn_typ  = 4      ;default no kfactor adjustment
            self.edep_yn   = 0      ;no energy dependent detector efficiency correction
            fixedgeom      = 0      ;could be either direct or inverse geometry
            end
       2:   begin   ;INX file   no tools available
            widget_control,ftoolmenu,sensitive=0
            *(self.rebinsize) = [1s,2s,4s,8s,16s,32s,64s]
            self.intn_typ  = 4      ;default no kfactor adjustment
            self.edep_yn   = 0      ;no energy dependent detector efficiency correction
            fixedgeom      = 0      ;could be either direct or inverse geometry
            end
       3:   begin ;MACS file, no tools available yet
            widget_control, ftoolmenu,sensitive=0   ;no tools at this moment
            self.intn_typ  = 4      ;default no kfactor adjustment
            self.edep_yn   = 0      ;no energy dependent detector efficiency correction
            self.instrgeom = 1
            fixedgeom      = 1      ;an inverse geometry instrument only
            ptr_free,self.detPosPtr
            self.detPosPtr = dm_load_detpos(/macs)
            end
       else:begin
            widget_control,ftoolmenu,sensitive=0
            self.intn_typ  = 4      ;default no kfactor adjustment
            self.edep_yn   = 0
            fixedgeom      = 0
            end
    endcase
    ;reset menus
    self->reset_menu,geomsensitive=1-fixedgeom
    ;reset ebin size values
    if (self.samp_typ lt 2) and obj_valid(self.fileSel) then begin
       ebinbut = widget_info(self.tlb,find_by_uname='eBin')
       widget_control,ebinbut,set_value=dm_to_string(*(self.rebinsize))
       tmp = where(*(self.rebinsize) eq self.e_bin[self.samp_typ],count)
       if count eq 0 then self.e_bin[self.samp_typ]=1
       tmp = (0>(tmp[0]))
       dm_set_droplist,ebinbut,select=tmp
    endif
end