CFx SDK Documentation  2022 SP0
GiFaceEdgeDataTraitsSaver.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 
24 #ifndef __ODGIFACEEDGEDATATRAITSSAVER_H__
25 #define __ODGIFACEEDGEDATATRAITSSAVER_H__
26 
27 #include "Gi/GiGeometry.h"
28 #include "Gi/GiCommonDraw.h"
29 #include "Gi/GiConveyorGeometry.h"
30 
31 // Uncomment to enable selection marker restore on exit
32 //#define EX_TRAITS_SELMARK_RESTORE
33 // Uncomment to enable onTraitsModified call on exit
34 //#define EX_TRAITS_TRAITSMOD_ONEXIT
35 // Uncomment to enable traits restoration on exit
36 #define EX_TRAITS_RESTORE_ONEXIT
37 
38 #ifdef EX_TRAITS_SELMARK_RESTORE
39 #include "Gi/GiPathNode.h"
40 #endif
41 
42 #ifdef EX_TRAITS_TRAITSMOD_ONEXIT
43 #define EX_TRAITS_TRAITSMOD_ONEXIT_SET() \
44  bModified = true
45 #else // EX_TRAITS_TRAITSMOD_ONEXIT
46 #define EX_TRAITS_TRAITSMOD_ONEXIT_SET()
47 #endif // EX_TRAITS_TRAITSMOD_ONEXIT
48 
49 #ifdef EX_TRAITS_RESTORE_ONEXIT
50 #define EX_TRAITS_SET(prevStorage, curStorage, param) \
51  prevStorage = curStorage = param
52 #define EX_TRAITS_DEFINE(type, prevStorage, curStorage) \
53  type prevStorage, curStorage
54 #define EX_TRAITS_DEFINE_PTR(type, prevStorage, curStorage) \
55  type prevStorage, *curStorage
56 #else // EX_TRAITS_RESTORE_ONEXIT
57 #define EX_TRAITS_SET(prevStorage, curStorage, param) \
58  curStorage = param
59 #define EX_TRAITS_DEFINE(type, prevStorage, curStorage) \
60  type curStorage
61 #define EX_TRAITS_DEFINE_PTR(type, prevStorage, curStorage) \
62  type curStorage
63 #ifdef EX_TRAITS_SELMARK_RESTORE
64 #undef EX_TRAITS_SELMARK_RESTORE
65 #endif // EX_TRAITS_SELMARK_RESTORE
66 #endif
67 
69 {
70  protected:
72  {
73  // LoWord - FaceTraits
74  kFaceColors = (1 << 0),
75  kFaceTrueColors = (1 << 1),
76  kFaceLayers = (1 << 2),
78  kFaceMaterials = (1 << 4),
79  kFaceMappers = (1 << 5),
80  kFaceTransparencies = (1 << 6),
81  kFaceVisibilities = (1 << 7),
82  kFaceSelMarkAvail = (1 << 8),
84  // HiWord - EdgeTraits
85  kEdgeColors = (1 << 16),
86  kEdgeTrueColors = (1 << 17),
87  kEdgeLayers = (1 << 18),
88  kEdgeLinetypes = (1 << 19),
89  kEdgeSelectionMarkers = (1 << 20),
90  kEdgeVisibilities = (1 << 21),
91  kEdgeSelMarkAvail = (1 << 22),
92  kEdgeSelMarkOnModify = (1 << 23),
93  // Masks
94  kFaceMask = 0x0000FFFF,
95  kEdgeMask = 0xFFFF0000,
96  // Mask used for restore traits state
97 #ifdef EX_TRAITS_SELMARK_RESTORE
100 #else
103 #endif
104  // Mask used for reset traits state
107  };
108  protected:
113  EX_TRAITS_DEFINE(OdCmEntityColor, m_prevTrueColor, m_curTrueColor);
114  EX_TRAITS_DEFINE_PTR(OdDbStub*, m_prevLayerId, m_curLayerId);
115 #ifdef EX_TRAITS_SELMARK_RESTORE
116  OdGsMarker m_prevSelectionMarker;
117 #endif // EX_TRAITS_SELMARK_RESTORE
118  protected:
120  : m_pTraits(pTraits), m_pDrawCtx(pDrawCtx), m_renderMode(renderMode), m_components(0)
121  {
122  }
123  // The default constructor will be used for virtual inheritance
126  {
127  }
128 
129  bool setColor(const OdUInt16* pColors, int index)
130  {
131  OdCmEntityColor trueColor; trueColor.setColorIndex(pColors[index]);
132  if (m_curTrueColor != trueColor)
133  {
134  m_curTrueColor = trueColor;
135  m_pTraits->setColor(pColors[index]);
136  return true;
137  }
138  return false;
139  }
140  bool setTrueColor(const OdCmEntityColor* pTrueColors, int index)
141  {
142  if (m_curTrueColor != pTrueColors[index])
143  {
144  m_pTraits->setTrueColor(m_curTrueColor = pTrueColors[index]);
145  return true;
146  }
147  return false;
148  }
149  bool setLayer(OdDbStub **pLayers, int index)
150  {
151  if (m_curLayerId != pLayers[index])
152  {
153  m_pTraits->setLayer(m_curLayerId = pLayers[index]);
154  return true;
155  }
156  return false;
157  }
158 
159  bool needExit() const { return m_renderMode != OdGsView::k2DOptimized; }
160 };
161 
163 {
164  protected:
166  EX_TRAITS_DEFINE_PTR(OdDbStub*, m_prevMaterialId, m_curMaterialId);
167  EX_TRAITS_DEFINE_PTR(const OdGiMapper*, m_prevMapper, m_curMapper);
168  EX_TRAITS_DEFINE( OdCmTransparency, m_prevTransparency, m_curTransparency);
169  public:
171  OdGsView::RenderMode renderMode, bool bForEdge = false)
172  : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode), m_pFaceData(pFaceData)
173  {
174  if (pFaceData && pTraits)
175  {
176  if (pFaceData->colors())
177  {
178  EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
180  }
181  if (pFaceData->trueColors())
182  {
183  EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
185  }
186  if (pFaceData->layerIds())
187  {
188  EX_TRAITS_SET(m_prevLayerId, m_curLayerId, pTraits->layer());
190  }
191  if (pFaceData->selectionMarkers())
192  {
193 #ifdef EX_TRAITS_SELMARK_RESTORE
194  if (pDrawCtx->currentGiPath())
195  {
196  m_prevSelectionMarker = pDrawCtx->currentGiPath()->selectionMarker();
198  }
199 #endif // EX_TRAITS_SELMARK_RESTORE
203  }
204  if (!bForEdge)
205  {
206  if (pFaceData->materials())
207  {
208  EX_TRAITS_SET(m_prevMaterialId, m_curMaterialId, pTraits->material());
210  }
211  if (pFaceData->mappers())
212  {
213  EX_TRAITS_SET(m_prevMapper, m_curMapper, pTraits->mapper());
214 #ifdef EX_TRAITS_RESTORE_ONEXIT
215  // Mapper can point onto internal storage which is similar always, we need store data itself
216  if (m_prevMapper) m_prevMapper = new OdGiMapper(*m_curMapper);
217 #endif // EX_TRAITS_RESTORE_ONEXIT
219  }
220  }
221  if (pFaceData->transparency())
222  {
223  EX_TRAITS_SET(m_prevTransparency, m_curTransparency, pTraits->transparency());
225  }
226  if (pFaceData->visibility())
228  }
229  }
230 
231 #ifdef EX_TRAITS_RESTORE_ONEXIT
232  bool onExit()
233  {
234  bool bModified = false;
236  {
237  if (GETBIT(m_components, kFaceColors | kFaceTrueColors) && (m_prevTrueColor != m_curTrueColor))
238  {
239  m_pTraits->setTrueColor(m_prevTrueColor);
241  }
242  if (GETBIT(m_components, kFaceLayers) && (m_prevLayerId != m_curLayerId))
243  {
244  m_pTraits->setLayer(m_prevLayerId);
246  }
247 #ifdef EX_TRAITS_SELMARK_RESTORE
249  {
250  m_pTraits->setSelectionMarker(m_prevSelectionMarker);
253  }
254 #endif // EX_TRAITS_SELMARK_RESTORE
255  if (GETBIT(m_components, kFaceMaterials) && (m_prevMaterialId != m_curMaterialId))
256  {
257  m_pTraits->setMaterial(m_prevMaterialId);
259  }
261  { // If mappers is specified them will be different always
262  m_pTraits->setMapper(m_prevMapper);
263  if (m_prevMapper) delete m_prevMapper;
265  }
266  if (GETBIT(m_components, kFaceTransparencies) && (m_prevTransparency != m_curTransparency))
267  {
268  m_pTraits->setTransparency(m_prevTransparency);
270  }
271  }
272  return bModified;
273  }
274  bool needExit() const
275  {
277  {
278  if (GETBIT(m_components, kFaceMappers) && m_prevMapper)
279  delete m_prevMapper;
280  return false;
281  }
282  return true;
283  }
285  {
286  if (needExit() && onExit())
288  }
289 #endif // EX_TRAITS_RESTORE_ONEXIT
290 
291  bool setFaceTraits(int faceIndex)
292  {
293  if (!(m_components & kFaceMask))
294  return true;
295 
298 
300  return false;
301 
303  {
304  bool bModified = GETBIT(m_components, kFaceSelMarkOnModify);
306  bModified |= setColor(m_pFaceData->colors(), faceIndex);
308  bModified |= setTrueColor(m_pFaceData->trueColors(), faceIndex);
310  bModified |= setLayer(m_pFaceData->layerIds(), faceIndex);
312  {
313  OdDbStub **pMaterials = m_pFaceData->materials();
314  if (m_curMaterialId != pMaterials[faceIndex])
315  {
316  m_pTraits->setMaterial(m_curMaterialId = pMaterials[faceIndex]);
317  bModified = true;
318  }
319  }
321  {
322  const OdGiMapper* pMappers = m_pFaceData->mappers();
323  m_pTraits->setMapper(m_curMapper = (pMappers + faceIndex));
324  bModified = true;
325  }
327  {
328  const OdCmTransparency* pTransparencies = m_pFaceData->transparency();
329  if (m_curTransparency != pTransparencies[faceIndex])
330  {
331  m_pTraits->setTransparency(m_curTransparency = pTransparencies[faceIndex]);
332  bModified = true;
333  }
334  }
336  {
337  if (bModified)
339  return true;
340  }
341  else
342  return false;
343  }
344 
345  return m_pDrawCtx->effectivelyVisible();
346  }
347 
348  bool hasData() const { return (m_components & kFaceMask) != 0; }
349 };
350 
352 {
353  protected:
355  EX_TRAITS_DEFINE_PTR(OdDbStub*, m_prevLinetypeId, m_curLinetypeId);
356  public:
358  OdGsView::RenderMode renderMode, bool bFaceChk = false)
359  : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode), m_pEdgeData(pEdgeData)
360  {
361  if (pEdgeData && pTraits)
362  {
363  if (pEdgeData->colors())
364  {
365  if (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors))
366  EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
368  }
369  if (pEdgeData->trueColors())
370  {
371  if (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors))
372  EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
374  }
375  if (pEdgeData->layerIds())
376  {
377  if (!bFaceChk || !GETBIT(m_components, kFaceLayers))
378  EX_TRAITS_SET(m_prevLayerId, m_curLayerId, pTraits->layer());
380  }
381  if (pEdgeData->linetypeIds())
382  {
383  EX_TRAITS_SET(m_prevLinetypeId, m_curLinetypeId, pTraits->lineType());
385  }
386  if (pEdgeData->selectionMarkers())
387  {
388 #ifdef EX_TRAITS_SELMARK_RESTORE
389  if ((!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers)) && pDrawCtx->currentGiPath())
390  {
391  m_prevSelectionMarker = pDrawCtx->currentGiPath()->selectionMarker();
393  }
394 #endif // EX_TRAITS_SELMARK_RESTORE
396  if (!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers))
397  {
400  }
403  }
404  if (pEdgeData->visibility())
406  }
407  }
408 
409 #ifdef EX_TRAITS_RESTORE_ONEXIT
410  bool onExit(bool bFaceChk = false)
411  {
412  bool bModified = false;
414  {
416  (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors)) && (m_prevTrueColor != m_curTrueColor))
417  {
418  m_pTraits->setTrueColor(m_prevTrueColor);
420  }
422  (!bFaceChk || !GETBIT(m_components, kFaceLayers)) && (m_prevLayerId != m_curLayerId))
423  {
424  m_pTraits->setLayer(m_prevLayerId);
426  }
427  if (GETBIT(m_components, kEdgeLinetypes) && (m_prevLinetypeId != m_curLinetypeId))
428  {
429  m_pTraits->setLineType(m_prevLinetypeId);
431  }
432 #ifdef EX_TRAITS_SELMARK_RESTORE
434  (!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers)))
435  {
436  m_pTraits->setSelectionMarker(m_prevSelectionMarker);
439  }
440 #endif // EX_TRAITS_SELMARK_RESTORE
441  }
442  return bModified;
443  }
445  {
446  if (needExit() && onExit())
448  }
449 #endif // EX_TRAITS_RESTORE_ONEXIT
450 
451  bool setEdgeTraits(int edgeIndex)
452  {
453  if (!(m_components & kEdgeMask))
454  return true;
455 
458 
460  return false;
461 
463  {
464  bool bModified = GETBIT(m_components, kEdgeSelMarkOnModify);
466  bModified |= setColor(m_pEdgeData->colors(), edgeIndex);
468  bModified |= setTrueColor(m_pEdgeData->trueColors(), edgeIndex);
470  bModified |= setLayer(m_pEdgeData->layerIds(), edgeIndex);
472  {
473  OdDbStub **pLinetypes = m_pEdgeData->linetypeIds();
474  if (m_curLinetypeId != pLinetypes[edgeIndex])
475  {
476  m_pTraits->setLineType(m_curLinetypeId = pLinetypes[edgeIndex]);
477  bModified = true;
478  }
479  }
481  {
482  if (bModified)
484  return true;
485  }
486  else
487  return false;
488  }
489 
490  return m_pDrawCtx->effectivelyVisible();
491  }
492 
493  bool hasData() const { return (m_components & kEdgeMask) != 0; }
494 };
495 
497 {
498  public:
499  OdGiFaceEdgeDataTraitsSaver(const OdGiFaceData *pFaceData, const OdGiEdgeData *pEdgeData,
500  OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx,
501  OdGsView::RenderMode renderMode)
502  : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode)
503  , OdGiFaceDataTraitsSaver(pFaceData, pTraits, pDrawCtx, renderMode, true)
504  , OdGiEdgeDataTraitsSaver(pEdgeData, pTraits, pDrawCtx, renderMode, true)
505  {
506  }
507 #ifdef EX_TRAITS_RESTORE_ONEXIT
509  {
511  {
512  bool bModified = OdGiFaceDataTraitsSaver::onExit();
513  bModified |= OdGiEdgeDataTraitsSaver::onExit(true);
514  if (bModified)
516  }
517  m_components = 0; // Avoid redundant operations in base class destructors
518  }
519 #endif
520 
521  bool hasData() const { return m_components != 0; }
522 };
523 
524 #endif // __ODGIFACEEDGEDATATRAITSSAVER_H__
true
Definition: DimVarDefs.h:2046
@ kOdGiInvisible
Definition: Gi.h:47
#define EX_TRAITS_TRAITSMOD_ONEXIT_SET()
#define EX_TRAITS_SET(prevStorage, curStorage, param)
#define NULL
Definition: GsProperties.h:177
ptrdiff_t OdGsMarker
unsigned int OdUInt32
unsigned short OdUInt16
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
#define SETBIT_1(flags, bit)
Definition: OdaDefs.h:501
void setColorIndex(OdInt16 colorIndex)
Definition: CmColorBase.h:321
virtual OdUInt32 drawContextFlags() const
virtual bool effectivelyVisible() const
virtual void onTraitsModified()=0
virtual const OdGiPathNode * currentGiPath() const =0
OdDbStub ** layerIds() const
Definition: GiGeometry.h:195
OdDbStub ** linetypeIds() const
Definition: GiGeometry.h:204
const OdGsMarker * selectionMarkers() const
Definition: GiGeometry.h:213
const OdCmEntityColor * trueColors() const
Definition: GiGeometry.h:186
const OdUInt16 * colors() const
Definition: GiGeometry.h:177
const OdUInt8 * visibility() const
Definition: GiGeometry.h:232
bool onExit(bool bFaceChk=false)
OdGiEdgeDataTraitsSaver(const OdGiEdgeData *pEdgeData, OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx, OdGsView::RenderMode renderMode, bool bFaceChk=false)
EX_TRAITS_DEFINE_PTR(OdDbStub *, m_prevLinetypeId, m_curLinetypeId)
const OdUInt8 * visibility() const
Definition: GiGeometry.h:477
const OdCmEntityColor * trueColors() const
Definition: GiGeometry.h:432
OdDbStub ** materials() const
Definition: GiGeometry.h:486
const OdUInt16 * colors() const
Definition: GiGeometry.h:423
const OdGiMapper * mappers() const
Definition: GiGeometry.h:495
const OdGsMarker * selectionMarkers() const
Definition: GiGeometry.h:450
const OdCmTransparency * transparency() const
Definition: GiGeometry.h:504
OdDbStub ** layerIds() const
Definition: GiGeometry.h:441
OdGiFaceDataTraitsSaver(const OdGiFaceData *pFaceData, OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx, OdGsView::RenderMode renderMode, bool bForEdge=false)
EX_TRAITS_DEFINE_PTR(OdDbStub *, m_prevMaterialId, m_curMaterialId)
EX_TRAITS_DEFINE(OdCmTransparency, m_prevTransparency, m_curTransparency)
EX_TRAITS_DEFINE_PTR(const OdGiMapper *, m_prevMapper, m_curMapper)
EX_TRAITS_DEFINE_PTR(OdDbStub *, m_prevLayerId, m_curLayerId)
bool setLayer(OdDbStub **pLayers, int index)
bool setColor(const OdUInt16 *pColors, int index)
EX_TRAITS_DEFINE(OdCmEntityColor, m_prevTrueColor, m_curTrueColor)
OdGiFaceEdgeDataTraitsSaverBase(OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx, OdGsView::RenderMode renderMode)
bool setTrueColor(const OdCmEntityColor *pTrueColors, int index)
OdGiFaceEdgeDataTraitsSaver(const OdGiFaceData *pFaceData, const OdGiEdgeData *pEdgeData, OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx, OdGsView::RenderMode renderMode)
virtual OdGsMarker selectionMarker() const =0
virtual void setLayer(OdDbStub *layerId)=0
virtual OdDbStub * layer() const =0
virtual void setLineType(OdDbStub *lineTypeId)=0
virtual OdDbStub * material() const =0
virtual void setMapper(const OdGiMapper *pMapper)=0
virtual OdDbStub * lineType() const =0
virtual void setSelectionMarker(OdGsMarker selectionMarker)=0
virtual void setColor(OdUInt16 color)=0
virtual OdCmTransparency transparency() const
virtual void setTrueColor(const OdCmEntityColor &color)=0
virtual OdCmEntityColor trueColor() const =0
virtual void setMaterial(OdDbStub *materialId)=0
virtual const OdGiMapper * mapper() const =0
virtual void setTransparency(const OdCmTransparency &transparency)
Definition: Gs.h:133
RenderMode
Definition: Gs.h:138
@ k2DOptimized
Definition: Gs.h:140
GLuint index
Definition: gles2_ext.h:265
@ k2DOptimized
Definition: ViewportDefs.h:47