1 /* Copyright (C) 2000 Damir Zucic */
2
3 /*=============================================================================
4
5 comm_slab.c
6
7 Purpose:
8 Execute slab command. Change slab mode or change the position of
9 front or back slab surface.
10
11 Input:
12 (1) Pointer to MolComplexS structure, with macromol. complexes.
13 (2) The number of macromolecular complexes.
14 (3) Pointer to RuntimeS structure, with some runtime data.
15 (4) Pointer to ConfigS structure, with configuration data.
16 (5) Pointer to GUIS structure, with GUI data.
17 (6) Pointer to NearestAtomS structure.
18 (7) The number of pixels in the main window free area.
19 (8) Pointer to refreshI.
20 (9) String which contains slab surface specification and slab
21 shift.
22
23 Output:
24 (1) Slab surfaces moved.
25 (2) Return value.
26
27 Return value:
28 (1) Positive (command) code on success.
29 (2) Negative (error) code on failure.
30
31 ========includes:============================================================*/
32
33 #include <stdio.h>
34
35 #include <string.h>
36
37 #include <X11/Xlib.h>
38 #include <X11/Xutil.h>
39 #include <X11/Xos.h>
40 #include <X11/Xatom.h>
41
42 #include "defines.h"
43 #include "commands.h"
44 #include "typedefs.h"
45
46 /*======function prototypes:=================================================*/
47
48 char *ExtractToken_ (char *, int, char *, char *);
49 int ChangeSlab_ (MolComplexS *, int, int);
50 void MoveBackSlab_ (MolComplexS *, int, ConfigS *, double);
51 void MoveFrontSlab_ (MolComplexS *, int, ConfigS *, double);
52 size_t MainRefresh_ (MolComplexS *, int,
53 RuntimeS *, ConfigS *, GUIS *,
54 NearestAtomS *, size_t, unsigned int);
55 int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
56
57 /*======execute slab command:================================================*/
58
CommandSlab_(MolComplexS * mol_complexSP,int mol_complexesN,RuntimeS * runtimeSP,ConfigS * configSP,GUIS * guiSP,NearestAtomS * nearest_atomSP,size_t pixelsN,unsigned int * refreshIP,char * stringP)59 int CommandSlab_ (MolComplexS *mol_complexSP, int mol_complexesN,
60 RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
61 NearestAtomS *nearest_atomSP, size_t pixelsN,
62 unsigned int *refreshIP, char *stringP)
63 {
64 char *remainderP;
65 char tokenA[STRINGSIZE];
66 int surfaceID;
67 double shift;
68
69 /* Extract the first token: */
70 remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n");
71 if (!remainderP)
72 {
73 strcpy (runtimeSP->messageA, "Slab specification incomplete!");
74 runtimeSP->message_length = strlen (runtimeSP->messageA);
75 return ERROR_SLAB;
76 }
77
78 /* Switch slab off: */
79 if (strstr (tokenA, "OFF") == tokenA)
80 {
81 ChangeSlab_ (mol_complexSP, mol_complexesN, 0);
82 (*refreshIP)++;
83 MainRefresh_ (mol_complexSP, mol_complexesN,
84 runtimeSP, configSP, guiSP,
85 nearest_atomSP, pixelsN, *refreshIP);
86 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
87 configSP, guiSP);
88 return COMMAND_SLAB;
89 }
90
91 /* Change slab to planar: */
92 else if (strstr (tokenA, "PLA") == tokenA)
93 {
94 ChangeSlab_ (mol_complexSP, mol_complexesN, 1);
95 (*refreshIP)++;
96 MainRefresh_ (mol_complexSP, mol_complexesN,
97 runtimeSP, configSP, guiSP,
98 nearest_atomSP, pixelsN, *refreshIP);
99 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
100 configSP, guiSP);
101 return COMMAND_SLAB;
102 }
103
104 /* Change slab to spherical: */
105 else if (strstr (tokenA, "SPH") == tokenA)
106 {
107 ChangeSlab_ (mol_complexSP, mol_complexesN, 2);
108 (*refreshIP)++;
109 MainRefresh_ (mol_complexSP, mol_complexesN,
110 runtimeSP, configSP, guiSP,
111 nearest_atomSP, pixelsN, *refreshIP);
112 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
113 configSP, guiSP);
114 return COMMAND_SLAB;
115 }
116
117 /* Change slab to semi-spherical: */
118 else if ((strstr (tokenA, "HALF-SPH") == tokenA) ||
119 (strstr (tokenA, "HALF_SPH") == tokenA))
120 {
121 ChangeSlab_ (mol_complexSP, mol_complexesN, 3);
122 (*refreshIP)++;
123 MainRefresh_ (mol_complexSP, mol_complexesN,
124 runtimeSP, configSP, guiSP,
125 nearest_atomSP, pixelsN, *refreshIP);
126 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
127 configSP, guiSP);
128 return COMMAND_SLAB;
129 }
130
131 /* Change slab to cylindrical: */
132 else if (strstr (tokenA, "CYL") == tokenA)
133 {
134 ChangeSlab_ (mol_complexSP, mol_complexesN, 4);
135 (*refreshIP)++;
136 MainRefresh_ (mol_complexSP, mol_complexesN,
137 runtimeSP, configSP, guiSP,
138 nearest_atomSP, pixelsN, *refreshIP);
139 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
140 configSP, guiSP);
141 return COMMAND_SLAB;
142 }
143
144 /* Change slab to semi-cylindrical: */
145 else if ((strstr (tokenA, "HALF-CYL") == tokenA) ||
146 (strstr (tokenA, "HALF_CYL") == tokenA))
147 {
148 ChangeSlab_ (mol_complexSP, mol_complexesN, 5);
149 (*refreshIP)++;
150 MainRefresh_ (mol_complexSP, mol_complexesN,
151 runtimeSP, configSP, guiSP,
152 nearest_atomSP, pixelsN, *refreshIP);
153 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
154 configSP, guiSP);
155 return COMMAND_SLAB;
156 }
157
158 /* Identify the surface: */
159 else if (strstr (tokenA, "FRO") == tokenA) surfaceID = 1;
160 else if (strstr (tokenA, "BAC") == tokenA) surfaceID = 2;
161 else
162 {
163 strcpy (runtimeSP->messageA,
164 "Bad surface (valid keywords are front and back)!");
165 runtimeSP->message_length = strlen (runtimeSP->messageA);
166 return ERROR_BAD_SURFACE;
167 }
168
169 /* Extract the token which contains the shift: */
170 remainderP = ExtractToken_ (tokenA, STRINGSIZE, remainderP, " \t\n");
171 if (!remainderP)
172 {
173 strcpy (runtimeSP->messageA, "Slab shift missing!");
174 runtimeSP->message_length = strlen (runtimeSP->messageA);
175 return ERROR_NO_SHIFT;
176 }
177
178 /* Extract the shift: */
179 if (sscanf (tokenA, "%lf", &shift) != 1)
180 {
181 strcpy (runtimeSP->messageA,
182 "Slab specification is bad (unknown keyword used)!");
183 runtimeSP->message_length = strlen (runtimeSP->messageA);
184 return ERROR_NO_SHIFT;
185 }
186
187 /* Move the specified slab surface: */
188 if (surfaceID == 1)
189 {
190 MoveFrontSlab_ (mol_complexSP, mol_complexesN, configSP, shift);
191 }
192 else
193 {
194 MoveBackSlab_ (mol_complexSP, mol_complexesN, configSP, shift);
195 }
196
197 /* Refresh the main window: */
198 (*refreshIP)++;
199 MainRefresh_ (mol_complexSP, mol_complexesN,
200 runtimeSP, configSP, guiSP,
201 nearest_atomSP, pixelsN, *refreshIP);
202
203 /* Refresh the control window: */
204 ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
205
206 /* Return positive value on success: */
207 return COMMAND_SLAB;
208 }
209
210 /*===========================================================================*/
211
212
213