auto_window_drawer.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import core
  2. from drawer.BaseDrawer import BaseDrawer, VentGraphDrawer
  3. from entity.primitives import Window
  4. class AutoWindowDrawer(VentGraphDrawer):
  5. def __init__(self, obj, msp, style):
  6. super().__init__(obj, msp, style)
  7. self.window_drawers = {
  8. 0: self.draw_window_0,
  9. 1: self.draw_window_1,
  10. 2: self.draw_window_2,
  11. }
  12. def initialize_data(self):
  13. self.obj.color = (255, 255, 255)
  14. def draw_obj(self, center, route):
  15. self.window_drawers[self.style](center,route)
  16. def trans_window_rate(self, n):
  17. assert isinstance(self.obj, Window)
  18. return n * self.obj.width / 16.2
  19. def create_window_points(self, center, route):
  20. assert isinstance(self.obj, Window)
  21. cx, cy = center
  22. points = []
  23. # 定义一系列点的偏移量
  24. offsets = [
  25. (-8.11, 12.63), (-8.11, 21.60), (-8.11, -12.63), (-8.11, -21.60),
  26. (8.11, 12.63), (8.11, 21.60), (8.11, -12.63), (8.11, -21.60),
  27. (-8.11, 10.02), (3.935, 10.02), (-3.935, 7.09), (8.11, 7.09),
  28. (-8.11, 4.32), (3.935, 4.32), (-3.935, 1.385), (8.11, 1.385),
  29. (-8.11, -1.39), (3.935, -1.39), (-3.935, -4.32), (8.11, -4.32),
  30. (-8.11, -7.10), (3.935, -7.10), (-3.935, -10.03), (8.11, -10.03)
  31. ]
  32. for dx, dy in offsets:
  33. x = cx + self.trans_window_rate(dx)
  34. y = cy + self.trans_window_rate(dy)
  35. rotated_point = core.rotate_point_around_another((x, y), center, route)
  36. points.append(rotated_point)
  37. return points
  38. def draw_window_0(self, center, route):
  39. points = self.create_window_points(center, route)
  40. # 绘制线条
  41. lines = [
  42. (points[1], points[3]), (points[5], points[7]),
  43. (points[0], points[4]), (points[2], points[6]),
  44. (points[8], points[9]), (points[9], points[11]),
  45. (points[10], points[11]), (points[8], points[10]),
  46. (points[12], points[13]), (points[13], points[15]),
  47. (points[14], points[15]), (points[12], points[14]),
  48. (points[16], points[17]), (points[17], points[19]),
  49. (points[18], points[19]), (points[16], points[18]),
  50. (points[20], points[21]), (points[21], points[23]),
  51. (points[22], points[23]), (points[20], points[22])
  52. ]
  53. for line in lines:
  54. l = self.msp.add_line(line[0], line[1], dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  55. l.rgb = self.obj.color
  56. def draw_window_2(self, center, route):
  57. route = route + 1.57075
  58. points = self.create_window_points(center, route)
  59. # 绘制线条
  60. lines = [
  61. (points[1], points[3]), (points[5], points[7]),
  62. (points[0], points[4]), (points[2], points[6]),
  63. (points[8], points[9]), (points[9], points[11]),
  64. (points[10], points[11]), (points[8], points[10]),
  65. (points[12], points[13]), (points[13], points[15]),
  66. (points[14], points[15]), (points[12], points[14]),
  67. (points[16], points[17]), (points[17], points[19]),
  68. (points[18], points[19]), (points[16], points[18]),
  69. (points[20], points[21]), (points[21], points[23]),
  70. (points[22], points[23]), (points[20], points[22])
  71. ]
  72. for line in lines:
  73. l = self.msp.add_line(line[0], line[1], dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  74. l.rgb = self.obj.color
  75. # d1---d2
  76. # a1
  77. # b1-|-b2
  78. # e1
  79. # |||
  80. # c1-|-c2
  81. # e2
  82. # a2
  83. def draw_window_1(self, center, route):
  84. a1 = center[0], center[1] + self.obj.width * 0.7
  85. a2 = center[0], center[1] - self.obj.width * 0.7
  86. a1 = core.rotate_point_around_another(a1, center, route)
  87. a2 = core.rotate_point_around_another(a2, center, route)
  88. b1 = center[0]-self.obj.width * 0.3, center[1] + self.obj.width * 0.3
  89. b2 = center[0]+self.obj.width * 0.3, center[1] + self.obj.width * 0.3
  90. b1 = core.rotate_point_around_another(b1, center, route)
  91. b2 = core.rotate_point_around_another(b2, center, route)
  92. self.msp.add_line(b1, b2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  93. c1 = center[0] - self.obj.width * 0.3, center[1] - self.obj.width * 0.3
  94. c2 = center[0] + self.obj.width * 0.3, center[1] - self.obj.width * 0.3
  95. c1 = core.rotate_point_around_another(c1, center, route)
  96. c2 = core.rotate_point_around_another(c2, center, route)
  97. self.msp.add_line(c1, c2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  98. self.msp.add_line(b1, c1, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  99. self.msp.add_line(b2, c2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  100. d1 = center[0]-self.obj.width * 0.7, center[1] + self.obj.width * 0.7
  101. d2 = center[0]+self.obj.width * 0.7, center[1] + self.obj.width * 0.7
  102. d1 = core.rotate_point_around_another(d1, center, route)
  103. d2 = core.rotate_point_around_another(d2, center, route)
  104. self.msp.add_line(d1, d2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  105. e1 = center[0], center[1] + self.obj.width * 0.3
  106. e2 = center[0], center[1] - self.obj.width * 0.3
  107. e1 = core.rotate_point_around_another(e1, center, route)
  108. e2 = core.rotate_point_around_another(e2, center, route)
  109. self.msp.add_line(a1, e1, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})
  110. self.msp.add_line(a2, e2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50})