1 /* cn3dxprt.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: cn3dxprt.c
27 *
28 * Author: Christopher Hogue
29 *
30 * Version Creation Date: 1/31/96
31 *
32 * File Description: Cn3d file export to Kinemage / PDB sub menu...
33 *
34 * Modifications:
35 * --------------------------------------------------------------------------
36 * $Log: cn3dxprt.c,v $
37 * Revision 6.9 2000/07/28 21:05:56 lewisg
38 * more c++ fixes
39 *
40 * Revision 6.8 2000/03/24 20:34:58 lewisg
41 * add blast from file, bug fixes, get rid of redundant code, etc.
42 *
43 * Revision 6.7 2000/01/07 16:28:37 thiessen
44 * fixed broken header conflicts
45 *
46 * Revision 6.6 1999/12/17 20:25:00 thiessen
47 * put in preliminary PNG output (for Cn3D)
48 *
49 * Revision 6.5 1999/11/22 14:46:45 thiessen
50 * moved _OPENGL code blocks to only vibrant and ncbicn3d libraries
51 *
52 * Revision 6.4 1999/10/29 14:15:32 thiessen
53 * ran all Cn3D source through GNU Indent to prettify
54 *
55 * Revision 6.3 1999/04/06 20:19:26 lewisg
56 * more opengl
57 *
58 * Revision 6.2 1999/03/12 18:37:30 kans
59 * fixed ErrPostEx problems
60 *
61 * Revision 6.1 1999/02/25 23:14:32 ywang
62 * move around menu item and callback function, change menu item names
63 *
64 * Revision 6.0 1997/08/25 18:13:54 madden
65 * Revision changed to 6.0
66 *
67 * Revision 5.0 1996/05/28 14:05:44 ostell
68 * Set to revision 5.0
69 *
70 * Revision 1.2 1996/04/26 18:43:07 vakatov
71 * CN3D sources ported to MS-Windows;
72 * the portability errors and warnings fixed, etc.
73 *
74 * Revision 1.1 1996/02/01 18:47:38 kans
75 * Initial revision
76 *
77 *
78 * ==========================================================================
79 */
80
81 #include <vibrant.h>
82 #include <mmdbapi.h>
83 #include <cn3dxprt.h>
84 #include <cn3dmsel.h>
85 #include <cn3dmain.h>
86 #include <cn3dshim.h>
87
88 #if defined(_OPENGL)
89 #include <shim3d.h>
90 #endif
91
92 static Boolean Cn3D_Export_InUse = FALSE;
93
94 static WindoW Cn3D_wPDBSave;
95 static TexT Cn3D_tPDBSave;
96 static ButtoN Cn3D_bPDBBrowse;
97 static ButtoN Cn3D_bPDBOk;
98
99
100 static WindoW Cn3D_wKinSave;
101 static TexT Cn3D_tKinSave;
102 static ButtoN Cn3D_bKinBrowse;
103 static ButtoN Cn3D_bKinOk;
104 static ButtoN Cn3D_bRender[6];
105 static GrouP Cn3D_gColorAtoms;
106 static GrouP Cn3D_gRenderOpts;
107
Cn3D_PDBEnableProc(TexT t)108 static void Cn3D_PDBEnableProc(TexT t)
109 {
110 Char str[32];
111 GetTitle(Cn3D_tPDBSave, str, sizeof(str));
112 if (StringLen(str) == 0) {
113 Disable(Cn3D_bPDBOk);
114 } else {
115 Enable(Cn3D_bPDBOk);
116 }
117 return;
118 }
119
Cn3D_PDBBrowseProc(ButtoN b)120 static void Cn3D_PDBBrowseProc(ButtoN b)
121 {
122 Char dfault[32];
123 Char path[256];
124
125 path[0] = '\0';
126 dfault[0] = '\0';
127 if (GetOutputFileName(path, sizeof(path), dfault)) {
128 SetTitle(Cn3D_tPDBSave, path);
129 Cn3D_PDBEnableProc(NULL);
130 }
131 return;
132 }
133
Cn3D_ExportPDBNow(ButtoN b)134 static void Cn3D_ExportPDBNow(ButtoN b)
135 {
136
137 Char path[256];
138 FILE *pFile;
139 Int2 iTest;
140 Int4 iCount = 0;
141 PDNMS pdnmsMain = NULL;
142
143 Int2Ptr i2Vec = NULL;
144
145
146 i2Vec = PickedModels(&iCount);
147 if (iCount == 0) {
148 ErrClear();
149 ErrPostEx(SEV_INFO, 0, 0, "Nothing to save!");
150 ErrShow();
151 Disable(Cn3D_bPDBOk);
152 return;
153 }
154
155 GetTitle(Cn3D_tPDBSave, path, sizeof(path));
156 pdnmsMain = GetSelectedModelstruc();
157 #ifdef WIN_MAC
158 FileCreate(path, "TEXT", "ttxt");
159 #endif
160 WatchCursor();
161 pFile = FileOpen(path, "w");
162 if (pFile) {
163 iTest = WritePDBModelList(pdnmsMain, pFile, iCount, i2Vec);
164 I2VectorFree(i2Vec, 0);
165 if (!iTest) {
166 ErrClear();
167 ErrPostEx(SEV_FATAL, 0, 0,
168 "Unable to Export\nPossibly Corrupt Data in Memory!\n");
169 ErrShow();
170 }
171 fflush(pFile);
172 fclose(pFile);
173 } else {
174 ErrClear();
175 ErrPostEx(SEV_INFO, 0, 0, "Sorry, Unable to Open File:\n %s",
176 path);
177 ErrShow();
178 Disable(Cn3D_bPDBOk);
179 I2VectorFree(i2Vec, 0);
180 SetTitle(Cn3D_tPDBSave, "\0");
181 ArrowCursor();
182 return;
183 }
184 Remove(Cn3D_wPDBSave);
185 Cn3D_EnableFileOps();
186 Cn3D_Export_InUse = FALSE;
187 ArrowCursor();
188 return;
189 }
190
Cn3D_CancelPDB(ButtoN b)191 static void Cn3D_CancelPDB(ButtoN b)
192 {
193 Remove(Cn3D_wPDBSave);
194 Cn3D_EnableFileOps();
195 Cn3D_Export_InUse = FALSE;
196 return;
197 }
198
199
Cn3D_ExportPDB(IteM i)200 static void Cn3D_ExportPDB(IteM i)
201 {
202 PDNMS pdnmsThis = NULL;
203 PMSD pmsdThis = NULL;
204 Char pcSavestr[60];
205 Char pcSavename[32];
206 CharPtr Cn3D_pcPDBName;
207 GrouP g, g2, g3, g4;
208 GrouP gMS;
209 ButtoN b;
210
211 if (Cn3D_Export_InUse)
212 return;
213 else
214 Cn3D_Export_InUse = TRUE;
215
216 pdnmsThis = GetSelectedModelstruc();
217 if (!pdnmsThis) {
218 Cn3D_Export_InUse = FALSE;
219 return;
220 }
221 pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
222
223 Cn3D_wPDBSave = ModalWindow(-20, -13, -10, -10, NULL);
224
225 /* set up a group encolosing structures - models selection lists and - "info strings" */
226 Cn3D_pcPDBName = StringSave(GetStrucStrings(pdnmsThis, PDB_ACC));
227 sprintf(pcSavestr, "Save %s As a PDB Formatted File ...",
228 Cn3D_pcPDBName);
229 g = HiddenGroup(Cn3D_wPDBSave, 0, 3, NULL);
230 SetGroupMargins(g, 10, 10);
231 SetGroupSpacing(g, 10, 5);
232 StaticPrompt(g, pcSavestr, 0, 0, systemFont, 'l');
233 g2 = HiddenGroup(g, 2, 0, NULL);
234 SetGroupMargins(g2, 10, 10);
235 SetGroupSpacing(g2, 10, 5);
236 StringNCpy(pcSavename, Cn3D_pcPDBName, 8);
237 StringCat(pcSavename, ".pdb");
238 Cn3D_tPDBSave =
239 DialogText(g2, pcSavename, 18, (TxtActnProc) Cn3D_PDBEnableProc);
240 MemFree(Cn3D_pcPDBName);
241
242 Cn3D_bPDBBrowse =
243 PushButton(g2, " browse...", (BtnActnProc) Cn3D_PDBBrowseProc);
244 g3 = HiddenGroup(g, 2, 0, NULL);
245 gMS = Cn3D_ModelSelect(g3, FALSE); /* no vector models for PDB files saves */
246 g4 = HiddenGroup(g3, 0, 2, NULL);
247 SetGroupMargins(g4, 10, 10);
248 SetGroupSpacing(g4, 10, 5);
249 Cn3D_bPDBOk = PushButton(g4, "OK", Cn3D_ExportPDBNow);
250 b = PushButton(g4, "Cancel", Cn3D_CancelPDB);
251 Cn3D_PDBEnableProc(NULL);
252 Select(Cn3D_bPDBOk);
253 /* disable appropriate stuff here */
254 Cn3D_DisableFileOps();
255 Show(Cn3D_wPDBSave);
256
257 return;
258 }
259
260
261
262
263
Cn3D_KinEnableProc(TexT t)264 static void Cn3D_KinEnableProc(TexT t)
265 {
266 Char str[32];
267 GetTitle(Cn3D_tKinSave, str, sizeof(str));
268 if (StringLen(str) == 0) {
269 Disable(Cn3D_bKinOk);
270 } else {
271 Enable(Cn3D_bKinOk);
272 }
273 return;
274 }
275
Cn3D_KinBrowseProc(ButtoN b)276 static void Cn3D_KinBrowseProc(ButtoN b)
277 {
278 Char dfault[32];
279 Char path[256];
280
281 path[0] = '\0';
282 dfault[0] = '\0';
283 if (GetOutputFileName(path, sizeof(path), dfault)) {
284 SetTitle(Cn3D_tKinSave, path);
285 Cn3D_KinEnableProc(NULL);
286 }
287 return;
288 }
289
Cn3D_ExportKinNow(ButtoN b)290 static void Cn3D_ExportKinNow(ButtoN b)
291 {
292
293 Char path[256];
294 FILE *pFile;
295 Int2 iTest;
296 Int4 iCount = 0;
297 PDNMS pdnmsMain = NULL;
298 Int2 iColor = 0;
299 Byte bRender = 0;
300 Int2Ptr i2Vec = NULL;
301
302
303 i2Vec = PickedModels(&iCount);
304 if (iCount == 0) {
305 ErrClear();
306 ErrPostEx(SEV_INFO, 0, 0, "Nothing to save!");
307 ErrShow();
308 Disable(Cn3D_bKinOk);
309 return;
310 }
311 GetTitle(Cn3D_tKinSave, path, sizeof(path));
312
313 iColor = GetValue(Cn3D_gColorAtoms);
314 bRender = KIN_DEFAULT;
315 if (GetStatus(Cn3D_bRender[0]) == TRUE)
316 bRender = bRender | (Byte) KIN_VIRTUAL;
317 if (GetStatus(Cn3D_bRender[1]) == TRUE)
318 bRender = bRender | (Byte) KIN_BACKBONE;
319 if (GetStatus(Cn3D_bRender[2]) == TRUE)
320 bRender = bRender | (Byte) KIN_RESIDUE;
321 if (GetStatus(Cn3D_bRender[3]) == TRUE)
322 bRender = bRender | (Byte) KIN_HET;
323 if (GetStatus(Cn3D_bRender[4]) == TRUE)
324 bRender = bRender | (Byte) KIN_ALTCONF;
325 if (GetStatus(Cn3D_bRender[5]) == TRUE)
326 bRender = bRender | (Byte) KIN_MULTANIM;
327 pdnmsMain = GetSelectedModelstruc();
328 #ifdef WIN_MAC
329 FileCreate(path, "TEXT", "ttxt");
330 #endif
331 WatchCursor();
332 pFile = FileOpen(path, "w");
333 if (pFile) {
334 iTest = WriteKinModelList(pdnmsMain, pFile, iColor, bRender,
335 iCount, i2Vec);
336 I2VectorFree(i2Vec, 0);
337 if (!iTest) {
338 ErrClear();
339 ErrPostEx(SEV_FATAL, 0, 0,
340 "Unable to Export\nPossibly Corrupt Data in Memory!\n");
341 ErrShow();
342 }
343 fflush(pFile);
344 fclose(pFile);
345 } else {
346 ErrClear();
347 ErrPostEx(SEV_INFO, 0, 0, "Sorry, Unable to Open File:\n %s",
348 path);
349 ErrShow();
350 Disable(Cn3D_bKinOk);
351 I2VectorFree(i2Vec, 0);
352 SetTitle(Cn3D_tKinSave, "\0");
353 ArrowCursor();
354 return;
355 }
356 Remove(Cn3D_wKinSave);
357 Cn3D_EnableFileOps();
358 Cn3D_Export_InUse = FALSE;
359 ArrowCursor();
360 return;
361 }
362
Cn3D_CancelKin(ButtoN b)363 static void Cn3D_CancelKin(ButtoN b)
364 {
365 Remove(Cn3D_wKinSave);
366 Cn3D_EnableFileOps();
367 Cn3D_Export_InUse = FALSE;
368 return;
369 }
370
371
Cn3D_ExportKin(IteM i)372 static void Cn3D_ExportKin(IteM i)
373 {
374 PDNMS pdnmsThis = NULL;
375 PMSD pmsdThis = NULL;
376 Char pcSavestr[60];
377 Char pcSavename[32];
378 CharPtr Cn3D_pcKinName;
379 GrouP g, g2, g3, g4;
380 GrouP gMS;
381 ButtoN b;
382 Int2 iCount;
383
384 if (Cn3D_Export_InUse)
385 return;
386 else
387 Cn3D_Export_InUse = TRUE;
388
389 pdnmsThis = GetSelectedModelstruc();
390 if (!pdnmsThis) {
391 Cn3D_Export_InUse = FALSE;
392 return;
393 }
394 pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
395
396 Cn3D_wKinSave = ModalWindow(-20, -13, -10, -10, NULL);
397
398 /* set up a group encolosing structures - models selection lists and - "info strings" */
399 Cn3D_pcKinName = StringSave(GetStrucStrings(pdnmsThis, PDB_ACC));
400 sprintf(pcSavestr, "Save %s As a Kinemage Rendered File ...",
401 Cn3D_pcKinName);
402 g = HiddenGroup(Cn3D_wKinSave, 0, 5, NULL);
403 SetGroupMargins(g, 10, 10);
404 SetGroupSpacing(g, 10, 5);
405 StaticPrompt(g, pcSavestr, 0, 0, systemFont, 'l');
406 g2 = HiddenGroup(g, 2, 0, NULL);
407 SetGroupMargins(g2, 10, 10);
408 SetGroupSpacing(g2, 10, 5);
409 StringNCpy(pcSavename, Cn3D_pcKinName, 8);
410 StringCat(pcSavename, ".kin");
411 Cn3D_tKinSave =
412 DialogText(g2, pcSavename, 18, (TxtActnProc) Cn3D_KinEnableProc);
413 MemFree(Cn3D_pcKinName);
414
415 Cn3D_bKinBrowse =
416 PushButton(g2, " browse...", (BtnActnProc) Cn3D_KinBrowseProc);
417 g3 = HiddenGroup(g, 2, 0, NULL);
418 gMS = Cn3D_ModelSelect(g3, FALSE); /* no vector models for Kin files saves */
419 g4 = HiddenGroup(g3, 0, 2, NULL);
420 SetGroupMargins(g4, 10, 10);
421 SetGroupSpacing(g4, 10, 5);
422 Cn3D_bKinOk = PushButton(g4, "OK", Cn3D_ExportKinNow);
423 b = PushButton(g4, "Cancel", Cn3D_CancelKin);
424
425 Cn3D_gColorAtoms =
426 NormalGroup(g, 2, 2, " color by...", systemFont, NULL);
427 SetGroupMargins(Cn3D_gColorAtoms, 10, 10);
428 SetGroupSpacing(Cn3D_gColorAtoms, 10, 5);
429 RadioButton(Cn3D_gColorAtoms, "Molecule number");
430 RadioButton(Cn3D_gColorAtoms, "Secondary Structure & Residue Type");
431 RadioButton(Cn3D_gColorAtoms, "Thermal Factors");
432 RadioButton(Cn3D_gColorAtoms, "Element");
433 SetValue(Cn3D_gColorAtoms, 1);
434
435 Cn3D_gRenderOpts =
436 NormalGroup(g, 2, 3, " viewable subsets...", systemFont, NULL);
437 Cn3D_bRender[0] = CheckBox(Cn3D_gRenderOpts, "Virtual Backbone", NULL);
438 Cn3D_bRender[1] = CheckBox(Cn3D_gRenderOpts, "Real Backbone", NULL);
439 Cn3D_bRender[2] = CheckBox(Cn3D_gRenderOpts, "Residues", NULL);
440 Cn3D_bRender[3] = CheckBox(Cn3D_gRenderOpts, "Heterogens", NULL);
441 Cn3D_bRender[4] =
442 CheckBox(Cn3D_gRenderOpts, "Alternate Conformations", NULL);
443 Cn3D_bRender[5] = CheckBox(Cn3D_gRenderOpts, "NMR Animations", NULL);
444 for (iCount = 0; iCount < 6; iCount++)
445 SetStatus(Cn3D_bRender[iCount], TRUE);
446
447 Cn3D_KinEnableProc(NULL);
448 Select(Cn3D_bKinOk);
449 /* disable appropriate stuff here */
450 Cn3D_DisableFileOps();
451 Show(Cn3D_wKinSave);
452
453 return;
454 }
455
456 #ifndef _OPENGL
Cn3D_GifSaveProc(IteM i)457 static void Cn3D_GifSaveProc(IteM i)
458 {
459 Char fname[PATH_MAX];
460 Char defname[32];
461 PDNMS pdnmsThis = GetSelectedModelstruc();
462
463 fname[0] = '\0';
464 defname[0] = '\0';
465
466 if (pdnmsThis == NULL)
467 StringNCpy_0(defname,
468 pdnmsThis ? GetStrucStrings(pdnmsThis,
469 PDB_ACC) : "cn3d",
470 sizeof(defname) - 4);
471 StringCat(defname, ".gif");
472
473 if (GetOutputFileName(fname, sizeof(fname), defname)) {
474 SaveImageGIF(Nlm_GetViewerImage3D(Cn3D_v3d), fname);
475 }
476 }
477
478 #else
479
480 #if defined(_PNG)
Cn3D_PNGSaveProc(IteM i)481 static void Cn3D_PNGSaveProc(IteM i)
482 {
483 Char fname[PATH_MAX];
484 Char defname[32];
485 PDNMS pdnmsThis = GetSelectedModelstruc();
486
487 fname[0] = '\0';
488 defname[0] = '\0';
489
490 if (pdnmsThis == NULL)
491 StringNCpy_0(defname,
492 pdnmsThis ? GetStrucStrings(pdnmsThis,
493 PDB_ACC) : "cn3d",
494 sizeof(defname) - 4);
495 StringCat(defname, ".png");
496
497 if (GetOutputFileName(fname, sizeof(fname), defname)) {
498 Nlm_SaveImagePNG(fname);
499 }
500 }
501 #endif /* _PNG */
502
Cn3D_GetCurrentOGLData(void)503 TOGL_Data * Cn3D_GetCurrentOGLData(void)
504 {
505 return Cn3D_ColorData.OGL_Data;
506 }
507
508
509 #endif /* _OPENGL */
510
Cn3D_ExportSub(MenU m)511 MenU LIBCALL Cn3D_ExportSub(MenU m)
512 {
513 IteM i;
514 MenU s;
515
516 s = SubMenu(m, "Export");
517 i = CommandItem(s, "PDB File...", Cn3D_ExportPDB);
518 i = CommandItem(s, "Kinemage File...", Cn3D_ExportKin);
519 #ifndef _OPENGL
520 i = CommandItem(s, "GIF.../S", Cn3D_GifSaveProc);
521 #endif
522 #if defined(_OPENGL) && defined(_PNG)
523 i = CommandItem(s, "PNG...", Cn3D_PNGSaveProc);
524 #endif
525 return s;
526 }
527