123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import math
- import core
- class TunDrawer:
- def __init__(self, msp, layer, vec12, vec34, from_point, to_point, text, width):
- self.width = width
- self.text = text
- self.msp = msp
- self.layer = layer
- self.vec12 = vec12
- self.vec34 = vec34
- self.from_point = from_point
- self.to_point = to_point
- def draw_tun(self):
- color = core.get_color_by_layer(self.layer)
- for i in range(0, len(self.vec12), 2):
- pair = self.vec12[i:i + 2]
- point1 = pair[0][0], pair[0][1]
- point2 = pair[1][0], pair[1][1]
- # 取出每两个元素
- self.msp.add_line(point1, point2, dxfattribs={
- 'color': color,
- 'layer': f'图层{self.layer}'
- })
- for i in range(0, len(self.vec34), 2):
- pair = self.vec34[i:i + 2] # 取出每两个元素
- point1 = pair[0][0], pair[0][1]
- point2 = pair[1][0], pair[1][1]
- self.msp.add_line(point1, point2, dxfattribs={
- 'color': color,
- 'layer': f'图层{self.layer}'
- })
- self.draw_tun_text()
- # self.draw_middle_line()
- def draw_tun_text(self):
- length = core.distance(self.from_point, self.to_point)
- if length > 70:
- route = core.calculate_route(self.from_point, self.to_point)
- angle = math.degrees(route)
- from_point, to_point = core.parallel_line(self.from_point, self.to_point, 1.5*self.width)
- tun_center = core.find_point_on_line(from_point, to_point, 1 / 2)
- dxfattribs = {
- 'insert': tun_center, 'style': 'msyh', 'color': core.get_color_by_layer(self.layer), "layer": f"图层{self.layer}"}
- self.msp.add_text(text=self.text, rotation=angle, dxfattribs=dxfattribs)
- def draw_middle_line(self):
- self.msp.add_line(self.from_point, self.to_point, dxfattribs={
- 'color': '1',
- 'layer': f'图层{self.layer}'
- })
|