1
2
3 /*
4 A* -------------------------------------------------------------------
5 B* This file contains source code for the PyMOL computer program
6 C* Copyright (c) Schrodinger, LLC.
7 D* -------------------------------------------------------------------
8 E* It is unlawful to modify or remove this copyright notice.
9 F* -------------------------------------------------------------------
10 G* Please see the accompanying LICENSE file for further information.
11 H* -------------------------------------------------------------------
12 I* Additional authors of this source file include:
13 -*
14 -*
15 -*
16 Z* -------------------------------------------------------------------
17 */
18
19 #ifndef _H_Feedback
20 #define _H_Feedback
21
22 #include"PyMOLGlobals.h"
23 #include <vector>
24 #include <array>
25
26
27 /*
28
29 IMPORTANT DEVELOPER NOTICE:
30
31 All non-debugging output should pass through the PRINTF and ENDF
32 macros currently defined below, or through the FeedbackAdd or
33 FeedbackAutoAdd routines.
34
35 Feedback bits are:
36
37 Results -- DEFAULT: ON
38
39 output from a definite action which gives a result, such as an RMS
40 fit, a measured surface area, etc.
41
42 Errors -- DEFAULT: ON
43
44 complaints which will cause failure at some level.
45
46 Actions -- DEFAULT: ON
47
48 Output regarding actions in progress or completed, but which
49 don't return a particular result. Example: loading an object or
50 creating a selection.
51
52 Warnings -- DEFAULT: ON
53
54 Questionable situations which will not necessarily result in task
55 failure. Examples: creation of atom selection which includes no
56 atoms. RMS fitting with <4 atoms.
57
58 Details -- DEFAULT: ON
59
60 Verbose output reflecting details about what is going on, such as the
61 number of primitives in a raytracing scene. DEFAULT: ON
62
63 Blather -- DEFAULT: OFF
64
65 Output which doesn't fit into the above catogories, and is not likely
66 to be required except in extreme cases, but doesn't fall into the
67 category of debugging.
68
69 Debugging -- DEFAULT: OFF
70
71 Text output while would only be of interest to a developer.
72
73 NOTE: Debugging output is the only kind of output which should be sent
74 directly to standard output (actually, standard error).
75
76 NOTE: Debugging output should always be preceeded b the enclosing
77 function name.
78
79 */
80
81
82 /* WARNING: The following constants are replicated in Python for the purpose
83 * of minimize program startup time */
84
85
86 /* Discrete Systems and/or Code Modules */
87
88 #define FB_All 0 /* only used for setting */
89
90
91 /* NOTE, the following don't have to be packed, or in order -- we just
92 need to record what the maximum index is. Rember that that
93 feedback architecture is purely a performance hack, so expect some
94 inconvenience...
95 */
96
97
98 /* layer 0 */
99
100 #define FB_Isomesh 1
101 #define FB_Map 2
102 #define FB_Matrix 3
103 #define FB_MyPNG 4
104 #define FB_Triangle 5
105 #define FB_Match 6
106 #define FB_Raw 7
107 #define FB_Isosurface 8
108 #define FB_OpenGL 9
109
110 // FB_Shader; no room here
111
112
113 /* layer 1 */
114
115 #define FB_Color 10
116 #define FB_CGO 11
117 #define FB_Feedback 12
118 #define FB_Scene 13
119 #define FB_Threads 14 /* part of P.c */
120 #define FB_Symmetry 15
121 #define FB_Ray 16
122 #define FB_Setting 17
123 #define FB_Object 18
124 #define FB_Ortho 19
125 #define FB_Movie 20
126 #define FB_Python 21 /* part of P.c */
127 #define FB_Extrude 22
128 #define FB_Rep 23
129 #define FB_Shaker 24
130
131 /* layer 2 */
132
133 #define FB_CoordSet 25
134 #define FB_DistSet 26
135 #define FB_GadgetSet 27
136
137 #define FB_ObjectMolecule 30
138 #define FB_ObjectMap 31
139 #define FB_ObjectMesh 32
140 #define FB_ObjectDist 33
141 #define FB_ObjectCGO 34
142 #define FB_ObjectCallback 35
143 #define FB_ObjectSurface 36
144 #define FB_ObjectGadget 37
145 #define FB_ObjectSlice 38
146 #define FB_ObjectVolume 39
147
148 #define FB_RepAngle 43
149 #define FB_RepDihedral 44
150 #define FB_RepWireBond 45
151 #define FB_RepCylBond 46
152 #define FB_RepEllipsoid 47
153 #define FB_RepLabel 48
154 #define FB_RepSphere 49
155 #define FB_RepSurface 50
156 #define FB_RepMesh 51
157 #define FB_RepDot 52
158 #define FB_RepNonbonded 53
159 #define FB_RepNonbondedSphere 54
160 #define FB_RepDistDash 55
161 #define FB_RepDistLabel 56
162 #define FB_RepRibbon 57
163 #define FB_RepCartoon 58
164 #define FB_Sculpt 59
165 #define FB_VFont 60
166 // in layer0
167 #define FB_Shader 61
168 #define FB_ShaderMgr 62
169 #define FB_ShaderPrg 63
170 #define FB_Session 64
171 // in layer1
172 #define FB_Property 65
173
174 /* layer 3 */
175
176 #define FB_Executive 70
177 #define FB_Selector 71
178 #define FB_Editor 72
179 #define FB_Nag 73
180
181
182 /* layer 4 */
183
184 #define FB_Export 75
185 #define FB_CCmd 76 /* "cmd" is just the python version */
186 #define FB_API 77 /* APIEntry/Exit */
187
188
189 /* layer 5 */
190
191 #define FB_Main 80
192
193 #define FB_Total 81 /* highest index + 1 */
194
195
196 /* Feedback level bit masks */
197
198 #define FB_None 0x00
199
200 #define FB_Output 0x01
201
202
203 /* python/text output */
204 #define FB_Results 0x02
205
206
207 /* limited to actual results of an operation...requested measurements, etc. */
208 #define FB_Errors 0x04
209 #define FB_Actions 0x08
210
211
212 /* advisories regarding the completion of a */
213 #define FB_Warnings 0x10
214 #define FB_Details 0x20
215 #define FB_Blather 0x40
216 #define FB_Debugging 0x80
217
218 #define FB_Everything 0xFF
219
220 class CFeedback
221 {
222 std::vector<std::array<unsigned char, FB_Total>> m_stack{{}};
223 PyMOLGlobals* m_G;
224
225 public:
226 CFeedback(PyMOLGlobals* G, int quiet);
decltype(m_stack)227 decltype(m_stack)::value_type& currentLayer() { return m_stack.back(); };
228 void push();
229 void pop();
230 void autoAdd(unsigned int sysmod, unsigned char mask, const char* str);
231 void add(const char* str);
232 void addColored(const char* str, unsigned char mask);
233 void setMask(unsigned int sysmod, unsigned char mask);
234 unsigned char& currentMask(unsigned int sysmod);
235 bool testMask(unsigned int sysmod, unsigned char mask);
236 void disable(unsigned int sysmod, unsigned char mask);
237 void enable(unsigned int sysmod, unsigned char mask);
238 };
239
240 /* Mechanism: a high-speed bit test, with no range checking
241 * in order to avoid penalizing performance-senstive code
242 * modules which may contain live debugging code.
243 */
244
245 inline
Feedback(PyMOLGlobals * G,unsigned int sysmod,unsigned char mask)246 bool Feedback(PyMOLGlobals* G, unsigned int sysmod, unsigned char mask)
247 {
248 return G->Feedback->testMask(sysmod, mask);
249 }
250
251 /* FEEDBACK_MAX_OUTPUT should be as small as is reasonable
252 * since this much space gets consumed on the stack
253 * every time we have a PRINTF macro. One might consider
254 * rewriting these macros to consume heap space instead.
255 */
256
257 #define FEEDBACK_MAX_OUTPUT 255
258 typedef char FeedbackLineType[FEEDBACK_MAX_OUTPUT];
259
260
261 /* Print Feedback Macros -- this the most flexible and cross-OS
262 * portable solution I've come up with for sending output with
263 * variable arguments.
264 */
265
266 #ifdef _WEBGL
267 #else
268
269 #define PRINTFB(G,sysmod,mask) \
270 { \
271 FeedbackLineType _FBstr; \
272 if(G->Feedback->testMask(sysmod,mask)) {\
273 const unsigned char _mask = mask; \
274 (snprintf)( _FBstr, FEEDBACK_MAX_OUTPUT,
275
276 #define ENDFB(G) \
277 ); \
278 G->Feedback->addColored(_FBstr,_mask); \
279 } \
280 }
281
282 #define PRINTF { FeedbackLineType _FBstr; (snprintf)( _FBstr, FEEDBACK_MAX_OUTPUT,
283 #define ENDF(G) ); G->Feedback->add(_FBstr);}
284 #endif
285
286
287 /* debugging: goes to stderr */
288
289 #define PRINTFD(G,sysmod) {if(G->Feedback->testMask(sysmod, FB_Debugging)) { fprintf(stderr,
290 #define ENDFD );fflush(stderr);}}
291
292
293 /* convenient vector dumping routine */
294
295 #define ENDFD3f(v) );fprintf(stderr,": %8.3f %8.3f %8.3f\n",v[0],v[1],v[2]);fflush(stderr);}}
296
297 #endif
298