ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/do_file.tcl
Revision: 2.9
Committed: Thu Jul 6 12:15:54 1995 UTC (28 years, 9 months ago) by greg
Content type: application/x-tcl
Branch: MAIN
Changes since 2.8: +7 -1 lines
Log Message:
added RAWSAVE variable to rad to save original rpict output

File Contents

# User Rev Content
1 greg 2.1 # SCCSid "$SunId$ LBL"
2     #
3     # Choose the Rad Input File to work on.
4     #
5    
6     set rif_glob *.rif
7    
8     proc preen {} { # clean up radvar
9     global radvar rifname
10     foreach n {objects scene materials illum mkillum render oconv pfilt
11     AMBFILE OPTFILE EXPOSURE ZONE REPORT} {
12     if {! [info exists radvar($n)]} {
13     set radvar($n) {}
14     }
15     }
16     if [info exists radvar(view)] {
17     set oldval $radvar(view)
18     set radvar(view) {}
19     set n 1
20     foreach v $oldval {
21     if {"[string index $v 0]" == "-"} {
22 greg 2.8 lappend radvar(view) "u$n $v"
23 greg 2.1 } elseif {[lsearch -glob $radvar(view) \
24     "[lindex $v 0] *"] >= 0} {
25     continue
26     } else {
27     lappend radvar(view) $v
28     }
29     incr n
30     }
31     } else {
32     set radvar(view) {}
33     }
34     if {! [info exists radvar(UP)]} {
35     set radvar(UP) Z
36     } elseif {[string match +* $radvar(UP)]} {
37     set radvar(UP) [string toupper [string range $radvar(UP) 1 end]]
38     } else {
39     set radvar(UP) [string toupper $radvar(UP)]
40     }
41     set rifroot [file rootname [file tail $rifname]]
42     if {! [info exists radvar(OCTREE)]} {
43     set radvar(OCTREE) $rifroot.oct
44     }
45     if {! [info exists radvar(RESOLUTION)]} {
46     set radvar(RESOLUTION) 512
47     }
48     if [info exists radvar(QUALITY)] {
49     cardval radvar(QUALITY) {High Medium Low}
50     } else {
51     set radvar(QUALITY) Low
52     }
53     if {! [info exists radvar(PICTURE)]} {
54     set radvar(PICTURE) $rifroot
55     }
56     if {! [info exists radvar(INDIRECT)]} {
57     set radvar(INDIRECT) 0
58     }
59     if [info exists radvar(DETAIL)] {
60     cardval radvar(DETAIL) {High Medium Low}
61     } else {
62     set radvar(DETAIL) Medium
63     }
64     if [info exists radvar(PENUMBRAS)] {
65     cardval radvar(PENUMBRAS) {True False}
66     } else {
67     set radvar(PENUMBRAS) False
68     }
69 greg 2.9 if [info exists radvar(RAWSAVE)] {
70     cardval radvar(RAWSAVE) {True False}
71     } else {
72     set radvar(RAWSAVE) False
73     }
74 greg 2.1 if [info exists radvar(VARIABILITY)] {
75     cardval radvar(VARIABILITY) {High Medium Low}
76     } else {
77     set radvar(VARIABILITY) Low
78     }
79     }
80    
81     proc setradvar stmt { # assign a rad variable
82     global radvar
83     regexp {^([a-zA-Z][a-zA-Z0-9]*) *= *(.*)$} $stmt dummy vnam vval
84     switch -glob $vnam {
85     obj* { eval lappend radvar(objects) $vval }
86     sce* { eval lappend radvar(scene) $vval }
87     mat* { eval lappend radvar(materials) $vval }
88     ill* { eval lappend radvar(illum) $vval }
89     mki* { eval lappend radvar(mkillum) $vval }
90     ren* { eval lappend radvar(render) $vval }
91     oco* { eval lappend radvar(oconv) $vval }
92     pf* { eval lappend radvar(pfilt) $vval }
93     vi* { lappend radvar(view) $vval }
94     ZO* { set radvar(ZONE) $vval }
95     QUA* { set radvar(QUALITY) $vval }
96     OCT* { set radvar(OCTREE) $vval }
97     PIC* { set radvar(PICTURE) $vval }
98     AMB* { set radvar(AMBFILE) $vval }
99     OPT* { set radvar(OPTFILE) $vval }
100     EXP* { set radvar(EXPOSURE) $vval }
101     RES* { set radvar(RESOLUTION) $vval }
102     UP { set radvar(UP) $vval }
103     IND* { set radvar(INDIRECT) $vval }
104     DET* { set radvar(DETAIL) $vval }
105     PEN* { set radvar(PENUMBRAS) $vval }
106 greg 2.9 RAW* { set radvar(RAWSAVE) $vval }
107 greg 2.1 VAR* { set radvar(VARIABILITY) $vval }
108     REP* { set radvar(REPORT) $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 greg 2.9 RAWSAVE VARIABILITY REPORT} $vn] >= 0} {
129 greg 2.1 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 exists $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 greg 2.3 update
158 greg 2.1 if [catch {exec rad -n -w -e $f >& /usr/tmp/ro[pid]}] {
159     set curmess [exec cat /usr/tmp/ro[pid]]
160     exec rm -f /usr/tmp/ro[pid]
161     return 0
162     }
163     set fi [open /usr/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 greg 2.7 catch {unset radvar($n)}
177 greg 2.1 }
178     while {[gets $fi curli] != -1} {
179     if [regexp {^[a-zA-Z][a-zA-Z0-9]* *=} $curli] {
180     regexp {^[a-zA-Z][a-zA-Z0-9]*} $curli thisv
181     if {[lsearch -exact $vl $thisv] >= 0} {
182     setradvar $curli
183     }
184     } else {
185     break
186     }
187     }
188     set curmess {Variables loaded.}
189     }
190     set alldone [eof $fi]
191     close $fi
192     exec rm -f /usr/tmp/ro[pid]
193     preen
194     return 1
195     }
196    
197     proc save_vars {f {vl all}} { # save RIF variables
198     global curmess radvar
199     if {"$f" == {} || ! [info exists radvar]} {return 0}
200     if {"$vl" == "all"} {
201     if [catch {set fi [open $f w]} curmess] {
202     beep
203     return 0
204     }
205     puts $fi "# Rad Input File created by trad [exec date]"
206     foreach n [lsort [array names radvar]] {
207     putradvar $fi $n
208     }
209     } else {
210     if [catch {set fi [open $f a]} curmess] {
211     beep
212     return 0
213     }
214     foreach n [array names radvar] {
215     if {[lsearch -exact $vl $n] >= 0} {
216     putradvar $fi $n
217     }
218     }
219     }
220     close $fi
221     set curmess {File saved.}
222     return 1
223     }
224    
225     proc newload f { # load a RIF
226     global rifname readonly
227     if [load_vars $f] {
228     set rifname [pwd]/$f
229     set readonly [expr ! [file writable $f]]
230     gotfile 1
231     return 1
232     }
233     return 0
234     }
235    
236     proc newsave f { # save a RIF
237     global rifname readonly curmess
238     if {"[pwd]/$f" == "$rifname"} {
239     if $readonly {
240     beep
241     set curmess {Mode set to read only.}
242     return 0
243     }
244     } elseif {[file exists $f]} {
245     if [tk_dialog .dlg {Verification} \
246     "Overwrite existing file $f?" \
247     questhead 1 {Go Ahead} {Cancel}] {
248     return 0
249     }
250     }
251 greg 2.6 if {[file exists $f] && ! [file writable $f] &&
252     [catch {exec chmod u+w $f} curmess]} {
253 greg 2.5 beep
254     return 0
255     }
256 greg 2.1 if [save_vars $f] {
257     set rifname [pwd]/$f
258     set readonly 0
259     gotfile 1
260     return 1
261     }
262     return 0
263     }
264    
265     proc newnew f { # create a new RIF
266     global rifname readonly curmess radvar
267     if [file exists $f] {
268     if [tk_dialog .dlg {Verification} \
269     "File $f exists -- disregard it?" \
270     questhead 1 {Yes} {Cancel}] {
271     return 0
272     }
273     }
274     if {! [chksave]} {return 0}
275     set rifname [pwd]/$f
276     set readonly 0
277     catch {unset radvar}
278     preen
279     gotfile 1
280     set curmess {Go to SCENE and enter OCTREE and/or scene file(s).}
281     return 1
282     }
283    
284     proc do_file w {
285     global rifname readonly rif_glob curfile curpat
286     if {"$w" == "done"} {
287 greg 2.2 cd [file dirname $rifname]
288 greg 2.1 set rif_glob $curpat
289     return
290     }
291     frame $w
292     frame $w.left
293     pack $w.left -side left
294     button $w.left.load -text LOAD -width 5 \
295     -relief raised -command {newload $curfile}
296 greg 2.4 button $w.left.save -text SAVE -width 5 -relief raised \
297     -command "newsave \$curfile; update_dir $w.right"
298 greg 2.1 button $w.left.new -text NEW -width 5 \
299     -relief raised -command {newnew $curfile}
300     pack $w.left.load $w.left.save $w.left.new -side top -pady 15 -padx 20
301     checkbutton $w.left.ro -text "Read Only" -variable readonly \
302     -onvalue 1 -offvalue 0 -relief flat
303     pack $w.left.ro -side top -pady 15 -padx 20
304     helplink $w.left.load trad file load
305     helplink $w.left.save trad file save
306     helplink $w.left.new trad file new
307     helplink $w.left.ro trad file readonly
308     getfile -view view_txt -perm \
309     -win $w.right -glob [file dirname $rifname]/$rif_glob
310     set curfile [file tail $rifname]
311     }