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

« back to all changes in this revision

Viewing changes to venn.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
                                venn.c
 
6
 
 
7
Purpose:
 
8
        Execute venn command:  draw Venn diagram for the sequence which is
 
9
        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 the keyword OFF or with
 
22
            a range of residue serial indices.
 
23
 
 
24
Output:
 
25
        (1) The main window mode changed to 3 (default is zero),  i.e. the
 
26
            main window will be switched to Venn diagram.
 
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
========includes:============================================================*/
 
38
 
 
39
#include <stdio.h>
 
40
 
 
41
#include <string.h>
 
42
 
 
43
#include <X11/Xlib.h>
 
44
#include <X11/Xutil.h>
 
45
#include <X11/Xos.h>
 
46
#include <X11/Xatom.h>
 
47
 
 
48
#include "defines.h"
 
49
#include "commands.h"
 
50
#include "typedefs.h"
 
51
 
 
52
/*======function prototypes:=================================================*/
 
53
 
 
54
char            *ExtractToken_ (char *, int, char *, char *);
 
55
int             ExtractTwoIntegers_ (int *, int *, char *);
 
56
void            InitNearest_ (NearestAtomS *, size_t);
 
57
size_t          MainRefresh_ (MolComplexS *, int,
 
58
                              RuntimeS *, ConfigS *, GUIS *,
 
59
                              NearestAtomS *, size_t, unsigned int);
 
60
int             ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
 
61
 
 
62
/*======execute venn command:================================================*/
 
63
 
 
64
int Venn_ (MolComplexS *mol_complexSP, int mol_complexesN,
 
65
           RuntimeS *runtimeSP, ConfigS *configSP, GUIS *guiSP,
 
66
           NearestAtomS *nearest_atomSP, size_t pixelsN,
 
67
           unsigned int *refreshIP, char *stringP)
 
68
{
 
69
char            *remainderP;
 
70
char            tokenA[SHORTSTRINGSIZE];
 
71
char            *P;
 
72
int             n;
 
73
int             residue1I, residue2I;
 
74
 
 
75
/* Extract the first token: */
 
76
remainderP = ExtractToken_ (tokenA, STRINGSIZE, stringP, " \t\n");
 
77
 
 
78
/* If available, the first token should contain keyword OFF: */
 
79
if (remainderP)
 
80
        {
 
81
        /* If keyword OFF is present, switch to default drawing mode: */
 
82
        if (strstr (tokenA, "OFF") == tokenA)
 
83
                {
 
84
                /* Reset drawing mode index: */
 
85
                guiSP->main_window_modeI = 0;
 
86
 
 
87
                /* Reinitialize the NearestAtomS array: */
 
88
                InitNearest_ (nearest_atomSP, pixelsN);
 
89
                *refreshIP = 1;
 
90
 
 
91
                /* Refresh the main window: */
 
92
                (*refreshIP)++;
 
93
                MainRefresh_ (mol_complexSP, mol_complexesN,
 
94
                              runtimeSP, configSP, guiSP,
 
95
                              nearest_atomSP, pixelsN, *refreshIP);
 
96
 
 
97
                /* Refresh the control window: */
 
98
                ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI,
 
99
                                 configSP, guiSP);
 
100
 
 
101
                /* Return the command code: */
 
102
                return COMMAND_VENN;
 
103
                }
 
104
 
 
105
        /* If keyword OFF is not present, try to read two indices: */
 
106
        else
 
107
                {
 
108
                /* Replace each minus in the input string with space: */
 
109
                P = stringP;
 
110
                while ((n = *P++) != '\0')
 
111
                        {
 
112
                        if (n == '-') *(P - 1) = ' ';
 
113
                        }
 
114
 
 
115
                /* If reading fails: */
 
116
                if (ExtractTwoIntegers_ (&residue1I, &residue2I, stringP) < 0)
 
117
                        {
 
118
                        strcpy (runtimeSP->messageA,
 
119
                                "Command interpretation failed!");
 
120
                        runtimeSP->message_length =
 
121
                                                strlen (runtimeSP->messageA);
 
122
                        return ERROR_VENN;
 
123
                        }
 
124
 
 
125
                /* If indices were successfully read, check them: */
 
126
                if (residue2I < residue1I)
 
127
                        {
 
128
                        strcpy (runtimeSP->messageA,
 
129
                                "Bad range (check indices)!");
 
130
                        runtimeSP->message_length =
 
131
                                                strlen (runtimeSP->messageA);
 
132
                        return ERROR_VENN;
 
133
                        }
 
134
 
 
135
                /* Store the extracted indices: */
 
136
                runtimeSP->range_startI = (size_t) residue1I;
 
137
                runtimeSP->range_endI   = (size_t) residue2I;
 
138
                }
 
139
        }
 
140
 
 
141
/* If the first token is not available, initialize range indices: */
 
142
else
 
143
        {
 
144
        runtimeSP->range_startI = *runtimeSP->serialIP;
 
145
        runtimeSP->range_endI   = *(runtimeSP->serialIP +
 
146
                                    runtimeSP->residuesN - 1);
 
147
        }
 
148
 
 
149
/* Set the main window drawing mode index: */
 
150
guiSP->main_window_modeI = 3;
 
151
 
 
152
/* Reinitialize the NearestAtomS array and refresh index: */
 
153
InitNearest_ (nearest_atomSP, pixelsN);
 
154
*refreshIP = 1;
 
155
 
 
156
/* Refresh the main window: */
 
157
(*refreshIP)++;
 
158
MainRefresh_ (mol_complexSP, mol_complexesN,
 
159
              runtimeSP, configSP, guiSP,
 
160
              nearest_atomSP, pixelsN, *refreshIP);
 
161
 
 
162
/* Refresh the control window: */
 
163
ControlRefresh_ (mol_complexSP + runtimeSP->default_complexI, configSP, guiSP);
 
164
 
 
165
/* Return the command code: */
 
166
return COMMAND_VENN;
 
167
}
 
168
 
 
169
/*===========================================================================*/
 
170
 
 
171