AirDuctExampleDrawer.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import math
  2. import time
  3. import ezdxf
  4. from ezdxf.enums import TextEntityAlignment
  5. import core
  6. class AirDuctExampleDrawer:
  7. def __init__(self, msp, width, layer, center, route):
  8. self.msp = msp
  9. self.layer = layer
  10. self.center = center
  11. self.width = width
  12. self.route = route
  13. # b1 a1 a3 b3
  14. # c1|----------c2|F|c3----------c4|F
  15. # b2 a2 a4 b4
  16. def draw_air_duct_example(self):
  17. angle = math.degrees(self.route)
  18. center_x = self.center[0]
  19. center_y = self.center[1]
  20. dxfattribs = {
  21. 'insert': self.center, 'style': 'msyh', 'color': core.get_color_by_layer(self.layer),
  22. "layer": f"图层{self.layer}",
  23. }
  24. self.msp.add_text("F", rotation=angle, dxfattribs=dxfattribs, height=self.width/2).set_placement(self.center, align=TextEntityAlignment.MIDDLE_CENTER)
  25. F_coe = 3.3
  26. af = center_x+F_coe*self.width,center_y
  27. af = core.rotate_point_around_another(af, self.center, self.route)
  28. dxfattribs = {
  29. 'insert': af, 'style': 'msyh', 'color': core.get_color_by_layer(self.layer),
  30. "layer": f"图层{self.layer}"}
  31. self.msp.add_text("F", rotation=angle, dxfattribs=dxfattribs, height=self.width/2).set_placement(af, align=TextEntityAlignment.MIDDLE_CENTER)
  32. a_coe = 1 / 3
  33. a1 = center_x - self.width * a_coe, center_y + self.width * a_coe
  34. a2 = center_x - self.width * a_coe, center_y - self.width * a_coe
  35. a3 = center_x + self.width * a_coe, center_y + self.width * a_coe
  36. a4 = center_x + self.width * a_coe, center_y - self.width * a_coe
  37. a1 = core.rotate_point_around_another(a1, self.center, self.route)
  38. a2 = core.rotate_point_around_another(a2, self.center, self.route)
  39. a3 = core.rotate_point_around_another(a3, self.center, self.route)
  40. a4 = core.rotate_point_around_another(a4, self.center, self.route)
  41. self.msp.add_line(a1, a2,
  42. dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})
  43. self.msp.add_line(a3, a4,
  44. dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})
  45. c_coe = 3
  46. c1 = center_x - self.width * c_coe, center_y
  47. c2 = center_x - self.width * a_coe, center_y
  48. c3 = center_x + self.width * a_coe, center_y
  49. c4 = center_x + self.width * c_coe, center_y
  50. c1 = core.rotate_point_around_another(c1, self.center, self.route)
  51. c2 = core.rotate_point_around_another(c2, self.center, self.route)
  52. c3 = core.rotate_point_around_another(c3, self.center, self.route)
  53. c4 = core.rotate_point_around_another(c4, self.center, self.route)
  54. self.msp.add_line(c1, c2,
  55. dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})
  56. self.msp.add_line(c3, c4,
  57. dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})
  58. b1 = center_x - self.width * c_coe, center_y + self.width * a_coe
  59. b2 = center_x - self.width * c_coe, center_y - self.width * a_coe
  60. b3 = center_x + self.width * c_coe, center_y + self.width * a_coe
  61. b4 = center_x + self.width * c_coe, center_y - self.width * a_coe
  62. b1 = core.rotate_point_around_another(b1, self.center, self.route)
  63. b2 = core.rotate_point_around_another(b2, self.center, self.route)
  64. b3 = core.rotate_point_around_another(b3, self.center, self.route)
  65. b4 = core.rotate_point_around_another(b4, self.center, self.route)
  66. self.msp.add_line(b1, b2,
  67. dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})
  68. self.msp.add_line(b3, b4,
  69. dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})