ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_action.tcl
Revision: 2.8
Committed: Thu Oct 5 13:16:39 1995 UTC (28 years, 6 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Changes since 2.7: +7 -3 lines
Log Message:
added minimal error checking to error file parsing

File Contents

# User Rev Content
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.7 puts $fo \
77     " "
78 greg 2.1 if {$rpview == " ALL"} {
79     set radcom "rad"
80     } else {
81     set radcom "rad -v $rpview"
82     }
83     lappend radcom "[file tail $rifname]"
84     # Put out command
85     puts $fo $radcom
86     flush $fo
87     # Execute in background
88     set batch_pid [eval exec $radcom >>& $bfname &]
89     # Now, write PID and close file
90     seek $fo 0
91 greg 2.6 puts -nonewline $fo "[format $batch_fmt $batch_pid $hostname]\
92     [exec date]"
93 greg 2.1 close $fo
94     set curmess "Batch rendering process $batch_pid started."
95     # Correct button stati
96     $mywin.rbst configure -state disabled
97     $mywin.rbki configure -state normal
98     $mywin.rbce configure -state normal
99     $mywin.rbvmb configure -state disabled
100     }
101    
102     proc kill_batch {} { # kill batch rendering
103     global batch_pid env curmess mywin
104     # Kill batch process and children
105     switch -glob [exec uname] {
106     SunOS -
107     ULTRIX {set ps "ps -lg"}
108 greg 2.4 default {set ps "ps -lu $env(LOGNAME)"}
109 greg 2.1 }
110     set fi [open "|$ps" r]
111     gets $fi li
112     regexp -indices -nocase { *PID} $li pidsec
113     regexp -indices -nocase { *PPID} $li ppidsec
114     while {[gets $fi li] >= 0} {
115     lappend plist "[eval string range {$li} $pidsec]\
116     [eval string range {$li} $ppidsec]"
117     }
118     if [catch {close $fi} curmess] {
119     return
120     }
121     set plist [lsort $plist]
122     set procs $batch_pid
123     # Two passes required when process id's go into recycling
124     for {set i 0} {$i < 2} {incr i} {
125     foreach pp $plist {
126     if {[lsearch -exact $procs [lindex $pp 1]] >= 0 &&
127     ($i == 0 || [lsearch -exact $procs \
128     [lindex $pp 0]] < 0)} {
129     lappend procs [lindex $pp 0]
130     }
131     }
132     }
133     if {! [catch {eval exec kill $procs} curmess]} {
134     set curmess "Batch process $batch_pid and children killed."
135     }
136     # change modes
137     $mywin.rbki configure -state disabled
138     $mywin.rbst configure -state normal
139     $mywin.rbvmb configure -state normal
140     set batch_pid 0
141     }
142    
143     proc make_vmenus {} { # make/update view menus
144     global mywin radvar rvview
145     if {"$radvar(view)" == {}} {
146     set rvview X
147     } else {
148     set rvview [lindex [lindex $radvar(view) 0] 0]
149     }
150     catch {destroy $mywin.rivmb.m}
151 greg 2.2 catch {destroy $mywin.rbvmb.m}
152 greg 2.1 if {[llength $radvar(view)] < 2} {
153     $mywin.rivmb configure -state disabled
154 greg 2.2 return
155 greg 2.1 }
156 greg 2.2 menu $mywin.rivmb.m
157     $mywin.rivmb configure -menu $mywin.rivmb.m -state normal
158     foreach v $radvar(view) {
159     $mywin.rivmb.m add radiobutton -label [lindex $v 0] \
160     -variable rvview -value [lindex $v 0]
161     }
162     menu $mywin.rbvmb.m
163 greg 2.5 $mywin.rbvmb configure -menu $mywin.rbvmb.m
164 greg 2.2 $mywin.rbvmb.m add radiobutton -label ALL \
165     -variable rpview -value " ALL"
166     $mywin.rbvmb.m add separator
167     foreach v $radvar(view) {
168     $mywin.rbvmb.m add radiobutton -label [lindex $v 0] \
169     -variable rpview -value [lindex $v 0]
170 greg 2.1 }
171     }
172    
173     proc do_action w { # Action screen
174     global rifname rvview rpview radvar bfname batch_pid \
175 greg 2.6 curmess scname mywin alldone batch_fmt hostname
176 greg 2.1 if {"$w" == "done"} {
177 greg 2.8 unset rvview rpview bfname batch_pid mywin
178 greg 2.1 return
179     }
180     set bfname [file rootname [file tail $rifname]].err
181     frame $w
182     set mywin $w
183     # Generate octree
184     label $w.octl -text {Compile scene only}
185     place $w.octl -relx .1429 -rely .0610
186     button $w.octb -text oconv -relief raised -command make_oct
187     place $w.octb -relwidth .1071 -relheight .0610 -relx .4643 -rely .0610
188     helplink $w.octb trad action oconv
189     button $w.octt -text Touch -relief raised -command {make_oct -t}
190     place $w.octt -relwidth .1071 -relheight .0610 -relx .7143 -rely .0610
191     helplink $w.octt trad action touch
192     button $w.octf -text Force -relief raised -command \
193     {catch {exec rm -f $radvar(OCTREE)} ; make_oct}
194     place $w.octf -relwidth .1071 -relheight .0610 -relx .5893 -rely .0610
195     helplink $w.octf trad action force
196     # Render interactively
197     label $w.ril -text {Render interactively}
198     place $w.ril -relx .1429 -rely .2439
199     button $w.rirv -text rview -relief raised \
200     -command {run_rad -v $rvview -o x11}
201     place $w.rirv -relwidth .1071 -relheight .0610 -relx .4643 -rely .2439
202     helplink $w.rirv trad action rview
203     label $w.rivl -text View:
204     place $w.rivl -relx .6072 -rely .2439
205     menubutton $w.rivmb -textvariable rvview -anchor w -relief raised
206     place $w.rivmb -relwidth .1071 -relheight .0610 -relx .7143 -rely .2439
207     helplink $w.rivmb trad action view
208     # Render in background
209     label $w.rbl -text {Render in background}
210     place $w.rbl -relx .1429 -rely .4268
211     button $w.rbst -text Start -relief raised -command run_batch
212     place $w.rbst -relwidth .1071 -relheight .0610 -relx .4643 -rely .4268
213     helplink $w.rbst trad action start
214     label $w.rbvl -text View:
215     place $w.rbvl -relx .6072 -rely .4268
216     menubutton $w.rbvmb -textvariable rpview -anchor w -relief raised
217     place $w.rbvmb -relwidth .1071 -relheight .0610 -relx .7143 -rely .4268
218     helplink $w.rbvmb trad action view
219     button $w.rbki -text Kill -relief raised -command kill_batch
220     place $w.rbki -relwidth .1071 -relheight .0610 -relx .4643 -rely .5488
221     helplink $w.rbki trad action kill
222     button $w.rbce -text "Check errors" -relief raised \
223     -command {view_txt $bfname}
224     place $w.rbce -relwidth .1786 -relheight .0610 -relx .6429 -rely .5488
225     helplink $w.rbce trad action checkerr
226     if [file exists $bfname] {
227     set fi [open $bfname r]
228 greg 2.8 if {[scan [gets $fi] $batch_fmt batch_pid batch_host] != 2} {
229     set batch_host unknown
230     set radcom {}
231     } else {
232     gets $fi radcom
233     }
234 greg 2.1 close $fi
235 greg 2.6 if [string match "rad -v *" $radcom] {
236     set rpview [lindex $radcom 2]
237     } else {
238     set rpview " ALL"
239     }
240     if {"$hostname" != "$batch_host"} {
241 greg 2.1 if $alldone {
242 greg 2.6 set curmess "Batch rendering finished\
243 greg 2.7 on $batch_host."
244 greg 2.6 } else {
245 greg 2.7 set curmess "Batch rendering on\
246     $batch_host -- status UNKNOWN."
247 greg 2.6 $w.rbst configure -state disabled
248     $w.rbvmb configure -state disabled
249     }
250     set batch_pid 0
251     $w.rbki configure -state disabled
252     } elseif {[catch {exec /bin/kill -0 $batch_pid}]} {
253     if $alldone {
254 greg 2.1 set curmess "Batch rendering finished."
255     } else {
256     set curmess "Batch rendering stopped."
257     }
258     set batch_pid 0
259     set rpview " ALL"
260     $w.rbki configure -state disabled
261     } else {
262     set curmess "Batch rendering process $batch_pid running."
263     $w.rbst configure -state disabled
264     $w.rbvmb configure -state disabled
265     }
266     } else {
267     set curmess "No batch rendering in progress."
268     set batch_pid 0
269     set rpview " ALL"
270     $w.rbki configure -state disabled
271     $w.rbce configure -state disabled
272     }
273     make_vmenus
274     # Dry run
275     label $w.drl -text {Dry run}
276     place $w.drl -relx .1429 -rely .7317
277     button $w.drsc -text Script -relief raised -command make_script
278     place $w.drsc -relwidth .1071 -relheight .0610 -relx .4643 -rely .7317
279     entry $w.drsf -textvariable scname -relief sunken
280     place $w.drsf -relwidth .2143 -relheight .0610 -relx .6429 -rely .7317
281     helplink "$w.drsc $w.drsf" trad action script
282     button $w.drvw -text Edit -relief raised -command {view_txt $scname}
283     place $w.drvw -relwidth .1071 -relheight .0610 -relx .4643 -rely .8537
284     helplink $w.drvw trad action edit
285     button $w.drdel -text Delete -relief raised \
286     -command {catch {exec rm $scname < /dev/null} curmess}
287     place $w.drdel -relwidth .1071 -relheight .0610 -relx .6429 -rely .8537
288     helplink $w.drdel trad action delete
289     }