#-------------------
# Include source file
#-------------------
source vehicle.tcl

set vp .vehicle_popup




proc vehicle_popup { } {



   #-----------------------
   # Declare and set variable
   #-----------------------
   global vp

   if [winfo exists $vp] {destroy $vp}

   global env
   set env(DISPLAY) :0
   toplevel $vp -width 8c -height 6c
   wm title $vp "Vehicle"



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

    label $vp.vehicle_title \
        -foreground #0000c4 -height 0 -relief groove -text Vehicle -width 238
    label $vp.name_label \
        -height 0 -text Name
    label $vp.xlabel \
        -text x
    label $vp.ylabel \
        -text y
    entry $vp.name_entry \
        -background white -textvariable vehicle_name
    entry $vp.xentry \
        -background white -textvariable vehicle_xpos
    entry $vp.yentry \
        -background white -textvariable vehicle_ypos
    button $vp.add \
        -command {add_vehicle} -height 0 -text Add
    button $vp.remove \
        -command {remove_vehicle ; destroy $vp} -text Remove
    button $vp.closel \
        -command {destroy $vp} -text Close



    #---------------------------------------------------------------
    # Bind the motion of the mouse to display the mouse
    # coordinate at current time
    #---------------------------------------------------------------

    bind .ventana <ButtonRelease-1> {
    	global vehicle_xpos vehicle_ypos
    	#puts "%x %y"
     	set vehicle_xpos %x
     	set vehicle_ypos %y
    }	

    ###################
    # SETTING GEOMETRY
    ###################
    place $vp.vehicle_title \
        -x 15 -y 10 -width 210 -height 20 -anchor nw -bordermode ignore
    #place $vp.name_label \
        -x 15 -y 45 -anchor nw -bordermode ignore
    place $vp.xlabel \
        -x 40 -y 70 -anchor nw -bordermode ignore
    place $vp.ylabel \
        -x 40 -y 95 -anchor nw -bordermode ignore
    #place $vp.name_entry \
        -x 60 -y 45 -anchor nw -bordermode ignore
    place $vp.xentry \
        -x 60 -y 70 -anchor nw -bordermode ignore
    place $vp.yentry \
        -x 60 -y 95 -anchor nw -bordermode ignore
    place $vp.add \
        -x 20 -y 125 -anchor nw -bordermode ignore
    place $vp.remove \
        -x 75 -y 125 -anchor nw -bordermode ignore
    place $vp.closel \
        -x 155 -y 125 -anchor nw -bordermode ignore

# end of proc "vehicle_popup"
}

proc add_vehicle { } {
   global vehicle_name
   global vehicle_xpos
   global vehicle_ypos

   # set the window path name and position of the vehicle
   get_window_path_name $vehicle_name
   set_vehicle_pos $vehicle_xpos $vehicle_ypos


   #---------------------------------------------
   # Send information to database
   # set_graphic_info $type $name $x $y $screen
   #---------------------------------------------

   set_graphic_info "vehicle" $vehicle_name $vehicle_xpos $vehicle_ypos 1


   #-------------------------------------#
   # draw the vehicle into main window   #
   #-------------------------------------#

   display_vehicle_or_not 1

}

proc remove_vehicle { } {

   global veh


   #--------------------
   # Check existence
   #--------------------
   if [winfo exists $veh] {
   	
   	display_vehicle_or_not 0     	
  	set_graphic_info "vehicle" "none" -1 -1 1

   } else {

       set status [tk_dialog .warning { } {
    		The Vehicle you are trying to remove does not exist ! } \
		warning 0 {Close} ]
       	
       switch $status {
		0 return
       }

       # end 'else'
  }



}
