ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_action.tcl
Revision: 2.13
Committed: Fri Jun 1 22:55:14 2012 UTC (11 years, 10 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
CVS Tags: rad5R4, rad5R2, rad4R2P2, rad5R0, rad5R1, rad4R2, rad4R2P1, rad5R3, HEAD
Changes since 2.12: +35 -21 lines
Log Message:
Added number of processes control to trad

File Contents

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