
    'j                       d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
Z
d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZm Z  d dl!m"Z" d d	l#m$Z$ d d
l%m&Z& d dl'm(Z(m)Z) d dl*m+Z+m,Z- d dl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7 erd dl8m9Z9 d dl:m;Z; d dl!m<Z<m=Z=m>Z>m?Z?m@Z@ g dZA ejB        d          ZCdZDdZE G d de$jF                  ZGi dddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEZH G dF dG          ZI	 dddMZJddPZKddTZLddXZMejN        ejO        ejP        hZQdd\ZRdddZSddeZTddfZUddgZVddiZWddjZXefddnZYddpZZ G dq dr          Z[ G ds dtej\                  Z] G du dvej^                  Z_e_j`        ee_ja        e e_jb        e e_jc        eiZd G dw dxej\                  Ze G dy dzej\                  Zf G d{ d|ej\                  Zg G d} d~ej\                  Zhe G d d                      ZiddZj G d de
jk                  Zl G d del          Zm G d del          ZndS )    )annotations)AnyIterableIteratorOptionalTYPE_CHECKINGUnioncastN)defaultdict)	dataclass)colors)BoundingBoxMatrix44NULLVECOCSUCSUVecVec2Vec3X_AXISZ_AXISfit_points_to_cad_cvis_point_left_of_line)factory)const)ProxyGraphic)ARROWSarrow_length)	text_sizetext)	
AttribData	BlockData
LeaderData
LeaderLineMLeaderContextMLeaderStyle	MTextDataMultiLeaderacdb_mleader_style)Drawing)BlockLayout)
DXFGraphicInsertMTextSpline	Textstyle)
virtual_entitiesMultiLeaderBuilderMultiLeaderMTextBuilderMultiLeaderBlockBuilderConnectionSideHorizontalConnectionVerticalConnection
LeaderTypeTextAlignmentBlockAlignmentezdxfTg?c                      e Zd ZdS )ConnectionTypeErrorN)__name__
__module____qualname__     N/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/render/mleader.pyr=   r=   [   s        DrB   r=   leader_type   leader_line_color   leader_linetype_handle   leader_lineweight   has_landing   landing_gap    
has_dogleg@   dogleg_length   arrow_head_handle   arrow_head_sizei   content_typei   text_style_handlei   text_left_attachment_typei   text_angle_typei    text_alignment_typei @  
text_colori   char_heighti   i   i   i   i    i  @ i   i   i   i   i   i   i    )has_text_frameblock_record_handleblock_colorblock_scale_vectorblock_rotationblock_connection_typescaletext_right_attachment_typetext_switch_alignmenttext_attachment_directiontext_top_attachment_typetext_bottom_attachment_typec                  &    e Zd ZddZdd
ZddZdS )MLeaderStyleOverridestyler&   mleaderr(   c                   |j         | _        |j         | _        |j        | _        |j                             dd          | _        t          |j                             dd          |j                             dd          |j                             dd          f          | _        t          | j        dz            | _
        d S )Nproperty_override_flagsr   block_scale_x      ?block_scale_yblock_scale_zi   )dxf
_style_dxf_mleader_dxfcontext_contextget_property_override_flagsr   _block_scale_vectorbooluse_mtext_default_content)selfrl   rm   s      rC   __init__zMLeaderStyleOverride.__init__   s    )#K(/%q)
 )
% $(	os33	os33	os33$
 $
  *.)W5*
 *
&&&rB   attrib_namestrreturnr   c                    |dk    r| j         }n| j                            |          }t          s|                     |          r.|dk    r| j        j        }n| j                            ||          }|S )Nra   r]   )	r{   ru   get_defaultIGNORE_OVERRIDE_FLAGSis_overriddenrx   r]   rv   ry   )r~   r   values      rC   ry   zMLeaderStyleOverride.get   s    ...,EEO//<<E  	BD$6$6{$C$C 	Bm++1)--k5AArB   r|   c                f    t                               |d          }t          || j        z            S Nr   )OVERRIDE_FLAGry   r|   rz   )r~   r   flags      rC   r   z"MLeaderStyleOverride.is_overridden   s-      a00D488999rB   N)rl   r&   rm   r(   )r   r   r   r   )r   r   r   r|   )r>   r?   r@   r   ry   r   rA   rB   rC   rk   rk      sP        
 
 
 
$   : : : : : :rB   rk   Frm   r(   r   Iterator[DXFGraphic]c                    | j         }|
J d            |r.| j        't          | j        |                                          S t	          t          | |                                                    S )Nvalid DXF document required)docproxy_graphicr   r1   iterRenderEnginerun)rm   r   r   s      rC   r1   r1      sn     +C??9??? 6.:G1377HHJJJL#..2244555rB   r   r*   c                    | j         j        }|j                            |          }|8t                              d| d           |j                            d          }|
J d            t          t          t          |          |           S )Nzreferenced MLEADERSTYLE(#() does not exist, replaced by 'Standard'Standardz0mandatory MLEADERSTYLE 'Standard' does not exist)
rt   style_handleentitydbry   loggerwarningmleader_stylesrk   r
   r&   )rm   r   handlerl   s       rC   	get_styler      s    [%FLV$$E}& & & &	
 	
 	
 "&&z22P\5 9 97CCCrB   r   r   r0   c                    |j                             |           }|8t                              d|  d           |j                            d          }|
J d            |S )Nzreferenced STYLE(#r   r   z)mandatory STYLE 'Standard' does not exist)r   ry   r   r   styles)r   r   
text_styles      rC   get_text_styler      sy    !!&))J& & & &	
 	
 	
 Z^^J//
!!#N!!!rB   vertices
list[Vec3]r   c                    t          |           dk     rt          S | d         | d         z
  }|                                S )NrG   rE   r   )lenr   	normalize)r   	directions     rC   get_arrow_directionr      s<    
8}}qhqk)I   rB   	raw_colorinttuple[int, Optional[int]]c                    t           j        }d }t          j        |           \  }}|t          v r|}n|t           j        k    r|}||fS N)r   BYBLOCKdecode_raw_color_intACI_COLOR_TYPESCOLOR_TYPE_RGB)r   	aci_color
true_color
color_typecolors        rC   decode_raw_colorr      sS    I $J3I>>J_$$			v,	,	,
j  rB   mtextr.   
mtext_datar'   rd   floatNonec                   |j         | _        | j        }t          |j                  \  }}||_        |||_        |j        |_        | j        J t          |j	        | j                  j        j
        | j        _        |j                            t                    s|j        |_        |j        |_        |j        |z  |_        |j        |_        |j        |_        |j        |_        |j        |_        d S r   )default_contentr    rt   r   r   r   insertr   r   r   namerl   	extrusioniscloser   text_directionwidthline_spacing_factorline_spacing_styleflow_direction	alignmentattachment_point)r   r   rd   rt   r   r   s         rC   copy_mtext_datar      s     +EJ
)C,Z-=>>IzCI#"CJ9   $ 	$ 
IO ''// -",#2C 5(CI(<C':C#2C%/CrB   c                h   t          dt          j        d| j                            }| j        j        |j        _        | j        }|j        }|t          d          |j	        }|j
        |j        _
        |9t          |||           |j        rt          ||           t          |||           |S )Nr.   MTEXT)r   z MULTILEADER has no MTEXT content)r
   r   newr   rt   layerrw   r   	TypeErrorrd   r]   r   has_bg_fillset_mtext_bg_fillset_mtext_columns)rm   r   rw   r   rd   s        rC   
