opmexp.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. #ifndef __OPMEXP_H_
  11. #define __OPMEXP_H_
  12. #include "geassign.h" //for asDblArray
  13. #include "dbxutil.h" //for acdbWcs2Ucs
  14. #define BEGIN_ELEMENT_SETGET(theComClass, theArxClass) \
  15. int theComClass::SetGetElementValue(int GetOrSet, DISPID dispid, DWORD cookie, VARIANT *val, AcDbObject *pObj) \
  16. { \
  17. theArxClass *TheArxClass; \
  18. \
  19. if ((TheArxClass = theArxClass::cast(pObj)) == NULL) \
  20. return 0;
  21. #define ELEMENT_GET_ENTRY(DID, ACGEType, getelement, vtype) \
  22. if (dispid == DID) \
  23. { \
  24. ACGEType AcGeType = TheArxClass->##getelement(); \
  25. if (GetOrSet == ELEMENTGET) \
  26. { \
  27. ACGEType AcGeTypeUCS; \
  28. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  29. V_R8(val) = AcGeTypeUCS[cookie]; \
  30. V_VT(val) = VT_R8; \
  31. return 1; \
  32. } \
  33. }
  34. #define COM_ELEMENT_GET_ENTRY(DID, comclass, getfunc, objID) \
  35. if (dispid == DID) \
  36. { \
  37. VARIANT dumVar; \
  38. VariantInit(&dumVar); \
  39. pObj->close(); \
  40. I##comclass *p = static_cast<I##comclass *>(this); \
  41. if(FAILED(p->##getfunc(&dumVar))) \
  42. return 0; \
  43. if (GetOrSet == ELEMENTGET) \
  44. { \
  45. double dPt[3]; double dPtUCS[3]; \
  46. if(FAILED(SafeArrayPointToDoubleArrayPoint(V_ARRAY(&dumVar), dPt))) \
  47. return 0; \
  48. acdbWcs2Ucs(dPt, dPtUCS, 0); \
  49. V_R8(val) = dPtUCS[cookie]; \
  50. V_VT(val) = VT_R8; \
  51. } \
  52. acdbOpenAcDbObject(pObj, objID, AcDb::kForRead); \
  53. return 1; \
  54. }
  55. #define ELEMENT_SETGET_ENTRY(DID, ACGEType, setelement, getelement, vtype) \
  56. if (dispid == DID) \
  57. { \
  58. ACGEType AcGeTypeUCS; \
  59. ACGEType AcGeType = TheArxClass->##getelement(); \
  60. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  61. if (GetOrSet == ELEMENTGET) \
  62. { \
  63. V_R8(val) = AcGeTypeUCS[cookie]; \
  64. V_VT(val) = VT_R8; \
  65. } \
  66. else \
  67. { \
  68. AcGeTypeUCS[cookie] = V_R8(val); \
  69. acdbUcs2Wcs(asDblArray(AcGeTypeUCS), asDblArray(AcGeType), 0); \
  70. TheArxClass->##setelement(AcGeType); \
  71. } \
  72. return 1; \
  73. }
  74. #define ELEMENT_SETGET_ENTRY_GEPNT2D(DID, setelement, getelement, vtype) \
  75. if (dispid == DID) \
  76. { \
  77. AcGePoint3d AcGeTypeUCS; \
  78. AcGePoint2d AcGeType_tmp = TheArxClass->##getelement(); \
  79. AcGePoint3d AcGeType(AcGeType_tmp[0], AcGeType_tmp[1], 0.0); \
  80. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  81. if (GetOrSet == ELEMENTGET) \
  82. { \
  83. V_R8(val) = AcGeTypeUCS[cookie]; \
  84. V_VT(val) = VT_R8; \
  85. } \
  86. else \
  87. { \
  88. AcGeTypeUCS[cookie] = V_R8(val); \
  89. acdbUcs2Wcs(asDblArray(AcGeTypeUCS), asDblArray(AcGeType), 0); \
  90. TheArxClass->##setelement(AcGePoint2d(AcGeType[0], AcGeType[1])); \
  91. } \
  92. return 1; \
  93. }
  94. #define COM_ELEMENT_SETGET_ENTRY(DID, comclass, setfunc, getfunc, objID) \
  95. if (dispid == DID) \
  96. { \
  97. VARIANT dumVar; \
  98. VariantInit(&dumVar); \
  99. pObj->close(); \
  100. \
  101. I##comclass *p = static_cast<I##comclass *>(this); \
  102. if(FAILED(p->##getfunc(&dumVar))) \
  103. return 0; \
  104. \
  105. double dPt[3]; double dPtUCS[3]; \
  106. if(FAILED(SafeArrayPointToDoubleArrayPoint(V_ARRAY(&dumVar), dPt))) \
  107. return 0; \
  108. acdbWcs2Ucs(dPt, dPtUCS, 0); \
  109. \
  110. if (GetOrSet == ELEMENTGET) \
  111. { \
  112. V_R8(val) = dPtUCS[cookie]; \
  113. V_VT(val) = VT_R8; \
  114. } \
  115. else \
  116. { \
  117. dPtUCS[cookie] = V_R8(val); \
  118. acdbUcs2Wcs(dPtUCS, dPt, 0); \
  119. \
  120. SAFEARRAY* pSafeArr; \
  121. if(FAILED(CreateSafeArray(VT_R8, 3, &pSafeArr))) \
  122. return 0; \
  123. if(FAILED(DoubleArrayPointToSafeArrayPoint(dPt,pSafeArr))) \
  124. { \
  125. SafeArrayDestroy(pSafeArr); \
  126. return 0; \
  127. } \
  128. VARIANT var; \
  129. V_ARRAY(&var) = pSafeArr; \
  130. V_VT(&var) = VT_R8 | VT_ARRAY; \
  131. if(FAILED(p->##setfunc(var))) \
  132. { \
  133. SafeArrayDestroy(pSafeArr); \
  134. return 0; \
  135. } \
  136. SafeArrayDestroy(pSafeArr); \
  137. } \
  138. acdbOpenAcDbObject(pObj, objID, AcDb::kForRead); \
  139. return 1; \
  140. }
  141. #define ELEMENT_GROUP_SETGET_ENTRY(DID, CountFunc, ACGEType, setAt, getAt, vtype) \
  142. if (dispid == DID) \
  143. { \
  144. ACAD_OPMPROPMAP_ENTRY *pMap = this->GetOPMPropertyMap();\
  145. if (GetOrSet == ELEMENTCOUNT) \
  146. { \
  147. ULONG cnt = TheArxClass->##CountFunc(); \
  148. V_I4(val) = cnt; \
  149. V_VT(val) = VT_I4; \
  150. return 1; \
  151. } \
  152. \
  153. ACGEType AcGeType; \
  154. long grouping = 1; \
  155. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++) \
  156. { \
  157. if (pMap[i].dispid == dispid) \
  158. { \
  159. grouping = pMap[i].grouping; \
  160. break; \
  161. } \
  162. } \
  163. ACGEType AcGeTypeUCS; \
  164. TheArxClass->##getAt(cookie/grouping, AcGeType); \
  165. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  166. if (GetOrSet == ELEMENTGET) \
  167. { \
  168. V_R8(val) = AcGeTypeUCS[cookie % grouping ]; \
  169. V_VT(val) = VT_R8; \
  170. } \
  171. else \
  172. { \
  173. AcGeTypeUCS[cookie % grouping] = V_R8(val); \
  174. acdbUcs2Wcs(asDblArray(AcGeTypeUCS), asDblArray(AcGeType), 0); \
  175. TheArxClass->##setAt(cookie/grouping, AcGeType); \
  176. } \
  177. return 1; \
  178. }
  179. #define ELEMENT_GROUP2_SETGET_ENTRY(DID, CountFunc, ACGEType, setAt, getAt, vtype) \
  180. if (dispid == DID) \
  181. { \
  182. ACAD_OPMPROPMAP_ENTRY *pMap = this->GetOPMPropertyMap();\
  183. if (GetOrSet == ELEMENTCOUNT) \
  184. { \
  185. ULONG cnt = TheArxClass->##CountFunc(); \
  186. V_I4(val) = cnt; \
  187. V_VT(val) = VT_I4; \
  188. return 1; \
  189. } \
  190. \
  191. ACGEType AcGeType; \
  192. long grouping = 1; \
  193. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++) \
  194. { \
  195. if (pMap[i].dispid == dispid) \
  196. { \
  197. grouping = pMap[i].grouping; \
  198. break; \
  199. } \
  200. } \
  201. \
  202. ACGEType AcGeTypeUCS; \
  203. AcGeType = TheArxClass->##getAt(cookie/grouping); \
  204. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  205. if (GetOrSet == ELEMENTGET) \
  206. { \
  207. V_R8(val) = AcGeTypeUCS[cookie % grouping ]; \
  208. V_VT(val) = VT_R8; \
  209. } \
  210. else \
  211. { \
  212. AcGeTypeUCS[cookie % grouping] = V_R8(val); \
  213. acdbUcs2Wcs(asDblArray(AcGeTypeUCS), asDblArray(AcGeType), 0); \
  214. TheArxClass->##setAt(cookie/grouping, AcGeType); \
  215. } \
  216. return 1; \
  217. }
  218. #define ELEMENT_GROUP3_SETGET_ENTRY(DID, Count, ACGEType, setAt, getAt, vtype) \
  219. if (dispid == DID) \
  220. { \
  221. ACAD_OPMPROPMAP_ENTRY *pMap = this->GetOPMPropertyMap();\
  222. if (GetOrSet == ELEMENTCOUNT) \
  223. { \
  224. ULONG cnt = Count; \
  225. V_I4(val) = cnt; \
  226. V_VT(val) = VT_I4; \
  227. return 1; \
  228. } \
  229. \
  230. ACGEType AcGeType; \
  231. long grouping = 1; \
  232. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++) \
  233. { \
  234. if (pMap[i].dispid == dispid) \
  235. { \
  236. grouping = pMap[i].grouping; \
  237. break; \
  238. } \
  239. } \
  240. \
  241. ACGEType AcGeTypeUCS; \
  242. TheArxClass->##getAt((Adesk::UInt16)(cookie/grouping), AcGeType); \
  243. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  244. if (GetOrSet == ELEMENTGET) \
  245. { \
  246. V_R8(val) = AcGeTypeUCS[cookie % grouping ]; \
  247. V_VT(val) = VT_R8; \
  248. } \
  249. else \
  250. { \
  251. AcGeTypeUCS[cookie % grouping] = V_R8(val); \
  252. acdbUcs2Wcs(asDblArray(AcGeTypeUCS), asDblArray(AcGeType), 0); \
  253. TheArxClass->##setAt((Adesk::UInt16)(cookie/grouping), AcGeType); \
  254. } \
  255. return 1; \
  256. }
  257. #define ELEMENT_ACDB_ITERATE_SETGET_ENTRY(DID, Iter, recordt, ACGEType, setelem, getelem, vtype) \
  258. if (dispid == DID) \
  259. { \
  260. AcDbObjectIterator* pIter = NULL; \
  261. ACAD_OPMPROPMAP_ENTRY *pMap = this->GetOPMPropertyMap();\
  262. if (GetOrSet == ELEMENTCOUNT) \
  263. { \
  264. ULONG cnt = 0; \
  265. pIter = TheArxClass-> Iter##(); \
  266. for (pIter->start(); !pIter->done(); pIter->step())cnt++; \
  267. delete pIter; \
  268. V_I4(val) = cnt; \
  269. V_VT(val) = VT_I4; \
  270. return 1; \
  271. } \
  272. \
  273. ACGEType AcGeType; \
  274. long grouping = 1; \
  275. for(int i = 0; pMap[i].pclsidPropPage != NULL; i++) \
  276. { \
  277. if (pMap[i].dispid == dispid) \
  278. { \
  279. grouping = pMap[i].grouping; \
  280. break; \
  281. } \
  282. } \
  283. \
  284. int j = 0; \
  285. int vert = cookie/grouping; \
  286. pIter = TheArxClass->Iter(); \
  287. \
  288. for (pIter->start(); !pIter->done(); pIter->step()) \
  289. { \
  290. if (j == vert) \
  291. break; \
  292. else \
  293. j++; \
  294. } \
  295. Acad::ErrorStatus es; \
  296. AcDbObjectId objID = pIter->objectId(); \
  297. recordt *record; \
  298. AcDbObject *pRecObj; \
  299. \
  300. delete pIter; \
  301. \
  302. if (j != vert) \
  303. return 0; \
  304. \
  305. if ((es = acdbOpenAcDbObject(pRecObj, objID, \
  306. GetOrSet == ELEMENTGET ? AcDb::kForRead : \
  307. AcDb::kForWrite)) != Acad::eOk) \
  308. return 0; \
  309. \
  310. if ((record = recordt##::cast(pRecObj)) == NULL) \
  311. { \
  312. pRecObj->close(); \
  313. return 0; \
  314. } \
  315. \
  316. ACGEType AcGeTypeUCS; \
  317. AcGeType = record-> getelem##(); \
  318. acdbWcs2Ucs(asDblArray(AcGeType), asDblArray(AcGeTypeUCS), 0); \
  319. if (GetOrSet == ELEMENTGET) \
  320. { \
  321. \
  322. V_R8(val) = AcGeTypeUCS[cookie % grouping ]; \
  323. V_VT(val) = VT_R8; \
  324. } \
  325. else \
  326. { \
  327. AcGeTypeUCS[cookie % grouping] = V_R8(val); \
  328. acdbUcs2Wcs(asDblArray(AcGeTypeUCS), asDblArray(AcGeType), 0); \
  329. record-> setelem##(AcGeType); \
  330. } \
  331. \
  332. record->close(); \
  333. return 1; \
  334. }
  335. #define END_ELEMENT_SETGET \
  336. return 0; \
  337. }
  338. #endif