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 |
lappend radvar(view) "$n $v" |
23 |
} 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 |
if [info exists radvar(VARIABILITY)] { |
70 |
cardval radvar(VARIABILITY) {High Medium Low} |
71 |
} else { |
72 |
set radvar(VARIABILITY) Low |
73 |
} |
74 |
} |
75 |
|
76 |
proc setradvar stmt { # assign a rad variable |
77 |
global radvar |
78 |
regexp {^([a-zA-Z][a-zA-Z0-9]*) *= *(.*)$} $stmt dummy vnam vval |
79 |
switch -glob $vnam { |
80 |
obj* { eval lappend radvar(objects) $vval } |
81 |
sce* { eval lappend radvar(scene) $vval } |
82 |
mat* { eval lappend radvar(materials) $vval } |
83 |
ill* { eval lappend radvar(illum) $vval } |
84 |
mki* { eval lappend radvar(mkillum) $vval } |
85 |
ren* { eval lappend radvar(render) $vval } |
86 |
oco* { eval lappend radvar(oconv) $vval } |
87 |
pf* { eval lappend radvar(pfilt) $vval } |
88 |
vi* { lappend radvar(view) $vval } |
89 |
ZO* { set radvar(ZONE) $vval } |
90 |
QUA* { set radvar(QUALITY) $vval } |
91 |
OCT* { set radvar(OCTREE) $vval } |
92 |
PIC* { set radvar(PICTURE) $vval } |
93 |
AMB* { set radvar(AMBFILE) $vval } |
94 |
OPT* { set radvar(OPTFILE) $vval } |
95 |
EXP* { set radvar(EXPOSURE) $vval } |
96 |
RES* { set radvar(RESOLUTION) $vval } |
97 |
UP { set radvar(UP) $vval } |
98 |
IND* { set radvar(INDIRECT) $vval } |
99 |
DET* { set radvar(DETAIL) $vval } |
100 |
PEN* { set radvar(PENUMBRAS) $vval } |
101 |
VAR* { set radvar(VARIABILITY) $vval } |
102 |
REP* { set radvar(REPORT) $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 |
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 exists $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 |
catch {unset radvar($n)} |
171 |
} |
172 |
while {[gets $fi curli] != -1} { |
173 |
if [regexp {^[a-zA-Z][a-zA-Z0-9]* *=} $curli] { |
174 |
regexp {^[a-zA-Z][a-zA-Z0-9]*} $curli thisv |
175 |
if {[lsearch -exact $vl $thisv] >= 0} { |
176 |
setradvar $curli |
177 |
} |
178 |
} else { |
179 |
break |
180 |
} |
181 |
} |
182 |
set curmess {Variables loaded.} |
183 |
} |
184 |
set alldone [eof $fi] |
185 |
close $fi |
186 |
exec rm -f /usr/tmp/ro[pid] |
187 |
preen |
188 |
return 1 |
189 |
} |
190 |
|
191 |
proc save_vars {f {vl all}} { # save RIF variables |
192 |
global curmess radvar |
193 |
if {"$f" == {} || ! [info exists radvar]} {return 0} |
194 |
if {"$vl" == "all"} { |
195 |
if [catch {set fi [open $f w]} curmess] { |
196 |
beep |
197 |
return 0 |
198 |
} |
199 |
puts $fi "# Rad Input File created by trad [exec date]" |
200 |
foreach n [lsort [array names radvar]] { |
201 |
putradvar $fi $n |
202 |
} |
203 |
} else { |
204 |
if [catch {set fi [open $f a]} curmess] { |
205 |
beep |
206 |
return 0 |
207 |
} |
208 |
foreach n [array names radvar] { |
209 |
if {[lsearch -exact $vl $n] >= 0} { |
210 |
putradvar $fi $n |
211 |
} |
212 |
} |
213 |
} |
214 |
close $fi |
215 |
set curmess {File saved.} |
216 |
return 1 |
217 |
} |
218 |
|
219 |
proc newload f { # load a RIF |
220 |
global rifname readonly |
221 |
if [load_vars $f] { |
222 |
set rifname [pwd]/$f |
223 |
set readonly [expr ! [file writable $f]] |
224 |
gotfile 1 |
225 |
return 1 |
226 |
} |
227 |
return 0 |
228 |
} |
229 |
|
230 |
proc newsave f { # save a RIF |
231 |
global rifname readonly curmess |
232 |
if {"[pwd]/$f" == "$rifname"} { |
233 |
if $readonly { |
234 |
beep |
235 |
set curmess {Mode set to read only.} |
236 |
return 0 |
237 |
} |
238 |
} elseif {[file exists $f]} { |
239 |
if [tk_dialog .dlg {Verification} \ |
240 |
"Overwrite existing file $f?" \ |
241 |
questhead 1 {Go Ahead} {Cancel}] { |
242 |
return 0 |
243 |
} |
244 |
} |
245 |
if {[file exists $f] && ! [file writable $f] && |
246 |
[catch {exec chmod u+w $f} curmess]} { |
247 |
beep |
248 |
return 0 |
249 |
} |
250 |
if [save_vars $f] { |
251 |
set rifname [pwd]/$f |
252 |
set readonly 0 |
253 |
gotfile 1 |
254 |
return 1 |
255 |
} |
256 |
return 0 |
257 |
} |
258 |
|
259 |
proc newnew f { # create a new RIF |
260 |
global rifname readonly curmess radvar |
261 |
if [file exists $f] { |
262 |
if [tk_dialog .dlg {Verification} \ |
263 |
"File $f exists -- disregard it?" \ |
264 |
questhead 1 {Yes} {Cancel}] { |
265 |
return 0 |
266 |
} |
267 |
} |
268 |
if {! [chksave]} {return 0} |
269 |
set rifname [pwd]/$f |
270 |
set readonly 0 |
271 |
catch {unset radvar} |
272 |
preen |
273 |
gotfile 1 |
274 |
set curmess {Go to SCENE and enter OCTREE and/or scene file(s).} |
275 |
return 1 |
276 |
} |
277 |
|
278 |
proc do_file w { |
279 |
global rifname readonly rif_glob curfile curpat |
280 |
if {"$w" == "done"} { |
281 |
cd [file dirname $rifname] |
282 |
set rif_glob $curpat |
283 |
return |
284 |
} |
285 |
frame $w |
286 |
frame $w.left |
287 |
pack $w.left -side left |
288 |
button $w.left.load -text LOAD -width 5 \ |
289 |
-relief raised -command {newload $curfile} |
290 |
button $w.left.save -text SAVE -width 5 -relief raised \ |
291 |
-command "newsave \$curfile; update_dir $w.right" |
292 |
button $w.left.new -text NEW -width 5 \ |
293 |
-relief raised -command {newnew $curfile} |
294 |
pack $w.left.load $w.left.save $w.left.new -side top -pady 15 -padx 20 |
295 |
checkbutton $w.left.ro -text "Read Only" -variable readonly \ |
296 |
-onvalue 1 -offvalue 0 -relief flat |
297 |
pack $w.left.ro -side top -pady 15 -padx 20 |
298 |
helplink $w.left.load trad file load |
299 |
helplink $w.left.save trad file save |
300 |
helplink $w.left.new trad file new |
301 |
helplink $w.left.ro trad file readonly |
302 |
getfile -view view_txt -perm \ |
303 |
-win $w.right -glob [file dirname $rifname]/$rif_glob |
304 |
set curfile [file tail $rifname] |
305 |
} |