
    Og                       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j                  d      ZCdZDdZE G d de$j                        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	 dl	 	 	 dmdHZJdndIZKdodJZLdpdKZMej                  ej                  ej                  hZQdqdLZRdrdMZSdsdNZTdtdOZU	 	 	 	 	 	 	 	 drdPZVdudQZWdudRZXefdvdSZYdwdTZZ G dU dV      Z[ G dW dXej                        Z] G dY dZej                        Z_e_j                  ee_j                  e e_j                  e e_j                  eiZd G d[ d\ej                        Ze G d] d^ej                        Zf G d_ d`ej                        Zg G da dbej                        Zhe G dc dd             ZidxdeZj G df dge
j                        Zl G dh diel      Zm G dj dkel      Zny)y    )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y)ConnectionTypeErrorN)__name__
__module____qualname__     Y/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/render/mleader.pyr=   r=   [   s    rB   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y)MLeaderStyleOverridec                   |j                   | _        |j                   | _        |j                  | _        |j                   j                  dd      | _        t        |j                   j                  dd      |j                   j                  dd      |j                   j                  dd      f      | _        t        | j                  dz        | _
        y )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)selfstylemleaders      rC   __init__zMLeaderStyleOverride.__init__   s    ))#KK(/%q)
% $(		os3		os3		os3$
  *.))W5*
&rB   c                    |dk(  r| j                   }n| j                  j                  |      }t        s| j	                  |      r9|dk(  r| j
                  j                  }|S | j                  j                  ||      }|S )Nra   r]   )	ry   rs   get_defaultIGNORE_OVERRIDE_FLAGSis_overriddenrv   r]   rt   rw   )r|   attrib_namevalues      rC   rw   zMLeaderStyleOverride.get   sw    ..,,EOO//<E D$6$6{$Cm+11  ))--k5ArB   c                ^    t         j                  |d      }t        || j                  z        S Nr   )OVERRIDE_FLAGrw   rz   rx   )r|   r   flags      rC   r   z"MLeaderStyleOverride.is_overridden   s*      a0D488899rB   N)r}   r&   r~   r(   )r   strreturnr   )r   r   r   rz   )r>   r?   r@   r   rw   r   rA   rB   rC   rk   rk      s    
$:rB   rk   c                    | j                   }|J d       |r0| j                  $t        | j                  |      j                         S t	        t        | |      j                               S )Nvalid DXF document required)docproxy_graphicr   r1   iterRenderEnginerun)r~   r   r   s      rC   r1   r1      sb     ++C?999?..:G1137HHJJL#.22455rB   c                   | j                   j                  }|j                  j                  |      }|4t        j                  d| d       |j                  j                  d      }|J d       t        t        t        |      |       S )Nzreferenced MLEADERSTYLE(#() does not exist, replaced by 'Standard'Standardz0mandatory MLEADERSTYLE 'Standard' does not exist)
rr   style_handleentitydbrw   loggerwarningmleader_stylesrk   r
   r&   )r~   r   handler}   s       rC   	get_styler      s    [[%%FLLV$E}'x 0% &	
 ""&&z2PPP\5 97CCrB   c                    |j                   j                  |       }|4t        j                  d|  d       |j                  j                  d      }|J d       |S )Nzreferenced STYLE(#r   r   z)mandatory STYLE 'Standard' does not exist)r   rw   r   r   styles)r   r   
text_styles      rC   get_text_styler      se    !!&)J  )% &	
 ZZ^^J/
!N#NN!rB   c                `    t        |       dk  rt        S | d   | d   z
  }|j                         S )NrG   rE   r   )lenr   	normalize)vertices	directions     rC   get_arrow_directionr      s4    
8}qhqk)I  rB   c                    t         j                  }d }t        j                  |       \  }}|t        v r|}||fS |t         j                  k(  r|}||fS N)r   BYBLOCKdecode_raw_color_intACI_COLOR_TYPESCOLOR_TYPE_RGB)	raw_color	aci_color
true_color
color_typecolors        rC   decode_raw_colorr      s_    I $J33I>J_$	 j   
v,,	,
j  rB   c                   |j                   | _        | j                  }t        |j                        \  }}||_        |||_        |j                  |_        | j                  J t        |j                  | j                        j                  j                  | j                  _        |j                  j                  t              s|j                  |_        |j                  |_        |j                   |z  |_        |j"                  |_        |j$                  |_        |j&                  |_        |j(                  |_        y r   )default_contentr    rr   r   r   r   insertr   r   r   namer}   	extrusioniscloser   text_directionwidthline_spacing_factorline_spacing_styleflow_direction	alignmentattachment_point)mtext
mtext_datard   rr   r   r   s         rC   copy_mtext_datar      s    ++EJ
))C,Z-=-=>IzCI#""CJ99   $	c$$ 
IIO ''/",,#22C  5(CI(<<C'::C#22C%//CrB   c                   t        dt        j                  d| j                              }| j                  j
                  |j                  _        | j                  }|j                  }|t        d      |j                  }|j                  |j                  _
        |2t        |||       |j                  rt        ||       t        |||       |S )Nr.   MTEXT)r   z MULTILEADER has no MTEXT content)r
   r   newr   rr   layerru   r   	TypeErrorrd   r]   r   has_bg_fillset_mtext_bg_fillset_mtext_columns)r~   r   ru   r   rd   s        rC   
