ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_action.tcl
Revision: 2.5
Committed: Wed Nov 30 15:23:56 1994 UTC (29 years, 4 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Changes since 2.4: +1 -2 lines
Log Message:
fixed improper disabling/enabling of rpict view menu button

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