gate_drawer.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. from core import rotate_point_around_another
  2. from drawer.BaseDrawer import BaseDrawer, VentGraphDrawer
  3. from entity.primitives import Gate
  4. from ezdxf import math as mt
  5. from dict.model_config import _get_app_name, _global_model_configs
  6. class GateDrawer(VentGraphDrawer):
  7. def __init__(self, obj, msp, style):
  8. super().__init__(obj, msp, style)
  9. self.gate_drawers = {
  10. 0: self.draw_gate_style_0,
  11. 1: self.draw_gate_style_1,
  12. 2: self.draw_gate_style_2,
  13. 3: self.draw_gate_style_3,
  14. 4: self.draw_gate_style_4
  15. }
  16. def initialize_data(self):
  17. self.obj.color = (255, 255, 255)
  18. def draw_obj(self, center, route):
  19. self.gate_drawers[self.style](center, route)
  20. def add_gate_part(self, start_point, end_point, def_point):
  21. carc = mt.arc.ConstructionArc()
  22. b = carc.from_3p(start_point=start_point, def_point=def_point, end_point=end_point)
  23. arc = self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,
  24. dxfattribs={"layer": f"图层{self.obj.layer_id}", })
  25. arc.rgb = self.obj.color
  26. # self.msp.add_lwpolyline([(start_point[0], start_point[1], 1), (end_point[0], end_point[1], 0)], format="xyb", dxfattribs={"layer": f"图层{self.layer}"})
  27. line = self.msp.add_line(start_point, end_point, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  28. line.rgb = self.obj.color
  29. def draw_gate_style_0(self, center, route):
  30. assert isinstance(self.obj, Gate)
  31. grid = 0.8 * self.obj.width
  32. rad = self.obj.width * 0.8
  33. point_center = center
  34. # 计算第一个门的三个点
  35. gate1_circle_a = (point_center[0] - grid, point_center[1] + rad)
  36. gate1_circle_b = (point_center[0] - grid, point_center[1] - rad)
  37. gate1_circle_c = (point_center[0] - grid + rad, point_center[1])
  38. # 旋转这些点
  39. gate1_a = rotate_point_around_another(gate1_circle_a, point_center, route)
  40. gate1_b = rotate_point_around_another(gate1_circle_b, point_center, route)
  41. gate1_c = rotate_point_around_another(gate1_circle_c, point_center, route)
  42. # 创建和添加第一个门的弧和线
  43. self.add_gate_part(gate1_a, gate1_b, gate1_c)
  44. # 计算第二个门的三个点
  45. gate2_circle_a = (point_center[0] + grid, point_center[1] + rad)
  46. gate2_circle_b = (point_center[0] + grid, point_center[1] - rad)
  47. gate2_circle_c = (point_center[0] + grid - rad, point_center[1])
  48. # 旋转这些点
  49. gate2_a = rotate_point_around_another(gate2_circle_a, point_center, route)
  50. gate2_b = rotate_point_around_another(gate2_circle_b, point_center, route)
  51. gate2_c = rotate_point_around_another(gate2_circle_c, point_center, route)
  52. # 创建和添加第二个门的弧和线
  53. self.add_gate_part(gate2_a, gate2_b, gate2_c)
  54. def draw_gate_style_1(self, center, route):
  55. rad = self.obj.width * 0.8
  56. small_circle_rad = self.obj.width * 0.1
  57. gate1_circle_a = (center[0], center[1] + rad)
  58. gate1_circle_b = (center[0], center[1] - rad)
  59. gate1_circle_c = (center[0] + rad, center[1])
  60. gate1_a = rotate_point_around_another(gate1_circle_a, center, route)
  61. gate1_b = rotate_point_around_another(gate1_circle_b, center, route)
  62. gate1_c = rotate_point_around_another(gate1_circle_c, center, route)
  63. carc = mt.arc.ConstructionArc()
  64. b = carc.from_3p(start_point=gate1_a, def_point=gate1_c, end_point=gate1_b)
  65. arc = self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,
  66. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  67. arc.rgb = self.obj.color
  68. line = self.msp.add_line(gate1_a, gate1_b,
  69. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  70. line.rgb = self.obj.color
  71. self.msp.add_circle(center=gate1_a, radius=small_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  72. self.msp.add_circle(center=gate1_b, radius=small_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  73. # b1 a1
  74. # a3(| |
  75. # b2 a2
  76. def draw_gate_style_4(self, center, route):
  77. a1 = center[0], center[1] + self.obj.width
  78. a2 = center[0], center[1] - self.obj.width
  79. a3 = center[0] - self.obj.width*1.5, center[1]
  80. b1 = a1[0] - 1 / 2 * self.obj.width, a1[1]
  81. b2 = a2[0] - 1 / 2 * self.obj.width, a2[1]
  82. a1 = rotate_point_around_another(a1, center, route)
  83. a2 = rotate_point_around_another(a2, center, route)
  84. a3 = rotate_point_around_another(a3, center, route)
  85. b1 = rotate_point_around_another(b1, center, route)
  86. b2 = rotate_point_around_another(b2, center, route)
  87. line = self.msp.add_line(a1, a2,
  88. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  89. line.rgb = self.obj.color
  90. line = self.msp.add_line(b1, b2,
  91. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  92. line.rgb = self.obj.color
  93. mt_carc = mt.arc.ConstructionArc()
  94. arc_1 = mt_carc.from_3p(start_point=b1, def_point=a3, end_point=b2)
  95. # b1 a1 c1
  96. # a3(| | |)a4
  97. # b2 a2 c2
  98. arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle,
  99. end_angle=arc_1.end_angle,
  100. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  101. arc.rgb = self.obj.color
  102. # b1 a1 c1
  103. # a3(| | |)a4
  104. # b2 a2 c2
  105. def draw_gate_style_2(self, center, route):
  106. a1 = center[0], center[1] + self.obj.width
  107. a2 = center[0], center[1] - self.obj.width
  108. a3 = center[0] - self.obj.width, center[1]
  109. a4 = center[0] + self.obj.width, center[1]
  110. b1 = a1[0] - 1 / 2 * self.obj.width, a1[1]
  111. b2 = a2[0] - 1 / 2 * self.obj.width, a2[1]
  112. c1 = a1[0] + 1 / 2 * self.obj.width, a1[1]
  113. c2 = a2[0] + 1 / 2 * self.obj.width, a2[1]
  114. a1 = rotate_point_around_another(a1, center, route)
  115. a2 = rotate_point_around_another(a2, center, route)
  116. a3 = rotate_point_around_another(a3, center, route)
  117. a4 = rotate_point_around_another(a4, center, route)
  118. b1 = rotate_point_around_another(b1, center, route)
  119. b2 = rotate_point_around_another(b2, center, route)
  120. c1 = rotate_point_around_another(c1, center, route)
  121. c2 = rotate_point_around_another(c2, center, route)
  122. line = self.msp.add_line(a1, a2,
  123. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  124. line.rgb = self.obj.color
  125. line = self.msp.add_line(b1, b2,
  126. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  127. line.rgb = self.obj.color
  128. line = self.msp.add_line(c1, c2,
  129. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  130. line.rgb = self.obj.color
  131. mt_carc = mt.arc.ConstructionArc()
  132. arc_1 = mt_carc.from_3p(start_point=c2, def_point=a4, end_point=c1)
  133. # b1 a1 c1
  134. # a3(| | |)a4
  135. # b2 a2 c2
  136. arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle,
  137. end_angle=arc_1.end_angle,
  138. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  139. arc.rgb = self.obj.color
  140. arc_2 = mt_carc.from_3p(start_point=b1, def_point=a3, end_point=b2)
  141. arc = self.msp.add_arc(center=arc_2.center, radius=arc_2.radius, start_angle=arc_2.start_angle,
  142. end_angle=arc_2.end_angle,
  143. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  144. arc.rgb = self.obj.color
  145. def draw_gate_style_3(self, center, route):
  146. # 双向调节风门
  147. #
  148. # a3---a1 a2---a4
  149. # b1 c1
  150. # d1(| |)d2
  151. # b2 c2
  152. unit = self.obj.width
  153. a1 = center[0] - 2 * unit, center[1]
  154. b1 = center[0] - unit, center[1] - unit
  155. c1 = center[0] - unit, center[1] + unit
  156. d1 = center[0] - unit, center[1] + unit * 1.15
  157. e1 = center[0] - unit, center[1] - unit * 1.15
  158. g1 = center[0] - 2 * unit, center[1] + unit * 1.15
  159. f1 = center[0] - 0.15 * unit, center[1] + unit * 1.15
  160. a1 = rotate_point_around_another(a1, center, route)
  161. b1 = rotate_point_around_another(b1, center, route)
  162. c1 = rotate_point_around_another(c1, center, route)
  163. d1 = rotate_point_around_another(d1, center, route)
  164. e1 = rotate_point_around_another(e1, center, route)
  165. g1 = rotate_point_around_another(g1, center, route)
  166. f1 = rotate_point_around_another(f1, center, route)
  167. line = self.msp.add_line(d1, e1,
  168. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  169. line.rgb = self.obj.color
  170. line = self.msp.add_line(g1, f1,
  171. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  172. line.rgb = self.obj.color
  173. mt_carc = mt.arc.ConstructionArc()
  174. arc_1 = mt_carc.from_3p(start_point=c1, def_point=a1, end_point=b1)
  175. arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle,
  176. end_angle=arc_1.end_angle,
  177. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  178. arc.rgb = self.obj.color
  179. a1 = center[0] + 2 * unit, center[1]
  180. b1 = center[0] + unit, center[1] - unit
  181. c1 = center[0] + unit, center[1] + unit
  182. d1 = center[0] + unit, center[1] + unit * 1.15
  183. e1 = center[0] + unit, center[1] - unit * 1.15
  184. g1 = center[0] + 2 * unit, center[1] + unit * 1.15
  185. f1 = center[0] + 0.15 * unit, center[1] + unit * 1.15
  186. a1 = rotate_point_around_another(a1, center, route)
  187. b1 = rotate_point_around_another(b1, center, route)
  188. c1 = rotate_point_around_another(c1, center, route)
  189. d1 = rotate_point_around_another(d1, center, route)
  190. e1 = rotate_point_around_another(e1, center, route)
  191. g1 = rotate_point_around_another(g1, center, route)
  192. f1 = rotate_point_around_another(f1, center, route)
  193. line = self.msp.add_line(d1, e1,
  194. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  195. line.rgb = self.obj.color
  196. line = self.msp.add_line(g1, f1,
  197. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  198. line.rgb = self.obj.color
  199. mt_carc = mt.arc.ConstructionArc()
  200. arc_1 = mt_carc.from_3p(start_point=b1, def_point=a1, end_point=c1)
  201. arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle,
  202. end_angle=arc_1.end_angle,
  203. dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  204. arc.rgb = self.obj.color