source: trunk/gui/scripts/xyprint.tcl @ 2654

Last change on this file since 2654 was 2654, checked in by gah, 13 years ago
File size: 52.2 KB
RevLine 
[1572]1
2# ----------------------------------------------------------------------
3#  COMPONENT: xyprint - Print X-Y plot.
4#
5# ======================================================================
6#  AUTHOR:  Michael McLennan, Purdue University
7#  Copyright (c) 2004-2005  Purdue Research Foundation
8#
9#  See the file "license.terms" for information on usage and
10#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11# ======================================================================
[1588]12package require Itk
[1572]13package require BLT
14
[1593]15#option add *XyPrint.width 3i widgetDefault
16#option add *XyPrint.height 3i widgetDefault
17option add *XyPrint.gridColor #d9d9d9 widgetDefault
[1588]18option add *XyPrint.activeColor blue widgetDefault
19option add *XyPrint.dimColor gray widgetDefault
20option add *XyPrint.controlBackground gray widgetDefault
[1785]21option add *XyPrint*Font "Arial 9" widgetDefault
[1588]22option add *XyPrint*Entry*width "6" widgetDefault
23option add *XyPrint*Entry*background "white" widgetDefault
24
25itcl::class Rappture::XyPrint {
26    inherit itk::Widget
27
[1589]28    constructor {args} {}
[1572]29    destructor {}
[1589]30
31    private variable _graph "";         # Original graph.
[1588]32    private variable _clone "";         # Cloned graph.
33    private variable _preview "";       # Preview image.
[1598]34    private variable _savedSettings;    # Array of settings.
[1607]35
[1636]36    private common _oldSettingsFile "~/.rpsettings"
37    private common _settingsFile "~/.rp_settings"
[1607]38
[1598]39    public method print { graph toolName plotName }
[1603]40    public method reset {}
[1572]41
[1785]42    private method CopyOptions { cmd orig clone {exclude {}}}
[1572]43    private method CloneGraph { orig }
[1588]44
[1593]45    private method BuildGeneralTab {}
[1588]46    private method BuildLayoutTab {}
47    private method BuildLegendTab {}
48    private method BuildAxisTab {}
49    private method SetOption { opt }
50    private method SetComponentOption { comp opt }
51    private method SetNamedComponentOption { comp name opt }
52    private method GetAxis {}
53    private method GetElement { args }
54    private method RegeneratePreview {}
55    private method InitClone {}
56    private method Pixels2Inches { pixels }
[1636]57    private method Inches2Pixels { inches {defValue ""}}
[1606]58    private method Color2RGB { color }
[1589]59
60    private method ApplyGeneralSettings {}
61    private method ApplyLegendSettings {}
62    private method ApplyAxisSettings {}
63    private method ApplyElementSettings {}
64    private method ApplyLayoutSettings {}
65    private method InitializeSettings {}
[1598]66    private method CreateSettings { toolName plotName }
67    private method RestoreSettings { toolName plotName }
68    private method SaveSettings { toolName plotName }
[1603]69    private method DestroySettings {}
[1593]70    private method ResetSettings { }
71    private method GetOutput {}
[1785]72    private method SetWaitVariable { state }
[1636]73    private method SetLayoutOption { option }
74    private method GetAxisType { axis }
[1598]75    private method restore { toolName plotName data }
[2653]76
77    # Same dialog may be used for different graphs
[1588]78    private common _settings
[1589]79    private common _wait
[1572]80}
81
82# ----------------------------------------------------------------------
83# CONSTRUCTOR
84# ----------------------------------------------------------------------
[1589]85itcl::body Rappture::XyPrint::constructor { args } {
[1588]86    Rappture::dispatcher _dispatcher
87    $_dispatcher register !rebuild
88    $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list"
89   
90    set w [winfo pixels . 2.5i]
91    set h [winfo pixels . 2i]
92    set _preview [image create photo -width $w -height $h]
93    itk_component add tabs {
94        blt::tabset $itk_interior.tabs \
95            -highlightthickness 0 -tearoff 0 -side top \
96            -bd 0 -gap 0 -tabborderwidth 1 \
97            -outerpad 1 -background grey
98    } {
99        keep -cursor
100        ignore -highlightthickness -borderwidth -background
101    }
[2653]102    set inner [frame $itk_interior.frame -bg grey]
[1588]103    itk_component add preview {
[2653]104        label $inner.preview \
[1588]105            -highlightthickness 0 -bd 0 -image $_preview -width 2.5i \
[2653]106                -height 2.5i -background grey
[1588]107    } {
[1929]108        ignore -background
[1588]109    }
110    itk_component add ok {
[1601]111        button $itk_interior.ok -text "Save" \
[1785]112            -highlightthickness 0 -pady 2 -padx 0 \
[1929]113            -command [itcl::code $this SetWaitVariable 1] \
114            -compound left \
115            -image [Rappture::icon download]
[1588]116    }
117    itk_component add cancel {
118        button $itk_interior.cancel -text "Cancel" \
[1785]119            -highlightthickness 0 -pady 2 -padx 0 \
[1929]120            -command [itcl::code $this SetWaitVariable 0] \
121            -compound left \
122            -image [Rappture::icon cancel]
[1588]123    }
124    blt::table $itk_interior \
[2653]125        0,0 $inner -fill both \
126        0,1 $itk_component(tabs) -fill both -cspan 2 \
127        1,2 $itk_component(cancel) -padx 2 -pady 2 -width .9i -fill y \
128        1,1 $itk_component(ok) -padx 2 -pady 2 -width .9i -fill y
129    blt::table $inner \
130        0,0 $itk_component(preview) -fill both -padx 10 -pady 10
[1588]131
[2653]132    #blt::table configure $itk_interior c1 c2 -resize none
133    blt::table configure $itk_interior c0 -resize both
[1593]134    BuildGeneralTab
[1588]135    BuildAxisTab
136    BuildLegendTab
137    BuildLayoutTab
138    eval itk_initialize $args
[1572]139}
140
[1588]141# ----------------------------------------------------------------------
142# DESTRUCTOR
143# ----------------------------------------------------------------------
[1593]144itcl::body Rappture::XyPrint::destructor {} {
[1588]145    destroy $_clone
146    image delete $_preview
147    array unset _settings $this-*
148}
149
[1593]150itcl::body Rappture::XyPrint::DestroySettings {} {
[1590]151    destroy $_clone
152    set _clone ""
153    set _graph ""
154}
155
[1603]156itcl::body Rappture::XyPrint::reset {} {
[1785]157    SetWaitVariable 0
[1603]158}
159
[1785]160itcl::body Rappture::XyPrint::SetWaitVariable { state } {
[1589]161    set _wait($this) $state
162}
[1588]163
[1598]164itcl::body Rappture::XyPrint::print { graph toolName plotName } {
[1590]165    set _graph $graph
[1785]166    CloneGraph $graph
[1589]167    InitClone
[1604]168    RestoreSettings $toolName $plotName
[1589]169    InitializeSettings
[1785]170    SetWaitVariable 0
[1589]171    tkwait variable [itcl::scope _wait($this)]
[1785]172    SaveSettings $toolName $plotName
[1593]173    set output ""
174    if { $_wait($this) } {
[1929]175        set output [GetOutput]
[1589]176    }
[1598]177    DestroySettings
[1593]178    return $output
[1589]179}
180
181itcl::body Rappture::XyPrint::GetOutput {} {
[1588]182    # Get the selected format of the download.
183    set page $itk_component(graph_page)
184    set format [$page.format current]
185
186    if { $format == "jpg" } {
[1929]187        set img [image create photo]
188        $_clone snap $img
189        set bytes [$img data -format "jpeg -quality 100"]
190        set bytes [Rappture::encoding::decode -as b64 $bytes]
191        image delete $img
192        return [list .jpg $bytes]
[1588]193    } elseif { $format == "png" } {
[1929]194        set img [image create photo]
195        $_clone snap $img
196        set bytes [$img data -format "png"]
197        set bytes [Rappture::encoding::decode -as b64 $bytes]
198        image delete $img
199        return [list .png $bytes]
[1588]200    }
201
202    # Handle encapsulated postscript or portable document format.
203
204    # Append an "i" for the graph postscript component.
205    set w $_settings($this-layout-width)i
206    set h $_settings($this-layout-height)i
207
208    $_clone postscript configure \
[1929]209        -maxpect false \
210        -decoration yes \
211        -center yes \
212        -width $w -height $h
[1572]213   
[1588]214    set psdata [$_clone postscript output]
[1572]215
[1717]216    if 0 {
[1929]217        set f [open "junk.raw" "w"]
218        puts -nonewline $f $psdata
219        close $f
[1717]220    }
[1616]221    if { $format == "eps" } {
[1929]222        return [list .$format $psdata]
[1572]223    }
[1598]224
225    set cmd ""
226    # | eps2eps << $psdata
227    lappend cmd "|" "/usr/bin/gs" \
[1929]228        "-q" "-sDEVICE=epswrite" "-sstdout=%stderr" \
229        "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \
230        "-dDEVICEWIDTH=250000" "-dDEVICEHEIGHT=250000" "-" "<<" "$psdata"
[1598]231    if { $format == "pdf" } {
[1929]232        # | eps2eps << $psdata | ps2pdf
233        lappend cmd "|" "/usr/bin/gs" \
234            "-q" "-sDEVICE=pdfwrite" "-sstdout=%stderr" \
235            "-sOutputFile=-" "-dNOPAUSE" "-dBATCH" "-dSAFER" \
236            "-dCompatibilityLevel=1.4" "-c" ".setpdfwrite" "-f" "-"
[1598]237    }
[1588]238    if { [catch {
[1929]239        set f [open $cmd "r"]
240        fconfigure $f -translation binary -encoding binary
241        set output [read $f]
242        close $f
[1588]243    } err ] != 0 } {
[1929]244        global errorInfo
245        puts stderr "failed to generate file: $err\n$errorInfo"
246        return ""
[1572]247    }
[1593]248    if 0 {
[1929]249        set f [open "junk.$format" "w"]
250        fconfigure $f -translation binary -encoding binary
251        puts -nonewline $f $output
252        close $f
[1593]253    }
[1588]254    return [list .$format $output]
[1572]255}
256
[1785]257itcl::body Rappture::XyPrint::CopyOptions { cmd orig clone {exclude {}} } {
[1572]258    set all [eval $orig $cmd]
259    set configLine $clone
[1785]260    foreach name $exclude {
[1929]261        set ignore($name) 1
[1785]262    }
[1572]263    foreach arg $cmd {
[1929]264        lappend configLine $arg
[1572]265    }
266    foreach option $all {
[1929]267        if { [llength $option] != 5 } {
268            continue
269        }
270        set switch [lindex $option 0]
271        set initial [lindex $option 3]
272        set current [lindex $option 4]
273        if { [info exists ignore($switch)] } {
274            continue
275        }
276        if { [string compare $initial $current] == 0 } {
277            continue
278        }
279        lappend configLine $switch $current
[1572]280    }
281    eval $configLine
282}
283
284itcl::body Rappture::XyPrint::CloneGraph { orig } {
[1588]285    set top $itk_interior
[1636]286    if { [winfo exists $top.graph] } {
[1929]287        destroy $top.graph
[1636]288    }
[1785]289    set _clone [blt::graph $top.graph]
290    CopyOptions "configure" $orig $_clone
[1572]291    # Axis component
292    foreach axis [$orig axis names] {
[1929]293        if { [$orig axis cget $axis -hide] } {
294            continue
295        }
296        if { [$_clone axis name $axis] == "" } {
297            $_clone axis create $axis
298        }
299        CopyOptions [list axis configure $axis] $orig $_clone
[1572]300    }
301    foreach axis { x y x2 y2 } {
[1929]302        $_clone ${axis}axis use [$orig ${axis}axis use]
[1572]303    }
304    # Pen component
305    foreach pen [$orig pen names] {
[1929]306        if { [$_clone pen name $pen] == "" } {
307            $_clone pen create $pen
308        }
309        CopyOptions [list pen configure $pen] $orig $_clone
[1572]310    }
311    # Marker component
312    foreach marker [$orig marker names] {
[1929]313        $_clone marker create [$orig marker type $marker] -name $marker
314        CopyOptions [list marker configure $marker] $orig $_clone -name
[1572]315    }
316    # Element component
317    foreach elem [$orig element names] {
[1930]318        set oper [$orig element type $elem]
319        $_clone $oper create $elem
320        CopyOptions [list $oper configure $elem] $orig $_clone -data
321        if { [$_clone $oper cget $elem -hide] } {
322            $_clone $oper configure $elem -label ""
[1929]323        }
[1572]324    }
325    # Fix element display list
[1785]326    $_clone element show [$orig element show]
[1572]327    # Legend component
[1785]328    CopyOptions {legend configure} $orig $_clone
[1572]329    # Postscript component
[1785]330    CopyOptions {postscript configure} $orig $_clone
331    # Crosshairs component
332    CopyOptions {crosshairs configure} $orig $_clone
[1572]333    # Grid component
[1785]334    CopyOptions {grid configure} $orig $_clone
335
336    # Create markers representing lines at zero for the x and y axis.
337    $_clone marker create line -name x-zero \
[1929]338        -coords "0 -Inf 0 Inf" -dashes 1 -hide yes
[1785]339    $_clone marker create line -name y-zero \
[1929]340        -coords "-Inf 0 Inf 0" -dashes 1 -hide yes
[1572]341}
[1588]342
343itcl::body Rappture::XyPrint::InitClone {} {
[1572]344   
[1588]345    $_clone configure -width 3.4i -height 3.4i -background white \
[1929]346        -borderwidth 0 \
347        -leftmargin 0 \
348        -rightmargin 0 \
349        -topmargin 0 \
350        -bottommargin 0
[1588]351   
352    # Kill the title and create a border around the plot
353    $_clone configure \
[1929]354        -title "" \
355        -plotborderwidth 1 -plotrelief solid  \
356        -plotbackground white -plotpadx 0 -plotpady 0
[1930]357
[1604]358    set _settings($this-layout-width) [Pixels2Inches [$_clone cget -width]]
359    set _settings($this-layout-height) [Pixels2Inches [$_clone cget -height]]
[2653]360
361    set _settings($this-legend-fontfamily) helvetica
362    set _settings($this-legend-fontsize)   10
363    set _settings($this-legend-fontweight) normal
364    set _settings($this-legend-fontslant)  roman
365    set font "helvetica 10 normal roman"
[1588]366    $_clone legend configure \
[1929]367        -position right \
[2653]368        -font $font \
[1929]369        -hide yes -borderwidth 0 -background white -relief solid \
370        -anchor nw -activeborderwidth 0
[1588]371    #
[2653]372    set _settings($this-axis-ticks-fontfamily) helvetica
373    set _settings($this-axis-ticks-fontsize)   10
374    set _settings($this-axis-ticks-fontweight) normal
375    set _settings($this-axis-ticks-fontslant)  roman
376    set _settings($this-axis-title-fontfamily) helvetica
377    set _settings($this-axis-title-fontsize)   10
378    set _settings($this-axis-title-fontweight) normal
379    set _settings($this-axis-title-fontslant)  roman
[1588]380    foreach axis [$_clone axis names] {
[1929]381        if { [$_clone axis cget $axis -hide] } {
382            continue
383        }
[2653]384        set _settings($this-$axis-ticks-fontfamily) helvetica
385        set _settings($this-$axis-ticks-fontsize)   10
386        set _settings($this-$axis-ticks-fontweight) normal
387        set _settings($this-$axis-ticks-fontslant)  roman
388        set _settings($this-$axis-title-fontfamily) helvetica
389        set _settings($this-$axis-title-fontsize)   10
390        set _settings($this-$axis-title-fontweight) normal
391        set _settings($this-$axis-title-fontslant)  roman
392        set tickfont "helvetica 10 normal roman"
393        set titlefont "helvetica 10 normal roman"
[1929]394        $_clone axis configure $axis -ticklength 5  \
395            -majorticks {} -minorticks {}
396        $_clone axis configure $axis \
[2653]397            -tickfont $tickfont \
398            -titlefont $titlefont
[1588]399    }
400    foreach elem [$_clone element names] {
[1930]401        if { [$_clone element type $elem] == "bar" } {
402            continue
403        }
[1929]404        if { [$_clone element cget $elem -linewidth] > 1 } {
405            $_clone element configure $elem -linewidth 1 -pixels 3
406        }
[1588]407    }
408}
409
410itcl::body Rappture::XyPrint::SetOption { opt } {
[2653]411    set new $_settings($this$opt)
[1785]412    set old [$_clone cget $opt]
413    set code [catch [list $_clone configure $opt $new] err]
[1588]414    if { $code != 0 } {
[1929]415        bell
416        global errorInfo
417        puts stderr "$err: $errorInfo"
[2653]418        set _settings($this$opt) $old
[1929]419        $_clone configure $opt $old
[1588]420    }
421}
422
423itcl::body Rappture::XyPrint::SetComponentOption { comp opt } {
[1785]424    set new $_settings($this-$comp$opt)
425    set old [$_clone $comp cget $opt]
426    set code [catch [list $_clone $comp configure $opt $new] err]
[1588]427    if { $code != 0 } {
[1929]428        bell
429        global errorInfo
430        puts stderr "$err: $errorInfo"
431        set _settings($this-$comp$opt) $old
432        $_clone $comp configure $opt $old
[1588]433    }
434}
435
436itcl::body Rappture::XyPrint::SetNamedComponentOption { comp name opt } {
[1785]437    set new $_settings($this-$comp$opt)
438    set old [$_clone $comp cget $name $opt]
439    set code [catch [list $_clone $comp configure $name $opt $new] err]
[1588]440    if { $code != 0 } {
[1929]441        bell
442        global errorInfo
443        puts stderr "$err: $errorInfo"
444        set _settings($this-$comp$opt) $old
445        $_clone $comp configure $name $opt $old
[1588]446    }
447}
448
[1589]449itcl::body Rappture::XyPrint::RegeneratePreview {} {
450    update
451    set img [image create photo]
[1636]452    set w [Inches2Pixels $_settings($this-layout-width) 3.4]
453    set h [Inches2Pixels $_settings($this-layout-height) 3.4]
[2653]454    $_clone snap $img -width $w -height $h
455
[1589]456    set pixelsPerInch [winfo pixels . 1i]
[2653]457    set cw [winfo width $itk_component(preview)]
458    set ch [winfo height $itk_component(preview)]
459    set rw [expr 2.5*$pixelsPerInch]
460    set rh [expr 2.5*$pixelsPerInch]
461    set maxwidth $rw
462    set maxheight $rh
463    if { $maxwidth > $cw } {
464        set maxwidth $cw
465    }
466    if { $maxheight > $ch } {
467        set maxheight $ch
468    }
469    set sx [expr double($maxwidth)/$w]
470    set sy [expr double($maxheight)/$h]
[1589]471    set s [expr min($sx,$sy)]
472
473    set pw [expr int(round($s * $w))]
474    set ph [expr int(round($s * $h))]
[2653]475    $_preview configure -width $pw -height $ph
[1589]476    blt::winop resample $img $_preview box
477    image delete $img
[1588]478}
479
[1589]480itcl::body Rappture::XyPrint::Pixels2Inches { pixels } {
481    if { [llength $pixels] == 2 } {
[1929]482        set pixels [lindex $pixels 0]
[1589]483    }
484    set pixelsPerInch [winfo pixels . 1i]
485    set inches [expr { double($pixels) / $pixelsPerInch }]
486    return [format %.3g ${inches}]
487}
488
[1636]489itcl::body Rappture::XyPrint::Inches2Pixels { inches {defValue ""}} {
490    set n [scan $inches %g dummy]
[1653]491    if { $n != 1  && $defValue != "" } {
[1929]492        set inches $defValue
[1636]493    }
[1589]494    return  [winfo pixels . ${inches}i]
495}
496
[1606]497itcl::body Rappture::XyPrint::Color2RGB { color } {
498    foreach { r g b } [winfo rgb $_clone $color] {
[1929]499        set r [expr round($r / 257.0)]
500        set g [expr round($g / 257.0)]
501        set b [expr round($b / 257.0)]
[1606]502    }
503    return [format "\#%02x%02x%02x" $r $g $b]
504}
[1589]505
[1636]506itcl::body Rappture::XyPrint::GetAxisType { axis } {
507    foreach type { x y x2 y2 } {
[1929]508        set axes [$_clone ${type}axis use]
509        if { [lsearch $axes $axis] >= 0 } {
510            return [string range $type 0 0]
511        }
[1636]512    }
513    return ""
514}
[1606]515
[1589]516itcl::body Rappture::XyPrint::GetAxis {} {
517    set axis [$itk_component(axis_combo) current]
[1785]518    foreach option { -min -max -loose -title -stepsize -subdivisions } {
[1929]519        set _settings($this-axis$option) [$_clone axis cget $axis $option]
[1589]520    }
[2653]521    foreach attr { fontfamily fontsize fontweight fontslant } {
522        set specific $this-$axis-ticks
523        set general $this-axis-ticks
524        set _settings(${general}-${attr}) $_settings(${specific}-${attr})
525        set specific $this-$axis-title
526        set general $this-axis-title
527        set _settings(${general}-${attr}) $_settings(${specific}-${attr})
528    }
[1636]529    set type [GetAxisType $axis]
[1589]530    if { [$_clone grid cget -map${type}] == $axis } {
[1929]531        set _settings($this-axis-grid) 1
[1589]532    }  else {
[1929]533        set _settings($this-axis-grid) 0
[1589]534    }
[1599]535    set _settings($this-axis-plotpad${type}) \
[1929]536        [Pixels2Inches [$_clone cget -plotpad${type}]]
[1589]537    set _settings($this-axis-zero) [$_clone marker cget ${type}-zero -hide]
538}
539
540itcl::body Rappture::XyPrint::GetElement { args } {
541    set index 1
[1636]542    array unset _settings $this-element-*
[1589]543    foreach elem [$_clone element show] {
[1929]544        set _settings($this-element-$index) $elem
545        incr index
[1589]546    }
547    set index [$itk_component(element_slider) get]
548    set elem $_settings($this-element-$index)
[1930]549    set _settings($this-element-label) [$_clone element cget $elem -label]
[1589]550    set _settings($this-element-color) [$_clone element cget $elem -color]
[1930]551    if { [$_clone element type $elem] != "bar" } {
552        set _settings($this-element-symbol) [$_clone element cget $elem -symbol]
553        set _settings($this-element-dashes) [$_clone element cget $elem -dashes]
554    }
[1589]555    set page $itk_component(legend_page)
[1606]556    set color [$page.color label $_settings($this-element-color)]
557    if { $color == "" } {
[1929]558        set color [Color2RGB $_settings($this-element-color)]
559        $page.color choices insert end $color $color
560        $page.color value $color
[1606]561    } else {
[1929]562        $page.color value [$page.color label $_settings($this-element-color)]
[1606]563    }
[1930]564    if { [$_clone element type $elem] != "bar" } {
565        $page.symbol value [$page.symbol label $_settings($this-element-symbol)]
566        $page.dashes value [$page.dashes label $_settings($this-element-dashes)]
567    }
[1589]568    #FixElement
569}
570
571itcl::body Rappture::XyPrint::BuildLayoutTab {} {
572    itk_component add layout_page {
[1929]573        frame $itk_component(tabs).layout_page
[1589]574    }
575    set page $itk_component(layout_page)
576    $itk_component(tabs) insert end "layout" \
577        -text "Layout" -padx 2 -pady 2 -window $page -fill both
578
579    label $page.width_l -text "width" 
580    entry $page.width -width 6 \
[1929]581        -textvariable [itcl::scope _settings($this-layout-width)]
[1589]582    bind  $page.width <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
[1609]583    Rappture::Tooltip::for $page.width \
584        "Set the width (inches) of the output image. Must be a positive number."
[1589]585
586    label $page.height_l -text "height"
587    entry $page.height -width 6 \
[1929]588        -textvariable [itcl::scope _settings($this-layout-height)]
[1589]589    bind  $page.height <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
[1609]590    Rappture::Tooltip::for $page.height \
591        "Set the height (inches) of the output image. Must be a positive number"
[1589]592
593    label $page.margin_l -text "Margins" 
594
595    label $page.left_l -text "left"
596    entry $page.left -width 6 \
[1929]597        -textvariable [itcl::scope _settings($this-layout-leftmargin)]
[1589]598    bind  $page.left <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
[1609]599    Rappture::Tooltip::for $page.left \
600        "Set the size (inches) of the left margin. If zero, the size is automatically determined."
[1589]601
602    label $page.right_l -text "right"
603    entry $page.right -width 6 \
[1929]604        -textvariable [itcl::scope _settings($this-layout-rightmargin)]
[1589]605    bind  $page.right <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
[1609]606    Rappture::Tooltip::for $page.right \
607        "Set the size (inches) of the right margin. If zero, the size is automatically determined."
[1589]608
[1609]609
[1589]610    label $page.top_l -text "top"
611    entry $page.top -width 6 \
[1929]612        -textvariable [itcl::scope _settings($this-layout-topmargin)]
[1589]613    bind  $page.top <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
[1609]614    Rappture::Tooltip::for $page.top \
615        "Set the size (inches) of the top margin. If zero, the size is automatically determined."
[1589]616
617    label $page.bottom_l -text "bottom"
618    entry $page.bottom -width 6 \
[1929]619        -textvariable [itcl::scope _settings($this-layout-bottommargin)]
[1589]620    bind  $page.bottom <KeyPress-Return> [itcl::code $this ApplyLayoutSettings]
[1609]621    Rappture::Tooltip::for $page.bottom \
622        "Set the size (inches) of the bottom margin. If zero, the size is automatically determined."
[1589]623
[1621]624
625    label $page.map -image [Rappture::icon graphmargins]
[1589]626    blt::table $page \
[1929]627        0,0 $page.width_l -anchor e \
628        0,1 $page.width -fill x  \
629        1,0 $page.height_l -anchor e \
630        1,1 $page.height -fill x \
631        3,0 $page.left_l -anchor e \
632        3,1 $page.left -fill x  \
633        4,0 $page.right_l -anchor e \
634        4,1 $page.right -fill x \
635        5,0 $page.top_l -anchor e \
636        5,1 $page.top -fill x \
637        6,0 $page.bottom_l -anchor e \
638        6,1 $page.bottom -fill x  \
639        0,2 $page.map -fill both -rspan 7 -padx 2
[1589]640
[1621]641    blt::table configure $page c0 r* -resize none
642    blt::table configure $page c1 r2 -resize both
[1589]643}
644
645
646itcl::body Rappture::XyPrint::BuildGeneralTab {} {
[1588]647    itk_component add graph_page {
[1929]648        frame $itk_component(tabs).graph_page
[1588]649    }
650    set page $itk_component(graph_page)
651    $itk_component(tabs) insert end "graph" \
652        -text "General" -padx 2 -pady 2 -window $page -fill both
653
654    label $page.format_l -text "format"
655    Rappture::Combobox $page.format -width 30 -editable no
656    $page.format choices insert end \
[1929]657        "pdf" "PDF Portable Document Format" \
658        "ps"  "PS PostScript Format"  \
659        "eps" "EPS Encapsulated PostScript"  \
660        "jpg" "JPEG Joint Photographic Experts Group Format" \
661        "png" "PNG Portable Network Graphics Format"         
[1588]662
[1589]663    bind $page.format <<Value>> [itcl::code $this ApplyGeneralSettings]
[1609]664    Rappture::Tooltip::for $page.format \
665        "Set the format of the image."
[1588]666
667    label $page.style_l -text "style"
668    Rappture::Combobox $page.style -width 20 -editable no
669    $page.style choices insert end \
[1929]670        "ieee" "IEEE Journal"  \
671        "gekco" "G Klimeck" 
[1589]672    bind $page.style <<Value>> [itcl::code $this ApplyGeneralSettings]
[1609]673    Rappture::Tooltip::for $page.format \
674        "Set the style template."
[1588]675
676    checkbutton $page.remember -text "remember settings" \
[1929]677        -variable [itcl::scope _settings($this-general-remember)] 
[1609]678    Rappture::Tooltip::for $page.remember \
679        "Remember the settings. They will be override the default settings."
[1588]680
[1785]681    button $page.revert -text "revert" -image [Rappture::icon revert] \
[1929]682        -compound left -padx 3 -pady 1 -overrelief raised -relief flat \
683        -command [itcl::code $this ResetSettings]
[1785]684    Rappture::Tooltip::for $page.revert \
685        "Revert to the default settings."
686
[1588]687    blt::table $page \
[1929]688        2,0 $page.format_l -anchor e \
689        2,1 $page.format -fill x -cspan 2 \
690        3,0 $page.style_l -anchor e \
691        3,1 $page.style -fill x -cspan 2 \
692        5,0 $page.remember -cspan 2 -anchor w \
693        5,2 $page.revert -anchor e
[1601]694    blt::table configure $page r* -resize none  -pady { 0 2 }
[1588]695    blt::table configure $page r4 -resize both
696
697}
698   
[1589]699itcl::body Rappture::XyPrint::ApplyLegendSettings {} {
[1588]700    set page $itk_component(legend_page)
701    set _settings($this-legend-anchor)    [$page.anchor current]
[1930]702    if { $_clone != "" } {
[2653]703        lappend font $_settings($this-legend-fontfamily)
704        lappend font $_settings($this-legend-fontsize)
705        lappend font $_settings($this-legend-fontweight)
706        lappend font $_settings($this-legend-fontslant)
[1930]707        foreach option { -hide -position -anchor -borderwidth } {
708            SetComponentOption legend $option
709        }
[2653]710        $_clone legend configure -font fixed -font $font
[1588]711    }
[1589]712    ApplyElementSettings
[1588]713}
714
715itcl::body Rappture::XyPrint::BuildLegendTab {} {
716    itk_component add legend_page {
[1929]717        frame $itk_component(tabs).legend_page
[1588]718    }
719    set page $itk_component(legend_page)
720    $itk_component(tabs) insert end "legend" \
721        -text "Legend" -padx 2 -pady 2 -window $page -fill both
722
723    checkbutton $page.show -text "show legend" \
[1929]724        -offvalue 1 -onvalue 0 \
725        -variable [itcl::scope _settings($this-legend-hide)]  \
726        -command [itcl::code $this ApplyLegendSettings]
[1609]727    Rappture::Tooltip::for $page.show \
728        "Display the legend."
[1588]729
730    label $page.position_l -text "position"
731    Rappture::Combobox $page.position -width 15 -editable no
732    $page.position choices insert end \
[1929]733        "leftmargin" "left margin"  \
734        "rightmargin" "right margin"  \
735        "bottommargin" "bottom margin"  \
736        "topmargin" "top margin"  \
737        "plotarea" "inside plot"
[1589]738    bind $page.position <<Value>> [itcl::code $this ApplyLegendSettings]
[1609]739    Rappture::Tooltip::for $page.position \
740        "Set the position of the legend.  This option and the anchor determine the legend's location."
[1588]741
742    Rappture::Combobox $page.anchor -width 10 -editable no
743    $page.anchor choices insert end \
[1929]744        "nw" "northwest"  \
745        "n" "north"  \
746        "ne" "northeast"  \
747        "sw" "southwest"  \
748        "s" "south"  \
749        "se" "southeast"  \
750        "c" "center"  \
751        "e" "east"  \
752        "w" "west" 
[1589]753    bind $page.anchor <<Value>> [itcl::code $this ApplyLegendSettings]
[1609]754    Rappture::Tooltip::for $page.anchor \
755        "Set the anchor of the legend.  This option and the anchor determine the legend's location."
[1588]756
757    checkbutton $page.border -text "border" \
[1929]758        -variable [itcl::scope _settings($this-legend-borderwidth)] \
759        -onvalue 1 -offvalue 0 \
760        -command [itcl::code $this ApplyLegendSettings]
[1609]761    Rappture::Tooltip::for $page.border \
762        "Display a solid border around the legend."
[1588]763
[1785]764    label $page.slider_l -text "legend\nentry"  -justify right
[1588]765    itk_component add element_slider {
[1929]766        ::scale $page.slider -from 1 -to 1 \
767            -orient horizontal -width 12 \
768            -command [itcl::code $this GetElement]
[1588]769    }
[1609]770    Rappture::Tooltip::for $page.slider \
771        "Select the current entry."
[1588]772
[1785]773    label $page.label_l -text "label"
[1588]774    entry $page.label \
[1929]775        -background white \
776        -textvariable [itcl::scope _settings($this-element-label)]
[1589]777    bind  $page.label <KeyPress-Return> [itcl::code $this ApplyElementSettings]
[1609]778    Rappture::Tooltip::for $page.label \
779        "Set the label of the current entry in the legend."
[1588]780
[1785]781    label $page.color_l -text "color "
[1588]782    Rappture::Combobox $page.color -width 15 -editable no
783    $page.color choices insert end \
[1929]784        "#000000" "black" \
785        "#ffffff" "white" \
786        "#0000cd" "blue" \
787        "#cd0000" "red" \
788        "#00cd00" "green" \
789        "#3a5fcd" "royal blue" \
[1588]790        "#cdcd00" "yellow" \
791        "#cd1076" "deep pink" \
792        "#009acd" "deep sky blue" \
[1929]793        "#00c5cd" "torquise" \
[1588]794        "#a2b5cd" "light steel blue" \
[1929]795        "#7ac5cd" "cadet blue" \
796        "#66cdaa" "aquamarine" \
797        "#a2cd5a" "dark olive green" \
[1607]798        "#cd9b9b" "rosy brown" \
[1929]799        "#0000ff" "blue1" \
800        "#ff0000" "red1" \
801        "#00ff00" "green1"
[1589]802    bind $page.color <<Value>> [itcl::code $this ApplyElementSettings]
[1609]803    Rappture::Tooltip::for $page.color \
804        "Set the color of the current entry."
[1588]805
[1785]806    label $page.dashes_l -text "line style"
[1588]807    Rappture::Combobox $page.dashes -width 15 -editable no
808    $page.dashes choices insert end \
[1929]809        "" "solid"  \
[1588]810        "1" "dot" \
811        "5 2" "dash" \
812        "2 4 2" "dashdot" \
813        "2 4 2 2" "dashdotdot"
[1589]814    bind $page.dashes <<Value>> [itcl::code $this ApplyElementSettings]
[1609]815    Rappture::Tooltip::for $page.dashes \
816        "Set the line style of the current entry."
[1588]817
[1785]818    label $page.symbol_l -text "symbol"
[1588]819    Rappture::Combobox $page.symbol -editable no
820    $page.symbol choices insert end \
[1929]821        "none" "none"  \
822        "square" "square" \
823        "circle" "circle" \
824        "diamond" "diamond" \
825        "plus" "plus" \
826        "cross" "cross" \
827        "splus" "skinny plus"  \
828        "scross" "skinny cross" \
829        "triangle" "triangle"
[1589]830    bind $page.symbol <<Value>> [itcl::code $this ApplyElementSettings]
[1609]831    Rappture::Tooltip::for $page.symbol \
832        "Set the symbol of the current entry. \"none\" display no symbols."
[1588]833
[1599]834    label $page.font_l -text "font"
835    Rappture::Combobox $page.fontfamily -width 10 -editable no
836    $page.fontfamily choices insert end \
[1929]837        "courier" "courier" \
838        "helvetica" "helvetica"  \
839        "new*century*schoolbook"  "new century schoolbook" \
840        "symbol"  "symbol" \
841        "times"  "times"         
[1601]842    bind $page.fontfamily <<Value>> [itcl::code $this ApplyLegendSettings]
[1609]843    Rappture::Tooltip::for $page.fontfamily \
844        "Set the font of entries in the legend."
[1599]845
846    Rappture::Combobox $page.fontsize -width 4 -editable no
847    $page.fontsize choices insert end \
[1929]848        "8" "8" \
849        "9" "9" \
850        "10" "10" \
851        "11" "11" \
852        "12" "12" \
853        "14" "14" \
854        "17" "17" \
855        "18" "18" \
856        "20" "20"
[1601]857    bind  $page.fontsize <<Value>> [itcl::code $this ApplyLegendSettings]
[1609]858    Rappture::Tooltip::for $page.fontsize \
859        "Set the size (points) of the font."
[1599]860
[1604]861    Rappture::PushButton $page.fontweight \
[1929]862        -onimage [Rappture::icon font-bold] \
863        -offimage [Rappture::icon font-bold] \
864        -onvalue "bold" -offvalue "normal" \
865        -command [itcl::code $this ApplyLegendSettings] \
[2653]866        -variable [itcl::scope _settings($this-legend-fontweight)]
[1609]867    Rappture::Tooltip::for $page.fontweight \
868        "Use the bold version of the font."
[1599]869
[1604]870    Rappture::PushButton $page.fontslant \
[1929]871        -onimage [Rappture::icon font-italic] \
872        -offimage [Rappture::icon font-italic] \
873        -onvalue "italic" -offvalue "roman" \
874        -command [itcl::code $this ApplyLegendSettings] \
[2653]875        -variable [itcl::scope _settings($this-legend-fontslant)]
[1609]876    Rappture::Tooltip::for $page.fontslant \
877        "Use the italic version of the font."
[1599]878
[1588]879    blt::table $page \
[1929]880        1,0 $page.show -cspan 2 -anchor w \
881        1,2 $page.border -cspan 2 -anchor w \
882        2,0 $page.position_l -anchor e \
883        2,1 $page.position -fill x \
884        2,2 $page.anchor -fill x  -cspan 3 \
885        3,0 $page.font_l -anchor e \
886        3,1 $page.fontfamily -fill x \
887        3,2 $page.fontsize -fill x \
888        3,3 $page.fontweight -anchor e \
889        3,4 $page.fontslant -anchor e \
890        4,0 $page.slider_l -anchor e \
891        4,1 $page.slider -fill x -cspan 5 \
892        5,0 $page.label_l -anchor e \
893        5,1 $page.label -fill x -cspan 5 \
894        6,0 $page.color_l -anchor e \
895        6,1 $page.color -fill x \
896        6,2 $page.symbol_l -anchor e \
897        6,3 $page.symbol -fill both -cspan 3 \
898        7,0 $page.dashes_l -anchor e \
899        7,1 $page.dashes -fill x \
[1588]900
[1601]901    blt::table configure $page r* -resize none -pady { 0 2 }
[2653]902    blt::table configure $page c3 c4 -resize none
[1588]903    blt::table configure $page r8 -resize both
904
905}
906
907itcl::body Rappture::XyPrint::BuildAxisTab {} {
908    itk_component add axis_page {
[1929]909        frame $itk_component(tabs).axis_page
[1588]910    }
911    set page $itk_component(axis_page)
912    $itk_component(tabs) insert end "axis" \
913        -text "Axis" -padx 2 -pady 2 -window $page -fill both
914   
[1785]915    label $page.axis_l -text "axis"
[1588]916    itk_component add axis_combo {
[1929]917        Rappture::Combobox $page.axis -width 20 -editable no
[1588]918    }
919    bind $itk_component(axis_combo) <<Value>> [itcl::code $this GetAxis]
[1609]920    Rappture::Tooltip::for $page.axis \
921        "Select the current axis."
[1588]922
[1785]923    label $page.title_l -text "title"
[1588]924    entry $page.title \
[1929]925        -textvariable [itcl::scope _settings($this-axis-title)]
[1589]926    bind  $page.title <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
[1609]927    Rappture::Tooltip::for $page.title \
928        "Set the title of the current axis."
[1588]929
[1785]930    label $page.min_l -text "min"
[1588]931    entry $page.min -width 10 \
[1929]932        -textvariable [itcl::scope _settings($this-axis-min)]
[1589]933    bind  $page.min <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
[1609]934    Rappture::Tooltip::for $page.min \
935        "Set the minimum limit for the current axis. If empty, the minimum is automatically determined."
[1588]936
[1785]937    label $page.max_l -text "max"
[1588]938    entry $page.max -width 10 \
[1929]939        -textvariable [itcl::scope _settings($this-axis-max)]
[1589]940    bind  $page.max <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
[1609]941    Rappture::Tooltip::for $page.max \
942        "Set the maximum limit for the current axis. If empty, the maximum is automatically determined."
[1588]943
[1785]944    label $page.subdivisions_l -text "subdivisions"
[1588]945    entry $page.subdivisions \
[1929]946        -textvariable [itcl::scope _settings($this-axis-subdivisions)]
[1589]947    bind  $page.subdivisions <KeyPress-Return> \
[1929]948        [itcl::code $this ApplyAxisSettings]
[1609]949    Rappture::Tooltip::for $page.subdivisions \
950        "Set the number of subdivisions (minor ticks) for the current axis."
[1588]951
[1785]952    label $page.stepsize_l -text "step size"
[1588]953    entry $page.stepsize \
[1929]954        -textvariable [itcl::scope _settings($this-axis-stepsize)]
[1589]955    bind  $page.stepsize <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
[1609]956    Rappture::Tooltip::for $page.stepsize \
957        "Set the interval between major ticks for the current axis. If zero, the interval is automatically determined."
[1588]958
959    checkbutton $page.loose -text "loose limits" \
[1929]960        -onvalue "always" -offvalue "0" \
961        -variable [itcl::scope _settings($this-axis-loose)] \
962        -command [itcl::code $this ApplyAxisSettings]
[1609]963    Rappture::Tooltip::for $page.loose \
964        "Set major ticks outside of the limits for the current axis."
[1588]965
[1599]966    label $page.plotpad_l -text "pad" 
967    entry $page.plotpad -width 6 \
[1929]968        -textvariable [itcl::scope _settings($this-axis-plotpad)]
[1599]969    bind  $page.plotpad <KeyPress-Return> [itcl::code $this ApplyAxisSettings]
[1609]970    Rappture::Tooltip::for $page.plotpad \
971        "Set padding (points) between the current axis and the plot."
[1588]972
973    checkbutton $page.grid -text "show grid lines" \
[1929]974        -variable [itcl::scope _settings($this-axis-grid)] \
975        -command [itcl::code $this ApplyAxisSettings]
[1609]976    Rappture::Tooltip::for $page.grid \
977        "Display grid lines for the current axis."
[1588]978
979    checkbutton $page.zero -text "mark zero" \
[1929]980        -offvalue 1 -onvalue 0 \
981        -variable [itcl::scope _settings($this-axis-zero)] \
982        -command [itcl::code $this ApplyAxisSettings]
[1609]983    Rappture::Tooltip::for $page.zero \
984        "Display a line at zero for the current axis."
[1588]985
[1598]986    label $page.tickfont_l -text "tick font"
987    Rappture::Combobox $page.tickfontfamily -width 10 -editable no
988    $page.tickfontfamily choices insert end \
[1929]989        "courier" "courier" \
990        "helvetica" "helvetica"  \
991        "new*century*schoolbook"  "new century schoolbook" \
992        "symbol"  "symbol" \
993        "times"  "times"         
[1601]994    bind $page.tickfontfamily <<Value>> [itcl::code $this ApplyAxisSettings]
[1609]995    Rappture::Tooltip::for $page.tickfontfamily \
996        "Set the font of the ticks for the current axis."
[1598]997
998    Rappture::Combobox $page.tickfontsize -width 4 -editable no
999    $page.tickfontsize choices insert end \
[1929]1000        "8" "8" \
1001        "9" "9" \
1002        "10" "10" \
1003        "11" "11" \
1004        "12" "12" \
1005        "14" "14" \
1006        "17" "17" \
1007        "18" "18" \
1008        "20" "20"
[1601]1009    bind $page.tickfontsize <<Value>> [itcl::code $this ApplyAxisSettings]
[1609]1010    Rappture::Tooltip::for $page.tickfontsize \
1011        "Set the size (points) of the tick font."
[1598]1012
[1604]1013    Rappture::PushButton $page.tickfontweight \
[1929]1014        -onimage [Rappture::icon font-bold] \
1015        -offimage [Rappture::icon font-bold] \
1016        -onvalue "bold" -offvalue "normal" \
1017        -command [itcl::code $this ApplyAxisSettings] \
[2653]1018        -variable [itcl::scope _settings($this-axis-ticks-fontweight)]
[1609]1019    Rappture::Tooltip::for $page.tickfontweight \
1020        "Use the bold version of the tick font."
[1598]1021
[1604]1022    Rappture::PushButton $page.tickfontslant \
[1929]1023        -onimage [Rappture::icon font-italic] \
1024        -offimage [Rappture::icon font-italic] \
1025        -onvalue "italic" -offvalue "roman" \
1026        -command [itcl::code $this ApplyAxisSettings] \
[2653]1027        -variable [itcl::scope _settings($this-axis-ticks-fontslant)]
[1609]1028    Rappture::Tooltip::for $page.tickfontslant \
1029        "Use the italic version of the tick font."
[1598]1030
[1599]1031    label $page.titlefont_l -text "title font"
1032    Rappture::Combobox $page.titlefontfamily -width 10 -editable no
1033    $page.titlefontfamily choices insert end \
[1929]1034        "courier" "courier" \
1035        "helvetica" "helvetica"  \
1036        "new*century*schoolbook"  "new century schoolbook" \
1037        "symbol"  "symbol" \
1038        "times"  "times"         
[1601]1039    bind $page.titlefontfamily <<Value>> [itcl::code $this ApplyAxisSettings]
[1609]1040    Rappture::Tooltip::for $page.titlefontfamily \
1041        "Set the font of the title for the current axis."
[1599]1042
1043    Rappture::Combobox $page.titlefontsize -width 4 -editable no
1044    $page.titlefontsize choices insert end \
[1929]1045        "8" "8" \
1046        "9" "9" \
1047        "10" "10" \
1048        "11" "11" \
1049        "12" "12" \
1050        "14" "14" \
1051        "17" "17" \
1052        "18" "18" \
1053        "20" "20"
[1647]1054    bind $page.titlefontsize <<Value>> [itcl::code $this ApplyAxisSettings]
[1609]1055    Rappture::Tooltip::for $page.titlefontsize \
1056        "Set the size (point) of the title font."
[1599]1057
[1604]1058    Rappture::PushButton $page.titlefontweight \
[1929]1059        -onimage [Rappture::icon font-bold] \
1060        -offimage [Rappture::icon font-bold] \
1061        -onvalue "bold" -offvalue "normal" \
1062        -command [itcl::code $this ApplyAxisSettings] \
[2653]1063        -variable [itcl::scope _settings($this-axis-title-fontweight)]
[1609]1064    Rappture::Tooltip::for $page.titlefontweight \
1065        "Use the bold version of the title font."
[1599]1066
[1604]1067    Rappture::PushButton $page.titlefontslant \
[1929]1068        -onimage [Rappture::icon font-italic] \
1069        -offimage [Rappture::icon font-italic] \
1070        -onvalue "italic" -offvalue "roman" \
1071        -command [itcl::code $this ApplyAxisSettings] \
[2653]1072        -variable [itcl::scope _settings($this-axis-title-fontslant)]
[1609]1073    Rappture::Tooltip::for $page.titlefontslant \
1074        "Use the italic version of the title font."
[1599]1075
[1588]1076    blt::table $page \
[1929]1077        1,1 $page.axis_l -anchor e  -pady 6 \
1078        1,2 $page.axis -fill x -cspan 6 \
1079        2,1 $page.title_l -anchor e \
1080        2,2 $page.title -fill x -cspan 5 \
1081        3,1 $page.min_l -anchor e \
1082        3,2 $page.min -fill x \
1083        3,3 $page.stepsize_l -anchor e \
1084        3,4 $page.stepsize -fill both -cspan 3 \
1085        4,1 $page.max_l -anchor e \
1086        4,2 $page.max -fill both \
1087        4,3 $page.subdivisions_l -anchor e \
1088        4,4 $page.subdivisions -fill both -cspan 3  \
1089        5,1 $page.titlefont_l -anchor e \
1090        5,2 $page.titlefontfamily -fill x -cspan 2 \
1091        5,4 $page.titlefontsize -fill x \
1092        5,5 $page.titlefontweight -anchor e \
1093        5,6 $page.titlefontslant -anchor e \
1094        6,1 $page.tickfont_l -anchor e \
1095        6,2 $page.tickfontfamily -fill x -cspan 2 \
1096        6,4 $page.tickfontsize -fill x \
1097        6,5 $page.tickfontweight -anchor e \
1098        6,6 $page.tickfontslant -anchor e \
1099        7,1 $page.loose -cspan 2 -anchor w \
1100        7,3 $page.grid -anchor w -cspan 2 \
1101        8,1 $page.zero -cspan 2 -anchor w \
1102        8,3 $page.plotpad_l -anchor e \
1103        8,4 $page.plotpad -fill both -cspan 3
[1785]1104
[2653]1105    blt::table configure $page  c0 c4 c5 c6 c7 c8 -resize none
[1588]1106}
1107
[1589]1108itcl::body Rappture::XyPrint::ApplyGeneralSettings {} {
1109    RegeneratePreview
1110}
1111
1112itcl::body Rappture::XyPrint::ApplyLegendSettings {} {
1113    set page $itk_component(legend_page)
1114    set _settings($this-legend-position)  [$page.position current]
1115    set _settings($this-legend-anchor)    [$page.anchor current]
[2653]1116   
[1788]1117    foreach option { -hide -position -anchor -borderwidth } {
[1929]1118        SetComponentOption legend $option
[1588]1119    }
[2654]1120    set _settings($this-legend-fontfamily)  [$page.fontfamily value]
1121    set _settings($this-legend-fontsize)    [$page.fontsize value]
[2653]1122    lappend font $_settings($this-legend-fontfamily)
1123    lappend font $_settings($this-legend-fontsize)
1124    lappend font $_settings($this-legend-fontweight)
1125    lappend font $_settings($this-legend-fontslant)
1126    $_clone legend configure -font fixed -font $font
[1589]1127    ApplyElementSettings
[1588]1128}
1129
[1589]1130itcl::body Rappture::XyPrint::ApplyAxisSettings {} {
1131    set axis [$itk_component(axis_combo) current]
[1636]1132    set type [GetAxisType $axis]
[1601]1133    set page $itk_component(axis_page)
[1589]1134    if { $_settings($this-axis-grid) } {
[1929]1135        $_clone grid configure -hide no -map${type} ${axis}
[1589]1136    } else {
[1929]1137        $_clone grid configure -hide no -map${type} ""
[1589]1138    }
[1599]1139    $_clone configure -plotpad${type} $_settings($this-axis-plotpad)
[1785]1140    foreach option { -min -max -loose -title -stepsize -subdivisions } {
[1929]1141        SetNamedComponentOption axis $axis $option
[1589]1142    }
[2654]1143    set _settings($this-axis-ticks-fontfamily)  [$page.tickfontfamily value]
1144    set _settings($this-axis-ticks-fontsize)    [$page.tickfontsize value]
1145    set _settings($this-axis-title-fontfamily)  [$page.titlefontfamily value]
1146    set _settings($this-axis-title-fontsize)    [$page.titlefontsize value]
1147
[2653]1148    set tickfont {}
1149    set titlefont {}
[2654]1150
[2653]1151    foreach attr { fontfamily fontsize fontweight fontslant } {
1152        set specific $this-$axis-ticks
1153        set general  $this-axis-ticks
1154        set _settings(${specific}-${attr}) $_settings(${general}-${attr})
1155        lappend tickfont $_settings(${general}-${attr})
1156        set specific $this-$axis-title
1157        set general  $this-axis-title
1158        set _settings(${specific}-${attr}) $_settings(${general}-${attr})
1159        lappend titlefont $_settings(${general}-${attr})
1160    }
1161    $_clone axis configure $axis -tickfont $tickfont -titlefont $titlefont
[1589]1162    $_clone marker configure ${type}-zero -hide $_settings($this-axis-zero)
1163    GetAxis
1164    RegeneratePreview
1165}
1166
1167itcl::body Rappture::XyPrint::ApplyElementSettings {} {
[1588]1168    set index [$itk_component(element_slider) get]
1169    set page $itk_component(legend_page)
1170    set _settings($this-element-color)  [$page.color current]
[1930]1171    if { $_clone != "" } {
1172        set elem $_settings($this-element-$index)
1173        if { [$_clone element type $elem] != "bar" } {
1174            set _settings($this-element-symbol) [$page.symbol current]
1175            set _settings($this-element-dashes) [$page.dashes current]
1176            foreach option { -symbol -dashes } {
1177                SetNamedComponentOption element $elem $option
1178            }
1179        }
1180        foreach option { -color -label } {
1181            SetNamedComponentOption element $elem $option
1182        }
1183        RegeneratePreview
[1588]1184    }
1185}
1186
[1636]1187itcl::body Rappture::XyPrint::SetLayoutOption { opt } {
[1785]1188    set new [Inches2Pixels $_settings($this-layout$opt)]
1189    $_clone configure $opt $new
[1636]1190}
1191
[1589]1192itcl::body Rappture::XyPrint::ApplyLayoutSettings {} {
[1785]1193    foreach opt { -width -height -leftmargin -rightmargin -topmargin
[1929]1194        -bottommargin } {
1195        set old [$_clone cget $opt]
1196        set code [catch { SetLayoutOption $opt } err]
1197        if { $code != 0 } {
1198            bell
1199            global errorInfo
1200            puts stderr "$err: $errorInfo"
1201            set _settings($this-layout$opt) [Pixels2Inches $old]
1202            $_clone configure $opt [Pixels2Inches $old]
1203        }
[1588]1204    }
1205    RegeneratePreview
1206}
1207
1208
[1589]1209itcl::body Rappture::XyPrint::InitializeSettings {} {
1210    # General settings
[1588]1211
[1616]1212    # Always set to "ps" "ieee"
1213    set _settings($this-general-format) ps
[1589]1214    set _settings($this-general-style) ieee
[1636]1215    set _settings($this-general-remember) 0
[1589]1216    set page $itk_component(graph_page)
[1943]1217    $page.format value [$page.format label $_settings($this-general-format)]
1218    $page.style value [$page.style label $_settings($this-general-style)]
[1588]1219
[1589]1220    # Layout settings
[1588]1221    set _settings($this-layout-width) [Pixels2Inches [$_clone cget -width]]
1222    set _settings($this-layout-height) [Pixels2Inches [$_clone cget -height]]
1223    set _settings($this-layout-leftmargin) \
[1929]1224        [Pixels2Inches [$_clone cget -leftmargin]]
[1588]1225    set _settings($this-layout-rightmargin) \
[1929]1226        [Pixels2Inches [$_clone cget -rightmargin]]
[1588]1227    set _settings($this-layout-topmargin) \
[1929]1228        [Pixels2Inches [$_clone cget -topmargin]]
[1588]1229    set _settings($this-layout-bottommargin) \
[1929]1230        [Pixels2Inches [$_clone cget -bottommargin]]
[1589]1231
1232    # Legend settings
1233    set page $itk_component(legend_page)
1234
1235    set names [$_clone element show]
1236    $itk_component(element_slider) configure -from 1 -to [llength $names]
[1593]1237    set state [expr  { ([llength $names] < 2) ? "disabled" : "normal" } ]
1238    $page.slider configure -state $state
1239    $page.slider_l configure -state $state
[1589]1240    # Always initialize the slider to the first entry in the element list.
1241    $itk_component(element_slider) set 1
1242    # Always set the borderwidth to be not displayed
1243    set _settings($this-legend-borderwidth) 0
1244
[2653]1245    $page.fontfamily value $_settings($this-legend-fontfamily)
1246    $page.fontsize value $_settings($this-legend-fontsize)
1247    if { $_settings($this-legend-fontweight) == "bold" } {
[1929]1248        set _settings($this-legend-font-bold) 1
[1604]1249    }
[1589]1250    set _settings($this-legend-hide) [$_clone legend cget -hide]
1251    set _settings($this-legend-position) [$_clone legend cget -position]
1252    set _settings($this-legend-anchor) [$_clone legend cget -anchor]
1253    $page.position value \
[1929]1254        [$page.position label $_settings($this-legend-position)]
[1589]1255    $page.anchor value [$page.anchor label $_settings($this-legend-anchor)]
1256    GetElement
1257
1258    # Axis settings
[1601]1259    set page $itk_component(axis_page)
[1589]1260    set names [lsort [$_clone axis names]]
1261    $itk_component(axis_combo) choices delete 0 end
1262    foreach axis $names {
[1929]1263        if { ![$_clone axis cget $axis -hide] } {
1264            $itk_component(axis_combo) choices insert end $axis $axis
1265        }
1266        lappend axisnames $axis
[1589]1267    }
[1604]1268    set axis [lindex $names 0]
1269
[2653]1270    $page.titlefontfamily value $_settings($this-$axis-title-fontfamily)
1271    $page.titlefontsize value   $_settings($this-axis-title-fontsize)
1272    $page.tickfontfamily value  $_settings($this-$axis-ticks-fontfamily)
1273    $page.tickfontsize value    $_settings($this-axis-ticks-fontsize)
[1604]1274
[1589]1275    # Always hide the zero line.
1276    set _settings($this-axis-zero) 1
[1601]1277    set _settings($this-axis-plotpad) [Pixels2Inches [$_clone cget -plotpadx]]
[1589]1278    # Pick the first axis to initially display
1279    set axis [lindex $axisnames 0]
1280    $itk_component(axis_combo) value $axis
1281    GetAxis
[1943]1282    RegeneratePreview
[1588]1283}
1284
[1589]1285
[1598]1286itcl::body Rappture::XyPrint::restore { toolName plotName data } {
1287    set key [list $toolName $plotName]
1288    set _savedSettings($key) $data
1289}
[1590]1290
[1598]1291itcl::body Rappture::XyPrint::RestoreSettings { toolName plotName } {
[1607]1292    if { ![file readable $_settingsFile] } {
[1929]1293        return;                         # No file or not readable
[1636]1294    }
1295    if { [file exists $_oldSettingsFile] } {
[1929]1296        file delete $_oldSettingsFile
[1598]1297    }
1298    # Read the file by sourcing it into a safe interpreter The only commands
1299    # executed will be "xyprint" which will simply add the data into an array
1300    # _savedSettings.
1301    set parser [interp create -safe]
1302    $parser alias xyprint [itcl::code $this restore]
[1607]1303    set f [open $_settingsFile "r"]
[1598]1304    set code [read $f]
1305    close $f
1306    $parser eval $code
1307   
1308    # Now see if there's an entry for this tool/plot combination.  The data
1309    # associated with the variable is itself code to update the graph (clone).
1310    set key [list $toolName $plotName]
1311    if { [info exists _savedSettings($key)] }  {
[1929]1312        $parser alias "preview" $_clone
1313        $parser eval $_savedSettings($key)
[1598]1314    }
[2653]1315    # Restore settings to this instance
1316    foreach {name value} [$parser eval "array get settings"] {
1317        set _settings($this-$name) $value
[1598]1318    }
1319    interp delete $parser
1320}
1321
[1593]1322itcl::body Rappture::XyPrint::ResetSettings {} {
[1785]1323    set graph $_graph
1324    DestroySettings
1325    set _graph $graph
1326    CloneGraph $graph
[1590]1327    InitClone
1328    InitializeSettings
[1589]1329}
1330
[1598]1331itcl::body Rappture::XyPrint::SaveSettings { toolName plotName } {
[1604]1332    if { !$_settings($this-general-remember) } {
[1929]1333        return
[1598]1334    }
[1607]1335    if { [catch { open $_settingsFile "w" 0600 } f ] != 0 } {
[1929]1336        puts stderr "$_settingsFile isn't writable: $f"
1337        bell
1338        return
[1604]1339    }
1340    set key [list $toolName $plotName]
1341    set _savedSettings($key) [CreateSettings $toolName $plotName]
[1598]1342    # Write the settings out
1343    foreach key [lsort [array names _savedSettings]] {
[1929]1344        set tool [lindex $key 0]
1345        set plot [lindex $key 1]
1346        puts $f "xyprint \"$tool\" \"$plot\" \{"
1347        set settings [string trim $_savedSettings($key) \n]
1348        puts $f "$settings"
1349        puts $f "\}\n"
[1598]1350    }
1351    close $f
1352}
1353
1354itcl::body Rappture::XyPrint::CreateSettings { toolName plotName } {
[1589]1355    # Create stanza associated with tool and plot title.
1356    # General settings
[2653]1357    set length [string length "${this}-"]
1358    append out "    array set settings {\n"
1359    foreach item [array names _settings ${this}-*] {
1360        set field [string range $item $length end]
1361        if { [regexp {^element-[0-9]+$} $field] } {
1362            continue
1363        }
1364        set value $_settings($item)
1365        append out "        [list $field] [list $value]\n"
[1604]1366    }
[2653]1367    append out "    }\n"
1368    # Legend font
1369    lappend legendfont $_settings($this-legend-fontfamily)
1370    lappend legendfont $_settings($this-legend-fontsize)
1371    lappend legendfont $_settings($this-legend-fontweight)
1372    lappend legendfont $_settings($this-legend-fontslant)
1373    # Axis tick font
1374    lappend axistickfont $_settings($this-axis-ticks-fontfamily)
1375    lappend axistickfont $_settings($this-axis-ticks-fontsize)
1376    lappend axistickfont $_settings($this-axis-ticks-fontweight)
1377    lappend axistickfont $_settings($this-axis-ticks-fontslant)
1378    # Axis title font
1379    lappend axistitlefont $_settings($this-axis-title-fontfamily)
1380    lappend axistitlefont $_settings($this-axis-title-fontsize)
1381    lappend axistitlefont $_settings($this-axis-title-fontweight)
1382    lappend axistitlefont $_settings($this-axis-title-fontslant)
[1607]1383    append out "\n"
[1604]1384
[1589]1385    # Layout settings
[1607]1386    append out "    preview configure"
[1606]1387    foreach opt { -width -height -leftmargin -rightmargin -topmargin
[1929]1388        -bottommargin -plotpadx -plotpady } {
1389        set value [list [$_clone cget $opt]]
1390        append out " $opt $value"
[1606]1391    }
1392    append out "\n"
[1595]1393
[1589]1394    # Legend settings
[1607]1395    append out "    preview legend configure"
[1606]1396    foreach opt { -position -anchor -borderwidth -hide } {
[1929]1397        set value [list [$_clone legend cget $opt]]
1398        append out " $opt $value"
[1606]1399    }
[2653]1400    append out " -font \"$legendfont\"\n"
[1606]1401
[1589]1402    # Element settings
1403    foreach elem [$_clone element show] {
[1929]1404        set label [$_clone element cget $elem -label]
1405        if { $label == "" } {
1406            continue
1407        }
1408        append out "    if \{ \[preview element exists \"$label\"\] \} \{\n"
1409        append out "        preview element configure \"$label\""
[1930]1410        if { [$_clone element type $elem] != "bar" } {
1411            set options { -symbol -color -dashes -label }
1412        } else {
1413            set options { -color -label }
1414        }
1415        foreach opt $options {
[1929]1416            set value [list [$_clone element cget $elem $opt]]
1417            append out " $opt $value"
1418        }
1419        append out "    \}\n"
[1589]1420    }
1421   
1422    # Axis settings
1423    foreach axis [$_clone axis names] {
[1929]1424        if { [$_clone axis cget $axis -hide] } {
1425            continue
1426        }
1427        append out "    if \{ \[preview axis names \"$axis\"\] == \"$axis\" \} \{\n"
1428        append out "        preview axis configure \"$axis\""
1429        foreach opt { -hide -min -max -loose -title -stepsize -subdivisions } {
1430            set value [list [$_clone axis cget $axis $opt]]
1431            append out " $opt $value"
1432        }
[2653]1433        append out " -tickfont \"$axistickfont\""
1434        append out " -titlefont \"$axistitlefont\"\n"
[1929]1435        set hide [$_clone marker cget ${axis}-zero -hide]
1436        append out "        preview marker configure \"${axis}-zero\" -hide $hide\n"
1437        append out "    \}\n"
[1589]1438    }   
[1604]1439
[1607]1440    append out "    preview grid configure"
[1606]1441    append out " -hide \"[$_clone grid cget -hide]\""
1442    append out " -mapx \"[$_clone grid cget -mapx]\""
1443    append out " -mapy \"[$_clone grid cget -mapy]\""
[1598]1444    return $out
[1589]1445}
Note: See TracBrowser for help on using the repository browser.