ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_action.tcl
Revision: 2.2
Committed: Thu Oct 27 17:28:19 1994 UTC (29 years, 6 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Changes since 2.1: +17 -20 lines
Log Message:
fixed problem with reading in new views

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