make_mtextr      s    '++g7;;?@Ekk''EIIOooGJ:<<MME#//EIIz51!!eZ0%U3LrB   c                   |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                  _        y y )NrE      )bg_scale_factorrr   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      *99EIIEII$nnEII%/%?%?EII"33J4G4GHJ_$"'			v,,	,',		$ 	&&444 		 5rB   c                     y r   rA   )r   r   rd   s      rC   r   r   &  s    
 	rB   c                    | j                   }|j                  |j                  j                  S |j                  |j                  j                  S |j                  S r   )ru   r   r   blockplane_originentityru   s     rC   _get_insertr   .  sK    nnG}} }}###		"}}###rB   c                    | j                   }|j                  |j                  j                  S |j                  |j                  j                  S |j                  S r   )ru   r   r   r   plane_z_axisr   s     rC   _get_extrusionr   7  sK    nnG}} }}&&&		"}}&&&rB   c                    	 | j                   r%| j                  j                  | j                        S 	 |j                  | j                        S # t        $ r Y &w xY wr   )has_dogleg_vectordogleg_vectorr   rR   ZeroDivisionError)leaderdefaults     rC   _get_dogleg_vectorr   @  s_    ##''11&2F2FGG $ V1122  s   0A 	AAc                    |j                   j                  |       }|t        j                  d|  d       y |j                  j                  d      S )Nzrequired BLOCK_RECORD entity # does not existr   )r   rw   r   errorrr   )r   r   block_records      rC   _get_block_namer   J  sL    <<##F+L5fX_MN''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	ddZ
ddZdd d
Zd!dZd!dZd!dZd!dZd"dZd!dZd#dZd#dZ	 d$	 	 	 	 	 d%dZd&dZd'dZ	 	 d(	 	 	 	 	 d)dZdd*dZ	 	 	 	 	 	 	 	 	 	 d+dZy	),r   c                h   g | _         || _        || _        t        ||      | _        |j
                  | _        t        |      | _        t        |      | _	        d | _
        | j                  j                  t              st        | j                        | _
        | j                  j                  | _        | j
                  j                   | _        |j"                  j$                  | _        | j'                         | _        | j                  j+                  d      | _        t/        | j                  j+                  d            \  }}|| _        || _        | j                  j+                  d      | _        d| _        t9        | j                  j+                  d            | _        |j<                  D ci c]  }|j>                  |j@                   c}| _        | j                  j+                  d      | _!        d | _"        d | _#        t9        | j                  j+                  d            | _$        | j                  j+                  d      | _%        | j                  j+                  d	      | _&        | j                  j+                  d
      | _'        | j                  j+                  d      | _(        y c c}w )NrJ   rF   rD   FrP   rT   rg   rY   re   rh   ri   ))entitiesr~   r   r   r}   ru   r   r   r   r   ocsr   r   r   z	elevationrd   rr   r   linetype_namelinetyperw   
lineweightr   leader_aci_colorleader_true_colorrD   r^   rz   rP   arrow_headsindexr   rT   dxf_mtext_entity_dxf_mtext_extentshas_horizontal_attachmentleft_attachment_typeright_attachment_typetop_attachment_typebottom_attachment_type)r|   r~   r   r   r   heads         rC   r   zRenderEngine.__init__S  s   *,+4Wc+B
!'*-g6"&~~%%f-4>>*DH $ !LL..
[[&&
**,**..)<= 0JJNN./!
	: &/0: $

} =# $TZZ^^L%A B070C0C,
(,DJJ#,
 "&0C!D37AE)-JJNN67*
& %)JJNN3N$O!%)ZZ^^(&
" $(::>>2L#M &*jjnn)'
#,
s   1J/c                    | j                   d uS r   )r   r|   s    rC   has_extrusionzRenderEngine.has_extrusion  s    xxt##rB   c                2    | j                   j                  d uS r   )ru   r   r  s    rC   has_text_contentzRenderEngine.has_text_content      ||!!--rB   c                2    | j                   j                  d uS r   )ru   r   r  s    rC   has_block_contentzRenderEngine.has_block_content  r  rB   c                    | j                   | j                   S | j                  #t        j                  | j                        \  }}nd\  }}||f| _         | j                   S )z Calculate MTEXT width on demand.        r  )r   r   r   estimate_mtext_extents)r|   r   heights      rC   mtext_extentszRenderEngine.mtext_extents  sj     "".***  , &<<%%ME6 %ME6#(&/&&&rB   c                    | j                   j                          t        | j                        dkD  r | j	                          | j                          | j                   S )z'Entry point to render MLEADER entities.&.>)r   clearabsrd   add_contentadd_leadersr  s    rC   r   zRenderEngine.run  sD    tzz?T!}}rB   c                    | j                   j                  d      }| j                  j                  j                  |      }||j                  j
                  S t        j                  d| d| j                          y)NrH   zinvalid linetype handle # in 
Continuous)	r}   rw   r   r   rr   r   r   r   r~   )r|   r   ltypes      rC   r   zRenderEngine.linetype_name  sd     89!!%%f-99>>!26($t||nMNrB   c                .   d}| j                   j                  || j                        }||dk(  r|S | j                  j                  j                  |      }|(t
        j                  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   rw   rT   r   r   r   r   r~   rr   r   )r|   r   closed_filledr   r   s        rC   arrow_block_namezRenderEngine.arrow_block_name  s    (!!%%eT-C-CD>Vs]  xx((,,V4NNxtDLL> :2 3 ! $$$rB   Nc                    | 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  sq    ))	++
 &*C*CC$4Y$?!Iz ZZ//	
 !$.GL!rB   c                x    | j                   r| j                          y | j                  r| j                          y y r   )r  add_mtext_contentr
  add_block_contentr  s    rC   r  zRenderEngine.add_content  s1      ""$##""$ $rB   c                    t        | j                        }| j                  j                  |       || _        | j
                  r| j                          y y r   )r   r~   r   appendr   r^   add_text_frame)r|   r   s     rC   r%  zRenderEngine.add_mtext_content  sD    4<<(U# %! rB   c                     y r   rA   r  s    rC   r)  zRenderEngine.add_text_frame  s     	rB   c           	        | j                   j                  }|J t        |j                  | j                        }|y |j
                  }t        j                  |j                        }| j                  | j                  j                  |      }t        |j                        \  }}|j                  }|||||j                  |j                  |j                   |j"                  d}|||d<   t%        dt'        j(                  d|| j                              }	| j*                  j-                  |	       | j.                  j0                  r| j3                  |	       y y )N)r   r   rotationr   r   xscaleyscalezscaler   r-   INSERT
