File: main_refresh.c

package info (click to toggle)
garlic 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny, squeeze
  • size: 4,440 kB
  • ctags: 1,403
  • sloc: ansic: 52,465; makefile: 1,133
file content (468 lines) | stat: -rw-r--r-- 16,785 bytes parent folder | download | duplicates (4)
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
/* Copyright (C) 2000-2006 Damir Zucic */

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

				main_refresh.c

Purpose:
	Refresh  the main  window  content.  This function  does the most
	important job from  the user's standpoint: draws something to the
	screen.  This function calls  the functions  which are  doing the
	most important job.

Input:
	(1) Pointer to MolComplexS structure, with macromol. complexes.
	(2) Number of macromolecular complexes.
	(3) Pointer to RuntimeS structure, with some runtime data.
	(4) Pointer to ConfigS structure, with configuration data.
	(5) Pointer to GUIS structure, with GUI data.
	(6) Pointer to NearestAtomS structure, with information about the
	    atom occupying the given pixel.
	(7) The number of pixels in the main window free area.
	(8) The refreshI, used to check the  NearestAtomS associated with
	    a given pixel.  If refreshI is larger than  the corresponding
	    value stored in NearestAtomS,  the structure does not contain
	    fresh data, so the pixel may be redrawn without any checking.
	    If values are equal,  the check should be  made to see  which
	    atom is closer  to the observer:  the one which  is currently
	    processed, or the one which already occupies the pixel.

Output:
	(1) Image drawn to the main window.
	(2) Return value.

Return value:
	(1) Depends on  main window  drawing mode index.  If mode is zero 
	    the number of atoms which were drawn  will be returned.  Zero
	    is returned if there are no visible atoms.  Negative value is
	    never returned,  because the return type is size_t,  so it is
	    unsigned on most systems.

Notes:
	(1) The initial drawing destination is the hidden pixmap, and the
	    content of this pixmap is  copied  later to  the main window.

	(2) The human eye may discriminate  something like  25 images per 
	    second.  Thus,  if this  function executes  once in less than
	    40  milliseconds,  refreshing will be smooth for the user. It
	    will be quite smooth even if needs more time for one passage,
	    because drawing is done on hidden pixmap ("hidden frame").

	(3) In default mode  (structure drawing mode),  after  the loaded
	    objects are drawn,  a small legend is placed to  the top left
	    corner (system.xpm).

	(4) A macromolecular object is visible and should be projected if
	    if least  one atom  of  this object  is visible.  The atom is
	    visible  if it is  not  hidden  (user may decide to hide some
	    atoms) and if it  falls inside the slab.  This does  not mean
	    that this atom will be truly visible in the main window:  its	
	    projection  may be outside  the free area of the main window.
	    Note  that the term  visible applyes both to  the atoms which
	    are actually  visible and to  the atoms  which are  projected
	    outside of the main window free area!

	(5) Do not change the execution order of Slab_, ProjectAtoms_ and
	    Fading_ !

	(6) Note that atoms and bonds  are drawn  style by style.  In the
	    first step,  only atoms which have  style "1"  are drawn. All
	    other atoms are ignored in this step. In the next step, atoms
	    which have style "2" are drawn etc.  Another approach will be
	    to draw  atom by atom  and bond by bond,  choosing the proper
	    style. This may require a larger number of function calls and
	    repeated passing of certain parameters, reducing the speed of
	    execution.

	(7) Planes are drawn after atoms and bonds are drawn.

========includes:============================================================*/

#include <stdio.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:=================================================*/

void		InformUser_ (GUIS *, char *);
int		RefreshPixmap_ (Display *, Pixmap, GC,
				unsigned int, unsigned int, unsigned long);
size_t		Slab_ (MolComplexS *, int);
size_t		ProjectAtoms_ (MolComplexS *, int, ConfigS *);
void		ProjectMembranes_ (MolComplexS *, int, ConfigS *);
void		ProjectPlanes_ (MolComplexS *, int, ConfigS *);
size_t		Fading_ (MolComplexS *, int, GUIS *);
void		ResetPositionFlag_ (MolComplexS *, int);
size_t		DrawAtomsStyle1_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawAtomsStyle2_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawAtomsStyle3_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawAtomsStyle4_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawAtomsStyle5_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawAtomsStyle6_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawAtomsStyle7_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawBondsStyle1_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawBondsStyle2_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawBondsStyle3_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawBondsStyle4_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawBondsStyle5_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawNiceBonds_ (MolComplexS *, int, ConfigS *, GUIS *,
				NearestAtomS *, size_t, unsigned int);
