;+
;show value
;+
PRO sesLQU::ShowValue , eventX, eventY
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	oView = (oSystem.CurrentPro).oView
	zoom = (oSystem.CurrentPro).zoom
	Class = (oSystem.CurrentPro)
	oView->GetProperty, Location = viewLoc , Dimensions = dim , $
	                    Viewplane_Rect = viewPlane

	eventX = (viewPlane[0]+eventX-viewLoc[0])/zoom
	eventY = (viewPlane[1]+eventY-viewLoc[1])/zoom
	self.crossModel->SetProperty,Hide = 0
	ox = Fix(((eventX-1)>0)<(Class.imageX-1))
	oy = Fix(((eventY-1)>0)<(Class.imageY-1))

	mmValue = self.mmValue
	XYValue = (mmValue[1]-mmValue[0])/255*(*(self.image))[ox,oy]+mmValue[0]
	Widget_Control,self.XY,Set_Value = (Strtrim(String(XYValue),2))[0]
	data1 = [[ox-10,oy],[ox+10,oy]]
	data2 = [[ox,oy-10],[ox,oy+10]]
	self.crossX->Setproperty,data = data1
	self.crossY->Setproperty,data = data2
	self.Label->Setproperty,Location = [ox+10,oy+10]
	self.Label->Setproperty,Strings = 'Value:' + Strtrim(String(XYValue),2)
	oSystem.oWindow -> Draw,oSystem.oScene
END
;+
;handle event
;+
PRO sesLQU::HandleEvent, event
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	UName = Widget_Info(event.id, /UName)
	IF Tag_Names(event, /Structure_Name) EQ 'WIDGET_KILL_REQUEST' THEN BEGIN
		Widget_Control, event.top, /Destroy
		Obj_Destroy , self.lquContainer
        oSystem.oWindow -> Draw,oSystem.oScene
        menuBar = (oSystem.menuBar)
        menuBar.CurrentName = ''
        Obj_Destroy,(oSystem.menuBar).ShowLQU
		Return
	ENDIF
	CASE UName OF
		'parameter':BEGIN
			Widget_Control, event.id, Get_Value=value
			value = 1000 > value < 100000
			self.parameter = value
			Widget_Control, event.id, Set_Value=value
			Widget_Control, self.tButton , Sensitive = 1
		END
		'Rework':BEGIN
			head = (oSystem.CurrentPro).head
			data = (oSystem.CurrentPro).data
			fitData=(*(data))*(self.parameter)/Sxpar((*head),'CALIBRAT')
			self.mmValue = [min(fitData),max(fitData)]
			Widget_Control,self.minL,Set_Value = Strtrim(String(self.mmValue[0]),2)
			Widget_Control,self.maxL,Set_Value = Strtrim(String(self.mmValue[1]),2)
			Widget_Control,self.XY,Set_Value = ''
			self.crossModel->SetProperty,Hide = 1
			*(self.image) = BytScl(fitData)
			(oSystem.CurrentPro).oImage->SetProperty,Data = Temporary(BytScl(fitData))
			oSystem.oWindow -> Draw,oSystem.oScene
			Widget_Control, self.tButton , Sensitive = 0
		END
	ELSE:
	ENDCASE
