4 * Created by Toshi Nagata on 12/09/01.
5 * Copyright 2012 Toshi Nagata. All rights reserved.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation version 2 of the License.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
17 /* On MinGW, #include of <GL/gl.h> should be before something in MolLib.h.
18 Therefore, we include MainView.h first separately and then include
19 the rest of MolLib.h. */
27 #pragma mark ====== Drawing Settings ======
32 MainView *mview = (MainView *)calloc(sizeof(MainView), 1);
34 /* Initialize common members (that are used both in GUI and CMD versions */
35 memset(mview, 0, sizeof(MainView));
36 mview->track = TrackballNew();
37 mview->atomRadius = 0.2;
38 mview->bondRadius = 0.1;
39 mview->atomResolution = 12;
40 mview->bondResolution = 8;
41 mview->probabilityScale = 1.5382;
42 mview->dimension = 10.0;
43 mview->showHydrogens = mview->showDummyAtoms = mview->showExpandedAtoms = 1;
44 mview->showPeriodicBox = 1;
45 mview->showGraphite = 5;
51 MainView_release(MainView *mview)
54 if (mview->ref != NULL) {
55 fprintf(stderr, "%s:%d:Memory leak warning: mview->ref is not NULL\n", __FILE__, __LINE__);
58 // MainView_setMolecule(mview, NULL);
59 TrackballRelease(mview->track);
60 #if !defined(__CMDMAC__)
61 IntGroupRelease(mview->tableCache);
62 IntGroupRelease(mview->tableSelection);
63 if (mview->nlabels > 0) {
65 for (i = 0; i < mview->nlabels; i++) {
66 MainViewCallback_releaseLabel(mview->labels[i].label);
69 free(mview->sortedLabels);
71 if (mview->rotateFragment != NULL)
72 IntGroupRelease(mview->rotateFragment);
73 if (mview->rotateFragmentOldPos != NULL)
74 free(mview->rotateFragmentOldPos);
75 if (mview->visibleFlags != NULL)
76 free(mview->visibleFlags);
84 MainView_setMolecule(MainView *mview, struct Molecule *mol)
86 if (mview == NULL || mview->mol == mol)
88 if (mview->mol != NULL) {
89 mview->mol->mview = NULL; // No need to release
90 MoleculeRelease(mview->mol);
95 mol->mview = mview; // No retain
96 MainViewCallback_moleculeReplaced(mview, mol);
97 MoleculeCallback_notifyModification(mol, 0);
103 MainView_setBackgroundColor(MainView *mview, float red, float green, float blue)
106 mview->background_color[0] = red;
107 mview->background_color[1] = green;
108 mview->background_color[2] = blue;
109 MoleculeCallback_notifyModification(mview->mol, 0);
114 MainView_getBackgroundColor(const MainView *mview, float *rgb)
117 rgb[0] = mview->background_color[0];
118 rgb[1] = mview->background_color[1];
119 rgb[2] = mview->background_color[2];
123 #pragma mark ====== Graphics ======
126 MainView_insertGraphic(MainView *mview, int index, const MainViewGraphic *graphic)
128 if (index < 0 || index >= mview->ngraphics)
129 index = mview->ngraphics;
130 InsertArray(&mview->graphics, &mview->ngraphics, sizeof(MainViewGraphic), index, 1, graphic);
131 MoleculeCallback_notifyModification(mview->mol, 0);
136 MainView_removeGraphic(MainView *mview, int index)
139 if (index < 0 || index >= mview->ngraphics)
141 g = &mview->graphics[index];
142 if (g->points != NULL)
144 if (g->normals != NULL)
146 DeleteArray(&mview->graphics, &mview->ngraphics, sizeof(MainViewGraphic), index, 1, NULL);
147 MoleculeCallback_notifyModification(mview->mol, 0);