1 /* udvpanel.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: udvpanel.c
27 *
28 * Author: Patrick Durand
29 *
30 * Version Creation Date: 5/3/99
31 *
32 * $Revision: 6.54 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: udvpanel.c,v $
39 * Revision 6.54 2006/07/13 17:13:18 bollin
40 * use Uint4 instead of Uint2 for itemID values
41 *
42 * Revision 6.53 2002/03/14 16:38:48 kans
43 * SeqMgrIndexFeaturesEx takes new parameter
44 *
45 * Revision 6.52 2000/06/27 20:46:38 hurwitz
46 * fixed bugs with select rectangle, added select row option
47 *
48 * Revision 6.51 2000/06/16 17:30:40 kans
49 * UDVResetProc sends TRUE to UDV_FreeVDPstruct
50 *
51 * Revision 6.50 2000/05/19 13:48:31 hurwitz
52 * made a version of DDE that doesn't allow aligned gaps, changed wording for adding new rows
53 *
54 * Revision 6.49 2000/05/18 13:42:16 lewisg
55 * get rid of features list for all but standalone udv
56 *
57 * Revision 6.48 2000/05/17 21:32:41 lewisg
58 * disable feature search except for standalone udv
59 *
60 * Revision 6.47 2000/05/15 23:39:34 lewisg
61 * shred cblast, add menu items for gapped/ungapped, fix pdbheaders
62 *
63 * Revision 6.46 2000/05/09 17:00:46 kans
64 * remove monitor when creating udv panel
65 *
66 * Revision 6.45 2000/05/01 21:21:13 lewisg
67 * make features dialogs modal
68 *
69 * Revision 6.44 2000/04/27 22:21:58 lewisg
70 * misc bugs/features
71 *
72 * Revision 6.43 2000/04/27 19:50:59 kans
73 * implemented udv reset and select (PD+JK)
74 *
75 * Revision 6.42 2000/04/27 15:38:02 hurwitz
76 * changed wording on menu
77 *
78 * Revision 6.41 2000/04/20 23:27:43 lewisg
79 * misc bug fixes
80 *
81 * Revision 6.40 2000/04/17 21:46:56 lewisg
82 * do not do double index on viewmgr update, rename menus
83 *
84 * Revision 6.39 2000/04/13 13:58:02 durand
85 * allowed udv to display reverse complement sequence
86 *
87 * Revision 6.38 2000/04/11 13:19:26 durand
88 * added UDV_LoadSpecificEditor for Sequin
89 *
90 * Revision 6.37 2000/04/10 21:41:27 lewisg
91 * move alignment menus into ddv, udv from cn3d
92 *
93 * Revision 6.36 2000/04/05 21:54:17 kans
94 * resize udvpanel, get vdp directly from slate
95 *
96 * Revision 6.35 2000/04/05 21:13:20 kans
97 * more changes to allow udv panel to be added to Sequin viewer
98 *
99 * Revision 6.34 2000/03/31 13:51:22 durand
100 * added UDV_InitForSequin()
101 *
102 * Revision 6.33 2000/03/30 19:54:09 kans
103 * initial work to get UDV and DDV into Sequin viewer
104 *
105 * Revision 6.32 2000/03/22 20:37:29 durand
106 * added system menus to slave UDV
107 *
108 * Revision 6.31 2000/03/15 19:32:20 lewisg
109 * launch only single udv window
110 *
111 * Revision 6.30 2000/03/07 17:34:14 durand
112 * avoid udv sending an OM_MSG_FLUSH message when it runs as a slave
113 *
114 * Revision 6.29 2000/03/06 14:00:47 durand
115 * first release of the Summary viewer done
116 *
117 * Revision 6.28 2000/03/02 15:47:52 durand
118 * use MovableModalWindow for dialog boxes
119 *
120 * Revision 6.27 2000/02/19 01:23:59 lewisg
121 * use ibm, add row tracking code, various bug fixes
122 *
123 * Revision 6.26 2000/02/16 22:38:29 durand
124 * fixed some wierd behaviours of features selections
125 *
126 * Revision 6.25 2000/02/15 22:40:58 lewisg
127 * add ability to launch udv so that it colors by row, fixes to colormgr, track rows from viewmgr, fix visual c projects
128 *
129 * Revision 6.24 2000/02/11 15:40:29 durand
130 * replaced ObjMgrSendMsg by ObjMgrSelect calls for features selection
131 *
132 * Revision 6.23 2000/02/07 20:17:37 lewisg
133 * minor bug fixes, use gui font for win32
134 *
135 * Revision 6.22 2000/01/24 16:15:22 durand
136 * add loader function for the genome viewer
137 *
138 * Revision 6.21 2000/01/18 22:49:16 lewisg
139 * send OM_MSG_FLUSH to ddv/udv, tweak CPK coloration, misc bugs
140 *
141 * Revision 6.20 2000/01/12 15:06:52 durand
142 * .
143 *
144 * Revision 6.19 2000/01/11 15:03:18 durand
145 * remove network stuff
146 *
147 * Revision 6.18 2000/01/10 15:29:26 durand
148 * add include to netcnfg include file
149 *
150 * Revision 6.17 2000/01/10 15:18:41 durand
151 * use Entrez instead of ID1
152 *
153 * Revision 6.16 2000/01/08 00:47:54 lewisg
154 * fixes to selection, update, color
155 *
156 * Revision 6.15 2000/01/05 21:06:37 durand
157 * update mouse click actions and DrawSequence function for a better use from ddv and cn3d
158 *
159 * Revision 6.14 2000/01/03 21:06:38 durand
160 * update the way the udv main window is created
161 *
162 * Revision 6.13 1999/12/28 23:06:34 lewisg
163 * udv/cn3d communication
164 *
165 * Revision 6.12 1999/12/15 23:17:47 lewisg
166 * make cn3d launch udv, fix launching of non-autonomous udv, add mouseup message
167 *
168 * Revision 6.11 1999/11/29 15:17:55 durand
169 * designed a new GUI; fixed problems under Win95 and Linux
170 *
171 * Revision 6.10 1999/11/19 15:01:47 durand
172 * speed up mouse selection ; avoid sequence flashing during selection ; update menu functionalities
173 *
174 * Revision 6.9 1999/11/09 21:06:58 durand
175 * add sequence selection manager
176 *
177 * Revision 6.8 1999/10/02 15:11:16 durand
178 * update the code to be used by wwwudv
179 *
180 * Revision 6.7 1999/09/07 19:38:45 durand
181 * don't display special features
182 *
183 * Revision 6.6 1999/07/30 20:08:57 durand
184 * updates for the new Entrez graphical viewer
185 *
186 * Revision 6.5 1999/06/08 13:52:36 durand
187 * update UDV data structures for the MSA editor
188 *
189 * Revision 6.4 1999/06/07 15:39:44 durand
190 * add LOG line to keep track of the history
191 *
192 *
193 *
194 * ==========================================================================
195 */
196
197 #include <udviewer.h>
198 #include <samutil.h>
199 #include <viewmgr.h>
200 #ifdef UDV_GENOME
201 #include <udvgv.h>
202 #endif
203
204 /*local text*/
205 static Char szAppName[]="OneD-Viewer";
206
207 /*local text*/
208 static Char szAbout[]="OneD-Viewer : A sequence viewer for GenBank\n\
209 Version 1.0.2\n\nInformation Engineering Branch\n\
210 NCBI - NLM - NIH, Bldg 38A\n\
211 8600 Rockville Pike\n\
212 Bethesda, MD 20894 - USA\n\n\
213 info@ncbi.nlm.nih.gov";
214
215 /*struture passed to the FEAT List dialog box; one struct by entry*/
216 #define COMMENT_SIZE 100
217 typedef struct fldata {
218 Int4 num; /*order num*/
219 Int4 from; /*position of the feature on the sequence*/
220 Int4 to;
221 Int2 segments; /*feature constituted by several seg. (ex: RNA)*/
222 Char szType[COMMENT_SIZE]; /*names of the feature*/
223 Char szComment[COMMENT_SIZE];
224 Uint2 eID; /*entity ID of this feature*/
225 Uint2 iID; /*item ID of this feature*/
226 Uint1 strand; /*minus, plus, ...*/
227 } FLData, PNTR FLDataPtr;
228
229 typedef struct fksdata {
230 WindoW hWinMain;
231 TexT keyField;
232 ButtoN bOk;
233 }FKSData, PNTR FKSDataPtr;
234
235 /*use to initialize the Feature List Dialog box*/
236 static char *szSeqFeatClassName[]={
237 "All",
238 "Gene",
239 "Organism",
240 "CD region",
241 "Protein",
242 "RNA",
243 "Publication",
244 "SEQ",
245 "IMP",
246 "Region",
247 "Comment",
248 "Bond",
249 "Site",
250 "RSITE",
251 "USER",
252 "TXINIT",
253 "Numbering",
254 "Secondary structure",
255 "Non standard residue",
256 "Heteroatom",
257 "Biosource",
258 };
259
260 /*local functions*/
261 static ValNodePtr UDV_GetParaGNodeGivenPos(ValNodePtr ParaG_head,Int4 bsp_pos);
262 static void UnDViewerVScrlUpdatePage(Int4Ptr PageUpDn,Int2 cyClient,
263 Int2 LineHeight);
264 static void PanelOrgChange(PaneL p,ViewerDialogDataPtr vdp);
265 static Boolean CreateUDVpanel(WindoW w,ViewerMainPtr PNTR vmp,
266 SAM_ViewGlobal *vgp);
267 static void UDV_ReLocateRcParaGList(RecT rcP,Boolean ShowTop,Boolean ShowTick,
268 Boolean ShowSequence, Boolean ShowFeatures,
269 Boolean ShowBlank,Int4Ptr nTotL,ValNodePtr ParaG_head);
270 static void ShowFeaturesListDlg(IteM i);
271 static void UDV_SearchFeatForKey(IteM i);
272 static void UDV_ShowReverseComplement(IteM i);
273 static void UDV_analyse_buffer(UnDViewerGraphDataPtr GrData,
274 ValNodePtr ParaG_list,BspInfoPtr bsp_i,Uint2 ActionType,Boolean bReverse);
275 #ifdef UDV_GENOME
276 static void UDV_GenViewProc(IteM I);
277 #endif
278 /*******************************************************************************
279
280 Function : UDV_TimerProc()
281
282 Purpose : function called by the timer. Right now, this function is used
283 to highlighte the GoTo letter.
284
285 Return value :
286
287 *******************************************************************************/
UDV_TimerProc(WindoW w)288 static void UDV_TimerProc (WindoW w)
289 {
290 ViewerDialogDataPtr vdp;
291 ViewerMainPtr vmp;
292 ValNodePtr vnp;
293 ParaGPtr pgp;
294 Int4 bsp_pos;
295
296 vmp=(ViewerMainPtr)GetObjectExtra(w);
297 if (vmp==NULL || vmp->vdp==NULL) return;
298 vdp = vmp->vdp;
299 if (vdp==NULL) return;
300 if (vdp->ParaG==NULL) return;
301
302 if (vdp->udt.status==UDV_SET_TIMER){
303 vdp->udt.delay=0;
304 if (vdp->udt.action==UDV_INVAL_REGION){
305 vnp=UDV_GetParaGNodeGivenPos(vdp->ParaG,vdp->udt.pos);
306 if (!vnp) return;
307 pgp=(ParaGPtr)vnp->data.ptrvalue;
308 UDV_InvalRegion(vdp->UnDViewer,&(vdp->udv_graph),
309 pgp,_max_(0,vdp->udt.pos-1),vdp->udt.pos+1,FALSE);
310 }
311 vdp->udt.status=UDV_TEST_TIMER;
312 }
313 if (vdp->udt.status==UDV_TEST_TIMER){
314 if (vdp->udt.delay>10){
315 if (vdp->udt.action==UDV_INVAL_REGION){
316 bsp_pos=vdp->udt.pos;
317 vdp->udt.pos=0;
318 vnp=UDV_GetParaGNodeGivenPos(vdp->ParaG,bsp_pos);
319 if (!vnp) return;
320 pgp=(ParaGPtr)vnp->data.ptrvalue;
321 vdp->udv_graph.GotoLetter=0;
322 UDV_InvalRegion(vdp->UnDViewer,&(vdp->udv_graph),
323 pgp,_max_(0,bsp_pos-1),bsp_pos+1,FALSE);
324 vdp->udt.action=UDV_NOTHING;
325 }
326 }
327 }
328 vdp->udt.delay++;
329 }
330
331
332 /*******************************************************************************
333
334 Function : UDV_GetSelectedRegions()
335
336 Purpose : get the selected region(s) of one bioseq.
337
338 Parameters : om_ssp;list of selected regions (usually this field points to
339 ObjMgr data)
340 bsp_eID,bsp_iID; bioseq identifiers.
341
342 Return value : list of selected regions on the bioseq bsp_eID,bsp_iID
343
344 *******************************************************************************/
UDV_GetSelectedRegions(SelStructPtr om_ssp,Uint2 bsp_eID,Uint2 bsp_iID)345 NLM_EXTERN ValNodePtr UDV_GetSelectedRegions(SelStructPtr om_ssp, Uint2 bsp_eID,
346 Uint2 bsp_iID)
347 {
348 SelStructPtr ssp;
349 SeqLocPtr slp,slp2;
350 ValNodePtr bsp_vnp=NULL,vnp;
351
352 if (om_ssp==NULL || bsp_eID==0 || bsp_iID==0) return(NULL);
353
354 ssp=om_ssp;
355
356 while(ssp){
357 if (ssp->entityID==bsp_eID && ssp->itemID==bsp_iID &&
358 ssp->itemtype==OBJ_BIOSEQ && ssp->regiontype==OM_REGION_SEQLOC){
359 slp=(SeqLocPtr)ssp->region;
360 while(slp){
361 slp2=slp->next;
362 slp->next=NULL;
363 if (!bsp_vnp){
364 vnp=ValNodeAddPointer(NULL,0,(Pointer)slp);
365 if (!vnp) return(NULL);
366 bsp_vnp=vnp;
367 }
368 else{
369 vnp=ValNodeAddPointer(&vnp,0,(Pointer)slp);
370 if (!vnp){
371 if (bsp_vnp) ValNodeFree(bsp_vnp);
372 return(NULL);
373 }
374 }
375 slp->next=slp2;
376 slp=slp->next;
377 }
378 }
379 ssp=ssp->next;
380 }
381 return(bsp_vnp);
382 }
383
384 /*******************************************************************************
385
386 Function : UDV_IsLetterSelected()
387
388 Purpose : check if a bsp_pos is selected (vnp_bsp is usually built with
389 DDV_GetSelectedRegions() function)
390
391 Return value : TRUE if bsp_pos is selected
392
393 *******************************************************************************/
UDV_IsLetterSelected(ValNodePtr vnp_bsp,Int4 bsp_pos,Int4 bspLength,Boolean bDisplayRevComp)394 NLM_EXTERN Boolean UDV_IsLetterSelected(ValNodePtr vnp_bsp, Int4 bsp_pos,
395 Int4 bspLength,Boolean bDisplayRevComp)
396 {
397 Boolean bSelected=FALSE;
398 ValNodePtr vnp;
399 SeqLocPtr slp;
400 Int4 bsp_start,bsp_stop;
401 if (vnp_bsp==NULL || bsp_pos==(Int4)-1) return(FALSE);
402
403 vnp=vnp_bsp;
404
405 while(vnp){
406 slp=(SeqLocPtr)vnp->data.ptrvalue;
407 bsp_start=SeqLocStart(slp);
408 bsp_stop=SeqLocStop(slp);
409 if (bDisplayRevComp){
410 bsp_start=UDV_RevertBioSeqCoord(bsp_start,bspLength);
411 bsp_stop=UDV_RevertBioSeqCoord(bsp_stop,bspLength);
412 if (bsp_stop<bsp_start)
413 swap(&bsp_start,&bsp_stop);
414 }
415 if (bsp_pos>=bsp_start && bsp_pos<=bsp_stop){
416 bSelected=TRUE;
417 break;
418 }
419 vnp=vnp->next;
420 }
421
422 return(bSelected);
423 }
424
425 /*****************************************************************************
426
427 Function: UDV_GetClosetSeqLocGivenBspPos()
428
429 Purpose: given a position in the Bioseq, this function return the closest
430 selected region on that bioseq.
431
432 Parameters: sip, eID, iID; bsioseq identifiers
433 bsp_pos; current position on that bioseq
434 old_pos; returns old_pos of a selection (used only if bModify is TRUE)
435 bModify; if TRUE, create a modified slp
436
437 Note : sip can be null ONLY if bModify if FALSE.
438
439 Return value: see Purpose.
440
441 *****************************************************************************/
UDV_GetClosetSeqLocGivenBspPos(SeqIdPtr sip,Uint2 eID,Uint2 iID,Int4 bsp_pos,Int4Ptr old_pos,Boolean bModify)442 NLM_EXTERN SeqLocPtr UDV_GetClosetSeqLocGivenBspPos(SeqIdPtr sip, Uint2 eID,
443 Uint2 iID, Int4 bsp_pos, Int4Ptr old_pos, Boolean bModify)
444 {
445 SelStructPtr ssp;
446 SeqLocPtr slp=NULL;
447 ValNodePtr vnp_bsp,vnp;
448 Int4 diff,old_diff,diff_l,diff_r,bsp_start,bsp_stop;
449 Uint1 strand;
450
451 ssp=ObjMgrGetSelected();
452 if (ssp==NULL) return(NULL);
453
454 vnp_bsp=UDV_GetSelectedRegions(ssp,eID,iID);
455 if (vnp_bsp==NULL) return(NULL);
456 vnp=vnp_bsp;
457 *old_pos=(Int4)-1;
458 old_diff=(Int4)INT4_MAX;
459
460 while(vnp){
461 bsp_start=SeqLocStart((SeqLocPtr)vnp->data.ptrvalue);
462 bsp_stop=SeqLocStop((SeqLocPtr)vnp->data.ptrvalue);
463 strand=SeqLocStrand((SeqLocPtr)vnp->data.ptrvalue);
464 if (bsp_pos<bsp_start){/*left of a selected region ?*/
465 diff=bsp_start-bsp_pos;
466 if (diff<old_diff){
467 if (slp) slp=SeqLocFree(slp);
468 if (bModify){
469 slp = SeqLocIntNew (bsp_pos, bsp_stop, strand/*Seq_strand_minus*/, sip);
470 *old_pos=bsp_stop;
471 }
472 else{
473 slp = SeqLocIntNew (bsp_start, bsp_stop, strand, sip);
474 *old_pos=(Int4)-1;
475 }
476 old_diff=diff;
477 }
478 }
479 else if (bsp_pos>bsp_stop){/*right of a selected region ?*/
480 diff=bsp_pos-bsp_stop;
481 if (diff<old_diff){
482 if (slp) slp=SeqLocFree(slp);
483 if (bModify){
484 slp = SeqLocIntNew (bsp_start, bsp_pos, strand/*Seq_strand_plus*/, sip);
485 *old_pos=bsp_start;
486 }
487 else{
488 slp = SeqLocIntNew (bsp_start, bsp_stop, strand, sip);
489 *old_pos=(Int4)-1;
490 }
491 old_diff=diff;
492 }
493 }
494 else{/*inside a selected region ?*/
495 if(bModify){
496 diff_l=bsp_pos-bsp_start;
497 diff_r=bsp_stop-bsp_pos;
498 if (diff_l<diff_r){
499 bsp_start=bsp_pos;
500 *old_pos=bsp_stop;
501 /*strand=Seq_strand_plus;*/
502 }
503 else{
504 bsp_stop=bsp_pos;
505 *old_pos=bsp_start;
506 /*strand=Seq_strand_minus;*/
507 }
508 slp = SeqLocIntNew (bsp_start, bsp_stop, strand, sip);
509 break;
510 }
511 }
512 vnp=vnp->next;
513 }
514 ValNodeFree(vnp_bsp);
515 return(slp);
516 }
517
518 /*******************************************************************************
519
520 Function : UDV_GetParaGNodeGivenPos()
521
522 Purpose : given a bsp_pos, get back the node in the ParaG list
523
524 Return value : -
525
526 *******************************************************************************/
UDV_GetParaGNodeGivenPos(ValNodePtr ParaG_head,Int4 bsp_pos)527 static ValNodePtr UDV_GetParaGNodeGivenPos(ValNodePtr ParaG_head,Int4 bsp_pos)
528 {
529 ValNodePtr vnp,vnp_find;
530 ParaGPtr pgp;
531
532 vnp_find=NULL;
533 vnp=ParaG_head;
534 while(vnp){
535 if (vnp->data.ptrvalue){
536 pgp=(ParaGPtr)vnp->data.ptrvalue;
537 if (bsp_pos>=pgp->StartLetter && bsp_pos<=pgp->StopLetter){
538 vnp_find=vnp;
539 break;
540 }
541 }
542 vnp=vnp->next;
543 }
544 return(vnp_find);
545 }
546
547 /*******************************************************************************
548
549 Function : UDV_GetLineNumGivenPos()
550
551 Purpose : given a bsp_pos, get back the line number
552
553 Return value : -
554
555 *******************************************************************************/
UDV_GetLineNumGivenPos(ValNodePtr ParaG_head,Int4 bsp_pos,Int4Ptr line_num)556 static ValNodePtr UDV_GetLineNumGivenPos(ValNodePtr ParaG_head,Int4 bsp_pos,
557 Int4Ptr line_num)
558 {
559 ValNodePtr vnp;
560 ParaGPtr pgp;
561
562 vnp=UDV_GetParaGNodeGivenPos(ParaG_head,bsp_pos);
563
564 if (!vnp) {
565 *line_num=(Int4)-1;
566 return(NULL);
567 }
568
569 pgp=(ParaGPtr)vnp->data.ptrvalue;
570 *line_num=pgp->StartLine;
571
572 return(vnp);
573 }
574
575 /*******************************************************************************
576
577 Function : UDV_MSG_SELECT()
578
579 Purpose : manage select/deselect messages
580
581 Return value : -
582
583 *******************************************************************************/
UDV_MSG_SELECT(ViewerDialogDataPtr vdp,OMMsgStructPtr ommsp,Boolean IsSelect)584 static Int2 UDV_MSG_SELECT(ViewerDialogDataPtr vdp,OMMsgStructPtr ommsp,
585 Boolean IsSelect)
586 {
587 SeqLocPtr slp;
588 ParaGPtr pgp;
589 ValNodePtr vnp_start,vnp;
590 Int4 from_bsp,to_bsp,bsp_start,bsp_stop,tot,pop,decal,start_inval,stop_inval;
591 Uint2 bsp_eID;
592 Uint4 bsp_iID;
593
594 /*some usefull tests...*/
595 if (vdp == NULL) return(OM_MSG_RET_ERROR);
596 if (ommsp->itemtype != OBJ_BIOSEQ) return(OM_MSG_RET_OK);
597 if (ommsp->regiontype!=OM_REGION_SEQLOC) return(OM_MSG_RET_OK);
598
599 /*Am I concern by that Bioseq ?*/
600 bsp_eID=ObjMgrGetEntityIDForPointer((Pointer)vdp->bsp_i.bsp);
601 bsp_iID = GetItemIDGivenPointer (bsp_eID,
602 OBJ_BIOSEQ, (Pointer) vdp->bsp_i.bsp);
603 if (bsp_eID!=ommsp->entityID || bsp_iID!=ommsp->itemID) return(OM_MSG_RET_ERROR);
604
605 /*get the current display range*/
606 UDV_GetCurrentDispRange(vdp,&from_bsp,&to_bsp,NULL,NULL);
607 if (from_bsp==0 && to_bsp==0) return(OM_MSG_RET_ERROR);
608
609 /*scan the SeqLoc list to figure out if it's currently on the screen*/
610 slp=(SeqLocPtr)ommsp->region;
611 while(slp){/*for each SeqLoc, I try to see what region(s) has (have) to be
612 uptdated*/
613 bsp_start=SeqLocStart(slp);
614 bsp_stop=SeqLocStop(slp);
615 /*when udv displays a reverse/complement sequence, bsp_coords are
616 actually display coords. */
617 if (vdp->bDisplayRevComp){
618 bsp_start=UDV_RevertBioSeqCoord(bsp_start,vdp->bsp_i.bspLength);
619 bsp_stop=UDV_RevertBioSeqCoord(bsp_stop,vdp->bsp_i.bspLength);
620 if (bsp_stop<bsp_start)
621 swap(&bsp_start,&bsp_stop);
622 }
623 if (bsp_start<=to_bsp && bsp_stop>=from_bsp){
624 vnp_start=UDV_GetParaGNodeGivenPos(vdp->ParaG,bsp_start);
625 vnp=vnp_start;
626 tot=bsp_stop-bsp_start+1;
627 pop=decal=0;
628 while(vnp){
629 pgp=(ParaGPtr)vnp->data.ptrvalue;
630 start_inval=bsp_start+decal;
631 stop_inval=_min_(bsp_stop,pgp->StopLetter);
632 UDV_InvalRegion(vdp->UnDViewer,&(vdp->udv_graph),pgp,
633 start_inval,stop_inval,IsSelect);
634 pop+=(stop_inval-start_inval+1);
635 if (pop>=tot)
636 break;
637 decal=pop;
638 vnp=vnp->next;
639 }
640 }
641 slp=slp->next;
642 }
643 return(OM_MSG_RET_OK);
644
645 }
646
647 /*******************************************************************************
648
649 Function : UDV_MSG_FLUSH()
650
651 Purpose : kill the viewer in response to a OM_MSG_FLUSH message
652
653 Return value : OM_MSG_RET_OK if success
654
655 *******************************************************************************/
UDV_MSG_FLUSH(ViewerDialogDataPtr vdp,OMMsgStructPtr ommsp)656 static Int2 UDV_MSG_FLUSH(ViewerDialogDataPtr vdp,OMMsgStructPtr ommsp)
657 {
658 Uint2 bsp_eID,bsp_iID;
659 ViewerMainPtr vmp;
660
661 /*standalone UDV : doesn't answer this message*/
662 if (vdp->Parent){
663 vmp = (ViewerMainPtr)GetObjectExtra(vdp->Parent);
664 if (vmp && vmp->AutonomeViewer==TRUE)
665 return(OM_MSG_RET_OK);
666 }
667
668 /*Am I concern by that Bioseq ?*/
669 bsp_eID=ObjMgrGetEntityIDForPointer((Pointer)vdp->bsp_i.bsp);
670 bsp_iID = GetItemIDGivenPointer (bsp_eID,
671 OBJ_BIOSEQ, (Pointer) vdp->bsp_i.bsp);
672
673 if (bsp_eID==ommsp->entityID &&
674 ((bsp_iID==ommsp->itemID && ommsp->itemtype==OBJ_BIOSEQ)
675 || (ommsp->itemID == 0 && ommsp->itemtype==0))){
676 Remove(ParentWindow(vdp->UnDViewer));
677 }
678 return(OM_MSG_RET_OK);
679 }
680
681 /*******************************************************************************
682
683 Function : UDV_OM_MsgFunc()
684
685 Purpose : ObjMgr message loop of the viewer
686
687 Parameters : see Toolkit
688
689 Return value : see Toolkit
690
691 *******************************************************************************/
UDV_OM_MsgFunc(OMMsgStructPtr ommsp)692 static Int2 LIBCALLBACK UDV_OM_MsgFunc (OMMsgStructPtr ommsp)
693 {
694 OMUserDataPtr omudp;
695 /*BioseqPtr bsp;*/
696 ViewerDialogDataPtr vdp;
697 ViewerMainPtr vmp = NULL;
698
699 omudp = (OMUserDataPtr)(ommsp->omuserdata);
700 vdp = (ViewerDialogDataPtr)(omudp->userdata.ptrvalue);
701
702 if (!vdp) return(OM_MSG_RET_OK);
703
704 switch (ommsp->message)
705 {
706 case OM_MSG_DEL:
707 break;
708 case OM_MSG_CREATE:
709 break;
710 case OM_MSG_UPDATE:
711
712 if (vdp->UnDViewer){
713 RecT rc;
714 WindoW temport;
715 temport=SavePort((WindoW)vdp->UnDViewer);
716 Select (vdp->UnDViewer);
717 ObjectRect(vdp->UnDViewer,&rc);
718 InvalRect(&rc);
719 RestorePort(temport);
720 }
721 break;
722 case OM_MSG_SELECT:
723 /*Click Feat ?*/
724 if (ommsp->itemtype==OBJ_SEQFEAT) {
725 UDV_select_feature(vdp->UnDViewer,vdp,ommsp->entityID,
726 ommsp->itemID,TRUE);
727 /*(Boolean)(vdp->ClickFeatFromDlg ? TRUE : FALSE));*/
728 if (!vdp->ClickFeatFromDlg){
729 if (vdp->Parent)
730 vmp=(ViewerMainPtr)GetObjectExtra(vdp->Parent);
731 if (vmp && vmp->hFeatDlg){/*update Features List Dlg if needed;
732 to do : convert this Feature ListBox to a real Viewer able
733 to play with ObjMgr*/
734 UDV_SelectFeatInFeatDlg(vmp,ommsp->entityID,ommsp->itemID);
735 }
736 }
737 vdp->ClickFeatFromDlg=FALSE;
738 }
739 else if (ommsp->itemtype==OBJ_BIOSEQ){
740 UDV_MSG_SELECT(vdp,ommsp,TRUE);
741 }
742 break;
743 case OM_MSG_DESELECT:
744 if (ommsp->itemtype==OBJ_SEQFEAT) {
745 UDV_deselect_feature(vdp);
746 }
747 else if (ommsp->itemtype==OBJ_BIOSEQ){
748 UDV_MSG_SELECT(vdp,ommsp,FALSE);
749 }
750 break;
751 case OM_MSG_CACHED:
752 break;
753 case OM_MSG_UNCACHED:
754 break;
755 case OM_MSG_TO_CLIPBOARD:
756 break;
757 case OM_MSG_SETCOLOR:
758 if (vdp->UnDViewer){
759 RecT rc;
760 ObjectRect(vdp->UnDViewer,&rc);
761 InvalRect(&rc);
762 Update();
763 }
764 break;
765 case OM_MSG_FLUSH:
766 UDV_MSG_FLUSH(vdp,ommsp);
767 break;
768 default:
769 break;
770 }
771
772 return OM_MSG_RET_OK;
773 }
774
775 /*******************************************************************************
776
777 Function : UDV_ObjRegAutonomous()
778
779 Purpose : call by ObjMgr to start the viewer; Autonomous version
780
781 Parameters : see Toolkit
782
783 Note: only for the Autonomous viewer purpose
784
785 Return value : see Toolkit
786
787 *******************************************************************************/
UDV_ObjRegAutonomous(Pointer data)788 NLM_EXTERN Int2 LIBCALLBACK UDV_ObjRegAutonomous (Pointer data)
789 {
790 WindoW w=NULL;
791 OMProcControlPtr ompcp;
792 OMUserDataPtr omudp;
793 BioseqPtr bsp=NULL;
794 ViewerMainPtr vmp=NULL;
795 ViewerDialogDataPtr vdp=NULL;
796 Char szBuf[255]={""};
797 UdvGlobalsPtr ugp=NULL;
798 RecT rcP;
799 WindoW temport;
800 SAM_ViewGlobal *vgp=NULL;
801 Uint2 eID;
802 Uint4 iID;
803
804 vgp = GetAppProperty(SAM_ViewString);
805
806 /*retrieve data*/
807 ompcp = (OMProcControlPtr) data;
808
809 if (ompcp == NULL || ompcp->proc == NULL) {
810 ErrPostEx (SEV_ERROR, 0, 0, "Data NULL [1]");
811 return OM_MSG_RET_ERROR;
812 }
813
814 /*initialize the viewer windows (viewer and info panels)*/
815 /*autonomous viewer ?*/
816 ugp=(UdvGlobalsPtr)GetAppProperty("UdvGlobals");
817 if (ugp) vmp=ugp->vmp;
818
819 /*if w and/or vmp are NULL, they'll be initialized in this function*/
820 if (vmp || ((vmp = (ViewerMainPtr)GetAppProperty("nonautonomous")) != NULL)) {/*reuse the viewer if already there*/
821 w=vmp->hWndMain;
822 if (!CreateUDVpanel(w,&vmp, vgp))
823 return OM_MSG_RET_ERROR;
824 }
825 else {/*for each call, create a new viewer window*/
826 /*non-autonomous viewer*/
827 if (!CreateUDVpanel(w,&vmp, vgp)) return OM_MSG_RET_ERROR;
828 }
829
830 /*init specific data for the ObjMgr msg loop*/
831 vdp=vmp->vdp;
832 if (!vdp) return OM_MSG_RET_ERROR;
833
834 switch (ompcp->input_itemtype) {
835 case OBJ_BIOSEQ :
836 bsp = (BioseqPtr) ompcp->input_data;
837 UDV_CreateOneFeatureIndex(0, bsp, vdp->bDisplayRevComp);
838 break;
839 case OBJ_BIOSEQSET:
840 UDV_CreateOneFeatureIndex(ompcp->input_entityID, NULL, vdp->bDisplayRevComp);
841 vmp->BspTable = NULL;
842 SeqMgrExploreBioseqs (ompcp->input_entityID, NULL, (Pointer) &vmp->BspTable,
843 SearchBioseq, TRUE, TRUE, TRUE);
844 if(vmp->BspTable == NULL) return OM_MSG_RET_ERROR;
845 UDV_DecodeIdxFeat ((Uint4)vmp->BspTable->data.intvalue,&eID,&iID);
846 bsp=GetBioseqGivenIDs (eID, iID, OBJ_BIOSEQ);
847 if(bsp == NULL) return OM_MSG_RET_ERROR;
848 break;
849 case 0 :
850 return OM_MSG_RET_ERROR;
851 default :
852 return OM_MSG_RET_ERROR;
853 }
854
855 if (bsp == NULL) {
856 ErrPostEx (SEV_ERROR, 0, 0, "Data NULL [2]");
857 return OM_MSG_RET_ERROR;
858 }
859
860 vdp->procid=ompcp->proc->procid;
861 vdp->proctype=ompcp->proc->proctype;
862 vdp->userkey=OMGetNextUserKey ();
863 if( vgp != NULL ) {
864 if (vgp->MasterViewer == SAMVIEWDDV) {
865 vdp->vgp = MemNew(sizeof(SAM_ViewGlobal));
866 MemCpy(vdp->vgp, vgp, sizeof(SAM_ViewGlobal));
867 ViewMgr_SetRow(vgp->pCGlobal, vdp->userkey, vgp->Row);
868 }
869 else vdp->vgp = NULL;
870 }
871 else vdp->vgp = NULL;
872
873 if (UDV_init_bsp_forViewer(vmp->vdp->UnDViewer,bsp,ompcp->input_entityID,
874 ompcp->input_itemID,ompcp->input_itemtype,vdp)){
875 UDV_set_MainMenus(&vmp->MainMenu,TRUE);
876 UDV_set_MainControls(vmp,TRUE);
877 }
878 else{
879 UDV_set_MainMenus(&vmp->MainMenu,FALSE);
880 UDV_set_MainControls(vmp,FALSE);
881 return OM_MSG_RET_ERROR;
882 }
883
884 /*Update dialog box title*/
885 sprintf(szBuf,"%s - [%s - %d letters]",szAppName,
886 vdp->bsp_i.bspAccNum,
887 vdp->bsp_i.bspLength);
888 SetTitle(w,szBuf);
889
890 temport=SavePort((WindoW)vdp->UnDViewer);
891 Select (vdp->UnDViewer);
892 ObjectRect(vdp->UnDViewer,&rcP);
893 InvalRect(&rcP);
894 RestorePort(temport);
895
896 omudp = ObjMgrAddUserData (ompcp->input_entityID, ompcp->proc->procid,
897 OMPROC_VIEW, vdp->userkey);
898 if (omudp != NULL) {
899 omudp->userdata.ptrvalue = (Pointer) vdp;
900 omudp->messagefunc = UDV_OM_MsgFunc;
901 }
902
903 return(OM_MSG_RET_DONE);
904 }
905
906
907 /*******************************************************************************
908
909 Function : UDV_WinMainProgQuit()
910
911 Purpose : end of prog
912
913 Parameters : w; main window handle
914
915 Return value : none
916
917 *******************************************************************************/
UDV_WinMainProgQuit(WindoW w)918 NLM_EXTERN void UDV_WinMainProgQuit(WindoW w)
919 {
920 QuitProgram();
921 }
922
923 /*******************************************************************************
924
925 Function : QuitProc()
926
927 Purpose : bye-bye procedure !
928
929 Parameters : i; menu item which has called this function
930
931 Return value : none
932
933 *******************************************************************************/
QuitProc(IteM i)934 static void QuitProc(IteM i)
935 {
936 ViewerMainPtr vmp;
937 WindoW hWinMain;
938
939 hWinMain=(WindoW)ParentWindow(i);
940
941 if (!hWinMain) return;
942
943 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
944
945 if (vmp==NULL) return;
946
947 Remove(hWinMain);
948 if (vmp->AutonomeViewer) QuitProgram();
949
950 }
951
952
953 /*******************************************************************************
954
955 Function : UDV_FreeVDPstruct()
956
957 Purpose : free VDP struct before leaving viewer
958
959 Parameters : vdp; data to delete
960
961 Return value : NULL
962
963 *******************************************************************************/
UDV_FreeVDPstruct(ViewerDialogDataPtr vdp,Boolean final)964 NLM_EXTERN void * UDV_FreeVDPstruct(ViewerDialogDataPtr vdp,Boolean final)
965 {
966 ViewerMainPtr vmp;
967
968 if (vdp){
969 /*a call to close all the internal UDV viewers (Genome Viewer for example)*/
970 /*standalone UDV : doesn't answer this message*/
971 if (vdp->Parent){
972 vmp = (ViewerMainPtr)GetObjectExtra(vdp->Parent);
973 if (vmp && vmp->AutonomeViewer==TRUE)
974 ObjMgrSendMsg(OM_MSG_FLUSH, vdp->bsp_i.bsp_entityID,
975 vdp->bsp_i.bsp_itemID, OBJ_BIOSEQ);
976 }
977
978 /*free some user data of Obj Mgr*/
979 if (vdp->userkey>0) {
980 if (vdp->bsp_i.bsp_entityID>0){
981 ObjMgrFreeUserData(vdp->bsp_i.bsp_entityID,
982 vdp->procid,vdp->proctype,vdp->userkey);
983 }
984 }
985
986 UDV_FreeListParaG(&vdp->ParaG);
987 vdp->procid=0;
988 vdp->proctype=0;
989 vdp->userkey=0;
990 if (vdp->bsp_i.SeqBuf)
991 MemFree(vdp->bsp_i.SeqBuf);
992 memset(&vdp->bsp_i,0,sizeof(BspInfo));
993 memset(&vdp->udv_graph.udv_vscrl,0,sizeof(UDVScrollData));
994 vdp->udv_graph.udv_panel.nTotLines=0;
995 if (vdp->udv_graph.udv_panel.region)
996 ValNodeFreeData(vdp->udv_graph.udv_panel.region);
997 ClearUDV_mouse_select(&(vdp->UDV_ms));
998 vdp->UDV_ms.Action_type=MS_ACTION_FEAT_NOTHING;
999 memset(&vdp->Item_select,(Uint2)-1,sizeof(UDV_Item_Select));
1000 memset(&vdp->Old_Item_select,(Uint2)-1,sizeof(UDV_Item_Select));
1001 if (!final) UnDViewerVScrlUpdate(vdp->UnDViewer,TRUE,0);
1002 vdp->ClickFeatFromDlg=FALSE;
1003 vdp->bDisplayRevComp=FALSE;
1004 }
1005
1006 return(NULL);
1007 }
1008
1009 /*******************************************************************************
1010
1011 Function : UDV_WinMainCleanupExtraProc()
1012
1013 Purpose : free memory before leaving viewer
1014
1015 Parameters : vmp; main data
1016
1017 Return value : none
1018
1019 *******************************************************************************/
UDV_WinMainCleanupExtraProc(GraphiC g,VoidPtr data)1020 NLM_EXTERN void UDV_WinMainCleanupExtraProc (GraphiC g, VoidPtr data)
1021 {
1022 ViewerMainPtr vmp=(ViewerMainPtr)data;
1023
1024 if (!vmp) return;
1025 /*if (vmp->the_set) SeqEntryFree(vmp->the_set); */
1026 if (vmp->BspTable) ValNodeFree(vmp->BspTable);
1027
1028 UDV_FreeVDPstruct(vmp->vdp,TRUE);
1029
1030 /*done only for Autonomous viewer*/
1031 if (vmp->dataptr) ObjMgrFree(vmp->datatype,vmp->dataptr);
1032
1033 if (vmp->vdp->udv_graph.pClr) MemFree(vmp->vdp->udv_graph.pClr);
1034 MemFree(vmp->vdp->vgp);
1035 MemFree(vmp->vdp);
1036 MemFree(vmp);
1037 }
1038
1039
1040 /*******************************************************************************
1041
1042 Function : UDV_AboutProc()
1043
1044 Purpose : about dialog box
1045
1046 Parameters : -
1047
1048 Return value : none
1049
1050 *******************************************************************************/
UDV_AboutProc(IteM i)1051 static void UDV_AboutProc(IteM i)
1052 {
1053 MsgAlert(KEY_OK, SEV_INFO, "About OneD-Viewer",szAbout);
1054
1055 }
1056
1057 /*******************************************************************************
1058
1059 Function : UDV_set_PullMenus()
1060
1061 Purpose : manage main window pulldown menus
1062
1063 Parameters : mmp; menu data
1064 enable; if TRUE, enable the command menus listed in mmp
1065
1066 Return value : none
1067
1068 *******************************************************************************/
UDV_set_PullMenus(UDVMainMenuPtr mmp,Boolean enable)1069 NLM_EXTERN void UDV_set_PullMenus(UDVMainMenuPtr mmp,Boolean enable)
1070 {
1071 if (enable){
1072 Enable(mmp->FileOpen);
1073 Enable(mmp->EntrezOpen);
1074 Enable(mmp->FileClose);
1075 Enable(mmp->ListSequence);
1076 Enable(mmp->QuitViewer);
1077 Enable(mmp->ShowFeature);
1078 Enable(mmp->ShowFeatureList);
1079 Enable(mmp->SearchForFeature);
1080 Enable(mmp->ShowRevComp);
1081 Enable(mmp->RefreshScreen);
1082 Enable(mmp->HelpAbout);
1083 }
1084 else{
1085 Disable(mmp->FileOpen);
1086 Disable(mmp->EntrezOpen);
1087 Disable(mmp->FileClose);
1088 Disable(mmp->ListSequence);
1089 Disable(mmp->QuitViewer);
1090 Disable(mmp->ShowFeature);
1091 Disable(mmp->ShowFeatureList);
1092 Disable(mmp->SearchForFeature);
1093 Disable(mmp->ShowRevComp);
1094 Disable(mmp->RefreshScreen);
1095 Disable(mmp->HelpAbout);
1096 }
1097 }
1098
1099
1100 /*******************************************************************************
1101
1102 Function : UDV_set_MainMenus()
1103
1104 Purpose : manage main window command menus
1105
1106 Parameters : mmp; menu data
1107 enable; if TRUE, enable the command menus listed in mmp
1108
1109 Return value : none
1110
1111 *******************************************************************************/
UDV_set_MainMenus(UDVMainMenuPtr mmp,Boolean enable)1112 NLM_EXTERN void UDV_set_MainMenus(UDVMainMenuPtr mmp,Boolean enable)
1113 {
1114
1115 SetStatus(mmp->ShowRevComp,FALSE);
1116 if (enable){
1117 if (mmp->FileClose) Enable(mmp->FileClose);
1118 Enable(mmp->ShowFeature);
1119 Enable(mmp->ShowFeatureList);
1120 Enable(mmp->SearchForFeature);
1121 Enable(mmp->ScalePos);
1122 Enable(mmp->RefreshScreen);
1123 Enable(mmp->ShowRevComp);
1124 if (mmp->ListSequence) Enable(mmp->ListSequence);
1125 }
1126 else{
1127 if (mmp->FileClose) Disable(mmp->FileClose);
1128 Disable(mmp->ShowFeature);
1129 Disable(mmp->ShowFeatureList);
1130 Disable(mmp->SearchForFeature);
1131 Disable(mmp->ScalePos);
1132 Disable(mmp->RefreshScreen);
1133 Disable(mmp->ShowRevComp);
1134 if (mmp->ListSequence) Disable(mmp->ListSequence);
1135 }
1136 }
1137
1138 /*******************************************************************************
1139
1140 Function : UDV_set_MainControls()
1141
1142 Purpose : manage main window controls (GoTO btn, etc)
1143
1144 Return value : none
1145
1146 *******************************************************************************/
UDV_set_MainControls(ViewerMainPtr vmp,Boolean enable)1147 NLM_EXTERN void UDV_set_MainControls(ViewerMainPtr vmp,Boolean enable)
1148 {
1149
1150 if (enable){
1151 Enable(vmp->gotoBtn);
1152 Enable(vmp->gotoVal);
1153 }
1154 else{
1155 Disable(vmp->gotoBtn);
1156 Disable(vmp->gotoVal);
1157 }
1158 }
1159
1160 /*******************************************************************************
1161
1162 Function : RefreshScreenProc()
1163
1164 Purpose : redraw the screen
1165
1166 Parameters : i; menu item
1167
1168 Return value : none
1169
1170 *******************************************************************************/
RefreshScreenProc(IteM i)1171 static void RefreshScreenProc(IteM i)
1172 {
1173 ViewerMainPtr vmp;
1174 WindoW hWinMain,temport;
1175 ViewerDialogDataPtr vdp;
1176 RecT rcP;
1177
1178 hWinMain=(WindoW)ParentWindow(i);
1179
1180 if (!hWinMain) return;
1181
1182 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
1183
1184 if (vmp==NULL) return;
1185
1186 vdp = vmp->vdp;
1187 if (vdp == NULL) return;
1188
1189 if (vdp->UnDViewer==NULL) return;
1190
1191 temport=SavePort((WindoW)vdp->UnDViewer);
1192 Select (vdp->UnDViewer);
1193 ObjectRect(vdp->UnDViewer,&rcP);
1194 InvalRect(&rcP);
1195 RestorePort(temport);
1196 }
1197
1198 /*******************************************************************************
1199
1200 Function : ScalePosChoiceProc()
1201
1202 Purpose : modification of the scale position
1203
1204 Parameters : i; menu item
1205
1206 Return value : none
1207
1208 *******************************************************************************/
ScalePosChoiceProc(ChoicE i)1209 static void ScalePosChoiceProc(ChoicE i)
1210 {
1211 Int2 value;
1212 ViewerMainPtr vmp;
1213 WindoW hWinMain;
1214
1215 ViewerDialogDataPtr vdp;
1216
1217 hWinMain=(WindoW)ParentWindow(i);
1218
1219 if (!hWinMain) return;
1220
1221 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
1222
1223 if (vmp==NULL) return;
1224
1225 vdp = vmp->vdp;
1226 if (vdp == NULL) return;
1227
1228 value=GetValue(i);
1229 switch(value){
1230 case 1:/*Left only*/
1231 vdp->udv_graph.udv_scale.ScalePosition=SCALE_POS_LEFT;
1232 vdp->udv_graph.udv_scale.ShowMajorTick=FALSE;
1233 break;
1234 case 2:/*Top only*/
1235 vdp->udv_graph.udv_scale.ScalePosition=SCALE_POS_TOP;
1236 vdp->udv_graph.udv_scale.ShowMajorTick=TRUE;
1237 break;
1238 case 3:/*Top and left*/
1239 vdp->udv_graph.udv_scale.ScalePosition=SCALE_POS_BOTH;
1240 vdp->udv_graph.udv_scale.ShowMajorTick=TRUE;
1241 break;
1242 }
1243
1244 PanelOrgChange(vdp->UnDViewer,vdp);
1245 }
1246
1247 /*******************************************************************************
1248
1249 Function : ShowFeatProc()
1250
1251 Purpose : show/hide features
1252
1253 Parameters : i; menu item
1254
1255 Return value : none
1256
1257 *******************************************************************************/
ShowFeatProc(IteM i)1258 static void ShowFeatProc(IteM i)
1259 {
1260 ViewerMainPtr vmp;
1261 WindoW hWinMain;
1262 Boolean ShowFeatures;
1263 ViewerDialogDataPtr vdp;
1264
1265 hWinMain=(WindoW)ParentWindow(i);
1266
1267 if (!hWinMain) return;
1268
1269 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
1270
1271 if (vmp==NULL) return;
1272
1273 vdp = vmp->vdp;
1274 if (vdp == NULL) return;
1275
1276 ShowFeatures=GetStatus(i);
1277 vdp->udv_graph.udv_panel.ShowFeatures=ShowFeatures;
1278
1279 if (ShowFeatures==FALSE && vmp->hFeatDlg){
1280 Remove(vmp->hFeatDlg);
1281 vmp->hFeatDlg=NULL;
1282 SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
1283 }
1284 if (ShowFeatures==FALSE){
1285 Disable(vmp->MainMenu.ShowFeatureList);
1286 Disable(vmp->MainMenu.SearchForFeature);
1287 }
1288 else{
1289 Enable(vmp->MainMenu.ShowFeatureList);
1290 Enable(vmp->MainMenu.SearchForFeature);
1291 }
1292
1293 PanelOrgChange(vdp->UnDViewer,vdp);
1294 }
1295
1296 /*******************************************************************************
1297
1298 Function : PanelOrgChange()
1299
1300 Purpose : redraw window after some graph changes (show features, scale,...)
1301
1302 Parameters : w; handle of the viewer window
1303
1304 Return value : none
1305
1306 *******************************************************************************/
PanelOrgChange(PaneL p,ViewerDialogDataPtr vdp)1307 static void PanelOrgChange(PaneL p,ViewerDialogDataPtr vdp)
1308 {
1309 RecT rcP;
1310 BaR vsb;
1311 ValNodePtr vnp;
1312 ParaGPtr pgp;
1313 Int4 nLettre=-1;
1314 Int4 CurPos=0;
1315 Boolean ShowTop=FALSE,
1316 ShowTick=FALSE;
1317 WindoW temport;
1318
1319 if (vdp->ParaG == NULL) return;
1320
1321 temport=SavePort((WindoW)p);
1322
1323 Select (p);
1324 ObjectRect(p,&rcP);
1325
1326 /*current scroll status*/
1327 vsb = GetSlateVScrollBar ((SlatE) p);
1328 CurPos=GetBarValue(vsb);
1329 if (vdp->ParaG){
1330 for(vnp=vdp->ParaG ; vnp!=NULL ; vnp=vnp->next){
1331 if (vnp->data.ptrvalue){
1332 pgp=(ParaGPtr)vnp->data.ptrvalue;
1333 if (CurPos>=pgp->StartLine && CurPos<=(pgp->StartLine+
1334 pgp->nLines)){
1335 nLettre=pgp->StartLetter;
1336 break;
1337 }
1338 }
1339 }
1340 }
1341
1342 /*repos. ParaG - compute TotalLines*/
1343 if (vdp->udv_graph.udv_panel.ShowScale){
1344 if (vdp->udv_graph.udv_scale.ScalePosition==SCALE_POS_LEFT)
1345 ShowTop=FALSE;
1346 else ShowTop=TRUE;
1347
1348 if (vdp->udv_graph.udv_scale.ShowMajorTick)
1349 ShowTick=TRUE;
1350 else ShowTick=FALSE;
1351 }
1352 else{
1353 ShowTop=FALSE;
1354 ShowTick=FALSE;
1355 }
1356
1357
1358 UDV_ReLocateRcParaGList(/*vdp->udv_graph,*/rcP,
1359 ShowTop,ShowTick,TRUE,vdp->udv_graph.udv_panel.ShowFeatures,FALSE,
1360 &vdp->udv_graph.udv_panel.nTotLines,vdp->ParaG);
1361
1362 /*compute new Vscroll pos */
1363 if (vdp->ParaG){
1364 for(vnp=vdp->ParaG ; vnp!=NULL ; vnp=vnp->next){
1365 if (vnp->data.ptrvalue){
1366 pgp=(ParaGPtr)vnp->data.ptrvalue;
1367 if (nLettre>=pgp->StartLetter && nLettre<=pgp->StopLetter){
1368 CurPos=pgp->StartLine;
1369 break;
1370 }
1371 }
1372 }
1373 }
1374
1375 /*update the Vscroll Bar*/
1376 UnDViewerVScrlUpdatePage(&(vdp->udv_graph.udv_vscrl.ScrollPage),
1377 vdp->udv_graph.udv_panel.cyClient,
1378 vdp->udv_graph.udv_font.LineHeight);
1379 UnDViewerVScrlUpdate(p,FALSE,CurPos);
1380
1381 /*create new buffer*/
1382 UDV_create_buffer(&vdp->udv_graph,vdp->ParaG,&vdp->bsp_i,NULL,vdp->bDisplayRevComp);
1383
1384 /*Redraw*/
1385 InvalRect(&rcP);
1386 RestorePort(temport);
1387 }
1388
1389 /*******************************************************************************
1390
1391 Function : UDV_SetupMenus()
1392
1393 Purpose : create the menu of the main dialog box
1394
1395 Parameters : w; handle of the dialog box
1396
1397 Return value : none
1398
1399 *******************************************************************************/
UDV_SetupMenus(WindoW w,Boolean isEntrezOk,SAM_ViewGlobal * vgp)1400 NLM_EXTERN void UDV_SetupMenus(WindoW w,Boolean isEntrezOk,
1401 SAM_ViewGlobal *vgp)
1402 {
1403 MenU m,s; /*temp variable*/
1404 ChoicE c; /* " */
1405 ViewerMainPtr vmp;/*program data*/
1406 UdvGlobalsPtr ugp;
1407
1408 vmp = (ViewerMainPtr) GetObjectExtra (w);
1409 ugp=(UdvGlobalsPtr)GetAppProperty("UdvGlobals");
1410
1411 /*File menu*/
1412 m=PulldownMenu(w,"File");
1413 vmp->MainMenu.File=m;
1414
1415 if (vmp->AutonomeViewer){/*available only for the Auntonomous viewer*/
1416 s=SubMenu(m,"Open from ");
1417 vmp->MainMenu.FileOpen=CommandItem(s,"a local file...",
1418 UDV_FileOpen);
1419 vmp->MainMenu.EntrezOpen=CommandItem(s,"the network...",
1420 UDV_NetOpen);
1421 if (isEntrezOk==FALSE) Disable(vmp->MainMenu.EntrezOpen);
1422
1423 vmp->MainMenu.FileClose=CommandItem(m,"Close",UDV_FileClose);
1424 SeparatorItem(m);
1425 }
1426 vmp->MainMenu.ListSequence=
1427 CommandItem(m,"Sequence list...",UDV_CreateListBioseqDlg);
1428 SeparatorItem(m);
1429 vmp->MainMenu.QuitViewer=CommandItem(m,"Quit/Q",QuitProc);
1430
1431 if(vgp != NULL) {
1432 if(vgp->MasterViewer == SAMVIEWCN3D) {
1433 vmp->MainMenu.Align = PulldownMenu(w, "Align/A");
1434 vmp->MainMenu.AddRow = SubMenu(vmp->MainMenu.Align, "Add New Row");
1435 vmp->MainMenu.FromFile = SubMenu(vmp->MainMenu.AddRow, "From FASTA file");
1436 CommandItem(vmp->MainMenu.FromFile,
1437 "By gapped BLAST...", (Nlm_ItmActnProc)vgp->BlastFileGap);
1438 CommandItem(vmp->MainMenu.FromFile,
1439 "By ungapped BLAST...", (Nlm_ItmActnProc)vgp->BlastFile);
1440 if (vgp->NetStartProc) {
1441 vmp->MainMenu.FromNet = SubMenu(vmp->MainMenu.AddRow, "Download from Entrez");
1442 CommandItem(vmp->MainMenu.FromNet,
1443 "By gapped BLAST...", (Nlm_ItmActnProc)vgp->BlastNetGap);
1444 CommandItem(vmp->MainMenu.FromNet,
1445 "By ungapped BLAST...", (Nlm_ItmActnProc)vgp->BlastNet);
1446 /* vmp->MainMenu.BlastMany = CommandItem(vmp->MainMenu.Align,
1447 "Blast...", (Nlm_ItmActnProc)vgp->BlastMany); */
1448 }
1449 }
1450 }
1451
1452
1453 /*Options menu*/
1454 m=PulldownMenu(w,"Options");
1455 vmp->MainMenu.Options=m;
1456 vmp->MainMenu.ShowFeature=StatusItem(m,"Show features",
1457 ShowFeatProc);
1458 SetStatus(vmp->MainMenu.ShowFeature,TRUE);
1459 if(vgp == NULL) {
1460 vmp->MainMenu.ShowFeatureList=StatusItem(m,"Features List...",
1461 ShowFeaturesListDlg);
1462 SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
1463 vmp->MainMenu.SearchForFeature=CommandItem(m,"Search for features...",
1464 UDV_SearchFeatForKey);
1465 SeparatorItem(m);
1466 }
1467
1468 if(vgp == NULL) {
1469 vmp->MainMenu.ShowRevComp=StatusItem(m,"Show reverse complement",
1470 UDV_ShowReverseComplement);
1471 SeparatorItem(m);
1472 }
1473 vmp->MainMenu.ScalePos=SubMenu(m,"Scale position");
1474
1475 c=ChoiceGroup(vmp->MainMenu.ScalePos,ScalePosChoiceProc);
1476 ChoiceItem(c,"Left only");
1477 ChoiceItem(c,"Top only");
1478 ChoiceItem(c,"Top and left");
1479 SetValue(c,3);
1480 vmp->MainMenu.ScalePosChoice=c;
1481 SeparatorItem(m);
1482 vmp->MainMenu.RefreshScreen=CommandItem(m,"Refresh screen",
1483 RefreshScreenProc);
1484 if (vmp->AutonomeViewer && ugp!=NULL && ugp->NetCfgMenuProc!=NULL){/*available only for the Auntonomous viewer*/
1485 vmp->MainMenu.ConfigNet=CommandItem(m,"Network...",ugp->NetCfgMenuProc);
1486 }
1487 #ifdef UDV_GENOME
1488 CommandItem(m,"Overview...",UDV_GenViewProc);
1489 #endif
1490 /*Help menu*/
1491 m=PulldownMenu(w,"Help");
1492 vmp->MainMenu.Help=m;
1493 vmp->MainMenu.HelpAbout=CommandItem(m,"About...",UDV_AboutProc);
1494 }
1495
1496 /*******************************************************************************
1497
1498 Function : WinMainMsgProc()
1499
1500 Purpose : Main dialog box answering loop
1501
1502 Parameters : d; handle of the dialog box
1503 mssg; message
1504
1505 Return value : none
1506
1507 *******************************************************************************/
1508 /*static void WinMainMsgProc (DialoG d, Int2 mssg)
1509
1510 {
1511 ViewerDialogDataPtr vdp;
1512 ViewerMainPtr vmp;
1513
1514 vmp = (ViewerMainPtr) GetObjectExtra (d);
1515 if (vmp==NULL) return;
1516
1517 vdp=vmp->vdp;
1518
1519 if (vdp != NULL) {
1520 switch (mssg) {
1521 case VIB_MSG_INIT :
1522 break;
1523 case VIB_MSG_CLOSE :
1524 Remove (d);
1525 break;
1526 default :
1527 break;
1528 }
1529 }
1530 }
1531 */
1532 /*******************************************************************************
1533
1534 Function : UDV_Resize_Logo_Panel()
1535
1536 Purpose : resize logo panel
1537
1538 Parameters : p; handle of the main window
1539 rcP; new rc of the logo panel
1540
1541 Return value : none (see rcP)
1542
1543 *******************************************************************************/
UDV_Resize_Logo_Panel(WindoW Parent,RecT PNTR rcL)1544 NLM_EXTERN void UDV_Resize_Logo_Panel (WindoW Parent,RecT PNTR rcL)
1545 {
1546 RecT rcDlg;
1547
1548 /*size of the parent Window of the Panel*/
1549 ObjectRect(Parent,&rcDlg);
1550
1551 /*new size of the Logo Panel*/
1552 LoadRect (rcL, (Int2)4*VIEWER_HORZ_MARGIN, (Int2)4*VIEWER_VERT_MARGIN,
1553 (Int2)(rcDlg.right - rcDlg.left - 4*VIEWER_HORZ_MARGIN),
1554 (Int2)(rcDlg.bottom - rcDlg.top - 4*VIEWER_VERT_MARGIN));
1555 }
1556
1557 /*******************************************************************************
1558
1559 Function : UDV_VSscroll()
1560
1561 Purpose : UnD Viewer Vertical Scroll Bar Callback
1562
1563 Parameters : p; viewer
1564 vdp; viewer data structure
1565 newval; new value of the thumb
1566 oldval; old value of the thumb
1567
1568 Note : this function MUST to be used by external software using the viewer.
1569
1570 Return value : none
1571
1572 *******************************************************************************/
UDV_VScroll(PaneL p,ViewerDialogDataPtr vdp,Int4 newval,Int4 oldval)1573 static void UDV_VScroll(PaneL p,ViewerDialogDataPtr vdp, Int4 newval,
1574 Int4 oldval)
1575 {
1576 RecT rcP;
1577 WindoW temport;
1578 Int4 n;
1579 Boolean IsGoUp=FALSE;
1580
1581 if (!vdp) return;
1582
1583 vdp->udv_graph.udv_vscrl.ScrollPos=newval;
1584
1585 temport=SavePort(ParentWindow((WindoW)p));
1586 Select(p);
1587 ObjectRect(p,&rcP);
1588 InsetRect(&rcP,4,4);
1589 ClipRect(&rcP);
1590
1591 if (oldval>newval){
1592 n=oldval-newval;
1593 IsGoUp=TRUE;
1594 }
1595 else {
1596 n=newval-oldval;
1597 IsGoUp=FALSE;
1598 }
1599
1600 if (n<vdp->udv_graph.udv_vscrl.ScrollPage){/*Line UP/Down*/
1601 /*Create a new Buffer ?*/
1602 UDV_analyse_buffer(&vdp->udv_graph,vdp->ParaG,&vdp->bsp_i,
1603 (Uint2)(IsGoUp==TRUE ? BUFFER_REPOP_VCRL_LUP :
1604 BUFFER_REPOP_VCRL_LDN),vdp->bDisplayRevComp);
1605
1606 /*move and redraw*/
1607 ScrollRect (&rcP, 0, (Int2)((oldval-newval)*
1608 vdp->udv_graph.udv_font.LineHeight));
1609 }
1610 else{/*Page Up/Down*/
1611 /*Create a new Buffer ?*/
1612 UDV_analyse_buffer(&vdp->udv_graph,vdp->ParaG,&vdp->bsp_i,
1613 (Uint2)(IsGoUp==TRUE ? BUFFER_REPOP_VCRL_PUP :
1614 BUFFER_REPOP_VCRL_PDN),vdp->bDisplayRevComp);
1615
1616 /*redraw*/
1617 /*rcP.left=0;
1618 rcP.top=0;*/
1619 InvalRect(&rcP);
1620 }
1621 ResetClip();
1622 RestorePort(temport);
1623 Update ();
1624 }
1625
1626 /*******************************************************************************
1627
1628 Function : UnDViewerVScrlProc()
1629
1630 Purpose : UnD Viewer Vertical Scroll Bar Callback
1631
1632 Parameters : sb; handle of the scroll
1633 s; pane;
1634 newval; new value of the thumb
1635 oldval; old value of the thumb
1636
1637 Return value : none
1638
1639 *******************************************************************************/
UnDViewerVScrlProc(BaR sb,SlatE s,Int4 newval,Int4 oldval)1640 NLM_EXTERN void UnDViewerVScrlProc (BaR sb, SlatE s, Int4 newval,
1641 Int4 oldval)
1642 {
1643 ViewerDialogDataPtr vdp;
1644
1645 /*get the parent Window of the Panel*/
1646 /*
1647 w=ParentWindow(s);
1648
1649 if (w==NULL) return;
1650 */
1651
1652 /*get some usefull data...*/
1653 /*
1654 vmp = (ViewerMainPtr) GetObjectExtra (w);
1655 if (vmp==NULL) return;
1656
1657 vdp=vmp->vdp;
1658 */
1659 vdp = (ViewerDialogDataPtr) GetObjectExtra (s);
1660
1661 UDV_VScroll((PaneL)s,vdp,newval,oldval);
1662 }
1663
1664 /*******************************************************************************
1665
1666 Function : UnDViewerVScrlUpdatePage()
1667
1668 Purpose : compute PageUp & Down (VScroll)
1669
1670 Parameters : PageUpDn; initialize here
1671 cyClient; height of UnDviewer panel
1672 LineHeight; height of one data line
1673
1674 Return value : none
1675
1676 *******************************************************************************/
UnDViewerVScrlUpdatePage(Int4Ptr PageUpDn,Int2 cyClient,Int2 LineHeight)1677 static void UnDViewerVScrlUpdatePage(Int4Ptr PageUpDn,Int2 cyClient,
1678 Int2 LineHeight)
1679 {
1680 *PageUpDn=(Int4)(cyClient/LineHeight);
1681 }
1682
1683 /*******************************************************************************
1684
1685 Function : UnDViewerVScrlUpdate()
1686
1687 Purpose : update the UnDviewer VScroll bar
1688
1689 Parameters : p; handel of the UnDviewer panel
1690 bInit; TRUE only when the UnDviewer is created (soft. start up)
1691 CurPos ; new position
1692
1693 Return value : none
1694
1695 *******************************************************************************/
UnDViewerVScrlUpdate(PaneL p,Boolean bInit,Int4 CurPos)1696 NLM_EXTERN void UnDViewerVScrlUpdate(PaneL p,Boolean bInit,Int4 CurPos)
1697 {
1698 BaR vsb;
1699 ViewerDialogDataPtr vdp;
1700
1701 /*get some usefull data...*/
1702 vdp = (ViewerDialogDataPtr) GetObjectExtra (p);
1703 if (vdp == NULL) return;
1704
1705 /*current scroll status*/
1706 vsb = GetSlateVScrollBar ((SlatE) p);
1707
1708 if (bInit) CurPos=0;
1709
1710 /*given curpos (lineNumber) retrieve letter number*/
1711
1712 /*compute new values*/
1713 UnDViewerVScrlUpdatePage(&(vdp->udv_graph.udv_vscrl.ScrollPage),
1714 vdp->udv_graph.udv_panel.cyClient,
1715 vdp->udv_graph.udv_font.LineHeight);
1716 if (vdp->udv_graph.udv_panel.nTotLines>vdp->udv_graph.udv_vscrl.ScrollPage){
1717 vdp->udv_graph.udv_vscrl.ScrollMax=vdp->udv_graph.udv_panel.nTotLines-
1718 vdp->udv_graph.udv_vscrl.ScrollPage;
1719 }
1720 else{
1721 vdp->udv_graph.udv_vscrl.ScrollMax=0;
1722 vdp->udv_graph.udv_vscrl.ScrollPos=0;
1723 vdp->udv_graph.udv_vscrl.ScrollPage=0;
1724 }
1725
1726 if (CurPos<0) CurPos=0;
1727
1728 if (CurPos>=vdp->udv_graph.udv_vscrl.ScrollMax)
1729 vdp->udv_graph.udv_vscrl.ScrollPos=vdp->udv_graph.udv_vscrl.ScrollMax;
1730 else vdp->udv_graph.udv_vscrl.ScrollPos=CurPos;
1731
1732 /*update scroll*/
1733 CorrectBarMax(vsb,vdp->udv_graph.udv_vscrl.ScrollMax);
1734 CorrectBarValue(vsb,vdp->udv_graph.udv_vscrl.ScrollPos);
1735 CorrectBarPage(vsb,vdp->udv_graph.udv_vscrl.ScrollPage,
1736 vdp->udv_graph.udv_vscrl.ScrollPage);
1737
1738 }
1739
1740 /*******************************************************************************
1741
1742 Function : UDV_resize_viewer()
1743
1744 Purpose : viewer Resize function
1745
1746 Parameters : p; handle of the viewer panel
1747 vdp; viewer data structure
1748
1749 Return value : none
1750
1751 *******************************************************************************/
UDV_resize_viewer(PaneL p,ViewerDialogDataPtr vdp)1752 NLM_EXTERN void UDV_resize_viewer(PaneL p,ViewerDialogDataPtr vdp)
1753 {
1754 BaR vsb;
1755 ValNodePtr vnp;
1756 ParaGPtr pgp;
1757 Int4 nLettre=-1;
1758 Int4 CurPos=0;
1759 Boolean ShowTop=TRUE;
1760 Boolean ShowTick=TRUE;
1761 RecT rcP;
1762 WindoW temport;
1763
1764 if (vdp->ParaG == NULL) return;
1765
1766 ObjectRect(p,&rcP);
1767 temport=SavePort(ParentWindow(p));
1768 Select(p);
1769
1770 /*Update UnDviewer's panel size values*/
1771 UDV_ComputePanelSize(rcP,&(vdp->udv_graph.udv_panel.cxClient),
1772 &(vdp->udv_graph.udv_panel.cyClient));
1773
1774 /*block lines*/
1775 UDV_ComputeBlockByLine(vdp->udv_graph.udv_panel.cxClient,
1776 vdp->udv_graph.udv_panel.cxName,
1777 vdp->udv_graph.udv_scale.cxLeftScale,
1778 vdp->udv_graph.udv_font.cxChar,
1779 &vdp->udv_graph.udv_panel.nCharByLine,
1780 &vdp->udv_graph.udv_panel.nBlockByLine);
1781
1782 /*current scroll status*/
1783 vsb = GetSlateVScrollBar ((SlatE) p);
1784 CurPos=GetBarValue(vsb);
1785 if (vdp->ParaG){
1786 for(vnp=vdp->ParaG ; vnp!=NULL ; vnp=vnp->next){
1787 if (vnp->data.ptrvalue){
1788 pgp=(ParaGPtr)vnp->data.ptrvalue;
1789 if (CurPos>=pgp->StartLine && CurPos<=(pgp->StartLine+
1790 pgp->nLines)){
1791 nLettre=pgp->StartLetter;
1792 break;
1793 }
1794 }
1795 }
1796 }
1797
1798 /*securite*/
1799 if (vdp->udv_graph.udv_panel.nBlockByLine<1){
1800 /*WindoW temport = SavePort(ParentWindow(vdp->UnDViewer));
1801 Select (vdp->UnDViewer);*/
1802 InvalRect(&rcP);
1803 RestorePort (temport);
1804 Update();
1805 return;
1806 }
1807
1808 /*repos. ParaG - compute TotalLines*/
1809 if (vdp->udv_graph.udv_panel.ShowScale){
1810 if (vdp->udv_graph.udv_scale.ScalePosition==SCALE_POS_LEFT)
1811 ShowTop=FALSE;
1812 else ShowTop=TRUE;
1813
1814 if (vdp->udv_graph.udv_scale.ShowMajorTick)
1815 ShowTick=TRUE;
1816 else ShowTick=FALSE;
1817 }
1818 else{
1819 ShowTop=FALSE;
1820 ShowTick=FALSE;
1821 }
1822
1823 /*total lines in the viewer*/
1824 vdp->ParaG=UDV_CreateParaGList(vdp->udv_graph.udv_panel.nCharByLine,
1825 vdp->bsp_i.bspLength,0,vdp->bsp_i.bspLength-1,
1826 ShowTop,ShowTick,TRUE,FALSE,&vdp->udv_graph.udv_panel.nTotLines,
1827 vdp->ParaG);
1828
1829 if (vdp->ParaG) UDV_PopulateParaGFeatures(/*vdp->udv_graph,*/vdp->bsp_i.bsp,
1830 vdp->ParaG,vdp->udv_graph.udv_panel.ShowFeatures,
1831 /*rcP,*/&vdp->udv_graph.udv_panel.nTotLines,
1832 vdp->udv_graph.DisplayOptions,NULL);
1833
1834 /*compute new Vscroll pos */
1835 if (vdp->ParaG){
1836 for(vnp=vdp->ParaG ; vnp!=NULL ; vnp=vnp->next){
1837 if (vnp->data.ptrvalue){
1838 pgp=(ParaGPtr)vnp->data.ptrvalue;
1839 if (nLettre>=pgp->StartLetter && nLettre<=pgp->StopLetter){
1840 CurPos=pgp->StartLine;
1841 break;
1842 }
1843 }
1844 }
1845 }
1846
1847 /*update the Vscroll Bar*/
1848 UnDViewerVScrlUpdate(p,FALSE,CurPos);
1849
1850 /*create new buffer*/
1851 UDV_create_buffer(&vdp->udv_graph,vdp->ParaG,&vdp->bsp_i,NULL,vdp->bDisplayRevComp);
1852 InvalRect(&rcP);
1853 RestorePort(temport);
1854 Update();
1855 }
1856
1857
1858 /*******************************************************************************
1859
1860 Function : UDV_WinMainResize()
1861
1862 Purpose : Main Dialog Box Resize function
1863
1864 Parameters : w; handle of the dialog box
1865
1866 Return value : none
1867
1868 *******************************************************************************/
UDV_WinMainResize(WindoW w)1869 NLM_EXTERN void UDV_WinMainResize (WindoW w)
1870 {
1871 ViewerDialogDataPtr vdp;
1872 ViewerMainPtr vmp;
1873 RecT rcP,rcI,rcW;
1874 Int2 height,diff,gap,width;
1875
1876 vmp = (ViewerMainPtr) GetObjectExtra (w);
1877 if (vmp==NULL) return;
1878
1879 vdp=vmp->vdp;
1880
1881 if (vdp == NULL) return;
1882
1883 /*viewer not initialized; typically at the startup of the soft
1884 just draw the logo*/
1885 if (vdp->UnDViewer == NULL) return;
1886
1887 /*move UDV_Panel & InfoPanel*/
1888 ObjectRect(w,&rcW);
1889 width= rcW.right-rcW.left;
1890 height= rcW.bottom-rcW.top;
1891
1892 GetPosition(vmp->StatusGroup,&rcI);
1893 GetPosition(vdp->UnDViewer,&rcP);
1894 diff=rcI.bottom-rcI.top;
1895 gap=rcI.top-rcP.bottom;
1896 rcI.bottom = height - rcP.left;
1897 rcI.top = rcI.bottom - diff;
1898 rcI.right = width - rcI.left;
1899 rcP.right = width - rcP.left;
1900
1901 rcP.bottom = rcI.top - gap;
1902 SetPosition (vmp->StatusGroup, &rcI);
1903 SetPosition (vdp->InfoPanel, &rcI);
1904 SetPosition (vdp->UnDViewer, &rcP);
1905 AdjustPrnt (vdp->UnDViewer, &rcP, FALSE);
1906
1907 Update();
1908
1909 if (vdp->ParaG == NULL) return;
1910
1911 UDV_resize_viewer(vdp->UnDViewer,vdp);
1912 }
1913
1914 /*******************************************************************************
1915
1916 Function : UDV_init_bsp_forViewer()
1917
1918 Purpose : initialize a bsp to display it in the viewer
1919
1920 Parameters : w ; dialog box (parent window of the viewer)
1921 bsp; the bsp
1922 eID, iID, itype; identification of the BSP
1923 vdp; general data to store ParaG
1924
1925 Return value : none
1926
1927 *******************************************************************************/
UDV_init_bsp_forViewer(PaneL p,BioseqPtr bsp,Uint2 eID,Uint2 iID,Uint2 itype,ViewerDialogDataPtr vdp)1928 NLM_EXTERN Boolean UDV_init_bsp_forViewer(PaneL p,BioseqPtr bsp,Uint2 eID,
1929 Uint2 iID,Uint2 itype,ViewerDialogDataPtr vdp)
1930 {
1931 Boolean ShowTop=TRUE;
1932 Boolean ShowTick=TRUE;
1933 Boolean nRet=FALSE;
1934 RecT rcP;
1935 WindoW temport;
1936
1937 /*size of UDV_VIEWER*/
1938 temport=SavePort(ParentWindow(p));
1939 Select(p);
1940 ObjectRect(p,&rcP);
1941
1942 /*store BSP info*/
1943 vdp->bsp_i.bsp=bsp;
1944 UDV_ReadBspDataForViewer(&vdp->bsp_i);
1945 vdp->bsp_i.bsp_entityID=eID;
1946 vdp->bsp_i.bsp_itemID=iID;
1947 vdp->bsp_i.bsp_itemType=itype;
1948
1949 WatchCursor();
1950 /*
1951 mon = MonitorStrNewEx (szAppName, 30, FALSE);
1952 MonitorStrValue (mon, "Preparing display...");
1953 */
1954 Update ();
1955
1956 /*Populate ParaG - compute TotalLines*/
1957 if (vdp->udv_graph.udv_panel.ShowScale){
1958 if (vdp->udv_graph.udv_scale.ScalePosition==SCALE_POS_LEFT)
1959 ShowTop=FALSE;
1960 else ShowTop=TRUE;
1961
1962 if (vdp->udv_graph.udv_scale.ShowMajorTick)
1963 ShowTick=TRUE;
1964 else ShowTick=FALSE;
1965 }
1966 else{
1967 ShowTop=FALSE;
1968 ShowTick=FALSE;
1969 }
1970
1971 vdp->ParaG=UDV_CreateParaGList(vdp->udv_graph.udv_panel.nCharByLine,
1972 vdp->bsp_i.bspLength,0,vdp->bsp_i.bspLength-1,
1973 ShowTop,ShowTick,TRUE,FALSE,&vdp->udv_graph.udv_panel.nTotLines,
1974 vdp->ParaG);
1975
1976 if (vdp->ParaG) {
1977 UDV_PopulateParaGFeatures(vdp->bsp_i.bsp,vdp->ParaG,
1978 vdp->udv_graph.udv_panel.ShowFeatures,
1979 &vdp->udv_graph.udv_panel.nTotLines,vdp->udv_graph.DisplayOptions,
1980 NULL);
1981 }
1982 else {
1983 UDV_Init_vdp_struct(p,vdp,FALSE,TRUE,TRUE);
1984 nRet=FALSE;
1985 goto fin;
1986 }
1987
1988 /*update scroll*/
1989 UnDViewerVScrlUpdatePage(&(vdp->udv_graph.udv_vscrl.ScrollPage),
1990 vdp->udv_graph.udv_panel.cyClient,
1991 vdp->udv_graph.udv_font.LineHeight);
1992 UnDViewerVScrlUpdate(p,TRUE,0);
1993
1994 /*create sequence buffer*/
1995 UDV_create_buffer(&vdp->udv_graph,vdp->ParaG,&vdp->bsp_i,NULL,vdp->bDisplayRevComp);
1996
1997 /*redraw the viewer*/
1998 rcP.top=0;rcP.left=0;
1999 InvalRect(&rcP);
2000 Update();
2001 nRet=TRUE;
2002
2003 fin:
2004 RestorePort(temport);
2005 ArrowCursor();
2006 /*
2007 MonitorFree (mon);
2008 */
2009 return(nRet);
2010 }
2011
2012 /*******************************************************************************
2013
2014 Function : UDV_init_NonAutonomous()
2015
2016 Purpose : viewer panel creation for external software using the viewer
2017
2018 Parameters : vdp; viewer data block - allocated & initialized here
2019 p; viewer panel - MUST be not NULL
2020 f; font - MUST be not NULL
2021
2022 Note : 1. the external software MUST initialize p and f before entering this
2023 function
2024 2. the PaneL p MUST have a correct size : UDV_Init_GraphData() computes
2025 cxClient and cyClient used by the viewer to populate ParaG data blocks.
2026
2027 Return value : FALSE if failure
2028
2029 *******************************************************************************/
UDV_Init_NonAutonomous(PaneL p,ViewerDialogDataPtr PNTR vdp,FonT f)2030 NLM_EXTERN Boolean UDV_Init_NonAutonomous(PaneL p,ViewerDialogDataPtr PNTR vdp,
2031 FonT f)
2032 {
2033 /*init data structure*/
2034 (*vdp)=(ViewerDialogDataPtr)MemNew(sizeof(ViewerDialogData));
2035 if ((*vdp)){
2036 MemSet((*vdp),0,sizeof(ViewerDialogData));
2037 }
2038 else{
2039 Message (MSG_ERROR, "Viewer creation failed.");
2040 return(FALSE);
2041 }
2042
2043 (*vdp)->udv_graph.udv_font.hFnt=f;
2044
2045 /*init font size*/
2046 Select(p);
2047 SelectFont((*vdp)->udv_graph.udv_font.hFnt);
2048 UDV_FontDim(&((*vdp)->udv_graph.udv_font.cxChar),
2049 &((*vdp)->udv_graph.udv_font.cyChar));
2050
2051 /*compute Feature Color Palette*/
2052 (*vdp)->udv_graph.pClr=UDV_BuildFeatColorTable();
2053
2054 /*compute layout letters for NA and AA*/
2055 UDV_Build_NA_LayoutPalette(&(*vdp)->udv_graph);
2056 UDV_Build_AA_LayoutPalette(&(*vdp)->udv_graph);
2057
2058 (*vdp)->udv_graph.udv_font.LineHeight=
2059 UDV_ComputeLineHeight((*vdp)->udv_graph.udv_font.cyChar);
2060
2061 /*general graph data init; scale pos, etc.*/
2062 UDV_Init_GraphData((*vdp)->UnDViewer,&(*vdp)->udv_graph);
2063
2064 return(TRUE);
2065 }
2066
2067 /*******************************************************************************
2068
2069 Function : UDV_GotoBtnProc()
2070
2071 Purpose : manage the "Go To" button
2072
2073 *******************************************************************************/
UDV_GotoBtnProc(ButtoN g)2074 static void UDV_GotoBtnProc(ButtoN g)
2075 {
2076 WindoW w;
2077 ViewerMainPtr vmp;
2078 CharPtr szTmp;
2079 ValNodePtr vnp;
2080 Int4 iValue,old_ivalue,line_num,from_bsp,to_bsp,
2081 from_line,to_line;
2082 BaR vsb;
2083 Char szValue[20];
2084 Char szRange[100];
2085
2086 w=ParentWindow(g);
2087
2088 vmp=(ViewerMainPtr)GetObjectExtra(w);
2089
2090 if (vmp->vdp->ParaG==NULL)
2091 return;
2092
2093 GetTitle(vmp->gotoVal, szValue, 19);
2094 if (StringHasNoText (szValue)) {
2095 Message (MSG_OK, "Please enter a position");
2096 Select (vmp->gotoVal);
2097 return;
2098 }
2099
2100 szTmp=szValue;
2101 while(*szTmp){
2102 if (!IS_DIGIT(*szTmp)){
2103 Message (MSG_OK, "The value you entered is wrong.");
2104 Select (vmp->gotoVal);
2105 return;
2106 }
2107 szTmp++;
2108 }
2109
2110 iValue=atoi(szValue);
2111
2112 if (iValue>0 && iValue<=vmp->vdp->bsp_i.bspLength){
2113 vnp=UDV_GetLineNumGivenPos(vmp->vdp->ParaG,iValue-1,&line_num);
2114 if (line_num==(Int4)-1) return;
2115 UDV_GetCurrentDispRange(vmp->vdp,&from_bsp,&to_bsp,&from_line,&to_line);
2116 old_ivalue=vmp->vdp->udv_graph.GotoLetter;
2117 vmp->vdp->udv_graph.GotoLetter=iValue;
2118 if (line_num<from_line || line_num>to_line){
2119 vsb = GetSlateVScrollBar ((SlatE) vmp->vdp->UnDViewer);
2120 SetValue(vsb,line_num);
2121 }
2122 vmp->vdp->udt.action=UDV_INVAL_REGION;
2123 vmp->vdp->udt.status=UDV_SET_TIMER;
2124 vmp->vdp->udt.pos=iValue-1;
2125
2126 }
2127 else{
2128 sprintf(szRange,"Please enter a value in the range\n[1..%i].",
2129 vmp->vdp->bsp_i.bspLength);
2130 Select (vmp->gotoVal);
2131 Message (MSG_OK, szRange);
2132 }
2133 }
2134
UDVResetProc(PaneL p)2135 NLM_EXTERN void UDVResetProc (PaneL p)
2136
2137 {
2138 ViewerDialogDataPtr vdp;
2139
2140 vdp = (ViewerDialogDataPtr) GetObjectExtra (p);
2141 if (vdp == NULL) return;
2142 UDV_FreeVDPstruct (vdp, TRUE);
2143 }
2144
2145 /*******************************************************************************
2146
2147 Function : CreateMainControls()
2148
2149 Purpose : create the content of the main window
2150
2151 Parameters : w; parent main window
2152 vmp; main data structure
2153
2154 Return value : FALSE if failure
2155
2156 *******************************************************************************/
CreateMainControls(WindoW w,ViewerMainPtr vmp,SAM_ViewGlobal * vgp)2157 NLM_EXTERN Boolean CreateMainControls(WindoW w,ViewerMainPtr vmp,
2158 SAM_ViewGlobal *vgp)
2159 {
2160 GrouP g,StatusGroup;
2161 ButtoN gotoBtn;
2162 TexT gotoTxt;
2163 PrompT info;
2164 FonT hFnt;
2165 Int2 cxChar,cyChar,Margins;
2166 PaneL pnl;
2167
2168 vmp->vdp=(ViewerDialogDataPtr)MemNew(sizeof(ViewerDialogData));
2169 if (vmp->vdp==NULL)
2170 return(FALSE);
2171
2172 /*FonT & FonT size*/
2173 if (!UDV_InitFont(&(vmp->vdp->udv_graph.udv_font)))
2174 return(FALSE);
2175
2176 SelectFont(vmp->vdp->udv_graph.udv_font.hFnt);
2177 UDV_FontDim(&(vmp->vdp->udv_graph.udv_font.cxChar),
2178 &(vmp->vdp->udv_graph.udv_font.cyChar));
2179
2180 /*compute Feature Color Palette*/
2181 vmp->vdp->udv_graph.pClr=UDV_BuildFeatColorTable();
2182 UDV_Build_Other_Colors(&(vmp->vdp->udv_graph));
2183
2184 /*compute layout letters for NA and AA*/
2185 UDV_Build_NA_LayoutPalette(&(vmp->vdp->udv_graph));
2186 UDV_Build_AA_LayoutPalette(&(vmp->vdp->udv_graph));
2187
2188 vmp->vdp->udv_graph.udv_font.LineHeight=
2189 UDV_ComputeLineHeight(vmp->vdp->udv_graph.udv_font.cyChar);
2190
2191 #ifdef WIN_MAC
2192 hFnt = ParseFont ("Monaco, 9");
2193 #endif
2194
2195 #ifdef WIN_MSWIN
2196 hFnt = ParseFont ("Courier, 7");
2197 #endif
2198
2199 #ifdef WIN_MOTIF
2200 hFnt = ParseFont ("fixed, 12");
2201 #endif
2202
2203 SelectFont (hFnt);
2204 cxChar=MaxCharWidth();
2205 cyChar=LineHeight();
2206 g = HiddenGroup (w, 3, 0, NULL);
2207 gotoBtn = PushButton (g, "Go to:", UDV_GotoBtnProc);
2208 gotoTxt = DialogText (g, "0", (Int2)6, NULL);
2209
2210 g = HiddenGroup (w, 1, 0, NULL);
2211
2212 Margins=20*stdCharWidth;
2213
2214 if(vgp != NULL) {
2215 if(vgp->MasterViewer == SAMVIEWCN3D) {
2216 pnl = AutonomousPanel4 (g,
2217 vgp->Rect.right-vgp->Rect.left,
2218 vgp->Rect.bottom-vgp->Rect.top,
2219 UDV_draw_viewer,UnDViewerVScrlProc,NULL,
2220 sizeof(ViewerDialogDataPtr),NULL,NULL);
2221 }
2222 else {
2223 pnl = AutonomousPanel4 (g,
2224 (Int2)2*((screenRect.right-screenRect.left)-Margins)/3,
2225 (Int2)2*((screenRect.bottom-screenRect.top)-Margins)/3,
2226 UDV_draw_viewer,UnDViewerVScrlProc,NULL,
2227 sizeof(ViewerDialogDataPtr),NULL,NULL);
2228 }
2229 }
2230 else{
2231 pnl = AutonomousPanel4 (g,
2232 (Int2)2*((screenRect.right-screenRect.left)-Margins)/3,
2233 (Int2)2*((screenRect.bottom-screenRect.top)-Margins)/3,
2234 UDV_draw_viewer,UnDViewerVScrlProc,NULL,
2235 sizeof(ViewerDialogDataPtr),NULL,NULL);
2236 }
2237 SetObjectExtra (pnl, (Pointer) vmp->vdp, NULL);
2238 StatusGroup = HiddenGroup (w, 1, 0, NULL);
2239 info = StaticPrompt (StatusGroup, "Ready !", 0, 3*cyChar/2, hFnt, 'l');
2240
2241 if (pnl==NULL || gotoBtn==NULL || gotoTxt==NULL || info==NULL)
2242 return(FALSE);
2243
2244 SetPanelClick(pnl,UDV_ClickProc,
2245 UDV_DragProc,UDV_HoldProc,UDV_ReleaseProc);
2246 vmp->vdp->UDV_ms.Action_type=MS_ACTION_FEAT_NOTHING;
2247
2248 SetWindowTimer(w,UDV_TimerProc);
2249
2250 AlignObjects(ALIGN_RIGHT, (HANDLE) pnl, (HANDLE) StatusGroup, NULL);
2251
2252 vmp->gotoBtn=gotoBtn;
2253 vmp->gotoVal=gotoTxt;
2254 vmp->StatusGroup=StatusGroup;
2255 vmp->vdp->InfoPanel=info;
2256 vmp->vdp->UnDViewer=pnl;
2257 vmp->vdp->Parent=w;
2258
2259 return(TRUE);
2260 }
2261
2262 /*******************************************************************************
2263
2264 Function : UDV_InitForSequin()
2265
2266 Purpose : initialize udv data structure to start UDV from Sequin
2267
2268 Note : before entering this function, udvPanel must have a correct size
2269 (this is because this function calls UDV_Init_GraphData() ).
2270
2271 Return value : FALSE if failure
2272
2273 *******************************************************************************/
UDV_InitForSequin(PaneL udvPanel,BioseqViewPtr bvp)2274 NLM_EXTERN Boolean UDV_InitForSequin(PaneL udvPanel, BioseqViewPtr bvp)
2275 {
2276 ViewerDialogDataPtr vdp;
2277 Uint2 eID;
2278 Uint4 iID;
2279
2280 vdp=(ViewerDialogDataPtr)MemNew(sizeof(ViewerDialogData));
2281 if (vdp==NULL)
2282 return(FALSE);
2283
2284 vdp->bvp = bvp;
2285
2286 /*FonT & FonT size*/
2287 if (bvp != NULL && bvp->displayFont!=NULL){
2288 vdp->udv_graph.udv_font.hFnt = bvp->displayFont;
2289 }
2290 else{
2291 if (!UDV_InitFont(&(vdp->udv_graph.udv_font)))
2292 return(FALSE);
2293 }
2294
2295 SelectFont(vdp->udv_graph.udv_font.hFnt);
2296 UDV_FontDim(&(vdp->udv_graph.udv_font.cxChar),
2297 &(vdp->udv_graph.udv_font.cyChar));
2298
2299 /*compute Feature Color Palette*/
2300 vdp->udv_graph.pClr=UDV_BuildFeatColorTable();
2301 UDV_Build_Other_Colors(&(vdp->udv_graph));
2302
2303 /*compute layout letters for NA and AA*/
2304 UDV_Build_NA_LayoutPalette(&(vdp->udv_graph));
2305 UDV_Build_AA_LayoutPalette(&(vdp->udv_graph));
2306
2307 vdp->udv_graph.udv_font.LineHeight=
2308 UDV_ComputeLineHeight(vdp->udv_graph.udv_font.cyChar);
2309
2310 /*attach data to udvPanel*/
2311 SetObjectExtra (udvPanel, (Pointer) vdp, NULL);
2312
2313 /*set up the mouse callbacks*/
2314 SetPanelClick(udvPanel,UDV_ClickProc,
2315 UDV_DragProc,UDV_HoldProc,UDV_ReleaseProc);
2316
2317 /*save udvPanel handle*/
2318 vdp->UnDViewer=udvPanel;
2319
2320 /*general graph data init; scale pos, etc.*/
2321 UDV_Init_GraphData(vdp->UnDViewer,&vdp->udv_graph);
2322
2323 /*build the display*/
2324 eID = ObjMgrGetEntityIDForPointer (bvp->bsp);
2325 iID = GetItemIDGivenPointer (eID, OBJ_BIOSEQ, bvp->bsp);
2326 UDV_init_bsp_forViewer (bvp->udv, bvp->bsp, eID, iID, OBJ_BIOSEQ, vdp);
2327
2328 return(TRUE);
2329 }
2330
InitSelectUDV(ViewerDialogDataPtr vdp)2331 static void InitSelectUDV (ViewerDialogDataPtr vdp)
2332
2333 {
2334 Uint2 entityID;
2335 SelStructPtr sel;
2336
2337 if (vdp == NULL) return;
2338 entityID = vdp->bsp_i.bsp_entityID;
2339 for (sel = ObjMgrGetSelected (); sel != NULL; sel = sel->next) {
2340 if (entityID == sel->entityID && sel->itemtype == OBJ_SEQFEAT) {
2341 UDV_select_feature (vdp->UnDViewer, vdp, entityID,
2342 sel->itemID, TRUE);
2343 }
2344 }
2345 }
2346
PopulateUDV(BioseqViewPtr bvp)2347 static void PopulateUDV (BioseqViewPtr bvp)
2348
2349 {
2350 ViewerDialogDataPtr vdp;
2351
2352 if (bvp == NULL) return;
2353 UDV_InitForSequin (bvp->udv, bvp);
2354 vdp = (ViewerDialogDataPtr) GetObjectExtra (bvp->udv);
2355 InitSelectUDV (vdp);
2356 }
2357
ShowUDV(BioseqViewPtr bvp,Boolean show)2358 static void ShowUDV (BioseqViewPtr bvp, Boolean show)
2359
2360 {
2361 if (bvp == NULL) return;
2362 if (show) {
2363 SafeShow (bvp->udv);
2364 SafeShow (bvp->udvParentGrp);
2365 EnableDisableLegendItem (bvp, FALSE);
2366 SafeHide (bvp->findGeneGrp);
2367 SafeShow (bvp->clickMe);
2368 } else {
2369 SafeHide (bvp->udvParentGrp);
2370 SafeHide (bvp->udv);
2371 Reset (bvp->udv);
2372 SafeHide (bvp->styleControlGrp);
2373 SafeHide (bvp->scaleControlGrp);
2374 EnableDisableLegendItem (bvp, FALSE);
2375 SafeHide (bvp->findGeneGrp);
2376 SafeHide (bvp->docTxtControlGrp);
2377 SafeHide (bvp->modeControlGrp);
2378 SafeHide (bvp->clickMe);
2379 }
2380 }
2381
SelectUDV(BioseqViewPtr bvp,Uint2 selentityID,Uint4 selitemID,Uint2 selitemtype,SeqLocPtr region,Boolean select,Boolean scrollto)2382 static void SelectUDV (BioseqViewPtr bvp, Uint2 selentityID, Uint4 selitemID,
2383 Uint2 selitemtype, SeqLocPtr region,
2384 Boolean select, Boolean scrollto)
2385
2386 {
2387 OMMsgStruct omms;
2388 OMMsgStructPtr ommsp;
2389 OMUserData omud;
2390 ViewerDialogDataPtr vdp;
2391
2392 MemSet ((Pointer) &omms, 0, sizeof (OMMsgStruct));
2393 MemSet ((Pointer) &omud, 0, sizeof (OMUserData));
2394 ommsp = &omms;
2395 if (select) {
2396 ommsp->message = OM_MSG_SELECT;
2397 } else {
2398 ommsp->message = OM_MSG_DESELECT;
2399 }
2400 ommsp->entityID = selentityID;
2401 ommsp->itemID = selitemID;
2402 ommsp->itemtype = selitemtype;
2403 ommsp->region = (Pointer) region;
2404 ommsp->omuserdata = &omud;
2405 vdp = (ViewerDialogDataPtr) GetObjectExtra (bvp->udv);
2406 omud.userdata.ptrvalue = (Pointer) vdp;
2407 UDV_OM_MsgFunc (ommsp);
2408 }
2409
ResizeUDV(BioseqViewPtr bvp)2410 static void ResizeUDV (BioseqViewPtr bvp)
2411
2412 {
2413 ViewerDialogDataPtr vdp;
2414
2415 if (bvp == NULL) return;
2416 vdp = (ViewerDialogDataPtr) GetObjectExtra (bvp->udv);
2417 UDV_resize_viewer (bvp->udv, vdp);
2418 }
2419
2420 BioseqPageData udvPageData = {
2421 "Sequence", TRUE, TRUE, TRUE, FALSE, -1,
2422 PopulateUDV, ShowUDV, SelectUDV,
2423 NULL, NULL,
2424 NULL, NULL, ResizeUDV, NULL
2425 };
2426
UDV_SlaveQuit(WindoW w)2427 static void UDV_SlaveQuit(WindoW w)
2428 {
2429 Remove(w);
2430 }
2431
2432 /*******************************************************************************
2433
2434 Function : CreateUDVpanel()
2435
2436 Purpose : viewer panel creation ; only graphic strctures and panel itself
2437
2438 Parameters : w; parent main window
2439 vmp; main data structure
2440
2441 Return value : FALSE if failure
2442
2443 *******************************************************************************/
CreateUDVpanel(WindoW w,ViewerMainPtr PNTR vmp,SAM_ViewGlobal * vgp)2444 static Boolean CreateUDVpanel(WindoW w,ViewerMainPtr PNTR vmp,
2445 SAM_ViewGlobal *vgp)
2446 {
2447 ViewerDialogDataPtr vdp;
2448 WindoW hParent;
2449
2450 /*w==NULL; we have to build a child viewer*/
2451 /*w!=NULL; we deal with an autonomous viewer*/
2452 if (w==NULL){
2453 Int2 Margins;
2454
2455 *vmp=(ViewerMainPtr)MemNew(sizeof(ViewerMain));
2456 if (*vmp){
2457 MemSet(*vmp,0,sizeof(ViewerMain));
2458 }
2459 else{
2460 Message (MSG_ERROR, "Viewer creation failed.");
2461 return(FALSE);
2462 }
2463
2464 Margins=20*stdCharWidth;
2465 hParent = NULL;
2466 if(vgp != NULL) {
2467 if(vgp->MasterViewer == SAMVIEWCN3D) {
2468 hParent=DocumentWindow(vgp->Rect.left,vgp->Rect.top,
2469 (Int2)(-10),
2470 (Int2)(-10),
2471 szAppName,
2472 UDV_SlaveQuit,
2473 UDV_WinMainResize);
2474 }
2475 else {
2476 hParent=DocumentWindow(Margins,Margins,
2477 (Int2)(-10),
2478 (Int2)(-10),
2479 szAppName,
2480 UDV_SlaveQuit,
2481 UDV_WinMainResize);
2482 }
2483 }
2484 else {
2485 hParent=DocumentWindow(Margins,Margins,
2486 (Int2)(-10),
2487 (Int2)(-10),
2488 szAppName,
2489 UDV_SlaveQuit,
2490 UDV_WinMainResize);
2491 }
2492
2493 if (hParent==NULL){
2494 Message (MSG_ERROR, "Viewer creation failed.");
2495 MemFree((*vmp));
2496 return(FALSE);
2497 }
2498 w = hParent;
2499 (*vmp)->hWndMain=hParent;
2500 SetObjectExtra (hParent, (Pointer) *vmp, (FreeProc)UDV_WinMainCleanupExtraProc);
2501
2502 (*vmp)->AutonomeViewer=FALSE;
2503
2504 /*menus*/
2505 UDV_SetupMenus(hParent,FALSE, vgp);
2506 UDV_set_MainMenus(&((*vmp)->MainMenu),FALSE);
2507 UDV_set_MainControls(*vmp,FALSE);
2508 /*create the windows*/
2509 CreateMainControls(w,*vmp,vgp);
2510
2511 RealizeWindow(hParent);
2512 Show(hParent);
2513 }
2514 else {
2515 hParent=w;
2516 /*hide the logo panel; only fot the autonomous viewer variant*/
2517 if ((*vmp)->AutonomeViewer) (*vmp)->Show_logo=FALSE;
2518 }
2519
2520 vdp=(*vmp)->vdp;
2521
2522 /*general graph data init; scale pos, etc.*/
2523 UDV_Init_GraphData(vdp->UnDViewer,&vdp->udv_graph);
2524 return(TRUE);
2525 }
2526
2527
2528
2529 /*******************************************************************************
2530
2531 Function : UDV_create_buffer()
2532
2533 Purpose : create a sequence buffer for a specific bioseq
2534
2535 Parameters : vdp; general data
2536
2537 Return value : none
2538
2539 *******************************************************************************/
UDV_create_buffer(UnDViewerGraphDataPtr GrData,ValNodePtr ParaG_list,BspInfoPtr bsp_i,ValNodePtr StartScan,Boolean bReverse)2540 NLM_EXTERN void UDV_create_buffer(UnDViewerGraphDataPtr GrData,
2541 ValNodePtr ParaG_list,BspInfoPtr bsp_i,ValNodePtr StartScan,
2542 Boolean bReverse)
2543 {
2544 ParaGPtr pgp=NULL;
2545 ValNodePtr vnp=NULL,vnp2=NULL;
2546 Int4 start_seq=0,stop_seq=0,stop=0,nLength=0,StartBuf=0,StopBuf=0;
2547 SeqIdPtr sip;
2548
2549 if (StartScan==NULL) vnp=ParaG_list;
2550 else vnp=StartScan;
2551
2552 /*find the ParaG where ScrollPos is Located*/
2553 /*Find the end of the display; last PGP currently displayed*/
2554 if (GrData->udv_vscrl.ScrollMax){/*Vscroll ?*/
2555 for( ; vnp != NULL ; vnp=vnp->next){
2556 if (vnp->data.ptrvalue){
2557 pgp=(ParaGPtr)vnp->data.ptrvalue;
2558 if ((GrData->udv_vscrl.ScrollPos>=pgp->StartLine) &&
2559 (GrData->udv_vscrl.ScrollPos<=(pgp->StartLine+pgp->nLines))){
2560 start_seq=pgp->StartLetter;
2561 break;
2562 }
2563 }
2564 }
2565 }
2566 else{/*no Vscroll: buffer starts at the beginning of the Bioseq*/
2567 start_seq=0;
2568 }
2569
2570 /*Find the end of the display; last PGP currently displayed*/
2571 if (GrData->udv_vscrl.ScrollMax){/*Vscroll ?*/
2572 stop=MIN(GrData->udv_panel.nTotLines,
2573 GrData->udv_vscrl.ScrollPos+GrData->udv_vscrl.ScrollPage);
2574 for(vnp2=vnp ; vnp2 != NULL ; vnp2=vnp2->next){
2575 pgp=(ParaGPtr)vnp2->data.ptrvalue;
2576 if (pgp->StartLine+pgp->nLines>=stop){
2577 stop_seq=pgp->StopLetter;
2578 break;
2579 }
2580 }
2581 }
2582 else{/*no Vscroll: buffer ends at the end of the Bioseq*/
2583 stop_seq=bsp_i->bspLength;
2584 }
2585
2586 /*nb of char within a panel*/
2587 nLength=stop_seq-start_seq+1;
2588
2589 /*read sequence; buffer size: three panels*/
2590 StartBuf=MAX(0,start_seq-nLength);
2591 StopBuf=MIN(bsp_i->bspLength-1,StartBuf+3*nLength);
2592
2593 /*if same buffer, return*/
2594 if (bsp_i->StartBuf==StartBuf && bsp_i->StopBuf==StopBuf) return;
2595
2596 bsp_i->StartBuf=StartBuf;
2597 bsp_i->StopBuf=StopBuf;
2598 bsp_i->LengthBuf=bsp_i->StopBuf-bsp_i->StartBuf+1;
2599
2600 if (bsp_i->SeqBuf) MemFree(bsp_i->SeqBuf);
2601
2602 sip=SeqIdFindBest(bsp_i->bsp->id,0);
2603 if (sip==NULL) sip=bsp_i->bsp->id;
2604
2605 if (bReverse){
2606 bsp_i->SeqBuf=UDV_Read_SequenceEx (sip,
2607 bsp_i->bspLength-1-bsp_i->StopBuf,bsp_i->bspLength-1-bsp_i->StartBuf,
2608 (Boolean)(!bsp_i->bspMolNuc),bsp_i->LengthBuf,Seq_strand_minus);
2609 }
2610 else{
2611 bsp_i->SeqBuf=UDV_Read_Sequence (sip,bsp_i->StartBuf,bsp_i->StopBuf,
2612 (Boolean)(!bsp_i->bspMolNuc),bsp_i->LengthBuf);
2613 }
2614
2615 /*find the ParaG where bsp_i->StartBuf is Located*/
2616 if (StartScan==NULL) vnp=ParaG_list;
2617 else vnp=StartScan;
2618 for( ; vnp != NULL ; vnp=vnp->next){
2619 if (vnp->data.ptrvalue){
2620 pgp=(ParaGPtr)vnp->data.ptrvalue;
2621 if (pgp->StartLetter==bsp_i->StartBuf){
2622 bsp_i->PgpStartBuf=vnp;
2623 break;
2624 }
2625 }
2626 }
2627 }
2628
2629
2630 /*******************************************************************************
2631
2632 Function : UDV_analyse_buffer()
2633
2634 Purpose : adjust a buffer in response to VScroll action
2635
2636 Parameters : vdp; general data
2637
2638 Return value : none
2639
2640 *******************************************************************************/
UDV_analyse_buffer(UnDViewerGraphDataPtr GrData,ValNodePtr ParaG_list,BspInfoPtr bsp_i,Uint2 ActionType,Boolean bReverse)2641 static void UDV_analyse_buffer(UnDViewerGraphDataPtr GrData,
2642 ValNodePtr ParaG_list,BspInfoPtr bsp_i,Uint2 ActionType,
2643 Boolean bReverse)
2644 {
2645 ParaGPtr pgp=NULL;
2646 ValNodePtr vnp=NULL,vnp2=NULL;
2647 Int4 start_seq=0,stop_seq=0,stop=0;
2648
2649 if (ActionType==BUFFER_REPOP_VCRL_LUP ||
2650 ActionType==BUFFER_REPOP_VCRL_PUP){/*Vscroll Up*/
2651
2652 if (bsp_i->PgpStartBuf==NULL) vnp=ParaG_list;
2653 else vnp=bsp_i->PgpStartBuf;
2654
2655 /*find the ParaG where ScrollPos is Located*/
2656 /*Find the end of the display; last PGP currently displayed*/
2657 for( ; vnp != NULL ; vnp=vnp->next){
2658 if (vnp->data.ptrvalue){
2659 pgp=(ParaGPtr)vnp->data.ptrvalue;
2660 if ((GrData->udv_vscrl.ScrollPos>=pgp->StartLine) &&
2661 (GrData->udv_vscrl.ScrollPos<=(pgp->StartLine+pgp->nLines))){
2662 start_seq=pgp->StartLetter;
2663 break;
2664 }
2665 }
2666 }
2667
2668 if (start_seq<=bsp_i->StartBuf){
2669 UDV_create_buffer(GrData,ParaG_list,bsp_i,NULL,bReverse);
2670 return;
2671 }
2672 }
2673
2674 if (ActionType==BUFFER_REPOP_VCRL_LDN ||
2675 ActionType==BUFFER_REPOP_VCRL_PDN){/*Vscroll Down*/
2676
2677 if (bsp_i->PgpStartBuf==NULL) vnp=ParaG_list;
2678 else vnp=bsp_i->PgpStartBuf;
2679
2680 /*find the last ParaG located in the panel*/
2681
2682 stop=MIN(GrData->udv_panel.nTotLines,
2683 GrData->udv_vscrl.ScrollPos+GrData->udv_vscrl.ScrollPage);
2684 for(vnp2=vnp; vnp2 != NULL ; vnp2=vnp2->next){
2685 pgp=(ParaGPtr)vnp2->data.ptrvalue;
2686 if (pgp->StartLine+pgp->nLines>=stop){
2687 stop_seq=pgp->StopLetter;
2688 break;
2689 }
2690 }
2691 if (stop_seq>=bsp_i->StopBuf-GrData->udv_panel.nCharByLine){
2692 UDV_create_buffer(GrData,ParaG_list,bsp_i,vnp,bReverse);
2693 }
2694 }
2695 }
2696
2697
2698 /*******************************************************************************
2699
2700 Function : UDV_ReLocateRcParaGList()
2701
2702 Purpose : relocate RecT (position) of each ParaG in the list. This function
2703 is generally called in response to a Scale change (top, left, etc)
2704 or to Show Features change (on/off)
2705
2706 Parameters : GrData; graphical data
2707 rcP; size and position of the UnD viewer's panel
2708 ShowTop; show scale on top if TRUE
2709 ShowTick; show scale's ticks if TRUE
2710 ShowSequence; show sequence if TRUE
2711 ShowFeature; show features if TRUE
2712 ShowBlank; add blank line at the bottom of the ParaG
2713 nTotL; total number of single lines for the whole ParaG list
2714 ParaG_head; head of the ParaG list
2715
2716 Note : This function
2717 is generally called in response to a Scale change (top, left, etc)
2718 or to Show Features change (on/off).
2719
2720 Return value : none (see nTotL)
2721
2722 *******************************************************************************/
UDV_ReLocateRcParaGList(RecT rcP,Boolean ShowTop,Boolean ShowTick,Boolean ShowSequence,Boolean ShowFeatures,Boolean ShowBlank,Int4Ptr nTotL,ValNodePtr ParaG_head)2723 static void UDV_ReLocateRcParaGList(/*UnDViewerGraphData GrData,*/
2724 RecT rcP,
2725 Boolean ShowTop,Boolean ShowTick,Boolean ShowSequence,
2726 Boolean ShowFeatures,
2727 Boolean ShowBlank,Int4Ptr nTotL,ValNodePtr ParaG_head)
2728 {
2729 ValNodePtr vnp; /*just for ParaG list scanning*/
2730 Int1 minLineByParaG=0; /*min height of a paraG, nb. of lines*/
2731 Int4 nTotLines=0; /*Total lines in viewer*/
2732 ParaGPtr pgp=NULL; /*ParaG data*/
2733
2734 if (ParaG_head == NULL) {*nTotL=0;return;}
2735
2736 /*Minimum ParaG height*/
2737 if (ShowTop) minLineByParaG++;
2738 if (ShowTick) minLineByParaG++;
2739 if (ShowSequence) minLineByParaG++;
2740 if (ShowBlank) minLineByParaG++;
2741
2742 /*modify the RecT of each ParaG*/
2743 for(vnp=ParaG_head ; vnp!=NULL ; vnp=vnp->next){
2744 pgp=(ParaGPtr)vnp->data.ptrvalue;
2745 /*modify in each ParaG just the needed*/
2746 pgp->StartLine=nTotLines;
2747 pgp->nLines=minLineByParaG;
2748
2749 if (ShowFeatures) {
2750 /*nLines=pgp->nFeat+pgp->nTrans;*/
2751 pgp->nLines+=pgp->nFeatLines;/*nLines;*/
2752 }
2753
2754 /*modify values*/
2755 if (ShowFeatures) nTotLines+=pgp->nLines;
2756 else nTotLines+=minLineByParaG;
2757 }
2758
2759 *nTotL=nTotLines;
2760 }
2761
2762 /*******************************************************************************
2763
2764 Function: FeaturesListBoxScan()
2765
2766 Purpose: scan features to retrieve the index of a seleted feature. This callback
2767 is used when the user clicks a feature on the UnDviewer panel while the
2768 Feature List Dialog Box is opened.
2769
2770 Parameters: see explore.h
2771
2772 *******************************************************************************/
FeaturesListBoxScan(SeqFeatPtr sfp,SeqMgrFeatContextPtr context)2773 static Boolean LIBCALLBACK FeaturesListBoxScan (SeqFeatPtr sfp,
2774 SeqMgrFeatContextPtr context)
2775 {
2776 ScanFeatPtr sf=(ScanFeatPtr)context->userdata;
2777
2778 if(sf){
2779 sf->index++;
2780 if (sf->eID==context->entityID && sf->iID==context->itemID){
2781 return(FALSE);
2782 }
2783 }
2784 return(TRUE);
2785 }
2786
2787
2788
2789 /*******************************************************************************
2790
2791 Function: FLB_OnDraw()
2792
2793 Purpose: Owner Draw Features List box drawing procedure.
2794
2795 Parameter: mid; entry data to draw.
2796
2797 Return value: -
2798
2799 *******************************************************************************/
FLB_OnDraw(MIDataPtr mid)2800 static void FLB_OnDraw(MIDataPtr mid)
2801 {
2802 RecT rc;
2803 Char szTmp[255]={""};
2804 FLDataPtr fldp=(FLDataPtr)mid->Data;
2805
2806 if (fldp==NULL) return;
2807
2808 rc=mid->rcItem;
2809 InsetRect(&rc,3,1);
2810 rc.left+=mid->cxChar/2;
2811 /*mid->rcItem.right=rc.right;*/
2812 /*selection ?*/
2813 if (mid->Selected){
2814 SetColor(GetColorRGB(0,0,128));
2815 PaintRect(&rc);
2816 White();
2817 }
2818 else{
2819 White();
2820 PaintRect(&rc);
2821 Black();
2822 }
2823 mid->rcItem.bottom-=(mid->cyChar/3);
2824 /*draw features elements*/
2825 SelectFont(mid->f);
2826 MoveTo(mid->rcItem.left,(Int2)(mid->rcItem.bottom-mid->cyChar));
2827 sprintf(szTmp,"%5d.",fldp->num);
2828 PaintString(szTmp);
2829 if (mid->Selected) White();
2830 else Blue();
2831 MoveTo((Int2)(mid->rcItem.left+7*mid->cxChar),
2832 (Int2)(mid->rcItem.bottom-mid->cyChar));
2833 PaintString("Name :");
2834 if (!mid->Selected) Black();
2835 sprintf(szTmp,"%s",fldp->szComment);
2836 MoveTo((Int2)(mid->rcItem.left+14*mid->cxChar),
2837 (Int2)(mid->rcItem.bottom-mid->cyChar));
2838 PaintString(szTmp);
2839
2840 if (fldp->segments>1){
2841 sprintf(szTmp,"%s [from %d to %d in %d segments]. Length: %d.",
2842 fldp->szType,fldp->from+1,fldp->to+1,
2843 fldp->segments,fldp->to-fldp->from+1);
2844 }
2845 else{
2846 sprintf(szTmp,"%s [from %d to %d]. Length: %d.",
2847 fldp->szType,fldp->from+1,fldp->to+1,fldp->to-fldp->from+1);
2848 }
2849 if (!mid->Selected) SetColor(GetColorRGB(0,128,0));
2850 MoveTo((Int2)(mid->rcItem.left+8*mid->cxChar),mid->rcItem.bottom);
2851 PaintString("Info :");
2852 if (!mid->Selected) Black();
2853
2854 MoveTo((Int2)(mid->rcItem.left+15*mid->cxChar),mid->rcItem.bottom);
2855 PaintString(szTmp);
2856 LtGray();
2857 mid->rcItem.bottom+=(mid->cyChar/3);
2858 MoveTo(rc.left,mid->rcItem.bottom);
2859 LineTo(rc.right,mid->rcItem.bottom);
2860 Black();
2861 }
2862
2863 /*******************************************************************************
2864
2865 Function: FeatListlBoxProc()
2866
2867 Purpose: Owner Draw Features List box callback function.
2868
2869 Parameter: mid; entry data to draw.
2870
2871 Return value: -
2872
2873 *******************************************************************************/
FeatListlBoxProc(WindoW lbox,Int2 msg,Pointer data)2874 static Boolean FeatListlBoxProc(WindoW lbox,Int2 msg,Pointer data)
2875 {
2876 MIDataPtr mid=(MIDataPtr)data;
2877
2878 if (mid==NULL) return(TRUE);
2879
2880 switch(msg){
2881 case ODLB_DrawItem:{
2882 WindoW temport;
2883 temport=SavePort(ParentWindow(lbox));
2884 Select(lbox);
2885 /*ClipRect(&mid->rcP);*/
2886 FLB_OnDraw(mid);
2887 /*ResetClip();*/
2888 RestorePort(temport);
2889 break;
2890 }
2891 case ODLB_MeasureItem:{
2892
2893 mid->rcItem.left=mid->rcP.left;
2894 mid->rcItem.right=mid->rcP.right;
2895 mid->rcItem.top=0;
2896 mid->rcItem.bottom=5*mid->cyChar/2;
2897
2898 break;
2899 }
2900 case ODLB_SelectItem:{
2901 ViewerMainPtr vmp;
2902 FLMDataPtr pflm;
2903 FLDataPtr fldp=(FLDataPtr)mid->Data;
2904
2905 pflm=(FLMDataPtr)GetObjectExtra(mid->Parent);
2906 if (pflm==NULL) break;
2907 vmp=(ViewerMainPtr)GetObjectExtra(pflm->hWndMain);
2908 if (vmp==NULL) break;
2909 if (fldp==NULL) break;
2910 vmp->vdp->ClickFeatFromDlg=TRUE;
2911 ObjMgrSelect(fldp->eID,fldp->iID,OBJ_SEQFEAT,0,NULL);
2912 break;
2913 }
2914 }
2915 return(TRUE);
2916 }
2917
2918 /*******************************************************************************
2919
2920 Function : FeatListDlgQuit()
2921
2922 Purpose : end of prog Features List Dialog Box
2923
2924 Parameters : w; Dialog Box window handle
2925
2926 Return value : none
2927
2928 *******************************************************************************/
2929
FeatListDlgQuit(WindoW w)2930 static void FeatListDlgQuit(WindoW w)
2931 {
2932 FLMDataPtr pflm;
2933 ViewerMainPtr vmp;
2934
2935 pflm = (FLMDataPtr) GetObjectExtra (w);
2936 if (!pflm) return;
2937
2938 vmp = (ViewerMainPtr) GetObjectExtra (pflm->hWndMain);
2939
2940 if (vmp==NULL) return;
2941
2942 SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
2943 Remove(w);
2944 vmp->hFeatDlg=NULL;
2945 }
2946
2947
2948 /*******************************************************************************
2949
2950 Function : FeatListDlgProc()
2951
2952 Purpose : Features List Dialog Box Resize function
2953
2954 Parameters : w; handle of the dialog box
2955
2956 Return value : none
2957
2958 *******************************************************************************/
FeatListDlgProc(WindoW w)2959 static void FeatListDlgProc (WindoW w)
2960 {
2961 RecT rcDlg,rc;
2962 FLMDataPtr pflm;
2963
2964 Select(w);
2965 ObjectRect(w,&rcDlg);
2966
2967 pflm = (FLMDataPtr) GetObjectExtra (w);
2968 if (!pflm) return;
2969 if (pflm->gFeatClass){
2970 ObjectRect(pflm->gFeatClass,&rc);
2971 rc.bottom+=3;
2972 }
2973 else rc.bottom=10;
2974
2975 OwnerDrawLbox_MoveWindow(pflm->lbox,10,rc.bottom,
2976 (Int2)(rcDlg.right-rcDlg.left-20),
2977 (Int2)(rcDlg.bottom-rcDlg.top-10-rc.bottom));
2978 }
2979
2980 /*******************************************************************************
2981
2982 Function: UDV_FeaturesListBoxFind()
2983
2984 Purpose: feature selection
2985
2986 Parameters: see explore.h
2987
2988 *******************************************************************************/
UDV_FeaturesListBoxFind(SeqFeatPtr sfp,SeqMgrFeatContextPtr context)2989 NLM_EXTERN Boolean LIBCALLBACK UDV_FeaturesListBoxFind (SeqFeatPtr sfp,
2990 SeqMgrFeatContextPtr context)
2991 {
2992 ScanFeatForSelectPtr sffs;
2993
2994
2995 sffs=(ScanFeatForSelectPtr)context->userdata;
2996
2997 sffs->compteur++;
2998
2999 if (sffs->eID==context->entityID && sffs->iID==context->itemID){
3000 sffs->index=sffs->compteur;
3001 return(FALSE);
3002 }
3003
3004 return(TRUE);
3005 }
3006
3007 /*******************************************************************************
3008
3009 Function: FeaturesListBoxInit()
3010
3011 Purpose: retrieve features for Features List Box
3012
3013 Parameters: see explore.h
3014
3015 *******************************************************************************/
FeaturesListBoxInit(SeqFeatPtr sfp,SeqMgrFeatContextPtr context)3016 static Boolean LIBCALLBACK FeaturesListBoxInit (SeqFeatPtr sfp,
3017 SeqMgrFeatContextPtr context)
3018 {
3019 FLDataPtr fldp;
3020 ScanFeatForSelectPtr sffs;
3021
3022 /* for test only
3023 if (context->seqfeattype==SEQFEAT_HET){
3024 Char str [256];
3025 int i;
3026
3027 if (FeatDefLabel (sfp, str, sizeof (str) - 1, OM_LABEL_BOTH)) {
3028 printf ( " Feature item %d index %d (%d) (%d - %d) (%d) %s\n",
3029 (int) context->itemID, (int) context->index,
3030 (int) context->numivals,(int) context->left,
3031 (int) context->right,(int) context->strand,str);
3032 if (context->numivals>1){
3033 for (i=0;i<context->numivals*2;i+=2){
3034 printf ( " Ivals: (%d - %d)\n", context->ivals[i],
3035 context->ivals[i+1]);
3036 }
3037 }
3038 }
3039
3040 }
3041 */
3042 sffs=(ScanFeatForSelectPtr)context->userdata;
3043
3044 /*keyword search only*/
3045 if (sffs->SearchFeat==TRUE){
3046 Char szType[COMMENT_SIZE];
3047
3048 FeatDefLabel(sfp, szType, sizeof (szType) - 1, OM_LABEL_BOTH);
3049 StringUpper(szType);
3050 if (!StringStr(szType,sffs->szKeyword)){
3051 if (context->sfp->comment){
3052 MemCopy(szType,context->sfp->comment,
3053 MIN(COMMENT_SIZE-1,StringLen(context->sfp->comment)));
3054 StringUpper(szType);
3055 if (!StringStr(szType,sffs->szKeyword)) return(TRUE);
3056 }
3057 else return(TRUE);
3058 }
3059 }
3060
3061 sffs->compteur++;
3062 fldp=(FLDataPtr)MemNew(sizeof(FLData));
3063 if (fldp==NULL) return(TRUE);
3064 fldp->num=sffs->compteur;/*context->index;*/
3065 fldp->from=context->left;
3066 fldp->to=context->right;
3067 fldp->segments=context->numivals;
3068 fldp->eID=context->entityID;
3069 fldp->iID=context->itemID;
3070 fldp->strand=context->strand;
3071 FeatDefLabel(sfp, fldp->szType, sizeof (fldp->szType) - 1, OM_LABEL_BOTH);
3072 if (context->sfp->comment){
3073 MemCopy(fldp->szComment,context->sfp->comment,
3074 MIN(COMMENT_SIZE-1,StringLen(context->sfp->comment)));
3075 }
3076 OwnerDrawLbox_AddItem(sffs->lbox,(Pointer) fldp);
3077
3078 if (sffs->eID==context->entityID && sffs->iID==context->itemID){
3079 sffs->index=sffs->compteur;
3080 }
3081
3082 sffs->SeqFeatListAvail[context->seqfeattype]=TRUE;
3083
3084 return(TRUE);
3085 }
3086
3087 /*******************************************************************************
3088
3089 Function : FeatClassChooseProc()
3090
3091 Purpose : repopulate the Feature list box when the nice user choose various
3092 feature classes
3093
3094 Parameters : pop; popup list of feat classes
3095
3096 Return value : none
3097
3098 *******************************************************************************/
FeatClassChooseProc(PopuP pop)3099 static void FeatClassChooseProc (PopuP pop)
3100 {
3101 WindoW w,temport;
3102 Int1 Choice;
3103 ViewerMainPtr vmp;
3104 ScanFeatForSelect sffs;
3105 Boolean SeqFeatListAvail[SEQFEAT_MAX];
3106 FLMDataPtr pflm;
3107 RecT rcP;
3108
3109 w=(WindoW)ParentWindow(pop);
3110
3111 if (w==NULL) return;
3112 pflm = (FLMDataPtr) GetObjectExtra (w);
3113 if (!pflm) return;
3114 vmp = (ViewerMainPtr) GetObjectExtra (pflm->hWndMain);
3115 if (!vmp) return;
3116 if (!pflm->SeqFeatClass) return;
3117 Choice=pflm->SeqFeatClass[GetValue(pflm->pop)-1];
3118 /*reset lbox Content*/
3119 OwnerDrawLbox_ResetLBContent(pflm->lbox);
3120
3121 /*repopulate lbox with the user Choice*/
3122 sffs.eID=vmp->vdp->Item_select.eIDsel;
3123 sffs.iID=vmp->vdp->Item_select.iIDsel;
3124 sffs.index=0;
3125 sffs.compteur=0;
3126 sffs.lbox=pflm->lbox;
3127 sffs.SearchFeat=FALSE;
3128 sffs.szKeyword[0]='\0';
3129 MemSet(sffs.SeqFeatListAvail,0,sizeof(sffs.SeqFeatListAvail));
3130 if (Choice==0){
3131 MemSet(SeqFeatListAvail,1,sizeof(SeqFeatListAvail));
3132 }
3133 else{
3134 MemSet(SeqFeatListAvail,0,sizeof(SeqFeatListAvail));
3135 SeqFeatListAvail[Choice]=TRUE;
3136 }
3137 SeqMgrExploreFeatures (vmp->vdp->bsp_i.bsp, (Pointer) &sffs,
3138 FeaturesListBoxInit, NULL, SeqFeatListAvail, NULL);
3139 if (sffs.index>0)
3140 OwnerDrawLbox_SelectItem(pflm->lbox,sffs.index);
3141 temport=SavePort(w);
3142 Select(pflm->lbox);
3143 ObjectRect(pflm->lbox,&rcP);
3144 InvalRect(&rcP);
3145 RestorePort(temport);
3146 }
3147
3148 /*******************************************************************************
3149
3150 Function : FeatListDlgCleanupProc()
3151
3152 Purpose : clean data structure of Features DlgBox
3153
3154 Parameters : data; something to delete
3155
3156 Return value : none
3157
3158 *******************************************************************************/
FeatListDlgCleanupProc(GraphiC g,VoidPtr data)3159 static void FeatListDlgCleanupProc (GraphiC g, VoidPtr data)
3160 {
3161 FLMDataPtr pflm=(FLMDataPtr)data;
3162
3163 if (pflm){
3164 if (pflm->SeqFeatClass) Free(pflm->SeqFeatClass);
3165 Free(pflm);
3166 }
3167 }
3168
3169
3170 /*******************************************************************************
3171
3172 Function : InitFeaturesListDlg()
3173
3174 Purpose : initialize Features DlgBox
3175
3176 Parameters : vmp; main data
3177 hWndMain; handle of the viewer main window
3178 Search; TRUE is keyword search
3179 szKeyword; used only for keyword search
3180
3181 Return value : none
3182
3183 *******************************************************************************/
InitFeaturesListDlg(ViewerMainPtr vmp,WindoW hWinMain,Boolean Search,CharPtr szKeyword)3184 static void InitFeaturesListDlg(ViewerMainPtr vmp,WindoW hWinMain,
3185 Boolean Search,CharPtr szKeyword)
3186 {
3187 WindoW w,lbox;
3188 Int2 Margins,nFeatClass,nClass=SEQFEAT_MAX+1;
3189 Int1 k;
3190 RecT rcDlg,rc;
3191 FLMDataPtr pflm;
3192 ScanFeatForSelect sffs;
3193 GrouP g2;
3194 PopuP pop;
3195 PrompT txt;
3196
3197 Margins=4*stdCharWidth;
3198 w=/*DocumentWindow*/Nlm_MovableModalWindow(Margins,Margins ,
3199 (Int2)((screenRect.right-screenRect.left)/2-2*Margins),
3200 (Int2)((screenRect.bottom-screenRect.top)/3-2*Margins),
3201 "Features List",
3202 FeatListDlgQuit/*,
3203 FeatListDlgProc*/);
3204 Nlm_SetResize(w, FeatListDlgProc);
3205
3206 if (w==NULL){
3207 Message (MSG_ERROR, "Dialog creation failed.");
3208 return;
3209 }
3210
3211 Select(w);
3212 ObjectRect(w,&rcDlg);
3213
3214 if (!Search){
3215 g2=HiddenGroup(w,2,0,NULL);
3216 txt=StaticPrompt(g2,"Feature classes :",0,0,NULL,'l');
3217
3218 #ifdef WIN_MAC
3219 pop=PopupList(g2,TRUE,FeatClassChooseProc);
3220 #endif
3221
3222 #ifndef WIN_MAC
3223 pop=PopupList(g2,FALSE,FeatClassChooseProc);
3224 #endif
3225 AlignObjects(ALIGN_MIDDLE,(HANDLE) txt, (HANDLE) pop, NULL);
3226
3227 ObjectRect(g2,&rc);
3228 rc.bottom+=3;
3229 }
3230 else rc.bottom=10;
3231
3232 lbox=OwnerDrawLbox_Create(w,10,rc.bottom,
3233 (Int2)(rcDlg.right-rcDlg.left-20),
3234 (Int2)(rcDlg.bottom-rcDlg.top-10-rc.bottom),
3235 FeatListlBoxProc,
3236 vmp->vdp->udv_graph.udv_font.hFnt,
3237 vmp->vdp->udv_graph.udv_font.cxChar,
3238 vmp->vdp->udv_graph.udv_font.cyChar);
3239
3240 if (lbox==NULL) {
3241 Remove(w);
3242 return;
3243 }
3244
3245 pflm=(FLMDataPtr)MemNew(sizeof(FLMData));
3246 if (pflm==NULL){
3247 Remove(w);
3248 return;
3249 }
3250 MemSet(pflm,0,sizeof(FLMData));
3251 pflm->hWndMain=hWinMain;
3252 pflm->lbox=lbox;
3253 if (!Search){
3254 pflm->gFeatClass=g2;
3255 pflm->pop=pop;
3256 }
3257 else{
3258 pflm->gFeatClass=NULL;
3259 pflm->pop=NULL;
3260 }
3261 /*add features to the listbox*/
3262 WatchCursor();
3263 sffs.eID=vmp->vdp->Item_select.eIDsel;
3264 sffs.iID=vmp->vdp->Item_select.iIDsel;
3265 sffs.index=0;
3266 sffs.compteur=0;
3267 sffs.lbox=lbox;
3268 sffs.SearchFeat=Search;
3269 StringCpy(sffs.szKeyword,szKeyword);
3270 MemSet(sffs.SeqFeatListAvail,0,sizeof(sffs.SeqFeatListAvail));
3271
3272 SeqMgrExploreFeatures (vmp->vdp->bsp_i.bsp, (Pointer) &sffs,
3273 FeaturesListBoxInit, NULL, NULL, NULL);
3274
3275
3276 /*no features found*/
3277 if (sffs.compteur==0){
3278 RealizeWindow(w);
3279 goto error;
3280 }
3281 /*Select the currently selected feature of UNDViewer*/
3282 if (sffs.index>0)
3283 OwnerDrawLbox_SelectItem(pflm->lbox,sffs.index);
3284
3285 /*Fill the popup list with Feature classes*/
3286 if (!Search){
3287 nFeatClass=0;
3288 for(k=0;k<nClass;k++){
3289 if (sffs.SeqFeatListAvail[k]) nFeatClass++;
3290 }
3291 PopupItem(pop,szSeqFeatClassName[0]);/*ALL*/
3292 if (nFeatClass>0){
3293 nFeatClass++;
3294 pflm->SeqFeatClass=(Int1Ptr)MemNew(nFeatClass*sizeof(Int1));
3295 if (pflm->SeqFeatClass){
3296 Int1 j=1;
3297 pflm->SeqFeatClass[0]=0;
3298 for(k=1;k<nClass;k++){
3299 if (sffs.SeqFeatListAvail[k]) {
3300 pflm->SeqFeatClass[j++]=k;
3301 PopupItem(pop,szSeqFeatClassName[k]);
3302 }
3303 }
3304 }
3305 }
3306 SetValue(pop,1);
3307 }
3308 /*show the dialog box*/
3309 ArrowCursor();
3310 SetObjectExtra (w, (Pointer) pflm, FeatListDlgCleanupProc);
3311 RealizeWindow(w);
3312 Show(w);
3313 Update();
3314 vmp->hFeatDlg=w;
3315 /*if true means this function has been called for a string search*/
3316 if (Search) SetStatus(vmp->MainMenu.ShowFeatureList,TRUE);
3317 return;
3318
3319 error:
3320 ArrowCursor();
3321 /*delete unused data*/
3322 if (pflm) Free(pflm);
3323 /*delete the dlg box*/
3324 Remove(w);
3325 /*update menu*/
3326 SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
3327 MsgAlert(KEY_OK, SEV_INFO, "OneD-Viewer","Nothing found.");
3328 }
3329
3330 /*******************************************************************************
3331
3332 Function : ShowFeaturesListDlg()
3333
3334 Purpose : show/hide Features DlgBox
3335
3336 Parameters : i; menu item
3337
3338 Return value : none
3339
3340 *******************************************************************************/
ShowFeaturesListDlg(IteM i)3341 static void ShowFeaturesListDlg(IteM i)
3342 {
3343 ViewerMainPtr vmp;
3344 WindoW hWinMain;
3345
3346 hWinMain=(WindoW)ParentWindow(i);
3347
3348 if (!hWinMain) return;
3349
3350 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
3351
3352 if (vmp==NULL) return;
3353
3354 if (GetStatus(i)==FALSE){
3355 Remove(vmp->hFeatDlg);
3356 vmp->hFeatDlg=NULL;
3357 return;
3358 }
3359 InitFeaturesListDlg(vmp, hWinMain, FALSE, NULL);
3360 }
3361
3362 /*******************************************************************************
3363
3364 Function : UDV_FeatKeySearchCancelProc()
3365
3366 Purpose : manage cancel button of the Feature keyword search dialog box
3367
3368 Parameters : g; button
3369
3370 Return value : none
3371
3372 *******************************************************************************/
UDV_FeatKeySearchCancelProc(ButtoN g)3373 static void UDV_FeatKeySearchCancelProc(ButtoN g)
3374 {
3375 WindoW w;
3376 FKSDataPtr fksd;
3377 ViewerMainPtr vmp;
3378
3379 w=(WindoW)ParentWindow(g);
3380
3381 if (!w) return;
3382 fksd = (FKSDataPtr) GetObjectExtra (w);
3383
3384 if (fksd){
3385 vmp = (ViewerMainPtr) GetObjectExtra (fksd->hWinMain);
3386 UDV_set_PullMenus(&vmp->MainMenu,TRUE);
3387 }
3388
3389 Remove(w);
3390 }
3391
3392 /*******************************************************************************
3393
3394 Function : UDV_FeatKeySearchAcceptProc()
3395
3396 Purpose : manage search button of the Feature keyword search dialog box
3397
3398 Parameters : g; button
3399
3400 Return value : none
3401
3402 *******************************************************************************/
UDV_FeatKeySearchAcceptProc(ButtoN g)3403 static void UDV_FeatKeySearchAcceptProc(ButtoN g)
3404 {
3405 Char szFName[PATH_MAX]={""};
3406 WindoW w;
3407 FKSDataPtr fksd;
3408 ViewerMainPtr vmp;
3409
3410 w=(WindoW)ParentWindow(g);
3411
3412 if (!w) return;
3413 fksd = (FKSDataPtr) GetObjectExtra (w);
3414
3415 if (fksd){
3416 vmp = (ViewerMainPtr) GetObjectExtra (fksd->hWinMain);
3417 /*retrieve the keyword*/
3418 GetTitle(fksd->keyField, szFName, sizeof(szFName)-1);
3419 /*find it; if yes: Features List will be created*/
3420 StringUpper(szFName);
3421 InitFeaturesListDlg(vmp, fksd->hWinMain, TRUE, szFName);
3422 UDV_set_PullMenus(&vmp->MainMenu,TRUE);
3423 }
3424
3425 Remove(w);
3426 }
3427
3428 /*******************************************************************************
3429
3430 Function : UDV_FeatKeySearchTextProc()
3431
3432 Purpose : manage keyword edit control of the Feature keyword search
3433 dialog box
3434
3435 Parameters : t; edit control
3436
3437 Return value : none
3438
3439 *******************************************************************************/
UDV_FeatKeySearchTextProc(TexT t)3440 static void UDV_FeatKeySearchTextProc(TexT t)
3441 {
3442 Char szFName[PATH_MAX]={""};
3443 WindoW w;
3444 FKSDataPtr fksd;
3445
3446 w=(WindoW)ParentWindow(t);
3447
3448 if (!w) return;
3449 fksd = (FKSDataPtr) GetObjectExtra (w);
3450
3451 if (fksd==NULL) return;
3452
3453 GetTitle(t, szFName, sizeof(szFName)-1);
3454
3455 if (StringLen(szFName) == 0)
3456 Disable(fksd->bOk);
3457 else Enable(fksd->bOk);
3458
3459 return;
3460 }
3461
3462 /*******************************************************************************
3463
3464 Function : UDV_SearchFeatForKey()
3465
3466 Purpose : callback of the Options|Search for features command
3467
3468 Parameters : i; command item
3469
3470 Return value : none
3471
3472 *******************************************************************************/
UDV_SearchFeatForKey(IteM i)3473 static void UDV_SearchFeatForKey(IteM i)
3474 {
3475 ViewerMainPtr vmp;
3476 WindoW hWinMain,w;
3477 GrouP g1,g2,g3;
3478 ButtoN b1,b2;
3479 PrompT t1;
3480 TexT t2;
3481 FKSDataPtr fksd;
3482 MsgAnswer nRet;
3483
3484 hWinMain=(WindoW)ParentWindow(i);
3485
3486 if (!hWinMain) return;
3487
3488 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
3489
3490 if (vmp==NULL) return;
3491
3492 /*if hFeatDlg opens, ask to close it*/
3493 if (vmp->hFeatDlg){
3494 nRet=MsgAlert(KEY_OKC, SEV_INFO, "OneD-Viewer",
3495 "Features List is already opened.\n Would you like to close it?");
3496 if (nRet==ANS_OK){
3497 Remove(vmp->hFeatDlg);
3498 vmp->hFeatDlg=NULL;
3499 SetStatus(vmp->MainMenu.ShowFeatureList,FALSE);
3500 }
3501 else return;
3502 }
3503
3504 fksd=(FKSDataPtr)MemNew(sizeof(FKSData));
3505 if (!fksd) return;
3506 MemSet(fksd,0,sizeof(FKSData));
3507
3508 w = MovableModalWindow(-30, -20, -10, -10,
3509 "OneD-Viewer - Find Features", NULL);
3510 g1=HiddenGroup(w,0,2,NULL);
3511
3512 SetGroupSpacing(g1,10,10);
3513 g2=HiddenGroup(g1,2,0,NULL);
3514 t1=StaticPrompt(g2,"Keyword :",0,0,systemFont,'l');
3515 t2=DialogText(g2,"",20, UDV_FeatKeySearchTextProc);
3516
3517 AlignObjects(ALIGN_MIDDLE,(HANDLE) t1, (HANDLE) t2, NULL);
3518
3519 g3=HiddenGroup(g1,2,0,NULL);
3520
3521 b1 = DefaultButton(g3, "Search", UDV_FeatKeySearchAcceptProc);
3522 b2 = PushButton(g3, "Cancel", UDV_FeatKeySearchCancelProc);
3523
3524 SetObjectExtra (w, (Pointer) fksd, StdCleanupExtraProc);
3525 fksd->hWinMain=hWinMain;
3526 fksd->keyField=t2;
3527 fksd->bOk=b1;
3528 RealizeWindow(w);
3529 Show(w);
3530 Select(w);
3531 Select(t2);
3532
3533 /*disable all menus*/
3534 UDV_set_PullMenus(&vmp->MainMenu,FALSE);
3535 }
3536
3537 /*******************************************************************************
3538
3539 Function : UDV_GenViewProc()
3540
3541 Purpose : Genome Viewer menu Proc
3542
3543 Return value : TRUE if ok
3544
3545 *******************************************************************************/
3546 #ifdef UDV_GENOME
UDV_GenViewProc(IteM i)3547 static void UDV_GenViewProc(IteM i)
3548 {
3549 WindoW w;
3550 ViewerMainPtr vmp;
3551
3552 w=ParentWindow(i);
3553 vmp = (ViewerMainPtr) GetObjectExtra (w);
3554 if (vmp==NULL) return;
3555 if (vmp->vdp==NULL) return;
3556
3557 GatherSpecificProcLaunch(vmp->GVprocid, "GV_MOD", OMPROC_VIEW, FALSE,
3558 vmp->vdp->bsp_i.bsp_entityID,vmp->vdp->bsp_i.bsp_itemID,OBJ_BIOSEQ);
3559
3560 }
3561 #endif
3562
3563 /*******************************************************************************
3564
3565 Function : UDV_LoadSpecificEditor()
3566
3567 Purpose : load an editor given entityID, itemID, itemtype
3568
3569 *******************************************************************************/
UDV_LoadSpecificEditor(BioseqViewPtr bvp,Uint2 entityID,Uint4 itemID,Uint2 itemtype)3570 NLM_EXTERN void UDV_LoadSpecificEditor(BioseqViewPtr bvp, Uint2 entityID,
3571 Uint4 itemID, Uint2 itemtype)
3572 {
3573 SeqEntryPtr sep;
3574
3575 if (bvp==NULL) return;
3576
3577 sep = GetTopSeqEntryForEntityID (entityID);
3578
3579 if (bvp->launchSubviewers) {
3580 WatchCursor ();
3581 Update ();
3582 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
3583 ArrowCursor ();
3584 Update ();
3585 } else if (LaunchViewerNotEditor (bvp, sep, entityID, itemID, itemtype)) {
3586 WatchCursor ();
3587 Update ();
3588 LaunchNewBioseqViewer (bvp->bsp, entityID, itemID, itemtype);
3589 ArrowCursor ();
3590 Update ();
3591 } else if (bvp->launchEditors) {
3592 WatchCursor ();
3593 Update ();
3594 GatherProcLaunch (OMPROC_EDIT, FALSE, entityID, itemID,
3595 itemtype, 0, 0, itemtype, 0);
3596 ArrowCursor ();
3597 Update ();
3598 }
3599 }
3600
3601 /*******************************************************************************
3602
3603 Function : UDV_ShowReverseComplement()
3604
3605 Purpose : callback of the Options|ShowRevComp
3606
3607 Parameters : i; command item
3608
3609 Return value : none
3610
3611 *******************************************************************************/
UDV_ShowReverseComplement(IteM i)3612 static void UDV_ShowReverseComplement(IteM i)
3613 {
3614 ViewerMainPtr vmp;
3615 ViewerDialogDataPtr vdp;
3616 WindoW hWinMain;
3617
3618 hWinMain=(WindoW)ParentWindow(i);
3619 if (!hWinMain) return;
3620 vmp = (ViewerMainPtr) GetObjectExtra (hWinMain);
3621 if (vmp==NULL) return;
3622 vdp = vmp->vdp;
3623 if (vdp == NULL) return;
3624 if (!vdp->bsp_i.bspMolNuc) return;
3625
3626 /*switch the seq. direction*/
3627 WatchCursor();
3628 if (GetStatus(i))
3629 vdp->bDisplayRevComp = TRUE;
3630 else
3631 vdp->bDisplayRevComp = FALSE;
3632 /*rebuilt the Feature Index*/
3633 SeqMgrClearFeatureIndexes(0,vdp->bsp_i.bsp);
3634 SeqMgrIndexFeaturesEx (0, vdp->bsp_i.bsp, vdp->bDisplayRevComp, FALSE);
3635
3636 /*rebuilt the display*/
3637 UDV_resize_viewer(vdp->UnDViewer,vdp);
3638 ArrowCursor ();
3639 }
3640
3641
ClearUDV_mouse_select(UDV_mouse_selectPtr msp)3642 NLM_EXTERN void ClearUDV_mouse_select(UDV_mouse_selectPtr msp) {
3643 /*******************************************************************************
3644 zero the UDV_mouse_select structure.
3645 *******************************************************************************/
3646 if (msp->first_cols != NULL) MemFree(msp->first_cols);
3647 if (msp->first_pgps != NULL) MemFree(msp->first_pgps);
3648 MemSet(msp, 0, sizeof(UDV_mouse_select));
3649 }
3650