CFx SDK Documentation  2022 SP0
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_
#define TOOLKIT_EXPORT
Definition: DbExport.h:40
OdSmartPtr< OdDbGraphNode > OdDbGraphNodePtr
Definition: DbGraph.h:408
OdArray< OdDbGraphNode *, OdMemoryAllocator< OdDbGraphNode * > > OdDbGraphNodeArray
Definition: DbGraph.h:38
#define ODA_FAIL()
Definition: DebugStuff.h:65
false
Definition: DimVarDefs.h:165
unsigned char OdUInt8
#define GETBIT(flags, bit)
Definition: OdaDefs.h:498
T & last()
Definition: OdArray.h:1198
bool empty() const
Definition: OdArray.h:901
void push_back(const T &value)
Definition: OdArray.h:987
OdArray & removeLast()
Definition: OdArray.h:1242
void getOutgoing(OdDbGraphNodeArray &outgoing)
OdDbGraph()
Definition: DbGraph.h:505
void clearAllCycles()
void clearAll(OdUInt8 flags)
void addNode(OdDbGraphNode *pNode)
void delNode(OdDbGraphNode *pNode)
void breakCycleEdge(OdDbGraphNode *pFrom, OdDbGraphNode *pTo)
OdDbGraphNode * rootNode() const
void addEdge(OdDbGraphNode *pFrom, OdDbGraphNode *pTo)
virtual bool findCycles(OdDbGraphNode *pStart=0)
int numNodes() const
Definition: DbGraph.h:529
void reset()
bool isEmpty() const
Definition: DbGraph.h:534
virtual ~OdDbGraph()
OdDbGraphNode * node(int nodeIndex) const
Definition: DbGraph.h:513
OdDbGraphNode * nextCycleNode() const
Definition: DbGraph.h:370
friend class OdDbGraph
Definition: DbGraph.h:73
bool isMarkedAs(OdUInt8 flags) const
Definition: DbGraph.h:203
int numIn() const
Definition: DbGraph.h:115
void addRefTo(OdDbGraphNode *pTo)
OdDbGraphNode * cycleOut(int refIndex) const
Definition: DbGraph.h:357
void markAs(OdUInt8 flags)
Definition: DbGraph.h:227
virtual ~OdDbGraphNode()
OdDbGraphNode * cycleIn(int refIndex) const
Definition: DbGraph.h:342
void clear(OdUInt8 flags)
Definition: DbGraph.h:261
OdDbGraphNode * out(int refIndex) const
Definition: DbGraph.h:135
void setData(void *pData)
Definition: DbGraph.h:104
int numCycleOut() const
Definition: DbGraph.h:319
OdDbGraph * owner() const
Definition: DbGraph.h:180
bool isCycleNode() const
Definition: DbGraph.h:379
void disconnectAll()
OdDbGraphNode * in(int refIndex) const
Definition: DbGraph.h:125
int numCycleIn() const
Definition: DbGraph.h:328
void removeRefTo(OdDbGraphNode *pNode)
void markTree(OdUInt8 flags, OdDbGraphNodeArray *pNodeArray=0)
OdDbGraphNode()
Definition: DbGraph.h:75
int numOut() const
Definition: DbGraph.h:110
void * data() const
Definition: DbGraph.h:97
ODRX_DECLARE_MEMBERS(OdDbGraphNode)
friend void break_edge(OdDbGraphNode *, OdDbGraphNode *)
OdDbGraphNode * pop()
Definition: DbGraph.h:449
OdDbGraphNode * top() const
Definition: DbGraph.h:467
bool isEmpty() const
Definition: DbGraph.h:472
OdDbGraphStack(int initPhysicalLength=0, int initGrowLength=8)
Definition: DbGraph.h:428
void push(OdDbGraphNode *pNode)
Definition: DbGraph.h:440
@ kNone
Light mode is inherited from the annotation.