You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

548 lines
17 KiB

  1. /****************************************************************************
  2. ** Copyright (C) 2001-2013 RibbonSoft, GmbH. All rights reserved.
  3. ** Copyright (C) 2001 Robert J. Campbell Jr.
  4. **
  5. ** This file is part of the dxflib project.
  6. **
  7. ** This file is free software; you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation; either version 2 of the License, or
  10. ** (at your option) any later version.
  11. **
  12. ** Licensees holding valid dxflib Professional Edition licenses may use
  13. ** this file in accordance with the dxflib Commercial License
  14. ** Agreement provided with the Software.
  15. **
  16. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  17. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18. **
  19. ** See http://www.ribbonsoft.com for further details.
  20. **
  21. ** Contact info@ribbonsoft.com if any conditions of this licensing are
  22. ** not clear to you.
  23. **
  24. **********************************************************************/
  25. /**
  26. * Defines common DXF codes and constants.
  27. */
  28. #ifndef DXF_CODES_H
  29. #define DXF_CODES_H
  30. #include "dl_global.h"
  31. #if defined(__OS2__)||defined(__EMX__)
  32. #define strcasecmp( s, t ) stricmp( s, t )
  33. #endif
  34. #if defined(_WIN32)
  35. #ifndef strcasecmp // on mingw, strcasecmp is defined
  36. #define strcasecmp( s, t ) stricmp( s, t )
  37. #endif
  38. #endif
  39. #ifdef _WIN32
  40. #undef M_PI
  41. #define M_PI 3.14159265358979323846
  42. #endif
  43. #ifndef M_PI
  44. #define M_PI 3.1415926535897932384626433832795
  45. #endif
  46. #define DL_DXF_MAXLINE 1024
  47. #define DL_DXF_MAXGROUPCODE 1100
  48. // used to mark invalid vectors:
  49. // #define DL_DXF_MAXDOUBLE 1.0E+10
  50. /**
  51. * Codes for colors and DXF versions.
  52. */
  53. class DXFLIB_EXPORT DL_Codes
  54. {
  55. public:
  56. /**
  57. * Standard DXF colors.
  58. */
  59. enum color
  60. {
  61. black = 250,
  62. green = 3,
  63. red = 1,
  64. brown = 15,
  65. yellow = 2,
  66. cyan = 4,
  67. magenta = 6,
  68. gray = 8,
  69. blue = 5,
  70. l_blue = 163,
  71. l_green = 121,
  72. l_cyan = 131,
  73. l_red = 23,
  74. l_magenta = 221,
  75. l_gray = 252,
  76. white = 7,
  77. bylayer = 256,
  78. byblock = 0
  79. };
  80. /**
  81. * Version numbers for the DXF Format.
  82. */
  83. enum version
  84. {
  85. AC1009_MIN, // R12, minimalistic
  86. AC1009, // R12
  87. AC1012,
  88. AC1014,
  89. AC1015 // R2000
  90. };
  91. };
  92. // Extended color palette:
  93. // The first entry is only for direct indexing starting with [1]
  94. // Color 1 is red (1,0,0)
  95. const double dxfColors[][3] =
  96. {
  97. { 0, 0, 0 }, // unused
  98. { 1, 0, 0 }, // 1
  99. { 1, 1, 0 },
  100. { 0, 1, 0 },
  101. { 0, 1, 1 },
  102. { 0, 0, 1 },
  103. { 1, 0, 1 },
  104. { 1, 1, 1 }, // black or white
  105. { 0.5, 0.5, 0.5 },
  106. { 0.75, 0.75, 0.75 },
  107. { 1, 0, 0 }, // 10
  108. { 1, 0.5, 0.5 },
  109. { 0.65, 0, 0 },
  110. { 0.65, 0.325, 0.325 },
  111. { 0.5, 0, 0 },
  112. { 0.5, 0.25, 0.25 },
  113. { 0.3, 0, 0 },
  114. { 0.3, 0.15, 0.15 },
  115. { 0.15, 0, 0 },
  116. { 0.15, 0.075, 0.075 },
  117. { 1, 0.25, 0 }, // 20
  118. { 1, 0.625, 0.5 },
  119. { 0.65, 0.1625, 0 },
  120. { 0.65, 0.4063, 0.325 },
  121. { 0.5, 0.125, 0 },
  122. { 0.5, 0.3125, 0.25 },
  123. { 0.3, 0.075, 0 },
  124. { 0.3, 0.1875, 0.15 },
  125. { 0.15, 0.0375, 0 },
  126. { 0.15, 0.0938, 0.075 },
  127. { 1, 0.5, 0 }, // 30
  128. { 1, 0.75, 0.5 },
  129. { 0.65, 0.325, 0 },
  130. { 0.65, 0.4875, 0.325 },
  131. { 0.5, 0.25, 0 },
  132. { 0.5, 0.375, 0.25 },
  133. { 0.3, 0.15, 0 },
  134. { 0.3, 0.225, 0.15 },
  135. { 0.15, 0.075, 0 },
  136. { 0.15, 0.1125, 0.075 },
  137. { 1, 0.75, 0 }, // 40
  138. { 1, 0.875, 0.5 },
  139. { 0.65, 0.4875, 0 },
  140. { 0.65, 0.5688, 0.325 },
  141. { 0.5, 0.375, 0 },
  142. { 0.5, 0.4375, 0.25 },
  143. { 0.3, 0.225, 0 },
  144. { 0.3, 0.2625, 0.15 },
  145. { 0.15, 0.1125, 0 },
  146. { 0.15, 0.1313, 0.075 },
  147. { 1, 1, 0 }, // 50
  148. { 1, 1, 0.5 },
  149. { 0.65, 0.65, 0 },
  150. { 0.65, 0.65, 0.325 },
  151. { 0.5, 0.5, 0 },
  152. { 0.5, 0.5, 0.25 },
  153. { 0.3, 0.3, 0 },
  154. { 0.3, 0.3, 0.15 },
  155. { 0.15, 0.15, 0 },
  156. { 0.15, 0.15, 0.075 },
  157. { 0.75, 1, 0 }, // 60
  158. { 0.875, 1, 0.5 },
  159. { 0.4875, 0.65, 0 },
  160. { 0.5688, 0.65, 0.325 },
  161. { 0.375, 0.5, 0 },
  162. { 0.4375, 0.5, 0.25 },
  163. { 0.225, 0.3, 0 },
  164. { 0.2625, 0.3, 0.15 },
  165. { 0.1125, 0.15, 0 },
  166. { 0.1313, 0.15, 0.075 },
  167. { 0.5, 1, 0 }, // 70
  168. { 0.75, 1, 0.5 },
  169. { 0.325, 0.65, 0 },
  170. { 0.4875, 0.65, 0.325 },
  171. { 0.25, 0.5, 0 },
  172. { 0.375, 0.5, 0.25 },
  173. { 0.15, 0.3, 0 },
  174. { 0.225, 0.3, 0.15 },
  175. { 0.075, 0.15, 0 },
  176. { 0.1125, 0.15, 0.075 },
  177. { 0.25, 1, 0 }, // 80
  178. { 0.625, 1, 0.5 },
  179. { 0.1625, 0.65, 0 },
  180. { 0.4063, 0.65, 0.325 },
  181. { 0.125, 0.5, 0 },
  182. { 0.3125, 0.5, 0.25 },
  183. { 0.075, 0.3, 0 },
  184. { 0.1875, 0.3, 0.15 },
  185. { 0.0375, 0.15, 0 },
  186. { 0.0938, 0.15, 0.075 },
  187. { 0, 1, 0 }, // 90
  188. { 0.5, 1, 0.5 },
  189. { 0, 0.65, 0 },
  190. { 0.325, 0.65, 0.325 },
  191. { 0, 0.5, 0 },
  192. { 0.25, 0.5, 0.25 },
  193. { 0, 0.3, 0 },
  194. { 0.15, 0.3, 0.15 },
  195. { 0, 0.15, 0 },
  196. { 0.075, 0.15, 0.075 },
  197. { 0, 1, 0.25 }, // 100
  198. { 0.5, 1, 0.625 },
  199. { 0, 0.65, 0.1625 },
  200. { 0.325, 0.65, 0.4063 },
  201. { 0, 0.5, 0.125 },
  202. { 0.25, 0.5, 0.3125 },
  203. { 0, 0.3, 0.075 },
  204. { 0.15, 0.3, 0.1875 },
  205. { 0, 0.15, 0.0375 },
  206. { 0.075, 0.15, 0.0938 },
  207. { 0, 1, 0.5 }, // 110
  208. { 0.5, 1, 0.75 },
  209. { 0, 0.65, 0.325 },
  210. { 0.325, 0.65, 0.4875 },
  211. { 0, 0.5, 0.25 },
  212. { 0.25, 0.5, 0.375 },
  213. { 0, 0.3, 0.15 },
  214. { 0.15, 0.3, 0.225 },
  215. { 0, 0.15, 0.075 },
  216. { 0.075, 0.15, 0.1125 },
  217. { 0, 1, 0.75 }, // 120
  218. { 0.5, 1, 0.875 },
  219. { 0, 0.65, 0.4875 },
  220. { 0.325, 0.65, 0.5688 },
  221. { 0, 0.5, 0.375 },
  222. { 0.25, 0.5, 0.4375 },
  223. { 0, 0.3, 0.225 },
  224. { 0.15, 0.3, 0.2625 },
  225. { 0, 0.15, 0.1125 },
  226. { 0.075, 0.15, 0.1313 },
  227. { 0, 1, 1 }, // 130
  228. { 0.5, 1, 1 },
  229. { 0, 0.65, 0.65 },
  230. { 0.325, 0.65, 0.65 },
  231. { 0, 0.5, 0.5 },
  232. { 0.25, 0.5, 0.5 },
  233. { 0, 0.3, 0.3 },
  234. { 0.15, 0.3, 0.3 },
  235. { 0, 0.15, 0.15 },
  236. { 0.075, 0.15, 0.15 },
  237. { 0, 0.75, 1 }, // 140
  238. { 0.5, 0.875, 1 },
  239. { 0, 0.4875, 0.65 },
  240. { 0.325, 0.5688, 0.65 },
  241. { 0, 0.375, 0.5 },
  242. { 0.25, 0.4375, 0.5 },
  243. { 0, 0.225, 0.3 },
  244. { 0.15, 0.2625, 0.3 },
  245. { 0, 0.1125, 0.15 },
  246. { 0.075, 0.1313, 0.15 },
  247. { 0, 0.5, 1 }, // 150
  248. { 0.5, 0.75, 1 },
  249. { 0, 0.325, 0.65 },
  250. { 0.325, 0.4875, 0.65 },
  251. { 0, 0.25, 0.5 },
  252. { 0.25, 0.375, 0.5 },
  253. { 0, 0.15, 0.3 },
  254. { 0.15, 0.225, 0.3 },
  255. { 0, 0.075, 0.15 },
  256. { 0.075, 0.1125, 0.15 },
  257. { 0, 0.25, 1 }, // 160
  258. { 0.5, 0.625, 1 },
  259. { 0, 0.1625, 0.65 },
  260. { 0.325, 0.4063, 0.65 },
  261. { 0, 0.125, 0.5 },
  262. { 0.25, 0.3125, 0.5 },
  263. { 0, 0.075, 0.3 },
  264. { 0.15, 0.1875, 0.3 },
  265. { 0, 0.0375, 0.15 },
  266. { 0.075, 0.0938, 0.15 },
  267. { 0, 0, 1 }, // 170
  268. { 0.5, 0.5, 1 },
  269. { 0, 0, 0.65 },
  270. { 0.325, 0.325, 0.65 },
  271. { 0, 0, 0.5 },
  272. { 0.25, 0.25, 0.5 },
  273. { 0, 0, 0.3 },
  274. { 0.15, 0.15, 0.3 },
  275. { 0, 0, 0.15 },
  276. { 0.075, 0.075, 0.15 },
  277. { 0.25, 0, 1 }, // 180
  278. { 0.625, 0.5, 1 },
  279. { 0.1625, 0, 0.65 },
  280. { 0.4063, 0.325, 0.65 },
  281. { 0.125, 0, 0.5 },
  282. { 0.3125, 0.25, 0.5 },
  283. { 0.075, 0, 0.3 },
  284. { 0.1875, 0.15, 0.3 },
  285. { 0.0375, 0, 0.15 },
  286. { 0.0938, 0.075, 0.15 },
  287. { 0.5, 0, 1 }, // 190
  288. { 0.75, 0.5, 1 },
  289. { 0.325, 0, 0.65 },
  290. { 0.4875, 0.325, 0.65 },
  291. { 0.25, 0, 0.5 },
  292. { 0.375, 0.25, 0.5 },
  293. { 0.15, 0, 0.3 },
  294. { 0.225, 0.15, 0.3 },
  295. { 0.075, 0, 0.15 },
  296. { 0.1125, 0.075, 0.15 },
  297. { 0.75, 0, 1 }, // 200
  298. { 0.875, 0.5, 1 },
  299. { 0.4875, 0, 0.65 },
  300. { 0.5688, 0.325, 0.65 },
  301. { 0.375, 0, 0.5 },
  302. { 0.4375, 0.25, 0.5 },
  303. { 0.225, 0, 0.3 },
  304. { 0.2625, 0.15, 0.3 },
  305. { 0.1125, 0, 0.15 },
  306. { 0.1313, 0.075, 0.15 },
  307. { 1, 0, 1 }, // 210
  308. { 1, 0.5, 1 },
  309. { 0.65, 0, 0.65 },
  310. { 0.65, 0.325, 0.65 },
  311. { 0.5, 0, 0.5 },
  312. { 0.5, 0.25, 0.5 },
  313. { 0.3, 0, 0.3 },
  314. { 0.3, 0.15, 0.3 },
  315. { 0.15, 0, 0.15 },
  316. { 0.15, 0.075, 0.15 },
  317. { 1, 0, 0.75 }, // 220
  318. { 1, 0.5, 0.875 },
  319. { 0.65, 0, 0.4875 },
  320. { 0.65, 0.325, 0.5688 },
  321. { 0.5, 0, 0.375 },
  322. { 0.5, 0.25, 0.4375 },
  323. { 0.3, 0, 0.225 },
  324. { 0.3, 0.15, 0.2625 },
  325. { 0.15, 0, 0.1125 },
  326. { 0.15, 0.075, 0.1313 },
  327. { 1, 0, 0.5 }, // 230
  328. { 1, 0.5, 0.75 },
  329. { 0.65, 0, 0.325 },
  330. { 0.65, 0.325, 0.4875 },
  331. { 0.5, 0, 0.25 },
  332. { 0.5, 0.25, 0.375 },
  333. { 0.3, 0, 0.15 },
  334. { 0.3, 0.15, 0.225 },
  335. { 0.15, 0, 0.075 },
  336. { 0.15, 0.075, 0.1125 },
  337. { 1, 0, 0.25 }, // 240
  338. { 1, 0.5, 0.625 },
  339. { 0.65, 0, 0.1625 },
  340. { 0.65, 0.325, 0.4063 },
  341. { 0.5, 0, 0.125 },
  342. { 0.5, 0.25, 0.3125 },
  343. { 0.3, 0, 0.075 },
  344. { 0.3, 0.15, 0.1875 },
  345. { 0.15, 0, 0.0375 },
  346. { 0.15, 0.075, 0.0938 },
  347. { 0.33, 0.33, 0.33 }, // 250
  348. { 0.464, 0.464, 0.464 },
  349. { 0.598, 0.598, 0.598 },
  350. { 0.732, 0.732, 0.732 },
  351. { 0.866, 0.866, 0.866 },
  352. { 1, 1, 1 } // 255
  353. }
  354. ;
  355. // AutoCAD VERSION aliases
  356. #define DL_VERSION_R12 DL_Codes::AC1009
  357. #define DL_VERSION_LT2 DL_Codes::AC1009
  358. #define DL_VERSION_R13 DL_Codes::AC1012 // not supported yet
  359. #define DL_VERSION_LT95 DL_Codes::AC1012 // not supported yet
  360. #define DL_VERSION_R14 DL_Codes::AC1014 // not supported yet
  361. #define DL_VERSION_LT97 DL_Codes::AC1014 // not supported yet
  362. #define DL_VERSION_LT98 DL_Codes::AC1014 // not supported yet
  363. #define DL_VERSION_2000 DL_Codes::AC1015
  364. #define DL_VERSION_2002 DL_Codes::AC1015
  365. // DXF Group Codes:
  366. // Strings
  367. #define DL_STRGRP_START 0
  368. #define DL_STRGRP_END 9
  369. // Coordinates
  370. #define DL_CRDGRP_START 10
  371. #define DL_CRDGRP_END 19
  372. // Real values
  373. #define DL_RLGRP_START 38
  374. #define DL_RLGRP_END 59
  375. // Short integer values
  376. #define DL_SHOGRP_START 60
  377. #define DL_SHOGRP_END 79
  378. // New in Release 13,
  379. #define DL_SUBCLASS 100
  380. // More coordinates
  381. #define DL_CRD2GRP_START 210
  382. #define DL_CRD2GRP_END 239
  383. // Extended data strings
  384. #define DL_ESTRGRP_START 1000
  385. #define DL_ESTRGRP_END 1009
  386. // Extended data reals
  387. #define DL_ERLGRP_START 1010
  388. #define DL_ERLGRP_END 1059
  389. #define DL_Y8_COORD_CODE 28
  390. #define DL_Z0_COORD_CODE 30
  391. #define DL_Z8_COORD_CODE 38
  392. #define DL_POINT_COORD_CODE 10
  393. #define DL_INSERT_COORD_CODE 10
  394. #define DL_CRD2GRP_START 210
  395. #define DL_CRD2GRP_END 239
  396. #define DL_THICKNESS 39
  397. #define DL_FIRST_REAL_CODE THICKNESS
  398. #define DL_LAST_REAL_CODE 59
  399. #define DL_FIRST_INT_CODE 60
  400. #define DL_ATTFLAGS_CODE 70
  401. #define DL_PLINE_FLAGS_CODE 70
  402. #define DL_LAYER_FLAGS_CODE 70
  403. #define DL_FLD_LEN_CODE 73 // Inside ATTRIB resbuf
  404. #define DL_LAST_INT_CODE 79
  405. #define DL_X_EXTRU_CODE 210
  406. #define DL_Y_EXTRU_CODE 220
  407. #define DL_Z_EXTRU_CODE 230
  408. #define DL_COMMENT_CODE 999
  409. // Start and endpoints of a line
  410. #define DL_LINE_START_CODE 10 // Followed by x coord
  411. #define DL_LINE_END_CODE 11 // Followed by x coord
  412. // Some codes used by blocks
  413. #define DL_BLOCK_FLAGS_CODE 70 // An int containing flags
  414. #define DL_BLOCK_BASE_CODE 10 // Origin of block definition
  415. #define DL_XREF_DEPENDENT 16 // If a block contains an XREF
  416. #define DL_XREF_RESOLVED 32 // If a XREF resolved ok
  417. #define DL_REFERENCED 64 // If a block is ref'd in DWG
  418. #define DL_XSCALE_CODE 41
  419. #define DL_YSCALE_CODE 42
  420. #define DL_ANGLE_CODE 50
  421. #define DL_INS_POINT_CODE 10 // Followed by x of ins pnt
  422. #define DL_NAME2_CODE 3 // Second appearance of name
  423. // Some codes used by circle entities
  424. #define DL_CENTER_CODE 10 // Followed by x of center
  425. #define DL_RADIUS_CODE 40 // Followd by radius of circle
  426. #define DL_COND_OP_CODE -4 // Conditional op,ads_ssget
  427. // When using ads_buildlist you MUST use RTDXF0 instead of these
  428. #define DL_ENTITY_TYPE_CODE 0 // Then there is LINE, 3DFACE..
  429. #define DL_SES_CODE 0 // Start End String Code
  430. #define DL_FILE_SEP_CODE 0 // File separator
  431. #define DL_SOT_CODE 0 // Start Of Table
  432. #define DL_TEXTVAL_CODE 1
  433. #define DL_NAME_CODE 2
  434. #define DL_BLOCK_NAME_CODE 2
  435. #define DL_SECTION_NAME_CODE 2
  436. #define DL_ENT_HAND_CODE 5 // What follows is hexa string
  437. #define DL_TXT_STYLE_CODE 7 // Inside attributes
  438. #define DL_LAYER_NAME_CODE 8 // What follows is layer name
  439. #define DL_FIRST_XCOORD_CODE 10 // Group code x of 1st coord
  440. #define DL_FIRST_YCOORD_CODE 20 // Group code y of 1st coord
  441. #define DL_FIRST_ZCOORD_CODE 30 // Group code z of 1st coord
  442. #define DL_L_START_CODE 10
  443. #define DL_L_END_CODE 11
  444. #define DL_TXTHI_CODE 40
  445. #define DL_SCALE_X_CODE 41
  446. #define DL_SCALE_Y_CODE 42
  447. #define DL_SCALE_Z_CODE 43
  448. #define DL_BULGE_CODE 42 // Used in PLINE verts for arcs
  449. #define DL_ROTATION_CODE 50
  450. #define DL_COLOUR_CODE 62 // What follows is a color int
  451. #define DL_LTYPE_CODE 6 // What follows is a linetype
  452. // Attribute flags
  453. #define DL_ATTS_FOLLOW_CODE 66
  454. #define DL_ATT_TAG_CODE 2
  455. #define DL_ATT_VAL_CODE 1
  456. #define DL_ATT_FLAGS_CODE 70 // 4 1 bit flags as follows...
  457. #define DL_ATT_INVIS_FLAG 1
  458. #define DL_ATT_CONST_FLAG 2
  459. #define DL_ATT_VERIFY_FLAG 4 // Prompt and verify
  460. #define DL_ATT_PRESET_FLAG 8 // No prompt and no verify
  461. // PLINE defines
  462. // Flags
  463. #define DL_OPEN_PLINE 0x00
  464. #define DL_CLOSED_PLINE 0x01
  465. #define DL_POLYLINE3D 0x80
  466. #define DL_PFACE_MESH 0x40
  467. #define DL_PGON_MESH 0x10
  468. // Vertices follow entity, required in POLYLINES
  469. #define DL_VERTS_FOLLOW_CODE 66 // Value should always be 1
  470. #define DL_VERTEX_COORD_CODE 10
  471. // LAYER flags
  472. #define DL_FROZEN 1
  473. #define DL_FROZEN_BY_DEF 2
  474. #define DL_LOCKED 4
  475. #define DL_OBJECT_USED 64 // Object is ref'd in the dwg
  476. #define DL_BLOCK_EN_CODE -2 // Block entity definition
  477. #define DL_E_NAME -1 // Entity name
  478. // Extended data codes
  479. #define DL_EXTD_SENTINEL (-3)
  480. #define DL_EXTD_STR 1000
  481. #define DL_EXTD_APP_NAME 1001
  482. #define DL_EXTD_CTL_STR 1002
  483. #define DL_EXTD_LYR_STR 1003
  484. #define DL_EXTD_CHUNK 1004
  485. #define DL_EXTD_HANDLE 1005
  486. #define DL_EXTD_POINT 1010
  487. #define DL_EXTD_POS 1011
  488. #define DL_EXTD_DISP 1012
  489. #define DL_EXTD_DIR 1013
  490. #define DL_EXTD_FLOAT 1040
  491. #define DL_EXTD_DIST 1041
  492. #define DL_EXTD_SCALE 1042
  493. #define DL_EXTD_INT16 1070
  494. #define DL_EXTD_INT32 1071
  495. // UCS codes for use in ads_trans
  496. #define DL_WCS_TRANS_CODE 0
  497. #define DL_UCS_TRANS_CODE 1
  498. #define DL_DCS_TRANS_CODE 2
  499. #define DL_PCS_TRANS_CODE 3
  500. #endif