#
######################################################
#
#  SaVi by Robert Thurman (thurman@geom.umn.edu) and
#          Patrick Worfolk (worfolk@alum.mit.edu).
#
#  Copyright (c) 1997 by The Geometry Center.
#  This file is part of SaVi.  SaVi is free software;
#  you can redistribute it and/or modify it only under
#  the terms given in the file COPYRIGHT which you should
#  have received along with this file.  SaVi may be
#  obtained from:
#  http://savi.sourceforge.net/
#  http://www.geom.uiuc.edu/locate/SaVi
#
######################################################
#
# coverage.tcl
#
# $Id: coverage.tcl,v 1.54 2005/02/27 00:23:09 lloydwood Exp $

# Note: IM_W and IM_H are linked to C variables for the image size

proc coverage(build) {} {
    global FONT COLOR COLDIV COLDEC coverage_flag no_access_flag tracks_flag \
	coverage_proj_flag coverage_angle_flag project_tracks_flag map_flag \
	coverage_projection coverage_angle IM_W IM_H im_x_offset im_y_offset \
	coverage_flag_dismissed tracks_flag_dismissed no_access_flag_dismissed \
	coverage_display_center_longitude coverage_name use_X geomview_module


    if [winfo exists .coverage] {
	wm deiconify .coverage
	raise .coverage
	return
    }

    set coverage_name [build_Toplevel coverage]

    wm protocol $coverage_name WM_DELETE_WINDOW coverage(dismiss)

    coverage(title)

    build_Menubar $coverage_name mbar \
	{"Help" \
             {"about SaVi..." "about(build)"} } \
	{"File" \
	     {"Load satellites..." "load(build)"} \
	     {"Save satellites as Tcl script..." "save(build)"} \
	     {} \
	     {"Save map..." "coverage(save_map)"} \
	     {} \
	     {"Load color shades..." "coverage(load_colors)"} \
	     {"Save color shades..." "coverage(save_colors)"} \
	     {} \
	     {"Close" "coverage(dismiss)"} } \
	{"Shading" \
	     {"Change shading" "coverage(run_of_colors)"} \
	     {} \
             {"Select random colors" "coverage(random_colors)"} \
	     {"Shade between end colors" "coverage(blend_colors)"} \
	     {} \
	     {"SaVi color shades" "coverage(restore_colors)"} } \
	{"Views" \
	     {"Satellite list..." "window(raise) main"} \
	     {} \
	     {"> Step forwards" "main(forw_step)"} \
	     {"< Step back" "main(back_step)"} \
	     {">> Forwards..." "main(forwards)"} \
	     {"<< Reverse..." "main(backwards)"} \
	     {"Freeze views" "main(stop)"} \
	     {} \
	     {"Refresh coverage view" "coverage(foot)"} \
	     {} \
	     {"Restart views at time zero" "main(restart)"} } \
	{"Constellations"} \
	{"Rastering"} \
	{"Rendering"}

    main(constellations_menu) $coverage_name.mbar.b3

    build_options_menu $coverage_name.mbar.b4 \
	{"Show Earth map" map_flag} \
	{} \
	{"Show coverage" coverage_flag} \
	{"Add interval decay" no_access_flag} \
	{} \
	{"Show satellites" tracks_flag} \
	{"Record ground tracks" project_tracks_flag}

    if {$geomview_module == 1} {
	build_options_menu $coverage_name.mbar.b5 \
	    {"Real-time mode" realtime_flag} \
	    {} \
	    {"Show central body" earth_flag} \
	    {"Use detailed Earth model" fancy_earth_flag} \
	    {} \
	    {"Texturemapping" texture_flag} \
	    {"Send cylindrical map to Geomview" geomview_dynamic_texture_flag}
    } else {
	build_options_menu $coverage_name.mbar.b5 \
	    {"Real-time mode" realtime_flag}
    }

    set cmd [build_CmdFrame $coverage_name cmd]

    set c "$cmd.c"
    # canvas counts from 0
    canvas $c -bg $COLOR(bg) -width $IM_W -height $IM_H
    pack $c -fill x -side top

    if {$coverage_display_center_longitude < 0} {
	set offset_longitude [expr $coverage_display_center_longitude + 360]
    } else {
	set offset_longitude $coverage_display_center_longitude
    }

    set im_x_offset [expr 2 + ($offset_longitude * -$IM_W/360)]
    set im_y_offset 2

    set im [image create photo im_coverage -width [expr $IM_W*2] -height $IM_H]
    $c create image [expr $IM_W + $im_x_offset] [expr $IM_H/2 + $im_y_offset] \
	-image $im

    # catch button click in map to get fisheye Lat/Long
    bind $c <Button-1> {coverage(lat_long) %x %y}

    set cmdq [build_StdFrame $cmd q]
    build_Optionslist $cmdq olist \
	{"Show Earth map" map_flag}
    pack $cmdq.olist -side left
    build_IPopupMenu $cmdq p0 "projected as:" \
        coverage_projection coverage(map) {"cylindrical" "unprojected" "sinusoidal" "spherical"}
    pack $cmdq.p0 -side left

    build_LabelEntryColumns $cmdq p1 \
	{text "" {"Last loaded:"}} \
	{label "" {last_filename}}

    pack $cmdq.p1 -side left
    pack $cmdq -anchor w

    set cmda [build_StdFrame $cmd a]
    build_Optionslist $cmda olist \
	{"Show coverage" coverage_flag} \
	{"Add interval decay" no_access_flag} \
	{"Show satellites" tracks_flag}
# this will give a numerical idea of coverage by latitude
#       {"Print access data" print_access_flag}
# this is hacked into utils.tcl instead.
#	{"Record ground tracks    and project forwards" project_tracks_flag}
    pack $cmda.olist -side left

    build_StdFrame $cmda ce
    # the background colors should match the colors in coverage_vis.c
    build_StdFrame $cmda.ce cf
    label $cmda.ce.cf.0 -text "diversity of coverage now:" \
	    -font $FONT(label)
    button $cmda.ce.cf.1 -text "1" -font $FONT(fixed) -bg $COLDIV(1) \
	    -activebackground $COLDIV(1) -command "coverage(diversitycolor) 1" \
	    -relief groove
    button $cmda.ce.cf.2 -text "2" -font $FONT(fixed) -bg $COLDIV(2) \
	    -activebackground $COLDIV(2) -command "coverage(diversitycolor) 2" \
	    -relief groove
    button $cmda.ce.cf.3 -text "3" -font $FONT(fixed) -bg $COLDIV(3) \
	    -activebackground $COLDIV(3) -command "coverage(diversitycolor) 3" \
	    -relief groove
    button $cmda.ce.cf.4 -text "4+" -font $FONT(fixed) -bg $COLDIV(4) \
	    -activebackground $COLDIV(4) -command "coverage(diversitycolor) 4" \
	    -relief groove
    label $cmda.ce.cf.5 -text "satellites" -font $FONT(label)
    pack $cmda.ce.cf.0 $cmda.ce.cf.1 $cmda.ce.cf.2 $cmda.ce.cf.3 $cmda.ce.cf.4 \
         $cmda.ce.cf.5 -expand 1 -fill x -side left -ipadx 2m -ipady 2m \
	 -padx 1m -pady 1m
    pack $cmda.ce.cf -side top

    build_StdFrame $cmda.ce cg
    label $cmda.ce.cg.0 -text "age of decayed coverage:" -font $FONT(label)
    button $cmda.ce.cg.1 -text "1" -font $FONT(fixed) -bg $COLDEC(1) \
	    -activebackground $COLDEC(1) -command "coverage(decaycolor) 1" \
	    -relief groove
    button $cmda.ce.cg.2 -text "2" -font $FONT(fixed) -bg $COLDEC(2) \
	    -activebackground $COLDEC(2) -command "coverage(decaycolor) 2" \
	    -relief groove
    button $cmda.ce.cg.3 -text "3" -font $FONT(fixed) -bg $COLDEC(3) \
	    -activebackground $COLDEC(3) -command "coverage(decaycolor) 3" \
	    -relief groove
    button $cmda.ce.cg.4 -text "4+" -font $FONT(fixed) -bg $COLDEC(4) \
	    -activebackground $COLDEC(4) -command "coverage(decaycolor) 4" \
	    -relief groove
    label $cmda.ce.cg.5 -text "intervals" -font $FONT(label)
    pack $cmda.ce.cg.0 $cmda.ce.cg.1 $cmda.ce.cg.2 $cmda.ce.cg.3 $cmda.ce.cg.4 \
         $cmda.ce.cg.5 -expand 1 -fill x -side left -ipadx 2m -ipady 2m \
	 -padx 1m -pady 1m
    pack $cmda.ce.cg -side top

    pack $cmda.ce -side right -fill both

    pack $cmda -fill both

    build_LabelEntryColumns $cmd le2 \
	{lcheckbox "" project_tracks_flag} \
	{ientry "" {tracks_interval}} \
	{text "" {hours}}

    build_IPopupMenu $cmd p2 "Coverage angle describes:" \
	coverage_angle_flag coverage(foot) {"ground terminal mask elevation" "cones from satellites"}

    pack $cmd.p2 -fill both -expand 1

    set cmdb [build_StdFrame $cmd b]

    button $cmdb.b1 -font $FONT(button)
    $cmdb.b1 configure -text "Set angle:" \
		-command "coverage(foot)"
    pack $cmdb.b1 -side left

    build_LabelEntryColumns $cmdb le1 \
	{dentry "" {coverage_angle}} \
	{label "" {coverage}} \
	{label "" {mean_coverage}}

    pack $cmdb.le1

    pack $cmdb -fill both -expand 1

    set cmdd [build_StdFrame $cmd d]

    build_LabelEntryColumns $cmdd le0 \
	{label "" {coverage_init_time}} \
	{label "" {coverage_time}} \
	{text "" "Time:"} \
	{label "" {time}}

    pack $cmdd.le0 -side left
    pack $cmdd -fill both -expand 1

    pack $cmd -fill both -side top -expand 1

    build_Buttonbar $coverage_name bb1 \
        {"Restart" coverage(restart)} \
        {"  <  " coverage(back_step)} \
        {"  >  " coverage(forw_step)} \
        {"  STOP  " coverage(stop)} \
        {"   < <   " coverage(backwards)} \
        {"   > >   " coverage(forwards)}

    set coverage_flag $coverage_flag_dismissed
    set tracks_flag $tracks_flag_dismissed

    coverage(update)
}

