NCBI C Toolkit Cross Reference

C/cn3d/cn3dmatn.c


  1 /*   cn3dmatn.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:  cn3dmatn.c
 27 *
 28 * Author: Yanli Wang
 29 *
 30 * Version Creation Date:   3/26/98
 31 *
 32 * File Description: Functions for cn3d/salsa communication
 33 *
 34 * Modifications:
 35 * $Log: cn3dmatn.c,v $
 36 * Revision 6.94  2006/07/13 17:08:36  bollin
 37 * use Uint4 instead of Uint2 for itemID values
 38 *
 39 * Revision 6.93  2000/03/14 16:20:56  lewisg
 40 * bug fix: selection on non-aligned residues
 41 *
 42 * Revision 6.92  2000/02/28 14:47:58  thiessen
 43 * fixed "show selected only" in show/hide
 44 *
 45 * Revision 6.91  2000/01/11 01:16:46  lewisg
 46 * fix color selection in Cn3D, other misc. bugs
 47 *
 48 * Revision 6.90  1999/11/23 16:16:17  vakatov
 49 * Fixed a (dangerous!) cast of the callback function Cn3D_FindMMCB()
 50 *
 51 * Revision 6.89  1999/11/18 00:21:42  lewisg
 52 * draw speedups and selection on mouseup
 53 *
 54 * Revision 6.88  1999/11/15 18:30:08  lewisg
 55 * get rid of extra redraws when selecting
 56 *
 57 * Revision 6.87  1999/11/10 23:19:40  lewisg
 58 * rewrite of selection code for ddv
 59 *
 60 * Revision 6.86  1999/10/29 14:15:28  thiessen
 61 * ran all Cn3D source through GNU Indent to prettify
 62 *
 63 * Revision 6.85  1999/10/05 23:18:20  lewisg
 64 * add ddv and udv to cn3d with memory management
 65 *
 66 * Revision 6.84  1999/09/21 18:09:16  lewisg
 67 * binary search added to color manager, various bug fixes, etc.
 68 *
 69 * Revision 6.83  1999/07/07 15:44:00  ywang
 70 * set Cn3D_ObjMgrOpen FALSE as GatherProcLaunch returns OM_MSG_RET_ERROR or OM_MSG_RET_NOPROC
 71 *
 72 * Revision 6.82  1999/05/27 16:11:21  ywang
 73 * initilize all local variables at defined
 74 *
 75 * Revision 6.81  1999/05/25 22:04:58  ywang
 76 * always check mediadata->length before assigning residue information for mediadata to protect memory from corruption upon weird data
 77 *
 78 * Revision 6.80  1999/05/24 16:55:15  ywang
 79 * work around last letter selection problem
 80 *
 81 * Revision 6.79  1999/05/24 15:16:58  ywang
 82 * work around messaging problem on C-terminal dashes selection
 83 *
 84 * Revision 6.78  1999/05/10 20:24:26  ywang
 85 * initialize iRes Cn3DColorSalsaForStrucSeqs
 86 *
 87 * Revision 6.77  1999/05/04 23:12:47  ywang
 88 * fix selection retaining problem on show/hide
 89 *
 90 * Revision 6.76  1999/04/23 14:25:11  ywang
 91 * fix bug for Cn3DObjMgrGetSelected
 92 *
 93 * Revision 6.75  1999/04/21 21:08:42  ywang
 94 * fix small memory leak
 95 *
 96 * Revision 6.74  1999/04/16 22:21:24  ywang
 97 * update residue aligned status on mediadata upon sequence SHOW/HIDE
 98 *
 99 * Revision 6.73  1999/04/01 17:48:23  ywang
100 * fix bug for coloring salsa for strucseqs data
101 *
102 * Revision 6.72  1999/03/30 22:36:18  ywang
103 * add functions to color salsa for NcbiMimeAsn1_strucseqs & code reorganization
104 *
105 * Revision 6.71  1999/03/22 22:41:14  ywang
106 * remove argument in MediaObjSelect
107 *
108 * Revision 6.70  1999/02/12 15:11:52  ywang
109 * send color message to salsa when user changes highlight color from cn3d
110 *
111 * Revision 6.69  1999/02/11 22:42:39  ywang
112 * explicitly call ObjMgrDeSelect to DeHighlight
113 *
114 * Revision 6.68  1999/02/11 22:40:15  ywang
115 * rename functions
116 *
117 * Revision 6.67  1999/02/11 18:48:15  lewisg
118 * delete color index functions
119 *
120 * Revision 6.66  1999/02/10 23:49:43  lewisg
121 * use RGB values instead of indexed palette
122 *
123 * Revision 6.65  1999/02/10 17:04:21  ywang
124 * work around (Uint1) max number 255 problem for valnode choice number
125 *
126 * Revision 6.64  1999/01/20 22:57:25  ywang
127 * customize color for secondary structure & rearrange Option menu
128 *
129 * Revision 6.63  1999/01/20 18:21:19  ywang
130 * include salmedia.h due to the move around of MediaInfo from cn3dmsg.h to the new created salmedia.h
131 *
132 * Revision 6.62  1999/01/19 23:42:49  ywang
133 * fix bugs over improving color msg
134 *
135 * Revision 6.61  1999/01/19 18:25:26  kans
136 * send default rgb to ObjMgrSetColor
137 *
138 * Revision 6.60  1999/01/19 17:51:06  ywang
139 * fix bug in Cn3DSendColorMsg on NULL sip
140 *
141 * Revision 6.59  1999/01/19 17:31:51  ywang
142 * switch color message from many to once
143 *
144 * Revision 6.58  1998/12/16  22:49:39  ywang
145 * fix compiling warnings on Win32
146 *
147 * Revision 6.57  1998/12/16  19:32:20  ywang
148 * improve highlight residues function when rerendering
149 *
150 * Revision 6.56  1998/10/27  15:55:51  ywang
151 * add functions for testing color by sequence conservation
152 *
153 * Revision 6.55  1998/10/21  15:51:26  ywang
154 * reset residue color for salsa before cn3d redraws so that residues shown in salsa will become black if they are not shown in cn3d window
155 *
156 * Revision 6.54  1998/10/19  20:16:06  ywang
157 * add function FillSeqinfoForSeqEditViewProcs so that salsa can get color array
158 *
159 * Revision 6.53  1998/10/19  17:43:02  kans
160 * prototype needed for Cn3DSendColorMsg
161 *
162 * Revision 6.52  1998/10/16 22:06:09  ywang
163 * make global color array for sequence display
164 *
165 * Revision 6.51  1998/10/07  21:19:50  kans
166 * ObjMgrAlsoSelect changes (CC)
167 *
168 * Revision 6.50  1998/09/23 22:07:32  ywang
169 * fix file name error
170 * 
171 * ===========================================================================  */
172 
173 #include <vibrant.h>
174 #include <document.h>
175 #include <vsm.h>
176 #include <sequtil.h>            /* for sequence load funcs */
177 #include <objsub.h>
178 #include <string.h>
179 #include <saledit.h>
180 #include <objmgr.h>
181 #include <mmdbapi.h>            /* the MMDB-API header */
182 #include <mmdbdata.h>
183 #include <cn3dmsg.h>
184 #include <salmedia.h>
185 #include <sqnutils.h>
186 #include <cn3dmain.h>
187 #include <algorend.h>
188 #include <cn3dshim.h>
189 #include <objmime.h>
190 #include <udviewer.h>           /* udv */
191 #include <ddvopen.h>            /* ddv */
192 
193 extern Int1 bColorAlignments[];
194 
195 
196 static void LIBCALLBACK Cn3D_FindMMCB(PFB pfbThis, Nlm_Int4 iModel,
197                                       Nlm_Int4 iIndex,
198                                       Pointer ptr)
199 {
200     PDNMM* ModelList = (PDNMM*) ptr;
201     PMMD pmmdThis = NULL;
202 
203     if (pfbThis == NULL) return;
204     if (pfbThis->bMe == (Byte) AM_MMD) { /* is this molecular model data? */
205         pmmdThis = (PMMD) pfbThis;
206         if (pmmdThis->pSeqId)
207             DValNodeAddPointer (ModelList, 0, pmmdThis);
208     }
209 }
210 
211 
212 
213 PDNMM FindMM(void)
214 /* find coordinates of the bounding box of a structure */
215 {
216     PDNMM ModelList = NULL;
217     PDNMS pdnmsThis = NULL, pdnmsThisSlave = NULL;
218     PMSD pmsdThis = NULL;
219 
220     pdnmsThis = GetSelectedModelstruc();
221     if(pdnmsThis == NULL) return NULL;
222 
223     TraverseModels(pdnmsThis, TRAVERSE_MOLECULE, 0, &ModelList, Cn3D_FindMMCB);
224 
225     pmsdThis = pdnmsThis->data.ptrvalue;
226     if(pmsdThis == NULL) return ModelList;
227 
228     for(pdnmsThis = pmsdThis->pdnmsSlaves; pdnmsThis != NULL;
229             pdnmsThis = pdnmsThis->next) {
230         TraverseModels(pdnmsThis, TRAVERSE_MOLECULE, 0, &ModelList,
231                        Cn3D_FindMMCB);
232     }
233     
234     return ModelList;
235 }
236 
237 
238 /*----------------------------------------------*/
239 void DoMediaHL(PMMD pmmdThis, Int4 from, Int4 to, Boolean highlight)
240 {
241     PDNMG pdnmgThis = NULL;
242 
243     PMGD pmgdThis = NULL;
244     PVNMA pvnmaThis = NULL;
245     PMAD pmadThis = NULL;
246     PVNAL pvnalThis = NULL;
247     PALD paldThis = NULL;
248 
249     Byte MainAtom = 0;
250 
251 
252     pdnmgThis = pmmdThis->pdnmgHead;
253     if (pdnmgThis == NULL)
254         return;
255 
256     pmgdThis = pdnmgThis->data.ptrvalue;
257     if ((pmgdThis->bWhat & (Byte) RES_RNA)
258         || (pmgdThis->bWhat & (Byte) RES_DNA)) MainAtom = AM_PALPHA;
259     if (pmgdThis->bWhat & (Byte) RES_AA)
260         MainAtom = AM_CALPHA;
261 
262     while (pdnmgThis) {
263         if (pdnmgThis->choice <= to && pdnmgThis->choice >= from) {
264             pmgdThis = pdnmgThis->data.ptrvalue;
265             if (pmgdThis == NULL)
266                 goto setout;
267 
268 
269             fnPreCHLresidue(pdnmgThis, highlight);
270         }
271       setout:
272         pdnmgThis = pdnmgThis->next;
273     }
274 
275 
276 }
277 
278 /*----------------------------------------------*/
279 void MediaHL(SelStructPtr sel, Boolean highlight)
280 {
281     /* media action -- highlight... */
282     SeqLocPtr slp = NULL;
283     SeqIntPtr sintp = NULL;
284     SeqIdPtr sip = NULL;
285     Int4 from = 0, to = 0;
286     PDNMM ModelList,iList;
287     PMMD pmmdThis;
288     Bioseq *bsp;
289 
290     slp = sel->region;
291     if (slp == NULL) return;
292     sintp = slp->data.ptrvalue;
293     if(sintp == NULL) return;
294     sip = sintp->id;
295 
296     from = SeqLocStart(slp);
297     to = SeqLocStop(slp);
298 
299     if(to == LAST_RESIDUE || to == APPEND_RESIDUE ) {
300         bsp = BioseqLockById(sip);
301         if (bsp) {
302             to = bsp->length-1;
303             BioseqUnlock(bsp);
304         }
305     }
306 
307     /* residue starts with number 1 in structure, but with number 0 in sequence */
308     from++;
309     to++;
310         
311     ModelList = FindMM();
312     
313     for(iList = ModelList; iList != NULL; iList = iList->next) {
314         pmmdThis = iList->data.ptrvalue;
315         if(pmmdThis == NULL) continue;
316         if (SeqIdForSameBioseq(sip, pmmdThis->pSeqId))
317             DoMediaHL(pmmdThis, from, to, highlight);
318     }
319     DValNodeFree(ModelList);
320 
321 }
322 
323 /* selection originating from Cn3D */
324 void MediaObjSelect(PDNMG pdnmgThis, Boolean highlight)
325 {
326     PMGD pmgdThis = NULL;
327     PMMD pmmdThis = NULL;
328     SeqLocPtr slp = NULL;
329 
330     Uint4 entityID, itemID;
331     Int4 from, to;
332 
333     pmgdThis = pdnmgThis->data.ptrvalue;
334     pmmdThis = GetParentMol((PFB) pmgdThis);  
335 
336     if (pmmdThis == NULL)return;
337 
338     entityID = BioseqFindEntity(pmmdThis->pSeqId, &itemID);
339     if(pmmdThis->pSeqId && entityID != 0) {
340         from = pdnmgThis->choice - 1;
341         to = pdnmgThis->choice - 1;
342         slp = SeqLocIntNew(from, to, 0, pmmdThis->pSeqId);
343         if (highlight)
344             ObjMgrAlsoSelect(entityID, itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
345             slp);
346         /* now explicitly use ObjMgrDeSelect */
347         else
348             ObjMgrDeSelect(entityID, itemID, OBJ_BIOSEQ, OM_REGION_SEQLOC,
349             slp);
350         ObjMgrSendMsg(OM_MSG_MOUSEUP, entityID, itemID, OBJ_BIOSEQ);
351     }
352     else {
353         fnPreCHLresidue(pdnmgThis, highlight);
354 #ifdef _OPENGL
355         Cn3D_Redraw(FALSE);
356 #else
357         RedrawViewer3D(Cn3D_v3d);
358 #endif
359 
360     }
361 
362 }
363 
364 
365 /*-----------------------------------------------*/
366 void LIBCALLBACK Cn3DCheckAndDoHighlight(PFB pfbThis, Int4 iModel,
367                                          Int4 iIndex, Pointer ptr)
368 {
369     PMGD pmgdThis = NULL;
370     PDNMG pdnmgThis = NULL;
371     PMMD pmmdThis = NULL;
372     PMSD pmsdThis = NULL;
373 
374     pmgdThis = (PMGD) pfbThis;
375     if (pmgdThis && pmgdThis->bHighlighted == 1) {
376         pdnmgThis = pmgdThis->pdnmgLink;
377 
378         fnPreCHLresidue(pdnmgThis, TRUE);
379     }
380 
381 }
382 
383 /*-----------------------------------------------*/
384 void Cn3dObjMgrGetSelected(void)
385 {
386 #ifndef _OPENGL
387     PDNMS pdnmsMaster = NULL, pdnmsSlave = NULL;
388     PMSD pmsdMaster = NULL, pmsdSlave = NULL;
389 
390     /* replace old function which depends on ObjMgr */
391     /* by doing so, highlight for non ObjMgr registered residues will */
392     /* also be picked up when do Cn3D_Redraw */
393 
394     pdnmsMaster = GetSelectedModelstruc();
395     if (pdnmsMaster != NULL) {
396         pmsdMaster = pdnmsMaster->data.ptrvalue;
397 
398         if (pmsdMaster->bVisible == 1) {
399             TraverseGraphs(pdnmsMaster, 0, 0, NULL,
400                            Cn3DCheckAndDoHighlight);
401         }
402         pdnmsSlave = pmsdMaster->pdnmsSlaves;
403         while (pdnmsSlave) {
404             pmsdSlave = pdnmsSlave->data.ptrvalue;
405             if (pmsdSlave->bVisible == 1) {
406                 TraverseGraphs(pdnmsSlave, 0, 0, NULL,
407                                Cn3DCheckAndDoHighlight);
408             }
409             pdnmsSlave = pdnmsSlave->next;
410         }
411     }
412 #endif
413 }
414 

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.