CFx SDK Documentation  2020SP3
DbGraph.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 
25 
26 
27 #ifndef _ODDBGRAPH_H_INCLUDED_
28 #define _ODDBGRAPH_H_INCLUDED_
29 
30 #include "TD_PackPush.h"
31 
32 #include "OdaDefs.h"
33 #include "DbExport.h"
34 #include "RxObject.h"
35 #include "OdArray.h"
36 
37 class OdDbGraph;
38 class OdDbGraphNode;
39 
44 
72 {
73  friend class OdDbGraph;
74 public:
75  OdDbGraphNode() : m_pData(0), m_flags(0), m_pOwner(0) {}
76 
78 
79  virtual ~OdDbGraphNode();
80 
81  enum Flags
82  {
83  kNone = 0x00, // None.
84  kVisited = 0x01, // Used internally by OdDbGraph::findCycles() and while traversing a graphs with cycles.
85  kOutsideRefed = 0x02, // Used internally by Xref detach.
86  kSelected = 0x04, // User selection. Set by getOutgoing.
87  kInList = 0x08, // Is *in* list. Set by getOutgoing.
88  kListAll = 0x0E, // Used to *clear* kSelected, kInList, and kOutsideRefed.
89  kFirstLevel = 0x10, // The *node* is connected to the root *node*. Read Only.
90  kUnresTree = 0x20, // The tree is unresolved.
91  kAll = 0x2F // Used to *clear* all but kFirstLevel.
92  };
93 
97  void* data() const { return m_pData; }
98 
104  void setData(
105  void* pData) { m_pData = pData; }
106 
110  int numOut() const { return m_outgoing.size(); }
111 
115  int numIn() const { return m_incoming.size(); }
116 
126  int refIndex) const { return m_incoming.at(refIndex); }
127 
136  int refIndex) const { return m_outgoing.at(refIndex); }
137 
153  void addRefTo(
154  OdDbGraphNode* pTo);
155 
167  OdDbGraphNode* pNode);
168 
176 
180  OdDbGraph* owner() const { return m_pOwner; }
181 
204  OdUInt8 flags) const { return ((m_flags & flags)==flags); }
205 
227  void markAs(
228  OdUInt8 flags)
229  {
230  if(!GETBIT(flags, kFirstLevel))
231  {
232  m_flags |= flags;
233  }
234  else
235  {
236  throw OdError(eInvalidInput);
237  }
238  }
239 
261  void clear(
262  OdUInt8 flags)
263  {
264  if(!GETBIT(flags, kFirstLevel))
265  {
266  m_flags &= (~flags);
267  }
268  else
269  {
270  throw OdError(eInvalidInput);
271  }
272  }
273 
274 
306  void markTree(
307  OdUInt8 flags,
308  OdDbGraphNodeArray* pNodeArray = 0);
309 
310  // Circularity detection methods
311 
319  int numCycleOut() const { return m_cycleOut.size(); }
320 
328  int numCycleIn() const { return m_cycleIn.size(); }
329 
343  int refIndex) const { return m_cycleIn[refIndex]; }
344 
358  int refIndex) const { return m_cycleOut[refIndex]; }
359 
370  OdDbGraphNode* nextCycleNode() const { return cycleOut(0); }
371 
379  bool isCycleNode() const { return (numCycleOut() != 0 || numCycleIn() != 0); }
380 
381 private:
382  void setOwner(
383  OdDbGraph* pGraph)
384  {
385  if(m_pOwner)
386  {
387  ODA_FAIL();
388  throw OdError(eInvalidOwnerObject);
389  }
390  m_pOwner = pGraph;
391  }
392 
393  friend struct if_leaf_push_to;
394  friend struct clear_cycles;
396 
397  void* m_pData;
398  OdUInt8 m_flags;
399  OdDbGraphNodeArray m_outgoing;
400  OdDbGraphNodeArray m_incoming;
401  OdDbGraph* m_pOwner;
402  OdDbGraphNodeArray m_cycleOut;
403  OdDbGraphNodeArray m_cycleIn;
404 };
409 
417 {
418 public:
429  int initPhysicalLength = 0,
430  int initGrowLength = 8)
431  : m_stack(initPhysicalLength, initGrowLength) {}
432 
434 
440  void push(
441  OdDbGraphNode* pNode) { m_stack.push_back(pNode); }
442 
450  {
451  if(!isEmpty())
452  {
453  OdDbGraphNode* pRes = top();
454  m_stack.removeLast();
455  return pRes;
456  }
457  return 0;
458  }
459 
460 
467  OdDbGraphNode* top() const { return isEmpty() ? 0 : m_stack.last(); }
468 
472  bool isEmpty() const { return m_stack.empty(); }
473 private:
474  OdDbGraphNodeArray m_stack;
475 };
476 
502 {
503  friend class OdDbGraphNode;
504 public:
505  OdDbGraph() : m_bDirty(false), m_nNonCycleNodes(0) {}
506  virtual ~OdDbGraph();
507 
514  int nodeIndex) const { return m_nodes.at(nodeIndex); }
515 
523 
529  int numNodes() const { return m_nodes.size(); }
530 
534  bool isEmpty() const { return numNodes() == 0; }
535 
548  void addNode(
549  OdDbGraphNode* pNode);
550 
563  void addEdge(
564  OdDbGraphNode* pFrom,
565  OdDbGraphNode* pTo);
566 
572  void delNode(
573  OdDbGraphNode* pNode);
574 
581  void reset();
582 
606  void clearAll(
607  OdUInt8 flags);
608 
617  OdDbGraphNodeArray& outgoing);
618 
629  virtual bool findCycles(
630  OdDbGraphNode* pStart = 0);
638  OdDbGraphNode* pFrom,
639  OdDbGraphNode* pTo);
640 
641 protected:
653 private:
654  OdDbGraph(
655  const OdDbGraph&);
656  OdDbGraph& operator =(
657  const OdDbGraph&);
658 
659  void removeLeaves(
660  OdDbGraphStack& stack);
661  void setDirty() { m_bDirty = true; }
662  bool isDirty() const { return m_bDirty; }
663  bool m_bDirty;
664  OdDbGraphNodeArray::size_type m_nNonCycleNodes;
665  OdDbGraphNodeArray m_nodes;
666 };
667 
668 #include "TD_PackPop.h"
669 
670 #endif // _ODDBGRAPH_H_INCLUDED_
GETBIT
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
OdDbGraph::addNode
void addNode(OdDbGraphNode *pNode)
DbExport.h
OdDbGraph::numNodes
int numNodes() const
Definition: DbGraph.h:529
OdDbGraphNode::out
OdDbGraphNode * out(int refIndex) const
Definition: DbGraph.h:135
OdDbGraphNode::owner
OdDbGraph * owner() const
Definition: DbGraph.h:180
OdArray::removeLast
OdArray & removeLast()
Definition: OdArray.h:1242
OdDbGraph::clearAll
void clearAll(OdUInt8 flags)
OdDbGraphNodeArray
OdArray< OdDbGraphNode *, OdMemoryAllocator< OdDbGraphNode * > > OdDbGraphNodeArray
Definition: DbGraph.h:38
OdDbGraphNode::Flags
Flags
Definition: DbGraph.h:82
OdUInt8
unsigned char OdUInt8
Definition: OdPlatformSettings.h:759
OdDbGraphNode::ODRX_DECLARE_MEMBERS
ODRX_DECLARE_MEMBERS(OdDbGraphNode)
OdDbGraphNode::markAs
void markAs(OdUInt8 flags)
Definition: DbGraph.h:227
OdDbGraph::node
OdDbGraphNode * node(int nodeIndex) const
Definition: DbGraph.h:513
OdDbGraphNode::setData
void setData(void *pData)
Definition: DbGraph.h:104
OdDbGraphNode::disconnectAll
void disconnectAll()
false
false
Definition: DimVarDefs.h:165
OdRxObject
Definition: RxObject.h:564
OdDbGraphStack::top
OdDbGraphNode * top() const
Definition: DbGraph.h:467
OdDbGraphNode::nextCycleNode
OdDbGraphNode * nextCycleNode() const
Definition: DbGraph.h:370
OdDbGraphNode::numIn
int numIn() const
Definition: DbGraph.h:115
OdDbGraphNode::in
OdDbGraphNode * in(int refIndex) const
Definition: DbGraph.h:125
OdDbGraphStack
Definition: DbGraph.h:417
OdDbGraphNode::numOut
int numOut() const
Definition: DbGraph.h:110
OdDbGraphNode::data
void * data() const
Definition: DbGraph.h:97
OdArray
Definition: OdArray.h:591
OdDbGraphNode
Definition: DbGraph.h:72
TD_PackPop.h
OdDbGraph::~OdDbGraph
virtual ~OdDbGraph()
RxObject.h
ODA_FAIL
#define ODA_FAIL()
Definition: DebugStuff.h:65
OdDbGraph::clearAllCycles
void clearAllCycles()
OdDbGraph::rootNode
OdDbGraphNode * rootNode() const
OdPdfPublish::Lighting::kNone
@ kNone
Light mode is inherited from the annotation.
Definition: PdfPublishCommon.h:160
OdArray::last
T & last()
Definition: OdArray.h:1198
OdDbGraph::getOutgoing
void getOutgoing(OdDbGraphNodeArray &outgoing)
OdDbGraphNode::cycleIn
OdDbGraphNode * cycleIn(int refIndex) const
Definition: DbGraph.h:342
OdArray.h
OdDbGraph::OdDbGraph
OdDbGraph()
Definition: DbGraph.h:505
OdaDefs.h
OdSmartPtr
Definition: SmartPtr.h:58
OdDbGraphNode::markTree
void markTree(OdUInt8 flags, OdDbGraphNodeArray *pNodeArray=0)
OdDbGraphNode::removeRefTo
void removeRefTo(OdDbGraphNode *pNode)
OdDbGraph::isEmpty
bool isEmpty() const
Definition: DbGraph.h:534
OdDbGraphNode::OdDbGraphNode
OdDbGraphNode()
Definition: DbGraph.h:75
OdDbGraphStack::isEmpty
bool isEmpty() const
Definition: DbGraph.h:472
OdDbGraphNode::break_edge
friend void break_edge(OdDbGraphNode *, OdDbGraphNode *)
TD_PackPush.h
OdDbGraph::addEdge
void addEdge(OdDbGraphNode *pFrom, OdDbGraphNode *pTo)
OdArray< OdDbGraphNode *, OdMemoryAllocator< OdDbGraphNode * > >::size_type
A::size_type size_type
Definition: OdArray.h:593
OdDbGraph::findCycles
virtual bool findCycles(OdDbGraphNode *pStart=0)
OdDbGraphNode::OdDbGraph
friend class OdDbGraph
Definition: DbGraph.h:73
OdDbGraphStack::pop
OdDbGraphNode * pop()
Definition: DbGraph.h:449
OdDbGraphNode::isCycleNode
bool isCycleNode() const
Definition: DbGraph.h:379
OdDbGraph::delNode
void delNode(OdDbGraphNode *pNode)
OdError
Definition: OdError.h:43
OdDbGraphStack::~OdDbGraphStack
~OdDbGraphStack()
Definition: DbGraph.h:433
OdArray::push_back
void push_back(const T &value)
Definition: OdArray.h:987
OdDbGraphNode::numCycleOut
int numCycleOut() const
Definition: DbGraph.h:319
OdDbGraphNodePtr
OdSmartPtr< OdDbGraphNode > OdDbGraphNodePtr
Definition: DbGraph.h:408
OdDbGraphNode::addRefTo
void addRefTo(OdDbGraphNode *pTo)
OdDbGraph::breakCycleEdge
void breakCycleEdge(OdDbGraphNode *pFrom, OdDbGraphNode *pTo)
OdDbGraphNode::cycleOut
OdDbGraphNode * cycleOut(int refIndex) const
Definition: DbGraph.h:357
TOOLKIT_EXPORT
#define TOOLKIT_EXPORT
Definition: DbExport.h:40
OdDbGraphNode::clear
void clear(OdUInt8 flags)
Definition: DbGraph.h:261
OdDbGraphNode::numCycleIn
int numCycleIn() const
Definition: DbGraph.h:328
OdDbGraph::reset
void reset()
OdDbGraphStack::push
void push(OdDbGraphNode *pNode)
Definition: DbGraph.h:440
OdDbGraphNode::isMarkedAs
bool isMarkedAs(OdUInt8 flags) const
Definition: DbGraph.h:203
OdArray::empty
bool empty() const
Definition: OdArray.h:901
OdDbGraph
Definition: DbGraph.h:502
OdDbGraphStack::OdDbGraphStack
OdDbGraphStack(int initPhysicalLength=0, int initGrowLength=8)
Definition: DbGraph.h:428
OdDbGraphNode::~OdDbGraphNode
virtual ~OdDbGraphNode()