| 1 |
#!/usr/bin/perl -w |
| 2 |
###################################################################### |
| 3 |
## Tk utilities module for Atoms 3.0beta9 |
| 4 |
## copyright (c) 1999 Bruce Ravel |
| 5 |
## [email protected] |
| 6 |
## http://feff.phys.washington.edu/~ravel/ |
| 7 |
## |
| 8 |
## The latest version of Atoms can always be found at |
| 9 |
## http://feff.phys.washington.edu/~ravel/software/atoms/ |
| 10 |
## |
| 11 |
## ------------------------------------------------------------------- |
| 12 |
## All rights reserved. This program is free software; you can |
| 13 |
## redistribute it and/or modify it under the same terms as Perl |
| 14 |
## itself. |
| 15 |
## |
| 16 |
## This program is distributed in the hope that it will be useful, |
| 17 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
## Artistic License for more details. |
| 20 |
## ------------------------------------------------------------------- |
| 21 |
###################################################################### |
| 22 |
|
| 23 |
package Xray::Tk::Utils; |
| 24 |
|
| 25 |
use strict; |
| 26 |
use vars qw($VERSION $cvs_info @ISA @EXPORT @EXPORT_OK); |
| 27 |
|
| 28 |
@ISA = qw(Exporter AutoLoader); |
| 29 |
@EXPORT = qw(tkatoms_make_tic tkatoms_fraction2canvas saveplot); |
| 30 |
$cvs_info = '$Id: Utils.pm,v 1.2 2001/09/21 21:47:42 bruce Exp $ '; |
| 31 |
$VERSION = (split(' ', $cvs_info))[2] || 'pre_release'; |
| 32 |
|
| 33 |
## ref to canvas, 'x' or 'y', percentage of full span, height in |
| 34 |
## pixels of tic |
| 35 |
sub tkatoms_make_tic { |
| 36 |
my ($canvas, $width, $height, $axis, $value, $size) = @_; |
| 37 |
my ($x1, $y1, $x2, $y2); |
| 38 |
if ($axis eq 'x') { |
| 39 |
$value *= ($width-36-11); |
| 40 |
$x1 = int($value)+36; |
| 41 |
$y1 = $height-21; |
| 42 |
$x2 = int($value)+36; |
| 43 |
$y2 = $height-21-$size; |
| 44 |
} else { |
| 45 |
$value *= $height-21-11; |
| 46 |
$value = $height-21-11-int($value); |
| 47 |
$x1 = 36; |
| 48 |
$y1 = $value+11; |
| 49 |
$x2 = 36+$size; |
| 50 |
$y2 = $value+11; |
| 51 |
}; |
| 52 |
$$canvas -> createLine($x1, $y1, $x2, $y2); |
| 53 |
1; |
| 54 |
} |
| 55 |
|
| 56 |
sub tkatoms_fraction2canvas { |
| 57 |
my ($width, $height, $x, $y) = @_; |
| 58 |
$x = $x*($width-36-11) + 36; |
| 59 |
$y *= $height-21-11; |
| 60 |
$y = $height-21-11 - $y + 11; |
| 61 |
return (sprintf("%d", $x), sprintf("%d", $y)); |
| 62 |
}; |
| 63 |
|
| 64 |
|
| 65 |
sub saveplot { |
| 66 |
require Xray::Tk::Plotter; |
| 67 |
my $format = $_[0]; |
| 68 |
my $fname; |
| 69 |
if (lc($_[1]) eq 'dafs') { |
| 70 |
$fname = |
| 71 |
join("", 'dafs_', (map {sprintf "%d", $_} @{$::keywords->{'qvec'}}), |
| 72 |
".", lc($format)); |
| 73 |
} elsif (lc($_[1]) eq 'powder') { |
| 74 |
$fname = "powder." . lc($format); |
| 75 |
}; |
| 76 |
&Xray::Tk::Plotter::saveplot($format, $fname); |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
1; |
| 81 |
__END__ |