CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
GiFaceEdgeDataTraitsSaver.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
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
101 kFaceRestoreMask = kFaceMask & ~kFaceVisibilities,
102 kEdgeRestoreMask = kEdgeMask & ~kEdgeVisibilities,
103#else
106#endif
107 // Mask used for reset traits state
108 kFaceSetMask = kFaceMask & ~kFaceVisibilities,
109 kEdgeSetMask = kEdgeMask & ~kEdgeVisibilities
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;
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)
142 {
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)
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)
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())
316 }
317#endif // EX_TRAITS_RESTORE_ONEXIT
318
319 bool setFaceTraits(int faceIndex)
320 {
321 if (!(m_components & kFaceMask))
322 return true;
323
326
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 }
364 {
365 if (bModified)
367 return true;
368 }
369 else
370 return false;
371 }
372
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), m_pEdgeData(pEdgeData)
388 {
389 if (pEdgeData && pTraits)
390 {
391 if (pEdgeData->colors())
392 {
393 if (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors))
394 EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
396 }
397 if (pEdgeData->trueColors())
398 {
399 if (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors))
400 EX_TRAITS_SET(m_prevTrueColor, m_curTrueColor, pTraits->trueColor());
402 }
403 if (pEdgeData->layerIds())
404 {
405 if (!bFaceChk || !GETBIT(m_components, kFaceLayers))
406 EX_TRAITS_SET(m_prevLayerId, m_curLayerId, pTraits->layer());
408 }
409 if (pEdgeData->linetypeIds())
410 {
411 EX_TRAITS_SET(m_prevLinetypeId, m_curLinetypeId, pTraits->lineType());
413 }
414 if (pEdgeData->selectionMarkers())
415 {
416#ifdef EX_TRAITS_SELMARK_RESTORE
417 if ((!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers)) && pDrawCtx->currentGiPath())
418 {
419 m_prevSelectionMarker = pDrawCtx->currentGiPath()->selectionMarker();
421 }
422#endif // EX_TRAITS_SELMARK_RESTORE
424 if (!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers))
425 {
428 }
431 }
432 if (pEdgeData->visibility())
434 }
435 }
436
437#ifdef EX_TRAITS_RESTORE_ONEXIT
438 bool onExit(bool bFaceChk = false)
439 {
440 bool bModified = false;
442 {
444 (!bFaceChk || !GETBIT(m_components, kFaceColors | kFaceTrueColors)) && (m_prevTrueColor != m_curTrueColor))
445 {
446 m_pTraits->setTrueColor(m_prevTrueColor);
448 }
450 (!bFaceChk || !GETBIT(m_components, kFaceLayers)) && (m_prevLayerId != m_curLayerId))
451 {
452 m_pTraits->setLayer(m_prevLayerId);
454 }
455 if (GETBIT(m_components, kEdgeLinetypes) && (m_prevLinetypeId != m_curLinetypeId))
456 {
457 m_pTraits->setLineType(m_prevLinetypeId);
459 }
460#ifdef EX_TRAITS_SELMARK_RESTORE
462 (!bFaceChk || !GETBIT(m_components, kFaceSelectionMarkers)))
463 {
464 m_pTraits->setSelectionMarker(m_prevSelectionMarker);
467 }
468#endif // EX_TRAITS_SELMARK_RESTORE
469 }
470 return bModified;
471 }
473 {
474 if (needExit() && onExit())
476 }
477#endif // EX_TRAITS_RESTORE_ONEXIT
478
479 bool setEdgeTraits(int edgeIndex)
480 {
481 if (!(m_components & kEdgeMask))
482 return true;
483
486
488 return false;
489
491 {
492 bool bModified = GETBIT(m_components, kEdgeSelMarkOnModify);
494 bModified |= setColor(m_pEdgeData->colors(), edgeIndex);
496 bModified |= setTrueColor(m_pEdgeData->trueColors(), edgeIndex);
498 bModified |= setLayer(m_pEdgeData->layerIds(), edgeIndex);
500 {
501 OdDbStub **pLinetypes = m_pEdgeData->linetypeIds();
502 if (m_curLinetypeId != pLinetypes[edgeIndex])
503 {
504 m_pTraits->setLineType(m_curLinetypeId = pLinetypes[edgeIndex]);
505 bModified = true;
506 }
507 }
509 {
510 if (bModified)
512 return true;
513 }
514 else
515 return false;
516 }
517
519 }
520
521 bool hasData() const { return (m_components & kEdgeMask) != 0; }
522};
523
525{
526 public:
527 OdGiFaceEdgeDataTraitsSaver(const OdGiFaceData *pFaceData, const OdGiEdgeData *pEdgeData,
528 OdGiSubEntityTraits *pTraits, OdGiConveyorContext *pDrawCtx,
529 OdGsView::RenderMode renderMode)
530 : OdGiFaceEdgeDataTraitsSaverBase(pTraits, pDrawCtx, renderMode)
531 , OdGiFaceDataTraitsSaver(pFaceData, pTraits, pDrawCtx, renderMode, true, true)
532 , OdGiEdgeDataTraitsSaver(pEdgeData, pTraits, pDrawCtx, renderMode, true)
533 {
534 }
535#ifdef EX_TRAITS_RESTORE_ONEXIT
537 {
539 {
540 bool bModified = OdGiFaceDataTraitsSaver::onExit();
541 bModified |= OdGiEdgeDataTraitsSaver::onExit(true);
542 if (bModified)
544 }
545 m_components = 0; // Avoid redundant operations in base class destructors
546 }
547#endif
548
549 bool hasData() const { return m_components != 0; }
550};
551
552#endif // __ODGIFACEEDGEDATATRAITSSAVER_H__
true
Definition: DimVarDefs.h:2046
@ kOdGiInvisible
Definition: Gi.h:49
#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
Definition: BaseObjectPtr.h:86
void setColorIndex(OdInt16 colorIndex)
Definition: CmColorBase.h:372
virtual OdGiDrawablePtr openDrawable(OdDbStub *drawableId)=0
virtual OdGiContext & giContext() const =0
virtual OdUInt32 drawContextFlags() const
virtual bool effectivelyVisible() const
virtual const OdGiPathNode * currentGiPath() const =0
virtual void onTraitsModified()=0
ODRX_SEALED_VIRTUAL OdUInt32 setAttributes(OdGiDrawableTraits *pTraits) const ODRX_SEALED
OdDbStub ** linetypeIds() const
Definition: GiGeometry.h:226
const OdUInt16 * colors() const
Definition: GiGeometry.h:186
const OdCmEntityColor * trueColors() const
Definition: GiGeometry.h:199
const OdGsMarker * selectionMarkers() const
Definition: GiGeometry.h:238
OdDbStub ** layerIds() const
Definition: GiGeometry.h:212
const OdUInt8 * visibility() const
Definition: GiGeometry.h:260
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:469
const OdCmEntityColor * trueColors() const
Definition: GiGeometry.h:482
const OdGiMapper * mappers() const
Definition: GiGeometry.h:563
const OdUInt8 * visibility() const
Definition: GiGeometry.h:537
const OdGsMarker * selectionMarkers() const
Definition: GiGeometry.h:506
const OdCmTransparency * transparency() const
Definition: GiGeometry.h:578
OdDbStub ** materials() const
Definition: GiGeometry.h:550
OdDbStub ** layerIds() const
Definition: GiGeometry.h:495
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 void setLayer(OdDbStub *layerId)=0
virtual OdDbStub * material() const =0
virtual void setLineType(OdDbStub *lineTypeId)=0
virtual void setMapper(const OdGiMapper *pMapper)=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 const OdGiMapper * mapper() const =0
virtual OdCmEntityColor trueColor() const =0
virtual OdDbStub * layer() const =0
virtual OdDbStub * lineType() const =0
virtual void setMaterial(OdDbStub *materialId)=0
virtual void setTransparency(const OdCmTransparency &transparency)
Definition: Gs.h:140
RenderMode
Definition: Gs.h:148
@ k2DOptimized
Definition: Gs.h:150
GLuint index
Definition: gles2_ext.h:265