WindBridgeDrawer.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import math
  2. import time
  3. import ezdxf
  4. import core
  5. from drawer import WindFlowDrawer
  6. class WindBridgeDrawer:
  7. def __init__(self, msp, center, layer_id, route, gap, color=0, is_cross=True):
  8. self.msp = msp
  9. self.gap = gap
  10. self.route = route
  11. self.is_cross = is_cross
  12. self.color = color
  13. self.layer = layer_id
  14. self.center = center
  15. def draw_wind_bridge_drawer(self):
  16. width = self.gap * 1.7
  17. line_top_middle = self.center[0], self.center[1] + width / 2
  18. line_top_left = line_top_middle[0] - width * 1.25 / 2, line_top_middle[1]
  19. line_top_left_2 = line_top_left[0] - math.cos(math.pi / 6) * width * 0.625, line_top_left[1] + math.sin(
  20. math.pi / 6) * width * 0.625
  21. line_top_right = core.symmetric_point(line_top_left, line_top_middle)
  22. line_top_right_2 = core.symmetric_point(line_top_left_2, (line_top_middle[0], line_top_middle[1] + math.sin(
  23. math.pi / 6) * width * 0.625))
  24. line_bottom_middle = self.center[0], self.center[1] - width / 2
  25. line_bottom_left = line_bottom_middle[0] - width * 1.25 / 2, line_bottom_middle[1]
  26. line_bottom_left_2 = line_bottom_left[0] - math.cos(math.pi / 6) * width * 0.625, line_bottom_left[
  27. 1] - math.sin(
  28. math.pi / 6) * width * 0.625
  29. line_bottom_right = core.symmetric_point(line_bottom_left, line_bottom_middle)
  30. line_bottom_right_2 = core.symmetric_point(line_bottom_left_2,
  31. (line_bottom_middle[0], line_bottom_middle[1] - math.sin(
  32. math.pi / 6) * width * 0.625))
  33. line_top_left = core.rotate_point_around_another(line_top_left, self.center, self.route)
  34. line_top_left_2 = core.rotate_point_around_another(line_top_left_2, self.center, self.route)
  35. line_top_right = core.rotate_point_around_another(line_top_right, self.center, self.route)
  36. line_top_right_2 = core.rotate_point_around_another(line_top_right_2, self.center, self.route)
  37. line_bottom_left = core.rotate_point_around_another(line_bottom_left, self.center, self.route)
  38. line_bottom_left_2 = core.rotate_point_around_another(line_bottom_left_2, self.center, self.route)
  39. line_bottom_right = core.rotate_point_around_another(line_bottom_right, self.center, self.route)
  40. line_bottom_right_2 = core.rotate_point_around_another(line_bottom_right_2, self.center, self.route)
  41. self.msp.add_line(line_top_left, line_top_left_2,dxfattribs={"layer":f"图层{self.layer}"})
  42. self.msp.add_line(line_top_right, line_top_left,dxfattribs={"layer":f"图层{self.layer}"})
  43. self.msp.add_line(line_top_right, line_top_right_2,dxfattribs={"layer":f"图层{self.layer}"})
  44. self.msp.add_line(line_bottom_left, line_bottom_right,dxfattribs={"layer":f"图层{self.layer}"})
  45. self.msp.add_line(line_bottom_right, line_bottom_right_2,dxfattribs={"layer":f"图层{self.layer}"})
  46. self.msp.add_line(line_bottom_left, line_bottom_left_2,dxfattribs={"layer":f"图层{self.layer}"})
  47. if __name__ == '__main__':
  48. doc = ezdxf.new()
  49. msp = doc.modelspace()
  50. wbd = WindBridgeDrawer(msp, (0, 0), 100, 10, 0, 0, 100)
  51. wbd.draw_wind_bridge_drawer()
  52. file_name = f'shaft{str(time.time())}.dxf'
  53. print("保存文件 " + file_name)
  54. doc.saveas(file_name)