WindowDrawer.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from core import rotate_point_around_another
  2. class WindowDrawer:
  3. def __init__(self, msp, gap, center,route):
  4. self.msp = msp # 假设 msp 是绘图空间的引用
  5. self.gap = gap # 转换系数
  6. self.center = center
  7. self.route = route
  8. def trans_window_rate(self, n):
  9. return n * self.gap / 16.2
  10. def create_window_points(self):
  11. cx, cy = self.center
  12. points = []
  13. # 定义一系列点的偏移量
  14. offsets = [
  15. (-8.11, 12.63), (-8.11, 21.60), (-8.11, -12.63), (-8.11, -21.60),
  16. (8.11, 12.63), (8.11, 21.60), (8.11, -12.63), (8.11, -21.60),
  17. (-8.11, 10.02), (3.935, 10.02), (-3.935, 7.09), (8.11, 7.09),
  18. (-8.11, 4.32), (3.935, 4.32), (-3.935, 1.385), (8.11, 1.385),
  19. (-8.11, -1.39), (3.935, -1.39), (-3.935, -4.32), (8.11, -4.32),
  20. (-8.11, -7.10), (3.935, -7.10), (-3.935, -10.03), (8.11, -10.03)
  21. ]
  22. for dx, dy in offsets:
  23. x = cx + self.trans_window_rate(dx)
  24. y = cy + self.trans_window_rate(dy)
  25. rotated_point = rotate_point_around_another((x, y), self.center, self.route)
  26. points.append(rotated_point)
  27. return points
  28. def draw_window(self):
  29. points = self.create_window_points()
  30. # 绘制线条
  31. lines = [
  32. (points[1], points[3]), (points[5], points[7]),
  33. (points[0], points[4]), (points[2], points[6]),
  34. (points[8], points[9]), (points[9], points[11]),
  35. (points[10], points[11]), (points[8], points[10]),
  36. (points[12], points[13]), (points[13], points[15]),
  37. (points[14], points[15]), (points[12], points[14]),
  38. (points[16], points[17]), (points[17], points[19]),
  39. (points[18], points[19]), (points[16], points[18]),
  40. (points[20], points[21]), (points[21], points[23]),
  41. (points[22], points[23]), (points[20], points[22])
  42. ]
  43. for line in lines:
  44. self.msp.add_line(line[0], line[1])
  45. return self.msp