ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_file.tcl
Revision: 2.15
Committed: Tue Aug 12 15:19:05 1997 UTC (26 years, 8 months ago) by gregl
Content type: application/x-tcl
Branch: MAIN
Changes since 2.14: +2 -2 lines
Log Message:
fixed problems with understanding tabs in variable assignments

File Contents

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