File: full_colors.c

package info (click to toggle)
garlic 1.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,492 kB
  • ctags: 1,013
  • sloc: ansic: 29,925; makefile: 753
file content (213 lines) | stat: -rw-r--r-- 5,684 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

			    full_colors.c

Purpose:
	This function  handles the precise  color definitions.  The input
	string is expected  at least three tokens,  specifying three near
	and three far colors. The keyword old may be used to leave any of
	the old  colors  unchanged.  See  the table below  for mapping of
	tokens.  If  six colors  are  defined,  there  will be  two color
	surfaces; nine colors define three color surfaces etc.

Input:
	(1) Pointer to MolComplexS structure.
	(2) Number of macromolecular complexes.
	(3) Pointer to GUIS structure, with GUI data.
	(4) String with six colors.

Output:
	(1) Return value.

Return value:
	(1) Positive on success.
	(2) Negative on failure.

Notes:
	(1) Mapping tokens to colors:

	    ==================
	    | token | color  |
	    ==================
	    |   1   | left   |
	    |   2   | middle |
	    |   3   | right  |
	    ==================

=============================================================================*/

#include <stdio.h>

#include <string.h>

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======function prototypes:=================================================*/

char		*ExtractToken_ (char *, int, char *, char *);
int		IsOld_ (char *);
int		ParseColor_ (RGBS *, unsigned long *, GUIS *, char *, char *);

/*======full color specifications:===========================================*/

int FullColors_ (MolComplexS *mol_complexSP, int mol_complexesN,
		 GUIS *guiSP, char *stringP)
{
char			*remainderP;
char			tokenA[SHORTSTRINGSIZE];
int			tokensN = 0;
int			surfacesN, surfaceI;
size_t			rgb_struct_size;
RGBS			rgbS;
unsigned long		dummyID;
static ColorSchemeS	color_schemeS;
int			leftF[MAXSURFACES];
int			middleF[MAXSURFACES];
int			rightF[MAXSURFACES];
int			mol_complexI;
MolComplexS		*curr_mol_complexSP;
size_t			atomsN, atomI;
AtomS			*curr_atomSP;

/* Skip the first token: */
remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t,;");
if (remainderP == NULL) return -1;

/* Count tokens: */
while ((remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE,
				    remainderP, " \t,;")) != NULL) tokensN++;

/* Check the number of tokens: */
if (tokensN == 0) return -2;
if ((tokensN % 3) != 0) return -3;

/* Prepare the number of surfaces: */
surfacesN = tokensN / 3;
if (surfacesN > MAXSURFACES) return -4;

/*------extract and parse colors:--------------------------------------------*/

/* Skip the first token: */
remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE, stringP, " \t,;");
if (remainderP == NULL) return -5;

/* The size of RGBS structure: */
rgb_struct_size = sizeof (RGBS); 

/* Parse all tokens: */
for (surfaceI = 0; surfaceI < surfacesN; surfaceI++)
	{
	/** Left color: **/
	remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE,
				    remainderP, " \t,;");
	if (remainderP == NULL) return -6;
	if (IsOld_ (tokenA)) leftF[surfaceI] = 0;
	else
		{
		leftF[surfaceI] = 1;
		ParseColor_ (&rgbS, &dummyID, guiSP, tokenA, "white");
		memcpy (color_schemeS.left_rgbSA + surfaceI,
			&rgbS, rgb_struct_size);
		}

	/** Middle color: **/
	remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE,
				    remainderP, " \t,;");
	if (remainderP == NULL) return -7;
	if (IsOld_ (tokenA)) middleF[surfaceI] = 0;
	else
		{
		middleF[surfaceI] = 1;
		ParseColor_ (&rgbS, &dummyID, guiSP, tokenA, "gray");
		memcpy (color_schemeS.middle_rgbSA + surfaceI,
			&rgbS, rgb_struct_size);
		}

	/** Right color: **/
	remainderP = ExtractToken_ (tokenA, SHORTSTRINGSIZE,
				    remainderP, " \t,;");
	if (remainderP == NULL) return -8;
	if (IsOld_ (tokenA)) rightF[surfaceI] = 0;
	else
		{
		rightF[surfaceI] = 1;
		ParseColor_ (&rgbS, &dummyID, guiSP, tokenA, "black");
		memcpy (color_schemeS.right_rgbSA + surfaceI,
			&rgbS, rgb_struct_size);
		}
	}

/*------assign colors to selected atoms:-------------------------------------*/

/* Scan every macromolecular complex: */
for (mol_complexI = 0; mol_complexI < mol_complexesN; mol_complexI++)
	{
	/** Pointer to the current macromolecular complex: **/
	curr_mol_complexSP = mol_complexSP + mol_complexI;

	/** Check is the current macromolecular complex caught: **/
	if (curr_mol_complexSP->catchF == 0) continue;

	/** Number of atoms in a macromolecular complex: **/
	atomsN = curr_mol_complexSP->atomsN;

	/** Scan all atoms in the current complex: **/
	for (atomI = 0; atomI < atomsN; atomI++)
		{
		/** Pointer to the current atom: **/
		curr_atomSP = curr_mol_complexSP->atomSP + atomI;

		/** Check is atom selected: **/
		if (curr_atomSP->selectedF == 0) continue;

		/** Set the number of color surfaces: **/
		curr_atomSP->surfacesN = surfacesN;

		/** Copy the color specifications: **/
		for (surfaceI = 0; surfaceI < surfacesN; surfaceI++)
			{
			/*** Left color: ***/
			if (leftF[surfaceI])
				{
				memcpy (curr_atomSP->left_rgbSA  + surfaceI,
					color_schemeS.left_rgbSA + surfaceI,
					rgb_struct_size);
				}

			/*** Middle color: ***/
			if (middleF[surfaceI])
				{
				memcpy (curr_atomSP->middle_rgbSA  + surfaceI,
					color_schemeS.middle_rgbSA + surfaceI,
					rgb_struct_size);
				}

			/*** Right color: ***/
			if (rightF[surfaceI])
				{
				memcpy (curr_atomSP->right_rgbSA  + surfaceI,
					color_schemeS.right_rgbSA + surfaceI,
					rgb_struct_size);
				}
			}
		}

	/* Reset the position_changedF: */
	curr_mol_complexSP->position_changedF = 1;
	}

/* Return positive value on success: */
return 1;
}

/*===========================================================================*/