WindowDrawer.py 2.1 KB

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