from core import rotate_point_around_another from drawer.BaseDrawer import BaseDrawer, VentGraphDrawer from entity.primitives import Gate from ezdxf import math as mt from dict.model_config import _get_app_name, _global_model_configs class GateDrawer(VentGraphDrawer): def __init__(self, obj, msp, style): super().__init__(obj, msp, style) self.gate_drawers = { 0: self.draw_gate_style_0, 1: self.draw_gate_style_1, 2: self.draw_gate_style_2, 3: self.draw_gate_style_3, 4: self.draw_gate_style_4 } def initialize_data(self): self.obj.color = (255, 255, 255) def draw_obj(self, center, route): self.gate_drawers[self.style](center, route) def add_gate_part(self, start_point, end_point, def_point): carc = mt.arc.ConstructionArc() b = carc.from_3p(start_point=start_point, def_point=def_point, end_point=end_point) arc = 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}", }) arc.rgb = self.obj.color # self.msp.add_lwpolyline([(start_point[0], start_point[1], 1), (end_point[0], end_point[1], 0)], format="xyb", dxfattribs={"layer": f"图层{self.layer}"}) line = self.msp.add_line(start_point, end_point, dxfattribs={"layer": f"图层{self.obj.layer_id}"}) line.rgb = self.obj.color def draw_gate_style_0(self, center, route): assert isinstance(self.obj, Gate) grid = 0.8 * self.obj.width rad = self.obj.width * 0.8 point_center = center # 计算第一个门的三个点 gate1_circle_a = (point_center[0] - grid, point_center[1] + rad) gate1_circle_b = (point_center[0] - grid, point_center[1] - rad) gate1_circle_c = (point_center[0] - grid + rad, point_center[1]) # 旋转这些点 gate1_a = rotate_point_around_another(gate1_circle_a, point_center, route) gate1_b = rotate_point_around_another(gate1_circle_b, point_center, route) gate1_c = rotate_point_around_another(gate1_circle_c, point_center, route) # 创建和添加第一个门的弧和线 self.add_gate_part(gate1_a, gate1_b, gate1_c) # 计算第二个门的三个点 gate2_circle_a = (point_center[0] + grid, point_center[1] + rad) gate2_circle_b = (point_center[0] + grid, point_center[1] - rad) gate2_circle_c = (point_center[0] + grid - rad, point_center[1]) # 旋转这些点 gate2_a = rotate_point_around_another(gate2_circle_a, point_center, route) gate2_b = rotate_point_around_another(gate2_circle_b, point_center, route) gate2_c = rotate_point_around_another(gate2_circle_c, point_center, route) # 创建和添加第二个门的弧和线 self.add_gate_part(gate2_a, gate2_b, gate2_c) def draw_gate_style_1(self, center, route): rad = self.obj.width * 0.8 small_circle_rad = self.obj.width * 0.1 gate1_circle_a = (center[0], center[1] + rad) gate1_circle_b = (center[0], center[1] - rad) gate1_circle_c = (center[0] + rad, center[1]) gate1_a = rotate_point_around_another(gate1_circle_a, center, route) gate1_b = rotate_point_around_another(gate1_circle_b, center, route) gate1_c = rotate_point_around_another(gate1_circle_c, center, route) carc = mt.arc.ConstructionArc() b = carc.from_3p(start_point=gate1_a, def_point=gate1_c, end_point=gate1_b) arc = 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}", "lineweight": 50}) arc.rgb = self.obj.color line = self.msp.add_line(gate1_a, gate1_b, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color self.msp.add_circle(center=gate1_a, radius=small_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"}) self.msp.add_circle(center=gate1_b, radius=small_circle_rad, dxfattribs={"layer": f"图层{self.obj.layer_id}"}) # b1 a1 # a3(| | # b2 a2 def draw_gate_style_4(self, center, route): a1 = center[0], center[1] + self.obj.width a2 = center[0], center[1] - self.obj.width a3 = center[0] - self.obj.width*1.5, center[1] b1 = a1[0] - 1 / 2 * self.obj.width, a1[1] b2 = a2[0] - 1 / 2 * self.obj.width, a2[1] a1 = rotate_point_around_another(a1, center, route) a2 = rotate_point_around_another(a2, center, route) a3 = rotate_point_around_another(a3, center, route) b1 = rotate_point_around_another(b1, center, route) b2 = rotate_point_around_another(b2, center, route) line = self.msp.add_line(a1, a2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color line = self.msp.add_line(b1, b2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color mt_carc = mt.arc.ConstructionArc() arc_1 = mt_carc.from_3p(start_point=b1, def_point=a3, end_point=b2) # b1 a1 c1 # a3(| | |)a4 # b2 a2 c2 arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle, end_angle=arc_1.end_angle, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) arc.rgb = self.obj.color # b1 a1 c1 # a3(| | |)a4 # b2 a2 c2 def draw_gate_style_2(self, center, route): a1 = center[0], center[1] + self.obj.width a2 = center[0], center[1] - self.obj.width a3 = center[0] - self.obj.width, center[1] a4 = center[0] + self.obj.width, center[1] b1 = a1[0] - 1 / 2 * self.obj.width, a1[1] b2 = a2[0] - 1 / 2 * self.obj.width, a2[1] c1 = a1[0] + 1 / 2 * self.obj.width, a1[1] c2 = a2[0] + 1 / 2 * self.obj.width, a2[1] a1 = rotate_point_around_another(a1, center, route) a2 = rotate_point_around_another(a2, center, route) a3 = rotate_point_around_another(a3, center, route) a4 = rotate_point_around_another(a4, center, route) b1 = rotate_point_around_another(b1, center, route) b2 = rotate_point_around_another(b2, center, route) c1 = rotate_point_around_another(c1, center, route) c2 = rotate_point_around_another(c2, center, route) line = self.msp.add_line(a1, a2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color line = self.msp.add_line(b1, b2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color line = self.msp.add_line(c1, c2, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color mt_carc = mt.arc.ConstructionArc() arc_1 = mt_carc.from_3p(start_point=c2, def_point=a4, end_point=c1) # b1 a1 c1 # a3(| | |)a4 # b2 a2 c2 arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle, end_angle=arc_1.end_angle, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) arc.rgb = self.obj.color arc_2 = mt_carc.from_3p(start_point=b1, def_point=a3, end_point=b2) arc = self.msp.add_arc(center=arc_2.center, radius=arc_2.radius, start_angle=arc_2.start_angle, end_angle=arc_2.end_angle, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) arc.rgb = self.obj.color def draw_gate_style_3(self, center, route): # 双向调节风门 # # a3---a1 a2---a4 # b1 c1 # d1(| |)d2 # b2 c2 unit = self.obj.width a1 = center[0] - 2 * unit, center[1] b1 = center[0] - unit, center[1] - unit c1 = center[0] - unit, center[1] + unit d1 = center[0] - unit, center[1] + unit * 1.15 e1 = center[0] - unit, center[1] - unit * 1.15 g1 = center[0] - 2 * unit, center[1] + unit * 1.15 f1 = center[0] - 0.15 * unit, center[1] + unit * 1.15 a1 = rotate_point_around_another(a1, center, route) b1 = rotate_point_around_another(b1, center, route) c1 = rotate_point_around_another(c1, center, route) d1 = rotate_point_around_another(d1, center, route) e1 = rotate_point_around_another(e1, center, route) g1 = rotate_point_around_another(g1, center, route) f1 = rotate_point_around_another(f1, center, route) line = self.msp.add_line(d1, e1, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color line = self.msp.add_line(g1, f1, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color mt_carc = mt.arc.ConstructionArc() arc_1 = mt_carc.from_3p(start_point=c1, def_point=a1, end_point=b1) arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle, end_angle=arc_1.end_angle, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) arc.rgb = self.obj.color a1 = center[0] + 2 * unit, center[1] b1 = center[0] + unit, center[1] - unit c1 = center[0] + unit, center[1] + unit d1 = center[0] + unit, center[1] + unit * 1.15 e1 = center[0] + unit, center[1] - unit * 1.15 g1 = center[0] + 2 * unit, center[1] + unit * 1.15 f1 = center[0] + 0.15 * unit, center[1] + unit * 1.15 a1 = rotate_point_around_another(a1, center, route) b1 = rotate_point_around_another(b1, center, route) c1 = rotate_point_around_another(c1, center, route) d1 = rotate_point_around_another(d1, center, route) e1 = rotate_point_around_another(e1, center, route) g1 = rotate_point_around_another(g1, center, route) f1 = rotate_point_around_another(f1, center, route) line = self.msp.add_line(d1, e1, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color line = self.msp.add_line(g1, f1, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) line.rgb = self.obj.color mt_carc = mt.arc.ConstructionArc() arc_1 = mt_carc.from_3p(start_point=b1, def_point=a1, end_point=c1) arc = self.msp.add_arc(center=arc_1.center, radius=arc_1.radius, start_angle=arc_1.start_angle, end_angle=arc_1.end_angle, dxfattribs={"layer": f"图层{self.obj.layer_id}", "lineweight": 50}) arc.rgb = self.obj.color