CFx SDK Documentation 2026 SP0
Loading...
Searching...
No Matches
GiFaceEdgeDataTraitsSaver.h
Go to the documentation of this file.
1
2// Copyright (C) 2002-2024, 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-2024 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"
31#define STL_USING_MAP
32#include "OdaSTL.h"
33
34// Uncomment to enable selection marker restore on exit
35//#define EX_TRAITS_SELMARK_RESTORE
36// Uncomment to enable onTraitsModified call on exit
37//#define EX_TRAITS_TRAITSMOD_ONEXIT
38// Uncomment to enable traits restoration on exit
39#define EX_TRAITS_RESTORE_ONEXIT
40
41#ifdef EX_TRAITS_SELMARK_RESTORE
42#include "Gi/GiPathNode.h"
43#endif
44
45#ifdef EX_TRAITS_TRAITSMOD_ONEXIT
46#define EX_TRAITS_TRAITSMOD_ONEXIT_SET() \
47 bModified = true
48#else // EX_TRAITS_TRAITSMOD_ONEXIT
49#define EX_TRAITS_TRAITSMOD_ONEXIT_SET()
50#endif // EX_TRAITS_TRAITSMOD_ONEXIT
51
52#ifdef EX_TRAITS_RESTORE_ONEXIT
53#define EX_TRAITS_SET(prevStorage, curStorage, param) \
54 prevStorage = curStorage = param
55#define EX_TRAITS_DEFINE(type, prevStorage, curStorage) \
56 type prevStorage, curStorage
57#define EX_TRAITS_DEFINE_PTR(type, prevStorage, curStorage) \
58 type prevStorage, *curStorage
59#else // EX_TRAITS_RESTORE_ONEXIT
60#define EX_TRAITS_SET(prevStorage, curStorage, param) \
61 curStorage = param
62#define EX_TRAITS_DEFINE(type, prevStorage, curStorage) \
63 type curStorage
64#define EX_TRAITS_DEFINE_PTR(type, prevStorage, curStorage) \
65 type curStorage
66#ifdef EX_TRAITS_SELMARK_RESTORE
67#undef EX_TRAITS_SELMARK_RESTORE
68#endif // EX_TRAITS_SELMARK_RESTORE
69#endif
70
72{
73 protected:
75 {
76 // LoWord - FaceTraits
77 kFaceColors = (1 << 0),
78 kFaceTrueColors = (1 << 1),
79 kFaceLayers = (1 << 2),
81 kFaceMaterials = (1 << 4),
82 kFaceMappers = (1 << 5),
87 // HiWord - EdgeTraits
88 kEdgeColors = (1 << 16),
89 kEdgeTrueColors = (1 << 17),
90 kEdgeLayers = (1 << 18),
91 kEdgeLinetypes = (1 << 19),
93 kEdgeVisibilities = (1 << 21),
94 kEdgeSelMarkAvail = (1 << 22),
96 // Masks
97 kFaceMask = 0x0000FFFF,
98 kEdgeMask = 0xFFFF0000,
99 // Mask used for restore traits state
100#ifdef EX_TRAITS_SELMARK_RESTORE
103#else
106#endif
107 // Mask used for reset traits state
110 };
111 protected:
116 //SEA
118 std::map< OdDbStub*, bool > m_layersByBlock;
119 bool isDefaultLayer( OdDbStub* layerId )
120 {
121 std::map< OdDbStub*, bool >::iterator it = m_layersByBlock.find( layerId );
122 if( it != m_layersByBlock.end() ) return it->second;
123 OdGiDrawablePtr pDr = m_pDrawCtx->giContext().openDrawable( layerId );
124 if( pDr.isNull() )
125 {
126 m_layersByBlock[ layerId ] = false;
127 return false;
128 }
130 OdUInt32 flgs = pDr->setAttributes( static_cast<OdGiLayerTraits*>(&taker) );
132 return GETBIT( flgs, OdGiLayerTraits::kByBlock );
133 }
134 EX_TRAITS_DEFINE(OdCmEntityColor, m_prevTrueColor, m_curTrueColor);
135 EX_TRAITS_DEFINE_PTR(OdDbStub*, m_prevLayerId, m_curLayerId);
136#ifdef EX_TRAITS_SELMARK_RESTORE
137 OdGsMarker m_prevSelectionMarker;
138#endif // EX_TRAITS_SELMARK_RESTORE
139 protected:
141 : m_pTraits(pTraits), m_pDrawCtx(pDrawCtx), m_renderMode(renderMode), m_components(0), m_prevLayerId(NULL), m_curLayerId(NULL)
142 {
143 m_defaultLayerId = m_pTraits->layer();
144 }
145 // The default constructor will be used for virtual inheritance
147 : m_pTraits(NULL), m_pDrawCtx(NULL), m_renderMode(OdGsView::k2DOptimized), m_components(0), m_prevLayerId(NULL), m_curLayerId(NULL)
148 {
149 m_defaultLayerId = NULL;
150 }
151
152 bool setColor(const OdUInt16* pColors, int index)
153 {
154 OdCmEntityColor trueColor; trueColor.setColorIndex(pColors[index]);
155 if (m_curTrueColor != trueColor)
156 {
157 m_curTrueColor = trueColor;
158 m_pTraits->setColor(pColors[index]);
159 return true;
160 }
161 return false;
162 }
163 bool setTrueColor(const OdCmEntityColor* pTrueColors, int index)
164 {
165 if (m_curTrueColor != pTrueColors[index])
166 {
167 m_pTraits->setTrueColor(m_curTrueColor = pTrueColors[index]);
168 return true;
169 }
170 return false;
171 }
172 bool setLayer(OdDbStub **pLayers, int index)
173 {
174 if (m_curLayerId != pLayers[index])
175 {
176 if( !isDefaultLayer( pLayers[index] ) || !m_defaultLayerId )
177 m_pTraits->setLayer(m_curLayerId = pLayers[index]);
178 else if( m_curLayerId != m_defaultLayerId )
179 {
180 m_pTraits->setLayer(m_curLayerId = m_defaultLayerId);
181 }
182 return true;
183 }
184 return false;
185 }
186
187 bool needExit() const { return m_renderMode != OdGsView::k2DOptimized; }
188};
189
191{
192 protected:
194 EX_TRAITS_DEFINE_PTR(OdDbStub*, m_prevMaterialId, m_curMaterialId);
195 EX_TRAITS_DEFINE_PTR(const OdGiMapper*, m_prevMapper, m_curMapper);
196 EX_TRAITS_DEFINE( OdCmTransparency, m_prevTransparency, m_curTransparency);
197 public:
199 OdGsView::RenderMode renderMode, bool bForEdge = false, bool ignoreFaceVisibilities = false)
200 : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode), m_pFaceData(pFaceData), m_prevMaterialId(NULL), m_curMaterialId(NULL), m_prevMapper(NULL), m_curMapper(NULL)
201 {
202 if (pFaceData && pTraits)
203 {
204 if (pFaceData->colors())
205 {
206 EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
208 }
209 if (pFaceData->trueColors())
210 {
211 EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
213 }
214 if (pFaceData->layerIds())
215 {
216 EX_TRAITS_SET(m_prevLayerId, m_curLayerId, pTraits->layer());
218 }
219 if (pFaceData->selectionMarkers())
220 {
221#ifdef EX_TRAITS_SELMARK_RESTORE
222 if (pDrawCtx->currentGiPath())
223 {
224 m_prevSelectionMarker = pDrawCtx->currentGiPath()->selectionMarker();
226 }
227#endif // EX_TRAITS_SELMARK_RESTORE
231 }
232 if (!bForEdge)
233 {
234 if (pFaceData->materials())
235 {
236 EX_TRAITS_SET(m_prevMaterialId, m_curMaterialId, pTraits->material());
238 }
239 if (pFaceData->mappers())
240 {
241 EX_TRAITS_SET(m_prevMapper, m_curMapper, pTraits->mapper());
242#ifdef EX_TRAITS_RESTORE_ONEXIT
243 // Mapper can point onto internal storage which is similar always, we need store data itself
244 if (m_prevMapper) m_prevMapper = new OdGiMapper(*m_curMapper);
245#endif // EX_TRAITS_RESTORE_ONEXIT
247 }
248 }
249 if (pFaceData->transparency())
250 {
251 EX_TRAITS_SET(m_prevTransparency, m_curTransparency, pTraits->transparency());
253 }
254 if (pFaceData->visibility() && !ignoreFaceVisibilities)
256 }
257 }
258
259#ifdef EX_TRAITS_RESTORE_ONEXIT
260 bool onExit()
261 {
262 bool bModified = false;
264 {
265 if (GETBIT(m_components, kFaceColors | kFaceTrueColors) && (m_prevTrueColor != m_curTrueColor))
266 {
267 m_pTraits->setTrueColor(m_prevTrueColor);
269 }
270 if (GETBIT(m_components, kFaceLayers) && (m_prevLayerId != m_curLayerId))
271 {
272 m_pTraits->setLayer(m_prevLayerId);
274 }
275#ifdef EX_TRAITS_SELMARK_RESTORE
277 {
278 m_pTraits->setSelectionMarker(m_prevSelectionMarker);
281 }
282#endif // EX_TRAITS_SELMARK_RESTORE
283 if (GETBIT(m_components, kFaceMaterials) && (m_prevMaterialId != m_curMaterialId))
284 {
285 m_pTraits->setMaterial(m_prevMaterialId);
287 }
289 { // If mappers is specified them will be different always
290 m_pTraits->setMapper(m_prevMapper);
291 if (m_prevMapper) delete m_prevMapper;
293 }
294 if (GETBIT(m_components, kFaceTransparencies) && (m_prevTransparency != m_curTransparency))
295 {
296 m_pTraits->setTransparency(m_prevTransparency);
298 }
299 }
300 return bModified;
301 }
302 bool needExit() const
303 {
305 {
306 if (GETBIT(m_components, kFaceMappers) && m_prevMapper)
307 delete m_prevMapper;
308 return false;
309 }
310 return true;
311 }
313 {
314 if (needExit() && onExit())
315 m_pDrawCtx->onTraitsModified();
316 }
317#endif // EX_TRAITS_RESTORE_ONEXIT
318
319 bool setFaceTraits(int faceIndex)
320 {
321 if (!(m_components & kFaceMask))
322 return true;
323
325 m_pTraits->setSelectionMarker(m_pFaceData->selectionMarkers()[faceIndex]);
326
327 if (GETBIT(m_components, kFaceVisibilities) && (m_pFaceData->visibility()[faceIndex] == kOdGiInvisible))
328 return false;
329
331 {
332 bool bModified = GETBIT(m_components, kFaceSelMarkOnModify);
334 bModified |= setColor(m_pFaceData->colors(), faceIndex);
336 bModified |= setTrueColor(m_pFaceData->trueColors(), faceIndex);
338 bModified |= setLayer(m_pFaceData->layerIds(), faceIndex);
340 {
341 OdDbStub **pMaterials = m_pFaceData->materials();
342 if (m_curMaterialId != pMaterials[faceIndex])
343 {
344 m_pTraits->setMaterial(m_curMaterialId = pMaterials[faceIndex]);
345 bModified = true;
346 }
347 }
349 {
350 const OdGiMapper* pMappers = m_pFaceData->mappers();
351 m_pTraits->setMapper(m_curMapper = (pMappers + faceIndex));
352 bModified = true;
353 }
355 {
356 const OdCmTransparency* pTransparencies = m_pFaceData->transparency();
357 if (m_curTransparency != pTransparencies[faceIndex])
358 {
359 m_pTraits->setTransparency(m_curTransparency = pTransparencies[faceIndex]);
360 bModified = true;
361 }
362 }
363 if (m_pDrawCtx->effectivelyVisible())
364 {
365 if (bModified)
366 m_pDrawCtx->onTraitsModified();
367 return true;
368 }
369 else
370 return false;
371 }
372
373 return m_pDrawCtx->effectivelyVisible();
374 }
375
376 bool hasData() const { return (m_components & kFaceMask) != 0; }
377};
378
380{
381 protected:
383 EX_TRAITS_DEFINE_PTR(OdDbStub*, m_prevLinetypeId, m_curLinetypeId);
384 public:
386 OdGsView::RenderMode renderMode, bool bFaceChk = false)
387 : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode)
388 , m_pEdgeData(pEdgeData), m_prevLinetypeId(nullptr), m_curLinetypeId(nullptr)
389 {
390 if (pEdgeData && pTraits)
391 {
392 if (pEdgeData->colors())
393 {
394 if (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors))
395 EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
397 }
398 if (pEdgeData->trueColors())
399 {
400 if (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors))
401 EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
403 }
404 if (pEdgeData->layerIds())
405 {
406 if (!bFaceChk || !GETBIT(m_components, kFaceLayers))
407 EX_TRAITS_SET(m_prevLayerId, m_curLayerId, pTraits->layer());
409 }
410 if (pEdgeData->linetypeIds())
411 {
412 EX_TRAITS_SET(m_prevLinetypeId, m_curLinetypeId, pTraits->lineType());
414 }
415 if (pEdgeData->selectionMarkers())
416 {
417#ifdef EX_TRAITS_SELMARK_RESTORE
418 if ((!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers)) && pDrawCtx->currentGiPath())
419 {
420 m_prevSelectionMarker = pDrawCtx->currentGiPath()->selectionMarker();
422 }
423#endif // EX_TRAITS_SELMARK_RESTORE
425 if (!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers))
426 {
429 }
432 }
433 if (pEdgeData->visibility())
435 }
436 }
437
438#ifdef EX_TRAITS_RESTORE_ONEXIT
439 bool onExit(bool bFaceChk = false)
440 {
441 bool bModified = false;
443 {
445 (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors)) && (m_prevTrueColor != m_curTrueColor))
446 {
447 m_pTraits->setTrueColor(m_prevTrueColor);
449 }
451 (!bFaceChk || !GETBIT(m_components, kFaceLayers)) && (m_prevLayerId != m_curLayerId))
452 {
453 m_pTraits->setLayer(m_prevLayerId);
455 }
456 if (GETBIT(m_components, kEdgeLinetypes) && (m_prevLinetypeId != m_curLinetypeId))
457 {
458 m_pTraits->setLineType(m_prevLinetypeId);
460 }
461#ifdef EX_TRAITS_SELMARK_RESTORE
463 (!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers)))
464 {
465 m_pTraits->setSelectionMarker(m_prevSelectionMarker);
468 }
469#endif // EX_TRAITS_SELMARK_RESTORE
470 }
471 return bModified;
472 }
474 {
475 if (needExit() && onExit())
476 m_pDrawCtx->onTraitsModified();
477 }
478#endif // EX_TRAITS_RESTORE_ONEXIT
479
480 bool setEdgeTraits(int edgeIndex)
481 {
482 if (!(m_components & kEdgeMask))
483 return true;
484
486 m_pTraits->setSelectionMarker(m_pEdgeData->selectionMarkers()[edgeIndex]);
487
488 if (GETBIT(m_components, kEdgeVisibilities) && (m_pEdgeData->visibility()[edgeIndex] == kOdGiInvisible))
489 return false;
490
492 {
493 bool bModified = GETBIT(m_components, kEdgeSelMarkOnModify);
495 bModified |= setColor(m_pEdgeData->colors(), edgeIndex);
497 bModified |= setTrueColor(m_pEdgeData->trueColors(), edgeIndex);
499 bModified |= setLayer(m_pEdgeData->layerIds(), edgeIndex);
501 {
502 OdDbStub **pLinetypes = m_pEdgeData->linetypeIds();
503 if (m_curLinetypeId != pLinetypes[edgeIndex])
504 {
505 m_pTraits->setLineType(m_curLinetypeId = pLinetypes[edgeIndex]);
506 bModified = true;
507 }
508 }
509 if (m_pDrawCtx->effectivelyVisible())
510 {
511 if (bModified)
512 m_pDrawCtx->onTraitsModified();
513 return true;
514 }
515 else
516 return false;
517 }
518
519 return m_pDrawCtx->effectivelyVisible();
520 }
521
522 bool hasData() const { return (m_components & kEdgeMask) != 0; }
523};
524
526{
527 public:
528 OdGiFaceEdgeDataTraitsSaver(const OdGiFaceData *pFaceData, const OdGiEdgeData *pEdgeData,
529 OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx,
530 OdGsView::RenderMode renderMode)
531 : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode)
532 , OdGiFaceDataTraitsSaver(pFaceData, pTraits, pDrawCtx, renderMode, true, true)
533 , OdGiEdgeDataTraitsSaver(pEdgeData, pTraits, pDrawCtx, renderMode, true)
534 {
535 }
536#ifdef EX_TRAITS_RESTORE_ONEXIT
538 {
540 {
541 bool bModified = OdGiFaceDataTraitsSaver::onExit();
542 bModified |= OdGiEdgeDataTraitsSaver::onExit(true);
543 if (bModified)
544 m_pDrawCtx->onTraitsModified();
545 }
546 m_components = 0; // Avoid redundant operations in base class destructors
547 }
548#endif
549
550 bool hasData() const { return m_components != 0; }
551};
552
553#endif // __ODGIFACEEDGEDATATRAITSSAVER_H__
true
@ kOdGiInvisible
Definition Gi.h:55
OdSmartPtr< OdGiDrawable > OdGiDrawablePtr
#define EX_TRAITS_TRAITSMOD_ONEXIT_SET()
#define EX_TRAITS_SET(prevStorage, curStorage, param)
ptrdiff_t OdGsMarker
unsigned int OdUInt32
unsigned short OdUInt16
#define GETBIT(flags, bit)
Definition OdaDefs.h:517
#define SETBIT_1(flags, bit)
Definition OdaDefs.h:520
bool isNull() const
void setColorIndex(OdInt16 colorIndex)
virtual OdUInt32 drawContextFlags() const
virtual const OdGiPathNode * currentGiPath() const =0
ODRX_SEALED_VIRTUAL OdUInt32 setAttributes(OdGiDrawableTraits *pTraits) const ODRX_FINAL
OdDbStub ** linetypeIds() const
Definition GiGeometry.h:230
const OdUInt16 * colors() const
Definition GiGeometry.h:190
const OdCmEntityColor * trueColors() const
Definition GiGeometry.h:203
const OdGsMarker * selectionMarkers() const
Definition GiGeometry.h:242
OdDbStub ** layerIds() const
Definition GiGeometry.h:216
const OdUInt8 * visibility() const
Definition GiGeometry.h:265
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 OdUInt16 * colors() const
Definition GiGeometry.h:518
const OdCmEntityColor * trueColors() const
Definition GiGeometry.h:531
const OdGiMapper * mappers() const
Definition GiGeometry.h:612
const OdUInt8 * visibility() const
Definition GiGeometry.h:586
const OdGsMarker * selectionMarkers() const
Definition GiGeometry.h:555
const OdCmTransparency * transparency() const
Definition GiGeometry.h:627
OdDbStub ** materials() const
Definition GiGeometry.h:599
OdDbStub ** layerIds() const
Definition GiGeometry.h:544
OdGiFaceDataTraitsSaver(const OdGiFaceData *pFaceData, OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx, OdGsView::RenderMode renderMode, bool bForEdge=false, bool ignoreFaceVisibilities=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)
std::map< OdDbStub *, bool > m_layersByBlock
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 OdDbStub * material() const =0
virtual OdCmTransparency transparency() const
virtual const OdGiMapper * mapper() const =0
virtual OdCmEntityColor trueColor() const =0
virtual OdDbStub * layer() const =0
virtual OdDbStub * lineType() const =0
Definition Gs.h:141
RenderMode
Definition Gs.h:149
@ k2DOptimized
Definition Gs.h:151
GLuint index
Definition gles2_ext.h:265