source new_compass.tcl

set cp .compass_popup
set compass_type "fog"

proc compass_popup { } {

    global cp compass_type

    if [winfo exists $cp] {destroy $cp}	

    global env
    set env(DISPLAY) :0
    toplevel $cp -width 95m -height 10c
    wm title $cp "Compass"	

    #--------------------
    # Declare variables
    #--------------------

    label $cp.compass_title \
        -foreground #0000d4 -height 0 -relief groove -text Compass -width 250
    label $cp.type_label \
        -height 0 -text Type
    label $cp.xlabel \
        -text "X Pos"
    label $cp.ylabel \
        -text "Y Pos"
    label $cp.fog_deviation_label \
        -text "Fog Deviation"
    label $cp.fog_declination_label \
        -text "Fog Declination"
    label $cp.compass_deviation_label \
        -text "Compass Deviation"
    label $cp.compass_declination_label \
        -text "Compass Declination"

    radiobutton $cp.fog -text "Primary" -variable compass_type -value fog
    radiobutton $cp.backup -text "Backup" -variable compass_type -value backup_comp

    entry $cp.xentry \
        -background white -textvariable compass_xpos
    entry $cp.yentry \
        -background white -textvariable compass_ypos
    entry $cp.fog_deviation_entry \
        -background white -textvariable fog_deviation
    entry $cp.fog_declination_entry \
        -background white -textvariable fog_declination
    entry $cp.compass_deviation_entry \
        -background white -textvariable compass_deviation
    entry $cp.compass_declination_entry \
        -background white -textvariable compass_declination
    button $cp.add \
        -command {add_compass} -text Add
    button $cp.remove \
        -command {remove_compass} -height 0 -text Remove -width 0
    button $cp.close \
        -command {close_compass} -text Close




    #---------------------------------------------------------------
    # Bind the motion of the mouse to display the mouse
    # coordinate at current time
    #---------------------------------------------------------------

    bind .ventana <ButtonRelease-1> {
    	global compass_xpos compass_ypos
      	set compass_xpos %x
     	set compass_ypos %y
    }	
    bind $cp.compass_deviation_entry <Return> { set_compass_deviation  $fog_deviation $compass_deviation $fog_declination $compass_declination }	
    bind $cp.compass_declination_entry <Return> { set_compass_deviation  $fog_deviation $compass_deviation $fog_declination $compass_declination }	
    bind $cp.fog_deviation_entry <Return> { set_compass_deviation  $fog_deviation $compass_deviation $fog_declination $compass_declination }	
    bind $cp.fog_declination_entry <Return> { set_compass_deviation  $fog_deviation $compass_deviation $fog_declination $compass_declination }	
  	
    #---------------------------------------------------------------

    ###################
    # SETTING GEOMETRY
    ###################
    place $cp.compass_title \
        -x 15 -y 10 -width 250 -height 20 -anchor nw -bordermode ignore
    place $cp.type_label \
        -x 5 -y 45 -anchor nw -bordermode ignore
    place $cp.xentry \
        -x 65 -y 70 -anchor nw -bordermode ignore
    place $cp.yentry \
        -x 65 -y 95 -anchor nw -bordermode ignore
    place $cp.xlabel \
        -x 5 -y 70 -anchor nw -bordermode ignore
    place $cp.ylabel \
        -x 5 -y 95 -anchor nw -bordermode ignore
    place $cp.fog \
        -x 40 -y 45 -anchor nw -bordermode ignore
    place $cp.backup \
        -x 125 -y 45 -anchor nw -bordermode ignore
    place $cp.fog_deviation_label \
        -x 5 -y 175 -anchor nw -bordermode ignore
    place $cp.fog_declination_label \
        -x 5 -y 200 -anchor nw -bordermode ignore
    place $cp.fog_deviation_entry \
        -x 140 -y 175 -anchor nw -bordermode ignore -width 80
    place $cp.fog_declination_entry \
        -x 140 -y 200 -anchor nw -bordermode ignore -width 80
    place $cp.compass_deviation_label \
        -x 5 -y 225 -anchor nw -bordermode ignore
    place $cp.compass_declination_label \
        -x 5 -y 250 -anchor nw -bordermode ignore
    place $cp.compass_deviation_entry \
        -x 140 -y 225 -anchor nw -bordermode ignore -width 80
    place $cp.compass_declination_entry \
        -x 140 -y 250 -anchor nw -bordermode ignore -width 80
    place $cp.add \
        -x 20 -y 125 -anchor nw -bordermode ignore
    place $cp.remove \
        -x 70 -y 125 -anchor nw -bordermode ignore
    place $cp.close \
        -x 150 -y 125 -anchor nw -bordermode ignore

# end of proc "compas_popup"
}


proc add_compass { } {

    	# Declare the variables
    	global cp
    	global compass_type compass_xpos  compass_ypos
        global compass_deviation compass_declination fog_deviation fog_declination

  	if {$compass_xpos == ""} {
	  	set compass_xpos 0
  	}
  	
  	if {$compass_ypos == ""} {
  		set compass_ypos 0  	
  	}
  	
   	if {$compass_deviation == ""} {
  		set compass.deviation 0  	
  	}
  	
   	if {$compass_declination == ""} {
  		set compass_declination 0  	
  	}
   	
   	if {$fog_deviation == ""} {
  		set fog.deviation 0  	
  	}
  	
   	if {$fog_declination == ""} {
  		set fog_declination 0  	
  	}
	
        get_compass_window_path_name $compass_type
        set_compass_pos $compass_xpos $compass_ypos

        # Call the procedure from "new_compass.tcl" here  to display compass
        display_heading_or_not 1

        #-------------------------------------------#
        # This will send the info down to database  #
        #-------------------------------------------#
        set_graphic_info "compass" $compass_type $compass_xpos $compass_ypos 1
        set_compass_deviation  $fog_deviation $compass_deviation $fog_declination $compass_declination

# end of procedure "add_compass"
}

proc remove_compass { } {

      	# Declare the variables
        global compass_type
       	set vhframe .ventana.editor.$compass_type
	
      	#----------------------------------------------------#
      	# Check if the button name has already exists        #
      	#----------------------------------------------------#
      	if [winfo exists $vhframe] {
         	get_compass_window_path_name $compass_type
         	display_heading_or_not 0
	   	set_graphic_info "compass" $compass_type -1 -1 1
      	}  else {

         	set status [tk_dialog .warning { } { The Compass you are trying to remove does not exist ! } \
			warning 0 {Close} ]
       	
	       	switch $status {
			0 return
         	}

       	# end 'else'
       	}


# end of procedure "remove_compass"
}



proc close_compass { } {

        global compass_deviation compass_declination fog_deviation fog_declination
        global cp

	destroy $cp
	set_compass_deviation  $fog_deviation $compass_deviation $fog_declination $compass_declination

# end of procedure "close_compass"
}