CFx SDK Documentation  2022 SP0
TrVisVisualStyle.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 // GLES2 device visual style definition
24 
25 #ifndef ODTRVISVISUALSTYLE
26 #define ODTRVISVISUALSTYLE
27 
28 #include "TD_PackPush.h"
29 
30 #include "Gi/GiVisualStyle.h"
31 #include "OdVector.h"
32 
33 #include "TrVisRenderMode.h"
34 
39 {
40  protected:
41  struct DataType
42  {
49 
51  : m_type(0), m_set(0), m_alloc(0), m_modified(0), m_reserve(0), m_num(0)
52  { }
53 
54  bool isPropSet() const { return m_alloc == 1; }
55  void setPropSet(bool bSet = true) { m_alloc = (bSet) ? 1 : 0; }
56 
57  bool isInherit() const { return m_set != 1; }
58  void setInherit(bool bSet) { m_set = (bSet) ? 0 : 1; }
59 
60  bool isModified() const { return m_modified == 1; }
61  void setModified(bool bSet) { m_modified = (bSet) ? 1 : 0; }
62 
65 
66  OdUInt32 getPropNumber() const { return m_num; }
67  void setPropNumber(OdUInt32 num) { m_num = num; }
68  } m_type;
69  union TypeData
70  {
71  bool m_boolVal;
74  double m_dblVal;
76 
78  : m_ptrVal(NULL)
79  { }
80 
81  bool getBool() const { return m_boolVal; }
82  void setBool(bool bVal) { m_boolVal = bVal; }
83 
84  OdInt32 getInt() const { return m_intVal; }
85  void setInt(OdInt32 iVal) { m_intVal = iVal; }
86 
87  OdUInt32 getUInt() const { return m_uintVal; }
88  void setUInt(OdUInt32 uVal) { m_uintVal = uVal; }
89 
90  double getDouble() const { return m_dblVal; }
91  void setDouble(double dVal) { m_dblVal = dVal; }
92 
93  const OdChar *getString() const { return m_ptrVal; }
94  void setString(const OdChar *pStr)
95  {
96  if (pStr)
97  {
98  OdUInt32 nLen = lclk(pStr);
99  OdChar *pNew = new OdChar[nLen + 1];
100  cstr(pNew, pStr, nLen); pNew[nLen] = 0;
101  m_ptrVal = pNew;
102  } else m_ptrVal = NULL;
103  }
104  void resetString()
105  {
106  if (m_ptrVal) { delete []m_ptrVal; m_ptrVal = NULL; }
107  }
108  bool cmpString(const OdChar *pStr) const
109  {
110  if (!m_ptrVal != !m_ptrVal) return false;
111  if (m_ptrVal)
112  {
113  const OdChar *pStrLeft = m_ptrVal;
114  while (*pStrLeft && *pStr)
115  {
116  if (*pStrLeft != *pStr)
117  return false;
118  pStrLeft++; pStr++;
119  }
120  return *pStrLeft == *pStr;
121  }
122  return true;
123  }
124  protected:
125  OdUInt32 lclk(const OdChar *pStr) const
126  {
127  if (!pStr) return 0;
128  OdUInt32 nLen = 0;
129  while (pStr[nLen]) nLen++;
130  return nLen;
131  }
132  void cstr(OdChar *pStr, const OdChar *pStr_, OdUInt32 nLen) const
133  {
134  for (OdUInt32 i = 0; i < nLen; i++)
135  pStr[i] = pStr_[i];
136  }
138  public:
140  {
144 
145  kColorRGB = 255
146  };
147  protected:
148  void blockExecution() const { throw OdError(eInvalidInput); }
150  bool hasString() const { return m_type.isPropSet() && (m_type.getType() == OdGiVariant::kString); }
153  {
154  if (!isValidType(type))
155  blockExecution();
156  if (!m_type.isPropSet())
157  {
159  m_type.setPropSet();
160  }
161  else if (type != m_type.getType())
162  blockExecution();
163  }
164  void checkType(const OdGiVariant::VariantType *pTypes, OdUInt32 nTypes) const
165  {
166  if (!m_type.isPropSet())
167  blockExecution();
168  for (OdUInt32 nType = 0; nType < nTypes; nType++)
169  {
170  if (m_type.getType() == pTypes[nType])
171  return;
172  }
173  blockExecution();
174  }
176  public:
180 
182  { reset(); copyFrom(from, from.operation()); return *this; }
183 
184  void setPropertyNumber(OdUInt32 propNum) { m_type.setPropNumber(propNum); }
186 
188 
189  void set(bool bVal, bool bSet = true)
190  {
192  m_data.setBool(bVal);
193  m_type.setInherit(!bSet);
194  }
195  void set(OdInt32 iVal, bool bSet = true)
196  {
198  m_data.setInt(iVal);
199  m_type.setInherit(!bSet);
200  }
201  void set(OdUInt32 uVal, bool bSet = true, bool bAsColor = false)
202  {
204  m_data.setUInt(uVal);
205  m_type.setInherit(!bSet);
206  }
207  void set(ODCOLORREF cVal, ColorType type, bool bSet = true)
208  {
210  m_data.setUInt(ODRGBA(ODGETRED(cVal), ODGETGREEN(cVal), ODGETBLUE(cVal), type));
211  m_type.setInherit(!bSet);
212  }
213  void set(double dVal, bool bSet = true)
214  {
216  m_data.setDouble(dVal);
217  m_type.setInherit(!bSet);
218  }
219  void set(const OdChar *sVal, bool bSet = true)
220  {
221  resetString();
223  m_data.setString(sVal);
224  m_type.setInherit(!bSet);
225  }
226  void set(const OdString &sVal, bool bSet = true) { set(sVal.c_str(), bSet); }
227  void set(const char *sVal, bool bSet = true) { set(OdString(sVal), bSet); }
228 
229  bool getBool() const
230  {
232  return m_data.getBool();
233  }
234  OdUInt8 getBoolAsInt() const { return (getBool()) ? 1 : 0; }
235  OdInt32 getInt() const
236  {
238  return m_data.getInt();
239  }
241  {
243  checkType(validTypes, sizeof(validTypes) / sizeof(OdGiVariant::VariantType));
244  return m_data.getUInt();
245  }
247  {
249  if (pType) *pType = (ColorType)ODGETALPHA(m_data.getUInt());
251  }
253  {
255  return (ColorType)ODGETALPHA(m_data.getUInt());
256  }
257  double getDouble() const
258  {
260  return m_data.getDouble();
261  }
262  const OdChar *getString() const
263  {
265  return m_data.getString();
266  }
267 
268  void setOperation(bool bSet) { m_type.setInherit(!bSet); }
269  bool operation() const { return !m_type.isInherit(); }
270 
271  void setFlag(OdUInt32 nFlag, bool bSet)
272  {
273  OdUInt32 flags = 0;
274  if (m_type.isPropSet()) flags = getUInt();
275  SETBIT(flags, nFlag, bSet);
276  set(flags);
277  }
278  bool getFlag(OdUInt32 nFlag) const
279  { return GETBIT(getUInt(), nFlag); }
280 
281  void setModified(bool bSet) { m_type.setModified(bSet); }
282  bool isModified() const { return m_type.isModified(); }
283 
284  void copyFrom(const OdTrVisVisualStyleProperty &from, bool bSet = true)
285  {
286  resetString();
287  setType(from.m_type.getType());
288  switch (from.m_type.getType())
289  {
290  case OdGiVariant::kBoolean: m_data.setBool(from.m_data.getBool()); break;
295  }
296  m_type.setInherit(!bSet);
297  m_type.setModified(from.isModified());
299  }
300 
301  void reset()
302  {
303  resetString();
305  m_type.setPropSet(false);
306  m_type.setInherit(true);
308  m_data.m_ptrVal = NULL;
309  }
310 
311  bool compare(const OdTrVisVisualStyleProperty &with, bool bCmpVal = true, bool bCmpOp = false, bool bCmpNum = false) const
312  {
313  if ((m_type.isPropSet() != with.m_type.isPropSet()) || (m_type.getType() != with.m_type.getType()))
314  return false;
315  if (bCmpVal)
316  {
317  switch (m_type.getType())
318  {
319  case OdGiVariant::kBoolean: if (m_data.getBool() != with.m_data.getBool()) return false; break;
320  case OdGiVariant::kInt: case OdGiVariant::kColor: if (m_data.getUInt() != with.m_data.getUInt()) return false; break;
321  case OdGiVariant::kDouble: if (!OdEqual(m_data.getDouble(), with.m_data.getDouble())) return false; break;
322  case OdGiVariant::kString: if (!m_data.cmpString(with.m_data.getString())) return false; break;
324  }
325  }
326  if (bCmpOp && (m_type.isInherit() != with.m_type.isInherit()))
327  return false;
328  if (bCmpNum && (m_type.getPropNumber() != with.m_type.getPropNumber()))
329  return false;
330  return true;
331  }
332  bool operator ==(const OdTrVisVisualStyleProperty &with) const { return compare(with); }
333  bool operator !=(const OdTrVisVisualStyleProperty &with) const { return !compare(with); }
334 };
335 
340 {
341  protected:
343  protected:
349  protected:
350  void checkLength(OdUInt32 nProp) const
351  {
352  if (m_props.size() <= nProp)
353  m_props.resize(nProp + 1);
354  }
355  void copyType(const OdTrVisVisualStyle &from)
356  {
357  m_type = from.m_type;
358  m_name = from.m_name;
359  m_bInternal = from.m_bInternal;
360  m_bTemporary = from.m_bTemporary;
361  }
362  struct PropCheck
363  {
365  static void lwd_mod(int& curExtension) { curExtension = (curExtension + 1) / 2; }
366  static void jitter_mod(int& curExtension)
367  {
368  switch (curExtension)
369  {
370  case OdGiVisualStyleProperties::kJitterLow: curExtension = 4; break;
371  case OdGiVisualStyleProperties::kJitterMedium: curExtension = 6; break;
372  case OdGiVisualStyleProperties::kJitterHigh: curExtension = 8; break;
373  }
374  }
375  static bool run(const OdTrVisVisualStyle &pVS, OdGiVisualStyleProperties::Property EdgeFlags, OdUInt32 EdgeFlag,
376  OdGiVisualStyleProperties::Property PropName, int minLimit, ModifierType modType, int &maxExtension)
377  {
378  if (pVS.property(EdgeFlags).getFlag(EdgeFlag))
379  {
380  int curExtension = (int)pVS.property(PropName).getInt();
381  if (curExtension > minLimit)
382  {
383  switch (modType)
384  {
385  case kLwdMod: lwd_mod(curExtension); break;
386  case kJitterMod: jitter_mod(curExtension); break;
387  default: break;
388  }
389  if (curExtension > maxExtension)
390  maxExtension = curExtension;
391  return true;
392  }
393  }
394  return false;
395  }
396  };
397  public:
399  : m_type(OdGiVisualStyle::kEmptyStyle)
400  , m_name()
401  , m_bInternal(false)
403  , m_props(0, 1)
404  { }
406  : m_type(OdGiVisualStyle::kEmptyStyle)
407  , m_name()
408  , m_bInternal(false)
410  , m_props(0, 1)
411  { copyFrom(from); }
413 
414  void copyFrom(const OdTrVisVisualStyle &from, bool bCopyType = true, bool bCopyDiff = false)
415  {
416  if (bCopyType)
417  copyType(from);
418  OdUInt32 nProps = from.m_props.size();
419  m_props.resize(nProps);
420  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
421  {
422  if (!bCopyDiff || (m_props[nProp] != from.m_props[nProp]))
423  m_props[nProp] = from.m_props[nProp];
424  }
425  }
426  void copyModified(const OdTrVisVisualStyle &from, bool bCopyType = true)
427  {
428  if (bCopyType)
429  copyType(from);
430  OdUInt32 nProps = from.m_props.size();
431  m_props.resize(nProps);
432  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
433  {
434  if (from.m_props[nProp].isModified())
435  {
436  m_props[nProp] = from.m_props[nProp];
437  m_props[nProp].setModified(false);
438  }
439  }
440  }
441 
442  OdTrVisVisualStyle &operator =(const OdTrVisVisualStyle &from) { copyFrom(from); return *this; }
443 
444  void setType(OdGiVisualStyle::Type tpy) { m_type = tpy; }
445  OdGiVisualStyle::Type type() const { return m_type; }
446 
447  void setName(const OdString &name) { m_name = name; }
448  const OdString &name() const { return m_name; }
449 
450  void setInternal(bool bSet) { m_bInternal = bSet; }
451  bool isInternal() const { return m_bInternal; }
452 
453  void setTemporary(bool bSet) { m_bTemporary = bSet; }
454  bool isTemporary() const { return m_bTemporary; }
455 
456  void setPropertiesNumber(OdUInt32 nProps) { m_props.resize(nProps); }
457  OdUInt32 numProperties() const { return m_props.size(); }
458 
460 
463 
464  bool compare(const OdTrVisVisualStyle &with, bool bCmpType = false, bool bCmpProps = true) const
465  {
466  if (bCmpType && ((m_type != with.m_type) ||
467  (m_name != with.m_name) ||
468  (m_bInternal != with.m_bInternal) ||
469  (m_bTemporary != with.m_bTemporary)))
470  return false;
471  if (bCmpProps)
472  {
473  if (m_props.size() != with.m_props.size())
474  return false;
475  const OdUInt32 nProps = m_props.size();
476  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
477  {
478  if (m_props[nProp] != with.m_props[nProp])
479  return false;
480  }
481  }
482  return true;
483  }
484  bool operator ==(const OdTrVisVisualStyle &with) const { return compare(with); }
485  bool operator !=(const OdTrVisVisualStyle &with) const { return !compare(with); }
486 
487  void resetModified(bool bSet = false)
488  {
489  const OdUInt32 nProps = m_props.size();
491  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
492  pProps[nProp].setModified(bSet);
493  }
495  {
496  OdUInt32 nModified = 0;
497  const OdUInt32 nProps = m_props.size();
498  const OdTrVisVisualStyleProperty *pProps = m_props.getPtr();
499  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
500  {
501  if (pProps[nProp].isModified())
502  nModified++;
503  }
504  return nModified;
505  }
506 
507  bool resolveInheritance(const OdTrVisVisualStyle &owner, OdUInt32 *nResolved = NULL, OdUInt32 *nUnresolved = NULL);
508  OdUInt32 countUnresolved() const;
509  bool backSubstitution(const OdTrVisVisualStyle &child, OdUInt32 *nSubstituted = NULL, OdUInt32 *nUnresolved = NULL);
510 
511  void computeRenderMode(OdTrVisRenderMode &pRM, bool bBestMatch = false) const;
512  int computeExtentsEnlargement() const;
513 };
514 
515 // Inlines section
516 
517 inline
519 {
520  if (nResolved) *nResolved = 0; if (nUnresolved) *nUnresolved = 0;
521  if (m_props.size() > owner.m_props.size())
522  return false;
523  const OdUInt32 nProps = m_props.size();
524  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
525  {
526  OdTrVisVisualStyleProperty &prop = m_props[nProp];
527  if (!prop.operation())
528  {
529  if (owner.m_props[nProp].operation())
530  {
531  prop = owner.m_props[nProp];
532  if (nResolved) (*nResolved)++;
533  }
534  else if (nUnresolved)
535  (*nUnresolved)++;
536  }
537  }
538  return true;
539 }
540 
541 inline
543 {
544  OdUInt32 nUnresolved = 0;
545  const OdUInt32 nProps = m_props.size();
546  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
547  {
548  if (!m_props[nProp].operation())
549  nUnresolved++;
550  }
551  return nUnresolved;
552 }
553 
554 inline
555 bool OdTrVisVisualStyle::backSubstitution(const OdTrVisVisualStyle &child, OdUInt32 *nSubstituted, OdUInt32 *nUnresolved)
556 {
557  const OdUInt32 nProps = odmax(m_props.size(), child.m_props.size());
558  for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
559  {
560  OdTrVisVisualStyleProperty &prop = child.m_props[nProp];
561  if (prop.operation())
562  {
563  m_props[nProp] = prop;
564  if (nSubstituted) (*nSubstituted)++;
565  }
566  else if (nUnresolved && !m_props[nProp].operation())
567  (*nUnresolved)++;
568  }
569  return true;
570 }
571 
572 inline
574 {
576  //pRM.setStencilBufferEnabled(property(OdGiVisualStyleProperties::kFaceColorMode).getInt() == OdGiVisualStyleProperties::kBackgroundColor);
579  // There are 4 places where lighting can be enabled/disable. Which is actually used by Acad?
580  //pRM.setLightingEnabled(property(OdGiVisualStyleProperties::kFaceLightingModel).getInt() != OdGiVisualStyleProperties::kInvisible);
581  //pRM.setLightingEnabled(property(OdGiVisualStyleProperties::kLightingEnabled).getBool());
584  pRM.calibrate();
585  if (bBestMatch)
586  {
589  pRM.setPolygonOffsetEnabled(true); // #CORE-11059
590  }
591 }
592 
593 inline
595 {
596  int maxExtension = 0;
597 
598  // Edges width flag
600  // Edges overhang
602  // Jitter effect
604  // Halo gap
606  // Silhouette
608  return maxExtension;
609 }
610 
611 #include "TD_PackPop.h"
612 
613 #endif // ODTRVISVISUALSTYLE
#define ODA_FAIL()
Definition: DebugStuff.h:65
false
Definition: DimVarDefs.h:165
#define NULL
Definition: GsProperties.h:177
#define ODGETBLUE(rgb)
Definition: OdPlatform.h:889
#define ODCOLORREF
Definition: OdPlatform.h:883
#define ODGETGREEN(rgb)
Definition: OdPlatform.h:888
#define odmax(X, Y)
Definition: OdPlatform.h:35
#define ODRGBA(r, g, b, a)
Definition: OdPlatform.h:885
#define ODGETALPHA(rgba)
Definition: OdPlatform.h:890
#define ODGETRED(rgb)
Definition: OdPlatform.h:887
unsigned int OdUInt32
int OdInt32
unsigned char OdUInt8
wchar_t OdChar
OdString OdString
Definition: OdString.h:1224
bool OdEqual(double x, double y, double tol=1.e-10)
Definition: OdaDefs.h:523
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:497
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
const OdChar * c_str() const
Definition: OdString.h:200
bool compare(const OdTrVisVisualStyle &with, bool bCmpType=false, bool bCmpProps=true) const
void setName(const OdString &name)
void setInternal(bool bSet)
OdTrVisVisualStyle(const OdTrVisVisualStyle &from)
void copyType(const OdTrVisVisualStyle &from)
void resetModified(bool bSet=false)
int computeExtentsEnlargement() const
OdGiVisualStyle::Type type() const
bool backSubstitution(const OdTrVisVisualStyle &child, OdUInt32 *nSubstituted=NULL, OdUInt32 *nUnresolved=NULL)
bool operator==(const OdTrVisVisualStyle &with) const
OdGiVisualStyle::Type m_type
OdUInt32 numProperties() const
void computeRenderMode(OdTrVisRenderMode &pRM, bool bBestMatch=false) const
void copyModified(const OdTrVisVisualStyle &from, bool bCopyType=true)
bool isTemporary() const
void copyFrom(const OdTrVisVisualStyle &from, bool bCopyType=true, bool bCopyDiff=false)
bool isInternal() const
void setPropertiesNumber(OdUInt32 nProps)
OdVector< OdTrVisVisualStyleProperty > PropsCont
void checkLength(OdUInt32 nProp) const
OdTrVisVisualStyleProperty & property(OdGiVisualStyleProperties::Property prop)
const OdString & name() const
OdUInt32 countUnresolved() const
void setTemporary(bool bSet)
void setType(OdGiVisualStyle::Type tpy)
OdUInt32 countModified() const
bool operator!=(const OdTrVisVisualStyle &with) const
bool resolveInheritance(const OdTrVisVisualStyle &owner, OdUInt32 *nResolved=NULL, OdUInt32 *nUnresolved=NULL)
const OdTrVisVisualStyleProperty & property(OdGiVisualStyleProperties::Property prop) const
OdTrVisVisualStyle & operator=(const OdTrVisVisualStyle &from)
void set(double dVal, bool bSet=true)
void set(const OdChar *sVal, bool bSet=true)
void checkType(const OdGiVariant::VariantType *pTypes, OdUInt32 nTypes) const
void set(OdInt32 iVal, bool bSet=true)
OdTrVisVisualStyleProperty(const OdTrVisVisualStyleProperty &from)
void setFlag(OdUInt32 nFlag, bool bSet)
bool compare(const OdTrVisVisualStyleProperty &with, bool bCmpVal=true, bool bCmpOp=false, bool bCmpNum=false) const
void copyFrom(const OdTrVisVisualStyleProperty &from, bool bSet=true)
OdUInt32 propertyNumber() const
struct OdTrVisVisualStyleProperty::DataType m_type
bool operator!=(const OdTrVisVisualStyleProperty &with) const
void set(OdUInt32 uVal, bool bSet=true, bool bAsColor=false)
void setPropertyNumber(OdUInt32 propNum)
union OdTrVisVisualStyleProperty::TypeData m_data
ColorType getColorType() const
const OdChar * getString() const
bool getFlag(OdUInt32 nFlag) const
void set(ODCOLORREF cVal, ColorType type, bool bSet=true)
void setType(OdGiVariant::VariantType type)
bool isValidType(OdGiVariant::VariantType type) const
bool operator==(const OdTrVisVisualStyleProperty &with) const
void set(bool bVal, bool bSet=true)
OdGiVariant::VariantType type() const
ODCOLORREF getColor(ColorType *pType=NULL) const
void set(const OdString &sVal, bool bSet=true)
OdTrVisVisualStyleProperty & operator=(const OdTrVisVisualStyleProperty &from)
void checkType(OdGiVariant::VariantType type) const
void set(const char *sVal, bool bSet=true)
void resize(size_type logicalLength, const T &value)
size_type size() const
Definition: OdVector.h:866
const T * asArrayPtr() const
Definition: OdVector.h:970
const T * getPtr() const
Definition: OdVector.h:976
OdVector & setPhysicalLength(size_type physicalLength)
Definition: OdVector.h:1141
GLuint const GLchar * name
Definition: gles2_ext.h:265
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
void setFaceNormalsEnabled(bool bSet)
void setStencilBufferEnabled(bool bSet)
void setLightingEnabled(bool bSet)
void setDepthBufferEnabled(bool bSet)
void setPolygonOffsetEnabled(bool bSet)
bool is_sh() const
static void lwd_mod(int &curExtension)
static bool run(const OdTrVisVisualStyle &pVS, OdGiVisualStyleProperties::Property EdgeFlags, OdUInt32 EdgeFlag, OdGiVisualStyleProperties::Property PropName, int minLimit, ModifierType modType, int &maxExtension)
static void jitter_mod(int &curExtension)
void setType(OdGiVariant::VariantType type)
OdGiVariant::VariantType getType() const
void cstr(OdChar *pStr, const OdChar *pStr_, OdUInt32 nLen) const
void setString(const OdChar *pStr)
bool cmpString(const OdChar *pStr) const
OdUInt32 lclk(const OdChar *pStr) const