make_mtextr      s    '+g7;???@@Ek'EIOoGJ;<<<ME#/EIz5111! 	1eZ000%U333LrB   c                t   |j         | j        _        d| j        _        t          j        | j        _        |j        | j        _        t	          j	        |j
                  \  }}|t          v r|| j        _        n|t          j        k    r|| j        _        |j        s|t          j        k    rd| j        _        d S d S )NrE      )bg_scale_factorrt   box_fill_scalebg_fillr   r   bg_fill_colorbg_transparencybg_fill_transparencyr   bg_colorr   r   bg_fill_true_coloruse_window_bg_colorCOLOR_TYPE_WINDOW_BG)r   r   r   r   s       rC   r   r     s      *9EIEI$nEI%/%?EI"3J4GHHJ_$$"'		v,	,	,',	$ 	&444 	 54rB   c                    d S r   rA   )r   r   rd   s      rC   r   r   &  s	    
 	DrB   entityc                j    | j         }|j        |j        j        S |j        |j        j        S |j        S r   )rw   r   r   blockplane_originr   rw   s     rC   _get_insertr   .  s8    nG} }##		"}##rB   c                j    | j         }|j        |j        j        S |j        |j        j        S |j        S r   )rw   r   r   r   plane_z_axisr   s     rC   _get_extrusionr   7  s8    nG} }&&		"}&&rB   leaderr#   defaultc                    	 | j         r| j                            | j                  S n# t          $ r Y nw xY w|                    | j                  S r   )has_dogleg_vectordogleg_vectorr   rR   ZeroDivisionError)r   r   s     rC   _get_dogleg_vectorr   @  sj    # 	H'11&2FGGG	H   V1222s   %) 
66Optional[str]c                    |j                             |           }| t                              d|  d           d S |j                            d          S )Nzrequired BLOCK_RECORD entity # does not existr   )r   ry   r   errorrt   )r   r   block_records      rC   _get_block_namer   J  sW    <##F++LMfMMMNNNt'''rB   c                     e Zd Zd=dZed>d            Zed>d	            Zed>d
            Zed?d            Zd@dZ	dAdZ
dBdZdCdDdZdEdZdEdZdEdZdEdZdFd ZdEd!ZdGd$ZdGd%Z	 dHdId)ZdJd,ZdKd.Z	 	 dLdMd3ZdCdNd7ZdOd<ZdS )Pr   rm   r(   r   r*   c                    g | _         || _        || _        t          ||          | _        |j        | _        t          |          | _        t          |          | _	        d | _
        | j	                            t                    st          | j	                  | _
        | j        j        | _        | j        j        | _        |j        j        | _        |                                 | _        | j                            d          | _        t/          | j                            d                    \  }}|| _        || _        | j                            d          | _        d| _        t9          | j                            d                    | _        d |j        D             | _        | j                            d          | _        d | _         d | _!        t9          | j                            d                    | _"        | j                            d	          | _#        | j                            d
          | _$        | j                            d          | _%        | j                            d          | _&        d S )NrJ   rF   rD   FrP   c                (    i | ]}|j         |j        S rA   )indexr   ).0heads     rC   
<dictcomp>z)RenderEngine.__init__.<locals>.<dictcomp>n  s+     ,
 ,
 ,
(,DJ,
 ,
 ,
rB   rT   rg   rY   re   rh   ri   )'entitiesrm   r   r   rl   rw   r   r   r   r   ocsr   r   r   z	elevationrd   rt   r   linetype_namelinetypery   
lineweightr   leader_aci_colorleader_true_colorrD   r^   r|   rP   arrow_headsrT   dxf_mtext_entity_dxf_mtext_extentshas_horizontal_attachmentleft_attachment_typeright_attachment_typetop_attachment_typebottom_attachment_type)r~   rm   r   r   r   s        rC   r   zRenderEngine.__init__S  s   *,+4Wc+B+B
!'**-g66"&~%%f-- 	+4>**DH $ !L.
[&
**,,*..)<== 0JNN.//!
 !
	: &/0: $
} = =# $TZ^^L%A%A B B,
 ,
070C,
 ,
 ,
 "&0C!D!D37AE)-JNN677*
 *
& %)JNN3N$O$O!%)Z^^(&
 &
" $(:>>2L#M#M &*jnn)'
 '
###rB   r   r|   c                    | j         d uS r   )r   r~   s    rC   has_extrusionzRenderEngine.has_extrusion  s    xt##rB   c                    | j         j        d uS r   )rw   r   r  s    rC   has_text_contentzRenderEngine.has_text_content      |!--rB   c                    | j         j        d uS r   )rw   r   r  s    rC   has_block_contentzRenderEngine.has_block_content  r  rB   tuple[float, float]c                    | j         | j         S | j        t          j        | j                  \  }}nd\  }}||f| _         | j         S )z Calculate MTEXT width on demand.N        r  )r  r  r   estimate_mtext_extents)r~   r   heights      rC   mtext_extentszRenderEngine.mtext_extents  s_     ".** , &<% ME66 %ME6#(&/&&rB   list[DXFGraphic]c                    | j                                          t          | j                  dk    r(|                                  |                                  | j         S )z'Entry point to render MLEADER entities.&.>)r   clearabsrd   add_contentadd_leadersr  s    rC   r   zRenderEngine.run  sU    tz??T!!}rB   r   c                    | j                             d          }| j        j                            |          }||j        j        S t                              d| d| j                    dS )NrH   zinvalid linetype handle # in 
Continuous)	rl   ry   r   r   rt   r   r   r   rm   )r~   r   ltypes      rC   r   zRenderEngine.linetype_name  sh     899!%%f--9>!M6MMt|MMNNN|rB   r   r   c                   d}| j                             || j                  }||dk    r|S | j        j                            |          }|(t
                              d| d| j         d           |S |j        j	        S )N_CLOSED_FILLED0zarrow block #r$  z0 does not exist, replaced by closed filled arrow)
