ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_file.tcl
Revision: 2.18
Committed: Wed Feb 16 05:40:12 2005 UTC (19 years, 2 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1, rad4R1, rad4R0, rad3R8, rad3R9
Changes since 2.17: +6 -6 lines
Log Message:
Replaced instances of "/usr/tmp" with "/tmp" in scripts & documentation

File Contents

# Content
1 # RCSid: $Id: do_file.tcl,v 2.17 2003/02/22 02:07:30 greg Exp $
2 #
3 # Choose the Rad Input File to work on.
4 #
5
6 proc preen {} { # clean up radvar
7 global radvar rifname
8 foreach n {objects scene materials illum mkillum render oconv pfilt
9 RAWFILE ZFILE AMBFILE OPTFILE EXPOSURE ZONE REPORT} {
10 if {! [info exists radvar($n)]} {
11 set radvar($n) {}
12 }
13 }
14 if [info exists radvar(view)] {
15 set oldval $radvar(view)
16 set radvar(view) {}
17 set n 1
18 foreach v $oldval {
19 if {"[string index $v 0]" == "-"} {
20 lappend radvar(view) "u$n $v"
21 } elseif {[lsearch -glob $radvar(view) \
22 "[lindex $v 0] *"] >= 0} {
23 continue
24 } else {
25 lappend radvar(view) $v
26 }
27 incr n
28 }
29 } else {
30 set radvar(view) {}
31 }
32 if {! [info exists radvar(UP)]} {
33 set radvar(UP) Z
34 } elseif {[string match +* $radvar(UP)]} {
35 set radvar(UP) [string toupper [string range $radvar(UP) 1 end]]
36 } else {
37 set radvar(UP) [string toupper $radvar(UP)]
38 }
39 set rifroot [file rootname [file tail $rifname]]
40 if {! [info exists radvar(OCTREE)]} {
41 set radvar(OCTREE) $rifroot.oct
42 }
43 if {! [info exists radvar(RESOLUTION)]} {
44 set radvar(RESOLUTION) 512
45 }
46 if {! [info exists radvar(EYESEP)]} {
47 set radvar(EYESEP) 1
48 }
49 if [info exists radvar(QUALITY)] {
50 cardval radvar(QUALITY) {High Medium Low}
51 } else {
52 set radvar(QUALITY) Low
53 }
54 if {! [info exists radvar(PICTURE)]} {
55 set radvar(PICTURE) $rifroot
56 }
57 if {! [info exists radvar(INDIRECT)]} {
58 set radvar(INDIRECT) 0
59 }
60 if [info exists radvar(DETAIL)] {
61 cardval radvar(DETAIL) {High Medium Low}
62 } else {
63 set radvar(DETAIL) Medium
64 }
65 if [info exists radvar(PENUMBRAS)] {
66 cardval radvar(PENUMBRAS) {True False}
67 } else {
68 set radvar(PENUMBRAS) False
69 }
70 if [info exists radvar(VARIABILITY)] {
71 cardval radvar(VARIABILITY) {High Medium Low}
72 } else {
73 set radvar(VARIABILITY) Low
74 }
75 }
76
77 proc setradvar stmt { # assign a rad variable
78 global radvar
79 regexp {^([a-zA-Z][a-zA-Z0-9]*) *=[ ]*(.*)$} $stmt dummy vnam vval
80 switch -glob $vnam {
81 obj* { eval lappend radvar(objects) $vval }
82 sce* { eval lappend radvar(scene) $vval }
83 mat* { eval lappend radvar(materials) $vval }
84 ill* { eval lappend radvar(illum) $vval }
85 mki* { eval lappend radvar(mkillum) $vval }
86 ren* { eval lappend radvar(render) $vval }
87 oco* { eval lappend radvar(oconv) $vval }
88 pf* { eval lappend radvar(pfilt) $vval }
89 vi* { lappend radvar(view) $vval }
90 ZO* { set radvar(ZONE) $vval }
91 QUA* { set radvar(QUALITY) $vval }
92 OCT* { set radvar(OCTREE) $vval }
93 PIC* { set radvar(PICTURE) $vval }
94 AMB* { set radvar(AMBFILE) $vval }
95 OPT* { set radvar(OPTFILE) $vval }
96 EXP* { set radvar(EXPOSURE) $vval }
97 EYE* { set radvar(EYESEP) $vval }
98 RES* { set radvar(RESOLUTION) $vval }
99 UP { set radvar(UP) $vval }
100 IND* { set radvar(INDIRECT) $vval }
101 DET* { set radvar(DETAIL) $vval }
102 PEN* { set radvar(PENUMBRAS) $vval }
103 VAR* { set radvar(VARIABILITY) $vval }
104 REP* { set radvar(REPORT) $vval }
105 RAW* { set radvar(RAWFILE) $vval }
106 ZF* {set radvar(ZFILE) $vval }
107 }
108
109 }
110
111 proc putradvar {fi vn} { # print out a rad variable
112 global radvar
113 if {! [info exists radvar($vn)] || $radvar($vn) == {}} {return}
114 if [regexp {^[A-Z]} $vn] {
115 puts $fi "$vn= $radvar($vn)"
116 return
117 }
118 if {"$vn" == "view"} {
119 foreach v $radvar(view) {
120 puts $fi "view= $v"
121 }
122 return
123 }
124 if {[lsearch -exact {ZONE QUALITY OCTREE PICTURE AMBFILE OPTFILE
125 EXPOSURE RESOLUTION UP INDIRECT DETAIL PENUMBRAS
126 EYESEP RAWFILE ZFILE VARIABILITY REPORT} $vn] >= 0} {
127 puts $fi "$vn= $radvar($vn)"
128 return
129 }
130 puts -nonewline $fi "$vn="
131 set vnl [expr [string length $vn] + 1]
132 set pos $vnl
133 for {set i 0} {$i < [llength $radvar($vn)]} {incr i} {
134 set len [expr [string length [lindex $radvar($vn) $i]] + 1]
135 if {$pos > $vnl && $pos + $len > 70} {
136 puts -nonewline $fi "\n$vn="
137 set pos $vnl
138 }
139 puts -nonewline $fi " [lindex $radvar($vn) $i]"
140 incr pos $len
141 }
142 puts $fi {}
143 }
144
145 proc load_vars {f {vl all}} { # load RIF variables
146 global curmess radvar alldone
147 if {"$f" == ""} {return 0}
148 if {! [file isfile $f]} {
149 beep
150 set curmess "$f: no such file."
151 return 0
152 }
153 if {"$vl" == "all" && ! [chksave]} {return 0}
154 set curmess {Please wait...}
155 update
156 if [catch {exec rad -n -w -e $f >& /tmp/ro[pid]}] {
157 set curmess [exec cat /tmp/ro[pid]]
158 exec rm -f /tmp/ro[pid]
159 return 0
160 }
161 set fi [open /tmp/ro[pid] r]
162 if {"$vl" == "all"} {
163 catch {unset radvar}
164 while {[gets $fi curli] != -1} {
165 if [regexp {^[a-zA-Z][a-zA-Z0-9]* *=} $curli] {
166 setradvar $curli
167 } else {
168 break
169 }
170 }
171 set curmess {Project loaded.}
172 } else {
173 foreach n $vl {
174 if [regexp {[a-z][a-z]*} $n] {
175 set radvar($n) {}
176 } else {
177 catch {unset radvar($n)}
178 }
179 }
180 while {[gets $fi curli] != -1} {
181 if [regexp {^[a-zA-Z][a-zA-Z0-9]* *=} $curli] {
182 regexp {^[a-zA-Z][a-zA-Z0-9]*} $curli thisv
183 if {[lsearch -exact $vl $thisv] >= 0} {
184 setradvar $curli
185 }
186 } else {
187 break
188 }
189 }
190 set curmess {Variables loaded.}
191 }
192 set alldone [eof $fi]
193 close $fi
194 exec rm -f /tmp/ro[pid]
195 preen
196 return 1
197 }
198
199 proc save_vars {f {vl all}} { # save RIF variables
200 global curmess radvar
201 if {"$f" == {} || ! [info exists radvar]} {return 0}
202 if {"$vl" == "all"} {
203 if [catch {set fi [open $f w]} curmess] {
204 beep
205 return 0
206 }
207 puts $fi "# Rad Input File created by trad [exec date]"
208 foreach n [lsort [array names radvar]] {
209 putradvar $fi $n
210 }
211 } else {
212 if [catch {set fi [open $f a]} curmess] {
213 beep
214 return 0
215 }
216 foreach n [array names radvar] {
217 if {[lsearch -exact $vl $n] >= 0} {
218 putradvar $fi $n
219 }
220 }
221 }
222 close $fi
223 set curmess {File saved.}
224 return 1
225 }
226
227 proc newload f { # load a RIF
228 global rifname readonly
229 if [load_vars $f] {
230 set rifname [pwd]/$f
231 set readonly [expr ! [file writable $f]]
232 gotfile 1
233 return 1
234 }
235 return 0
236 }
237
238 proc newsave f { # save a RIF
239 global rifname readonly curmess
240 if {"[pwd]/$f" == "$rifname"} {
241 if $readonly {
242 beep
243 set curmess {Mode set to read only.}
244 return 0
245 }
246 } elseif {[file exists $f]} {
247 set ftyp [file type $f]
248 if { $ftyp != "file" } {
249 beep
250 set curmess "Selected file $f is a $ftyp."
251 return 0
252 }
253 if [tk_dialog .dlg {Verification} \
254 "Overwrite existing file $f?" \
255 questhead 1 {Go Ahead} {Cancel}] {
256 return 0
257 }
258 }
259 if {[file isfile $f] && ! [file writable $f] &&
260 [catch {exec chmod u+w $f} curmess]} {
261 beep
262 return 0
263 }
264 if [save_vars $f] {
265 set rifname [pwd]/$f
266 set readonly 0
267 gotfile 1
268 return 1
269 }
270 return 0
271 }
272
273 proc newnew f { # create a new RIF
274 global rifname readonly curmess radvar
275 if [file exists $f] {
276 set ftyp [file type $f]
277 if { $ftyp != "file" } {
278 beep
279 set curmess "Selected file $f is a $ftyp."
280 return 0
281 }
282 if [tk_dialog .dlg {Verification} \
283 "File $f exists -- disregard it?" \
284 questhead 1 {Yes} {Cancel}] {
285 return 0
286 }
287 }
288 if {! [chksave]} {return 0}
289 set rifname [pwd]/$f
290 set readonly 0
291 catch {unset radvar}
292 preen
293 gotfile 1
294 set curmess {Go to SCENE and enter OCTREE and/or scene file(s).}
295 return 1
296 }
297
298 proc do_file w {
299 global rifname readonly myglob curfile curpat
300 if {"$w" == "done"} {
301 cd [file dirname $rifname]
302 set myglob(rif) $curpat
303 return
304 }
305 frame $w
306 frame $w.left
307 pack $w.left -side left
308 button $w.left.load -text LOAD -width 5 \
309 -relief raised -command {newload $curfile}
310 button $w.left.save -text SAVE -width 5 -relief raised \
311 -command "newsave \$curfile; update_dir $w.right"
312 button $w.left.new -text NEW -width 5 \
313 -relief raised -command {newnew $curfile}
314 pack $w.left.load $w.left.save $w.left.new -side top -pady 15 -padx 20
315 checkbutton $w.left.ro -text "Read Only" -variable readonly \
316 -onvalue 1 -offvalue 0 -relief flat
317 pack $w.left.ro -side top -pady 15 -padx 20
318 helplink $w.left.load trad file load
319 helplink $w.left.save trad file save
320 helplink $w.left.new trad file new
321 helplink $w.left.ro trad file readonly
322 getfile -view view_txt -perm \
323 -win $w.right -glob [file dirname $rifname]/$myglob(rif)
324 set curfile [file tail $rifname]
325 }