ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_action.tcl
Revision: 2.1
Committed: Thu Oct 27 15:56:06 1994 UTC (29 years, 6 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Log Message:
Initial revision

File Contents

# Content
1 # SCCSid "$SunId$ LBL"
2 #
3 # Action screen for trad
4 #
5
6 proc make_script {} { # make run script
7 global scname rpview curmess
8 set rfn /usr/tmp/rf[pid]
9 if {! [save_vars $rfn]} {
10 beep
11 set curmess "Cannot save variables to temporary file!"
12 return
13 }
14 set radcom {rad -n}
15 if {"$rpview" != " ALL"} {
16 lappend radcom -v $rpview
17 }
18 if {"$scname" == {}} {
19 set rof /usr/tmp/ro[pid]
20 } else {
21 set rof $scname
22 }
23 lappend radcom $rfn > $rof
24 set badrun [catch "exec $radcom" curmess]
25 if {"$scname" == {}} {
26 if {! $badrun} {
27 view_txt $rof
28 }
29 exec rm $rof
30 }
31 exec rm $rfn
32 }
33
34 proc make_oct args { # Make octree file ($args is {-t} or {})
35 global radvar curmess
36 if {"$radvar(scene)" == {} && "$radvar(illum)" == {}} {
37 set fi [open "|make $radvar(OCTREE) $args" r]
38 while {[gets $fi curmess] >= 0} { update ; after 1000 }
39 catch {close $fi} curmess
40 if {"$args" == {}} {return}
41 }
42 if {"$args" == {}} {
43 run_rad -v 0
44 } else {
45 run_rad $args
46 }
47 }
48
49 proc run_rad args { # Run rad command with given arguments
50 global curmess
51 set rfn /usr/tmp/rf[pid]
52 if {! [save_vars $rfn]} {
53 beep
54 set curmess "Cannot save variables to temporary file!"
55 return
56 }
57 set ot [file mtime $rfn]
58 set fi [open "|rad $args $rfn" r]
59 while {[gets $fi curmess] >= 0} { update ; after 1000 }
60 if {! [catch {close $fi} curmess] && [file mtime $rfn] > $ot} {
61 load_vars $rfn {view}
62 make_vmenus
63 }
64 exec rm $rfn
65 }
66
67 proc run_batch {} { # start rendering in background
68 global rpview bfname batch_pid curmess rifname mywin
69 if {! [chksave]} {return}
70 if [catch {set fo [open $bfname w]} curmess] {
71 return
72 }
73 # Make space for PID to be written later
74 puts $fo " "
75 if {$rpview == " ALL"} {
76 set radcom "rad"
77 } else {
78 set radcom "rad -v $rpview"
79 }
80 lappend radcom "[file tail $rifname]"
81 # Put out command
82 puts $fo $radcom
83 flush $fo
84 # Execute in background
85 set batch_pid [eval exec $radcom >>& $bfname &]
86 # Now, write PID and close file
87 seek $fo 0
88 puts -nonewline $fo $batch_pid
89 close $fo
90 set curmess "Batch rendering process $batch_pid started."
91 # Correct button stati
92 $mywin.rbst configure -state disabled
93 $mywin.rbki configure -state normal
94 $mywin.rbce configure -state normal
95 $mywin.rbvmb configure -state disabled
96 }
97
98 proc kill_batch {} { # kill batch rendering
99 global batch_pid env curmess mywin
100 # Kill batch process and children
101 switch -glob [exec uname] {
102 SunOS -
103 ULTRIX {set ps "ps -lg"}
104 default {set ps "ps -lu $env(USER)"}
105 }
106 set fi [open "|$ps" r]
107 gets $fi li
108 regexp -indices -nocase { *PID} $li pidsec
109 regexp -indices -nocase { *PPID} $li ppidsec
110 while {[gets $fi li] >= 0} {
111 lappend plist "[eval string range {$li} $pidsec]\
112 [eval string range {$li} $ppidsec]"
113 }
114 if [catch {close $fi} curmess] {
115 return
116 }
117 set plist [lsort $plist]
118 set procs $batch_pid
119 # Two passes required when process id's go into recycling
120 for {set i 0} {$i < 2} {incr i} {
121 foreach pp $plist {
122 if {[lsearch -exact $procs [lindex $pp 1]] >= 0 &&
123 ($i == 0 || [lsearch -exact $procs \
124 [lindex $pp 0]] < 0)} {
125 lappend procs [lindex $pp 0]
126 }
127 }
128 }
129 if {! [catch {eval exec kill $procs} curmess]} {
130 set curmess "Batch process $batch_pid and children killed."
131 }
132 # change modes
133 $mywin.rbki configure -state disabled
134 $mywin.rbst configure -state normal
135 $mywin.rbvmb configure -state normal
136 set batch_pid 0
137 }
138
139 proc make_vmenus {} { # make/update view menus
140 global mywin radvar rvview
141 if {"$radvar(view)" == {}} {
142 set rvview X
143 } else {
144 set rvview [lindex [lindex $radvar(view) 0] 0]
145 }
146 catch {destroy $mywin.rivmb.m}
147 if {[llength $radvar(view)] < 2} {
148 $mywin.rivmb configure -state disabled
149 } else {
150 menu $mywin.rivmb.m
151 $mywin.rivmb configure -menu $mywin.rivmb.m
152 foreach v $radvar(view) {
153 $mywin.rivmb.m add radiobutton -label [lindex $v 0] \
154 -variable rvview -value [lindex $v 0]
155 }
156 }
157 catch {destroy $mywin.rbvmb.m}
158 if {[llength $radvar(view)] < 2} {
159 $mywin.rbvmb configure -state disabled
160 } else {
161 menu $mywin.rbvmb.m
162 $mywin.rbvmb configure -menu $mywin.rbvmb.m
163 $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 }
170 }
171 }
172
173 proc do_action w { # Action screen
174 global rifname rvview rpview radvar bfname batch_pid \
175 curmess scname mywin alldone
176 if {"$w" == "done"} {
177 unset rpview bfname batch_pid mywin
178 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 eval set batch_pid [gets $fi]
229 gets $fi radcom
230 close $fi
231 if [catch {exec /bin/kill -0 $batch_pid}] {
232 if $alldone {
233 set curmess "Batch rendering finished."
234 } else {
235 set curmess "Batch rendering stopped."
236 }
237 set batch_pid 0
238 set rpview " ALL"
239 $w.rbki configure -state disabled
240 } else {
241 set curmess "Batch rendering process $batch_pid running."
242 if [string match "rad -v *" $radcom] {
243 set rpview [lindex $radcom 2]
244 } else {
245 set rpview " ALL"
246 }
247 $w.rbst configure -state disabled
248 $w.rbvmb configure -state disabled
249 }
250 } else {
251 set curmess "No batch rendering in progress."
252 set batch_pid 0
253 set rpview " ALL"
254 $w.rbki configure -state disabled
255 $w.rbce configure -state disabled
256 }
257 make_vmenus
258 # Dry run
259 label $w.drl -text {Dry run}
260 place $w.drl -relx .1429 -rely .7317
261 button $w.drsc -text Script -relief raised -command make_script
262 place $w.drsc -relwidth .1071 -relheight .0610 -relx .4643 -rely .7317
263 entry $w.drsf -textvariable scname -relief sunken
264 place $w.drsf -relwidth .2143 -relheight .0610 -relx .6429 -rely .7317
265 helplink "$w.drsc $w.drsf" trad action script
266 button $w.drvw -text Edit -relief raised -command {view_txt $scname}
267 place $w.drvw -relwidth .1071 -relheight .0610 -relx .4643 -rely .8537
268 helplink $w.drvw trad action edit
269 button $w.drdel -text Delete -relief raised \
270 -command {catch {exec rm $scname < /dev/null} curmess}
271 place $w.drdel -relwidth .1071 -relheight .0610 -relx .6429 -rely .8537
272 helplink $w.drdel trad action delete
273 }