NCBI C Toolkit Cross Reference

C/cn3d/cn3dwin.c


  1 /*  $Id: cn3dwin.c,v 6.162 2001/05/25 19:16:15 vakatov Exp $
  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 * Author:  Christopher Hogue, Yanli Wang, Lewis Geer, Jonathan Kans
 27 *
 28 * First Version Creation Date:   1/31/96
 29 *
 30 * File Description:  Cn3D GUI API
 31 *
 32 * Modifications:
 33 * --------------------------------------------------------------------------
 34 * $Log: cn3dwin.c,v $
 35 * Revision 6.162  2001/05/25 19:16:15  vakatov
 36 * Nested comment typo fixed
 37 *
 38 * Revision 6.161  2001/04/27 20:08:07  juran
 39 * Heed warnings.
 40 *
 41 * Revision 6.160  2000/08/17 16:09:53  thiessen
 42 * fix X/OpenGL initialization bug
 43 *
 44 * Revision 6.159  2000/05/17 22:27:36  lewisg
 45 * rename viewer controls
 46 *
 47 * Revision 6.158  2000/05/16 17:38:43  thiessen
 48 * do glGenLists after context init on X11 - for Mesa 3.2
 49 *
 50 * Revision 6.157  2000/05/09 19:51:01  lewisg
 51 * add new blast header to file>properties
 52 *
 53 * Revision 6.156  2000/04/27 22:21:57  lewisg
 54 * misc bugs/features
 55 *
 56 * Revision 6.155  2000/04/25 00:22:35  thiessen
 57 * save quality settings in config
 58 *
 59 * Revision 6.154  2000/04/20 23:27:45  lewisg
 60 * misc bug fixes
 61 *
 62 * Revision 6.153  2000/04/19 17:56:48  thiessen
 63 * added background color in OpenGL
 64 *
 65 * Revision 6.152  2000/04/17 21:46:56  lewisg
 66 * do not do double index on viewmgr update, rename menus
 67 *
 68 * Revision 6.151  2000/04/10 21:41:26  lewisg
 69 * move alignment menus into ddv, udv from cn3d
 70 *
 71 * Revision 6.150  2000/04/04 22:18:43  lewisg
 72 * add defline to ddv, fix seq import bugs, set boundbox
 73 *
 74 * Revision 6.149  2000/03/27 22:15:05  lewisg
 75 * add show/hide row dialog
 76 *
 77 * Revision 6.148  2000/03/24 20:34:55  lewisg
 78 * add blast from file, bug fixes, get rid of redundant code, etc.
 79 *
 80 * Revision 6.147  2000/03/24 19:59:20  thiessen
 81 * draw new logo in OpenGL
 82 *
 83 * Revision 6.146  2000/03/23 14:53:04  thiessen
 84 * fix bug in viewer3d camera; added conservation color algorithm to ARS
 85 *
 86 * Revision 6.145  2000/03/18 00:06:00  lewisg
 87 * add blast, new help, new menus
 88 *
 89 * Revision 6.144  2000/03/17 22:49:00  thiessen
 90 * fix for multi-chain / multi-model features ; added feature-move ; misc bug fixes
 91 *
 92 * Revision 6.143  2000/03/15 18:49:07  thiessen
 93 * fixed viewer3d color bug
 94 *
 95 * Revision 6.142  2000/03/15 16:59:55  thiessen
 96 * fix highlighting, other minor bugs
 97 *
 98 * Revision 6.141  2000/03/15 04:43:56  thiessen
 99 * various minor fixes
100 *
101 * Revision 6.140  2000/03/10 18:46:59  lewisg
102 * add show/hide
103 *
104 * Revision 6.139  2000/03/09 18:58:55  thiessen
105 * fixed typo
106 *
107 * Revision 6.138  2000/03/09 17:56:58  thiessen
108 * changes to palette handling, feature implementation, PARS storage
109 *
110 * Revision 6.137  2000/03/08 21:46:15  lewisg
111 * cn3d saves viewport, misc bugs
112 *
113 * Revision 6.136  2000/03/06 15:33:53  lewisg
114 * add new hydrophobic palette, update visual c++ project to move seqcons
115 *
116 * Revision 6.135  2000/03/03 20:05:17  thiessen
117 * removal of palette-building pass if in 24-bit color
118 *
119 * Revision 6.134  2000/03/01 16:17:55  thiessen
120 * improved handling of colors; many small fixes
121 *
122 * Revision 6.133  2000/02/26 00:01:41  thiessen
123 * OpenGL improvements, progress on cleanup of Show/Hide
124 *
125 * Revision 6.132  2000/02/22 17:10:00  thiessen
126 * fix typecast error
127 *
128 * Revision 6.131  2000/02/19 21:25:57  thiessen
129 * split of cn3dmodl into cn3dmodl and cn3dstyl
130 *
131 * Revision 6.130  2000/02/19 01:23:59  lewisg
132 * use ibm, add row tracking code, various bug fixes
133 *
134 * Revision 6.129  2000/02/17 15:41:11  thiessen
135 * added CSC algorithm selection submenu
136 *
137 * Revision 6.128  2000/02/10 19:04:25  thiessen
138 * added checkbox to change altConf behaviour
139 *
140 * Revision 6.127  2000/02/10 17:47:02  thiessen
141 * added: color-by-sequence-conservation menu item, zoom-out to OpenGL, misc fixes
142 *
143 * Revision 6.126  2000/02/10 15:51:59  lewisg
144 * cn3d responds and send correct update messages.  many coloring bug fixes
145 *
146 * Revision 6.125  2000/01/18 22:49:16  lewisg
147 * send OM_MSG_FLUSH to ddv/udv, tweak CPK coloration, misc bugs
148 *
149 * Revision 6.124  2000/01/14 21:40:41  lewisg
150 * add translucent spheres, ion labels, new cpk, fix misc bugs
151 *
152 * Revision 6.123  2000/01/11 01:16:47  lewisg
153 * fix color selection in Cn3D, other misc. bugs
154 *
155 * Revision 6.122  2000/01/06 00:04:43  lewisg
156 * selection bug fixes, update message outbound, animation APIs moved to vibrant
157 *
158 * Revision 6.121  2000/01/04 15:55:51  lewisg
159 * don't hang on disconnected network and fix memory leak/hang at exit
160 *
161 * Revision 6.120  1999/12/28 15:08:44  lewisg
162 * remove remaining mediainfo code
163 *
164 * Revision 6.119  1999/12/23 22:22:53  lewisg
165 * fix Cn3D_Align undefined for non-opengl build
166 *
167 * Revision 6.118  1999/12/23 21:40:33  lewisg
168 * move animation controls to dialog
169 *
170 * Revision 6.117  1999/12/13 23:20:44  lewisg
171 * bug fixes: duplicate color structures eliminated, clear color doesn't clear case
172 *
173 * Revision 6.116  1999/12/11 01:30:35  lewisg
174 * fix bugs with sharing colors between ddv and cn3d
175 *
176 * Revision 6.115  1999/12/08 22:58:01  thiessen
177 * added quality settings for OpenGL rendering
178 *
179 * Revision 6.114  1999/12/03 23:17:23  lewisg
180 * Patrick's new global update msg, argument passing when launching ddv, experimental editing
181 *
182 * Revision 6.113  1999/12/01 16:15:54  lewisg
183 * interim checkin to fix blocking memory leak
184 *
185 * Revision 6.112  1999/11/30 22:32:10  vakatov
186 * Changed "#if _OPENGL" to "#ifdef _OPENGL" to suit Borland 5.0 compiler
187 *
188 * Revision 6.111  1999/11/24 15:23:20  lewisg
189 * added color selection dialogs for SS
190 *
191 * Revision 6.110  1999/11/23 19:23:09  thiessen
192 * change OGL_Redraw to OGL_DrawViewer3D
193 *
194 * Revision 6.109  1999/11/22 17:29:54  lewisg
195 * add back color selection dialogs, fix viewer3d half-selection bug
196 *
197 * Revision 6.108  1999/11/22 15:44:05  thiessen
198 * added image.h header to fix Mac compiler error
199 *
200 * Revision 6.107  1999/11/22 14:46:45  thiessen
201 * moved _OPENGL code blocks to only vibrant and ncbicn3d libraries
202 *
203 * Revision 6.105  1999/11/15 18:30:09  lewisg
204 * get rid of extra redraws when selecting
205 *
206 * Revision 6.104  1999/11/10 23:19:42  lewisg
207 * rewrite of selection code for ddv
208 *
209 * Revision 6.103  1999/11/03 16:24:21  lewisg
210 * get rid of non-existing includes
211 *
212 * Revision 6.102  1999/11/02 23:06:08  lewisg
213 * fix cn3d to launch correctly if there is no seqentry associated with bioseq
214 *
215 * Revision 6.101  1999/11/01 22:10:27  lewisg
216 * add ability to call color functions by type, and add this to cn3d
217 *
218 * Revision 6.100  1999/10/29 14:15:31  thiessen
219 * ran all Cn3D source through GNU Indent to prettify
220 *
221 * Revision 6.99  1999/10/15 20:56:40  lewisg
222 * append DDV_ColorGlobal as userdata.  free memory when cn3d terminates.
223 *
224 * Revision 6.98  1999/10/08 23:20:35  lewisg
225 * add case and box attributes to DDV_ColorCell
226 *
227 * Revision 6.97  1999/10/05 23:18:25  lewisg
228 * add ddv and udv to cn3d with memory management
229 *
230 * Revision 6.96  1999/09/21 18:09:15  lewisg
231 * binary search added to color manager, various bug fixes, etc.
232 *
233 * Revision 6.95  1999/09/21 13:59:22  thiessen
234 * port of Lewis's OpenGL code to X/Motif
235 *
236 * Revision 6.94  1999/09/16 17:16:21  ywang
237 * open multiple salsa window for data with multiple seq-annot data
238 *
239 * Revision 6.93  1999/09/15 14:22:13  ywang
240 * modify Cn3D_AlignEdit to open multiple salsa window for alignment
241 *
242 * Revision 6.92  1999/07/09 20:50:56  ywang
243 * set highlight color for salsa in Cn3dObjRegiste
244 *
245 * Revision 6.91  1999/07/01 21:44:49  ywang
246 * *** empty log message ***
247 *
248 * Revision 6.90  1999/07/01 14:07:25  ywang
249 * cn3dwin.c
250 *
251 * Revision 6.89  1999/06/30 16:51:08  ywang
252 * comment out 'Salsa_BioseqUpdate = TRUE' in AlignEdit
253 *
254 * Revision 6.88  1999/06/15 18:18:16  ywang
255 * loop over all the existed models for highligt
256 *
257 * Revision 6.87  1999/05/27 16:12:22  ywang
258 * synchronize highlight color change in the cn3d viewer
259 *
260 * Revision 6.86  1999/05/04 23:12:47  ywang
261 * fix selection retaining problem on show/hide
262 *
263 * Revision 6.85  1999/04/08 15:08:02  ywang
264 * disable color by SeqConservation
265 *
266 * Revision 6.84  1999/04/06 14:23:30  lewisg
267 * add opengl replacement for viewer3d
268 *
269 * Revision 6.83  1999/03/30 22:36:19  ywang
270 * add functions to color salsa for NcbiMimeAsn1_strucseqs & code reorganization
271 *
272 * Revision 6.82  1999/03/22 22:41:53  ywang
273 * redesign feature page, fix bugs
274 *
275 * Revision 6.81  1999/03/03 23:17:22  lewisg
276 * one master struct at a time, list slaves in structure info, bug fixes
277 *
278 * Revision 6.80  1999/03/02 22:05:58  lewisg
279 * warn on less than 256 entry palette
280 *
281 * Revision 6.79  1999/02/25 23:14:32  ywang
282 * move around menu item and callback function, change menu item names
283 *
284 * Revision 6.78  1999/02/24 23:16:03  ywang
285 * minor name change
286 *
287 * Revision 6.77  1999/02/12 15:11:52  ywang
288 * send color message to salsa when user changes highlight color from cn3d
289 *
290 * Revision 6.76  1999/02/11 22:39:47  ywang
291 * fix bug on display highlight residues only--if no res are highlighted, cn3d sets that button status as FALSE and draw whole structures
292 *
293 * Revision 6.75  1999/02/11 18:48:15  lewisg
294 * delete color index functions
295 *
296 * Revision 6.74  1999/02/10 23:49:43  lewisg
297 * use RGB values instead of indexed palette
298 *
299 * Revision 6.73  1999/01/27 16:23:34  ywang
300 * return on NULL pdnmsMaster in Cn3D_AlignEdit
301 *
302 * Revision 6.72  1999/01/26 17:14:34  ywang
303 * redesign Display menu and add 'display highlight residues only' function
304 *
305 * Revision 6.71  1999/01/20 22:57:23  ywang
306 * customize color for secondary structure & rearrange Option menu
307 *
308 * Revision 6.70  1999/01/20 18:21:20  ywang
309 * include salmedia.h due to the move around of MediaInfo from cn3dmsg.h to the new created salmedia.h
310 *
311 * Revision 6.69  1999/01/14 19:07:17  kans
312 * network availability is configurable
313 *
314 * Revision 6.68  1998/12/16 19:32:19  ywang
315 * improve highlight residues function when rerendering
316 *
317  * Revision 6.67  1998/11/24  17:01:01  kans
318  * put render/label/view/model controls in separate window
319  *
320 * Revision 6.66  1998/11/06 23:01:05  ywang
321 * fix bugs for modeling
322 *
323  * Revision 6.65  1998/11/04  00:06:24  ywang
324  * add function for modeling: change render/color for special residue(s)
325  *
326  * Revision 6.64  1998/10/30  19:42:38  ywang
327  * turn animation on by default
328  *
329  * Revision 6.63  1998/10/27  15:55:53  ywang
330  * add functions for testing color by sequence conservation
331  *
332  * Revision 6.62  1998/10/21  21:16:56  ywang
333  * update highlight RGB in the global application property data structure
334  *
335  * Revision 6.61  1998/10/21  15:51:27  ywang
336  * reset residue color for salsa before cn3d redraws so that residues shown in salsa will become black if they are not shown in cn3d window
337  *
338  * Revision 6.60  1998/10/16  22:06:09  ywang
339  * make global color array for sequence display
340  *
341  * Revision 6.59  1998/10/07  23:10:46  ywang
342  * merge align control with general display control
343  *
344  * Revision 6.58  1998/10/05  21:24:36  ywang
345  * re-arrange menu
346  *
347  * Revision 6.57  1998/09/30  22:10:48  ywang
348  * control display on three levels: structure, chain, domain
349  *
350  * Revision 6.56  1998/09/23  18:38:50  ywang
351  * add functions to control display on domain level
352  *
353  * Revision 6.55  1998/09/22  17:53:13  ywang
354  * add menu for display control
355  *
356  * Revision 6.54  1998/09/17  20:51:17  ywang
357  * add functions for edit background and highlight color
358  *
359  * Revision 6.53  1998/09/04  19:50:53  ywang
360  * reorganize codes for highlighting
361  *
362  * Revision 6.52  1998/09/01  18:19:15  ywang
363  * initialize IteM i = NULL in LaunchSequenceWindow
364  *
365  * Revision 6.51  1998/08/26  18:28:38  kans
366  * fixed -v -fd warnings
367  *
368 * Revision 6.50  1998/08/17 18:45:48  lewisg
369 * change version to 2.01
370 *
371 * Revision 6.49  1998/08/05 19:12:36  ywang
372 * comment out MK_Shift/MA_DClick, MK_Ctrl/MA_DClick
373 *
374  * Revision 6.48  1998/07/23  14:34:30  chappey
375  * resize of salsa window
376  *
377 * Revision 6.47  1998/07/22 20:18:34  lewisg
378 * resize of salsa window
379 *
380 * Revision 6.46  1998/07/16 18:18:39  chappey
381 * SeqIsIn -> SeqIdForSameBioseq
382 *
383 * Revision 6.45  1998/07/13 23:19:57  ywang
384 * check hidden sequence whenever launching salsa
385 *
386  * Revision 6.44  1998/07/09  21:47:37  ywang
387  * reduce color messages for salsa
388  *
389  * Revision 6.43  1998/06/30  23:29:22  ywang
390  * fix bugs regarding to read in more structures
391  *
392  * Revision 6.42  1998/06/30  20:49:02  ywang
393  * improve performance and prepare for close salsa
394  *
395  * Revision 6.41  1998/06/22  18:58:07  chappey
396  * moved GetAppProperty SeqEditDisplayForm to cn3dwin.c
397  *
398 * Revision 6.40  1998/06/17 17:42:25  lewisg
399 * moved a menu item
400 *
401 * Revision 6.39  1998/06/16 18:00:30  lewisg
402 * moved rendering menus and created a reset presentation menu item
403 *
404 * Revision 6.38  1998/06/10 22:04:32  ywang
405 * remove obsolete code
406 *
407  * Revision 6.37  1998/06/10  22:01:08  ywang
408  * remove obsolete code
409  *
410  * Revision 6.36  1998/06/04  16:33:26  ywang
411  * autamatially launch salsa window
412  *
413  * Revision 6.35  1998/05/28  22:06:00  ywang
414  * maintain highlight upon rendering switch when salsa is on
415  *
416  * Revision 6.33  1998/05/26  22:06:13  ywang
417  * salsa get cn3d color when it is launched
418  *
419  * Revision 6.32  1998/05/26  21:35:21  lewisg
420  * added defaults to render menu, got rid of mouse 3D actions menu item
421  *
422 * Revision 6.31  1998/05/18 22:09:14  ywang
423 * move codes around
424 *
425  * Revision 6.30  1998/05/18  16:45:52  ywang
426  * allocate memory for mediadata
427  *
428  * Revision 6.29  1998/05/14  14:53:42  ywang
429  * fix bugs
430  *
431  * Revision 6.27  1998/05/06  23:50:27  lewisg
432  * fixed launching problem with sequin
433  *
434 * Revision 6.26  1998/05/05 20:06:36  ywang
435 * set yellow as highlight color in cn3d
436 *
437  * Revision 6.25  1998/04/30  15:22:29  ywang
438  * start to store Num_ActiveSlave
439  *
440  * Revision 6.24  1998/04/29  18:03:06  lewisg
441  * new menus
442  *
443 * Revision 6.23  1998/04/28 22:47:24  lewisg
444 * master/slave color in sync
445 *
446 * Revision 6.22  1998/04/28 18:51:07  ywang
447 * slight modification
448 *
449  * Revision 6.21  1998/04/27  17:49:57  lewisg
450  * added color by conservation
451  *
452 * Revision 6.20  1998/04/20 16:03:27  ywang
453 * launch sequence viewer correctly in one biostruc/multiple chain case
454 *
455  * Revision 6.19  1998/04/18  00:33:51  lewisg
456  * added ability to turn slaves on/off
457  *
458 * Revision 6.18  1998/04/17 01:08:13  ywang
459 * call LaunchAlignEditor in one pair alignment case while call LaunchAnnotAlignEditor in multiple alignment case
460 *
461  * Revision 6.16  1998/04/15  19:22:51  chappey
462  * Add REGISTER_NEW_SEQANNOT_EDIT to be able to launch multiple alignment from the SeqAnnot
463  *
464 * Revision 6.15  1998/04/14 21:16:56  ywang
465 * try to pass the head of alignment data link list to salsa
466 *
467  * Revision 6.14  1998/04/09  17:07:23  lewisg
468  * added a version # and got rid of File/Vast Alignments
469  *
470 * Revision 6.13  1998/04/03 18:06:24  ywang
471 * show NA sequence also
472 *
473  * Revision 6.12  1998/04/02  23:01:51  kans
474  * code warrior distinguishes 0 from NULL
475  *
476 * Revision 6.11  1998/04/02 22:27:18  ywang
477 * multiple sequence viewer for multiple chain protein
478 *
479  * Revision 6.9  1998/04/01  01:26:19  ywang
480  * sequence view and get blast alignment-Colombe
481  *
482 * Revision 6.8  1998/03/30 23:32:28  ywang
483 * Set Hightlight Color as Red instead of Blue; Associate simple double click action with one residue highlight
484 *
485  * Revision 6.7  1998/03/30  16:02:11  kans
486  * changed printf to ErrPostEx
487  *
488 * Revision 6.6  1998/03/27 23:17:38  ywang
489 * Get psaAlignment from pmsdMaster
490 *
491  * Revision 6.5  1998/03/26  22:27:42  kans
492  * fixed CodeWarrior complaints and missing prototypes
493  *
494 * Revision 6.4  1998/03/26 20:44:20  ywang
495 * start cn3d messager
496 *
497  * Revision 6.3  1998/03/07  20:43:53  kans
498  * moved Cn3D_fEntrezOn to cn3dwin.c
499  *
500 * Revision 6.2  1998/03/06 19:03:00  kans
501 * needed to add two includes
502 *
503 * Revision 6.1  1998/03/06 01:22:59  lewisg
504 * merge
505 *
506 * Revision 6.0  1997/08/25 18:13:48  madden
507 * Revision changed to 6.0
508 *
509 * Revision 1.4  1997/07/29 21:17:11  vakatov
510 * [WIN32,DLL]  Made Cn3D's stubbed functions be DLL-exportable
511 *
512 * Revision 1.3  1997/03/31 16:53:14  vakatov
513 * Use Z-rotation scrollbar in the 3D-viewer controls.
514 * Changed the CN3D release from 1.0 to 1.1.
515 *
516  * Revision 1.2  1997/03/20  21:21:12  vakatov
517  * [WIN_MAC] Cn3DResizeProc():  take into account the window menubar height
518  *
519  * Revision 1.1  1997/03/20  16:24:36  vakatov
520  * Initial revision
521  *
522  * Revision 5.18  1996/08/19  21:05:26  vakatov
523  * Made functions of type "pNodeFunc" to be of that type(sharp)
524  * (and thus fixed fatal bug under Borland/WIN32); removed all
525  * castings to (pNodeFunc) -- to let compiler to check for such bugs
526  *
527  * Revision 5.17  1996/07/31  18:36:32  hogue
528  * Segment highlighting code added, MIME-type code from Network Entrez
529  * adapted for STANDALONE Cn3D.
530  *
531  * Revision 5.16  1996/07/29  21:12:44  epstein
532  * add logic to hide query window when cn3d MIME viewer starts up
533  *
534  * Revision 5.15  1996/07/26  18:57:41  kans
535  * hide and update, then show and update
536  *
537  * Revision 5.14  1996/07/22  00:26:37  hogue
538  * Default 3D viewer made smaller, Help menu refers to WWW-site,
539  * Quit Entrez menu item, and About Structure menu item which
540  * displays Structure Summary + PDB remarks.  Also trapped
541  * no-primitives condition.
542  *
543  * Revision 5.13  1996/06/14  14:54:19  vakatov
544  * [WIN_MOTIF]  RestrictMotifColorsTo( 32 ) call added before creating
545  * 3D-Viewer shell window -- to provide proper Motif/3D-V color sharing
546  *
547  * Revision 5.12  1996/06/13  21:26:45  kans
548  * fixed mac resize
549  *
550  * Revision 5.11  1996/06/13  21:05:31  kans
551  * fixed mac-specific typos
552  *
553  * Revision 5.10  1996/06/13  20:49:10  hogue
554  * Removed Beta designation .
555  *
556  * Revision 5.9  1996/06/13  20:44:17  hogue
557  * Hides window now when starting up in Entrez, fix for Mac window
558  * resize problem.
559  *
560  * Revision 5.8  1996/06/13  16:36:42  kans
561  * menus now in the window for all platforms, including Mac
562  *
563  * Revision 5.7  1996/06/12  14:31:33  hogue
564  * Added Cn3DWin function for integration into Entrez
565  *
566  * Revision 5.6  1996/06/05  16:28:45  hogue
567  * Fixed a gif file name save bug.
568  *
569  * Revision 5.5  1996/06/03  22:36:08  hogue
570  * Rearragned top menus for ease of use & cosmetic reasons.
571  *
572  * Revision 5.4  1996/06/03  21:20:09  hogue
573  * Changed FixedWindow to DocumentWindwo for Win/Mac resize-ability,
574  * Added call to MyQuit to stop playing layers if was on.  Also
575  * added an initial call to the resizer to clean up sizing problems
576  * on startup.
577  *
578  * Revision 5.3  1996/06/03  20:00:57  kans
579  * command item was missing a closing double quo;te
580  *
581  * Revision 5.2  1996/06/03  19:43:52  vakatov
582  * Quit the program more careful
583  *
584  * Revision 5.1  1996/05/29  19:16:02  vakatov
585  * Cn3DResizeProc():  LinkAnimCtrls3D() call added to relink 3D-controls
586  * to the new 3D-viewer
587  *
588  * Revision 5.0  1996/05/28  14:05:44  ostell
589  * Set to revision 5.0
590  *
591  * Revision 1.17  1996/05/23  14:33:49  hogue
592  * Added Image menu with Zoom, Move, All, Save fn;
593  * Added MS-Win Edit menu (Copy only) and Print fn on Image menu
594  * Added call to stop animation playing for redraw.
595  *
596  * Revision 1.16  1996/05/22  21:23:54  hogue
597  * Added Watch/Arrow cursor calls, ProgMon.
598  *
599  * Revision 1.15  1996/05/21  22:50:10  hogue
600  * Capture camera of current structure before resize.
601  *
602  * Revision 1.14  1996/05/21  22:18:49  hogue
603  * Added call to ResetLabelCtrls
604  *
605  * Revision 1.13  1996/05/21  22:12:28  vakatov
606  * "Cn3DResizeProc()" rewritten and it is now able to count the menu-bar height
607  * "Viewer3DGroups()" modified to better control over the groups positioning
608  *
609  * Revision 1.12  1996/05/14  15:45:16  hogue
610  * Added UpdateColorTable call & changed palette structure accordingly,
611  * Added Cn3dResizeProc and set up the Label,
612  * Render & Viewer Controls and the 3D window to move around as planned-
613  *  which uncovers new bugs in Viewer3d code...
614  *
615  * Revision 1.11  1996/05/09  15:41:10  hogue
616  * Domain rendering enabled.
617  *
618  * Revision 1.10  1996/05/07  18:30:58  vakatov
619  * Viewer3DGroups() -- slightly changed;  + casting...
620  *
621  * Revision 1.9  1996/04/26  21:44:21  vakatov
622  * Tune the 3D-viewer size to fit the screen
623  *
624  * Revision 1.8  1996/04/26  18:42:24  vakatov
625  * CN3D sources ported to MS-Windows;
626  * the portability errors and warnings fixed, etc.
627  *
628  * Revision 1.7  1996/04/18  16:57:01  hogue
629  * Altered color palette for multi-structure display, preparing for neighbors...
630  *
631  * Revision 1.6  1996/04/04  21:05:21  hogue
632  * rearranged menus, fixed camera calls, added NCBI logo
633  *
634  * Revision 1.5  1996/03/30  23:40:19  hogue
635  * Redraw now saves camera
636  *
637  * Revision 1.4  1996/03/29  20:00:06  hogue
638  * Integrated 3d viewing, menus & controls for algorithmic rendering
639  *
640  * Revision 1.2  1996/02/02  19:39:32  hogue
641  * Initial Revision
642  *
643 *
644 * ==========================================================================
645 */
646 
647 #include <ncbi.h>
648 #include <accentr.h>
649 #include <cn3dmain.h>
650 #include <cn3dopen.h>
651 #include <cn3dxprt.h>
652 #include <cn3dsave.h>
653 #include <algorend.h>
654 #include <objalign.h>
655 #include <objseq.h>
656 #include <objmgr.h>
657 #include <saledit.h>
658 #include <lsqfetch.h>
659 #include <salutil.h>
660 #include <cn3dmsg.h>
661 #include <salmedia.h>
662 #include <cn3dshim.h>
663 #include <diagnost.h>
664 #include <cn3dmesh.h>
665 #include <udviewer.h>
666 #include <vsm.h>
667 #include <image.h>
668 #include <seqcons.h>
669 #include <cn3dmodl.h>
670 #include <cn3dstyl.h>
671 #include <bspview.h>
672 #ifdef _OPENGL
673 #include <shim3d.h>
674 #endif
675 
676 static Uint2 Cn3D_Vy, Cn3D_Rx;
677 static MenU Cn3D_sOpen;
678 static IteM Cn3D_iOpen;
679 static IteM Cn3D_iSelStruc;
680 static IteM Cn3D_iClearStruc;
681 static IteM Cn3D_iRendCtrl = NULL;
682 static IteM Cn3D_iLabelCtrl = NULL;
683 static IteM Cn3D_iAlignCtrl = NULL;
684 static IteM Cn3D_iDisplayCtrl = NULL; /* For display control, Yanli */
685 #ifndef _OPENGL
686 static IteM Cn3D_iViewCtrl = NULL;
687 #endif
688 static IteM Cn3D_iModelCtrl = NULL;
689 static IteM Cn3D_sSave = NULL;
690 static MenU Cn3D_sExport;
691 static WindoW Cn3D_w = NULL;
692 static MenU Cn3D_ma_group_menu;
693 static MenU Cn3D_ma_action_menu;
694 /*static MenU     Cn3D_sNaybor;*/
695 static MenU Cn3D_mRender;
696 static MenU Cn3D_mColor;
697 static MenU Cn3D_mControls;
698 static WindoW Cn3D_wCtrls = NULL;
699 
700 static Uint1 errNum;
701 static Int1 errType;
702 static CharPtr errMsg;
703 
704 #ifndef _OPENGL
705 Viewer3D Cn3D_v3d = NULL;
706 static Picture3D Cn3D_pMain;
707 static Camera3D Cn3D_Camera3D;
708 #endif
709 TCn3D_ColorData Cn3D_ColorData;
710 
711 
712 static GrouP Cn3D_gWinGP;
713 static GrouP Cn3D_gViewer;
714 static GrouP Cn3D_gRendCtrl;
715 static GrouP Cn3D_gLabelCtrl;
716 static GrouP Cn3D_gAlignCtrl;
717 static GrouP Cn3D_gDisplayCtrl; /* For display control, Yanli  */
718 static GrouP Cn3D_gModelCtrl;   /* For modeling, Yanli  */
719 static GrouP Cn3D_gViewCtrl;
720 #ifdef _OPENGL
721 /*static GrouP Cn3D_gOGLCtrl;*/     /* group that controls 3D view, including animation */
722 static GrouP Cn3D_gOGLQuality;  /* group that controls rendering quality */
723 #endif                          /* _OPENGL */
724 
725 #ifndef _OPENGL
726 static Nlm_Controls3D Cn3D_left;
727 #endif
728 
729 ValNodePtr Cn3d_ColorNames = NULL; /* choice holds table number */
730 
731 /* the default palette */
732 Uint1 Cn3d_PaletteRGB[CN3D_COLOR_MAX][3] =
733 {
734   255, 255, 255, /* default     0 */
735   255,  20, 147, /* hotpink     1 */
736   255,   0, 255, /* magenta     2 */
737   155,  48, 255, /* purple      3 */
738     0,   0, 255, /* blue        4 */
739    30, 144, 255, /* sky         5 */
740     0, 255, 255, /* cyan        6 */
741     0, 255, 127, /* sea         7 */
742     0, 255,   0, /* green       8 */
743   255, 255,   0, /* yellow      9 */
744   255, 165,   0, /* gold       10 */
745   255,  69,   0, /* orange     11 */
746   255,   0,   0, /* red        12 */
747   255, 114,  86, /* pink       13 */
748   255, 174, 185, /* pinktint   14 */
749   255, 255, 255, /* white      15 */
750     0,   0,   0, /* black      16 */
751   176, 226, 255, /* bluetint   17 */
752   154, 255, 154, /* greentint  18 */
753   255, 236, 139, /* yellowtint 19 */
754   125, 125, 125, /* gray       20 */
755   139,  87,  66, /* brown      21 */
756   255,   0,   0, /* perm colors 22: red */
757     0, 255,   0, /* perm colors 23: green */
758   255,   0, 255, /* perm colors 24: magenta */
759    30, 144, 255, /* perm colors 25: sky */
760   155,  48, 255, /* perm colors 26: purple */
761     0, 255,   0, /* SS colors 27: helix, green */
762   255, 165,   0, /* SS colors 28: strand, gold */
763   255,  69,   0, /* SS colors 29: turn, orange */
764     0, 255, 255, /* SS colors 30: coil, cyan */
765   255, 255,   0, /* highlight colors 31: yellow */
766     0,   0,   0, /* background colors 32: black */
767   160,  82,  45, /* sienna 33 */
768   240, 230, 140, /* khaki 34 */
769   171, 130, 255, /* light purple 35 */
770   255, 200,   0, /* orange yellow 36 */
771   117, 128, 160, /* 37 */
772     5,  53, 239, /* 38 */
773    27,  62, 255, /* 39 */
774    84, 110, 203, /* 40 */
775   216,  77,  84, /* 41 */
776   125, 128, 135, /* 42 */
777   237,  29,  61, /* 43 */
778   184, 118, 120, /* 44 */
779   155,   9,   0, /* 45 */
780   155, 119, 107, /* 46 */
781    80, 110, 196, /* 47 */
782   122, 127, 157, /* 48 */
783    50,  85, 241, /* 49 */
784   201,  93,  91, /* 50 */
785   254,   0,   5, /* 51 */
786   155, 137, 133, /* 52 */
787     3,  53, 246  /* 53 */
788 };
789 
790 
791 
792 
793 
794 
795 extern Boolean LIBCALL readErrors(void)
796 {
797     Uint1 i;
798 
799     errNum = DiagGetRecordCount();
800     for (i = 0; i < errNum; i++) {
801         errType = DiagGetRecordType(i);
802         errMsg = DiagGetRecordStr(i);
803         Message(MSG_OK, "%d %d %s", errNum, errType, errMsg);
804     }
805 
806     return DiagHasErrorRec();
807 }
808 
809 
810 void LIBCALL Cn3D_EnableFileOps(void)
811 {
812     if (GetFirstModelstruc() == NULL) { /* nothing in memory - disable stuff */
813         Cn3D_DisableFileOps();
814         /* just leave the "opener enabled" */
815         Enable(Cn3D_sOpen);
816         Enable(Cn3D_iOpen);
817     } else {
818         Enable(Cn3D_sOpen);
819         Enable(Cn3D_iOpen);
820         Enable(Cn3D_sSave);
821         Enable(Cn3D_sExport);
822         Enable(Cn3D_iSelStruc);
823         Enable(Cn3D_iClearStruc);
824     }
825     return;
826 }
827 
828 void LIBCALL Cn3D_DisableFileOps(void)
829 {
830     Disable(Cn3D_sOpen);
831     Disable(Cn3D_iOpen);
832     Disable(Cn3D_sSave);
833     Disable(Cn3D_sExport);
834     Disable(Cn3D_iSelStruc);
835     Disable(Cn3D_iClearStruc);
836     return;
837 }
838 
839 
840 void LIBCALL Cn3D_DisableMenus(void)
841 {
842     Cn3D_DisableFileOps();
843     Disable(Cn3D_mRender);
844     Disable(Cn3D_mColor);
845     Disable(Cn3D_mControls);
846 }
847 
848 
849 void LIBCALL Cn3D_EnableMenus(void)
850 {
851     Cn3D_EnableFileOps();
852     Enable(Cn3D_mRender);
853     Enable(Cn3D_mColor);
854     Enable(Cn3D_mControls);
855 }
856 
857 
858 static void Cn3D_AboutProc(IteM i)
859 {
860     MsgAlert(KEY_OK, SEV_INFO, "About Cn3D",
861              "Cn3D\n\nA 3-D Viewer for\nNCBI Databases\nVersion 3.0\n\nThe National Center for Biotechnology Information\nhttp://www.ncbi.nlm.nih.gov\ninfo@ncbi.nlm.nih.gov");
862 }
863 
864 
865 static void Cn3D_HelpProcOK(ButtoN g)
866 {
867     WindoW hOpenDlg;
868 
869     hOpenDlg=(WindoW)ParentWindow(g);
870     if (!hOpenDlg) return;
871     Remove(hOpenDlg);
872 
873     Nlm_LaunchWebPage("http://www.ncbi.nlm.nih.gov/Structure/CN3D/cn3dhelp.html");
874 }
875 
876 static void Cn3D_HelpProcCancel(ButtoN g)
877 {
878     WindoW hOpenDlg;
879 
880     hOpenDlg=(WindoW)ParentWindow(g);
881     if (!hOpenDlg) return;
882     Remove(hOpenDlg);
883 }
884 
885 static void Cn3D_HelpProc(IteM i)
886 {
887     WindoW d;
888     GrouP h, h1, h2;
889     
890     d = MovableModalWindow(-50, -33 ,-10, -10, "Help", NULL);
891     if (d != NULL){
892         h = HiddenGroup(d, 1, 2,  NULL);
893 
894         h1 = HiddenGroup(h, 1, 5,  NULL);
895         StaticPrompt(h1,"An WWW Manual for Cn3D can be viewed at:",0,0,systemFont,'l');
896         StaticPrompt(h1,"http://www.ncbi.nlm.nih.gov/Structure/CN3D/cn3dhelp.html",0,0,systemFont,'l');
897         StaticPrompt(h1,"Send questions to:",0,0,systemFont,'l');
898         StaticPrompt(h1,"info@ncbi.nlm.nih.gov",0,0,systemFont,'l');
899         StaticPrompt(h1,"",0,0,systemFont,'l');
900 
901         h2 = HiddenGroup(h, 2, 0,  NULL);
902         PushButton(h2, "Launch", Cn3D_HelpProcOK);
903         PushButton(h2, "Cancel", Cn3D_HelpProcCancel);
904         RealizeWindow(d);
905         Show(d);
906     }
907 }
908 
909 
910 static void Cn3D_AllCB(IteM i)
911 {
912 #ifdef _OPENGL
913     OGL_Reset(Cn3D_ColorData.OGL_Data);
914     if (!GetSelectedModelstruc())
915         OGL_DrawLogo(Cn3D_ColorData.OGL_Data);
916     OGL_DrawViewer3D(Cn3D_ColorData.OGL_Data);
917 #else
918     ZoomAll3D(Cn3D_v3d);
919 #endif
920 }
921 
922 static void Cn3D_ZoomCB(IteM i)
923 {
924     MsgAlert(KEY_OK, SEV_INFO, "Cn3D Online Manual",
925              "Use the [Control] modifier key to zoom with mouse\n\n\
926 (see also Image/Mouse3D_Groups)");
927 }
928 
929 static void Cn3D_MoveCB(IteM i)
930 {
931     MsgAlert(KEY_OK, SEV_INFO, "Cn3D Online Manual",
932              "Use the [Shift] modifier key to move with mouse\n\n\
933 (see also Image/Mouse3D_Groups)");
934 }
935 
936 static void Cn3D_Default_BgColor(IteM i)
937 {
938 #ifdef _OPENGL
939     Cn3D_ColorData.OGL_Data->Background.rgb[0] = 0;
940     Cn3D_ColorData.OGL_Data->Background.rgb[1] = 0;
941     Cn3D_ColorData.OGL_Data->Background.rgb[2] = 0;
942     if (Cn3D_ColorData.OGL_Data->IndexMode)
943         Cn3D_Redraw(FALSE);     /* new palette */
944     else
945         OGL_DrawViewer3D(Cn3D_ColorData.OGL_Data);
946 #else                           /* _OPENGL */
947     if (Cn3D_v3d != NULL)
948         Nlm_SetBackground3D(Cn3D_v3d, 0, 0, 0);
949 #endif
950 
951 }
952 
953 static void Cn3D_BgColor(IteM i)
954 {
955 
956 #ifdef _OPENGL
957 /* not currently used in OpenGL... done in Render panel instead */
958     DDV_ColorCell *pColorCell;
959 
960     pColorCell =
961         DDV_SearchColorCellbyName(Cn3D_ColorData.pDDVColorGlobal->
962                                   pvnSpecialColors, "Background");
963     if (pColorCell == NULL) return;
964     ChooseColorDialog(&(Cn3D_ColorData.OGL_Data->Background.rgb[0]),
965                       &(Cn3D_ColorData.OGL_Data->Background.rgb[1]),
966                       &(Cn3D_ColorData.OGL_Data->Background.rgb[2]), TRUE);
967     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Background", "CN3D",
968         pColorCell->rgb[0], pColorCell->rgb[1], pColorCell->rgb[2]);
969 
970         Cn3D_Redraw(FALSE);     /* new palette */
971 #else                           /* _OPENGL */
972     if (Cn3D_v3d != NULL)
973         BgColorDlg3D(Cn3D_v3d);
974 #endif
975 
976 }
977 
978 
979 static void Cn3D_Default_HLColor(IteM i)
980 {
981 
982     Uint1 colorR, colorG, colorB;
983 
984     colorR = 255;
985     colorG = 255;
986     colorB = 0;
987     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Highlight", "CN3D",
988         255, 255, 0);
989 
990 #ifndef _OPENGL
991     SetHLColor3D(Cn3D_v3d, colorR, colorG, colorB);
992 #endif /* ndef _OPENGL */
993     Cn3D_RedrawNUpdate(FALSE);
994 
995 }
996 
997 static void Cn3D_HLColor(IteM i)
998 {
999     DDV_ColorCell *pColorCell;
1000 
1001     pColorCell =
1002         DDV_SearchColorCellbyName(Cn3D_ColorData.pDDVColorGlobal->
1003                                   pvnSpecialColors, "Highlight");
1004     if (pColorCell == NULL)
1005         return;
1006 
1007     ChooseColorDialog(&pColorCell->rgb[0], &pColorCell->rgb[1],
1008                       &pColorCell->rgb[2], TRUE);
1009     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Highlight", "CN3D",
1010         pColorCell->rgb[0], pColorCell->rgb[1], pColorCell->rgb[2]);
1011 
1012 #ifndef _OPENGL
1013     SetHLColor3D(Cn3D_v3d, pColorCell->rgb[0], pColorCell->rgb[1],
1014                  pColorCell->rgb[2]);
1015 #endif /* ndef _OPENGL */
1016     Cn3D_RedrawNUpdate(FALSE);
1017 }
1018 
1019 static void Cn3D_Default_SSColor(IteM i)
1020 {
1021 #ifdef _OPENGL
1022     DDV_DefaultSSColor(Cn3D_ColorData.pDDVColorGlobal, "CN3D");
1023 #else  /* _OPENGL */
1024     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Helix", "CN3D", 0, 255, 0);
1025     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Strand", "CN3D", 255, 165, 0);
1026     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Turn", "CN3D", 255, 69, 0);
1027     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Coil", "CN3D", 0, 255, 255);
1028 #endif  /* else _OPENGL */
1029     Cn3D_RedrawNUpdate(FALSE);
1030 }
1031 
1032 static void Cn3D_HelixColor(IteM i)
1033 {
1034     DDV_ColorCell *pColorCell;
1035 
1036     pColorCell =
1037         DDV_SearchColorCellbyName(Cn3D_ColorData.pDDVColorGlobal->
1038                                   pvnSpecialColors, "Helix");
1039     if (pColorCell == NULL)
1040         return;
1041 
1042     ChooseColorDialog(&pColorCell->rgb[0], &pColorCell->rgb[1],
1043                       &pColorCell->rgb[2], TRUE);
1044     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Helix", "CN3D",
1045         pColorCell->rgb[0], pColorCell->rgb[1], pColorCell->rgb[2]);
1046 
1047     Cn3D_RedrawNUpdate(FALSE);
1048 }
1049 
1050 static void Cn3D_StrandColor(IteM i)
1051 {
1052     DDV_ColorCell *pColorCell;
1053 
1054     pColorCell =
1055         DDV_SearchColorCellbyName(Cn3D_ColorData.pDDVColorGlobal->
1056                                   pvnSpecialColors, "Strand");
1057     if (pColorCell == NULL)
1058         return;
1059 
1060     ChooseColorDialog(&pColorCell->rgb[0], &pColorCell->rgb[1],
1061         &pColorCell->rgb[2], TRUE);
1062     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Strand", "CN3D",
1063         pColorCell->rgb[0], pColorCell->rgb[1], pColorCell->rgb[2]);
1064     
1065     Cn3D_RedrawNUpdate(FALSE);
1066 }
1067 
1068 static void Cn3D_TurnColor(IteM i)
1069 {
1070     DDV_ColorCell *pColorCell;
1071 
1072     pColorCell =
1073         DDV_SearchColorCellbyName(Cn3D_ColorData.pDDVColorGlobal->
1074                                   pvnSpecialColors, "Turn");
1075     if (pColorCell == NULL)
1076         return;
1077 
1078     ChooseColorDialog(&pColorCell->rgb[0], &pColorCell->rgb[1],
1079                       &pColorCell->rgb[2], TRUE);
1080     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Turn", "CN3D",
1081         pColorCell->rgb[0], pColorCell->rgb[1], pColorCell->rgb[2]);
1082 
1083     Cn3D_RedrawNUpdate(FALSE);
1084 }
1085 
1086 static void Cn3D_CoilColor(IteM i)
1087 {
1088     DDV_ColorCell *pColorCell;
1089 
1090     pColorCell =
1091         DDV_SearchColorCellbyName(Cn3D_ColorData.pDDVColorGlobal->
1092                                   pvnSpecialColors, "Coil");
1093     if (pColorCell == NULL)
1094         return;
1095 
1096     ChooseColorDialog(&pColorCell->rgb[0], &pColorCell->rgb[1],
1097                       &pColorCell->rgb[2], TRUE);
1098     DDV_SetPaletteColor(Cn3D_ColorData.pDDVColorGlobal, "Coil", "CN3D",
1099         pColorCell->rgb[0], pColorCell->rgb[1], pColorCell->rgb[2]);
1100     
1101     Cn3D_RedrawNUpdate(FALSE);
1102 }
1103 
1104 
1105 /* Compose the starting(NCBI-Logo) 3D-Picture */
1106 static void LogoProc(Nlm_ButtoN b)
1107 {
1108 #ifdef _OPENGL
1109     OGL_DrawLogo(Cn3D_ColorData.OGL_Data);
1110 #else
1111     Nlm_Prim3D p[4];
1112     Int4 x1, x2;
1113     double ang1, ang2;
1114     double r;
1115 
1116     if (Cn3D_pMain != NULL)
1117         DeletePicture3D(Cn3D_pMain);
1118     Cn3D_pMain = CreatePicture3D();
1119     if (readErrors())
1120         return;
1121 
1122     ResetPicture3D(Cn3D_pMain);
1123     if (readErrors())
1124         return;
1125 
1126     AllocPalette3D(Cn3D_pMain, 4);
1127     if (readErrors())
1128         return;
1129 
1130     SetColor3D(Cn3D_pMain, 0, 255, 0, 255);
1131     SetColor3D(Cn3D_pMain, 1, 0, 0, 255);
1132     SetColor3D(Cn3D_pMain, 2, 255, 255, 0);
1133     SetColor3D(Cn3D_pMain, 3, 0, 0, 255);
1134 
1135     x1 = 0;
1136     x2 = 4000000;
1137     ang1 = 0.2;
1138     p[0] = AddPoly3D(Cn3D_pMain, NULL, 0, 0, 0,
1139                      x2, (Int4) (15000000 * cos(ang1)),
1140                      (Int4) (15000000 * sin(ang1)), x1,
1141                      (Int4) (15000000 * cos(ang1)),
1142                      (Int4) (15000000 * sin(ang1)));
1143     ang2 = 3.2;
1144     p[1] = AddPoly3D(Cn3D_pMain, NULL, 0, 0, 1,
1145                      x2, (Int4) (15000000 * cos(ang2)),
1146                      (Int4) (15000000 * sin(ang2)), x1,
1147                      (Int4) (15000000 * cos(ang2)),
1148                      (Int4) (15000000 * sin(ang2)));
1149 
1150     ang1 = 0.0;
1151     for (r = 1; r <= 63; r++, ang1 += 0.2) {
1152         x1 += 700000;
1153         x2 += 700000;
1154         AddVertPoly3D(Cn3D_pMain, p[0],
1155                       x2, (Int4) (15000000 * cos(ang1)),
1156                       (Int4) (15000000 * sin(ang1)));
1157         AddVertPoly3D(Cn3D_pMain, p[0], x1, (Int4) (15000000 * cos(ang1)),
1158                       (Int4) (15000000 * sin(ang1)));
1159     }
1160 
1161     x1 = 0;
1162     x2 = 4000000;
1163     ang1 = 3.0;
1164     for (r = 1; r <= 79; r++, ang1 += 0.2) {
1165         x1 += 700000;
1166         x2 += 700000;
1167         AddVertPoly3D(Cn3D_pMain, p[1],
1168                       x2, (Int4) (15000000 * cos(ang1)),
1169                       (Int4) (15000000 * sin(ang1)));
1170         AddVertPoly3D(Cn3D_pMain, p[1], x1, (Int4) (15000000 * cos(ang1)),
1171                       (Int4) (15000000 * sin(ang1)));
1172     }
1173 
1174     AddSphere3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 45000000, 0, 0,
1175                 5000000);
1176     AddCylinder3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 52000000, 5000000,
1177                   0, 52000000, -5000000, 0, 1000000);
1178     AddCylinder3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 58000000, 5000000,
1179                   0, 58000000, -5000000, 0, 1000000);
1180     AddSphere3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 65000000, 0, 0,
1181                 5000000);
1182     AddCylinder3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 72000000, 5000000,
1183                   0, 72000000, -5000000, 0, 1000000);
1184     AddSphere3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 80000000, 0, 0,
1185                 5000000);
1186     AddCylinder3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2, 87000000, 5000000,
1187                   0, 87000000, -5000000, 0, 1000000);
1188 
1189     AddCylinder3D(Cn3D_pMain, NULL, (BigScalar) 0, 0, 2,
1190                   93000000, 5000000, 0, 93000000, -5000000, 0, 1000000);
1191 
1192 
1193     if (readErrors())
1194         return;
1195     SetHLColor3D(Cn3D_v3d, 255, 255, 0); /* use yellow color for highlight by default */
1196 
1197     AttachPicture3D(Cn3D_v3d, Cn3D_pMain, NULL);
1198 
1199     readErrors();
1200     SetLayerTop3D(0);
1201 #endif                          /* ndef _OPENGL */
1202 }
1203 
1204 
1205 
1206 NLM_EXTERN void LIBCALL Cn3D_ResetActiveStrucProc(void)
1207 {
1208     Cn3D_CountDomainProc();
1209 
1210     ResetRenderCtrls();
1211     ResetLabelCtrls();
1212 /*    ResetAlignCtrls(); */
1213     ResetDisplayCtrls();
1214     Cn3dObjMgrGetSelected();
1215 }
1216 
1217 void /*LIBCALL*/ Cn3D_SaveActiveCam(void)
1218 {
1219 #ifndef _OPENGL
1220     PARS pars;
1221     PDNMS pdnmsThis = GetSelectedModelstruc();
1222 
1223     if (pdnmsThis && pdnmsThis->data.ptrvalue &&
1224         (pars = (PARS) ((PMSD) pdnmsThis->data.ptrvalue)->pGlobalPARS))
1225         GetViewerInfo3D(Cn3D_v3d, NULL, &Cn3D_Camera3D, NULL);
1226 #endif                          /* ndef _OPENGL */
1227 }
1228 
1229 
1230 
1231 
1232 NLM_EXTERN void Cn3D_RedrawNUpdate(Boolean New)
1233 {
1234     DDV_Clear2Default(Cn3D_ColorData.pDDVColorGlobal); 
1235     Cn3D_Redraw(New);
1236     Cn3D_SendUpdate();
1237 }
1238 
1239 NLM_EXTERN void LIBCALL Cn3D_Redraw(Boolean New)
1240 {
1241     Cn3D_RedrawEx(New);
1242 #ifdef _OPENGL
1243     OGL_DrawViewer3D(Cn3D_ColorData.OGL_Data); /* force a window redraw */
1244 #endif
1245 }
1246 
1247 NLM_EXTERN void LIBCALL Cn3D_RedrawEx(Boolean New)
1248 {
1249     /* fetch the active structure */
1250     PARS pars = NULL;
1251     DDV_ColorCell iColor;
1252     PDNMS pdnmsThis = GetSelectedModelstruc();
1253 
1254     if (pdnmsThis == NULL || 
1255         (pars = (PARS) ((PMSD) pdnmsThis->data.ptrvalue)->pGlobalPARS) == NULL) {
1256         LogoProc(NULL);
1257         return;
1258     }
1259 #ifndef _OPENGL
1260     if (!New)
1261         GetViewerInfo3D(Cn3D_v3d, NULL, &Cn3D_Camera3D, NULL);
1262 #endif                          /* ndef _OPENGL */
1263 
1264     WatchCursor();
1265     ProgMon("Removing 3D image ...");
1266 #ifdef _OPENGL
1267     if (OGL_IsPlaying(Cn3D_ColorData.OGL_Data))
1268         OGL_StopPlaying(Cn3D_ColorData.OGL_Data);
1269 #else
1270     if (IsPlaying3D())
1271         StopPlaying3D();
1272 #endif
1273     Cn3D_DisableFileOps();
1274 
1275 #ifndef _OPENGL
1276     if (Cn3D_pMain)
1277         DeletePicture3D(Cn3D_pMain);
1278     Cn3D_pMain = CreatePicture3D();
1279     if (readErrors())
1280         return;
1281 
1282     ResetPicture3D(Cn3D_pMain);
1283     if (readErrors())
1284         return;
1285 #endif                          /* ndef _OPENGL */
1286 
1287 #ifdef _OPENGL
1288     /* resize the bound box */
1289     if (New) {
1290         OGL_ClearOGL_Data(Cn3D_ColorData.OGL_Data);
1291         Cn3D_Size(&(Cn3D_ColorData.OGL_Data->BoundBox), pdnmsThis);
1292         /* to do: add slaves to traverse */
1293         OGL_Reset(Cn3D_ColorData.OGL_Data);
1294     }
1295     /* set background color */
1296     Cn3D_ColorData.OGL_Data->Background.rgb[0] = pars->BGColRGB[0];
1297     Cn3D_ColorData.OGL_Data->Background.rgb[1] = pars->BGColRGB[1];
1298     Cn3D_ColorData.OGL_Data->Background.rgb[2] = pars->BGColRGB[2];
1299 #endif                          /* _OPENGL */
1300 
1301 
1302 /*
1303     if (Cn3D_DisplayHighlight)
1304         Cn3DCheckHighlighted();
1305     if (Cn3D_NoSingleHL) {
1306         Cn3D_DisplayHighlight = FALSE;
1307         Cn3D_bDisplayHighlightStatusSet(FALSE);
1308     }
1309 */
1310     /* execute all color functions */
1311     /*DDV_ColorExecute(Cn3D_ColorData.pDDVColorGlobal, NULL, NULL, Cn3D_ColorFuncFind());*/
1312 
1313     ProgMon("Rendering Structure...");
1314 #ifdef _OPENGL
1315     AlgorithmicRendering();
1316 #else                           /* _OPENGL */
1317     Cn3D_pMain = AlgorithmicRendering(Cn3D_pMain);
1318 
1319     if (readErrors())
1320         return;
1321     if (Cn3D_pMain == NULL) {   /* must have something; do xyz origin... reset palette with white */
1322         Cn3D_pMain = CreatePicture3D();
1323         if (readErrors())
1324             return;
1325         ResetPicture3D(Cn3D_pMain);
1326         if (readErrors())
1327             return;
1328         DDV_FreePalette(&(Cn3D_ColorData.pDDVColorGlobal->Palette)); /* free global palette */
1329         DDV_SetColorInCell(&iColor, Cn3d_PaletteRGB[C_white]); /* use white */
1330         DDV_RequestColor(&Cn3D_ColorData.pDDVColorGlobal->Palette,
1331                          &iColor);
1332         Cn3d_Lock3DPalette(Cn3D_pMain); /* Allocates the Picture3D palette  */
1333         Cn3D_pMain = Do3DOrigin(Cn3D_pMain); /* make the origin */
1334     }
1335 
1336     ProgMon("Redrawing 3D image ...");
1337     AttachPicture3D(Cn3D_v3d, Cn3D_pMain, &Cn3D_Camera3D);
1338 #endif                          /* else _OPENGL */
1339 
1340     readErrors();
1341     Cn3D_EnableFileOps();
1342     ArrowCursor();
1343 }
1344 
1345 
1346 
1347 /* Mouse Action Callbacks */
1348 
1349 static void LIBCALLBACK DoHighlightSeg(PFB pfbThis,
1350                                        Int4 iModel, Int4 iIndex,
1351                                        Pointer ptr)
1352 /* used only for molecule wide highlighting.  not used at present time */
1353 {
1354     PMAD pmadAtom = (PMAD) pfbThis;
1355 #ifndef _OPENGL
1356     Viewer3D vvv = (Viewer3D) ptr;
1357 #endif
1358     PALD paldLoc;
1359 
1360     if (!IsAtomNode(pfbThis))
1361         return;
1362 
1363     paldLoc = GetAtomLocs(pmadAtom, (Int2) iModel);
1364     while (paldLoc) {
1365 #ifdef _OPENGL
1366 #else                           /* _OPENGL */
1367         Segment3D seg = (Segment3D) paldLoc->pGraphic;
1368         if (seg != NULL)
1369             HighlightSeg3D(vvv, seg,
1370                            (Boolean) (!IsSeg3DHlighted(vvv, seg)));
1371 #endif                          /* else _OPENGL */
1372 
1373         paldLoc = paldLoc->next; /* get next location */
1374     }
1375 }
1376 
1377 #ifndef _OPENGL
1378 static Boolean GetPointData(MAPtr ma, PoinT point,
1379                             Prim3D PNTR prim,
1380                             Segment3D PNTR seg, BigScalar PNTR data)
1381 {
1382     Prim3D x_prim = NULL;
1383     Segment3D x_seg = NULL;
1384     BigScalar x_data = 0;
1385 
1386     do { /* TRY */  {
1387             Viewer3D vvv = Nlm_MAToViewer3D(ma);
1388             Picture3D ppp = NULL;
1389 
1390             Nlm_GetViewerInfo3D(vvv, &ppp, NULL, NULL);
1391             if (!ppp)
1392                 break;
1393 
1394             { {
1395                     Uint2 n_prim = FindPrim3D(vvv, point);
1396                     if (!n_prim)
1397                         break;
1398             }
1399             }
1400 
1401             x_prim = GetFoundPrim3D(vvv, 0);
1402             if (!x_prim)
1403                 break;
1404 
1405             if (data || seg)
1406                 GetPrimInfo3D(ppp, x_prim, &x_data, NULL, NULL, &x_seg,
1407                               NULL);
1408     }
1409     } while (0);
1410 
1411     if (prim)
1412         *prim = x_prim;
1413     if (seg)
1414         *seg = x_seg;
1415     if (data)
1416         *data = x_data;
1417 
1418     return (Boolean) (x_data != 0);
1419 }
1420 
1421 #endif                          /* ndef _OPENGL */
1422 
1423 
1424 /*
1425  *  for highlighting an atom.  not presently used or ported to opengl
1426  */
1427 
1428 static void HLatom_MA(MAPtr ma,
1429                       MA_TracePtr trace, PoinT point, VoidPtr extra)
1430 {
1431 #ifndef _OPENGL
1432     Viewer3D vvv = MAToViewer3D(ma);
1433     Prim3D prim = NULL;
1434     Segment3D seg = NULL;
1435     BigScalar data = 0;
1436 
1437     if (GetPointData(ma, point, &prim, &seg, &data) &&
1438         IsAtomLocNode((PFB) data))
1439             HighlightSeg3D(vvv, seg,
1440                            (Boolean) (!IsSeg3DHlighted(vvv, seg)));
1441 
1442     else if (data && IsObjectNode((PFB) data))
1443         HighlightPrim3D(vvv, prim,
1444                         (Boolean) (!IsPrim3DHlighted(vvv, prim)));
1445 
1446     else {
1447         if (!prim)
1448             BgColorDlg3D(vvv);
1449         return;
1450     }
1451 
1452     RedrawViewer3D(vvv);
1453 #endif                          /* ndef _OPENGL */
1454 }
1455 
1456 
1457 /*
1458  *  the following functions are for highlighting a residue
1459  */
1460 
1461 void DoCHighlightSeg(PFB pfbThis, Int4 iModel, Int4 iIndex, Pointer ptr,
1462                      Boolean highlight)
1463 {
1464     PMAD pmadAtom = (PMAD) pfbThis;
1465 #ifndef _OPENGL
1466     Viewer3D vvv = (Viewer3D) ptr;
1467 #endif
1468     PALD paldLoc;
1469 
1470     if (!IsAtomNode(pfbThis))
1471         return;
1472 
1473     paldLoc = GetAtomLocs(pmadAtom, (Int2) iModel);
1474     while (paldLoc) {
1475 #ifdef _OPENGL
1476 #else                           /* _OPENGL */
1477         Segment3D seg = (Segment3D) paldLoc->pGraphic;
1478         if (seg != NULL) {
1479             if (highlight && !IsSeg3DHlighted(vvv, seg)) {
1480                 HighlightSeg3D(vvv, seg,
1481                                (Boolean) (!IsSeg3DHlighted(vvv, seg)));
1482             } else if (!highlight && IsSeg3DHlighted(vvv, seg)) {
1483                 HighlightSeg3D(vvv, seg,
1484                                (Boolean) (!IsSeg3DHlighted(vvv, seg)));
1485             }
1486         }
1487 #endif                          /* else _OPENGL */
1488 
1489         paldLoc = paldLoc->next; /* get next location */
1490     }
1491 }
1492 
1493 void fnCHLresidue(PDNMG pdnmgThis,
1494 #ifndef _OPENGL
1495                   Viewer3D vvv,
1496 #endif
1497                   Boolean highlight)
1498 {
1499     /* highlight residues corresponding to those in Salsa Window */
1500 
1501     PMGD pmgdThis = NULL;
1502     PVNMA pvnmaThis = NULL;
1503     PMAD pmadThis = NULL;
1504     PVNAL pvnalThis = NULL;
1505     PALD paldThis = NULL;
1506     PVNAL pvnalLinkThis = NULL;
1507 #ifdef _OPENGL
1508     Nlm_VoidPtr vvv = NULL;
1509 #endif
1510 
1511     pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
1512     pvnmaThis = pmgdThis->pvnmaAHead;
1513 
1514     while (pvnmaThis) {
1515         pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
1516         if (pmadThis == NULL)
1517             goto setout;
1518         pvnalThis = pmadThis->pvnalLocate;
1519         if (pvnalThis == NULL)
1520             goto setout;
1521         paldThis = pvnalThis->data.ptrvalue;
1522         if (paldThis == NULL)
1523             goto setout;
1524         pvnalLinkThis = paldThis->pvnalLink;
1525         while (pvnalLinkThis) {
1526             DoCHighlightSeg((PFB) pmadThis, (Int4) pvnalLinkThis->choice,
1527                             0, vvv, highlight);
1528             pvnalLinkThis = pvnalLinkThis->next;
1529         }
1530       setout:
1531         pvnmaThis = pvnmaThis->next;
1532     }
1533     return;
1534 }
1535 
1536 /*
1537  * this is the main function called to highlight a particular residue
1538  */
1539 
1540 void fnPreCHLresidue(PDNMG pdnmgThis, Boolean highlight)
1541 {
1542     PMGD pmgdThis = NULL;
1543     PMSD pmsdThis = NULL;
1544 
1545     pmgdThis = pdnmgThis->data.ptrvalue;
1546     if (pmgdThis) {
1547         if (highlight)
1548             pmgdThis->bHighlighted = 1;
1549         else
1550             pmgdThis->bHighlighted = 0;
1551 #ifndef _OPENGL
1552 
1553         pmsdThis = ToMSDParent((PFB) pmgdThis);
1554 
1555         if (pmsdThis && pmgdThis && pmsdThis->bVisible && pmgdThis->bVisible) {
1556             fnCHLresidue(pdnmgThis, Cn3D_v3d, highlight);
1557         }
1558 #endif
1559     }
1560 }
1561 
1562 static void HLresidue_MA(MAPtr ma,
1563                          MA_TracePtr trace, PoinT point, VoidPtr extra)
1564 /* highlight a residue */
1565 {
1566 #ifndef _OPENGL
1567     Viewer3D vvv = MAToViewer3D(ma);
1568     Prim3D prim = NULL;
1569     BigScalar data = 0;
1570 
1571     Boolean highlight = FALSE;
1572 #endif                          /* ndef _OPENGL */
1573 
1574 #ifdef _OPENGL
1575     {
1576         PMGD pmgdThis;
1577         PDNMG pdnmgThis;
1578 
1579         OGL_SetSelectPoint(Cn3D_ColorData.OGL_Data, point);
1580         OGL_Select(Cn3D_ColorData.OGL_Data, TRUE);
1581         OGL_DrawViewer3D(Cn3D_ColorData.OGL_Data);
1582         OGL_Select(Cn3D_ColorData.OGL_Data, FALSE);
1583 
1584         pmgdThis = OGL_Hit(Cn3D_ColorData.OGL_Data);
1585         if (pmgdThis == NULL || !IsGraphNode(pmgdThis)) /* can highlight anything */
1586             return;
1587 
1588         pdnmgThis = pmgdThis->pdnmgLink;
1589         MediaObjSelect(pdnmgThis, !pmgdThis->bHighlighted);
1590     }
1591 
1592 #else /* _OPENGL */
1593 
1594     if (GetPointData(ma, point, &prim, NULL, &data) &&
1595         IsAtomLocNode((PFB) data)) {
1596         PALD paldThis = (PALD) data;
1597         PMGD pmgdThis = GetParentGraph((PFB) data);
1598         PDNMG pdnmgThis = pmgdThis->pdnmgLink;
1599         Segment3D seq = paldThis->pGraphic;
1600         if (!IsSeg3DHlighted(vvv, seq))
1601             highlight = TRUE;
1602         else
1603             highlight = FALSE;
1604 
1605         MediaObjSelect(pdnmgThis, highlight);
1606 
1607     }
1608 
1609     else if (data && IsObjectNode((PFB) data))
1610         HighlightPrim3D(vvv, prim,
1611                         (Boolean) (!IsPrim3DHlighted(vvv, prim)));
1612 
1613     else
1614         return;
1615 
1616     /* RedrawViewer3D(vvv); */
1617 #endif                          /* else _OPENGL */
1618 
1619 }
1620 
1621 /*
1622  *   for highlighting an entire molecule.  not presently used or ported
1623  *   to opengl
1624  */
1625 
1626 static void HLmolecule_MA(MAPtr ma,
1627                           MA_TracePtr trace, PoinT point, VoidPtr extra)
1628 {
1629 #ifndef _OPENGL
1630     Viewer3D vvv = Nlm_MAToViewer3D(ma);
1631     Prim3D prim = NULL;
1632     BigScalar data = 0;
1633 
1634     if (GetPointData(ma, point, &prim, NULL, &data) &&
1635         IsAtomLocNode((PFB) data)) {
1636         PALD paldThis = (PALD) data;
1637         PMMD pmmdThis = GetParentMol((PFB) data);
1638         if (pmmdThis)
1639             TraverseAtoms(pmmdThis->pdnmgHead,
1640                           (Int4) paldThis->pvnalLink->choice,
1641                           0, vvv, DoHighlightSeg);
1642     }
1643 
1644     else if (data && IsObjectNode((PFB) data))
1645         HighlightPrim3D(vvv, prim,
1646                         (Boolean) (!IsPrim3DHlighted(vvv, prim)));
1647 
1648     else
1649         return;
1650 
1651     RedrawViewer3D(vvv);
1652 #endif                          /* ndef _OPENGL */
1653 }
1654 
1655 
1656 static Boolean Cn3D_InitMA(MAPtr ma, VoidPtr data)
1657 {
1658 /*MActionPtr hl_atom     = MA_AddAction(ma, MK_Shift, MA_DClick,
1659                                         HLatom_MA, data, "Highlight-Atom"); */
1660 
1661     MActionPtr hl_residue = MA_AddAction(ma, MK_Normal, MA_DClick,
1662                                          HLresidue_MA, data,
1663                                          "Highlight-Res");
1664 
1665 /*MActionPtr hl_molecule = MA_AddAction(ma, MK_Ctrl,   MA_DClick,
1666                                         HLmolecule_MA, data, "Highlight-Mol"); */
1667 
1668     return (Boolean) (MA_SetAction(hl_residue, TRUE));
1669 /*return (Boolean)(MA_SetAction(hl_atom,     TRUE)  &&
1670                    MA_SetAction(hl_residue,  TRUE)  &&
1671                    MA_SetAction(hl_molecule, TRUE)); */
1672 }
1673 
1674 
1675 #ifndef _OPENGL
1676 static void Cn3D_ViewerCtrlProc(IteM i);
1677 #endif
1678 static void Cn3D_ShowCtrlProc(IteM i);
1679 
1680 
1681 static CharPtr cn3dControlFormTabs[] = {
1682     "Style", "Label", "Show/Hide", "Annotate",
1683 #ifdef _OPENGL
1684     "Quality",
1685 #endif                          /* _OPENGL */
1686     NULL
1687 };
1688 
1689 static void ChangeCn3DCtrlPage(VoidPtr data, Int2 newval, Int2 oldval)
1690  {
1691     SafeHide(Cn3D_gRendCtrl);
1692     SafeHide(Cn3D_gLabelCtrl);
1693     SafeHide(Cn3D_gDisplayCtrl);
1694     SafeHide(Cn3D_gModelCtrl);
1695     SafeHide(Cn3D_gAlignCtrl);
1696 #ifdef _OPENGL
1697 /*    SafeHide(Cn3D_gOGLCtrl); */
1698     SafeHide(Cn3D_gOGLQuality);
1699 #endif                          /* _OPENGL */
1700     switch (newval) {
1701     case 0:
1702         SafeShow(Cn3D_gRendCtrl);
1703         break;
1704     case 1:
1705         SafeShow(Cn3D_gLabelCtrl);
1706         break;
1707     case 2:
1708         SafeShow(Cn3D_gDisplayCtrl);
1709         break;
1710     case 3:
1711         SafeShow(Cn3D_gModelCtrl);
1712         break;
1713 #ifdef _OPENGL
1714     case 4:
1715 /*        SafeShow(Cn3D_gOGLCtrl);
1716         break;
1717     case 5:*/
1718         SafeShow(Cn3D_gOGLQuality);
1719         break;
1720 #endif                          /* _OPENGL */
1721     default:
1722         break;
1723     }
1724 }
1725 
1726 static GrouP Viewer3DGroups(WindoW w)
1727 {
1728     Int2 groups = 0;
1729     /* PoinT pnt; */
1730     RecT Cn3D_rRC;
1731     GrouP g, h;
1732     DialoG tabs;
1733 
1734     h = HiddenGroup(w, 1, 0, NULL);
1735     tabs = CreateFolderTabs(h, cn3dControlFormTabs, 0, 0, 0,
1736                             SYSTEM_FOLDER_TAB, ChangeCn3DCtrlPage, NULL);
1737 
1738     g = HiddenGroup(w, 0, 0, NULL);
1739 
1740 #ifdef WIN_MOTIF
1741     SetGroupMargins(g, 0, 0);
1742     SetGroupSpacing(g, 8, 1);
1743 #else
1744     SetGroupMargins(g, 1, 1);
1745     SetGroupSpacing(g, 0, 0);
1746 #endif
1747 
1748     Cn3D_gRendCtrl = RenderControls(g);
1749     GetPosition(Cn3D_gRendCtrl, &Cn3D_rRC);
1750     Cn3D_Rx = (Uint2) (Cn3D_rRC.right - Cn3D_rRC.left + 10);
1751 
1752     Cn3D_gLabelCtrl = LabelControls(g);
1753     Hide(Cn3D_gLabelCtrl);
1754 
1755     Cn3D_gDisplayCtrl = DisplayControls(g);
1756     Hide(Cn3D_gDisplayCtrl);
1757 
1758     Cn3D_gModelCtrl = ModelControls(g);
1759     Hide(Cn3D_gModelCtrl);
1760 
1761 #ifdef _OPENGL
1762 /*    Cn3D_gOGLCtrl = OGL_Controls(g);
1763     Hide(Cn3D_gOGLCtrl); */
1764 
1765     Cn3D_gOGLQuality = OGL_Quality(g);
1766     Hide(Cn3D_gOGLQuality);
1767 #endif                          /* _OPENGL */
1768 
1769     AlignObjects(ALIGN_CENTER, (HANDLE) tabs,
1770                  (HANDLE) Cn3D_gRendCtrl, (HANDLE) Cn3D_gLabelCtrl,
1771                  (HANDLE) Cn3D_gDisplayCtrl, (HANDLE) Cn3D_gModelCtrl,
1772 #ifdef _OPENGL
1773                  /*(HANDLE) Cn3D_gOGLCtrl,*/ (HANDLE) Cn3D_gOGLQuality,
1774 #endif                          /* _OPENGL */
1775                  NULL);
1776 
1777 
1778     return w;
1779 }
1780 
1781 #ifndef _OPENGL
1782 static GrouP Viewer3DViewer(WindoW w, Uint2Ptr width, Uint2 height)
1783 {
1784     Int2 groups = 0;
1785     PoinT pnt;
1786     RecT Cn3D_rVC;
1787 
1788     GrouP g = HiddenGroup(w, 0, 0, NULL);
1789 
1790 #ifdef WIN_MOTIF
1791     SetGroupMargins(g, 0, 0);
1792     SetGroupSpacing(g, 8, 1);
1793 #else
1794     SetGroupMargins(g, 1, 1);
1795     SetGroupSpacing(g, 0, 0);
1796 #endif
1797 
1798     Cn3D_gViewCtrl = HiddenGroup(g, 0, 0, NULL);
1799 
1800     GetPosition(Cn3D_gViewCtrl, &Cn3D_rVC);
1801     Cn3D_Vy = (Uint2) (Cn3D_rVC.bottom - Cn3D_rVC.top + 10);
1802 
1803     Cn3D_left = CreateControls3D(Cn3D_gViewCtrl, FALSE, TRUE, NULL);
1804     Hide(Cn3D_gViewCtrl);
1805 
1806     GetPosition(Cn3D_gViewCtrl, &Cn3D_rVC);
1807     Cn3D_Vy = (Uint2) (Cn3D_rVC.bottom - Cn3D_rVC.top + 10);
1808     Break(g);
1809 
1810     pnt.x = 10;
1811     pnt.y = 15;
1812     SetNextPosition(g, pnt);
1813     Cn3D_gViewer = HiddenGroup(g, 0, 0, NULL); /* the viewer */
1814 
1815     Cn3D_v3d = CreateViewer3D(Cn3D_gViewer, width, height,
1816                               X_ROTATE_SBAR | Y_ROTATE_SBAR |
1817                               Z_ROTATE_SBAR, Cn3D_ma_group_menu,
1818                               Cn3D_ma_action_menu, Cn3D_InitMA, NULL);
1819     if (readErrors())
1820         return NULL;
1821 
1822     if (Cn3D_v3d == NULL) {
1823         Message(MSG_OK,
1824                 "Cn3D Viewer - Insufficient Memory For Structures");
1825         return NULL;
1826     }
1827 
1828     if (GetStatus(Cn3D_iViewCtrl) == TRUE)
1829         LinkControls3D(Cn3D_left, Cn3D_v3d);
1830 
1831     return HiddenGroup(w, 1, 0, NULL);
1832 }
1833 
1834 #endif                          /* ndef _OPENGL */
1835 
1836 
1837 void Cn3DResizeProc(WindoW w)
1838 {
1839     RecT r;
1840     ObjectRect(Cn3D_w, &r);
1841     OffsetRect(&r, (Int2) (-r.left), (Int2) (-r.top));
1842 
1843     InsetRect(&r, 5, 5);
1844 
1845 #ifdef WIN_MAC
1846     { {
1847             extern Handle Nlm_GetWindowMenuBar(WindoW w);
1848 
1849             Handle hdl = Nlm_GetWindowMenuBar(Cn3D_w);
1850             if (hdl) {
1851                 RecT mbr;
1852                 ObjectRect(hdl, &mbr);
1853                 r.top += (mbr.bottom - mbr.top);
1854             }
1855     }
1856     }
1857 #endif
1858 
1859 
1860 #ifdef _OPENGL
1861     OGL_SetPosition3D(Cn3D_ColorData.OGL_Data, &r);
1862 #else                           /* _OPENGL */
1863     if (GetStatus(Cn3D_iViewCtrl) == TRUE)
1864         r.top += Cn3D_Vy;
1865     SetPosition3D(Cn3D_v3d, &r);
1866 #endif                          /* else _OPENGL */
1867 }
1868 
1869 
1870 #ifndef _OPENGL
1871 #ifdef WIN_MSWIN
1872 static void Cn3D_ImageCopyProc(IteM I)
1873 {
1874     CopyViewer3D(Cn3D_v3d);
1875 }
1876 
1877 #endif
1878 #endif                          /* ndef _OPENGL */
1879 
1880 
1881 
1882 #include <document.h>
1883 static ParData Cn3D_ParFmt = { FALSE, FALSE, FALSE, FALSE, TRUE, 0, 0 };
1884 static ColData Cn3D_ColFmt =
1885     { 0, 0, 40, 0, NULL, 'l', TRUE, FALSE, FALSE, FALSE, TRUE };
1886 
1887 static void Cn3D_AboutQuit(WindoW w)
1888 {
1889     Remove(w);
1890     return;
1891 }
1892 
1893 
1894 static void Cn3D_AboutSize(WindoW w)
1895 {
1896     Int4 height, width;
1897     RecT r;
1898 
1899     DoC d = (DoC) GetObjectExtra(w);
1900     if (!d)
1901         return;
1902 
1903     WatchCursor();
1904 
1905     ObjectRect(w, &r);
1906     width = r.right - r.left;
1907     height = r.bottom - r.top;
1908 
1909     GetPosition(d, &r);
1910     r.right = (Int2) (width - r.left);
1911     r.bottom = (Int2) (height - r.top);
1912     SetPosition(d, &r);
1913 
1914     AdjustPrnt(d, &r, FALSE);
1915     ObjectRect(d, &r);
1916     InsetRect(&r, 4, 4);
1917     Cn3D_ColFmt.pixWidth = (Int2) (screenRect.right - screenRect.left);
1918     Cn3D_ColFmt.pixInset = 8;
1919     if (Visible(d) && AllParentsVisible(d))
1920         UpdateDocument(d, 0, 0);
1921 
1922     ArrowCursor();
1923     Update();
1924 }
1925 
1926 static void Cn3D_AlignEdit(IteM i)
1927 /* launches the sequin editor, salsa */
1928 {
1929     PDNMS pdnmsMaster = NULL;
1930     PDNMS pdnmsSlave = NULL;
1931     PMSD pmsdMaster = NULL, pmsdSlave = NULL;
1932     SeqAnnotPtr psaAlign = NULL;
1933     SeqAlignPtr salp = NULL;
1934     PDNMM pdnmmHead = NULL;
1935     PMMD pmmdThis = NULL;
1936     Int2 iCount = 0;
1937 
1938 
1939     pdnmsMaster = GetSelectedModelstruc();
1940     if (pdnmsMaster == NULL)
1941         return;
1942     pmsdMaster = (PMSD) pdnmsMaster->data.ptrvalue;
1943 
1944     pdnmmHead = pmsdMaster->pdnmmHead;
1945     pmmdThis = pdnmmHead->data.ptrvalue;
1946 
1947     if (pmsdMaster->pdnmsSlaves != NULL) {
1948         pmsdSlave = pmsdMaster->pdnmsSlaves->data.ptrvalue;
1949     }
1950     if (Cn3D_ColorData.sap != NULL)
1951         psaAlign = Cn3D_ColorData.sap;
1952 
1953     if (psaAlign == NULL) {
1954         Cn3D_LaunchSeqEntry(Cn3D_ColorData.pvnsep);
1955         Cn3dObjMgrGetSelected();
1956     }
1957 
1958     if (psaAlign != NULL && psaAlign->data != NULL) {
1959         Cn3dObjMgrGetSelected();
1960         Cn3D_LaunchSeqAnnot(psaAlign);
1961     }
1962 
1963     return;
1964 }
1965 
1966 void LaunchSequenceWindow(void)
1967 {
1968     IteM i = NULL;
1969     Cn3D_AlignEdit(i);
1970 }
1971 
1972 static void Cn3D_AboutPrint(PDNMS pdnmsThisSlave, FILE *fp) 
1973 {
1974     WritePDBHeader(pdnmsThisSlave, fp);
1975     WritePDBRemarks(pdnmsThisSlave, fp);
1976     WritePDBMotifs(pdnmsThisSlave, fp);
1977     WriteStrucHTMLSeq(pdnmsThisSlave, fp);
1978     fprintf(fp, "\n\n\n\n\n\n\n\n\n\n");
1979 }
1980 
1981 static void Cn3D_AboutStruc(IteM i)
1982 {
1983     PMSD pmsdThis;
1984     DoC d;
1985     Char path[PATH_MAX];
1986     FILE *fp;
1987     WindoW Cn3D_wAbout;
1988     PDNMS pdnmsThisSlave;       /* pointer to slave structures */
1989 
1990     PDNMS pdnmsThis = GetSelectedModelstruc();
1991     if (!pdnmsThis)
1992         return;
1993 
1994     pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
1995 
1996     Cn3D_wAbout = DocumentWindow(-66, -50, -10, -10,
1997                                  GetStrucStrings(pdnmsThis, PDB_ACC),
1998                                  Cn3D_AboutQuit, Cn3D_AboutSize);
1999 
2000     d = DocumentPanel(Cn3D_wAbout,
2001                       (Int2) (35 * stdCharWidth + 17),
2002                       (Int2) (14 * stdLineHeight));
2003     SetObjectExtra(Cn3D_wAbout, (Pointer) d, NULL);
2004     Cn3D_ColFmt.pixWidth = (Int2) (60 * stdCharWidth);
2005     Cn3D_ColFmt.font = programFont;
2006 
2007     path[0] = '\0';
2008     TmpNam(path);
2009     fp = FileOpen(path, "w");
2010     if (fp != NULL) {
2011         Cn3D_AboutPrint(pdnmsThis, fp);
2012         /* loop through the slave structures */
2013         if (pmsdThis->pdnmsSlaves != NULL) {
2014             pdnmsThisSlave = pmsdThis->pdnmsSlaves; /* go through the slave structures */
2015             while (pdnmsThisSlave) {
2016                 Cn3D_AboutPrint(pdnmsThisSlave, fp);
2017                 pdnmsThisSlave = pdnmsThisSlave->next;
2018             }
2019         }
2020         fflush(fp);
2021         FileClose(fp);
2022     }
2023 
2024     DisplayFancy(d, path, &Cn3D_ParFmt, &Cn3D_ColFmt, programFont, 4);
2025     FileRemove(path);
2026     Show(Cn3D_wAbout);
2027 }
2028 
2029 #ifdef _OPENGL
2030 static void Cn3D_ZoomOutCB(IteM i)
2031 {
2032     OGL_ZoomOut(Cn3D_ColorData.OGL_Data);
2033 }
2034 
2035 static void Cn3D_ZoomInCB(IteM i)
2036 {
2037     OGL_ZoomIn(Cn3D_ColorData.OGL_Data);
2038 }
2039 #endif
2040 
2041 /* Create the generic CN3D menu system;
2042  * return handler to the "File" top menu
2043  */
2044 static MenU Cn3D_Menus(WindoW w, ItmActnProc netconfig)
2045 {
2046     MenU file_menu, color_menu, color_submenu, menu;
2047     int i;
2048 
2049     /* FILE top menu
2050      */
2051 
2052     file_menu = menu = PulldownMenu(w, "File/F");
2053 
2054     if (!Cn3D_ColorData.UseEntrez) {
2055         Cn3D_iOpen = CommandItem(menu, "Open.../O", Cn3D_OpenBiostruc);
2056         Cn3D_sOpen = NULL;
2057     } else {
2058         Cn3D_sOpen = SubMenu(menu, "Open/0");
2059         CommandItem(Cn3D_sOpen, "File.../B", Cn3D_OpenBiostruc);
2060         CommandItem(Cn3D_sOpen, "by Network.../N", Cn3D_NetOpenBiostruc);
2061         Cn3D_iOpen = NULL;
2062     }
2063 
2064 
2065     /* Import menu item would go here */
2066     /*Cn3D_sSave = Cn3D_SaveSub(menu);*/
2067     Cn3D_sSave = CommandItem(menu, "Save.../S", Cn3D_SaveBiostruc);
2068     Cn3D_sExport = Cn3D_ExportSub(menu);
2069     /*CommandItem(menu, "Mesh /M", Cn3D_OpenMesh);*/
2070 
2071     SeparatorItem(menu);
2072     CommandItem(menu, "Properties.../P", Cn3D_AboutStruc);
2073 
2074     /* EDIT top menu */
2075 
2076     menu = PulldownMenu(w, "View/V");
2077 #ifndef _OPENGL
2078 #ifdef WIN_MSWIN
2079     CommandItem(menu, "Copy/C", Cn3D_ImageCopyProc);
2080     SeparatorItem(menu);
2081 #endif
2082 #endif                          /* ndef _OPENGL */
2083 
2084 
2085     Cn3D_iDisplayCtrl =
2086         StatusItem(menu, "Drawing Settings.../N", Cn3D_ShowCtrlProc);
2087 #ifndef _OPENGL
2088     Cn3D_iViewCtrl = StatusItem(menu,
2089                                 "Animation Controls/A",
2090                                 Cn3D_ViewerCtrlProc);
2091 #else
2092     CommandItem(menu, "Animation.../A", Cn3D_Animate);
2093 #endif                          /* ndef _OPENGL */
2094     CommandItem(menu, "Sequence Window.../S", Cn3D_AlignEdit);
2095 
2096     SeparatorItem(menu);
2097 #ifdef _OPENGL
2098     CommandItem(menu, "Zoom Out", Cn3D_ZoomOutCB);
2099     CommandItem(menu, "Zoom In", Cn3D_ZoomInCB);
2100 #endif
2101     CommandItem(menu, "Reset", Cn3D_AllCB);
2102 
2103 #ifdef _DEBUG
2104     SeparatorItem(menu);
2105     VSMAddToMenu(menu, VSM_DESKTOP);
2106 #endif  /* _DEBUG */
2107 
2108     /* RENDER top menu
2109      */
2110 
2111     menu = PulldownMenu(w, "Style/S");
2112 
2113     CommandItem(menu, "Sec. Structure/S", Cn3D_RenStruc);
2114     CommandItem(menu, "Neighbor/N", Cn3D_RenAlign);
2115     CommandItem(menu, "WireFrame/W", Cn3D_RenWire);
2116     CommandItem(menu, "Tubular/T", Cn3D_RenTube);
2117     CommandItem(menu, "Hierarchy/H", Cn3D_RenHier);
2118     CommandItem(menu, "Spacefill/P", Cn3D_RenSpace);
2119     CommandItem(menu, "Ball and Stick/B", Cn3D_RenBS);
2120 
2121     /* COLOR top menu */
2122     menu = PulldownMenu(w, "Color/C");
2123     CommandItem(menu, Cn3D_ColorFuncName(C_BYSECSTRUC), Cn3D_ColSecStruc);
2124     CommandItem(menu, Cn3D_ColorFuncName(C_BYSTRUCALIGN), Cn3D_ColStrucAlign);
2125     color_submenu = SubMenu(menu, Cn3D_ColorFuncName(C_BYSEQCONS));
2126 
2127         /* sequence conservation submenu */
2128     for (i = 0; i < CSC_NUMALGORITHMS; i++) {
2129         SetObjectExtra(
2130           CommandItem(color_submenu, (Nlm_CharPtr) CSC_GetAlgorithmName(i),  Cn3D_ColSeqCons), 
2131           (Nlm_VoidPtr) i, NULL);
2132     }
2133 
2134     CommandItem(menu, Cn3D_ColorFuncName(C_BYOBJECT), Cn3D_ColObject);
2135     CommandItem(menu, Cn3D_ColorFuncName(C_BYCHAIN), Cn3D_ColCyChain);
2136     CommandItem(menu, Cn3D_ColorFuncName(C_BYDOMAIN), Cn3D_ColDomain);
2137     CommandItem(menu, Cn3D_ColorFuncName(C_BYRES), Cn3D_ColRes);
2138     CommandItem(menu, Cn3D_ColorFuncName(C_BYHYDRO), Cn3D_ColHydro);
2139     CommandItem(menu, Cn3D_ColorFuncName(C_CPK), Cn3D_ColCPK);
2140     CommandItem(menu, Cn3D_ColorFuncName(C_BYTEMP), Cn3D_ColTemp);
2141 
2142     /* OPTIONS top menu */
2143     menu = PulldownMenu(w, "Option/O");
2144     if (netconfig != NULL) {
2145         CommandItem(menu, "Net Configure.../N", netconfig);
2146     }
2147     color_menu = SubMenu(menu, "Palette Settings");
2148 
2149 #ifndef _OPENGL
2150     color_submenu = SubMenu(color_menu, "Background/B");
2151     CommandItem(color_submenu, "Default", Cn3D_Default_BgColor);
2152     CommandItem(color_submenu, "User Defined...", Cn3D_BgColor);
2153     SeparatorItem(color_menu);
2154     color_submenu = SubMenu(color_menu, "Highlight");
2155     CommandItem(color_submenu, "Default", Cn3D_Default_HLColor);
2156     CommandItem(color_submenu, "User Defined...", Cn3D_HLColor);
2157     SeparatorItem(color_menu);
2158 
2159     color_submenu = SubMenu(color_menu,  "Secondary Structure");
2160     CommandItem(color_submenu, "Default", Cn3D_Default_SSColor);
2161     CommandItem(color_submenu, "Helix...", Cn3D_HelixColor);
2162     CommandItem(color_submenu, "Strand/Sheet...", Cn3D_StrandColor);
2163     CommandItem(color_submenu, "Turn...", Cn3D_TurnColor);
2164     CommandItem(color_submenu, "Coil...", Cn3D_CoilColor);
2165 #else /* _OPENGL */
2166     CommandItem(color_menu, "Helix...", Cn3D_HelixColor);
2167     CommandItem(color_menu, "Strand/Sheet...", Cn3D_StrandColor);
2168     CommandItem(color_menu, "Turn...", Cn3D_TurnColor);
2169     CommandItem(color_menu, "Coil...", Cn3D_CoilColor);
2170     CommandItem(color_menu, "Highlight...", Cn3D_HLColor);
2171     SeparatorItem(color_menu);
2172     CommandItem(color_menu, "Default", Cn3D_Default_SSColor);
2173 #endif
2174 
2175     Cn3D_ma_group_menu = NULL /*SubMenu(menu, "Mouse Settings/M")*/;
2176     Cn3D_ma_action_menu = NULL /* SubMenu(menu, "Mouse3D Actions") */ ;
2177 
2178     /* CONTROLS top menu
2179      */
2180 
2181     menu = PulldownMenu(w, "Help/H");
2182 
2183     CommandItem(menu, "Help.../H", Cn3D_HelpProc);
2184     CommandItem(menu, "About Cn3D.../B", Cn3D_AboutProc);
2185 
2186     SetStatus(Cn3D_iRendCtrl, FALSE);
2187 #ifndef _OPENGL
2188     SetStatus(Cn3D_iViewCtrl, FALSE);
2189 #endif
2190     SetStatus(Cn3D_iAlignCtrl, FALSE);
2191 
2192 
2193     return file_menu;
2194 }
2195 
2196 
2197 static void Cn3D_ShowCtrlProc(IteM i)
2198  {
2199     if (GetStatus(i)) {
2200         SafeShow(Cn3D_wCtrls);
2201         Select(Cn3D_wCtrls);
2202     } else {
2203         SafeHide(Cn3D_wCtrls);
2204     }
2205     Update();
2206 }
2207 
2208 #ifndef _OPENGL
2209 static void Cn3D_ViewerCtrlProc(IteM i)
2210 {
2211     if (i == NULL) {
2212         SetStatus(Cn3D_iViewCtrl, FALSE);
2213         Hide(Cn3D_gViewCtrl);
2214         Update();
2215         return;
2216     }
2217 
2218     if (GetStatus(Cn3D_iViewCtrl) == TRUE) {
2219         Show(Cn3D_gViewCtrl);
2220         Update();
2221         LinkControls3D(Cn3D_left, Cn3D_v3d);
2222     } else {
2223         Hide(Cn3D_gViewCtrl);
2224         Update();
2225     }
2226 
2227     Cn3DResizeProc(Cn3D_w);
2228 }
2229 
2230 #endif                          /* ndef _OPENGL */
2231 
2232 extern void Cn3D_HideCtrl(WindoW w);
2233 extern void Cn3D_HideCtrl(WindoW w)
2234  {
2235     SetStatus(Cn3D_iDisplayCtrl, FALSE);
2236     SafeHide(Cn3D_wCtrls);      /* w may be NULL if called from cn3dentr.c */
2237     Update();
2238 }
2239 
2240 
2241 static void Cn3D_QuitAlready()
2242 {
2243     ClearStructures();
2244     ClearSequences();
2245     QuitProgram();
2246 }
2247 
2248 /*  Default Quits
2249  */
2250 static void Cn3D_QuitProc(IteM i)
2251 {
2252     Cn3D_QuitAlready();
2253 }
2254 
2255 static void Cn3D_Quit(WindoW w)
2256 {
2257     Cn3D_QuitAlready();
2258 }
2259 
2260 
2261 /* Create a complete CN3D window and GUI environment
2262    StandAlone determines whether Cn3D was called or is standalone
2263  */
2264 extern WindoW LIBCALL Cn3DWin(WndActnProc on_close, MenU * file_menu,
2265                               ItmActnProc netconfig, Boolean StandAlone)
2266 {
2267     static Boolean Cn3D_Window_Alive = FALSE;
2268 #ifdef _OPENGL
2269     TOGL_Data *OGL_Data;
2270 #endif
2271 
2272     /* register bioseq callback */
2273     REGISTER_BIOSEQ_BIOSTRUC_MEDIA;
2274     REGISTER_SEQANNOT_BIOSTRUC_MEDIA;
2275     Cn3D_ColorData.userkey = OMGetNextUserKey(); /* uniquely ids process */
2276 
2277     fnMMDBCn3Dmode();           /* make mmdbapi run in cn3d mode */
2278 
2279     Cn3D_fAlignOn = TRUE;       /* turn on aligned and unaligned residues */
2280     Cn3D_fUnalignOn = TRUE;
2281 
2282     if (Cn3D_Window_Alive)
2283         return (Handle) Cn3D_w;
2284 
2285     /* to ensure that Motif will allocate only the colors having
2286      * index less than 32;  all other colorcells will be used (and
2287      * are to be redefined) by 3D-viewer
2288      */
2289     RestrictMotifColorsTo(32);
2290 
2291     /* CN3d window and menus */
2292     { {
2293             MenU menu;
2294 
2295             /* CN3d window and menubar
2296              */
2297             Cn3D_w = DocumentWindow(-33, -10, -10, -10, "Cn3D 3.0",
2298                                     (on_close ? on_close : Cn3D_Quit),
2299                                     NULL);
2300 
2301             /* CN3D general menu set
2302              */
2303             menu = Cn3D_Menus(Cn3D_w, netconfig);
2304 
2305             if (file_menu)
2306                 *file_menu = menu;
2307             else {              /* standard quit */
2308                 SeparatorItem(menu);
2309                 CommandItem(menu, "Quit/Q", Cn3D_QuitProc);
2310             }
2311     }
2312     }
2313 
2314 
2315     { {
2316             Uint2 Cn3D_uSize;
2317             Int2 Cn3D_size =
2318                 (Int2) MIN(screenRect.right, screenRect.bottom);
2319 
2320             Cn3D_size -= 128;
2321             if (Cn3D_size < 200)
2322                 Cn3D_size = 200;
2323             else if (Cn3D_size > 400)
2324                 Cn3D_size = 400;
2325 
2326             Cn3D_uSize = (Uint2) Cn3D_size;
2327 #ifdef _OPENGL
2328             OGL_Data =
2329                 OGL_CreateViewer(Cn3D_w, &Cn3D_uSize, Cn3D_uSize,
2330                                  X_ROTATE_SBAR | Y_ROTATE_SBAR |
2331                                  Z_ROTATE_SBAR, Cn3D_ma_group_menu,
2332                                  Cn3D_ma_action_menu, Cn3D_InitMA, NULL);
2333 #else
2334             Cn3D_gWinGP = Viewer3DViewer(Cn3D_w, &Cn3D_uSize, Cn3D_uSize);
2335 #endif
2336     }
2337     }
2338     Cn3D_ConstructColorData(&Cn3D_ColorData
2339 #ifdef _OPENGL
2340         , OGL_Data
2341 #endif
2342         , StandAlone); /* create default palette */
2343     Cn3D_ColorData.Cn3D_w = Cn3D_w;
2344 
2345     /*
2346        todo: both Viewer3dViewer and Cn3D_ColorData need to be deallocated.  CloseMMDBAPI()
2347        probably should be called also.  This means we need some sort of callback from Entrez
2348        and Sequin to do this right.  lyg
2349 
2350        also need to break out OGL_Data from Viewer 3D when it gets its own initialization routine.
2351 
2352      */
2353 
2354     ProcessUpdatesFirst(FALSE);
2355 #ifndef _OPENGL
2356     if (Cn3D_gWinGP == NULL)
2357         return (Handle) NULL;
2358 #endif
2359 
2360     Cn3D_EnableFileOps();
2361     RealizeWindow(Cn3D_w);
2362 #if defined(_OPENGL) && defined(WIN_MOTIF)
2363     /* now that all windows are realized, set X OpenGL context  (thiessen) */
2364     Nlm_SetOGLContext(NULL, NULL, NULL, NULL);
2365 #endif
2366 #ifdef _OPENGL
2367     OGL_InitializeLists(OGL_Data);
2368 #endif
2369 
2370     Cn3dObjMgrGetSelected();
2371     Cn3D_Redraw(TRUE);
2372     SetResize(Cn3D_w, Cn3DResizeProc);
2373     Cn3DResizeProc(Cn3D_w);
2374     Cn3D_Window_Alive = TRUE;
2375 
2376     Cn3D_wCtrls =
2377         FixedWindow(-10, -33, -10, -10, "Drawing settings", Cn3D_HideCtrl);
2378     Cn3D_gWinGP = Viewer3DGroups(Cn3D_wCtrls);
2379     RealizeWindow(Cn3D_wCtrls);
2380 
2381 #ifdef _OPENGL
2382     /* restore saved quality settings */
2383     Cn3D_SetQualityFromAppParams();
2384 #endif
2385 
2386     return Cn3D_w;
2387 }
2388 
2389 
2390 Nlm_Boolean Nlm_Call_SetPosition3D(Nlm_RecT *rect)
2391 {
2392 #ifdef _OPENGL
2393     return OGL_SetPosition3D(Cn3D_ColorData.OGL_Data, rect);
2394 #else                           /* _OPENGL */
2395     return SetPosition3D(Cn3D_v3d, rect);
2396 #endif                          /* else _OPENGL */
2397 }
2398 
2399 Nlm_Boolean Nlm_Call_SaveImageGIF(CharPtr defname)
2400 {
2401 #ifndef _OPENGL
2402     return Nlm_SaveImageGIF(Nlm_GetViewerImage3D(Cn3D_v3d), defname);
2403 #else
2404     return Nlm_SaveImageGIF(NULL, NULL);
2405 #endif
2406 }
2407 

source navigation ]   [ diff markup ]   [ identifier search ]   [ freetext search ]   [ file search ]  

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.