proc coverage(forw_step) {} {
    main(forw_step)
}

proc coverage(back_step) {} {
    main(back_step)
}

proc coverage(forwards) {} {
    global COLOR playbar

    if {([winfo exists .coverage])} {
	.coverage.bb1.b3 configure -bg $COLOR(bg)
	.coverage.bb1.b4 configure -bg $COLOR(bg)
	.coverage.bb1.b5 configure -bg $COLOR(sbg)
    }
    set flag $playbar
    set playbar 1
    if {$flag == 0} {
	main(forwards)
    }
    set playbar 0
}

proc coverage(backwards) {} {
    global COLOR playbar

    if {([winfo exists .coverage])} {
	.coverage.bb1.b3 configure -bg $COLOR(bg)
	.coverage.bb1.b4 configure -bg $COLOR(sbg)
	.coverage.bb1.b5 configure -bg $COLOR(bg)
    }
    set flag $playbar
    set playbar 1
    if {$flag == 0} {
	main(backwards)
    }
    set playbar 0
}

proc coverage(stop) {} {
    global COLOR playbar

    if {([winfo exists .coverage])} { 
	.coverage.bb1.b3 configure -bg $COLOR(sbg)
	.coverage.bb1.b4 configure -bg $COLOR(bg)
	.coverage.bb1.b5 configure -bg $COLOR(bg)
    }
    set flag $playbar
    set playbar 1
    if {$flag == 0} {
	main(stop)
    }
    set playbar 0
}

