xreflock.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. // DESCRIPTION: Header for Xref FileLock & Consistency Check
  12. #ifndef _XREFLOCK_H
  13. #define _XREFLOCK_H
  14. #include "rxnames.h"
  15. #include "dbidar.h"
  16. #pragma pack (push, 8)
  17. class AcDbDatabase;
  18. class AcDbIdMapping;
  19. class AcDwgFileHandle;
  20. class ACDB_PORT AcEdXrefFileLock
  21. {
  22. public:
  23. AcEdXrefFileLock();
  24. ~AcEdXrefFileLock();
  25. Acad::ErrorStatus lockFile(
  26. int& retstatus,
  27. const AcDbObjectId& selectedBTRid);
  28. Acad::ErrorStatus releaseFile(
  29. int& retstatus,
  30. bool bSkipSaveback = false,
  31. bool bReload = true);
  32. Acad::ErrorStatus consistencyCheck(
  33. int& retstatus,
  34. const AcDbObjectId& selectedBTRid,
  35. AcDbObjectIdArray& outofSyncBTRids);
  36. Acad::ErrorStatus consistencyCheck(
  37. int& retstatus,
  38. const AcDbObjectId& selectedBTRid);
  39. Acad::ErrorStatus consistencyChecklocal(
  40. int& retstatus,
  41. const AcDbObjectId& selectedBTRid);
  42. Acad::ErrorStatus xloadctlType(
  43. int& retstatus,
  44. const AcDbObjectId& selectedBTRid);
  45. int getlockxloadctlType() const { return mXldctltype; }
  46. const AcDbObjectIdArray& getoutofSyncIdArray() const { return mXBTRidArray; }
  47. Acad::ErrorStatus reloadFile(
  48. int& retstatus,
  49. const AcDbObjectIdArray& BTRids,
  50. const int xldctltype = -1);
  51. Acad::ErrorStatus reloadFile(
  52. int& retstatus,
  53. const int xldctltype = -1);
  54. void setInternalTNmgmt(bool bTNmgmt);
  55. AcDbObjectId getLockBtrId() const { return mXBTRid; }
  56. private:
  57. AcDwgFileHandle* mdwgfile;
  58. AcDbDatabase* mpXDB;
  59. AcDbDatabase* mpXDBlockFile;
  60. int mXldctltype;
  61. AcDbObjectId mXBTRid;
  62. AcDbObjectIdArray mXBTRidArray;
  63. bool mbIntTNmgmt;
  64. };
  65. /// <summary>
  66. /// The constructor locks the XREF file, checks consistency, and reloads all releated
  67. /// databases than need to be reloaded. The destructor saves changes made to the XREF
  68. /// database back to the XREF file and releases the lock on the XREF file. If there
  69. /// were some objects in the XREF database that are open, it temporarily closes them
  70. /// before doing the save back to the XREF file, and reopens them after the save.
  71. /// </summary>
  72. /// <remarks> This class is at this time for internal use only. </remarks>
  73. ///
  74. class ACDB_PORT AcDbXrefFileLocker
  75. {
  76. public:
  77. /// <summary>
  78. /// Locks the XREF file, checks consistency, and reloads all releated databases than
  79. /// need to be reloaded. If the database ix NULL or not an XREF database, it does not
  80. /// nothing ant treats this condition as an expected condition, so that client code
  81. /// does not need to check what database it passes to the constructor. If there are
  82. /// any opened objects and the XREF database would need to be reloaded, it returns
  83. /// eXrefReloaded ErrorStatus, because it is not possible to reload a database when
  84. /// it has some opened objects in it. </summary>
  85. ///
  86. explicit AcDbXrefFileLocker(AcDbDatabase* pXrefDatabase);
  87. /// <summary> Just calls release(). </summary>
  88. ///
  89. virtual ~AcDbXrefFileLocker();
  90. /// <summary>
  91. /// Saves changes made to the XREF database back to the XREF file and releases the file lock.
  92. /// Subsequent release() calls are no-ops. setSaveBack() allows to control whether to save the
  93. /// changes back to the file or not. If status() != Acad::eOk, it does not update the XREF file.
  94. /// </summary>
  95. ///
  96. void release();
  97. /// <summary>
  98. /// If anything went wrong, non-eOk ErrorStatus is returned.
  99. /// </summary>
  100. ///
  101. Acad::ErrorStatus status() const;
  102. /// <summary>
  103. /// By default changes made to the XREF database are saved back to the XREF file
  104. /// on release() (or destructor) call. This allows not to save back to the XREF file,
  105. /// e.g. when the client operation didn't succeed.
  106. /// </summary>
  107. ///
  108. void setSaveBackToXrefFile(bool yesNo);
  109. static bool isXrefDatabase(const AcDbDatabase* pDatabase);
  110. private: // methods
  111. /// <summary>
  112. /// Collects all AcDbObjects in the XREF database that are opened and that need to be
  113. /// temporarily closed before the modified XREF database is saved to the file, and then
  114. /// reopened.
  115. /// </summary>
  116. ///
  117. void collectAllOpenedObjects(AcDbObjectIdArray& openedObjectIds);
  118. bool hasOpenedObjects();
  119. // Temporarily close the opened objects in the XREF database, so that no objects
  120. // are open when saving the XREF database to file. Reopen the objects back to their
  121. // previous open states after the save is completed
  122. //
  123. void closeOpenedObjects (AcDbObjectIdArray& openedObjectIds, AcArray<AcDb::OpenMode>& openModes, AcArray<int>& openCounts);
  124. void reopenClosedObjects(const AcDbObjectIdArray& openedObjectIds, const AcArray<AcDb::OpenMode>& openModes, const AcArray<int>& openCounts);
  125. private: // data
  126. AcDbDatabase* mpXrefDatabase;
  127. AcEdXrefFileLock mXrefFileLock;
  128. Acad::ErrorStatus mStatus;
  129. bool mSaveBackToXrefFile;
  130. // Disable
  131. AcDbXrefFileLocker();
  132. AcDbXrefFileLocker(const AcDbXrefFileLocker&);
  133. AcDbXrefFileLocker& operator =(AcDbXrefFileLocker&);
  134. };
  135. #pragma pack (pop)
  136. #endif // !_XREFLOCK_H