const.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. # Purpose: constant values
  2. # Created: 10.03.2011
  3. # Copyright (c) 2011-2018, Manfred Moitzi
  4. # License: MIT License
  5. acad_release = {
  6. 'AC1009': 'R12',
  7. 'AC1012': 'R13',
  8. 'AC1014': 'R14',
  9. 'AC1015': 'R2000',
  10. 'AC1018': 'R2004',
  11. 'AC1021': 'R2007',
  12. 'AC1024': 'R2010',
  13. 'AC1027': 'R2013',
  14. 'AC1032': 'R2018',
  15. }
  16. versions_supported_by_new = ['AC1009', 'AC1015', 'AC1018', 'AC1021', 'AC1024', 'AC1027', 'AC1032']
  17. LATEST_DXF_VERSION = versions_supported_by_new[-1]
  18. acad_release_to_dxf_version = {
  19. acad: dxf for dxf, acad in acad_release.items()
  20. }
  21. class DXFError(Exception): # root exception
  22. pass
  23. class DXFStructureError(DXFError):
  24. pass
  25. class DXFAppDataError(DXFStructureError):
  26. pass
  27. class DXFXDataError(DXFStructureError):
  28. pass
  29. class DXFVersionError(DXFError):
  30. pass
  31. class DXFInternalEzdxfError(DXFError):
  32. pass
  33. class DXFValueError(DXFError, ValueError):
  34. pass
  35. class DXFKeyError(DXFError, KeyError):
  36. pass
  37. class DXFAttributeError(DXFError, AttributeError):
  38. pass
  39. class DXFIndexError(DXFError, IndexError):
  40. pass
  41. class DXFTypeError(DXFError, TypeError):
  42. pass
  43. class DXFTableEntryError(DXFValueError):
  44. pass
  45. class DXFEncodingError(DXFError):
  46. pass
  47. class DXFDecodingError(DXFError):
  48. pass
  49. class DXFInvalidLayerName(DXFValueError):
  50. pass
  51. class DXFBlockInUseError(DXFValueError):
  52. pass
  53. class DXFUndefinedBlockError(DXFKeyError):
  54. pass
  55. APP_DATA_MARKER = 102
  56. SUBCLASS_MARKER = 100
  57. XDATA_MARKER = 1001
  58. COMMENT_MARKER = 999
  59. STRUCTURE_MARKER = 0
  60. HEADER_VAR_MARKER = 9
  61. # Special tag codes for internal purpose
  62. # -1 to -5 id reserved by AutoCAD for internal use, but this tags will never be saved to file.
  63. # Same approach here, the following tags have to be converted/transformed into normal tags before
  64. # saved to file.
  65. COMPRESSED_TAGS = -10
  66. BYBLOCK = 0
  67. BYLAYER = 256
  68. BYOBJECT = 257
  69. LINEWEIGHT_BYLAYER = -1
  70. LINEWEIGHT_BYBLOCK = -2
  71. LINEWEIGHT_DEFAULT = -3
  72. # Entity: Polyline, Polymesh
  73. # 70 flags
  74. POLYLINE_CLOSED = 1
  75. POLYLINE_MESH_CLOSED_M_DIRECTION = POLYLINE_CLOSED
  76. POLYLINE_CURVE_FIT_VERTICES_ADDED = 2
  77. POLYLINE_SPLINE_FIT_VERTICES_ADDED = 4
  78. POLYLINE_3D_POLYLINE = 8
  79. POLYLINE_3D_POLYMESH = 16
  80. POLYLINE_MESH_CLOSED_N_DIRECTION = 32
  81. POLYLINE_POLYFACE = 64
  82. POLYLINE_GENERATE_LINETYPE_PATTERN = 128
  83. # Entity: Polymesh
  84. # 75 surface smooth type
  85. POLYMESH_NO_SMOOTH = 0
  86. POLYMESH_QUADRATIC_BSPLINE = 5
  87. POLYMESH_CUBIC_BSPLINE = 6
  88. POLYMESH_BEZIER_SURFACE = 8
  89. # Entity: Vertex
  90. # 70 flags
  91. VERTEXNAMES = ('vtx0', 'vtx1', 'vtx2', 'vtx3')
  92. VTX_EXTRA_VERTEX_CREATED = 1 # Extra vertex created by curve-fitting
  93. VTX_CURVE_FIT_TANGENT = 2 # Curve-fit tangent defined for this vertex.
  94. # A curve-fit tangent direction of 0 may be omitted from the DXF output, but is
  95. # significant if this bit is set.
  96. # 4 = unused, never set in dxf files
  97. VTX_SPLINE_VERTEX_CREATED = 8 # Spline vertex created by spline-fitting
  98. VTX_SPLINE_FRAME_CONTROL_POINT = 16
  99. VTX_3D_POLYLINE_VERTEX = 32
  100. VTX_3D_POLYGON_MESH_VERTEX = 64
  101. VTX_3D_POLYFACE_MESH_VERTEX = 128
  102. VERTEX_FLAGS = {
  103. 'AcDb2dPolyline': 0,
  104. 'AcDb3dPolyline': VTX_3D_POLYLINE_VERTEX,
  105. 'AcDbPolygonMesh': VTX_3D_POLYGON_MESH_VERTEX,
  106. 'AcDbPolyFaceMesh': VTX_3D_POLYGON_MESH_VERTEX | VTX_3D_POLYFACE_MESH_VERTEX,
  107. }
  108. POLYLINE_FLAGS = {
  109. 'AcDb2dPolyline': 0,
  110. 'AcDb3dPolyline': POLYLINE_3D_POLYLINE,
  111. 'AcDbPolygonMesh': POLYLINE_3D_POLYMESH,
  112. 'AcDbPolyFaceMesh': POLYLINE_POLYFACE,
  113. }
  114. # block-type flags (bit coded values, may be combined):
  115. # Entity: BLOCK
  116. # 70 flags
  117. # This is an anonymous block generated by hatching, associative dimensioning, other internal operations, or an
  118. # application
  119. BLK_ANONYMOUS = 1
  120. # This block has non-constant attribute definitions (this bit is not set if the block has any attribute definitions that
  121. # are constant, or has no attribute definitions at all)
  122. BLK_NON_CONSTANT_ATTRIBUTES = 2
  123. BLK_XREF = 4 # This block is an external reference (xref)
  124. BLK_XREF_OVERLAY = 8 # This block is an xref overlay
  125. BLK_EXTERNAL = 16 # This block is externally dependent
  126. BLK_RESOLVED = 32 # This is a resolved external reference, or dependent of an external reference (ignored on input)
  127. BLK_REFERENCED = 64 # This definition is a referenced external reference (ignored on input)
  128. LWPOLYLINE_CLOSED = 1
  129. LWPOLYLINE_PLINEGEN = 128
  130. TEXT_ALIGN_FLAGS = {
  131. 'LEFT': (0, 0),
  132. 'CENTER': (1, 0),
  133. 'RIGHT': (2, 0),
  134. 'ALIGNED': (3, 0),
  135. 'MIDDLE': (4, 0),
  136. 'FIT': (5, 0),
  137. 'BOTTOM_LEFT': (0, 1),
  138. 'BOTTOM_CENTER': (1, 1),
  139. 'BOTTOM_RIGHT': (2, 1),
  140. 'MIDDLE_LEFT': (0, 2),
  141. 'MIDDLE_CENTER': (1, 2),
  142. 'MIDDLE_RIGHT': (2, 2),
  143. 'TOP_LEFT': (0, 3),
  144. 'TOP_CENTER': (1, 3),
  145. 'TOP_RIGHT': (2, 3),
  146. }
  147. TEXT_ALIGNMENT_BY_FLAGS = dict((flags, name) for name, flags in TEXT_ALIGN_FLAGS.items())
  148. LEFT = 0
  149. CENTER = 1
  150. RIGHT = 2
  151. BOTTOM = 1
  152. MIDDLE = 2
  153. TOP = 3
  154. MIRROR_X = 2
  155. MIRROR_Y = 4
  156. MTEXT_TOP_LEFT = 1
  157. MTEXT_TOP_CENTER = 2
  158. MTEXT_TOP_RIGHT = 3
  159. MTEXT_MIDDLE_LEFT = 4
  160. MTEXT_MIDDLE_CENTER = 5
  161. MTEXT_MIDDLE_RIGHT = 6
  162. MTEXT_BOTTOM_LEFT = 7
  163. MTEXT_BOTTOM_CENTER = 8
  164. MTEXT_BOTTOM_RIGHT = 9
  165. MTEXT_ALIGN_FLAGS = {
  166. 'TOP_LEFT': 1,
  167. 'TOP_CENTER': 2,
  168. 'TOP_RIGHT': 3,
  169. 'MIDDLE_LEFT': 4,
  170. 'MIDDLE_CENTER': 5,
  171. 'MIDDLE_RIGHT': 6,
  172. 'BOTTOM_LEFT': 7,
  173. 'BOTTOM_CENTER': 8,
  174. 'BOTTOM_RIGHT': 9,
  175. }
  176. MTEXT_LEFT_TO_RIGHT = 1
  177. MTEXT_TOP_TO_BOTTOM = 3
  178. MTEXT_BY_STYLE = 5
  179. MTEXT_AT_LEAST = 1
  180. MTEXT_EXACT = 2
  181. MTEXT_COLOR_INDEX = {
  182. 'red': 1,
  183. 'yellow': 2,
  184. 'green': 3,
  185. 'cyan': 4,
  186. 'blue': 5,
  187. 'magenta': 6,
  188. 'white': 7,
  189. }
  190. MTEXT_BG_OFF = 0
  191. MTEXT_BG_COLOR = 1
  192. MTEXT_BG_WINDOW_COLOR = 2
  193. MTEXT_BG_CANVAS_COLOR = 3
  194. MTEXT_INLINE_ALIGN = {
  195. 'BOTTOM': 0,
  196. 'MIDDLE': 1,
  197. 'TOP': 2,
  198. }
  199. CLOSED_SPLINE = 1
  200. PERIODIC_SPLINE = 2
  201. RATIONAL_SPLINE = 4
  202. PLANAR_SPLINE = 8
  203. LINEAR_SPLINE = 16
  204. # Hatch constants
  205. HATCH_TYPE_USER_DEFINED = 0
  206. HATCH_TYPE_PREDEFINED = 1
  207. HATCH_TYPE_CUSTOM = 2
  208. HATCH_STYLE_NORMAL = 0
  209. HATCH_STYLE_OUTERMOST = 1
  210. HATCH_STYLE_IGNORE = 2
  211. BOUNDARY_PATH_DEFAULT = 0
  212. BOUNDARY_PATH_EXTERNAL = 1
  213. BOUNDARY_PATH_POLYLINE = 2
  214. BOUNDARY_PATH_DERIVED = 4
  215. BOUNDARY_PATH_TEXTBOX = 8
  216. BOUNDARY_PATH_OUTERMOST = 16
  217. GRADIENT_TYPES = frozenset([
  218. 'LINEAR',
  219. 'CYLINDER',
  220. 'INVCYLINDER',
  221. 'SPHERICAL',
  222. 'INVSPHERICAL',
  223. 'HEMISPHERICAL',
  224. 'INVHEMISPHERICAL',
  225. 'CURVED',
  226. 'INVCURVED'
  227. ])
  228. # Viewport Status Flags (VSF) group code=90
  229. VSF_PERSPECTIVE_MODE = 0x1 # enabled if set
  230. VSF_FRONT_CLIPPING = 0x2 # enabled if set
  231. VSF_BACK_CLIPPING = 0x4 # enabled if set
  232. VSF_USC_FOLLOW = 0x8 # enabled if set
  233. VSF_FRONT_CLIPPING_NOT_AT_EYE = 0x10 # enabled if set
  234. VSF_UCS_ICON_VISIBILITY = 0x20 # enabled if set
  235. VSF_UCS_ICON_AT_ORIGIN = 0x40 # enabled if set
  236. VSF_FAST_ZOOM = 0x80 # enabled if set
  237. VSF_SNAP_MODE = 0x100 # enabled if set
  238. VSF_GRID_MODE = 0x200 # enabled if set
  239. VSF_ISOMETRIC_SNAP_STYLE = 0x400 # enabled if set
  240. VSF_HIDE_PLOT_MODE = 0x800 # enabled if set
  241. VSF_KISOPAIR_TOP = 0x1000 # If set and kIsoPairRight is not set, then isopair top is enabled. If both kIsoPairTop and kIsoPairRight are set, then isopair left is enabled
  242. VSF_KISOPAIR_RIGHT = 0x2000 # If set and kIsoPairTop is not set, then isopair right is enabled
  243. VSF_VIEWPORT_ZOOM_LOCKING = 0x4000 # enabled if set
  244. VSF_CURRENTLY_ALWAYS_ENABLED = 0x8000 # always set without a meaning :)
  245. VSF_NON_RECTANGULAR_CLIPPING = 0x10000 # enabled if set
  246. VSF_TURN_VIEWPORT_OFF = 0x20000
  247. # Viewport Render Mode (VRM) group code=281
  248. VRM_2D_OPTIMIZED = 0
  249. VRM_WIREFRAME = 1
  250. VRM_HIDDEN_LINE = 2
  251. VRM_FLAT_SHADED = 3
  252. VRM_GOURAUD_SHADED = 4
  253. VRM_FLAT_SHADED_WITH_WIREFRAME = 5
  254. VRM_GOURAUD_SHADED_WITH_WIREFRAME = 6
  255. IMAGE_SHOW = 1
  256. IMAGE_SHOW_WHEN_NOT_ALIGNED = 2
  257. IMAGE_USE_CLIPPING_BOUNDARY = 4
  258. IMAGE_TRANSPARENCY_IS_ON = 8
  259. UNDERLAY_CLIPPING = 1
  260. UNDERLAY_ON = 2
  261. UNDERLAY_MONOCHROME = 4
  262. UNDERLAY_ADJUST_FOR_BG = 8
  263. DIM_LINEAR = 0
  264. DIM_ALIGNED = 1
  265. DIM_ANGULAR = 2
  266. DIM_DIAMETER = 3
  267. DIM_RADIUS = 4
  268. DIM_ANGULAR_3P = 5
  269. DIM_ORDINATE = 6
  270. DIM_BLOCK_EXCLUSIVE = 32
  271. DIM_ORDINATE_TYPE = 64
  272. DIM_USER_LOCATION_OVERRIDE = 128
  273. DIMZIN_SUPPRESS_ZERO_FEET_AND_PRECISELY_ZERO_INCHES = 0
  274. DIMZIN_INCLUDES_ZERO_FEET_AND_PRECISELY_ZERO_INCHES = 1
  275. DIMZIN_INCLUDES_ZERO_FEET_AND_SUPPRESSES_ZERO_INCHES = 2
  276. DIMZIN_INCLUDES_ZERO_INCHES_AND_SUPPRESSES_ZERO_FEET = 3
  277. DIMZIN_SUPPRESSES_LEADING_ZEROS = 4 # only decimal dimensions
  278. DIMZIN_SUPPRESSES_TRAILING_ZEROS = 8 # only decimal dimensions
  279. # ATTRIB & ATTDEF flags
  280. ATTRIB_INVISIBLE = 1 # Attribute is invisible (does not appear)
  281. ATTRIB_CONST = 2 # This is a constant attribute
  282. ATTRIB_VERIFY = 4 # Verification is required on input of this attribute
  283. ATTRIB_IS_PRESET = 8 # no prompt during insertion
  284. class Error:
  285. MISSING_REQUIRED_ROOT_DICT_ENTRY = 1
  286. DUPLICATE_TABLE_ENTRY_NAME = 2
  287. POINTER_TARGET_NOT_EXISTS = 3
  288. TABLE_NOT_FOUND = 4
  289. UNDEFINED_LINETYPE = 100
  290. UNDEFINED_DIMENSION_STYLE = 101
  291. UNDEFINED_TEXT_STYLE = 102
  292. INVALID_LAYER_NAME = 200
  293. INVALID_COLOR_INDEX = 201
  294. INVALID_OWNER_HANDLE = 202
  295. INVALID_GROUP_CODE_IN_CLASS_DEFINITION = 203
  296. INVALID_LAYER_NAME_CHARACTERS = frozenset(['<', '>', '/', '\\', '"', ':', ';', '?', '*', '|', '=', '`'])
  297. STD_SCALES = {
  298. 1: (1. / 128., 12.),
  299. 2: (1. / 64., 12.),
  300. 3: (1. / 32., 12.),
  301. 4: (1. / 16., 12.),
  302. 5: (3. / 32., 12.),
  303. 6: (1. / 8., 12.),
  304. 7: (3. / 16., 12.),
  305. 8: (1. / 4., 12.),
  306. 9: (3. / 8., 12.),
  307. 10: (1. / 2., 12.),
  308. 11: (3. / 4., 12.),
  309. 12: (1., 12.),
  310. 13: (3., 12.),
  311. 14: (6., 12.),
  312. 15: (12., 12.),
  313. 16: (1., 1.),
  314. 17: (1., 2.),
  315. 18: (1., 4.),
  316. 19: (1., 8.),
  317. 20: (1., 10.),
  318. 21: (1., 16.),
  319. 22: (1., 20.),
  320. 23: (1., 30.),
  321. 24: (1., 40.),
  322. 25: (1., 50.),
  323. 26: (1., 100.),
  324. 27: (2., 1.),
  325. 28: (4., 1.),
  326. 29: (8., 1.),
  327. 30: (10., 1.),
  328. 31: (100., 1.),
  329. 32: (1000., 1.),
  330. }
  331. RASTER_UNITS = {
  332. 'mm': 1,
  333. 'cm': 2,
  334. 'm': 3,
  335. 'km': 4,
  336. 'in': 5,
  337. 'ft': 6,
  338. 'yd': 7,
  339. 'mi': 8,
  340. }
  341. LAYOUT_NAMES = ('*paper_space', '$paper_space', '*model_space', '$model_space')
  342. class SortEntities:
  343. DISABLE = 0
  344. SELECTION = 1 # 1 = Sorts for object selection
  345. SNAP = 2 # 2 = Sorts for object snap
  346. REDRAW = 4 # 4 = Sorts for redraws; obsolete
  347. MSLIDE = 8 # 8 = Sorts for MSLIDE command slide creation; obsolete
  348. REGEN = 16 # 16 = Sorts for REGEN commands
  349. PLOT = 32 # 32 = Sorts for plotting
  350. POSTSCRIPT = 64 # 64 = Sorts for PostScript output; obsolete
  351. DIMJUST = {
  352. 'center': 0,
  353. 'left': 1,
  354. 'right': 2,
  355. 'above1': 3,
  356. 'above2': 4,
  357. }
  358. DIMTAD = {
  359. 'above': 1,
  360. 'center': 0,
  361. 'below': 4,
  362. }