| 1 | greg | 2.1 | # SCCSid "$SunId$ LBL" | 
| 2 |  |  | # | 
| 3 |  |  | # Action screen for trad | 
| 4 |  |  | # | 
| 5 |  |  |  | 
| 6 | greg | 2.6 | set batch_fmt "Process %d on %s started" | 
| 7 |  |  | set hostname [exec hostname] | 
| 8 |  |  |  | 
| 9 | greg | 2.1 | proc make_script {} {           # make run script | 
| 10 |  |  | global scname rpview curmess | 
| 11 |  |  | set rfn /usr/tmp/rf[pid] | 
| 12 |  |  | if {! [save_vars $rfn]} { | 
| 13 |  |  | beep | 
| 14 |  |  | set curmess "Cannot save variables to temporary file!" | 
| 15 |  |  | return | 
| 16 |  |  | } | 
| 17 |  |  | set radcom {rad -n} | 
| 18 |  |  | if {"$rpview" != " ALL"} { | 
| 19 |  |  | lappend radcom -v $rpview | 
| 20 |  |  | } | 
| 21 |  |  | if {"$scname" == {}} { | 
| 22 |  |  | set rof /usr/tmp/ro[pid] | 
| 23 |  |  | } else { | 
| 24 |  |  | set rof $scname | 
| 25 |  |  | } | 
| 26 |  |  | lappend radcom $rfn > $rof | 
| 27 |  |  | set badrun [catch "exec $radcom" curmess] | 
| 28 |  |  | if {"$scname" == {}} { | 
| 29 |  |  | if {! $badrun} { | 
| 30 |  |  | view_txt $rof | 
| 31 |  |  | } | 
| 32 |  |  | exec rm $rof | 
| 33 |  |  | } | 
| 34 |  |  | exec rm $rfn | 
| 35 |  |  | } | 
| 36 |  |  |  | 
| 37 |  |  | proc make_oct args {            # Make octree file ($args is {-t} or {}) | 
| 38 |  |  | global radvar curmess | 
| 39 |  |  | if {"$radvar(scene)" == {} && "$radvar(illum)" == {}} { | 
| 40 |  |  | set fi [open "|make $radvar(OCTREE) $args" r] | 
| 41 |  |  | while {[gets $fi curmess] >= 0} { update ; after 1000 } | 
| 42 |  |  | catch {close $fi} curmess | 
| 43 |  |  | } | 
| 44 |  |  | if {"$args" == {}} { | 
| 45 |  |  | run_rad -v 0 | 
| 46 |  |  | } else { | 
| 47 |  |  | run_rad $args | 
| 48 |  |  | } | 
| 49 |  |  | } | 
| 50 |  |  |  | 
| 51 |  |  | proc run_rad args {             # Run rad command with given arguments | 
| 52 |  |  | global curmess | 
| 53 |  |  | set rfn /usr/tmp/rf[pid] | 
| 54 |  |  | if {! [save_vars $rfn]} { | 
| 55 |  |  | beep | 
| 56 |  |  | set curmess "Cannot save variables to temporary file!" | 
| 57 |  |  | return | 
| 58 |  |  | } | 
| 59 |  |  | set ot [file mtime $rfn] | 
| 60 |  |  | set fi [open "|rad $args $rfn" r] | 
| 61 |  |  | while {[gets $fi curmess] >= 0} { update ; after 1000 } | 
| 62 |  |  | if {! [catch {close $fi} curmess] && [file mtime $rfn] > $ot} { | 
| 63 |  |  | load_vars $rfn {view} | 
| 64 |  |  | make_vmenus | 
| 65 |  |  | } | 
| 66 |  |  | exec rm $rfn | 
| 67 |  |  | } | 
| 68 |  |  |  | 
| 69 |  |  | proc run_batch {} {             # start rendering in background | 
| 70 | greg | 2.6 | global rpview bfname batch_pid curmess rifname mywin batch_fmt hostname | 
| 71 | greg | 2.1 | if {! [chksave]} {return} | 
| 72 |  |  | if [catch {set fo [open $bfname w]} curmess] { | 
| 73 |  |  | return | 
| 74 |  |  | } | 
| 75 |  |  | # Make space for PID to be written later | 
| 76 | greg | 2.6 | puts $fo "                                                            " | 
| 77 | greg | 2.1 | if {$rpview == " ALL"} { | 
| 78 |  |  | set radcom "rad" | 
| 79 |  |  | } else { | 
| 80 |  |  | set radcom "rad -v $rpview" | 
| 81 |  |  | } | 
| 82 |  |  | lappend radcom "[file tail $rifname]" | 
| 83 |  |  | # Put out command | 
| 84 |  |  | puts $fo $radcom | 
| 85 |  |  | flush $fo | 
| 86 |  |  | # Execute in background | 
| 87 |  |  | set batch_pid [eval exec $radcom >>& $bfname &] | 
| 88 |  |  | # Now, write PID and close file | 
| 89 |  |  | seek $fo 0 | 
| 90 | greg | 2.6 | puts -nonewline $fo "[format $batch_fmt $batch_pid $hostname]\ | 
| 91 |  |  | [exec date]" | 
| 92 | greg | 2.1 | close $fo | 
| 93 |  |  | set curmess "Batch rendering process $batch_pid started." | 
| 94 |  |  | # Correct button stati | 
| 95 |  |  | $mywin.rbst configure -state disabled | 
| 96 |  |  | $mywin.rbki configure -state normal | 
| 97 |  |  | $mywin.rbce configure -state normal | 
| 98 |  |  | $mywin.rbvmb configure -state disabled | 
| 99 |  |  | } | 
| 100 |  |  |  | 
| 101 |  |  | proc kill_batch {} {            # kill batch rendering | 
| 102 |  |  | global batch_pid env curmess mywin | 
| 103 |  |  | # Kill batch process and children | 
| 104 |  |  | switch -glob [exec uname] { | 
| 105 |  |  | SunOS - | 
| 106 |  |  | ULTRIX {set ps "ps -lg"} | 
| 107 | greg | 2.4 | default {set ps "ps -lu $env(LOGNAME)"} | 
| 108 | greg | 2.1 | } | 
| 109 |  |  | set fi [open "|$ps" r] | 
| 110 |  |  | gets $fi li | 
| 111 |  |  | regexp -indices -nocase {  *PID} $li pidsec | 
| 112 |  |  | regexp -indices -nocase {  *PPID} $li ppidsec | 
| 113 |  |  | while {[gets $fi li] >= 0} { | 
| 114 |  |  | lappend plist "[eval string range {$li} $pidsec]\ | 
| 115 |  |  | [eval string range {$li} $ppidsec]" | 
| 116 |  |  | } | 
| 117 |  |  | if [catch {close $fi} curmess] { | 
| 118 |  |  | return | 
| 119 |  |  | } | 
| 120 |  |  | set plist [lsort $plist] | 
| 121 |  |  | set procs $batch_pid | 
| 122 |  |  | # Two passes required when process id's go into recycling | 
| 123 |  |  | for {set i 0} {$i < 2} {incr i} { | 
| 124 |  |  | foreach pp $plist { | 
| 125 |  |  | if {[lsearch -exact $procs [lindex $pp 1]] >= 0 && | 
| 126 |  |  | ($i == 0 || [lsearch -exact $procs \ | 
| 127 |  |  | [lindex $pp 0]] < 0)} { | 
| 128 |  |  | lappend procs [lindex $pp 0] | 
| 129 |  |  | } | 
| 130 |  |  | } | 
| 131 |  |  | } | 
| 132 |  |  | if {! [catch {eval exec kill $procs} curmess]} { | 
| 133 |  |  | set curmess "Batch process $batch_pid and children killed." | 
| 134 |  |  | } | 
| 135 |  |  | # change modes | 
| 136 |  |  | $mywin.rbki configure -state disabled | 
| 137 |  |  | $mywin.rbst configure -state normal | 
| 138 |  |  | $mywin.rbvmb configure -state normal | 
| 139 |  |  | set batch_pid 0 | 
| 140 |  |  | } | 
| 141 |  |  |  | 
| 142 |  |  | proc make_vmenus {} {           # make/update view menus | 
| 143 |  |  | global mywin radvar rvview | 
| 144 |  |  | if {"$radvar(view)" == {}} { | 
| 145 |  |  | set rvview X | 
| 146 |  |  | } else { | 
| 147 |  |  | set rvview [lindex [lindex $radvar(view) 0] 0] | 
| 148 |  |  | } | 
| 149 |  |  | catch {destroy $mywin.rivmb.m} | 
| 150 | greg | 2.2 | catch {destroy $mywin.rbvmb.m} | 
| 151 | greg | 2.1 | if {[llength $radvar(view)] < 2} { | 
| 152 |  |  | $mywin.rivmb configure -state disabled | 
| 153 | greg | 2.2 | return | 
| 154 | greg | 2.1 | } | 
| 155 | greg | 2.2 | menu $mywin.rivmb.m | 
| 156 |  |  | $mywin.rivmb configure -menu $mywin.rivmb.m -state normal | 
| 157 |  |  | foreach v $radvar(view) { | 
| 158 |  |  | $mywin.rivmb.m add radiobutton -label [lindex $v 0] \ | 
| 159 |  |  | -variable rvview -value [lindex $v 0] | 
| 160 |  |  | } | 
| 161 |  |  | menu $mywin.rbvmb.m | 
| 162 | greg | 2.5 | $mywin.rbvmb configure -menu $mywin.rbvmb.m | 
| 163 | greg | 2.2 | $mywin.rbvmb.m add radiobutton -label ALL \ | 
| 164 |  |  | -variable rpview -value " ALL" | 
| 165 |  |  | $mywin.rbvmb.m add separator | 
| 166 |  |  | foreach v $radvar(view) { | 
| 167 |  |  | $mywin.rbvmb.m add radiobutton -label [lindex $v 0] \ | 
| 168 |  |  | -variable rpview -value [lindex $v 0] | 
| 169 | greg | 2.1 | } | 
| 170 |  |  | } | 
| 171 |  |  |  | 
| 172 |  |  | proc do_action w {              # Action screen | 
| 173 |  |  | global rifname rvview rpview radvar bfname batch_pid \ | 
| 174 | greg | 2.6 | curmess scname mywin alldone batch_fmt hostname | 
| 175 | greg | 2.1 | if {"$w" == "done"} { | 
| 176 |  |  | unset rpview bfname batch_pid mywin | 
| 177 |  |  | return | 
| 178 |  |  | } | 
| 179 |  |  | set bfname [file rootname [file tail $rifname]].err | 
| 180 |  |  | frame $w | 
| 181 |  |  | set mywin $w | 
| 182 |  |  | # Generate octree | 
| 183 |  |  | label $w.octl -text {Compile scene only} | 
| 184 |  |  | place $w.octl -relx .1429 -rely .0610 | 
| 185 |  |  | button $w.octb -text oconv -relief raised -command make_oct | 
| 186 |  |  | place $w.octb -relwidth .1071 -relheight .0610 -relx .4643 -rely .0610 | 
| 187 |  |  | helplink $w.octb trad action oconv | 
| 188 |  |  | button $w.octt -text Touch -relief raised -command {make_oct -t} | 
| 189 |  |  | place $w.octt -relwidth .1071 -relheight .0610 -relx .7143 -rely .0610 | 
| 190 |  |  | helplink $w.octt trad action touch | 
| 191 |  |  | button $w.octf -text Force -relief raised -command \ | 
| 192 |  |  | {catch {exec rm -f $radvar(OCTREE)} ; make_oct} | 
| 193 |  |  | place $w.octf -relwidth .1071 -relheight .0610 -relx .5893 -rely .0610 | 
| 194 |  |  | helplink $w.octf trad action force | 
| 195 |  |  | # Render interactively | 
| 196 |  |  | label $w.ril -text {Render interactively} | 
| 197 |  |  | place $w.ril -relx .1429 -rely .2439 | 
| 198 |  |  | button $w.rirv -text rview -relief raised \ | 
| 199 |  |  | -command {run_rad -v $rvview -o x11} | 
| 200 |  |  | place $w.rirv -relwidth .1071 -relheight .0610 -relx .4643 -rely .2439 | 
| 201 |  |  | helplink $w.rirv trad action rview | 
| 202 |  |  | label $w.rivl -text View: | 
| 203 |  |  | place $w.rivl -relx .6072 -rely .2439 | 
| 204 |  |  | menubutton $w.rivmb -textvariable rvview -anchor w -relief raised | 
| 205 |  |  | place $w.rivmb -relwidth .1071 -relheight .0610 -relx .7143 -rely .2439 | 
| 206 |  |  | helplink $w.rivmb trad action view | 
| 207 |  |  | # Render in background | 
| 208 |  |  | label $w.rbl -text {Render in background} | 
| 209 |  |  | place $w.rbl -relx .1429 -rely .4268 | 
| 210 |  |  | button $w.rbst -text Start -relief raised -command run_batch | 
| 211 |  |  | place $w.rbst -relwidth .1071 -relheight .0610 -relx .4643 -rely .4268 | 
| 212 |  |  | helplink $w.rbst trad action start | 
| 213 |  |  | label $w.rbvl -text View: | 
| 214 |  |  | place $w.rbvl -relx .6072 -rely .4268 | 
| 215 |  |  | menubutton $w.rbvmb -textvariable rpview -anchor w -relief raised | 
| 216 |  |  | place $w.rbvmb -relwidth .1071 -relheight .0610 -relx .7143 -rely .4268 | 
| 217 |  |  | helplink $w.rbvmb trad action view | 
| 218 |  |  | button $w.rbki -text Kill -relief raised -command kill_batch | 
| 219 |  |  | place $w.rbki -relwidth .1071 -relheight .0610 -relx .4643 -rely .5488 | 
| 220 |  |  | helplink $w.rbki trad action kill | 
| 221 |  |  | button $w.rbce -text "Check errors" -relief raised \ | 
| 222 |  |  | -command {view_txt $bfname} | 
| 223 |  |  | place $w.rbce -relwidth .1786 -relheight .0610 -relx .6429 -rely .5488 | 
| 224 |  |  | helplink $w.rbce trad action checkerr | 
| 225 |  |  | if [file exists $bfname] { | 
| 226 |  |  | set fi [open $bfname r] | 
| 227 | greg | 2.6 | scan [gets $fi] $batch_fmt batch_pid batch_host | 
| 228 | greg | 2.1 | gets $fi radcom | 
| 229 |  |  | close $fi | 
| 230 | greg | 2.6 | if [string match "rad -v *" $radcom] { | 
| 231 |  |  | set rpview [lindex $radcom 2] | 
| 232 |  |  | } else { | 
| 233 |  |  | set rpview " ALL" | 
| 234 |  |  | } | 
| 235 |  |  | if {"$hostname" != "$batch_host"} { | 
| 236 | greg | 2.1 | if $alldone { | 
| 237 | greg | 2.6 | set curmess "Batch rendering finished\ | 
| 238 |  |  | on host $batch_host." | 
| 239 |  |  | } else { | 
| 240 |  |  | set curmess "Unknown batch rendering status\ | 
| 241 |  |  | on host $batch_host." | 
| 242 |  |  | $w.rbst configure -state disabled | 
| 243 |  |  | $w.rbvmb configure -state disabled | 
| 244 |  |  | } | 
| 245 |  |  | set batch_pid 0 | 
| 246 |  |  | $w.rbki configure -state disabled | 
| 247 |  |  | } elseif {[catch {exec /bin/kill -0 $batch_pid}]} { | 
| 248 |  |  | if $alldone { | 
| 249 | greg | 2.1 | set curmess "Batch rendering finished." | 
| 250 |  |  | } else { | 
| 251 |  |  | set curmess "Batch rendering stopped." | 
| 252 |  |  | } | 
| 253 |  |  | set batch_pid 0 | 
| 254 |  |  | set rpview " ALL" | 
| 255 |  |  | $w.rbki configure -state disabled | 
| 256 |  |  | } else { | 
| 257 |  |  | set curmess "Batch rendering process $batch_pid running." | 
| 258 |  |  | $w.rbst configure -state disabled | 
| 259 |  |  | $w.rbvmb configure -state disabled | 
| 260 |  |  | } | 
| 261 |  |  | } else { | 
| 262 |  |  | set curmess "No batch rendering in progress." | 
| 263 |  |  | set batch_pid 0 | 
| 264 |  |  | set rpview " ALL" | 
| 265 |  |  | $w.rbki configure -state disabled | 
| 266 |  |  | $w.rbce configure -state disabled | 
| 267 |  |  | } | 
| 268 |  |  | make_vmenus | 
| 269 |  |  | # Dry run | 
| 270 |  |  | label $w.drl -text {Dry run} | 
| 271 |  |  | place $w.drl -relx .1429 -rely .7317 | 
| 272 |  |  | button $w.drsc -text Script -relief raised -command make_script | 
| 273 |  |  | place $w.drsc -relwidth .1071 -relheight .0610 -relx .4643 -rely .7317 | 
| 274 |  |  | entry $w.drsf -textvariable scname -relief sunken | 
| 275 |  |  | place $w.drsf -relwidth .2143 -relheight .0610 -relx .6429 -rely .7317 | 
| 276 |  |  | helplink "$w.drsc $w.drsf" trad action script | 
| 277 |  |  | button $w.drvw -text Edit -relief raised -command {view_txt $scname} | 
| 278 |  |  | place $w.drvw -relwidth .1071 -relheight .0610 -relx .4643 -rely .8537 | 
| 279 |  |  | helplink $w.drvw trad action edit | 
| 280 |  |  | button $w.drdel -text Delete -relief raised \ | 
| 281 |  |  | -command {catch {exec rm $scname < /dev/null} curmess} | 
| 282 |  |  | place $w.drdel -relwidth .1071 -relheight .0610 -relx .6429 -rely .8537 | 
| 283 |  |  | helplink $w.drdel trad action delete | 
| 284 |  |  | } |