git-svn-id: svn://svn.icms.temple.edu/lammps-ro/trunk@16053 f3b2605a-c512-4ea7-a41b...
[lammps.git] / tools / xmovie / control.c
blobdfa078162062a10a47204d14e87f3b88e17993df
1 /* **************************************************************** */
2 /* functions to handle control panel (sliders, labels, etc.) */
4 #include <stdio.h>
5 #include <stdlib.h>
7 #include <X11/Intrinsic.h>
8 #include <X11/StringDefs.h>
9 #include <X11/Shell.h>
10 #include <X11/Xos.h>
12 #include <X11/Xaw/Cardinals.h>
14 #include <X11/Xaw/Box.h>
15 #include <X11/Xaw/Command.h>
16 #include <X11/Xaw/Dialog.h>
17 #include <X11/Xaw/Form.h>
18 #include <X11/Xaw/Label.h>
19 #include <X11/Xaw/MenuButton.h>
20 #include <X11/Xaw/Scrollbar.h>
21 #include <X11/Xaw/SimpleMenu.h>
22 #include <X11/Xaw/Sme.h>
23 #include <X11/Xaw/SmeBSB.h>
24 #include <X11/Xaw/Toggle.h>
26 #include "xmovie.h"
28 #define POPUPSHELLCLASS overrideShellWidgetClass
30 /* **************************************************************** */
31 /* local typedefs */
33 typedef void (*InitFunc)(Widget parent);
35 typedef struct {
36 char *name;
37 XtCallbackProc exec_func;
38 XtPointer data;
39 InitFunc init_func;
40 } ButtonStruct;
42 #define NBTN(a) (sizeof(a)/sizeof(ButtonStruct))
44 typedef struct {
45 char *name;
46 int value;
47 Widget w;
48 } ToggleStruct;
50 #define TGLCNT(x) (sizeof(x)/sizeof(ToggleStruct))
52 typedef struct {
53 char *name;
54 XtCallbackProc callback;
55 ToggleStruct *buttons;
56 int nbuttons;
57 Widget lw;
58 } RadioStruct;
60 typedef struct {
61 char *labelname;
62 Widget *label;
63 char *slidername;
64 Widget *slider;
65 XtCallbackProc callback;
66 } SliderLabelStruct;
68 typedef struct {
69 Widget *w;
70 XtGrabKind grab;
71 Bool stop_motion;
72 } PopupData;
74 /* **************************************************************** */
75 /* local prototypes */
77 PRIVATE void SetSpeed(float percent);
78 PRIVATE void NewSpeed(Widget w, XtPointer client_data, XtPointer percent);
79 PRIVATE void SetPosition(float percent);
80 PRIVATE void NewPosition(Widget w, XtPointer client_data, XtPointer percent);
81 PRIVATE void SetThickness(float percent);
82 PRIVATE void NewThickness(Widget w, XtPointer client_data, XtPointer percent);
84 PRIVATE void AxisSelect(Widget w, XtPointer client_data, XtPointer call_data);
85 PRIVATE void DirectionSelect(Widget w, XtPointer client_data, XtPointer call_data);
86 PRIVATE void MotionSelect(Widget w, XtPointer client_data, XtPointer call_data);
88 PRIVATE void FindAndDisplaySlider(Widget w, XtCallbackProc func);
90 PRIVATE void DrawAxes(void);
92 PRIVATE void MakeRadioGroup(Widget parent, RadioStruct *radio);
93 PRIVATE void MakeSliderWithLabel(Widget parent, SliderLabelStruct *sl);
95 PRIVATE void SetRadio(RadioStruct *radio);
97 PRIVATE void do_start(Widget w, XtPointer client_data, XtPointer call_data);
98 PRIVATE void do_stop(Widget w, XtPointer client_data, XtPointer call_data);
99 PRIVATE void do_restart(Widget w, XtPointer client_data, XtPointer call_data);
100 PRIVATE void do_step(Widget w, XtPointer client_data, XtPointer call_data);
101 PRIVATE void do_back(Widget w, XtPointer client_data, XtPointer call_data);
103 PRIVATE void do_save_off(Widget w, XtPointer client_data, XtPointer call_data);
104 PRIVATE void do_save_on(Widget w, XtPointer client_data, XtPointer call_data);
105 PRIVATE void do_save_one(Widget w, XtPointer client_data, XtPointer call_data);
107 PRIVATE void do_popup(Widget w, XtPointer client_data, XtPointer call_data);
108 PRIVATE void cancel_popup(Widget w, XtPointer client_data, XtPointer call_data);
110 PRIVATE void init_quit(Widget w);
111 PRIVATE void quit_ok(Widget w, XtPointer client_data, XtPointer call_data);
113 PRIVATE void init_atoms(Widget w);
114 PRIVATE void init_bonds(Widget w);
115 PRIVATE void init_bg(Widget w);
116 PRIVATE void init_file(Widget w);
118 PRIVATE void color_apply(Widget w, XtPointer client_data, XtPointer call_data);
119 PRIVATE void bond_apply(Widget w, XtPointer client_data, XtPointer call_data);
120 PRIVATE void bg_apply(Widget w, XtPointer client_data, XtPointer call_data);
121 PRIVATE void file_apply(Widget w, XtPointer client_data, XtPointer call_data);
123 PRIVATE Pixel ConvertColorToPixel(Widget w, String color);
124 PRIVATE XtActionProc NoOp(Widget w, XEvent event, String *params,
125 Cardinal nparams);
127 PRIVATE void visible_toggle(Widget w, XtPointer client_data, XtPointer
128 call_data);
130 PRIVATE void bvisible_toggle(Widget w, XtPointer client_data, XtPointer
131 call_data);
133 /* **************************************************************** */
134 /* local data */
136 static Widget QuitPopup = (Widget) 0,
137 AtomPopup = (Widget) 0,
138 BondPopup = (Widget) 0,
139 BackgroundPopup = (Widget) 0,
140 FileColorPopup = (Widget) 0,
141 TimeLabel = (Widget) 0,
142 SpeedBar = (Widget) 0,
143 SpeedLabel = (Widget) 0,
144 PositionBar = (Widget) 0,
145 PositionLabel = (Widget) 0,
146 ThicknessBar = (Widget) 0,
147 ThicknessLabel = (Widget) 0,
148 Axes = (Widget) 0,
149 ReadInfo = (Widget) 0;
151 static Widget BGDialog = (Widget) 0,
152 FileDialog = (Widget) 0,
153 *FGDialog = (Widget *) NULL,
154 *Visible = (Widget *) NULL,
155 *Invisible = (Widget *) NULL,
156 *SizeDialog = (Widget *) NULL,
157 *BFGDialog = (Widget *) NULL,
158 *BVisible = (Widget *) NULL,
159 *BInvisible = (Widget *) NULL,
160 *ThicknessDialog= (Widget *) NULL;
162 static PopupData
163 QuitData = { &QuitPopup, XtGrabExclusive, True},
164 AtomData = { &AtomPopup, XtGrabNone, False },
165 BondData = { &BondPopup, XtGrabNone, False },
166 BackgroundData = { &BackgroundPopup, XtGrabNone, False },
167 FileColorData = { &FileColorPopup, XtGrabNone, False };
169 static ButtonStruct Buttons[] = {
170 { "quit", do_popup, (XtPointer) &QuitData, init_quit },
171 { "start", do_start, NULL, NULL },
172 { "stop", do_stop, NULL, NULL },
173 { "restart", do_restart, NULL, NULL },
174 { "step", do_step, NULL, NULL },
175 { "back", do_back, NULL, NULL },
178 static ButtonStruct SaveButtons[] = {
179 { "Off while animating", do_save_off, NULL, NULL },
180 { "On while animating", do_save_on , NULL, NULL },
181 { "This snapshot", do_save_one, NULL, NULL },
184 static ButtonStruct ColorButtons[] = {
185 { "atoms", do_popup, (XtPointer) &AtomData, init_atoms },
186 { "bonds", do_popup, (XtPointer) &BondData, init_bonds },
187 { "background", do_popup, (XtPointer) &BackgroundData, init_bg },
188 { "filecolor", do_popup, (XtPointer) &FileColorData, init_file }
191 static int in_motion;
193 static SliderLabelStruct
194 SpeedSL = {
195 "speed", &SpeedLabel,
196 "speedbar", &SpeedBar,
197 NewSpeed },
198 PositionSL = {
199 "position", &PositionLabel,
200 "positionbar", &PositionBar,
201 NewPosition },
202 ThicknessSL = {
203 "thickness", &ThicknessLabel,
204 "thicknessbar", &ThicknessBar,
205 NewThickness }
208 static ToggleStruct
209 AxisButtons[] = {
210 { "x", 0 },
211 { "y", 1 },
212 { "z", 2 } },
213 DirectionButtons[] = {
214 { "vplus", 1 },
215 { "vminus", 0 } },
216 MotionButtons[] = {
217 { "mplus", 1 },
218 { "mminus", -1 } }
221 static RadioStruct
222 AxisRadio = {
223 "axis",
224 AxisSelect,
225 AxisButtons,
226 TGLCNT(AxisButtons) },
227 DirectionRadio = {
228 "viewdir",
229 DirectionSelect,
230 DirectionButtons,
231 TGLCNT(DirectionButtons) },
232 MotionRadio = {
233 "motiondir",
234 MotionSelect,
235 MotionButtons,
236 TGLCNT(MotionButtons) }
239 static int normal = 1;
240 static char *null_string = "";
242 static XtActionsRec actions[] = {
243 { "NoOp", (XtActionProc) NoOp},
246 /* **************************************************************** */
248 Widget CreateControl(Widget parent, char *name)
250 Widget form, command, button, menu;
251 ButtonStruct *bptr;
252 int bcnt;
254 /* register the new actions */
256 XtAppAddActions(XtWidgetToApplicationContext(parent),
257 actions, XtNumber(actions));
259 /* create a form widget to handle layout */
261 form = XtCreateManagedWidget(name, formWidgetClass, parent,
262 NULL, ZERO);
264 /* create all the command buttons */
266 for(bcnt = NBTN(Buttons), bptr = Buttons;bcnt > 0; bcnt--, bptr++){
268 /* create a button */
270 command = XtCreateManagedWidget(bptr->name,
271 commandWidgetClass, form, NULL, ZERO);
273 /* Add the function as a callback */
275 XtAddCallback(command, XtNcallback, bptr->exec_func,
276 bptr->data);
278 /* call initialization routine */
280 if (bptr->init_func) (bptr->init_func)(command);
284 /* create the save menu */
286 command = XtCreateManagedWidget("save", menuButtonWidgetClass,
287 form, NULL, ZERO);
289 menu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
290 command, NULL, ZERO);
292 for(bcnt=NBTN(SaveButtons), bptr=SaveButtons; bcnt>0; bcnt--,bptr++){
293 button = XtCreateManagedWidget(bptr->name, smeBSBObjectClass,
294 menu, NULL, ZERO);
295 XtAddCallback(button, XtNcallback, bptr->exec_func,bptr->data);
296 if (bptr->init_func) (bptr->init_func)(button);
299 /* create the color menu */
301 command = XtCreateManagedWidget("color", menuButtonWidgetClass,
302 form, NULL, ZERO);
304 menu = XtCreatePopupShell("menu", simpleMenuWidgetClass,
305 command, NULL, ZERO);
307 for(bcnt=NBTN(ColorButtons), bptr=ColorButtons; bcnt>0; bcnt--,bptr++){
308 button = XtCreateManagedWidget(bptr->name, smeBSBObjectClass,
309 menu, NULL, ZERO);
310 XtAddCallback(button, XtNcallback, bptr->exec_func,bptr->data);
311 if (bptr->init_func) (bptr->init_func)(button);
314 /* create a label widget to display time */
316 TimeLabel = XtCreateManagedWidget("time", labelWidgetClass,
317 form, NULL, ZERO);
319 SetTime("Time: 0");
321 /* ************************************************ */
322 /* create all the sliders */
323 /* ************************************************ */
326 MakeSliderWithLabel(form, &SpeedSL);
327 MakeSliderWithLabel(form, &PositionSL);
328 MakeSliderWithLabel(form, &ThicknessSL);
330 /* ******************************************************** */
331 /* create a radio group for axis, view, motion directions */
332 /* ******************************************************** */
334 MakeRadioGroup(form, &AxisRadio);
335 MakeRadioGroup(form, &DirectionRadio);
336 MakeRadioGroup(form, &MotionRadio);
338 /* create a label widget to put axes in */
340 /* SJP - 10/02, had to add last NULL argument to each call */
342 Axes = XtVaCreateManagedWidget("axes", labelWidgetClass, form,
343 XtNlabel, null_string,NULL);
345 ReadInfo = XtVaCreateManagedWidget("read", labelWidgetClass,
346 form, XtNlabel, null_string,NULL);
350 PRIVATE XtActionProc NoOp(Widget w, XEvent event, String *params,
351 Cardinal nparams)
353 return;
356 void SetTime(char *s)
358 XtVaSetValues(TimeLabel, XtNlabel, s, NULL);
361 PRIVATE void SetSpeed(float percent)
363 char string[40];
364 int speed;
366 speed = percent * 100;
367 (void) sprintf(string,"Speed: %i", speed);
369 XtVaSetValues(SpeedLabel, XtNlabel, string, NULL);
372 PRIVATE void NewSpeed(Widget w, XtPointer client_data, XtPointer percent_ptr)
374 float percent;
376 percent = * (float *) percent_ptr;
378 /* delay between frames in milliseconds */
380 Common.delay = 30 + 10.0/(0.01 + percent);
382 SetSpeed(percent);
385 PRIVATE void SetPosition(float position)
387 char string[40];
389 static char *axis[] = { "X", "Y", "Z" };
391 (void) sprintf(string,"%s Position: %6.3f", axis[Common.axis],
392 position);
394 XtVaSetValues(PositionLabel, XtNlabel, string, NULL);
397 PRIVATE void NewPosition(Widget w, XtPointer client_data, XtPointer percent_ptr)
399 float percent;
400 int i;
401 float old_pos;
403 percent = * (float *) percent_ptr;
405 i = Common.axis;
407 old_pos = Common.position;
409 Common.position =
410 (Common.bounds[i].high - Common.bounds[i].low) * percent +
411 Common.bounds[i].low;
413 SetPosition(Common.position);
415 if (Common.position == old_pos) return;
417 if (normal) SceneUpdate();
420 PRIVATE void SetThickness(float thickness)
422 char string[40];
424 (void) sprintf(string,"Thickness: %6.3f", thickness);
426 XtVaSetValues(ThicknessLabel, XtNlabel, string, NULL);
429 PRIVATE void NewThickness(Widget w, XtPointer client_data, XtPointer percent_ptr)
431 float percent;
432 int i;
433 float old_thick;
435 percent = * (float *) percent_ptr;
436 i = Common.axis;
438 old_thick = Common.thickness;
439 Common.thickness =
440 (Common.bounds[i].high - Common.bounds[i].low) * percent;
442 if (old_thick == Common.thickness) return;
444 SetThickness(Common.thickness);
446 if (normal) SceneUpdate();
449 /* **************************************************************** */
451 PRIVATE void AxisSelect(Widget w, XtPointer client_data, XtPointer call_data)
453 int new_axis;
455 new_axis = (int) client_data;
457 if (new_axis == Common.axis) return;
459 Common.axis = new_axis;
461 DrawAxes();
463 normal = 0;
465 FindAndDisplaySlider(PositionBar, NewPosition);
466 FindAndDisplaySlider(ThicknessBar, NewThickness);
468 normal = 1;
470 SceneUpdate();
473 PRIVATE void DirectionSelect(Widget w, XtPointer client_data, XtPointer call_data)
475 int new_dir;
477 new_dir = (int) client_data;
479 if (new_dir == Common.direction) return;
481 Common.direction = new_dir;
483 DrawAxes();
484 SceneUpdate();
487 PRIVATE void MotionSelect(Widget w, XtPointer client_data, XtPointer call_data)
489 int new_dir;
491 new_dir = (int) client_data;
493 Common.dstep = new_dir;
497 PRIVATE void FindAndDisplaySlider(Widget w, XtCallbackProc func)
499 float percent;
501 XtVaGetValues(w, XtNtopOfThumb, &percent, NULL);
503 (func)(NULL, NULL, &percent);
506 void PositionUpdate(void)
508 FindAndDisplaySlider(PositionBar, NewPosition);
511 void ThicknessUpdate(void)
513 FindAndDisplaySlider(ThicknessBar, NewThickness);
516 void SpeedUpdate(void)
518 FindAndDisplaySlider(SpeedBar, NewSpeed);
521 /* **************************************************************** */
523 typedef struct {
524 int x;
525 int y;
526 char *name;
527 } LABEL;
529 typedef struct {
530 XSegment lines[6];
531 LABEL labels[2];
532 } AXIS;
534 static AXIS axis_data[] = {
535 { { { 120, 120, 120, 30 }, { 115, 35, 120, 30 },
536 { 120, 30, 125, 35 }, { 120, 120, 30, 120 },
537 { 35, 125, 30, 120 }, { 30, 120, 35, 115 } },
538 { { 15, 127, "Z" }, { 115, 25, "Y" } },
540 { { { 20, 20, 20, 110 }, { 15, 105, 20, 110 },
541 { 20, 110, 25, 105 }, { 20, 20, 110, 20 },
542 { 105, 15, 110, 20 }, { 110, 20, 105, 25 } },
543 { { 115, 27, "X" }, { 15, 127, "Z" } },
545 { { { 20, 120, 20, 30 }, { 15, 35, 20, 30 },
546 { 20, 30, 25, 35 }, { 20, 120, 110, 120 },
547 { 105, 125, 110, 120 }, { 110, 120, 105, 115 } },
548 { { 115, 127, "X" }, { 15, 27, "Y" } },
550 { { { 20, 120, 20, 30 }, { 15, 35, 20, 30 },
551 { 20, 30, 25, 35 }, { 20, 120, 110, 120 },
552 { 105, 125, 110, 120 }, { 110, 120, 105, 115 } },
553 { { 115, 127, "Z" }, { 15, 27, "Y" } },
555 { { { 20, 120, 20, 30 }, { 15, 35, 20, 30 },
556 { 20, 30, 25, 35 }, { 20, 120, 110, 120 },
557 { 105, 125, 110, 120 }, { 110, 120, 105, 115 } },
558 { { 115, 127, "X" }, { 15, 27, "Z" } },
560 { { { 20, 20, 20, 110 }, { 15, 105, 20, 110 },
561 { 20, 110, 25, 105 }, { 20, 20, 110, 20 },
562 { 105, 15, 110, 20 }, { 110, 20, 105, 25 } },
563 { { 115, 27, "X" }, { 15, 127, "Y" } },
567 PRIVATE void DrawAxes(void)
569 static int first = 1;
570 static GC gc;
571 static Dimension height, width;
572 XGCValues xgc;
573 AXIS *a;
574 int i;
575 XFontStruct *font;
577 if ( Common.axis < 0 ||
578 Common.direction < 0 ||
579 !Axes ||
580 !XtIsRealized(Axes) ) return;
582 if (first) {
583 xgc.function = GXcopy;
585 XtVaGetValues(Axes,
586 XtNbackground, &xgc.background,
587 XtNforeground, &xgc.foreground,
588 XtNfont, &font,
589 XtNheight, &height,
590 XtNwidth, &width,
591 NULL );
593 xgc.font = font->fid;
595 gc = XCreateGC(XtDisplay(Axes), XtWindow(Axes),
596 GCFunction | GCBackground | GCForeground | GCFont,
597 &xgc);
599 first = 0;
602 XClearWindow(XtDisplay(Axes), XtWindow(Axes));
604 a = axis_data + Common.axis + 3*Common.direction;
606 XDrawSegments(XtDisplay(Axes), XtWindow(Axes), gc, a->lines, 6);
608 for(i = 0; i < 2; i++)
609 XDrawString(XtDisplay(Axes), XtWindow(Axes), gc,
610 a->labels[i].x, a->labels[i].y,
611 a->labels[i].name,
612 strlen(a->labels[i].name));
615 void ExposeAxes(Widget w, XEvent *event, String *strings, Cardinal *nstrings)
617 DrawAxes();
621 /* **************************************************************** */
623 PRIVATE void MakeRadioGroup(Widget parent, RadioStruct *radio)
625 ToggleStruct *t;
626 int i;
628 if (radio->name)
629 radio->lw = XtCreateManagedWidget(radio->name,
630 labelWidgetClass, parent , NULL, ZERO );
632 for(t = radio->buttons, i = radio->nbuttons; i; i--, t++) {
633 t->w = XtCreateManagedWidget(t->name, toggleWidgetClass,
634 parent, NULL, ZERO);
635 XtAddCallback(t->w, XtNcallback, radio->callback,
636 (XtPointer) t->value);
641 /* **************************************************************** */
643 PRIVATE void MakeSliderWithLabel(Widget parent, SliderLabelStruct *sl)
645 /* create the slider */
647 *(sl->slider) = XtCreateManagedWidget(sl->slidername,
648 scrollbarWidgetClass, parent, NULL, ZERO);
650 /* add the callback */
652 XtAddCallback(*(sl->slider), XtNjumpProc, sl->callback, NULL);
654 /* create the label */
656 *(sl->label) = XtCreateManagedWidget(sl->labelname,
657 labelWidgetClass, parent, NULL, ZERO);
659 /* Initialize the display */
661 FindAndDisplaySlider(*(sl->slider), sl->callback);
665 void UpdateRadios(void)
667 SetRadio(&AxisRadio);
668 SetRadio(&DirectionRadio);
669 SetRadio(&MotionRadio);
672 PRIVATE void SetRadio(RadioStruct *radio)
674 ToggleStruct *t;
675 int i;
676 char set_name[80], *rg;
678 t = radio->buttons;
680 /* find out which toggle is currently set */
681 strcpy(set_name, (char *) XawToggleGetCurrent(t->w));
683 for(i = radio->nbuttons; i; i--, t++)
684 if (!strcmp(set_name, t->name)) goto found_set;
686 t = radio->buttons;
688 XtVaGetValues(t->w, XtNradioGroup, &rg, NULL);
689 fprintf(stderr,"Error: radioData for radioGroup %s inconsistent.\n",
690 rg);
691 XtDestroyApplicationContext(XtWidgetToApplicationContext(TopLevel));
692 exit(0);
694 found_set:
696 /* call the callback with the proper data */
698 (radio->callback)((Widget) t->w, (XtPointer) t->value, (XtPointer) 0);
701 void SetReadString(char *s)
703 if (ReadInfo == (Widget) 0) return;
705 XtVaSetValues(ReadInfo, XtNlabel, s, NULL);
708 /* **************************************************************** */
710 PRIVATE void init_quit(Widget parent)
712 Widget dialog;
714 /* create a popup shell */
716 QuitPopup = XtCreatePopupShell("popup", POPUPSHELLCLASS,
717 parent, NULL, ZERO);
719 /* put a dialog box in it */
721 dialog = XtCreateManagedWidget("dialog", dialogWidgetClass,
722 QuitPopup, NULL, ZERO);
724 XawDialogAddButton(dialog, "ok", quit_ok, (XtPointer) dialog);
725 XawDialogAddButton(dialog, "cancel", cancel_popup,
726 (XtPointer) &QuitData);
730 /* **************************************************************** */
732 PRIVATE void do_popup(Widget w, XtPointer client_data, XtPointer call_data)
734 Position x, y;
735 PopupData *pdata;
737 pdata = (PopupData *) client_data;
739 /* stop motion for now */
741 if (pdata->stop_motion) {
742 in_motion = Common.motion;
743 RemoveMotion();
746 /* translate to corner of calling widgets window */
748 XtTranslateCoords(w, 0, 0, &x, &y);
750 /* Set us to pop up there */
752 XtVaSetValues(*(pdata->w), XtNx, x, XtNy, y, NULL);
754 /* do the popping */
756 XtPopup(*(pdata->w), pdata->grab);
760 PRIVATE void quit_ok(Widget w, XtPointer client_data, XtPointer call_data)
762 XtDestroyApplicationContext(XtWidgetToApplicationContext(w));
763 exit(0);
766 PRIVATE void cancel_popup(Widget w, XtPointer client_data, XtPointer call_data)
768 PopupData *pdata;
770 pdata = (PopupData *) client_data;
772 if (pdata->stop_motion && in_motion) InstallMotion();
774 XtPopdown(*(pdata->w));
777 /* **************************************************************** */
779 PRIVATE void do_start(Widget w, XtPointer client_data, XtPointer call_data)
781 InstallMotion();
784 PRIVATE void do_stop(Widget w, XtPointer client_data, XtPointer call_data)
786 RemoveMotion();
789 PRIVATE void do_restart(Widget w, XtPointer client_data, XtPointer call_data)
791 RemoveMotion();
793 if (Common.dstep > 0)
794 Common.step = 0;
795 else
796 Common.step = Common.ndata-1;
798 InstallMotion();
801 PRIVATE void do_step(Widget w, XtPointer client_data, XtPointer call_data)
803 RemoveMotion();
805 Common.step = CoerceStep(Common.step + 1);
807 SceneUpdate();
810 PRIVATE void do_back(Widget w, XtPointer client_data, XtPointer call_data)
812 RemoveMotion();
814 Common.step = CoerceStep(Common.step - 1);
816 SceneUpdate();
819 PRIVATE void do_save_off(Widget w, XtPointer client_data, XtPointer call_data)
821 Common.saveflag = 0;
824 PRIVATE void do_save_on(Widget w, XtPointer client_data, XtPointer call_data)
826 Common.saveflag = 1;
829 PRIVATE void do_save_one(Widget w, XtPointer client_data, XtPointer call_data)
831 SceneSave();
834 /* **************************************************************** */
836 PRIVATE void init_atoms(Widget parent)
838 Widget outerform, form;
839 Widget apply, cancel, last;
840 char formname[80], fglabel[80], sizelabel[80];
841 char fgname[80], sizename[80], vname[80], iname[80];
842 int i, j;
843 size_t size;
845 /* create a popup shell for atom colors */
847 AtomPopup = XtCreatePopupShell("atomcolors",
848 transientShellWidgetClass, TopLevel, NULL, ZERO);
850 /* put a form widget in it for layout */
852 outerform = XtCreateManagedWidget("form", formWidgetClass, AtomPopup,
853 NULL, ZERO);
855 /* add the buttons */
857 apply = XtCreateManagedWidget("apply", commandWidgetClass,
858 outerform, NULL, ZERO);
859 XtAddCallback(apply, XtNcallback, color_apply,
860 (XtPointer) NULL);
862 cancel = XtVaCreateManagedWidget("cancel", commandWidgetClass,
863 outerform, XtNfromHoriz, apply, NULL);
864 XtAddCallback(cancel, XtNcallback, cancel_popup,
865 (XtPointer) &AtomData);
867 /* put the dialog boxes in it for the colors */
869 /* ************************************************ */
870 /* allocate all the widgets */
871 /* ************************************************ */
873 size = Common.natomcolors * sizeof(Widget);
875 FGDialog = (Widget *) XtMalloc(size);
876 SizeDialog = (Widget *) XtMalloc(size);
877 Visible = (Widget *) XtMalloc(size);
878 Invisible = (Widget *) XtMalloc(size);
880 /* ************************************************ */
881 /* build the rest of the panel */
882 /* ************************************************ */
884 last = apply;
886 for(i = 0; i < Common.natomcolors; i++) {
887 j = i+1;
889 sprintf(formname, "colorform%i", j);
890 sprintf(fgname, "color%i", j);
891 sprintf(fglabel, "Type %i Color", j);
892 sprintf(sizename, "size%i", j);
893 sprintf(sizelabel, "Type %i Diameter", j);
894 sprintf(vname, "visible%i", j);
895 sprintf(iname, "invisible%i", j);
897 form = XtVaCreateManagedWidget(formname, formWidgetClass,
898 outerform, XtNfromVert, last, NULL);
900 FGDialog[i] = XtVaCreateManagedWidget(fgname,
901 dialogWidgetClass, form, XtNlabel, fglabel,
902 XtNvalue, "white", NULL);
904 SizeDialog[i] = XtVaCreateManagedWidget(sizename,
905 dialogWidgetClass, form, XtNlabel, sizelabel,
906 XtNvalue, "10", XtNfromHoriz, FGDialog[i], NULL);
908 Visible[i] = XtVaCreateManagedWidget(vname,
909 toggleWidgetClass, form, XtNlabel, "Visible",
910 XtNstate, True, XtNfromVert, FGDialog[i], NULL);
912 Invisible[i] = XtVaCreateManagedWidget(iname,
913 toggleWidgetClass, form, XtNlabel, "Invisible",
914 XtNstate, False, XtNradioGroup, Visible[i],
915 XtNfromHoriz, Visible[i], XtNfromVert, FGDialog[i],
916 NULL);
918 XtAddCallback(Visible[i], XtNcallback, visible_toggle,
919 (XtPointer) i);
921 XtAddCallback(Invisible[i], XtNcallback, visible_toggle,
922 (XtPointer) i);
924 Common.atoms_visible[i] = True;
925 Common.diameter[i] = 10;
926 last = form;
930 /* **************************************************************** */
932 PRIVATE void init_bg(Widget parent)
934 Widget outerform;
935 Widget apply, cancel;
937 /* create a popup shell for background color */
939 BackgroundPopup = XtCreatePopupShell("backcolors",
940 transientShellWidgetClass, TopLevel, NULL, ZERO);
942 /* put a form widget in it for layout */
944 outerform = XtCreateManagedWidget("form", formWidgetClass,
945 BackgroundPopup, NULL, ZERO);
947 /* add the buttons */
949 apply = XtCreateManagedWidget("apply", commandWidgetClass,
950 outerform, NULL, ZERO);
951 XtAddCallback(apply, XtNcallback, bg_apply, (XtPointer) NULL);
953 cancel = XtVaCreateManagedWidget("cancel", commandWidgetClass,
954 outerform, XtNfromHoriz, apply, NULL);
955 XtAddCallback(cancel, XtNcallback, cancel_popup,
956 (XtPointer) &BackgroundData);
958 /* put the dialog box in it for the color */
960 BGDialog = XtVaCreateManagedWidget("bg", dialogWidgetClass,
961 outerform, XtNfromVert, apply, NULL);
964 /* **************************************************************** */
966 PRIVATE void init_file(Widget parent)
968 Widget outerform;
969 Widget apply, cancel;
971 /* create a popup shell for color file */
973 FileColorPopup = XtCreatePopupShell("filecolors",
974 transientShellWidgetClass, TopLevel, NULL, ZERO);
976 /* put a form widget in it for layout */
978 outerform = XtCreateManagedWidget("form", formWidgetClass,
979 FileColorPopup, NULL, ZERO);
981 /* add the buttons */
983 apply = XtCreateManagedWidget("apply", commandWidgetClass,
984 outerform, NULL, ZERO);
985 XtAddCallback(apply, XtNcallback, file_apply, (XtPointer) NULL);
987 cancel = XtVaCreateManagedWidget("cancel", commandWidgetClass,
988 outerform, XtNfromHoriz, apply, NULL);
989 XtAddCallback(cancel, XtNcallback, cancel_popup,
990 (XtPointer) &FileColorData);
992 /* put the dialog box in it for the filename */
994 FileDialog = XtVaCreateManagedWidget("file", dialogWidgetClass,
995 outerform, XtNfromVert, apply, NULL);
998 PRIVATE void init_bonds(Widget parent)
1000 Widget outerform, form;
1001 Widget apply, cancel, last;
1002 char formname[80], fglabel[80], sizelabel[80];
1003 char fgname[80], sizename[80], vname[80], iname[80];
1004 int i, j;
1005 size_t size;
1007 /* create a popup shell for bond colors */
1009 BondPopup = XtCreatePopupShell("bondcolors",
1010 transientShellWidgetClass,
1011 TopLevel, NULL, ZERO);
1013 /* put a form widget in it for layout */
1015 outerform = XtCreateManagedWidget("form", formWidgetClass, BondPopup,
1016 NULL, ZERO);
1018 /* add the buttons */
1020 apply = XtCreateManagedWidget("apply", commandWidgetClass,
1021 outerform, NULL, ZERO);
1022 XtAddCallback(apply, XtNcallback, bond_apply,
1023 (XtPointer) NULL);
1025 cancel = XtVaCreateManagedWidget("cancel", commandWidgetClass,
1026 outerform, XtNfromHoriz, apply, NULL);
1027 XtAddCallback(cancel, XtNcallback, cancel_popup,
1028 (XtPointer) &BondData);
1030 /* ************************************************ */
1031 /* allocate all the widgets */
1032 /* ************************************************ */
1034 size = Common.nbondcolors * sizeof(Widget);
1036 BFGDialog = (Widget *) XtMalloc(size);
1037 ThicknessDialog = (Widget *) XtMalloc(size);
1038 BVisible = (Widget *) XtMalloc(size);
1039 BInvisible = (Widget *) XtMalloc(size);
1041 /* ************************************************ */
1042 /* build the rest of the panel */
1043 /* ************************************************ */
1045 last = apply;
1047 for(i = 0; i < Common.nbondcolors; i++) {
1048 j = i+1;
1050 sprintf(formname, "bondform%i", j);
1051 sprintf(fgname, "color%i", j);
1052 sprintf(fglabel, "Bond Type %i Color", j);
1053 sprintf(sizename, "thickness%i", j);
1054 sprintf(sizelabel, "Bond Type %i Thickness",j);
1055 sprintf(vname, "visible%i", j);
1056 sprintf(iname, "invisible%i", j);
1058 form = XtVaCreateManagedWidget(formname,
1059 formWidgetClass, outerform, XtNfromVert,
1060 last, NULL);
1062 BFGDialog[i] = XtVaCreateManagedWidget(fgname,
1063 dialogWidgetClass, form, XtNlabel, fglabel,
1064 XtNvalue, "white", NULL);
1066 ThicknessDialog[i] = XtVaCreateManagedWidget(sizename,
1067 dialogWidgetClass, form, XtNlabel, sizelabel,
1068 XtNvalue, "1", XtNfromHoriz, BFGDialog[i], NULL);
1070 BVisible[i] = XtVaCreateManagedWidget(vname,
1071 toggleWidgetClass, form, XtNlabel, "Visible",
1072 XtNstate, True, XtNfromVert, BFGDialog[i], NULL);
1074 BInvisible[i] = XtVaCreateManagedWidget(iname,
1075 toggleWidgetClass, form, XtNlabel, "Invisible",
1076 XtNstate, False, XtNradioGroup, BVisible[i],
1077 XtNfromHoriz, BVisible[i], XtNfromVert, BFGDialog[i],
1078 NULL);
1080 XtAddCallback(BVisible[i], XtNcallback, bvisible_toggle,
1081 (XtPointer) i);
1083 XtAddCallback(BInvisible[i], XtNcallback, bvisible_toggle,
1084 (XtPointer) i);
1086 Common.bonds_visible[i] = True;
1087 last = form;
1091 /* **************************************************************** */
1093 PRIVATE void color_apply(Widget w, XtPointer client_data, XtPointer call_data)
1095 static String *fg, *size;
1096 static Pixel *fgpixel;
1097 static int *diam;
1098 static Bool first = True;
1100 Boolean ok;
1101 int i, n;
1104 if (first) {
1105 n = Common.natomcolors;
1107 fg = (String *) XtMalloc( n * sizeof(String) );
1108 size = (String *) XtMalloc( n * sizeof(String) );
1109 fgpixel = (Pixel *) XtMalloc( n * sizeof(Pixel) );
1110 diam = (int *) XtMalloc( n * sizeof(int) );
1112 first = False;
1115 ok = True;
1117 for(i = 0; i < Common.natomcolors; i++) {
1118 fg[i] = XawDialogGetValueString(FGDialog[i]);
1119 fgpixel[i] = ConvertColorToPixel(FGDialog[i], fg[i]);
1121 if (fgpixel[i] == (Pixel) -1) {
1122 ok = False;
1123 XtVaSetValues(FGDialog[i], XtNvalue,
1124 "-Invalid Color-", NULL);
1127 size[i] = XawDialogGetValueString(SizeDialog[i]);
1128 diam[i] = atoi(size[i]);
1130 if (diam[i] < 1 || diam[i] > MAXDIAM) {
1131 ok = False;
1132 XtVaSetValues(SizeDialog[i], XtNvalue,
1133 "-Invalid Size-", NULL);
1137 if (!ok){
1138 XBell(XtDisplay(BGDialog), 0);
1139 return;
1142 SetAtomColors(fgpixel);
1144 for(i = 0; i < Common.natomcolors; i++)
1145 Common.diameter[i] = diam[i];
1147 SceneUpdate();
1150 /* **************************************************************** */
1152 PRIVATE void bond_apply(Widget w, XtPointer client_data, XtPointer call_data)
1154 static String *fg, *size;
1155 static Pixel *fgpixel;
1156 static Dimension *thick;
1157 static Bool first = True;
1159 Boolean ok;
1160 int i, n, ithick;
1162 if (first) {
1163 n = Common.nbondcolors;
1165 fg = (String *) XtMalloc( n * sizeof(String) );
1166 size = (String *) XtMalloc( n * sizeof(String) );
1167 fgpixel = (Pixel *) XtMalloc( n * sizeof(Pixel) );
1168 thick = (Dimension *) XtMalloc( n * sizeof(Dimension) );
1170 first = False;
1173 ok = True;
1175 for(i = 0; i < Common.nbondcolors; i++) {
1176 fg[i] = XawDialogGetValueString(BFGDialog[i]);
1177 fgpixel[i] = ConvertColorToPixel(BFGDialog[i], fg[i]);
1179 if (fgpixel[i] == (Pixel) -1) {
1180 ok = False;
1181 XtVaSetValues(BFGDialog[i], XtNvalue,
1182 "-Invalid Color-", NULL);
1185 size[i] = XawDialogGetValueString(ThicknessDialog[i]);
1186 ithick = atoi(size[i]);
1188 if (ithick < 1 || ithick > MAXTHICK) {
1189 ok = False;
1190 XtVaSetValues(ThicknessDialog[i], XtNvalue,
1191 "-Invalid Size-", NULL);
1193 thick[i] = ithick;
1196 if (!ok){
1197 XBell(XtDisplay(BGDialog), 0);
1198 return;
1201 SetBondColors(fgpixel, thick);
1203 SceneUpdate();
1206 /* **************************************************************** */
1208 PRIVATE void bg_apply(Widget w, XtPointer client_data, XtPointer call_data)
1210 String bg;
1211 Pixel bgpixel;
1213 bg = XawDialogGetValueString(BGDialog);
1214 bgpixel = ConvertColorToPixel(BGDialog, bg);
1216 if (bgpixel == (Pixel) -1) {
1217 XtVaSetValues(BGDialog, XtNvalue, "-Invalid Color-", NULL);
1218 XBell(XtDisplay(BGDialog), 0);
1219 return;
1222 SetBGColor(bgpixel);
1224 SceneUpdate();
1227 PRIVATE Pixel ConvertColorToPixel(Widget w, String color)
1229 XrmValue from, to;
1230 Pixel pixel;
1232 from.size = strlen(color) + 1;
1233 from.addr = color;
1234 /* SJP - 10/02, new Linux couldn't fine caddr_t */
1235 /* to.addr = (caddr_t) &pixel; */
1236 to.addr = (char *) &pixel;
1237 to.size = sizeof(pixel);
1239 if (XtConvertAndStore(w, XtRString, (XrmValuePtr) &from,
1240 XtRPixel, (XrmValuePtr) &to))
1241 return(pixel);
1242 else
1243 return( (Pixel) -1);
1247 PRIVATE void file_apply(Widget w, XtPointer client_data, XtPointer call_data)
1249 String bg;
1250 Pixel bgpixel;
1251 static String *fg, *size;
1252 static Pixel *fgpixel;
1253 static int *diam;
1254 static Bool first = True;
1256 int i, n;
1258 if (first) {
1259 n = Common.natomcolors;
1261 fg = (String *) XtMalloc( n * sizeof(String) );
1262 size = (String *) XtMalloc( n * sizeof(String) );
1263 fgpixel = (Pixel *) XtMalloc( n * sizeof(Pixel) );
1264 diam = (int *) XtMalloc( n * sizeof(int) );
1266 first = False;
1269 for(i = 0; i < Common.natomcolors; i++) {
1270 fg[i] = "red";
1271 fgpixel[i] = ConvertColorToPixel(FGDialog[i], fg[i]);
1273 if (fgpixel[i] == (Pixel) -1) return;
1275 XtVaSetValues(FGDialog[i], XtNvalue, fg[i], NULL);
1277 size[i] = "20";
1278 diam[i] = atoi(size[i]);
1280 if (diam[i] < 1 || diam[i] > MAXDIAM) return;
1281 XtVaSetValues(SizeDialog[i], XtNvalue, size[i], NULL);
1284 SetAtomColors(fgpixel);
1286 for(i = 0; i < Common.natomcolors; i++)
1287 Common.diameter[i] = diam[i];
1290 Common.atoms_visible[0] = 0;
1291 Common.atoms_visible[1] = 0;
1292 Common.atoms_visible[2] = 0;
1293 Common.atoms_visible[3] = 0;
1296 bg = "green";
1297 bgpixel = ConvertColorToPixel(BGDialog, bg);
1299 if (bgpixel == (Pixel) -1) {
1300 XtVaSetValues(BGDialog, XtNvalue, "-Invalid Color-", NULL);
1301 XBell(XtDisplay(BGDialog), 0);
1302 return;
1305 SetBGColor(bgpixel);
1307 SceneUpdate();
1310 PRIVATE void visible_toggle(Widget w, XtPointer client_data,
1311 XtPointer call_data)
1313 int i;
1314 XtPointer data;
1315 char c;
1317 i = (int) client_data;
1319 XtVaGetValues(w, XtNradioData, &data, NULL);
1321 c = *((char *) data);
1323 Common.atoms_visible[i] = c == 'v';
1326 PRIVATE void bvisible_toggle(Widget w, XtPointer client_data,
1327 XtPointer call_data)
1329 int i;
1330 XtPointer data;
1331 char c;
1333 i = (int) client_data;
1335 XtVaGetValues(w, XtNradioData, &data, NULL);
1337 c = *((char *) data);
1339 Common.bonds_visible[i] = c == 'v';