CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
TrVisVisualStyle.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2022, 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 Open Design Alliance software pursuant to a license
16// agreement with Open Design Alliance.
17// Open Design Alliance Copyright (C) 2002-2022 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; }
70 {
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 }
105 {
106 if (m_ptrVal) { delete []m_ptrVal; m_ptrVal = NULL; }
107 }
108 bool cmpString(const OdChar *pStr) const
109 {
110 if (!m_ptrVal != !pStr) 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))
156 if (!m_type.isPropSet())
157 {
160 }
161 else if (type != m_type.getType())
163 }
164 void checkType(const OdGiVariant::VariantType *pTypes, OdUInt32 nTypes) const
165 {
166 if (!m_type.isPropSet())
168 for (OdUInt32 nType = 0; nType < nTypes; nType++)
169 {
170 if (m_type.getType() == pTypes[nType])
171 return;
172 }
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; }
236 {
238 return m_data.getInt();
239 }
241 {
243 checkType(validTypes, sizeof(validTypes) / sizeof(OdGiVariant::VariantType));
244 return m_data.getUInt();
245 }
246 ODCOLORREF getColor(ColorType *pType = NULL) const
247 {
249 if (pType) *pType = (ColorType)ODGETALPHA(m_data.getUInt());
251 }
253 {
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 {
295 }
296 m_type.setInherit(!bSet);
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:
344 protected:
345 void checkLength(OdUInt32 nProp) const
346 {
347 if (m_props.size() <= nProp)
348 m_props.resize(nProp + 1);
349 }
351 {
353 static void lwd_mod(int& curExtension) { curExtension = (curExtension + 1) / 2; }
354 static void jitter_mod(int& curExtension)
355 {
356 switch (curExtension)
357 {
358 case OdGiVisualStyleProperties::kJitterLow: curExtension = 4; break;
359 case OdGiVisualStyleProperties::kJitterMedium: curExtension = 6; break;
360 case OdGiVisualStyleProperties::kJitterHigh: curExtension = 8; break;
361 }
362 }
363 static bool run(const OdTrVisVisualStyle &pVS, OdGiVisualStyleProperties::Property EdgeFlags, OdUInt32 EdgeFlag,
364 OdGiVisualStyleProperties::Property PropName, int minLimit, ModifierType modType, int &maxExtension)
365 {
366 if (pVS.property(EdgeFlags).getFlag(EdgeFlag))
367 {
368 int curExtension = (int)pVS.property(PropName).getInt();
369 if (curExtension > minLimit)
370 {
371 switch (modType)
372 {
373 case kLwdMod: lwd_mod(curExtension); break;
374 case kJitterMod: jitter_mod(curExtension); break;
375 default: break;
376 }
377 if (curExtension > maxExtension)
378 maxExtension = curExtension;
379 return true;
380 }
381 }
382 return false;
383 }
384 };
385 public:
387 : m_props(0, 1)
388 { }
390 : m_props(0, 1)
391 { copyFrom(from); }
393
394 void copyFrom(const OdTrVisVisualStyle &from, bool bCopyDiff = false)
395 {
396 OdUInt32 nProps = from.m_props.size();
397 m_props.resize(nProps);
398 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
399 {
400 if (!bCopyDiff || (m_props[nProp] != from.m_props[nProp]))
401 m_props[nProp] = from.m_props[nProp];
402 }
403 }
405 {
406 OdUInt32 nProps = from.m_props.size();
407 m_props.resize(nProps);
408 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
409 {
410 if (from.m_props[nProp].isModified())
411 {
412 m_props[nProp] = from.m_props[nProp];
413 m_props[nProp].setModified(false);
414 }
415 }
416 }
417
418 OdTrVisVisualStyle &operator =(const OdTrVisVisualStyle &from) { copyFrom(from); return *this; }
419
420 void setPropertiesNumber(OdUInt32 nProps) { m_props.resize(nProps); }
421 OdUInt32 numProperties() const { return m_props.size(); }
422
424
427
428 bool compare(const OdTrVisVisualStyle &with) const
429 {
430 if (m_props.size() != with.m_props.size())
431 return false;
432 const OdUInt32 nProps = m_props.size();
433 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
434 {
435 if (m_props[nProp] != with.m_props[nProp])
436 return false;
437 }
438 return true;
439 }
440 bool operator ==(const OdTrVisVisualStyle &with) const { return compare(with); }
441 bool operator !=(const OdTrVisVisualStyle &with) const { return !compare(with); }
442
443 void resetModified(bool bSet = false)
444 {
445 const OdUInt32 nProps = m_props.size();
447 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
448 pProps[nProp].setModified(bSet);
449 }
451 {
452 OdUInt32 nModified = 0;
453 const OdUInt32 nProps = m_props.size();
454 const OdTrVisVisualStyleProperty *pProps = m_props.getPtr();
455 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
456 {
457 if (pProps[nProp].isModified())
458 nModified++;
459 }
460 return nModified;
461 }
462
463 bool resolveInheritance(const OdTrVisVisualStyle &owner, OdUInt32 *nResolved = NULL, OdUInt32 *nUnresolved = NULL);
465 bool backSubstitution(const OdTrVisVisualStyle &child, OdUInt32 *nSubstituted = NULL, OdUInt32 *nUnresolved = NULL);
466
467 void computeRenderMode(OdTrVisRenderMode &pRM, bool bBestMatch = false) const;
468 int computeExtentsEnlargement() const;
469};
470
471// Inlines section
472
473inline
475{
476 if (nResolved) *nResolved = 0; if (nUnresolved) *nUnresolved = 0;
477 if (m_props.size() > owner.m_props.size())
478 return false;
479 const OdUInt32 nProps = m_props.size();
480 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
481 {
482 OdTrVisVisualStyleProperty &prop = m_props[nProp];
483 if (!prop.operation())
484 {
485 if (owner.m_props[nProp].operation())
486 {
487 prop = owner.m_props[nProp];
488 if (nResolved) (*nResolved)++;
489 }
490 else if (nUnresolved)
491 (*nUnresolved)++;
492 }
493 }
494 return true;
495}
496
497inline
499{
500 OdUInt32 nUnresolved = 0;
501 const OdUInt32 nProps = m_props.size();
502 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
503 {
504 if (!m_props[nProp].operation())
505 nUnresolved++;
506 }
507 return nUnresolved;
508}
509
510inline
511bool OdTrVisVisualStyle::backSubstitution(const OdTrVisVisualStyle &child, OdUInt32 *nSubstituted, OdUInt32 *nUnresolved)
512{
513 const OdUInt32 nProps = odmax(m_props.size(), child.m_props.size());
514 for (OdUInt32 nProp = 0; nProp < nProps; nProp++)
515 {
516 OdTrVisVisualStyleProperty &prop = child.m_props[nProp];
517 if (prop.operation())
518 {
519 m_props[nProp] = prop;
520 if (nSubstituted) (*nSubstituted)++;
521 }
522 else if (nUnresolved && !m_props[nProp].operation())
523 (*nUnresolved)++;
524 }
525 return true;
526}
527
528inline
530{
532 //pRM.setStencilBufferEnabled(property(OdGiVisualStyleProperties::kFaceColorMode).getInt() == OdGiVisualStyleProperties::kBackgroundColor);
535 // There are 4 places where lighting can be enabled/disable. Which is actually used by Acad?
536 //pRM.setLightingEnabled(property(OdGiVisualStyleProperties::kFaceLightingModel).getInt() != OdGiVisualStyleProperties::kInvisible);
537 //pRM.setLightingEnabled(property(OdGiVisualStyleProperties::kLightingEnabled).getBool());
540 pRM.calibrate();
541 if (bBestMatch)
542 {
545 pRM.setPolygonOffsetEnabled(true); // #CORE-11059
547 pRM.setDepthBufferEnabled(true), pRM.setStencilBufferEnabled(true); // #VIS-654
548 }
549}
550
551inline
553{
554 int maxExtension = 0;
555
556 // Edges width flag
558 // Edges overhang
560 // Jitter effect
562 // Halo gap
564 // Silhouette
566 return maxExtension;
567}
568
569#include "TD_PackPop.h"
570
571#endif // ODTRVISVISUALSTYLE
#define ODA_FAIL()
Definition: DebugStuff.h:88
#define ODGETBLUE(rgb)
Definition: OdPlatform.h:939
#define ODCOLORREF
Definition: OdPlatform.h:933
#define ODGETGREEN(rgb)
Definition: OdPlatform.h:938
#define odmax(X, Y)
Definition: OdPlatform.h:35
#define ODRGBA(r, g, b, a)
Definition: OdPlatform.h:935
#define ODGETALPHA(rgba)
Definition: OdPlatform.h:940
#define ODGETRED(rgb)
Definition: OdPlatform.h:937
unsigned int OdUInt32
int OdInt32
unsigned char OdUInt8
wchar_t OdChar
bool OdEqual(double x, double y, double tol=1.e-10)
Definition: OdaDefs.h:542
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:516
#define GETBIT(flags, bit)
Definition: OdaDefs.h:517
const OdChar * c_str() const
Definition: OdString.h:203
const OdTrVisVisualStyleProperty & property(OdGiVisualStyleProperties::Property prop) const
void copyModified(const OdTrVisVisualStyle &from)
OdTrVisVisualStyle(const OdTrVisVisualStyle &from)
void resetModified(bool bSet=false)
OdTrVisVisualStyle & operator=(const OdTrVisVisualStyle &from)
int computeExtentsEnlargement() const
bool backSubstitution(const OdTrVisVisualStyle &child, OdUInt32 *nSubstituted=NULL, OdUInt32 *nUnresolved=NULL)
bool operator==(const OdTrVisVisualStyle &with) const
void copyFrom(const OdTrVisVisualStyle &from, bool bCopyDiff=false)
OdUInt32 numProperties() const
OdTrVisVisualStyleProperty & property(OdGiVisualStyleProperties::Property prop)
void computeRenderMode(OdTrVisRenderMode &pRM, bool bBestMatch=false) const
bool compare(const OdTrVisVisualStyle &with) const
void setPropertiesNumber(OdUInt32 nProps)
OdVector< OdTrVisVisualStyleProperty > PropsCont
void checkLength(OdUInt32 nProp) const
OdUInt32 countUnresolved() const
OdUInt32 countModified() const
bool operator!=(const OdTrVisVisualStyle &with) const
bool resolveInheritance(const OdTrVisVisualStyle &owner, OdUInt32 *nResolved=NULL, OdUInt32 *nUnresolved=NULL)
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
OdTrVisVisualStyleProperty & operator=(const OdTrVisVisualStyleProperty &from)
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
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)
const OdChar * getString() const
void checkType(OdGiVariant::VariantType type) const
void set(const char *sVal, bool bSet=true)
void resize(size_type logicalLength, const T &value)
Definition: OdVector.h:1166
size_type size() const
Definition: OdVector.h:1204
const T * asArrayPtr() const
Definition: OdVector.h:1350
const T * getPtr() const
Definition: OdVector.h:1356
OdVector & setPhysicalLength(size_type physicalLength)
Definition: OdVector.h:1540
GLuint GLsizei GLsizei GLint GLenum * type
Definition: gles2_ext.h:274
void setFaceNormalsEnabled(bool bSet)
void setStencilBufferEnabled(bool bSet)
bool is_2d() const
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