import core from core import rotate_point_around_another class WindowDrawer: def __init__(self, msp, gap,layer, center,route): self.layer = layer self.msp = msp # 假设 msp 是绘图空间的引用 self.gap = gap # 转换系数 self.center = center self.route = route def trans_window_rate(self, n): return n * self.gap / 16.2 def create_window_points(self): cx, cy = self.center points = [] # 定义一系列点的偏移量 offsets = [ (-8.11, 12.63), (-8.11, 21.60), (-8.11, -12.63), (-8.11, -21.60), (8.11, 12.63), (8.11, 21.60), (8.11, -12.63), (8.11, -21.60), (-8.11, 10.02), (3.935, 10.02), (-3.935, 7.09), (8.11, 7.09), (-8.11, 4.32), (3.935, 4.32), (-3.935, 1.385), (8.11, 1.385), (-8.11, -1.39), (3.935, -1.39), (-3.935, -4.32), (8.11, -4.32), (-8.11, -7.10), (3.935, -7.10), (-3.935, -10.03), (8.11, -10.03) ] for dx, dy in offsets: x = cx + self.trans_window_rate(dx) y = cy + self.trans_window_rate(dy) rotated_point = rotate_point_around_another((x, y), self.center, self.route) points.append(rotated_point) return points def draw_window(self): points = self.create_window_points() # 绘制线条 lines = [ (points[1], points[3]), (points[5], points[7]), (points[0], points[4]), (points[2], points[6]), (points[8], points[9]), (points[9], points[11]), (points[10], points[11]), (points[8], points[10]), (points[12], points[13]), (points[13], points[15]), (points[14], points[15]), (points[12], points[14]), (points[16], points[17]), (points[17], points[19]), (points[18], points[19]), (points[16], points[18]), (points[20], points[21]), (points[21], points[23]), (points[22], points[23]), (points[20], points[22]) ] for line in lines: self.msp.add_line(line[0], line[1],dxfattribs={"layer":f"图层{self.layer}"}) return self.msp