proc coverage(restart) {} {

    coverage(stop)
    satellites RESET

}

proc coverage(init_colors) {} {
    global COLDIV COLDEC NUMCOLORS
    global DIV0 DIV1 DIV2 DIV3 DIV4
    global DEC0 DEC1 DEC2 DEC3 DEC4

    set NUMCOLORS 4

    # set diversity colors to shades of yellow
    # strings
    set COLDIV(0) #ffffff
    set COLDIV(1) #ffff00
    set COLDIV(2) #ffaa00
    set COLDIV(3) #ff5500
    set COLDIV(4) #ff0000

    # ints
    set DIV0 [expr 0xffffff]
    set DIV1 [expr 0xffff00]
    set DIV2 [expr 0xffaa00]
    set DIV3 [expr 0xff5500]
    set DIV4 [expr 0xff0000]

    # set decay colors to shades of blue
    #strings
    set COLDEC(0) #ffffff
    set COLDEC(1) #0000ff
    set COLDEC(2) #0000d9
    set COLDEC(3) #0000b4
    set COLDEC(4) #00008f

    #ints
    set DEC0 [expr 0xffffff]
    set DEC1 [expr 0x0000ff]
    set DEC2 [expr 0x0000d9]
    set DEC3 [expr 0x0000b4]
    set DEC4 [expr 0x00008f]
}

