ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_action.tcl
Revision: 2.4
Committed: Mon Oct 31 11:30:44 1994 UTC (29 years, 5 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Changes since 2.3: +1 -1 lines
Log Message:
changed USER to LOGNAME for better system compatibility

File Contents

# User Rev Content
1 greg 2.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 greg 2.4 default {set ps "ps -lu $env(LOGNAME)"}
104 greg 2.1 }
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 greg 2.2 catch {destroy $mywin.rbvmb.m}
147 greg 2.1 if {[llength $radvar(view)] < 2} {
148     $mywin.rivmb configure -state disabled
149 greg 2.2 $mywin.rbvmb configure -state disabled
150     return
151 greg 2.1 }
152 greg 2.2 menu $mywin.rivmb.m
153     $mywin.rivmb configure -menu $mywin.rivmb.m -state normal
154     foreach v $radvar(view) {
155     $mywin.rivmb.m add radiobutton -label [lindex $v 0] \
156     -variable rvview -value [lindex $v 0]
157     }
158     menu $mywin.rbvmb.m
159     $mywin.rbvmb configure -menu $mywin.rbvmb.m -state normal
160     $mywin.rbvmb.m add radiobutton -label ALL \
161     -variable rpview -value " ALL"
162     $mywin.rbvmb.m add separator
163     foreach v $radvar(view) {
164     $mywin.rbvmb.m add radiobutton -label [lindex $v 0] \
165     -variable rpview -value [lindex $v 0]
166 greg 2.1 }
167     }
168    
169     proc do_action w { # Action screen
170     global rifname rvview rpview radvar bfname batch_pid \
171     curmess scname mywin alldone
172     if {"$w" == "done"} {
173     unset rpview bfname batch_pid mywin
174     return
175     }
176     set bfname [file rootname [file tail $rifname]].err
177     frame $w
178     set mywin $w
179     # Generate octree
180     label $w.octl -text {Compile scene only}
181     place $w.octl -relx .1429 -rely .0610
182     button $w.octb -text oconv -relief raised -command make_oct
183     place $w.octb -relwidth .1071 -relheight .0610 -relx .4643 -rely .0610
184     helplink $w.octb trad action oconv
185     button $w.octt -text Touch -relief raised -command {make_oct -t}
186     place $w.octt -relwidth .1071 -relheight .0610 -relx .7143 -rely .0610
187     helplink $w.octt trad action touch
188     button $w.octf -text Force -relief raised -command \
189     {catch {exec rm -f $radvar(OCTREE)} ; make_oct}
190     place $w.octf -relwidth .1071 -relheight .0610 -relx .5893 -rely .0610
191     helplink $w.octf trad action force
192     # Render interactively
193     label $w.ril -text {Render interactively}
194     place $w.ril -relx .1429 -rely .2439
195     button $w.rirv -text rview -relief raised \
196     -command {run_rad -v $rvview -o x11}
197     place $w.rirv -relwidth .1071 -relheight .0610 -relx .4643 -rely .2439
198     helplink $w.rirv trad action rview
199     label $w.rivl -text View:
200     place $w.rivl -relx .6072 -rely .2439
201     menubutton $w.rivmb -textvariable rvview -anchor w -relief raised
202     place $w.rivmb -relwidth .1071 -relheight .0610 -relx .7143 -rely .2439
203     helplink $w.rivmb trad action view
204     # Render in background
205     label $w.rbl -text {Render in background}
206     place $w.rbl -relx .1429 -rely .4268
207     button $w.rbst -text Start -relief raised -command run_batch
208     place $w.rbst -relwidth .1071 -relheight .0610 -relx .4643 -rely .4268
209     helplink $w.rbst trad action start
210     label $w.rbvl -text View:
211     place $w.rbvl -relx .6072 -rely .4268
212     menubutton $w.rbvmb -textvariable rpview -anchor w -relief raised
213     place $w.rbvmb -relwidth .1071 -relheight .0610 -relx .7143 -rely .4268
214     helplink $w.rbvmb trad action view
215     button $w.rbki -text Kill -relief raised -command kill_batch
216     place $w.rbki -relwidth .1071 -relheight .0610 -relx .4643 -rely .5488
217     helplink $w.rbki trad action kill
218     button $w.rbce -text "Check errors" -relief raised \
219     -command {view_txt $bfname}
220     place $w.rbce -relwidth .1786 -relheight .0610 -relx .6429 -rely .5488
221     helplink $w.rbce trad action checkerr
222     if [file exists $bfname] {
223     set fi [open $bfname r]
224     eval set batch_pid [gets $fi]
225     gets $fi radcom
226     close $fi
227     if [catch {exec /bin/kill -0 $batch_pid}] {
228     if $alldone {
229     set curmess "Batch rendering finished."
230     } else {
231     set curmess "Batch rendering stopped."
232     }
233     set batch_pid 0
234     set rpview " ALL"
235     $w.rbki configure -state disabled
236     } else {
237     set curmess "Batch rendering process $batch_pid running."
238     if [string match "rad -v *" $radcom] {
239     set rpview [lindex $radcom 2]
240     } else {
241     set rpview " ALL"
242     }
243     $w.rbst configure -state disabled
244     $w.rbvmb configure -state disabled
245     }
246     } else {
247     set curmess "No batch rendering in progress."
248     set batch_pid 0
249     set rpview " ALL"
250     $w.rbki configure -state disabled
251     $w.rbce configure -state disabled
252     }
253     make_vmenus
254     # Dry run
255     label $w.drl -text {Dry run}
256     place $w.drl -relx .1429 -rely .7317
257     button $w.drsc -text Script -relief raised -command make_script
258     place $w.drsc -relwidth .1071 -relheight .0610 -relx .4643 -rely .7317
259     entry $w.drsf -textvariable scname -relief sunken
260     place $w.drsf -relwidth .2143 -relheight .0610 -relx .6429 -rely .7317
261     helplink "$w.drsc $w.drsf" trad action script
262     button $w.drvw -text Edit -relief raised -command {view_txt $scname}
263     place $w.drvw -relwidth .1071 -relheight .0610 -relx .4643 -rely .8537
264     helplink $w.drvw trad action edit
265     button $w.drdel -text Delete -relief raised \
266     -command {catch {exec rm $scname < /dev/null} curmess}
267     place $w.drdel -relwidth .1071 -relheight .0610 -relx .6429 -rely .8537
268     helplink $w.drdel trad action delete
269     }