| 1 |
## -*- cperl -*- |
| 2 |
## |
| 3 |
## This file is part of Athena, copyright (c) 2001-2006 Bruce Ravel |
| 4 |
## |
| 5 |
## This section of the code contains subroutines associated with |
| 6 |
## saving and restoring plotting styles |
| 7 |
|
| 8 |
|
| 9 |
sub plst_save { |
| 10 |
my $name; |
| 11 |
my $label = "Name for this plot style: "; |
| 12 |
my $loop = 1; |
| 13 |
while ($loop) { |
| 14 |
my $ed = get_string($dmode, $label, \$name, \@rename_history); |
| 15 |
$ed -> waitWindow; # the get_string dialog will be |
| 16 |
# destroyed once the user hits ok, |
| 17 |
# then we can move on... |
| 18 |
Echo("Plot style save aborted."), return unless defined($name); |
| 19 |
Echo("Plot style save aborted."), return if ($name =~ /^\s*$/); |
| 20 |
$label = "Name (other than \"default\") for this plot style: ", next if ($name eq 'default'); |
| 21 |
if (exists $plot_styles{$name}) { |
| 22 |
my $dialog = $top -> Dialog(-bitmap => 'questhead', |
| 23 |
-text => "A plot style named \"$name\" already exists.", |
| 24 |
-title => 'Athena: Question...', |
| 25 |
-buttons => ['Overwrite', 'Different name', 'Cancel'], |
| 26 |
-default_button => 'Overwrite'); |
| 27 |
my $response = $dialog->Show(); |
| 28 |
Echo("Plot style save aborted."), return if $response eq 'Cancel'; |
| 29 |
next if $response eq 'Different name'; |
| 30 |
}; |
| 31 |
$loop = 0; |
| 32 |
foreach my $k (keys %plot_features) { |
| 33 |
next unless ($k =~ /^[ekqr](_|ma|mi)/); |
| 34 |
$plot_styles{$name}{$k} = $plot_features{$k}; |
| 35 |
}; |
| 36 |
}; |
| 37 |
my $file = $groups{"Default Parameters"} -> find('athena', 'plotstyles'); |
| 38 |
tied(%plot_styles) -> WriteConfig($file); |
| 39 |
Echo("Saved plot style \"$name\""); |
| 40 |
}; |
| 41 |
|
| 42 |
sub plst_post_menu { |
| 43 |
## figure out where the user clicked |
| 44 |
my $w = shift; |
| 45 |
my $Ev = $w->XEvent; |
| 46 |
delete $w->{'shiftanchor'}; |
| 47 |
my ($X, $Y) = ($Ev->X, $Ev->Y); |
| 48 |
|
| 49 |
my @restore_list; |
| 50 |
my @discard_list; |
| 51 |
foreach my $ps (keys %plot_styles) { |
| 52 |
##next if ($ps eq "___plst___"); |
| 53 |
push @restore_list, [ command => $ps, -command => [\&plst_restore, $ps]]; |
| 54 |
next if ($ps eq 'default'); |
| 55 |
push @discard_list, [ command => $ps, -command => [\&plst_discard, $ps]]; |
| 56 |
}; |
| 57 |
|
| 58 |
$top -> |
| 59 |
Menu(-tearoff=>0, |
| 60 |
-menuitems=>[ |
| 61 |
[ command => "Save plot style", |
| 62 |
-command => \&plst_save], |
| 63 |
[ cascade => "Restore named style", |
| 64 |
-tearoff => 0, |
| 65 |
-menuitems => [@restore_list]], |
| 66 |
[ cascade => "Discard named style", |
| 67 |
-tearoff => 0, |
| 68 |
-menuitems => [@discard_list]], |
| 69 |
[ command => "About plot styles", |
| 70 |
-command => sub{pod_display("ui::styles.pod")}] |
| 71 |
]) |
| 72 |
-> Post($X, $Y); |
| 73 |
$w -> break; |
| 74 |
}; |
| 75 |
|
| 76 |
sub plst_restore { |
| 77 |
foreach my $k (keys %plot_features) { |
| 78 |
next unless ($k =~ /^[ekqr](_|ma|mi)/); |
| 79 |
$plot_features{$k} = $plot_styles{$_[0]}{$k}; |
| 80 |
}; |
| 81 |
#$last_plot='e'; |
| 82 |
#$last_plot_params = [$current, 'marked', 'e', $str]; |
| 83 |
if ($current eq 'Default Parameters') { |
| 84 |
1; # do nothing, probably there are no records in the project |
| 85 |
} elsif (not exists($last_plot_params->[1])) { |
| 86 |
1; # do nothing, probably there are no records in the project |
| 87 |
} elsif ($last_plot_params->[1] eq 'group') { |
| 88 |
autoreplot($last_plot); |
| 89 |
} else { |
| 90 |
SWITCH: { |
| 91 |
&plot_marked_e, last SWITCH if (lc($last_plot) eq 'e'); |
| 92 |
&plot_marked_k, last SWITCH if (lc($last_plot) eq 'k'); |
| 93 |
&plot_marked_r, last SWITCH if (lc($last_plot) eq 'r'); |
| 94 |
&plot_marked_q, last SWITCH if (lc($last_plot) eq 'q'); # , |
| 95 |
}; |
| 96 |
}; |
| 97 |
|
| 98 |
Echo("Restored saved plot style \"$_[0]\""); |
| 99 |
}; |
| 100 |
|
| 101 |
sub plst_discard { |
| 102 |
my $dialog = $top -> Dialog(-bitmap => 'questhead', |
| 103 |
-text => "Are you sure you want to discard plot style \"$_[0]\"?", |
| 104 |
-title => 'Athena: Question...', |
| 105 |
-buttons => ['Discard', 'Cancel'], |
| 106 |
-default_button => 'Discard'); |
| 107 |
my $response = $dialog->Show(); |
| 108 |
Echo("Not discarding \"$_[0]\""), return if $response eq 'Cancel'; |
| 109 |
delete $plot_styles{$_[0]}; |
| 110 |
tied(%plot_styles) -> WriteConfig($groups{"Default Parameters"} -> find('athena', 'plotstyles')); |
| 111 |
Echo("Discarded plot style \"$_[0]\""); |
| 112 |
}; |
| 113 |
|
| 114 |
## END OF PLOT STYLES SUBSECTION |
| 115 |
########################################################################################## |