size_t		DrawSticks_ (MolComplexS *, int, ConfigS *, GUIS *,
			     NearestAtomS *, size_t, unsigned int);
size_t		DrawBackbone_ (MolComplexS *, int, ConfigS *, GUIS *,
			       NearestAtomS *, size_t, unsigned int);
int		DrawBalls_ (MolComplexS *, int, ConfigS *, GUIS *,
			    NearestAtomS *, size_t, unsigned int);
int		DrawBalls2_ (MolComplexS *, int, ConfigS *, GUIS *,
			     NearestAtomS *, size_t, unsigned int);
int		DrawBigSpheres_ (MolComplexS *, int, ConfigS *, GUIS *,
				 NearestAtomS *, size_t, unsigned int);
int		DrawBigSpheres2_ (MolComplexS *, int, ConfigS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
int		DrawSpacefill_ (MolComplexS *, int, ConfigS *, GUIS *,
				NearestAtomS *, size_t, unsigned int);
int		DrawSpacefill2_ (MolComplexS *, int, ConfigS *, GUIS *,
				 NearestAtomS *, size_t, unsigned int);
int		DrawCovalent_ (MolComplexS *, int, ConfigS *, GUIS *,
			       NearestAtomS *, size_t, unsigned int);
int		DrawCovalent2_ (MolComplexS *, int, ConfigS *, GUIS *,
				NearestAtomS *, size_t, unsigned int);
int		DrawSmall_ (MolComplexS *, int, ConfigS *, GUIS *,
			    NearestAtomS *, size_t, unsigned int);
int		DrawSmall2_ (MolComplexS *, int, ConfigS *, GUIS *,
			     NearestAtomS *, size_t, unsigned int);
int		DrawEditSymbol_ (MolComplexS *, int,
				 RuntimeS *, ConfigS *, GUIS *,
				 NearestAtomS *, size_t, unsigned int);
int		DrawMembranes_ (MolComplexS *, int, ConfigS *, GUIS *,
				NearestAtomS *, size_t, unsigned int);
int		DrawPlanes_ (MolComplexS *, int, ConfigS *, GUIS *,
			     NearestAtomS *, size_t, unsigned int);
size_t		DrawRamachandran_ (MolComplexS *, int,
				   RuntimeS *, ConfigS *, GUIS *,
				   NearestAtomS *, size_t, unsigned int);
size_t		WheelTopView_ (RuntimeS *, GUIS *,
			       NearestAtomS *, size_t, unsigned int);
size_t		WheelBottomView_ (RuntimeS *, GUIS *,
				  NearestAtomS *, size_t, unsigned int);
size_t		DrawVenn_ (RuntimeS *, GUIS *,
			   NearestAtomS *, size_t, unsigned int);
size_t		DrawPlots_ (RuntimeS *, GUIS *,
			    NearestAtomS *, size_t, unsigned int);
size_t		DrawComparison_ (RuntimeS *, GUIS *,
				 NearestAtomS *, size_t, unsigned int);
int		SmallRamachandran_ (MolComplexS *, RuntimeS *, GUIS *);
int		SmallOmega_ (MolComplexS *, RuntimeS *, GUIS *);
int		BlurMainWindow_ (RuntimeS *, GUIS *, NearestAtomS *, size_t);
size_t		DrawLabels_ (MolComplexS *, int, ConfigS *, GUIS *);
int		DrawTags_ (MolComplexS *, int, ConfigS *, GUIS *);
int		DrawTitles_ (RuntimeS *, GUIS *);
int		DrawSystem_ (GUIS *);
int		WriteHints_ (GUIS *);

/*======refresh the main window:=============================================*/

size_t MainRefresh_ (MolComplexS *mol_complexSP, int mol_complexesN,
		     RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
		     NearestAtomS *nearest_atomSP, size_t pixelsN,
		     unsigned int refreshI)
{
size_t			atoms_drawnN = 0;
size_t			pixelI;
NearestAtomS		*curr_pixelSP;
int			edit_modeI;

/* Check  the main window refresh flag:  if it is equal to  zero,  do not */
/* refresh the main window - just inform the user that refreshing is off: */
if (guiSP->main_window_refreshF == 0)
	{
	InformUser_ (guiSP, "Refreshing off!");
	return 0;
	}

/* Draw Ramachandran plot instead of structure, if requested: */
if (guiSP->main_window_modeI == 1)
	{
	return DrawRamachandran_ (mol_complexSP, mol_complexesN,
				  runtimeSP, configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);
	}

/* Draw helical wheel instead of structure, if requested: */
else if (guiSP->main_window_modeI == 2)
	{
	/* Counterclockwise wheel: */
	if (runtimeSP->wheel_clockwiseF == 0)
		{
		return WheelTopView_ (runtimeSP, guiSP,
				      nearest_atomSP, pixelsN, refreshI);
		}
	else
		{
		return WheelBottomView_ (runtimeSP, guiSP,
					 nearest_atomSP, pixelsN, refreshI);
		}
	}

/* Draw Venn diagram instead of structure, if requested: */
else if (guiSP->main_window_modeI == 3)
	{
	return DrawVenn_ (runtimeSP, guiSP,
			  nearest_atomSP, pixelsN, refreshI);
	}

/* Draw hydrophobicity plots instead of structure, if requested: */
else if (guiSP->main_window_modeI == 4)
	{
	return DrawPlots_ (runtimeSP, guiSP,
			   nearest_atomSP, pixelsN, refreshI);
	}

/* Draw sequence comparison: */
else if (guiSP->main_window_modeI == 5)
	{
	return DrawComparison_ (runtimeSP, guiSP,
				nearest_atomSP, pixelsN, refreshI);
	}

/* If this point is reached,  structures should be drawn */
/* (default drawing mode, guiSP->main_window_modeI = 0). */

/*---------------------------------------------------------------------------*/

/* Refresh the hidden pixmap, where drawing will be done: */
RefreshPixmap_ (guiSP->displaySP,
		guiSP->main_hidden_pixmapID,
		guiSP->theGCA[0],
		guiSP->control_winS.x0, guiSP->input_winS.y0,
		guiSP->main_winS.bg_colorID);

/* If blur is on,  fill the colorID element of each */
/* NearestAtomS structure with background color ID: */
if (runtimeSP->blurF)
	{
	for (pixelI = 0; pixelI < pixelsN; pixelI++)
		{
		curr_pixelSP = nearest_atomSP + pixelI;
		curr_pixelSP->colorID = guiSP->main_winS.bg_colorID;
		}
	}

/*---------------------------------------------------------------------------*/

/* Check which atoms are inside slab: */
Slab_ (mol_complexSP, mol_complexesN);

/* Project atoms: */
ProjectAtoms_ (mol_complexSP, mol_complexesN, configSP);

/* Project all available membranes: */
ProjectMembranes_ (mol_complexSP, mol_complexesN, configSP);

/* Project all planes (even if not visible): */
ProjectPlanes_ (mol_complexSP, mol_complexesN, configSP);

/* Prepare  the left,  middle and  right color for each atom. */
/* These are the only colors required by fast drawing styles. */
Fading_ (mol_complexSP, mol_complexesN, guiSP);

/* Reset the position_changedF in each macromolecular complex: */
ResetPositionFlag_ (mol_complexSP, mol_complexesN);

/*------draw atoms (simple styles):------------------------------------------*/

atoms_drawnN += DrawAtomsStyle1_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

atoms_drawnN += DrawAtomsStyle2_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

atoms_drawnN += DrawAtomsStyle3_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

atoms_drawnN += DrawAtomsStyle4_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

atoms_drawnN += DrawAtomsStyle5_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

atoms_drawnN += DrawAtomsStyle6_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

atoms_drawnN += DrawAtomsStyle7_ (mol_complexSP, mol_complexesN,
				  configSP, guiSP,
				  nearest_atomSP, pixelsN, refreshI);

/*------draw bonds (simple styles):------------------------------------------*/

DrawBondsStyle1_ (mol_complexSP, mol_complexesN,
		  configSP, guiSP,
		  nearest_atomSP, pixelsN, refreshI);

DrawBondsStyle2_ (mol_complexSP, mol_complexesN,
		  configSP, guiSP,
		  nearest_atomSP, pixelsN, refreshI);

DrawBondsStyle3_ (mol_complexSP, mol_complexesN,
		  configSP, guiSP,
		  nearest_atomSP, pixelsN, refreshI);

DrawBondsStyle4_ (mol_complexSP, mol_complexesN,
		  configSP, guiSP,
		  nearest_atomSP, pixelsN, refreshI);

DrawBondsStyle5_ (mol_complexSP, mol_complexesN,
		  configSP, guiSP,
		  nearest_atomSP, pixelsN, refreshI);

/*------special drawing functions:-------------------------------------------*/

DrawBackbone_ (mol_complexSP, mol_complexesN,
	       configSP, guiSP,
	       nearest_atomSP, pixelsN, refreshI);

DrawBalls_ (mol_complexSP, mol_complexesN,
	    configSP, guiSP,
	    nearest_atomSP, pixelsN, refreshI);

DrawBalls2_ (mol_complexSP, mol_complexesN,
	     configSP, guiSP,
	     nearest_atomSP, pixelsN, refreshI);

DrawBigSpheres_ (mol_complexSP, mol_complexesN,
		 configSP, guiSP,
		 nearest_atomSP, pixelsN, refreshI);

DrawBigSpheres2_ (mol_complexSP, mol_complexesN,
		  configSP, guiSP,
		  nearest_atomSP, pixelsN, refreshI);

DrawSpacefill_ (mol_complexSP, mol_complexesN,
		configSP, guiSP,
		nearest_atomSP, pixelsN, refreshI);

DrawSpacefill2_ (mol_complexSP, mol_complexesN,
		 configSP, guiSP,
		 nearest_atomSP, pixelsN, refreshI);

DrawCovalent_ (mol_complexSP, mol_complexesN,
	       configSP, guiSP,
	       nearest_atomSP, pixelsN, refreshI);

DrawCovalent2_ (mol_complexSP, mol_complexesN,
		configSP, guiSP,
		nearest_atomSP, pixelsN, refreshI);

DrawSmall_ (mol_complexSP, mol_complexesN,
	    configSP, guiSP,
	    nearest_atomSP, pixelsN, refreshI);

DrawSmall2_ (mol_complexSP, mol_complexesN,
	     configSP, guiSP,
	     nearest_atomSP, pixelsN, refreshI);

DrawNiceBonds_ (mol_complexSP, mol_complexesN,
		configSP, guiSP,
		nearest_atomSP, pixelsN, refreshI);

DrawSticks_ (mol_complexSP, mol_complexesN,
	     configSP, guiSP,
	     nearest_atomSP, pixelsN, refreshI);

if (runtimeSP->edit_modeI != 0)
	{
	DrawEditSymbol_ (mol_complexSP, mol_complexesN,
			 runtimeSP, configSP, guiSP,
			 nearest_atomSP, pixelsN, refreshI);
	}

DrawMembranes_ (mol_complexSP, mol_complexesN,
		configSP, guiSP,
		nearest_atomSP, pixelsN, refreshI);

DrawPlanes_ (mol_complexSP, mol_complexesN,
	     configSP, guiSP,
	     nearest_atomSP, pixelsN, refreshI);

/*------auxiliary symbols and plots:-----------------------------------------*/

/* If editing dihedral angle phi or psi (or both), draw small Rama. */
/* plot for the first selected residue  to the bottom right corner: */
edit_modeI = runtimeSP->edit_modeI;
if ((edit_modeI == 2) || (edit_modeI == 3) || (edit_modeI == 5))
	{
	SmallRamachandran_ (mol_complexSP + runtimeSP->default_complexI,
			    runtimeSP, guiSP);
	}

/* If editing the omega angle, draw small */
/* omega plot to the bottom right corner: */
else if (edit_modeI == 4)
	{
	SmallOmega_ (mol_complexSP + runtimeSP->default_complexI,
		     runtimeSP, guiSP);
	}

/* Write some hints if there are no macromolecular complexes loaded: */
if (mol_complexesN == 0) WriteHints_ (guiSP);

/*---------------------------------------------------------------------------*/

/* Copy hidden pixmap to the main window: */
XCopyArea (guiSP->displaySP,
	   guiSP->main_hidden_pixmapID, guiSP->main_winS.ID,
	   guiSP->theGCA[0],
	   0, 0,
	   guiSP->main_win_free_area_width, guiSP->main_win_free_area_height,
	   0, 0);

/* Blur image if blur flag is equal to one: */
if (runtimeSP->blurF)
	{
	BlurMainWindow_ (runtimeSP, guiSP, nearest_atomSP, pixelsN);
	}

/*------labels, tags, titles and coordinate system hint:---------------------*/

DrawLabels_ (mol_complexSP, mol_complexesN, configSP, guiSP);

DrawTags_ (mol_complexSP, mol_complexesN, configSP, guiSP);

DrawTitles_ (runtimeSP, guiSP);

/* Put a small legend to the top left corner: */
/* (system.xpm, to explain the coord. system) */
if (configSP->show_coord_systemF) DrawSystem_ (guiSP);

/*---------------------------------------------------------------------------*/

return atoms_drawnN;
}

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