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, } 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}"})