r  ry   rT   r   r   r   r   rm   rt   r   )r~   r   closed_filledr   r   s        rC   arrow_block_namezRenderEngine.arrow_block_name  s    (!%%eT-CDD>Vs]]  x(,,V44NN3 3 3DL 3 3 3   ! $$rB   Nr   Optional[int]dictc                    | j         }| j        }|r |t          j        urt	          |          \  }}| j        || j        | j        d}|||d<   |S )N)r   r   r  r  r   )r  r  r   BY_BLOCK_RAW_VALUEr   r   r  r  )r~   r   r   r   attribss        rC   leader_line_attribsz RenderEngine.leader_line_attribs  ss    )	+
  	@&*CCC$4Y$?$?!Iz Z/	
 
 !$.GL!rB   r   c                z    | j         r|                                  d S | j        r|                                  d S d S r   )r  add_mtext_contentr  add_block_contentr  s    rC   r!  zRenderEngine.add_content  sR      	%""$$$$$# 	%""$$$$$	% 	%rB   c                    t          | j                  }| j                            |           || _        | j        r|                                  d S d S r   )r   rm   r   appendr  r^   add_text_frame)r~   r   s     rC   r3  zRenderEngine.add_mtext_content  s\    4<((U### % 	"!!!!!	" 	"rB   c                    d S r   rA   r  s    rC   r7  zRenderEngine.add_text_frame  s	     	rB   c           	     :   | j         j        }|J t          |j        | j                  }|d S |j        }t          j        |j                  }| j	        | j	        
                    |          }t          |j                  \  }}|j        }|||||j        |j        |j        |j        d}|||d<   t%          dt'          j        d|| j                            }	| j                            |	           | j        j        r|                     |	           d S d S )N)r   r   rotationr   r   xscaleyscalezscaler   r-   INSERT
dxfattribsr   )rw   r   r   r_   r   r   mathdegreesr:  r   from_wcsr   r   rd   r   xyr   r
   r   r   r   r6  rm   block_attribsadd_block_attributes)
r~   r   
block_namelocationr:  r   r   rd   r0  r   s
             rC   r4  zRenderEngine.add_block_content  s7   "   $U%>II
F<<//8x((22H 0 = =	:  ggg	
 	
 !$.GL!gk(wDHMMM
 
 	V$$$<% 	.%%f-----	. 	.rB   r   r-   c                6   | j         j        }t                      }| j        j        D ]X}|                    |j                  }|$t                              d|j         d           B|j	        j
        }|j        ||<   Y|r|                    |           d S d S )Nzrequired ATTDEF entity #r   )r   r   r-  rm   rF  ry   r   r   r   rt   tagr    add_auto_attribs)r~   r   r   valuesattribattdefrK  s          rC   rG  z!RenderEngine.add_block_attributes  s    8$!%l0 	& 	&F\\&-00F~Mv}MMM   *.C +F3KK 	,##F+++++	, 	,rB   c                    | j         dk    rd S | j        j        D ][}|j        D ]}|                     ||           | j        r2|j        r|                     |           F|                     |           \d S r   )	rD   rw   leaderslinesadd_leader_liner  r  add_text_underlineadd_overline)r~   r   lines      rC   r"  zRenderEngine.add_leaders  s    q  Fl* 	. 	.F 3 3$$VT2222$ 	.3 . ++F3333 %%f---	. 	.rB   r   r#   c                   | j         j        }|d S | j        dv }| j        dv }|s|sd S |j        t          |          z   }| j        \  }}|| j         j        z   }|dk     rd S |j        }	| j	        -|	j
        }
|j        j
                                        }|j
        }nk| j	        j        }t           ||	                    }
t           ||j                                                            }t           ||                    }t          ||
|
|z             }| }|j                            |r|n|           }|r|s|r|r|                     |||z              d S d S d S )N)      rK   r  )rw   r   r	  r
  last_leader_pointr   r  landing_gap_sizer   r   vec2r   
orthogonalrC  r   r   r   add_dxf_line)r~   r   r   has_left_underlinehas_right_underlineconnection_pointr   r  lengthstartstart2dup2dcp2drC  is_leftis_rightrV  s                    rC   rT  zRenderEngine.add_text_underline'  s   "=F!6)C"8IE" 	&9 	F!36H6P6PP*v66D==F 8jG',7799D#(DDx(H88E??++G!56677BBDDD!12233D'gw~FF;#--.LfffWMM 	I* 	I	I,	I .0@40GHHHHH	I 	I 	I 	IrB   c                   | j         j        }|d S | j        dk    }| j        dk    }|s|sd S | j        \  }}|dk     rd S |j        }|j        }|j                            |dz            }	||	z
  }
||	z   }| j	        t          ||
|          }n8| j	        j        }t           ||           ||
           ||                    }| }|r|s|r|r|                     |
|           d S d S d S )N
   r  rG   )rw   r   r  r  r  rZ  r   r   r   r   r   rC  r^  )r~   r   r   has_bottom_linehas_top_linerb  r  centerr   line2rc  endbottomrC  tops                  rC   rU  zRenderEngine.add_overlineI  sF   "=F5;/25 	< 	F+D==F
 )$..vz::un8*65#>>FFx(H*  ((5//88C== F j 	* 	*C 	*L 	*eS)))))	* 	* 	* 	*rB   Fline_verticesr   c                    t          |          }|j        }|j        r=|r|                    |           |                    |t	          |          z              n|                    |           |S r   )listrZ  r  r6  r   )r~   r   rr  rP   r   	end_points         rC   leader_verticeszRenderEngine.leader_verticesi  sx     &&,	+ 	' +	***OOI(:6(B(BBCCCCOOI&&&rB   rV  r$   c                   | j         }|dk    rd S | j        }|dk    rd}|                     ||j        |          }t	          |          dk     rd S t          |          }|j        }|j        }|                     | 	                    |                    }	| j
        j        }
|                     |	|d         ||
|           |t          |	|
          z  }|dxx         |z  cc<   |dk    r7t          ||dd                    D ]\  }}|                     |||           d S |dk    rD|j        rt#          |          }n|d         |d         z
  }|                     |||g|           d S d S )	Nr   rG   F)r   rI  r   rd   r   rE   )tangentsr   )rD   rP   rv  r   r   r   r   r   create_arrow_blockr+  rw   rV   	add_arrowr   zipr^  r  r   add_dxf_spline)r~   r   rV  rD   rP   r   arrow_directionr   r   rH  
arrow_sizearrow_offsetseend_tangents                  rC   rS  zRenderEngine.add_leader_linew  s   +!F?
!J#33DM: 
  
 x==1F 3H = =	Z11$2G2G2N2NOO
 L8
a[% 	 	
 	
 	
 -|
0
 0
 
 	|#!Hhqrrl33 3 31!!!Q	22223 3A/ :088&rlXb\9);7	        rB   r   c                    || j         j        vrHt          j        |          }|t          vrt          j        }t          j        | j         j        |          }|S r   )r   blocksr   
arrow_namer*  create_block)r~   r   r  s      rC   r{  zRenderEngine.create_arrow_block  sO    tx&&*400J''#1
&tx
CCDrB   
fit_pointsrz  Optional[Iterable[UVec]]r   c                    |                      |          }t          dt          j        d|| j                            }|                    t          ||                     | j                            |           d S )Nr/   SPLINEr?  )rz  )	r1  r
   r   r   r   apply_construction_toolr   r   r6  )r~   r  rz  r   r0  splines         rC   r~  zRenderEngine.add_dxf_spline  s     **511KW$(CCC
 
 	&& h???	
 	
 	
 	V$$$$$rB   rc  r   ro  c                    |                      |          }||d<   ||d<   | j                            t          j        d|| j                             d S )Nrc  ro  LINEr?  )r1  r   r6  r   r   r   )r~   rc  ro  r   r0  s        rC   r^  zRenderEngine.add_dxf_line  sb    **511 K7AAA	
 	
 	
 	
 	
