arxEntryPoint.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. //
  2. //
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Copyright 2015 Autodesk, Inc. All rights reserved.
  6. //
  7. // Use of this software is subject to the terms of the Autodesk license
  8. // agreement provided at the time of installation or download, or which
  9. // otherwise accompanies this software in either electronic or hard copy form.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Written by Cyrille Fauvel
  14. // Autodesk Developer Technical Services
  15. //-----------------------------------------------------------------------------
  16. #pragma once
  17. //-----------------------------------------------------------------------------
  18. #include "dbxEntryPoint.h"
  19. #ifdef __ATLCOM_H__
  20. #include "dynpropmgr.h"
  21. #endif
  22. //-----------------------------------------------------------------------------
  23. struct _ARXCOMMAND_ENTRY {
  24. const ACHAR *pszCmdGroupName ;
  25. const ACHAR *pszCmdGlobalName ;
  26. const ACHAR *pszCmdLocalName ;
  27. Adesk::Int32 commandFlags ;
  28. AcRxFunctionPtr pCmdFct ;
  29. AcEdUIContext *pUIContext ;
  30. UINT localNameID ;
  31. } ;
  32. #pragma section("ARXCOMMAND$__a", read, shared)
  33. #pragma section("ARXCOMMAND$__z", read, shared)
  34. #pragma section("ARXCOMMAND$__m", read, shared)
  35. #ifndef _ADESK_MAC_
  36. #define ARXCOMMAND_FIRST_ENTRYNAME "ARXCOMMAND$__a"
  37. #else
  38. #define ARXCOMMAND_FIRST_ENTRYNAME "ARXCOMMAND$__m"
  39. #endif
  40. #define ARXCOMMAND_LAST_ENTRYNAME "ARXCOMMAND$__z"
  41. extern "C" {
  42. __declspec(selectany) __declspec(allocate(ARXCOMMAND_FIRST_ENTRYNAME)) _ARXCOMMAND_ENTRY* __pArxCmdMapEntryFirst =NULL ;
  43. __declspec(selectany) __declspec(allocate(ARXCOMMAND_LAST_ENTRYNAME)) _ARXCOMMAND_ENTRY* __pArxCmdMapEntryLast =NULL ;
  44. }
  45. #ifndef _ADESK_MAC_
  46. #if defined(_WIN64) || defined(_AC64)
  47. #define ACED_ARXCOMMAND_ENTRY_PRAGMA(group,globCmd) __pragma(comment(linker, "/include:__pArxCmdMap_" #group #globCmd)) ;
  48. #else
  49. #define ACED_ARXCOMMAND_ENTRY_PRAGMA(group,globCmd) __pragma(comment(linker, "/include:___pArxCmdMap_" #group #globCmd)) ;
  50. #endif
  51. #else
  52. #define ACED_ARXCOMMAND_ENTRY_PRAGMA(group,globCmd)
  53. #endif
  54. #define ACED_ARXCOMMAND_ENTRY_AUTO(classname, group, globCmd, locCmd, cmdFlags, UIContext) \
  55. __declspec(selectany) _ARXCOMMAND_ENTRY __ArxCmdMap_##group##globCmd = { _RXST(#group), _RXST(#globCmd), _RXST(#locCmd), cmdFlags, classname::group ##globCmd, UIContext, -1 } ; \
  56. extern "C" __declspec(allocate("ARXCOMMAND$__m")) __declspec(selectany) _ARXCOMMAND_ENTRY* const __pArxCmdMap_##group##globCmd = &__ArxCmdMap_##group##globCmd ; \
  57. ACED_ARXCOMMAND_ENTRY_PRAGMA(group, globCmd)
  58. #define ACED_ARXCOMMAND_ENTRYBYID_AUTO(classname, group, globCmd, locCmdId, cmdFlags, UIContext) \
  59. __declspec(selectany) _ARXCOMMAND_ENTRY __ArxCmdMap_##group##globCmd = { _RXST(#group), _RXST(#globCmd), NULL, cmdFlags, classname::group ##globCmd, UIContext, locCmdId } ; \
  60. extern "C" __declspec(allocate("ARXCOMMAND$__m")) __declspec(selectany) _ARXCOMMAND_ENTRY* const __pArxCmdMap_##group##globCmd = &__ArxCmdMap_##group##globCmd ; \
  61. ACED_ARXCOMMAND_ENTRY_PRAGMA(group, globCmd)
  62. //-----------------------------------------------------------------------------
  63. struct _ADSSYMBOL_ENTRY {
  64. const ACHAR *pszName ;
  65. int (*fptr) () ;
  66. bool bRegFunc ;
  67. UINT nameID ;
  68. } ;
  69. #pragma section("ADSSYMBOL$__a", read, shared)
  70. #pragma section("ADSSYMBOL$__z", read, shared)
  71. #pragma section("ADSSYMBOL$__m", read, shared)
  72. #ifndef _ADESK_MAC_
  73. #define ADSSYMBOL_FIRST_ENTRYNAME "ADSSYMBOL$__a"
  74. #else
  75. #define ADSSYMBOL_FIRST_ENTRYNAME "ADSSYMBOL$__m"
  76. #endif
  77. #define ADSSYMBOL_LAST_ENTRYNAME "ADSSYMBOL$__z"
  78. extern "C" {
  79. __declspec(selectany) __declspec(allocate(ADSSYMBOL_FIRST_ENTRYNAME)) _ADSSYMBOL_ENTRY* __pAdsSymbolMapEntryFirst =NULL ;
  80. __declspec(selectany) __declspec(allocate(ADSSYMBOL_LAST_ENTRYNAME)) _ADSSYMBOL_ENTRY* __pAdsSymbolMapEntryLast =NULL ;
  81. }
  82. #ifndef _ADESK_MAC_
  83. #if defined(_WIN64) || defined(_AC64)
  84. #define ACED_ADSSYMBOL_ENTRY_PRAGMA(name) __pragma(comment(linker, "/include:__pAdsSymbolMap_" #name)) ;
  85. #else
  86. #define ACED_ADSSYMBOL_ENTRY_PRAGMA(name) __pragma(comment(linker, "/include:___pAdsSymbolMap_" #name)) ;
  87. #endif
  88. #else
  89. #define ACED_ADSSYMBOL_ENTRY_PRAGMA(name)
  90. #endif
  91. #define ACED_ADSSYMBOL_ENTRY_AUTO(classname, name, regFunc) \
  92. __declspec(selectany) _ADSSYMBOL_ENTRY __AdsSymbolMap_##name = { _RXST(#name), classname::ads_ ##name, regFunc, -1 } ; \
  93. extern "C" __declspec(allocate("ADSSYMBOL$__m")) __declspec(selectany) _ADSSYMBOL_ENTRY* const __pAdsSymbolMap_##name = &__AdsSymbolMap_##name ; \
  94. ACED_ADSSYMBOL_ENTRY_PRAGMA(name)
  95. #define ACED_ADSCOMMAND_ENTRY_AUTO(classname, name, regFunc) \
  96. __declspec(selectany) _ADSSYMBOL_ENTRY __AdsSymbolMap_##name = { _RXST("c:") _RXST(#name), classname::ads_ ##name, regFunc, -1 } ; \
  97. extern "C" __declspec(allocate("ADSSYMBOL$__m")) __declspec(selectany) _ADSSYMBOL_ENTRY* const __pAdsSymbolMap_##name = &__AdsSymbolMap_##name ; \
  98. ACED_ADSSYMBOL_ENTRY_PRAGMA(name)
  99. #define ACED_ADSSYMBOL_ENTRYBYID_AUTO(classname, name, nameId, regFunc) \
  100. __declspec(selectany) _ADSSYMBOL_ENTRY __AdsSymbolMap_##name = { NULL, classname::ads_ ##name, regFunc, nameId } ; \
  101. extern "C" __declspec(allocate("ADSSYMBOL$__m")) __declspec(selectany) _ADSSYMBOL_ENTRY* const __pAdsSymbolMap_##name = &__AdsSymbolMap_##name ; \
  102. ACED_ADSSYMBOL_ENTRY_PRAGMA(name)
  103. #define ACED_ADSCOMMAND_ENTRYBYID_AUTO(classname, name, nameId, regFunc) \
  104. ACED_ADSSYMBOL_ENTRYBYID_AUTO(classname, name, nameId, regFunc)
  105. //-----------------------------------------------------------------------------
  106. class AcRxArxApp : public AcRxDbxApp {
  107. #ifdef __ATLCOM_H__
  108. protected:
  109. AcRxDynPropManager *m_pDynPropManager ;
  110. #endif
  111. public:
  112. #ifdef __ATLCOM_H__
  113. AcRxArxApp () : AcRxDbxApp (), m_pDynPropManager(NULL) {}
  114. #else
  115. AcRxArxApp () : AcRxDbxApp () {}
  116. #endif
  117. virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
  118. AcRx::AppRetCode retCode =AcRxDbxApp::On_kInitAppMsg (pkt) ;
  119. #ifdef __ATLCOM_H__
  120. //----- Register Dynamic Properties
  121. m_pDynPropManager =new AcRxDynPropManager ;
  122. #endif
  123. //----- Register ARX comamnds
  124. _ARXCOMMAND_ENTRY **ppArxCmdMapEntryFirst =&__pArxCmdMapEntryFirst + 1 ;
  125. _ARXCOMMAND_ENTRY **ppArxCmdMapEntryLast =&__pArxCmdMapEntryLast ;
  126. ACHAR buffer [133] ;
  127. for ( _ARXCOMMAND_ENTRY **ppEntry =ppArxCmdMapEntryFirst ; ppEntry < ppArxCmdMapEntryLast ; ppEntry++ ) {
  128. if ( *ppEntry != NULL ) {
  129. if ( (*ppEntry)->pszCmdLocalName == NULL )
  130. ::LoadString (m_hdllInstance, (*ppEntry)->localNameID, buffer, 132) ;
  131. acedRegCmds->addCommand (
  132. (*ppEntry)->pszCmdGroupName,
  133. (*ppEntry)->pszCmdGlobalName,
  134. (*ppEntry)->pszCmdLocalName == NULL ? buffer : (*ppEntry)->pszCmdLocalName,
  135. (*ppEntry)->commandFlags,
  136. (*ppEntry)->pCmdFct,
  137. (*ppEntry)->pUIContext,
  138. -1,
  139. ((*ppEntry)->commandFlags & ACRX_CMD_SESSION) ? NULL : m_hdllInstance,
  140. NULL
  141. ) ;
  142. }
  143. }
  144. return (retCode) ;
  145. }
  146. virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
  147. AcRx::AppRetCode retCode =AcRxDbxApp::On_kUnloadAppMsg (pkt) ;
  148. #ifdef __ATLCOM_H__
  149. //----- Unregister Dynamic Properties
  150. if ( m_pDynPropManager != NULL ) {
  151. delete m_pDynPropManager ;
  152. m_pDynPropManager =NULL ;
  153. }
  154. #endif
  155. _ARXCOMMAND_ENTRY **ppArxCmdMapEntryFirst =&__pArxCmdMapEntryFirst + 1 ;
  156. _ARXCOMMAND_ENTRY **ppArxCmdMapEntryLast =&__pArxCmdMapEntryLast ;
  157. for ( _ARXCOMMAND_ENTRY **ppEntry =ppArxCmdMapEntryFirst ; ppEntry < ppArxCmdMapEntryLast ; ppEntry++ ) {
  158. if ( *ppEntry != NULL ) {
  159. acedRegCmds->removeCmd (
  160. (*ppEntry)->pszCmdGroupName,
  161. (*ppEntry)->pszCmdGlobalName
  162. ) ;
  163. }
  164. }
  165. return (retCode) ;
  166. }
  167. virtual AcRx::AppRetCode On_kLoadDwgMsg (void *pkt) {
  168. AcRx::AppRetCode retCode =AcRxDbxApp::On_kLoadDwgMsg (pkt) ;
  169. //----- Register ADS Symbols
  170. _ADSSYMBOL_ENTRY **ppAdsSymbolMapEntryFirst =&__pAdsSymbolMapEntryFirst + 1 ;
  171. _ADSSYMBOL_ENTRY **ppAdsSymbolMapEntryLast =&__pAdsSymbolMapEntryLast ;
  172. ACHAR buffer [133] ;
  173. int param =0 ;
  174. for ( _ADSSYMBOL_ENTRY **ppEntry =ppAdsSymbolMapEntryFirst ; ppEntry < ppAdsSymbolMapEntryLast ; ppEntry++ ) {
  175. if ( *ppEntry != NULL ) {
  176. if ( (*ppEntry)->pszName == NULL )
  177. ::LoadString (m_hdllInstance, (*ppEntry)->nameID, buffer, 132) ;
  178. acedDefun (
  179. (*ppEntry)->pszName == NULL ? buffer : (*ppEntry)->pszName,
  180. param
  181. ) ;
  182. if ( (*ppEntry)->bRegFunc == true )
  183. acedRegFunc ((*ppEntry)->fptr, param) ;
  184. param++ ;
  185. }
  186. }
  187. return (retCode) ;
  188. }
  189. virtual AcRx::AppRetCode On_kUnloadDwgMsg (void *pkt) {
  190. AcRx::AppRetCode retCode =AcRxDbxApp::On_kUnloadDwgMsg (pkt) ;
  191. //----- Unregister ADS Symbols
  192. _ADSSYMBOL_ENTRY **ppAdsSymbolMapEntryFirst =&__pAdsSymbolMapEntryFirst + 1 ;
  193. _ADSSYMBOL_ENTRY **ppAdsSymbolMapEntryLast =&__pAdsSymbolMapEntryLast ;
  194. ACHAR buffer [133] ;
  195. int param =0 ;
  196. for ( _ADSSYMBOL_ENTRY **ppEntry =ppAdsSymbolMapEntryFirst ; ppEntry < ppAdsSymbolMapEntryLast ; ppEntry++ ) {
  197. if ( *ppEntry != NULL ) {
  198. if ( (*ppEntry)->pszName == NULL )
  199. ::LoadString (m_hdllInstance, (*ppEntry)->nameID, buffer, 132) ;
  200. acedUndef (
  201. (*ppEntry)->pszName == NULL ? buffer : (*ppEntry)->pszName,
  202. param++
  203. ) ;
  204. }
  205. }
  206. return (retCode) ;
  207. }
  208. virtual AcRx::AppRetCode On_kInvkSubrMsg (void *pkt) {
  209. AcRx::AppRetCode retCode =AcRxDbxApp::On_kInvkSubrMsg (pkt) ;
  210. //----- Dispatch ADS symbol calls
  211. int param =acedGetFunCode () ;
  212. _ADSSYMBOL_ENTRY **ppAdsSymbolMapEntryFirst =&__pAdsSymbolMapEntryFirst + 1 ;
  213. _ADSSYMBOL_ENTRY **ppAdsSymbolMapEntryLast =&__pAdsSymbolMapEntryLast ;
  214. int paramIter =0 ;
  215. for ( _ADSSYMBOL_ENTRY **ppEntry =ppAdsSymbolMapEntryFirst ; ppEntry < ppAdsSymbolMapEntryLast ; ppEntry++ ) {
  216. if ( *ppEntry != NULL ) {
  217. if ( paramIter++ == param ) {
  218. (*((*ppEntry)->fptr)) () ;
  219. break ;
  220. }
  221. }
  222. }
  223. return (retCode) ;
  224. }
  225. } ;