123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- from numpy.ma.core import outer
- from drawer.BaseDrawer import VentGraphDrawer
- import math
- from core import rotate_point_around_another
- from ezdxf import math as mt
- class ShaftDrawer(VentGraphDrawer):
- def __init__(self, obj, msp, style):
- super().__init__(obj, msp, style)
- self.shaft_drawers = {
- 0: self.draw_shaft_style_0,
- 1: self.draw_shaft_style_1,
- }
- def initialize_data(self):
- pass
- def draw_obj(self, center, route):
- self.shaft_drawers[self.style](center)
- def draw_shaft_style_0(self, center):
- points12 = self.calculate_dodecagon_points(center)
- self.draw_polygon(points12)
- points8_out = self.calculate_outside_octagon_points(center)
- self.draw_polygon(points8_out)
- points8_in = self.calculate_inner_octagon_points(center)
- self.draw_polygon(points8_in)
- # for i,points8 in enumerate(points8_in):
- # msp.add_text(text=str(i),dxfattribs={'insert':points8})
- carc = mt.arc.ConstructionArc()
- b = carc.from_3p(start_point=points8_in[1], def_point=points8_in[3], end_point=points8_in[5])
- self.msp.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle,
- dxfattribs={"layer": f"图层{self.obj.layer_id}"})
- hatch = self.msp.add_hatch(dxfattribs={"layer": f"图层{self.obj.layer_id}"})
- edge_path = hatch.paths.add_edge_path()
- edge_path.add_arc(center=b.center, radius=b.radius, start_angle=b.start_angle, end_angle=b.end_angle)
- def draw_shaft_style_1(self, center):
- inner_circle_rad = self.obj.width / 2.4
- outer_circle_rad = self.obj.width / 1.8
- self.msp.add_circle(center=center, radius=inner_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
- self.msp.add_circle(center=center, radius=outer_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"})
- hatch = self.msp.add_hatch(dxfattribs={"layer": f"图层{self.obj.layer_id}"})
- edge_path = hatch.paths.add_edge_path()
- edge_path.add_arc(center=center, radius=inner_circle_rad, start_angle=-90, end_angle=90)
- def calculate_dodecagon_points(self, center):
- # 存储结果的列表
- points = []
- points_rotated = []
- Cx, Cy = center
- r = 1 / 2 * self.obj.width
- # 正十二边形有12个顶点,每个顶点间隔30度
- for i in range(12):
- # 将角度从度转换为弧度
- theta = math.radians(30 * i)
- # 计算x和y坐标
- x = Cx + r * math.cos(theta)
- y = Cy + r * math.sin(theta)
- # 将坐标添加到列表中
- points.append((x, y))
- return points
- def calculate_outside_octagon_points(self, center):
- # 存储结果的列表
- points = []
- Cx, Cy = center
- r = 1 / 4 * self.obj.width
- # 正八边形有8个顶点,每个顶点间隔45度
- for i in range(8):
- # 将角度从度转换为弧度
- theta = math.radians(45 * i)
- # 计算x和y坐标
- x = Cx + r * math.cos(theta)
- y = Cy + r * math.sin(theta)
- x_y_ = rotate_point_around_another((x, y), center, math.radians(12.5))
- # 将坐标添加到列表中
- points.append(x_y_)
- return points
- def calculate_inner_octagon_points(self, center):
- # 存储结果的列表
- points = []
- Cx, Cy = center
- r = 1 / 8 * self.obj.width
- # 正八边形有8个顶点,每个顶点间隔45度
- for i in range(8):
- # 将角度从度转换为弧度
- theta = math.radians(45 * i)
- # 计算x和y坐标
- x = Cx + r * math.cos(theta)
- y = Cy + r * math.sin(theta)
- # 将坐标添加到列表中
- points.append((x, y))
- return points
- def draw_polygon(self, points):
- i = 0
- while i < len(points) - 1:
- self.msp.add_line(points[i], points[i + 1], {"layer": f"图层{self.obj.layer_id}"})
- i = i + 1
- self.msp.add_line(points[-1], points[0], {
- "layer": f"图层{self.obj.layer_id}"
- })
|