attrib.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. # Created: 25.03.2011
  2. # Copyright (c) 2011-2018, Manfred Moitzi
  3. # License: MIT License
  4. from ezdxf.lldxf import const
  5. from ezdxf.tools import set_flag_state
  6. from .graphics import ExtendedTags, make_attribs, DXFAttr, XType
  7. from .text import Text
  8. _ATTRIB_TPL = """0
  9. ATTRIB
  10. 5
  11. 0
  12. 8
  13. 0
  14. 10
  15. 0.0
  16. 20
  17. 0.0
  18. 30
  19. 0.0
  20. 40
  21. 1.0
  22. 1
  23. DEFAULTTEXT
  24. 2
  25. TAG
  26. 70
  27. 0
  28. 50
  29. 0.0
  30. 51
  31. 0.0
  32. 41
  33. 1.0
  34. 7
  35. STANDARD
  36. 71
  37. 0
  38. 72
  39. 0
  40. 73
  41. 0
  42. 74
  43. 0
  44. 11
  45. 0.0
  46. 21
  47. 0.0
  48. 31
  49. 0.0
  50. """
  51. class Attrib(Text):
  52. __slots__ = ()
  53. TEMPLATE = ExtendedTags.from_text(_ATTRIB_TPL)
  54. DXFATTRIBS = make_attribs({
  55. 'insert': DXFAttr(10, xtype=XType.any_point),
  56. 'height': DXFAttr(40),
  57. 'text': DXFAttr(1),
  58. 'tag': DXFAttr(2),
  59. 'flags': DXFAttr(70),
  60. 'field_length': DXFAttr(73, default=0),
  61. 'rotation': DXFAttr(50, default=0.0),
  62. 'oblique': DXFAttr(51, default=0.0),
  63. 'width': DXFAttr(41, default=1.0), # width factor
  64. 'style': DXFAttr(7, default='STANDARD'),
  65. 'text_generation_flag': DXFAttr(71, default=0), # 2 = backward (mirr-x), 4 = upside down (mirr-y)
  66. 'halign': DXFAttr(72, default=0), # horizontal justification
  67. 'valign': DXFAttr(74, default=0), # vertical justification
  68. 'align_point': DXFAttr(11, xtype=XType.any_point),
  69. })
  70. @property
  71. def is_const(self) -> bool:
  72. """
  73. This is a constant attribute.
  74. """
  75. return bool(self.dxf.flags & const.ATTRIB_CONST)
  76. @is_const.setter
  77. def is_const(self, state: bool) -> None:
  78. """
  79. This is a constant attribute.
  80. """
  81. self.dxf.flags = set_flag_state(self.dxf.flags, const.ATTRIB_CONST, state)
  82. @property
  83. def is_invisible(self) -> bool:
  84. """
  85. Attribute is invisible (does not appear).
  86. """
  87. return bool(self.dxf.flags & const.ATTRIB_INVISIBLE)
  88. @is_invisible.setter
  89. def is_invisible(self, state: bool) -> None:
  90. """
  91. Attribute is invisible (does not appear).
  92. """
  93. self.dxf.flags = set_flag_state(self.dxf.flags, const.ATTRIB_INVISIBLE, state)
  94. @property
  95. def is_verify(self) -> bool:
  96. """
  97. Verification is required on input of this attribute. (CAD application feature)
  98. """
  99. return bool(self.dxf.flags & const.ATTRIB_VERIFY)
  100. @is_verify.setter
  101. def is_verify(self, state: bool) -> None:
  102. """
  103. Verification is required on input of this attribute. (CAD application feature)
  104. """
  105. self.dxf.flags = set_flag_state(self.dxf.flags, const.ATTRIB_VERIFY, state)
  106. @property
  107. def is_preset(self) -> bool:
  108. """
  109. No prompt during insertion. (CAD application feature)
  110. """
  111. return bool(self.dxf.flags & const.ATTRIB_IS_PRESET)
  112. @is_preset.setter
  113. def is_preset(self, state: bool) -> None:
  114. """
  115. No prompt during insertion. (CAD application feature)
  116. """
  117. self.dxf.flags = set_flag_state(self.dxf.flags, const.ATTRIB_IS_PRESET, state)
  118. _ATTDEF_TPL = """0
  119. ATTDEF
  120. 5
  121. 0
  122. 8
  123. 0
  124. 10
  125. 0.0
  126. 20
  127. 0.0
  128. 30
  129. 0.0
  130. 40
  131. 1.0
  132. 1
  133. DEFAULTTEXT
  134. 3
  135. PROMPTTEXT
  136. 2
  137. TAG
  138. 70
  139. 0
  140. 50
  141. 0.0
  142. 51
  143. 0.0
  144. 41
  145. 1.0
  146. 7
  147. STANDARD
  148. 71
  149. 0
  150. 72
  151. 0
  152. 73
  153. 0
  154. 74
  155. 0
  156. 11
  157. 0.0
  158. 21
  159. 0.0
  160. 31
  161. 0.0
  162. """
  163. class Attdef(Attrib):
  164. __slots__ = ()
  165. TEMPLATE = ExtendedTags.from_text(_ATTDEF_TPL)
  166. DXFATTRIBS = make_attribs({
  167. 'insert': DXFAttr(10, xtype=XType.any_point),
  168. 'height': DXFAttr(40),
  169. 'text': DXFAttr(1),
  170. 'prompt': DXFAttr(3),
  171. 'tag': DXFAttr(2),
  172. 'flags': DXFAttr(70),
  173. 'field_length': DXFAttr(73, default=0),
  174. 'rotation': DXFAttr(50, default=0.0),
  175. 'oblique': DXFAttr(51, default=0.0),
  176. 'width': DXFAttr(41, default=1.0), # width factor
  177. 'style': DXFAttr(7, default='STANDARD'),
  178. 'text_generation_flag': DXFAttr(71, default=0), # 2 = backward (mirr-x), 4 = upside down (mirr-y)
  179. 'halign': DXFAttr(72, default=0), # horizontal justification
  180. 'valign': DXFAttr(74, default=0), # vertical justification
  181. 'align_point': DXFAttr(11, xtype=XType.any_point),
  182. })