Debian Codegraph @

lib/Xray/Tk/SGB.pm

raw
1 #!/usr/bin/perl -w
2 ######################################################################
3 ## Space Group Browser for TkAtoms using Atoms version 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 ## $Id: SGB.pm,v 1.3 1999/05/19 22:23:25 bruce Exp $
23 ######################################################################
24 ##
25 ## This is a perl module supplying the space group browser widget.
26 ## This was developed for use with TkAtoms.
27 ##
28 ## To use the space group browser, insert this in the appropriate
29 ## place in the main program:
30 ## use Xray::Tk::SGB;
31 ## $browser = $top -> SGB(-SpaceWidget=>\$space_field);
32 ## $browser -> configure(@sgb_args);
33 ## $browser -> Show;
34 ##
35 ## $top is the top level widget. \$space_field is a reference to the
36 ## widget into which the browser should insert a space group symbol.
37 ## Typically this is an Entry widget.
38 ##
39 ######################################################################
40 ##
41 ## To do:
42 ##
43 ######################################################################
44 ## Code:
45
46 =head1 NAME
47
48 Xray::Tk::SGB - A widget for browsing space group symbols
49
50 =head1 DESCRIPTION
51
52 This widget is composite of a Text field, and Entry field, and two
53 Buttons which supply as simple textual browsing mechanism for
54 exploring space group symbols. In a typical use, it is hooked up to
55 an Entry widget in a perl/Tk application so that a space group symbol
56 can be specified in the application with the click of a mouse.
57
58 =head1 SYNOPSIS
59
60 use Tk;
61 use Xray::Xtal;
62 use Xray::Tk::SGB;
63 $browser = $top -> SGB(-SpaceWidget=>\$space_field);
64 $browser -> configure(@sgb_args);
65 $browser -> Show;
66
67 Configuration parameters are described below.
68
69 =head1 METHODS
70
71 The only non-standard method is C<Show>, which is used to actually
72 display the browser on your screen. C<Show> always returns 0;
73
74 =head1 CONFIGURATION OPTIONS
75
76 =over 4
77
78 =item -SpaceWidget
79
80 This is a reference to a widget, typically an Entry widget, into which
81 the browser will insert space group symbols. If this is undefined or
82 not a reference to a widget, then the Mouse-1 action of the browser is
83 disabled.
84
85 =item -sgbActive
86
87 The color of active text in the browser.
88
89 =item -sgbGroup
90
91 The color used for particular emphasis of active text.
92
93 =item -button
94
95 Background color of the button.
96
97 =item -buttonActive
98
99 Active color of the buttons. Also the color of the text in the statusbar.
100
101 =item -buttonLabel
102
103 Color of the text on the buttons.
104
105 =item -buttonFont
106
107 The font to use on the button.
108
109 =item -sgbFont
110
111 The font to use in the text and status areas of the browser. This
112 looks best if it is a fixed width font.
113
114 =back
115
116 Other properties, such as C<-foreground> are inherited and may be
117 configured.
118
119
120 =head1 INTERNATIONALIZATION
121
122 All of the text displayed in the SGB widget can be customized using
123 configure. The primary purpose of this is to allow the use of other
124 languages in the SGB widget. The following list shows the configure
125 switch and its default value. You should play around with SGB before
126 translating or otherwise changing them so you can see what each string
127 is used for.
128
129 =over 4
130
131 =item -dismiss
132
133 Dismiss
134
135 =item -back
136
137 Back
138
139 =item -restore
140
141 Restore
142
143 =item -Triclinic
144
145 Triclinic
146
147 =item -Monoclinic
148
149 Monoclinic
150
151 =item -Orthorhombic
152
153 Orthorhombic
154
155 =item -Tetragonal
156
157 Tetragonal
158
159 =item -Trigonal
160
161 Trigonal
162
163 =item -Hexagonal
164
165 Hexagonal
166
167 =item -Cubic
168
169 Cubic
170
171 =item -MouseLInsert
172
173 Mouse-1 to insert this symbol.
174
175 =item -MouseLDisplay
176
177 Mouse-1 to display space group
178
179 =item -MouseADisplay
180
181 Any mouse button for groups of this class.
182
183 =item -RestoreMsg
184
185 Restore the initial symbol:
186
187 =item -DismissMsg
188
189 Dismiss the space group browser.
190
191 =item -Groups
192
193 groups
194
195 =item -MouseLR
196
197 Mouse-1=insert Mouse-3=describe
198
199 =item -BackScreen
200
201 Return to the previous screen.
202
203 =item -Number
204
205 Number
206
207 =item -NumberDesc
208
209 Space group index from ITC
210
211 =item -Schoenflies
212
213 Schoenflies
214
215 =item -SchoenfliesDesc
216
217 Schoenflies notation
218
219 =item -Full
220
221 Full symbol
222
223 =item -FullDesc
224
225 Symbol denoting complete symmetries
226
227 =item -NewSymbol
228
229 New symbol
230
231 =item -NewSymbolDesc
232
233 Symbol using \"e\" for the glide plane
234
235 =item -Thirtyfive
236
237 1935 symbol
238
239 =item -ThirtyfiveDesc
240
241 Symbol from the 1935 edition of ITXC
242
243 =item -Shorthand
244
245 Shorthand
246
247 =item -ShorthandDesc
248
249 Special strings recognized by Atoms
250
251 =item -Settings
252
253 Settings
254
255 =item -SettingsDesc
256
257 Symbols for alternate settings
258
259 =item -Short
260
261 Short symbols
262
263 =item -ShortDesc
264
265 Short symbols for alternate settings
266
267 =item -TopTop
268
269 Select a crystal class to display all space groups
270 within that class.
271
272 =item -ViewCurrent
273
274 View current group:
275
276 =item -ClassTop
277
278 Space group listing:
279
280 =item -GroupTop
281
282 Various symbols which may be used to describe space group:
283
284 =item -Note
285
286 Note:
287
288 =item -SettingsMon
289
290 The first three settings are for the b axis and beta
291 angle unique. The next three are for the c axis and
292 gamma angle unique. The final three are for the a
293 axis and alpha angle unique. Within each group, the
294 three choices are the possible choices of axes. Atoms
295 has no a priori way of knowing the correct setting
296 for your data.
297
298 =item -SettingsOrt
299
300 The five additional settings correspond to the five
301 additional ways of setting a coordinate system in
302 3-space. They correspond to permutations of ba-c,
303 cab, -cba, bca, and a-cb away from the standard
304 setting, abc. Atoms has no a priori way of knowing
305 the correct setting for your data.
306
307 =item -SettingsTet
308
309 C and F centered tetragonal cells are related to the
310 standard cells by a 45 degree rotation in ab plane
311 and a doubling of the cell volume. Atoms has no a
312 priori way of knowing the correct setting for your
313 data.
314
315 =item -SettingsRho
316
317 You may use the rhombohedral parameters, in which
318 case you must specify a and alpha. You may also use
319 the trigonal parameters in which case you must
320 specify a and c. The trigonal representation has
321 three times the volume of the rhombohedral
322 representation. Atoms has no a priori way of knowing
323 the correct setting for your data.
324
325
326
327 =back
328
329
330 =head1 USING THE SPACE GROUP BROWSER
331
332 Use of the browser is pretty straight forward because the status bar
333 at the bottom of the widget always informs the user about what actions
334 are available.
335
336 The opening panel displays the seven crystal classes. The names of
337 the crystal classes are active text. Clicking any mouse button on a
338 crystal class will display a list of all space groups in that class.
339 If the widget specified by C<-SpaceWidget> is displaying a valid group
340 symbol, then that symbol will be displayed as active text. Clicking
341 Mouse-1 one on that symbol will jump to the panel describing that
342 symbol.
343
344 The second panel displays lists of space groups divided by crystal
345 class. The index of the group (as indexed in the International Tables
346 of Crystallography) and the canonical (Hermann-Maguin) space group
347 symbol are shown. The space group symbols are active text. Clicking
348 Mouse-1 will insert that symbol into the widget given by
349 C<-SpaceWidget>. Clicking Mouse-3 will display information about that
350 group.
351
352 The last panel is the space group description. It shows all symbols
353 recognized as describing that group by the database in C<Xray::Xtal>,
354 which is use-ed by C<Xray::Tk::SGB>. Clicking Mouse-1 on any active
355 text will insert that symbol into the widget given by C<-SpaceWidget>.
356
357 At the bottom of the widget are three buttons. The C<back> button
358 causes the previous panel to be displayed. The C<restore> is only
359 active if the widget given by C<-SpaceWidget> contains a symbol. If so,
360 pressing it will restore that widget to its initial value. The
361 C<dismiss> button destroys the SGB widget.
362
363
364 =head1 TO DO
365
366 =over 4
367
368 =item *
369
370 The interaction of SGB(), configure(), and Show() is not as smooth as
371 it should be.
372
373 =back
374
375 =head1 Author
376
377 Bruce Ravel <[email protected]> (c) 1999
378 http://feff.phys.washington.edu/~ravel/software/
379 http://feff.phys.washington.edu/~ravel/software/atoms/
380
381 This code is distributed with Atoms and may be redistributed under the
382 same terms as Atoms, which are the same terms as Perl itself.
383
384 =cut
385
386
387
388 package Xray::Tk::SGB;
389
390 require 5.002;
391 use Tk;
392 use Tk::Balloon;
393 use Carp;
394 use strict;
395 use Xray::Xtal;
396
397 @Xray::Tk::SGB::ISA = qw(Tk::Toplevel);
398
399 Tk::Widget->Construct('SGB');
400
401 $Xray::Tk::SGB::VERSION = '0.03';
402
403
404 my ($sg_back_button, $sg_dismiss_button, $sg_restore_button, $sg_t, $sg_status,
405 $sg_balloon, $sg_space_widget, $sg_cache);
406 my %sgb_top_hints;
407
408 # SGB object constructor. Uses `new' method from base class
409 # to create object container then creates the dialog toplevel.
410 sub Populate {
411 my($sgb, @args) = @_;
412 $sgb -> SUPER::Populate(@args);
413 ##print $sgb->class, $/;
414 $sgb -> resizable(0,0);
415 $sgb -> title("Space Group Browser");
416 $sgb -> iconname("Space Group Browser");
417 $sgb -> bind('<Control-q>' => sub{$sgb->withdraw});
418 $sgb -> bind('<Control-d>' => sub{$sgb->withdraw});
419 $sgb -> protocol(WM_DELETE_WINDOW => sub{$sgb->withdraw});
420
421 ## fill it up with widgets
422 $sg_t = $sgb->Scrolled(qw/Text -setgrid true -width 50 -height 30
423 -wrap word -scrollbars e/)
424 -> pack();
425 $sg_t -> Subwidget("yscrollbar")
426 -> configure(-background=>$sg_t->cget('-background'));
427 $sg_t->tag(qw/configure bold -font/, $sgb->cget('-sgbFont') );
428 &disable_mouse3($sg_t->Subwidget('text'));
429 $sg_t->tag(qw/configure margins -lmargin1 6m -lmargin2 6m -rmargin 10m/);
430 $sg_t->tag('bind', 'unhint', '<Any-Leave>' =>
431 sub {$sg_status -> delete(qw/0 end/)} );
432
433
434 $sg_status = $sgb->Entry(qw/-width 50 -borderwidth 1 -relief sunken/)
435 -> pack();
436 $sg_balloon = $sgb -> Balloon(-borderwidth=>0, -initwait=>0,
437 -state=>'status', -statusbar=>$sg_status,
438 );
439
440 $sg_restore_button = $sgb -> Button(-command => \&sg_restore_symbol)
441 -> pack(-side=>'left', -padx=>4,);
442 $sg_restore_button -> configure(-state=>'disabled');
443 $sg_back_button = $sgb -> Button() -> pack(-side=>'left', -padx=>4,);
444 $sg_dismiss_button = $sgb -> Button(-command => sub{$sgb->withdraw})
445 -> pack(-side=>'right', -padx=>4,);
446
447 $sgb->Advertise(text_area => $sg_t);
448 $sgb->Advertise(status_area => $sg_status);
449 $sgb->Advertise(dimiss_button => $sg_dismiss_button);
450 $sgb->Advertise(back_button => $sg_back_button);
451 $sgb->Advertise(restore_button => $sg_restore_button);
452
453
454 $sgb ->
455 ConfigSpecs(
456 -sgbActive => ['PASSIVE', undef, undef, '#0000ff'], # blue
457 -sgbGroup => ['PASSIVE', undef, undef, '#9400d3'], # darkviolet
458 -button => ['PASSIVE', undef, undef,
459 $sg_back_button->cget('-background')],
460 -buttonActive => ['PASSIVE', undef, undef,
461 $sg_back_button->cget('-activebackground')],
462 -buttonLabel => ['PASSIVE', undef, undef,
463 $sg_back_button->cget('-activeforeground')],
464 -buttonFont => ['PASSIVE', undef, undef,
465 $sg_back_button->cget('-font')],
466 -sgbFont => ['PASSIVE', undef, undef, $sg_t->cget('-font')],
467 -dismiss => ['PASSIVE', undef, undef, 'Dismiss'],
468 -back => ['PASSIVE', undef, undef, 'Back'],
469 -restore => ['PASSIVE', undef, undef, 'Restore'],
470 -SpaceWidget => ['PASSIVE', undef, undef, undef],
471 -Triclinic => ['PASSIVE', undef, undef, 'Triclinic'],
472 -Monoclinic => ['PASSIVE', undef, undef, 'Monoclinic'],
473 -Orthorhombic => ['PASSIVE', undef, undef, 'Orthorhombic'],
474 -Tetragonal => ['PASSIVE', undef, undef, 'Tetragonal'],
475 -Trigonal => ['PASSIVE', undef, undef, 'Trigonal'],
476 -Hexagonal => ['PASSIVE', undef, undef, 'Hexagonal'],
477 -Cubic => ['PASSIVE', undef, undef, 'Cubic'],
478 -MouseLInsert => ['PASSIVE', undef, undef,
479 'Mouse-1 to insert this symbol.'],
480 -MouseLDisplay => ['PASSIVE', undef, undef,
481 'Mouse-1 to display space group'],
482 -MouseADisplay => ['PASSIVE', undef, undef,
483 'Any mouse button for groups of this class.'],
484 -RestoreMsg => ['PASSIVE', undef, undef,
485 'Restore the initial symbol: '],
486 -DismissMsg => ['PASSIVE', undef, undef,
487 'Dismiss the space group browser.'],
488 -Groups => ['PASSIVE', undef, undef, 'groups'],
489 -MouseLR => ['PASSIVE', undef, undef,
490 'Mouse-1=insert Mouse-3=describe'],
491 -BackScreen => ['PASSIVE', undef, undef,
492 'Return to the previous screen.'],
493 -Number => ['PASSIVE', undef, undef, 'Number'],
494 -NumberDesc => ['PASSIVE', undef, undef,
495 'Space group index from ITC'],
496 -Schoenflies => ['PASSIVE', undef, undef, 'Schoenflies'],
497 -SchoenfliesDesc => ['PASSIVE', undef, undef,
498 'Schoenflies notation'],
499 -Full => ['PASSIVE', undef, undef,
500 'Symbol denoting complete symmetries'],
501 -FullDesc => ['PASSIVE', undef, undef, 'Full symbol'],
502 -NewSymbol => ['PASSIVE', undef, undef, 'New symbol'],
503 -NewSymbolDesc => ['PASSIVE', undef, undef,
504 'Symbol using \"e\" for the glide plane'],
505 -Thirtyfive => ['PASSIVE', undef, undef, '1935 symbol'],
506 -ThirtyfiveDesc => ['PASSIVE', undef, undef,
507 'Symbol from the 1935 edition of ITXC'],
508 -Shorthand => ['PASSIVE', undef, undef, 'Shorthand'],
509 -ShorthandDesc => ['PASSIVE', undef, undef,
510 'Special strings recognized by Atoms'],
511 -Settings => ['PASSIVE', undef, undef, 'Settings'],
512 -SettingsDesc => ['PASSIVE', undef, undef,
513 'Symbols for alternate settings'],
514 -Short => ['PASSIVE', undef, undef, 'Short symbols'],
515 -ShortDesc => ['PASSIVE', undef, undef,
516 'Short symbols for alternate settings'],
517
518 '-TopTop' => ['PASSIVE', undef, undef,
519 'Select a crystal class to display all space groups within that class.'],
520 '-ViewCurrent' => ['PASSIVE', undef, undef, 'View current group:'],
521 '-ClassTop' => ['PASSIVE', undef, undef, 'Space group listing:'],
522 '-GroupTop' => ['PASSIVE', undef, undef,
523 'Various symbols which may be used to describe space group:'],
524 '-Note' => ['PASSIVE', undef, undef, 'Note:'],
525
526 '-SettingsMon' => ['PASSIVE', undef, undef,
527 'The first three settings are for the b axis and beta angle unique. The next three are for the c axis and gamma angle unique. The final three are for the a axis and alpha angle unique. Within each group, the three choices are the possible choices of axes. Atoms has no a priori way of knowing the correct setting for your data.'],
528
529 '-SettingsOrt' => ['PASSIVE', undef, undef,
530 'The five additional settings correspond to the five additional ways of setting a coordinate system in 3-space. They correspond to permutations of ba-c, cab, -cba, bca, and a-cb away from the standard setting, abc. Atoms has no a priori way of knowing the correct setting for your data.'],
531
532 '-SettingsTet' => ['PASSIVE', undef, undef,
533 'C and F centered tetragonal cells are related to the standard cells by a 45 degree rotation in ab plane and a doubling of the cell volume. Atoms has no a priori way of knowing the correct setting for your data.'],
534
535 '-SettingsRho' => ['PASSIVE', undef, undef,
536 'You may use the rhombohedral parameters, in which case you must specify a and alpha. You may also use the trigonal parameters in which case you must specify a and c. The trigonal representation has three times the volume of the rhombohedral representation. Atoms has no a priori way of knowing the correct setting for your data.'],
537
538 #-foreground => ['ADVERTISED','foreground','Foreground','black'],
539 #-background => ['DESCENDANTS','background','Background',undef],
540 DEFAULT => ['text_area',undef,undef,undef]
541 );
542 $sgb->Delegates('Construct' => $sg_t);
543
544 } # end Dialog constructor
545
546
547 # SGB object public method - finish configuring and display the browser.
548 sub Show {
549 my $sgb = $_[0];
550
551 %sgb_top_hints = ("Tri" => [$sgb->cget('-Triclinic'), 1, 2],
552 "Mon" => [$sgb->cget('-Monoclinic'), 3, 15],
553 "Ort" => [$sgb->cget('-Orthorhombic'), 16, 74],
554 "Tet" => [$sgb->cget('-Tetragonal'), 75, 142],
555 "Trg" => [$sgb->cget('-Trigonal'), 143, 167],
556 "Hex" => [$sgb->cget('-Hexagonal'), 168, 194],
557 "Cub" => [$sgb->cget('-Cubic'), 195, 230]);
558
559
560 $sg_t -> configure(-font => $sgb->cget('-sgbFont'));
561 $sg_t -> tag(qw/configure color1 -foreground/, $sgb->cget('-foreground') );
562 $sg_t -> tag(qw/configure color2 -foreground/, $sgb->cget('-sgbActive') );
563 $sg_t -> tag(qw/configure color3 -foreground/, $sgb->cget('-sgbGroup') );
564 $sg_t->tag('bind', 'hint_insert', '<Any-Enter>' =>
565 [\&hint, $sgb->cget('-MouseLInsert')]);
566
567 $sg_status -> configure(-foreground => $sgb->cget('-buttonActive'),
568 -font => $sgb->cget('-sgbFont'));
569 $sg_dismiss_button ->
570 configure(
571 -text => $sgb->cget('-dismiss'),
572 -foreground => $sgb->cget('-buttonLabel'),
573 -background => $sgb->cget('-button'),
574 -activeforeground => $sgb->cget('-buttonLabel'),
575 -activebackground => $sgb->cget('-buttonActive'),
576 -font => $sgb->cget('-buttonFont'),);
577 $sg_balloon -> attach($sg_dismiss_button,
578 -statusmsg=>$sgb->cget('-DismissMsg'));
579 $sg_back_button ->
580 configure(
581 -text => $sgb->cget('-back'),
582 -foreground => $sgb->cget('-buttonLabel'),
583 -background => $sgb->cget('-button'),
584 -activeforeground => $sgb->cget('-buttonLabel'),
585 -activebackground => $sgb->cget('-buttonActive'),
586 -font => $sgb->cget('-buttonFont'),
587 -command => sub{1});
588 $sg_restore_button ->
589 configure(
590 -text => $sgb->cget('-restore'),
591 -foreground => $sgb->cget('-buttonLabel'),
592 -background => $sgb->cget('-button'),
593 -activeforeground => $sgb->cget('-buttonLabel'),
594 -activebackground => $sgb->cget('-buttonActive'),
595 -font => $sgb->cget('-buttonFont'),);
596
597 if (Exists($ {$sgb->cget('-SpaceWidget')})) {
598 $sg_space_widget = $sgb->cget('-SpaceWidget');
599 unless ($$sg_space_widget -> get() =~ /^\s*$/) {
600 $sg_restore_button -> configure(-state=>'normal');
601 $sg_cache ||= $$sg_space_widget -> get();
602 my $str = join(" ", $sgb->cget('-RestoreMsg'), $sg_cache);
603 $sg_balloon -> attach($sg_restore_button, -statusmsg=>$str);
604 };
605 };
606
607 &space_group_browser_top($sgb);
608 return 0;
609 };
610
611
612
613
614 ### private subroutines
615
616 sub space_group_browser_top {
617 my $sgb = $_[0];
618 my $str = "";
619 $sg_back_button -> configure(-state=>'disabled');
620 $sg_balloon -> detach($sg_back_button);
621 $sg_t -> configure(-state=>'normal');
622 $sg_t -> delete(qw/1.0 end/);
623 inswt($sg_t, "\n\n");
624 inswt($sg_t, $sgb->cget('-TopTop'), 'margins');
625 inswt($sg_t, "\n\n");
626 foreach my $class ("Tri", "Mon", "Ort", "Tet", "Trg", "Hex", "Cub") {
627 $sg_t->tag('bind', 'hint'.$class, '<Any-Enter>' =>
628 [\&hint, $sgb->cget('-MouseADisplay')]);
629 $sg_t->tag('bind', 'm1'.$class, '<1>' =>
630 [\&space_group_browser_class, $sgb, $class]);
631 $sg_t->tag('bind', 'm2'.$class, '<2>' =>
632 [\&space_group_browser_class, $sgb, $class]);
633 $sg_t->tag('bind', 'm3'.$class, '<3>' =>
634 [\&space_group_browser_class, $sgb, $class]);
635
636 inswt($sg_t, " $sgb_top_hints{$class}->[0]",
637 'color2', 'hint'.$class, 'unhint', 'm1'.$class, ,
638 'm2'.$class, 'm3'.$class);
639 inswt($sg_t, " " x (15 - length($sgb_top_hints{$class}->[0])));
640 inswt($sg_t, "(" . $sgb->cget('-Groups') . " $sgb_top_hints{$class}->[1]-" .
641 "$sgb_top_hints{$class}->[2])\n\n");
642 };
643
644 my $current_group;
645 Exists($$sg_space_widget) and
646 $current_group = $$sg_space_widget -> get();
647 if ($current_group) {
648
649 my ($group, $foo) = Xray::Xtal::Cell::canonicalize_symbol($current_group);
650 my $class;
651 my $this = Xray::Xtal::Cell::describe_group($group);
652 (exists $$this{number}) && do {
653 my $index = $$this{number};
654 CLASS: {
655 $class = "", last CLASS if ($index <= 0);
656 $class = "Tri", last CLASS if ($index <= 2);
657 $class = "Mon", last CLASS if ($index <= 15);
658 $class = "Ort", last CLASS if ($index <= 74);
659 $class = "Tet", last CLASS if ($index <= 142);
660 $class = "Trg", last CLASS if ($index <= 167);
661 $class = "Hex", last CLASS if ($index <= 194);
662 $class = "Cub", last CLASS if ($index <= 230);
663 $class = ""
664 };
665 $sg_t->tag('bind', 'm1_current', '<1>' =>
666 [\&space_group_browser_group, $sgb, $group, $class]);
667 $str = $sgb->cget('-MouseLDisplay') . " " . $current_group;
668 $sg_t->tag('bind', 'hint_current', '<Any-Enter>' => [\&hint, $str]);
669 inswt($sg_t, $sgb->cget('-ViewCurrent') . " ",
670 qw/margins m1_current hint_current unhint/);
671 inswt($sg_t, "$current_group",
672 qw/margins color3 m1_current hint_current unhint/);
673 };
674 };
675 $sg_t -> configure(-state=>'disabled');
676 };
677
678 sub space_group_browser_class {
679 my $sgb = $_[1];
680 my $token = $_[2];
681 ##print "sgb ref: ", $sgb, $/, "token: ", $token, $/;
682 my ($class, $first, $last) = @{$sgb_top_hints{$token}};
683 my @sg_list = &generate_sg_list;
684 $sg_back_button -> configure(-state=>'normal',
685 -command=>[\&space_group_browser_top, $sgb],
686 );
687 $sg_balloon -> attach($sg_back_button,
688 -statusmsg=>$sgb->cget('-BackScreen'));
689 $sg_t -> configure(-state=>'normal');
690 $sg_t -> delete(qw/1.0 end/);
691 inswt($sg_t, "\n " . $sgb->cget('-ClassTop') . " " . $class . "\n\n");
692
693 foreach my $i ($first .. $last) {
694 my $this = $i-1;
695 $sg_t->tag('bind', 'hintGroup'.$i, '<Any-Enter>' =>
696 [\&hint, sprintf("%-10s: ", $sg_list[$this]) .
697 $sgb->cget('-MouseLR')]);
698 $sg_t->tag('bind', 'm1_'.$i, '<1>' =>
699 [\&sg_browser_dispose, $sg_list[$this]]);
700 $sg_t->tag('bind', 'm3_'.$i, '<3>' =>
701 [\&space_group_browser_group, $sgb, $sg_list[$this], $token]);
702
703 inswt($sg_t, sprintf(" %3s: ", $i));
704 inswt($sg_t, sprintf("%-10s", $sg_list[$this]),
705 qw/color2 unhint/, 'hintGroup'.$i, 'm1_'.$i, 'm3_'.$i);
706 inswt($sg_t, "\n");
707 };
708 $sg_t -> configure(-state=>'disabled');
709 };
710
711
712 sub space_group_browser_group {
713 my ($sgb, $group, $class) = ($_[1], $_[2], $_[3]);
714 $sg_back_button -> configure(-state=>'normal',
715 -command=>[\&space_group_browser_class,
716 " ", $sgb, $class],
717 );
718 $sg_balloon -> attach($sg_back_button,
719 -statusmsg=>$sgb->cget('-BackScreen'));
720 $sg_t -> configure(-state=>'normal');
721 $sg_t -> delete(qw/1.0 end/);
722 inswt($sg_t, "\n");
723 inswt($sg_t, $sgb->cget('-GroupTop'));
724 inswt($sg_t, " ");
725 $sg_t->tag('bind', 'm1_canonical', '<1>' => [\&sg_browser_dispose, $group]);
726 inswt($sg_t, $group, qw/color3 m1_canonical hint_insert unhint/);
727 inswt($sg_t, "\n\n");
728 ## inswt($sg_t, " Atoms will usually interpret correctly symbols " .
729 ## "entered without white space.\n\n");
730
731 my $this = Xray::Xtal::Cell::describe_group($group);
732
733 ## insert fields from space groups hash which are scalar valued
734 my %labels = ("number" =>
735 [$sgb->cget("-Number"), $sgb->cget("-NumberDesc")],
736 "schoenflies" =>
737 [$sgb->cget("-Schoenflies"), $sgb->cget("-SchoenfliesDesc")],
738 "full" =>
739 [$sgb->cget("-Full"), $sgb->cget("-FullDesc")],
740 "new_symbol" =>
741 [$sgb->cget("-NewSymbol"), $sgb->cget("-NewSymbolDesc")],
742 "thirtyfive" =>
743 [$sgb->cget("-Thirtyfive"), $sgb->cget("-ThirtyfiveDesc")],
744 );
745 foreach my $field (qw/number schoenflies full new_symbol thirtyfive/) {
746 next unless exists $$this{$field};
747
748 $sg_t->tag('bind', 'hint_'.$field, '<Any-Enter>' =>
749 [\&hint, $labels{$field}->[1]]);
750 inswt($sg_t, sprintf(" %13s: ", $labels{$field}->[0]),
751 'hint_'.$field, 'unhint');
752
753 my $sym = $$this{$field};
754 $sg_t->tag('bind', 'm1_'.$field, '<1>' => [\&sg_browser_dispose, $sym]);
755 inswt($sg_t, $sym, 'color2', 'm1_'.$field, 'hint_insert', 'unhint');
756
757 inswt($sg_t, "\n\n");
758 };
759
760 ## insert shorthand notation
761 if (exists $$this{'shorthand'}) {
762
763 $sg_t->tag('bind', 'hint_shorthand', '<Any-Enter>' =>
764 [\&hint, $sgb->cget('-ShorthandDesc')]);
765 inswt($sg_t, sprintf(" %13s: ", $sgb->cget('-Shorthand')),
766 'hint_shorthand', 'unhint');
767
768 my $counter = 0;
769 foreach my $sh (@{$$this{'shorthand'}}) {
770 $counter and inswt($sg_t, " " x 17);
771 ++$counter;
772 $sg_t->tag('bind', 'm1_'.$sh, '<1>' => [\&sg_browser_dispose, $sh]);
773 inswt($sg_t, $sh, 'color2', 'm1_'.$sh, 'hint_insert', 'unhint');
774 inswt($sg_t, "\n");
775 };
776 inswt($sg_t, "\n");
777 };
778
779 ## symbols for alternate settings
780 if (exists $$this{'settings'}) {
781
782 $sg_t->tag('bind', 'hint_settings', '<Any-Enter>' =>
783 [\&hint, $sgb->cget('-SettingsDesc')]);
784 inswt($sg_t, sprintf(" %13s: ", $sgb->cget('-Settings')),
785 'hint_settings', 'unhint');
786
787 my $counter = 0;
788 foreach my $sh (@{$$this{'settings'}}) {
789 $counter and inswt($sg_t, " " x 17);
790 ++$counter;
791 $sg_t->tag('bind', 'm1_'.$counter, '<1>' => [\&sg_browser_dispose, $sh]);
792 inswt($sg_t, $sh, 'color2', 'm1_'.$counter, 'hint_insert', 'unhint');
793 inswt($sg_t, "\n");
794 };
795 inswt($sg_t, "\n");
796 };
797
798 ## short symbols for alternate settings (monoclinic)
799 if (exists $$this{'short'}) {
800
801 $sg_t->tag('bind', 'hint_short', '<Any-Enter>' =>
802 [\&hint, $sgb->cget('-ShortDesc')]);
803 inswt($sg_t, sprintf(" %13s: ", $sgb->cget('-Short')),
804 'hint_short', 'unhint');
805
806 my $counter = 0;
807 foreach my $sh (@{$$this{'short'}}) {
808 $counter and inswt($sg_t, " " x 17);
809 ++$counter;
810 $sg_t->tag('bind', 'm1_short_'.$counter, '<1>' =>
811 [\&sg_browser_dispose, $sh]);
812 inswt($sg_t, $sh, 'color2', 'm1_short_'.$counter,
813 'hint_insert', 'unhint');
814 inswt($sg_t, "\n");
815 };
816 inswt($sg_t, "\n");
817 };
818
819 my %settings_explain =
820 ("Mon" => $sgb->cget(-'SettingsMon'),
821 "Ort" => $sgb->cget(-'SettingsOrt'),
822 "Tet" => $sgb->cget(-'SettingsTet'),
823 );
824
825 if (exists $$this{'settings'}) {
826 inswt($sg_t, $sgb->cget('-Note')."\n", qw/bold/);
827 inswt($sg_t, $settings_explain{$class}, qw/margins/);
828 };
829
830 if ($group =~ /^r/i) {
831 inswt($sg_t, $sgb->cget('-Note')."\n", qw/bold/);
832 inswt($sg_t, $sgb->cget(-'SettingsRho'), qw/margins/);
833 };
834 $sg_t -> configure(-state=>'disabled');
835 };
836
837
838 sub disable_mouse3 {
839 my $text = $_[0];
840 my @swap_bindtags = $text->bindtags;
841 $text -> bindtags([@swap_bindtags[1,0,2,3]]);
842 $text -> bind('<Button-3>' => sub{$_[0]->break});
843 };
844
845
846 sub hint {
847 $sg_status -> delete(qw/0 end/);
848 $sg_status -> insert(0, $_[1]);
849 };
850
851
852 sub inswt {
853 # insert_with_tags
854 #
855 # The procedure below inserts text into a given text widget and applies
856 # one or more tags to that text. The arguments are:
857 #
858 # w Window in which to insert
859 # text Text to insert (it's inserted at the "insert" mark)
860 # args One or more tags to apply to text. If this is empty then all
861 # tags are removed from the text.
862 # swiped from widget demo
863 my($w, $text, @args) = @_;
864 my $start = $w->index('insert');
865 $w->insert('insert', $text);
866 foreach my $tag ($w->tagNames($start)) {
867 $w->tagRemove($tag, $start, 'insert');
868 };
869 foreach my $i (@args) {
870 $w->tagAdd($i, $start, 'insert');
871 };
872 }; # end inswt
873
874
875 sub sg_restore_symbol {
876 $$sg_space_widget -> delete(qw/0 end/);
877 $$sg_space_widget -> insert(0, $sg_cache);
878 };
879
880 sub sg_browser_dispose {
881 ## local $| = 1;
882 ## print $_[1], $/;
883 ## print $$sg_space_widget, $/;
884 if (Exists($$sg_space_widget)) {
885 $$sg_space_widget -> delete(qw/0 end/);
886 $$sg_space_widget -> insert(0, $_[1]);
887 };
888 };
889
890 sub generate_sg_list {
891 return ('p 1',
892 'p -1',
893 'p 2',
894 'p 21',
895 'c 2',
896 'p m',
897 'p c',
898 'c m',
899 'c c',
900 'p 2/m',
901 'p 21/m',
902 'c 2/m',
903 'p 2/c',
904 'p 21/c',
905 'c 2/c',
906 'p 2 2 2',
907 'p 2 2 21',
908 'p 21 21 2',
909 'p 21 21 21',
910 'c 2 2 21',
911 'c 2 2 2',
912 'f 2 2 2',
913 'i 2 2 2',
914 'i 21 21 21',
915 'p m m 2',
916 'p m c 21',
917 'p c c 2',
918 'p m a 2',
919 'p c a 21',
920 'p n c 2',
921 'p m n 21',
922 'p b a 2',
923 'p n a 21',
924 'p n n 2',
925 'c m m 2',
926 'c m c 21',
927 'c c c 2',
928 'a m m 2',
929 'a b m 2',
930 'a m a 2',
931 'a b a 2',
932 'f m m 2',
933 'f d d 2',
934 'i m m 2',
935 'i b a 2',
936 'i m a 2',
937 'p m m m',
938 'p n n n',
939 'p c c m',
940 'p b a n',
941 'p m m a',
942 'p n n a',
943 'p m n a',
944 'p c c a',
945 'p b a m',
946 'p c c n',
947 'p b c m',
948 'p n n m',
949 'p m m n',
950 'p b c n',
951 'p b c a',
952 'p n m a',
953 'c m c m',
954 'c m c a',
955 'c m m m',
956 'c c c m',
957 'c m m a',
958 'c c c a',
959 'f m m m',
960 'f d d d',
961 'i m m m',
962 'i b a m',
963 'i b c a',
964 'i m m a',
965 'p 4',
966 'p 41',
967 'p 42',
968 'p 43',
969 'i 4',
970 'i 41',
971 'p -4',
972 'i -4',
973 'p 4/m',
974 'p 42/m',
975 'p 4/n',
976 'p 42/n',
977 'i 4/m',
978 'i 41/a',
979 'p 4 2 2',
980 'p 4 21 2',
981 'p 41 2 2',
982 'p 41 21 2',
983 'p 42 2 2',
984 'p 42 21 2',
985 'p 43 2 2',
986 'p 43 21 2',
987 'i 4 2 2',
988 'i 41 2 2',
989 'p 4 m m',
990 'p 4 b m',
991 'p 42 c m',
992 'p 42 n m',
993 'p 4 c c',
994 'p 4 n c',
995 'p 42 m c',
996 'p 42 b c',
997 'i 4 m m',
998 'i 4 c m',
999 'i 41 m d',
1000 'i 41 c d',
1001 'p -4 2 m',
1002 'p -4 2 c',
1003 'p -4 21 m',
1004 'p -4 21 c',
1005 'p -4 m 2',
1006 'p -4 c 2',
1007 'p -4 b 2',
1008 'p -4 n 2',
1009 'i -4 m 2',
1010 'i -4 c 2',
1011 'i -4 2 m',
1012 'i -4 2 d',
1013 'p 4/m m m',
1014 'p 4/m c c',
1015 'p 4/n b m',
1016 'p 4/n n c',
1017 'p 4/m b m',
1018 'p 4/m n c',
1019 'p 4/n m m',
1020 'p 4/n c c',
1021 'p 42/m m c',
1022 'p 42/m c m',
1023 'p 42/n b c',
1024 'p 42/n n m',
1025 'p 42/m b c',
1026 'p 42/m n m',
1027 'p 42/n m c',
1028 'p 42/n c m',
1029 'i 4/m m m',
1030 'i 4/m c m',
1031 'i 41/a m d',
1032 'i 41/a c d',
1033 'p 3',
1034 'p 31',
1035 'p 32',
1036 'r 3',
1037 'p -3',
1038 'r -3',
1039 'p 3 1 2',
1040 'p 3 2 1',
1041 'p 31 1 2',
1042 'p 31 2 1',
1043 'p 32 1 2',
1044 'p 32 2 1',
1045 'r 3 2',
1046 'p 3 m 1',
1047 'p 3 1 m',
1048 'p 3 c 1',
1049 'p 3 1 c',
1050 'r 3 m',
1051 'r 3 c',
1052 'p -3 1 m',
1053 'p -3 1 c',
1054 'p -3 m 1',
1055 'p -3 c 1',
1056 'r -3 m',
1057 'r -3 c',
1058 'p 6',
1059 'p 61',
1060 'p 65',
1061 'p 62',
1062 'p 64',
1063 'p 63',
1064 'p -6',
1065 'p 6/m',
1066 'p 63/m',
1067 'p 6 2 2',
1068 'p 61 2 2',
1069 'p 65 2 2',
1070 'p 62 2 2',
1071 'p 64 2 2',
1072 'p 63 2 2',
1073 'p 6 m m',
1074 'p 6 c c',
1075 'p 63 c m',
1076 'p 63 m c',
1077 'p -6 m 2',
1078 'p -6 c 2',
1079 'p -6 2 m',
1080 'p -6 2 c',
1081 'p 6/m m m',
1082 'p 6/m c c',
1083 'p 63/m c m',
1084 'p 63/m m c',
1085 'p 2 3',
1086 'f 2 3',
1087 'i 2 3',
1088 'p 21 3',
1089 'i 21 3',
1090 'p m -3',
1091 'p n -3',
1092 'f m -3',
1093 'f d -3',
1094 'i m -3',
1095 'p a -3',
1096 'i a -3',
1097 'p 4 3 2',
1098 'p 42 3 2',
1099 'f 4 3 2',
1100 'f 41 3 2',
1101 'i 4 3 2',
1102 'p 43 3 2',
1103 'p 41 3 2',
1104 'i 41 3 2',
1105 'p -4 3 m',
1106 'f -4 3 m',
1107 'i -4 3 m',
1108 'p -4 3 n',
1109 'f -4 3 c',
1110 'i -4 3 d',
1111 'p m -3 m',
1112 'p n -3 n',
1113 'p m -3 n',
1114 'p n -3 m',
1115 'f m -3 m',
1116 'f m -3 c',
1117 'f d -3 m',
1118 'f d -3 c',
1119 'i m -3 m',
1120 'i a -3 d'
1121 );
1122
1123 };
1124
1125 1;