NCBI C Toolkit Cross Reference

C/cn3d/cn3dmsel.c


  1 /*   cn3dmsel.c
  2 * ===========================================================================
  3 *
  4 *                            PUBLIC DOMAIN NOTICE
  5 *            National Center for Biotechnology Information (NCBI)
  6 *
  7 *  This software/database is a "United States Government Work" under the
  8 *  terms of the United States Copyright Act.  It was written as part of
  9 *  the author's official duties as a United States Government employee and
 10 *  thus cannot be copyrighted.  This software/database is freely available
 11 *  to the public for use. The National Library of Medicine and the U.S.
 12 *  Government do not place any restriction on its use or reproduction.
 13 *  We would, however, appreciate having the NCBI and the author cited in
 14 *  any work or product based on this material
 15 *
 16 *  Although all reasonable efforts have been taken to ensure the accuracy
 17 *  and reliability of the software and data, the NLM and the U.S.
 18 *  Government do not and cannot warrant the performance or results that
 19 *  may be obtained by using this software or data. The NLM and the U.S.
 20 *  Government disclaim all warranties, express or implied, including
 21 *  warranties of performance, merchantability or fitness for any particular
 22 *  purpose.
 23 *
 24 * ===========================================================================
 25 *
 26 * File Name:  cn3dmsel.c
 27 *
 28 * Author:  Christopher Hogue
 29 *
 30 * Version Creation Date:   1/31/96
 31 *
 32 * File Description: Reusable group for model selection in mmdbapi 
 33 *
 34 * Modifications:  
 35 * --------------------------------------------------------------------------
 36 * $Log: cn3dmsel.c,v $
 37 * Revision 6.1  1999/10/29 14:15:29  thiessen
 38 * ran all Cn3D source through GNU Indent to prettify
 39 *
 40 * Revision 6.0  1997/08/25 18:13:35  madden
 41 * Revision changed to 6.0
 42 *
 43 * Revision 5.0  1996/05/28 14:05:44  ostell
 44 * Set to revision 5.0
 45 *
 46  * Revision 1.4  1996/05/09  15:41:27  hogue
 47  * Fixed SGI compiler warnings.
 48  *
 49  * Revision 1.3  1996/04/26  18:42:34  vakatov
 50  * CN3D sources ported to MS-Windows;
 51  * the portability errors and warnings fixed, etc.
 52  *
 53  * Revision 1.2  1996/02/02  19:40:04  hogue
 54  * Initial Revision
 55  *
 56 *
 57 * ==========================================================================
 58 */
 59 
 60 #include <vibrant.h>
 61 #include <mmdbapi.h>
 62 #include <cn3dmsel.h>
 63 #include <cn3dmain.h>
 64 
 65 
 66 static GrouP Cn3D_gModelSelect;
 67 static LisT Cn3D_lModels;
 68 static Boolean VectorKeeper = FALSE;
 69 
 70 static void Cn3D_ModelPickProc(LisT l)
 71 {
 72     Int2 iCount = 0;
 73     PDNMS pdnmsThis;
 74     PDNML pdnmlThis;
 75     PMSD pmsdThis;
 76     PMLD pmldThis;
 77 
 78     /* sets all models' status at once */
 79 
 80     pdnmsThis = GetSelectedModelstruc();
 81     pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
 82     pdnmlThis = pmsdThis->pdnmlModels;
 83     while (pdnmlThis) {
 84         pmldThis = (PMLD) pdnmlThis->data.ptrvalue;
 85         if ((pmldThis->iType == Model_type_ncbi_vector)
 86             && (VectorKeeper == FALSE)) {
 87             pmldThis->bSelected &= (Byte) 0xFE; /* don't keep vectors - ignore 'em */
 88         } else {
 89             iCount++;
 90             ASSERT(iCount > 0);
 91             if (GetItemStatus(Cn3D_lModels, iCount))
 92                 pmldThis->bSelected |= (Byte) 0x01;
 93             else
 94                 pmldThis->bSelected &= (Byte) 0xFE;
 95         }
 96         pdnmlThis = pdnmlThis->next;
 97     }
 98     return;
 99 }
