Changeset 5661 for branches/1.3/gui/scripts/xyprint.tcl
- Timestamp:
- Jun 5, 2015, 10:16:12 AM (9 years ago)
- Location:
- branches/1.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
-
branches/1.3/gui/scripts/xyprint.tcl
r4946 r5661 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 2 1 # -*- mode: tcl; indent-tabs-mode: nil -*- 3 2 # ---------------------------------------------------------------------- 4 3 # COMPONENT: xyprint - Print X-Y plot. … … 30 29 destructor {} 31 30 32 private variable _graph ""; # Original graph. 31 private variable _graph ""; # Original graph. 33 32 private variable _clone ""; # Cloned graph. 34 33 private variable _preview ""; # Preview image. … … 41 40 public method reset {} 42 41 43 private method CopyOptions { cmd orig clone {exclude {}}} 42 private method CopyOptions { cmd orig clone {exclude {}}} 44 43 private method CloneGraph { orig } 45 44 … … 53 52 private method GetAxis {} 54 53 private method GetElement { args } 55 private method RegeneratePreview {} 56 private method InitClone {} 57 private method Pixels2Inches { pixels } 58 private method Inches2Pixels { inches {defValue ""}} 59 private method Color2RGB { color } 60 61 private method ApplyGeneralSettings {} 62 private method ApplyLegendSettings {} 63 private method ApplyAxisSettings {} 64 private method ApplyElementSettings {} 65 private method ApplyLayoutSettings {} 66 private method InitializeSettings {} 67 private method CreateSettings { toolName plotName } 68 private method RestoreSettings { toolName plotName } 69 private method SaveSettings { toolName plotName } 54 private method RegeneratePreview {} 55 private method InitClone {} 56 private method Pixels2Inches { pixels } 57 private method Inches2Pixels { inches {defValue ""}} 58 private method Color2RGB { color } 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 {} 66 private method CreateSettings { toolName plotName } 67 private method RestoreSettings { toolName plotName } 68 private method SaveSettings { toolName plotName } 70 69 private method DestroySettings {} 71 private method ResetSettings { } 70 private method ResetSettings { } 72 71 private method GetOutput {} 73 72 private method SetWaitVariable { state } 74 private method SetLayoutOption { option } 75 private method GetAxisType { axis } 76 private method restore { toolName plotName data } 73 private method SetLayoutOption { option } 74 private method GetAxisType { axis } 75 private method restore { toolName plotName data } 77 76 78 77 # Same dialog may be used for different graphs … … 88 87 $_dispatcher register !rebuild 89 88 $_dispatcher dispatch $this !rebuild "[itcl::code $this Rebuild]; list" 90 89 91 90 set w [winfo pixels . 2.5i] 92 91 set h [winfo pixels . 2i] … … 127 126 0,1 $itk_component(tabs) -fill both -cspan 2 \ 128 127 1,2 $itk_component(cancel) -padx 2 -pady 2 -width .9i -fill y \ 129 1,1 $itk_component(ok) -padx 2 -pady 2 -width .9i -fill y 128 1,1 $itk_component(ok) -padx 2 -pady 2 -width .9i -fill y 130 129 blt::table $inner \ 131 0,0 $itk_component(preview) -fill both -padx 10 -pady 10 130 0,0 $itk_component(preview) -fill both -padx 10 -pady 10 132 131 133 132 #blt::table configure $itk_interior c1 c2 -resize none … … 167 166 CloneGraph $graph 168 167 InitClone 169 RestoreSettings $toolName $plotName 168 RestoreSettings $toolName $plotName 170 169 InitializeSettings 171 170 SetWaitVariable 0 172 171 tkwait variable [itcl::scope _wait($this)] 173 SaveSettings $toolName $plotName 172 SaveSettings $toolName $plotName 174 173 set output "" 175 174 if { $_wait($this) } { 176 175 set output [GetOutput] 177 176 } 178 DestroySettings 177 DestroySettings 179 178 return $output 180 179 } … … 212 211 -center yes \ 213 212 -width $w -height $h 214 213 215 214 set psdata [$_clone postscript output] 216 215 217 216 if 0 { 218 set f [open "junk.raw" "w"] 217 set f [open "junk.raw" "w"] 219 218 puts -nonewline $f $psdata 220 219 close $f 221 220 } 222 if { $format == "eps" } { 221 if { $format == "eps" } { 223 222 return [list .$format $psdata] 224 223 } 225 224 226 225 set cmd "" 227 # | eps2eps << $psdata 226 # | eps2eps << $psdata 228 227 lappend cmd "|" "/usr/bin/gs" \ 229 228 "-q" "-sDEVICE=epswrite" "-sstdout=%stderr" \ … … 231 230 "-dDEVICEWIDTH=250000" "-dDEVICEHEIGHT=250000" "-" "<<" "$psdata" 232 231 if { $format == "pdf" } { 233 # | eps2eps << $psdata | ps2pdf 232 # | eps2eps << $psdata | ps2pdf 234 233 lappend cmd "|" "/usr/bin/gs" \ 235 234 "-q" "-sDEVICE=pdfwrite" "-sstdout=%stderr" \ … … 243 242 close $f 244 243 } err ] != 0 } { 245 global errorInfo 244 global errorInfo 246 245 puts stderr "failed to generate file: $err\n$errorInfo" 247 246 return "" 248 247 } 249 248 if 0 { 250 set f [open "junk.$format" "w"] 249 set f [open "junk.$format" "w"] 251 250 fconfigure $f -translation binary -encoding binary 252 251 puts -nonewline $f $output … … 320 319 # Element component 321 320 foreach elem [$orig element names] { 322 set oper [$orig element type $elem] 321 set oper [$orig element type $elem] 323 322 $_clone $oper create $elem 324 CopyOptions [list $oper configure $elem] $orig $_clone -data 323 CopyOptions [list $oper configure $elem] $orig $_clone -data 325 324 if { [$_clone $oper cget $elem -hide] } { 326 $_clone $oper configure $elem -label "" 325 $_clone $oper configure $elem -label "" 327 326 } 328 327 } … … 346 345 347 346 itcl::body Rappture::XyPrint::InitClone {} { 348 347 349 348 $_clone configure -width 3.4i -height 3.4i -background white \ 350 349 -borderwidth 0 \ … … 353 352 -topmargin 0 \ 354 353 -bottommargin 0 355 354 356 355 # Kill the title and create a border around the plot 357 356 $_clone configure \ … … 373 372 -hide yes -borderwidth 0 -background white -relief solid \ 374 373 -anchor nw -activeborderwidth 0 375 # 374 # 376 375 set _settings($this-axis-ticks-fontfamily) helvetica 377 376 set _settings($this-axis-ticks-fontsize) 10 … … 412 411 incr count 413 412 if { [$_clone element cget $elem -linewidth] > 1 } { 414 $_clone element configure $elem -linewidth 1 -pixels 3 413 $_clone element configure $elem -linewidth 1 -pixels 3 415 414 } 416 415 } 417 416 if { $count == 0 } { 418 # There are no "line" elements in the graph. 417 # There are no "line" elements in the graph. 419 418 # Remove the symbol and dashes controls. 420 419 set page $itk_component(legend_page) 421 420 # May have already been forgotten. 422 catch { 421 catch { 423 422 blt::table forget $page.symbol_l 424 423 blt::table forget $page.symbol 425 424 blt::table forget $page.dashes_l 426 blt::table forget $page.dashes 425 blt::table forget $page.dashes 427 426 } 428 427 } … … 430 429 431 430 itcl::body Rappture::XyPrint::SetOption { opt } { 432 set new $_settings($this$opt) 431 set new $_settings($this$opt) 433 432 set old [$_clone cget $opt] 434 433 set code [catch [list $_clone configure $opt $new] err] … … 443 442 444 443 itcl::body Rappture::XyPrint::SetComponentOption { comp opt } { 445 set new $_settings($this-$comp$opt) 444 set new $_settings($this-$comp$opt) 446 445 set old [$_clone $comp cget $opt] 447 446 set code [catch [list $_clone $comp configure $opt $new] err] … … 456 455 457 456 itcl::body Rappture::XyPrint::SetNamedComponentOption { comp name opt } { 458 set new $_settings($this-$comp$opt) 457 set new $_settings($this-$comp$opt) 459 458 set old [$_clone $comp cget $name $opt] 460 459 set code [catch [list $_clone $comp configure $name $opt $new] err] … … 469 468 470 469 itcl::body Rappture::XyPrint::RegeneratePreview {} { 471 update 470 update 472 471 set img [image create photo] 473 472 set w [Inches2Pixels $_settings($this-layout-width) 3.4] … … 483 482 set maxheight $rh 484 483 if { $maxwidth > $cw } { 485 set maxwidth $cw 484 set maxwidth $cw 486 485 } 487 486 if { $maxheight > $ch } { 488 set maxheight $ch 487 set maxheight $ch 489 488 } 490 489 set sx [expr double($maxwidth)/$w] … … 494 493 set pw [expr int(round($s * $w))] 495 494 set ph [expr int(round($s * $h))] 496 $_preview configure -width $pw -height $ph 495 $_preview configure -width $pw -height $ph 497 496 blt::winop resample $img $_preview box 498 497 image delete $img … … 592 591 itcl::body Rappture::XyPrint::BuildLayoutTab {} { 593 592 itk_component add layout_page { 594 frame $itk_component(tabs).layout_page 593 frame $itk_component(tabs).layout_page 595 594 } 596 595 set page $itk_component(layout_page) … … 598 597 -text "Layout" -padx 2 -pady 2 -window $page -fill both 599 598 600 label $page.width_l -text "width" 599 label $page.width_l -text "width" 601 600 entry $page.width -width 6 \ 602 601 -textvariable [itcl::scope _settings($this-layout-width)] … … 605 604 "Set the width (inches) of the output image. Must be a positive number." 606 605 607 label $page.height_l -text "height" 606 label $page.height_l -text "height" 608 607 entry $page.height -width 6 \ 609 608 -textvariable [itcl::scope _settings($this-layout-height)] … … 612 611 "Set the height (inches) of the output image. Must be a positive number" 613 612 614 label $page.margin_l -text "Margins" 613 label $page.margin_l -text "Margins" 615 614 616 615 label $page.left_l -text "left" … … 621 620 "Set the size (inches) of the left margin. If zero, the size is automatically determined." 622 621 623 label $page.right_l -text "right" 622 label $page.right_l -text "right" 624 623 entry $page.right -width 6 \ 625 624 -textvariable [itcl::scope _settings($this-layout-rightmargin)] … … 660 659 0,2 $page.map -fill both -rspan 7 -padx 2 661 660 662 blt::table configure $page c0 r* -resize none 661 blt::table configure $page c0 r* -resize none 663 662 blt::table configure $page c1 r2 -resize both 664 663 } … … 667 666 itcl::body Rappture::XyPrint::BuildGeneralTab {} { 668 667 itk_component add graph_page { 669 frame $itk_component(tabs).graph_page 668 frame $itk_component(tabs).graph_page 670 669 } 671 670 set page $itk_component(graph_page) … … 680 679 "eps" "EPS Encapsulated PostScript" \ 681 680 "jpg" "JPEG Joint Photographic Experts Group Format" \ 682 "png" "PNG Portable Network Graphics Format" 681 "png" "PNG Portable Network Graphics Format" 683 682 684 683 bind $page.format <<Value>> [itcl::code $this ApplyGeneralSettings] … … 686 685 "Set the format of the image." 687 686 688 label $page.style_l -text "style" 687 label $page.style_l -text "style" 689 688 Rappture::Combobox $page.style -width 20 -editable no 690 689 $page.style choices insert end \ 691 690 "ieee" "IEEE Journal" \ 692 "gekco" "G Klimeck" 691 "gekco" "G Klimeck" 693 692 bind $page.style <<Value>> [itcl::code $this ApplyGeneralSettings] 694 693 Rappture::Tooltip::for $page.format \ … … 696 695 697 696 checkbutton $page.remember -text "remember settings" \ 698 -variable [itcl::scope _settings($this-general-remember)] 697 -variable [itcl::scope _settings($this-general-remember)] 699 698 Rappture::Tooltip::for $page.remember \ 700 699 "Remember the settings. They will be override the default settings." … … 712 711 3,1 $page.style -fill x -cspan 2 \ 713 712 5,0 $page.remember -cspan 2 -anchor w \ 714 5,2 $page.revert -anchor e 713 5,2 $page.revert -anchor e 715 714 blt::table configure $page r* -resize none -pady { 0 2 } 716 715 blt::table configure $page r4 -resize both 717 716 718 717 } 719 718 720 719 itcl::body Rappture::XyPrint::ApplyLegendSettings {} { 721 720 set page $itk_component(legend_page) … … 736 735 itcl::body Rappture::XyPrint::BuildLegendTab {} { 737 736 itk_component add legend_page { 738 frame $itk_component(tabs).legend_page 737 frame $itk_component(tabs).legend_page 739 738 } 740 739 set page $itk_component(legend_page) … … 745 744 -offvalue 1 -onvalue 0 \ 746 745 -variable [itcl::scope _settings($this-legend-hide)] \ 747 -command [itcl::code $this ApplyLegendSettings] 746 -command [itcl::code $this ApplyLegendSettings] 748 747 Rappture::Tooltip::for $page.show \ 749 748 "Display the legend." … … 756 755 "bottommargin" "bottom margin" \ 757 756 "topmargin" "top margin" \ 758 "plotarea" "inside plot" 757 "plotarea" "inside plot" 759 758 bind $page.position <<Value>> [itcl::code $this ApplyLegendSettings] 760 759 Rappture::Tooltip::for $page.position \ … … 771 770 "c" "center" \ 772 771 "e" "east" \ 773 "w" "west" 772 "w" "west" 774 773 bind $page.anchor <<Value>> [itcl::code $this ApplyLegendSettings] 775 774 Rappture::Tooltip::for $page.anchor \ … … 788 787 -orient horizontal -width 12 \ 789 788 -command [itcl::code $this GetElement] 790 } 789 } 791 790 Rappture::Tooltip::for $page.slider \ 792 791 "Select the current entry." 793 792 794 label $page.label_l -text "label" 793 label $page.label_l -text "label" 795 794 entry $page.label \ 796 795 -background white \ … … 800 799 "Set the label of the current entry in the legend." 801 800 802 label $page.color_l -text "color " 801 label $page.color_l -text "color " 803 802 Rappture::Combobox $page.color -width 15 -editable no 804 803 $page.color choices insert end \ … … 820 819 "#0000ff" "blue1" \ 821 820 "#ff0000" "red1" \ 822 "#00ff00" "green1" 821 "#00ff00" "green1" 823 822 bind $page.color <<Value>> [itcl::code $this ApplyElementSettings] 824 823 Rappture::Tooltip::for $page.color \ 825 824 "Set the color of the current entry." 826 825 827 label $page.dashes_l -text "line style" 826 label $page.dashes_l -text "line style" 828 827 Rappture::Combobox $page.dashes -width 15 -editable no 829 828 $page.dashes choices insert end \ … … 837 836 "Set the line style of the current entry." 838 837 839 label $page.symbol_l -text "symbol" 838 label $page.symbol_l -text "symbol" 840 839 Rappture::Combobox $page.symbol -editable no 841 840 $page.symbol choices insert end \ … … 860 859 "new*century*schoolbook" "new century schoolbook" \ 861 860 "symbol" "symbol" \ 862 "times" "times" 861 "times" "times" 863 862 bind $page.fontfamily <<Value>> [itcl::code $this ApplyLegendSettings] 864 863 Rappture::Tooltip::for $page.fontfamily \ … … 875 874 "17" "17" \ 876 875 "18" "18" \ 877 "20" "20" 876 "20" "20" 878 877 bind $page.fontsize <<Value>> [itcl::code $this ApplyLegendSettings] 879 878 Rappture::Tooltip::for $page.fontsize \ … … 928 927 itcl::body Rappture::XyPrint::BuildAxisTab {} { 929 928 itk_component add axis_page { 930 frame $itk_component(tabs).axis_page 929 frame $itk_component(tabs).axis_page 931 930 } 932 931 set page $itk_component(axis_page) 933 932 $itk_component(tabs) insert end "axis" \ 934 933 -text "Axis" -padx 2 -pady 2 -window $page -fill both 935 936 label $page.axis_l -text "axis" 934 935 label $page.axis_l -text "axis" 937 936 itk_component add axis_combo { 938 937 Rappture::Combobox $page.axis -width 20 -editable no 939 } 938 } 940 939 bind $itk_component(axis_combo) <<Value>> [itcl::code $this GetAxis] 941 940 Rappture::Tooltip::for $page.axis \ 942 941 "Select the current axis." 943 942 944 label $page.title_l -text "title" 943 label $page.title_l -text "title" 945 944 entry $page.title \ 946 945 -textvariable [itcl::scope _settings($this-axis-title)] … … 985 984 "Set major ticks outside of the limits for the current axis." 986 985 987 label $page.plotpad_l -text "pad" 986 label $page.plotpad_l -text "pad" 988 987 entry $page.plotpad -width 6 \ 989 988 -textvariable [itcl::scope _settings($this-axis-plotpad)] … … 1012 1011 "new*century*schoolbook" "new century schoolbook" \ 1013 1012 "symbol" "symbol" \ 1014 "times" "times" 1013 "times" "times" 1015 1014 bind $page.tickfontfamily <<Value>> [itcl::code $this ApplyAxisSettings] 1016 1015 Rappture::Tooltip::for $page.tickfontfamily \ … … 1027 1026 "17" "17" \ 1028 1027 "18" "18" \ 1029 "20" "20" 1028 "20" "20" 1030 1029 bind $page.tickfontsize <<Value>> [itcl::code $this ApplyAxisSettings] 1031 1030 Rappture::Tooltip::for $page.tickfontsize \ … … 1057 1056 "new*century*schoolbook" "new century schoolbook" \ 1058 1057 "symbol" "symbol" \ 1059 "times" "times" 1058 "times" "times" 1060 1059 bind $page.titlefontfamily <<Value>> [itcl::code $this ApplyAxisSettings] 1061 1060 Rappture::Tooltip::for $page.titlefontfamily \ … … 1072 1071 "17" "17" \ 1073 1072 "18" "18" \ 1074 "20" "20" 1073 "20" "20" 1075 1074 bind $page.titlefontsize <<Value>> [itcl::code $this ApplyAxisSettings] 1076 1075 Rappture::Tooltip::for $page.titlefontsize \ … … 1122 1121 8,1 $page.zero -cspan 2 -anchor w \ 1123 1122 8,3 $page.plotpad_l -anchor e \ 1124 8,4 $page.plotpad -fill both -cspan 3 1123 8,4 $page.plotpad -fill both -cspan 3 1125 1124 1126 1125 blt::table configure $page c0 c4 c5 c6 c7 c8 -resize none … … 1135 1134 set _settings($this-legend-position) [$page.position current] 1136 1135 set _settings($this-legend-anchor) [$page.anchor current] 1137 1136 1138 1137 foreach option { -hide -position -anchor -borderwidth } { 1139 1138 SetComponentOption legend $option … … 1212 1211 1213 1212 itcl::body Rappture::XyPrint::ApplyLayoutSettings {} { 1214 foreach opt { -width -height -leftmargin -rightmargin -topmargin 1213 foreach opt { -width -height -leftmargin -rightmargin -topmargin 1215 1214 -bottommargin } { 1216 1215 set old [$_clone cget $opt] … … 1255 1254 1256 1255 set names [$_clone element show] 1257 $itk_component(element_slider) configure -from 1 -to [llength $names] 1256 $itk_component(element_slider) configure -from 1 -to [llength $names] 1258 1257 set state [expr { ([llength $names] < 2) ? "disabled" : "normal" } ] 1259 1258 $page.slider configure -state $state … … 1279 1278 # Axis settings 1280 1279 set page $itk_component(axis_page) 1281 set names [lsort [$_clone axis names]] 1280 set names [lsort [$_clone axis names]] 1282 1281 $itk_component(axis_combo) choices delete 0 end 1283 1282 foreach axis $names { … … 1303 1302 set axis [lindex $axisnames 0] 1304 1303 $itk_component(axis_combo) value $axis 1305 GetAxis 1304 GetAxis 1306 1305 RegeneratePreview 1307 1306 } … … 1316 1315 if { ![file readable $_settingsFile] } { 1317 1316 return; # No file or not readable 1318 } 1317 } 1319 1318 if { [file exists $_oldSettingsFile] } { 1320 1319 file delete $_oldSettingsFile … … 1347 1346 itcl::body Rappture::XyPrint::ResetSettings {} { 1348 1347 set graph $_graph 1349 DestroySettings 1348 DestroySettings 1350 1349 set _graph $graph 1351 1350 CloneGraph $graph … … 1381 1380 # General settings 1382 1381 set length [string length "${this}-"] 1383 append out " array set settings {\n" 1382 append out " array set settings {\n" 1384 1383 foreach item [array names _settings ${this}-*] { 1385 1384 set field [string range $item $length end] … … 1390 1389 append out " [list $field] [list $value]\n" 1391 1390 } 1392 append out " }\n" 1391 append out " }\n" 1393 1392 # Legend font 1394 1393 lappend legendfont $_settings($this-legend-fontfamily) … … 1409 1408 1410 1409 # Layout settings 1411 append out " preview configure" 1412 foreach opt { -width -height -leftmargin -rightmargin -topmargin 1410 append out " preview configure" 1411 foreach opt { -width -height -leftmargin -rightmargin -topmargin 1413 1412 -bottommargin -plotpadx -plotpady } { 1414 1413 set value [$_clone cget $opt] … … 1418 1417 1419 1418 # Legend settings 1420 append out " preview legend configure" 1421 foreach opt { -position -anchor -borderwidth -hide } { 1419 append out " preview legend configure" 1420 foreach opt { -position -anchor -borderwidth -hide } { 1422 1421 set value [$_clone legend cget $opt] 1423 1422 append out " $opt [list $value]" … … 1435 1434 append out " preview element configure $label" 1436 1435 if { [$_clone element type $elem] != "bar" } { 1437 set options { -symbol -color -dashes -label } 1436 set options { -symbol -color -dashes -label } 1438 1437 } else { 1439 set options { -color -label } 1440 } 1441 foreach opt $options { 1438 set options { -color -label } 1439 } 1440 foreach opt $options { 1442 1441 set value [$_clone element cget $elem $opt] 1443 1442 append out " $opt [list $value]" … … 1445 1444 append out " \}\n" 1446 1445 } 1447 1446 1448 1447 # Axis settings 1449 1448 foreach axis [$_clone axis names] { … … 1463 1462 append out " preview marker configure ${axis}-zero -hide $hide\n" 1464 1463 append out " \}\n" 1465 } 1466 1467 append out " preview grid configure" 1464 } 1465 1466 append out " preview grid configure" 1468 1467 append out " -hide \"[$_clone grid cget -hide]\"" 1469 1468 append out " -mapx \"[$_clone grid cget -mapx]\""
Note: See TracChangeset
for help on using the changeset viewer.