!
! Depth contour support
!


!
! Adjust limits stuff.
!
procedure depcont-adjust comp string
	popup dc-limits
endprocedure


define widget dc-limits form 'depth contour adjuster'
	popup dc-popup
	noheader
!
! Title line.
!
	label title 'Adjust depth contour limits'
	button 'apply' 'Apply' command dc-apply
	button 'dismiss' 'Dismiss' color red command 'popdown #ui$form'
	label comp 'comp' color gray95 width 1
	newline
!
! time period
!
	label l1 'Time period:'
	blank time 'funky' width 60 command dc-apply
	label l2 's = seconds, m = minutes, h = hours, d = days'
	newline
!
! Scale mode.
!
	label l3 'Depth limit mode:'
	button d-mode 'weird' command 'dc-ToggleMode d-mode' width 70
!
! Manual values
!
	label l4 'Manual scale min:'
	blank d-min 'min' width 60 command dc-apply
	label l5 'max:'
	blank d-max 'max' width 60 command dc-apply
!
! Same for dependent variable  (sigh someday)
!
	newline
	label l6 'Field limit mode:'
	button f-mode 'weird' command 'dc-ToggleMode f-mode' width 70
!	newline
!
! Manual values
!
	label l7 'Manual scale center:'
	blank f-center 'min' width 60 command dc-apply
	label l8 'step:'
	blank f-step 'max' width 60 command dc-apply
enddef


procedure dc-popup
	local c icon_component
	local f PDParam(c,'z-field')
	formtext #ui$form comp #c
!
! Do the time period.
!
	local period PDParam('global','xy-series-span')
	formtext #ui$form time #period
!
! Fill in the scale mode.
!
	local mode PDSearch(c,'scale-y-mode','xy-contour')
	if (mode = '(Undefined)')
		local mode 'autoscale'
	endif
	formtext #ui$form d-mode #mode
!
! And the manual values.
!
	local min PDSearch(c,'scale-y-min','depth')
	if (min = "(Undefined)")
		local min "0.0"
	endif
	formtext #ui$form d-min #min
	local max PDSearch(c,'scale-y-max','depth')
	if (max = "(Undefined)")
		local max "0.0"
	endif
	formtext #ui$form d-max #max
!
! Now do field values too
!
	local mode PDSearch(c,'scale-z-mode','xy-contour')
	if (mode = '(Undefined)')
		local mode 'autoscale'
	endif
	formtext #ui$form f-mode #mode
!
! And the manual values.
!
	local center PDSearch(c,'scale-z-center',f)
	if (center = "(Undefined)")
		local center "0.0"
	endif
	formtext #ui$form f-center #center
	local step PDSearch(c,'scale-z-step',f)
	if (step = "(Undefined)")
		local step "0.0"
	endif
	formtext #ui$form f-step #step
endprocedure


procedure dc-apply
	local c getftext(ui$form,'comp')
	local t getftext(ui$form,'time')
	local f PDParam(c,'z-field')

	parameter 'global' 'xy-series-span' #t

	local mode getftext(ui$form,'d-mode')
	parameter #c 'scale-y-mode' #mode
	local min getftext(ui$form,'d-min')
	parameter 'global' depth-scale-y-min #min
	local max getftext(ui$form,'d-max')
	parameter 'global' depth-scale-y-max #max

	local mode getftext(ui$form,'f-mode')
	parameter #c 'scale-z-mode' #mode
	local center getftext(ui$form,'f-center')
	local param concat(f,'-scale-z-center')
	parameter 'global' #param #center
	local step getftext(ui$form,'f-step')
	local param concat(f,'-scale-z-step')
	parameter 'global' #param #step
endprocedure


!
! Tweak autoscale mode.
!
procedure dc-ToggleMode mode string
	local current getftext(ui$form, mode)
	if (current = 'manual')
		formtext #ui$form #mode 'autoscale'
	else
		formtext #ui$form #mode 'manual'
	endif
endprocedure
