~ubuntu-branches/ubuntu/breezy/garlic/breezy

« back to all changes in this revision

Viewing changes to wheel.c

  • Committer: Bazaar Package Importer
  • Author(s): zhaoway
  • Date: 2001-04-24 07:09:13 UTC
  • Revision ID: james.westby@ubuntu.com-20010424070913-uzpupnwdfhmliebz
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2000 Damir Zucic */
 
2
 
 
3
/*=============================================================================
 
4
 
 
5
                                wheel.c
 
6
 
 
7
Purpose:
 
8
        Execute  wheel command:  draw helical wheel for the sequence which
 
9
        is kept in the sequence buffer.
 
10
 
 
11
Input:
 
12
        (1) Pointer to MolComplexS structure.
 
13
        (2) The number of macromolecular complexes.
 
14
        (3) Pointer to RuntimeS structure.
 
15
        (4) Pointer to ConfigS structure.
 
16
        (5) Pointer to GUIS structure.
 
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) Pointer to  the remainder of the command string.  This command
 
21
            may be given without any keyword, with keyword OFF or with two
 
22
            residue serial numbers.
 
23
 
 
24
Output:
 
25
        (1) The main window mode changed to 2 (default is zero),  i.e. the
 
26
            main window will be switched to helical wheel plot.
 
27
        (2) Return value.
 
28
 
 
29
Return value:
 
30
        (1) Positive (command) code on success.
 
31
        (2) Negative (error) code on failure.
 
32
 
 
33
Notes:
 
34
        (1) This command reinitializes the  NearestAtomS array,  except if
 
35
            the additional keyword is not recognized.
 
36
 
 
37
        (2) Helical wheel is drawn for the sequence  which is currently in
 
38
            the sequence buffer. This sequence will be typically short.
 
39
 
 
40
========includes:============================================================*/
 
41
 
 
42
#include <stdio.h>
 
43
 
 
44
#include <string.h>
 
45
 
 
46
#include <X11/Xlib.h>
 
47
#include <X11/Xutil.h>
 
48
#include <X11/Xos.h>
 
49
#include <X11/Xatom.h>
 
50
 
 
51
#include "defines.h"
 
52
#include "commands.h"
 
53
#include "typedefs.h"
 
54
 
 
55
/*======function prototypes:=================================================*/
 
56
 
 
57
char            *ExtractToken_ (char *, int, char *, char *);
 
58
int             ExtractTwoIntegers_ (int *, int *, char *);
 
59
void            InitNearest_ (NearestAtomS *, size_t);
 
60
size_t          MainRefresh_ (MolComplexS *, int,
 
61
                              RuntimeS *, ConfigS *, GUIS *,
 
62
                              NearestAtomS *, size_t, unsigned int);
 
63
int             ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
 
64
 
 
65
/*======execute wheel command:===============================================*/
 
66
 
 
67
int Wheel_ (MolComplexS *mol_complexSP, int mol_complexesN,
 
68
            RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
 
69
            NearestAtomS *nearest_atomSP, size_t pixelsN,
 
70
            unsigned int *refreshIP, char *stringP)
 
71
{
 
72
char            *remainderP;
 
73
char            tokenA[SHORTSTRINGSIZE];
 
74
char            *P;
 
75
int             n;
 
76
int             residue1I, residue2I;
 
77
 
 
78
/* Extract the first token: */
 
79
remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n");
 
80
 
 
81
/* If available, the first token may contain keyword OFF: */
 
82
if (remainderP)
 
83
        {
 
84
        /* If keyword OFF is present, switch to default drawing mode: */
 
85
        if (strstr (tokenA, "OFF") == tokenA)
 
86
                {
 
87
                /* Reset drawing mode index: */
 
88
                guiSP->main_window_modeI = 0;
 
89
 
 
90
                /* Reinitialize the NearestAtomS array: */
 
91
                InitNearest_ (nearest_atomSP, pixelsN);
 
92
                *refreshIP = 1;
 
93
 
 
94
                /* Refresh the main window: */
 
95
                (*refreshIP)++;
 
96
                MainRefresh_ (mol_complexSP, mol_complexesN,
 
97
                              runtimeSP, configSP, guiSP,
 
98
                              nearest_atomSP, pixelsN, *refreshIP);
 
99
 
 
100
                /* Refresh the control window: */
 
101
                ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
 
102
                                 configSP, guiSP);
 
103
 
 
104
                /* Return the command code: */
 
105
                return COMMAND_WHEEL;
 
106
                }
 
107
 
 
108
        /* If keyword OFF is not present, try to read two indices: */
 
109
        else
 
110
                {
 
111
                /* Replace each minus in the input string with space: */
 
112
                P = stringP;
 
113
                while ((n = *P++) != '\0')
 
114
                        {
 
115
                        if (n == '-') *(P - 1) = ' ';
 
116
                        }
 
117
 
 
118
                /* If reading fails: */
 
119
                if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) < 0)
 
120
                        {
 
121
                        strcpy (runtimeSP->messageA,
 
122
                                "Command interpretation failed!");
 
123
                        runtimeSP->message_length =
 
124
                                                strlen (runtimeSP->messageA);
 
125
                        return ERROR_WHEEL;
 
126
                        }
 
127
 
 
128
                /* If indices were successfully read, check them: */
 
129
                if (residue2I < residue1I)
 
130
                        {
 
131
                        strcpy (runtimeSP->messageA,
 
132
                                "Bad range (check indices)!");
 
133
                        runtimeSP->message_length =
 
134
                                                strlen (runtimeSP->messageA);
 
135
                        return ERROR_WHEEL;
 
136
                        }
 
137
 
 
138
                /* Store the extracted indices: */
 
139
                runtimeSP->range_startI = (size_t) residue1I;
 
140
                runtimeSP->range_endI   = (size_t) residue2I;
 
141
                }
 
142
        }
 
143
 
 
144
/* If the first token is not available, initialize range indices: */
 
145
else
 
146
        {
 
147
        runtimeSP->range_startI = *runtimeSP->serialIP;
 
148
        runtimeSP->range_endI   = *(runtimeSP->serialIP +
 
149
                                    runtimeSP->residuesN - 1);
 
150
        }
 
151
 
 
152
/* Set the main window drawing mode index: */
 
153
guiSP->main_window_modeI = 2;
 
154
 
 
155
/* Reinitialize the NearestAtomS array and refresh index: */
 
156
InitNearest_ (nearest_atomSP, pixelsN);
 
157
*refreshIP = 1;
 
158
 
 
159
/* Refresh the main window: */
 
160
(*refreshIP)++;
 
161
MainRefresh_ (mol_complexSP, mol_complexesN,
 
162
              runtimeSP, configSP, guiSP,
 
163
              nearest_atomSP, pixelsN, *refreshIP);
 
164
 
 
165
/* Refresh the control window: */
 
166
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
 
167
 
 
168
/* Return the command code: */
 
169
return COMMAND_WHEEL;
 
170
}
 
171
 
 
172
/*===========================================================================*/
 
173
 
 
174