rB   rI  r   rd   r   c                n   |                      |          }||d<   | j        >| j                            |          }| j                            |          }| j        |d<   ||d<   |j        dz   |d<   ||d<   ||d<   ||d<   | j                            t          j        d	|| j	        
                     d S )Nr   r   r   g     f@r:  r;  r<  r=  r>  r?  )
r1  r   rC  r   	angle_degr   r6  r   r   r   )r~   r   rI  r   rd   r   r0  s          rC   r|  zRenderEngine.add_arrow  s     **5118x((22H)))44I#'>GK $'1E9
!!!KW$(CCC	
 	
 	
 	
 	
rB   )rm   r(   r   r*   )r   r|   )r   r  )r   r  )r   r   )r   r   r   r   r   )r   r,  r   r-  )r   r   )r   r-   )r   r#   F)r   r#   rr  r   r   r   )r   r#   rV  r$   )r   r   r   r   )NN)r  r   rz  r  r   r,  )rc  r   ro  r   r   r,  )
r   r   rI  r   r   r   rd   r   r   r   )r>   r?   r@   r   propertyr  r  r  r  r   r   r+  r1  r!  r3  r7  r4  rG  r"  rT  rU  rv  rS  r{  r~  r^  r|  rA   rB   rC   r   r   R  s<       +
 +
 +
 +
Z $ $ $ X$ . . . X. . . . X. ' ' ' X'"      % % % %    $% % % %" " " "   . . . .@, , , ,. . . .& I  I  I  ID* * * *B IN    + + + +Z    .2#	% % % % % 
 
 
 
 

 
 
 
 
 
rB   r   c                      e Zd ZdZdZdZdZdS )r8   zThe leader type.r   rE   rG   N)r>   r?   r@   __doc__nonestraight_linessplinesrA   rB   rC   r8   r8     s#        DNGGGrB   r8   c                      e Zd ZdZ ej                    Z ej                    Z ej                    Z ej                    Z	dS )r5   z
    The leader connection side.

    Vertical (top, bottom) and horizontal attachment sides (left, right)
    can not be mixed in a single entity - this is a limitation of the
    MULTILEADER entity.
    N)
r>   r?   r@   r  enumautoleftrightrq  rp  rA   rB   rC   r5   r5     sN          49;;DDIKKE
$)++CTY[[FFFrB   r5   c                  :    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdS )r6   z&The horizontal leader connection type.rx  r   rE   rG   r   rI   rX  rY     rK   N)r>   r?   r@   r  by_styletop_of_top_linemiddle_of_top_linemiddle_of_textmiddle_of_bottom_linebottom_of_bottom_linebottom_of_bottom_line_underlinebottom_of_top_line_underlinebottom_of_top_line bottom_of_top_line_underline_allrA   rB   rC   r6   r6     sO        00HON&'##$ '($$$rB   r6   c                      e Zd ZdZdZdZdZdS )r7   z$The vertical leader connection type.r   	   rj  N)r>   r?   r@   r  r  rm  center_overlinerA   rB   rC   r7   r7     s#        ..HFOOOrB   r7   c                      e Zd ZdZdZdZdZdS )r9   z"The :class:`MText` alignment type.rE   rG   r   N)r>   r?   r@   r  r  rm  r  rA   rB   rC   r9   r9     s#        ,,DFEEErB   r9   c                      e Zd ZdZdZdZdS )r:   z"The :class:`Block` alignment type.r   rE   N)r>   r?   r@   r  center_extentsinsertion_pointrA   rB   rC   r:   r:     s        ,,NOOOrB   r:   c                  D    e Zd ZU dZded<   ded<   ded<   ded<   dd
ZdS )ConnectionBoxzdContains the connection points for all 4 sides of the content, the
    landing gap is included.
    r   r  r  rq  rp  sider5   r   c                    |t           j        k    r| j        S |t           j        k    r| j        S |t           j        k    r| j        S | j        S r   )r5   r  r  rq  rp  )r~   r  s     rC   ry   zConnectionBox.get/  sK    >&&&9^))):^'''8O{rB   N)r  r5   r   r   )r>   r?   r@   r  __annotations__ry   rA   rB   rC   r  r  $  sZ           JJJKKKIIILLL     rB   r  ucsr   c                    t          j        | j                  sBt          | j                  }t	          |                    | j                            }|j        S dS )z)Returns the ocs rotation angle of the UCSr  )r   r   uzr   r   rC  uxangle)r  r   x_axis_in_ocss      rC   ocs_rotationr  9  sL    >#&!! ##&kkS\\#&1122""3rB   c                     e Zd ZdEdZej        d             Zd Zej        dFd            Zej        dGd            Z	ej        dHd            Z
ej        dId            ZedJd            ZedKd            ZedLd            ZdMdZ	 	 dNdOdZej        ej        ej        ej        fd ZdPd"Zej        d#ej        ej        fdQd*Z	 	 dRdSd.ZdTd3Z	 dUdVd7Z d8 Z!dWd:Z"d; Z#dXdAZ$e%dYdD            Z&d4S )Zr2   multileaderr(   c                f   |j         }|
J d            |j        j        }|j                            |          }|t          d|           || _        || _        || _        t          t                    | _        |                     |           | j        j        j        | j        j        _        d S )Nr   zinvalid MLEADERSTYLE handle #)r   rt   r   r   ry   
ValueError_doc_mleader_style_multileaderr   rt  _leadersset_mleader_styler[  rw   )r~   r  r   r   rl   s        rC   r   zMultiLeaderBuilder.__init__C  s    o =-!l..v66=EVEEFFF"	,1'@KA
 A
 	u%%%#4 	!222rB   c                    d S r   rA   r  s    rC   _init_contentz MultiLeaderBuilder._init_contentU      rB   c                    d S r   rA   r  s    rC   _reset_cachezMultiLeaderBuilder._reset_cacheY  s    rB   r   r  c                    dS )zReturns the connection box with the connection points on all 4 sides
        in build UCS coordinates. The origin of the build ucs is the insertion
        or attachment point of the content.
        NrA   r  s    rC   _build_connection_boxz(MultiLeaderBuilder._build_connection_box\  s	     	rB   r   r   r:  r   r   c                    d S r   rA   )r~   r   r:  s      rC    _transform_content_to_render_ucsz3MultiLeaderBuilder._transform_content_to_render_ucsd  s	     	rB   conversion_factorc                    d S r   rA   )r~   r  s     rC   _apply_conversion_factorz+MultiLeaderBuilder._apply_conversion_factorj  r  rB   r  r   rp  c                    d S r   rA   r~   r  rp  s      rC   _set_base_pointz"MultiLeaderBuilder._set_base_pointn  r  rB   c                    | j         S )z8Returns the :class:`~ezdxf.entities.MultiLeader` entity.)r  r  s    rC   r  zMultiLeaderBuilder.multileaderr  s       rB   r%   c                    | j         j        S )zCReturns the context entity :class:`~ezdxf.entities.MLeaderContext`.)r  rw   r  s    rC   rw   zMultiLeaderBuilder.contextw  s      ((rB   c                $    | j         j        j        S r   )r  rw   r[  r  s    rC   _landing_gap_sizez$MultiLeaderBuilder._landing_gap_size|  s     (99rB   rl   r&   c                     fd}| _          j        j        }|j        t          t          j                                                  }|D ]@}|                    |          r)|                    |	                    |                     A |             t          j        j        j                  |_         j                            |j                                                     dS )zyReset base properties by :class:`~ezdxf.entities.MLeaderStyle`
        properties. This also resets the content!
        c                 L    j          j        _         j         j        _        d S r   )r]   rw   r[  )r~   	style_dxfs   rC   copy_style_to_contextzCMultiLeaderBuilder.set_mleader_style.<locals>.copy_style_to_context  s#    '0'<DL$,5,FDL)))rB   N)r  r  rt   rt  r)   r0  keysis_supportedsetr   r   rp   rr   rs   ra   rw   	set_scalerd   r  )r~   rl   r  multileader_dxfr  keyr  s   `     @rC   r  z$MultiLeaderBuilder.set_mleader_style  s   
	G 	G 	G 	G 	G 	G $+/I	&.335566 	E 	EC++C00 E##C)>)>s)C)CDDD-1###.
 .
* 	4555rB   r  rN   rR   c                    | j         }|j        j        }|rd|j        _        ||z  |j        _        nd|j        _        ||z  |j        _        dS )a  Set the properties how to connect the leader line to the content.

        The landing gap is the space between the content and the start of the
        leader line. The "dogleg" is the first line segment of the leader
        in the "horizontal" direction of the content.

        rE   r   N)r  rt   rd   rP   rR   rw   r[  )r~   rN   rR   r  rd   s        rC   set_connection_propertiesz,MultiLeaderBuilder.set_connection_properties  sZ     &% 	+)*KO&,9E,AKO)))*KO&/:U/B,,,rB   c                J   | j         }| j        }|t          j        k    r|j        j        |_        nt          |          |_        |t          j        k    r|j        j        |_	        nt          |          |_	        |t          j        k    r|j        j        |_        nt          |          |_        |t          j        k    r|j        j        |_        nt          |          |_        | j        j        }|j        |_        |j	        |_        |j        |_        |j        |_        dS )z1Set the connection type for each connection side.N)rw   r  r6   r  rt   rY   left_attachmentr   re   right_attachmentr7   rh   top_attachmentri   bottom_attachmentr  )r~   r  r  rq  rp  rw   rl   rt   s           rC   set_connection_typesz'MultiLeaderBuilder.set_connection_types  s    ,#'000&+i&IG##&)$iiG#(111',y'KG$$'*5zzG$$---%*Y%GG""%(XXG"'000(-	(MG%%(+FG%#(/(?%)0)A&'.'=$*1*C'''rB   rd   c                P   t          |          }|dk    rt          d|           | j        }| j        }|j        j        }	 ||z  }n# t          $ r |}Y nw xY w||j        _        |j        xj        |z  c_        |                    |           | 	                    |           dS )zSet the overall scaling factor for the whole entity,
        except for the leader line vertices!

        Args:
            scale: scaling factor > 0.0

        r  zinvalid scaling factor: N)
