
set tms2 .tms_popup2
set tms_display2 .ventana2.editor.tms_display2


proc tms_popup2 { }  {

    global tms2 tms_display2


    	
    #------------------------------------------
    # Create a new window
    #------------------------------------------

    if [winfo exists $tms2] {destroy $tms2}
    global env
    set env(DISPLAY) :0.1
    toplevel $tms2  -width 65m -height 55m
    wm title $tms2 "TMS Display"

    #-------------------------------------------
    # Creating Widgets
    #-------------------------------------------

    label $tms2.title -text "TMS Display" \
    	-fg blue -relief groove -width 23


    label $tms2.xlabel -text x
    entry $tms2.x -textvariable tmsx2 -bg white

    label $tms2.ylabel -text y
    entry $tms2.y -textvariable tmsy2 -bg white

    button $tms2.add -text Display -command {set_tms_display $tmsx2 $tmsy2 2; display_tms2}
    button $tms2.remove -text Remove -command {set_tms_display -1 -1 2 ;destroy $tms_display2}
    button $tms2.close -text Close -command {destroy $tms2}

    place $tms2.title -x 10 -y 10
    place $tms2.xlabel -x 10 -y 35
    place $tms2.ylabel -x 10 -y 55

    place $tms2.x -x 30 -y 35
    place $tms2.y -x 30 -y 55

    place $tms2.add -x 20 -y 85 -width 70
    place $tms2.remove -x 100 -y 85 -width 70
    place $tms2.close -x 20 -y 115 -width 70



    bind .ventana2 <ButtonRelease-1> {
    	#global tms2
     	set tmsx2 %x
     	set tmsy2 %y

    }
}


proc display_tms2 { } {
 	global tmsx2 tmsy2  tms_display2
 	global velocity tether temperature tension pressure torque grd_flt

 	if [winfo exists $tms_display2] { destroy $tms_display2 }
 	
 	set tmp_str [split [get_tms_display] | ]
 	set tmsx2 [lindex $tmp_str 2]
 	set tmsy2 [lindex $tmp_str 3]
 	
 	
 	
 	if {$tmsx2 == "" || $tmsx2 == " " } {
 		set tmsx2 0
 	}
 	if {$tmsy2 == "" || $tmsy2 == " " } {
 		set tmsy2 0
 	}
 	
 	if {$tmsx2 == -1 || $tmsy2 == -1 } {
 		return
 	}
 	
 	frame $tms_display2 -width 200 -height 100 -bg black
 	
 	# Cable Speed
 	label $tms_display2.velocity -text "Velocity" -bg black -fg white              	
 	entry $tms_display2.v_entry -bg black -fg white -textvariable velocity -width 7	
 	label $tms_display2.v_unit -text "mtr/min" -bg black -fg white
 	
 	# Cable Out
 	label $tms_display2.tether -text "Tether" -bg black -fg white
 	entry $tms_display2.tet_entry -bg black -fg white -textvariable tether -width 7	
 	label $tms_display2.tet_unit -text "meter" -bg black -fg white
 	
 	# Temperature 	
 	#label $tms_display2.temp -text "Temp" -bg black -fg white
 	#entry $tms_display2.temp_entry -bg black -fg white -textvariable temperature -width 7	
 	#label $tms_display2.temp_unit -text "C" -bg black -fg white
 	
 	# Tension  	
 	label $tms_display2.tension -text "Tension" -bg black -fg white
 	entry $tms_display2.ten_entry -bg black -fg white -textvariable tension -width 7	
 	label $tms_display2.ten_unit -text "lbs" -bg black -fg white
 	
 	# Pressure
 	label $tms_display2.cyl -text "Pressure" -bg black -fg white
 	entry $tms_display2.cyl_entry -bg black -fg white -textvariable pressure -width 7	
 	label $tms_display2.cyl_unit -text "psi" -bg black -fg white
 	
 	#label $tms_display2.torque -text "Torque" -bg black -fg white
 	#entry $tms_display2.tor_entry -bg black -fg white -textvariable torque -width 7	
 	#label $tms_display2.tor_unit -text "ft/lbs" -bg black -fg white
 	
 	#label $tms_display2.grd -text "GRD FLT" -bg black -fg white
 	#entry $tms_display2.grd_entry -bg black -fg white -textvariable grd_flt -width 7	
 	#label $tms_display2.grd_unit -text "ohms" -bg black -fg white
 	
 	
 	#--------------------#
 	# Setting Geometry   #
 	#--------------------#
 	
 	
 	place $tms_display2.velocity -x 10 -y 10
 	place $tms_display2.v_entry -x 80 -y 10
 	place $tms_display2.v_unit -x 145 -y 10
 	
 	place $tms_display2.tether -x 10 -y 30
 	place $tms_display2.tet_entry -x 80 -y 30
 	place $tms_display2.tet_unit -x 145 -y 30
 	 	
 	#place $tms_display2.temp -x 10 -y 50
 	#place $tms_display2.temp_entry -x 80 -y 50
 	#place $tms_display2.temp_unit -x 145 -y 50
 	 	
 	place $tms_display2.tension -x 10 -y 50
 	place $tms_display2.ten_entry -x 80 -y 50
 	place $tms_display2.ten_unit -x 145 -y 50
 	
 	place $tms_display2.cyl -x 10 -y 70
 	place $tms_display2.cyl_entry  -x 80 -y 70
 	place $tms_display2.cyl_unit -x 145 -y 70
 	
 	#place $tms_display2.torque -x 10 -y 110
 	#place $tms_display2.tor_entry -x 80 -y 110
 	#place $tms_display2.tor_unit -x 145 -y 110
 	
 	#place $tms_display2.grd -x 10 -y 130
 	#place $tms_display2.grd_entry -x 80 -y 130
 	#place $tms_display2.grd_unit -x 145 -y 130
 	
	
 	place $tms_display2 -x $tmsx2 -y $tmsy2
 	
 	update_tms2
 	
}



proc update_tms2 { } {
        global tms_display
	global velocity tether temperature tension pressure torque grd_flt

	if ![winfo exists $tms_display] {
	 	return
	}

        set temp_str [get_tms_info]

        #puts "temp_str : $temp_str"


		#puts "temperature : $temperature"	        	
	 	#puts "velocity = $velocity"
	 	#puts "tether = $tether"
	
		#puts "grd_flt : $grd_flt"
		#puts "pressure : $pressure"
		#puts "torque : $torque"
	
	set tether [lindex $temp_str 0]
        set velocity [lindex $temp_str 1]
        set tension [lindex $temp_str 2]
	set pressure [lindex $temp_str 3]
	

 	after 300 [list update_tms2]
}