; $Id: dm_plot_slice.pro,v 1.27 2007/08/01 14:52:33 ymqiu Exp $
;#######################################################################
;
; NAME:
;  dm_plot_slice
;
; PURPOSE:
;  plot the slice
;
; CATEGORY:
;  dcs_mslice
;
; AUTHOR:
;  Yiming Qiu
;  NIST Center for Neutron Research
;  100 Bureau Drive, Gaithersburg, MD 20899-6102
;  United States
;  yiming.qiu@nist.gov
;  July, 2007
;
; 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_plot_slice,surfplot=surfplot
    if (not ptr_valid(self.projStrPtr)) or (not ptr_valid(self.dataStrPtr)) or self.error then begin
       ok = dialog_message('Please load data and calculate projection first.',dialog_parent=self.tlb)
       return
    endif
    ;select data
    self->dm_choose_slicedata,xdat=xdat,ydat=ydat,zdat=zdat,xtit=xtit,ytit=ytit,zran=zran,zmin=zmin
    ztit = self.intn_lab

    ;extra info in the title
    tmp_tit = ''
    if (self.samp_typ eq 1) or (self.samp_typ eq 3) then begin
       labels = [self.view_u1lab[1],self.view_u2lab[1],self.view_u3lab]
       if self.samp_typ eq 1 then begin
          index = (where([self.view_u1[3],self.view_u2[3],self.view_u3[3]] eq 1))[0]
          if index ge 0 then labels[index] = 'E'
       endif else labels[2] = 'E'
       if total(finite(self.disp_tran)) ne 0 then begin
          tmp_tit = ' '+labels[self.disp_perp]+'=['+dm_to_string(self.disp_tran[0])+','+dm_to_string(self.disp_tran[1])+']'
          if labels[self.disp_perp] eq 'E' then tmp_tit=tmp_tit+'meV'
       endif
    endif
    if (self.samp_typ ge 2) and (strlen(tmp_tit) eq 0) then begin
       case self.e_bin[self.samp_typ] of
          0:  tmp_tit = ''
          1:  tmp_tit = ' Elastic'
          2:  tmp_tit = ' E=['+dm_to_string(self.e_range[0])+','+dm_to_string(self.e_range[1])+']meV'
       endcase
    endif
    if (self.samp_typ gt 0) and (self.hklran_yn eq 1) and (total(finite(self.disp_hklran)) ne 0) then $
       tmp_tit = tmp_tit+' '+(['H','K','L'])[self.disp_hkl]+'=['+dm_to_string(self.disp_hklran[0])+','+$
                 dm_to_string(self.disp_hklran[1])+']'

    title = self.titl_lab+tmp_tit

    ;plot the data
    if self.useitool then begin
       ok = dialog_message('Itools plotting is not implemented yet. Soooorry!',dialog_parent=self.tlb)
       return
    endif else begin
       obj_name = 'dm_plot'
       if not obj_valid(self.current) then begin
          self.current=obj_new(obj_name,xdat,ydat,zdat,xtit=xtit,ytit=ytit,ztit=ztit,/no_copy,$
                parentobj=self,xran=self.disp_hran,yran=self.disp_vran,shading=self.disp_shading,$
                coltable=self.disp_color,iran=zran,title=title,zmin=zmin,surfplot=surfplot,$
                /usepolygon,/hidelegend)
       endif else begin
          self.current->getproperty,keep=keep
          if keep eq 1 then begin
             self.current = obj_new(obj_name,parentobj=self)
          endif
          self.current->setproperty,xdat=xdat,ydat=ydat,zdat=zdat,xtit=xtit,ytit=ytit,ztit=ztit,/no_copy,$
                xran=self.disp_hran,yran=self.disp_vran,shading=self.disp_shading,$
                coltable=self.disp_color,iran=zran,title=title,zmin=zmin,surfplot=surfplot,$
                /usepolygon,/nodraw,/hidelegend
       endelse
       ;add powder lines in diffuse scattering mode
       if ptr_valid(self.powd_line) then begin
          tmp = size(*self.powd_line)
          tmp = tmp[tmp[0]]
          for i=0,tmp-1 do $
              self.current->add_plot,(*self.powd_line)[*,0,i],(*self.powd_line)[*,1,i],psym='no symbol',$
                    color='yellow',linestyle='solid',layer=i
       endif
       self.current->draw
    endelse
    self->dm_add_plotwindow,type=0,title=title
end