r   r  rw   r  rt   rd   r   rR   r  r  )r~   rd   	new_scalerw   r  	old_scaler  s          rC   set_overall_scalingz&MultiLeaderBuilder.set_overall_scaling  s     %LL	???@@@,&O)		* )I 5  	* 	* 	* )	* !*%%)::%%)$$$%%&788888s   A	 	AAr   r   Union[int, colors.RGB]r  r   r  r   c                .   | j         }t          j        |          |j        _        | j        j                            |          }|t          d| d          |j        j	        |j        _
        ||j        _        t          |          |j        _        dS )a  Set leader line properties.

        Args:
            color: line color as :ref:`ACI` or RGB tuple
            linetype: as name string, e.g. "BYLAYER"
            lineweight: as integer value, see: :ref:`lineweights`
            leader_type: straight lines of spline type

        Nzinvalid linetype name '')r  r   encode_raw_colorrt   rF   r  	linetypesry   r  r   rH   rJ   r   rD   )r~   r   r  r  rD   rm   	linetype_s          rC   set_leader_propertiesz(MultiLeaderBuilder.set_leader_properties  s      #(.(?(F(F%I'++H55	BxBBBCCC-6]-A*(2%"%k"2"2rB    r   sizec                    |dk    r| j         j        j        }|| j        j        _        || j        _        |r0t          j        | j        j        |          | j        j        _	        dS | j        j        `	dS )a  Set leader arrow properties all leader lines have the same arrow
        type.

        The MULTILEADER entity is able to support multiple arrows, but this
        seems to be unsupported by CAD applications and is therefore also not
        supported by the builder classes.

        r  N)
