dbaudita.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. //
  12. // Header file for auditing routines
  13. #ifndef DB_DBAUDITA_H
  14. #define DB_DBAUDITA_H 1
  15. #include "AdAChar.h"
  16. #pragma pack(push, 8)
  17. class AcDbDatabase;
  18. class AcDbAuditInfo;
  19. class AcDbImpAuditInfo;
  20. class AcDbAuditImp;
  21. class AcDbObject;
  22. // ACDB_AUDIT_RETURN
  23. //
  24. // This macro encapsulates the recommended "contract" for arbitrating
  25. // audit return statuses between parent class status and local class
  26. // status. If either the parent class audit member fails or the
  27. // local audit member fails, the object audit fails, with the parent
  28. // class failure taking precedence. The last parameter is a bool
  29. // which specifies whether to "boil down" failure status to the
  30. // recommended audit return values or return the direct local status.
  31. // If this member doesn't supermessage a parent class, then pass in
  32. // "eOk" for BaseEs.
  33. //
  34. // if AcDbImpObject::audit failed,
  35. // then the audit "fails"
  36. // else if local test succeeded,
  37. // then the audit "succeeds" so far,
  38. // return different bad status or
  39. // "boil down" to accepted status
  40. // else if audit is to fix errors
  41. // then say we fixed all errors
  42. // else we didn't fix them!
  43. // Return local status
  44. //
  45. #define ACDB_AUDIT_RETURN(pAuditInfo, baseEs, localEs, boilDownLocalStatus) \
  46. return (baseEs != eOk) ? \
  47. baseEs : \
  48. (eOk == localEs) ? \
  49. eOk : \
  50. boilDownLocalStatus ? \
  51. (pAuditInfo->fixErrors()? \
  52. eFixedAllErrors : \
  53. eLeftErrorsUnfixed) : \
  54. localEs;
  55. class AcDbAuditInfo
  56. {
  57. public:
  58. friend class AcDbImpAuditInfo;
  59. friend class AcDbAuditImp;
  60. enum AuditPass {
  61. PASS1 = 1,
  62. PASS2 = 2
  63. };
  64. AcDbAuditInfo();
  65. ~AcDbAuditInfo();
  66. bool fixErrors(void) const; // True if errors are to
  67. // be fixed.
  68. int numErrors() const;
  69. int numFixes(void) const;
  70. void errorsFound(int count); // Specify the number
  71. // of errors found.
  72. void errorsFixed(int count); // Specify the number of
  73. // errors fixed.
  74. AuditPass auditPass(void) const; // The audit pass
  75. // number:
  76. // 1 = pass 1,
  77. // 2 = pass 2.
  78. void printError(const ACHAR * name,
  79. const ACHAR * value,
  80. const ACHAR * validation,
  81. const ACHAR * defaultValue); // Print an error
  82. // message string to the
  83. // Audit report file.
  84. // Obeys AUDITCTL.
  85. // Same as above except that name is automatically constructed
  86. // from the AcDbObject.
  87. //
  88. void printError(const AcDbObject *pObj,
  89. const ACHAR * value,
  90. const ACHAR * validation,
  91. const ACHAR * defaultValue);
  92. void requestRegen();
  93. void resetNumEntities();
  94. void incNumEntities();
  95. int numEntities();
  96. void printNumEntities(const ACHAR* msg);
  97. /// <summary>
  98. /// fetchObject is invoked from AcDbObject::audit() override members, as
  99. /// well as the AcDb recovery-audit complex. Its purpose is to retrieve
  100. /// an object id based on the input object id. It will usually be the
  101. /// same object id as is passed in, but can differ when recover logic
  102. /// creates new objects under new object ids.
  103. /// </summary>
  104. ///
  105. /// <param name="originalObjId">
  106. /// The object id read in from the DWG file.
  107. /// </param>
  108. ///
  109. /// <param name="newObjId">
  110. /// The object id to use insetad of originalObjId.
  111. /// </param>
  112. ///
  113. /// <param name="pObjClass">
  114. /// The anticipated class of the missing-corrupted object.
  115. /// </param>
  116. ///
  117. /// <param name="uneraseIfPossible">
  118. /// If true, and the referenced object is erased, it will be
  119. /// unerased if the object permits itself to be unerased.
  120. /// </param>
  121. ///
  122. /// <param name="createIfNotFound">
  123. /// Every call to fetchObject with this parameter set to true will
  124. /// cause the object recreation mechanism to be invoked.
  125. /// if false, then fetchObject will return results based on what is
  126. /// already in the lookup table.
  127. /// </param>
  128. ///
  129. /// <param name="externalDbOk">
  130. /// true implies that objId and newObjId can reside in another database.
  131. /// Note: Not yet implemented.
  132. /// </param>
  133. ///
  134. /// <returns>
  135. /// The following ErrorStatus values can be returned from this function.
  136. /// eOk: Success, objId has a valid valuel
  137. /// eInvalidInput: Errors include newObjId being NULL and pObjClass
  138. /// being NULL.
  139. /// eNotImplementedYet: returned if externalDbOk is true and newObjId is
  140. /// from an external database.
  141. /// eInvalidXrefObjectId: objId cannot be a forwarding reference to another
  142. /// object Id in an xref database.
  143. /// eWasErased: if an object is erased and the uneraseIfPossible
  144. /// parameter is false or the object cannot be unerased.
  145. /// eNullObjectPointer and
  146. /// eNullObjectId: if a valid object cannot be returned for various
  147. /// reasons.
  148. /// </returns>
  149. ///
  150. /// <remarks>
  151. /// If eOk is returned, then newObjId will be valid and should be used (and
  152. /// will most often be the same as objId).
  153. /// If any other value is returned, then both objId and newObjId should be
  154. /// considered to be invalid.
  155. /// </remarks>
  156. ///
  157. Acad::ErrorStatus fetchObject(AcDbObjectId originalObjId,
  158. AcDbObjectId& newObjId,
  159. AcRxClass* pObjClass,
  160. bool uneraseIfPossible = false,
  161. bool createIfNotFound = true,
  162. bool externalDbOk = false);
  163. /// <summary>
  164. /// registerObject is invoked from AcDb Recover and Audit internals, and can
  165. /// also be invoked from AcDbObject::audit(), dwgInFields() and any other
  166. /// override members invoked during a recover operation and its subsequent
  167. /// audit. It is the easy way to make entries for valid objects, compared
  168. /// to AcDbAuditInfo::updateObject, which has a much more verbose parameter
  169. /// list.
  170. /// </summary>
  171. ///
  172. /// <param name="handle">
  173. /// The handle of the original object, readily obtainable from an object
  174. /// id as well. It is the lookup key for indirect object lookup table
  175. /// entries.
  176. /// </param>
  177. ///
  178. /// <param name="objIsValid">
  179. /// A bool indicating whether the object is valid or not. If true is
  180. /// passed in, then the entire lookup table entry is filled out with
  181. /// the handle pointing to its own object id as its replacement.
  182. /// </param>
  183. ///
  184. /// <param name="pObjClass">
  185. /// The anticipated or known class of the missing-corrupted object.
  186. /// </param>
  187. ///
  188. /// <returns>
  189. /// The following ErrorStatus values can be returned from this function.
  190. /// eOk: Success, objId has a valid value.
  191. /// eInvalidInput: The input handle cannot be null (0).
  192. /// eHandleInUse: Returned if this function is invoked more than
  193. /// once for the input handle in a single recover
  194. /// operation.
  195. /// </returns>
  196. ///
  197. /// <remarks>
  198. /// The Recover logic usually populates the indirect object table
  199. /// with entries that map object ids to themselves. But it can be invoked by
  200. /// applications as well.
  201. ///
  202. /// Once objIsValid is passed in as false, AcDbAuditInfo::updateObject
  203. /// must be invoked to establish the new object id.
  204. /// </remarks>
  205. ///
  206. Acad::ErrorStatus registerObject(AcDbHandle handle,
  207. bool objIsValid,
  208. AcRxClass* pObjClass);
  209. /// <summary>
  210. /// updateObject is invoked from AcDb Recover and Audit internals, and can
  211. /// also be invoked from AcDbObject::audit(), dwgInFields() and any other
  212. /// override members invoked during a recover operation and its subsequent
  213. /// audit.
  214. /// </summary>
  215. ///
  216. /// <param name="setFileObjIsValid">
  217. /// Boolean indicating whether the fileObjIsValid parameter should
  218. /// replace the corresponding field in the lookup table entry.
  219. /// </param>
  220. ///
  221. /// <param name="setNewObjIsValid">
  222. /// Boolean indicating whether the newObjIsValid parameter should
  223. /// replace the corresponding field in the lookup table entry.
  224. /// </param>
  225. ///
  226. /// <param name="setFileObjClass">
  227. /// Boolean indicating whether the fileObjClass parameter should
  228. /// replace the corresponding field in the lookup table entry.
  229. /// </param>
  230. ///
  231. /// <param name="setNewObjClass">
  232. /// Boolean indicating whether the setNewObjClass parameter should
  233. /// replace the corresponding field in the lookup table entry.
  234. /// </param>
  235. ///
  236. /// <param name="setNewObjId">
  237. /// Boolean indicating whether the newObjId parameter should
  238. /// replace the corresponding field in the lookup table entry.
  239. /// </param>
  240. ///
  241. /// <param name="fileObjIsValid">
  242. /// A bool indicating whether the object image in the DWG file was
  243. /// valid or not.
  244. /// </param>
  245. ///
  246. /// <param name="newObjIsValid">
  247. /// A bool indicating whether the object under newObjId is
  248. /// valid or not. If not set to true, then fetchObject on
  249. /// objectHandle will return eNullObjectPointer.
  250. /// </param>
  251. ///
  252. /// <param name="pFileObjClass">
  253. /// The original class of the missing or corrupted object.
  254. /// </param>
  255. ///
  256. /// <param name="pNewObjClass">
  257. /// The class of the original or replacement object.
  258. /// </param>
  259. ///
  260. /// <param name="newObjId">
  261. /// Boolean indicating whether the newObjId parameter should
  262. /// replace the corresponding field in the lookup table entry.
  263. /// Usually that of objectHandle unless the object id had to
  264. /// be redirected.
  265. /// </param>
  266. ///
  267. /// <returns>
  268. /// The following ErrorStatus values can be returned from this function.
  269. /// eOk: Success, the indicated fields were replaced.
  270. /// eInvalidInput: The input handle cannot be null (0).
  271. /// </returns>
  272. ///
  273. /// <remarks>
  274. /// The Recover logic makes use of this member to indicated fixed up
  275. /// objects and redirected object ids. But it can be invoked by
  276. /// applications as well.
  277. ///
  278. /// This is the most powerful and most verbose way to create and update
  279. /// entries for the indirect object lookup table; with a separate parameter
  280. /// for every field in a table entry, and a boolean flag for each parameter,
  281. /// indicating whether the corresponding parameter should replace the current
  282. /// entry or not.
  283. /// </remarks>
  284. ///
  285. Acad::ErrorStatus updateObject( AcDbHandle handle,
  286. bool setFileObjIsValid,
  287. bool setNewObjIsValid,
  288. bool setFileObjClass,
  289. bool setNewObjClass,
  290. bool setNewObjId,
  291. bool fileObjIsValid,
  292. bool newObjIsValid,
  293. AcRxClass* pFileObjClass,
  294. AcRxClass* pNewObjClass,
  295. AcDbObjectId newObjId);
  296. private:
  297. AcDbImpAuditInfo * getImpAudit() const;
  298. AcDbImpAuditInfo * mpImpAudit;
  299. };
  300. // Class to hold the call back function.
  301. class AcDbRecover{
  302. public:
  303. virtual int callBack(AcDbDatabase*) = 0;
  304. };
  305. class AcDbImpRecoverCallBack;
  306. class AcDbRecoverCallBack {
  307. public:
  308. AcDbRecoverCallBack();
  309. virtual ~AcDbRecoverCallBack();
  310. virtual Acad::ErrorStatus registerCallBack(AcDbRecover*);
  311. virtual Acad::ErrorStatus removeCallBack();
  312. private:
  313. AcDbImpRecoverCallBack *mpImpRecoverCallBack;
  314. };
  315. #pragma pack(pop)
  316. #endif