~ubuntu-branches/ubuntu/quantal/ncbi-tools6/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*   udvmain.c
* ===========================================================================
*
*                            PUBLIC DOMAIN NOTICE
*            National Center for Biotechnology Information (NCBI)
*
*  This software/database is a "United States Government Work" under the
*  terms of the United States Copyright Act.  It was written as part of
*  the author's official duties as a United States Government employee and
*  thus cannot be copyrighted.  This software/database is freely available
*  to the public for use. The National Library of Medicine and the U.S.
*  Government do not place any restriction on its use or reproduction.
*  We would, however, appreciate having the NCBI and the author cited in
*  any work or product based on this material
*
*  Although all reasonable efforts have been taken to ensure the accuracy
*  and reliability of the software and data, the NLM and the U.S.
*  Government do not and cannot warrant the performance or results that
*  may be obtained by using this software or data. The NLM and the U.S.
*  Government disclaim all warranties, express or implied, including
*  warranties of performance, merchantability or fitness for any particular
*  purpose.
*
* ===========================================================================
*
* File Name:  udvmain.c
*
* Author:  Patrick Durand
*
* Version Creation Date:   5/3/99
*
* $Revision: 6.15 $
*
* File Description: 
*
* Modifications:
* --------------------------------------------------------------------------
* $Log: udvmain.c,v $
* Revision 6.15  2000/04/10 21:41:26  lewisg
* move alignment menus into ddv, udv from cn3d
*
* Revision 6.14  2000/03/06 14:01:27  durand
* first release of the Summary viewer done
*
* Revision 6.13  2000/03/01 16:53:17  durand
* add the Genome Viewer init functions
*
* Revision 6.12  2000/01/12 14:01:17  durand
* fix a cast to avoid compiling error on NT
*
* Revision 6.11  2000/01/11 15:04:02  durand
* add Entrez network stuff
*
* Revision 6.10  2000/01/10 15:19:07  durand
* use Entrez instead of ID1
*
* Revision 6.9  2000/01/03 21:05:58  durand
* update the way the udv main window is created
*
* Revision 6.8  1999/11/29 15:18:48  durand
* designed a new GUI; fixed problems under Win95 and Linux
*
* Revision 6.7  1999/11/09 21:09:17  durand
* reduce the size of the main window at startup
*
* Revision 6.6  1999/09/29 20:08:59  durand
* set UdvGlobals before using getArgs
*
* Revision 6.5  1999/07/30 20:10:15  durand
* updates for the new Entrez graphical viewer
*
* Revision 6.4  1999/06/07 15:40:30  durand
* add LOG line to keep track of the history
*
*
*
* ==========================================================================
*/

#include <udviewer.h>
#include <accentr.h>
#include <netcnfg.h>
#ifdef UDV_GENOME
#include <udvgv.h>
#endif

/*local text*/
static Char szAppName[]="OneD-Viewer";

/*******************************************************************************

  Function : UDV_ConfigAccepted()
  
  Purpose : Entrez Network COnfiguration Dialog Box; accept a new config
  
  Return value : none 

*******************************************************************************/
static void UDV_ConfigAccepted(void)
{
    SetAppParam("UDV", "SETTINGS", "NETWORKAVAILABLE", "TRUE");
    Message(MSG_OK, "Setting will take affect when you restart OneD-Viewer");
}

/*******************************************************************************

  Function : UDV_ConfigCancelled()
  
  Purpose : Entrez Network COnfiguration Dialog Box; close dlg without modif.
  
  Return value : none 

*******************************************************************************/
static void UDV_ConfigCancelled(void)
{
}

/*******************************************************************************

  Function : UDV_ConfigTurnedOff()
  
  Purpose : Entrez Network COnfiguration Dialog Box; cancel Entrez connection
  
  Return value : none 

*******************************************************************************/
static void UDV_ConfigTurnedOff(void)
{
    SetAppParam("UDV", "SETTINGS", "NETWORKAVAILABLE", "FALSE");
    Message(MSG_OK, "Setting will take affect when you restart OneD-Viewer");
}

/*******************************************************************************

  Function : UDV_ConfigNetwork()
  
  Purpose : call the Entrez Network COnfiguration Dialog Box
  
  Return value : none 

*******************************************************************************/
static void UDV_ConfigNetwork(IteM i)
{
ViewerMainPtr vmp;
WindoW        hParent;

	/*get main data block*/
	hParent=(WindoW)ParentWindow(i);
	if (!hParent) return;
	vmp = (ViewerMainPtr) GetObjectExtra (hParent);

    if (vmp->UseNetwork) ShowNetConfigForm(NULL,NULL, UDV_ConfigAccepted, 
		UDV_ConfigCancelled, UDV_ConfigTurnedOff, TRUE);
    else ShowNetConfigForm(NULL, NULL, UDV_ConfigAccepted, UDV_ConfigCancelled,
                      UDV_ConfigTurnedOff, FALSE);
}

/*******************************************************************************

  Function : UDV_StartEntrez()
  
  Purpose :  start connection to Entrez Server.
  				    
  Return value : -

*******************************************************************************/
static Boolean UDV_StartEntrez(Boolean UseNetwork)
{
Boolean bRet;

	bRet=FALSE;
	
    if (!UseNetwork) {
		bRet=FALSE; 
	}
	else{
    	if (!EntrezIsInited()) {
        	if(EntrezBioseqFetchEnable(szAppName, FALSE)) {
            	if (EntrezInit(szAppName, TRUE, NULL)) 
					bRet=TRUE;
				else
					bRet=FALSE;
        	}
			else {
				bRet=FALSE;
			}
    	}
		else{
			bRet=TRUE;
		}
	}
	return(bRet);
}

