source elem_prop.tcl

set over .overlay
set overlay_color 0
set overlay_list ""
set commstring "Tranmitted From Comm 0"
set enablestring "000111"
set insertstring "Inserted String"
set overlaystring "Overlay String"
set overlay_string_enable 1
    set temp [split [get_overlay_strings_from_file] |]
    set enablestring [lindex $temp 0]
    set insertstring [lindex $temp 1]

set overlay_string_timer 0

proc overlay { } {
	
    global over
    global overlay_color overlay_list
    global commstring enablestring insertstring overlaystring
    global overlay_string_enable

    if [winfo exists $over] {destroy $over}
		
    global env
    set env(DISPLAY) :0
    toplevel $over -width 25c -height 17c
    wm title $over "Overlay Field"
	
    label $over.lab43 \
        -foreground #0000d0 -relief groove -text {Add Overlay Field} \
        -width 351
    label $over.lab44 \
        -foreground #0000d0 -height 0 -relief groove \
        -text {Existing Overlay Field} -width 178

    label $over.lab58 \
        -height 0 -text {Overlay Fields}

    listbox $over.lis57 -font {Halvetica 10} \
        -background white -height 226 -width 148 \
	-yscroll "$over.scr59 set"

    scrollbar $over.scr59 \
        -width 16 -command {$over.lis57 yview}

    frame $over.fra65 \
        -borderwidth 2 -height 180 -relief groove -width 180
    radiobutton $over.fra65.rad66 \
        -text Analog -variable ov_type  -value analog  -command {select_analog}
    radiobutton $over.fra65.rad68 \
        -text Dive -variable ov_type  -value dive  -command {set type_entry "Dive"}
    radiobutton $over.fra65.rad69 \
        -text Pitch -variable ov_type  -value pitch -command {set type_entry "Pitch"}
    radiobutton $over.fra65.rad70 \
        -text Roll -variable ov_type  -value roll  -command {set type_entry "Roll"}
    radiobutton $over.fra65.rad71 \
     -text DVLaltitude -variable ov_type  -value dvlaltitude  -command {set type_entry "DVLaltitude"}

    entry $over.fra65.ent78 \
        -background white -textvariable type_entry
    label $over.lab71 \
        -text {Select type}
    label $over.lab73 \
        -text {Line (5-20)}
    label $over.lab74 \
        -height 0 -text {Column (1-4)}
    entry $over.ent75 \
        -background white -textvariable ovline_entry -width 88
    entry $over.ent76 \
        -background white -textvariable ovcol_entry -width 88
    label $over.lab77 \
        -height 0 -text Color -width 0
    frame $over.fra79 \
        -borderwidth 2 -height 225 -relief groove -width 160
    radiobutton $over.fra79.rad80 \
        -text Black -variable ov_color -value black  -command {set overlay_color 0}
    radiobutton $over.fra79.rad81 \
        -text Green -variable ov_color -value green -command {set overlay_color 2}
    radiobutton $over.fra79.rad82 \
        -text Red -variable ov_color -value red  -command {set overlay_color 1}
    radiobutton $over.fra79.rad83 \
        -text Cyan -variable ov_color  -value cyan  -command {set overlay_color 6}
    radiobutton $over.fra79.rad84 \
        -text White -variable ov_color  -value white -command {set overlay_color 7}
    radiobutton $over.fra79.rad85 \
        -text Magenta -variable ov_color -value magenta  -command {set overlay_color 5}
    radiobutton $over.fra79.rad86 \
        -text Blue -variable ov_color  -value blue -command {set overlay_color 4}
    radiobutton $over.fra79.rad87 \
        -text Yellow -variable ov_color -value yellow  -command {set overlay_color 3}

    # Units
    entry $over.fra65.units -width 5 -bg white -textvariable unit

    # Button to add a field
    button $over.but88 \
        -command {add_o_item $type_entry $ovline_entry $ovcol_entry $overlay_color $unit} \
        -height 0 -text Add
    button $over.but89 \
        -command {delete_o_item $type_entry} -text Remove
    button $over.but90 \
        -command {destroy .overlay} -text Close

    # For the String from Comm Rocket Port 0 to be displayed
    entry $over.commstring_entry \
           -background white -textvariable commstring -width 100 -state disabled -font {Halvetica 10}
    label $over.commstring_lable \
        -height 0 -text String -width 0

    entry $over.enablestring_entry \
           -background white -textvariable enablestring -width 100 -font {Halvetica 10}
    label $over.enablestring_lable \
        -height 0 -text {Enable Bits} -width 0

    entry $over.insertstring_entry \
           -background white -textvariable insertstring -width 100 -font {Halvetica 10}
    label $over.insertstring_lable \
        -height 0 -text {Insert Text} -width 0

    entry $over.overlaystring_entry \
           -background white -textvariable overlaystring -width 100 -state disabled -font {Halvetica 10}
    label $over.overlaystring_lable \
        -height 0 -text {Overlay Text} -width 0

    checkbutton $over.overlaystring_enable \
        -text {Overlay the String} -variable overlay_string_enable


    ###################
    # SETTING GEOMETRY
    ###################
    place $over.lab43 \
        -x 20 -y 15 -width 351 -height 20 -anchor nw -bordermode ignore
    place $over.lab44 \
        -x 390 -y 15 -width 178 -height 20 -anchor nw -bordermode ignore
    place $over.lis57 \
        -x 395 -y 75 -width 148 -height 226 -anchor nw -bordermode ignore
    place $over.lab58 \
        -x 390 -y 50 -anchor nw -bordermode ignore
    place $over.scr59 \
        -x 540 -y 75 -width 16 -height 225 -anchor nw -bordermode ignore

    # Type
    place $over.fra65 \
        -x 20 -y 75 -width 180 -height 180 -anchor nw -bordermode ignore
    place $over.fra65.rad66 \
        -x 10 -y 50 -anchor nw -bordermode ignore
    place $over.fra65.rad68 \
        -x 10 -y 75 -anchor nw -bordermode ignore
    place $over.fra65.rad69 \
        -x 10 -y 100 -anchor nw -bordermode ignore
    place $over.fra65.rad70 \
        -x 10 -y 125 -anchor nw -bordermode ignore
    place $over.fra65.rad71 \
     -x 10 -y 150 -anchor nw -bordermode ignore

    place $over.fra65.ent78 \
        -x 15 -y 15 -anchor nw -bordermode ignore
    place $over.lab71 \
        -x 20 -y 50 -anchor nw -bordermode ignore
    place $over.lab73 \
        -x 20 -y 260 -anchor nw -bordermode ignore
    place $over.lab74 \
        -x 20 -y 290 -anchor nw -bordermode ignore
    place $over.ent75 \
        -x 110 -y 260 -width 88 -height 22 -anchor nw -bordermode ignore
    place $over.ent76 \
        -x 110 -y 290 -width 88 -height 22 -anchor nw -bordermode ignore
    place $over.lab77 \
        -x 210 -y 50 -anchor nw -bordermode ignore
    place $over.fra79 \
        -x 210 -y 75 -width 160 -height 225 -anchor nw -bordermode ignore

    # Color
    place $over.fra79.rad80 \
        -x 10 -y 15 -anchor nw -bordermode ignore
    place $over.fra79.rad81 \
        -x 10 -y 40 -anchor nw -bordermode ignore
    place $over.fra79.rad82 \
        -x 10 -y 65 -anchor nw -bordermode ignore
    place $over.fra79.rad83 \
        -x 10 -y 90 -anchor nw -bordermode ignore
    place $over.fra79.rad84 \
        -x 10 -y 115 -anchor nw -bordermode ignore
    place $over.fra79.rad85 \
        -x 10 -y 140 -anchor nw -bordermode ignore
    place $over.fra79.rad86 \
        -x 10 -y 165 -anchor nw -bordermode ignore
    place $over.fra79.rad87 \
        -x 10 -y 190 -anchor nw -bordermode ignore

    # Add, Remove, Close buttons
    place $over.but88 \
        -x 325 -y 315 -anchor nw -bordermode ignore
    place $over.but89 \
        -x 400 -y 315 -anchor nw -bordermode ignore
    place $over.but90 \
        -x 500 -y 315 -anchor nw -bordermode ignore 

    #String from Comm 0 of the rocket port
    place $over.commstring_entry \
        -x 90 -y 380 -anchor nw -bordermode ignore
    place $over.commstring_lable \
        -x 5 -y 380 -anchor nw -bordermode ignore
    place $over.enablestring_entry \
        -x 90 -y 400 -anchor nw -bordermode ignore
    place $over.enablestring_lable \
        -x 5 -y 400 -anchor nw -bordermode ignore
    place $over.insertstring_entry \
        -x 90 -y 420 -anchor nw -bordermode ignore
    place $over.insertstring_lable \
        -x 5 -y 420 -anchor nw -bordermode ignore
    place $over.overlaystring_entry \
        -x 90 -y 440 -anchor nw -bordermode ignore
    place $over.overlaystring_lable \
        -x 5 -y 440 -anchor nw -bordermode ignore
    place $over.overlaystring_enable \
        -x 5 -y 460 -anchor nw -bordermode ignore

    # Units
    place $over.fra65.units \
        -x 120 -y 50 -anchor nw -bordermode ignore

	#---------------------------------------#      		
 	# Display the previous selection     	#
 	# Inserting data into the listbox	#	
  	#---------------------------------------#
      		
   	set overlay_size [get_ov_count]
   	puts "overlay_size $overlay_size"

        for {set i 0} {$i < $overlay_size} {incr i} {
        	
        	set temp [split [get_overlay_info $i] |]
        	puts "overlay.tcl: temp is : $temp"
        	set temp_type [lindex $temp 0]
        	set temp_channel [lindex $temp 1]
        	set temp_line [lindex $temp 2]
        	set temp_column [lindex $temp 3]
        	
        	set name [get_element_name 0 0 $temp_channel]
        	
        	if {$temp_type == 0 } {set name "Ana Gesadc $temp_channel"}
        	if {$temp_type == 1 } {set name "Dive"}
        	if {$temp_type == 2 } {set name "Pitch"}
        	if {$temp_type == 3 } {set name "Roll"}
        	if {$temp_type == 4 } {set name "DVLaltitude"}
      		$over.lis57 insert end "$name l($temp_line) c($temp_column)"
               	
        }
    #set temp [split [get_overlay_strings_from_file] |]
    #set enablestring [lindex $temp 0]
    #set insertstring [lindex $temp 1]

    set commstring [get_overlay_string]
    set overlaystring [get_overlay_string_plus $enablestring $insertstring]

    set overlay_string_timer 1
    loop_overlay_string_transmission

}

