import math import time import ezdxf from ezdxf.enums import TextEntityAlignment import core class AirDuctExampleDrawer: def __init__(self, msp, width, layer, center, route): self.msp = msp self.layer = layer self.center = center self.width = width self.route = route # b1 a1 a3 b3 # c1|----------c2|F|c3----------c4|F # b2 a2 a4 b4 def draw_air_duct_example(self): angle = math.degrees(self.route) center_x = self.center[0] center_y = self.center[1] dxfattribs = { 'insert': self.center, 'style': 'msyh', 'color': core.get_color_by_layer(self.layer), "layer": f"图层{self.layer}", } self.msp.add_text("F", rotation=angle, dxfattribs=dxfattribs, height=self.width/2).set_placement(self.center, align=TextEntityAlignment.MIDDLE_CENTER) F_coe = 3.3 af = center_x+F_coe*self.width,center_y af = core.rotate_point_around_another(af, self.center, self.route) dxfattribs = { 'insert': af, 'style': 'msyh', 'color': core.get_color_by_layer(self.layer), "layer": f"图层{self.layer}"} self.msp.add_text("F", rotation=angle, dxfattribs=dxfattribs, height=self.width/2).set_placement(af, align=TextEntityAlignment.MIDDLE_CENTER) a_coe = 1 / 3 a1 = center_x - self.width * a_coe, center_y + self.width * a_coe a2 = center_x - self.width * a_coe, center_y - self.width * a_coe a3 = center_x + self.width * a_coe, center_y + self.width * a_coe a4 = center_x + self.width * a_coe, center_y - self.width * a_coe a1 = core.rotate_point_around_another(a1, self.center, self.route) a2 = core.rotate_point_around_another(a2, self.center, self.route) a3 = core.rotate_point_around_another(a3, self.center, self.route) a4 = core.rotate_point_around_another(a4, self.center, self.route) self.msp.add_line(a1, a2, dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)}) self.msp.add_line(a3, a4, dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)}) c_coe = 3 c1 = center_x - self.width * c_coe, center_y c2 = center_x - self.width * a_coe, center_y c3 = center_x + self.width * a_coe, center_y c4 = center_x + self.width * c_coe, center_y c1 = core.rotate_point_around_another(c1, self.center, self.route) c2 = core.rotate_point_around_another(c2, self.center, self.route) c3 = core.rotate_point_around_another(c3, self.center, self.route) c4 = core.rotate_point_around_another(c4, self.center, self.route) self.msp.add_line(c1, c2, dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)}) self.msp.add_line(c3, c4, dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)}) b1 = center_x - self.width * c_coe, center_y + self.width * a_coe b2 = center_x - self.width * c_coe, center_y - self.width * a_coe b3 = center_x + self.width * c_coe, center_y + self.width * a_coe b4 = center_x + self.width * c_coe, center_y - self.width * a_coe b1 = core.rotate_point_around_another(b1, self.center, self.route) b2 = core.rotate_point_around_another(b2, self.center, self.route) b3 = core.rotate_point_around_another(b3, self.center, self.route) b4 = core.rotate_point_around_another(b4, self.center, self.route) self.msp.add_line(b1, b2, dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)}) self.msp.add_line(b3, b4, dxfattribs={"layer": f"图层{self.layer}", "color": core.get_color_by_layer(self.layer)})