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