leader.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Created: 08.04.2018
  2. # Copyright (c) 2018, Manfred Moitzi
  3. # License: MIT-License
  4. from .graphics import ExtendedTags, DXFAttr, DefSubclass, DXFAttributes, XType
  5. from .graphics import none_subclass, entity_subclass, ModernGraphicEntity
  6. from typing import TYPE_CHECKING, Iterable
  7. if TYPE_CHECKING:
  8. from ezdxf.eztypes import Tags, Vertex
  9. # example: D:\source\dxftest\CADKitSamples\AEC Plan Elev Sample.dxf
  10. _LEADER_TPL = """0
  11. LEADER
  12. 5
  13. 0
  14. 330
  15. 0
  16. 100
  17. AcDbEntity
  18. 8
  19. 0
  20. 100
  21. AcDbLeader
  22. 3
  23. DIMSTYLE
  24. 73
  25. 3
  26. 40
  27. 1.0
  28. 41
  29. 1.0
  30. 76
  31. 3
  32. 10
  33. 0.0
  34. 20
  35. 0.0
  36. 30
  37. 0.0
  38. 340
  39. 0
  40. 210
  41. 0.0
  42. 220
  43. 0.0
  44. 230
  45. 1.0
  46. 213
  47. 0.0
  48. 223
  49. 0.0
  50. 233
  51. 0.0
  52. """
  53. leader_subclass = DefSubclass('AcDbLeader', {
  54. 'dimstyle': DXFAttr(3), # Dimension style name
  55. 'has_arrowhead': DXFAttr(71), # Arrowhead flag: 0/1 = no/yes
  56. 'path_type': DXFAttr(72), # Leader path type: 0 = Straight line segments; 1 = Spline
  57. 'annotation_type': DXFAttr(73, default=3), # Leader creation flag:
  58. # 0= Created with text annotation
  59. # 1 = Created with tolerance annotation;
  60. # 2 = Created with block reference annotation
  61. # 3 = Created without any annotation
  62. 'hookline_direction': DXFAttr(74), # Hookline direction flag:
  63. # 0 = Hookline (or end of tangent for a splined leader) is the opposite direction from the horizontal vector
  64. # 1 = Hookline (or end of tangent for a splined leader) is the same direction as horizontal vector (see code 75)
  65. 'has_hookline': DXFAttr(75), # Hookline flag: 0/1 = no/yes
  66. 'text_height': DXFAttr(40), # Text annotation height
  67. 'text_width': DXFAttr(41), # Text annotation width
  68. 'n_vertices': DXFAttr(76), # Number of vertices in leader (ignored for OPEN)
  69. # 10, 20, 30 - Vertex coordinates (one entry for each vertex)
  70. 'block_color': DXFAttr(76), # Color to use if leader's DIMCLRD = BYBLOCK
  71. 'annotation': DXFAttr(340), # Hard reference to associated annotation (mtext, tolerance, or insert entity)
  72. 'normal_vector': DXFAttr(210, xtype=XType.point3d), # Normal vector
  73. 'horizontal_direction': DXFAttr(211, xtype=XType.point3d), # 'horizontal' direction for leader
  74. 'leader_offset_block_ref': DXFAttr(212, xtype=XType.point3d), # Offset of last leader vertex from block reference insertion point
  75. 'leader_offset_annotation_placement': DXFAttr(213, xtype=XType.point3d), # Offset of last leader vertex from annotation placement point
  76. # Xdata belonging to the application ID "ACAD" follows a leader entity if any dimension overrides have been applied
  77. # to this entity. See Dimension Style Overrides.
  78. })
  79. class Leader(ModernGraphicEntity):
  80. # Requires AC1015/R2000
  81. __slots__ = ()
  82. TEMPLATE = ExtendedTags.from_text(_LEADER_TPL)
  83. DXFATTRIBS = DXFAttributes(none_subclass, entity_subclass, leader_subclass)
  84. @property
  85. def AcDbLeader(self) -> 'Tags':
  86. return self.tags.subclasses[2]
  87. def get_vertices(self) -> Iterable['Vertex']:
  88. return (tag.value for tag in self.AcDbLeader if tag.code == 10)