dxfattribsr   )ru   r   r   r_   r   r   mathdegreesr,  r   from_wcsr   r   rd   r   xyr   r
   r   r   r   r(  r~   block_attribsadd_block_attributes)
r|   r   
block_namelocationr,  r   r   rd   r"  r   s
             rC   r&  zRenderEngine.add_block_content  s(   ""   $U%>%>I
<<<</88xx((2H 0 =	:  gggggg	
 !$.GL!gkk(wDHHM
 	V$<<%%%%f- &rB   c                n   | j                   j                  }t               }| j                  j                  D ]h  }|j                  |j                        }|$t        j                  d|j                   d       D|j                  j                  }|j                  ||<   j |r|j                  |       y y )Nzrequired ATTDEF entity #r   )r   r   dictr~   r8  rw   r   r   r   rr   tagr    add_auto_attribs)r|   r   r   valuesattribattdefr>  s          rC   r9  z!RenderEngine.add_block_attributes  s    88$$!%ll00 	&F\\&--0F~.v}}o_M **..C ++F3K	& ##F+ rB   c                   | j                   dk(  ry | j                  j                  D ]a  }|j                  D ]  }| j	                  ||        | j
                  s3|j                  r| j                  |       Q| j                  |       c y r   )	rD   ru   leaderslinesadd_leader_liner  r   add_text_underlineadd_overline)r|   r   lines      rC   r  zRenderEngine.add_leaders  s    q ll** 	.F 3$$VT23 $$33 ++F3 %%f-	.rB   c                   | j                   j                  }|y | j                  dv }| j                  dv }|s|sy |j                  t        |      z   }| j                  \  }}|| j                   j                  z   }|dk  ry |j                  }	| j                  =|	j                  }
|j                  j                  j                         }|j                  }na| j                  j                  }t         ||	            }
t         ||j                              j                         }t         ||            }t        ||
|
|z         }| }|j                  j!                  |r|n|       }|r|s|r|r| j#                  |||z          y y y )N)      rK   r  )ru   r   r   r   last_leader_pointr   r  landing_gap_sizer   r   vec2r   
orthogonalr5  r   r   r   add_dxf_line)r|   r   r   has_left_underlinehas_right_underlineconnection_pointr   r  lengthstartstart2dup2dcp2dr5  is_leftis_rightrI  s                    rC   rG  zRenderEngine.add_text_underline'  su   ""=!66)C"88IE"&9!336H6PP**v666D= 88jjG'',,779D#((Dxx((H8E?+G!5!567BBDD!123D'gw~F;##--ffWM*,.0@40GH -HrB   c                   | j                   j                  }|y | j                  dk(  }| j                  dk(  }|s|sy | j                  \  }}|dk  ry |j
                  }|j                  }|j                  j                  |dz        }	||	z
  }
||	z   }| j                  t        ||
|      }n5| j                  j                  }t         ||       ||
       ||            }| }|r|s|r|r| j                  |
|       y y y )N
   r  rG   )ru   r   r  r   r  rM  r   r   r   r   r   r5  rQ  )r|   r   r   has_bottom_linehas_top_linerU  r  centerr   line2rV  endbottomr5  tops                  rC   rH  zRenderEngine.add_overlineI  s   ""=55;//25<++D=
 ))$$..vz:un88*65#>Fxx((H* (5/8C=F jCLeS) 5ACrB   c                    t        |      }|j                  }|j                  r2|r|j                  |       |j                  |t	        |      z          |S |j                  |       |S r   )listrM  r   r(  r   )r|   r   line_verticesrP   r   	end_points         rC   leader_verticeszRenderEngine.leader_verticesi  sb     &,,	++	*OOI(:6(BBC  OOI&rB   c                   | j                   }|dk(  ry | j                  }|dk(  rd}| j                  ||j                  |      }t	        |      dk  ry t        |      }|j                  }|j                  }| j                  | j                  |            }	| j                  j                  }
| j                  |	|d   ||
|       |t        |	|
      z  }|dxx   |z  cc<   |dk(  r+t        ||dd        D ]  \  }}| j                  |||        y |dk(  r:|j                   rt#        |      }n|d   |d   z
  }| j%                  |||g|       y y )	Nr   rG   F)r   r;  r   rd   r   rE   )tangentsr   )rD   rP   ri  r   r   r   r   r   create_arrow_blockr  ru   rV   	add_arrowr   ziprQ  r   r   add_dxf_spline)r|   r   rI  rD   rP   r   arrow_directionr   r   r:  
arrow_sizearrow_offsetseend_tangents                  rC   rF  zRenderEngine.add_leader_linew  sy   ++!??
!J#33DMM: 
 x=1 3H =	ZZ11$2G2G2NO
 LL88
