| 1 |
#bltdebug 100 |
| 2 |
|
| 3 |
array set cursors { |
| 4 |
w left_side |
| 5 |
e right_side |
| 6 |
n top_side |
| 7 |
s bottom_side |
| 8 |
sw bottom_left_corner |
| 9 |
ne top_right_corner |
| 10 |
se bottom_right_corner |
| 11 |
nw top_left_corner |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
array set pageInfo { |
| 16 |
gripSize 8 |
| 17 |
scale 0.25 |
| 18 |
radioFont -*-helvetica-medium-r-*-*-11-120-*-*-*-*-*-* |
| 19 |
labelFont -*-helvetica-bold-r-*-*-12-120-*-*-*-*-*-* |
| 20 |
printCmd "nlp -d2a211" |
| 21 |
printFile "out.ps" |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
proc SetUnits { units } { |
| 26 |
global pageInfo |
| 27 |
switch -glob $units { |
| 28 |
"i*" { set pageInfo(uscale) [winfo fpixels . 1i] } |
| 29 |
"c*" { set pageInfo(uscale) [winfo fpixels . 1c] } |
| 30 |
default { error "unknown unit \"$units\"" } |
| 31 |
} |
| 32 |
set pageInfo(units) [string index $units 0] |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
proc ConvertUnits { value } { |
| 37 |
global pageInfo |
| 38 |
set value [expr double($value) / $pageInfo(uscale)] |
| 39 |
return [format "%.1f%s" $value $pageInfo(units)] |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
proc SetPaperSize { unit } { |
| 44 |
global pageInfo |
| 45 |
SetUnits $unit |
| 46 |
set pageInfo(-paperwidth) [lindex $pageInfo(paperSize) 0] |
| 47 |
set pageInfo(-paperheight) [lindex $pageInfo(paperSize) 1] |
| 48 |
ApplyPs |
| 49 |
} |
| 50 |
|
| 51 |
proc SetCanvasSize { canvas width height } { |
| 52 |
global pageInfo |
| 53 |
|
| 54 |
set width [winfo pixels . $width] |
| 55 |
set height [winfo pixels . $height] |
| 56 |
$canvas configure -width $width -height $height |
| 57 |
} |
| 58 |
|
| 59 |
proc SetCanvasOrientation { canvas } { |
| 60 |
global pageInfo |
| 61 |
set width $pageInfo(paperWidth) |
| 62 |
set height $pageInfo(paperHeight) |
| 63 |
SetCanvasSize $canvas $width $height |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
proc GetPsOptions { graph } { |
| 68 |
global pageInfo |
| 69 |
|
| 70 |
foreach opt [$graph postscript configure] { |
| 71 |
set pageInfo([lindex $opt 0]) [lindex $opt 4] |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
proc SetOutline { canvas } { |
| 76 |
global pageInfo |
| 77 |
foreach var { gripSize xMin yMin xMax yMax } { |
| 78 |
set $var $pageInfo($var) |
| 79 |
} |
| 80 |
set xMid [expr ($xMax + $xMin - $gripSize) * 0.5] |
| 81 |
set yMid [expr ($yMax + $yMin - $gripSize) * 0.5] |
| 82 |
$canvas coords image $xMin $yMin |
| 83 |
$canvas itemconfigure image \ |
| 84 |
-width [expr $xMax - $xMin] -height [expr $yMax - $yMin] |
| 85 |
$canvas coords nw \ |
| 86 |
$xMin $yMin [expr $xMin + $gripSize] [expr $yMin + $gripSize] |
| 87 |
$canvas coords se \ |
| 88 |
[expr $xMax - $gripSize] [expr $yMax - $gripSize] $xMax $yMax |
| 89 |
$canvas coords ne \ |
| 90 |
[expr $xMax - $gripSize] [expr $yMin + $gripSize] $xMax $yMin |
| 91 |
$canvas coords sw \ |
| 92 |
$xMin $yMax [expr $xMin + $gripSize] [expr $yMax - $gripSize] |
| 93 |
SetCanvasOrientation $canvas |
| 94 |
$canvas coords n \ |
| 95 |
$xMid $yMin [expr $xMid + $gripSize] [expr $yMin + $gripSize] |
| 96 |
$canvas coords s \ |
| 97 |
$xMid [expr $yMax - $gripSize] [expr $xMid + $gripSize] $yMax |
| 98 |
$canvas coords e \ |
| 99 |
[expr $xMax - $gripSize] $yMid $xMax [expr $yMid + $gripSize] |
| 100 |
$canvas coords w \ |
| 101 |
$xMin $yMid [expr $xMin + $gripSize] [expr $yMid + $gripSize] |
| 102 |
} |
| 103 |
|
| 104 |
proc CreateOutline { canvas } { |
| 105 |
global pageInfo |
| 106 |
foreach var { gripSize xMin yMin xMax yMax } { |
| 107 |
set $var $pageInfo($var) |
| 108 |
} |
| 109 |
if { ![bitmap exists pattern8] } { |
| 110 |
bitmap define pattern8 { {8 8} {ff 00 ff 00 ff 00 ff 00 } } |
| 111 |
} |
| 112 |
$canvas create eps $xMin $yMin \ |
| 113 |
-tags "outline image" \ |
| 114 |
-width [expr $xMax - $xMin] \ |
| 115 |
-height [expr $yMax - $yMin] |
| 116 |
|
| 117 |
$canvas bind image <ButtonPress-1> "StartMove $canvas %x %y" |
| 118 |
$canvas bind image <B1-Motion> "MoveOutline $canvas %x %y" |
| 119 |
$canvas bind image <ButtonRelease-1> "EndMove $canvas" |
| 120 |
|
| 121 |
$canvas bind image <Shift-B1-Motion> "ConstrainMoveOutline $canvas %x %y" |
| 122 |
$canvas bind image <Enter> "EnterImage $canvas" |
| 123 |
$canvas bind image <Leave> "LeaveImage $canvas" |
| 124 |
focus $canvas |
| 125 |
$canvas create rectangle \ |
| 126 |
$xMin $yMin [expr $xMin + $gripSize] [expr $yMin + $gripSize] \ |
| 127 |
-tags "outline grip nw" |
| 128 |
$canvas create rectangle \ |
| 129 |
[expr $xMax - $gripSize] [expr $yMax - $gripSize] $xMax $yMax \ |
| 130 |
-tags "outline grip se" |
| 131 |
$canvas create rectangle \ |
| 132 |
[expr $xMax - $gripSize] [expr $yMin + $gripSize] $xMax $yMin \ |
| 133 |
-tags "outline grip ne" |
| 134 |
$canvas create rectangle \ |
| 135 |
$xMin $yMax [expr $xMin + $gripSize] [expr $yMax - $gripSize] \ |
| 136 |
-tags "outline grip sw" |
| 137 |
|
| 138 |
set xMid [expr ($xMax + $xMin - $gripSize) * 0.5] |
| 139 |
set yMid [expr ($yMax + $yMin - $gripSize) * 0.5] |
| 140 |
$canvas create rectangle \ |
| 141 |
$xMid $yMin [expr $xMid + $gripSize] [expr $yMin + $gripSize] \ |
| 142 |
-tags "outline grip n" |
| 143 |
$canvas create rectangle \ |
| 144 |
$xMid [expr $yMax - $gripSize] [expr $xMid + $gripSize] $yMax \ |
| 145 |
-tags "outline grip s" |
| 146 |
$canvas create rectangle \ |
| 147 |
[expr $xMax - $gripSize] $yMid $xMax [expr $yMid + $gripSize] \ |
| 148 |
-tags "outline grip e" |
| 149 |
$canvas create rectangle \ |
| 150 |
$xMin $yMid [expr $xMin + $gripSize] [expr $yMid + $gripSize] \ |
| 151 |
-tags "outline grip w" |
| 152 |
foreach grip { e w s n sw ne se nw } { |
| 153 |
$canvas bind $grip <ButtonPress-1> "StartResize %W $grip %x %y" |
| 154 |
$canvas bind $grip <B1-Motion> "ResizeOutline %W %x %y" |
| 155 |
$canvas bind $grip <ButtonRelease-1> "EndResize %W $grip %x %y" |
| 156 |
$canvas bind $grip <Enter> "EnterGrip %W $grip %x %y" |
| 157 |
$canvas bind $grip <Leave> "LeaveGrip %W $grip" |
| 158 |
} |
| 159 |
$canvas raise grip |
| 160 |
$canvas itemconfigure grip -fill red -outline black |
| 161 |
|
| 162 |
set pageInfo(image) [image create photo] |
| 163 |
$pageInfo(graph) snap $pageInfo(image) |
| 164 |
$canvas itemconfigure image -image $pageInfo(image) |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
proc EnterImage { canvas } { |
| 169 |
global cursors |
| 170 |
global pageInfo |
| 171 |
bind $canvas <KeyPress-Left> { |
| 172 |
MoveOutline %W [expr $pageInfo(lastX) - 1] $pageInfo(lastY) |
| 173 |
} |
| 174 |
bind $canvas <KeyPress-Right> { |
| 175 |
MoveOutline %W [expr $pageInfo(lastX) + 1] $pageInfo(lastY) |
| 176 |
} |
| 177 |
bind $canvas <KeyPress-Up> { |
| 178 |
MoveOutline %W $pageInfo(lastX) [expr $pageInfo(lastY) - 1] |
| 179 |
} |
| 180 |
bind $canvas <KeyPress-Down> { |
| 181 |
MoveOutline %W $pageInfo(lastX) [expr $pageInfo(lastY) + 1] |
| 182 |
} |
| 183 |
focus $canvas |
| 184 |
$canvas configure -cursor fleur |
| 185 |
set pageInfo(lastX) 0 |
| 186 |
set pageInfo(lastY) 0 |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
proc LeaveImage { canvas } { |
| 191 |
bind $canvas <KeyPress-Left> "" |
| 192 |
bind $canvas <KeyPress-Right> "" |
| 193 |
bind $canvas <KeyPress-Up> "" |
| 194 |
bind $canvas <KeyPress-Down> "" |
| 195 |
$canvas configure -cursor "" |
| 196 |
} |
| 197 |
|
| 198 |
proc EnterGrip { canvas grip x y } { |
| 199 |
global pageInfo |
| 200 |
$canvas itemconfigure $grip -fill blue -outline black |
| 201 |
set pageInfo(grip) $grip |
| 202 |
global cursors |
| 203 |
bind $canvas <KeyPress-Left> { |
| 204 |
ResizeOutline %W [expr $pageInfo(lastX) - 1] $pageInfo(lastY) |
| 205 |
} |
| 206 |
bind $canvas <KeyPress-Right> { |
| 207 |
ResizeOutline %W [expr $pageInfo(lastX) + 1] $pageInfo(lastY) |
| 208 |
} |
| 209 |
bind $canvas <KeyPress-Up> { |
| 210 |
ResizeOutline %W $pageInfo(lastX) [expr $pageInfo(lastY) - 1] |
| 211 |
} |
| 212 |
bind $canvas <KeyPress-Down> { |
| 213 |
ResizeOutline %W $pageInfo(lastX) [expr $pageInfo(lastY) + 1] |
| 214 |
} |
| 215 |
focus $canvas |
| 216 |
$canvas configure -cursor $cursors($grip) |
| 217 |
set pageInfo(lastX) $x |
| 218 |
set pageInfo(lastY) $y |
| 219 |
} |
| 220 |
|
| 221 |
proc LeaveGrip { canvas grip } { |
| 222 |
$canvas itemconfigure $grip -fill red -outline black |
| 223 |
bind $canvas <KeyPress-Left> "" |
| 224 |
bind $canvas <KeyPress-Right> "" |
| 225 |
bind $canvas <KeyPress-Up> "" |
| 226 |
bind $canvas <KeyPress-Down> "" |
| 227 |
$canvas configure -cursor "" |
| 228 |
} |
| 229 |
|
| 230 |
proc StartMove { canvas x y } { |
| 231 |
global pageInfo |
| 232 |
set pageInfo(lastX) $x |
| 233 |
set pageInfo(lastY) $y |
| 234 |
set pageInfo(direction) "undecided" |
| 235 |
$canvas configure -cursor fleur |
| 236 |
} |
| 237 |
|
| 238 |
proc MoveOutline { canvas x y } { |
| 239 |
global pageInfo |
| 240 |
$canvas move outline [expr $x - $pageInfo(lastX)] [expr $y - $pageInfo(lastY)] |
| 241 |
set pageInfo(lastX) $x |
| 242 |
set pageInfo(lastY) $y |
| 243 |
} |
| 244 |
|
| 245 |
proc ConstrainMoveOutline { canvas x y } { |
| 246 |
global pageInfo |
| 247 |
|
| 248 |
set dx [expr $x - $pageInfo(lastX)] |
| 249 |
set dy [expr $y - $pageInfo(lastY)] |
| 250 |
|
| 251 |
if { $pageInfo(direction) == "undecided" } { |
| 252 |
if { abs($dx) > abs($dy) } { |
| 253 |
set pageInfo(direction) x |
| 254 |
$canvas configure -cursor sb_h_double_arrow |
| 255 |
} else { |
| 256 |
set pageInfo(direction) y |
| 257 |
$canvas configure -cursor sb_v_double_arrow |
| 258 |
} |
| 259 |
} |
| 260 |
switch $pageInfo(direction) { |
| 261 |
x { set dy 0 ; set pageInfo(lastX) $x } |
| 262 |
y { set dx 0 ; set pageInfo(lastY) $y } |
| 263 |
} |
| 264 |
$canvas move outline $dx $dy |
| 265 |
} |
| 266 |
|
| 267 |
proc EndMove { canvas } { |
| 268 |
$canvas configure -cursor "" |
| 269 |
|
| 270 |
set coords [$canvas coords image] |
| 271 |
set x [lindex $coords 0] |
| 272 |
set y [lindex $coords 1] |
| 273 |
set w [$canvas itemcget image -width] |
| 274 |
set h [$canvas itemcget image -height] |
| 275 |
|
| 276 |
global pageInfo |
| 277 |
set pageInfo(xMin) $x |
| 278 |
set pageInfo(xMin) $y |
| 279 |
set pageInfo(xMax) [expr $x + $w] |
| 280 |
set pageInfo(yMax) [expr $y + $h] |
| 281 |
|
| 282 |
global pageInfo |
| 283 |
set pageInfo(-padx) [list $pageInfo(xMin) [expr $pageInfo(paperWidth) - $pageInfo(xMax)]] |
| 284 |
set pageInfo(-pady) [list $pageInfo(yMin) [expr $pageInfo(paperHeight) - $pageInfo(yMax)]] |
| 285 |
} |
| 286 |
|
| 287 |
proc StartResize { canvas grip x y } { |
| 288 |
global pageInfo |
| 289 |
$canvas itemconfigure image -quick yes |
| 290 |
set pageInfo(grip) $grip |
| 291 |
$canvas itemconfigure $grip -fill red -outline black |
| 292 |
$canvas raise grip |
| 293 |
global cursors |
| 294 |
$canvas configure -cursor $cursors($grip) |
| 295 |
set pageInfo(lastX) $x |
| 296 |
set pageInfo(lastY) $y |
| 297 |
} |
| 298 |
|
| 299 |
proc EndResize { canvas grip x y } { |
| 300 |
$canvas itemconfigure image -quick no |
| 301 |
ResizeOutline $canvas $x $y |
| 302 |
$canvas itemconfigure $grip -fill "" -outline "" |
| 303 |
$canvas configure -cursor "" |
| 304 |
} |
| 305 |
|
| 306 |
proc ResizeOutline { canvas x y } { |
| 307 |
global pageInfo |
| 308 |
|
| 309 |
foreach var { gripSize xMin yMin xMax yMax } { |
| 310 |
set $var $pageInfo($var) |
| 311 |
} |
| 312 |
switch $pageInfo(grip) { |
| 313 |
n { |
| 314 |
set yMin $y |
| 315 |
} |
| 316 |
s { |
| 317 |
set yMax $y |
| 318 |
} |
| 319 |
e { |
| 320 |
set xMax $x |
| 321 |
} |
| 322 |
w { |
| 323 |
set xMin $x |
| 324 |
} |
| 325 |
sw { |
| 326 |
set xMin $x ; set yMax $y |
| 327 |
} |
| 328 |
ne { |
| 329 |
set xMax $x ; set yMin $y |
| 330 |
} |
| 331 |
se { |
| 332 |
set xMax $x ; set yMax $y |
| 333 |
} |
| 334 |
nw { |
| 335 |
set xMin $x ; set yMin $y |
| 336 |
} |
| 337 |
} |
| 338 |
set width [expr $xMax - $xMin] |
| 339 |
set height [expr $yMax - $yMin] |
| 340 |
if { ($width < 1) || ($height < 1) } { |
| 341 |
return |
| 342 |
} |
| 343 |
SetOutline $canvas |
| 344 |
foreach var { xMin yMin xMax yMax } { |
| 345 |
set pageInfo($var) [set $var] |
| 346 |
} |
| 347 |
} |
| 348 |
|
| 349 |
proc ComputePlotGeometry { graph } { |
| 350 |
global pageInfo |
| 351 |
|
| 352 |
GetPsOptions $graph |
| 353 |
set width [winfo width $graph] |
| 354 |
set height [winfo height $graph] |
| 355 |
if { $pageInfo(-width) > 0 } { |
| 356 |
set width $pageInfo(-width) |
| 357 |
} |
| 358 |
if { $pageInfo(-height) > 0 } { |
| 359 |
set height $pageInfo(-height) |
| 360 |
} |
| 361 |
|
| 362 |
set left [lindex $pageInfo(-padx) 0] |
| 363 |
set right [lindex $pageInfo(-padx) 1] |
| 364 |
set top [lindex $pageInfo(-pady) 0] |
| 365 |
set bottom [lindex $pageInfo(-pady) 1] |
| 366 |
set padx [expr $left + $right] |
| 367 |
set pady [expr $top + $bottom] |
| 368 |
|
| 369 |
if { $pageInfo(-paperwidth) > 0 } { |
| 370 |
set paperWidth $pageInfo(-paperwidth) |
| 371 |
} else { |
| 372 |
set paperWidth [expr $width + $padx] |
| 373 |
} |
| 374 |
if { $pageInfo(-paperheight) > 0 } { |
| 375 |
set paperHeight $pageInfo(-paperheight) |
| 376 |
} else { |
| 377 |
set paperHeight [expr $height + $pady] |
| 378 |
} |
| 379 |
if { $pageInfo(-landscape) } { |
| 380 |
set temp $paperWidth |
| 381 |
set paperWidth $paperHeight |
| 382 |
set paperHeight $temp |
| 383 |
} |
| 384 |
|
| 385 |
set scale 1.0 |
| 386 |
if { $pageInfo(-maxpect) } { |
| 387 |
set xScale [expr ($paperWidth - $padx) / double($width)] |
| 388 |
set yScale [expr ($paperHeight - $pady) / double($height)] |
| 389 |
set scale [expr min($xScale,$yScale)] |
| 390 |
set bboxWidth [expr round($width * $scale)] |
| 391 |
set bboxHeight [expr round($height * $scale)] |
| 392 |
} else { |
| 393 |
if { ($width + $padx) > $paperWidth } { |
| 394 |
set width [expr $paperWidth - $padx] |
| 395 |
} |
| 396 |
if { ($height + $pady) > $paperHeight } { |
| 397 |
set height [expr $paperHeight - $pady] |
| 398 |
} |
| 399 |
set bboxWidth $width |
| 400 |
set bboxHeight $height |
| 401 |
} |
| 402 |
set x $left |
| 403 |
set y $top |
| 404 |
if { $pageInfo(-center) } { |
| 405 |
if { $paperWidth > $bboxWidth } { |
| 406 |
set x [expr ($paperWidth - $bboxWidth) / 2] |
| 407 |
} |
| 408 |
if { $paperHeight > $bboxHeight } { |
| 409 |
set y [expr ($paperHeight - $bboxHeight) / 2] |
| 410 |
} |
| 411 |
} |
| 412 |
set pageInfo(xMin) [expr $x * $pageInfo(scale)] |
| 413 |
set pageInfo(yMin) [expr $y * $pageInfo(scale)] |
| 414 |
set pageInfo(xMax) [expr ($x + $bboxWidth) * $pageInfo(scale)] |
| 415 |
set pageInfo(yMax) [expr ($y + $bboxHeight) * $pageInfo(scale)] |
| 416 |
set pageInfo(paperHeight) [expr $paperHeight * $pageInfo(scale)] |
| 417 |
set pageInfo(paperWidth) [expr $paperWidth * $pageInfo(scale)] |
| 418 |
} |
| 419 |
|
| 420 |
proc PsDialog { graph } { |
| 421 |
global pageInfo |
| 422 |
|
| 423 |
set pageInfo(graph) $graph |
| 424 |
set top $graph.top |
| 425 |
toplevel $top |
| 426 |
option add *graph.top*Radiobutton.font $pageInfo(radioFont) |
| 427 |
GetPsOptions $graph |
| 428 |
ComputePlotGeometry $graph |
| 429 |
set canvas $top.layout |
| 430 |
canvas $canvas -confine yes \ |
| 431 |
-width $pageInfo(paperWidth) -height $pageInfo(paperHeight) -bg gray \ |
| 432 |
-bd 2 -relief sunken |
| 433 |
CreateOutline $canvas |
| 434 |
SetCanvasOrientation $canvas |
| 435 |
label $top.titleLabel -text "PostScript Options" |
| 436 |
table $top \ |
| 437 |
0,0 $top.titleLabel -cspan 7 \ |
| 438 |
1,0 $canvas -cspan 7 |
| 439 |
|
| 440 |
set row 2 |
| 441 |
set col 0 |
| 442 |
label $top.paperLabel -text "Paper" |
| 443 |
radiobutton $top.letter -text "Letter 8 1/2 x 11 in." -value "8.5i 11i" \ |
| 444 |
-variable pageInfo(paperSize) \ |
| 445 |
-command "SetPaperSize i" |
| 446 |
radiobutton $top.a3 -text "A3 29.7 x 42 cm." -value "28.7c 41c" \ |
| 447 |
-variable pageInfo(paperSize) \ |
| 448 |
-command "SetPaperSize c" |
| 449 |
radiobutton $top.a4 -text "A4 21 x 29.7 cm." -value "21c 29.7c" \ |
| 450 |
-variable pageInfo(paperSize) \ |
| 451 |
-command "SetPaperSize c" |
| 452 |
radiobutton $top.a5 -text "A5 14.85 x 21 cm." -value "14.85c 21c" \ |
| 453 |
-variable pageInfo(paperSize) \ |
| 454 |
-command "SetPaperSize c" |
| 455 |
radiobutton $top.legal -text "Legal 8 1/2 x 14 in." -value "8.5i 14i" \ |
| 456 |
-variable pageInfo(paperSize) \ |
| 457 |
-command "SetPaperSize i" |
| 458 |
radiobutton $top.large -text "Large 11 x 17 in." -value "11i 17i" \ |
| 459 |
-variable pageInfo(paperSize) \ |
| 460 |
-command "SetPaperSize i" |
| 461 |
table configure $top r$row -pady { 4 0 } |
| 462 |
table $top \ |
| 463 |
$row,$col $top.paperLabel -anchor e \ |
| 464 |
$row+0,$col+1 $top.letter -anchor w \ |
| 465 |
$row+1,$col+1 $top.legal -anchor w \ |
| 466 |
$row+2,$col+1 $top.large -anchor w \ |
| 467 |
$row+0,$col+2 $top.a3 -anchor w \ |
| 468 |
$row+1,$col+2 $top.a4 -anchor w \ |
| 469 |
$row+2,$col+2 $top.a5 -anchor w |
| 470 |
|
| 471 |
incr row 3 |
| 472 |
|
| 473 |
label $top.orientLabel -text "Orientation" |
| 474 |
radiobutton $top.portrait -text "Portrait" -value "0" \ |
| 475 |
-variable pageInfo(-landscape) -command "ApplyPs" |
| 476 |
radiobutton $top.landscape -text "Landscape" -value "1" \ |
| 477 |
-variable pageInfo(-landscape) -command "ApplyPs" |
| 478 |
table configure $top r$row -pady { 4 0 } |
| 479 |
table $top \ |
| 480 |
$row,$col+0 $top.orientLabel -anchor e \ |
| 481 |
$row,$col+1 $top.portrait -anchor w \ |
| 482 |
$row,$col+2 $top.landscape -anchor w |
| 483 |
|
| 484 |
incr row 6 |
| 485 |
|
| 486 |
set col 0 |
| 487 |
label $top.plotLabel -text "Plot Options" |
| 488 |
table $top \ |
| 489 |
$row,$col $top.plotLabel -cspan 3 |
| 490 |
incr row |
| 491 |
label $top.sizeLabel -text "Size" |
| 492 |
radiobutton $top.default -text "Default" -value "default" \ |
| 493 |
-variable pageInfo(plotSize) \ |
| 494 |
-command "SetPlotSize" |
| 495 |
radiobutton $top.maxpect -text "Max Aspect" -value "maxpect" \ |
| 496 |
-variable pageInfo(plotSize) \ |
| 497 |
-command "SetPlotSize" |
| 498 |
radiobutton $top.resize -text "Resize" -value "resize" \ |
| 499 |
-variable pageInfo(plotSize) \ |
| 500 |
-command "SizeDialog $graph {Adjust Plot Size}" |
| 501 |
table configure $top r$row -pady { 4 0 } |
| 502 |
table $top \ |
| 503 |
$row,$col $top.sizeLabel -anchor e \ |
| 504 |
$row,$col+1 $top.default -anchor w \ |
| 505 |
$row+1,$col+1 $top.maxpect -anchor w \ |
| 506 |
$row+2,$col+1 $top.resize -anchor w |
| 507 |
|
| 508 |
#incr row 4 |
| 509 |
|
| 510 |
set pageInfo(oldPadX) $pageInfo(-padx) |
| 511 |
set pageInfo(oldPadY) $pageInfo(-pady) |
| 512 |
|
| 513 |
label $top.posLabel -text "Position" |
| 514 |
set pageInfo(position) $pageInfo(-center) |
| 515 |
radiobutton $top.center -text "Center" -value "1" \ |
| 516 |
-variable pageInfo(position) -command { |
| 517 |
set pageInfo(-center) 1 |
| 518 |
CenterPlot |
| 519 |
} |
| 520 |
radiobutton $top.origin -text "Origin" -value "0" \ |
| 521 |
-variable pageInfo(position) -command { |
| 522 |
set pageInfo(-center) 0 |
| 523 |
ApplyPs |
| 524 |
} |
| 525 |
radiobutton $top.move -text "Move" -value "move" \ |
| 526 |
-variable pageInfo(position) -command { |
| 527 |
set pageInfo(-center) 0 |
| 528 |
MoveDialog |
| 529 |
} |
| 530 |
table configure $top r$row -pady { 4 0 } |
| 531 |
table $top \ |
| 532 |
$row,$col+2 $top.posLabel -anchor e \ |
| 533 |
$row,$col+3 $top.center -anchor w \ |
| 534 |
$row+1,$col+3 $top.origin -anchor w \ |
| 535 |
$row+2,$col+3 $top.move -anchor w |
| 536 |
|
| 537 |
incr row 4 |
| 538 |
label $top.printLabel -text "Print To" |
| 539 |
radiobutton $top.toFile -text "File" -value "printFile" \ |
| 540 |
-variable pageInfo(printTo) -command " |
| 541 |
$top.fileEntry configure -textvariable pageInfo(printFile) |
| 542 |
" |
| 543 |
radiobutton $top.toCmd -text "Command" -value "printCmd" \ |
| 544 |
-variable pageInfo(printTo) -command " |
| 545 |
$top.fileEntry configure -textvariable pageInfo(printCmd) |
| 546 |
" |
| 547 |
entry $top.fileEntry |
| 548 |
table configure $top r$row -pady { 4 0 } |
| 549 |
table configure $top r[expr $row+1] -pady { 4 0 } |
| 550 |
table configure $top r[expr $row+2] -pady { 4 0 } |
| 551 |
table $top \ |
| 552 |
$row,0 $top.printLabel -anchor e \ |
| 553 |
$row,1 $top.toFile -anchor w \ |
| 554 |
$row+1,1 $top.toCmd -anchor w \ |
| 555 |
$row+2,1 $top.fileEntry -anchor w -fill x -cspan 3 |
| 556 |
$top.toFile invoke |
| 557 |
incr row 3 |
| 558 |
#table configure $top c4 -width .125i |
| 559 |
button $top.cancel -text "Cancel" -command "destroy $top" |
| 560 |
button $top.print -text "Done" -command "PrintPs $graph" |
| 561 |
button $top.advanced -text "Options" -command "MarginDialog $graph" |
| 562 |
table $top \ |
| 563 |
$row,1 $top.print -width 1i -pady 2 \ |
| 564 |
$row,2 $top.advanced -width 1i -pady 2 \ |
| 565 |
$row,3 $top.cancel -width 1i -pady 2 -anchor w |
| 566 |
|
| 567 |
SetUnits "inches" |
| 568 |
foreach label [info commands $top.*Label] { |
| 569 |
$label configure -font $pageInfo(labelFont) -padx 4 |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
proc PrintPs { graph } { |
| 574 |
$graph postscript output "out.ps" |
| 575 |
puts stdout "wrote file \"out.ps\"." |
| 576 |
flush stdout |
| 577 |
} |
| 578 |
|
| 579 |
proc ApplyPs { } { |
| 580 |
global pageInfo |
| 581 |
|
| 582 |
set graph $pageInfo(graph) |
| 583 |
foreach option [$graph postscript configure] { |
| 584 |
set var [lindex $option 0] |
| 585 |
set old [lindex $option 4] |
| 586 |
if { [catch {$graph postscript configure $var $pageInfo($var)}] != 0 } { |
| 587 |
$graph postscript configure $var $old |
| 588 |
set pageInfo($var) $old |
| 589 |
} |
| 590 |
} |
| 591 |
ComputePlotGeometry $graph |
| 592 |
foreach var { -paperheight -paperwidth -width -height } { |
| 593 |
set pageInfo($var) [ConvertUnits $pageInfo($var)] |
| 594 |
} |
| 595 |
SetOutline $graph.top.layout |
| 596 |
} |
| 597 |
|
| 598 |
proc StartChange { w delta } { |
| 599 |
ChangeSize $w $delta |
| 600 |
global pageInfo |
| 601 |
set pageInfo(afterId) [after 300 RepeatChange $w $delta] |
| 602 |
} |
| 603 |
|
| 604 |
proc RepeatChange { w delta } { |
| 605 |
ChangeSize $w $delta |
| 606 |
global pageInfo |
| 607 |
set pageInfo(afterId) [after 100 RepeatChange $w $delta] |
| 608 |
} |
| 609 |
|
| 610 |
proc EndChange { w } { |
| 611 |
global pageInfo |
| 612 |
after cancel $pageInfo(afterId) |
| 613 |
} |
| 614 |
|
| 615 |
proc ChangeSize { w delta } { |
| 616 |
set f [winfo parent $w] |
| 617 |
set value [$f.entry get] |
| 618 |
set value [expr $value + $delta] |
| 619 |
if { $value < 0 } { |
| 620 |
set value 1 |
| 621 |
} |
| 622 |
$f.entry delete 0 end |
| 623 |
$f.entry insert 0 $value |
| 624 |
} |
| 625 |
|
| 626 |
proc MakeSizeAdjustor { w label var } { |
| 627 |
frame $w |
| 628 |
label $w.label -text $label |
| 629 |
button $w.plus -text "+" -padx 1 -pady 0 -font \*symbol\* |
| 630 |
entry $w.entry -width 6 -textvariable "pageInfo($var)" |
| 631 |
button $w.minus -text "-" -padx 1 -pady 0 -font \*symbol\* |
| 632 |
label $w.units -text "in" |
| 633 |
bind $w.plus <ButtonPress-1> { StartChange %W 0.1} |
| 634 |
bind $w.plus <ButtonRelease-1> { EndChange %W } |
| 635 |
bind $w.minus <ButtonPress-1> { StartChange %W -0.1} |
| 636 |
bind $w.minus <ButtonRelease-1> { EndChange %W } |
| 637 |
table $w \ |
| 638 |
0,1 $w.label \ |
| 639 |
1,1 $w.entry -rspan 2 -fill y \ |
| 640 |
1,0 $w.minus -padx 2 -pady 2 \ |
| 641 |
2,0 $w.plus -padx 2 -pady { 0 2 } \ |
| 642 |
1,2 $w.units -rspan 2 -fill y |
| 643 |
|
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
proc SizeDialog { graph title } { |
| 648 |
global pageInfo |
| 649 |
set top .plotSize |
| 650 |
if { [winfo exists $top] } { |
| 651 |
return |
| 652 |
} |
| 653 |
toplevel $top |
| 654 |
label $top.title -text $title |
| 655 |
button $top.cancel -text "Cancel" -command "destroy $top" |
| 656 |
button $top.ok -text "Ok" -command "ApplyPs; destroy $top" |
| 657 |
MakeSizeAdjustor $top.plotWidth "Width" -width |
| 658 |
MakeSizeAdjustor $top.plotHeight "Height" -height |
| 659 |
table $top \ |
| 660 |
0,0 $top.title -cspan 2 \ |
| 661 |
1,0 $top.plotWidth \ |
| 662 |
1,1 $top.plotHeight \ |
| 663 |
2,0 $top.cancel -pady 4 -padx 4 -width 1i \ |
| 664 |
2,1 $top.ok -pady 4 -padx 4 -width 1i |
| 665 |
set width [winfo fpixels . $pageInfo(-width)] |
| 666 |
set height [winfo fpixels . $pageInfo(-height)] |
| 667 |
if { $width == 0 } { |
| 668 |
set width [expr ($pageInfo(xMax) - $pageInfo(xMin)) / $pageInfo(scale)] |
| 669 |
set pageInfo(-width) [ConvertUnits $width] |
| 670 |
} |
| 671 |
if { $height == 0 } { |
| 672 |
set height [expr ($pageInfo(yMax) - $pageInfo(yMin)) / $pageInfo(scale)] |
| 673 |
set pageInfo(-height) [ConvertUnits $height] |
| 674 |
} |
| 675 |
set pageInfo(-maxpect) 0 |
| 676 |
} |
| 677 |
|
| 678 |
proc SetPlotSize { } { |
| 679 |
global pageInfo |
| 680 |
set graph $pageInfo(graph) |
| 681 |
switch $pageInfo(plotSize) { |
| 682 |
default { |
| 683 |
set pageInfo(-width) 0 |
| 684 |
set pageInfo(-height) 0 |
| 685 |
set pageInfo(-maxpect) 0 |
| 686 |
set pageInfo(-padx) $pageInfo(oldPadX) |
| 687 |
set pageInfo(-pady) $pageInfo(oldPadY) |
| 688 |
} maxpect { |
| 689 |
set pageInfo(-width) 0 |
| 690 |
set pageInfo(-height) 0 |
| 691 |
set pageInfo(-maxpect) 1 |
| 692 |
set pageInfo(-padx) $pageInfo(oldPadX) |
| 693 |
set pageInfo(-pady) $pageInfo(oldPadY) |
| 694 |
} resize { |
| 695 |
set pageInfo(-maxpect) 0 |
| 696 |
} |
| 697 |
} |
| 698 |
ApplyPs |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
proc PaperSizeDialog { title } { |
| 703 |
set top .paperSize |
| 704 |
if { [winfo exists $top] } { |
| 705 |
return |
| 706 |
} |
| 707 |
toplevel $top |
| 708 |
label $top.title -text $title |
| 709 |
MakeSizeAdjustor $top.width "Width" -paperwidth |
| 710 |
MakeSizeAdjustor $top.height "Height" -paperheight |
| 711 |
button $top.cancel -text "Cancel" -command "destroy $top" |
| 712 |
button $top.ok -text "Ok" -command "ApplyPs; destroy $top" |
| 713 |
table $top \ |
| 714 |
0,0 $top.title -cspan 2 \ |
| 715 |
1,0 $top.width \ |
| 716 |
1,1 $top.height \ |
| 717 |
2,0 $top.cancel -pady 4 -padx 4 -width 1i \ |
| 718 |
2,1 $top.ok -pady 4 -padx 4 -width 1i |
| 719 |
} |
| 720 |
|
| 721 |
proc MarginDialog { graph } { |
| 722 |
set top $graph.top.options |
| 723 |
if { [winfo exists $top] } { |
| 724 |
return |
| 725 |
} |
| 726 |
toplevel $top |
| 727 |
set row 0 |
| 728 |
set col 0 |
| 729 |
label $top.modeLabel -text "Printer" |
| 730 |
radiobutton $top.color -text "Color" -value "color" \ |
| 731 |
-variable pageInfo(-colormode) -command "ApplyPs" |
| 732 |
radiobutton $top.greyscale -text "Greyscale" -value "greyscale" \ |
| 733 |
-variable pageInfo(-colormode) -command "ApplyPs" |
| 734 |
table $top \ |
| 735 |
$row,$col $top.modeLabel -anchor e \ |
| 736 |
$row,$col+1 $top.color -anchor w \ |
| 737 |
$row+1,$col+1 $top.greyscale -anchor w |
| 738 |
|
| 739 |
table configure $top r$row -pady { 4 0 } |
| 740 |
|
| 741 |
label $top.previewLabel -text "Preview" |
| 742 |
radiobutton $top.previewYes -text "Yes" -value "1" \ |
| 743 |
-variable pageInfo(-preview) -command "ApplyPs" |
| 744 |
radiobutton $top.previewNo -text "No" -value "0" \ |
| 745 |
-variable pageInfo(-preview) -command "ApplyPs" |
| 746 |
set col 2 |
| 747 |
table $top \ |
| 748 |
$row,$col $top.previewLabel -anchor e \ |
| 749 |
$row,$col+1 $top.previewYes -anchor w \ |
| 750 |
$row+1,$col+1 $top.previewNo -anchor w |
| 751 |
incr row 2 |
| 752 |
|
| 753 |
button $top.cancel -text "Cancel" -command "destroy $top" |
| 754 |
button $top.ok -text "Done" -command "PrintPs $graph" |
| 755 |
table $top \ |
| 756 |
$row,0 $top.cancel -pady 4 -padx 4 -width 1i \ |
| 757 |
$row,1 $top.ok -pady 4 -padx 4 -width 1i |
| 758 |
|
| 759 |
} |
| 760 |
|
| 761 |
proc CenterPlot { } { |
| 762 |
global pageInfo |
| 763 |
|
| 764 |
set pageInfo(-padx) $pageInfo(oldPadX) |
| 765 |
set pageInfo(-pady) $pageInfo(oldPadY) |
| 766 |
ApplyPs |
| 767 |
} |