proc coverage(update_colors) {} {
global DIV1 DIV2 DIV3 DIV4 DEC1 DEC2 DEC3 DEC4 COLDIV COLDEC

    for {set i 1} {$i < 5} {incr i} {
        set name DIV$i
	set COLDIV($i) [eval format "#%06x" $$name]
	.coverage.cmd.a.ce.cf.$i configure -bg $COLDIV($i) \
	  -activebackground $COLDIV($i)

	set name DEC$i
	set COLDEC($i) [eval format "#%06x" $$name]
	.coverage.cmd.a.ce.cg.$i configure -bg $COLDEC($i) \
	  -activebackground $COLDEC($i)
    }
    satellites COLOR_UPDATE
    coverage(update)
}

proc coverage(random_colors) {} {
    global DIV1 DIV2 DIV3 DIV4 DEC1 DEC2 DEC3 DEC4

    for {set i 1} {$i < 5} {incr i} {
	set DIV$i [random_color]
	set DEC$i [random_color]
    }
    coverage(update_colors)
}

proc coverage(restore_colors) {} {

    coverage(init_colors)

    coverage(update_colors)
}

proc coverage(run_of_colors) {} {
    global DIV1 DIV4 DEC1 DEC4

    set DIV1 [random_color]
    set DIV4 [random_color]

    set DEC1 [random_color]
    set DEC4 [random_color]

    coverage(blend_colors)
}

proc coverage(blend_colors) {} {
    global DIV1 DIV2 DIV3 DIV4 DEC1 DEC2 DEC3 DEC4

    set DIV1B [expr $DIV1 % 256]
    set DIV1G [expr ($DIV1 - $DIV1B)/256 % 256]
    set DIV1R [expr ($DIV1 - $DIV1B - $DIV1G * 256) / 65536]

    set DIV4B [expr $DIV4 % 256]
    set DIV4G [expr ($DIV4 - $DIV4B)/256 % 256]
    set DIV4R [expr ($DIV4 - $DIV4B - $DIV4G * 256) / 65536]

    set DEC1B [expr $DEC1 % 256]
    set DEC1G [expr ($DEC1 - $DEC1B)/256 % 256]
    set DEC1R [expr ($DEC1 - $DEC1B - $DEC1G * 256) / 65536]

    set DEC4B [expr $DEC4 % 256]
    set DEC4G [expr ($DEC4 - $DEC4B)/256 % 256]
    set DEC4R [expr ($DEC4 - $DEC4B - $DEC4G * 256) / 65536]

    set DIVRinc [expr ($DIV4R - $DIV1R) / 3 * 65536]
    set DIVGinc [expr ($DIV4G - $DIV1G) / 3 * 256]
    set DIVBinc [expr ($DIV4B - $DIV1B) / 3]

    set DECRinc [expr ($DEC4R - $DEC1R) / 3 * 65536]
    set DECGinc [expr ($DEC4G - $DEC1G) / 3 * 256]
    set DECBinc [expr ($DEC4B - $DEC1B) / 3]

    set DIV2 [expr $DIV1 + $DIVRinc + $DIVGinc + $DIVBinc]
    set DIV3 [expr $DIV2 + $DIVRinc + $DIVGinc + $DIVBinc]

    set DEC2 [expr $DEC1 + $DECRinc + $DECGinc + $DECBinc]
    set DEC3 [expr $DEC2 + $DECRinc + $DECGinc + $DECBinc]

    coverage(update_colors)
}

proc coverage(save_colors) {} {
    global Save DIV1 DIV2 DIV3 DIV4 DEC1 DEC2 DEC3 DEC4

    set types {
        {"SaVi coverage color shades"  {.shades} }
    }

    set filename [tk_getSaveFile -filetypes $types \
	          -title "SaVi: save coverage color shades" ]

    if {"$filename" == ""} return

    if {![string_ends "$filename" ".shades"]} {
	set filename "$filename.shades"
    }

    # open file
    set f [open "$filename" w]
    if {$f == ""} {
	puts stderr "SaVi: couldn't save coverage color shades to $filename"
	return
    }

    # write colors
    puts $f "\# SaVi saved coverage color shades"
    puts $f "\# http://savi.sourceforge.net/"

    for {set i 1} {$i < 5} {incr i} {
      set name DIV$i
	set name [expr $$name]
      puts $f "set DIV$i $name"
      set name DEC$i
	set name [expr $$name]
      puts $f "set DEC$i $name"
    }

    close $f

    puts stderr "SaVi: saved coverage color shades to $filename"
}

