AcDbCompoundObjectId.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. // DESCRIPTION:
  11. //
  12. // Declaration of the AcDbCompoundObjectId class.
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #pragma once
  16. #pragma pack (push, 8)
  17. /// <summary><para>
  18. /// Class used to identify an AcDbObject in an AcDbDatabase when the object is
  19. /// references via a path of AcDbBlockReferences, and possibly by some other
  20. /// ways in the future. The object may reside in the host database (the same
  21. /// database as the AcDbCompoundObjectId belongs to) or it may reside in an XREF
  22. /// database or even in an unrelated database.
  23. /// </para><para>
  24. /// Notice that if the AcDbCompoundObjectId references an object in another
  25. /// database, reactors will be created to keep tract of relevant events happening
  26. /// to the database, such as database deletion or XREF unload/reload.
  27. /// </para></summary>
  28. ///
  29. class ACDB_PORT AcDbCompoundObjectId : public AcRxObject
  30. {
  31. public:
  32. ACRX_DECLARE_MEMBERS(AcDbCompoundObjectId);
  33. /// <summary>
  34. /// The default constructor creates an empty AcDbCompoundObjectId.
  35. /// </summary>
  36. ///
  37. AcDbCompoundObjectId();
  38. /// <summary>
  39. /// Creates AcDbCompoundObjectId from an ordinary AcDbObjectId. If the
  40. /// host database is null, the host database is obtained from the given
  41. /// AcDbObjectId. Even if it is in XREF database, the database hosting the
  42. /// XREF is obtained.
  43. /// </summary>
  44. /// <param name="id"> AcDbObjectId of the AcDbObject that this AcDbCompoundObjectId
  45. /// is going to reference. </param>
  46. /// <param name="pHostDatabase"> The host database. If null, the database
  47. /// is taken from the AcDbObjectId (even if it is in XREF database). </param>
  48. ///
  49. AcDbCompoundObjectId(const AcDbObjectId& id, AcDbDatabase* pHostDatabase = NULL);
  50. /// <summary> Copy constructor. </summary>
  51. ///
  52. AcDbCompoundObjectId(const AcDbCompoundObjectId&);
  53. /// <summary>
  54. /// Creates AcDbCompoundObjectId from an ordinary AcDbObjectId and a path
  55. /// of AcDbBlockReferences. If the host database is null, the host database
  56. /// is obtained from the first id in the path. Even if it is in XREF database,
  57. /// the database hosting the XREF is obtained.
  58. /// </summary>
  59. /// <param name="id"> AcDbObjectId of the AcDbObject that this AcDbCompoundObjectId
  60. /// is going to reference. </param>
  61. /// <param name="path"> The path of AcDbBlockReferences that lead to the
  62. /// referenced object. The first AcDbBlockReference in the path resides in the
  63. /// host database, the second AcDbBlockReference is from the AcDbBlockTableRecord
  64. /// that the first AcDbBlockReference references, the third AcDbBlockReference
  65. /// is from the AcDbBlockTableRecord that the second AcDbBlockReference
  66. /// references, etc. </param>
  67. /// <param name="pHostDatabase"> The host database. If null, the database
  68. /// is taken from the first AcDbBlockReference id in the path (even if it is
  69. /// in XREF database). </param>
  70. ///
  71. AcDbCompoundObjectId(const AcDbObjectId& id, const AcDbObjectIdArray& path, AcDbDatabase* pHostDatabase = NULL);
  72. virtual ~AcDbCompoundObjectId();
  73. AcDbCompoundObjectId& operator =(const AcDbObjectId&);
  74. AcDbCompoundObjectId& operator =(const AcDbCompoundObjectId&);
  75. bool operator ==(const AcDbCompoundObjectId&) const;
  76. bool operator !=(const AcDbCompoundObjectId& other) const { return !(*this == other); }
  77. /// <summary> Returns the first AcDbObjectId (of an AcDbBlockReference)
  78. /// in the path, or the leaf-node AcDbObjectId, if there is no path.
  79. /// </summary>
  80. ///
  81. AcDbObjectId topId() const;
  82. /// <summary> Returns the leaf-node AcDbObjectId that resides in the
  83. /// AcDbBlockTableRecord that the last AcDbBlockReference in the path references,
  84. /// or simply the AcDbObjectId if there is no path.
  85. /// </summary>
  86. ///
  87. AcDbObjectId leafId() const;
  88. /// <summary> Returns the full path, i.e. the given path of AcDbBlockReference
  89. /// ids appended with the leaf AcDbObjectId.
  90. /// </summary>
  91. ///
  92. Acad::ErrorStatus getFullPath(AcDbObjectIdArray& fullPath) const; // path + leaf object
  93. /// <summary> Returns the AcDbBlockReference path. </summary>
  94. ///
  95. Acad::ErrorStatus getPath(AcDbObjectIdArray& path) const;
  96. /// <summary> Sets the AcDbCompoundObjectId to be empty, containing no data. </summary>
  97. ///
  98. void setEmpty();
  99. /// <summary>
  100. /// Sets this AcDbCompoundObjectId from an ordinary AcDbObjectId. If the
  101. /// host database is null, the host database is obtained from the given
  102. /// AcDbObjectId. Even if it is in XREF database, the database hosting the
  103. /// XREF is obtained.
  104. /// </summary>
  105. /// <param name="id"> AcDbObjectId of the AcDbObject that this AcDbCompoundObjectId
  106. /// is going to reference. </param>
  107. /// <param name="pHostDatabase"> The host database. If null, the database
  108. /// is taken from the AcDbObjectId (even if it is in XREF database). </param>
  109. ///
  110. Acad::ErrorStatus set(const AcDbObjectId&, AcDbDatabase* pHostDatabase = NULL);
  111. /// <summary> Sets this AcDbCompoundObjectId from another AcDbCompoundObjectId. </summary>
  112. ///
  113. Acad::ErrorStatus set(const AcDbCompoundObjectId&, AcDbDatabase* pHostDatabase = NULL);
  114. /// <summary>
  115. /// Sets this AcDbCompoundObjectId from an ordinary AcDbObjectId and a path
  116. /// of AcDbBlockReferences. If the host database is null, the host database
  117. /// is obtained from the first id in the path. Even if it is in XREF database,
  118. /// the database hosting the XREF is obtained.
  119. /// </summary>
  120. /// <param name="id"> AcDbObjectId of the AcDbObject that this AcDbCompoundObjectId
  121. /// is going to reference. </param>
  122. /// <param name="path"> The path of AcDbBlockReferences that lead to the
  123. /// referenced object. The first AcDbBlockReference in the path resides in the
  124. /// host database, the second AcDbBlockReference is from the AcDbBlockTableRecord
  125. /// that the first AcDbBlockReference references, the third AcDbBlockReference
  126. /// is from the AcDbBlockTableRecord that the second AcDbBlockReference
  127. /// references, etc. </param>
  128. /// <param name="pHostDatabase"> The host database. If null, the database
  129. /// is taken from the first AcDbBlockReference id in the path (even if it is
  130. /// in XREF database). </param>
  131. /// <returns> Acad::ErrorStatus. </returns>
  132. ///
  133. Acad::ErrorStatus set(const AcDbObjectId& id, const AcDbObjectIdArray& path, AcDbDatabase* pHostDatabase = NULL);
  134. /// <summary> Sets this AcDbCompoundObjectId from the path that contains the
  135. /// path of AcDbBlockReferences apppended by the leaf AcDbObjectId.
  136. /// </summary>
  137. /// <param name="fullPath"> The path of AcDbBlockReferences and the leaf level
  138. /// object itself as the last element of the array.
  139. /// </param>
  140. /// <param name="pHostDatabase"> The host database. If null, the database
  141. /// is taken from the first AcDbBlockReference id in the fullPath. </param>
  142. /// <returns> Acad::ErrorStatus. </returns>
  143. ///
  144. Acad::ErrorStatus setFullPath(const AcDbObjectIdArray& fullPath, AcDbDatabase* pHostDatabase = NULL);
  145. /// <summary> Checks if the AcDbCompoundObjectId contains no data. </summary>
  146. ///
  147. bool isEmpty() const;
  148. /// <summary> Returns true iff the AcDbCompoundObjectId is valid. The given
  149. /// validityCheckingLevel specifies the level of testing. Bigger number means
  150. /// more thorough checks are being performed. At this moment the
  151. /// validityCheckingLevel argument is unused but will be used in the future.
  152. /// </summary>
  153. ///
  154. bool isValid(int validityCheckingLevel = 1) const;
  155. /// <summary> Returns true iff the AcDbCompoundObjectId is from an external
  156. /// drawing. </summary>
  157. ///
  158. bool isExternal() const;
  159. /// <summary> Returns true iff there is no path, only the leaf id (which may be null).
  160. /// </summary>
  161. ///
  162. bool isSimpleObjectId() const;
  163. enum Status
  164. {
  165. kValid = 0, // Good to go, can be Null
  166. kWasLoadedNowUnloaded = 1, // Loaded during dwgOpen, then xref was unloaded
  167. kCouldNotResolveNonTerminal = 2, // Couldn't be resolved - xref not found, unloaded when last saved, etc. non-terminal
  168. kCouldNotResolveTerminal = 3, // Couldn't be resolved, bad sceario - xref dwg replaced, not referenced, etc.
  169. kCouldNotResolveTooEarly = 4, // Couldn't be resolved yet - too early - xref not finished resolving
  170. kIncompatibleIdType = 1000,
  171. };
  172. Status status() const;
  173. /// <summary>
  174. /// Returns the compound transform from the leaf object to the world,
  175. /// concatennating all the AcDbBlockReference transforms, from the most nested
  176. /// one to the topmost one. This transformation represents mapping of the
  177. /// coordinates of the leaf-level object from its AcDbBlockTableRecord
  178. /// coordinate space to the world coordinate space.
  179. /// </summary>
  180. /// <param name="trans"> The returned compound transform. </param>
  181. /// <returns> Acad::ErrorStatus. </returns>
  182. ///
  183. Acad::ErrorStatus getTransform(AcGeMatrix3d& trans) const;
  184. /// <summary> Remaps all the AcDbObjectIds in this AcDbCompoundObjectId by
  185. /// the given AcDbIdMapping. Returns true if any remapping actually happened,
  186. /// false otherwise. </summary>
  187. /// <param name="idMap"> See the description of the AcDbIdMapping class. </param>
  188. /// <returns> True if some ids actually changed, false otherwise. </returns>
  189. ///
  190. bool remap(const AcDbIdMapping& idMap);
  191. Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler, AcDbDatabase* pHostDatabase) const;
  192. /// <remarks>
  193. /// The ownerVersion greater or equal to 0 means the new format, less than 0
  194. /// means the old format (w/o the class name and object version) that we need
  195. /// to maintain only to be able to read Beta1/2 drawings.
  196. /// </remarks>
  197. ///
  198. Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler, int ownerVersion);
  199. Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* pFiler, AcDbDatabase* pHostDatabase) const;
  200. /// <remarks>
  201. /// The ownerVersion greater or equal to 0 means the new format, less than 0
  202. /// means the old format (w/o the class name and object version) that we need
  203. /// to maintain only to be able to read Beta1/2 drawings.
  204. /// </remarks>
  205. ///
  206. Acad::ErrorStatus dxfInFields(AcDbDxfFiler* pFiler, AcDbDatabase* pHostDatabase, int ownerVersion);
  207. /// <summary> Returns an empty AcDbCompoundObjectId. </summary>
  208. ///
  209. static const AcDbCompoundObjectId& nullId();
  210. private:
  211. class AcDbImpCompoundObjectId* mpImp;
  212. };
  213. /// <summary>
  214. /// Protocol extension used by AcDbCompoundObjectId::getTransform() to find the
  215. /// transform that the parent object applies to its child object, if the AcDbCompoundObjectId
  216. /// contains a whole path of objects. For example for AcDbBlockReference the returned
  217. /// transform is AcDbBlockReference::blockTransform(). If the path contains other parent
  218. /// objects than AcDbBlockReference (it seems to be allowed, e.g. the parent object may
  219. /// be a custom entity), the parent object may specify the transform. If the parent object
  220. /// does not expose this PE, an identify transform is assumed.
  221. /// </summary>
  222. ///
  223. class ACDB_PORT AcDbParentTransformOfChildPE : public AcRxObject
  224. {
  225. public:
  226. ACRX_DECLARE_MEMBERS(AcDbParentTransformOfChildPE);
  227. /// <summary>
  228. /// Returns the transform of the child object in the parent object.
  229. /// </summary>
  230. ///
  231. virtual Acad::ErrorStatus getParentTransformOfChild(const AcDbObject* pThisParent, const AcDbObjectId& childId, AcGeMatrix3d&) = NULL;
  232. };
  233. #pragma pack (pop)