1
2 /*
3 A* -------------------------------------------------------------------
4 B* This file contains source code for the PyMOL computer program
5 C* copyright 1998-2000 by Warren Lyford Delano of DeLano Scientific.
6 D* -------------------------------------------------------------------
7 E* It is unlawful to modify or remove this copyright notice.
8 F* -------------------------------------------------------------------
9 G* Please see the accompanying LICENSE file for further information.
10 H* -------------------------------------------------------------------
11 I* Additional authors of this source file include:
12 -*
13 -*
14 -*
15 Z* -------------------------------------------------------------------
16 */
17 #include"os_python.h"
18
19 #include"os_predef.h"
20 #include"os_std.h"
21 #include"os_gl.h"
22
23 #include"main.h"
24 #include"Feedback.h"
25 #include"Rep.h"
26 #include"MemoryDebug.h"
27 #include"CoordSet.h"
28 #include"P.h"
29 #include"Util.h"
30 #include"Scene.h"
31
32 /*========================================================================*/
33 static
RepRebuild(struct Rep * I,struct CoordSet * cs,int state,int rep)34 struct Rep *RepRebuild(struct Rep *I, struct CoordSet *cs, int state, int rep)
35 {
36 Rep *tmp = NULL;
37
38 PRINTFD(I->G, FB_Rep)
39 " RepRebuild-Debug: entered: rep %d I->fNew %p\n", rep, (void *) I->fNew ENDFD;
40
41 if(I->fNew) {
42 tmp = I->fNew(cs, state);
43 if(tmp) {
44 tmp->fNew = I->fNew;
45 I->fFree(I);
46 } else { /* nothing returned -- visibility is zero... */
47 cs->Active[rep] = false; /* keep the old object around, but inactive */
48 tmp = I;
49 }
50 } else
51 I->fFree(I);
52 return (tmp);
53 }
54
55
56 /*========================================================================*/
57 static
RepUpdate(struct Rep * I,struct CoordSet * cs,int state,int rep)58 struct Rep *RepUpdate(struct Rep *I, struct CoordSet *cs, int state, int rep)
59 {
60
61 PRINTFD(I->G, FB_Rep)
62 " RepUpdate-Debug: entered: rep %d I->MaxInvalid %d\n", rep, I->MaxInvalid ENDFD;
63
64 if(I->MaxInvalid) {
65 if(I->MaxInvalid == cRepInvPick) {
66 if((rep == cRepLine) ||
67 (rep == cRepCyl) || (rep == cRepRibbon) || (rep == cRepNonbonded))
68 I->MaxInvalid = cRepInvRep;
69 }
70
71 if(I->MaxInvalid < cRepInvColor) {
72 } else if(I->MaxInvalid == cRepInvColor) {
73 if(I->fRecolor) {
74 I->fRecolor(I, cs);
75 } else {
76 I = I->fRebuild(I, cs, state, rep);
77 }
78 } else if(I->MaxInvalid <= cRepInvVisib) {
79 int rebuilt = false;
80 if(I->fSameVis) {
81 if(!I->fSameVis(I, cs)){
82 I = I->fRebuild(I, cs, state, rep);
83 rebuilt = true;
84 }
85 }
86 if(I->fSameColor) {
87 if (!rebuilt){
88 if(!I->fSameColor(I, cs)){
89 I->fRecolor(I, cs);
90 }
91 }
92 }
93 if (!I->fSameVis && !I->fSameColor)
94 I = I->fRebuild(I, cs, state, rep);
95 } else if(I->MaxInvalid >= cRepInvCoord) {
96 I = I->fRebuild(I, cs, state, rep);
97 if(!cs->Active[rep]) {
98 I->fFree(I);
99 I = NULL;
100 }
101 /* if(I->fNew) {
102 tmp = I->fNew(cs);
103 if(I->fFree) I->fFree(I);
104 I=tmp;
105 */
106 } else {
107 I = I->fRebuild(I, cs, state, rep);
108 }
109 if(I)
110 I->MaxInvalid = 0;
111 }
112 return (I);
113 }
114
115 /*========================================================================*/
RepInvalidate(struct Rep * I,struct CoordSet * cs,int level)116 void RepInvalidate(struct Rep *I, struct CoordSet *cs, int level)
117 {
118 SceneInvalidatePicking(I->G); // for now, if anything invalidated, then invalidate picking
119 if(level > I->MaxInvalid)
120 I->MaxInvalid = level;
121 }
122
123 /*
124 * Get the visRep mask according to auto_show_* settings
125 */
RepGetAutoShowMask(PyMOLGlobals * G)126 int RepGetAutoShowMask(PyMOLGlobals * G)
127 {
128 int mask = 0;
129 if (SettingGetGlobal_b(G, cSetting_auto_show_lines)) mask |= cRepLineBit;
130 if (SettingGetGlobal_b(G, cSetting_auto_show_spheres)) mask |= cRepSphereBit;
131 if (SettingGetGlobal_b(G, cSetting_auto_show_nonbonded)) mask |= cRepNonbondedBit;
132 return mask;
133 }
134
135 /*========================================================================*/
RepRenderBox(struct Rep * this_,RenderInfo * info)136 static void RepRenderBox(struct Rep *this_, RenderInfo * info)
137 {
138 PyMOLGlobals *G = this_->G;
139 if(G->HaveGUI && G->ValidContext) {
140 #ifdef PURE_OPENGL_ES_2
141 /* TODO */
142 #else
143 glBegin(GL_LINE_LOOP);
144 glVertex3f(-0.5F, -0.5F, -0.5F);
145 glVertex3f(-0.5F, -0.5F, 0.5F);
146 glVertex3f(-0.5F, 0.5F, 0.5F);
147 glVertex3f(-0.5F, 0.5F, -0.5F);
148
149 glVertex3f(0.5F, 0.5F, -0.5F);
150 glVertex3f(0.5F, 0.5F, 0.5F);
151 glVertex3f(0.5F, -0.5F, 0.5F);
152 glVertex3f(0.5F, -0.5F, -0.5F);
153 glEnd();
154
155 glBegin(GL_LINES);
156 glVertex3i(0, 0, 0);
157 glVertex3i(1, 0, 0);
158
159 glVertex3i(0, 0, 0);
160 glVertex3i(0, 2, 0);
161
162 glVertex3i(0, 0, 0);
163 glVertex3i(0, 0, 3);
164
165 glEnd();
166 #endif
167 }
168
169 }
170
171
172 /*========================================================================*/
RepInit(PyMOLGlobals * G,Rep * I)173 void RepInit(PyMOLGlobals * G, Rep * I)
174 {
175 UtilZeroMem(I, sizeof(Rep));
176 I->G = G;
177 I->fInvalidate = RepInvalidate;
178 I->fUpdate = RepUpdate;
179 I->fRender = RepRenderBox;
180 I->fRebuild = RepRebuild;
181 }
182
183
184 /*========================================================================*/
RepPurge(Rep * I)185 void RepPurge(Rep * I)
186 {
187 FreeP(I->P);
188 }
189
RepIterator(PyMOLGlobals * G,int rep_)190 RepIterator::RepIterator(PyMOLGlobals * G, int rep_) {
191 if (rep_ < 0){
192 end = cRepCnt;
193 rep = -1;
194 } else {
195 end = rep_ + 1;
196 rep = rep_ - 1;
197 }
198 }
199