r  rt   rV   r  rw   r   arrow_handler  r  rT   )r~   r   r  s      rC   set_arrow_propertiesz'MultiLeaderBuilder.set_arrow_properties  sz     3;;&*:D04-'+$ 	86<6I	 $7 7D!333 !%777rB   r  r5   r   Iterable[Vec2]c                `    | j         |                             t          |                     dS )a  Add leader as iterable of vertices in render UCS coordinates
        (:ref:`WCS` by default).

        .. note::

            Vertical (top, bottom) and horizontal attachment sides (left, right)
            can not be mixed in a single entity - this is a limitation of the
            MULTILEADER entity.

        Args:
            side: connection side where to attach the leader line
            vertices: leader vertices

        N)r  r6  rt  )r~   r  r   s      rC   rS  z"MultiLeaderBuilder.add_leader_line  s+    " 	d""4>>22222rB   Nr  Optional[UCS]c                N   t          |t                    s
J d            t          j        |          }t	          j        |          }|                                 }|                    d|j        |j	        f           | 
                                 |                     ||           |                                  |                     |                    |j        j                  |                    |j        j                             | j        j                                         | j                                        D ]0\  }}|                     |||                    |          |           1||                     |           | j                                         dS )a  Compute the required geometry data. The construction plane is
        the xy-plane of the given render :class:`~ezdxf.math.UCS`.

        Args:
            insert: insert location for the content in render UCS coordinates
            rotation: content rotation angle around the render UCS z-axis in degrees
            ucs: the render :class:`~ezdxf.math.UCS`, default is the :ref:`WCS`

        z insert has to be a Vec2() objectr   )r  rp  N)
isinstancer   rA  radiansr   z_rotater  set_rowrD  rE  $_set_required_multileader_attributesr  _set_attachment_directionr  	transformr  vec3rp  rw   rQ  r  r  items_build_leaderry   _transform_to_wcsr  update_proxy_graphic)r~   r   r:  r  mconnection_boxr  leader_liness           rC   buildzMultiLeaderBuilder.build2  s    &$''KK)KKK'<))h''3355			!fh)***11333--fh???&&(((^0566;;~49:: 	 	
 	
 	
 	""$$$"&-"5"5"7"7 	P 	PD,|T>3E3Ed3K3KQOOOO?""3'''--/////rB   c                   | j         }|rut          j        |v pt          j        |v }t          j        |v pt          j        |v }|r|rt          d          |rdnd| j        j        _	        |rd| j        j        _
        d S d S d S )Nz7invalid mix of horizontal and vertical connection typesr   rE   F)r  r5   r  r  rq  rp  r=   r  rt   rg   rP   )r~   rQ  
horizontalverticals       rC   r  z,MultiLeaderBuilder._set_attachment_directionT  s    - 	9(-8 $/  '*g5 %0   h )M    &Q !;  938!%000	9 	99 9rB   r   c                D    | j                             |j                   d S r   )r  r  matrix)r~   r  s     rC   r
  z$MultiLeaderBuilder._transform_to_wcsh  s!    ""3:.....rB   c                    | j         j        }| j        }|                    d          }|	||j        vr<|j                            d          }|t          d          |j        j        |_        d|_	        d S )NrH   BYLAYERz*required linetype 'BYLAYER' does not existi)
r  rt   r  ry   r   r  r  r   rH   ro   )r~   rt   r   r   r  s        rC   r  z7MultiLeaderBuilder._set_required_multileader_attributesl  s|    "i122>V3<77}((33H !NOOO)1)<C&&0###rB   r  list[list[Vec2]]ra  r  r   c                   t           |         }t                      }t          | j        j                  |_        t          | j        j        j	                  |_	        d|_
        d|_        ||_        |t          j        k    s|t          j        k    rd|_        nd|_        | j        j        j        r|j        ||j	         z  z   |_        n|j        |_        |                    |j                  |_        |                    |j                  |_        |                     ||           | j        j                            |           d S )NrE   r   )DOGLEG_DIRECTIONSr#   r   rw   rQ  r   r   r  rt   rR   r   has_last_leader_liner   r5   r  r  attachment_directionr  rP   r  rZ  r  transform_direction_append_leader_linesr6  )r~   r  r  ra  r  dogleg_directionr   s          rC   r	  z MultiLeaderBuilder._build_leaderw  s<    -T24</00  %T%6%:%HII#$  	#  0>&&&$.2F*F*F*+F''*+F' * 	='7'< F$8#88(F$$ (8'<F$ $%;;v/G#H#H  44V5IJJ 	!!&,777##F+++++rB   r   r#   c                    t          |          D ]M\  }}t                      }||_        t          j        |          |_        | j                            |           Nd S r   )	enumerater$   r   r   rt  r   rR  r6  )r   r  r   r   rV  s        rC   r  z'MultiLeaderBuilder._append_leader_lines  sc      )66 	& 	&OE8<<DDJ Ih//DML%%%%		& 	&rB   r  r(   r   r  r   r   r:  r   r   r   r  r   r   r   r  r   rp  r   )r   r(   )r   r%   r   r   )rl   r&   r  )rN   r   rR   r   )rd   r   )r   r  r  r   r  r   )r  r  )r   r   r  r   )r  r5   r   r  r   r   )r  N)r   r   r:  r   r  r  r   r   )r  r   r   r   )r  r  r  r5   ra  r   r  r   )r   r#   r  r  r   r   )'r>   r?   r@   r   abcabstractmethodr  r  r  r  r  r  r  r  rw   r  r  r  r6   r  r7   r  r  r   r   r   LINEWEIGHT_BYBLOCKr8   r  r  r  rS  r  r  r
  r  r	  staticmethodr  rA   rB   rC   r2   r2   B  s       
 
 
 
$ 	     	    	   
 	    	    ! ! ! X! ) ) ) X) : : : X:   8 !"C C C C C. "*"+'!*"D "D "D "DH9 9 9 96 )/!2-3 3 3 3 36 8 8 8 8 843 3 3 3( IM 0  0  0  0  0D9 9 9(/ / / /	1 	1 	1*, *, *, *,X & & & \& & &rB   r2   c                  r    e Zd Zd Zddej        dfd(dZd)dZd*dZd+dZ	d,dZ
dej        dfd-d#Zd.d'ZdS )/r3   c                0   |                                   | j        }| j        }| j        }d|j        _        d |_        t                      }||_        |j        j	        |_
        |j        j        |_        |j        j        |_        |j        j        |_        d S )NrG   )r  rw   r  r  rt   rW   r   r'   r   default_text_contentr   rX   r   r\   r   text_attachment_pointr   )r~   rw   rl   rm   r   s        rC   r  z%MultiLeaderMTextBuilder._init_content  s    ,## $%   %	 >$[:k,!+;rB   Nr  r  contentr   r    Optional[Union[int, colors.RGB]]r]   r   r   r9   rl   c                r   | j         }| j        }|t          j        |          |j        _        t          |          |j        _        |                                  |j	        J t          j        |          |j	        _        |r|| j        j        j        z  |_        |r|                     |           dS dS )a\  Set MTEXT content.

        Args:
            content: MTEXT content as string
            color: block color as :ref:`ACI` or RGB tuple
            char_height: initial char height in drawing units
            alignment: :class:`TextAlignment` - left, center, right
            style: name of :class:`~ezdxf.entities.Textstyle` as string

        N)r  rw   r   r  rt   r\   r   r.  r  r   
text_toolsescape_dxf_line_endingsr   r  rd   r]   _set_mtext_style)r~   r/  r   r]   r   rl   rm   rw   s           rC   set_contentz#MultiLeaderMTextBuilder.set_content  s    ( #,%+%<U%C%CGK",/	NN)}((((2(J)
 )
%  	K"-0@0D0J"JG 	)!!%(((((	) 	)rB   r   c                    | j         j                            |          }|F|j        j        | j        j        _        | j        j        J |j        j        | j        j        _	        d S t          d| d          )Nztext style 'z' does not exist)r  r   ry   rt   r   r  rX   rw   r   r   r  )r~   r   rl   s      rC   r4  z(MultiLeaderMTextBuilder._set_mtext_style  sv    	 $$T**6;i6FD!3<%111.3i.>DL+++BDBBBCCCrB   r   r  c           
        dfd}dfd}| j         }|j        t          t                    s
J d            t	          |j                  }t	          |j                  }|j        |j        t          | j
                  }t          j        |j                  r#t          j        |          }|j        |j        nt          j        |          \   |            }|z   dz  z   }	||	z   d	z  }
t'          t)          | ||                    t)          |	 ||                    t)          |
          t)          |
 z
            
          S )zReturns the connection box with the connection points on all 4 sides
        in build UCS coordinates. The origin of the build ucs is the attachment
        point of the MTEXT content.
        r   r   c                 b    J  } j         dk    r
 dz  z
  } nj         dk    r z
  } | S )NrG         ?r   r   )rD  gapr   r   s    rC   
get_left_xzAMultiLeaderMTextBuilder._build_connection_box.<locals>.get_left_x  sR    $$$A!##FSL3&A%%FSLHrB   
connectionr6   c                <   t           z  }| t          j        k    r dz  S | t          j        k    r dz  S | t          j        k    r	 dz  z   S | t          j        t          j        fv r |z
  S | t          j        t          j        t          j	        fv r |z
  S dS )Nr9  r  )
UNDERLINE_DISTANCE_FACTORr6   r  r  r  r  r  r  r  r  )r=  underline_distancer]   r  s     rC   vertical_connection_heightzQMultiLeaderMTextBuilder._build_connection_box.<locals>.vertical_connection_height  s     "-/H!H1DDD#|c))3BBBw}$3IIIws!222$:$D    w!333$7$A$E   
 $|&8883rB   zundefined MTEXT contentg       @r9  r  r  rq  rp  r&  )r=  r6   r   r   )rw   r   r   r'   r6   r  r  r]   r[  r   r  r2  has_inline_formatting_codesr    r   
mtext_sizetotal_widthtotal_heightr  r  r   )r~   r<  rA  rw   r  r  r   r  left_xright_xcenter_xr]   r;  r  r   r   s              @@@@@rC   r  z-MultiLeaderMTextBuilder._build_connection_box  s   	 	 	 	 	 	 	 		 	 	 	 	 	 	. ,%++FF-FFF+.w/FGG/0HII)&
 D-..1&+>> 	E'//D$E&FF%<VDDME65.39,W$+ f88IIJJw : :;K L LMMXs##6'C-00	
 
 
 	
rB   r   r   r:  r   c                    | j         j        }|J t          |_        t	          |          |_        t          j        |          |_        ||_	        d S r   )
rw   r   r   r   r   r   r   rotater   r:  )r~   r   r:  r   s       rC   r  z8MultiLeaderMTextBuilder._transform_content_to_render_ucsC  sK     "    F||%}X66!rB   r  c                P    | j         j        }|J |                    |           d S r   )rw   r   apply_conversion_factor)r~   r  r   s      rC   r  z0MultiLeaderMTextBuilder._apply_conversion_factorN  s3    "   %%&788888rB   targetsegment1segment2Optional[Vec2]connection_type/Union[HorizontalConnection, VerticalConnection]r  r  c                j   |}|||z  }t          |t                    rt          j        }n#|j        dk    rt          j        nt          j        }|                     ||           t          | j	        j
        j                  }	|                                 }
t          |t                    rXd}|j        dk    rt          j        }|
j        j         }nt          j        }|
j        j         }|                     ||           n~t          |t                    rZd}	d}|j        dk    rt          j        }|
j        j         }nt          j        }|
j        j         }|                     ||           nt'          d          |g}||                    ||z              |                     ||           t-          | j        j
        j                  }| j        }||z   }t4          |         }|	r	|||z   z  }nt7                      }||z   t7          ||          z   }|                     ||           dS )	a+  Creates a quick MTEXT leader. The `target` point defines where the
        leader points to.
        The `segment1` is the first segment of the leader line relative to the
        `target` point, `segment2` is an optional second line segment relative
        to the first line segment.
        The `connection_type` defines the type of connection (horizontal or
        vertical) and the MTEXT alignment (left, center or right).
        Horizontal connections are always left or right aligned, vertical
        connections are always center aligned.

        Args:
            content: MTEXT content string
            target: leader target point as :class:`Vec2`
            segment1: first leader line segment as relative distance to `insert`
            segment2: optional second leader line segment as relative distance to
                first line segment
            connection_type: one of :class:`HorizontalConnection` or
                :class:`VerticalConnection`
            ucs: the rendering :class:`~ezdxf.math.UCS`, default is the :ref:`WCS`

        Nr  r:  )r  r  F)rq  rp  zinvalid connection type)r  )r   r7   r9   rm  rD  r  r  r5  r|   r  rt   rP   r  r6   r5   rE  r  rp  rq  r  r6  rS  r   r  rR   r  r  r   r  )r~   r/  rN  rO  rP  rR  r  offsetr   rP   r  move_text_xr  move_text_ypointsrR   r;  rZ  r  last_segmentr   s                        rC   quick_leaderz$MultiLeaderMTextBuilder.quick_leaderS  sq   @ hFo'9:: 	%,II (.x3##M<N  	I666 $*.9::
3355o';<< 	8Kx3%+-355%*-244%%$% &     );<< 	8JKx3%,-466%)-133%%#& &    
 6777 MM&8+,,,T6*** d/3ABB$"VO,T2 	"+}s/BCLL66L,tK/M/MM 	 	

6s
#####rB   r  r   rp  c                d    | j         j        j        dk    r|| j        _        d S || j        _        d S r   )r  rt   rg   rw   
base_pointr  s      rC   r  z'MultiLeaderMTextBuilder._set_base_point  s6     :a??&*DL###&,DL###rB   )
r/  r   r   r0  r]   r   r   r9   rl   r   )r   r   r"  r#  r$  )r/  r   rN  r   rO  r   rP  rQ  rR  rS  r  r  r   r   r%  )r>   r?   r@   r  r9   r  r5  r4  r  r  r  r6   r  rZ  r  rA   rB   rC   r3   r3     s        < < <8  #0#5#) #) #) #) #)JD D D DD
 D
 D
 D
L	" 	" 	" 	"9 9 9 9 $( !3!a$ a$ a$ a$ a$F- - - - - -rB   r3   c                       e Zd Zd$ fdZd Z fdZed%d            Zed&d
            Zd'dZ	d(dZ
d)dZej        dej        fd*dZd+d,dZd-d#Z xZS ).r4   r  r(   c                ~    t                                          |           d | _        t                      | _        d S r   )superr   _block_layoutr   _extents)r~   r  	__class__s     rC   r   z MultiLeaderBlockBuilder.__init__  s2    %%%6:#rB   c                2   |                                   | j        }| j        }d|j        _        d |_        t                      }||_        |j        j        |_        |j        j	        |j
        z  |_
        |j        j        |_        |j        j        |_        d S )NrE   )r  rw   r  rt   rW   r   r"   r   r_   ra   rd   rb   r:  r`   r   )r~   rw   r  r   s       rC   r  z%MultiLeaderBlockBuilder._init_content  s    ,' ()$ $/O$G!!o87=H$7!o1rB   c                |    t                                                       d | _        t                      | _        d S r   )r_  r  r`  r   ra  )r~   rb  s    rC   r  z$MultiLeaderBlockBuilder._reset_cache  s0    !#rB   r   'BlockLayout'c                   | j         | j         S | j        j        }t          |t                    s
