1 /* gphview.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: gphview.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 2/5/97
31 *
32 * $Revision: 6.69 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44
45 #include <bspview.h>
46 #include <fstyle.h>
47 #include <txalign.h>
48 #include <drawseq.h>
49 #include <drawingp.h>
50 #include <viewerp.h>
51 #include <mapgene.h>
52 #include <saledit.h>
53 #include <vsmpriv.h>
54 #include <edutil.h>
55 #include <gphdraw.h>
56
57 extern SegmenT VSMEntityDraw PROTO((ObjMgrDataPtr omdp, VSMPictPtr vsmpp, VSeqMgrPtr vsmp));
58
59 static void InitSelectGraphical (BioseqViewPtr bvp);
60 static void InitSelectDesktop (BioseqViewPtr bvp);
61 static void DrawSelectionRange (VieweR viewer, SegmenT segment);
62 static void PopulateDesktop (BioseqViewPtr bvp);
63
64 #define MAXZOOMSCALEVAL 22
65
66 static Int4 zoomScaleVal [MAXZOOMSCALEVAL] = {
67 1L, 1L, 2L, 5L, 10L, 20L, 50L, 100L, 200L, 500L,
68 1000L, 2000L, 5000L, 10000L, 20000L, 50000L,
69 100000L, 200000L, 500000L, 1000000L, 2000000L, 5000000L
70 };
71
Find_segment_IDs(VieweR viewer,PoinT pt,Uint2Ptr entityID,Uint4Ptr itemID,Uint2Ptr itemType)72 static Boolean Find_segment_IDs (VieweR viewer, PoinT pt, Uint2Ptr entityID,
73 Uint4Ptr itemID, Uint2Ptr itemType)
74 {
75 SegmenT seg, pseg;
76 Uint2 pID, sID, primID, primCt;
77
78 if (entityID == NULL || itemID == NULL ||itemType == NULL) return FALSE;
79
80 seg = FindSegment (viewer, pt, &sID, &primID, &primCt);
81 if (seg == NULL || sID == 0 || primID == 0) return FALSE;
82 pseg = ParentSegment (seg);
83 if (pseg == NULL) return FALSE;
84 pID = SegmentID (pseg);
85 if (pID == 0) return FALSE;
86
87 *itemType = pID;
88 *entityID = sID;
89 *itemID = primID;
90 return TRUE;
91 }
92
get_viewer_position(VieweR viewer,Int4Ptr x,Int4Ptr y)93 static void get_viewer_position (VieweR viewer, Int4Ptr x, Int4Ptr y)
94
95 {
96 Int4 scale_x, scale_y;
97 BoxInfo port, world;
98 RecT v_iew;
99
100 ViewerBox (viewer, &world, &port, &v_iew, &scale_x, &scale_y);
101 *x = (port.left + port.right) / 2;
102 *y = (port.top + port.bottom) / 2;
103 }
104
105 typedef struct makemultidata {
106 ValNodePtr slp_list;
107 Int4 len;
108 } MakeMultiData, PNTR MakeMultiPtr;
109
MakeMultiSlpList(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)110 static void MakeMultiSlpList (SeqEntryPtr sep, Pointer mydata,
111 Int4 index, Int2 indent)
112
113 {
114 BioseqPtr bsp;
115 Int4 len;
116 MakeMultiPtr mmp;
117 SeqLocPtr slp;
118
119 if (sep != NULL && sep->choice == 1 && mydata != NULL) {
120 mmp = (MakeMultiPtr) mydata;
121 bsp = (BioseqPtr) sep->data.ptrvalue;
122 if (bsp != NULL && ISA_na (bsp->mol)) {
123 len = bsp->length;
124 slp = SeqLocIntNew (0, len-1, Seq_strand_plus, SeqIdFindBest (bsp->id, 0));
125 ValNodeAddPointer (&(mmp->slp_list), 0, (Pointer) slp);
126 mmp->len = MAX (mmp->len, len);
127 }
128 }
129 }
130
FindAlignment(SeqEntryPtr sep,Pointer mydata,Int4 index,Int2 indent)131 static void FindAlignment (SeqEntryPtr sep, Pointer mydata,
132 Int4 index, Int2 indent)
133
134 {
135 SeqAlignPtr align;
136 BioseqPtr bsp;
137 BioseqSetPtr bssp;
138 SeqAnnotPtr sap;
139 SeqAlignPtr PNTR sapp;
140
141 if (sep != NULL && sep->data.ptrvalue != NULL && mydata != NULL) {
142 sapp = (SeqAlignPtr PNTR) mydata;
143 sap = NULL;
144 if (IS_Bioseq (sep)) {
145 bsp = (BioseqPtr) sep->data.ptrvalue;
146 sap = bsp->annot;
147 } else if (IS_Bioseq_set (sep)) {
148 bssp = (BioseqSetPtr) sep->data.ptrvalue;
149 sap = bssp->annot;
150 } else {
151 return;
152 }
153 while (sap != NULL) {
154 if (sap->type == 2) {
155 align = sap->data;
156 if (align != NULL && *sapp == NULL) {
157 *sapp = align;
158 }
159 }
160 sap = sap->next;
161 }
162 }
163 }
164
CommonFrameProc(VieweR vwr,BioseqViewPtr bvp)165 static void CommonFrameProc (VieweR vwr, BioseqViewPtr bvp)
166
167 {
168 RecT dr;
169 RecT or;
170 RecT r;
171
172 if (vwr == NULL || bvp == NULL) return;
173 Dotted ();
174 ObjectRect (vwr, &or);
175 InsetRect (&or, 2, 2);
176 LoadRect (&r, bvp->pnt_start.x, bvp->pnt_start.y,
177 bvp->pnt_stop.x, bvp->pnt_stop.y);
178 SectRect (&r, &or, &dr);
179 FrameRect (&dr);
180 }
181
ClickMap(VieweR vwr,SegmenT seg,PoinT pt)182 static void ClickMap (VieweR vwr, SegmenT seg, PoinT pt)
183
184 {
185 BioseqViewPtr bvp;
186
187 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
188 if (bvp == NULL) return;
189 bvp->wasDoubleClick = dblClick;
190 bvp->wasShiftKey = shftKey;
191 if (bvp->old_rect_shown) {
192 InvertMode ();
193 CommonFrameProc (vwr, bvp);
194 }
195 bvp->old_rect_shown = FALSE;
196 bvp->pnt_start = pt;
197 bvp->pnt_stop = pt;
198 InvertMode ();
199 CommonFrameProc (vwr, bvp);
200 }
201
DragMap(VieweR vwr,SegmenT seg,PoinT pt)202 static void DragMap (VieweR vwr, SegmenT seg, PoinT pt)
203
204 {
205 BioseqViewPtr bvp;
206
207 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
208 if (bvp == NULL) return;
209 if(bvp->wasDoubleClick || bvp->wasShiftKey) return;
210 InvertMode ();
211 CommonFrameProc (vwr, bvp);
212 bvp->pnt_stop = pt;
213 CommonFrameProc (vwr, bvp);
214 }
215
ReleaseMap(VieweR vwr,SegmenT seg,PoinT pt)216 static void ReleaseMap (VieweR vwr, SegmenT seg, PoinT pt)
217
218 {
219 BioseqViewPtr bvp;
220 Uint2 entityID;
221 Uint4 itemID;
222 Uint2 itemtype;
223 SeqEntryPtr sep;
224 PntInfo start_info, stop_info;
225
226 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
227 if (bvp == NULL) return;
228
229 if (bvp->wasDoubleClick) {
230 if (Find_segment_IDs (vwr, pt, &entityID, &itemID, &itemtype)) {
231 sep = GetTopSeqEntryForEntityID (entityID);
232 if (bvp->launchSubviewers) {
233 WatchCursor ();
234 Update ();
235 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
236 ArrowCursor ();
237 Update ();
238 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
239 WatchCursor ();
240 Update ();
241 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
242 ArrowCursor ();
243 Update ();
244 }
245 return;
246 }
247 if (! bvp->sendSelectMessages) return;
248 if (bvp->wasShiftKey) {
249 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
250 } else {
251 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
252 }
253 } else if (bvp->sendSelectMessages) {
254 if (Find_segment_IDs (vwr, pt, &entityID, &itemID, &itemtype)) {
255 if (bvp->wasShiftKey) {
256 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
257 } else {
258 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
259 }
260 } else if (! bvp->wasShiftKey) {
261 ObjMgrDeSelect (0, 0, 0, 0, NULL);
262 }
263 }
264 if (bvp->gdraw_p != NULL) {
265 bvp->old_rect_shown = TRUE;
266 if (bvp->slp_list != NULL) {
267 free_slp_list (bvp->slp_list);
268 }
269 bvp->slp_list = NULL;
270 if (bvp->anp_node != NULL) {
271 FreeAlignNode (bvp->anp_node);
272 }
273 bvp->anp_node = NULL;
274 bvp->scaleNotCalculated = TRUE;
275 MapViewerToWorld(bvp->vwr, bvp->pnt_start, &start_info);
276 MapViewerToWorld(bvp->vwr, bvp->pnt_stop, &stop_info);
277 bvp->slp_list = find_map_pos (bvp->gdraw_p, start_info, stop_info);
278 }
279 }
280
PopulateMap(BioseqViewPtr bvp)281 static void PopulateMap (BioseqViewPtr bvp)
282
283 {
284 Uint2 entityID;
285 Int2 oldstyle;
286 RecT r;
287 SeqEntryPtr sep;
288 Int2 style;
289
290 if (bvp == NULL) return;
291 WatchCursor ();
292 oldstyle = GetMuskCurrentSt ();
293 style = GetValue (bvp->style) - 1;
294 SetMuskCurrentSt (GetMuskStyleName (style));
295 ObjectRect (bvp->vwr, &r);
296 InsetRect (&r, 4, 4);
297 bvp->pict = DeletePicture (bvp->pict);
298 entityID = ObjMgrGetEntityIDForPointer (bvp->bsp);
299 sep = GetTopSeqEntryForEntityID (entityID);
300 if (bvp->gdraw_p == NULL) {
301 bvp->pict = SequinGlobalPicture (sep, r.right - r.left, r.bottom - r.top,
302 bvp->g_list, &(bvp->gdraw_p), FALSE);
303 } else {
304 bvp->pict = GlobalPictureUpdate (bvp->gdraw_p, bvp->g_list,
305 r.right - r.left, r.bottom - r.top);
306 }
307 if (bvp->gdraw_p != NULL && bvp->pict != NULL) {
308 if (bvp->gdraw_p->is_circle) {
309 AttachPicture (bvp->vwr, bvp->pict, 0, 0, UPPER_LEFT, 1, 1, NULL);
310 } else {
311 AttachPicture (bvp->vwr, bvp->pict, INT4_MIN, 0, UPPER_LEFT, 1, 1, NULL);
312 }
313 SetViewerProcs (bvp->vwr, ClickMap, DragMap, ReleaseMap, NULL);
314 }
315 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
316 ArrowCursor ();
317 }
318
ClickGraphic(VieweR vwr,SegmenT seg,PoinT pt)319 static void ClickGraphic (VieweR vwr, SegmenT seg, PoinT pt)
320
321 {
322 BioseqViewPtr bvp;
323
324 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
325 if (bvp == NULL) return;
326 bvp->wasDoubleClick = dblClick;
327 bvp->wasShiftKey = shftKey;
328 bvp->old_rect_shown = FALSE;
329 bvp->pnt_start = pt;
330 bvp->pnt_stop = pt;
331 }
332
ReleaseGraphic(VieweR vwr,SegmenT seg,PoinT pt)333 static void ReleaseGraphic (VieweR vwr, SegmenT seg, PoinT pt)
334
335 {
336 BioseqViewPtr bvp;
337 Uint2 entityID;
338 Uint4 itemID;
339 Uint2 itemtype;
340 SeqEntryPtr sep;
341
342 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
343 if (bvp == NULL) return;
344
345 if (bvp->wasDoubleClick) {
346 if (Find_segment_IDs (vwr, pt, &entityID, &itemID, &itemtype)) {
347 sep = GetTopSeqEntryForEntityID (entityID);
348 if (bvp->launchSubviewers) {
349 WatchCursor ();
350 Update ();
351 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
352 ArrowCursor ();
353 Update ();
354 return;
355 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
356 WatchCursor ();
357 Update ();
358 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
359 ArrowCursor ();
360 Update ();
361 return;
362 } else if (bvp->launchEditors) {
363 WatchCursor ();
364 Update ();
365 GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, itemID,
366 itemtype, 0, 0, itemtype, 0);
367 ArrowCursor ();
368 Update ();
369 return;
370 } else {
371 return;
372 }
373 }
374 if (! bvp->sendSelectMessages) return;
375 if (bvp->wasShiftKey) {
376 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
377 } else {
378 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
379 }
380 } else if (bvp->sendSelectMessages) {
381 if (Find_segment_IDs (vwr, pt, &entityID, &itemID, &itemtype)) {
382 if (bvp->wasShiftKey) {
383 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
384 } else {
385 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
386 }
387 } else if (! bvp->wasShiftKey) {
388 ObjMgrDeSelect (0, 0, 0, 0, NULL);
389 }
390 }
391 }
392
DrawCompressNoAlignment(SeqLocPtr m_loc,ValNodePtr PNTR anp_list,Uint2Ptr seq_entityID,Boolean flat_insert,Int4 width,Int4Ptr p_scale,Int4Ptr p_maxwidth)393 static SegmenT DrawCompressNoAlignment (SeqLocPtr m_loc, ValNodePtr PNTR anp_list,
394 Uint2Ptr seq_entityID, Boolean flat_insert,
395 Int4 width, Int4Ptr p_scale, Int4Ptr p_maxwidth)
396
397 {
398 Int2 styleNum;
399 CharPtr old_style;
400 Int4 scale;
401 SegmenT pic;
402 ValNode vn;
403 Int4 max_width;
404 Int4 y_pos;
405 ValNodePtr anp_node;
406 Int4 len;
407 Uint2 entityID;
408
409
410 anp_node = collect_alignnode_from_slp(m_loc, &entityID, flat_insert);
411 if(anp_node == NULL)
412 return NULL;
413
414 vn.data.ptrvalue = m_loc;
415 vn.next = NULL;
416 max_width = CountMaxSeqLabel(&vn);
417 scale = FigureMaxScale(&vn, (Int2)width, max_width);
418 if(scale <=0)
419 return NULL;
420
421 pic = CreatePicture();
422 len = slp_list_len(m_loc);
423
424 /*set up the sepcial style */
425 styleNum = GetMuskCurrentSt();
426 old_style = GetMuskStyleName(styleNum);
427 SetMuskCurrentSt("StyleX");
428
429 y_pos = 0;
430 DrawMPAlignment(anp_node, 0, len-1, m_loc, entityID, scale, &y_pos, MSM_MPAIR, FALSE, pic);
431
432 *p_scale = scale;
433 *p_maxwidth = max_width;
434 SetMuskCurrentSt(old_style);
435
436 if(seq_entityID != NULL)
437 *seq_entityID = entityID;
438 if(anp_list != NULL)
439 *anp_list = anp_node;
440 else
441 FreeAlignNode(anp_node);
442 return pic;
443 }
444
PopulateCompressedNoAlignment(BioseqViewPtr bvp)445 static void PopulateCompressedNoAlignment (BioseqViewPtr bvp)
446
447 {
448 ValNodePtr anp_list = NULL;
449 BioseqPtr bsp;
450 Uint2 entityID;
451 SeqLocPtr m_loc;
452 Int4 max_width;
453 RecT r;
454 Int4 scale = 0;
455 Int4 X_VIEW;
456
457 if (bvp == NULL) return;
458 bsp = bvp->bsp;
459 if (bsp == NULL) return;
460 m_loc = SeqLocIntNew (0, bsp->length - 1, 0, bsp->id);
461 ObjectRect (bvp->vwr, &r);
462 InsetRect (&r, 4, 4);
463 X_VIEW = r.right - r.left;
464 bvp->pict = DrawCompressNoAlignment (m_loc, &(anp_list), &(entityID), FALSE,
465 X_VIEW, &scale, &max_width);
466 if (bvp->pict != NULL) {
467 max_width += 2;
468 max_width *= scale;
469 AttachPicture (bvp->vwr, bvp->pict, INT4_MIN, 0, UPPER_LEFT, scale, 1, NULL);
470 SetViewerProcs (bvp->vwr, ClickGraphic, NULL, ReleaseGraphic, NULL);
471 }
472 FreeAlignNode (anp_list);
473 SeqLocFree (m_loc);
474 ArrowCursor ();
475 }
476
PopulateCompressed(BioseqViewPtr bvp)477 static void PopulateCompressed (BioseqViewPtr bvp)
478
479 {
480 ValNodePtr anp_list;
481 BioseqPtr bsp;
482 Uint2 entityID;
483 SeqLocPtr m_loc;
484 Int4 max_width;
485 RecT r;
486 Int4 scale;
487 SeqEntryPtr sep;
488 Int4 X_VIEW;
489
490 if (bvp == NULL) return;
491 WatchCursor ();
492 Reset (bvp->vwr);
493 bvp->pict = DeletePicture (bvp->pict);
494 bsp = bvp->bsp;
495 if (bsp == NULL) return;
496 sep = SeqMgrGetSeqEntryForData (bsp);
497 entityID = ObjMgrGetEntityIDForChoice (sep);
498 if (! SeqEntryHasAligns (entityID, sep)) {
499 PopulateCompressedNoAlignment (bvp);
500 return;
501 }
502 anp_list = MakeCompressAlignList (bvp->bsp, NULL, &entityID);
503 if (anp_list == NULL) {
504 PopulateCompressedNoAlignment (bvp);
505 return;
506 }
507 m_loc = SeqLocIntNew (0, bsp->length - 1, 0, bsp->id);
508 ObjectRect (bvp->vwr, &r);
509 InsetRect (&r, 4, 4);
510 X_VIEW = r.right - r.left;
511 bvp->pict = DrawCompressAlignment (anp_list, m_loc, X_VIEW, &scale,
512 &max_width, entityID, NULL);
513 if (bvp->pict != NULL) {
514 max_width += 2;
515 max_width *= scale;
516 AttachPicture (bvp->vwr, bvp->pict, INT4_MIN, 0, UPPER_LEFT, scale, 1, NULL);
517 SetViewerProcs (bvp->vwr, ClickGraphic, NULL, ReleaseGraphic, NULL);
518 }
519 FreeAlignNode (anp_list);
520 SeqLocFree (m_loc);
521 ArrowCursor ();
522 }
523
524 typedef struct gphfinddata {
525 ValNodePtr vnp;
526 SeqLocPtr slp;
527 Int4 start;
528 Int4 stop;
529 BioseqPtr bsp;
530 } GphFindData, PNTR GphFindPtr;
531
GraphFindFunc(GatherContextPtr gcp)532 static Boolean GraphFindFunc (GatherContextPtr gcp)
533
534 {
535 GphFindPtr gfp;
536 SeqGraphPtr sgp;
537 Int4 left;
538 Int4 right;
539
540 if (gcp == NULL) return TRUE;
541
542 gfp = (GphFindPtr) gcp->userdata;
543 if (gfp == NULL ) return TRUE;
544
545 if (gcp->thistype == OBJ_SEQGRAPH) {
546 sgp = (SeqGraphPtr) gcp->thisitem;
547 if (sgp != NULL) {
548 if (SeqIdForSameBioseq (SeqLocId (sgp->loc), SeqLocId (gfp->slp))) {
549 left = GetOffsetInBioseq (sgp->loc, gfp->bsp, SEQLOC_LEFT_END);
550 right = GetOffsetInBioseq (sgp->loc, gfp->bsp, SEQLOC_RIGHT_END);
551 if (left == -1 || right == -1) return TRUE;
552 if (left >= gfp->start && right <= gfp->stop) {
553 ValNodeAddPointer (&(gfp->vnp), 0, (Pointer) sgp);
554 }
555 }
556 }
557 }
558 return TRUE;
559 }
560
CollectGraphs(Uint2 entityID,BioseqPtr bsp,Int4 start,Int4 stop)561 static ValNodePtr CollectGraphs (Uint2 entityID, BioseqPtr bsp, Int4 start, Int4 stop)
562
563 {
564 GphFindData gfd;
565 GatherScope gs;
566 ValNode vn;
567
568 gfd.vnp = NULL;
569 vn.choice = SEQLOC_WHOLE;
570 vn.data.ptrvalue = (Pointer) bsp->id;
571 gfd.slp = &vn;
572 gfd.start = start;
573 gfd.stop = stop;
574 gfd.bsp = bsp;
575 MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
576 gs.seglevels = 1;
577 MemSet ((Pointer) (gs.ignore), (int)(TRUE), (size_t) (OBJ_MAX * sizeof (Boolean)));
578 gs.ignore[OBJ_BIOSEQ] = FALSE;
579 gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
580 gs.ignore[OBJ_SEQGRAPH] = FALSE;
581 gs.ignore[OBJ_SEQANNOT] = FALSE;
582 GatherEntity (entityID, (Pointer) &gfd, GraphFindFunc, &gs);
583 return gfd.vnp;
584 }
585
PopulateSimpleGraphic(BioseqViewPtr bvp)586 static void PopulateSimpleGraphic (BioseqViewPtr bvp)
587
588 {
589 BoxInfo box;
590 BioseqPtr bsp;
591 Uint2 entityID;
592 GeneDataPtr gdata;
593 ValNodePtr graphs;
594 Int2 i;
595 Int4 labelWid;
596 Int4 len;
597 Int4 max;
598 Int4 min;
599 MakeMultiData mmd;
600 SeqEntryPtr oldscope = NULL;
601 Int2 oldstyle;
602 RecT r;
603 Int4 scaleX;
604 Int4 scaleY;
605 SeqEntryPtr sep;
606 SeqGraphPtr sgp;
607 ValNodePtr slp_list;
608 SeqLocPtr slp;
609 Char str [32];
610 Int2 style;
611 ValNodePtr vnp;
612 Int4 vwr_x;
613 Int4 vwr_y;
614 Int2 vwr_align;
615
616 if (bvp == NULL) return;
617 WatchCursor ();
618 vwr_x = INT4_MIN;
619 vwr_y = INT4_MAX;
620 vwr_align = UPPER_LEFT;
621 if (bvp->moveToOldPos) {
622 if (bvp->pict != NULL) {
623 get_viewer_position (bvp->vwr, &(vwr_x), &(vwr_y));
624 vwr_align = MIDDLE_CENTER;
625 }
626 bvp->moveToOldPos = FALSE;
627 }
628 Reset (bvp->vwr);
629 bvp->pict = DeletePicture (bvp->pict);
630 Update ();
631 if (bvp->isGenome && bvp->slp_list == NULL) return;
632 bsp = bvp->bsp;
633 if (bsp != NULL) {
634 scaleY = 1;
635 len = 0;
636 if (! bvp->isGenome) {
637 slp_list = NULL;
638 sep = NULL;
639 len = 0;
640 if (bvp->viewWholeEntity) {
641 sep = SeqMgrGetSeqEntryForData (bsp);
642 entityID = ObjMgrGetEntityIDForChoice (sep);
643 sep = GetTopSeqEntryForEntityID (entityID);
644 mmd.slp_list = NULL;
645 mmd.len = 0;
646 BioseqExplore (sep, (Pointer) &mmd, MakeMultiSlpList);
647 slp_list = mmd.slp_list;
648 len = mmd.len;
649 } else {
650 sep = SeqMgrGetSeqEntryForData (bsp);
651 len = bsp->length;
652 slp = SeqLocIntNew (0, len-1, Seq_strand_plus, SeqIdFindBest (bsp->id, 0));
653 ValNodeAddPointer (&slp_list, 0, (Pointer) slp);
654 }
655 if (bvp->slp_list != NULL) {
656 free_slp_list (bvp->slp_list);
657 bvp->slp_list = NULL;
658 }
659 bvp->slp_list = slp_list;
660 }
661 oldstyle = GetMuskCurrentSt ();
662 style = GetValue (bvp->style) - 1;
663 SetMuskCurrentSt (GetMuskStyleName (style));
664
665 if (bvp->scaleNotCalculated) {
666 SafeHide (bvp->scale);
667 Reset (bvp->scale);
668 ObjectRect (bvp->vwr, &r);
669 InsetRect (&r, 4, 4);
670 labelWid = CountMaxSeqLabel (bvp->slp_list) + 2;
671 if (r.right - r.left < 2 * labelWid) {
672 labelWid = 0;
673 }
674 if (bvp->isGenome) {
675 slp = (SeqLocPtr) bvp->slp_list->data.ptrvalue;
676 len = slp_list_len (slp);
677 }
678 max = (Int4) MAX (len / (Int4) (r.right - r.left - labelWid), 1) + 2;
679 max = (Int4) MIN (max, 50000L);
680 min = (Int4) MAX (len / 320000L, 1L);
681 bvp->maxScale = max;
682 i = 1;
683 while (i < MAXZOOMSCALEVAL && min > zoomScaleVal [i]) {
684 i++;
685 }
686 bvp->minIndex = i;
687 while (i < MAXZOOMSCALEVAL && max > zoomScaleVal [i - 1]) {
688 sprintf (str, "%ld", (long) (zoomScaleVal [i]));
689 if (max < zoomScaleVal [i]) {
690 sprintf (str, "%ld", (long) zoomScaleVal [i]);
691 }
692 PopupItem (bvp->scale, str);
693 i++;
694 }
695 SetValue (bvp->scale, MAX (i - bvp->minIndex, 1));
696 bvp->scaleNotCalculated = FALSE;
697 }
698 SafeShow (bvp->scale);
699 i = GetValue (bvp->scale) - 1 + bvp->minIndex;
700 if (i < MAXZOOMSCALEVAL && i > 0) {
701 scaleX = MIN (zoomScaleVal [i], bvp->maxScale);
702 } else {
703 scaleX = bvp->minIndex;
704 }
705
706 sep = SeqMgrGetSeqEntryForData (bsp);
707 entityID = ObjMgrGetEntityIDForChoice (sep);
708 if (entityID > 0) {
709 sep = GetBestTopParentForData (entityID, bsp);
710 oldscope = SeqEntrySetScope (sep);
711 }
712
713 gdata = make_gene_data (bvp->g_list);
714 bvp->ftype_list = ValNodeFree (bvp->ftype_list);
715 bvp->pict = DrawSequinMapEx (bvp->slp_list, sep, scaleX, gdata,
716 &(bvp->ftype_list), FALSE, bvp->tempResultList);
717 GeneDataFree (gdata);
718
719 graphs = CollectGraphs (entityID, bsp, 0, bsp->length - 1);
720 if (graphs != NULL) {
721 SegmentBox (bvp->pict, &box);
722 for (vnp = graphs; vnp != NULL; vnp = vnp->next) {
723 sgp = (SeqGraphPtr) vnp->data.ptrvalue;
724 AddGraphSentinelToPicture (sgp, bsp, bvp->pict, scaleX,
725 box.bottom - 10, 0, NULL);
726 }
727 }
728
729 if (entityID > 0) {
730 SeqEntrySetScope (oldscope);
731 }
732
733 AttachPicture (bvp->vwr, bvp->pict, vwr_x, vwr_y, vwr_align, scaleX, scaleY,
734 bvp->highlightSelections ? DrawSelectionRange : NULL);
735 SetViewerProcs (bvp->vwr, ClickGraphic, NULL, ReleaseGraphic, NULL);
736 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
737 InitSelectGraphical (bvp);
738 }
739 ArrowCursor ();
740 }
741
742 /* functions copied from glbpic.c */
743
get_min_size(Int4 seq_len)744 static Int4 get_min_size(Int4 seq_len)
745 {
746 if(seq_len <= 350000)
747 return seq_len;
748
749 return MAX(350000, seq_len/8);
750 }
751
load_seq_loc(Int4 val_1,Int4 val_2,Int4 seq_len,Boolean has_zero,SeqIdPtr sip,BoolPtr show_msg,Boolean add_interval)752 static SeqLocPtr load_seq_loc(Int4 val_1, Int4 val_2, Int4 seq_len, Boolean has_zero, SeqIdPtr sip, BoolPtr show_msg, Boolean add_interval)
753 {
754 Int4 m_start, m_stop;
755 Uint1 m_strand = Seq_strand_plus;
756 SeqLocPtr slp = NULL, loc;
757 Int4 min_len;
758 Int4 temp;
759 Int4 len;
760
761 min_len = get_min_size(seq_len);
762
763
764 if(has_zero)
765 {
766 if(val_1 < val_2)
767 {
768 temp = val_2;
769 val_2 = val_1;
770 val_1 = temp;
771 }
772 if(add_interval)
773 {
774 val_1 -= seq_len/20;
775 val_2 += seq_len/20;
776 }
777 len = (seq_len - 1 - val_1 +1 + val_2 +1);
778 if(len > min_len)
779 {
780 if(*show_msg)
781 Message(MSG_OK, "The selected region is too large. Reduced to %ld base pairs", min_len);
782 val_1 = seq_len - 1 - min_len/2;
783 val_2= min_len/2 -1;
784 }
785 m_start = val_1;
786 m_stop = seq_len -1;
787 loc = SeqLocIntNew(m_start, m_stop, m_strand, sip);
788 m_start = 0;
789 m_stop = val_2;
790 loc->next = SeqLocIntNew(m_start, m_stop, m_strand, sip);
791 slp = loc;
792 }
793 else
794 {
795 m_start = MIN(val_1, val_2);
796 m_start = MAX(0, m_start);
797
798 m_stop = MAX(val_1, val_2);
799 m_stop = MIN(seq_len-1, m_stop);
800 len = m_stop - m_start + 1;
801 if(add_interval)
802 {
803 len += seq_len/10;
804 m_start = MAX(0, (m_start - seq_len/20));
805 m_stop = m_start + len -1;
806 }
807
808 /* if(len > min_len)
809 {
810 if(*show_msg)
811 Message(MSG_OK, "The selected region is too large. Reduced to %ld base pairs", min_len);
812 center = (m_start + m_stop)/2;
813 m_start = center - min_len/2;
814 m_stop = m_start + min_len -1;
815 } */
816 slp = SeqLocIntNew(m_start, m_stop, m_strand, sip);
817 }
818 *show_msg = FALSE;
819 return slp;
820 }
821
822 typedef struct sentineldata {
823 BioseqViewPtr bvp;
824 SegmenT seg;
825 PrimitivE snt;
826 Int4 start;
827 Int4 stop;
828 Boolean fetched;
829 } SentinelData, PNTR SentinelPtr;
830
AddToEntityList(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)831 static Boolean AddToEntityList (SegmenT seg, PrimitivE prim, Uint2 segID,
832 Uint2 primID, Uint2 primCt, VoidPtr userdata)
833
834 {
835 BioseqViewPtr bvp;
836 BaseFormPtr bfp;
837 Uint2 entityID;
838 OMUserDataPtr omudp;
839
840 bvp = (BioseqViewPtr) userdata;
841 entityID = segID;
842 if (bvp == NULL || entityID == 0) return TRUE;
843 bfp = (BaseFormPtr) GetObjectExtra (bvp->form);
844 if (bfp == NULL || entityID == bfp->input_entityID) return TRUE;
845 if (! InBioseqViewEntityList (entityID, bvp)) {
846 ValNodeAddInt (&(bvp->entityList), 0, (Int4) entityID);
847 omudp = ObjMgrAddUserData (entityID, bfp->procid, OMPROC_VIEW, bfp->userkey);
848 if (omudp != NULL) {
849 omudp->userdata.ptrvalue = (Pointer) bfp;
850 omudp->messagefunc = BioseqViewMsgFunc;
851 }
852 }
853 return TRUE;
854 }
855
GenomicSentinelProc(BigScalar calldata,PrimDrawContext pdc)856 static void GenomicSentinelProc (BigScalar calldata, PrimDrawContext pdc)
857
858 {
859 BoxInfo box;
860 BioseqPtr bsp;
861 BioseqViewPtr bvp;
862 ValNodePtr curr;
863 Uint2 entityID;
864 Boolean forceSeglevelsTo1 = TRUE;
865 GlobalBspPtr gbp;
866 ValNodePtr graphs;
867 /* SeqEntryPtr oldscope; */
868 Int2 oldstyle;
869 SegmenT pic;
870 BasePPtr prim;
871 Int4 scaleX;
872 Int4 scaleY;
873 SeqEntryPtr sep;
874 Int4 seq_len;
875 SeqGraphPtr sgp;
876 Boolean show_msg = FALSE;
877 ValNodePtr slp_list;
878 SeqLocPtr slp;
879 SentinelPtr sp;
880 Int2 style;
881 ValNodePtr vnp;
882 BoxInfo world;
883
884 sp = (SentinelPtr) calldata;
885 if (sp == NULL) return;
886 if (sp->fetched) return;
887 sp->fetched = TRUE;
888 bvp = sp->bvp;
889 bsp = bvp->bsp;
890 slp_list = NULL;
891 if (bvp->isGenome && bvp->gdraw_p != NULL) {
892 slp_list = NULL;
893 for (curr = bvp->gdraw_p->gbp_list; curr !=NULL; curr = curr->next) {
894 gbp = curr->data.ptrvalue;
895 bsp = gbp->bsp;
896 seq_len = bsp->length;
897 slp = load_seq_loc (sp->start, sp->stop, seq_len, FALSE,
898 SeqIdFindBest (bsp->id, 0), &show_msg, FALSE);
899 if (slp != NULL) {
900 ValNodeAddPointer ((Pointer) &slp_list, (Uint1) (gbp->priority), slp);
901 }
902 }
903 } else {
904 bsp = bvp->bsp;
905 slp = SeqLocIntNew (sp->start, sp->stop, Seq_strand_plus, SeqIdFindBest (bsp->id, 0));
906 ValNodeAddPointer (&slp_list, 0, (Pointer) slp);
907 }
908 oldstyle = GetMuskCurrentSt ();
909 style = GetValue (bvp->style) - 1;
910 SetMuskCurrentSt (GetMuskStyleName (style));
911
912 bsp = bvp->bsp;
913 sep = SeqMgrGetSeqEntryForData (bsp);
914 if (IsADeltaBioseq (sep)) {
915 forceSeglevelsTo1 = FALSE;
916 }
917 entityID = ObjMgrGetEntityIDForChoice (sep);
918 if (entityID > 0) {
919 sep = GetBestTopParentForData (entityID, bsp);
920 /* oldscope = SeqEntrySetScope (sep); */
921 }
922
923 ViewerBox (bvp->vwr, NULL, NULL, NULL, &scaleX, &scaleY);
924 pic = DrawSequinMapEx (slp_list, sep, scaleX, NULL, NULL, forceSeglevelsTo1, bvp->tempResultList);
925 ChangeAddPrimOrder (ADD_TO_TAIL);
926 prim = (BasePPtr) pic;
927 prim->code = SEGMENT;
928 OffsetSegment (pic, sp->start, 0);
929 ExploreSegment (pic, (Pointer) bvp, AddToEntityList);
930
931 graphs = CollectGraphs (entityID, bsp, sp->start, sp->stop);
932 if (graphs != NULL) {
933 SegmentBox (pic, &box);
934 for (vnp = graphs; vnp != NULL; vnp = vnp->next) {
935 sgp = (SeqGraphPtr) vnp->data.ptrvalue;
936 AddGraphSentinelToPicture (sgp, bsp, pic, scaleX,
937 box.bottom - 10, /* sp->start */ 0, NULL);
938 }
939 }
940
941 LinkSegment (bvp->pict, pic);
942 RecalculateSegment (pic, scaleX, scaleY);
943
944 ViewerBox (bvp->vwr, &world, NULL, NULL, &scaleX, &scaleY);
945 for (vnp = bvp->sentinelList; vnp != NULL; vnp = vnp->next) {
946 sp = (SentinelPtr) vnp->data.ptrvalue;
947 if (sp != NULL) {
948 if (PrimitiveBox (sp->snt, scaleX, scaleY, &box)) {
949 ChangeSentinelRectangle (sp->snt, box.left, world.top, box.right, world.bottom);
950 }
951 }
952 }
953
954 /*
955 if (entityID > 0) {
956 SeqEntrySetScope (oldscope);
957 }
958 */
959 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
960 }
961
PopulateGraphic(BioseqViewPtr bvp)962 static void PopulateGraphic (BioseqViewPtr bvp)
963
964 {
965 BioseqPtr bsp;
966 BioseqSetPtr bssp;
967 DeltaSeqPtr dsp;
968 Uint2 entityID;
969 Int2 i;
970 Boolean isGenome;
971 Int4 labelWid;
972 Int4 len;
973 SeqLocPtr loc;
974 Int4 max;
975 Int4 min;
976 MakeMultiData mmd;
977 Int2 oldstyle;
978 RecT r;
979 Int4 scaleX;
980 Int4 scaleY;
981 SeqEntryPtr sep;
982 SeqLocPtr slp;
983 ValNodePtr slp_list;
984 SentinelPtr sp;
985 Int4 start;
986 Char str [32];
987 Int2 style;
988 ValNode vn;
989 ValNodePtr vnp;
990 Int4 vwr_x;
991 Int4 vwr_y;
992 Int2 vwr_align;
993 SeqViewProcsPtr svpp;
994
995 if (bvp == NULL) return;
996 sep = SeqMgrGetSeqEntryForData (bvp->bsp);
997 entityID = ObjMgrGetEntityIDForChoice (sep);
998
999 svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
1000 if (svpp != NULL && svpp->lockFarComponents) {
1001 sep = GetTopSeqEntryForEntityID (entityID);
1002 LookupFarSeqIDs (sep, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE);
1003 }
1004
1005 sep = GetBestTopParentForData (entityID, bvp->bsp);
1006 if (! bvp->hasTargetControl) {
1007 PopulateSimpleGraphic (bvp); /* Nentrez should do this until more work is done */
1008 return;
1009 }
1010 isGenome = FALSE;
1011 if (IsAGenomeRecord (sep) ||
1012 IsSegmentedBioseqWithoutParts (sep)) {
1013 isGenome = TRUE;
1014 if (bvp->isGenome) {
1015 if (IS_Bioseq_set (sep)) {
1016 bssp = (BioseqSetPtr) sep->data.ptrvalue;
1017 if (bssp != NULL && bssp->_class == BioseqseqSet_class_equiv) {
1018 PopulateSimpleGraphic (bvp);
1019 return;
1020 }
1021 }
1022 }
1023
1024 } else if (IsADeltaBioseq (sep)) {
1025 /*
1026 isGenome = FALSE;
1027 if (bvp->isGenome) {
1028 if (IS_Bioseq_set (sep)) {
1029 bssp = (BioseqSetPtr) sep->data.ptrvalue;
1030 if (bssp != NULL && bssp->_class == BioseqseqSet_class_equiv) {
1031 PopulateSimpleGraphic (bvp);
1032 return;
1033 }
1034 }
1035 }
1036 */
1037 PopulateSimpleGraphic (bvp);
1038 return;
1039
1040 } else {
1041 PopulateSimpleGraphic (bvp);
1042 return;
1043 }
1044 WatchCursor ();
1045 vwr_x = INT4_MIN;
1046 vwr_y = INT4_MAX;
1047 vwr_align = UPPER_LEFT;
1048 if (bvp->moveToOldPos) {
1049 if (bvp->pict != NULL) {
1050 get_viewer_position (bvp->vwr, &(vwr_x), &(vwr_y));
1051 vwr_align = MIDDLE_CENTER;
1052 }
1053 bvp->moveToOldPos = FALSE;
1054 }
1055 Reset (bvp->vwr);
1056 bvp->pict = DeletePicture (bvp->pict);
1057 Update ();
1058 if (bvp->isGenome && bvp->gdraw_p == NULL) {
1059 PopulateMap (bvp);
1060 Reset (bvp->vwr);
1061 bvp->pict = DeletePicture (bvp->pict);
1062 Update ();
1063 }
1064 bsp = bvp->bsp;
1065 if (bsp != NULL) {
1066 scaleY = 1;
1067 len = 0;
1068 if (bvp->sentinelList != NULL) {
1069 bvp->sentinelList = ValNodeFreeData (bvp->sentinelList);
1070 }
1071 if (bvp->sentinelList == NULL) {
1072 sep = SeqMgrGetSeqEntryForData (bsp);
1073 if (bsp->repr == Seq_repr_raw) {
1074 sp = MemNew (sizeof (SentinelData));
1075 if (sp != NULL) {
1076 sp->bvp = bvp;
1077 sp->start = 0;
1078 sp->stop = bsp->length - 1;
1079 sp->fetched = FALSE;
1080 ValNodeAddPointer (&(bvp->sentinelList), 0, (Pointer) sp);
1081 }
1082 } else if (bsp->repr == Seq_repr_seg) {
1083 vn.choice = SEQLOC_MIX;
1084 vn.next = NULL;
1085 vn.data.ptrvalue = bsp->seq_ext;
1086 start = 0;
1087 slp = SeqLocFindNext (&vn, NULL);
1088 while (slp != NULL) {
1089 if (slp->choice != SEQLOC_NULL) {
1090 len = SeqLocLen (slp);
1091 if (len > 0) {
1092 sp = MemNew (sizeof (SentinelData));
1093 if (sp != NULL) {
1094 sp->bvp = bvp;
1095 sp->start = start;
1096 sp->stop = start + len - 1;
1097 sp->fetched = FALSE;
1098 ValNodeAddPointer (&(bvp->sentinelList), 0, (Pointer) sp);
1099 start += len;
1100 }
1101 }
1102 }
1103 slp = SeqLocFindNext (&vn, slp);
1104 }
1105 } else if (bsp->repr == Seq_repr_delta && bsp->seq_ext_type == 4) {
1106 dsp = (DeltaSeqPtr) bsp->seq_ext;
1107 loc = DeltaSeqsToSeqLocs (dsp);
1108 start = 0;
1109 slp = SeqLocFindNext (loc, NULL);
1110 while (slp != NULL) {
1111 if (slp->choice != SEQLOC_NULL) {
1112 len = SeqLocLen (slp);
1113 if (len > 0) {
1114 sp = MemNew (sizeof (SentinelData));
1115 if (sp != NULL) {
1116 sp->bvp = bvp;
1117 sp->start = start;
1118 sp->stop = start + len - 1;
1119 sp->fetched = FALSE;
1120 ValNodeAddPointer (&(bvp->sentinelList), 0, (Pointer) sp);
1121 start += len;
1122 }
1123 }
1124 }
1125 slp = SeqLocFindNext (loc, slp);
1126 }
1127 SeqLocFree (loc);
1128 } else if (bsp->repr == Seq_repr_map) {
1129 if (bsp->length > 100000000) {
1130 len = 10000000;
1131 } else if (bsp->length > 10000000) {
1132 len = 1000000;
1133 } else if (bsp->length > 1000000) {
1134 len = 100000;
1135 } else if (bsp->length > 100000) {
1136 len = 10000;
1137 } else {
1138 len = bsp->length;
1139 }
1140 start = 0;
1141 while (start < bsp->length) {
1142 sp = MemNew (sizeof (SentinelData));
1143 if (sp != NULL) {
1144 sp->bvp = bvp;
1145 sp->start = start;
1146 if (start + len - 1 > bsp->length) {
1147 len = bsp->length - start;
1148 }
1149 sp->stop = start + len - 1;
1150 sp->fetched = FALSE;
1151 ValNodeAddPointer (&(bvp->sentinelList), 0, (Pointer) sp);
1152 start += len;
1153 }
1154 }
1155 }
1156 }
1157
1158 len = 0;
1159 if (! bvp->isGenome) {
1160 slp_list = NULL;
1161 sep = NULL;
1162 len = 0;
1163 if (bvp->viewWholeEntity) {
1164 sep = SeqMgrGetSeqEntryForData (bsp);
1165 entityID = ObjMgrGetEntityIDForChoice (sep);
1166 sep = GetTopSeqEntryForEntityID (entityID);
1167 mmd.slp_list = NULL;
1168 mmd.len = 0;
1169 BioseqExplore (sep, (Pointer) &mmd, MakeMultiSlpList);
1170 slp_list = mmd.slp_list;
1171 len = mmd.len;
1172 } else {
1173 sep = SeqMgrGetSeqEntryForData (bsp);
1174 len = bsp->length;
1175 slp = SeqLocIntNew (0, len-1, Seq_strand_plus, SeqIdFindBest (bsp->id, 0));
1176 ValNodeAddPointer (&slp_list, 0, (Pointer) slp);
1177 }
1178 if (bvp->slp_list != NULL) {
1179 free_slp_list (bvp->slp_list);
1180 bvp->slp_list = NULL;
1181 }
1182 bvp->slp_list = slp_list;
1183 }
1184
1185 if (bvp->scaleNotCalculated) {
1186 SafeHide (bvp->scale);
1187 Reset (bvp->scale);
1188 ObjectRect (bvp->vwr, &r);
1189 InsetRect (&r, 4, 4);
1190 oldstyle = GetMuskCurrentSt ();
1191 style = GetValue (bvp->style) - 1;
1192 SetMuskCurrentSt (GetMuskStyleName (style));
1193 labelWid = CountMaxSeqLabel (bvp->slp_list) + 2;
1194 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
1195 if (r.right - r.left < 2 * labelWid) {
1196 labelWid = 0;
1197 }
1198 if (isGenome) {
1199 if (bsp->length > 100000000) {
1200 max = 49999L;
1201 } else if (bsp->length > 10000000) {
1202 max = 4999L;
1203 } else if (bsp->length > 1000000) {
1204 max = 499L;
1205 } else if (bsp->length > 100000) {
1206 max = 49L;
1207 } else if (bsp->length > 10000) {
1208 max = 19L;
1209 } else if (bsp->length > 1000) {
1210 max = 9L;
1211 } else {
1212 max = 4L;
1213 }
1214 min = (Int4) 1;
1215 } else {
1216 max = (Int4) MAX (len / (Int4) (r.right - r.left - labelWid), 1) + 2;
1217 max = (Int4) MIN (max, 50000L);
1218 min = (Int4) MAX (len / 320000L, 1L);
1219 }
1220 bvp->maxScale = max;
1221 i = 1;
1222 while (i < MAXZOOMSCALEVAL && min > zoomScaleVal [i]) {
1223 i++;
1224 }
1225 bvp->minIndex = i;
1226 while (i < MAXZOOMSCALEVAL && max > zoomScaleVal [i - 1]) {
1227 sprintf (str, "%ld", (long) (zoomScaleVal [i]));
1228 if (max < zoomScaleVal [i]) {
1229 sprintf (str, "%ld", (long) zoomScaleVal [i]);
1230 }
1231 PopupItem (bvp->scale, str);
1232 i++;
1233 }
1234 SetValue (bvp->scale, MAX (i - bvp->minIndex - 3, 1));
1235 bvp->scaleNotCalculated = FALSE;
1236 }
1237 SafeShow (bvp->scale);
1238 i = GetValue (bvp->scale) - 1 + bvp->minIndex;
1239 if (i < MAXZOOMSCALEVAL && i > 0) {
1240 scaleX = MIN (zoomScaleVal [i], bvp->maxScale);
1241 } else {
1242 scaleX = bvp->minIndex;
1243 }
1244
1245 bvp->pict = CreatePicture ();
1246 for (vnp = bvp->sentinelList; vnp != NULL; vnp = vnp->next) {
1247 sp = (SentinelPtr) vnp->data.ptrvalue;
1248 if (sp != NULL) {
1249 sp->seg = CreateSegment (bvp->pict, 0, 0);
1250 sp->snt = AddSntRectangle (bvp->pict, sp->start, -35, sp->stop, -40,
1251 GenomicSentinelProc, (BigScalar) sp, NULL, 0);
1252 /* AddRectangle (bvp->pict, sp->start, -35, sp->stop, -40, 0, FALSE, 0); */
1253 }
1254 }
1255
1256 AttachPicture (bvp->vwr, bvp->pict, vwr_x, vwr_y, vwr_align, scaleX, scaleY,
1257 bvp->highlightSelections ? DrawSelectionRange : NULL);
1258 SetViewerProcs (bvp->vwr, ClickGraphic, NULL, ReleaseGraphic, NULL);
1259 /* InitSelectGraphical (bvp); */
1260 }
1261 ArrowCursor ();
1262 }
1263
ClickAlignment(VieweR vwr,SegmenT seg,PoinT pt)1264 static void ClickAlignment (VieweR vwr, SegmenT seg, PoinT pt)
1265
1266 {
1267 BioseqViewPtr bvp;
1268
1269 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
1270 if (bvp == NULL) return;
1271 bvp->wasDoubleClick = dblClick;
1272 bvp->wasShiftKey = shftKey;
1273 bvp->old_rect_shown = FALSE;
1274 bvp->pnt_start = pt;
1275 bvp->pnt_stop = pt;
1276 InvertMode ();
1277 CommonFrameProc (vwr, bvp);
1278 }
1279
DragAlignment(VieweR vwr,SegmenT seg,PoinT pt)1280 static void DragAlignment (VieweR vwr, SegmenT seg, PoinT pt)
1281
1282 {
1283 BioseqViewPtr bvp;
1284
1285 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
1286 if (bvp == NULL) return;
1287 if(bvp->wasDoubleClick || bvp->wasShiftKey) return;
1288 InvertMode ();
1289 CommonFrameProc (vwr, bvp);
1290 bvp->pnt_stop = pt;
1291 CommonFrameProc (vwr, bvp);
1292 }
1293
ReleaseAlignment(VieweR vwr,SegmenT seg,PoinT pt)1294 static void ReleaseAlignment (VieweR vwr, SegmenT seg, PoinT pt)
1295
1296 {
1297 BioseqViewPtr bvp;
1298 Uint2 entityID;
1299 FILE *fp;
1300 Uint4 itemID;
1301 Uint2 itemtype;
1302 Int4 left, right;
1303 Uint4 option = TXALIGN_MISMATCH;
1304 Char path [PATH_MAX];
1305 SeqEntryPtr sep;
1306 SeqLocPtr slp;
1307 PntInfo start_info, stop_info;
1308 Char title [64];
1309
1310 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
1311 if (bvp == NULL) return;
1312
1313 if (bvp->wasDoubleClick) {
1314 if (Find_segment_IDs (vwr, pt, &entityID, &itemID, &itemtype)) {
1315 sep = GetTopSeqEntryForEntityID (entityID);
1316 if (bvp->launchSubviewers) {
1317 WatchCursor ();
1318 Update ();
1319 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
1320 ArrowCursor ();
1321 Update ();
1322 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
1323 WatchCursor ();
1324 Update ();
1325 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
1326 ArrowCursor ();
1327 Update ();
1328 } else if (bvp->launchEditors) {
1329 WatchCursor ();
1330 Update ();
1331 GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, itemID,
1332 itemtype, 0, 0, itemtype, 0);
1333 ArrowCursor ();
1334 Update ();
1335 return;
1336 } else {
1337 return;
1338 }
1339 }
1340 if (! bvp->sendSelectMessages) return;
1341 if (bvp->wasShiftKey) {
1342 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
1343 } else {
1344 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
1345 }
1346 } else if (bvp->sendSelectMessages) {
1347 if (Find_segment_IDs (vwr, pt, &entityID, &itemID, &itemtype)) {
1348 if (bvp->wasShiftKey) {
1349 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
1350 } else {
1351 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
1352 }
1353 } else if (! bvp->wasShiftKey) {
1354 ObjMgrDeSelect (0, 0, 0, 0, NULL);
1355 }
1356 }
1357 if (bvp->slp_list != NULL && bvp->anp_node != NULL) {
1358 InvertMode ();
1359 CommonFrameProc (vwr, bvp);
1360 bvp->pnt_stop = pt;
1361
1362 if (ABS (bvp->pnt_start.x - bvp->pnt_stop.x) > 5) {
1363 WatchCursor ();
1364 Update ();
1365 GetTitle (ParentWindow (vwr), title, sizeof (title) - 1);
1366 MapViewerToWorld(vwr, bvp->pnt_start, &start_info);
1367 MapViewerToWorld(vwr, bvp->pnt_stop, &stop_info);
1368 left = MIN(start_info.x, stop_info.x);
1369 right = MAX(start_info.x, stop_info.x);
1370 StringCat (title, " alignment");
1371 TmpNam (path);
1372 fp = FileOpen(path, "w");
1373 if (fp != NULL) {
1374 slp = bvp->slp_list->data.ptrvalue;
1375 if (ShowAlignNodeText (bvp->anp_node, -1, 40, fp, left, right, option, NULL, NULL))
1376 FileClose(fp);
1377 else
1378 FileClose(fp);
1379 }
1380 LaunchGeneralTextViewer (path, title);
1381 }
1382 FileRemove (path);
1383 ArrowCursor ();
1384 Update ();
1385 }
1386 }
1387
DrawAlignOnAllSequences(BioseqViewPtr bvp,SeqAlignPtr align,Int2 scaleX)1388 static void DrawAlignOnAllSequences (BioseqViewPtr bvp, SeqAlignPtr align, Int2 scaleX)
1389
1390 {
1391 ValNode vn;
1392
1393 Int4 y_pos = 0;
1394 Int4 value, style;
1395 SeqIdPtr m_sip;
1396 BioseqPtr mbsp;
1397 SeqLocPtr m_loc;
1398 Int4 start, stop;
1399 CollectSeqOption cs_option;
1400 CollectAlignOption ca_option;
1401 SeqEntryPtr sep;
1402 Uint2 entityID;
1403
1404
1405 if (bvp == NULL || align == NULL) return;
1406 sep = SeqMgrGetSeqEntryForData (bvp->bsp);
1407 entityID = ObjMgrGetEntityIDForChoice (sep);
1408
1409 m_sip = make_master(align);
1410 if(m_sip == NULL)
1411 {
1412 Message(MSG_ERROR, "Fail to get the master id");
1413 return;
1414 }
1415
1416 mbsp = BioseqLockById(m_sip);
1417 if(mbsp == NULL)
1418 {
1419 get_boundary(m_sip, &start, &stop, align);
1420 m_loc = SeqLocIntNew(start, stop, Seq_strand_plus, m_sip);
1421 }
1422 else
1423 m_loc = SeqLocIntNew(0, mbsp->length-1, Seq_strand_plus, m_sip);
1424 vn.data.ptrvalue = m_loc;
1425 vn.next = NULL;
1426 if(scaleX <=0)
1427 {
1428 if(mbsp != NULL)
1429 BioseqUnlock(mbsp);
1430 SeqLocFree(m_loc);
1431 return;
1432 }
1433
1434
1435 style= GetMuskCParam(MSM_ALIGNMENT, 0, MSM_STYLE);
1436 if(style== MSM_MDIM)
1437 {
1438 if(!use_multiple_dimension(align))
1439 style= MSM_MPAIR;
1440 }
1441 else
1442 style= MSM_MPAIR;
1443
1444
1445 load_align_option_for_graphic(&ca_option, &cs_option, style, FALSE);
1446 if(mbsp == NULL)
1447 ca_option.show_mismatch = FALSE;
1448 ca_option.csop = &cs_option;
1449
1450 if(style== MSM_MDIM)
1451 value = COLLECT_MD;
1452 else
1453 value = COLLECT_MP;
1454 if (bvp->anp_node != NULL) {
1455 bvp->anp_node = FreeAlignNode (bvp->anp_node);
1456 }
1457 bvp->anp_node = collect_anpnode_with_option(&ca_option, m_loc, entityID,
1458 value, OBJ_SEQALIGN, NULL, NULL, TRUE);
1459 if(bvp->anp_node == NULL)
1460 {
1461 if(mbsp != NULL)
1462 BioseqUnlock(mbsp);
1463 SeqLocFree(m_loc);
1464 return;
1465 }
1466
1467 bvp->pict = CreatePicture();
1468 DrawMPAlignment(bvp->anp_node, 0, SeqLocLen(m_loc)-1, m_loc, entityID,
1469 scaleX, &y_pos, (Uint1)style, FALSE, bvp->pict);
1470 if(mbsp != NULL)
1471 BioseqUnlock(mbsp);
1472 SeqLocFree(m_loc);
1473 }
1474
PopulateAlignment(BioseqViewPtr bvp)1475 static void PopulateAlignment (BioseqViewPtr bvp)
1476
1477 {
1478 SeqAlignPtr align;
1479 BioseqPtr bsp;
1480 BioseqSetPtr bssp;
1481 Uint2 entityID;
1482 Int2 i;
1483 Int4 labelWid;
1484 Int4 len;
1485 Int4 max;
1486 Int4 min;
1487 MakeMultiData mmd;
1488 SeqEntryPtr oldscope = NULL;
1489 Int2 oldstyle;
1490 RecT r;
1491 Int4 scaleX;
1492 Int4 scaleY;
1493 SeqEntryPtr sep;
1494 ValNodePtr slp_list;
1495 SeqLocPtr slp;
1496 Char str [32];
1497 Int2 style;
1498 Int4 vwr_x;
1499 Int4 vwr_y;
1500 Int2 vwr_align;
1501 Int4 y_pos = 0;
1502
1503 if (bvp == NULL) return;
1504 WatchCursor ();
1505 vwr_x = INT4_MIN;
1506 vwr_y = INT4_MAX;
1507 vwr_align = UPPER_LEFT;
1508 if (bvp->moveToOldPos) {
1509 if (bvp->pict != NULL) {
1510 get_viewer_position (bvp->vwr, &(vwr_x), &(vwr_y));
1511 vwr_align = MIDDLE_CENTER;
1512 }
1513 bvp->moveToOldPos = FALSE;
1514 }
1515 Reset (bvp->vwr);
1516 bvp->pict = DeletePicture (bvp->pict);
1517 Update ();
1518 if (bvp->isGenome && bvp->slp_list == NULL) return;
1519 bsp = bvp->bsp;
1520 if (bsp != NULL) {
1521 sep = SeqMgrGetSeqEntryForData (bsp);
1522 entityID = ObjMgrGetEntityIDForChoice (sep);
1523 sep = GetBestTopParentForData (entityID, bsp);
1524 if (sep != NULL && sep->choice == 2) {
1525 bssp = (BioseqSetPtr) sep->data.ptrvalue;
1526 if (bssp != NULL && bssp->_class == 10) {
1527 ArrowCursor ();
1528 return;
1529 }
1530 }
1531 scaleY = 1;
1532 len = 0;
1533 slp = NULL;
1534 if (! bvp->isGenome) {
1535 slp_list = NULL;
1536 sep = NULL;
1537 len = 0;
1538 if (bvp->viewWholeEntity) {
1539 sep = SeqMgrGetSeqEntryForData (bsp);
1540 entityID = ObjMgrGetEntityIDForChoice (sep);
1541 sep = GetTopSeqEntryForEntityID (entityID);
1542 mmd.slp_list = NULL;
1543 mmd.len = 0;
1544 BioseqExplore (sep, (Pointer) &mmd, MakeMultiSlpList);
1545 slp_list = mmd.slp_list;
1546 len = mmd.len;
1547 } else {
1548 sep = SeqMgrGetSeqEntryForData (bsp);
1549 len = bsp->length;
1550 slp = SeqLocIntNew (0, len-1, Seq_strand_plus, SeqIdFindBest (bsp->id, 0));
1551 ValNodeAddPointer (&slp_list, 0, (Pointer) slp);
1552 }
1553 if (bvp->slp_list != NULL) {
1554 free_slp_list (bvp->slp_list);
1555 bvp->slp_list = NULL;
1556 }
1557 bvp->slp_list = slp_list;
1558 }
1559 oldstyle = GetMuskCurrentSt ();
1560 style = GetValue (bvp->style) - 1;
1561 SetMuskCurrentSt (GetMuskStyleName (style));
1562
1563 if (bvp->scaleNotCalculated) {
1564 SafeHide (bvp->scale);
1565 Reset (bvp->scale);
1566 ObjectRect (bvp->vwr, &r);
1567 InsetRect (&r, 4, 4);
1568 labelWid = CountMaxSeqLabel (bvp->slp_list) + 2;
1569 if (r.right - r.left < 2 * labelWid) {
1570 labelWid = 0;
1571 }
1572 if (bvp->isGenome) {
1573 slp = (SeqLocPtr) bvp->slp_list->data.ptrvalue;
1574 len = slp_list_len (slp);
1575 }
1576 max = (Int4) MAX (len / (Int4) (r.right - r.left - labelWid), 1) + 2;
1577 max = (Int4) MIN (max, 50000L);
1578 min = (Int4) MAX (len / 320000L, 1L);
1579 bvp->maxScale = max;
1580 i = 1;
1581 while (i < MAXZOOMSCALEVAL && min > zoomScaleVal [i]) {
1582 i++;
1583 }
1584 bvp->minIndex = i;
1585 while (i < MAXZOOMSCALEVAL && max > zoomScaleVal [i - 1]) {
1586 sprintf (str, "%ld", (long) (zoomScaleVal [i]));
1587 if (max < zoomScaleVal [i]) {
1588 sprintf (str, "%ld", (long) zoomScaleVal [i]);
1589 }
1590 PopupItem (bvp->scale, str);
1591 i++;
1592 }
1593 SetValue (bvp->scale, MAX (i - bvp->minIndex, 1));
1594 bvp->scaleNotCalculated = FALSE;
1595 }
1596 SafeShow (bvp->scale);
1597 i = GetValue (bvp->scale) - 1 + bvp->minIndex;
1598 if (i < MAXZOOMSCALEVAL && i > 0) {
1599 scaleX = MIN (zoomScaleVal [i], bvp->maxScale);
1600 } else {
1601 scaleX = bvp->minIndex;
1602 }
1603
1604 sep = SeqMgrGetSeqEntryForData (bsp);
1605 entityID = ObjMgrGetEntityIDForChoice (sep);
1606 if (entityID > 0) {
1607 sep = GetBestTopParentForData (entityID, bsp);
1608 oldscope = SeqEntrySetScope (sep);
1609 }
1610
1611 if (bvp->viewWholeEntity) {
1612 align = NULL;
1613 sep = GetTopSeqEntryForEntityID (entityID);
1614 SeqEntryExplore (sep, &align, FindAlignment);
1615 DrawAlignOnAllSequences (bvp, align, scaleX);
1616 } else if (bvp->anp_node == NULL) {
1617 Reset (bvp->vwr);
1618 bvp->pict = DeletePicture (bvp->pict);
1619 slp = (SeqLocPtr) bvp->slp_list->data.ptrvalue;
1620 bvp->pict = DrawSeqHistoryAlignment (slp, scaleX,
1621 &(bvp->anp_node),
1622 &(bvp->seq_entityID),
1623 FALSE);
1624 } else if (bvp->seq_entityID > 0) {
1625 bvp->pict = CreatePicture ();
1626 slp = (SeqLocPtr) bvp->slp_list->data.ptrvalue;
1627 DrawMPAlignment (bvp->anp_node, 0, SeqLocLen (slp), slp,
1628 bvp->seq_entityID, scaleX, &y_pos,
1629 MSM_MPAIR, FALSE, bvp->pict);
1630 } else {
1631 if (entityID > 0) {
1632 SeqEntrySetScope (oldscope);
1633 }
1634 ArrowCursor ();
1635 return;
1636 }
1637
1638 if (entityID > 0) {
1639 SeqEntrySetScope (oldscope);
1640 }
1641
1642 AttachPicture (bvp->vwr, bvp->pict, vwr_x, vwr_y,
1643 vwr_align, scaleX, scaleY, NULL);
1644 SetViewerProcs (bvp->vwr, ClickAlignment, DragAlignment, ReleaseAlignment, NULL);
1645 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
1646 InitSelectGraphical (bvp);
1647 }
1648 ArrowCursor ();
1649 }
1650
ClickSalsa(PaneL pnl,PoinT pt)1651 static void ClickSalsa (PaneL pnl, PoinT pt)
1652
1653 {
1654 BioseqViewPtr bvp;
1655
1656 bvp = (BioseqViewPtr) GetObjectExtra (pnl);
1657 if (bvp == NULL) return;
1658 bvp->wasDoubleClick = dblClick;
1659 bvp->wasShiftKey = shftKey;
1660 }
1661
ReleaseSalsa(PaneL pnl,PoinT pt)1662 static void ReleaseSalsa (PaneL pnl, PoinT pt)
1663
1664 {
1665 BioseqViewPtr bvp;
1666 Uint2 entityID;
1667 Uint4 itemID;
1668 Uint2 itemtype;
1669 SeqEntryPtr sep;
1670
1671 bvp = (BioseqViewPtr) GetObjectExtra (pnl);
1672 if (bvp == NULL) return;
1673
1674 if (bvp->wasDoubleClick) {
1675 if (FindIdsInSalsaPanel (pnl, pt, &entityID, &itemID, &itemtype)) {
1676 sep = GetTopSeqEntryForEntityID (entityID);
1677 if (bvp->launchSubviewers) {
1678 WatchCursor ();
1679 Update ();
1680 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
1681 ArrowCursor ();
1682 Update ();
1683 return;
1684 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
1685 WatchCursor ();
1686 Update ();
1687 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
1688 ArrowCursor ();
1689 Update ();
1690 return;
1691 } else if (bvp->launchEditors) {
1692 WatchCursor ();
1693 Update ();
1694 GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, itemID,
1695 itemtype, 0, 0, itemtype, 0);
1696 ArrowCursor ();
1697 Update ();
1698 return;
1699 } else {
1700 return;
1701 }
1702 }
1703 if (! bvp->sendSelectMessages) return;
1704 if (bvp->wasShiftKey) {
1705 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
1706 } else {
1707 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
1708 }
1709 } else if (bvp->sendSelectMessages) {
1710 if (FindIdsInSalsaPanel (pnl, pt, &entityID, &itemID, &itemtype)) {
1711 if (bvp->wasShiftKey) {
1712 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
1713 } else {
1714 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
1715 }
1716 } else if (! bvp->wasShiftKey) {
1717 ObjMgrDeSelect (0, 0, 0, 0, NULL);
1718 }
1719 }
1720 }
1721
PopulateSalsa(BioseqViewPtr bvp)1722 static void PopulateSalsa (BioseqViewPtr bvp)
1723
1724 {
1725 BioseqPtr bsp;
1726 Uint2 entityID;
1727 Uint1 numbering;
1728 Int2 oldstyle;
1729 RecT r;
1730 SeqEntryPtr sep;
1731 Uint1 sequence_shown;
1732 Uint1 show_feat;
1733 Int2 style;
1734 WindoW tempPort;
1735 Int2 val;
1736
1737 if (bvp == NULL) return;
1738 WatchCursor ();
1739 Reset (bvp->pnl);
1740 SetPanelClick (bvp->pnl, NULL, NULL, NULL, NULL);
1741 Update ();
1742 bsp = bvp->bsp;
1743 if (bsp != NULL) {
1744 oldstyle = GetMuskCurrentSt ();
1745 style = GetValue (bvp->style) - 1;
1746 SetMuskCurrentSt (GetMuskStyleName (style));
1747 sep = SeqMgrGetSeqEntryForData (bsp);
1748 if (bvp->viewWholeEntity) {
1749 entityID = ObjMgrGetEntityIDForChoice (sep);
1750 sep = GetTopSeqEntryForEntityID (entityID);
1751 }
1752 val = GetValue (bvp->seqControl);
1753 switch (val) {
1754 case 1 :
1755 sequence_shown = SEQ_SHOW1;
1756 break;
1757 case 2 :
1758 sequence_shown = SEQ_SHOWALG;
1759 break;
1760 default :
1761 sequence_shown = SEQ_SHOW1;
1762 break;
1763 }
1764 val = GetValue (bvp->featControl);
1765 switch (val) {
1766 case 1 :
1767 show_feat = SEQ_FEAT0;
1768 break;
1769 case 2 :
1770 show_feat = SEQ_FEAT1;
1771 break;
1772 case 3 :
1773 show_feat = SEQ_FEATALL;
1774 break;
1775 default :
1776 show_feat = SEQ_FEAT1;
1777 break;
1778 }
1779 val = GetValue (bvp->numControl);
1780 switch (val) {
1781 case 1 :
1782 numbering = SEQ_NUM0;
1783 break;
1784 case 2 :
1785 numbering = SEQ_NUM1;
1786 break;
1787 case 3 :
1788 numbering = SEQ_NUM2;
1789 break;
1790 default :
1791 numbering = SEQ_NUM2;
1792 break;
1793 }
1794 PopulateSalsaPanel (bvp->pnl, sep, bvp->viewWholeEntity,
1795 sequence_shown, show_feat, numbering,
1796 bvp->displayFont);
1797 SetPanelClick (bvp->pnl, ClickSalsa, NULL, NULL, ReleaseSalsa);
1798 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
1799 if (Visible (bvp->pnl) && AllParentsVisible (bvp->pnl)) {
1800 tempPort = SavePort (bvp->pnl);
1801 ResetClip ();
1802 Select (bvp->pnl);
1803 ObjectRect (bvp->pnl, &r);
1804 InsetRect (&r, 1, 1);
1805 InvalRect (&r);
1806 RestorePort (tempPort);
1807 }
1808 }
1809 ArrowCursor ();
1810 }
1811
1812 #define VSM_PICT_UP_BUTTON 65001
1813 #define VSM_PICT_DOWN_BUTTON 65002
1814
ClickDesktop(VieweR vwr,SegmenT s,PoinT pt)1815 static void ClickDesktop (VieweR vwr, SegmenT s, PoinT pt)
1816
1817 {
1818 BioseqViewPtr bvp;
1819
1820 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
1821 if (bvp == NULL) return;
1822 bvp->wasDoubleClick = dblClick;
1823 bvp->wasShiftKey = shftKey;
1824 }
1825
ReleaseDesktop(VieweR vwr,SegmenT s,PoinT pt)1826 static void ReleaseDesktop (VieweR vwr, SegmenT s, PoinT pt)
1827
1828 {
1829 BioseqPtr bsp;
1830 BioseqViewPtr bvp;
1831 Uint2 entityID;
1832 Int2 expand = 0;
1833 Uint4 itemID;
1834 Uint2 itemtype;
1835 Uint2 primID;
1836 SegmenT seg;
1837 Uint2 segID;
1838 SeqEntryPtr sep;
1839
1840 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
1841 if (bvp == NULL) return;
1842 bsp = bvp->bsp;
1843 if (bsp == NULL) return;
1844 sep = SeqMgrGetSeqEntryForData (bsp);
1845 entityID = ObjMgrGetEntityIDForChoice (sep);
1846
1847 seg = FindSegment (vwr, pt, &segID, &primID, NULL);
1848 itemID = primID;
1849 itemtype = segID;
1850 if (primID == 0 || segID == 0) {
1851 if (! bvp->wasShiftKey) {
1852 ObjMgrDeSelect (0, 0, 0, 0, NULL);
1853 }
1854 return;
1855 }
1856 if (itemID == VSM_PICT_UP_BUTTON) {
1857 expand = 1;
1858 } else if (itemID == VSM_PICT_DOWN_BUTTON) {
1859 expand = -1;
1860 }
1861 if (expand != 0) {
1862 bvp->expansion += expand;
1863 Hide (vwr);
1864 ResetClip ();
1865 Update ();
1866 PopulateDesktop (bvp);
1867 Show (vwr);
1868 Update ();
1869 return;
1870 }
1871 if (bvp->wasDoubleClick) {
1872 sep = GetTopSeqEntryForEntityID (entityID);
1873 if (bvp->launchSubviewers) {
1874 WatchCursor ();
1875 Update ();
1876 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
1877 ArrowCursor ();
1878 Update ();
1879 return;
1880 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
1881 WatchCursor ();
1882 Update ();
1883 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
1884 ArrowCursor ();
1885 Update ();
1886 return;
1887 } else if (bvp->launchEditors) {
1888 WatchCursor ();
1889 Update ();
1890 GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, itemID,
1891 itemtype, 0, 0, itemtype, 0);
1892 ArrowCursor ();
1893 Update ();
1894 return;
1895 } else {
1896 return;
1897 }
1898 } else if (bvp->sendSelectMessages) {
1899 if (bvp->wasShiftKey) {
1900 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
1901 } else {
1902 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
1903 }
1904 }
1905 }
1906
PopulateDesktop(BioseqViewPtr bvp)1907 static void PopulateDesktop (BioseqViewPtr bvp)
1908
1909 {
1910 BioseqPtr bsp;
1911 Uint2 entityID;
1912 Boolean oldExtraLevel;
1913 ObjMgrDataPtr omdp;
1914 SegmenT seg;
1915 SeqEntryPtr sep;
1916 FonT tempfont;
1917 VSeqMgrPtr vsmp;
1918 VSMPictPtr vsmpp;
1919 Int4 vwr_x;
1920 Int4 vwr_y;
1921 Int2 vwr_align;
1922
1923 if (bvp == NULL) return;
1924 WatchCursor ();
1925 vwr_x = INT4_MIN;
1926 vwr_y = INT4_MAX;
1927 vwr_align = UPPER_LEFT;
1928 if (bvp->moveToOldPos) {
1929 if (bvp->pict != NULL) {
1930 get_viewer_position (bvp->vwr, &(vwr_x), &(vwr_y));
1931 vwr_align = MIDDLE_CENTER;
1932 }
1933 bvp->moveToOldPos = FALSE;
1934 }
1935 Reset (bvp->vwr);
1936 bvp->pict = DeletePicture (bvp->pict);
1937 Update ();
1938 bsp = bvp->bsp;
1939 if (bsp != NULL) {
1940 sep = SeqMgrGetSeqEntryForData (bsp);
1941 entityID = ObjMgrGetEntityIDForChoice (sep);
1942 omdp = ObjMgrGetData (entityID);
1943 vsmpp = MemNew (sizeof (VSMPict));
1944 if (vsmpp != NULL) {
1945 vsmpp->expansion = bvp->expansion;
1946 vsmp = VSeqMgrGet ();
1947 if (vsmp != NULL) {
1948 oldExtraLevel = vsmp->extraLevel;
1949 vsmp->extraLevel = TRUE;
1950 tempfont = vsmp->font;
1951 if (bvp->displayFont != NULL) {
1952 vsmp->font = bvp->displayFont;
1953 }
1954 SelectFont (vsmp->font);
1955 vsmp->lineheight = LineHeight();
1956 vsmp->leading = Leading();
1957 vsmp->charw = MaxCharWidth();
1958 seg = VSMEntityDraw (omdp, vsmpp, vsmp);
1959 vsmp->font = tempfont;
1960 SelectFont (vsmp->font);
1961 vsmp->lineheight = LineHeight();
1962 vsmp->leading = Leading();
1963 vsmp->charw = MaxCharWidth();
1964 SelectFont (systemFont);
1965 vsmp->extraLevel = oldExtraLevel;
1966 bvp->pict = CreatePicture ();
1967 LinkSegment (bvp->pict, seg);
1968 AttachPicture (bvp->vwr, bvp->pict, vwr_x, vwr_y, vwr_align, 1, 1, NULL);
1969 SetViewerProcs (bvp->vwr, ClickDesktop, NULL, ReleaseDesktop, NULL);
1970 }
1971 }
1972 MemFree (vsmpp);
1973 InitSelectDesktop (bvp);
1974 }
1975 ArrowCursor ();
1976 }
1977
1978 static ParData geneParFmt = {FALSE, FALSE, FALSE, FALSE, TRUE, 0, 0};
1979
1980 typedef struct geneinputdata {
1981 GrouP geneGrp;
1982 TexT geneText;
1983 DoC geneList;
1984 Int2 clickedItem;
1985 Int2 clickedRow;
1986 Int2 selectedItem;
1987 Int2 selectedRow;
1988 } GeneInputData, PNTR GeneInputDataPtr;
1989
1990 typedef struct genechoicedata {
1991 FORM_MESSAGE_BLOCK
1992
1993 BioseqViewPtr bvp;
1994 GeneInputData geneData1;
1995 GeneInputData geneData2;
1996 Int2 numItems;
1997 Int2 geneIdxNum;
1998 CharPtr PNTR geneListIdx;
1999 } GeneChoiceData, PNTR GeneChoiceDataPtr;
2000
CopyField(CharPtr str,size_t max,CharPtr source,Int2 col)2001 static void CopyField (CharPtr str, size_t max, CharPtr source, Int2 col)
2002
2003 {
2004 Char ch;
2005 size_t count;
2006 CharPtr ptr;
2007
2008 if (str != NULL && max > 0 && source != NULL) {
2009 MemSet (str, 0, max);
2010 ptr = source;
2011 ch = *ptr;
2012 while (col > 1 && ch != '\n' && ch != '\0') {
2013 while (ch != '\t' && ch != '\n' && ch != '\0') {
2014 ptr++;
2015 ch = *ptr;
2016 }
2017 if (ch == '\t') {
2018 ptr++;
2019 ch = *ptr;
2020 }
2021 col--;
2022 }
2023 count = 0;
2024 ch = ptr [count];
2025 while (ch != '\t' && ch != '\n' && ch != '\0') {
2026 count++;
2027 ch = ptr [count];
2028 }
2029 max = MIN (max, count);
2030 StringNCpy (str, ptr, max); /* remains StringNCpy, not _0 */
2031 }
2032 }
2033
CopyStrFromGeneList(GeneChoiceDataPtr gcp,CharPtr str,size_t max,Int2 row)2034 static void CopyStrFromGeneList (GeneChoiceDataPtr gcp, CharPtr str, size_t max, Int2 row)
2035
2036 {
2037 CharPtr source;
2038
2039 if (gcp != NULL && str != NULL && max > 0) {
2040 MemSet (str, 0, max);
2041 if (gcp->geneListIdx != NULL && row > 0) {
2042 source = gcp->geneListIdx [row - 1];
2043 CopyField (str, max, source, 1);
2044 }
2045 }
2046 }
2047
FindGeneName(GeneChoiceDataPtr gcp,CharPtr text)2048 static Int2 FindGeneName (GeneChoiceDataPtr gcp, CharPtr text)
2049
2050 {
2051 Int2 compare;
2052 Int2 left;
2053 Int2 mid;
2054 Int2 right;
2055 Char str [256];
2056
2057 mid = 0;
2058 if (gcp != NULL && text != NULL && gcp->geneIdxNum > 0) {
2059 left = 1;
2060 right = gcp->geneIdxNum;
2061 while (left <= right) {
2062 mid = (left + right) / 2;
2063 CopyStrFromGeneList (gcp, str, sizeof (str) - 2, mid);
2064 compare = StringICmp (text, str);
2065 if (compare <= 0) {
2066 right = mid - 1;
2067 }
2068 if (compare >= 0) {
2069 left = mid + 1;
2070 }
2071 }
2072 if (left <= right + 1) {
2073 CopyStrFromGeneList (gcp, str, sizeof (str) - 2, mid);
2074 str [StringLen (text)] = '\0';
2075 compare = StringICmp (text, str);
2076 if (compare > 0) {
2077 mid++;
2078 if (mid <= gcp->geneIdxNum) {
2079 CopyStrFromGeneList (gcp, str, sizeof (str) - 2, mid);
2080 str [StringLen (text)] = '\0';
2081 compare = StringICmp (text, str);
2082 if (compare > 0) {
2083 mid = 0;
2084 }
2085 }
2086 }
2087 }
2088 }
2089 return mid;
2090 }
2091
AutoScrollGeneName(GeneChoiceDataPtr gcp,TexT t)2092 static void AutoScrollGeneName (GeneChoiceDataPtr gcp, TexT t)
2093
2094 {
2095 GeneInputDataPtr gdp;
2096 Boolean goOn;
2097 Int2 item;
2098 Int2 itm;
2099 Int4 line;
2100 Int2 num;
2101 Int2 numRows;
2102 Int2 oldItem;
2103 Int2 oldRow;
2104 Int2 row;
2105 Int4 startsAt;
2106 Char str [256];
2107 Char txt [256];
2108
2109 if (gcp != NULL && t != NULL && gcp->geneListIdx != NULL) {
2110 if (t == gcp->geneData1.geneText) {
2111 gdp = &(gcp->geneData1);
2112 } else if (t == gcp->geneData2.geneText) {
2113 gdp = &(gcp->geneData2);
2114 } else {
2115 return;
2116 }
2117 GetTitle (t, str, sizeof (str) - 2);
2118 num = 0;
2119 oldItem = gdp->selectedItem;
2120 oldRow = gdp->selectedRow;
2121 line = FindGeneName (gcp, str);
2122 if (line > 0 && line <= gcp->geneIdxNum) {
2123 item = 0;
2124 row = 0;
2125 itm = 1;
2126 goOn = TRUE;
2127 while (goOn && itm <= gcp->numItems) {
2128 GetItemParams4 (gdp->geneList, itm, &startsAt, &numRows, NULL, NULL, NULL);
2129 if (line > startsAt + numRows) {
2130 itm++;
2131 } else {
2132 item = itm;
2133 row = line - startsAt;
2134 goOn = FALSE;
2135 }
2136 }
2137 if (! RowIsVisible (gdp->geneList, item, row, NULL, NULL)) {
2138 SetOffset (gdp->geneList, 0, line - 1);
2139 }
2140 CopyStrFromGeneList (gcp, txt, sizeof (txt) - 2, line);
2141 if (StringICmp (txt, str) != 0) {
2142 gdp->selectedItem = 0;
2143 gdp->selectedRow = 0;
2144 InvalDocRows (gdp->geneList, oldItem, oldRow, oldRow);
2145 return;
2146 }
2147 if (oldItem != item || oldRow != row) {
2148 gdp->selectedItem = 0;
2149 gdp->selectedRow = 0;
2150 InvalDocRows (gdp->geneList, oldItem, oldRow, oldRow);
2151 gdp->selectedItem = item;
2152 gdp->selectedRow = row;
2153 InvalDocRows (gdp->geneList, item, row, row);
2154 }
2155 }
2156 }
2157 }
2158
GeneNameText(TexT t)2159 static void GeneNameText (TexT t)
2160
2161 {
2162 GeneChoiceDataPtr gcp;
2163
2164 gcp = (GeneChoiceDataPtr) GetObjectExtra (t);
2165 if (gcp != NULL) {
2166 AutoScrollGeneName (gcp, t);
2167 }
2168 }
2169
dup_slp_list(ValNodePtr slp_list,Int4 window_size)2170 static ValNodePtr dup_slp_list(ValNodePtr slp_list, Int4 window_size)
2171 {
2172 ValNodePtr head = NULL;
2173 SeqLocPtr slp;
2174 SeqLocPtr dup_slp;
2175 Int4 start, stop;
2176 Int4 offset;
2177 SeqIntPtr sint;
2178
2179 while(slp_list)
2180 {
2181 slp = slp_list->data.ptrvalue;
2182 if(slp->choice == SEQLOC_INT)
2183 {
2184 sint = slp->data.ptrvalue;
2185 start = MIN(sint->from, sint->to);
2186 stop = MAX(sint->from, sint->to);
2187 offset = window_size - (stop - start);
2188 if(offset > 0)
2189 {
2190 start -= offset/2;
2191 stop += offset/2;
2192 if(start < 0)
2193 start = 0;
2194 }
2195
2196 dup_slp = SeqLocIntNew(start, stop, Seq_strand_plus, sint->id);
2197 ValNodeAddPointer(&head, 0, dup_slp);
2198 }
2199 slp_list = slp_list->next;
2200 }
2201
2202 return head;
2203 }
2204
get_default_window_size(GlobalDrawPtr gdraw_p)2205 static Int4 get_default_window_size(GlobalDrawPtr gdraw_p)
2206 {
2207 GlobalBspPtr gbp;
2208 ValNodePtr curr;
2209 Int4 max_len = 0, val;
2210
2211 for(curr = gdraw_p->gbp_list; curr != NULL; curr = curr->next)
2212 {
2213 gbp = (GlobalBspPtr)(curr->data.ptrvalue);
2214 max_len = MAX(max_len, gbp->bsp->length);
2215 }
2216
2217 val = MIN(max_len, 10000);
2218 return MAX(max_len/20, val);
2219 }
2220
AcceptGeneName(ButtoN b)2221 static void AcceptGeneName (ButtoN b)
2222
2223 {
2224 BioseqViewPtr bvp;
2225 GeneChoiceDataPtr gcp;
2226 GeneDataPtr gdata;
2227 ValNodePtr old_g_list = NULL;
2228 RecT r;
2229 Char str [64];
2230 CharPtr txt;
2231 ValNodePtr vnp;
2232 WindoW w;
2233 Int4 window_size;
2234
2235 w = ParentWindow (b);
2236 Hide (w);
2237 gcp = (GeneChoiceDataPtr) GetObjectExtra (b);
2238 if (gcp != NULL && gcp->bvp != NULL) {
2239 bvp = gcp->bvp;
2240
2241 str [0] = '\0';
2242 txt = GetDocText (gcp->geneData1.geneList, gcp->geneData1.selectedItem,
2243 gcp->geneData1.selectedRow, 1);
2244 SafeSetTitle (gcp->geneData1.geneText, txt);
2245 MemFree (txt);
2246
2247 GetTitle (gcp->geneData1.geneText, str, sizeof (str));
2248 bvp->pict = DeletePicture (bvp->pict);
2249 ObjectRect (bvp->vwr, &r);
2250 InsetRect (&r, 4, 4);
2251 if (StringHasNoText (str)) {
2252 old_g_list = bvp->g_list;
2253 bvp->g_list = NULL;
2254 } else {
2255 vnp = ValNodeNew (NULL);
2256 old_g_list = bvp->g_list;
2257 if (vnp != NULL) {
2258 vnp->data.ptrvalue = StringSave (str);
2259 }
2260 bvp->g_list = vnp;
2261 if (Visible (gcp->geneData2.geneGrp)) {
2262 str [0] = '\0';
2263 txt = GetDocText (gcp->geneData2.geneList, gcp->geneData2.selectedItem, gcp->geneData2.selectedRow, 1);
2264 SafeSetTitle (gcp->geneData2.geneText, txt);
2265 MemFree (txt);
2266 GetTitle (gcp->geneData2.geneText, str, sizeof (str));
2267 if (!StringHasNoText (str)) {
2268 ValNodeCopyStr (&(bvp->g_list), 0, str);
2269 }
2270 }
2271 }
2272
2273 gdata = NULL;
2274 if (map_gene_location (bvp->gdraw_p, bvp->g_list, &gdata, NULL, FALSE)) {
2275 }
2276
2277 PopulateMap (bvp);
2278
2279 if (old_g_list != NULL) {
2280 ValNodeFreeData (old_g_list);
2281 }
2282 if (bvp->gdraw_p != NULL) {
2283 if (bvp->slp_list != NULL) {
2284 free_slp_list (bvp->slp_list);
2285 }
2286 bvp->slp_list = NULL;
2287 window_size = get_default_window_size (bvp->gdraw_p);
2288 bvp->slp_list = dup_slp_list (bvp->gdraw_p->slp_list, window_size);
2289 }
2290 }
2291 Remove (w);
2292 }
2293
HighlightGeneName(DoC d,Int2 item,Int2 row,Int2 col)2294 static Boolean HighlightGeneName (DoC d, Int2 item, Int2 row, Int2 col)
2295
2296 {
2297 GeneChoiceDataPtr gcp;
2298 GeneInputDataPtr gdp;
2299
2300 gcp = (GeneChoiceDataPtr) GetObjectExtra (d);
2301 if (gcp != NULL) {
2302 if (d == gcp->geneData1.geneList) {
2303 gdp = &(gcp->geneData1);
2304 } else if (d == gcp->geneData2.geneList) {
2305 gdp = &(gcp->geneData2);
2306 } else {
2307 return FALSE;
2308 }
2309 return (Boolean) (item == gdp->selectedItem && row == gdp->selectedRow);
2310 } else {
2311 return FALSE;
2312 }
2313 }
2314
ClickGeneName(DoC d,PoinT pt)2315 static void ClickGeneName (DoC d, PoinT pt)
2316
2317 {
2318 GeneChoiceDataPtr gcp;
2319 GeneInputDataPtr gdp;
2320 Int2 item;
2321 Int2 oldItem;
2322 Int2 oldRow;
2323 Int2 row;
2324
2325 gcp = (GeneChoiceDataPtr) GetObjectExtra (d);
2326 if (gcp != NULL) {
2327 if (d == gcp->geneData1.geneList) {
2328 gdp = &(gcp->geneData1);
2329 } else if (d == gcp->geneData2.geneList) {
2330 gdp = &(gcp->geneData2);
2331 } else {
2332 return;
2333 }
2334 MapDocPoint (d, pt, &item, &row, NULL, NULL);
2335 if (item > 0 && row > 0) {
2336 gdp->clickedItem = item;
2337 gdp->clickedRow = row;
2338 oldItem = gdp->selectedItem;
2339 oldRow = gdp->selectedRow;
2340 if (gdp->selectedItem != item || gdp->selectedRow != row) {
2341 gdp->selectedItem = 0;
2342 gdp->selectedRow = 0;
2343 InvalDocRows (d, oldItem, oldRow, oldRow);
2344 gdp->selectedItem = item;
2345 gdp->selectedRow = row;
2346 InvalDocRows (d, item, row, row);
2347 }
2348 }
2349 }
2350 }
2351
ReleaseGeneName(DoC d,PoinT pt)2352 static void ReleaseGeneName (DoC d, PoinT pt)
2353
2354 {
2355 GeneChoiceDataPtr gcp;
2356 GeneInputDataPtr gdp;
2357 Int2 item;
2358 Int2 row;
2359 CharPtr str;
2360
2361 gcp = (GeneChoiceDataPtr) GetObjectExtra (d);
2362 if (gcp != NULL) {
2363 if (d == gcp->geneData1.geneList) {
2364 gdp = &(gcp->geneData1);
2365 } else if (d == gcp->geneData2.geneList) {
2366 gdp = &(gcp->geneData2);
2367 } else {
2368 return;
2369 }
2370 MapDocPoint (d, pt, &item, &row, NULL, NULL);
2371 if (gdp->clickedItem == item && gdp->clickedRow == row && item > 0 && row > 0) {
2372 str = GetDocText (d, item, row, 1);
2373 SafeSetTitle (gdp->geneText, str);
2374 Select (gdp->geneText);
2375 MemFree (str);
2376 }
2377 }
2378 }
2379
ShowSecondGroup(GrouP g)2380 static void ShowSecondGroup (GrouP g)
2381
2382 {
2383 GeneChoiceDataPtr gcp;
2384
2385 gcp = (GeneChoiceDataPtr) GetObjectExtra (g);
2386 if (gcp != NULL) {
2387 if (GetValue (g) == 2) {
2388 SafeShow (gcp->geneData2.geneGrp);
2389 } else {
2390 SafeHide (gcp->geneData2.geneGrp);
2391 }
2392 }
2393 }
2394
CleanupGeneChoiceForm(GraphiC g,VoidPtr data)2395 static void CleanupGeneChoiceForm (GraphiC g, VoidPtr data)
2396
2397 {
2398 GeneChoiceDataPtr gcp;
2399
2400 gcp = (GeneChoiceDataPtr) data;
2401 if (gcp != NULL) {
2402 gcp->geneListIdx = MemFree (gcp->geneListIdx);
2403 }
2404 StdCleanupFormProc (g, data);
2405 }
2406
DisplayGeneChoiceWindow(CharPtr path,BioseqViewPtr bvp)2407 static void DisplayGeneChoiceWindow (CharPtr path, BioseqViewPtr bvp)
2408
2409 {
2410 ButtoN b;
2411 GrouP c;
2412 Char ch;
2413 Pointer dataptr;
2414 GrouP g;
2415 GeneChoiceDataPtr gcp;
2416 CharPtr PNTR geneIdx;
2417 ValNodePtr g_list;
2418 GrouP h;
2419 Boolean hasTwoGenesSelected;
2420 Int2 idx;
2421 Int2 item;
2422 GrouP k;
2423 Int2 numItems;
2424 Int4 numLines;
2425 Int2 numRows;
2426 PrompT p;
2427 Char str [64];
2428 CharPtr tmp;
2429 WindoW w;
2430
2431 if (bvp == NULL) return;
2432 gcp = (GeneChoiceDataPtr) MemNew (sizeof (GeneChoiceData));
2433 if (gcp == NULL) return;
2434 gcp->bvp = bvp;
2435 w = MovableModalWindow (-50, -33, -10, -10, "Gene and Product List", NULL);
2436 SetObjectExtra (w, gcp, CleanupGeneChoiceForm);
2437 k = HiddenGroup (w, 2, 0, ShowSecondGroup);
2438 SetObjectExtra (k, gcp, NULL);
2439 RadioButton (k, "Find Single Gene");
2440 RadioButton (k, "Enter Gene Range");
2441 SetValue (k, 1);
2442 h = HiddenGroup (w, -2, 0, NULL);
2443
2444 str [0] = '\0';
2445 if (bvp->g_list != NULL) {
2446 g_list = bvp->g_list;
2447 StringNCpy_0 (str, (CharPtr) g_list->data.ptrvalue, sizeof (str));
2448 }
2449 gcp->geneData1.geneGrp = HiddenGroup (h, -1, 0, NULL);
2450 g = HiddenGroup (gcp->geneData1.geneGrp, 4, 0, NULL);
2451 p = StaticPrompt (g, "First Symbol", 0, dialogTextHeight, programFont, 'l');
2452 gcp->geneData1.geneText = DialogText (g, str, 10, GeneNameText);
2453 SetObjectExtra (gcp->geneData1.geneText, gcp, NULL);
2454 gcp->geneData1.geneList = DocumentPanel (gcp->geneData1.geneGrp, 15 * stdCharWidth,
2455 10 * stdLineHeight);
2456 SetObjectExtra (gcp->geneData1.geneList, gcp, NULL);
2457 AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) gcp->geneData1.geneList, NULL);
2458 SetDocProcs (gcp->geneData1.geneList, ClickGeneName, NULL, ReleaseGeneName, NULL);
2459 SetDocShade (gcp->geneData1.geneList, NULL, NULL, HighlightGeneName, NULL);
2460 DisplayFancy (gcp->geneData1.geneList, path, &geneParFmt, NULL, systemFont, 4);
2461
2462 str [0] = '\0';
2463 if (bvp->g_list != NULL) {
2464 g_list = bvp->g_list;
2465 g_list = g_list->next;
2466 if (g_list != NULL) {
2467 StringNCpy_0 (str, (CharPtr) g_list->data.ptrvalue, sizeof (str));
2468 }
2469 }
2470 hasTwoGenesSelected = (Boolean) (str [0] == '\0');
2471 gcp->geneData2.geneGrp = HiddenGroup (h, -1, 0, NULL);
2472 g = HiddenGroup (gcp->geneData2.geneGrp, 4, 0, NULL);
2473 p = StaticPrompt (g, "Second Symbol", 0, dialogTextHeight, programFont, 'l');
2474 gcp->geneData2.geneText = DialogText (g, str, 10, GeneNameText);
2475 SetObjectExtra (gcp->geneData2.geneText, gcp, NULL);
2476 gcp->geneData2.geneList = DocumentPanel (gcp->geneData2.geneGrp, 15 * stdCharWidth,
2477 10 * stdLineHeight);
2478 SetObjectExtra (gcp->geneData2.geneList, gcp, NULL);
2479 AlignObjects (ALIGN_CENTER, (HANDLE) g, (HANDLE) gcp->geneData2.geneList, NULL);
2480 SetDocProcs (gcp->geneData2.geneList, ClickGeneName, NULL, ReleaseGeneName, NULL);
2481 SetDocShade (gcp->geneData2.geneList, NULL, NULL, HighlightGeneName, NULL);
2482 DisplayFancy (gcp->geneData2.geneList, path, &geneParFmt, NULL, systemFont, 4);
2483 if (hasTwoGenesSelected) {
2484 Hide (gcp->geneData2.geneGrp);
2485 } else {
2486 SetValue (k, 2);
2487 }
2488
2489 gcp->geneIdxNum = 0;
2490 gcp->geneListIdx = NULL;
2491 gcp->numItems = 0;
2492 c = HiddenGroup (w, 4, 0, NULL);
2493 SetGroupSpacing (c, 10, 3);
2494 b = DefaultButton (c, "Accept", AcceptGeneName);
2495 SetObjectExtra (b, gcp, NULL);
2496 PushButton (c, "Cancel", StdCancelButtonProc);
2497 AlignObjects (ALIGN_CENTER, (HANDLE) k, (HANDLE) h, (HANDLE) c, NULL);
2498 GetDocParams4 (gcp->geneData1.geneList, &numItems, &numLines);
2499 if (numItems > 0 && numLines > 0 && numLines < 32000) {
2500 gcp->numItems = numItems;
2501 geneIdx = MemNew (sizeof (CharPtr) * (size_t) (numLines + 3));
2502 gcp->geneListIdx = geneIdx;
2503 if (geneIdx != NULL) {
2504 gcp->geneIdxNum = numLines;
2505 idx = 0;
2506 for (item = 1; item <= numItems; item++) {
2507 GetItemParams4 (gcp->geneData1.geneList, item, NULL, &numRows, NULL, NULL, &dataptr);
2508 if (dataptr != NULL && numRows > 0 && idx < numLines) {
2509 tmp = (CharPtr) dataptr;
2510 ch = *tmp;
2511 geneIdx [idx] = tmp;
2512 while (ch != '\0') {
2513 if (ch == '\n') {
2514 idx++;
2515 tmp++;
2516 ch = *tmp;
2517 geneIdx [idx] = tmp;
2518 } else {
2519 tmp++;
2520 ch = *tmp;
2521 }
2522 }
2523 }
2524 }
2525 GeneNameText (gcp->geneData1.geneText);
2526 }
2527 }
2528 Show (w);
2529 Select (w);
2530 Select (gcp->geneData1.geneText);
2531 }
2532
CompareValNodeStrings(VoidPtr ptr1,VoidPtr ptr2)2533 static int LIBCALLBACK CompareValNodeStrings (VoidPtr ptr1, VoidPtr ptr2)
2534
2535 {
2536 CharPtr str1;
2537 CharPtr str2;
2538 ValNodePtr vnp1;
2539 ValNodePtr vnp2;
2540
2541 if (ptr1 != NULL && ptr2 != NULL) {
2542 vnp1 = *((ValNodePtr PNTR) ptr1);
2543 vnp2 = *((ValNodePtr PNTR) ptr2);
2544 if (vnp1 != NULL && vnp2 != NULL) {
2545 str1 = (CharPtr) vnp1->data.ptrvalue;
2546 str2 = (CharPtr) vnp2->data.ptrvalue;
2547 if (str1 != NULL && str2 != NULL) {
2548 return StringICmp (str1, str2);
2549 } else {
2550 return 0;
2551 }
2552 } else {
2553 return 0;
2554 }
2555 } else {
2556 return 0;
2557 }
2558 }
2559
2560 typedef struct getgenesdata {
2561 SeqEntryPtr nsep;
2562 BioseqPtr segbsp;
2563 Boolean dirty;
2564 MonitorPtr mon;
2565 Int2 count;
2566 } GetGenesData, PNTR GetGenesPtr;
2567
GetGenesOnParts(GatherContextPtr gcp)2568 static Boolean GetGenesOnParts (GatherContextPtr gcp)
2569
2570 {
2571 BioseqContextPtr bcp;
2572 BioseqPtr bsp;
2573 Int4 from;
2574 GetGenesPtr ggp;
2575 GatherRangePtr grp;
2576 Int2 i;
2577 SeqFeatPtr newsfp;
2578 Boolean noLeft;
2579 Boolean noRight;
2580 Boolean partial5;
2581 Boolean partial3;
2582 SeqFeatPtr prot;
2583 ProtRefPtr prp;
2584 SeqIdPtr sip;
2585 SeqFeatPtr sfp;
2586 Int4 to;
2587 SeqFeatXrefPtr xref;
2588
2589 if (gcp == NULL) return TRUE;
2590 ggp = (GetGenesPtr) gcp->userdata;
2591 if (ggp == NULL) return TRUE;
2592 switch (gcp->thistype) {
2593 case OBJ_BIOSEQ_SEG :
2594 (ggp->count)++;
2595 MonitorIntValue (ggp->mon, ggp->count);
2596 break;
2597 case OBJ_SEQFEAT :
2598 sfp = (SeqFeatPtr) gcp->thisitem;
2599 if (sfp != NULL) {
2600 if (sfp->data.choice == SEQFEAT_GENE || sfp->data.choice == SEQFEAT_CDREGION) {
2601 CheckSeqLocForPartial (sfp->location, &noLeft, &noRight);
2602 ggp->dirty = TRUE;
2603 newsfp = AsnIoMemCopy (sfp, (AsnReadFunc) SeqFeatAsnRead,
2604 (AsnWriteFunc) SeqFeatAsnWrite);
2605 if (newsfp != NULL) {
2606 newsfp->location = SeqLocFree (newsfp->location);
2607 for (grp = gcp->rdp, i = 0; grp != NULL && i < gcp->num_interval; grp++, i++) {
2608 if (grp->strand == Seq_strand_minus) {
2609 from = grp->right;
2610 to = grp->left;
2611 partial5 = grp->r_trunc;
2612 partial3 = grp->l_trunc;
2613 } else {
2614 from = grp->left;
2615 to = grp->right;
2616 partial5 = grp->l_trunc;
2617 partial3 = grp->r_trunc;
2618 }
2619 AddSeqFeatInterval (newsfp, ggp->segbsp, from, to, partial5, partial3);
2620 }
2621 FreeAllFuzz (newsfp->location);
2622 SetSeqLocPartial (newsfp->location, noLeft, noRight);
2623 newsfp->partial = (newsfp->partial || noLeft || noRight);
2624 CreateNewFeature (ggp->nsep, NULL, sfp->data.choice, newsfp);
2625 if (sfp->data.choice == SEQFEAT_CDREGION) {
2626 sip = SeqLocId (newsfp->product);
2627 if (sip != NULL) {
2628 bsp = BioseqFind (sip);
2629 if (bsp != NULL) {
2630 bcp = BioseqContextNew (bsp);
2631 prot = BioseqContextGetSeqFeat (bcp, SEQFEAT_PROT, NULL, NULL, 0);
2632 BioseqContextFree(bcp);
2633 if (prot != NULL) {
2634 prp = (ProtRefPtr) prot->data.value.ptrvalue;
2635 if (prp != NULL) {
2636 xref = SeqFeatXrefNew ();
2637 if (xref != NULL) {
2638 xref->data.choice = SEQFEAT_PROT;
2639 xref->data.value.ptrvalue = AsnIoMemCopy (prp,
2640 (AsnReadFunc) ProtRefAsnRead,
2641 (AsnWriteFunc) ProtRefAsnWrite);
2642 xref->next = newsfp->xref;
2643 newsfp->xref = xref;
2644 }
2645 }
2646 }
2647 }
2648 }
2649 newsfp->product = SeqLocFree (newsfp->product);
2650 }
2651 }
2652 }
2653 }
2654 break;
2655 default :
2656 break;
2657 }
2658 return TRUE;
2659 }
2660
FetchGenesFromParts(Uint2 entityID,SeqEntryPtr nsep,BioseqPtr segbsp)2661 static Boolean FetchGenesFromParts (Uint2 entityID, SeqEntryPtr nsep, BioseqPtr segbsp)
2662
2663 {
2664 GetGenesData ggd;
2665 GatherScope gs;
2666 Int2 num;
2667 ValNode vn;
2668
2669 if (nsep == NULL || segbsp == NULL || segbsp->repr != Seq_repr_seg) return FALSE;
2670 ggd.nsep = nsep;
2671 ggd.segbsp = segbsp;
2672 ggd.dirty = FALSE;
2673 ggd.count = 0;
2674 MemSet ((Pointer) (&gs), 0, sizeof (GatherScope));
2675 gs.seglevels = 2;
2676 gs.nointervals = FALSE;
2677 gs.get_feats_location = TRUE;
2678 MemSet ((Pointer) (gs.ignore), (int)(TRUE), (size_t) (OBJ_MAX * sizeof (Boolean)));
2679 gs.ignore[OBJ_BIOSEQ] = FALSE;
2680 gs.ignore[OBJ_BIOSEQ_SEG] = FALSE;
2681 gs.ignore[OBJ_BIOSEQ_DELTA] = FALSE;
2682 gs.ignore[OBJ_BIOSEQ_MAPFEAT] = FALSE;
2683 gs.ignore[OBJ_SEQFEAT] = FALSE;
2684 gs.ignore[OBJ_SEQANNOT] = FALSE;
2685 vn.choice = SEQLOC_WHOLE;
2686 vn.data.ptrvalue = (Pointer) segbsp->id;
2687 gs.target = &vn;
2688 num = get_seg_num ((SeqLocPtr) (segbsp->seq_ext));
2689 ggd.mon = MonitorIntNew ("Searching components", 0, (Int4) num);
2690 GatherEntity (entityID, (Pointer) &ggd, GetGenesOnParts, &gs);
2691 MonitorFree (ggd.mon);
2692 return ggd.dirty;
2693 }
2694
ShowGeneList(ButtoN b)2695 extern void ShowGeneList (ButtoN b)
2696
2697 {
2698 BioseqPtr bsp;
2699 BioseqViewPtr bvp;
2700 Uint2 entityID;
2701 FILE *fp;
2702 ValNodePtr g_list;
2703 SeqEntryPtr nsep;
2704 Char path [PATH_MAX];
2705 SeqEntryPtr sep;
2706 CharPtr str;
2707 ValNodePtr vnp;
2708 ValNodePtr vnpn;
2709
2710 bvp = (BioseqViewPtr) GetObjectExtra (b);
2711 if (bvp == NULL) return;
2712 WatchCursor ();
2713 TmpNam (path);
2714 entityID = ObjMgrGetEntityIDForPointer (bvp->bsp);
2715 sep = GetTopSeqEntryForEntityID (entityID);
2716 nsep = FindNucSeqEntry (sep);
2717 if (nsep == NULL) return;
2718 bsp = (BioseqPtr) nsep->data.ptrvalue;
2719 if (bsp == NULL) return;
2720
2721 if (bsp->repr == Seq_repr_seg && (! BioseqHasFeature (bsp))) {
2722 if (bvp->hasTargetControl) {
2723 if (FetchGenesFromParts (entityID, nsep, bsp)) {
2724 ObjMgrSetDirtyFlag (entityID, TRUE);
2725 ObjMgrSendMsg (OM_MSG_UPDATE, entityID, 0, 0);
2726 }
2727 }
2728 }
2729
2730 g_list = BuildGeneList (sep);
2731 if (g_list != NULL) {
2732 g_list = SortValNode (g_list, CompareValNodeStrings);
2733 vnp = g_list;
2734 while (vnp != NULL) {
2735 vnpn = vnp->next;
2736 if (vnpn != NULL) {
2737 if (StringICmp ((CharPtr) vnp->data.ptrvalue, (CharPtr) vnpn->data.ptrvalue) == 0) {
2738 vnp->next = vnpn->next;
2739 vnpn->next = NULL;
2740 ValNodeFreeData (vnpn);
2741 } else {
2742 vnp = vnpn;
2743 }
2744 } else {
2745 vnp = vnpn;
2746 }
2747 }
2748 fp = FileOpen (path, "w");
2749 if (fp != NULL) {
2750 vnp = g_list;
2751 while (vnp != NULL) {
2752 str = (CharPtr) vnp->data.ptrvalue;
2753 if (str != NULL && StringLen (str) < 200) {
2754 fprintf (fp, "%s\n", str);
2755 }
2756 vnp = vnp->next;
2757 }
2758 FileClose (fp);
2759 DisplayGeneChoiceWindow (path, bvp);
2760 }
2761 }
2762 ValNodeFreeData (g_list);
2763 FileRemove (path);
2764 ArrowCursor ();
2765 }
2766
ShowMap(BioseqViewPtr bvp,Boolean show)2767 static void ShowMap (BioseqViewPtr bvp, Boolean show)
2768
2769 {
2770 if (bvp == NULL) return;
2771 if (show) {
2772 SafeShow (bvp->vwr);
2773 SafeShow (bvp->styleControlGrp);
2774 SafeHide (bvp->scaleControlGrp);
2775 EnableDisableLegendItem (bvp, FALSE);
2776 SafeShow (bvp->findGeneGrp);
2777 SafeHide (bvp->clickMe);
2778 } else {
2779 SafeHide (bvp->vwr);
2780 Reset (bvp->vwr);
2781 bvp->pict = DeletePicture (bvp->pict);
2782 SafeHide (bvp->styleControlGrp);
2783 SafeHide (bvp->scaleControlGrp);
2784 EnableDisableLegendItem (bvp, FALSE);
2785 SafeHide (bvp->findGeneGrp);
2786 SafeHide (bvp->docTxtControlGrp);
2787 SafeHide (bvp->baseCtgControlGrp);
2788 SafeHide (bvp->modeControlGrp);
2789 SafeHide (bvp->extraControlGrp);
2790 SafeHide (bvp->newGphControlGrp);
2791 SafeHide (bvp->clickMe);
2792 }
2793 }
2794
ShowCompressed(BioseqViewPtr bvp,Boolean show)2795 static void ShowCompressed (BioseqViewPtr bvp, Boolean show)
2796
2797 {
2798 if (bvp == NULL) return;
2799 if (show) {
2800 SafeShow (bvp->vwr);
2801 SafeHide (bvp->styleControlGrp);
2802 SafeHide (bvp->scaleControlGrp);
2803 EnableDisableLegendItem (bvp, FALSE);
2804 SafeHide (bvp->findGeneGrp);
2805 SafeShow (bvp->clickMe);
2806 } else {
2807 SafeHide (bvp->vwr);
2808 Reset (bvp->vwr);
2809 bvp->pict = DeletePicture (bvp->pict);
2810 SafeHide (bvp->styleControlGrp);
2811 SafeHide (bvp->scaleControlGrp);
2812 EnableDisableLegendItem (bvp, FALSE);
2813 SafeHide (bvp->findGeneGrp);
2814 SafeHide (bvp->docTxtControlGrp);
2815 SafeHide (bvp->baseCtgControlGrp);
2816 SafeHide (bvp->modeControlGrp);
2817 SafeHide (bvp->extraControlGrp);
2818 SafeHide (bvp->newGphControlGrp);
2819 SafeHide (bvp->clickMe);
2820 }
2821 }
2822
ShowGraphical(BioseqViewPtr bvp,Boolean show)2823 static void ShowGraphical (BioseqViewPtr bvp, Boolean show)
2824
2825 {
2826 if (bvp == NULL) return;
2827 if (show) {
2828 SafeShow (bvp->vwr);
2829 SafeShow (bvp->styleControlGrp);
2830 SafeShow (bvp->scaleControlGrp);
2831 EnableDisableLegendItem (bvp, TRUE);
2832 SafeHide (bvp->findGeneGrp);
2833 SafeShow (bvp->clickMe);
2834 } else {
2835 SafeHide (bvp->vwr);
2836 Reset (bvp->vwr);
2837 bvp->pict = DeletePicture (bvp->pict);
2838 SafeHide (bvp->styleControlGrp);
2839 SafeHide (bvp->scaleControlGrp);
2840 EnableDisableLegendItem (bvp, FALSE);
2841 SafeHide (bvp->findGeneGrp);
2842 SafeHide (bvp->docTxtControlGrp);
2843 SafeHide (bvp->baseCtgControlGrp);
2844 SafeHide (bvp->modeControlGrp);
2845 SafeHide (bvp->extraControlGrp);
2846 SafeHide (bvp->newGphControlGrp);
2847 SafeHide (bvp->clickMe);
2848 }
2849 }
2850
ShowAlignment(BioseqViewPtr bvp,Boolean show)2851 static void ShowAlignment (BioseqViewPtr bvp, Boolean show)
2852
2853 {
2854 if (bvp == NULL) return;
2855 if (show) {
2856 SafeShow (bvp->vwr);
2857 SafeShow (bvp->styleControlGrp);
2858 SafeShow (bvp->scaleControlGrp);
2859 EnableDisableLegendItem (bvp, FALSE);
2860 SafeHide (bvp->findGeneGrp);
2861 SafeShow (bvp->clickMe);
2862 } else {
2863 SafeHide (bvp->vwr);
2864 Reset (bvp->vwr);
2865 bvp->pict = DeletePicture (bvp->pict);
2866 SafeHide (bvp->styleControlGrp);
2867 SafeHide (bvp->scaleControlGrp);
2868 EnableDisableLegendItem (bvp, FALSE);
2869 SafeHide (bvp->findGeneGrp);
2870 SafeHide (bvp->docTxtControlGrp);
2871 SafeHide (bvp->baseCtgControlGrp);
2872 SafeHide (bvp->modeControlGrp);
2873 SafeHide (bvp->extraControlGrp);
2874 SafeHide (bvp->newGphControlGrp);
2875 SafeHide (bvp->clickMe);
2876 }
2877 }
2878
ShowSalsa(BioseqViewPtr bvp,Boolean show)2879 static void ShowSalsa (BioseqViewPtr bvp, Boolean show)
2880
2881 {
2882 if (bvp == NULL) return;
2883 if (show) {
2884 SafeShow (bvp->pnl);
2885 SafeShow (bvp->pnlParentGrp);
2886 SafeShow (bvp->styleControlGrp);
2887 SafeHide (bvp->scaleControlGrp);
2888 EnableDisableLegendItem (bvp, FALSE);
2889 SafeHide (bvp->findGeneGrp);
2890 SafeShow (bvp->clickMe);
2891 } else {
2892 SafeHide (bvp->pnlParentGrp);
2893 SafeHide (bvp->pnl);
2894 Reset (bvp->pnl);
2895 SafeHide (bvp->styleControlGrp);
2896 SafeHide (bvp->scaleControlGrp);
2897 EnableDisableLegendItem (bvp, FALSE);
2898 SafeHide (bvp->findGeneGrp);
2899 SafeHide (bvp->docTxtControlGrp);
2900 SafeHide (bvp->baseCtgControlGrp);
2901 SafeHide (bvp->modeControlGrp);
2902 SafeHide (bvp->extraControlGrp);
2903 SafeHide (bvp->newGphControlGrp);
2904 SafeHide (bvp->clickMe);
2905 }
2906 }
2907
ShowDesktop(BioseqViewPtr bvp,Boolean show)2908 static void ShowDesktop (BioseqViewPtr bvp, Boolean show)
2909
2910 {
2911 if (bvp == NULL) return;
2912 if (show) {
2913 SafeShow (bvp->vwr);
2914 SafeHide (bvp->styleControlGrp);
2915 SafeHide (bvp->scaleControlGrp);
2916 EnableDisableLegendItem (bvp, FALSE);
2917 SafeHide (bvp->findGeneGrp);
2918 SafeShow (bvp->clickMe);
2919 } else {
2920 SafeHide (bvp->vwr);
2921 Reset (bvp->vwr);
2922 bvp->pict = DeletePicture (bvp->pict);
2923 SafeHide (bvp->styleControlGrp);
2924 SafeHide (bvp->scaleControlGrp);
2925 EnableDisableLegendItem (bvp, FALSE);
2926 SafeHide (bvp->findGeneGrp);
2927 SafeHide (bvp->docTxtControlGrp);
2928 SafeHide (bvp->baseCtgControlGrp);
2929 SafeHide (bvp->modeControlGrp);
2930 SafeHide (bvp->extraControlGrp);
2931 SafeHide (bvp->newGphControlGrp);
2932 SafeHide (bvp->clickMe);
2933 }
2934 }
2935
2936 typedef struct selectdata {
2937 VieweR vwr;
2938 SelStructPtr sel;
2939 Uint2 entityID;
2940 Uint4 itemID;
2941 Uint2 itemtype;
2942 SeqLocPtr region;
2943 } SelectData, PNTR SelectPtr;
2944
SelectPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)2945 static Boolean SelectPrim (SegmenT seg, PrimitivE prim, Uint2 segID,
2946 Uint2 primID, Uint2 primCt, VoidPtr userdata)
2947
2948 {
2949 Uint2 entityID;
2950 Uint4 itemID;
2951 Uint2 itemtype;
2952 Int2 parID;
2953 SelectPtr sp;
2954
2955 sp = (SelectPtr) userdata;
2956 parID = SegmentID (ParentSegment (seg));
2957 entityID = segID;
2958 itemID = primID;
2959 itemtype = (Uint2) parID;
2960 if (entityID == sp->entityID &&
2961 itemID == sp->itemID &&
2962 itemtype == sp->itemtype) {
2963 HighlightPrimitive (sp->vwr, seg, prim, FRAME_PRIMITIVE);
2964 }
2965 return TRUE;
2966 }
2967
DeselectPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)2968 static Boolean DeselectPrim (SegmenT seg, PrimitivE prim, Uint2 segID,
2969 Uint2 primID, Uint2 primCt, VoidPtr userdata)
2970
2971 {
2972 Uint2 entityID;
2973 Uint4 itemID;
2974 Uint2 itemtype;
2975 Int2 parID;
2976 SelectPtr sp;
2977
2978 sp = (SelectPtr) userdata;
2979 parID = SegmentID (ParentSegment (seg));
2980 entityID = segID;
2981 itemID = primID;
2982 itemtype = (Uint2) parID;
2983 if (entityID == sp->entityID &&
2984 itemID == sp->itemID &&
2985 itemtype == sp->itemtype) {
2986 HighlightPrimitive (sp->vwr, seg, prim, PLAIN_PRIMITIVE);
2987 }
2988 return TRUE;
2989 }
2990
SelectGraphical(BioseqViewPtr bvp,Uint2 selentityID,Uint4 selitemID,Uint2 selitemtype,SeqLocPtr region,Boolean select,Boolean scrollto)2991 static void SelectGraphical (BioseqViewPtr bvp, Uint2 selentityID, Uint4 selitemID,
2992 Uint2 selitemtype, SeqLocPtr region,
2993 Boolean select, Boolean scrollto)
2994
2995 {
2996 SelectData sd;
2997
2998 if (bvp == NULL) return;
2999 if (! bvp->highlightSelections) return;
3000 /* if (bvp->viewWholeEntity) return; */
3001 sd.vwr = bvp->vwr;
3002 sd.sel = ObjMgrGetSelected ();
3003 sd.entityID = selentityID;
3004 sd.itemID = selitemID;
3005 sd.itemtype = selitemtype;
3006 sd.region = region;
3007 if (select) {
3008 ExploreSegment (bvp->pict, (Pointer) &sd, SelectPrim);
3009 } else {
3010 ExploreSegment (bvp->pict, (Pointer) &sd, DeselectPrim);
3011 }
3012 }
3013
InitSelectPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3014 static Boolean InitSelectPrim (SegmenT seg, PrimitivE prim, Uint2 segID,
3015 Uint2 primID, Uint2 primCt, VoidPtr userdata)
3016
3017 {
3018 Uint2 entityID;
3019 Uint4 itemID;
3020 Uint2 itemtype;
3021 Int2 parID;
3022 SelStructPtr sel;
3023 SelectPtr sp;
3024
3025 sp = (SelectPtr) userdata;
3026 parID = SegmentID (ParentSegment (seg));
3027 entityID = segID;
3028 itemID = primID;
3029 itemtype = (Uint2) parID;
3030 for (sel = sp->sel; sel != NULL; sel = sel->next) {
3031 if (entityID == sel->entityID &&
3032 itemID == sel->itemID &&
3033 itemtype == sel->itemtype) {
3034 HighlightPrimitive (sp->vwr, seg, prim, FRAME_PRIMITIVE);
3035 }
3036 }
3037 return TRUE;
3038 }
3039
InitSelectGraphical(BioseqViewPtr bvp)3040 static void InitSelectGraphical (BioseqViewPtr bvp)
3041
3042 {
3043 SelectData sd;
3044
3045 if (bvp == NULL) return;
3046 if (! bvp->highlightSelections) return;
3047 /* if (bvp->viewWholeEntity) return; */
3048 sd.vwr = bvp->vwr;
3049 sd.sel = ObjMgrGetSelected ();
3050 sd.entityID = 0;
3051 sd.itemID = 0;
3052 sd.itemtype = 0;
3053 sd.region = NULL;
3054 ExploreSegment (bvp->pict, (Pointer) &sd, InitSelectPrim);
3055 }
3056
SelectSalsa(BioseqViewPtr bvp,Uint2 selentityID,Uint4 selitemID,Uint2 selitemtype,SeqLocPtr region,Boolean select,Boolean scrollto)3057 static void SelectSalsa (BioseqViewPtr bvp, Uint2 selentityID, Uint4 selitemID,
3058 Uint2 selitemtype, SeqLocPtr region,
3059 Boolean select, Boolean scrollto)
3060
3061 {
3062 }
3063
VSMSelectProc(SegmenT seg,PrimitivE prim,Uint2 segid,Uint2 primID,Uint2 primct,Pointer data)3064 static Boolean VSMSelectProc (SegmenT seg, PrimitivE prim, Uint2 segid, Uint2 primID, Uint2 primct, Pointer data)
3065
3066 {
3067 Uint4 itemID;
3068 Uint2 itemtype;
3069 SelectPtr sp;
3070
3071 sp = (SelectPtr) data;
3072 itemID = primID;
3073 itemtype = segid;
3074 if (itemID == sp->itemID &&
3075 itemtype == sp->itemtype) {
3076 HighlightSegment (sp->vwr, seg, OUTLINE_SEGMENT);
3077 }
3078 return TRUE;
3079 }
3080
VSMDeselectProc(SegmenT seg,PrimitivE prim,Uint2 segid,Uint2 primID,Uint2 primct,Pointer data)3081 static Boolean VSMDeselectProc (SegmenT seg, PrimitivE prim, Uint2 segid, Uint2 primID, Uint2 primct, Pointer data)
3082
3083 {
3084 Uint4 itemID;
3085 Uint2 itemtype;
3086 SelectPtr sp;
3087
3088 sp = (SelectPtr) data;
3089 itemID = primID;
3090 itemtype = segid;
3091 if (itemID == sp->itemID &&
3092 itemtype == sp->itemtype) {
3093 HighlightSegment (sp->vwr, seg, PLAIN_SEGMENT);
3094 }
3095 return TRUE;
3096 }
3097
SelectDesktop(BioseqViewPtr bvp,Uint2 selentityID,Uint4 selitemID,Uint2 selitemtype,SeqLocPtr region,Boolean select,Boolean scrollto)3098 static void SelectDesktop (BioseqViewPtr bvp, Uint2 selentityID, Uint4 selitemID,
3099 Uint2 selitemtype, SeqLocPtr region,
3100 Boolean select, Boolean scrollto)
3101
3102 {
3103 SelectData sd;
3104
3105 if (bvp == NULL) return;
3106 if (! bvp->highlightSelections) return;
3107 /* if (bvp->viewWholeEntity) return; */
3108 sd.vwr = bvp->vwr;
3109 sd.sel = ObjMgrGetSelected ();
3110 sd.entityID = selentityID;
3111 sd.itemID = selitemID;
3112 sd.itemtype = selitemtype;
3113 sd.region = region;
3114 if (select) {
3115 ExploreSegment (bvp->pict, (Pointer) &sd, VSMSelectProc);
3116 } else {
3117 ExploreSegment (bvp->pict, (Pointer) &sd, VSMDeselectProc);
3118 }
3119 }
3120
VSMInitSelectProc(SegmenT seg,PrimitivE prim,Uint2 segid,Uint2 primID,Uint2 primct,Pointer data)3121 static Boolean VSMInitSelectProc (SegmenT seg, PrimitivE prim, Uint2 segid, Uint2 primID, Uint2 primct, Pointer data)
3122
3123 {
3124 Uint4 itemID;
3125 Uint2 itemtype;
3126 SelStructPtr sel;
3127 SelectPtr sp;
3128
3129 sp = (SelectPtr) data;
3130 itemID = primID;
3131 itemtype = segid;
3132 for (sel = sp->sel; sel != NULL; sel = sel->next) {
3133 if (itemID == sel->itemID &&
3134 itemtype == sel->itemtype) {
3135 HighlightSegment (sp->vwr, seg, OUTLINE_SEGMENT);
3136 }
3137 }
3138 return TRUE;
3139 }
3140
InitSelectDesktop(BioseqViewPtr bvp)3141 static void InitSelectDesktop (BioseqViewPtr bvp)
3142
3143 {
3144 SelectData sd;
3145
3146 if (bvp == NULL) return;
3147 if (! bvp->highlightSelections) return;
3148 /* if (bvp->viewWholeEntity) return; */
3149 sd.vwr = bvp->vwr;
3150 sd.sel = ObjMgrGetSelected ();
3151 sd.entityID = 0;
3152 sd.itemID = 0;
3153 sd.itemtype = 0;
3154 sd.region = NULL;
3155 ExploreSegment (bvp->pict, (Pointer) &sd, VSMInitSelectProc);
3156 }
3157
SelectRegion(VieweR viewer,SegmenT segment,PrimitivE primitive,SeqLocPtr region,Uint2 entityID)3158 static void SelectRegion (VieweR viewer, SegmenT segment, PrimitivE primitive,
3159 SeqLocPtr region, Uint2 entityID)
3160
3161 {
3162 BioseqPtr bsp;
3163 RecT d;
3164 ViewPData extra;
3165 RecT r;
3166 RecT s;
3167 SegPPtr seg;
3168 WindoW tempPort;
3169 BoxInfo pLimits;
3170
3171 if (viewer == NULL || segment == NULL || primitive == NULL || region == NULL) return;
3172 seg = (SegPPtr) segment;
3173 if (seg->base.code != SEGMENT && seg->base.code != PICTURE) return;
3174 if (! seg->seg.visible) return;
3175 if (Visible (viewer) && AllParentsVisible (viewer)) {
3176 GetPanelExtra ((PaneL) viewer, &extra);
3177 TryGetPrimitiveLimits ((BasePPtr) primitive, extra.scale.scaleX,
3178 extra.scale.scaleY, &pLimits);
3179 bsp = GetBioseqGivenSeqLoc (region, entityID);
3180 if (bsp == NULL) return;
3181 if (ABS (pLimits.left - pLimits.right) < bsp->length) return;
3182 pLimits.left = SeqLocStart (region);
3183 pLimits.right = SeqLocStop (region);
3184 if (! BoxInViewport (&r, &(pLimits), &(extra.scale))) return;
3185 InsetRect (&r, 0, -3);
3186 if (ABS (r.left - r.right) < 2) {
3187 InsetRect (&r, -1, 0);
3188 }
3189 ObjectRect (viewer, &s);
3190 InsetRect (&s, 2, 2);
3191 SectRect (&r, &s, &d);
3192 tempPort = SavePort (viewer);
3193 Select (viewer);
3194 Dotted ();
3195 FrameRect (&d);
3196 Solid ();
3197 RestorePort (tempPort);
3198 }
3199 }
3200
DrawSelectionPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3201 static Boolean DrawSelectionPrim (SegmenT seg, PrimitivE prim, Uint2 segID,
3202 Uint2 primID, Uint2 primCt, VoidPtr userdata)
3203
3204 {
3205 Uint2 entityID;
3206 Uint4 itemID;
3207 Uint2 itemtype;
3208 Int2 parID;
3209 SelStructPtr sel;
3210 SelectPtr sp;
3211
3212 parID = SegmentID (ParentSegment (seg));
3213 itemtype = (Uint2) parID;
3214 if (itemtype != OBJ_BIOSEQ) return TRUE;
3215 sp = (SelectPtr) userdata;
3216 entityID = segID;
3217 itemID = primID;
3218 for (sel = sp->sel; sel != NULL; sel = sel->next) {
3219 if (entityID == sel->entityID &&
3220 itemID == sel->itemID &&
3221 itemtype == sel->itemtype &&
3222 sel->region != NULL) {
3223 SelectRegion (sp->vwr, seg, prim, sel->region, entityID);
3224 }
3225 }
3226 return TRUE;
3227 }
3228
DrawSelectionRange(VieweR viewer,SegmenT segment)3229 static void DrawSelectionRange (VieweR viewer, SegmenT segment)
3230
3231 {
3232 Boolean okay;
3233 SelectData sd;
3234 SelStructPtr sel;
3235
3236 sd.vwr = viewer;
3237 sd.sel = ObjMgrGetSelected ();
3238 sd.entityID = 0;
3239 sd.itemID = 0;
3240 sd.itemtype = 0;
3241 sd.region = NULL;
3242 okay = FALSE;
3243 for (sel = sd.sel; sel != NULL; sel = sel->next) {
3244 if (sel->itemtype == OBJ_BIOSEQ && sel->region != NULL) {
3245 okay = TRUE;
3246 }
3247 }
3248 if (okay) {
3249 ExploreSegment (segment, (Pointer) &sd, DrawSelectionPrim);
3250 }
3251 }
3252
3253
CopyGraphicalToClipboard(BioseqViewPtr bvp)3254 static void CopyGraphicalToClipboard (BioseqViewPtr bvp)
3255
3256 {
3257 if (bvp == NULL || bvp->vwr == NULL) return;
3258 CopyViewer (bvp->vwr);
3259 }
3260
3261 #ifdef WIN_MOTIF
3262 extern CharPtr Nlm_XrmGetResource (const Char PNTR _resource);
3263 #endif
3264
PrintGraphical(BioseqViewPtr bvp)3265 static void PrintGraphical (BioseqViewPtr bvp)
3266
3267 {
3268 MsgAnswer ans;
3269
3270 if (bvp == NULL || bvp->vwr == NULL) return;
3271 #ifdef WIN_MOTIF
3272 Message (MSG_OK, "Printing of graphics under MOTIF is not supported at this time.");
3273 #else
3274 ans = Message (MSG_YN, "Do you want to print just the visible area?");
3275 if (ans == ANS_YES) {
3276 PrintViewer (bvp->vwr);
3277 } else {
3278 PrintAllViewer (bvp->vwr);
3279 }
3280 #endif
3281 }
3282
3283 typedef struct expboundstruc {
3284 FILE *file;
3285 ViewPData extra;
3286 RecT vwrct;
3287 } ExpBound, PNTR ExpBoundPtr;
3288
ExpBoundCallback(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3289 static Boolean ExpBoundCallback (SegmenT seg, PrimitivE prim, Uint2 segID,
3290 Uint2 primID, Uint2 primCt, VoidPtr userdata)
3291
3292 {
3293 ExpBoundPtr ebp;
3294 Uint2 entityID;
3295 Uint4 itemID;
3296 Uint2 itemType;
3297 BoxInfo pLimits;
3298 SegmenT pseg;
3299 RecT r;
3300
3301 if (seg == NULL || prim == NULL || segID == 0 ||
3302 primID == 0 || userdata == NULL) return TRUE;
3303 ebp = (ExpBoundPtr) userdata;
3304 pseg = ParentSegment (seg);
3305 if (pseg == NULL) return TRUE;
3306 entityID = segID;
3307 itemID = primID;
3308 itemType = SegmentID (pseg);
3309 if (itemType == 0) return TRUE;
3310 if (TryGetPrimitiveLimits ((BasePPtr) prim, ebp->extra.scale.scaleX,
3311 ebp->extra.scale.scaleY, &pLimits)) {
3312 if (BoxInViewport (&r, &(pLimits), &(ebp->extra.scale))) {
3313 OffsetRect (&r, -ebp->vwrct.left, -ebp->vwrct.top);
3314 if (ebp->file != NULL) {
3315 fprintf (ebp->file, "%d %d %d %d %d %d %d\n", (int) entityID,
3316 (int) itemID, (int) itemType,
3317 (int) r.left, (int) r.top,
3318 (int) r.right, (int) r.bottom);
3319 }
3320 }
3321 }
3322 return TRUE;
3323 }
3324
ExploreToGetBoundaries(VieweR vwr,SegmenT seg,CharPtr filename)3325 static void ExploreToGetBoundaries (VieweR vwr, SegmenT seg, CharPtr filename)
3326
3327 {
3328 ExpBound exp;
3329
3330 if (vwr == NULL || seg == NULL ||
3331 filename == NULL || *filename == '\0') return;
3332 GetPanelExtra ((PaneL) vwr, &(exp.extra));
3333 ObjectRect (vwr, &(exp.vwrct));
3334 InsetRect (&(exp.vwrct), 4, 4);
3335 exp.file = FileOpen (filename, "w");
3336 if (exp.file != NULL) {
3337 ExploreSegment (seg, &exp, ExpBoundCallback);
3338 }
3339 FileClose (exp.file);
3340 }
3341
GifGraphical(BioseqViewPtr bvp,CharPtr filename,CharPtr dfault)3342 static void GifGraphical (BioseqViewPtr bvp, CharPtr filename, CharPtr dfault)
3343
3344 {
3345 if (bvp == NULL || bvp->vwr == NULL) return;
3346 ExploreToGetBoundaries (bvp->vwr, bvp->pict, filename);
3347 }
3348
ExportSalsa(BioseqViewPtr bvp,CharPtr filename,CharPtr dfault)3349 static void ExportSalsa (BioseqViewPtr bvp, CharPtr filename, CharPtr dfault)
3350
3351 {
3352 SaveSalsaPanel (bvp->pnl);
3353 }
3354
3355 #define MIN_HEIGHT 100
3356
ResizeMap(BioseqViewPtr bvp)3357 static void ResizeMap (BioseqViewPtr bvp)
3358
3359 {
3360 Int2 height;
3361 Int2 oldstyle;
3362 RecT r;
3363 Int2 style;
3364
3365 if (bvp == NULL) return;
3366 if (bvp->vwr != NULL) {
3367 if (Visible (bvp->vwr) && AllParentsVisible (bvp->vwr)) {
3368 ObjectRect (ParentWindow (bvp->vwr), &r);
3369 height = r.bottom - r.top;
3370 if (height >= MIN_HEIGHT) {
3371 WatchCursor ();
3372 oldstyle = GetMuskCurrentSt ();
3373 style = GetValue (bvp->style) - 1;
3374 SetMuskCurrentSt (GetMuskStyleName (style));
3375 ObjectRect (bvp->vwr, &r);
3376 InsetRect (&r, 4, 4);
3377 bvp->pict = DeletePicture (bvp->pict);
3378 bvp->pict = GlobalPictureUpdate (bvp->gdraw_p, bvp->g_list,
3379 r.right - r.left, r.bottom - r.top);
3380 if (bvp->gdraw_p->is_circle) {
3381 AttachPicture (bvp->vwr, bvp->pict, 0, 0, UPPER_LEFT, 1, 1, NULL);
3382 } else {
3383 AttachPicture (bvp->vwr, bvp->pict, INT4_MIN, 0, UPPER_LEFT, 1, 1, NULL);
3384 }
3385 SetViewerProcs (bvp->vwr, ClickMap, DragMap, ReleaseMap, NULL);
3386 SetMuskCurrentSt (GetMuskStyleName (oldstyle));
3387 ArrowCursor ();
3388 }
3389 }
3390 }
3391 }
3392
ResizeCompressed(BioseqViewPtr bvp)3393 static void ResizeCompressed (BioseqViewPtr bvp)
3394
3395 {
3396 BioseqPtr bsp;
3397 ErrSev oldErrSev;
3398
3399 if (bvp == NULL) return;
3400 if (bvp->vwr != NULL) {
3401 if (Visible (bvp->vwr) && AllParentsVisible (bvp->vwr)) {
3402 Reset (bvp->vwr);
3403 bvp->pict = DeletePicture (bvp->pict);
3404 bsp = bvp->bsp;
3405 oldErrSev = ErrSetMessageLevel (SEV_FATAL);
3406 BioseqLock (bsp);
3407 PopulateCompressed (bvp);
3408 BioseqUnlock (bsp);
3409 ErrSetMessageLevel (oldErrSev);
3410 }
3411 }
3412 }
3413
ResizeGraphical(BioseqViewPtr bvp)3414 static void ResizeGraphical (BioseqViewPtr bvp)
3415
3416 {
3417 if (bvp == NULL) return;
3418 if (bvp->vwr != NULL) {
3419 if (Visible (bvp->vwr) && AllParentsVisible (bvp->vwr)) {
3420 ViewerWasResized (bvp->vwr);
3421 }
3422 }
3423 }
3424
ResizeSalsa(BioseqViewPtr bvp)3425 static void ResizeSalsa (BioseqViewPtr bvp)
3426
3427 {
3428 if (bvp == NULL) return;
3429 if (bvp->pnl != NULL) {
3430 if (Visible (bvp->pnl) && AllParentsVisible (bvp->pnl)) {
3431 SalsaPanelHasResized (bvp->pnl);
3432 }
3433 }
3434 }
3435
ResizeDesktop(BioseqViewPtr bvp)3436 static void ResizeDesktop (BioseqViewPtr bvp)
3437
3438 {
3439 if (bvp == NULL) return;
3440 if (bvp->vwr != NULL) {
3441 if (Visible (bvp->vwr) && AllParentsVisible (bvp->vwr)) {
3442 ViewerWasResized (bvp->vwr);
3443 }
3444 }
3445 }
3446
3447 BioseqPageData mapPageData = {
3448 "Map", FALSE, FALSE, TRUE, FALSE, -1,
3449 PopulateMap, ShowMap, SelectGraphical,
3450 CopyGraphicalToClipboard, PrintGraphical,
3451 NULL, NULL, ResizeMap, NULL
3452 };
3453
3454 BioseqPageData sumPageData = {
3455 "Summary", TRUE, FALSE, FALSE, FALSE, -1,
3456 PopulateCompressed, ShowCompressed, SelectGraphical,
3457 CopyGraphicalToClipboard, PrintGraphical,
3458 NULL, NULL, ResizeCompressed, NULL
3459 };
3460
3461 BioseqPageData gphPageData = {
3462 "OldGraphic", TRUE, TRUE, TRUE, FALSE, -1,
3463 PopulateGraphic, ShowGraphical, SelectGraphical,
3464 CopyGraphicalToClipboard, PrintGraphical,
3465 NULL, GifGraphical, ResizeGraphical, NULL
3466 };
3467
3468 BioseqPageData alnPageData = {
3469 "OldAlignment", TRUE, TRUE, TRUE, TRUE, -1,
3470 PopulateAlignment, ShowAlignment, SelectGraphical,
3471 CopyGraphicalToClipboard, PrintGraphical,
3472 NULL, NULL, ResizeGraphical, NULL
3473 };
3474
3475 BioseqPageData seqPageData = {
3476 "OldSequence", TRUE, TRUE, FALSE, FALSE, -1,
3477 PopulateSalsa, ShowSalsa, SelectSalsa,
3478 NULL, NULL,
3479 ExportSalsa, NULL, ResizeSalsa, NULL
3480 };
3481
3482 BioseqPageData dskPageData = {
3483 "Desktop", TRUE, TRUE, TRUE, FALSE, -1,
3484 PopulateDesktop, ShowDesktop, SelectDesktop,
3485 CopyGraphicalToClipboard, PrintGraphical,
3486 NULL, NULL, ResizeDesktop, NULL
3487 };
3488
3489 /* new graphical viewer - sequin integration */
3490
3491 #include <asn2graphicp.h>
3492
Asn2GphSelectRegion(VieweR viewer,SegmenT segment,PrimitivE primitive,SeqLocPtr region,Uint2 entityID)3493 static void Asn2GphSelectRegion (VieweR viewer, SegmenT segment, PrimitivE primitive,
3494 SeqLocPtr region, Uint2 entityID)
3495
3496 {
3497 BioseqPtr bsp;
3498 RecT d;
3499 ViewPData extra;
3500 RecT r;
3501 RecT s;
3502 SegPPtr seg;
3503 WindoW tempPort;
3504 BoxInfo pLimits;
3505
3506 if (viewer == NULL || segment == NULL || primitive == NULL || region == NULL) return;
3507 seg = (SegPPtr) segment;
3508 if (seg->base.code != SEGMENT && seg->base.code != PICTURE) return;
3509 if (! seg->seg.visible) return;
3510 if (Visible (viewer) && AllParentsVisible (viewer)) {
3511 GetPanelExtra ((PaneL) viewer, &extra);
3512 TryGetPrimitiveLimits ((BasePPtr) primitive, extra.scale.scaleX,
3513 extra.scale.scaleY, &pLimits);
3514 bsp = GetBioseqGivenSeqLoc (region, entityID);
3515 if (bsp == NULL) return;
3516 if (ABS (pLimits.left - pLimits.right) < bsp->length) return;
3517 pLimits.left = SeqLocStart (region);
3518 pLimits.right = SeqLocStop (region);
3519 if (! BoxInViewport (&r, &(pLimits), &(extra.scale))) return;
3520 InsetRect (&r, 0, -3);
3521 if (ABS (r.left - r.right) < 2) {
3522 InsetRect (&r, -1, 0);
3523 }
3524 ObjectRect (viewer, &s);
3525 InsetRect (&s, 2, 2);
3526 SectRect (&r, &s, &d);
3527 tempPort = SavePort (viewer);
3528 Select (viewer);
3529 Dotted ();
3530 FrameRect (&d);
3531 Solid ();
3532 RestorePort (tempPort);
3533 }
3534 }
3535
Asn2GphDrawSelectionPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3536 static Boolean Asn2GphDrawSelectionPrim (SegmenT seg, PrimitivE prim, Uint2 segID,
3537 Uint2 primID, Uint2 primCt, VoidPtr userdata)
3538
3539 {
3540 Uint2 entityID;
3541 Uint4 itemID;
3542 Uint2 itemtype;
3543 SelStructPtr sel;
3544 SelectPtr sp;
3545
3546 sp = (SelectPtr) userdata;
3547 GetPrimitiveIDs (prim, &entityID, &itemID, &itemtype, NULL);
3548 for (sel = sp->sel; sel != NULL; sel = sel->next) {
3549 if (entityID == sel->entityID &&
3550 itemID == sel->itemID &&
3551 itemtype == sel->itemtype &&
3552 sel->region != NULL) {
3553 Asn2GphSelectRegion (sp->vwr, seg, prim, sel->region, entityID);
3554 }
3555 }
3556 return TRUE;
3557 }
3558
Asn2GphDrawSelectionRange(VieweR viewer,SegmenT segment)3559 static void Asn2GphDrawSelectionRange (VieweR viewer, SegmenT segment)
3560
3561 {
3562 Boolean okay;
3563 SelectData sd;
3564 SelStructPtr sel;
3565
3566 sd.vwr = viewer;
3567 sd.sel = ObjMgrGetSelected ();
3568 sd.entityID = 0;
3569 sd.itemID = 0;
3570 sd.itemtype = 0;
3571 sd.region = NULL;
3572 okay = FALSE;
3573 for (sel = sd.sel; sel != NULL; sel = sel->next) {
3574 if (sel->itemtype == OBJ_BIOSEQ && sel->region != NULL) {
3575 okay = TRUE;
3576 }
3577 }
3578 if (okay) {
3579 ExploreSegment (segment, (Pointer) &sd, Asn2GphDrawSelectionPrim);
3580 }
3581 }
3582
CopyAsn2GphGraphicToClipboard(BioseqViewPtr bvp)3583 static void CopyAsn2GphGraphicToClipboard (BioseqViewPtr bvp)
3584 {
3585 if (bvp == NULL || bvp->vwr == NULL) return;
3586 CopyViewer (bvp->vwr);
3587 }
3588
PrintAsn2GphGraphic(BioseqViewPtr bvp)3589 static void PrintAsn2GphGraphic (BioseqViewPtr bvp)
3590
3591 {
3592 #ifdef WIN_MOTIF
3593 if (bvp == NULL || bvp->vwr == NULL) return;
3594 Message (MSG_OK, "Printing of graphics under MOTIF is not supported at this time.");
3595 #else
3596 MsgAnswer ans;
3597 if (bvp == NULL || bvp->vwr == NULL) return;
3598 ans = Message (MSG_YN, "Do you want to print just the visible area?");
3599 if (ans == ANS_YES) {
3600 PrintViewer (bvp->vwr);
3601 } else {
3602 PrintAllViewer (bvp->vwr);
3603 }
3604 #endif
3605 }
3606
SelectAsn2GphPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3607 static Boolean SelectAsn2GphPrim (
3608 SegmenT seg,
3609 PrimitivE prim,
3610 Uint2 segID,
3611 Uint2 primID,
3612 Uint2 primCt,
3613 VoidPtr userdata
3614 )
3615
3616 {
3617 Uint2 entityID;
3618 Uint4 itemID;
3619 Uint2 itemtype;
3620 SelectPtr sp;
3621
3622 sp = (SelectPtr) userdata;
3623 GetPrimitiveIDs (prim, &entityID, &itemID, &itemtype, NULL);
3624 if (entityID == sp->entityID &&
3625 itemID == sp->itemID &&
3626 itemtype == sp->itemtype) {
3627 HighlightPrimitive (sp->vwr, seg, prim, FRAME_PRIMITIVE);
3628 /*
3629 HighlightSegment (sp->vwr, seg, FRAME_SEGMENT);
3630 */
3631 }
3632 return TRUE;
3633 }
3634
DeselectAsn2GphPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3635 static Boolean DeselectAsn2GphPrim (
3636 SegmenT seg,
3637 PrimitivE prim,
3638 Uint2 segID,
3639 Uint2 primID,
3640 Uint2 primCt,
3641 VoidPtr userdata
3642 )
3643
3644 {
3645 Uint2 entityID;
3646 Uint4 itemID;
3647 Uint2 itemtype;
3648 SelectPtr sp;
3649
3650 sp = (SelectPtr) userdata;
3651 GetPrimitiveIDs (prim, &entityID, &itemID, &itemtype, NULL);
3652 if (entityID == sp->entityID &&
3653 itemID == sp->itemID &&
3654 itemtype == sp->itemtype) {
3655 HighlightPrimitive (sp->vwr, seg, prim, PLAIN_PRIMITIVE);
3656 /*
3657 HighlightSegment (sp->vwr, seg, PLAIN_SEGMENT);
3658 */
3659 }
3660 return TRUE;
3661 }
3662
SelectAsn2GphView(BioseqViewPtr bvp,Uint2 selentityID,Uint4 selitemID,Uint2 selitemtype,SeqLocPtr region,Boolean select,Boolean scrollto)3663 static void SelectAsn2GphView (
3664 BioseqViewPtr bvp,
3665 Uint2 selentityID,
3666 Uint4 selitemID,
3667 Uint2 selitemtype,
3668 SeqLocPtr region,
3669 Boolean select,
3670 Boolean scrollto
3671 )
3672
3673 {
3674 SelectData sd;
3675
3676 if (bvp == NULL) return;
3677 if (! bvp->highlightSelections) return;
3678 sd.vwr = bvp->vwr;
3679 sd.sel = ObjMgrGetSelected ();
3680 sd.entityID = selentityID;
3681 sd.itemID = selitemID;
3682 sd.itemtype = selitemtype;
3683 sd.region = region;
3684 if (select) {
3685 ExploreSegment (bvp->pict, (Pointer) &sd, SelectAsn2GphPrim);
3686 } else {
3687 ExploreSegment (bvp->pict, (Pointer) &sd, DeselectAsn2GphPrim);
3688 }
3689 }
3690
InitSelectAsn2GphPrim(SegmenT seg,PrimitivE prim,Uint2 segID,Uint2 primID,Uint2 primCt,VoidPtr userdata)3691 static Boolean InitSelectAsn2GphPrim (
3692 SegmenT seg,
3693 PrimitivE prim,
3694 Uint2 segID,
3695 Uint2 primID,
3696 Uint2 primCt,
3697 VoidPtr userdata
3698 )
3699
3700 {
3701 Uint2 entityID;
3702 Uint4 itemID;
3703 Uint2 itemtype;
3704 SelStructPtr sel;
3705 SelectPtr sp;
3706
3707 sp = (SelectPtr) userdata;
3708 GetPrimitiveIDs (prim, &entityID, &itemID, &itemtype, NULL);
3709 for (sel = sp->sel; sel != NULL; sel = sel->next) {
3710 if (entityID == sel->entityID &&
3711 itemID == sel->itemID &&
3712 itemtype == sel->itemtype) {
3713 HighlightPrimitive (sp->vwr, seg, prim, FRAME_PRIMITIVE);
3714 }
3715 }
3716 return TRUE;
3717 }
3718
InitSelectAsn2GphView(BioseqViewPtr bvp)3719 static void InitSelectAsn2GphView (BioseqViewPtr bvp)
3720
3721 {
3722 SelectData sd;
3723
3724 if (bvp == NULL) return;
3725 if (! bvp->highlightSelections) return;
3726 sd.vwr = bvp->vwr;
3727 sd.sel = ObjMgrGetSelected ();
3728 sd.entityID = 0;
3729 sd.itemID = 0;
3730 sd.itemtype = 0;
3731 sd.region = NULL;
3732 ExploreSegment (bvp->pict, (Pointer) &sd, InitSelectAsn2GphPrim);
3733 }
3734
ClickAsn2GphGraphic(VieweR vwr,SegmenT seg,PoinT pt)3735 static void ClickAsn2GphGraphic (
3736 VieweR vwr,
3737 SegmenT seg,
3738 PoinT pt
3739 )
3740
3741 {
3742 BioseqViewPtr bvp;
3743
3744 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
3745 if (bvp == NULL) return;
3746 bvp->wasDoubleClick = dblClick;
3747 bvp->wasShiftKey = shftKey;
3748 bvp->old_rect_shown = FALSE;
3749 if (! dblClick) {
3750 bvp->pnt_start = pt;
3751 }
3752 bvp->pnt_stop = pt;
3753 }
3754
ReleaseAsn2GphGraphic(VieweR vwr,SegmenT seg,PoinT pt)3755 static void ReleaseAsn2GphGraphic (
3756 VieweR vwr,
3757 SegmenT seg,
3758 PoinT pt
3759 )
3760
3761 {
3762 BioseqViewPtr bvp;
3763 Uint2 entityID;
3764 Uint4 itemID;
3765 Uint2 itemtype;
3766 SeqEntryPtr sep;
3767 PrimitivE thatPrim;
3768 PrimitivE thisPrim;
3769 SegmenT smallestSeg;
3770
3771 bvp = (BioseqViewPtr) GetObjectExtra (vwr);
3772 if (bvp == NULL) {
3773 ObjMgrDeSelect (0, 0, 0, 0, NULL);
3774 return;
3775 }
3776
3777 smallestSeg = FindSegPrim (vwr, pt, NULL, NULL, &thisPrim);
3778 if (smallestSeg == NULL || thisPrim == NULL) {
3779 ObjMgrDeSelect (0, 0, 0, 0, NULL);
3780 return;
3781 }
3782
3783 GetPrimitiveIDs (thisPrim, &entityID, &itemID, &itemtype, NULL);
3784
3785 if (entityID == 0 && itemID == 0 && (itemtype == OBJ_SEQFEAT || itemtype == 0)) {
3786 ObjMgrDeSelect (0, 0, 0, 0, NULL);
3787 return;
3788 }
3789 if (bvp->wasDoubleClick) {
3790
3791 seg = FindSegPrim (vwr, bvp->pnt_start, NULL, NULL, &thatPrim);
3792 if (seg == smallestSeg && thisPrim == thatPrim) {
3793
3794 sep = GetTopSeqEntryForEntityID (entityID);
3795 if (bvp->launchSubviewers) {
3796 WatchCursor ();
3797 Update ();
3798 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
3799 ArrowCursor ();
3800 Update ();
3801 return;
3802 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
3803 WatchCursor ();
3804 Update ();
3805 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
3806 ArrowCursor ();
3807 Update ();
3808 return;
3809 } else if (bvp->launchEditors) {
3810 WatchCursor ();
3811 Update ();
3812 GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, itemID,
3813 itemtype, 0, 0, itemtype, 0);
3814 ArrowCursor ();
3815 Update ();
3816 }
3817 }
3818 }
3819 if (! bvp->sendSelectMessages) return;
3820 if (bvp->wasShiftKey) {
3821 ObjMgrAlsoSelect (entityID, itemID, itemtype, 0, NULL);
3822 } else {
3823 ObjMgrSelect (entityID, itemID, itemtype, 0, NULL);
3824 }
3825 }
3826
3827
3828 typedef struct multiBioseqDrawState {
3829 Int4 ceiling;
3830 SegmenT topLevelSegment;
3831 FilterPtr FP;
3832 AppearancePtr AP;
3833 LayoutAlgorithm overrideLayout;
3834 Int4 scale;
3835 } MultiBioseqDrawState, PNTR MultiBioseqDrawStatePtr;
3836
VisitAndDrawBioseqs(BioseqPtr bsp,Pointer userdata)3837 static void VisitAndDrawBioseqs (
3838 BioseqPtr bsp,
3839 Pointer userdata
3840 )
3841
3842 {
3843 MultiBioseqDrawStatePtr state;
3844 state = userdata;
3845 if (state == NULL) return;
3846 CreateGraphicViewFromBsp (bsp, NULL, state->scale, &state->ceiling,
3847 state->topLevelSegment, state->AP,
3848 state->FP, state->overrideLayout, NULL);
3849 state->ceiling -= 25;
3850 }
3851
3852 /*
3853 #define TEST_SEQLOC_LIMIT
3854 static float START_FRACTION = 0.3;
3855 static float STOP_FRACTION = 0.6;
3856 */
3857
PopulateAsn2GphGraphic(BioseqViewPtr bvp)3858 static void PopulateAsn2GphGraphic (
3859 BioseqViewPtr bvp
3860 )
3861
3862 {
3863 BioseqPtr bsp;
3864 Uint2 entityID;
3865 Uint2 i;
3866 Int4 len;
3867 Int4 max;
3868 Int4 min;
3869
3870 SeqEntryPtr oldscope = NULL;
3871 RecT r;
3872 Int4 scaleX;
3873
3874 SeqEntryPtr sep;
3875 Char str[32];
3876 Int4 vwr_x;
3877 Int4 vwr_y;
3878 Int2 vwr_align;
3879
3880 CharPtr PNTR nameList;
3881 CharPtr appearanceName;
3882 CharPtr filterName;
3883 CharPtr layoutName;
3884 /*
3885 CharPtr alignScoreName;
3886 */
3887 CharPtr alignScoreCutoff;
3888 GraphicViewExtras gvExtras;
3889
3890 ViewerConfigsPtr myVCP;
3891
3892 MultiBioseqDrawState drawState;
3893
3894 SeqViewProcsPtr svpp;
3895
3896 if (bvp == NULL) return;
3897
3898 WatchCursor ();
3899
3900 vwr_x = INT4_MIN;
3901 vwr_y = INT4_MAX;
3902 vwr_align = UPPER_LEFT;
3903 if (bvp->moveToOldPos) {
3904 if (bvp->pict != NULL) {
3905 get_viewer_position (bvp->vwr, &(vwr_x), &(vwr_y));
3906 vwr_align = MIDDLE_CENTER;
3907 }
3908 bvp->moveToOldPos = FALSE;
3909 }
3910
3911 Reset (bvp->vwr);
3912 bvp->pict = DeletePicture (bvp->pict);
3913 Update ();
3914
3915 bsp = bvp->bsp;
3916 if (bsp == NULL) {
3917 ArrowCursor ();
3918 return;
3919 }
3920
3921 svpp = (SeqViewProcsPtr) GetAppProperty ("SeqDisplayForm");
3922 if (svpp != NULL && svpp->lockFarComponents) {
3923 entityID = ObjMgrGetEntityIDForPointer (bsp);
3924 sep = GetTopSeqEntryForEntityID (entityID);
3925 LookupFarSeqIDs (sep, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE);
3926 }
3927
3928 if (bvp->scaleNotCalculated) {
3929 SafeHide (bvp->newGphScale);
3930 Reset (bvp->newGphScale);
3931 ObjectRect (bvp->vwr, &r);
3932 InsetRect (&r, 4, 4);
3933 len = bsp->length;
3934 max = (Int4) MAX (len / (Int4) (r.right - r.left), 1) + 2;
3935 max = (Int4) MIN (max, 50000L);
3936 min = (Int4) MAX (len / 320000L, 1L);
3937 bvp->maxScale = max;
3938 i = 1;
3939 /* while (i < MAXZOOMSCALEVAL && min > zoomScaleVal[i]) {
3940 i++;
3941 }*/
3942 bvp->minIndex = i;
3943 while (i < MAXZOOMSCALEVAL && max > zoomScaleVal[i - 1]) {
3944 sprintf (str, "%ld", (long) (zoomScaleVal[i]));
3945 if (max < zoomScaleVal[i]) {
3946 sprintf (str, "%ld", (long) zoomScaleVal[i]);
3947 }
3948 PopupItem (bvp->newGphScale, str);
3949 i++;
3950 }
3951 SetValue (bvp->newGphScale, MAX (i - bvp->minIndex, 1));
3952 bvp->scaleNotCalculated = FALSE;
3953 }
3954 SafeShow (bvp->newGphScale);
3955 i = GetValue (bvp->newGphScale) - 1 + bvp->minIndex;
3956 if (i < MAXZOOMSCALEVAL && i > 0) {
3957 /* scaleX = MIN (zoomScaleVal[i], bvp->maxScale);*/
3958 scaleX = zoomScaleVal[i];
3959 } else {
3960 scaleX = bvp->minIndex;
3961 }
3962
3963 i = GetValue (bvp->newGphFilter) - 1;
3964 nameList = GetFilterNameList ();
3965 if (i < GetFilterCount ()) {
3966 filterName = nameList [i];
3967 } else {
3968 filterName = "default"; /* as good a guess as any, and it _should_ exist in the config file*/
3969 }
3970
3971 i = GetValue (bvp->newGphStyle) - 1;
3972 nameList = GetStyleNameList ();
3973 if (i < GetAppearanceCount ()) {
3974 appearanceName = nameList [i];
3975 } else {
3976 appearanceName = "default";
3977 }
3978
3979 i = GetValue (bvp->newGphLayout) - 1;
3980 nameList = GetLayoutNameList ();
3981 if (i < GetLayoutCount()) {
3982 layoutName = nameList[i];
3983 } else {
3984 layoutName = NULL; /* no need to pass a dummy string for an optional value */
3985 }
3986
3987 MemSet ((Pointer) &gvExtras, 0, sizeof (GraphicViewExtras));
3988 if (GetAppProperty("GPHVIEWSCOREALIGNS") != NULL) {
3989 /*
3990 i = GetValue (bvp->newGphAlnScore) - 1;
3991 nameList = GetAlnScoreNameList ();
3992 if (i < GetAlnScoreCount ()) {
3993 alignScoreName = nameList [i];
3994 } else {
3995 alignScoreName = nameList[0];
3996 }
3997 gvExtras.alignScoreName = alignScoreName;
3998 */
3999 i = GetValue (bvp->newGphAlnCutoff) - 1;
4000 nameList = GetAlnScoreCutoffList ();
4001 if (i < GetAlnScoreCutoffCount ()) {
4002 alignScoreCutoff = nameList [i];
4003 } else {
4004 alignScoreCutoff = nameList[0];
4005 }
4006 gvExtras.alignScoreCutoff = alignScoreCutoff;
4007 } else {
4008 gvExtras.alignScoreName = "";
4009 gvExtras.alignScoreCutoff = "";
4010 }
4011
4012 if (!bvp->viewWholeEntity) {
4013 sep = SeqMgrGetSeqEntryForData (bsp);
4014 entityID = ObjMgrGetEntityIDForChoice (sep);
4015 if (entityID > 0) {
4016 sep = GetBestTopParentForData (entityID, bsp);
4017 oldscope = SeqEntrySetScope (sep);
4018 }
4019
4020 #ifdef TEST_SEQLOC_LIMIT
4021 {
4022 SeqInt si;
4023 ValNode vn;
4024
4025 MemSet ((Pointer) (&si), 0, sizeof (SeqInt));
4026 MemSet ((Pointer) (&vn), 0, sizeof (ValNode));
4027
4028 si.from = bsp->length * START_FRACTION;
4029 si.to = bsp->length * STOP_FRACTION;
4030 si.strand = Seq_strand_plus;
4031 si.id = bsp->id;
4032
4033 vn.choice = SEQLOC_INT;
4034 vn.data.ptrvalue = &si;
4035
4036 bvp->pict = CreateGraphicView (bsp, &vn, scaleX, appearanceName, filterName, layoutName, &gvExtras);
4037 }
4038 #else
4039 bvp->pict = CreateGraphicView (bsp, NULL, scaleX, appearanceName, filterName, layoutName, &gvExtras);
4040 #endif
4041
4042 if (entityID > 0) {
4043 SeqEntrySetScope (oldscope);
4044 }
4045
4046 } else {
4047 sep = SeqMgrGetSeqEntryForData (bsp);
4048 entityID = ObjMgrGetEntityIDForChoice (sep);
4049 if (entityID > 0) {
4050 sep = GetTopSeqEntryForEntityID (entityID);
4051 oldscope = SeqEntrySetScope (sep);
4052 }
4053
4054 drawState.scale = scaleX;
4055 drawState.ceiling = 0;
4056 drawState.topLevelSegment = CreatePicture ();
4057 myVCP = GetGraphicConfigParseResults ();
4058 drawState.FP = FindFilterByName (filterName, myVCP);
4059 drawState.AP = FindAppearanceByName (appearanceName, myVCP);
4060 drawState.overrideLayout = FindLayoutByName (layoutName);
4061
4062 VisitBioseqsInSep (sep, &drawState, VisitAndDrawBioseqs);
4063 bvp->pict = drawState.topLevelSegment;
4064 }
4065
4066 AttachPicture (bvp->vwr, bvp->pict, vwr_x, vwr_y, vwr_align, scaleX, 1, bvp->highlightSelections ? Asn2GphDrawSelectionRange : NULL);
4067 SetViewerProcs (bvp->vwr, ClickAsn2GphGraphic, NULL, ReleaseAsn2GphGraphic, NULL);
4068
4069 InitSelectAsn2GphView (bvp);
4070
4071 ArrowCursor ();
4072 }
4073
ShowAsn2GphGraphic(BioseqViewPtr bvp,Boolean show)4074 static void ShowAsn2GphGraphic (
4075 BioseqViewPtr bvp,
4076 Boolean show
4077 )
4078
4079 {
4080 if (bvp == NULL)
4081 return;
4082 if (show) {
4083 SafeShow (bvp->vwr);
4084 SafeShow (bvp->newGphControlGrp);
4085 EnableDisableLegendItem (bvp, TRUE);
4086 SafeHide (bvp->findGeneGrp);
4087 SafeShow (bvp->clickMe);
4088 } else {
4089 SafeHide (bvp->vwr);
4090 Reset (bvp->vwr);
4091 bvp->pict = DeletePicture (bvp->pict);
4092 SafeHide (bvp->styleControlGrp);
4093 SafeHide (bvp->scaleControlGrp);
4094 EnableDisableLegendItem (bvp, FALSE);
4095 SafeHide (bvp->findGeneGrp);
4096 SafeHide (bvp->docTxtControlGrp);
4097 SafeHide (bvp->baseCtgControlGrp);
4098 SafeHide (bvp->modeControlGrp);
4099 SafeHide (bvp->extraControlGrp);
4100 SafeHide (bvp->newGphControlGrp);
4101 SafeHide (bvp->clickMe);
4102 }
4103 }
4104
ResizeAsn2GphGraphic(BioseqViewPtr bvp)4105 static void ResizeAsn2GphGraphic (BioseqViewPtr bvp)
4106
4107 {
4108 if (bvp == NULL) return;
4109 if (bvp->vwr != NULL) {
4110 if (Visible (bvp->vwr) && AllParentsVisible (bvp->vwr)) {
4111 ViewerWasResized (bvp->vwr);
4112 }
4113 }
4114 }
4115
4116 BioseqPageData asn2gphGphPageData = {
4117 "Graphic", TRUE, TRUE, TRUE, FALSE, -1,
4118 PopulateAsn2GphGraphic, ShowAsn2GphGraphic, SelectAsn2GphView,
4119 CopyAsn2GphGraphicToClipboard, PrintAsn2GphGraphic, NULL, NULL,
4120 ResizeAsn2GphGraphic, NULL
4121 };
4122
4123