123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import math
- from ezdxf.enums import TextEntityAlignment
- import core
- class PlgTunDrawer:
- def __init__(self,msp,vec_b,vec_r,vec_l,text,layer,color,from_point,to_point,width):
- self.msp = msp
- self.vec_b = vec_b
- self.vec_r = vec_r
- self.vec_l = vec_l
- self.text = text
- self.layer = layer
- self.color = color
- self.from_point = from_point
- self.to_point = to_point
- self.width = width
- def draw_plg_tun(self):
- self.draw_plg(self.vec_b,(0,0,0))
- self.draw_plg(self.vec_l,self.color)
- self.draw_plg(self.vec_r,self.color)
- def draw_plg(self,points,color):
- hatch = self.msp.add_hatch(dxfattribs={"layer":f"图层{self.layer}"})
- hatch.rgb = color
- edge_path = hatch.paths.add_edge_path()
- for i in range(3):
- edge_path.add_line(points[i], points[i+1])
- edge_path.add_line(points[-1], points[0])
- def draw_tun_text(self):
- length = core.distance(self.from_point, self.to_point)
- text_len = len(self.text) * 0.6
- if length * 0.8 > text_len:
- if self.to_point[0]>self.from_point[0]:
- route = core.calculate_angle_with_x_axis(self.from_point, self.to_point)
- else:
- route = core.calculate_angle_with_x_axis(self.to_point, self.from_point)
- angle = math.degrees(route)
- # if angle < -90: angle = angle+180
- from_point, to_point = core.parallel_line(self.from_point, self.to_point, 3.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,height=1).set_placement(tun_center, align=TextEntityAlignment.CENTER)
- def draw_middle_line(self):
- self.msp.add_line(self.from_point, self.to_point, dxfattribs={
- 'color': '1',
- 'layer': f'图层{self.layer}'
- })
|