CFx SDK Documentation  2022 SP0
GsContainerNode.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 __OD_GS_CONTAINER_NODE__
25 #define __OD_GS_CONTAINER_NODE__
26 
27 #include "TD_PackPush.h"
28 
29 #include "Gs/GsNode.h"
30 #include "Gs/GsDrawableHolder.h"
31 #include "Si/SiSpatialIndex.h"
32 #include "OdVector.h"
33 #include "ThreadsCounter.h"
34 
35 class OdGsEntityNode;
36 class OdGsLightNode;
37 class OdGsBlockNode;
38 
47 {
48 protected:
49  enum
50  {
51  kEntityListValid = OdGsNode::kLastFlag << 1,
52  kCheckWorkset = OdGsNode::kLastFlag << 2,
53  kHasStockData = OdGsNode::kLastFlag << 3,
54  kVpDepCache = OdGsNode::kLastFlag << 4,
55  kLastFlag = kVpDepCache
56  };
57 
58  enum
59  {
60  kChildrenNotUpToDate = 0x80000000 //special flag to use in setChildrenUpToDate/childrenUpToDate
61  //per each viewport, flags are stored in m_vpAwareFlags
62  };
63 
65 
67  {
70  LightsList m_lightPtrs; // some of the lights are entities (ones that lies in model space)
73  int m_nChild;
77  OdGsUpdateExtents m_realExtents; //Keeps real extents (for EXTMIN/MAX support)
79 
80  enum
81  {
83  kVpDepCache = OdGsContainerNode::kVpDepCache
84  };
85 
86  VpData();
87  static OdSmartPtr<VpData> createObject(bool bShareable = false);
88  };
91 
92  inline VpData *getVpData(OdUInt32 nVpId, bool bCreateIfNotFound = true) const;
93  VpData *makeVpData(OdUInt32 nVpId) const;
94  inline OdUInt32 vpDataId(const VpData *pVpData) const;
95 public:
96  inline bool hasVpData(OdUInt32 nVpId) const;
97  inline OdUInt32 numVpData() const;
99  void setEntityListsInvalid();
100  OdUInt32 viewportId(const OdGsViewImpl &pView, bool bForceVpId = true) const;
101  inline bool isVpDepCache() const;
102 public:
111  void setEntityListValid(OdUInt32 nVpId, bool entityListValid);
112 
119  bool childrenUpToDate(OdUInt32 nVpId) const;
120 
125  bool needRegen(OdUInt32 nVpId) const;
126 
128 
130  virtual ENodeType nodeType() const { return kContainerNode; }
131 
136  virtual void displayEntityList(OdGsDisplayContext& ctx);
137 
142  OdGsEntityNode* firstEntityNode(OdUInt32 nVpId);
147  const OdGsEntityNode* firstEntityNode(OdUInt32 nVpId) const;
152  OdGsEntityNode* lastEntityNode(OdUInt32 nVpId);
157  const OdGsEntityNode* lastEntityNode(OdUInt32 nVpId) const;
162  OdList<OdGsLightNode*> &lightNodesList(OdUInt32 nVpId);
167  const OdList<OdGsLightNode*> &lightNodesList(OdUInt32 nVpId) const;
168 
210  OdUInt32 awareFlags(OdUInt32 viewportId) const;
211 
254  void setAwareFlags(OdUInt32 viewportId, OdUInt32 flags);
255 
256 protected:
257  virtual void propagateLayerChanges(OdGsViewImpl& view);
258  bool saveVpData(OdGsFiler *pFiler, const VpData *pVpData) const;
259  bool loadVpData(OdGsFiler *pFiler, VpData *pVpData);
260 
261 public:
263 
268  OdGsContainerNode(OdGsBaseModel* pModel, const OdGiDrawable* pUnderlyingDrawable, bool bSetGsNode = true);
270 
277  bool entityListValid(OdUInt32 nVpId) const;
278  bool allEntityListsValid() const;
279  bool isEmpty() const;
280 
288  void setChildrenUpToDate(bool childrenUpToDate, const OdUInt32* nVpID = NULL);
289  bool childrenRegenDraw(OdUInt32 nVpID) const;
290  void setChildrenRegenDraw(bool bVal, OdUInt32 nVpID);
291 
297  virtual void addChild(const OdGiDrawable* pDrawable, OdGsViewImpl *pView, bool unerased = false);
298 
299  /* \details
300  Adds information about the light if the light doesn't have gsNode yet.
301  \param ctx [in] Current update context.
302  \param pDrawable [in] Pointer to the Drawable object.
303  */
304  virtual void addLight(OdGsUpdateContext& ctx, const OdGiDrawable* pDrawable);
305  /* \details
306  Removes information about the light added through addLight method.
307  \param pOwner [in] gsNode of the owner entity.
308  \param nVpId [in] Optional Viewport ID.
309  */
310  virtual void removeLights(OdGsNode *pOwner, OdUInt32 nVpId = 0xFFFFFFFF);
311 
316  virtual void removeChild(OdGsNode* pNode);
317 
318  void update(OdGsUpdateContext& ctx, OdGsContainerNode* pParent, OdSiSpatialIndex* pParentIndex);
319 
320  void updateVisible( OdGsViewImpl* pViewImpl );
321 
322  void display(OdGsDisplayContext& ctx);
323 
328  OdSiSpatialIndex& spatialIndex(OdUInt32 nVpId);
333  const OdSiSpatialIndex& spatialIndex(OdUInt32 nVpId) const;
334 
339 
344 
349  bool extents(OdGeExtents3d& extents) const;
350 
355  virtual bool extents(const OdGsView* pView, OdGeExtents3d& ext) const;
356 
361 
362  bool checkWorkset() const;
363  void setCheckWorkset(bool bVal);
364 
365  virtual bool updateEntityList(OdGsUpdateContext& ctx);
366 
367  virtual void updateEntities(OdGsUpdateContext& ctx);
368 
370 
378  bool highlightSubnodes(OdUInt32 nSubnodes, bool bHighlight, bool bAll);
379 
380  void destroy();
381 
383 
388  inline const OdGsUpdateExtents& realExtents(OdUInt32 nVpId) const;
389 
396  inline void setRealExtents(OdUInt32 nVpId, const OdGsUpdateExtents& ext);
397 
398  inline void addViewRef(OdUInt32 nVpId);
399  inline void removeViewRef(OdUInt32 nVpId);
400  inline const ViewRefs& viewRefs() const;
401 
402  inline const StockProps& stock() const;
403  void makeStock();
404  void releaseStock();
406 
407  bool saveNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer = NULL) const;
408  bool loadNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer = NULL);
410 
411  bool safeEntityUpdate(OdGsEntityNode* pEntity, OdGsUpdateContext& ctx, OdSiSpatialIndex* pSpatialIndex);
412  void addEntProps(const OdGsUpdateContext& ctx);
413  bool doMTUpdate(OdGsUpdateContext& ctx);
414  void doSTUpdate(OdGsUpdateContext& ctx);
415 
419  void removeErased();
420 
425  inline int numberOfChildren(OdUInt32 nVpId) const;
426  inline OdUInt32 numberOfChildrenST(OdUInt32 nVpId) const;
427  inline OdUInt32 numberOfChildrenErased(OdUInt32 nVpId) const;
428 protected:
431  OdUInt32Vector m_vpAwareFlags; //this memory is never shared, no need in OdArray with refcounter on buffer
435 public:
436  void addContentToUpdateManager( OdUInt32 viewportId, OdGsUpdateManager* pManager, const UpdateManagerContext& context );
437 };
438 
439 inline OdGsContainerNode::VpData *OdGsContainerNode::getVpData(OdUInt32 nVpId, bool bCreateIfNotFound) const
440 {
441  if (!GETBIT(m_flags, kVpDepCache))
442  return m_shareableData;
443  VpData *pVpData = (m_vpData.size() > nVpId) ? m_vpData[nVpId].get() : NULL;
444  if (!pVpData && bCreateIfNotFound)
445  return makeVpData(nVpId);
446  return pVpData;
447 }
448 
449 inline OdUInt32 OdGsContainerNode::vpDataId(const VpData *pVpData) const
450 {
451  if (GETBIT(m_flags, kVpDepCache))
452  {
453  const OdUInt32 nVpData = m_vpData.size();
454  const VpDataPtr *pVpDataPtr = m_vpData.getPtr();
455  for (OdUInt32 nVpId = 0; nVpId < nVpData; nVpId++)
456  {
457  if (pVpDataPtr[nVpId].get() == pVpData)
458  return nVpId;
459  }
460  }
461  return 0;
462 }
463 
464 inline bool OdGsContainerNode::hasVpData(OdUInt32 nVpId) const
465 {
466  if (!GETBIT(m_flags, kVpDepCache))
467  return true;
468  return ((m_vpData.size() > nVpId) && !m_vpData.getAt(nVpId).isNull());
469 }
470 
472 {
473  if (!GETBIT(m_flags, kVpDepCache))
474  return 1;
475  return m_vpData.size();
476 }
477 
479 {
480  return GETBIT(m_flags, kVpDepCache);
481 }
482 
484 {
485  if (!isVpDepCache())
487  const VpData *pVpData = getVpData(nVpId, false);
488  if (pVpData)
489  return GETBIT(pVpData->m_flags, kEntityListValid);
490  return false;
491 }
492 
494 {
496 }
497 
498 inline bool OdGsContainerNode::isEmpty() const
499 {
500  const OdUInt32 nVpData = numVpData();
501  for (OdUInt32 nView = 0; nView < nVpData; nView++)
502  {
503  const VpData *pVpData = getVpData(nView, false);
504  if (pVpData && pVpData->m_pFirstEntity)
505  return false;
506  }
507  return true;
508 }
509 
511 {
512  for (OdUInt32 nView = 0; nView < numVpData(); nView++)
513  {
514  if (hasVpData(nView))
516  }
518 }
519 
520 inline void OdGsContainerNode::setEntityListValid(OdUInt32 nVpId, bool bValid)
521 {
522  SETBIT(getVpData(nVpId)->m_flags, kEntityListValid, bValid);
523  if (!bValid || !isVpDepCache())
524  SETBIT(m_flags, kEntityListValid, bValid);
525  else
526  { // Check does all entity lists valid
527  const OdUInt32 nViews = numVpData();
528  bool bAllListsValid = true;
529  for (OdUInt32 nView = 0; nView < nViews; nView++)
530  {
531  const VpData *pVpData = getVpData(nView, false);
532  if (pVpData && !GETBIT(pVpData->m_flags, VpData::kEntityListValid))
533  {
534  bAllListsValid = false;
535  break;
536  }
537  }
538  SETBIT(m_flags, kEntityListValid, bAllListsValid);
539  }
540 }
541 
543 {
544  return *getVpData(nVpId)->m_pSpIndex.get();
545 }
546 
548 {
549  return *getVpData(nVpId)->m_pSpIndex.get();
550 }
551 
553 {
554  VpData *pVpData = getVpData(nVpId, false);
555  if (!pVpData)
556  return NULL;
557  return pVpData->m_pFirstEntity;
558 }
559 
561 {
562  VpData *pVpData = getVpData(nVpId, false);
563  if (!pVpData)
564  return NULL;
565  return pVpData->m_pFirstEntity;
566 }
567 
569 {
570  VpData *pVpData = getVpData(nVpId, false);
571  if (!pVpData)
572  return NULL;
573  return pVpData->m_pLastEntity;
574 }
575 
577 {
578  VpData *pVpData = getVpData(nVpId, false);
579  if (!pVpData)
580  return NULL;
581  return pVpData->m_pLastEntity;
582 }
583 
585 {
586  return getVpData(nVpId)->m_lightPtrs;
587 }
588 
590 {
591  return getVpData(nVpId)->m_lightPtrs;
592 }
593 
595 {
596  if(m_vpAwareFlags.size()>nVpID)
597  return !GETBIT(m_vpAwareFlags[nVpID], kChildrenNotUpToDate);
598  return false;
599 }
600 
601 inline void OdGsContainerNode::setChildrenUpToDate(bool bValid, const OdUInt32* nVpID)
602 {
603  if(nVpID)
604  {
606  if(n <= *nVpID)
607  m_vpAwareFlags.insert(m_vpAwareFlags.end(), (*nVpID)+1-n, 0xFFFFFFFF);
608  SETBIT(m_vpAwareFlags[*nVpID], kChildrenNotUpToDate, !bValid);
609  }
610  else
611  {
612  ODA_ASSERT(!bValid);
613  for(OdUInt32 i = 0; i < m_vpAwareFlags.size(); ++i)
615  }
616 }
617 
619 {
620  if(m_vpAwareFlags.size()>nVpID)
621  return m_vpAwareFlags[nVpID] & ~kChildrenNotUpToDate;
622  return 0xFFFFFFFF;
623 }
624 
626 {
627  flags &= ~kChildrenNotUpToDate;
629  if(n <= nVpID)
630  {
631  m_vpAwareFlags.insert(m_vpAwareFlags.end(), nVpID+1-n, 0xFFFFFFFF);
632  m_vpAwareFlags[nVpID] = flags;
633  }
634  else
635  {
636  m_vpAwareFlags[nVpID] = ((m_vpAwareFlags[nVpID] & kChildrenNotUpToDate) | flags);
637  }
638 }
639 
640 inline bool OdGsContainerNode::needRegen(OdUInt32 nVpID) const
641 {
642  if(!childrenUpToDate(nVpID))
643  return true;
644 
645  OdUInt32 nAF = awareFlags(nVpID);
646  return ( nAF == 0xFFFFFFFF || ( baseModel()->viewChanges(nVpID) & nAF) != 0 );
647 }
648 
650 {
651  return GETBIT(m_flags, kCheckWorkset);
652 }
653 
655 {
656  SETBIT(m_flags, kCheckWorkset, bVal);
657 }
658 
660 {
661  if(m_vpAwareFlags.size()>nVpID)
662  return GETBIT(m_vpAwareFlags[nVpID], kEntityRegenDraw);
663  return false;
664 }
665 
667 {
669  if(n <= nVpID)
670  m_vpAwareFlags.insert(m_vpAwareFlags.end(), nVpID+1-n, 0xFFFFFFFF);
671  SETBIT(m_vpAwareFlags[nVpID], kEntityRegenDraw, bVal);
672 }
673 
675 {
676  VpData *pVpData = getVpData(nVpId, false);
677  if (!pVpData)
679  return getVpData(nVpId)->m_realExtents;
680 }
681 
683 {
684  VpData *pVpData = getVpData(nVpId);
685  pVpData->m_realExtents = ext;
686 }
687 
689 {
690  m_viewRefs.add(nVpId);
691 }
692 
694 {
695  m_viewRefs.remove(nVpId);
696 }
697 
699 {
700  return m_viewRefs;
701 }
702 
704 {
705  return m_stock;
706 }
707 
709 {
710  return getVpData(nVpId)->m_nChild;
711 }
712 
714 {
715  return getVpData(nVpId)->m_nChildSingleThreaded;
716 }
717 
719 {
720  return getVpData(nVpId)->m_nChildErased;
721 }
722 
723 #include "TD_PackPop.h"
724 
725 #endif // __OD_GS_CONTAINER_NODE__
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
ENodeType
Definition: GsBaseModel.h:65
@ kContainerNode
Definition: GsBaseModel.h:70
#define GS_TOOLKIT_EXPORT
Definition: GsExport.h:37
#define NULL
Definition: GsProperties.h:177
@ kEntityRegenDraw
unsigned int OdUInt32
#define SETBIT(flags, bit, value)
Definition: OdaDefs.h:497
#define SETBIT_0(flags, bit)
Definition: OdaDefs.h:500
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
bool isNull() const
Definition: BaseObjectPtr.h:70
void setRealExtents(OdUInt32 nVpId, const OdGsUpdateExtents &ext)
virtual void updateEntities(OdGsUpdateContext &ctx)
OdUInt32 awareFlags(OdUInt32 viewportId) const
bool saveNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer=NULL) const
void addViewRef(OdUInt32 nVpId)
bool loadVpData(OdGsFiler *pFiler, VpData *pVpData)
bool isEmpty() const
OdList< OdGsLightNode * > & lightNodesList(OdUInt32 nVpId)
void invalidate(OdGsContainerNode *pParent, OdGsViewImpl *pView, OdUInt32 mask)
OdUInt32 currViewChanges() const
OdVector< VpDataPtr > VpDataArray
OdList< OdGsLightNode * > LightsList
virtual void removeChild(OdGsNode *pNode)
void turnOnLights(OdGsBaseVectorizer &view)
OdUInt32 isAttached(OdGsEntityNode *pNode) const
OdMutexPtr m_lightsMutex
virtual void propagateLayerChanges(OdGsViewImpl &view)
void display(OdGsDisplayContext &ctx)
OdGsEntityNode * firstEntityNode(OdUInt32 nVpId)
OdGsEntityNode * lastEntityNode(OdUInt32 nVpId)
int numberOfChildren(OdUInt32 nVpId) const
OdUInt32 viewportId(const OdGsViewImpl &pView, bool bForceVpId=true) const
virtual bool extents(const OdGsView *pView, OdGeExtents3d &ext) const
virtual bool updateEntityList(OdGsUpdateContext &ctx)
const ViewRefs & viewRefs() const
bool findCompatibleCache(OdGsViewImpl &keyView)
VpData * makeVpData(OdUInt32 nVpId) const
ODRX_DECLARE_MEMBERS(OdGsContainerNode)
void setCheckWorkset(bool bVal)
virtual ENodeType nodeType() const
void addEntProps(const OdGsUpdateContext &ctx)
bool isVpDepCache() const
bool allEntityListsValid() const
bool saveVpData(OdGsFiler *pFiler, const VpData *pVpData) const
bool entityListValid(OdUInt32 nVpId) const
void doSTUpdate(OdGsUpdateContext &ctx)
OdUInt32 vpDataId(const VpData *pVpData) const
const OdGsUpdateExtents & realExtents(OdUInt32 nVpId) const
bool postprocessNodeLoading(OdGsFiler *pFiler)
VpData * getVpData(OdUInt32 nVpId, bool bCreateIfNotFound=true) const
void updateVisible(OdGsViewImpl *pViewImpl)
bool extents(OdGeExtents3d &extents) const
VpDataPtr m_shareableData
OdUInt32Vector m_vpAwareFlags
bool childrenUpToDate(OdUInt32 nVpId) const
void setChildrenUpToDate(bool childrenUpToDate, const OdUInt32 *nVpID=NULL)
bool doMTUpdate(OdGsUpdateContext &ctx)
bool safeEntityUpdate(OdGsEntityNode *pEntity, OdGsUpdateContext &ctx, OdSiSpatialIndex *pSpatialIndex)
void setChildrenRegenDraw(bool bVal, OdUInt32 nVpID)
void setAwareFlags(OdUInt32 viewportId, OdUInt32 flags)
OdSmartPtr< VpData > VpDataPtr
void addContentToUpdateManager(OdUInt32 viewportId, OdGsUpdateManager *pManager, const UpdateManagerContext &context)
virtual void addLight(OdGsUpdateContext &ctx, const OdGiDrawable *pDrawable)
virtual void addChild(const OdGiDrawable *pDrawable, OdGsViewImpl *pView, bool unerased=false)
OdUInt32 numberOfChildrenErased(OdUInt32 nVpId) const
OdSiSpatialIndex & spatialIndex(OdUInt32 nVpId)
bool needRegen(OdUInt32 nVpId) const
bool hasVpData(OdUInt32 nVpId) const
bool childrenRegenDraw(OdUInt32 nVpID) const
void propagateInvalidVpFlag()
virtual void removeLights(OdGsNode *pOwner, OdUInt32 nVpId=0xFFFFFFFF)
void addChildNode(OdUInt32 nVpId, OdGsEntityNode *pEnt)
OdUInt32 numVpData() const
OdGsContainerNode(OdGsBaseModel *pModel, const OdGiDrawable *pUnderlyingDrawable, bool bSetGsNode=true)
const StockProps & stock() const
bool loadNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer=NULL)
OdUInt32 numberOfChildrenST(OdUInt32 nVpId) const
bool highlightSubnodes(OdUInt32 nSubnodes, bool bHighlight, bool bAll)
void update(OdGsUpdateContext &ctx, OdGsContainerNode *pParent, OdSiSpatialIndex *pParentIndex)
bool checkWorkset() const
void removeViewRef(OdUInt32 nVpId)
void setEntityListValid(OdUInt32 nVpId, bool entityListValid)
void propagateLayerChangesStock()
VpDataArray m_vpData
virtual void displayEntityList(OdGsDisplayContext &ctx)
OdUInt32 m_flags
Definition: GsNode.h:87
@ kLastFlag
Definition: GsNode.h:84
OdGsBaseModel * baseModel() const
Definition: GsNode.h:278
static GS_STATIC_EXPORT const OdGsUpdateExtents kInvalid
Definition: Gs.h:133
const T * get() const
Definition: SmartPtr.h:326
const T & getAt(size_type index) const
Definition: OdVector.h:1027
size_type size() const
Definition: OdVector.h:866
const T * getPtr() const
Definition: OdVector.h:976
void insert(iterator before, const_iterator first, const_iterator afterLast)
iterator end()
Definition: OdVector.h:671
void remove(OdUInt32 viewportId)
Definition: GsViewProps.h:103
void add(OdUInt32 viewportId)
Definition: GsViewProps.h:88
GLenum GLint GLuint mask
Definition: gles2_ext.h:262
OdGsUpdateExtents m_realExtents
OdGsEntityNode * m_pClearSpatialQueryStateFirst
OdGsEntityNode * m_pLastEntity
OdSiSpatialIndexPtr m_pSpIndex
OdGsEntityNode * m_pFirstEntity
static OdSmartPtr< VpData > createObject(bool bShareable=false)