HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_DisplayOption.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GR_DisplayOption.h
7  *
8  * COMMENTS: Drawing options for the render library. Authored by Mark.
9  *
10  */
11 
12 
13 #ifndef __GR_DisplayOption_h__
14 #define __GR_DisplayOption_h__
15 
16 #include "GR_API.h"
17 #include <string.h>
18 #include <UT/UT_VectorTypes.h>
19 #include <UT/UT_SymbolTable.h>
20 #include <UT/UT_Color.h>
21 #include <UT/UT_Array.h>
22 #include "GR_Defines.h"
23 #include "GR_CommonDispOption.h"
24 #include "GR_OptionTable.h"
25 #include "GR_UserOption.h"
26 
27 class RE_Render;
28 class RE_LightList;
29 
30 #define ASSIGN_BUMP(flag) if(myFlags.flag != onoff) mySerialNum++; \
31  myFlags.flag=onoff
32 
33 class GR_UserOption;
34 
36 {
37 public:
38  GR_DisplayOption(GR_CommonDispOption *common_options = 0,
39  int t = 0, bool for_lops = false);
42 
43  // Return the display set type this option set represents
44  int getDisplaySet() const { return myDisplaySet; }
45 
46  GR_DisplayOption &operator=(const GR_DisplayOption &opt);
47 
48  // Copy all but the common display options from the given GR_DisplayOption
49  // object.
50  void copyNonCommon(const GR_DisplayOption &opt);
51 
52  // Copy the user options (not done by copyNonCommon).
53  void copyUserOptions(const GR_DisplayOption &opt);
54 
55  // Refresh the version key for all of the enabled user options from the
56  // global option table.
57  void refreshUserOptionVersions();
58 
59  // Return whether or not the specified object has the same set of enabled
60  // user options. Version keys are ignored.
61  bool userOptionStatesEqual(
62  const GR_DisplayOption &opt) const;
63 
64  // Set the enabled user options to match the specified object. Note that
65  // version keys are also copied. However, this is irrelevant as version
66  // keys only matter while drawing and will have been refreshed in that
67  // case anyway.
68  void matchUserOptionStates(const GR_DisplayOption &opt);
69 
70  // Class I/O methods. Return true if successful, false if not.
71  bool save(std::ostream &, int indent=0) const;
72  bool load(UT_IStream &);
73 
74  const char *className() const;
75 
76  // Set the shading mode. The draw mode is either wireframe or shaded,
77  // but the shading mode can be hiddenwire, flag shaded, wire over gouraud,
78  // etc. Changing the shading mode will change the drawing mode as well as
79  // other flags in this class.
80  void shadingMode(GR_ShadingMode shading_mode);
81 
82  // Find which shading mode we're currently using.
83  GR_ShadingMode shadingMode() const;
84 
85  // Utility methods to convert a GR_BoundaryMode to/from a token. The parse
86  // method returns GR_BOUNDARY_NONE on a failure.
87  static void saveBoundaryMode(std::ostream &os, GR_BoundaryMode mode);
88  static GR_BoundaryMode parseBoundaryMode(const char *token,
89  bool for_uv_view = false);
90 
91  // Utility methods to convert a GR_ShadingMode to/from a token. The parse
92  // method returns -1 on a failure.
93  static void saveShadingMode(std::ostream &os, GR_ShadingMode mode);
94  static int parseShadingMode(const char *token);
95 
96  // "Get" methods.
97  bool drawPointMarkers() const { return myFlags.drawPointMarkers; }
98  bool drawPointNums () const { return myFlags.drawPointNums; }
99  bool drawPointNmls () const { return myFlags.drawPointNmls; }
100  bool drawPointTxtNums() const { return myFlags.drawPointTxtNums; }
101  bool drawPointPos () const { return myFlags.drawPointPos; }
102  bool drawPointVelocity() const { return myFlags.drawPointVelocity; }
103  bool drawPointCoincident() const
104  { return myFlags.drawPointCoincident; }
105  bool drawVertexMarkers() const{ return myFlags.drawVertexMarkers; }
106  bool drawVertexNums () const { return myFlags.drawVertexNums; }
107  bool drawVertexTxtNums() const { return myFlags.drawVertexTxtNums; }
108  bool drawVertexNmls () const { return myFlags.drawVertexNmls; }
109  bool drawPrimNums () const { return myFlags.drawPrimNums; }
110  bool drawPrimNmls () const { return myFlags.drawPrimNmls; }
111  bool drawPrimHulls () const { return myFlags.drawPrimHulls; }
112  bool drawPrimBreakpoints() const{return myFlags.drawPrimBreakpoints;}
113  bool drawProfiles () const { return myFlags.drawProfiles; }
114  bool drawProfNums () const { return myFlags.drawProfNums; }
115  bool drawLit () const { return myFlags.drawLit; }
116  bool drawFaded () const { return myFlags.drawFaded; }
117  bool drawGhosted () const { return myFlags.drawGhosted; }
118  bool drawXRay () const { return myFlags.drawXRay; }
119  bool appliesToSelection() const { return myFlags.appliesToSelection;}
120  bool toggleAffectsSet() const { return myFlags.toggleAffectsSet; }
121  bool boundBox () const;
122  bool hlGhostFill () const;
123  bool hlXray () const;
124  int drawMode () const;
125  bool wireHiddenLine () const;
126  bool flatShaded () const;
127  bool wireOverShaded () const;
128 
129  bool lockShadingMode () const { return myFlags.lockShadingMode; }
130  bool uvFillBackFaces () const { return myFlags.uvFillBackFaces; }
131  bool uvFillOverlap () const { return myFlags.uvFillOverlap; }
132  bool tintBackfaces () const { return myFlags.tintBackfaces; }
133 
134  // "Set" methods.
135  void drawPointMarkers(bool onoff){ASSIGN_BUMP(drawPointMarkers);}
136  void drawPointNums(bool onoff) { ASSIGN_BUMP(drawPointNums);}
137  void drawPointNmls(bool onoff) { ASSIGN_BUMP(drawPointNmls);}
138  void drawPointTxtNums(bool onoff) { ASSIGN_BUMP(drawPointTxtNums);}
139  void drawPointPos(bool onoff) { ASSIGN_BUMP(drawPointPos);}
140  void drawPointVelocity(bool onoff){ ASSIGN_BUMP(drawPointVelocity);}
141  void drawPointCoincident(bool onoff)
142  { ASSIGN_BUMP(drawPointCoincident);}
143  void drawVertexMarkers(bool onoff)
144  { ASSIGN_BUMP(drawVertexMarkers);}
145  void drawVertexNums(bool onoff) { ASSIGN_BUMP(drawVertexNums);}
146  void drawVertexNmls(bool onoff) { ASSIGN_BUMP(drawVertexNmls);}
147  void drawVertexTxtNums(bool onoff){ ASSIGN_BUMP(drawVertexTxtNums);}
148  void drawPrimNums (bool onoff) { ASSIGN_BUMP(drawPrimNums);}
149  void drawPrimNmls (bool onoff) { ASSIGN_BUMP(drawPrimNmls);}
150  void drawPrimHulls (bool onoff) { ASSIGN_BUMP(drawPrimHulls);}
151  void drawPrimBreakpoints (bool onoff)
152  { ASSIGN_BUMP(drawPrimBreakpoints);}
153 
154  void drawProfiles (bool onoff) { myFlags.drawProfiles =onoff;}
155  void drawProfNums (bool onoff) { myFlags.drawProfNums =onoff;}
156  void drawLit (bool onoff) { myFlags.drawLit =onoff;}
157  void drawFaded (bool onoff) { myFlags.drawFaded =onoff;}
158  void drawGhosted (bool onoff) { myFlags.drawGhosted =onoff;}
159  void drawXRay (bool onoff) { myFlags.drawXRay =onoff;}
160  void appliesToSelection(bool onoff)
161  { myFlags.appliesToSelection = onoff; }
162  void toggleAffectsSet(bool onoff) { myFlags.toggleAffectsSet =onoff;}
163  void lockShadingMode (bool onoff) { myFlags.lockShadingMode =onoff;}
164  void uvFillBackFaces (bool onoff) { myFlags.uvFillBackFaces =onoff;}
165  void uvFillOverlap (bool onoff) { myFlags.uvFillOverlap =onoff;}
166  void tintBackfaces (bool onoff) { myFlags.tintBackfaces =onoff;}
167 
168  // Decorations with enhanced visibility options.
169  void pointMarkersVisible(GR_DecorVisibility m);
170  void pointNumsVisible(GR_DecorVisibility m);
171  void pointNmlsVisible(GR_DecorVisibility m);
172  void pointTxtNumsVisible(GR_DecorVisibility m);
173  void pointPosVisible(GR_DecorVisibility m);
174  void pointVelocityVisible(GR_DecorVisibility m);
175  void vertexMarkersVisible(GR_DecorVisibility m);
176  void vertexNumsVisible(GR_DecorVisibility m);
177  void vertexNmlsVisible(GR_DecorVisibility m);
178  void vertexTxtNumsVisible(GR_DecorVisibility m);
179  void primNumsVisible(GR_DecorVisibility m);
180  void primNmlsVisible(GR_DecorVisibility m);
181  void primBreakpointsVisible(GR_DecorVisibility m);
182 
183  GR_DecorVisibility pointMarkersVisible() const;
184  GR_DecorVisibility pointNumsVisible() const;
185  GR_DecorVisibility pointNmlsVisible () const;
186  GR_DecorVisibility pointTxtNumsVisible() const;
187  GR_DecorVisibility pointPosVisible () const;
188  GR_DecorVisibility pointVelocityVisible () const;
189  GR_DecorVisibility vertexMarkersVisible() const;
190  GR_DecorVisibility vertexNumsVisible() const;
191  GR_DecorVisibility vertexNmlsVisible() const;
192  GR_DecorVisibility vertexTxtNumsVisible() const;
193  GR_DecorVisibility primNumsVisible() const;
194  GR_DecorVisibility primNmlsVisible() const;
195  GR_DecorVisibility primBreakpointsVisible() const;
196 
197  GR_DecorVisibility getVisibilityFor(GR_Decoration d) const;
198 
199  GR_BoundaryMode boundaryMode() const { return myBoundaryMode; }
201  {
202  if (mode != myBoundaryMode)
203  {
204  myBoundaryMode = mode;
205  mySerialNum++;
206  }
207  }
208  GR_BoundaryMode uvBoundaryMode() const { return myBoundaryUVMode; }
210  {
211  if (mode != myBoundaryUVMode)
212  {
213  myBoundaryUVMode = mode;
214  mySerialNum++;
215  }
216  }
217 
218  GR_CommonDispOption&common() { return *myCommonOptions; }
219  const GR_CommonDispOption&common() const { return *myCommonOptions; }
220 
221  void enableUserOption(const char *name, bool onoff);
222  bool getUserOptionState(const char *name) const;
223  void disableAllUserOptions();
224 
226  { return myUserOptions.entries() > 0; }
227 
228  // This method is called when user options are being destroyed. We need
229  // to take the option_id since there is no way at that time for us to map
230  // an option name to the id.
231  void removeUserOption(int option_id);
232 
233  // Methods to query the enabled user options.
234  int getNumUserOptions() const { return myUserOptions.entries(); }
235  const GR_UserOption *getUserOption(int i) const;
236  const GR_UserOption *getOption(const char *name) const;
237  int getOptionId(int i) const;
238 
239  // Display list support
240  void clearNonCachedDrawFlag() const { myNonCachedDrawFlag = false; }
241  void setNonCachedDrawFlag() const { myNonCachedDrawFlag = true; }
242  bool hasNonCachedDraw() const { return myNonCachedDrawFlag ; }
243 
244  void setNonCachedPass(bool nc_pass) { myNonCachedPass = nc_pass; }
245  bool isNonCachedPass() const { return myNonCachedPass; }
246 
247  const RE_LightList *getLightList() const { return common().getLightList(); }
248 
249  int getSerialNum() const { return (common().getSerialNum() +
250  mySerialNum + myRefineSerial); }
251  int getRefineSerial() const { return myRefineSerial; }
252  void bumpRefineSerial() { myRefineSerial++; }
253  int64 getUniqueID() const { return int64(mySerialNum)<<int64(32) |
254  int64(common().getUniqueID()); }
255 
256  void print(std::ostream &os) const;
257 
258  // return true if 'opt' uses the same shading mode and would request the
259  // same attributes as this display option set.
260  bool compatibleWith(const GR_DisplayOption &opt) const;
261 
262  int getVisContext() const { return common().getVisContext(); }
263 
264 private:
265  GR_CommonDispOption *myCommonOptions;
266  int myDisplaySet;
267  bool myOwnCommonOptionsFlag;
268 
269  //
270  // A simple class to store the unique id and version of a GR_UserOption.
271  // This needs to be here or else the UT_Array template won't be able
272  // to compile on Windows.
273  //
274  class gr_UserOptionRef
275  {
276  public:
277  gr_UserOptionRef(): myId(-1), myVersion(-1) {}
278  gr_UserOptionRef( int id, int version )
279  : myId(id), myVersion(version) {}
280 
281  int operator==(const gr_UserOptionRef &opt)
282  { return myId == opt.myId && myVersion == opt.myVersion; }
283  static int compareID(const gr_UserOptionRef *r1,
284  const gr_UserOptionRef *r2)
285  {
286  return r1->myId - r2->myId;
287  }
288 
289  int myId;
290  int myVersion;
291  };
292 
293  // This array consists only of references to the enabled user options, and
294  // is stored sorted by option id for performance reasons.
295  UT_Array<gr_UserOptionRef> myUserOptions;
296 
297  struct grDrawFlags
298  {
299  unsigned drawPointMarkers :1, // draw points
300  drawPointNums :1, // draw point numbers
301  drawPointNmls :1, // draw point normals
302  drawPointTxtNums :1, // draw point texture numbers
303  drawPointPos :1, // draw point positions
304  drawPointVelocity:1, // draw point velocity (v)
305  drawPointCoincident:1, // draw # of point coincidences
306 
307  drawVertexMarkers:1, // draw vertex markers
308  drawVertexNums :1, // draw vertex numbers
309  drawVertexNmls :1, // draw vertex normals
310  drawVertexTxtNums:1, // draw vertex texture numbers
311 
312  drawPrimNums :1, // draw primitive numbers
313  drawPrimNmls :1, // draw primitive normals
314  drawPrimHulls :1, // draw Spline prim hulls
315  drawPrimBreakpoints:1, // draw primitive break points
316 
317  drawProfiles :1, // draw profiles
318  drawProfNums :1, // draw profile numbers
319  drawFaded :1, // draw without point colors or textures
320  drawGhosted :1, // draw blended with BG color
321 
322  appliesToSelection:1, // use for selected or non-selected?
323  toggleAffectsSet:1, // RHS toolbar toggles affect this set
324 
325  drawLit :1,
326  drawXRay :1,
327  lockShadingMode :1,
328  uvFillBackFaces :1,
329  uvFillOverlap :1,
330  tintBackfaces :1;
331  };
332  grDrawFlags myFlags;
333  GR_BoundaryMode myBoundaryMode;
334  GR_BoundaryMode myBoundaryUVMode;
335  GR_ShadingMode myShadingMode;
336  mutable bool myNonCachedDrawFlag;
337  bool myNonCachedPass;
338  int mySerialNum;
339  int myUniqueID;
340  int myRefineSerial;
341  bool myForLops;
342 
344 };
345 
346 inline void
348 { myVisibility[GR_POINT_MARKER] = m;}
349 
350 inline void
352 { myVisibility[GR_POINT_NUMBER] = m; }
353 
354 inline void
356 { myVisibility[GR_POINT_NORMAL] = m; }
357 
358 inline void
360 { myVisibility[GR_POINT_UV] = m; }
361 
362 inline void
364 { myVisibility[GR_POINT_POSITION] = m; }
365 
366 inline void
368 { myVisibility[GR_POINT_VELOCITY] = m; }
369 
370 inline void
372 { myVisibility[GR_VERTEX_MARKER] = m; }
373 
374 inline void
376 { myVisibility[GR_VERTEX_NUMBER] = m; }
377 
378 inline void
380 { myVisibility[GR_VERTEX_NORMAL] = m; }
381 
382 inline void
384 { myVisibility[GR_VERTEX_UV] = m; }
385 
386 inline void
388 { myVisibility[GR_PRIM_NUMBER] = m; }
389 
390 inline void
392 { myVisibility[GR_PRIM_NORMAL] = m; }
393 
394 inline void
396 { myVisibility[GR_PRIM_BREAKPOINT] = m; }
397 
398 inline GR_DecorVisibility
400 { return myVisibility[GR_POINT_MARKER]; }
401 
402 inline GR_DecorVisibility
404 { return myVisibility[GR_POINT_NUMBER]; }
405 
406 inline GR_DecorVisibility
408 { return myVisibility[GR_POINT_NORMAL]; }
409 
410 inline GR_DecorVisibility
412 { return myVisibility[GR_POINT_UV]; }
413 
414 inline GR_DecorVisibility
416 { return myVisibility[GR_POINT_POSITION]; }
417 
418 inline GR_DecorVisibility
420 { return myVisibility[GR_POINT_VELOCITY]; }
421 
422 inline GR_DecorVisibility
424 { return myVisibility[GR_VERTEX_MARKER]; }
425 
426 inline GR_DecorVisibility
428 { return myVisibility[GR_VERTEX_NUMBER]; }
429 
430 inline GR_DecorVisibility
432 { return myVisibility[GR_VERTEX_NORMAL]; }
433 
434 inline GR_DecorVisibility
436 { return myVisibility[GR_VERTEX_UV]; }
437 
438 inline GR_DecorVisibility
440 { return myVisibility[GR_PRIM_NUMBER]; }
441 
442 inline GR_DecorVisibility
444 { return myVisibility[GR_PRIM_NORMAL]; }
445 
446 inline GR_DecorVisibility
448 { return myVisibility[GR_PRIM_BREAKPOINT]; }
449 
450 inline GR_DecorVisibility
452 {
453  if(d < GR_USER_DECORATION)
454  return myVisibility[d];
455 
457 }
458 
459 inline bool
461 {
462  return (myShadingMode == GR_BOUNDING_BOX_WIRE ||
463  myShadingMode == GR_BOUNDING_BOX_SHADED);
464 }
465 
466 inline bool
468 {
469  return myShadingMode == GR_HIDDEN_LINE_GHOST;
470 }
471 
472 inline bool
474 {
475  return myShadingMode == GR_WIRE_GHOST;
476 }
477 
478 inline int
480 {
481  if(myShadingMode >= GR_WIRE && myShadingMode <= GR_HIDDEN_LINE_GHOST)
482  return GR_DRAW_WIREFRAME;
483  else if(myShadingMode >= GR_FLAT_SHADED)
484  return GR_DRAW_SHADED;
485 
486  return 0; // no enum for bbox
487 }
488 
489 inline bool
491 {
492  return (myShadingMode == GR_WIRE_GHOST ||
493  myShadingMode == GR_HIDDEN_LINE_INVISIBLE ||
494  myShadingMode == GR_HIDDEN_LINE_GHOST);
495 }
496 
497 inline bool
499 {
500  return (myShadingMode == GR_FLAT_SHADED ||
501  myShadingMode == GR_FLAT_WIRE_SHADED);
502 }
503 
504 inline bool
506 {
507  return (myShadingMode == GR_SMOOTH_WIRE_SHADED ||
508  myShadingMode == GR_FLAT_WIRE_SHADED);
509 }
510 
511 
512 #endif
GLdouble s
Definition: glew.h:1390
void appliesToSelection(bool onoff)
bool wireOverShaded() const
#define ASSIGN_BUMP(flag)
void drawVertexMarkers(bool onoff)
bool drawProfNums() const
void drawFaded(bool onoff)
void drawPointMarkers(bool onoff)
GLuint const GLchar * name
Definition: glew.h:1814
void tintBackfaces(bool onoff)
const RE_LightList * getLightList() const
GLenum mode
Definition: glew.h:2163
bool flatShaded() const
void drawProfiles(bool onoff)
bool drawPointVelocity() const
void drawProfNums(bool onoff)
void toggleAffectsSet(bool onoff)
bool drawVertexNums() const
bool uvFillBackFaces() const
#define GR_DRAW_WIREFRAME
Definition: GR_Defines.h:18
int64 getUniqueID() const
void drawPointNums(bool onoff)
void drawVertexNmls(bool onoff)
GR_DecorVisibility pointVelocityVisible() const
void drawPrimHulls(bool onoff)
GR_DecorVisibility vertexNmlsVisible() const
void drawGhosted(bool onoff)
const GR_CommonDispOption & common() const
void drawVertexTxtNums(bool onoff)
const GLdouble * m
Definition: glew.h:9124
bool hlGhostFill() const
void setNonCachedDrawFlag() const
int getNumUserOptions() const
bool drawFaded() const
GR_Decoration
Definition: GR_Defines.h:142
GR_DecorVisibility vertexNumsVisible() const
void uvFillBackFaces(bool onoff)
bool drawXRay() const
bool wireHiddenLine() const
GR_DecorVisibility pointTxtNumsVisible() const
bool uvFillOverlap() const
bool drawVertexTxtNums() const
bool drawPointNums() const
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
void boundaryMode(GR_BoundaryMode mode)
bool drawGhosted() const
void uvBoundaryMode(GR_BoundaryMode mode)
void drawPointNmls(bool onoff)
bool drawProfiles() const
bool hlXray() const
bool drawPointMarkers() const
GR_DecorVisibility
Definition: GR_Defines.h:172
GR_CommonDispOption & common()
bool drawPrimBreakpoints() const
bool hasNonCachedDraw() const
GR_DecorVisibility pointMarkersVisible() const
void drawXRay(bool onoff)
bool tintBackfaces() const
void lockShadingMode(bool onoff)
bool drawVertexNmls() const
GR_ShadingMode
Definition: GR_Defines.h:29
int getDisplaySet() const
void drawVertexNums(bool onoff)
bool drawVertexMarkers() const
#define GR_API
Definition: GR_API.h:10
long long int64
Definition: SYS_Types.h:116
const GR_UserOption * getOption(int i) const
GR_DecorVisibility getVisibilityFor(GR_Decoration d) const
int getSerialNum() const
int getRefineSerial() const
GR_DecorVisibility primNumsVisible() const
bool drawPrimNums() const
void drawPointPos(bool onoff)
void drawPointVelocity(bool onoff)
GR_API GR_OptionTable * GRgetOptionTable()
bool drawPointNmls() const
void drawLit(bool onoff)
GT_API const UT_StringHolder version
void drawPrimBreakpoints(bool onoff)
void drawPrimNmls(bool onoff)
int getVisContext() const
bool drawPointPos() const
GR_BoundaryMode uvBoundaryMode() const
GR_DecorVisibility pointNumsVisible() const
void drawPointTxtNums(bool onoff)
void drawPrimNums(bool onoff)
bool toggleAffectsSet() const
GR_DecorVisibility getVisibility() const
Definition: GR_UserOption.h:79
void clearNonCachedDrawFlag() const
bool drawLit() const
bool boundBox() const
GR_DecorVisibility vertexMarkersVisible() const
GR_DecorVisibility primBreakpointsVisible() const
GR_BoundaryMode boundaryMode() const
bool drawPrimNmls() const
int drawMode() const
GR_DecorVisibility primNmlsVisible() const
bool hasEnabledUserOptions() const
bool drawPrimHulls() const
GR_BoundaryMode
Definition: GR_Defines.h:352
bool drawPointCoincident() const
bool isNonCachedPass() const
GR_DecorVisibility pointPosVisible() const
#define GR_DRAW_SHADED
Definition: GR_Defines.h:19
void uvFillOverlap(bool onoff)
GR_DecorVisibility pointNmlsVisible() const
GLdouble GLdouble t
Definition: glew.h:1398
bool appliesToSelection() const
void drawPointCoincident(bool onoff)
bool drawPointTxtNums() const
bool lockShadingMode() const
GR_DecorVisibility vertexTxtNumsVisible() const
void setNonCachedPass(bool nc_pass)
std::enable_if< internal::is_string< S >::value >::type print(std::basic_ostream< FMT_CHAR(S)> &os, const S &format_str, const Args &...args)
Definition: ostream.h:146