WindFlowDrawer.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import math
  2. import time
  3. import ezdxf
  4. import numpy as np
  5. from core import rotate_point_around_another, calculate_route, calculate_angle_with_x_axis
  6. class WindFlowDrawer:
  7. def __init__(self, msp,layer, gap, center, route, type):
  8. self.layer = layer
  9. self.msp = msp
  10. self.gap = gap
  11. self.center = center
  12. self.route = route
  13. self.type = type
  14. def draw_wind_flow(self):
  15. line_length = 2.55 * self.gap
  16. point_end = self.center[0] - line_length / 2, self.center[1]
  17. point_arrow = self.center[0] + line_length / 2, self.center[1]
  18. point_text = self.center[0] - 0.5 * line_length, self.center[1] + 0.1 * line_length
  19. arrow = ezdxf.ARROWS.ez_arrow_filled
  20. color = str(self.type)
  21. point_end = rotate_point_around_another(point_end, self.center, self.route)
  22. point_arrow = rotate_point_around_another(point_arrow, self.center, self.route)
  23. point_text = rotate_point_around_another(point_text, self.center, self.route)
  24. angle = math.degrees(self.route)
  25. if self.type == '1':
  26. dxfattribs = {
  27. 'insert': point_text, 'style': 'LiberationSerif', 'color': color, "layer":f"图层{self.layer}"}
  28. self.msp.add_text(text="S", rotation=angle - 90, dxfattribs=dxfattribs)
  29. self.msp.add_line(point_end, point_arrow, {
  30. "color": color,
  31. "layer":f"图层{self.layer}"
  32. })
  33. self.msp.add_arrow(arrow, point_arrow, 2, angle, {
  34. "color": color,
  35. "layer": f"图层{self.layer}"
  36. })