1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#!nviz -f
# This file contains the following script tools:
#
# 1. Vanilla looping construct - Allows the user to specify a bracket of
# a script to be looped a specified number of times.
#
# 2. File Seq. looping construct - Allows the user to specify a sequence
# of files to looped over for a specific section of code. Specifically,
# any mapBrowser interactions will use the current file name specified
# in the current iteration.
destroy .wait_ok
global src_boot
source $src_boot/etc/nviz2.2/scripts/config.tcl
# Create a simple list of script tools which are invoked by pressing
# the specified buttons
# Globals
global loop_stack loop_flag
global floop_stack floop_flag floop_names
global ScriptState
set ScriptState 0
set loop_stack 0
set floop_stack 0
set floop_names [list]
# Tools for vanilla looping
button .loop_start -text "Open Loop" -command open_loop -bg aquamarine
button .loop_end -text "Close Loop" -command close_loop -bg aquamarine
pack .loop_start .loop_end -side top -fill both -expand 1
# Tools for file sequence looping
button .floop_start -text "Open File Seq. Loop" -command fopen_loop -bg burlywood
button .floop_end -text "Close File Seq. Loop" -command fclose_loop -bg burlywood
pack .floop_start .floop_end -side top -fill both -expand 1
# Tools for more general file sequence looping
button .file_sequence_tools -text "File Sequence Tool" \
-command fopen_tools -bg cornflowerblue
pack .file_sequence_tools -side top -fill both -expand 1
# Quit button
button .quit -text "Close" -command "exit"
pack .quit -side top -fill both -expand 1
# File Sequence Tools open function
proc fopen_tools {} {
global src_boot
global env
source $src_boot/etc/nviz2.2/scripts/config.tcl
# Just start the external tools process
exec nviz -f $default_panel_path/script_file_tools -q &
exit
}
# File Seq. Loop functions
proc fopen_loop {} {
global floop_stack floop_flag floop_names ProcessName
# Determine the list of files to iterate through
set file_list [create_multimap_browser .browse_new_file all 1]
if {$file_list == -1 } then { return }
# Generate new loop variable and increment the loop stack
set new_name [unique lseq]
set new_name2 [unique lseq]
incr floop_stack
lappend floop_names $new_name2
# Send nviz necessary commands to add the for loop to the script
send $ProcessName "Nv_script_add_string \"set $new_name2 \\\$Nv_mapLoopFile\""
send $ProcessName "Nv_script_add_string \"foreach $new_name \{$file_list\} \{\""
send $ProcessName "Nv_script_add_string \"set Nv_mapLoopMode 1\""
send $ProcessName "Nv_script_add_string \"set Nv_mapLoopFile \\\$$new_name\""
}
proc fclose_loop {} {
global floop_stack floop_names ProcessName
if $floop_stack then {
send $ProcessName "Nv_script_add_string \"\}\""
send $ProcessName "Nv_script_add_string \"set Nv_mapLoopMode 0\""
incr floop_stack -1
set old_name [lindex $floop_names $floop_stack]
send $ProcessName "Nv_script_add_string \"set Nv_mapLoopFile \\\$$old_name\""
} else {
tkerror "No corresponding Open File Seq. Loop"
}
}
# Vanilla Loop functions
proc open_loop {} {
global loop_stack loop_flag ProcessName
# Determine how many iterations the loop should go through
set loop_flag 0
toplevel .loop_data
label .loop_data.start_val_l -text "Loop Start Value"
entry .loop_data.start_val -relief sunken
label .loop_data.end_val_l -text "Loop End Value"
entry .loop_data.end_val -relief sunken
label .loop_data.incr_val_l -text "Loop Increment Value"
entry .loop_data.incr_val -relief sunken
button .loop_data.ok -text "Accept" -command "set loop_flag 1"
button .loop_data.cancel -text "Cancel" -command "set loop_flag -1"
pack .loop_data.start_val_l .loop_data.start_val \
.loop_data.end_val_l .loop_data.end_val \
.loop_data.incr_val_l .loop_data.incr_val \
.loop_data.ok .loop_data.cancel -side top -expand 1 -fill both
grab .loop_data
tkwait variable loop_flag
if {$loop_flag == -1} then {
destroy .loop_data
return
}
# Get loop parameters before destroying window
set loop_start [.loop_data.start_val get]
set loop_end [.loop_data.end_val get]
set loop_incr [.loop_data.incr_val get]
destroy .loop_data
# Generate new loop variable and increment the loop stack
set new_name [unique lp]
incr loop_stack
# Send nviz necessary commands to add the for loop to the script
send $ProcessName "Nv_script_add_string \"for \{set $new_name $loop_start\} \{\\\$$new_name != $loop_end\} \{incr $new_name $loop_incr\} \{\""
}
proc close_loop {} {
global loop_stack ProcessName
if $loop_stack then {
send $ProcessName "Nv_script_add_string \"\}\""
incr loop_stack -1
} else {
tkerror "No corresponding Open Loop"
}
}
|