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

Last change on this file since 5659 was 5659, checked in by ldelgass, 9 years ago

whitespace

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