mleader.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. # Created: 08.04.2018
  2. # Copyright (c) 2018, Manfred Moitzi
  3. # License: MIT-License
  4. from typing import TYPE_CHECKING
  5. from .graphics import ExtendedTags, DXFAttr, DefSubclass, DXFAttributes
  6. from .graphics import none_subclass, entity_subclass, ModernGraphicEntity
  7. from .dxfobjects import DXFObject
  8. from .object_manager import ObjectManager
  9. if TYPE_CHECKING:
  10. from ezdxf.eztypes import Drawing
  11. # DXF Examples:
  12. # D:\source\dxftest\CADKitSamples\house design for two family with common staircasedwg.dxf
  13. # D:\source\dxftest\CADKitSamples\house design.dxf
  14. _MLEADER_CLS = """0
  15. CLASS
  16. 1
  17. MLEADER
  18. 2
  19. AcDbMLeader
  20. 3
  21. ACDB_MLEADER_CLASS
  22. 90
  23. 1025
  24. 91
  25. 0
  26. 280
  27. 0
  28. 281
  29. 1
  30. """
  31. _MLEADER_TPL = """0
  32. MLEADER
  33. 5
  34. 0
  35. 330
  36. 0
  37. 100
  38. AcDbEntity
  39. 8
  40. 0
  41. 100
  42. AcDbMLeader
  43. 340
  44. 0
  45. """
  46. mleader_subclass = DefSubclass('AcDbMLeader', {
  47. 'leader_style_id': DXFAttr(340), # handle of MLEADERSTYLE?
  48. })
  49. class MLeader(ModernGraphicEntity):
  50. # Requires AC1021/R2007
  51. __slots__ = ()
  52. TEMPLATE = ExtendedTags.from_text(_MLEADER_TPL)
  53. DXFATTRIBS = DXFAttributes(none_subclass, entity_subclass, mleader_subclass)
  54. CLASS = ExtendedTags.from_text(_MLEADER_CLS)
  55. _MLEADER_STYLE_CLS = """0
  56. CLASS
  57. 1
  58. MLEADERSTYLE
  59. 2
  60. AcDbMLeaderStyle
  61. 3
  62. ACDB_MLEADERSTYLE_CLASS
  63. 90
  64. 4095
  65. 91
  66. 0
  67. 280
  68. 0
  69. 281
  70. 0
  71. """
  72. _MLEADER_STYLE_TPL = """ 0
  73. MLEADERSTYLE
  74. 5
  75. 0
  76. 102
  77. {ACAD_REACTORS
  78. 102
  79. }
  80. 330
  81. 0
  82. 100
  83. AcDbMLeaderStyle
  84. 179
  85. 2
  86. 170
  87. 2
  88. 171
  89. 1
  90. 172
  91. 0
  92. 90
  93. 2
  94. 40
  95. 0.0
  96. 41
  97. 0.0
  98. 173
  99. 1
  100. 91
  101. -1056964608
  102. 340
  103. 14
  104. 92
  105. -2
  106. 290
  107. 1
  108. 42
  109. 2.0
  110. 291
  111. 1
  112. 43
  113. 8.0
  114. 3
  115. Standard
  116. 341
  117. 0
  118. 44
  119. 4.0
  120. 300
  121. 342
  122. 11
  123. 174
  124. 1
  125. 178
  126. 1
  127. 175
  128. 1
  129. 176
  130. 0
  131. 93
  132. -1056964608
  133. 45
  134. 4.0
  135. 292
  136. 0
  137. 297
  138. 0
  139. 46
  140. 4.0
  141. 343
  142. 0
  143. 94
  144. -1056964608
  145. 47
  146. 1.0
  147. 49
  148. 1.0
  149. 140
  150. 1.0
  151. 293
  152. 1
  153. 141
  154. 0.0
  155. 294
  156. 1
  157. 177
  158. 0
  159. 142
  160. 1.0
  161. 295
  162. 0
  163. 296
  164. 0
  165. 143
  166. 3.75
  167. 271
  168. 0
  169. 272
  170. 9
  171. 273
  172. 9
  173. """
  174. mleader_style_subclass = DefSubclass('AcDbMLeaderStyle', {
  175. 'content_type': DXFAttr(170),
  176. 'draw_mleader_order_type': DXFAttr(171),
  177. 'draw_leader_order_type': DXFAttr(172),
  178. 'max_leader_segments_points': DXFAttr(90), # MaxLeader Segments Points
  179. 'first_segment_angle_constraint': DXFAttr(40), # First Segment Angle Constraint
  180. 'second_segment_angle_constraint': DXFAttr(41), # Second Segment Angle Constraint
  181. 'leader_line_type': DXFAttr(173),
  182. 'leader_line_color': DXFAttr(91),
  183. 'leader_line_type_id': DXFAttr(340), # handle
  184. 'leader_line_weight': DXFAttr(92),
  185. 'enable_landing': DXFAttr(290),
  186. 'landing_gap': DXFAttr(42),
  187. 'enable_dog_leg': DXFAttr(291),
  188. 'dog_leg_length': DXFAttr(43),
  189. 'name': DXFAttr(3),
  190. 'arrow_head_id': DXFAttr(341),
  191. 'arrow_head_size': DXFAttr(44),
  192. 'default_mtext_contents': DXFAttr(300),
  193. 'mtext_style_id': DXFAttr(342),
  194. 'text_left_attachment_type': DXFAttr(174),
  195. 'text_angle_type': DXFAttr(175),
  196. 'text_right_attachment_type': DXFAttr(178),
  197. 'text_color': DXFAttr(93),
  198. 'text_height': DXFAttr(45),
  199. 'enable_frame_text': DXFAttr(292),
  200. 'text_align_always_left': DXFAttr(297),
  201. 'align_space': DXFAttr(46),
  202. 'enable_block_content_scale': DXFAttr(293),
  203. 'block_content_id': DXFAttr(343),
  204. 'block_content_color': DXFAttr(94),
  205. 'block_content_scale_x': DXFAttr(47),
  206. 'block_content_scale_y': DXFAttr(49),
  207. 'block_content_scale_z': DXFAttr(140),
  208. 'enable_block_content_rotation': DXFAttr(294),
  209. 'block_content_rotation': DXFAttr(141),
  210. 'block_content_connection_type': DXFAttr(177),
  211. 'scale': DXFAttr(142),
  212. 'overwrite_property_value': DXFAttr(295),
  213. 'is_annotative': DXFAttr(296),
  214. 'break_gap_size': DXFAttr(143),
  215. 'mtext_attachment_direction': DXFAttr(271), # 0 = Horizontal; 1 = Vertical
  216. 'bottom_text_attachment_direction': DXFAttr(272), # 9 = Center; 10 = Underline and Center
  217. 'top_text_attachment_direction': DXFAttr(272), # 9 = Center; 10 = Overline and Center
  218. })
  219. class MLeaderStyle(DXFObject):
  220. # Requires AC1021/R2007
  221. __slots__ = ()
  222. TEMPLATE = ExtendedTags.from_text(_MLEADER_STYLE_TPL)
  223. DXFATTRIBS = DXFAttributes(none_subclass, mleader_style_subclass)
  224. CLASS = ExtendedTags.from_text(_MLEADER_STYLE_CLS)
  225. class MLeaderStyleManager(ObjectManager):
  226. def __init__(self, drawing: 'Drawing'):
  227. super().__init__(drawing, dict_name='ACAD_MLEADERSTYLE', object_type='MLEADERSTYLE')
  228. self.create_required_entries()
  229. def create_required_entries(self) -> None:
  230. for name in ('Standard', ):
  231. if name not in self.object_dict:
  232. self.new(name)