acdocman.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // DESCRIPTION: Header for Document and Document Manager Classes.
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #ifndef ACDOCMAN_H
  16. #define ACDOCMAN_H
  17. #include "adesk.h"
  18. #include "accoredefs.h"
  19. #if defined(_ADESK_WINDOWS_)
  20. #include <wtypes.h> // for HINSTANCE
  21. #endif
  22. #include "acdb.h"
  23. #pragma pack (push, 8)
  24. class AcTransactionManager;
  25. class AcDbDatabase;
  26. class CDocument;
  27. class AcEdInputPointManager;
  28. class AcApStatusBar;
  29. class AcApPlotReactor;
  30. class AcRxIterator;
  31. class AcApCommandLineEditor;
  32. struct IDispatch;
  33. // Name of Registered Service Object for constructing AutoCAD-specific
  34. // instances.
  35. //
  36. #define AC_DOCUMENT_MANAGER_OBJ _T("AcApDocManager")
  37. struct AcAp {
  38. // The value order of this enum is important - and determines
  39. // the level of locking. Also, kWrite and kProtectedAutoWrite
  40. // share a common bit - so that (mode & kWrite) will be true
  41. // for either lock mode.
  42. //
  43. enum DocLockMode { kNone = 0x00,
  44. kAutoWrite = 0x01,
  45. kNotLocked = 0x02,
  46. kWrite = 0x04,
  47. kProtectedAutoWrite = 0x14,
  48. kRead = 0x20,
  49. kXWrite = 0x40 };
  50. };
  51. class AcLispAppInfo
  52. {
  53. public:
  54. ACHAR appFileName[_MAX_PATH];
  55. bool bUnloadable;
  56. };
  57. class AcApView;
  58. class IAcApDocumentHost;
  59. class ADESK_NO_VTABLE AcApDocument : public AcRxObject
  60. {
  61. public:
  62. ACRX_DECLARE_MEMBERS(AcApDocument);
  63. // Returns the full path and filename of the database
  64. //
  65. virtual const ACHAR* fileName() const = 0;
  66. // Returns the associated MFC CDocument object
  67. //
  68. virtual CDocument* cDoc() const = 0;
  69. virtual AcTransactionManager* transactionManager() const = 0;
  70. virtual AcDbDatabase* database() const = 0;
  71. // These enum numbers are not random, but correspond to the
  72. // following formula:
  73. // enum value = (Release # - 12) * 4 + (0 for dwg, 1 for dxf, 2 for dwt,
  74. // 3 for dws, 4 for xml). (and xml is obsolete)
  75. //
  76. enum SaveFormat {
  77. kUnknown = -1, // Invalid format
  78. kR12_dxf = 1, // AutoCAD R12/LT2 DXF (*.dxf)
  79. kR13_dwg = 4, // AutoCAD R13/LT95 Drawing (*.dwg)
  80. kR13_dxf = 5, // AutoCAD R13/LT95 DXF (*.dxf)
  81. kR14_dwg = 8, // AutoCAD R14/LT97 Drawing (*.dwg)
  82. kR14_dxf = 9, // AutoCAD R14/LT97 DXF (*.dxf)
  83. k2000_dwg = 12, // AutoCAD 2000 Drawing (*.dwg)
  84. k2000_dxf = 13, // AutoCAD 2000 DXF (*.dxf)
  85. k2000_Template = 14, // 2000 Drawing Template File (*.dwt)
  86. k2000_Standard = 15, // 2000(+) Drawing Standard File (*.dws)
  87. k2000_xml = 16, // 2000(+) = DesignXML v1.0 File (*.xml)
  88. k2004_dwg = 24, // AutoCAD 2004 Drawing (*.dwg)
  89. k2004_dxf = 25, // AutoCAD 2004 DXF (*.dxf)
  90. k2004_Template = 26, // AutoCAD 2004 Template File (*.dwt)
  91. k2004_Standard = 27, // 2004 Drawing Standard File (*.dws)
  92. k2007_dwg = 36, // AutoCAD 2007 Drawing (*.dwg)
  93. k2007_dxf = 37, // AutoCAD 2007 DXF (*.dxf)
  94. k2007_Template = 38, // AutoCAD 2007 Template File (*.dwt)
  95. k2007_Standard = 39, // 2007 Drawing Standard File (*.dws)
  96. k2010_dwg = 48, // AutoCAD 2010 Drawing (*.dwg)
  97. k2010_dxf = 49, // AutoCAD 2010 DXF (*.dxf)
  98. k2010_Template = 50, // AutoCAD 2010 Template File (*.dwt)
  99. k2010_Standard = 51, // 2010 Drawing Standard File (*.dws)
  100. k2013_dwg = 60, // AutoCAD 2013 Drawing (*.dwg)
  101. k2013_dxf = 61, // AutoCAD 2013 DXF (*.dxf)
  102. k2013_Template = 62, // AutoCAD 2013 Template File (*.dwt)
  103. k2013_Standard = 63, // 2013 Drawing Standard File (*.dws)
  104. kNative = k2013_dwg, // Current dwg version is 2013
  105. kNative_Template = k2013_Template //Current dwt version is 2013
  106. };
  107. virtual SaveFormat formatForSave() const = 0;
  108. ACCORE_PORT static Acad::ErrorStatus getDwgVersionFromSaveFormat(
  109. SaveFormat docFormat,
  110. AcDb::AcDbDwgVersion& dwgVer,
  111. AcDb::MaintenanceReleaseVersion& dwgMaintVer);
  112. virtual AcAp::DocLockMode lockMode(bool bIncludeMyLocks =
  113. false) const = 0;
  114. virtual AcAp::DocLockMode myLockMode() const = 0;
  115. // Is there a command, lisp, script, or ARX command active
  116. virtual bool isQuiescent() const = 0;
  117. // Return the document's context pointer
  118. virtual void * contextPtr() const = 0;
  119. // Return the document's input point manager
  120. virtual AcEdInputPointManager* inputPointManager() = 0;
  121. // Return the documents Window title
  122. virtual const ACHAR * docTitle() const = 0;
  123. ACCORE_PORT void setDocTitle(const ACHAR* title);
  124. // Returns a pointer to the IDispatch object associated with the CDocument object
  125. virtual IDispatch * GetIDispatch(bool bAddRef) = 0;
  126. // Return TRUE if the document is read only else false
  127. virtual bool isReadOnly() const = 0;
  128. // Access to the list of loaded Lisp applications
  129. virtual int GetCountOfLispList() const = 0;
  130. virtual AcLispAppInfo* GetItemOfLispList(int nIndex) const = 0;
  131. // Return the drawing status bar
  132. virtual AcApStatusBar* drawingStatusBar() const = 0;
  133. // return whether command input is currently inactive
  134. virtual bool isCommandInputInactive() const = 0;
  135. // Push/pop the current value of $DBMOD. Non-virtual is intentional.
  136. void pushDbmod();
  137. Acad::ErrorStatus popDbmod();
  138. // Convert the document status from read only to write if possible.
  139. //
  140. Acad::ErrorStatus upgradeDocOpen();
  141. // Convert the document status from writeable to read only.
  142. // If bPromptForSave is true - and the drawing is modified (based on dbmod)
  143. // the user is prompted to save the drawing. If bPromptForSave is
  144. // false and the drawing has been modified, an error is returned.
  145. //
  146. Acad::ErrorStatus downgradeDocOpen(bool bPromptForSave);
  147. ///<summary>
  148. ///Retrieves the one and only view associated with this document.
  149. ///</summary>
  150. ACCORE_PORT AcApView* view() const;
  151. ACCORE_PORT AcApCommandLineEditor* commandLineEditor() const;
  152. ACCORE_PORT void setHost(IAcApDocumentHost* pHost);
  153. ACCORE_PORT bool isNamedDrawing() const;
  154. };
  155. // These two functions are to be deprecated
  156. Acad::ErrorStatus acedUpgradeDocOpen();
  157. Acad::ErrorStatus acedDowngradeDocOpen(bool bPromptForSave);
  158. class ADESK_NO_VTABLE AcApDocManagerReactor : public AcRxObject
  159. {
  160. public:
  161. ACRX_DECLARE_MEMBERS(AcApDocManagerReactor);
  162. // Fired when a document is first instantiated no database is available.
  163. virtual void documentCreateStarted(AcApDocument* pDocCreating);
  164. // Fired when a document has been successfully created replaces kLoadDwgMsg.
  165. virtual void documentCreated(AcApDocument* pDocCreating);
  166. // Fired when a document is about to be destroyed replaces kUnloadDwgMsg
  167. virtual void documentToBeDestroyed(AcApDocument* pDocToDestroy);
  168. // Fired when a document is completely destroyed
  169. virtual void documentDestroyed(const ACHAR* fileName);
  170. // Fired when a user action has cancelled a documents creation.
  171. // Only fired in MDI mode and after a documentCreateStarted
  172. virtual void documentCreateCanceled(AcApDocument* pDocCreateCancelled);
  173. virtual void documentLockModeWillChange(AcApDocument* ,
  174. AcAp::DocLockMode myCurrentMode,
  175. AcAp::DocLockMode myNewMode,
  176. AcAp::DocLockMode currentMode,
  177. const ACHAR* pGlobalCmdName);
  178. virtual void documentLockModeChangeVetoed(AcApDocument* ,
  179. const ACHAR* pGlobalCmdName);
  180. virtual void documentLockModeChanged(AcApDocument* ,
  181. AcAp::DocLockMode myPreviousMode,
  182. AcAp::DocLockMode myCurrentMode,
  183. AcAp::DocLockMode currentMode,
  184. const ACHAR* pGlobalCmdName);
  185. virtual void documentBecameCurrent(AcApDocument* );
  186. // This reactor is fired PRIOR to a document becoming activated NOTE: The document
  187. // context will not be set yet see also documentActivated()
  188. virtual void documentToBeActivated(AcApDocument* pActivatingDoc );
  189. // Parallel to documentToBeActivated
  190. virtual void documentToBeDeactivated(AcApDocument* pDeActivatedDoc );
  191. // Notify of changes caused by disableDocumentActivation() or enableDocumentActivation().
  192. // bActivation == TRUE when document activation is enabled FALSE when disabled.
  193. virtual void documentActivationModified(bool bActivation);
  194. // This reactor is fired once a document has been activated and its context
  195. // successfully switched. NOTE: There are situations where document is
  196. // "activated" outside the normal UI user interaction. See also documentToBeActivated
  197. virtual void documentActivated(AcApDocument* pActivatedDoc);
  198. protected:
  199. AcApDocManagerReactor() : mVeto(0) {}
  200. Acad::ErrorStatus veto();
  201. private:
  202. Adesk::Int8 mVeto;
  203. friend class AcApDocImpManager;
  204. };
  205. class ADESK_NO_VTABLE AcApDocumentIterator : public AcRxObject
  206. {
  207. public:
  208. ACRX_DECLARE_MEMBERS(AcApDocumentIterator);
  209. virtual bool done() const = 0;
  210. virtual void step() = 0;
  211. virtual AcApDocument* document() = 0;
  212. };
  213. class IAcApDocManagerHost;
  214. class ADESK_NO_VTABLE AcApDocManager : public AcRxObject
  215. {
  216. public:
  217. ACRX_DECLARE_MEMBERS(AcApDocManager);
  218. // curDocument() returns the document having current context.
  219. // mdiActiveDocument() returns the MDI active document.
  220. // curDocument() and mdiActiveDocument() can be different.
  221. // You can call curDocument() to make a document "current"
  222. // without actually activating it. After finish your AcDbDatabase
  223. // operation under the temporary current document, call
  224. // setCurDocument(acDocManager->mdiActiveDocument())
  225. // to reset the MDI active document as the current document.
  226. virtual AcApDocument* curDocument() const = 0;
  227. virtual AcApDocument* mdiActiveDocument() const = 0;
  228. virtual bool isApplicationContext() const = 0;
  229. virtual AcApDocument* document(const AcDbDatabase* ) const = 0;
  230. virtual Acad::ErrorStatus lockDocument(AcApDocument* pDoc,
  231. AcAp::DocLockMode = AcAp::kWrite,
  232. const ACHAR* pGlobalCmdName = NULL,
  233. const ACHAR* pLocalCmdName = NULL,
  234. bool prompt = true) = 0;
  235. virtual Acad::ErrorStatus unlockDocument(AcApDocument* pDoc) = 0;
  236. virtual AcApDocumentIterator* newAcApDocumentIterator() = 0;
  237. virtual void addReactor(AcApDocManagerReactor* ) = 0;
  238. virtual void removeReactor(AcApDocManagerReactor* ) = 0;
  239. virtual Acad::ErrorStatus setDefaultFormatForSave(
  240. AcApDocument::SaveFormat format) = 0;
  241. virtual AcApDocument::SaveFormat defaultFormatForSave() const = 0;
  242. // Allows an external application running under the Application context
  243. // to make a document "current" without actually activating it.
  244. // This current state is only valid during the context of the function
  245. // calling this API. This enables safe manipulation of a documents
  246. // data without the document actually being the top most or
  247. // active document.
  248. // The default parameters "mode" and "activate" allow document locking
  249. // and activation to occur. These are shortcuts to allow several
  250. // steps to be accomplished with a single API and can also
  251. // be accomplished with the individual API calls.
  252. virtual Acad::ErrorStatus setCurDocument(AcApDocument* pDoc,
  253. AcAp::DocLockMode = AcAp::kNone,
  254. bool activate = false) = 0;
  255. // Activate target document
  256. virtual Acad::ErrorStatus activateDocument(AcApDocument* pAcTargetDocument,
  257. bool bPassScript = false) = 0;
  258. // Send string to target document to execute by default
  259. // activate document. Allow the string to be executed as soon as
  260. // possible if "bActivate" is false" and "bWrapUpInactiveDoc" is true.
  261. // "bEchoString" determines whether the sent string is echoed on the
  262. // command line.
  263. virtual Acad::ErrorStatus sendStringToExecute(AcApDocument* pAcTargetDocument,
  264. const ACHAR * pszExecute,
  265. bool bActivate = true,
  266. bool bWrapUpInactiveDoc = false,
  267. bool bEchoString = true) = 0;
  268. // These two member functions allow synchronous access to NEW OPEN
  269. // They may only be called from the application context
  270. // See also executeInApplicationContext() These APIs only
  271. // function in MDI mode.
  272. virtual Acad::ErrorStatus appContextNewDocument(const ACHAR *pszTemplateName) = 0;
  273. virtual Acad::ErrorStatus appContextOpenDocument(const ACHAR *pszDrawingName) = 0;
  274. virtual Acad::ErrorStatus appContextRecoverDocument(const ACHAR *pszDrawingName) = 0;
  275. //exactly the same as appContextNewDocument (including preconditions) but prompts for template name
  276. ACCORE_PORT Acad::ErrorStatus appContextPromptNewDocument();
  277. //exactly the same as appContextOpenDocument (including preconditions) but prompts for drawing name
  278. ACCORE_PORT Acad::ErrorStatus appContextPromptOpenDocument();
  279. // Caution: This function immediately destroys the active document and
  280. // a lot of related data, so beware what you reference after calling.
  281. // It can only be invoked from the application context.
  282. ACCORE_PORT Acad::ErrorStatus appContextCloseDocument(AcApDocument* pDoc);
  283. struct DocOpenParams {
  284. union { // drawing file name
  285. const ACHAR * mpszFileName;
  286. const wchar_t * mpwszFileName;
  287. };
  288. union { // layout or view name, or handle string
  289. const ACHAR * mpszViewName;
  290. const wchar_t * mpwszViewName;
  291. const double * mpCoords; // or world coords to zoom to
  292. };
  293. enum {kUnknown = 0, // not used
  294. kDefaultView = 1, // open in last saved view
  295. kLayoutName = 2, // specify layout by name
  296. kViewName = 3, // specify view by name
  297. kLayoutHandle = 4, // specify layout by acdb handle
  298. kViewHandle = 5, // specify view by acdb handle
  299. kViewWorldCoords = 6};
  300. BYTE mnInitialViewType;
  301. enum { kDisallowReadOnly = 0x01,
  302. kRequireReadOnly = 0x02,
  303. kFileNameArgIsUnicode = 0x04,
  304. kViewNameArgIsUnicode = 0x08,
  305. kUseUIOnErrors = 0x10,
  306. kOwnerControlled = 0x20,
  307. kUseUI = 0x40 }; // allow popup/confirmation messages
  308. int mnFlags; // open it as readonly, etc
  309. const wchar_t * mpwszPassword;
  310. void * mpOwnerData;
  311. void * mpUnused;
  312. int mnUnused;
  313. const wchar_t * mpwszTitle;
  314. };
  315. // Open a drawing and switch to the layout or view specified, if any.
  316. virtual Acad::ErrorStatus appContextOpenDocument(const DocOpenParams *pParams) = 0;
  317. // These three member functions provide standard, full user interaction,
  318. // to the NEW OPEN and CLOSE commands. They are asynchronous so if called
  319. // from a document context they will suspend the currently executing routine
  320. // until the orginal document context is re-activated.
  321. virtual Acad::ErrorStatus newDocument() = 0;
  322. virtual Acad::ErrorStatus openDocument() = 0;
  323. virtual Acad::ErrorStatus closeDocument(AcApDocument* pAcTargetDocument) = 0;
  324. // Return the state of the documents input buffer in characters pending.
  325. // A return value of zero indicates the document is not "currently"
  326. // processing. Used only in conjunction with sendStringToExecute()
  327. // for automated testing purposes. Return -1 if error
  328. virtual int inputPending(AcApDocument* pAcTargetDocument) = 0;
  329. // APIs to allow control of whether a user can activate another
  330. // document. May be used by commands that process for long periods of time
  331. // and wish to allow special cancelation checking without the chance
  332. // the user might be able to activate another document.
  333. // Aplications MUST be sure to restore activation when complete.
  334. // Attempts to disable or enable when already in the requested state
  335. // will return an error
  336. virtual Acad::ErrorStatus disableDocumentActivation() = 0;
  337. virtual Acad::ErrorStatus enableDocumentActivation() = 0;
  338. virtual bool isDocumentActivationEnabled() = 0;
  339. // Allows a void function() to be called from the application context
  340. virtual void executeInApplicationContext(void (*procAddr)(void *), void *pData ) const = 0;
  341. ///<summary>
  342. /// Allows anonymous code execution in command context (same as registering a command
  343. /// and calling sendStringToExecute to invoke it.). The command will be executed in the context
  344. /// of the mdi active document. The callback function will be called when the system has a chance to
  345. /// execute a command. This, at minimum, means that the caller of beginExecuteInCommandContext
  346. /// (i.e. your code) must return to its caller. All outstanding commands will be cancelled before
  347. /// the callback function is invoked.
  348. ///</summary>
  349. ///<param name="procAddr"> Required. The name of the callback function to be called. </param>
  350. ///<param name="pData" > Optional. Pointer to the data that will be passed to the callback.
  351. /// It is the caller's responsibility to make sure that the pointer remains valid until the
  352. /// callback is called. </param>
  353. ///<returns>
  354. /// Acad::eOk : if the request is successfully queued.
  355. /// Acad::eInvalidContext: if the call is made while AcApDocManager::isApplicationContext()==false.
  356. /// Acad::eInvalidInput: if procAddr is NULL.
  357. /// Acad::eNoDocument: if the call is made while AcApDocManager::mdiActiveDocument() == NULL.
  358. ///</returns>
  359. ACCORE_PORT Acad::ErrorStatus beginExecuteInCommandContext(void (*procAddr)(void *), void *pData);
  360. // Return the number of currently open documents
  361. virtual int documentCount() const = 0;
  362. // Handle setting/saving/restoring of resouce file handles
  363. // pushResouceHandle pushes the current resource handle onto the
  364. // current document's resource handle stack and makes the specified
  365. // handle current. pushAcadResourceHandle pushes the current resource
  366. // handle onto the current document's resource handle stack and makes
  367. // AutoCAD's resource file current. popResourceHandle makes the
  368. // resource file handle on top of the stack current and removes it from
  369. // the stack.
  370. virtual void pushResourceHandle( HINSTANCE hNewResourceHandle) = 0;
  371. virtual void pushAcadResourceHandle() = 0;
  372. virtual void popResourceHandle() = 0;
  373. // Causes a document waiting for input to return to the caller
  374. virtual Acad::ErrorStatus sendModelessInterrupt(AcApDocument* pAcTargetDocument) = 0;
  375. ACCORE_PORT void setHost(IAcApDocManagerHost* pHost);
  376. };
  377. ACCORE_PORT AcApDocManager* acDocManagerPtr();
  378. #define acDocManager acDocManagerPtr()
  379. inline AcApDocument* curDoc() { return ::acDocManager->curDocument(); }
  380. #pragma pack (pop)
  381. #endif // ACDOCMAND_H