ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_file.tcl
Revision: 2.19
Committed: Sun Jun 3 20:32:49 2012 UTC (11 years, 10 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
CVS Tags: rad4R2P2, rad4R2, rad4R2P1
Changes since 2.18: +4 -2 lines
Log Message:
Added missing rvu and rpict variables

File Contents

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