
###########################
# Include the other source files #
##########################


source file_proc.tcl
source submenu/vehicle_submenu2.tcl
source submenu/surface_submenu2.tcl
source submenu/detritus_submenu2.tcl
source submenu/instrument_submenu2.tcl
source submenu/tool_submenu2.tcl
source submenu/setting_submenu2.tcl
source submenu/lightmenu_submenu2.tcl
source submenu/lightisol_submenu2.tcl
source alarm_list2.tcl
source elem_prop2.tcl
#source bar_detail2.tcl
source depthbar2.tcl
source overlay2.tcl
source annotate_box2.tcl
source list_all_element.tcl
source out_elem_prop2.tcl



###########################
# Create the toplevel     #
###########################


set env(DISPLAY) :0.1
toplevel .ventana2 -bg black
set v2 .ventana2
wm title $v2 "Ventana Screen 2"

########################
# Initialize variables #
########################


#------------------------------------------------------------------------------------


#######################
# Create the menu bar       #
#######################

frame $v2.bar -relief raised -bd 2 -width 20c
frame $v2.editor -relief flat -width 1012 -height 710 -background black



###########################
# Create the menu buttons         #
###########################

menubutton $v2.bar.file -text File -underline 0 \
	-menu $v2.bar.file.menu
menubutton $v2.bar.maintenance -text Maintenance \
	-menu $v2.bar.maintenance.menu
menubutton $v2.bar.lightisol -text "Light Isolation" \
	-menu $v2.bar.lightisol.menu
menubutton $v2.bar.instrument -text Instruments \
	-menu $v2.bar.instrument.menu
menubutton $v2.bar.tool -text Tools \
	-menu $v2.bar.tool.menu
menubutton $v2.bar.detritus -text Detritus \
	-menu $v2.bar.detritus.menu
button $v2.bar.overlay -text "Overlay" -relief flat \
	-command overlay2
button $v2.bar.annotate -text "Annotate" -relief flat \
	-command annotate_box2
button $v2.bar.alarm -text "Alarm List" -relief flat \
	-command display_alarm_list2


#################################################
# Create the menu for the "File" button      	#
#################################################

#-------------------------------------------------------#
# The procedure to create new file, open, save, and  	#
# quit file are in "file_proc.tcl" file             	#
#-------------------------------------------------------#


menu $v2.bar.file.menu

# New
$v2.bar.file.menu add command -label "New" \
	-command newFile -underline 0

# Open
$v2.bar.file.menu add command -label "Open" \
	-command {openFile } -underline 0
	
# Save
$v2.bar.file.menu add command -label "Save" \
	-command  {saveFile } -underline 0

# Save As
$v2.bar.file.menu add command -label "Save As" \
	-command {saveAs } -underline 5

$v2.bar.file.menu add  separator


	
# Calling c++ function "download_init"
$v2.bar.file.menu add command -label "Download New Software" \
	-command download_init

$v2.bar.file.menu add separator

# Quit
$v2.bar.file.menu add command -label "Quit" \
	-command exit_program -underline 0

. configure -menu $v2.bar.file
	


#-------------------------------------------------------#
# Create  Top Menus					#
#-------------------------------------------------------#


#-------------------------------------------------------#
# Create the menu for the "Lights Isolation" button	#
#-------------------------------------------------------#

create_lightisol_submenu2

#-------------------------------------------------------#
# Create the menu for the "Instruments" button		#
#-------------------------------------------------------#

create_instrument_submenu2

#-------------------------------------------------------#
# Create the menu for the "Tool" button			#
#-------------------------------------------------------#

create_tool_submenu2

#-------------------------------------------------------#
# Create the menu for the "Detritus" button		#
#-------------------------------------------------------#

create_detritus_submenu2

#-------------------------------------------------------#
# Create the menu for the "Maintenance" button        	#
# This one has "Setting" and "Element" submenu		#
#-------------------------------------------------------#

menu $v2.bar.maintenance.menu -tearoff 0

$v2.bar.maintenance.menu add separator

#-------------------------------------------------------#
# Create the "Setting" submenu                       	#
#-------------------------------------------------------#

$v2.bar.maintenance.menu add cascade -label Setting \
	-menu $v2.bar.maintenance.menu.setting

$v2.bar.maintenance.menu add separator
	
#-------------------------------------------------------#
# Create the "Element" submenu				#
#-------------------------------------------------------#

$v2.bar.maintenance.menu add cascade -label Element \
	-menu $v2.bar.maintenance.menu.element

$v2.bar.maintenance.menu add separator

#-------------------------------------------------------#
# Create the menu for the "Setting"			#
#-------------------------------------------------------#

create_setting_submenu2

#-------------------------------------------------------#
# Create the menu for the "Element"			#
# This one has submenu "Surface" and "Vehicle"      	#
#-------------------------------------------------------#

menu $v2.bar.maintenance.menu.element


#-------------------------------------------------------#
# Create Display For All The Element    		#
#-------------------------------------------------------#
$v2.bar.maintenance.menu.element add cascade -label "Display All Element" \
	-menu $v2.bar.maintenance.menu.element.all_element
	

menu $v2.bar.maintenance.menu.element.all_element
	
$v2.bar.maintenance.menu.element.all_element add command \
	-label "Top Digital" -command list_dig_element