a[% 	 	
 -|
0
 
 	|#!Hhqrl3 31!!!Q	23A//08&rlXb\9);7	    rB   c                    || j                   j                  vrWt        j                  |      }|t        vrt        j                  }t        j
                  | j                   j                  |      }|S r   )r   blocksr   
arrow_namer  create_block)r|   r   rz  s      rC   rn  zRenderEngine.create_arrow_block  sT    txx&**40J'#11
&&txx
CDrB   c                    | j                  |      }t        dt        j                  d|| j                              }|j                  t        ||             | j                  j                  |       y )Nr/   SPLINEr1  )rm  )	r#  r
   r   r   r   apply_construction_toolr   r   r(  )r|   
fit_pointsrm  r   r"  splines         rC   rq  zRenderEngine.add_dxf_spline  sc     **51KKW$((C
 	&& h?	
 	V$rB   c                    | j                  |      }||d<   ||d<   | j                  j                  t        j                  d|| j
                               y )NrV  rb  LINEr1  )r#  r   r(  r   r   r   )r|   rV  rb  r   r"  s        rC   rQ  zRenderEngine.add_dxf_line  sK    **51 KK7A	
rB   c                   | j                  |      }||d<   | j                  E| j                  j                  |      }| j                  j                  |      }| j                  |d<   ||d<   |j                  dz   |d<   ||d<   ||d<   ||d<   | j
                  j                  t        j                  d	|| j                  
             y )Nr   r   r   g     f@r,  r-  r.  r/  r0  r1  )
r#  r   r5  r   	angle_degr   r(  r   r   r   )r|   r   r;  r   rd   r   r"  s          rC   ro  zRenderEngine.add_arrow  s     **5188xx((2H)))4I#'>>GK $'11E9
!!!KKW$((C	
rB   )r~   r(   r   r*   )r   rz   )r   ztuple[float, float])r   zlist[DXFGraphic])r   r   )r   intr   r   r   )r   Optional[int]r   r=  )r   None)r   r-   )r   r#   F)r   r#   rg  
list[Vec3]r   r  )r   r#   rI  r$   )r   r   r   r   )NN)r  r  rm  zOptional[Iterable[UVec]]r   r  )rV  r   rb  r   r   r  )
r   r   r;  r   r   r   rd   floatr   r  )r>   r?   r@   r   propertyr  r  r
  r  r   r   r  r#  r  r%  r)  r&  r9  r  rG  rH  ri  rF  rn  rq  rQ  ro  rA   rB   rC   r   r   R  s*   +
Z $ $ . . . . ' '"%$%".@,.& ID*B IN 1;	+Z .2#	%% +% 	% 


 
 	

 
 
rB   r   c                      e Zd ZdZdZdZdZy)r8   zThe leader type.r   rE   rG   N)r>   r?   r@   __doc__nonestraight_linessplinesrA   rB   rC   r8   r8     s    DNGrB   r8   c                      e Zd ZdZ ej
                         Z ej
                         Z ej
                         Z ej
                         Z	y)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rightrd  rc  rA   rB   rC   r5   r5     s=     499;DDIIKE