proc loop_overlay_string_transmission { } {

	global overlay_string_timer
	global commstring overlaystring enablestring insertstring
	global over
	
	if { ![winfo exists $over] } {return}
	
	set commstring [get_overlay_string]
     	set overlaystring [get_overlay_string_plus $enablestring $insertstring]		
	
	after 200 [list loop_overlay_string_transmission]
}


set ov_ana  .analog_overlay

proc select_analog { } {

   global type_entry
   global ov_ana



   if [winfo exists $ov_ana] { destroy $ov_ana }

   global env
   set env(DISPLAY) :0
   toplevel $ov_ana


   label $ov_ana.title -text "Analog Overlay"  -relief groove -fg blue
   pack $ov_ana.title -side top  -fill x -padx 3 -pady 3




   menubutton $ov_ana.b1 -text "1-8" -menu $ov_ana.b1.menu
   menubutton $ov_ana.b2 -text "9-16" -menu $ov_ana.b2.menu
   menubutton $ov_ana.b3 -text "17-24" -menu $ov_ana.b3.menu
   menubutton $ov_ana.b4 -text "25-32" -menu $ov_ana.b4.menu
   menubutton $ov_ana.b5 -text "33-40" -menu $ov_ana.b5.menu
   menubutton $ov_ana.b6 -text "41-48" -menu $ov_ana.b6.menu



   menu $ov_ana.b1.menu
   $ov_ana.b1.menu add command -label "1 [get_element_name 0 0 1]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 1" }
   $ov_ana.b1.menu add command -label "2 [get_element_name 0 0 2]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 2"}
   $ov_ana.b1.menu add command -label "3 [get_element_name 0 0 3]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 3"}
   $ov_ana.b1.menu add command -label "4 [get_element_name 0 0 4]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 4" }
   $ov_ana.b1.menu add command -label "5 [get_element_name 0 0 5]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 5" }
   $ov_ana.b1.menu add command -label "6 [get_element_name 0 0 6]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 6" }
   $ov_ana.b1.menu add command -label "7 [get_element_name 0 0 7]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 7" }
   $ov_ana.b1.menu add command -label "8 [get_element_name 0 0 8]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 8" }
	                                                                                         	
	


   menu $ov_ana.b2.menu
   $ov_ana.b2.menu add command -label "9 [get_element_name 0 0 9]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 9"}
   $ov_ana.b2.menu add command -label "10 [get_element_name 0 0 10]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 10"}
   $ov_ana.b2.menu add command -label "11 [get_element_name 0 0 11]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 11"}
   $ov_ana.b2.menu add command -label "12 [get_element_name 0 0 12]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 12"}
   $ov_ana.b2.menu add command -label "13 [get_element_name 0 0 13]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 13"}
   $ov_ana.b2.menu add command -label "14 [get_element_name 0 0 14]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 14"}
   $ov_ana.b2.menu add command -label "15 [get_element_name 0 0 15]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 15"}
   $ov_ana.b2.menu add command -label "16 [get_element_name 0 0 16]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 16"}

	

   menu $ov_ana.b3.menu
   $ov_ana.b3.menu add command -label "17 [get_element_name 0 0 17]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 17"}
   $ov_ana.b3.menu add command -label "18 [get_element_name 0 0 18]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 18"}
   $ov_ana.b3.menu add command -label "19 [get_element_name 0 0 19]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 19"}
   $ov_ana.b3.menu add command -label "20 [get_element_name 0 0 20]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 20"}
   $ov_ana.b3.menu add command -label "21 [get_element_name 0 0 21]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 21"}
   $ov_ana.b3.menu add command -label "22 [get_element_name 0 0 22]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 22"}
   $ov_ana.b3.menu add command -label "23 [get_element_name 0 0 23]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 23"}
   $ov_ana.b3.menu add command -label "24 [get_element_name 0 0 24]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 24"}

	


   menu $ov_ana.b4.menu
   $ov_ana.b4.menu add command -label "25 [get_element_name 0 0 25]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 25"}
   $ov_ana.b4.menu add command -label "26 [get_element_name 0 0 26]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 26"}
   $ov_ana.b4.menu add command -label "27 [get_element_name 0 0 27]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 27"}
   $ov_ana.b4.menu add command -label "28 [get_element_name 0 0 28]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 28"}   	
   $ov_ana.b4.menu add command -label "29 [get_element_name 0 0 29]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 29"}
   $ov_ana.b4.menu add command -label "30 [get_element_name 0 0 30]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 30"}
   $ov_ana.b4.menu add command -label "31 [get_element_name 0 0 31]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 31"}
   $ov_ana.b4.menu add command -label "32 [get_element_name 0 0 32]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 32"}


   menu $ov_ana.b5.menu	
   $ov_ana.b5.menu add command -label "33 [get_element_name 0 0 33]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 33"}
   $ov_ana.b5.menu add command -label "34 [get_element_name 0 0 34]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 34"}
   $ov_ana.b5.menu add command -label "35 [get_element_name 0 0 35]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 35"}
   $ov_ana.b5.menu add command -label "36 [get_element_name 0 0 36]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 36"}   	
   $ov_ana.b5.menu add command -label "37 [get_element_name 0 0 37]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 37"}
   $ov_ana.b5.menu add command -label "38 [get_element_name 0 0 38]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 38"}
   $ov_ana.b5.menu add command -label "39 [get_element_name 0 0 39]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 39"}
   $ov_ana.b5.menu add command -label "40 [get_element_name 0 0 40]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 40"}

   menu $ov_ana.b6.menu	
   $ov_ana.b6.menu add command -label "41 [get_element_name 0 0 41]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 41"}
   $ov_ana.b6.menu add command -label "42 [get_element_name 0 0 42]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 42"}
   $ov_ana.b6.menu add command -label "43 [get_element_name 0 0 43]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 43"}
   $ov_ana.b6.menu add command -label "44 [get_element_name 0 0 44]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 44"}   	
   $ov_ana.b6.menu add command -label "45 [get_element_name 0 0 45]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 45"}
   $ov_ana.b6.menu add command -label "46 [get_element_name 0 0 46]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 46"}
   $ov_ana.b6.menu add command -label "47 [get_element_name 0 0 47]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 47"}
   $ov_ana.b6.menu add command -label "48 [get_element_name 0 0 48]" \
	-command {destroy $ov_ana ; set type_entry  "Ana Gesadc 48"}

   # add a Close button
   button $ov_ana.close -text Close -command {destroy $ov_ana}

   # Pack things up
   pack $ov_ana.b1 $ov_ana.b2 $ov_ana.b3 $ov_ana.b4 $ov_ana.b5 $ov_ana.b6 $ov_ana.close -side top
	
}