100 
101 
102 
103 GrouP LIBCALL Cn3D_ModelSelect(GrouP g, Boolean KeepVectors)
104 {
105     PDNMS pdnmsThis = NULL;
106     PMSD pmsdThis = NULL;
107     PDNML pdnmlThis = NULL;     /* list of models */
108     PMLD pmldThis = NULL;
109     ValNodePtr pvnModelStrings = NULL;
110     ValNodePtr pvnTemp = NULL;
111     Int2 iCount = 0;
112     Char pcModelString[35];
113 
114 
115     pdnmsThis = GetSelectedModelstruc();
116     if (pdnmsThis)
117         pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
118     if (pmsdThis)
119         pdnmlThis = pmsdThis->pdnmlModels;
120     if (!pdnmlThis) {
121         Cn3D_gModelSelect =
122             NormalGroup(g, 0, 1, "Select Models:", systemFont, NULL);
123         SetGroupMargins(Cn3D_gModelSelect, 10, 10);
124         SetGroupSpacing(Cn3D_gModelSelect, 10, 5);
125         StaticPrompt(Cn3D_gModelSelect, "No Models  ", 0, 0, systemFont,
126                      'l');
127         return Cn3D_gModelSelect;
128     }
129     VectorKeeper = KeepVectors;
130     while (pdnmlThis) {
131         pmldThis = (PMLD) pdnmlThis->data.ptrvalue;
132         if (!
133             ((pmldThis->iType == Model_type_ncbi_vector)
134              && (KeepVectors == FALSE))) {
135             iCount++;
136             pcModelString[0] = '\0';
137             sprintf(pcModelString, "%d ", (int) pdnmlThis->choice);
138             switch (pmldThis->iType) {
139             case Model_type_ncbi_vector:
140                 StringCat(pcModelString, "Vector Model");
141                 break;
142             case Model_type_ncbi_backbone:
143                 StringCat(pcModelString, "Backbone Model");
144                 break;
145             case Model_type_ncbi_all_atom:
146                 StringCat(pcModelString, "One XYZ Coord/Atom Model");
147                 break;
148             case Model_type_pdb_model:
149                 StringCat(pcModelString, "Original PDB Model");
150                 break;
151             default:
152             case Model_type_other:
153                 StringCat(pcModelString, "Other model");
154             }
155             ValNodeCopyStr(&pvnModelStrings, pdnmlThis->choice,
156                            pcModelString);
157         }
158         pdnmlThis = pdnmlThis->next;
159     }
160     /* set up a group enclosing structures - models selection lists and - "info strings" */
161 
162     Cn3D_gModelSelect =
163         NormalGroup(g, 0, 1, "Select Models:", systemFont, NULL);
164     SetGroupMargins(Cn3D_gModelSelect, 10, 10);
165     SetGroupSpacing(Cn3D_gModelSelect, 10, 5);
166     Cn3D_lModels = MultiList(Cn3D_gModelSelect, 18, 3, Cn3D_ModelPickProc);
167     pvnTemp = pvnModelStrings;
168     while (pvnTemp) {
169         ListItem(Cn3D_lModels, (CharPtr) pvnTemp->data.ptrvalue);
170         pvnTemp = pvnTemp->next;
171     }
172     if (pvnModelStrings)
173         ValNodeFreeData(pvnModelStrings);
174     iCount = 0;
175     pdnmlThis = pmsdThis->pdnmlModels;
176     while (pdnmlThis) {         /* walk models, set select status for list */
177         pmldThis = (PMLD) pdnmlThis->data.ptrvalue;
178         if (!
179             ((pmldThis->iType == Model_type_ncbi_vector)
180              && (KeepVectors == FALSE))) {
181             iCount++;
182             SetItemStatus(Cn3D_lModels, iCount,
183                           (Boolean) (pmldThis->bSelected & (Byte) 0x01));
184         } else {
185             pmldThis->bSelected &= (Byte) 0xFE;
186         }
187         pdnmlThis = pdnmlThis->next;
188     }
189     return Cn3D_gModelSelect;
190 }
191 
192 
193 Int2Ptr LIBCALL PickedModels(Int4Ptr piNumModels)
194 {
195 
196     Int4 iCount = 0;
197     PDNMS pdnmsMain = NULL;
198     PMSD pmsdThis = NULL;
199     PDNML pdnmlThis = NULL;
200     PMLD pmldThis = NULL;
201     ValNodePtr pvnModelNos = NULL;
202     ValNodePtr pvnTemp = NULL;
203     Int2Ptr i2Vec = NULL;
204 
205     pdnmsMain = GetSelectedModelstruc();
206     if (!pdnmsMain) {
207         *piNumModels = iCount;
208         return NULL;
209     }
210     pmsdThis = (PMSD) pdnmsMain->data.ptrvalue;
211     pdnmlThis = pmsdThis->pdnmlModels;
212 
213     /* make a linked-list of selected model id's */
214     if (!pdnmlThis) {
215         *piNumModels = iCount;
216         return NULL;
217     }
218     while (pdnmlThis) {
219         pmldThis = (PMLD) pdnmlThis->data.ptrvalue;
220         if (pmldThis->bSelected & (Byte) 0x01) {
221             ValNodeAddInt(&pvnModelNos, pdnmlThis->choice,
222                           pdnmlThis->choice);
223             iCount++;
224         }
225         pdnmlThis = pdnmlThis->next;
226     }
227 
228     /* Allocate the vector */
229 
230     if (iCount)
231         i2Vec = I2Vector(0, iCount);
232     else {
233         return NULL;
234     }
235     /* copy the model numbers into vector */
236 
237     iCount = 0;
238     pvnTemp = pvnModelNos;
239     while (pvnTemp) {
240         i2Vec[iCount] = pvnTemp->choice;
241         iCount++;
242         pvnTemp = pvnTemp->next;
243     }
244 
245     /* free the linked-list */
246     if (pvnModelNos)
247         ValNodeFree(pvnModelNos);
248     *piNumModels = iCount;
249     return i2Vec;
250 }
251 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.