1# plot3d.tcl - PLOT3D import/export
2
3array set Plot3d {
4  mode ""
5  cgns ""
6  xyz ""
7  q ""
8  basenum ""
9  basename ""
10  solnum ""
11  basenum,flag 1
12  solnum,flag 1
13  block ""
14  format ""
15  iblank ""
16  type u
17  mach ""
18  ignore ""
19  double ""
20  base ""
21  convert ""
22  weight ""
23  gamma 1.4
24}
25
26proc plot3d_import {w name exe} {
27  global ProgData Plot3d Import
28  set cmd [get_executable $exe 1]
29  if {$cmd == ""} return
30
31  set Plot3d(mode) import
32  set Plot3d(cgns) $ProgData(file,name)
33  if ![plot3d_panel $w] return
34  update idletasks
35
36  set opts $Plot3d(block)$Plot3d(format)$Plot3d(type)
37  if {$Plot3d(ignore) != ""} {
38    append opts $Plot3d(ignore)
39  } else {
40    append opts $Plot3d(iblank)
41  }
42  append opts $Plot3d(double)$Plot3d(convert)
43  if {$Plot3d(mach) != ""} {
44    append opts M$Plot3d(mach)
45  }
46  if {$opts != ""} {
47    lappend cmd -$opts
48  }
49  if {$Plot3d(basenum) != ""} {
50    lappend cmd -b$Plot3d(basenum)
51  }
52  if {$Plot3d(basename) != ""} {
53    lappend cmd -B$Plot3d(basename)
54  }
55  if {$Plot3d(gamma) != ""} {
56    lappend cmd -g$Plot3d(gamma)
57  }
58
59  lappend cmd $Plot3d(xyz)
60  if {$Plot3d(q) != ""} {
61    lappend cmd $Plot3d(q)
62  }
63  lappend cmd $Plot3d(cgns)
64
65  import_run "PLOT3D Import" $cmd $Plot3d(cgns)
66}
67
68proc plot3d_export {w name exe} {
69  global ProgData Plot3d
70  set cmd [get_executable $exe 1]
71  if {$cmd == ""} return
72
73  set Plot3d(mode) export
74  set Plot3d(cgns) $ProgData(file,name)
75  set Plot3d(xyz) [file rootname $ProgData(file,name)].xyz
76  set Plot3d(q) [file rootname $ProgData(file,name)].q
77  if ![plot3d_panel $w] return
78  update idletasks
79
80  set opts $Plot3d(block)$Plot3d(format)$Plot3d(type)
81  append opts $Plot3d(ignore)$Plot3d(double)$Plot3d(weight)
82  if {$opts != ""} {
83    lappend cmd -$opts
84  }
85  if {$Plot3d(basenum) != ""} {
86    lappend cmd -b$Plot3d(basenum)
87  }
88  if {$Plot3d(solnum) != ""} {
89    lappend cmd -S$Plot3d(solnum)
90  }
91  if {$Plot3d(gamma) != ""} {
92    lappend cmd -g$Plot3d(gamma)
93  }
94
95  lappend cmd $Plot3d(cgns) $Plot3d(xyz)
96  if {$Plot3d(q) != ""} {
97    lappend cmd $Plot3d(q)
98  }
99
100  update
101  run_command "PLOT3D Export" $cmd
102}
103
104proc plot3d_panel {w} {
105  global ProgData Font Plot3d
106
107  toplevel $w
108  wm title $w "Plot3d $Plot3d(mode)"
109  wm transient $w .
110  wm protocol $w WM_DELETE_WINDOW {set Plot3d(done) 0}
111
112  FrameCreate $w.file -text "Files" -font $Font(bold)
113  pack $w.file -side top -pady 2 -fill x
114  set file [FrameGet $w.file]
115
116  foreach i {cgns xyz q} {
117    set f [frame $file.$i]
118    pack $f -side top -fill x
119    label $f.lab -text [string toupper $i] -width 6 -anchor w
120    pack $f.lab -side left
121    entry $f.ent -textvariable Plot3d($i) -width 30
122    pack $f.ent -side left -fill x -expand 1
123    button $f.but -text Browse -pady 0 -command "plot3d_browse_$i $w"
124    pack $f.but -side right -fill y
125  }
126
127  FrameCreate $w.base -text "CGNS Location" -font $Font(bold)
128  pack $w.base -side top -pady 2 -fill x
129  set base [FrameGet $w.base]
130  set labw 12
131
132  set f [frame $base.num]
133  pack $f -side top -anchor w
134  label $f.lab -text "Base Index" -width $labw -anchor w
135  entry $f.ent -textvariable Plot3d(basenum) -width 10
136  checkbutton $f.but -text default \
137    -variable Plot3d(basenum,flag) -onvalue 1 -offvalue 0 \
138    -command "plot3d_state basenum $f.ent"
139  pack $f.lab $f.ent $f.but -side left
140  plot3d_state basenum $f.ent
141
142  set f [frame $base.name]
143  if {$Plot3d(mode) == "import"} {
144    pack $f -side top -anchor w
145  }
146  label $f.lab -text "Base Name" -width $labw -anchor w
147  entry $f.ent -textvariable Plot3d(basename) -width 30
148  pack $f.lab $f.ent -side left
149
150  set f [frame $base.sol]
151  if {$Plot3d(mode) == "export"} {
152    pack $f -side top -anchor w
153  }
154  label $f.lab -text "Solution Index" -width $labw -anchor w
155  entry $f.ent -textvariable Plot3d(solnum) -width 10
156  checkbutton $f.but -text default \
157    -variable Plot3d(solnum,flag) -onvalue 1 -offvalue 0 \
158    -command "plot3d_state solnum $f.ent"
159  pack $f.lab $f.ent $f.but -side left
160  plot3d_state solnum $f.ent
161
162  FrameCreate $w.format -text "Plot3d File Format" -font $Font(bold)
163  pack $w.format -side top -pady 2 -fill x
164  set fmt [FrameGet $w.format]
165
166  set f [frame $fmt.block]
167  pack $f -side left -expand 1
168  radiobutton $f.m -text "Multi-Block" \
169    -variable Plot3d(block) -value ""
170  radiobutton $f.s -text "Single-Block" \
171    -variable Plot3d(block) -value s
172  pack $f.m $f.s -side top -anchor w
173
174  set f [frame $fmt.format]
175  pack $f -side left -expand 1
176  radiobutton $f.w -text "Whole Format" \
177    -variable Plot3d(format) -value ""
178  radiobutton $f.p -text "Planar Format" \
179    -variable Plot3d(format) -value p
180  pack $f.w $f.p -side top -anchor w
181
182  set f [frame $fmt.iblank]
183  if {$Plot3d(mode) == "import"} {
184    pack $f -side left -expand 1
185  }
186  radiobutton $f.n -text "No iblank" \
187    -variable Plot3d(iblank) -value ""
188  radiobutton $f.y -text "Has iblank" \
189    -variable Plot3d(iblank) -value i
190  pack $f.n $f.y -side top -anchor w
191
192  FrameCreate $w.type -text "Plot3d File Type" -font $Font(bold)
193  pack $w.type -side top -pady 2 -fill x
194  set type [FrameGet $w.type]
195
196  radiobutton $type.b -text binary \
197    -variable Plot3d(type) -value ""
198  radiobutton $type.u -text unformatted \
199    -variable Plot3d(type) -value u
200  radiobutton $type.f -text formatted \
201    -variable Plot3d(type) -value f
202  checkbutton $type.d -text "64-bit" \
203    -variable Plot3d(double) -onvalue d -offvalue ""
204  pack $type.b $type.u $type.f $type.d -side left -expand 1
205
206  FrameCreate $w.mach -text "Plot3d Machine Type" -font $Font(bold)
207  if {$Plot3d(mode) == "import"} {
208    pack $w.mach -side top -pady 2 -fill x
209  }
210  set mach [FrameGet $w.mach]
211
212  set n 1
213  foreach type {\
214    {default IEEE BSIEEE} \
215    {Iris Sun HP} \
216    {Alpha DEC IBM} \
217    {Cray Convex NT}} {
218    set f [frame $mach.f$n]
219    pack $f -side left -expand 1
220    foreach i $type {
221      set j [string tolower $i]
222      radiobutton $f.$j -text $i \
223        -variable Plot3d(mach) -value $j
224      if {$i == "default"} {
225        $f.$j configure -value ""
226      }
227      pack $f.$j -side top -anchor w
228    }
229    incr n
230  }
231
232  FrameCreate $w.opts -text "Options" -font $Font(bold)
233  pack $w.opts -side top -pady 2 -fill x
234  set opts [FrameGet $w.opts]
235
236  set f [frame $opts.f1]
237  pack $f -side left -expand 1
238  if {$Plot3d(mode) == "import"} {
239    checkbutton $f.i -text "Don't use iblank" \
240      -variable Plot3d(ignore) -onvalue n -offvalue ""
241    checkbutton $f.c -text "Write primitive variables" \
242      -variable Plot3d(convert) -onvalue c -offvalue ""
243  } else {
244    checkbutton $f.i -text "Don't write iblank" \
245      -variable Plot3d(ignore) -onvalue n -offvalue ""
246    checkbutton $f.c -text "Use volume weighting" \
247      -variable Plot3d(weight) -onvalue w -offvalue ""
248  }
249  pack $f.i $f.c -side top -anchor w
250
251  set f [frame $opts.gamma]
252  pack $f -side left -expand 1
253  label $f.lab -text gamma
254  entry $f.ent -textvariable Plot3d(gamma) -width 10
255  pack $f.lab $f.ent -side left
256
257  set f [frame $w.but]
258  pack $f -side top -pady 5
259  button $f.accept -text Accept -width 6 -default active \
260    -command "plot3d_check $w"
261  button $f.cancel -text Cancel -width 6 -command {set Plot3d(done) 0}
262  pack $f.accept $f.cancel -side left -padx 5
263
264  bind $w <Return> "plot3d_check $w"
265
266  center_window $w .
267  set oldFocus [focus]
268  set oldGrab [grab current $w]
269  if {$oldGrab != ""} {
270    set grabStatus [grab status $oldGrab]
271  }
272  catch {grab $w}
273  tkwait visibility $w
274  focus $w
275  tkwait variable Plot3d(done)
276  catch {focus $oldFocus}
277  destroy $w
278  if {$oldGrab != ""} {
279    if {$grabStatus == "global"} {
280      grab -global $oldGrab
281    } else {
282      grab $oldGrab
283    }
284  }
285
286  return $Plot3d(done)
287}
288
289proc plot3d_state {what ent {def 1}} {
290  global Plot3d
291  if {$Plot3d($what,flag)} {
292    set Plot3d($what) ""
293    $ent configure -state disabled -cursor {}
294  } else {
295    if {$Plot3d($what) == ""} {
296      set Plot3d($what) $def
297    }
298    $ent configure -state normal -cursor xterm
299  }
300}
301
302proc plot3d_check {w} {
303  global Plot3d
304  if {[string trim $Plot3d(cgns)] == "" ||
305      [string trim $Plot3d(xyz)] == ""} {
306    errormsg "must specify a CGNS and a Plot3d XYZ file" $w
307    return
308  }
309  if {$Plot3d(mode) == "import"} {
310    if {![file exists $Plot3d(xyz)]} {
311      errormsg "Plot3d XYZ file doesn't exist" $w
312      return
313    }
314    if {$Plot3d(q) != "" && ![file exists $Plot3d(q)]} {
315      errormsg "Plot3d Q file doesn't exist" $w
316      return
317    }
318  } else {
319    if {![file exists $Plot3d(cgns)]} {
320      errormsg "CGNS file doesn't exist" $w
321      return
322    }
323  }
324  if {$Plot3d(gamma) != ""} {
325    if {[catch {expr $Plot3d(gamma) <= 1.0} nogood] || $nogood} {
326      errormsg "invalid value for gamma" $w
327      return
328    }
329  }
330  set Plot3d(done) 1
331}
332
333proc plot3d_browse_cgns {w} {
334  global Plot3d tcl_platform
335  if {$Plot3d(mode) == "import"} {
336    set fname [FileSave "CGNS Output File" $Plot3d(cgns) $w \
337      {{{CGNS Files} {.cgns .cgn .adf}} {{All Files} {*}}} cgns]
338  } else {
339    set fname [FileOpen "CGNS Input File" $Plot3d(cgns) $w \
340      {{{CGNS Files} {.cgns .cgn .adf}} {{All Files} {*}}}]
341  }
342  if {$fname != ""} {
343    if {$tcl_platform(platform) == "windows"} {
344      set Plot3d(cgns) [join [split $fname /] \\]
345    } else {
346      set Plot3d(cgns) $fname
347    }
348  }
349}
350
351proc plot3d_browse_xyz {w} {
352  global Plot3d tcl_platform
353  if {$Plot3d(mode) == "import"} {
354    set fname [FileOpen "Plot3d XYZ Input File" $Plot3d(xyz) $w \
355      {{{Plot3d Files} {.bin .dat .fmt .xyz}} {{All Files} {*}}}]
356  } else {
357    set fname [FileSave "Plot3d XYZ Output File" $Plot3d(xyz) $w \
358      {{{Plot3d Files} {.bin .dat .fmt .xyz}} {{All Files} {*}}}]
359  }
360  if {$fname != ""} {
361    if {$tcl_platform(platform) == "windows"} {
362      set Plot3d(xyz) [join [split $fname /] \\]
363    } else {
364      set Plot3d(xyz) $fname
365    }
366  }
367}
368
369proc plot3d_browse_q {w} {
370  global Plot3d tcl_platform
371  if {$Plot3d(mode) == "import"} {
372    set fname [FileOpen "Plot3d Q Input File" $Plot3d(q) $w \
373      {{{Plot3d Files} {.bin .dat .fmt .q}} {{All Files} {*}}}]
374  } else {
375    set fname [FileSave "Plot3d Q Output File" $Plot3d(q) $w \
376      {{{Plot3d Files} {.bin .dat .fmt .q}} {{All Files} {*}}}]
377  }
378  if {$fname != ""} {
379    if {$tcl_platform(platform) == "windows"} {
380      set Plot3d(q) [join [split $fname /] \\]
381    } else {
382      set Plot3d(q) $fname
383    }
384  }
385}
386
387