1 /*   udvmain.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:  udvmain.c
27 *
28 * Author:  Patrick Durand
29 *
30 * Version Creation Date:   5/3/99
31 *
32 * $Revision: 6.15 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * $Log: udvmain.c,v $
39 * Revision 6.15  2000/04/10 21:41:26  lewisg
40 * move alignment menus into ddv, udv from cn3d
41 *
42 * Revision 6.14  2000/03/06 14:01:27  durand
43 * first release of the Summary viewer done
44 *
45 * Revision 6.13  2000/03/01 16:53:17  durand
46 * add the Genome Viewer init functions
47 *
48 * Revision 6.12  2000/01/12 14:01:17  durand
49 * fix a cast to avoid compiling error on NT
50 *
51 * Revision 6.11  2000/01/11 15:04:02  durand
52 * add Entrez network stuff
53 *
54 * Revision 6.10  2000/01/10 15:19:07  durand
55 * use Entrez instead of ID1
56 *
57 * Revision 6.9  2000/01/03 21:05:58  durand
58 * update the way the udv main window is created
59 *
60 * Revision 6.8  1999/11/29 15:18:48  durand
61 * designed a new GUI; fixed problems under Win95 and Linux
62 *
63 * Revision 6.7  1999/11/09 21:09:17  durand
64 * reduce the size of the main window at startup
65 *
66 * Revision 6.6  1999/09/29 20:08:59  durand
67 * set UdvGlobals before using getArgs
68 *
69 * Revision 6.5  1999/07/30 20:10:15  durand
70 * updates for the new Entrez graphical viewer
71 *
72 * Revision 6.4  1999/06/07 15:40:30  durand
73 * add LOG line to keep track of the history
74 *
75 *
76 *
77 * ==========================================================================
78 */
79 
80 #include <udviewer.h>
81 #include <accentr.h>
82 #include <netcnfg.h>
83 #ifdef UDV_GENOME
84 #include <udvgv.h>
85 #endif
86 
87 /*local text*/
88 static Char szAppName[]="OneD-Viewer";
89 
90 /*******************************************************************************
91 
92   Function : UDV_ConfigAccepted()
93 
94   Purpose : Entrez Network COnfiguration Dialog Box; accept a new config
95 
96   Return value : none
97 
98 *******************************************************************************/
UDV_ConfigAccepted(void)99 static void UDV_ConfigAccepted(void)
100 {
101     SetAppParam("UDV", "SETTINGS", "NETWORKAVAILABLE", "TRUE");
102     Message(MSG_OK, "Setting will take affect when you restart OneD-Viewer");
103 }
104 
105 /*******************************************************************************
106 
107   Function : UDV_ConfigCancelled()
108 
109   Purpose : Entrez Network COnfiguration Dialog Box; close dlg without modif.
110 
111   Return value : none
112 
113 *******************************************************************************/
UDV_ConfigCancelled(void)114 static void UDV_ConfigCancelled(void)
115 {
116 }
117 
118 /*******************************************************************************
119 
120   Function : UDV_ConfigTurnedOff()
121 
122   Purpose : Entrez Network COnfiguration Dialog Box; cancel Entrez connection
123 
124   Return value : none
125 
126 *******************************************************************************/
UDV_ConfigTurnedOff(void)127 static void UDV_ConfigTurnedOff(void)
128 {
129     SetAppParam("UDV", "SETTINGS", "NETWORKAVAILABLE", "FALSE");
130     Message(MSG_OK, "Setting will take affect when you restart OneD-Viewer");
131 }
132 
133 /*******************************************************************************
134 
135   Function : UDV_ConfigNetwork()
136 
137   Purpose : call the Entrez Network COnfiguration Dialog Box
138 
139   Return value : none
140 
141 *******************************************************************************/
UDV_ConfigNetwork(IteM i)142 static void UDV_ConfigNetwork(IteM i)
143 {
144 ViewerMainPtr vmp;
145 WindoW        hParent;
146 
147 	/*get main data block*/
148 	hParent=(WindoW)ParentWindow(i);
149 	if (!hParent) return;
150 	vmp = (ViewerMainPtr) GetObjectExtra (hParent);
151 
152     if (vmp->UseNetwork) ShowNetConfigForm(NULL,NULL, UDV_ConfigAccepted,
153 		UDV_ConfigCancelled, UDV_ConfigTurnedOff, TRUE);
154     else ShowNetConfigForm(NULL, NULL, UDV_ConfigAccepted, UDV_ConfigCancelled,
155                       UDV_ConfigTurnedOff, FALSE);
156 }
157 
158 /*******************************************************************************
159 
160   Function : UDV_StartEntrez()
161 
162   Purpose :  start connection to Entrez Server.
163 
164   Return value : -
165 
166 *******************************************************************************/
UDV_StartEntrez(Boolean UseNetwork)167 static Boolean UDV_StartEntrez(Boolean UseNetwork)
168 {
169 Boolean bRet;
170 
171 	bRet=FALSE;
172 
173     if (!UseNetwork) {
174 		bRet=FALSE;
175 	}
176 	else{
177     	if (!EntrezIsInited()) {
178         	if(EntrezBioseqFetchEnable(szAppName, FALSE)) {
179             	if (EntrezInit(szAppName, TRUE, NULL))
180 					bRet=TRUE;
181 				else
182 					bRet=FALSE;
183         	}
184 			else {
185 				bRet=FALSE;
186 			}
187     	}
188 		else{
189 			bRet=TRUE;
190 		}
191 	}
192 	return(bRet);
193 }
194 
195 /*****************************************************************************
196 
197 Function: UDV_UseNetwork()
198 
199 Purpose:  Determines if UDV should use the network
200 
201 Returns:  TRUE if yes
202 
203 *****************************************************************************/
UDV_UseNetwork(void)204 static Boolean UDV_UseNetwork(void)
205 {
206 Char str[64];
207 
208     if (GetAppParam
209         ("UDV", "SETTINGS", "NETWORKAVAILABLE", NULL, str, sizeof(str))) {
210         if (StringICmp(str, "TRUE") == 0) return TRUE;
211     }
212     return FALSE;
213 }
214 
215 /*******************************************************************************
216 
217   Function : Main()
218 
219   Purpose : Entry point of the software
220 
221   Parameters :
222 
223   Return value :
224 
225 *******************************************************************************/
Main(void)226 Int2 Main(void)
227 {
228 ViewerMainPtr 	vmp;
229 WindoW			w;
230 Int2			Margins;
231 Boolean 		UseNetwork;
232 RecT			rcL;
233 UdvGlobals      ug;
234 UDVLogoData		ldp;
235 
236 	ErrSetMessageLevel(SEV_WARNING);
237 	ErrSetOptFlags(EO_SHOW_CODES);
238 	ErrSetOptFlags(EO_XLATE_CODES);
239 	MemSet(&ug,0,sizeof(UdvGlobals));
240 
241 	/*init some important stuffs*/
242 	UseLocalAsnloadDataAndErrMsg();
243 
244 /*	isID1Ok=UDV_ID1Init();
245 	if (!isID1Ok){
246 		Message (MSG_ERROR, "Unable to connect Network.");
247 	}
248 */
249 	if (! AllObjLoad()){
250 		Message (MSG_ERROR, "AsnObjLoad() failed.");
251 		return(1);
252 	}
253 
254 	if (! SubmitAsnLoad()){
255 		Message (MSG_ERROR, "SeqSubmitLoad() failed.");
256 		return(1);
257 	}
258 
259 	if (!SeqCodeSetLoad ()){
260 		Message (MSG_ERROR, "SeqCodeSetLoad () failed.");
261 		return(1);
262 	}
263 
264 	if (!GeneticCodeTableLoad()){
265 		Message (MSG_ERROR, "GeneticCodeTableLoad() failed.");
266 		return(1);
267 	}
268 
269 	if (!FeatDefSetLoad()){
270 		Message (MSG_ERROR, "FeatDefSeqLoad() failed.");
271 		return(1);
272 	}
273 
274 	/*init data blocks*/
275 	vmp=(ViewerMainPtr)MemNew(sizeof(ViewerMain));
276 	if (vmp){
277 		MemSet(vmp,0,sizeof(ViewerMain));
278 	}
279 	else{
280 		Message (MSG_ERROR, "Viewer creation failed.");
281 		return(1);
282 	}
283 
284 	/*OBjMgr Callback Function declaration*/
285 	vmp->UDVprocid=REGISTER_UDV_AUTONOMOUS;
286 
287 #ifdef UDV_GENOME
288 	vmp->GVprocid=REGISTER_GV_MODULE;
289 #endif
290 
291 	/*main window*/
292 	Margins=20*stdCharWidth;
293 	w=DocumentWindow(Margins,Margins , -10 , -10 ,
294 			szAppName,
295 			UDV_WinMainProgQuit,
296 			UDV_WinMainResize);
297 
298 	if (w==NULL){
299 		Message (MSG_ERROR, "Viewer creation failed.");
300 		return(1);
301 	}
302 	vmp->hWndMain=w;
303 	SetObjectExtra (w, (Pointer) vmp, (FreeProc)UDV_WinMainCleanupExtraProc);
304 
305 	/*this is an autonomous viewer*/
306 	vmp->AutonomeViewer=TRUE;
307 
308 	/*Should use a connection to Entrez ?*/
309 	vmp->UseNetwork=UDV_UseNetwork();
310 	UseNetwork=vmp->UseNetwork;
311 	/*init menu*/
312 	UDV_SetupMenus(w,UseNetwork, NULL);
313 	UDV_set_MainMenus(&vmp->MainMenu,FALSE);
314 	/*create the windows*/
315 	CreateMainControls(w,vmp,NULL);
316 	UDV_set_MainControls(vmp,FALSE);
317 
318 	/*init logo data*/
319 	LogoFontCreate(&ldp.f1,&ldp.f2,&ldp.f3);
320 	StringCpy(ldp.szTitle,szAppName);
321 	StringCpy(ldp.szDesc,", a sequence viewer for GenBank");
322 	SetAppProperty("UDVLogoData",(Pointer)&ldp);
323 	vmp->Show_logo=TRUE;
324 	SetAppProperty("AutonomousUDVViewer",(Pointer)vmp);
325 
326 	ProcessUpdatesFirst(FALSE);
327 
328 	RealizeWindow(w);
329 	UDV_WinMainResize(w);
330 	Show(w);
331 
332 	ug.fetchSepProc=(UdvFetchSeqEntryProc)EntrezSeqEntryGet;
333 	ug.NetCfgMenuProc=UDV_ConfigNetwork;
334 	ug.NetStartProc=UDV_StartEntrez;
335 	ug.vmp=vmp;
336 	SetAppProperty("UdvGlobals",(Pointer)&ug);
337 
338 	/*is there a file to open on the command line ?*/
339 	if (GetArgc()>1){
340 		/*is GetArgv()[1] a file name ?*/
341 		FILE *f;
342 
343 		f=FileOpen(GetArgv()[1],"r");
344 		if (f){
345 			UDV_analyze_SEP_for_open(f,NULL,vmp,w);
346 			FileClose(f);
347 		}
348 	}
349 
350 	ProcessEvents();
351 
352 	/*ID1BioseqFetchDisable();*/
353 	/*close network connection, if needed*/
354 	if (UseNetwork && EntrezIsInited()) EntrezBioseqFetchDisable();
355 
356 	RemoveAppProperty("AutonomousUDVViewer");
357 	RemoveAppProperty("UDVLogoData");
358 	RemoveAppProperty("UdvGlobals");
359 
360 	return(0);
361 }
362 
363