/*****************************************************************************

Function: UDV_UseNetwork()

Purpose:  Determines if UDV should use the network
  
Returns:  TRUE if yes

*****************************************************************************/
static Boolean UDV_UseNetwork(void)
{
Char str[64];

    if (GetAppParam
        ("UDV", "SETTINGS", "NETWORKAVAILABLE", NULL, str, sizeof(str))) {
        if (StringICmp(str, "TRUE") == 0) return TRUE;
    }
    return FALSE;
}

/*******************************************************************************

  Function : Main()
  
  Purpose : Entry point of the software 
  
  Parameters : 
  
  Return value : 

*******************************************************************************/
Int2 Main(void)
{
ViewerMainPtr 	vmp;
WindoW			w; 
Int2			Margins;
Boolean 		UseNetwork;
RecT			rcL;
UdvGlobals      ug;
UDVLogoData		ldp;
	
	ErrSetMessageLevel(SEV_WARNING);
	ErrSetOptFlags(EO_SHOW_CODES);
	ErrSetOptFlags(EO_XLATE_CODES);
	MemSet(&ug,0,sizeof(UdvGlobals));
		
	/*init some important stuffs*/
	UseLocalAsnloadDataAndErrMsg();

/*	isID1Ok=UDV_ID1Init();
	if (!isID1Ok){
		Message (MSG_ERROR, "Unable to connect Network.");
	}
*/
	if (! AllObjLoad()){
		Message (MSG_ERROR, "AsnObjLoad() failed.");
		return(1);
	}

	if (! SubmitAsnLoad()){
		Message (MSG_ERROR, "SeqSubmitLoad() failed.");
		return(1);
	}

	if (!SeqCodeSetLoad ()){
		Message (MSG_ERROR, "SeqCodeSetLoad () failed.");
		return(1);
	}

	if (!GeneticCodeTableLoad()){
		Message (MSG_ERROR, "GeneticCodeTableLoad() failed.");
		return(1);
	}

	if (!FeatDefSetLoad()){
		Message (MSG_ERROR, "FeatDefSeqLoad() failed.");
		return(1);
	}
	
	/*init data blocks*/
	vmp=(ViewerMainPtr)MemNew(sizeof(ViewerMain));
	if (vmp){
		MemSet(vmp,0,sizeof(ViewerMain));
	}
	else{
		Message (MSG_ERROR, "Viewer creation failed.");
		return(1);
	}

	/*OBjMgr Callback Function declaration*/
	vmp->UDVprocid=REGISTER_UDV_AUTONOMOUS;

#ifdef UDV_GENOME
	vmp->GVprocid=REGISTER_GV_MODULE;
#endif
	
	/*main window*/
	Margins=20*stdCharWidth;
	w=DocumentWindow(Margins,Margins , -10 , -10 ,
			szAppName, 
			UDV_WinMainProgQuit,
			UDV_WinMainResize);

	if (w==NULL){
		Message (MSG_ERROR, "Viewer creation failed.");
		return(1);
	}
	vmp->hWndMain=w;
	SetObjectExtra (w, (Pointer) vmp, (FreeProc)UDV_WinMainCleanupExtraProc);

	/*this is an autonomous viewer*/
	vmp->AutonomeViewer=TRUE;

	/*Should use a connection to Entrez ?*/
	vmp->UseNetwork=UDV_UseNetwork();
	UseNetwork=vmp->UseNetwork;
	/*init menu*/
	UDV_SetupMenus(w,UseNetwork, NULL);
	UDV_set_MainMenus(&vmp->MainMenu,FALSE);
	/*create the windows*/
	CreateMainControls(w,vmp,NULL);
	UDV_set_MainControls(vmp,FALSE);

	/*init logo data*/
	LogoFontCreate(&ldp.f1,&ldp.f2,&ldp.f3);
	StringCpy(ldp.szTitle,szAppName);
	StringCpy(ldp.szDesc,", a sequence viewer for GenBank");
	SetAppProperty("UDVLogoData",(Pointer)&ldp);	
	vmp->Show_logo=TRUE;
	SetAppProperty("AutonomousUDVViewer",(Pointer)vmp);	
	
	ProcessUpdatesFirst(FALSE);
	
	RealizeWindow(w);
	UDV_WinMainResize(w);
	Show(w);

	ug.fetchSepProc=(UdvFetchSeqEntryProc)EntrezSeqEntryGet;
	ug.NetCfgMenuProc=UDV_ConfigNetwork;
	ug.NetStartProc=UDV_StartEntrez;	
	ug.vmp=vmp;
	SetAppProperty("UdvGlobals",(Pointer)&ug);
	
	/*is there a file to open on the command line ?*/
	if (GetArgc()>1){
		/*is GetArgv()[1] a file name ?*/
		FILE *f;
		
		f=FileOpen(GetArgv()[1],"r");
		if (f){
			UDV_analyze_SEP_for_open(f,NULL,vmp,w);
			FileClose(f);
		}
	}

	ProcessEvents();

	/*ID1BioseqFetchDisable();*/
	/*close network connection, if needed*/
	if (UseNetwork && EntrezIsInited()) EntrezBioseqFetchDisable();

	RemoveAppProperty("AutonomousUDVViewer");	
	RemoveAppProperty("UDVLogoData");	
	RemoveAppProperty("UdvGlobals");

	return(0);
}