File: Reference.pm

package info (click to toggle)
libdemeter-perl 0.9.27%2Bds6-9
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 74,028 kB
  • sloc: perl: 73,233; python: 2,196; makefile: 1,999; ansic: 1,368; lisp: 454; sh: 74
file content (224 lines) | stat: -rw-r--r-- 7,120 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package Demeter::UI::Athena::ColumnSelection::Reference;

use strict;
use warnings;

use Wx qw( :everything );
use base 'Wx::Panel';
use Wx::Event qw(EVT_CHECKBOX EVT_RADIOBUTTON EVT_BUTTON);
use Wx::Perl::TextValidator;

sub new {
  my ($class, $parent, $data) = @_;
  my $this = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxMAXIMIZE_BOX );
  $this->{numerator}   ||= 3;
  $this->{denominator} ||= 0;
  $this->{reference}     = q{};

  my $box = Wx::BoxSizer->new( wxVERTICAL );
  my $hbox = Wx::BoxSizer->new( wxHORIZONTAL );
  $box -> Add($hbox, 0, wxALL, 0);

  my @cols = split(" ", $data->columns);

  $this->{do_ref} = Wx::CheckBox->new($this, -1, "Import reference channel");
  $hbox -> Add($this->{do_ref}, 0, wxALL, 7);
  $hbox -> Add(1,1,1);
  $this->{controls} = [];
  EVT_CHECKBOX($this, $this->{do_ref}, sub{EnableReference(@_, $data)});

  my $columnbox = Wx::ScrolledWindow->new($this, -1, wxDefaultPosition, [300, -1], wxHSCROLL);
  $columnbox->SetScrollbars(30, 0, 50, 0);
  $box -> Add($columnbox, 0, wxGROW|wxALL, 10);
  push @{$this->{controls}}, $columnbox;

  my $gbs = Wx::GridBagSizer->new( 3, 3 );

  my $label    = Wx::StaticText->new($columnbox, -1, 'Numerator');
  $gbs -> Add($label, Wx::GBPosition->new(1,0));
  push @{$this->{controls}}, $label;
  $label    = Wx::StaticText->new($columnbox, -1, 'Denominator');
  $gbs -> Add($label, Wx::GBPosition->new(2,0));
  push @{$this->{controls}}, $label;


  my $count = 1;
  my @args = (wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
  foreach my $c (@cols) {
    my $i = $count;
    $label    = Wx::StaticText->new($columnbox, -1, $c);
    $gbs -> Add($label, Wx::GBPosition->new(0,$count));
    push @{$this->{controls}}, $label;

    $this->{'n'.$i} = Wx::CheckBox->new($columnbox, -1, q{}, @args);
    $gbs -> Add($this->{'n'.$i}, Wx::GBPosition->new(1,$count));
    $this->{'n'.$i} -> SetValue($i==$this->{numerator});
    push @{$this->{controls}}, $this->{'n'.$i};
    EVT_CHECKBOX($parent, $this->{'n'.$i}, sub{OnNumerClick(@_, $this, $i, $#cols)});
    @args = ();
    ++$count;
  };

  $count = 1;
  #@args = (wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
  foreach my $c (@cols) {
    my $i = $count;
    $this->{'d'.$i} = Wx::CheckBox->new($columnbox, -1, q{}); #, @args);
    $gbs -> Add($this->{'d'.$i}, Wx::GBPosition->new(2,$count));
    $this->{'d'.$i} -> SetValue($i==$this->{denominator});
    push @{$this->{controls}}, $this->{'d'.$i};
    EVT_CHECKBOX($parent, $this->{'d'.$i}, sub{OnDenomClick(@_, $this, $i, $#cols)});
    @args = ();
    ++$count;
  };

  $columnbox->SetSizer($gbs);

  $hbox = Wx::BoxSizer->new( wxHORIZONTAL );

  $this->{replot} = Wx::Button->new($this, -1, "Replot reference", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
  #$this->{clear}  = Wx::Button->new($this, -1, "Clear denominator");
  $this->{ln}     = Wx::CheckBox->new($this, -1, "Natural log");
  $this->{same}   = Wx::CheckBox->new($this, -1, "Same element");
  $hbox -> Add($this->{replot}, 0, wxLEFT|wxRIGHT, 5);
  #$hbox -> Add($this->{clear},  0, wxGROW|wxLEFT|wxRIGHT, 5);
  $hbox -> Add($this->{ln},     0, wxGROW|wxLEFT|wxRIGHT, 5);
  $hbox -> Add($this->{same},   0, wxGROW|wxLEFT|wxRIGHT, 5);
  push @{$this->{controls}}, $this->{replot};
  #push @{$this->{controls}}, $this->{clear};
  push @{$this->{controls}}, $this->{ln};
  push @{$this->{controls}}, $this->{same};
  #EVT_BUTTON($this, $this->{clear}, sub{  $this->clear_denominator($parent, $#cols) });
  EVT_CHECKBOX($this, $this->{ln}, sub{OnLnClick(@_, $this)} );
  EVT_BUTTON($this, $this->{replot}, sub{  $this->display_plot($parent) });

  $this->{ln}   -> SetValue(1);
  $this->{same} -> SetValue(1);

  $box -> Add($hbox, 0, wxALL, 3);

  EnableReference($this, 0, $data);

  $this->SetSizerAndFit($box);
  return $this;
};

sub EnableReference {
  #print join("|", caller), $/;
  my ($this, $event, $data) = @_;
  my $onoff = $this->{do_ref}->GetValue;
  $_->Enable($onoff) foreach @{$this->{controls}};
  if ($onoff) {
    $this->{reference} ||= Demeter::Data->new(file => $data->file,
					      name => "  Ref " . $data->name);
    $this->{reference} -> set(energy	  => $data->energy,
			      numerator	  => '$'.$this->{numerator},
			      denominator => ($this->{denominator}) ?'$'.$this->{denominator} : 1,
			      ln          => $this->{ln}->GetValue,
			      is_col	  => 1,);
    $this->{reference} -> display(1);
  };
};

sub OnLnClick {
  my ($nb, $event, $this) = @_;
  $this->{reference} -> ln($this->{ln}->GetValue);
  $this->display_plot($nb->GetParent);
};
sub OnNumerClick {
  my ($nb, $event, $this, $i, $n) = @_;
  foreach my $j (1 .. $n+1) {
    next if ($j == $i);
    $this->{'n'.$j} -> SetValue(0);
  };
  if ($this->{'n'.$i}->GetValue) {
    $this->{numerator}   = $i;
    $this->{reference}  -> numerator('$'.$i);
  } else {
    $this->{numerator}   = 0;
    $this->{reference}  -> numerator('1');
  };
  $this->display_plot($nb);
};
sub OnDenomClick {
  my ($nb, $event, $this, $i, $n) = @_;
  foreach my $j (1 .. $n+1) {
    next if ($j == $i);
    $this->{'d'.$j} -> SetValue(0);
  };
  if ($this->{'d'.$i}->GetValue) {
    $this->{denominator} = $i;
    $this->{reference}  -> denominator('$'.$i);
  } else {
    $this->{denominator} = 0;
    $this->{reference}  -> denominator('1');
  };
  $this->display_plot($nb);
};

#sub clear_denominator {
#  my ($this, $parent, $n) = @_;
#  foreach my $i (1 .. $n+1) {
#    $this->{'d'.$i} -> SetValue(0);
#  };
#  $this->{reference} -> denominator('1');
#  $this->display_plot($parent);
#};

sub display_plot {
  my ($this, $parent) = @_;
  my $kev = $parent->GetParent->GetParent->{units}->GetSelection;
  $this->{reference}  -> set(datatype=>'xmu', update_columns=>1, is_col=>1, is_kev=>$kev);
  $this->{reference}  -> _update('normalize');
  $this->{reference}  -> po -> start_plot;
  $this->{reference}  -> po -> set(e_mu=>1, e_markers=>0, e_bkg=>0, e_pre=>0, e_post=>0, e_norm=>0, e_der=>0, e_sec=>0, e_i0=>0, e_signal=>0, e_smooth=>0);
  $this->{reference}  -> plot('e');
};


1;


=head1 NAME

Demeter::UI::Athena::ColumnSelection::Preprocess - column selection reference spectrum controls

=head1 VERSION

This documentation refers to Demeter version 0.9.26.

=head1 SYNOPSIS

This module provides controls for specifying a reference in Athena's
column selection dialog

=head1 DEPENDENCIES

Demeter's dependencies are in the F<Build.PL> file.

=head1 BUGS AND LIMITATIONS

Please report problems to the Ifeffit Mailing List
(L<http://cars9.uchicago.edu/mailman/listinfo/ifeffit/>)

Patches are welcome.

=head1 AUTHOR

Bruce Ravel (L<http://bruceravel.github.io/home>)

L<http://bruceravel.github.io/demeter/>

=head1 LICENCE AND COPYRIGHT

Copyright (c) 2006-2019 Bruce Ravel (L<http://bruceravel.github.io/home>). All
rights reserved.

This module is free software; you can redistribute it and/or modify it
under the same terms as Perl itself. See L<perlgpl>.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

=cut