WindFlowDrawer.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. # 用风类型 0:未指定 1:进风 2: 用风 3:回风
  26. # 0、1 是绿色箭头, 2、3是红色箭头
  27. if self.type == '2' or self.type == '3':
  28. dxfattribs = {
  29. 'insert': point_text, 'style': 'LiberationSerif', 'color': '1', "layer":f"图层{self.layer}"}
  30. self.msp.add_text(text="S", rotation=angle - 90, dxfattribs=dxfattribs)
  31. self.msp.add_line(point_end, point_arrow, {
  32. "color": self.get_color(),
  33. "layer":f"图层{self.layer}"
  34. })
  35. self.msp.add_arrow(arrow, point_arrow, 2, angle, {
  36. "color": self.get_color(),
  37. "layer": f"图层{self.layer}"
  38. })
  39. def get_color(self):
  40. if self.type == '2' or self.type == '3':
  41. return '1'
  42. else:
  43. return '3'