!
! Useful stuff for station plots.
!
require simple-color
require winds

!
! Toggle quadrants on a station plot.  Intended to be called out of the
! field menu.
!
! This thing is becoming misnamed as it gets called from numerous contexts,
! only one of which calls for traditional "toggling"....
!
procedure p_toggle_quadrant field string
!
! Check and see if this dude is being called out of a position icon;
! if so, we really want to ship the result out elsewhere.
!
	if (area_type = "posicon")
		local cmd quote(concat4 ('putscalar ',icon_platform,' ',field))
		dm #cmd
		return
	endif
!
! Maybe it's even coming from the annotation??  If so the "platform" is really
! the quad number and we just stuff it in directly.
!
	if (area_type = "annot")
		parameter #icon_component #icon_platform #field
		return
	endif
!
! Start by seeing if this field is on display.
!
	foreach quad 1 2 3 4
		local pname concat("quad",quad)
		if (pd_param (icon_component, pname, "string") = field)
			parameter #icon_component #pname "none"
			return
		endif
	endfor
!
! Nope not there.  Look for a spot to put it.
!
	foreach quad 1 2 3 4
		local pname concat("quad",quad)
		local value pd_param(icon_component, pname, "string")
		if (value = "none" or value = "(Undefined)")
			parameter #icon_component #pname #field
			return
		endif
	endfor
! No such luck -- they have to delete something first.   ...or should we
! just overwrite some quad?
	dm "beep"
endprocedure

!
! The right button menu for station plots.
!
define widget p-station-right intmenu 'meaningless title here'
	title 'Station Plot Options'
	line
	entry "Spatial filtering..." 'popup SpaceFilter'
	submenu 'Color' 'simple-color'
	submenu	'Arrow Line Width' 'linewidth'
	submenu 'Barbs/Vectors' 'winds-style'
	submenu 'Annotation Size' 'side-annot-scale'
endmenu


!
! Control over spatial filtering.
!
define widget Spacefilter form "Adjust Spatial Filters"
	popup space-popup
	noheader
!!first line
	label l0 "Adjust Spatial Filtering"
	label comp "comp" color gray95 width 1
	newline
!!second line
	button help "Help" command 'help spatialfilter'
	button apply "Apply" command space-adjust
	button cancel "Dismiss" color red command 'popdown #ui$form'
	newline
!!third line
	label l1 "Spatial Filter is "
	button SpaceEnable "wrong" command 'ToggleEnable SpaceEnable' width 80
!!fourth line
	newline
	label l2 "Spatial Filter:"
	blank space "space" width 50
!	label l3 "pixels between stations"
!	newline
!	label gripe ' ' color red width 200
enddef

procedure space-adjust
	local c getftext(ui$form,'comp')
	local space getftext(ui$form,'space')
	parameter #c 'filter-resolution' #space
	local spaceenable getftext(ui$form,'SpaceEnable')
	if (spaceenable = "Enabled")
		parameter #c 'spatial-filter' 'true'
	else
		parameter #c 'spatial-filter' 'false'
	endif
endprocedure

!
! Popup procedure to initialize the spatial filter widget.
!
procedure space-popup
	local f ui$form
	local plat pd_param(icon_component,'platform','string')
	formtext #f comp #icon_component
!deal with whether filter is enabled
	local enabled pd_paramsearch(icon_component,'spatial-filter','platform','string')
	if (enabled='true')
		formtext #f SpaceEnable "Enabled"
	else
		formtext #f SpaceEnable "Disabled"
	endif
!deal with filter
	local space pd_param(icon_component,'filter-resolution','string')
	if (space = '(Undefined)')
		local space '50'
	endif
	formtext #f space #space
endprocedure


define widget side-annot-scale intmenu 'Side annotation'
	title 'Annotation Size'
	line
	entry 'Small' 'do_side_annot_size 11' \
		(pd_param(icon_component, "sa-scale", "string") = "11")
	entry 'Medium' 'do_side_annot_size 20' \
		(pd_param(icon_component, "sa-scale", "string") = "20")
	entry 'Large' 'do_side_annot_size 30' \
		(pd_param(icon_component, "sa-scale", "string") = "30")
endmenu

procedure do_side_annot_size size string
	parameter #icon_component sa-scale #size
endprocedure

