xgraph.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // ========= xgraph.h: AcDbXrefGraph classes ================
  12. //
  13. // This header defines classes:
  14. //
  15. // AcDbXrefGraph - a derived class for representing Xrefs
  16. // AcDbXrefGraphNode - each node represents one Xref database
  17. //
  18. // An AcDbXrefGraph is a representation of the relationship between a
  19. // host drawing, its Xref'ed drawings, and any nested Xref drawings.
  20. // Each database, or Xref BLock Table Record is represented by an
  21. // AcDbXrefGraphNode in the graph. The host drawing is always the
  22. // rootNode. Each reference is represented by an edge in the graph,
  23. // and can be queried for by calling AcDbGraphNode::in(idx) for who
  24. // is referencing this node, and AcDbGraphNode::out(idx) for who this
  25. // node references.
  26. //
  27. // Detection for circular references is done by internally creating
  28. // a duplicate set of references in each node and then triming away
  29. // all leaf nodes, which terminate without circularity. If any nodes
  30. // remain in the duplicate graph, those nodes exist in a cycle.
  31. // AcDbGraph::findCycles() is used to set up the internal cycle
  32. // information and enable several query methods to return information
  33. // about any cycles found.
  34. //
  35. //
  36. #ifndef AD_XGRAPH_H
  37. #define AD_XGRAPH_H 1
  38. #include "graph.h"
  39. #include "AdAChar.h"
  40. #pragma pack (push, 8)
  41. // =====================================
  42. // Xref Graph Classes
  43. // =====================================
  44. class AcDbXrefGraphNode : public AcDbGraphNode
  45. {
  46. public:
  47. AcDbXrefGraphNode(const ACHAR * pName = NULL,
  48. const AcDbObjectId& btrId = AcDbObjectId::kNull,
  49. AcDbDatabase* pDb = NULL,
  50. AcDb::XrefStatus status = AcDb::kXrfResolved);
  51. virtual ~AcDbXrefGraphNode();
  52. const ACHAR * name() const;
  53. AcDbObjectId btrId() const;
  54. AcDbDatabase* database() const;
  55. Acad::ErrorStatus setName(const ACHAR * pName);
  56. void setBtrId(const AcDbObjectId& id);
  57. void setDatabase(AcDbDatabase* pDb);
  58. bool isNested() const;
  59. AcDb::XrefStatus xrefStatus() const;
  60. void setXrefStatus(AcDb::XrefStatus stat);
  61. AcDb::XrefNotificationStatus xrefNotificationStatus() const;
  62. void setXrefNotificationStatus(AcDb::XrefNotificationStatus stat);
  63. void* xData() { return mpxdata; }
  64. void setxData(void *pXData) { mpxdata = pXData; }
  65. Acad::ErrorStatus xrefReadSubstatus() const;
  66. private:
  67. void* mpxdata; // since data already used!
  68. ACHAR * mpName;
  69. AcDbObjectId mBtrId;
  70. // AcDbDatabase* uses base class data() member
  71. AcDb::XrefStatus mStatus;
  72. AcDb::XrefNotificationStatus mNotifyStatus;
  73. };
  74. class AcDbXrefGraph : public AcDbGraph
  75. {
  76. public:
  77. AcDbXrefGraph(AcDbXrefGraphNode* pHostDwg = NULL);
  78. virtual ~AcDbXrefGraph();
  79. AcDbXrefGraphNode* xrefNode(const ACHAR * pName) const;
  80. AcDbXrefGraphNode* xrefNode(AcDbObjectId btrId) const;
  81. AcDbXrefGraphNode* xrefNode(const AcDbDatabase* pDb) const;
  82. AcDbXrefGraphNode* xrefNode(int idx) const;
  83. AcDbXrefGraphNode* hostDwg() const;
  84. Adesk::Boolean markUnresolvedTrees ();
  85. // cycle detection
  86. virtual Adesk::Boolean findCycles(AcDbGraphNode* pStart = NULL);
  87. };
  88. // =====================================
  89. // General Utility functions
  90. // =====================================
  91. // Acad.lib only -- Not for use in ObjectDBX
  92. //
  93. Acad::ErrorStatus acedGetCurDwgXrefGraph(AcDbXrefGraph&,
  94. Adesk::Boolean includeGhosts = Adesk::kFalse);
  95. // =====================================
  96. // Inline methods
  97. // =====================================
  98. // AcDbXrefGraphNode inlines ...
  99. inline const ACHAR * AcDbXrefGraphNode::name() const { return mpName; }
  100. inline AcDbObjectId AcDbXrefGraphNode::btrId() const { return mBtrId; }
  101. inline AcDbDatabase* AcDbXrefGraphNode::database() const
  102. { return (AcDbDatabase*)data(); }
  103. inline void AcDbXrefGraphNode::setBtrId(const AcDbObjectId& id)
  104. { mBtrId = id; }
  105. inline void AcDbXrefGraphNode::setDatabase(AcDbDatabase* pDb)
  106. { setData(pDb); }
  107. inline bool AcDbXrefGraphNode::isNested() const
  108. { return !isMarkedAs(kFirstLevel); }
  109. inline AcDb::XrefStatus AcDbXrefGraphNode::xrefStatus() const
  110. { return mStatus; }
  111. inline void AcDbXrefGraphNode::setXrefStatus(AcDb::XrefStatus stat)
  112. { mStatus = stat; }
  113. inline AcDb::XrefNotificationStatus
  114. AcDbXrefGraphNode::xrefNotificationStatus() const
  115. { return mNotifyStatus; }
  116. inline void AcDbXrefGraphNode::setXrefNotificationStatus(
  117. AcDb::XrefNotificationStatus stat)
  118. { mNotifyStatus = stat; }
  119. // AcDbXrefGraph inlines ...
  120. inline AcDbXrefGraphNode* AcDbXrefGraph::xrefNode(int idx) const
  121. { return (AcDbXrefGraphNode*)node(idx); }
  122. inline AcDbXrefGraphNode* AcDbXrefGraph::hostDwg() const
  123. { return (AcDbXrefGraphNode*)rootNode(); }
  124. #pragma pack (pop)
  125. #endif