J d            |j        }| j        j                            |          }|t          d|           |j
        j        }| j        j                            |          }|#t          d| dt          |           d          || _         |S )zReturns the block layout.Nundefined BLOCK contentzinvalid BLOCK_RECORD handle #zBLOCK 'z' defined by z
 not found)r`  rw   r   r   r"   r_   r  r   ry   r  rt   r   r  r   )r~   r   r   r   r   block_layouts         rC   rh  z$MultiLeaderBlockBuilder.block_layout  s     )%%"%++FF-FFF+*y)--f55EVEEFFF$y'++D11J$JJS->->JJJ   *rB   r   c                    | j         j        sUddlm} | j        }|                    d |D                       }|j        s|                    t          g           || _         | j         S )z&Returns the bounding box of the block.r   )bboxc              3  J   K   | ]}|                                 d k    |V  dS )ATTDEFN)dxftype)r   r  s     rC   	<genexpr>z2MultiLeaderBlockBuilder.extents.<locals>.<genexpr>  s=       # #199;;(+B+B+B+B+B+B# #rB   )ra  has_datar;   rj  rh  extentsextendr   )r~   rj  rh  rp  s       rC   rp  zMultiLeaderBlockBuilder.extents  s     }% 		$"""""",Lll # #'# # #  G # *y)))#DM}rB   r  c           
        | j         j        }t          |t                    s
J d            | j        j        j        }| j        }| j        }|j	        j
        }|j	        j        }|j        j
        dz  |z  }|j        j        dz  |z  }|j        j
        |z  }	|j        j        |z  }
|j        j
        |z  |	z
  }|j        j        |z  |
z
  }|t          j        k    rt#          | | d          |_        d}d}t'          t)          ||z
  |          t)          ||z   |          t)          |||z             t)          |||z
                      S )zReturns the connection box with the connection points on all 4 sides
        in build UCS coordinates. The origin of the build ucs is the insertion
        point of the BLOCK content.
        rg  r9  r   r  rB  )rw   r   r   r"   r  rt   rc   rh  rp  rd   rD  rE  r  r\  rm  r:   r  r   r   r  r   )r~   r   rc   rh  rp  sxsywidth2height2base_xbase_yrI  center_ys                rC   r  z-MultiLeaderBlockBuilder._build_connection_box  sY    "%++FF-FFF+ $ 1 5 K(,[][]#%*,.3&+(*R/(*R/>#b(61>#b(61 N$AAA	H9a88ELHHh'22x&((33Xx'122(W"455	
 
 
 	
rB   r   r   r:  r   c                    | j         j        }t          |t                    s
J d            t          |_        |j                            |          t          |          z   |_        ||_	        d S Nrg  )
rw   r   r   r"   r   r   r   rK  r   r:  )r~   r   r:  r   s       rC   r  z8MultiLeaderBlockBuilder._transform_content_to_render_ucs"  s_    "%++FF-FFF+ |**844tF||C!rB   r  r   c                    | j         j        }t          |t                    s
J d            |                    |           d S r{  )rw   r   r   r"   rM  )r~   r  r   s      rC   r  z0MultiLeaderBlockBuilder._apply_conversion_factor)  sF    "%++FF-FFF+%%&788888rB   rq   r   r   r   r  rd   c                j   | j         }| j        j                            |          }|t	          d| d          |j        |j        _        t          j        |          |j        _	        t          |||          |j        _        t          |          |j        _        |                                  dS )a(  Set BLOCK content.

        Args:
            name: the block name as string
            color: block color as :ref:`ACI` or RGB tuple
            scale: the block scaling, not to be confused with overall scaling
            alignment: the block insertion point or the center of extents

        Nzundefined BLOCK 'r  )r  r  r  ry   r  r_   rt   r   r  r`   r   ra   r   rc   r  )r~   r   r   rd   r   rm   r   s          rC   r5  z#MultiLeaderBlockBuilder.set_content.  s      #	 $$T**=8888999*/*C'"("9%"@"@)-eUE)B)B&,/	NN)rB   rK  r    r   c                4   | j         }| j        j        }t          |                                          D ]b\  }}||j        j        k    rM|                    t          |j        j	        |t          |          t          |                                dS cdS )aQ  Add BLOCK attributes based on an ATTDEF entity in the block
        definition. All properties of the new created ATTRIB entity are
        defined by the template ATTDEF entity including the location.

        Args:
            tag: attribute tag name
            text: attribute content string
            width: width factor

        )r   r   r   r    N)rh  r  rF  r   attdefsrt   rK  r6  r!   r   r   r   )r~   rK  r    r   rh  rF  r   rO  s           rC   set_attributez%MultiLeaderBlockBuilder.set_attributeJ  s     ()7&|';';'='=>> 
	 
	ME6fjn$$$$%z0##Ell YY	      %
	 
	rB   r  r   rp  c                    || j         _        d S r   )rw   r\  r  s      rC   r  z'MultiLeaderBlockBuilder._set_base_pointc  s    "&rB   r!  )r   re  )r   r   r"  )r   r   r:  r   r$  )r   r   r   r  rd   r   )rq   )rK  r   r    r   r   r   r%  )r>   r?   r@   r   r  r  r  rh  rp  r  r  r  r   r   r:   r  r5  r  r  __classcell__)rb  s   @rC   r4   r4     s8       & & & & & &
