GateDrawer.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from core import rotate_point_around_another
  2. from ezdxf import math as mt
  3. class GateDrawer:
  4. def __init__(self, msp, layer, gap, center, route):
  5. self.layer = layer
  6. self.msp = msp
  7. self.gap = gap
  8. self.center = center
  9. self.route = route
  10. def draw_gate(self):
  11. grid = 0.8 * self.gap
  12. rad = self.gap * 0.8
  13. point_center = self.center
  14. route = self.route
  15. # 计算第一个门的三个点
  16. gate1_circle_a = (point_center[0] - grid, point_center[1] + rad)
  17. gate1_circle_b = (point_center[0] - grid, point_center[1] - rad)
  18. gate1_circle_c = (point_center[0] - grid + rad, point_center[1])
  19. # 旋转这些点
  20. gate1_a = rotate_point_around_another(gate1_circle_a, point_center, route)
  21. gate1_b = rotate_point_around_another(gate1_circle_b, point_center, route)
  22. gate1_c = rotate_point_around_another(gate1_circle_c, point_center, route)
  23. # 创建和添加第一个门的弧和线
  24. self.add_gate_part(gate1_a, gate1_b, gate1_c)
  25. # 计算第二个门的三个点
  26. gate2_circle_a = (point_center[0] + grid, point_center[1] + rad)
  27. gate2_circle_b = (point_center[0] + grid, point_center[1] - rad)
  28. gate2_circle_c = (point_center[0] + grid - rad, point_center[1])
  29. # 旋转这些点
  30. gate2_a = rotate_point_around_another(gate2_circle_a, point_center, route)
  31. gate2_b = rotate_point_around_another(gate2_circle_b, point_center, route)
  32. gate2_c = rotate_point_around_another(gate2_circle_c, point_center, route)
  33. # 创建和添加第二个门的弧和线
  34. self.add_gate_part(gate2_a, gate2_b, gate2_c)
  35. def add_gate_part(self, start_point, end_point, def_point):
  36. carc = mt.arc.ConstructionArc()
  37. b = carc.from_3p(start_point=start_point, def_point=def_point, end_point=end_point)
  38. self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,
  39. dxfattribs={"layer": f"图层{self.layer}"})
  40. # 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}"})
  41. self.msp.add_line(start_point, end_point, dxfattribs={"layer": f"图层{self.layer}"})