END
;+
;create widget
;+
PRO sesLQU::Create
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	Device, Get_Screen_Size = screenSize
	xOff = 4
	yOff = screenSize[1]-(oSystem.baseSize)[1]-2
	self.lquContainer = Obj_New('IDL_Container')

	self.crossX = Obj_New('IDLgrPolyLine'                       , $
						   LineStyle = 0                        , $
	                       Data = [0,0]                         , $
                           Thick = 1                            , $
                           Color = [255,0,0]                  $
						 )

	self.crossY = Obj_New('IDLgrPolyLine'                       , $
						   LineStyle = 0                        , $
	                       Data = [0,0]                         , $
                           Thick = 1                            , $
                           Color = [255,0,0]                  $
						 )

	font = Obj_New('IDLgrFont', 'Helvetica', Size=12)

	self.Label  = Obj_New('IDLgrText'                           , $
		                   ALIGNMENT = 0.5                      , $
		                   Color           = [255,255,255]			, $
		                   font = font           )

	self.crossModel = Obj_New('IDLgrModel')
	self.crossModel->Add,self.crossX
	self.crossModel->Add,self.crossY
	self.crossModel->Add,self.Label
	(oSystem.CurrentPro).oModel->Add,self.crossModel
	self.lquContainer->Add,self.crossX
	self.lquContainer->Add,self.crossY
	self.lquContainer->Add,self.crossModel
	self.lquContainer->Add,font

	cBase = Widget_Base(Group_Leader = self.mainBase		, $
		                UName      = 'showValue'  	        , $
		                UValue	   = self					, $
		                Title      = 'show LQU value'	    , $
		                Space      = 2          			, $
		                XOffSet    = xOff					, $
		                YOffSet    = yOff					, $
		                Map        = 1                      , $
;		                tlb_frame_attr = 2 	   		        , $
		                /ToolBar 							, $
		                /Column		               			, $
		                /Floating               			, $
		                /Tlb_Kill_Request_Events 			)

	self.cBase = cBase

	wMagnify_base = Widget_Base(cBase, $
								/row, $
								ypad=0, $
								map=1)

	wMagnify_text = cw_field(wMagnify_base, $
							title='parameter :', $
							value=10000, $
							uname='parameter', $
							xsize=7, $
							ysize=1, $
							FONT='Helvetica*15' , $
							/integer, $
							/RETURN_EVENTS)

	minBase = Widget_Base(cBase, $
						  /row, $
						  ypad=0)

	label = Widget_Label(minBase  , $
						 Value = 'Min value : '   $
	                     )

	self.minL = Widget_Label(minBase                , $
							 /Dynamic_Resize        , $
							 Xsize = 50             , $
						     Value = Strtrim(String(self.mmValue[0]),2)  $
	                     )

	maxBase = Widget_Base(cBase, $
						  /row, $
						  ypad=0)

	label = Widget_Label(maxBase  , $
						 Value = 'Max value : '   $
	                     )

	self.maxL = Widget_Label(maxBase                , $
							 /Dynamic_Resize        , $
							 Xsize = 50             , $
						     Value = Strtrim(String(self.mmValue[1]),2)  $
	                     )

	XYBase = Widget_Base(cBase, $
						  /row, $
						  ypad=0)

	label = Widget_Label(XYBase  , $
						 Value = 'XY  value : '   $
	                     )

	self.XY = Widget_Label(XYBase                , $
							 /Dynamic_Resize        , $
							 Xsize = 50             , $
						     Value = ''               $
	                     )

	buttonBase = Widget_base(cBase, $
						     /row, $
						     ypad=0)

	self.tButton = Widget_Button(buttonBase               , $
							UName = 'Rework'	     , $
							Sensitive = 0            , $
							Value = 'rework'        $
	                        )
	widget_control, cBase, /realize

	XManager, 'SunEle'                              , $
	           cBase                                , $
	           /No_Block                            , $
	           Event_Handler = 'sesFrame_Event'   , $
  			   Cleanup = 'sesFrame_Cleanup'
END
;+
;close flow
;+
PRO sesLQU::CloseFlow
	COMPILE_OPT IDL2
	oSystem = self.oSystem
   	Obj_Destroy , self.lquContainer
	Ptr_Free,self.image
	Obj_Destroy,(oSystem.menuBar).ShowLQU
END
;+
;clean up
;+
PRO sesLQU::CleanUp
	COMPILE_OPT IDL2
	oSystem = self.oSystem
	Obj_Destroy , self.lquContainer
	Ptr_Free,self.image
	Obj_Destroy,(oSystem.menuBar).ShowLQU
END
;+
;initialize
;+
FUNCTION sesLQU::Init  , oSystem = oSystem , mmValue = mmValue

	COMPILE_OPT IDL2
	self.oSystem = oSystem
	self.mainBase = oSystem.mBase
	self.mmValue = mmValue
	(oSystem.CurrentPro).oImage->GetProperty,Data = Image
	Ptr_Free,self.image
	self.image = Ptr_New(Temporary(Image))
	self.parameter = 10000
	self->Create

	Return,1
END
;+
;LQU class name
;+
PRO sesLQU__Define
	COMPILE_OPT IDL2
	void = { sesLQU                               , $
	         ;system parameter
	         cBase              :    0L           , $
	         mainBase           :    0L           , $
	         XY                 :    0L           , $
	         tButton            :    0L           , $
	         minL               :    0L           , $
	         maxL               :    0L           , $
	         parameter          :    0            , $
	         mmValue            :    [0.0,0.0]    , $
			 ;system objct

			 lquContainer       :    Obj_New()    , $
			 Label              :    Obj_New()    , $
			 crossModel         :    Obj_New()    , $
			 image              :    Ptr_New()    , $
			 crossX             :    Obj_New()    , $
			 crossY             :    Obj_New()    , $
 	         oSystem            :    Obj_New()      $

	        }
END