$v2.bar.maintenance.menu.element.all_element add command \
	-label "Top Analog" -command list_ana_element

$v2.bar.maintenance.menu.element.all_element add command \
	-label "Sub Digital" -command list_subdig_element

$v2.bar.maintenance.menu.element.all_element add command \
	-label "Sub Analog" -command list_subana_element

$v2.bar.maintenance.menu.element.all_element add command \
	-label "Top Analog Out" -command list_anaout_element
	
$v2.bar.maintenance.menu.element.all_element add command \
	-label "Button List" -command list_button_element

$v2.bar.maintenance.menu.element add separator

#-------------------------------------------------------#
# Create the "Surface" submenu                      	#
#-------------------------------------------------------#

create_surface_submenu2

#-------------------------------------------------------#
# Create the "Vehicle" submenu                   	#
#-------------------------------------------------------#

create_vehicle_submenu2

#------------------------------------------------------------------------------------




########################
# Pack all the widgets #
########################


# pack the menubuttons altogether
pack $v2.bar.file $v2.bar.maintenance \
$v2.bar.lightisol $v2.bar.instrument $v2.bar.tool $v2.bar.detritus $v2.bar.annotate $v2.bar.overlay $v2.bar.alarm -side left -padx 3m


# pack the bar and the window together
pack $v2.bar $v2.editor -side top  -fill x



#----------------------------------------------------------------------------



#-------------------------------------
# Make the popup menu stays on top
#-------------------------------------

bind .ventana2 <ButtonPress-1> {


	# Arm Control , Auto Pilot , and Camera Control
        if [winfo exists .arm_control_popup2 ] { raise .arm_control_popup2 }
        if [winfo exists .auto_pilot_popup2 ] { raise .auto_pilot_popup2 }
        if [winfo exists .analog_input_list2] { raise .analog_input_list2 }
	if [winfo exists .analog_output_list2] { raise .analog_output_list2 }
	if [winfo exists .digital_input_list2] { raise .digital_input_list2 }
	if [winfo exists .serial_input_list2] { raise .serial_input_list2 }
	if [winfo exists .camera_popup2] { raise .camera_popup2}
     	
	
        # BPM and Output
        if [winfo exists .bpm2] { focus .bpm2; raise .bpm2 }
	if [winfo exists .add_output2] { focus .add_output2; raise .add_output2 }
	if [winfo exists .button_add_output2] { raise .button_add_output2 }
	if [winfo exists .slide_add_output2] { raise .slide_add_output2 }
	if [winfo exists .but_small_popup2] { raise .but_small_popup2 }
	if [winfo exists .slide_popup2] { raise .slide_popup2 }
	if [winfo exists .out_bpm2] { raise .out_bpm2 }
	
	
	# Tearoff
        if [winfo exists $v2.tearoff1] { raise $v2.tearoff1}
        if [winfo exists $v2.tearoff2] { raise $v2.tearoff2}
	if [winfo exists $v2.tearoff3] { raise $v2.tearoff3}
	if [winfo exists $v2.tearoff4] { raise $v2.tearoff4}
	if [winfo exists $v2.tearoff5] { raise $v2.tearoff5}
	if [winfo exists $v2.tearoff6] { raise $v2.tearoff6}
       	if [winfo exists $v2.tearoff7] { raise $v2.tearoff7}
	if [winfo exists $v2.tearoff8] { raise $v2.tearoff8}
	if [winfo exists $v2.tearoff9] { raise $v2.tearoff9}
	if [winfo exists $v2.tearoff10] { raise $v2.tearoff10}
	if [winfo exists $v2.tearoff11] { raise $v2.tearoff11}
        if [winfo exists $v2.tearoff12] { raise $v2.tearoff12}
       	if [winfo exists $v2.tearoff13] { raise $v2.tearoff13}
       	if [winfo exists $v2.tearoff14] { raise $v2.tearoff14}
        if [winfo exists $v2.tearoff15] { raise $v2.tearoff15}

        # Graphic Popup
        if [winfo exists .light2_menu] { raise .light2_menu}
        if [winfo exists .compass2_popup] { raise .compass2_popup}
       	if [winfo exists .but_small_popup2] { raise .but_small_popup2}
       	if [winfo exists .slide_popup2] { raise .slide_popup2}
       	
        if [winfo exists .annotate_box2] { raise .annotate_box2 }         	
     	if [winfo exists .overlay2] { raise .overlay2 }        	
     	if [winfo exists .alarm_list2] { raise .alarm_list2}
     	if [winfo exists .analog_overlay2] { raise .analog_overlay2}
     	
     	if [winfo exists .save_or_not] { raise .save_or_not}
     	if [winfo exists .tms_popup2] { raise .tms_popup2}
	if [winfo exists .gf2] { raise .gf2}
 	if [winfo exists .dive2] { raise .dive2}
	if [winfo exists .auto_cruise2] { raise .auto_cruise2}
        if [winfo exists .latitude2] { raise .latitude2}
        if [winfo exists .logging2] { raise .logging2}

	
        # Other Dialog Box
        if [winfo exists .__tk_filedialog] { raise .__tk_filedialog }
	if [winfo exists .save_or_not] { raise .save_or_not }
	if [winfo exists .wrong_ext] { raise .wrong_ext }	
	
        #puts "%W"
	
}

#------------------------------------------------------------------------------------