proc coverage(load_colors) {} {

    set types {
        {"SaVi coverage color shades"  {.shades} }
    }

    set filename [tk_getOpenFile -filetypes $types \
	          -parent .main -title "SaVi: load coverage color shades" ]

    if {"$filename" == ""} return

    coverage(source_colors) "$filename"
    coverage(update_colors)

}

proc coverage(source_colors) {filename} {
    global DIV1 DIV2 DIV3 DIV4 DEC1 DEC2 DEC3 DEC4

    source "$filename"   
}

proc coverage(diversitycolor) {n} {
    global COLDIV DIV1 DIV2 DIV3 DIV4

    if {$n == "1"} {
	set s ""
    } else {
	set s "s"
    }

    set color [tk_chooseColor -initialcolor $COLDIV($n) -parent .coverage \
	    -title "SaVi: diversity color for $n satellite$s visible"]
    if {($color != "") && ($color != $COLDIV($n))} {
	set COLDIV($n) $color
	.coverage.cmd.a.ce.cf.$n configure -bg $COLDIV($n) \
		-activebackground $COLDIV($n)
	set value [string range $COLDIV($n) 1 6]
	set DIV$n [expr 0x$value]
    }
    satellites COLOR_UPDATE
    coverage(update)
}

proc coverage(decaycolor) {n} {
    global COLDEC DEC1 DEC2 DEC3 DEC4

    if {$n == "1"} {
	set s ""
    } else {
	set s "s"
    }

    set color [tk_chooseColor -initialcolor $COLDEC($n) -parent .coverage \
	    -title "SaVi: decay color for $n interval$s since covered"]
    if {($color != "") && ($color != $COLDEC($n))} {
	set COLDEC($n) $color
	.coverage.cmd.a.ce.cg.$n configure -bg $COLDEC($n) \
		-activebackground $COLDEC($n)
	set value [string range $COLDEC($n) 1 6]
	set DEC$n [expr 0x$value]
    }
    satellites COLOR_UPDATE
    coverage(update)
}

proc coverage(save_map) {} {
    global Save last_map_filename

    set types {
	{"SaVi coverage map (gzipped)" {.ppm.gz} }
    }

    set filename [tk_getSaveFile -filetypes $types \
	          -parent .coverage -title "SaVi: save coverage map" ]

    if {"$filename" == ""} return

    set last_map_filename "$filename"

    if {[string_ends "$filename" ".gz"]} {
	set filename [string range "$filename" 0 [expr $length - 4]]
    }

    if {![string_ends $filename ".ppm"]} {
	set filename "$filename.ppm"
    }

    satellites COVERAGE_SAVE_MAP "$filename"

    puts stderr "SaVi: saved map as raw ppm to $filename"
    exec gzip -9 "$filename"
    puts stderr "SaVi: gzip-compressed map to $filename.gz"
}

proc coverage(dismiss) {} {
    global coverage_flag tracks_flag \
	   coverage_flag_dismissed tracks_flag_dismissed

    set coverage_flag_dismissed $coverage_flag
    set tracks_flag_dismissed $tracks_flag

    # turn off flags to avoid computing drawing when window not shown
    set coverage_flag 0
    set tracks_flag 0

    destroy .coverage
}

proc coverage(update_decay) {} {
    global no_access_flag

    if {$no_access_flag == 0} return

    # Removing satellites leaves gaps in decay, so we reset this before
    # coverage flags are reset in coverage(update)
    set flag $no_access_flag
    set no_access_flag 1
    if {$flag == 0} {
	set no_access_flag 0
    }
}

proc coverage(update) {} {
    global coverage_flag tracks_flag

    if {![winfo exists .coverage]} return

    set flag $coverage_flag
    set coverage_flag 1
    if {$flag == 0} {
	set coverage_flag 0
    }

    set flag $tracks_flag
    set tracks_flag 1
    if {$flag == 0} {
	set tracks_flag 0
    }

    update
}

