Debian Codegraph @

attic/scripts/Tk/Molecule.pm

raw
1 #!/usr/bin/perl -w
2 ######################################################################
3 ## Molecule notecard 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/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::Molecule;
24
25 use strict;
26 use vars qw($VERSION $cvs_info @ISA @EXPORT @EXPORT_OK);
27
28 require Exporter;
29
30 @ISA = qw(Exporter AutoLoader);
31 @EXPORT_OK = qw(molecule);
32 $cvs_info = '$Id: Molecule.pm,v 1.7 2001/09/20 17:55:04 bruce Exp $ ';
33 $VERSION = (split(' ', $cvs_info))[2] || 'pre_release';
34
35 use Tk;
36 use Tk::widgets qw/ColorEditor/;
37 use Xray::Atoms qw/number/;
38 use Xray::ATP;
39 ## File ##
40 use Xray::File;
41 use File::Basename qw(dirname);
42
43 ## ------- set up some variables ---------------------------------
44 my ($e, $x, $y, $z) = (0,1,2,3);
45 ## File ##
46 my $molecule = Xray::File -> new();
47 my $core_index = 0;
48 my @site_entry;
49 my @skip_list;
50 my $selected_atp;
51 my %mol_values = ('edge' => '', 'rmax' => 0, 'atp' => 'molecule6');
52 my ($ecenter, $xcenter, $ycenter, $zcenter);
53 my ($skip_window, $format_window);
54 my $is_windows = (($^O eq 'MSWin32') or ($^O eq 'cygwin'));
55
56 my ($sites_table, $mol_frame, %pages, $menubar, $rmax_box);
57
58 sub molecule {
59 #$mol_frame = $_[0] -> Frame() -> pack(-fill=>'x');
60 $mol_frame = $::pages{Molecule} -> Frame() -> pack(-fill=>'x');
61
62 ## ------- Menubar -----------------------------------------------
63 $menubar = $mol_frame -> Frame(-borderwidth=>2, -relief=>'ridge',)
64 -> pack(-anchor=>'nw', -fill=>'x', -pady=>4, -padx=>4);
65 my $file_menu = $menubar ->
66 Menubutton(-text=>$$::labels{'file'}, @::menu_args) ->
67 pack(-side=>'left');
68 &::manage($file_menu, "menu");
69
70 my $this;
71 $this = $file_menu ->
72 command(-label=>$$::labels{'load_data'}, @::menu_args,
73 -command=>[\&read_data, $::top], -accelerator=>'Control+l',);
74 &::manage($this, "menu");
75 ## my $sep = $file_menu -> separator();
76 ## &::manage($sep, "separator");
77 ## $this = $file_menu -> command(@::apt_args);
78 ## &::manage($this, "menu");
79 $sep = $file_menu -> separator();
80 &::manage($sep, "separator");
81 $this = $file_menu ->
82 command(-label=>$$::labels{'quit'}, @::menu_args,
83 -command=>sub{exit}, -accelerator=>'Control+q',);
84 &::manage($this, "menu");
85
86 my $clear_menu = $menubar ->
87 Menubutton(-text=>$$::labels{'clear_menu'}, @::menu_args) ->
88 pack(-side=>'left');
89 &::manage($clear_menu, "menu");
90 $this = $clear_menu
91 -> command(-label=>$$::labels{'clear_molecule'}, @::menu_args,
92 -command=>\&clear_molecule);
93 &::manage($this, "menu");
94 $this = $clear_menu
95 -> command(-label=>$$::labels{'clear_lattice'}, @::menu_args,
96 -command=>\&::clear_lattice);
97 &::manage($this, "menu");
98 $this = $clear_menu
99 -> command(-label=>$$::labels{'clear_all'}, @::menu_args,
100 -command=>sub{&clear_molecule; &::clear_lattice});
101 &::manage($this, "menu");
102
103 my $skip_menu = $menubar ->
104 Menubutton(-text=>$$::labels{'skip'}, @::menu_args) -> pack(-side=>'left');
105 &::manage($skip_menu, "menu");
106 $this = $skip_menu ->
107 command(-label=>$$::labels{'skip_rules'}, @::menu_args,
108 -command=>[\&skip_by, $mol_frame], );
109 &::manage($this, "menu");
110 $this = $skip_menu ->
111 command(-label=>$$::labels{'unselect_skip'}, @::menu_args,
112 -command=>sub{map {$$_{'skip'}->deselect;} @site_entry});
113 &::manage($this, "menu");
114
115
116 my $help_menu = $menubar ->
117 Menubutton(@::help_menubutton) -> pack(-side=>'right');
118 &::set_help_menu($help_menu);
119
120 my $pref_menu = $menubar ->
121 Menubutton(@::pref_menubutton) -> pack(-side=>'right');
122 &::set_pref_menu($pref_menu);
123
124 &::manage($help_menu, "menu");
125 &::manage($pref_menu, "menu");
126
127 my $top_frame = $mol_frame -> Frame(-relief=>'groove', -borderwidth=>2)
128 -> pack(-pady=>4, -side=>'top');
129 my $mol_label = $top_frame ->
130 Label(-text=>$$::labels{'molecule_description'}, @::header_args, ) ->
131 pack();
132 &::manage($mol_label, "header");
133
134 ## ------- Widgets Frame -----------------------------------------
135 my $params_frame = $mol_frame -> Frame(-relief=>'flat', -border=>2)
136 -> pack(-side=>'left', -fill=>'both', -pady=>4, -padx=>4);
137
138 my $run_button = $params_frame ->
139 Button(-text=>$$::labels{'run_molecule'}, @::button_args, -borderwidth=>4,
140 -command=>\&run_molecule, )
141 -> pack(-side=>'top');
142 $::balloon->attach($run_button, -msg=>$$::help{'run_mol'},);
143 &::manage($run_button, "button");
144
145 my $rmax_frame = $params_frame -> Frame()
146 -> pack(-fill=>'both', -expand=>1);
147 my $rmax_label = $rmax_frame ->
148 Label(-text=>$$::labels{rmax}, @::label_args, -anchor=>'w') ->
149 pack(-side=>'left');
150 &::manage($rmax_label, "label");
151 $::balloon->attach($rmax_label, -msg=>$$::help{'rmax'},);
152 $rmax_box = $rmax_frame ->
153 Entry(-width=>9, @::entry_args,
154 -textvariable=>\$mol_values{'rmax'}) ->
155 pack(-side=>'left');
156 &::manage($rmax_box, "entry");
157
158 my $atp_frame = $params_frame -> Frame()
159 -> pack(-side=>'bottom', -fill=>'both');
160 my $atp_label = $atp_frame ->
161 Label(-text=>$$::labels{outfiles}, @::label_args)
162 -> pack(-side=>'top');
163 $::balloon->attach($atp_label, -msg=>$$::help{'atp_mol'},);
164 &::manage($atp_label, "label");
165 my $atp_button = $atp_frame
166 -> Optionmenu(-textvariable => \$mol_values{'atp'},
167 -background => $::colors{'entry'},
168 -activeforeground => $::colors{'label'},
169 -activebackground => $::colors{'entry'},
170 -width=>15, -font=>$::fonts{'label'}, -relief=>'groove')
171 -> pack(-side=>'left');
172 &::manage($atp_button, "menu");
173 foreach my $e (@::atpfiles) {
174 if ($e =~ /^molec/i) {
175 my $this = $atp_button -> command(-label => $e, @::menu_args,
176 -command=>sub{$mol_values{'atp'}=$e;});
177 &::manage($this, "menu");
178 };
179 };
180
181
182 ## ------- Sites Table -------------------------------------------
183 my $sites_frame = $mol_frame -> Frame(-border=>2, -relief=>'groove')
184 -> pack(-side=>'left');
185 $sites_table = $sites_frame
186 -> Table(-fixedrows => 1,
187 -rows => 7,
188 -columns => 1,
189 -scrollbars => 'e',
190 -borderwidth=>0,)
191 -> pack(-side=>'left');
192 $sites_table -> put(0, 0, &site_labels(\$sites_table));
193 foreach my $i (0 .. 14) {
194 $sites_table -> put($i+1, 0, &site_line(\$sites_table, $i));
195 };
196 };
197
198 ## ----- functions for sites table -----------------------------------
199
200 ## make a frame and populate it with site information. Return that frame.
201 sub site_line {
202 my ($parent, $which) = @_;
203 my $frame = $$parent -> Frame();
204 my $site_label = $frame -> Label(-text => $which+1, @::header_args,
205 -font => $::fonts{entry},
206 -width => 4,
207 -justify=>'right', -anchor=>'e' )
208 -> pack(-side=>'left');
209 &::manage($site_label, "header");
210 $site_entry[$which]{'core'} = $frame ->
211 Radiobutton(-value => $which,
212 -selectcolor => $::colors{radio},
213 -variable => \$core_index,
214 -command => sub{$core_index = $which;}, )
215 -> pack(-side=>'left');
216 &::manage($site_entry[$which]{'core'}, "radio");
217 my %width = ('elem'=>5, 'x'=>9, 'y'=>9, 'z'=>9, 'tag'=>10);
218 foreach my $coord ('elem', 'x', 'y', 'z', 'tag') {
219 $site_entry[$which]{$coord} = $frame
220 -> Entry(-width=>$width{$coord}, @::entry_args,)
221 -> pack(-side=>'left');
222 &::manage($site_entry[$which]{$coord}, "entry");
223 ($coord =~ /^[xyz]$/) and $site_entry[$which]{$coord} -> insert(0,0);
224 $site_entry[$which]{$coord} ->
225 bind("<$::meta{unused_modifier}-Key-Right>",
226 [\&::site_navigate, \$sites_table, \@site_entry,
227 $which, $coord, 0, 0]);
228 $site_entry[$which]{$coord} ->
229 bind("<$::meta{unused_modifier}-Key-Left>",
230 [\&::site_navigate, \$sites_table, \@site_entry,
231 $which, $coord, 1, 0]);
232 $site_entry[$which]{$coord} ->
233 bind("<$::meta{unused_modifier}-Key-Up>",
234 [\&::site_navigate, \$sites_table, \@site_entry,
235 $which, $coord, 0, 1]);
236 $site_entry[$which]{$coord} ->
237 bind("<$::meta{unused_modifier}-Key-Down>",
238 [\&::site_navigate, \$sites_table, \@site_entry,
239 $which, $coord, 1, 1]);
240 };
241 $site_entry[$which]{'skip'} = $frame ->
242 Checkbutton(-selectcolor => $::colors{radio},
243 -variable => \$skip_list[$which], )
244 -> pack(-side=>'left');
245 &::manage($site_entry[$which]{'skip'}, "check");
246 $skip_list[$which] = 0;
247 return $frame;
248 };
249
250 ## This subroutine writes out the column labels at the top of the
251 ## sites list.
252 sub site_labels {
253 my $parent = $_[0];
254 my $frame = $$parent -> Frame() -> pack();
255 my $site_label = $frame -> Label(-width=>4,)
256 -> pack(-side=>'left');
257 &::manage($site_label, "label");
258 my %width = ('core'=> 4, 'elem'=>5, 'x'=>9, 'y'=>9,
259 'z'=>9, 'tag'=>10, 'skip'=>5);
260 foreach my $coord ('core', 'elem', 'x', 'y', 'z', 'tag', 'skip') {
261 my $field = $frame
262 -> Label(-text=>$$::labels{$coord}, -width=>$width{$coord},
263 -foreground=>$::colors{label},
264 -font=>$::fonts{entry}, )
265 -> pack(-side=>'left');
266 &::manage($field, "label");
267 $::balloon->attach($field, -msg=>$$::help{'mol_'.$coord},);
268 };
269 return $frame;
270 };
271
272 ## ----- functions for reading input data ----------------------------
273
274 ## read an external data file. This will have to be replaced with an
275 ## object oriented scheme..
276 sub read_data {
277 require Cwd;
278 local $Tk::FBox::a;
279 local $Tk::FBox::b;
280 my $path = $::default_filepath || Cwd::cwd();
281 my $types = [['All Files', '*', ],];
282 $inputfile = $top -> getOpenFile(-filetypes=>$types,
283 #(not $is_windows) ?
284 # (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () ,
285 -initialdir=>$path,
286 -title => $$::labels{'file_dialog'});
287 return 0 unless $inputfile;
288 $::default_filepath = dirname($inputfile);
289 &clear_molecule;
290
291 my $filetype;
292 TYPE: {
293 $filetype='alchemy', last TYPE if ($inputfile =~ /\.alc$/);
294 $filetype='xyz', last TYPE if ($inputfile =~ /\.xyz$/);
295 $filetype='PDB', last TYPE if ($inputfile =~ /\.pdb$/);
296 $filetype='generic';
297 };
298 if (not Exists $format_window) {
299 $format_window = $mol_frame -> Toplevel(-class=>'horae');
300 $format_window -> title($$::labels{'mol_format'});
301 $format_window -> resizable(0,0);
302 my $label = $format_window ->
303 Label(-text=>$$::labels{'mol_format_explain'},
304 @::header_args) -> pack(-side=>'top');
305 &::manage($label, "header");
306 foreach my $ftype ('generic', 'xyz', 'alchemy', 'PDB') {
307 my $frame = $format_window ->
308 Frame(-borderwidth=>2, -relief=>'ridge') ->
309 pack(-expand=>1, -fill=>'x', -side=>'top');
310 my $choice = $frame ->
311 Radiobutton(-text => $ftype,
312 -value => $ftype,
313 -selectcolor => $::colors{radio},
314 -variable => \$filetype,
315 -command => sub{$filetype = $ftype;},
316 )
317 -> pack(-side=>'left');
318 &::manage($choice, "radio");
319 };
320 my $frame = $format_window ->
321 Frame(-borderwidth=>2, -relief=>'ridge') ->
322 pack(-expand=>1, -fill=>'x', -side=>'top');
323 my $button = $frame -> Button(-text=>$$::labels{'ok'}, @::button_args,
324 -command=>sub{
325 $molecule -> read($inputfile, $filetype);
326 &fill_sites($molecule->{'coordinates'});
327 $format_window->withdraw})
328 -> pack(-side=>'left');
329 &::manage($button, "button");
330 $button = $frame -> Button(-text=>$$::labels{'dismiss'}, @::button_args,
331 -command=>sub{$format_window->withdraw})
332 -> pack(-side=>'right');
333 &::manage($button, "button");
334 } else {
335 $format_window->deiconify;
336 $format_window->raise;
337 };
338
339 ## open DAT, $inputfile or die $!;
340 ## my @cluster;
341 ## while (<DAT>) {
342 ## next if (/^\s*$/); # skip blank lines
343 ## next if (/^\s*\#/); # skip comment lines
344 ## chomp;
345 ## my @line = split;
346 ## my ($tag, $xx, $yy, $zz) = ($line[$e], $line[$x], $line[$y], $line[$z]);
347 ## ##($xx, $yy, $zz) = map {$scale*$_} ($xx, $yy, $zz);
348 ## (my $ee = $tag) =~ s/(.+)\([^\)]+\)/$1/;
349 ## ## load data into a temporary structure
350 ## push @cluster, [$xx, $yy, $zz, $ee, $tag];
351 ## };
352 ## close DAT;
353 ## &clear_molecule;
354 ## &fill_sites(\@cluster);
355 };
356
357 #sub add_site(\$sites_table, $na);
358
359 ## fill up the sites table with the values read from the data file
360 sub fill_sites {
361 my $r_clus = $_[0];
362 my $space;
363 my $nw = $#site_entry;
364 my $na = 0;
365 foreach my $s (@$r_clus) {
366 if ($na > $nw) {
367 $sites_table -> put($na+1, 0, &site_line(\$sites_table, $na));
368 };
369 $site_entry[$na]{'elem'} -> insert(0, $$s[3]);
370 $space = " " x (9-length($$s[0])); # right justify
371 $site_entry[$na]{'x'} -> insert(0, $space.$$s[0]);
372 $space = " " x (9-length($$s[1]));
373 $site_entry[$na]{'y'} -> insert(0, $space.$$s[1]);
374 $space = " " x (9-length($$s[2]));
375 $site_entry[$na]{'z'} -> insert(0, $space.$$s[2]);
376 ## make sure tags are unique
377 my $tag = (lc($$s[3]) eq lc($$s[4])) ? $$s[3] . "_" . ($na+1) : $$s[4];
378 $site_entry[$na]{'tag'} -> insert(0, $tag);
379 ++$na;
380 };
381 $site_entry[0]{'core'} -> select(); # select first atom
382 };
383
384
385 sub run_molecule {
386 ## fetch the coordinates of the central atom
387 my ($ecenter, $xcenter, $ycenter, $zcenter, $elcenter) =
388 ($site_entry[$core_index]{'tag'} -> get(),
389 $site_entry[$core_index]{'x'} -> get(),
390 $site_entry[$core_index]{'y'} -> get(),
391 $site_entry[$core_index]{'z'} -> get(),
392 $site_entry[$core_index]{'elem'} -> get());
393 ($ecenter) or ($ecenter = $elcenter."_".$core_index);
394 ## build a sites array
395 my $nsites = -1;
396 my $i = -1;
397 my @cluster;
398 my @sites;
399 undef $::keywords;
400 $::keywords = Xray::Atoms -> new();
401 ## fetch rmax indicated on the molecule notecard
402 $mol_values{'rmax'} = $rmax_box->get();
403 $mol_values{'rmax'} = number($mol_values{'rmax'});
404 $mol_values{'rmax'} = sprintf "%8.5f", $mol_values{'rmax'};
405 my $rsq = ($mol_values{'rmax'} > 0.01) ? $mol_values{'rmax'}**2 : 100000;
406
407 $Xray::Xtal::Site::molecule = 1;
408 foreach my $s (@site_entry) {
409 my $el = $$s{'elem'} -> get();
410 ++$i;
411 next if ($el =~ /^\s*$/);
412 next if $skip_list[$i];
413 ++$nsites;
414 $sites[$nsites] = Xray::Xtal::Site -> new();
415 my ($x, $y, $z, $e, $t) = ($$s{'x'} -> get(),
416 $$s{'y'} -> get(),
417 $$s{'z'} -> get(),
418 $$s{'elem'} -> get(),
419 $$s{'tag'} -> get());
420 ($t) or ($t = $e."_".$i);
421 ($x, $y, $z) = ($x-$xcenter, $y-$ycenter, $z-$zcenter);
422 $sites[$nsites] -> make(Element=>$e, Tag=>$t, X=>$x, Y=>$y, Z=>$z,
423 Occupancy=>1);
424 my $r_squared = $x**2 + $y**2 + $z**2;
425 $r_squared = sprintf "%9.5f", $r_squared;
426 ($r_squared <= $rsq) and
427 push(@cluster, [$x, $y, $z, \$sites[$nsites], $r_squared,
428 sprintf("%9.5f", $x),
429 sprintf("%9.5f", $y),
430 sprintf("%9.5f", $z)]);
431 #print join(" | ", @{$cluster[$nsites]}[4..7], $/);
432 };
433 unless ($nsites > 0) {
434 return &::tkatoms_dialog(\$::top, 'no_molecule_data', 'warning');
435 };
436
437 @cluster = sort {
438 ($a->[4] cmp $b->[4]) # sort by distance squared or ...
439 or
440 ($a->[7] cmp $b->[7]) # by z value or ...
441 or
442 ($a->[6] cmp $b->[6]) # by y value or ...
443 or
444 ($a->[5] cmp $b->[5]); # by x value
445 } @cluster;
446
447 ($mol_values{'rmax'} < 0.01) and
448 $mol_values{'rmax'} = 1.1 * sqrt($cluster[$#cluster] -> [4]);
449 $::keywords -> make('rmax' => $mol_values{'rmax'});
450
451 ## fetch the title lines and edge from the crystallography panel
452 my $eol = $/ . "+"; # split title text into lines
453 my @t = split /$eol/, $::atoms_widgets{'title'}->get(qw/1.0 end/);
454 $::keywords->{'title'} = [];
455 foreach my $t (@t) {
456 $::keywords->make('title'=>$t);
457 };
458 my $ed = $::atoms_values{'edge'};
459
460 ## make a trivial cell to keep parse_atp happy and set some other keywords
461 my $cell = Xray::Xtal::Cell -> new();
462 $cell -> make('Space_group' => 'p 1');
463 map { $cell->make( $_=>1 ) } ('a', 'b', 'c');
464 map { $cell->make( $_=>90 ) } ('alpha', 'beta', 'gamma');
465 $::keywords -> make('identity'=>"the Molecule notecard $VERSION");
466 $::keywords -> make('quiet'=> 0);
467 $::keywords -> make('core' => $ecenter);
468 my $z = Chemistry::Elements::get_Z($elcenter);
469 if ($ed) {
470 $::keywords -> make('edge' => $ed);
471 } else {
472 $::keywords -> make('edge' => 'K');
473 ($z > 57) and $::keywords -> make('edge' => 'L3');
474 };
475 $cell -> populate(\@sites);
476 $Xray::Xtal::Site::molecule = 0;
477
478 ## generate and display the output file
479 my ($contents, @neutral);
480 my ($default_name, $is_feff) =
481 parse_atp($mol_values{'atp'}, $cell, $::keywords, \@cluster,
482 \@::neutral, \$contents);
483
484 &::display_in_frame($::top, \$contents, $mol_values{'atp'},
485 $default_name, $is_feff);
486 };
487
488
489 ## this does not currently reduce the number of rows back down to
490 ## 15. getting rid of the rows works, but then I don't know how to
491 ## shrink the table back down to 15.
492 sub clear_molecule {
493 $core_index = 0;
494 foreach my $s (@site_entry) {
495 map {$$s{$_} -> delete(qw/0 end/)} (qw/elem x y z tag/);
496 $$s{'skip'} -> deselect;
497 };
498 ## my ($switch, $i, $which) = (0, 0, 0);
499 ## foreach my $w ($sites_table->children()) {
500 ## if ("$w" =~ /scrollbar/i) {
501 ## $switch = 1;
502 ## $which = $i;
503 ## next;
504 ## };
505 ## next unless $switch;
506 ## $w->UnmanageGeometry;
507 ## $sites_table -> Tk::Table::LostSlave($w);
508 ## ++$i;
509 ## };
510 ## $#site_entry = $which;
511 };
512
513
514 ## ----- subroutines for entering and applying skip rule ------------
515 sub skip_by {
516 my $parent = $_[0];
517 if (not Exists $skip_window) {
518 $skip_window = $parent -> Toplevel(-class=>'horae');
519 $skip_window ->title($$::labels{'mol_skip_rules'});
520 $skip_window->resizable(0,0);
521 ##-- explanation
522 my $label_frame = $skip_window -> Frame() -> pack();
523 my $this;
524 $this = $label_frame -> Label(-text=>$$::labels{'explain_skip'},
525 @::header_args)
526 -> pack();
527 &::manage($this, "header");
528 ##-- skip rules
529 my $widgets_frame = $skip_window -> Frame(-borderwidth=>2, -relief=>'ridge')
530 -> pack(-padx=>4, -pady=>4);
531 my (%check, %entry, %relation);
532 my %rel = ('x'=>'>', 'y'=>'>', 'z'=>'>') ;
533 my $r = 0;
534 foreach my $c (qw/elements tags/) { # ---- elem,tag -----
535 $check{$c} = 0;
536 $rel{$c} = '';
537 $this = $widgets_frame ->
538 Checkbutton(-selectcolor => $::colors{radio},
539 -foreground=> $::colors{'label'},
540 -text=>$$::labels{'skip_sites'} . " " .
541 $$::labels{'skip_'.$c},
542 -variable=>\$check{$c}, )
543 -> grid(-column=>0, -row=>$r, -sticky=>'w');
544 &::manage($this, "check");
545 $this = $widgets_frame -> Label(-text=>$$::labels{'skip_matching'},
546 -foreground=> $::colors{'label'}, )
547 -> grid(-column=>1, -row=>$r, -sticky=>'w');
548 &::manage($this, "label");
549 $this = $entry{$c} = $widgets_frame ->
550 Entry(-width=>10, @::entry_args)
551 -> grid(-column=>2, -row=>$r, -sticky=>'w');
552 &::manage($this, "entry");
553 $this = $widgets_frame -> Label(-text=>$$::labels{'skip_re'},
554 -foreground=> $::colors{'label'}, )
555 -> grid(-column=>3, -row=>$r++, -sticky=>'w');
556 &::manage($this, "label");
557 };
558 foreach my $c (qw/x y z/) { # ---- x,y,z -----
559 $check{$c} = 0;
560 $this = $widgets_frame ->
561 Checkbutton(-selectcolor => $::colors{radio},
562 -foreground => $::colors{'label'},
563 -text =>$$::labels{'skip_sites'} . " $c",
564 -variable =>\$check{$c}, )
565 -> grid(-column=>0, -row=>$r, -sticky=>'w');
566 &::manage($this, "check");
567 $this = $relation{$c} = $widgets_frame ->
568 Optionmenu(-textvariable => \$rel{$c},
569 -foreground => $::colors{'label'},
570 -background => $::colors{'entry'},
571 -activeforeground => $::colors{'label'},
572 -activebackground => $::colors{'entry'},
573 -width=>3, -font=>$::fonts{'label'}, -relief=>'groove')
574 -> grid(-column=>1, -row=>$r);
575 &::manage($this, "menu");
576 foreach my $e (qw/> >= == <= < /) {
577 $this = $relation{$c} -> command(-label => $e, @::menu_args,
578 -command=>sub{$rel{$c}=$e;});
579 &::manage($this, "menu");
580 };
581 $this = $entry{$c} = $widgets_frame ->
582 Entry(-width=>10, @::entry_args)
583 -> grid(-column=>2, -row=>$r, -sticky=>'w');
584 &::manage($this, "entry");
585 $this = $widgets_frame -> Label(-text=>$$::labels{'skip_numeric'},
586 -foreground=> $::colors{'label'}, )
587 -> grid(-column=>3, -row=>$r++, -sticky=>'w');
588 &::manage($this, "label");
589 };
590 ##-- OK button
591 my $buttons_frame = $skip_window -> Frame() -> pack(-fill=>'x', -expand=>1);
592 $this = $buttons_frame ->
593 Button(-text=>$$::labels{'dismiss'}, @::button_args,
594 -command=>sub{$skip_window->withdraw; })
595 -> pack(-side=>'right', -padx=>4);
596 &::manage($this, "button");
597 $::balloon->attach($this, -msg=>$$::help{'dismiss_skip'},);
598 $this = $buttons_frame ->
599 Button(-text=>$$::labels{'apply'}, @::button_args,
600 -command=>sub{&apply_skip(\%check, \%rel, \%entry);})
601 -> pack(-side=>'right', -padx=>10);
602 &::manage($this, "button");
603 $::balloon->attach($this, -msg=>$$::help{'apply_skip'},);
604 } else {
605 $skip_window->deiconify;
606 $skip_window->raise;
607 };
608 };
609
610 sub apply_skip {
611 my ($r_check, $r_rel, $r_entry) = @_;
612 foreach my $k (qw/elements tags/) { # regular expressions
613 next unless ($$r_check{$k});
614 my $skip_re = $$r_entry{$k} -> get();
615 next unless $skip_re;
616 my $t = ($k eq 'elements') ? 'elem' : substr($k,0,-1);
617 foreach my $s (@site_entry) {
618 ($$s{$t}->get() =~ /$skip_re/i) and $$s{'skip'} -> select();
619 };
620 };
621 foreach my $k (qw/x y z/) { # simple math relations
622 next unless ($$r_check{$k});
623 my $bound = $$r_entry{$k} -> get();
624 ($bound eq "0") and $bound = "0.0";
625 next unless $bound;
626 foreach my $s (@site_entry) {
627 my $val = $$s{$k}->get();
628 my $string = join(" ", $val, $$r_rel{$k}, $bound);
629 eval $string and $$s{'skip'} -> select();
630 };
631 };
632 };
633
634
635 1;
636 __END__