$))+CTYY[FrB   r5   c                  8    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y)r6   z&The horizontal leader connection type.rk  r   rE   rG   r   rI   rK  rL     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     s>    0HON&'##$ '($rB   r6   c                      e Zd ZdZdZdZdZy)r7   z$The vertical leader connection type.r   	   r]  N)r>   r?   r@   r  r  r`  center_overlinerA   rB   rC   r7   r7     s    .HFOrB   r7   c                      e Zd ZdZdZdZdZy)r9   z"The :class:`MText` alignment type.rE   rG   r   N)r>   r?   r@   r  r  r`  r  rA   rB   rC   r9   r9     s    ,DFErB   r9   c                      e Zd ZdZdZdZy)r:   z"The :class:`Block` alignment type.r   rE   N)r>   r?   r@   r  center_extentsinsertion_pointrA   rB   rC   r:   r:     s    ,NOrB   r:   c                  B    e Zd ZU dZded<   ded<   ded<   ded<   d	dZy)
ConnectionBoxzdContains the connection points for all 4 sides of the content, the
    landing gap is included.
    r   r  r  rd  rc  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  rd  rc  )r|   sides     rC   rw   zConnectionBox.get/  sS    >&&&99^)))::^'''88O{{rB   N)r  r5   r   r   )r>   r?   r@   r  __annotations__rw   rA   rB   rC   r  r  $  s"     JK	ILrB   r  c                    t        j                  | j                        sEt        | j                        }t	        |j                  | j                              }|j                  S y)z)Returns the ocs rotation angle of the UCSr  )r   r   uzr   r   r5  uxangle)ucsr   x_axis_in_ocss      rC   ocs_rotationr  9  sE    >>#&&!#&&kS\\#&&12"""rB   c                     e Zd ZddZej
                  d        Zd Zej
                  dd       Zej
                  	 	 	 	 	 	 dd       Z	ej
                  dd       Z
ej
                  dd       Zedd       Zed d	       Zed!d
       Zd"dZ	 	 d#	 	 	 d$dZej&                  ej&                  ej&                  ej&                  fdZd%dZej0                  dej4                  ej8                  f	 	 	 	 	 d&dZ	 	 d'	 	 	 d(dZ	 	 	 	 	 	 d)dZ	 d*	 	 	 	 	 	 	 d+dZ d Z!d,dZ"d Z#	 	 	 	 	 	 	 	 d-dZ$e%	 	 	 	 	 	 d.d       Z&y)/r2   c                   |j                   }|J d       |j                  j                  }|j                  j	                  |      }|t        d|       || _        || _        || _        t        t              | _        | j                  |       | j                  j                  j                  | j                  j                  _        y )Nr   zinvalid MLEADERSTYLE handle #)r   rr   r   r   rw   
ValueError_doc_mleader_style_multileaderr   rf  _leadersset_mleader_stylerN  ru   )r|   multileaderr   r   r}   s        rC   r   zMultiLeaderBuilder.__init__C  s    oo= ==--!ll..v6=<VHEFF"	,1'@KA
 	u%##44 	!!2rB   c                     y r   rA   r  s    rC   _init_contentz MultiLeaderBuilder._init_contentU      rB   c                     y r   rA   r  s    rC   _reset_cachezMultiLeaderBuilder._reset_cacheY  s    rB   c                     y)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   c                     y r   rA   )r|   r   r,  s      rC    _transform_content_to_render_ucsz3MultiLeaderBuilder._transform_content_to_render_ucsd  s     	rB   c                     y r   rA   )r|   conversion_factors     rC   _apply_conversion_factorz+MultiLeaderBuilder._apply_conversion_factorj  r  rB   c                     y r   rA   r|   r  rc  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   c                .    | j                   j                  S )zCReturns the context entity :class:`~ezdxf.entities.MLeaderContext`.)r  ru   r  s    rC   ru   zMultiLeaderBuilder.contextw  s       (((rB   c                B    | j                   j                  j                  S r   )r  ru   rN  r  s    rC   _landing_gap_sizez$MultiLeaderBuilder._landing_gap_size|  s      ((999rB   c                      fd}| _          j                  j                  }|j                  t        t        j
                  j                               }|D ]5  }|j                  |      s|j                  |j                  |             7  |        t        j                  j                  j                        |_         j                  j!                  |j"                          j%                          y)zyReset base properties by :class:`~ezdxf.entities.MLeaderStyle`
        properties. This also resets the content!
        c                 r    j                    j                  _         j                   j                  _        y r   )r]   ru   rN  )r|   	style_dxfs   rC   copy_style_to_contextzCMultiLeaderBuilder.set_mleader_style.<locals>.copy_style_to_context  s'    '0'<'<DLL$,5,F,FDLL)rB   N)r  r  rr   rf  r)   r"  keysis_supportedsetr   r   rn   rp   rq   ra   ru   	set_scalerd   r  )r|   r}   r  multileader_dxfr  keyr  s   `     @rC   r  z$MultiLeaderBuilder.set_mleader_style  s    
	G $++//II	&..3356 	EC++C0##C)>)>s)CD	E 	-1######.
* 	445rB   c                    | j                   }|j                  j                  }|r&d|j                  _        ||z  |j                  _        nd|j                  _        |j
                  j                  |z  |z   y)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  rr   rd   rP   rR   ru   rN  )r|   rN   rR   r  rd   s        rC   set_connection_propertiesz,MultiLeaderBuilder.set_connection_properties  sc     &&%%)*KOO&,9E,AKOO))*KOO&,,{:UBrB   c                   | 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                  |_        y)z1Set the connection type for each connection side.N)ru   r  r6   r  rr   rY   left_attachmentr  re   right_attachmentr7   rh   top_attachmentri   bottom_attachmentr  )r|   r  r  rd  rc  ru   r}   rr   s           rC   set_connection_typesz'MultiLeaderBuilder.set_connection_types  s    ,,##'000&+ii&I&IG#&)$iG#(111',yy'K'KG$'*5zG$$---%*YY%G%GG"%(XG"'000(-		(M(MG%(+FG%##(/(?(?%)0)A)A&'.'='=$*1*C*C'rB   c                n   t        |      }|dk  rt        d|       | j                  }| j                  }|j                  j
                  }	 ||z  }||j                  _        |j                  xj                  |z  c_        |j                  |       | j                  |       y# t        $ r |}Y `w xY w)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  ru   r  rr   rd   r   rR   r  r  )r|   rd   	new_scaleru   r  	old_scaler  s          rC   set_overall_scalingz&MultiLeaderBuilder.set_overall_scaling  s     %L	7w?@@,,&&OO))		* )I 5 !*%%)::%)$%%&78 ! 	* )	*s   B& &B43B4r   c                p   | j                   }t        j                  |      |j                  _        | j
                  j                  j                  |      }|t        d| d      |j                  j                  |j                  _
        ||j                  _        t        |      |j                  _        y)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_colorrr   rF   r  	linetypesrw   r  r   rH   rJ   r  rD   )r|   r   r   r   rD   r~   	linetype_s          rC   set_leader_propertiesz(MultiLeaderBuilder.set_leader_properties  s      ##(.(?(?(F%II''++H5	6xjBCC-6]]-A-A*(2%"%k"2rB   c                ^   |dk(  r | j                   j                  j                  }|| j                  j                  _        || j                  _        |rDt        j                  | j                  j                  |      | j                  j                  _	        y| j                  j                  `	y)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  rr   rV   r  ru   r   arrow_handler  ry  rT   )r|   r   sizes      rC   set_arrow_propertiesz'MultiLeaderBuilder.set_arrow_properties  s     3;&&**::D04-'+$6<6I6I		  $7D!!3 !!%%7rB   c                R    | j                   |   j                  t        |             y)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  r(  rf  )r|   r  r   s      rC   rF  z"MultiLeaderBuilder.add_leader_line  s    " 	d""4>2rB   Nc                8   t        |t              sJ d       t        j                  |      }t	        j
                  |      }| j                         }|j                  d|j                  |j                  f       | j                          | j                  ||       | j                          | j                  |j                  |j                  j                         |j                  |j"                  j                                | j$                  j&                  j)                          | j*                  j-                         D ](  \  }}| j/                  |||j1                  |      |       * || j3                  |       | j4                  j7                          y)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  rc  N)
isinstancer   r3  radiansr   z_rotater  set_rowr6  r7  $_set_required_multileader_attributesr  _set_attachment_directionr  	transformr  vec3rc  ru   rD  r  r  items_build_leaderrw   _transform_to_wcsr  update_proxy_graphic)r|   r   r,  r  mconnection_boxr  leader_liness           rC   buildzMultiLeaderBuilder.build2  sK    &$'K)KK'<<)h'335			!fhh)*113--fh?&&(^00556;;~4499: 	 	
 	""$"&--"5"5"7 	PD,|T>3E3Ed3KQO	P?""3'--/rB   c                R   | j                   }|rt        j                  |v xs t        j                  |v }t        j                  |v xs t        j
                  |v }|r|rt        d      |rdnd| j                  j                  _	        |rd| j                  j                  _
        y y y )Nz7invalid mix of horizontal and vertical connection typesr   rE   F)r  r5   r  r  rd  rc  r=   r  rr   rg   rP   )r|   rD  
horizontalverticals       rC   r  z,MultiLeaderBuilder._set_attachment_directionT  s    --(--8 $$/  '**g5 %%0  h)M   Q !!; 38!!%%0  rB   c                N    | j                   j                  |j                         y r   )r  r  matrix)r|   r  s     rC   r  z$MultiLeaderBuilder._transform_to_wcsh  s    ""3::.rB   c                   | j                   j                  }| j                  }|j                  d      }|||j                  vrC|j
                  j                  d      }|t        d      |j                  j                  |_        d|_	        y )NrH   BYLAYERz*required linetype 'BYLAYER' does not existi)
r  rr   r  rw   r   r  r  r   rH   rm   )r|   rr   r   r   r   s        rC   r  z7MultiLeaderBuilder._set_required_multileader_attributesl  s{    ""ii12>V3<<7}}((3H #MOO)1)<)<C&&0#rB   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                        |_        | j/                  ||       | j                  j                  j1                  |       y )NrE   r   )DOGLEG_DIRECTIONSr#   r   ru   rD  r   r  r  rr   rR   r   has_last_leader_liner   r5   r  r  attachment_directionr  rP   r  rM  r  transform_direction_append_leader_linesr(  )r|   r  r  rT  r  dogleg_directionr   s          rC   r  z MultiLeaderBuilder._build_leaderw  s<    -T24<<//0  %T%6%6%:%:%H%HI#$  	#  0>&&&$.2F2F*F*+F'*+F' **'7'<'< F$8$8#88(F$ (8'<'<F$ $%;;v/G/G#H  44V5I5IJ 	!!&,7##F+rB   c                    t        |      D ]K  \  }}t               }||_        t        j                  |      |_        | j                  j                  |       M y r   )	enumerater$   r   r   rf  r   rE  r(  )r   r  r   r   rI  s        rC   r  z'MultiLeaderBuilder._append_leader_lines  sL      )6 	&OE8<DDJ IIh/DMLL%		&rB   r  r(   r   r  r   r   r,  r  r   r  r  r  r   r  r  r   rc  r   )r   r(   )r   r%   r   r  )r}   r&   r  )rN   r  rR   r  )rd   r  )r   Union[int, colors.RGB]r   r   r   r  ) r  )r   r   r  r  )r  r5   r   zIterable[Vec2]r   r  )r  N)r   r   r,  r  r  Optional[UCS]r   r  )r  r   r   r  )r  list[list[Vec2]]r  r5   rT  r   r  r   )r   r#   r  r  r   r  )'r>   r?   r@   r   abcabstractmethodr  r  r  r  r  r  r  r  ru   r  r  r  r6   r  r7   r  r  r   r   r   LINEWEIGHT_BYBLOCKr8   r  r  r  rF  r  r  r  r  r  staticmethodr  rA   rB   rC   r2   r2   B  sJ   
$ 	  	  	&+	 
 	  	  ! ! ) ) : :8 !"CC C. "**"++''!**"DH96 )/!22--3%3 3 	36 88 843"3.<3	3( IM 0 0&+ 08E 0	 0D9(/	1*,&*, *, 	*,
 *,X &&*:&	& &rB   r2   c                      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y)r3   c                   | j                          | j                  }| j                  }| j                  }d|j                  _        d |_        t               }||_        |j                  j                  |_
        |j                  j                  |_        |j                  j                  |_        |j                  j                  |_        y )NrG   )r  ru   r  r  rr   rW   r   r'   r   default_text_contentr   rX   r   r\   r   text_attachment_pointr   )r|   ru   r}   r~   r   s        rC   r  z%MultiLeaderMTextBuilder._init_content  s    ,,#### $%   %		 > >$[[::kk,,!++;;rB   Nr  r  c                   | j                   }| j                  }|$t        j                  |      |j                  _        t        |      |j                  _        | j                          |j                  J t        j                  |      |j                  _        |r(|| j                  j                  j                  z  |_        |r| j!                  |       yy)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  ru   r   r  rr   r\   r  r$  r  r   
text_toolsescape_dxf_line_endingsr   r  rd   r]   _set_mtext_style)r|   contentr   r]   r   r}   r~   ru   s           rC   set_contentz#MultiLeaderMTextBuilder.set_content  s    ( ##,,%+%<%<U%CGKK",/	N)}}((((2(J(J)
% "-0@0@0D0D0J0J"JG!!%( rB   c                \   | j                   j                  j                  |      }|w|j                  j                  | j
                  j                  _        | j                  j                  J |j                  j                  | j                  j                  _	        y t        d| d      )Nztext style 'z' does not exist)r  r   rw   rr   r   r  rX   ru   r   r   r  )r|   r   r}   s      rC   r(  z(MultiLeaderMTextBuilder._set_mtext_style  s    		  $$T*6;ii6F6FD!!3<<%%111.3ii.>.>DLL+|D61ABCCrB   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.
        c                 t    J  } j                   dk(  r dz  z
  } | S j                   dk(  r z
  } | S )NrG         ?r   r   )r6  gapr   r   s    rC   
get_left_xzAMultiLeaderMTextBuilder._build_connection_box.<locals>.get_left_x  sW    $$$A!#FSL3& H A%FSLHrB   c                r   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 y)Nr.  r  )
UNDERLINE_DISTANCE_FACTORr6   r  r  r  r  r  r  r  r  )
connection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D   w!333$77$AA$EE  
 $|&888rB   zundefined MTEXT contentg       @r.  r  r  rd  rc  r  )r4  r6   r   r  )ru   r   r  r'   r6   r  r  r]   rN  r   r  r&  has_inline_formatting_codesr    r   
mtext_sizetotal_widthtotal_heightr  r  r   )r|   r1  r6  ru   r  r  r   r  left_xright_xcenter_xr]   r0  r  r   r   s              @@@@@rC   r  z-MultiLeaderMTextBuilder._build_connection_box  sN   		,		. ,,%+F-FF+.w/F/FG/0H0HI))&&
 D--.11&++>''/D$$E&&F%<<VDME65.39,W$+ f8IJw :;K LMXs#6'C-0	
 	
rB   c                    | j                   j                  }|J t        |_        t	        |      |_        t        j                  |      |_        ||_	        y r   )
ru   r   r   r   r   r   r   rotater   r,  )r|   r   r,  r   s       rC   r  z8MultiLeaderMTextBuilder._transform_content_to_render_ucsC  sI     ""    F|%}}X6!rB   c                Z    | j                   j                  }|J |j                  |       y r   )ru   r   apply_conversion_factor)r|   r  r   s      rC   r  z0MultiLeaderMTextBuilder._apply_conversion_factorN  s,    ""   %%&78rB   c                   |}|||z  }t        |t              rt        j                  }n/|j                  dk  rt        j
                  nt        j                  }| j                  ||       t        | j                  j                  j                        }	| j                         }
t        |t              rtd}|j                  dk  r(t        j
                  }|
j
                  j                   }n't        j                  }|
j                  j                   }| j!                  ||       nt        |t              rvd}	d}|j                  dk\  r(t        j"                  }|
j"                  j                   }n't        j$                  }|
j$                  j                   }| j!                  ||       nt'        d      |g}||j)                  ||z          | j+                  ||       t-        | j.                  j                  j0                        }| j2                  }||z   }t4        |   }|	r	|||z   z  }n
t7               }||z   t7        ||      z   }| j9                  ||       y)	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)rd  rc  zinvalid connection type)r  )r  r7   r9   r`  r6  r  r  r*  rz   r  rr   rP   r  r6   r5   r7  r  rc  rd  r  r(  rF  r  r  rR   r  r  r   r  )r|   r)  targetsegment1segment2connection_typer  offsetr   rP   r   move_text_xr  move_text_ypointsrR   r0  rM  r  last_segmentr   s                        rC   quick_leaderz$MultiLeaderMTextBuilder.quick_leaderS  s>   @ hFo'9:%,,I (.xx3##M<N<N  	I6 $**..99:
335o';<Kxx3%++-33555%**-22444%%$% &  );<JKxx3%,,-44666%))-11333%%#& & 
 677 MM&8+,T6* d//33AAB$$"VO,T2+}s/BCL6L,tK/MM 	 	

6s
#rB   c                    | j                   j                  j                  dk(  r|| j                  _        y || j                  _        y r   )r  rr   rg   ru   
base_pointr  s      rC   r  z'MultiLeaderMTextBuilder._set_base_point  s4      ::a?&*DLL#&,DLL#rB   )
r)  r   r   z Optional[Union[int, colors.RGB]]r]   r  r   r9   r}   r   )r   r   r  r  r  )r)  r   rD  r   rE  r   rF  zOptional[Vec2]rG  z/Union[HorizontalConnection, VerticalConnection]r  r  r   r  r  )r>   r?   r@   r  r9   r  r*  r(  r  r  r  r6   r  rM  r  rA   rB   rC   r3   r3     s    <8  #0#5#5#)#)
#) #) !#) #)JDD
L	"	"&+	"		"9 $( !33!a$a$ a$ 	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   c                P    t         |   |       d | _        t               | _        y r   )superr   _block_layoutr   _extents)r|   r  	__class__s     rC   r   z MultiLeaderBlockBuilder.__init__  s!    %6:#rB   c                   | j                          | j                  }| j                  }d|j                  _        d |_        t               }||_        |j                  j                  |_        |j                  j                  |j                  z  |_
        |j                  j                  |_        |j                  j                  |_        y )NrE   )r  ru   r  rr   rW   r   r"   r   r_   ra   rd   rb   r,  r`   r   )r|   ru   r  r   s       rC   r  z%MultiLeaderBlockBuilder._init_content  s    ,,'' ()$ $/OO$G$G!!oo887==H$77!oo11rB   c                N    t         |           d | _        t               | _        y r   )rR  r  rS  r   rT  )r|   rU  s    rC   r  z$MultiLeaderBlockBuilder._reset_cache  s    !#rB   c                   | j                   | j                   S | j                  j                  }t        |t              sJ d       |j
                  }| j                  j                  j                  |      }|t        d|       |j                  j                  }| j                  j                  j                  |      }|t        d| dt        |       d      || _         |S )zReturns the block layout.undefined BLOCK contentzinvalid BLOCK_RECORD handle #zBLOCK 'z' defined by z
 not found)rS  ru   r   r  r"   r_   r  r   rw   r  rr   r   ry  r   )r|   r   r   r   r   block_layouts         rC   rZ  z$MultiLeaderBlockBuilder.block_layout  s     )%%%""%+F-FF+**yy))--f5<VHEFF$$yy''++D1$}S->,?zJ  *rB   c                    | j                   j                  sSddlm} | j                  }|j                  d |D              }|j                  s|j                  t        g       || _         | j                   S )z&Returns the bounding box of the block.r   )bboxc              3  H   K   | ]  }|j                         d k7  s|  yw)ATTDEFN)dxftype).0rv  s     rC   	<genexpr>z2MultiLeaderBlockBuilder.extents.<locals>.<genexpr>  s"      #199;(+B#s   "")rT  has_datar;   r\  rZ  extentsextendr   )r|   r\  rZ  rc  s       rC   rc  zMultiLeaderBlockBuilder.extents  sd     }}%%",,Lll #'# G ##y)#DM}}rB   c           
     D   | 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.
        rY  r.  r   r  r7  )ru   r   r  r"   r  rr   rc   rZ  rc  rd   r6  r7  r  rO  r`  r:   r  r   r   r  r   )r|   r   rc   rZ  rc  sxsywidth2height2base_xbase_yr>  center_ys                rC   r  z-MultiLeaderBlockBuilder._build_connection_box  sp    ""%+F-FF+ $ 1 1 5 5 K K((,,[[]][[]]#%*,,..3&+((**R/((**R/>>##b(61>>##b(61 N$A$AA	H9a8ELHHh'2x&((3Xx'12(W"45	
 	
rB   c                    | j                   j                  }t        |t              sJ d       t        |_        |j                  j                  |      t        |      z   |_        ||_	        y NrY  )
ru   r   r  r"   r   r   r   r@  r   r,  )r|   r   r,  r   s       rC   r  z8MultiLeaderBlockBuilder._transform_content_to_render_ucs"  sT    ""%+F-FF+ ||**84tF|C!rB   c                    | j                   j                  }t        |t              sJ d       |j	                  |       y rn  )ru   r   r  r"   rB  )r|   r  r   s      rC   r  z0MultiLeaderBlockBuilder._apply_conversion_factor)  s6    ""%+F-FF+%%&78rB   ro   c                   | j                   }| j                  j                  j                  |      }|t	        d| d      |j
                  |j                  _        t        j                  |      |j                  _	        t        |||      |j                  _        t        |      |j                  _        | j                          y)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  ry  rw   r  r_   rr   r   r  r`   r   ra   r  rc   r  )r|   r   r   rd   r   r~   r   s          rC   r*  z#MultiLeaderBlockBuilder.set_content.  s      ##		  $$T*=0a899*/*C*C'"("9"9%"@)-eUE)B&,/	N)rB   c                H   | j                   }| j                  j                  }t        |j	                               D ]d  \  }}||j
                  j                  k(  s |j                  t        |j
                  j                  |t        |      t        |                    y y)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)rZ  r  r8  r  attdefsrr   r>  r(  r!   r   r  r   )r|   r>  r    r   rZ  r8  r   rB  s           rC   set_attributez%MultiLeaderBlockBuilder.set_attributeJ  s     (())77&|';';'=> 
	ME6fjjnn$$$%zz00##El Y	 
	rB   c                &    || j                   _        y r   )ru   rO  r  s      rC   r  z'MultiLeaderBlockBuilder._set_base_pointc  s    "&rB   r  )r   z'BlockLayout')r   r   r  )r   r   r,  r  r  )r   r   r   r  rd   r  )ro   )r>  r   r    r   r   r  r  )r>   r?   r@   r   r  r  r  rZ  rc  r  r  r  r   r   r:   r  r*  rs  r  __classcell__)rU  s   @rC   r4   r4     s    &
2(&
  *  
B"9 )/ // & 	82'rB   r4   r  )r~   r(   r   zIterator[DXFGraphic])r~   r(   r   r*   r   rk   )r   r   r   r*   r   r0   )r   r  r   r   )r   r  r   ztuple[int, Optional[int]])r   r.   r   r'   rd   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   zOptional[str])r  r   r   r  )o
__future__r   typingr   r   r   r   r   r	   r
   r  r3  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    r&  ezdxf.entities.mleaderr!   r"   r#   r$   r%   r&   r'   r(   r)   ezdxf.documentr*   ezdxf.layoutsr+   r,   r-   r.   r/   r0   __all__	getLoggerr   r   r3  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  rd  rc  r  r6   r7   r9   r:   r  r  ABCr2   r3   r4   rA   rB   rC   <module>r     sR   #       # !     #  + 4 5
 
 
 &)  
		7	#   ! 	%.. 	6 f 	
 6 6 & V  v G    w 7  '!" 7#$ "!$")$!( '#*=D#: #:N ).666
D	! 

	!04$*		'	05			   <B 3(I
 I
X TYY   6'6	 )4<< ) DLL T\\    (i& i&jC-0 C-Lh'0 h'rB   