shaft_drawer.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from numpy.ma.core import outer
  2. from drawer.BaseDrawer import VentGraphDrawer
  3. import math
  4. from core import rotate_point_around_another
  5. from ezdxf import math as mt
  6. class ShaftDrawer(VentGraphDrawer):
  7. def __init__(self, obj, msp, style):
  8. super().__init__(obj, msp, style)
  9. self.shaft_drawers = {
  10. 0: self.draw_shaft_style_0,
  11. 1: self.draw_shaft_style_1,
  12. }
  13. def initialize_data(self):
  14. pass
  15. def draw_obj(self, center, route):
  16. self.shaft_drawers[self.style](center)
  17. def draw_shaft_style_0(self, center):
  18. points12 = self.calculate_dodecagon_points(center)
  19. self.draw_polygon(points12)
  20. points8_out = self.calculate_outside_octagon_points(center)
  21. self.draw_polygon(points8_out)
  22. points8_in = self.calculate_inner_octagon_points(center)
  23. self.draw_polygon(points8_in)
  24. # for i,points8 in enumerate(points8_in):
  25. # msp.add_text(text=str(i),dxfattribs={'insert':points8})
  26. carc = mt.arc.ConstructionArc()
  27. b = carc.from_3p(start_point=points8_in[1], def_point=points8_in[3], end_point=points8_in[5])
  28. self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,
  29. dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  30. hatch = self.msp.add_hatch(dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  31. edge_path = hatch.paths.add_edge_path()
  32. edge_path.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle)
  33. def draw_shaft_style_1(self, center):
  34. inner_circle_rad = self.obj.width / 2.4
  35. outer_circle_rad = self.obj.width / 1.8
  36. self.msp.add_circle(center=center, radius=inner_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  37. self.msp.add_circle(center=center, radius=outer_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  38. hatch = self.msp.add_hatch(dxfattribs={"layer": f"图层{self.obj.layer_id}"})
  39. edge_path = hatch.paths.add_edge_path()
  40. edge_path.add_arc(center=center, radius=inner_circle_rad, start_angle=-90, end_angle=90)
  41. def calculate_dodecagon_points(self, center):
  42. # 存储结果的列表
  43. points = []
  44. points_rotated = []
  45. Cx, Cy = center
  46. r = 1 / 2 * self.obj.width
  47. # 正十二边形有12个顶点,每个顶点间隔30度
  48. for i in range(12):
  49. # 将角度从度转换为弧度
  50. theta = math.radians(30 * i)
  51. # 计算x和y坐标
  52. x = Cx + r * math.cos(theta)
  53. y = Cy + r * math.sin(theta)
  54. # 将坐标添加到列表中
  55. points.append((x, y))
  56. return points
  57. def calculate_outside_octagon_points(self, center):
  58. # 存储结果的列表
  59. points = []
  60. Cx, Cy = center
  61. r = 1 / 4 * self.obj.width
  62. # 正八边形有8个顶点,每个顶点间隔45度
  63. for i in range(8):
  64. # 将角度从度转换为弧度
  65. theta = math.radians(45 * i)
  66. # 计算x和y坐标
  67. x = Cx + r * math.cos(theta)
  68. y = Cy + r * math.sin(theta)
  69. x_y_ = rotate_point_around_another((x, y), center, math.radians(12.5))
  70. # 将坐标添加到列表中
  71. points.append(x_y_)
  72. return points
  73. def calculate_inner_octagon_points(self, center):
  74. # 存储结果的列表
  75. points = []
  76. Cx, Cy = center
  77. r = 1 / 8 * self.obj.width
  78. # 正八边形有8个顶点,每个顶点间隔45度
  79. for i in range(8):
  80. # 将角度从度转换为弧度
  81. theta = math.radians(45 * i)
  82. # 计算x和y坐标
  83. x = Cx + r * math.cos(theta)
  84. y = Cy + r * math.sin(theta)
  85. # 将坐标添加到列表中
  86. points.append((x, y))
  87. return points
  88. def draw_polygon(self, points):
  89. i = 0
  90. while i < len(points) - 1:
  91. self.msp.add_line(points[i], points[i + 1], {"layer": f"图层{self.obj.layer_id}"})
  92. i = i + 1
  93. self.msp.add_line(points[-1], points[0], {
  94. "layer": f"图层{self.obj.layer_id}"
  95. })