proc coverage(lat_long) {x y} {
    global Fisheye coverage_projection IM_W IM_H im_x_offset im_y_offset \
	   Longitude_Center_Line PI coverage_display_center_longitude

    set x [expr $x-$im_x_offset]
    set y [expr $y-$im_y_offset]

    set HALF_X [expr $IM_W/2]
    set HALF_Y [expr $IM_H/2]

    set off_map 0

    if {$coverage_projection == 0} {
	# cylindrical
	set long [expr (($x%$IM_W)-$HALF_X)/double($IM_W)*360.0+$Longitude_Center_Line]
	set y [expr 1-$y/double($IM_H)*2]
	if {$y < -1} {
	    set y -1
	} elseif {$y > 1} {
	    set y 1
	}
	set lat [expr asin($y)/$PI*180.0]
    } elseif {$coverage_projection == 1} {
	# unprojected
	set long [expr (($x%$IM_W)-$HALF_X)/double($IM_W)*360.0+$Longitude_Center_Line]
	set y [expr 1-$y/double($IM_H)*2]
	if {$y < -1} {
	    set y -1
	} elseif {$y > 1} {
	    set y 1
	}
	set lat [expr $y*90]
    } elseif {$coverage_projection == 2} {
	# sinusoidal
	set lat [expr ($HALF_Y-$y)/double($HALF_Y)*90.0]
	if {abs($lat) == 90} {
	    set long 0
	} else {
	    set long [expr \
	    (($x%$IM_W)-$HALF_X)/double($HALF_X)/cos($lat/180.0*$PI)*180 + $Longitude_Center_Line]
	}
	# below presumes that LCR is -90; it depends on the ppm map anyway.
	if {$long > ($Longitude_Center_Line+180)} {
	    set long [expr $Longitude_Center_Line+180]
	    set off_map 1
	} elseif {$long < ($Longitude_Center_Line-180)} {
	    set long [expr $Longitude_Center_Line+180]
	    set off_map 1
	}
    } elseif {$coverage_projection == 3} {
	# spherical
	set y [expr 1-$y/double($IM_H)*2]
	if {$y < -1} {
	    set y -1
	} elseif {$y > 1} {
	    set y 1
	}
	set lat [expr asin($y)/$PI*180.0]
        set long [expr 0]
        # longitude equation to be worked out.
    }

    if {$off_map == 0} {
	if {$long <= -180} {
	    set long [expr $long+360]
	} elseif {$long > 180} {
	    set long [expr $long-360]
	}
    }

    set Fisheye(lat_degrees) [expr {$lat<0 ? -int(-$lat) : int($lat)} ]
    set Fisheye(lat_minutes) [expr abs($lat-$Fisheye(lat_degrees))*60.0]
    set Fisheye(long_degrees) [expr {$long<0 ? -int(-$long) : int($long)} ]
    set Fisheye(long_minutes) [expr abs($long-$Fisheye(long_degrees))*60.0]

    if {![winfo exists .fisheye]} {
	puts stderr "SaVi: you selected (latitude,longitude) of ($Fisheye(lat_degrees),$Fisheye(long_degrees))"
    }

    # We could call fisheye(apply) here to set the coordinates directly,
    # but it's more useful to just know where you've clicked without also
    # changing the fisheye location.

}

proc coverage(foot) {} {
    coverage(update_decay)
    coverage(update)
}

proc coverage(title) {} {
    global coverage_name coverage_projection

    if {$coverage_projection == 0} {
	build_Title $coverage_name "view of coverage on cylindrical Earth map"
    } elseif {$coverage_projection == 1} {
	build_Title $coverage_name "view of coverage on unprojected (equirectangular) Earth map"
    } elseif {$coverage_projection == 2} {
	build_Title $coverage_name "view of coverage on sinusoidal Earth map (centred on 90W for Americas)"
    } elseif {$coverage_projection == 3} {
	build_Title $coverage_name "view of coverage on east/west hemispheres (equatorial orthographic maps)"
    }
}

proc coverage(map) {} {
    global coverage_proj_flag coverage_projection last_coverage_projection \
	geomview_module geomview_dynamic_texture_flag texture_flag \
	earth_flag fancy_earth_flag

    if {$coverage_projection == $last_coverage_projection} return

    coverage(title)

    set coverage_proj_flag [expr 1 - $coverage_proj_flag]

    # this is a hack to reset Earth while dynamic texturemapping if changed
    # from cylindrical projection.
    if {$geomview_module && $geomview_dynamic_texture_flag && $texture_flag && \
        $earth_flag && $fancy_earth_flag && ($last_coverage_projection == 0) && \
	($coverage_projection != 0)} {
	set texture_flag 0
	set texture_flag 1
    }
    set last_coverage_projection $coverage_projection

    coverage(update)
}