2 2 2(& & & & &
    X*    X
 
 
 
B" " " "9 9 9 9 )/ /    8    2' ' ' ' ' ' ' 'rB   r4   r  )rm   r(   r   r   )rm   r(   r   r*   r   rk   )r   r   r   r*   r   r0   )r   r   r   r   )r   r   r   r   )r   r.   r   r'   rd   r   r   r   )rm   r(   r   r.   )r   r.   r   r'   r   r   )r   r(   r   r   )r   r#   r   r   r   r   )r   r   r   r*   r   r   )r  r   r   r   )o
__future__r   typingr   r   r   r   r   r	   r
   r'  rA  loggingr  collectionsr   dataclassesr   r;   r   
ezdxf.mathr   r   r   r   r   r   r   r   r   r   r   r   ezdxf.entitiesr   ezdxf.lldxfr   ezdxf.proxygraphicr   ezdxf.render.arrowsr   r   ezdxf.toolsr   r    r2  ezdxf.entities.mleaderr!   r"   r#   r$   r%   r&   r'   r(   r)   ezdxf.documentr*   ezdxf.layoutsr+   r,   r-   r.   r/   r0   __all__	getLoggerr   r   r?  DXFErrorr=   r   rk   r1   r   r   r   COLOR_TYPE_BY_BLOCKCOLOR_TYPE_BY_LAYERCOLOR_TYPE_ACIr   r   r   r   r   r   r   r   r   r   r   IntEnumr8   Enumr5   r  r  rq  rp  r  r6   r7   r9   r:   r  r  ABCr2   r3   r4   rA   rB   rC   <module>r     s   # " " " " "                  


    # # # # # # ! ! ! ! ! !                                  # " " " " "       + + + + + + 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  	&&&&&&))))))                
	7	#	#   ! 	 	 	 	 	%. 	 	 	6 f 	
 6 6 & V  v G    w 7  '!" 7#$ "!$")$!( '#*=  D#: #: #: #: #: #: #: #:N ).6 6 6 6 6
D 
D 
D 
D	 	 	 	! ! ! ! 

	! 	! 	! 	!0 0 0 04   $   *	 	 	 	               <B 3 3 3 3 3( ( ( (I
 I
 I
 I
 I
 I
 I
 I
X           TY     6'6	 ) ) ) ) )4< ) ) )           DL       T\           (   i& i& i& i& i& i& i& i&jC- C- C- C- C-0 C- C- C-Lh' h' h' h' h'0 h' h' h' h' h'rB   