proc add_o_item { type_ent line col clr un} {

        global enablestring insertstring
	global over overlay_list unit
	
	set line $line
	set type [lindex $type_ent 0]
	set type_num -1
	set channel -1
	
	if { $type == "Ana"  } {
		set type_num 0
		set channel [lindex $type_ent 2]
	} elseif { $type == "Dive" } {
		set type_num 1
	} elseif { $type == "Pitch" } {
		set type_num 2
	} elseif {  $type == "Roll" } {
		set type_num 3
	} elseif {  $type == "DVLaltitude" } {	
		set type_num 4	
	}	
	
	#-----------------------------------------------#	
	# Send it to overlay page (c++ function)    	#
	# and save it to database as well           	#
	# if it returns -1, the element has already 	#
	# exist in database			  	#
	#-----------------------------------------------#	
	
	put_overlay_strings_to_file $enablestring $insertstring
	
	set exist [make_O_item $type_num $channel $line $col $clr $un]
	
	puts "has it exist = $exist"
	if {$exist == -1} { return }
	
	
	#-------------------------------#
	# Display it to the listbox	#
	#-------------------------------#
	
	$over.lis57 insert end "$type_ent l($line) c($col)"
}


proc delete_o_item { type } {
 	
	global over overlay_list
	global olay overlay_item
	#---------------------------------------#
	# Get the index of line selected        #
	# ( start from "0" to "end" )		#
	#---------------------------------------#
	
	set selected [$over.lis57 curselection]     	
	if { $selected == "" } {set selected end}
	set deleted_item [$over.lis57 get $selected]
	
	set type_num -1
	set channel -1	
	
	if { [lindex $deleted_item 0] == "Ana"  } {
		set type_num 0
		set channel [lindex $deleted_item 2]
	} elseif { [lindex $deleted_item 0] == "Dive" } {
		set type_num 1		  	
	} elseif { [lindex $deleted_item 0] == "Pitch" } {
		set type_num 2
	} elseif {  [lindex $deleted_item 0] == "Roll" } {
		set type_num 3
	} elseif {  [lindex $deleted_item 0] == "DVLaltitude" } {
		set type_num 4
	}
	
	# Call c++ function to delete it from overlay database
	delete_O_item $type_num $channel
	
 	set overlay_size [get_ov_count]
        for {set i 0} {$i < $overlay_size } {incr i} {
        	if [winfo exists $olay] { $olay delete $overlay_item($i)
        	}
        }

	
	#------------------------------#
	# Delete it from the listbox   #
	#------------------------------#
	$over.lis57 delete $selected
	

}
